1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
46 #include "gdb_string.h"
47 #include "gdb_assert.h"
48 #include <sys/types.h>
50 #ifndef DWARF2_REG_TO_REGNUM
51 #define DWARF2_REG_TO_REGNUM(REG) (REG)
55 /* .debug_info header for a compilation unit
56 Because of alignment constraints, this structure has padding and cannot
57 be mapped directly onto the beginning of the .debug_info section. */
58 typedef struct comp_unit_header
60 unsigned int length
; /* length of the .debug_info
62 unsigned short version
; /* version number -- 2 for DWARF
64 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
65 unsigned char addr_size
; /* byte size of an address -- 4 */
68 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
71 /* .debug_pubnames header
72 Because of alignment constraints, this structure has padding and cannot
73 be mapped directly onto the beginning of the .debug_info section. */
74 typedef struct pubnames_header
76 unsigned int length
; /* length of the .debug_pubnames
78 unsigned char version
; /* version number -- 2 for DWARF
80 unsigned int info_offset
; /* offset into .debug_info section */
81 unsigned int info_size
; /* byte size of .debug_info section
85 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
87 /* .debug_pubnames header
88 Because of alignment constraints, this structure has padding and cannot
89 be mapped directly onto the beginning of the .debug_info section. */
90 typedef struct aranges_header
92 unsigned int length
; /* byte len of the .debug_aranges
94 unsigned short version
; /* version number -- 2 for DWARF
96 unsigned int info_offset
; /* offset into .debug_info section */
97 unsigned char addr_size
; /* byte size of an address */
98 unsigned char seg_size
; /* byte size of segment descriptor */
101 #define _ACTUAL_ARANGES_HEADER_SIZE 12
103 /* .debug_line statement program prologue
104 Because of alignment constraints, this structure has padding and cannot
105 be mapped directly onto the beginning of the .debug_info section. */
106 typedef struct statement_prologue
108 unsigned int total_length
; /* byte length of the statement
110 unsigned short version
; /* version number -- 2 for DWARF
112 unsigned int prologue_length
; /* # bytes between prologue &
114 unsigned char minimum_instruction_length
; /* byte size of
116 unsigned char default_is_stmt
; /* initial value of is_stmt
119 unsigned char line_range
;
120 unsigned char opcode_base
; /* number assigned to first special
122 unsigned char *standard_opcode_lengths
;
126 /* offsets and sizes of debugging sections */
128 static file_ptr dwarf_info_offset
;
129 static file_ptr dwarf_abbrev_offset
;
130 static file_ptr dwarf_line_offset
;
131 static file_ptr dwarf_pubnames_offset
;
132 static file_ptr dwarf_aranges_offset
;
133 static file_ptr dwarf_loc_offset
;
134 static file_ptr dwarf_macinfo_offset
;
135 static file_ptr dwarf_str_offset
;
136 file_ptr dwarf_frame_offset
;
137 file_ptr dwarf_eh_frame_offset
;
139 static unsigned int dwarf_info_size
;
140 static unsigned int dwarf_abbrev_size
;
141 static unsigned int dwarf_line_size
;
142 static unsigned int dwarf_pubnames_size
;
143 static unsigned int dwarf_aranges_size
;
144 static unsigned int dwarf_loc_size
;
145 static unsigned int dwarf_macinfo_size
;
146 static unsigned int dwarf_str_size
;
147 unsigned int dwarf_frame_size
;
148 unsigned int dwarf_eh_frame_size
;
150 /* names of the debugging sections */
152 #define INFO_SECTION ".debug_info"
153 #define ABBREV_SECTION ".debug_abbrev"
154 #define LINE_SECTION ".debug_line"
155 #define PUBNAMES_SECTION ".debug_pubnames"
156 #define ARANGES_SECTION ".debug_aranges"
157 #define LOC_SECTION ".debug_loc"
158 #define MACINFO_SECTION ".debug_macinfo"
159 #define STR_SECTION ".debug_str"
160 #define FRAME_SECTION ".debug_frame"
161 #define EH_FRAME_SECTION ".eh_frame"
163 /* local data types */
165 /* We hold several abbreviation tables in memory at the same time. */
166 #ifndef ABBREV_HASH_SIZE
167 #define ABBREV_HASH_SIZE 121
170 /* The data in a compilation unit header, after target2host
171 translation, looks like this. */
172 struct comp_unit_head
174 unsigned long length
;
176 unsigned int abbrev_offset
;
177 unsigned char addr_size
;
178 unsigned char signed_addr_p
;
179 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
180 unsigned int initial_length_size
; /* size of the length field; either
183 /* Offset to the first byte of this compilation unit header in the
184 * .debug_info section, for resolving relative reference dies. */
188 /* Pointer to this compilation unit header in the .debug_info
193 /* Pointer to the first die of this compilatio unit. This will
194 * be the first byte following the compilation unit header. */
198 /* Pointer to the next compilation unit header in the program. */
200 struct comp_unit_head
*next
;
202 /* DWARF abbreviation table associated with this compilation unit */
204 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
207 /* The line number information for a compilation unit (found in the
208 .debug_line section) begins with a "statement program header",
209 which contains the following information. */
212 unsigned int total_length
;
213 unsigned short version
;
214 unsigned int header_length
;
215 unsigned char minimum_instruction_length
;
216 unsigned char default_is_stmt
;
218 unsigned char line_range
;
219 unsigned char opcode_base
;
221 /* standard_opcode_lengths[i] is the number of operands for the
222 standard opcode whose value is i. This means that
223 standard_opcode_lengths[0] is unused, and the last meaningful
224 element is standard_opcode_lengths[opcode_base - 1]. */
225 unsigned char *standard_opcode_lengths
;
227 /* The include_directories table. NOTE! These strings are not
228 allocated with xmalloc; instead, they are pointers into
229 debug_line_buffer. If you try to free them, `free' will get
231 unsigned int num_include_dirs
, include_dirs_size
;
234 /* The file_names table. NOTE! These strings are not allocated
235 with xmalloc; instead, they are pointers into debug_line_buffer.
236 Don't try to free them directly. */
237 unsigned int num_file_names
, file_names_size
;
241 unsigned int dir_index
;
242 unsigned int mod_time
;
246 /* The start and end of the statement program following this
247 header. These point into dwarf_line_buffer. */
248 char *statement_program_start
, *statement_program_end
;
251 /* When we construct a partial symbol table entry we only
252 need this much information. */
253 struct partial_die_info
256 unsigned char has_children
;
257 unsigned char is_external
;
258 unsigned char is_declaration
;
259 unsigned char has_type
;
266 struct dwarf_block
*locdesc
;
267 unsigned int language
;
271 /* This data structure holds the information of an abbrev. */
274 unsigned int number
; /* number identifying abbrev */
275 enum dwarf_tag tag
; /* dwarf tag */
276 int has_children
; /* boolean */
277 unsigned int num_attrs
; /* number of attributes */
278 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
279 struct abbrev_info
*next
; /* next in chain */
284 enum dwarf_attribute name
;
285 enum dwarf_form form
;
288 /* This data structure holds a complete die structure. */
291 enum dwarf_tag tag
; /* Tag indicating type of die */
292 unsigned short has_children
; /* Does the die have children */
293 unsigned int abbrev
; /* Abbrev number */
294 unsigned int offset
; /* Offset in .debug_info section */
295 unsigned int num_attrs
; /* Number of attributes */
296 struct attribute
*attrs
; /* An array of attributes */
297 struct die_info
*next_ref
; /* Next die in ref hash table */
298 struct die_info
*next
; /* Next die in linked list */
299 struct type
*type
; /* Cached type information */
302 /* Attributes have a name and a value */
305 enum dwarf_attribute name
;
306 enum dwarf_form form
;
310 struct dwarf_block
*blk
;
318 struct function_range
321 CORE_ADDR lowpc
, highpc
;
323 struct function_range
*next
;
326 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
328 /* Get at parts of an attribute structure */
330 #define DW_STRING(attr) ((attr)->u.str)
331 #define DW_UNSND(attr) ((attr)->u.unsnd)
332 #define DW_BLOCK(attr) ((attr)->u.blk)
333 #define DW_SND(attr) ((attr)->u.snd)
334 #define DW_ADDR(attr) ((attr)->u.addr)
336 /* Blocks are a bunch of untyped bytes. */
343 #ifndef ATTR_ALLOC_CHUNK
344 #define ATTR_ALLOC_CHUNK 4
347 /* A hash table of die offsets for following references. */
348 #ifndef REF_HASH_SIZE
349 #define REF_HASH_SIZE 1021
352 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
354 /* Obstack for allocating temporary storage used during symbol reading. */
355 static struct obstack dwarf2_tmp_obstack
;
357 /* Offset to the first byte of the current compilation unit header,
358 for resolving relative reference dies. */
359 static unsigned int cu_header_offset
;
361 /* Allocate fields for structs, unions and enums in this size. */
362 #ifndef DW_FIELD_ALLOC_CHUNK
363 #define DW_FIELD_ALLOC_CHUNK 4
366 /* The language we are debugging. */
367 static enum language cu_language
;
368 static const struct language_defn
*cu_language_defn
;
370 /* Actually data from the sections. */
371 static char *dwarf_info_buffer
;
372 static char *dwarf_abbrev_buffer
;
373 static char *dwarf_line_buffer
;
374 static char *dwarf_str_buffer
;
375 static char *dwarf_macinfo_buffer
;
377 /* A zeroed version of a partial die for initialization purposes. */
378 static struct partial_die_info zeroed_partial_die
;
380 /* The generic symbol table building routines have separate lists for
381 file scope symbols and all all other scopes (local scopes). So
382 we need to select the right one to pass to add_symbol_to_list().
383 We do it by keeping a pointer to the correct list in list_in_scope.
385 FIXME: The original dwarf code just treated the file scope as the first
386 local scope, and all other local scopes as nested local scopes, and worked
387 fine. Check to see if we really need to distinguish these
389 static struct pending
**list_in_scope
= &file_symbols
;
391 /* FIXME: decode_locdesc sets these variables to describe the location
392 to the caller. These ought to be a structure or something. If
393 none of the flags are set, the object lives at the address returned
394 by decode_locdesc. */
396 static int optimized_out
; /* No ops in location in expression,
397 so object was optimized out. */
398 static int isreg
; /* Object lives in register.
399 decode_locdesc's return value is
400 the register number. */
401 static int offreg
; /* Object's address is the sum of the
402 register specified by basereg, plus
403 the offset returned. */
404 static int basereg
; /* See `offreg'. */
405 static int isderef
; /* Value described by flags above is
406 the address of a pointer to the object. */
407 static int islocal
; /* Variable is at the returned offset
408 from the frame start, but there's
409 no identified frame pointer for
410 this function, so we can't say
411 which register it's relative to;
414 /* DW_AT_frame_base values for the current function.
415 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
416 contains the register number for the frame register.
417 frame_base_offset is the offset from the frame register to the
418 virtual stack frame. */
419 static int frame_base_reg
;
420 static CORE_ADDR frame_base_offset
;
422 /* This value is added to each symbol value. FIXME: Generalize to
423 the section_offsets structure used by dbxread (once this is done,
424 pass the appropriate section number to end_symtab). */
425 static CORE_ADDR baseaddr
; /* Add to each symbol value */
427 /* We put a pointer to this structure in the read_symtab_private field
429 The complete dwarf information for an objfile is kept in the
430 psymbol_obstack, so that absolute die references can be handled.
431 Most of the information in this structure is related to an entire
432 object file and could be passed via the sym_private field of the objfile.
433 It is however conceivable that dwarf2 might not be the only type
434 of symbols read from an object file. */
438 /* Pointer to start of dwarf info buffer for the objfile. */
440 char *dwarf_info_buffer
;
442 /* Offset in dwarf_info_buffer for this compilation unit. */
444 unsigned long dwarf_info_offset
;
446 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
448 char *dwarf_abbrev_buffer
;
450 /* Size of dwarf abbreviation section for the objfile. */
452 unsigned int dwarf_abbrev_size
;
454 /* Pointer to start of dwarf line buffer for the objfile. */
456 char *dwarf_line_buffer
;
458 /* Size of dwarf_line_buffer, in bytes. */
460 unsigned int dwarf_line_size
;
462 /* Pointer to start of dwarf string buffer for the objfile. */
464 char *dwarf_str_buffer
;
466 /* Size of dwarf string section for the objfile. */
468 unsigned int dwarf_str_size
;
470 /* Pointer to start of dwarf macro buffer for the objfile. */
472 char *dwarf_macinfo_buffer
;
474 /* Size of dwarf macinfo section for the objfile. */
476 unsigned int dwarf_macinfo_size
;
480 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
481 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
482 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
483 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
484 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
485 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
486 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
487 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
488 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
489 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
490 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
492 /* Maintain an array of referenced fundamental types for the current
493 compilation unit being read. For DWARF version 1, we have to construct
494 the fundamental types on the fly, since no information about the
495 fundamental types is supplied. Each such fundamental type is created by
496 calling a language dependent routine to create the type, and then a
497 pointer to that type is then placed in the array at the index specified
498 by it's FT_<TYPENAME> value. The array has a fixed size set by the
499 FT_NUM_MEMBERS compile time constant, which is the number of predefined
500 fundamental types gdb knows how to construct. */
501 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
503 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
504 but this would require a corresponding change in unpack_field_as_long
506 static int bits_per_byte
= 8;
508 /* The routines that read and process dies for a C struct or C++ class
509 pass lists of data member fields and lists of member function fields
510 in an instance of a field_info structure, as defined below. */
513 /* List of data member and baseclasses fields. */
516 struct nextfield
*next
;
523 /* Number of fields. */
526 /* Number of baseclasses. */
529 /* Set if the accesibility of one of the fields is not public. */
530 int non_public_fields
;
532 /* Member function fields array, entries are allocated in the order they
533 are encountered in the object file. */
536 struct nextfnfield
*next
;
537 struct fn_field fnfield
;
541 /* Member function fieldlist array, contains name of possibly overloaded
542 member function, number of overloaded member functions and a pointer
543 to the head of the member function field chain. */
548 struct nextfnfield
*head
;
552 /* Number of entries in the fnfieldlists array. */
556 /* Various complaints about symbol reading that don't abort the process */
558 static struct complaint dwarf2_const_ignored
=
560 "type qualifier 'const' ignored", 0, 0
562 static struct complaint dwarf2_volatile_ignored
=
564 "type qualifier 'volatile' ignored", 0, 0
566 static struct complaint dwarf2_non_const_array_bound_ignored
=
568 "non-constant array bounds form '%s' ignored", 0, 0
570 static struct complaint dwarf2_missing_line_number_section
=
572 "missing .debug_line section", 0, 0
574 static struct complaint dwarf2_statement_list_fits_in_line_number_section
=
576 "statement list doesn't fit in .debug_line section", 0, 0
578 static struct complaint dwarf2_mangled_line_number_section
=
580 "mangled .debug_line section", 0, 0
582 static struct complaint dwarf2_unsupported_die_ref_attr
=
584 "unsupported die ref attribute form: '%s'", 0, 0
586 static struct complaint dwarf2_unsupported_stack_op
=
588 "unsupported stack op: '%s'", 0, 0
590 static struct complaint dwarf2_complex_location_expr
=
592 "location expression too complex", 0, 0
594 static struct complaint dwarf2_unsupported_tag
=
596 "unsupported tag: '%s'", 0, 0
598 static struct complaint dwarf2_unsupported_at_encoding
=
600 "unsupported DW_AT_encoding: '%s'", 0, 0
602 static struct complaint dwarf2_unsupported_at_frame_base
=
604 "unsupported DW_AT_frame_base for function '%s'", 0, 0
606 static struct complaint dwarf2_unexpected_tag
=
608 "unexepected tag in read_type_die: '%s'", 0, 0
610 static struct complaint dwarf2_missing_at_frame_base
=
612 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
614 static struct complaint dwarf2_bad_static_member_name
=
616 "unrecognized static data member name '%s'", 0, 0
618 static struct complaint dwarf2_unsupported_accessibility
=
620 "unsupported accessibility %d", 0, 0
622 static struct complaint dwarf2_bad_member_name_complaint
=
624 "cannot extract member name from '%s'", 0, 0
626 static struct complaint dwarf2_missing_member_fn_type_complaint
=
628 "member function type missing for '%s'", 0, 0
630 static struct complaint dwarf2_vtbl_not_found_complaint
=
632 "virtual function table pointer not found when defining class '%s'", 0, 0
634 static struct complaint dwarf2_absolute_sibling_complaint
=
636 "ignoring absolute DW_AT_sibling", 0, 0
638 static struct complaint dwarf2_const_value_length_mismatch
=
640 "const value length mismatch for '%s', got %d, expected %d", 0, 0
642 static struct complaint dwarf2_unsupported_const_value_attr
=
644 "unsupported const value attribute form: '%s'", 0, 0
646 static struct complaint dwarf2_misplaced_line_number
=
648 "misplaced first line number at 0x%lx for '%s'", 0, 0
650 static struct complaint dwarf2_line_header_too_long
=
652 "line number info header doesn't fit in `.debug_line' section", 0, 0
654 static struct complaint dwarf2_missing_macinfo_section
=
656 "missing .debug_macinfo section", 0, 0
658 static struct complaint dwarf2_macros_too_long
=
660 "macro info runs off end of `.debug_macinfo' section", 0, 0
662 static struct complaint dwarf2_macros_not_terminated
=
664 "no terminating 0-type entry for macros in `.debug_macinfo' section", 0, 0
666 static struct complaint dwarf2_macro_outside_file
=
668 "debug info gives macro %s outside of any file: %s", 0, 0
670 static struct complaint dwarf2_macro_unmatched_end_file
=
672 "macro debug info has an unmatched `close_file' directive", 0, 0
674 static struct complaint dwarf2_macro_malformed_definition
=
676 "macro debug info contains a malformed macro definition:\n`%s'", 0, 0
678 static struct complaint dwarf2_macro_spaces_in_definition
=
680 "macro definition contains spaces in formal argument list:\n`%s'", 0, 0
682 static struct complaint dwarf2_invalid_attrib_class
=
684 "invalid attribute class or form for '%s' in '%s'", 0, 0
686 static struct complaint dwarf2_invalid_pointer_size
=
688 "invalid pointer size %d", 0, 0
691 /* local function prototypes */
693 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
696 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
699 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
701 static char *scan_partial_symbols (char *, struct objfile
*,
702 CORE_ADDR
*, CORE_ADDR
*,
703 const struct comp_unit_head
*);
705 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
706 const struct comp_unit_head
*);
708 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
710 static void psymtab_to_symtab_1 (struct partial_symtab
*);
712 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
714 static void dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
);
716 static void dwarf2_empty_abbrev_table (PTR
);
718 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
719 const struct comp_unit_head
*cu_header
);
721 static char *read_partial_die (struct partial_die_info
*,
723 const struct comp_unit_head
*);
725 static char *read_full_die (struct die_info
**, bfd
*, char *,
726 const struct comp_unit_head
*);
728 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
729 bfd
*, char *, const struct comp_unit_head
*);
731 static char *read_attribute_value (struct attribute
*, unsigned,
732 bfd
*, char *, const struct comp_unit_head
*);
734 static unsigned int read_1_byte (bfd
*, char *);
736 static int read_1_signed_byte (bfd
*, char *);
738 static unsigned int read_2_bytes (bfd
*, char *);
740 static unsigned int read_4_bytes (bfd
*, char *);
742 static unsigned long read_8_bytes (bfd
*, char *);
744 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
747 static LONGEST
read_initial_length (bfd
*, char *,
748 struct comp_unit_head
*, int *bytes_read
);
750 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
753 static char *read_n_bytes (bfd
*, char *, unsigned int);
755 static char *read_string (bfd
*, char *, unsigned int *);
757 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
760 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
762 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
764 static void set_cu_language (unsigned int);
766 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
768 static int die_is_declaration (struct die_info
*);
770 static void free_line_header (struct line_header
*lh
);
772 static struct line_header
*(dwarf_decode_line_header
773 (unsigned int offset
,
775 const struct comp_unit_head
*cu_header
));
777 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
778 const struct comp_unit_head
*);
780 static void dwarf2_start_subfile (char *, char *);
782 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
783 struct objfile
*, const struct comp_unit_head
*);
785 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
786 struct objfile
*, const struct comp_unit_head
*);
788 static void dwarf2_const_value_data (struct attribute
*attr
,
792 static struct type
*die_type (struct die_info
*, struct objfile
*,
793 const struct comp_unit_head
*);
795 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
796 const struct comp_unit_head
*);
799 static struct type
*type_at_offset (unsigned int, struct objfile
*);
802 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
803 const struct comp_unit_head
*);
805 static void read_type_die (struct die_info
*, struct objfile
*,
806 const struct comp_unit_head
*);
808 static void read_typedef (struct die_info
*, struct objfile
*,
809 const struct comp_unit_head
*);
811 static void read_base_type (struct die_info
*, struct objfile
*);
813 static void read_file_scope (struct die_info
*, struct objfile
*,
814 const struct comp_unit_head
*);
816 static void read_func_scope (struct die_info
*, struct objfile
*,
817 const struct comp_unit_head
*);
819 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
820 const struct comp_unit_head
*);
822 static int dwarf2_get_pc_bounds (struct die_info
*,
823 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
825 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
826 struct objfile
*, const struct comp_unit_head
*);
828 static void dwarf2_attach_fields_to_type (struct field_info
*,
829 struct type
*, struct objfile
*);
831 static void dwarf2_add_member_fn (struct field_info
*,
832 struct die_info
*, struct type
*,
833 struct objfile
*objfile
,
834 const struct comp_unit_head
*);
836 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
837 struct type
*, struct objfile
*);
839 static void read_structure_scope (struct die_info
*, struct objfile
*,
840 const struct comp_unit_head
*);
842 static void read_common_block (struct die_info
*, struct objfile
*,
843 const struct comp_unit_head
*);
845 static void read_enumeration (struct die_info
*, struct objfile
*,
846 const struct comp_unit_head
*);
848 static struct type
*dwarf_base_type (int, int, struct objfile
*);
850 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
851 const struct comp_unit_head
*);
853 static void read_array_type (struct die_info
*, struct objfile
*,
854 const struct comp_unit_head
*);
856 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
857 const struct comp_unit_head
*);
859 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
860 const struct comp_unit_head
*);
862 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
863 const struct comp_unit_head
*);
865 static void read_tag_const_type (struct die_info
*, struct objfile
*,
866 const struct comp_unit_head
*);
868 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
869 const struct comp_unit_head
*);
871 static void read_tag_string_type (struct die_info
*, struct objfile
*);
873 static void read_subroutine_type (struct die_info
*, struct objfile
*,
874 const struct comp_unit_head
*);
876 static struct die_info
*read_comp_unit (char *, bfd
*,
877 const struct comp_unit_head
*);
879 static void free_die_list (struct die_info
*);
881 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
883 static void process_die (struct die_info
*, struct objfile
*,
884 const struct comp_unit_head
*);
886 static char *dwarf2_linkage_name (struct die_info
*);
888 static char *dwarf_tag_name (unsigned int);
890 static char *dwarf_attr_name (unsigned int);
892 static char *dwarf_form_name (unsigned int);
894 static char *dwarf_stack_op_name (unsigned int);
896 static char *dwarf_bool_name (unsigned int);
898 static char *dwarf_type_encoding_name (unsigned int);
901 static char *dwarf_cfi_name (unsigned int);
903 struct die_info
*copy_die (struct die_info
*);
906 static struct die_info
*sibling_die (struct die_info
*);
908 static void dump_die (struct die_info
*);
910 static void dump_die_list (struct die_info
*);
912 static void store_in_ref_table (unsigned int, struct die_info
*);
914 static void dwarf2_empty_hash_tables (void);
916 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
918 static struct die_info
*follow_die_ref (unsigned int);
920 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
922 /* memory allocation interface */
924 static void dwarf2_free_tmp_obstack (PTR
);
926 static struct dwarf_block
*dwarf_alloc_block (void);
928 static struct abbrev_info
*dwarf_alloc_abbrev (void);
930 static struct die_info
*dwarf_alloc_die (void);
932 static void initialize_cu_func_list (void);
934 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
936 static void dwarf_decode_macros (struct line_header
*, unsigned int,
937 char *, bfd
*, const struct comp_unit_head
*,
940 static int attr_form_is_block (struct attribute
*);
942 /* Try to locate the sections we need for DWARF 2 debugging
943 information and return true if we have enough to do something. */
946 dwarf2_has_info (bfd
*abfd
)
948 dwarf_info_offset
= 0;
949 dwarf_abbrev_offset
= 0;
950 dwarf_line_offset
= 0;
951 dwarf_str_offset
= 0;
952 dwarf_macinfo_offset
= 0;
953 dwarf_frame_offset
= 0;
954 dwarf_eh_frame_offset
= 0;
955 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
956 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
966 /* This function is mapped across the sections and remembers the
967 offset and size of each of the debugging sections we are interested
971 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
973 if (STREQ (sectp
->name
, INFO_SECTION
))
975 dwarf_info_offset
= sectp
->filepos
;
976 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
978 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
980 dwarf_abbrev_offset
= sectp
->filepos
;
981 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
983 else if (STREQ (sectp
->name
, LINE_SECTION
))
985 dwarf_line_offset
= sectp
->filepos
;
986 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
988 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
990 dwarf_pubnames_offset
= sectp
->filepos
;
991 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
993 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
995 dwarf_aranges_offset
= sectp
->filepos
;
996 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
998 else if (STREQ (sectp
->name
, LOC_SECTION
))
1000 dwarf_loc_offset
= sectp
->filepos
;
1001 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
1003 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
1005 dwarf_macinfo_offset
= sectp
->filepos
;
1006 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1008 else if (STREQ (sectp
->name
, STR_SECTION
))
1010 dwarf_str_offset
= sectp
->filepos
;
1011 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1013 else if (STREQ (sectp
->name
, FRAME_SECTION
))
1015 dwarf_frame_offset
= sectp
->filepos
;
1016 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1018 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
1020 dwarf_eh_frame_offset
= sectp
->filepos
;
1021 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1025 /* Build a partial symbol table. */
1028 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1031 /* We definitely need the .debug_info and .debug_abbrev sections */
1033 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1036 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1037 dwarf_abbrev_offset
,
1040 if (dwarf_line_offset
)
1041 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1045 dwarf_line_buffer
= NULL
;
1047 if (dwarf_str_offset
)
1048 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1052 dwarf_str_buffer
= NULL
;
1054 if (dwarf_macinfo_offset
)
1055 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1056 dwarf_macinfo_offset
,
1057 dwarf_macinfo_size
);
1059 dwarf_macinfo_buffer
= NULL
;
1062 || (objfile
->global_psymbols
.size
== 0
1063 && objfile
->static_psymbols
.size
== 0))
1065 init_psymbol_list (objfile
, 1024);
1069 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1071 /* Things are significantly easier if we have .debug_aranges and
1072 .debug_pubnames sections */
1074 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1078 /* only test this case for now */
1080 /* In this case we have to work a bit harder */
1081 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1086 /* Build the partial symbol table from the information in the
1087 .debug_pubnames and .debug_aranges sections. */
1090 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1092 bfd
*abfd
= objfile
->obfd
;
1093 char *aranges_buffer
, *pubnames_buffer
;
1094 char *aranges_ptr
, *pubnames_ptr
;
1095 unsigned int entry_length
, version
, info_offset
, info_size
;
1097 pubnames_buffer
= dwarf2_read_section (objfile
,
1098 dwarf_pubnames_offset
,
1099 dwarf_pubnames_size
);
1100 pubnames_ptr
= pubnames_buffer
;
1101 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1103 struct comp_unit_head cu_header
;
1106 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1108 pubnames_ptr
+= bytes_read
;
1109 version
= read_1_byte (abfd
, pubnames_ptr
);
1111 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1113 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1117 aranges_buffer
= dwarf2_read_section (objfile
,
1118 dwarf_aranges_offset
,
1119 dwarf_aranges_size
);
1124 /* Read in the comp unit header information from the debug_info at
1128 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1129 char *info_ptr
, bfd
*abfd
)
1133 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1135 info_ptr
+= bytes_read
;
1136 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1138 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1140 info_ptr
+= bytes_read
;
1141 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1143 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1144 if (signed_addr
< 0)
1145 internal_error (__FILE__
, __LINE__
,
1146 "read_comp_unit_head: dwarf from non elf file");
1147 cu_header
->signed_addr_p
= signed_addr
;
1151 /* Build the partial symbol table by doing a quick pass through the
1152 .debug_info and .debug_abbrev sections. */
1155 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1157 /* Instead of reading this into a big buffer, we should probably use
1158 mmap() on architectures that support it. (FIXME) */
1159 bfd
*abfd
= objfile
->obfd
;
1160 char *info_ptr
, *abbrev_ptr
;
1161 char *beg_of_comp_unit
;
1162 struct partial_die_info comp_unit_die
;
1163 struct partial_symtab
*pst
;
1164 struct cleanup
*back_to
;
1165 CORE_ADDR lowpc
, highpc
;
1167 info_ptr
= dwarf_info_buffer
;
1168 abbrev_ptr
= dwarf_abbrev_buffer
;
1170 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1171 the partial symbol scan, like attribute values.
1173 We could reduce our peak memory consumption during partial symbol
1174 table construction by freeing stuff from this obstack more often
1175 --- say, after processing each compilation unit, or each die ---
1176 but it turns out that this saves almost nothing. For an
1177 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1178 on dwarf2_tmp_obstack. Some investigation showed:
1180 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1181 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1182 all fixed-length values not requiring dynamic allocation.
1184 2) 30% of the attributes used the form DW_FORM_string. For
1185 DW_FORM_string, read_attribute simply hands back a pointer to
1186 the null-terminated string in dwarf_info_buffer, so no dynamic
1187 allocation is needed there either.
1189 3) The remaining 1% of the attributes all used DW_FORM_block1.
1190 75% of those were DW_AT_frame_base location lists for
1191 functions; the rest were DW_AT_location attributes, probably
1192 for the global variables.
1194 Anyway, what this all means is that the memory the dwarf2
1195 reader uses as temporary space reading partial symbols is about
1196 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1198 obstack_init (&dwarf2_tmp_obstack
);
1199 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1201 /* Since the objects we're extracting from dwarf_info_buffer vary in
1202 length, only the individual functions to extract them (like
1203 read_comp_unit_head and read_partial_die) can really know whether
1204 the buffer is large enough to hold another complete object.
1206 At the moment, they don't actually check that. If
1207 dwarf_info_buffer holds just one extra byte after the last
1208 compilation unit's dies, then read_comp_unit_head will happily
1209 read off the end of the buffer. read_partial_die is similarly
1210 casual. Those functions should be fixed.
1212 For this loop condition, simply checking whether there's any data
1213 left at all should be sufficient. */
1214 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1216 struct comp_unit_head cu_header
;
1217 beg_of_comp_unit
= info_ptr
;
1218 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1220 if (cu_header
.version
!= 2)
1222 error ("Dwarf Error: wrong version in compilation unit header.");
1225 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1227 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1228 (long) cu_header
.abbrev_offset
,
1229 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1232 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1233 > dwarf_info_buffer
+ dwarf_info_size
)
1235 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1236 (long) cu_header
.length
,
1237 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1240 /* Complete the cu_header */
1241 cu_header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1242 cu_header
.first_die_ptr
= info_ptr
;
1243 cu_header
.cu_head_ptr
= beg_of_comp_unit
;
1245 /* Read the abbrevs for this compilation unit into a table */
1246 dwarf2_read_abbrevs (abfd
, &cu_header
);
1247 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1249 /* Read the compilation unit die */
1250 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1253 /* Set the language we're debugging */
1254 set_cu_language (comp_unit_die
.language
);
1256 /* Allocate a new partial symbol table structure */
1257 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1258 comp_unit_die
.name
? comp_unit_die
.name
: "",
1259 comp_unit_die
.lowpc
,
1260 objfile
->global_psymbols
.next
,
1261 objfile
->static_psymbols
.next
);
1263 pst
->read_symtab_private
= (char *)
1264 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1265 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1266 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1267 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1268 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1269 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1270 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1271 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1272 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1273 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1274 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1275 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1276 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1278 /* Store the function that reads in the rest of the symbol table */
1279 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1281 /* Check if comp unit has_children.
1282 If so, read the rest of the partial symbols from this comp unit.
1283 If not, there's no more debug_info for this comp unit. */
1284 if (comp_unit_die
.has_children
)
1286 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1289 /* If the compilation unit didn't have an explicit address range,
1290 then use the information extracted from its child dies. */
1291 if (! comp_unit_die
.has_pc_info
)
1293 comp_unit_die
.lowpc
= lowpc
;
1294 comp_unit_die
.highpc
= highpc
;
1297 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1298 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1300 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1301 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1302 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1303 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1304 sort_pst_symbols (pst
);
1306 /* If there is already a psymtab or symtab for a file of this
1307 name, remove it. (If there is a symtab, more drastic things
1308 also happen.) This happens in VxWorks. */
1309 free_named_symtabs (pst
->filename
);
1311 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1312 + cu_header
.initial_length_size
;
1314 do_cleanups (back_to
);
1317 /* Read in all interesting dies to the end of the compilation unit. */
1320 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1321 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1322 const struct comp_unit_head
*cu_header
)
1324 bfd
*abfd
= objfile
->obfd
;
1325 struct partial_die_info pdi
;
1327 /* This function is called after we've read in the comp_unit_die in
1328 order to read its children. We start the nesting level at 1 since
1329 we have pushed 1 level down in order to read the comp unit's children.
1330 The comp unit itself is at level 0, so we stop reading when we pop
1331 back to that level. */
1333 int nesting_level
= 1;
1335 *lowpc
= ((CORE_ADDR
) -1);
1336 *highpc
= ((CORE_ADDR
) 0);
1338 while (nesting_level
)
1340 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1346 case DW_TAG_subprogram
:
1347 if (pdi
.has_pc_info
)
1349 if (pdi
.lowpc
< *lowpc
)
1353 if (pdi
.highpc
> *highpc
)
1355 *highpc
= pdi
.highpc
;
1357 if ((pdi
.is_external
|| nesting_level
== 1)
1358 && !pdi
.is_declaration
)
1360 add_partial_symbol (&pdi
, objfile
, cu_header
);
1364 case DW_TAG_variable
:
1365 case DW_TAG_typedef
:
1366 case DW_TAG_class_type
:
1367 case DW_TAG_structure_type
:
1368 case DW_TAG_union_type
:
1369 case DW_TAG_enumeration_type
:
1370 if ((pdi
.is_external
|| nesting_level
== 1)
1371 && !pdi
.is_declaration
)
1373 add_partial_symbol (&pdi
, objfile
, cu_header
);
1376 case DW_TAG_enumerator
:
1377 /* File scope enumerators are added to the partial symbol
1379 if (nesting_level
== 2)
1380 add_partial_symbol (&pdi
, objfile
, cu_header
);
1382 case DW_TAG_base_type
:
1383 /* File scope base type definitions are added to the partial
1385 if (nesting_level
== 1)
1386 add_partial_symbol (&pdi
, objfile
, cu_header
);
1393 /* If the die has a sibling, skip to the sibling.
1394 Do not skip enumeration types, we want to record their
1396 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1398 info_ptr
= pdi
.sibling
;
1400 else if (pdi
.has_children
)
1402 /* Die has children, but the optional DW_AT_sibling attribute
1413 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1414 from `maint check'. */
1415 if (*lowpc
== ((CORE_ADDR
) -1))
1421 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1422 const struct comp_unit_head
*cu_header
)
1428 case DW_TAG_subprogram
:
1429 if (pdi
->is_external
)
1431 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1432 mst_text, objfile); */
1433 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1434 VAR_NAMESPACE
, LOC_BLOCK
,
1435 &objfile
->global_psymbols
,
1436 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1440 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1441 mst_file_text, objfile); */
1442 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1443 VAR_NAMESPACE
, LOC_BLOCK
,
1444 &objfile
->static_psymbols
,
1445 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1448 case DW_TAG_variable
:
1449 if (pdi
->is_external
)
1452 Don't enter into the minimal symbol tables as there is
1453 a minimal symbol table entry from the ELF symbols already.
1454 Enter into partial symbol table if it has a location
1455 descriptor or a type.
1456 If the location descriptor is missing, new_symbol will create
1457 a LOC_UNRESOLVED symbol, the address of the variable will then
1458 be determined from the minimal symbol table whenever the variable
1460 The address for the partial symbol table entry is not
1461 used by GDB, but it comes in handy for debugging partial symbol
1465 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1466 if (pdi
->locdesc
|| pdi
->has_type
)
1467 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1468 VAR_NAMESPACE
, LOC_STATIC
,
1469 &objfile
->global_psymbols
,
1470 0, addr
+ baseaddr
, cu_language
, objfile
);
1474 /* Static Variable. Skip symbols without location descriptors. */
1475 if (pdi
->locdesc
== NULL
)
1477 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1478 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1479 mst_file_data, objfile); */
1480 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1481 VAR_NAMESPACE
, LOC_STATIC
,
1482 &objfile
->static_psymbols
,
1483 0, addr
+ baseaddr
, cu_language
, objfile
);
1486 case DW_TAG_typedef
:
1487 case DW_TAG_base_type
:
1488 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1489 VAR_NAMESPACE
, LOC_TYPEDEF
,
1490 &objfile
->static_psymbols
,
1491 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1493 case DW_TAG_class_type
:
1494 case DW_TAG_structure_type
:
1495 case DW_TAG_union_type
:
1496 case DW_TAG_enumeration_type
:
1497 /* Skip aggregate types without children, these are external
1499 if (pdi
->has_children
== 0)
1501 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1502 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1503 &objfile
->static_psymbols
,
1504 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1506 if (cu_language
== language_cplus
)
1508 /* For C++, these implicitly act as typedefs as well. */
1509 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1510 VAR_NAMESPACE
, LOC_TYPEDEF
,
1511 &objfile
->static_psymbols
,
1512 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1515 case DW_TAG_enumerator
:
1516 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1517 VAR_NAMESPACE
, LOC_CONST
,
1518 &objfile
->static_psymbols
,
1519 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1526 /* Expand this partial symbol table into a full symbol table. */
1529 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1531 /* FIXME: This is barely more than a stub. */
1536 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1542 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1543 gdb_flush (gdb_stdout
);
1546 psymtab_to_symtab_1 (pst
);
1548 /* Finish up the debug error message. */
1550 printf_filtered ("done.\n");
1556 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1558 struct objfile
*objfile
= pst
->objfile
;
1559 bfd
*abfd
= objfile
->obfd
;
1560 struct comp_unit_head cu_header
;
1561 struct die_info
*dies
;
1562 unsigned long offset
;
1563 CORE_ADDR lowpc
, highpc
;
1564 struct die_info
*child_die
;
1566 struct symtab
*symtab
;
1567 struct cleanup
*back_to
;
1569 /* Set local variables from the partial symbol table info. */
1570 offset
= DWARF_INFO_OFFSET (pst
);
1571 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1572 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1573 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1574 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1575 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1576 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1577 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1578 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1579 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1580 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1581 cu_header_offset
= offset
;
1582 info_ptr
= dwarf_info_buffer
+ offset
;
1584 obstack_init (&dwarf2_tmp_obstack
);
1585 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1588 make_cleanup (really_free_pendings
, NULL
);
1590 /* read in the comp_unit header */
1591 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1593 /* Read the abbrevs for this compilation unit */
1594 dwarf2_read_abbrevs (abfd
, &cu_header
);
1595 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1597 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1599 make_cleanup_free_die_list (dies
);
1601 /* Do line number decoding in read_file_scope () */
1602 process_die (dies
, objfile
, &cu_header
);
1604 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1606 /* Some compilers don't define a DW_AT_high_pc attribute for
1607 the compilation unit. If the DW_AT_high_pc is missing,
1608 synthesize it, by scanning the DIE's below the compilation unit. */
1610 if (dies
->has_children
)
1612 child_die
= dies
->next
;
1613 while (child_die
&& child_die
->tag
)
1615 if (child_die
->tag
== DW_TAG_subprogram
)
1617 CORE_ADDR low
, high
;
1619 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1621 highpc
= max (highpc
, high
);
1624 child_die
= sibling_die (child_die
);
1628 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1630 /* Set symtab language to language from DW_AT_language.
1631 If the compilation is from a C file generated by language preprocessors,
1632 do not set the language if it was already deduced by start_subfile. */
1634 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1636 symtab
->language
= cu_language
;
1638 pst
->symtab
= symtab
;
1640 sort_symtab_syms (pst
->symtab
);
1642 do_cleanups (back_to
);
1645 /* Process a die and its children. */
1648 process_die (struct die_info
*die
, struct objfile
*objfile
,
1649 const struct comp_unit_head
*cu_header
)
1653 case DW_TAG_padding
:
1655 case DW_TAG_compile_unit
:
1656 read_file_scope (die
, objfile
, cu_header
);
1658 case DW_TAG_subprogram
:
1659 read_subroutine_type (die
, objfile
, cu_header
);
1660 read_func_scope (die
, objfile
, cu_header
);
1662 case DW_TAG_inlined_subroutine
:
1663 /* FIXME: These are ignored for now.
1664 They could be used to set breakpoints on all inlined instances
1665 of a function and make GDB `next' properly over inlined functions. */
1667 case DW_TAG_lexical_block
:
1668 read_lexical_block_scope (die
, objfile
, cu_header
);
1670 case DW_TAG_class_type
:
1671 case DW_TAG_structure_type
:
1672 case DW_TAG_union_type
:
1673 read_structure_scope (die
, objfile
, cu_header
);
1675 case DW_TAG_enumeration_type
:
1676 read_enumeration (die
, objfile
, cu_header
);
1678 case DW_TAG_subroutine_type
:
1679 read_subroutine_type (die
, objfile
, cu_header
);
1681 case DW_TAG_array_type
:
1682 read_array_type (die
, objfile
, cu_header
);
1684 case DW_TAG_pointer_type
:
1685 read_tag_pointer_type (die
, objfile
, cu_header
);
1687 case DW_TAG_ptr_to_member_type
:
1688 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1690 case DW_TAG_reference_type
:
1691 read_tag_reference_type (die
, objfile
, cu_header
);
1693 case DW_TAG_string_type
:
1694 read_tag_string_type (die
, objfile
);
1696 case DW_TAG_base_type
:
1697 read_base_type (die
, objfile
);
1698 if (dwarf_attr (die
, DW_AT_name
))
1700 /* Add a typedef symbol for the base type definition. */
1701 new_symbol (die
, die
->type
, objfile
, cu_header
);
1704 case DW_TAG_common_block
:
1705 read_common_block (die
, objfile
, cu_header
);
1707 case DW_TAG_common_inclusion
:
1710 new_symbol (die
, NULL
, objfile
, cu_header
);
1716 initialize_cu_func_list (void)
1718 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1722 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1723 const struct comp_unit_head
*cu_header
)
1725 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1726 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1727 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1728 struct attribute
*attr
;
1729 char *name
= "<unknown>";
1730 char *comp_dir
= NULL
;
1731 struct die_info
*child_die
;
1732 bfd
*abfd
= objfile
->obfd
;
1733 struct line_header
*line_header
= 0;
1735 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1737 if (die
->has_children
)
1739 child_die
= die
->next
;
1740 while (child_die
&& child_die
->tag
)
1742 if (child_die
->tag
== DW_TAG_subprogram
)
1744 CORE_ADDR low
, high
;
1746 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1748 lowpc
= min (lowpc
, low
);
1749 highpc
= max (highpc
, high
);
1752 child_die
= sibling_die (child_die
);
1757 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1758 from finish_block. */
1759 if (lowpc
== ((CORE_ADDR
) -1))
1764 attr
= dwarf_attr (die
, DW_AT_name
);
1767 name
= DW_STRING (attr
);
1769 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1772 comp_dir
= DW_STRING (attr
);
1775 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1776 directory, get rid of it. */
1777 char *cp
= strchr (comp_dir
, ':');
1779 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1784 if (objfile
->ei
.entry_point
>= lowpc
&&
1785 objfile
->ei
.entry_point
< highpc
)
1787 objfile
->ei
.entry_file_lowpc
= lowpc
;
1788 objfile
->ei
.entry_file_highpc
= highpc
;
1791 attr
= dwarf_attr (die
, DW_AT_language
);
1794 set_cu_language (DW_UNSND (attr
));
1797 /* We assume that we're processing GCC output. */
1798 processing_gcc_compilation
= 2;
1800 /* FIXME:Do something here. */
1801 if (dip
->at_producer
!= NULL
)
1803 handle_producer (dip
->at_producer
);
1807 /* The compilation unit may be in a different language or objfile,
1808 zero out all remembered fundamental types. */
1809 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1811 start_symtab (name
, comp_dir
, lowpc
);
1812 record_debugformat ("DWARF 2");
1814 initialize_cu_func_list ();
1816 /* Process all dies in compilation unit. */
1817 if (die
->has_children
)
1819 child_die
= die
->next
;
1820 while (child_die
&& child_die
->tag
)
1822 process_die (child_die
, objfile
, cu_header
);
1823 child_die
= sibling_die (child_die
);
1827 /* Decode line number information if present. */
1828 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1831 unsigned int line_offset
= DW_UNSND (attr
);
1832 line_header
= dwarf_decode_line_header (line_offset
,
1836 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1837 (void *) line_header
);
1838 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1842 /* Decode macro information, if present. Dwarf 2 macro information
1843 refers to information in the line number info statement program
1844 header, so we can only read it if we've read the header
1846 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1847 if (attr
&& line_header
)
1849 unsigned int macro_offset
= DW_UNSND (attr
);
1850 dwarf_decode_macros (line_header
, macro_offset
,
1851 comp_dir
, abfd
, cu_header
, objfile
);
1853 do_cleanups (back_to
);
1857 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1859 struct function_range
*thisfn
;
1861 thisfn
= (struct function_range
*)
1862 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1863 thisfn
->name
= name
;
1864 thisfn
->lowpc
= lowpc
;
1865 thisfn
->highpc
= highpc
;
1866 thisfn
->seen_line
= 0;
1867 thisfn
->next
= NULL
;
1869 if (cu_last_fn
== NULL
)
1870 cu_first_fn
= thisfn
;
1872 cu_last_fn
->next
= thisfn
;
1874 cu_last_fn
= thisfn
;
1878 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1879 const struct comp_unit_head
*cu_header
)
1881 register struct context_stack
*new;
1884 struct die_info
*child_die
;
1885 struct attribute
*attr
;
1888 name
= dwarf2_linkage_name (die
);
1890 /* Ignore functions with missing or empty names and functions with
1891 missing or invalid low and high pc attributes. */
1892 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1898 /* Record the function range for dwarf_decode_lines. */
1899 add_to_cu_func_list (name
, lowpc
, highpc
);
1901 if (objfile
->ei
.entry_point
>= lowpc
&&
1902 objfile
->ei
.entry_point
< highpc
)
1904 objfile
->ei
.entry_func_lowpc
= lowpc
;
1905 objfile
->ei
.entry_func_highpc
= highpc
;
1908 /* Decode DW_AT_frame_base location descriptor if present, keep result
1909 for DW_OP_fbreg operands in decode_locdesc. */
1910 frame_base_reg
= -1;
1911 frame_base_offset
= 0;
1912 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1917 /* Support the .debug_loc offsets */
1918 if (attr_form_is_block (attr
))
1920 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1922 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
1924 complain (&dwarf2_complex_location_expr
);
1929 complain (&dwarf2_invalid_attrib_class
, "DW_AT_frame_base", name
);
1934 complain (&dwarf2_unsupported_at_frame_base
, name
);
1936 frame_base_reg
= addr
;
1939 frame_base_reg
= basereg
;
1940 frame_base_offset
= addr
;
1943 complain (&dwarf2_unsupported_at_frame_base
, name
);
1946 new = push_context (0, lowpc
);
1947 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1948 list_in_scope
= &local_symbols
;
1950 if (die
->has_children
)
1952 child_die
= die
->next
;
1953 while (child_die
&& child_die
->tag
)
1955 process_die (child_die
, objfile
, cu_header
);
1956 child_die
= sibling_die (child_die
);
1960 new = pop_context ();
1961 /* Make a block for the local symbols within. */
1962 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1963 lowpc
, highpc
, objfile
);
1964 list_in_scope
= &file_symbols
;
1967 /* Process all the DIES contained within a lexical block scope. Start
1968 a new scope, process the dies, and then close the scope. */
1971 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1972 const struct comp_unit_head
*cu_header
)
1974 register struct context_stack
*new;
1975 CORE_ADDR lowpc
, highpc
;
1976 struct die_info
*child_die
;
1978 /* Ignore blocks with missing or invalid low and high pc attributes. */
1979 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1984 push_context (0, lowpc
);
1985 if (die
->has_children
)
1987 child_die
= die
->next
;
1988 while (child_die
&& child_die
->tag
)
1990 process_die (child_die
, objfile
, cu_header
);
1991 child_die
= sibling_die (child_die
);
1994 new = pop_context ();
1996 if (local_symbols
!= NULL
)
1998 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2001 local_symbols
= new->locals
;
2004 /* Get low and high pc attributes from a die.
2005 Return 1 if the attributes are present and valid, otherwise, return 0. */
2008 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2009 struct objfile
*objfile
)
2011 struct attribute
*attr
;
2015 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2017 low
= DW_ADDR (attr
);
2020 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2022 high
= DW_ADDR (attr
);
2029 /* When using the GNU linker, .gnu.linkonce. sections are used to
2030 eliminate duplicate copies of functions and vtables and such.
2031 The linker will arbitrarily choose one and discard the others.
2032 The AT_*_pc values for such functions refer to local labels in
2033 these sections. If the section from that file was discarded, the
2034 labels are not in the output, so the relocs get a value of 0.
2035 If this is a discarded function, mark the pc bounds as invalid,
2036 so that GDB will ignore it. */
2037 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
2045 /* Add an aggregate field to the field list. */
2048 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2049 struct objfile
*objfile
,
2050 const struct comp_unit_head
*cu_header
)
2052 struct nextfield
*new_field
;
2053 struct attribute
*attr
;
2055 char *fieldname
= "";
2057 /* Allocate a new field list entry and link it in. */
2058 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2059 make_cleanup (xfree
, new_field
);
2060 memset (new_field
, 0, sizeof (struct nextfield
));
2061 new_field
->next
= fip
->fields
;
2062 fip
->fields
= new_field
;
2065 /* Handle accessibility and virtuality of field.
2066 The default accessibility for members is public, the default
2067 accessibility for inheritance is private. */
2068 if (die
->tag
!= DW_TAG_inheritance
)
2069 new_field
->accessibility
= DW_ACCESS_public
;
2071 new_field
->accessibility
= DW_ACCESS_private
;
2072 new_field
->virtuality
= DW_VIRTUALITY_none
;
2074 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2076 new_field
->accessibility
= DW_UNSND (attr
);
2077 if (new_field
->accessibility
!= DW_ACCESS_public
)
2078 fip
->non_public_fields
= 1;
2079 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2081 new_field
->virtuality
= DW_UNSND (attr
);
2083 fp
= &new_field
->field
;
2084 if (die
->tag
== DW_TAG_member
)
2086 /* Get type of field. */
2087 fp
->type
= die_type (die
, objfile
, cu_header
);
2089 /* Get bit size of field (zero if none). */
2090 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2093 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2097 FIELD_BITSIZE (*fp
) = 0;
2100 /* Get bit offset of field. */
2101 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2104 FIELD_BITPOS (*fp
) =
2105 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2108 FIELD_BITPOS (*fp
) = 0;
2109 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2112 if (BITS_BIG_ENDIAN
)
2114 /* For big endian bits, the DW_AT_bit_offset gives the
2115 additional bit offset from the MSB of the containing
2116 anonymous object to the MSB of the field. We don't
2117 have to do anything special since we don't need to
2118 know the size of the anonymous object. */
2119 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2123 /* For little endian bits, compute the bit offset to the
2124 MSB of the anonymous object, subtract off the number of
2125 bits from the MSB of the field to the MSB of the
2126 object, and then subtract off the number of bits of
2127 the field itself. The result is the bit offset of
2128 the LSB of the field. */
2130 int bit_offset
= DW_UNSND (attr
);
2132 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2135 /* The size of the anonymous object containing
2136 the bit field is explicit, so use the
2137 indicated size (in bytes). */
2138 anonymous_size
= DW_UNSND (attr
);
2142 /* The size of the anonymous object containing
2143 the bit field must be inferred from the type
2144 attribute of the data member containing the
2146 anonymous_size
= TYPE_LENGTH (fp
->type
);
2148 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2149 - bit_offset
- FIELD_BITSIZE (*fp
);
2153 /* Get name of field. */
2154 attr
= dwarf_attr (die
, DW_AT_name
);
2155 if (attr
&& DW_STRING (attr
))
2156 fieldname
= DW_STRING (attr
);
2157 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2158 &objfile
->type_obstack
);
2160 /* Change accessibility for artificial fields (e.g. virtual table
2161 pointer or virtual base class pointer) to private. */
2162 if (dwarf_attr (die
, DW_AT_artificial
))
2164 new_field
->accessibility
= DW_ACCESS_private
;
2165 fip
->non_public_fields
= 1;
2168 else if (die
->tag
== DW_TAG_variable
)
2172 /* C++ static member.
2173 Get name of field. */
2174 attr
= dwarf_attr (die
, DW_AT_name
);
2175 if (attr
&& DW_STRING (attr
))
2176 fieldname
= DW_STRING (attr
);
2180 /* Get physical name. */
2181 physname
= dwarf2_linkage_name (die
);
2183 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2184 &objfile
->type_obstack
));
2185 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2186 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2187 &objfile
->type_obstack
);
2189 else if (die
->tag
== DW_TAG_inheritance
)
2191 /* C++ base class field. */
2192 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2194 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2196 FIELD_BITSIZE (*fp
) = 0;
2197 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2198 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2199 fip
->nbaseclasses
++;
2203 /* Create the vector of fields, and attach it to the type. */
2206 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2207 struct objfile
*objfile
)
2209 int nfields
= fip
->nfields
;
2211 /* Record the field count, allocate space for the array of fields,
2212 and create blank accessibility bitfields if necessary. */
2213 TYPE_NFIELDS (type
) = nfields
;
2214 TYPE_FIELDS (type
) = (struct field
*)
2215 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2216 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2218 if (fip
->non_public_fields
)
2220 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2222 TYPE_FIELD_PRIVATE_BITS (type
) =
2223 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2224 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2226 TYPE_FIELD_PROTECTED_BITS (type
) =
2227 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2228 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2230 TYPE_FIELD_IGNORE_BITS (type
) =
2231 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2232 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2235 /* If the type has baseclasses, allocate and clear a bit vector for
2236 TYPE_FIELD_VIRTUAL_BITS. */
2237 if (fip
->nbaseclasses
)
2239 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2242 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2243 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2244 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2245 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2246 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2249 /* Copy the saved-up fields into the field vector. Start from the head
2250 of the list, adding to the tail of the field array, so that they end
2251 up in the same order in the array in which they were added to the list. */
2252 while (nfields
-- > 0)
2254 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2255 switch (fip
->fields
->accessibility
)
2257 case DW_ACCESS_private
:
2258 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2261 case DW_ACCESS_protected
:
2262 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2265 case DW_ACCESS_public
:
2269 /* Unknown accessibility. Complain and treat it as public. */
2271 complain (&dwarf2_unsupported_accessibility
,
2272 fip
->fields
->accessibility
);
2276 if (nfields
< fip
->nbaseclasses
)
2278 switch (fip
->fields
->virtuality
)
2280 case DW_VIRTUALITY_virtual
:
2281 case DW_VIRTUALITY_pure_virtual
:
2282 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2286 fip
->fields
= fip
->fields
->next
;
2290 /* Add a member function to the proper fieldlist. */
2293 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2294 struct type
*type
, struct objfile
*objfile
,
2295 const struct comp_unit_head
*cu_header
)
2297 struct attribute
*attr
;
2298 struct fnfieldlist
*flp
;
2300 struct fn_field
*fnp
;
2303 struct nextfnfield
*new_fnfield
;
2305 /* Get name of member function. */
2306 attr
= dwarf_attr (die
, DW_AT_name
);
2307 if (attr
&& DW_STRING (attr
))
2308 fieldname
= DW_STRING (attr
);
2312 /* Get the mangled name. */
2313 physname
= dwarf2_linkage_name (die
);
2315 /* Look up member function name in fieldlist. */
2316 for (i
= 0; i
< fip
->nfnfields
; i
++)
2318 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2322 /* Create new list element if necessary. */
2323 if (i
< fip
->nfnfields
)
2324 flp
= &fip
->fnfieldlists
[i
];
2327 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2329 fip
->fnfieldlists
= (struct fnfieldlist
*)
2330 xrealloc (fip
->fnfieldlists
,
2331 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2332 * sizeof (struct fnfieldlist
));
2333 if (fip
->nfnfields
== 0)
2334 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2336 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2337 flp
->name
= fieldname
;
2343 /* Create a new member function field and chain it to the field list
2345 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2346 make_cleanup (xfree
, new_fnfield
);
2347 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2348 new_fnfield
->next
= flp
->head
;
2349 flp
->head
= new_fnfield
;
2352 /* Fill in the member function field info. */
2353 fnp
= &new_fnfield
->fnfield
;
2354 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2355 &objfile
->type_obstack
);
2356 fnp
->type
= alloc_type (objfile
);
2357 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2359 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2360 int nparams
= TYPE_NFIELDS (die
->type
);
2362 /* TYPE is the domain of this method, and DIE->TYPE is the type
2363 of the method itself (TYPE_CODE_METHOD). */
2364 smash_to_method_type (fnp
->type
, type
,
2365 TYPE_TARGET_TYPE (die
->type
),
2366 TYPE_FIELDS (die
->type
),
2367 TYPE_NFIELDS (die
->type
),
2368 TYPE_VARARGS (die
->type
));
2370 /* Handle static member functions.
2371 Dwarf2 has no clean way to discern C++ static and non-static
2372 member functions. G++ helps GDB by marking the first
2373 parameter for non-static member functions (which is the
2374 this pointer) as artificial. We obtain this information
2375 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2376 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2377 fnp
->voffset
= VOFFSET_STATIC
;
2380 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2382 /* Get fcontext from DW_AT_containing_type if present. */
2383 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2384 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2386 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2387 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2389 /* Get accessibility. */
2390 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2393 switch (DW_UNSND (attr
))
2395 case DW_ACCESS_private
:
2396 fnp
->is_private
= 1;
2398 case DW_ACCESS_protected
:
2399 fnp
->is_protected
= 1;
2404 /* Check for artificial methods. */
2405 attr
= dwarf_attr (die
, DW_AT_artificial
);
2406 if (attr
&& DW_UNSND (attr
) != 0)
2407 fnp
->is_artificial
= 1;
2409 /* Get index in virtual function table if it is a virtual member function. */
2410 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2413 /* Support the .debug_loc offsets */
2414 if (attr_form_is_block (attr
))
2416 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2418 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2420 complain (&dwarf2_complex_location_expr
);
2424 complain (&dwarf2_invalid_attrib_class
, "DW_AT_vtable_elem_location",
2430 /* Create the vector of member function fields, and attach it to the type. */
2433 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2434 struct objfile
*objfile
)
2436 struct fnfieldlist
*flp
;
2437 int total_length
= 0;
2440 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2441 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2442 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2444 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2446 struct nextfnfield
*nfp
= flp
->head
;
2447 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2450 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2451 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2452 fn_flp
->fn_fields
= (struct fn_field
*)
2453 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2454 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2455 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2457 total_length
+= flp
->length
;
2460 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2461 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2464 /* Called when we find the DIE that starts a structure or union scope
2465 (definition) to process all dies that define the members of the
2468 NOTE: we need to call struct_type regardless of whether or not the
2469 DIE has an at_name attribute, since it might be an anonymous
2470 structure or union. This gets the type entered into our set of
2473 However, if the structure is incomplete (an opaque struct/union)
2474 then suppress creating a symbol table entry for it since gdb only
2475 wants to find the one with the complete definition. Note that if
2476 it is complete, we just call new_symbol, which does it's own
2477 checking about whether the struct/union is anonymous or not (and
2478 suppresses creating a symbol table entry itself). */
2481 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2482 const struct comp_unit_head
*cu_header
)
2485 struct attribute
*attr
;
2487 type
= alloc_type (objfile
);
2489 INIT_CPLUS_SPECIFIC (type
);
2490 attr
= dwarf_attr (die
, DW_AT_name
);
2491 if (attr
&& DW_STRING (attr
))
2493 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2494 strlen (DW_STRING (attr
)),
2495 &objfile
->type_obstack
);
2498 if (die
->tag
== DW_TAG_structure_type
)
2500 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2502 else if (die
->tag
== DW_TAG_union_type
)
2504 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2508 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2510 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2513 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2516 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2520 TYPE_LENGTH (type
) = 0;
2523 /* We need to add the type field to the die immediately so we don't
2524 infinitely recurse when dealing with pointers to the structure
2525 type within the structure itself. */
2528 if (die
->has_children
&& ! die_is_declaration (die
))
2530 struct field_info fi
;
2531 struct die_info
*child_die
;
2532 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2534 memset (&fi
, 0, sizeof (struct field_info
));
2536 child_die
= die
->next
;
2538 while (child_die
&& child_die
->tag
)
2540 if (child_die
->tag
== DW_TAG_member
)
2542 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2544 else if (child_die
->tag
== DW_TAG_variable
)
2546 /* C++ static member. */
2547 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2549 else if (child_die
->tag
== DW_TAG_subprogram
)
2551 /* C++ member function. */
2552 process_die (child_die
, objfile
, cu_header
);
2553 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2555 else if (child_die
->tag
== DW_TAG_inheritance
)
2557 /* C++ base class field. */
2558 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2562 process_die (child_die
, objfile
, cu_header
);
2564 child_die
= sibling_die (child_die
);
2567 /* Attach fields and member functions to the type. */
2569 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2572 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2574 /* Get the type which refers to the base class (possibly this
2575 class itself) which contains the vtable pointer for the current
2576 class from the DW_AT_containing_type attribute. */
2578 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2580 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2582 TYPE_VPTR_BASETYPE (type
) = t
;
2585 static const char vptr_name
[] =
2586 {'_', 'v', 'p', 't', 'r', '\0'};
2589 /* Our own class provides vtbl ptr. */
2590 for (i
= TYPE_NFIELDS (t
) - 1;
2591 i
>= TYPE_N_BASECLASSES (t
);
2594 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2596 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2597 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2599 TYPE_VPTR_FIELDNO (type
) = i
;
2604 /* Complain if virtual function table field not found. */
2605 if (i
< TYPE_N_BASECLASSES (t
))
2606 complain (&dwarf2_vtbl_not_found_complaint
,
2607 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2611 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2616 new_symbol (die
, type
, objfile
, cu_header
);
2618 do_cleanups (back_to
);
2622 /* No children, must be stub. */
2623 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2627 /* Given a pointer to a die which begins an enumeration, process all
2628 the dies that define the members of the enumeration.
2630 This will be much nicer in draft 6 of the DWARF spec when our
2631 members will be dies instead squished into the DW_AT_element_list
2634 NOTE: We reverse the order of the element list. */
2637 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2638 const struct comp_unit_head
*cu_header
)
2640 struct die_info
*child_die
;
2642 struct field
*fields
;
2643 struct attribute
*attr
;
2646 int unsigned_enum
= 1;
2648 type
= alloc_type (objfile
);
2650 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2651 attr
= dwarf_attr (die
, DW_AT_name
);
2652 if (attr
&& DW_STRING (attr
))
2654 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2655 strlen (DW_STRING (attr
)),
2656 &objfile
->type_obstack
);
2659 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2662 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2666 TYPE_LENGTH (type
) = 0;
2671 if (die
->has_children
)
2673 child_die
= die
->next
;
2674 while (child_die
&& child_die
->tag
)
2676 if (child_die
->tag
!= DW_TAG_enumerator
)
2678 process_die (child_die
, objfile
, cu_header
);
2682 attr
= dwarf_attr (child_die
, DW_AT_name
);
2685 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2686 if (SYMBOL_VALUE (sym
) < 0)
2689 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2691 fields
= (struct field
*)
2693 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2694 * sizeof (struct field
));
2697 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2698 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2699 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2700 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2706 child_die
= sibling_die (child_die
);
2711 TYPE_NFIELDS (type
) = num_fields
;
2712 TYPE_FIELDS (type
) = (struct field
*)
2713 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2714 memcpy (TYPE_FIELDS (type
), fields
,
2715 sizeof (struct field
) * num_fields
);
2719 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2722 new_symbol (die
, type
, objfile
, cu_header
);
2725 /* Extract all information from a DW_TAG_array_type DIE and put it in
2726 the DIE's type field. For now, this only handles one dimensional
2730 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2731 const struct comp_unit_head
*cu_header
)
2733 struct die_info
*child_die
;
2734 struct type
*type
= NULL
;
2735 struct type
*element_type
, *range_type
, *index_type
;
2736 struct type
**range_types
= NULL
;
2737 struct attribute
*attr
;
2739 struct cleanup
*back_to
;
2741 /* Return if we've already decoded this type. */
2747 element_type
= die_type (die
, objfile
, cu_header
);
2749 /* Irix 6.2 native cc creates array types without children for
2750 arrays with unspecified length. */
2751 if (die
->has_children
== 0)
2753 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2754 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2755 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2759 back_to
= make_cleanup (null_cleanup
, NULL
);
2760 child_die
= die
->next
;
2761 while (child_die
&& child_die
->tag
)
2763 if (child_die
->tag
== DW_TAG_subrange_type
)
2765 unsigned int low
, high
;
2767 /* Default bounds to an array with unspecified length. */
2770 if (cu_language
== language_fortran
)
2772 /* FORTRAN implies a lower bound of 1, if not given. */
2776 index_type
= die_type (child_die
, objfile
, cu_header
);
2777 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2780 if (attr
->form
== DW_FORM_sdata
)
2782 low
= DW_SND (attr
);
2784 else if (attr
->form
== DW_FORM_udata
2785 || attr
->form
== DW_FORM_data1
2786 || attr
->form
== DW_FORM_data2
2787 || attr
->form
== DW_FORM_data4
2788 || attr
->form
== DW_FORM_data8
)
2790 low
= DW_UNSND (attr
);
2794 complain (&dwarf2_non_const_array_bound_ignored
,
2795 dwarf_form_name (attr
->form
));
2797 die
->type
= lookup_pointer_type (element_type
);
2804 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2807 if (attr
->form
== DW_FORM_sdata
)
2809 high
= DW_SND (attr
);
2811 else if (attr
->form
== DW_FORM_udata
2812 || attr
->form
== DW_FORM_data1
2813 || attr
->form
== DW_FORM_data2
2814 || attr
->form
== DW_FORM_data4
2815 || attr
->form
== DW_FORM_data8
)
2817 high
= DW_UNSND (attr
);
2819 else if (attr
->form
== DW_FORM_block1
)
2821 /* GCC encodes arrays with unspecified or dynamic length
2822 with a DW_FORM_block1 attribute.
2823 FIXME: GDB does not yet know how to handle dynamic
2824 arrays properly, treat them as arrays with unspecified
2830 complain (&dwarf2_non_const_array_bound_ignored
,
2831 dwarf_form_name (attr
->form
));
2833 die
->type
= lookup_pointer_type (element_type
);
2841 /* Create a range type and save it for array type creation. */
2842 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2844 range_types
= (struct type
**)
2845 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2846 * sizeof (struct type
*));
2848 make_cleanup (free_current_contents
, &range_types
);
2850 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2852 child_die
= sibling_die (child_die
);
2855 /* Dwarf2 dimensions are output from left to right, create the
2856 necessary array types in backwards order. */
2857 type
= element_type
;
2859 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2861 /* Understand Dwarf2 support for vector types (like they occur on
2862 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
2863 array type. This is not part of the Dwarf2/3 standard yet, but a
2864 custom vendor extension. The main difference between a regular
2865 array and the vector variant is that vectors are passed by value
2867 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
2869 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
2871 do_cleanups (back_to
);
2873 /* Install the type in the die. */
2877 /* First cut: install each common block member as a global variable. */
2880 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2881 const struct comp_unit_head
*cu_header
)
2883 struct die_info
*child_die
;
2884 struct attribute
*attr
;
2886 CORE_ADDR base
= (CORE_ADDR
) 0;
2888 attr
= dwarf_attr (die
, DW_AT_location
);
2891 /* Support the .debug_loc offsets */
2892 if (attr_form_is_block (attr
))
2894 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2896 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2898 complain (&dwarf2_complex_location_expr
);
2902 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
2903 "common block member");
2906 if (die
->has_children
)
2908 child_die
= die
->next
;
2909 while (child_die
&& child_die
->tag
)
2911 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2912 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2915 SYMBOL_VALUE_ADDRESS (sym
) =
2916 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2917 add_symbol_to_list (sym
, &global_symbols
);
2919 child_die
= sibling_die (child_die
);
2924 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2925 the user defined type vector. */
2928 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2929 const struct comp_unit_head
*cu_header
)
2932 struct attribute
*attr_byte_size
;
2933 struct attribute
*attr_address_class
;
2934 int byte_size
, addr_class
;
2941 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2943 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
2945 byte_size
= DW_UNSND (attr_byte_size
);
2947 byte_size
= cu_header
->addr_size
;
2949 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
2950 if (attr_address_class
)
2951 addr_class
= DW_UNSND (attr_address_class
);
2953 addr_class
= DW_ADDR_none
;
2955 /* If the pointer size or address class is different than the
2956 default, create a type variant marked as such and set the
2957 length accordingly. */
2958 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
2960 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
2964 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
2965 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
2966 type
= make_type_with_address_space (type
, type_flags
);
2968 else if (TYPE_LENGTH (type
) != byte_size
)
2970 complain (&dwarf2_invalid_pointer_size
, byte_size
);
2973 /* Should we also complain about unhandled address classes? */
2977 TYPE_LENGTH (type
) = byte_size
;
2981 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2982 the user defined type vector. */
2985 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2986 const struct comp_unit_head
*cu_header
)
2989 struct type
*to_type
;
2990 struct type
*domain
;
2997 type
= alloc_type (objfile
);
2998 to_type
= die_type (die
, objfile
, cu_header
);
2999 domain
= die_containing_type (die
, objfile
, cu_header
);
3000 smash_to_member_type (type
, domain
, to_type
);
3005 /* Extract all information from a DW_TAG_reference_type DIE and add to
3006 the user defined type vector. */
3009 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
3010 const struct comp_unit_head
*cu_header
)
3013 struct attribute
*attr
;
3020 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
3021 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3024 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3028 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3034 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
3035 const struct comp_unit_head
*cu_header
)
3037 struct type
*base_type
;
3044 base_type
= die_type (die
, objfile
, cu_header
);
3045 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3049 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
3050 const struct comp_unit_head
*cu_header
)
3052 struct type
*base_type
;
3059 base_type
= die_type (die
, objfile
, cu_header
);
3060 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3063 /* Extract all information from a DW_TAG_string_type DIE and add to
3064 the user defined type vector. It isn't really a user defined type,
3065 but it behaves like one, with other DIE's using an AT_user_def_type
3066 attribute to reference it. */
3069 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3071 struct type
*type
, *range_type
, *index_type
, *char_type
;
3072 struct attribute
*attr
;
3073 unsigned int length
;
3080 attr
= dwarf_attr (die
, DW_AT_string_length
);
3083 length
= DW_UNSND (attr
);
3087 /* check for the DW_AT_byte_size attribute */
3088 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3091 length
= DW_UNSND (attr
);
3098 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3099 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3100 if (cu_language
== language_fortran
)
3102 /* Need to create a unique string type for bounds
3104 type
= create_string_type (0, range_type
);
3108 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3109 type
= create_string_type (char_type
, range_type
);
3114 /* Handle DIES due to C code like:
3118 int (*funcp)(int a, long l);
3122 ('funcp' generates a DW_TAG_subroutine_type DIE)
3126 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3127 const struct comp_unit_head
*cu_header
)
3129 struct type
*type
; /* Type that this function returns */
3130 struct type
*ftype
; /* Function that returns above type */
3131 struct attribute
*attr
;
3133 /* Decode the type that this subroutine returns */
3138 type
= die_type (die
, objfile
, cu_header
);
3139 ftype
= lookup_function_type (type
);
3141 /* All functions in C++ have prototypes. */
3142 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3143 if ((attr
&& (DW_UNSND (attr
) != 0))
3144 || cu_language
== language_cplus
)
3145 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3147 if (die
->has_children
)
3149 struct die_info
*child_die
;
3153 /* Count the number of parameters.
3154 FIXME: GDB currently ignores vararg functions, but knows about
3155 vararg member functions. */
3156 child_die
= die
->next
;
3157 while (child_die
&& child_die
->tag
)
3159 if (child_die
->tag
== DW_TAG_formal_parameter
)
3161 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3162 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3163 child_die
= sibling_die (child_die
);
3166 /* Allocate storage for parameters and fill them in. */
3167 TYPE_NFIELDS (ftype
) = nparams
;
3168 TYPE_FIELDS (ftype
) = (struct field
*)
3169 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3171 child_die
= die
->next
;
3172 while (child_die
&& child_die
->tag
)
3174 if (child_die
->tag
== DW_TAG_formal_parameter
)
3176 /* Dwarf2 has no clean way to discern C++ static and non-static
3177 member functions. G++ helps GDB by marking the first
3178 parameter for non-static member functions (which is the
3179 this pointer) as artificial. We pass this information
3180 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3181 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3183 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3185 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3186 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3190 child_die
= sibling_die (child_die
);
3198 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3199 const struct comp_unit_head
*cu_header
)
3201 struct attribute
*attr
;
3206 attr
= dwarf_attr (die
, DW_AT_name
);
3207 if (attr
&& DW_STRING (attr
))
3209 name
= DW_STRING (attr
);
3211 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3212 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3216 /* Find a representation of a given base type and install
3217 it in the TYPE field of the die. */
3220 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3223 struct attribute
*attr
;
3224 int encoding
= 0, size
= 0;
3226 /* If we've already decoded this die, this is a no-op. */
3232 attr
= dwarf_attr (die
, DW_AT_encoding
);
3235 encoding
= DW_UNSND (attr
);
3237 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3240 size
= DW_UNSND (attr
);
3242 attr
= dwarf_attr (die
, DW_AT_name
);
3243 if (attr
&& DW_STRING (attr
))
3245 enum type_code code
= TYPE_CODE_INT
;
3250 case DW_ATE_address
:
3251 /* Turn DW_ATE_address into a void * pointer. */
3252 code
= TYPE_CODE_PTR
;
3253 type_flags
|= TYPE_FLAG_UNSIGNED
;
3255 case DW_ATE_boolean
:
3256 code
= TYPE_CODE_BOOL
;
3257 type_flags
|= TYPE_FLAG_UNSIGNED
;
3259 case DW_ATE_complex_float
:
3260 code
= TYPE_CODE_COMPLEX
;
3263 code
= TYPE_CODE_FLT
;
3266 case DW_ATE_signed_char
:
3268 case DW_ATE_unsigned
:
3269 case DW_ATE_unsigned_char
:
3270 type_flags
|= TYPE_FLAG_UNSIGNED
;
3273 complain (&dwarf2_unsupported_at_encoding
,
3274 dwarf_type_encoding_name (encoding
));
3277 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3278 if (encoding
== DW_ATE_address
)
3279 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3280 else if (encoding
== DW_ATE_complex_float
)
3283 TYPE_TARGET_TYPE (type
)
3284 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3285 else if (size
== 16)
3286 TYPE_TARGET_TYPE (type
)
3287 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3289 TYPE_TARGET_TYPE (type
)
3290 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3295 type
= dwarf_base_type (encoding
, size
, objfile
);
3300 /* Read a whole compilation unit into a linked list of dies. */
3302 static struct die_info
*
3303 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3304 const struct comp_unit_head
*cu_header
)
3306 struct die_info
*first_die
, *last_die
, *die
;
3310 /* Reset die reference table; we are
3311 building new ones now. */
3312 dwarf2_empty_hash_tables ();
3316 first_die
= last_die
= NULL
;
3319 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3320 if (die
->has_children
)
3331 /* Enter die in reference hash table */
3332 store_in_ref_table (die
->offset
, die
);
3336 first_die
= last_die
= die
;
3340 last_die
->next
= die
;
3344 while (nesting_level
> 0);
3348 /* Free a linked list of dies. */
3351 free_die_list (struct die_info
*dies
)
3353 struct die_info
*die
, *next
;
3366 do_free_die_list_cleanup (void *dies
)
3368 free_die_list (dies
);
3371 static struct cleanup
*
3372 make_cleanup_free_die_list (struct die_info
*dies
)
3374 return make_cleanup (do_free_die_list_cleanup
, dies
);
3378 /* Read the contents of the section at OFFSET and of size SIZE from the
3379 object file specified by OBJFILE into the psymbol_obstack and return it. */
3382 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3385 bfd
*abfd
= objfile
->obfd
;
3391 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3392 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3393 (bfd_bread (buf
, size
, abfd
) != size
))
3396 error ("Dwarf Error: Can't read DWARF data from '%s'",
3397 bfd_get_filename (abfd
));
3402 /* In DWARF version 2, the description of the debugging information is
3403 stored in a separate .debug_abbrev section. Before we read any
3404 dies from a section we read in all abbreviations and install them
3408 dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
)
3411 struct abbrev_info
*cur_abbrev
;
3412 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3413 unsigned int abbrev_form
, hash_number
;
3415 /* Initialize dwarf2 abbrevs */
3416 memset (cu_header
->dwarf2_abbrevs
, 0,
3417 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3419 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3420 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3421 abbrev_ptr
+= bytes_read
;
3423 /* loop until we reach an abbrev number of 0 */
3424 while (abbrev_number
)
3426 cur_abbrev
= dwarf_alloc_abbrev ();
3428 /* read in abbrev header */
3429 cur_abbrev
->number
= abbrev_number
;
3430 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3431 abbrev_ptr
+= bytes_read
;
3432 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3435 /* now read in declarations */
3436 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3437 abbrev_ptr
+= bytes_read
;
3438 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3439 abbrev_ptr
+= bytes_read
;
3442 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3444 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3445 xrealloc (cur_abbrev
->attrs
,
3446 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3447 * sizeof (struct attr_abbrev
));
3449 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3450 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3451 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3452 abbrev_ptr
+= bytes_read
;
3453 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3454 abbrev_ptr
+= bytes_read
;
3457 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3458 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3459 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3461 /* Get next abbreviation.
3462 Under Irix6 the abbreviations for a compilation unit are not
3463 always properly terminated with an abbrev number of 0.
3464 Exit loop if we encounter an abbreviation which we have
3465 already read (which means we are about to read the abbreviations
3466 for the next compile unit) or if the end of the abbreviation
3467 table is reached. */
3468 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3469 >= dwarf_abbrev_size
)
3471 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3472 abbrev_ptr
+= bytes_read
;
3473 if (dwarf2_lookup_abbrev (abbrev_number
, cu_header
) != NULL
)
3478 /* Empty the abbrev table for a new compilation unit. */
3482 dwarf2_empty_abbrev_table (PTR ptr_to_abbrevs_table
)
3485 struct abbrev_info
*abbrev
, *next
;
3486 struct abbrev_info
**abbrevs
;
3488 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3490 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3493 abbrev
= abbrevs
[i
];
3496 next
= abbrev
->next
;
3497 xfree (abbrev
->attrs
);
3505 /* Lookup an abbrev_info structure in the abbrev hash table. */
3507 static struct abbrev_info
*
3508 dwarf2_lookup_abbrev (unsigned int number
, const struct comp_unit_head
*cu_header
)
3510 unsigned int hash_number
;
3511 struct abbrev_info
*abbrev
;
3513 hash_number
= number
% ABBREV_HASH_SIZE
;
3514 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3518 if (abbrev
->number
== number
)
3521 abbrev
= abbrev
->next
;
3526 /* Read a minimal amount of information into the minimal die structure. */
3529 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3530 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3532 unsigned int abbrev_number
, bytes_read
, i
;
3533 struct abbrev_info
*abbrev
;
3534 struct attribute attr
;
3535 struct attribute spec_attr
;
3536 int found_spec_attr
= 0;
3537 int has_low_pc_attr
= 0;
3538 int has_high_pc_attr
= 0;
3540 *part_die
= zeroed_partial_die
;
3541 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3542 info_ptr
+= bytes_read
;
3546 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3549 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3551 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3552 part_die
->tag
= abbrev
->tag
;
3553 part_die
->has_children
= abbrev
->has_children
;
3554 part_die
->abbrev
= abbrev_number
;
3556 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3558 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3559 info_ptr
, cu_header
);
3561 /* Store the data if it is of an attribute we want to keep in a
3562 partial symbol table. */
3567 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3568 if (part_die
->name
== NULL
)
3569 part_die
->name
= DW_STRING (&attr
);
3571 case DW_AT_MIPS_linkage_name
:
3572 part_die
->name
= DW_STRING (&attr
);
3575 has_low_pc_attr
= 1;
3576 part_die
->lowpc
= DW_ADDR (&attr
);
3579 has_high_pc_attr
= 1;
3580 part_die
->highpc
= DW_ADDR (&attr
);
3582 case DW_AT_location
:
3583 /* Support the .debug_loc offsets */
3584 if (attr_form_is_block (&attr
))
3586 part_die
->locdesc
= DW_BLOCK (&attr
);
3588 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
3590 complain (&dwarf2_complex_location_expr
);
3594 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
3595 "partial symbol information");
3598 case DW_AT_language
:
3599 part_die
->language
= DW_UNSND (&attr
);
3601 case DW_AT_external
:
3602 part_die
->is_external
= DW_UNSND (&attr
);
3604 case DW_AT_declaration
:
3605 part_die
->is_declaration
= DW_UNSND (&attr
);
3608 part_die
->has_type
= 1;
3610 case DW_AT_abstract_origin
:
3611 case DW_AT_specification
:
3612 found_spec_attr
= 1;
3616 /* Ignore absolute siblings, they might point outside of
3617 the current compile unit. */
3618 if (attr
.form
== DW_FORM_ref_addr
)
3619 complain (&dwarf2_absolute_sibling_complaint
);
3622 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3629 /* If we found a reference attribute and the die has no name, try
3630 to find a name in the referred to die. */
3632 if (found_spec_attr
&& part_die
->name
== NULL
)
3634 struct partial_die_info spec_die
;
3638 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3639 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3642 part_die
->name
= spec_die
.name
;
3644 /* Copy DW_AT_external attribute if it is set. */
3645 if (spec_die
.is_external
)
3646 part_die
->is_external
= spec_die
.is_external
;
3650 /* When using the GNU linker, .gnu.linkonce. sections are used to
3651 eliminate duplicate copies of functions and vtables and such.
3652 The linker will arbitrarily choose one and discard the others.
3653 The AT_*_pc values for such functions refer to local labels in
3654 these sections. If the section from that file was discarded, the
3655 labels are not in the output, so the relocs get a value of 0.
3656 If this is a discarded function, mark the pc bounds as invalid,
3657 so that GDB will ignore it. */
3658 if (has_low_pc_attr
&& has_high_pc_attr
3659 && part_die
->lowpc
< part_die
->highpc
3660 && (part_die
->lowpc
!= 0
3661 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3662 part_die
->has_pc_info
= 1;
3666 /* Read the die from the .debug_info section buffer. And set diep to
3667 point to a newly allocated die with its information. */
3670 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3671 const struct comp_unit_head
*cu_header
)
3673 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3674 struct abbrev_info
*abbrev
;
3675 struct die_info
*die
;
3677 offset
= info_ptr
- dwarf_info_buffer
;
3678 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3679 info_ptr
+= bytes_read
;
3682 die
= dwarf_alloc_die ();
3684 die
->abbrev
= abbrev_number
;
3690 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3693 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3695 die
= dwarf_alloc_die ();
3696 die
->offset
= offset
;
3697 die
->tag
= abbrev
->tag
;
3698 die
->has_children
= abbrev
->has_children
;
3699 die
->abbrev
= abbrev_number
;
3702 die
->num_attrs
= abbrev
->num_attrs
;
3703 die
->attrs
= (struct attribute
*)
3704 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3706 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3708 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3709 abfd
, info_ptr
, cu_header
);
3716 /* Read an attribute value described by an attribute form. */
3719 read_attribute_value (struct attribute
*attr
, unsigned form
,
3720 bfd
*abfd
, char *info_ptr
,
3721 const struct comp_unit_head
*cu_header
)
3723 unsigned int bytes_read
;
3724 struct dwarf_block
*blk
;
3730 case DW_FORM_ref_addr
:
3731 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3732 info_ptr
+= bytes_read
;
3734 case DW_FORM_block2
:
3735 blk
= dwarf_alloc_block ();
3736 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3738 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3739 info_ptr
+= blk
->size
;
3740 DW_BLOCK (attr
) = blk
;
3742 case DW_FORM_block4
:
3743 blk
= dwarf_alloc_block ();
3744 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3746 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3747 info_ptr
+= blk
->size
;
3748 DW_BLOCK (attr
) = blk
;
3751 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3755 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3759 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3762 case DW_FORM_string
:
3763 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3764 info_ptr
+= bytes_read
;
3767 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3769 info_ptr
+= bytes_read
;
3772 blk
= dwarf_alloc_block ();
3773 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3774 info_ptr
+= bytes_read
;
3775 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3776 info_ptr
+= blk
->size
;
3777 DW_BLOCK (attr
) = blk
;
3779 case DW_FORM_block1
:
3780 blk
= dwarf_alloc_block ();
3781 blk
->size
= read_1_byte (abfd
, info_ptr
);
3783 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3784 info_ptr
+= blk
->size
;
3785 DW_BLOCK (attr
) = blk
;
3788 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3792 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3796 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3797 info_ptr
+= bytes_read
;
3800 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3801 info_ptr
+= bytes_read
;
3804 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3808 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3812 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3816 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3819 case DW_FORM_ref_udata
:
3820 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3821 info_ptr
+= bytes_read
;
3823 case DW_FORM_indirect
:
3824 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3825 info_ptr
+= bytes_read
;
3826 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
3829 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3830 dwarf_form_name (form
));
3835 /* Read an attribute described by an abbreviated attribute. */
3838 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3839 bfd
*abfd
, char *info_ptr
,
3840 const struct comp_unit_head
*cu_header
)
3842 attr
->name
= abbrev
->name
;
3843 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
3846 /* read dwarf information from a buffer */
3849 read_1_byte (bfd
*abfd
, char *buf
)
3851 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3855 read_1_signed_byte (bfd
*abfd
, char *buf
)
3857 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3861 read_2_bytes (bfd
*abfd
, char *buf
)
3863 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3867 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3869 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3873 read_4_bytes (bfd
*abfd
, char *buf
)
3875 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3879 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3881 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3884 static unsigned long
3885 read_8_bytes (bfd
*abfd
, char *buf
)
3887 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3891 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3894 CORE_ADDR retval
= 0;
3896 if (cu_header
->signed_addr_p
)
3898 switch (cu_header
->addr_size
)
3901 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3904 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3907 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3910 internal_error (__FILE__
, __LINE__
,
3911 "read_address: bad switch, signed");
3916 switch (cu_header
->addr_size
)
3919 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3922 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3925 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3928 internal_error (__FILE__
, __LINE__
,
3929 "read_address: bad switch, unsigned");
3933 *bytes_read
= cu_header
->addr_size
;
3937 /* Read the initial length from a section. The (draft) DWARF 3
3938 specification allows the initial length to take up either 4 bytes
3939 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3940 bytes describe the length and all offsets will be 8 bytes in length
3943 An older, non-standard 64-bit format is also handled by this
3944 function. The older format in question stores the initial length
3945 as an 8-byte quantity without an escape value. Lengths greater
3946 than 2^32 aren't very common which means that the initial 4 bytes
3947 is almost always zero. Since a length value of zero doesn't make
3948 sense for the 32-bit format, this initial zero can be considered to
3949 be an escape value which indicates the presence of the older 64-bit
3950 format. As written, the code can't detect (old format) lengths
3951 greater than 4GB. If it becomes necessary to handle lengths somewhat
3952 larger than 4GB, we could allow other small values (such as the
3953 non-sensical values of 1, 2, and 3) to also be used as escape values
3954 indicating the presence of the old format.
3956 The value returned via bytes_read should be used to increment
3957 the relevant pointer after calling read_initial_length().
3959 As a side effect, this function sets the fields initial_length_size
3960 and offset_size in cu_header to the values appropriate for the
3961 length field. (The format of the initial length field determines
3962 the width of file offsets to be fetched later with fetch_offset().)
3964 [ Note: read_initial_length() and read_offset() are based on the
3965 document entitled "DWARF Debugging Information Format", revision
3966 3, draft 8, dated November 19, 2001. This document was obtained
3969 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
3971 This document is only a draft and is subject to change. (So beware.)
3973 Details regarding the older, non-standard 64-bit format were
3974 determined empirically by examining 64-bit ELF files produced
3975 by the SGI toolchain on an IRIX 6.5 machine.
3977 - Kevin, July 16, 2002
3981 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3986 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3988 if (retval
== 0xffffffff)
3990 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3992 if (cu_header
!= NULL
)
3994 cu_header
->initial_length_size
= 12;
3995 cu_header
->offset_size
= 8;
3998 else if (retval
== 0)
4000 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4002 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4004 if (cu_header
!= NULL
)
4006 cu_header
->initial_length_size
= 8;
4007 cu_header
->offset_size
= 8;
4013 if (cu_header
!= NULL
)
4015 cu_header
->initial_length_size
= 4;
4016 cu_header
->offset_size
= 4;
4023 /* Read an offset from the data stream. The size of the offset is
4024 given by cu_header->offset_size. */
4027 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4032 switch (cu_header
->offset_size
)
4035 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4039 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4043 internal_error (__FILE__
, __LINE__
,
4044 "read_offset: bad switch");
4051 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4053 /* If the size of a host char is 8 bits, we can return a pointer
4054 to the buffer, otherwise we have to copy the data to a buffer
4055 allocated on the temporary obstack. */
4056 gdb_assert (HOST_CHAR_BIT
== 8);
4061 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4063 /* If the size of a host char is 8 bits, we can return a pointer
4064 to the string, otherwise we have to copy the string to a buffer
4065 allocated on the temporary obstack. */
4066 gdb_assert (HOST_CHAR_BIT
== 8);
4069 *bytes_read_ptr
= 1;
4072 *bytes_read_ptr
= strlen (buf
) + 1;
4077 read_indirect_string (bfd
*abfd
, char *buf
,
4078 const struct comp_unit_head
*cu_header
,
4079 unsigned int *bytes_read_ptr
)
4081 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4082 (int *) bytes_read_ptr
);
4084 if (dwarf_str_buffer
== NULL
)
4086 error ("DW_FORM_strp used without .debug_str section");
4089 if (str_offset
>= dwarf_str_size
)
4091 error ("DW_FORM_strp pointing outside of .debug_str section");
4094 gdb_assert (HOST_CHAR_BIT
== 8);
4095 if (dwarf_str_buffer
[str_offset
] == '\0')
4097 return dwarf_str_buffer
+ str_offset
;
4100 static unsigned long
4101 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4103 unsigned long result
;
4104 unsigned int num_read
;
4114 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4117 result
|= ((unsigned long)(byte
& 127) << shift
);
4118 if ((byte
& 128) == 0)
4124 *bytes_read_ptr
= num_read
;
4129 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4132 int i
, shift
, size
, num_read
;
4142 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4145 result
|= ((long)(byte
& 127) << shift
);
4147 if ((byte
& 128) == 0)
4152 if ((shift
< size
) && (byte
& 0x40))
4154 result
|= -(1 << shift
);
4156 *bytes_read_ptr
= num_read
;
4161 set_cu_language (unsigned int lang
)
4167 cu_language
= language_c
;
4169 case DW_LANG_C_plus_plus
:
4170 cu_language
= language_cplus
;
4172 case DW_LANG_Fortran77
:
4173 case DW_LANG_Fortran90
:
4174 case DW_LANG_Fortran95
:
4175 cu_language
= language_fortran
;
4177 case DW_LANG_Mips_Assembler
:
4178 cu_language
= language_asm
;
4181 cu_language
= language_java
;
4185 case DW_LANG_Cobol74
:
4186 case DW_LANG_Cobol85
:
4187 case DW_LANG_Pascal83
:
4188 case DW_LANG_Modula2
:
4190 cu_language
= language_unknown
;
4193 cu_language_defn
= language_def (cu_language
);
4196 /* Return the named attribute or NULL if not there. */
4198 static struct attribute
*
4199 dwarf_attr (struct die_info
*die
, unsigned int name
)
4202 struct attribute
*spec
= NULL
;
4204 for (i
= 0; i
< die
->num_attrs
; ++i
)
4206 if (die
->attrs
[i
].name
== name
)
4208 return &die
->attrs
[i
];
4210 if (die
->attrs
[i
].name
== DW_AT_specification
4211 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4212 spec
= &die
->attrs
[i
];
4216 struct die_info
*ref_die
=
4217 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4220 return dwarf_attr (ref_die
, name
);
4227 die_is_declaration (struct die_info
*die
)
4229 return (dwarf_attr (die
, DW_AT_declaration
)
4230 && ! dwarf_attr (die
, DW_AT_specification
));
4234 /* Free the line_header structure *LH, and any arrays and strings it
4237 free_line_header (struct line_header
*lh
)
4239 if (lh
->standard_opcode_lengths
)
4240 xfree (lh
->standard_opcode_lengths
);
4242 /* Remember that all the lh->file_names[i].name pointers are
4243 pointers into debug_line_buffer, and don't need to be freed. */
4245 xfree (lh
->file_names
);
4247 /* Similarly for the include directory names. */
4248 if (lh
->include_dirs
)
4249 xfree (lh
->include_dirs
);
4255 /* Add an entry to LH's include directory table. */
4257 add_include_dir (struct line_header
*lh
, char *include_dir
)
4259 /* Grow the array if necessary. */
4260 if (lh
->include_dirs_size
== 0)
4262 lh
->include_dirs_size
= 1; /* for testing */
4263 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4264 * sizeof (*lh
->include_dirs
));
4266 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4268 lh
->include_dirs_size
*= 2;
4269 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4270 (lh
->include_dirs_size
4271 * sizeof (*lh
->include_dirs
)));
4274 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4278 /* Add an entry to LH's file name table. */
4280 add_file_name (struct line_header
*lh
,
4282 unsigned int dir_index
,
4283 unsigned int mod_time
,
4284 unsigned int length
)
4286 struct file_entry
*fe
;
4288 /* Grow the array if necessary. */
4289 if (lh
->file_names_size
== 0)
4291 lh
->file_names_size
= 1; /* for testing */
4292 lh
->file_names
= xmalloc (lh
->file_names_size
4293 * sizeof (*lh
->file_names
));
4295 else if (lh
->num_file_names
>= lh
->file_names_size
)
4297 lh
->file_names_size
*= 2;
4298 lh
->file_names
= xrealloc (lh
->file_names
,
4299 (lh
->file_names_size
4300 * sizeof (*lh
->file_names
)));
4303 fe
= &lh
->file_names
[lh
->num_file_names
++];
4305 fe
->dir_index
= dir_index
;
4306 fe
->mod_time
= mod_time
;
4307 fe
->length
= length
;
4311 /* Read the statement program header starting at OFFSET in
4312 dwarf_line_buffer, according to the endianness of ABFD. Return a
4313 pointer to a struct line_header, allocated using xmalloc.
4315 NOTE: the strings in the include directory and file name tables of
4316 the returned object point into debug_line_buffer, and must not be
4318 static struct line_header
*
4319 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4320 const struct comp_unit_head
*cu_header
)
4322 struct cleanup
*back_to
;
4323 struct line_header
*lh
;
4327 char *cur_dir
, *cur_file
;
4329 if (dwarf_line_buffer
== NULL
)
4331 complain (&dwarf2_missing_line_number_section
);
4335 /* Make sure that at least there's room for the total_length field. That
4336 could be 12 bytes long, but we're just going to fudge that. */
4337 if (offset
+ 4 >= dwarf_line_size
)
4339 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4343 lh
= xmalloc (sizeof (*lh
));
4344 memset (lh
, 0, sizeof (*lh
));
4345 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4348 line_ptr
= dwarf_line_buffer
+ offset
;
4350 /* read in the header */
4351 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4352 line_ptr
+= bytes_read
;
4353 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4355 complain (&dwarf2_statement_list_fits_in_line_number_section
);
4358 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4359 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4361 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4362 line_ptr
+= bytes_read
;
4363 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4365 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4367 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4369 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4371 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4373 lh
->standard_opcode_lengths
4374 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4376 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4377 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4379 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4383 /* Read directory table */
4384 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4386 line_ptr
+= bytes_read
;
4387 add_include_dir (lh
, cur_dir
);
4389 line_ptr
+= bytes_read
;
4391 /* Read file name table */
4392 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4394 unsigned int dir_index
, mod_time
, length
;
4396 line_ptr
+= bytes_read
;
4397 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4398 line_ptr
+= bytes_read
;
4399 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4400 line_ptr
+= bytes_read
;
4401 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4402 line_ptr
+= bytes_read
;
4404 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4406 line_ptr
+= bytes_read
;
4407 lh
->statement_program_start
= line_ptr
;
4409 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4410 complain (&dwarf2_line_header_too_long
);
4412 discard_cleanups (back_to
);
4416 /* This function exists to work around a bug in certain compilers
4417 (particularly GCC 2.95), in which the first line number marker of a
4418 function does not show up until after the prologue, right before
4419 the second line number marker. This function shifts ADDRESS down
4420 to the beginning of the function if necessary, and is called on
4421 addresses passed to record_line. */
4424 check_cu_functions (CORE_ADDR address
)
4426 struct function_range
*fn
;
4428 /* Find the function_range containing address. */
4433 cu_cached_fn
= cu_first_fn
;
4437 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4443 while (fn
&& fn
!= cu_cached_fn
)
4444 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4454 if (address
!= fn
->lowpc
)
4455 complain (&dwarf2_misplaced_line_number
,
4456 (unsigned long) address
, fn
->name
);
4461 /* Decode the line number information for the compilation unit whose
4462 line number info is at OFFSET in the .debug_line section.
4463 The compilation directory of the file is passed in COMP_DIR. */
4466 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4467 const struct comp_unit_head
*cu_header
)
4471 unsigned int i
, bytes_read
;
4473 unsigned char op_code
, extended_op
, adj_opcode
;
4475 line_ptr
= lh
->statement_program_start
;
4476 line_end
= lh
->statement_program_end
;
4478 /* Read the statement sequences until there's nothing left. */
4479 while (line_ptr
< line_end
)
4481 /* state machine registers */
4482 CORE_ADDR address
= 0;
4483 unsigned int file
= 1;
4484 unsigned int line
= 1;
4485 unsigned int column
= 0;
4486 int is_stmt
= lh
->default_is_stmt
;
4487 int basic_block
= 0;
4488 int end_sequence
= 0;
4490 /* Start a subfile for the current file of the state machine. */
4491 if (lh
->num_file_names
>= file
)
4493 /* lh->include_dirs and lh->file_names are 0-based, but the
4494 directory and file name numbers in the statement program
4496 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4499 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4502 dwarf2_start_subfile (fe
->name
, dir
);
4505 /* Decode the table. */
4506 while (!end_sequence
)
4508 op_code
= read_1_byte (abfd
, line_ptr
);
4511 if (op_code
>= lh
->opcode_base
)
4512 { /* Special operand. */
4513 adj_opcode
= op_code
- lh
->opcode_base
;
4514 address
+= (adj_opcode
/ lh
->line_range
)
4515 * lh
->minimum_instruction_length
;
4516 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4517 /* append row to matrix using current values */
4518 address
= check_cu_functions (address
);
4519 record_line (current_subfile
, line
, address
);
4522 else switch (op_code
)
4524 case DW_LNS_extended_op
:
4525 line_ptr
+= 1; /* ignore length */
4526 extended_op
= read_1_byte (abfd
, line_ptr
);
4528 switch (extended_op
)
4530 case DW_LNE_end_sequence
:
4532 record_line (current_subfile
, 0, address
);
4534 case DW_LNE_set_address
:
4535 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4536 line_ptr
+= bytes_read
;
4537 address
+= baseaddr
;
4539 case DW_LNE_define_file
:
4542 unsigned int dir_index
, mod_time
, length
;
4544 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4545 line_ptr
+= bytes_read
;
4547 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4548 line_ptr
+= bytes_read
;
4550 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4551 line_ptr
+= bytes_read
;
4553 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4554 line_ptr
+= bytes_read
;
4555 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4559 complain (&dwarf2_mangled_line_number_section
);
4564 address
= check_cu_functions (address
);
4565 record_line (current_subfile
, line
, address
);
4568 case DW_LNS_advance_pc
:
4569 address
+= lh
->minimum_instruction_length
4570 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4571 line_ptr
+= bytes_read
;
4573 case DW_LNS_advance_line
:
4574 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4575 line_ptr
+= bytes_read
;
4577 case DW_LNS_set_file
:
4579 /* lh->include_dirs and lh->file_names are 0-based,
4580 but the directory and file name numbers in the
4581 statement program are 1-based. */
4582 struct file_entry
*fe
;
4584 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4585 line_ptr
+= bytes_read
;
4586 fe
= &lh
->file_names
[file
- 1];
4588 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4591 dwarf2_start_subfile (fe
->name
, dir
);
4594 case DW_LNS_set_column
:
4595 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4596 line_ptr
+= bytes_read
;
4598 case DW_LNS_negate_stmt
:
4599 is_stmt
= (!is_stmt
);
4601 case DW_LNS_set_basic_block
:
4604 /* Add to the address register of the state machine the
4605 address increment value corresponding to special opcode
4606 255. Ie, this value is scaled by the minimum instruction
4607 length since special opcode 255 would have scaled the
4609 case DW_LNS_const_add_pc
:
4610 address
+= (lh
->minimum_instruction_length
4611 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4613 case DW_LNS_fixed_advance_pc
:
4614 address
+= read_2_bytes (abfd
, line_ptr
);
4618 { /* Unknown standard opcode, ignore it. */
4620 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4622 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4623 line_ptr
+= bytes_read
;
4631 /* Start a subfile for DWARF. FILENAME is the name of the file and
4632 DIRNAME the name of the source directory which contains FILENAME
4633 or NULL if not known.
4634 This routine tries to keep line numbers from identical absolute and
4635 relative file names in a common subfile.
4637 Using the `list' example from the GDB testsuite, which resides in
4638 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4639 of /srcdir/list0.c yields the following debugging information for list0.c:
4641 DW_AT_name: /srcdir/list0.c
4642 DW_AT_comp_dir: /compdir
4643 files.files[0].name: list0.h
4644 files.files[0].dir: /srcdir
4645 files.files[1].name: list0.c
4646 files.files[1].dir: /srcdir
4648 The line number information for list0.c has to end up in a single
4649 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4652 dwarf2_start_subfile (char *filename
, char *dirname
)
4654 /* If the filename isn't absolute, try to match an existing subfile
4655 with the full pathname. */
4657 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4659 struct subfile
*subfile
;
4660 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4662 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4664 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4666 current_subfile
= subfile
;
4673 start_subfile (filename
, dirname
);
4676 /* Given a pointer to a DWARF information entry, figure out if we need
4677 to make a symbol table entry for it, and if so, create a new entry
4678 and return a pointer to it.
4679 If TYPE is NULL, determine symbol type from the die, otherwise
4680 used the passed type. */
4682 static struct symbol
*
4683 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4684 const struct comp_unit_head
*cu_header
)
4686 struct symbol
*sym
= NULL
;
4688 struct attribute
*attr
= NULL
;
4689 struct attribute
*attr2
= NULL
;
4692 name
= dwarf2_linkage_name (die
);
4695 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4696 sizeof (struct symbol
));
4697 OBJSTAT (objfile
, n_syms
++);
4698 memset (sym
, 0, sizeof (struct symbol
));
4699 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4700 &objfile
->symbol_obstack
);
4702 /* Default assumptions.
4703 Use the passed type or decode it from the die. */
4704 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4705 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4707 SYMBOL_TYPE (sym
) = type
;
4709 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4710 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4713 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4716 /* If this symbol is from a C++ compilation, then attempt to
4717 cache the demangled form for future reference. This is a
4718 typical time versus space tradeoff, that was decided in favor
4719 of time because it sped up C++ symbol lookups by a factor of
4722 SYMBOL_LANGUAGE (sym
) = cu_language
;
4723 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4727 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4730 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4732 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4734 case DW_TAG_subprogram
:
4735 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4737 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4738 attr2
= dwarf_attr (die
, DW_AT_external
);
4739 if (attr2
&& (DW_UNSND (attr2
) != 0))
4741 add_symbol_to_list (sym
, &global_symbols
);
4745 add_symbol_to_list (sym
, list_in_scope
);
4748 case DW_TAG_variable
:
4749 /* Compilation with minimal debug info may result in variables
4750 with missing type entries. Change the misleading `void' type
4751 to something sensible. */
4752 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4753 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4754 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4755 "<variable, no debug info>",
4757 attr
= dwarf_attr (die
, DW_AT_const_value
);
4760 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4761 attr2
= dwarf_attr (die
, DW_AT_external
);
4762 if (attr2
&& (DW_UNSND (attr2
) != 0))
4763 add_symbol_to_list (sym
, &global_symbols
);
4765 add_symbol_to_list (sym
, list_in_scope
);
4768 attr
= dwarf_attr (die
, DW_AT_location
);
4771 attr2
= dwarf_attr (die
, DW_AT_external
);
4772 if (attr2
&& (DW_UNSND (attr2
) != 0))
4774 /* Support the .debug_loc offsets */
4775 if (attr_form_is_block (attr
))
4777 SYMBOL_VALUE_ADDRESS (sym
) =
4778 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4780 else if (attr
->form
== DW_FORM_data4
4781 || attr
->form
== DW_FORM_data8
)
4783 complain (&dwarf2_complex_location_expr
);
4787 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
4788 "external variable");
4790 add_symbol_to_list (sym
, &global_symbols
);
4792 /* In shared libraries the address of the variable
4793 in the location descriptor might still be relocatable,
4794 so its value could be zero.
4795 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4796 value is zero, the address of the variable will then
4797 be determined from the minimal symbol table whenever
4798 the variable is referenced. */
4799 if (SYMBOL_VALUE_ADDRESS (sym
))
4801 fixup_symbol_section (sym
, objfile
);
4802 SYMBOL_VALUE_ADDRESS (sym
) +=
4803 ANOFFSET (objfile
->section_offsets
,
4804 SYMBOL_SECTION (sym
));
4805 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4808 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4812 /* Support the .debug_loc offsets */
4813 if (attr_form_is_block (attr
))
4815 SYMBOL_VALUE (sym
) = addr
=
4816 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4818 else if (attr
->form
== DW_FORM_data4
4819 || attr
->form
== DW_FORM_data8
)
4821 complain (&dwarf2_complex_location_expr
);
4825 complain (&dwarf2_invalid_attrib_class
, "DW_AT_location",
4826 "external variable");
4829 add_symbol_to_list (sym
, list_in_scope
);
4832 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4836 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4837 SYMBOL_VALUE (sym
) =
4838 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4842 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4843 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4847 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4851 fixup_symbol_section (sym
, objfile
);
4852 SYMBOL_VALUE_ADDRESS (sym
) =
4853 addr
+ ANOFFSET (objfile
->section_offsets
,
4854 SYMBOL_SECTION (sym
));
4855 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4861 /* We do not know the address of this symbol.
4862 If it is an external symbol and we have type information
4863 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4864 The address of the variable will then be determined from
4865 the minimal symbol table whenever the variable is
4867 attr2
= dwarf_attr (die
, DW_AT_external
);
4868 if (attr2
&& (DW_UNSND (attr2
) != 0)
4869 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4871 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4872 add_symbol_to_list (sym
, &global_symbols
);
4876 case DW_TAG_formal_parameter
:
4877 attr
= dwarf_attr (die
, DW_AT_location
);
4880 SYMBOL_VALUE (sym
) =
4881 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4884 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4885 SYMBOL_VALUE (sym
) =
4886 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4892 if (basereg
!= frame_base_reg
)
4893 complain (&dwarf2_complex_location_expr
);
4894 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4898 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4899 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4904 SYMBOL_CLASS (sym
) = LOC_ARG
;
4907 attr
= dwarf_attr (die
, DW_AT_const_value
);
4910 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4912 add_symbol_to_list (sym
, list_in_scope
);
4914 case DW_TAG_unspecified_parameters
:
4915 /* From varargs functions; gdb doesn't seem to have any
4916 interest in this information, so just ignore it for now.
4919 case DW_TAG_class_type
:
4920 case DW_TAG_structure_type
:
4921 case DW_TAG_union_type
:
4922 case DW_TAG_enumeration_type
:
4923 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4924 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4925 add_symbol_to_list (sym
, list_in_scope
);
4927 /* The semantics of C++ state that "struct foo { ... }" also
4928 defines a typedef for "foo". Synthesize a typedef symbol so
4929 that "ptype foo" works as expected. */
4930 if (cu_language
== language_cplus
)
4932 struct symbol
*typedef_sym
= (struct symbol
*)
4933 obstack_alloc (&objfile
->symbol_obstack
,
4934 sizeof (struct symbol
));
4935 *typedef_sym
= *sym
;
4936 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4937 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4938 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4939 obsavestring (SYMBOL_NAME (sym
),
4940 strlen (SYMBOL_NAME (sym
)),
4941 &objfile
->type_obstack
);
4942 add_symbol_to_list (typedef_sym
, list_in_scope
);
4945 case DW_TAG_typedef
:
4946 case DW_TAG_base_type
:
4947 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4948 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4949 add_symbol_to_list (sym
, list_in_scope
);
4951 case DW_TAG_enumerator
:
4952 attr
= dwarf_attr (die
, DW_AT_const_value
);
4955 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4957 add_symbol_to_list (sym
, list_in_scope
);
4960 /* Not a tag we recognize. Hopefully we aren't processing
4961 trash data, but since we must specifically ignore things
4962 we don't recognize, there is nothing else we should do at
4964 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4971 /* Copy constant value from an attribute to a symbol. */
4974 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4975 struct objfile
*objfile
,
4976 const struct comp_unit_head
*cu_header
)
4978 struct dwarf_block
*blk
;
4983 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4984 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4985 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4986 SYMBOL_VALUE_BYTES (sym
) = (char *)
4987 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4988 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4990 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4992 case DW_FORM_block1
:
4993 case DW_FORM_block2
:
4994 case DW_FORM_block4
:
4996 blk
= DW_BLOCK (attr
);
4997 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4998 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4999 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
5000 SYMBOL_VALUE_BYTES (sym
) = (char *)
5001 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5002 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5003 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5006 /* The DW_AT_const_value attributes are supposed to carry the
5007 symbol's value "represented as it would be on the target
5008 architecture." By the time we get here, it's already been
5009 converted to host endianness, so we just need to sign- or
5010 zero-extend it as appropriate. */
5012 dwarf2_const_value_data (attr
, sym
, 8);
5015 dwarf2_const_value_data (attr
, sym
, 16);
5018 dwarf2_const_value_data (attr
, sym
, 32);
5021 dwarf2_const_value_data (attr
, sym
, 64);
5025 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5026 SYMBOL_CLASS (sym
) = LOC_CONST
;
5030 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5031 SYMBOL_CLASS (sym
) = LOC_CONST
;
5035 complain (&dwarf2_unsupported_const_value_attr
,
5036 dwarf_form_name (attr
->form
));
5037 SYMBOL_VALUE (sym
) = 0;
5038 SYMBOL_CLASS (sym
) = LOC_CONST
;
5044 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5045 or zero-extend it as appropriate for the symbol's type. */
5047 dwarf2_const_value_data (struct attribute
*attr
,
5051 LONGEST l
= DW_UNSND (attr
);
5053 if (bits
< sizeof (l
) * 8)
5055 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5056 l
&= ((LONGEST
) 1 << bits
) - 1;
5058 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5061 SYMBOL_VALUE (sym
) = l
;
5062 SYMBOL_CLASS (sym
) = LOC_CONST
;
5066 /* Return the type of the die in question using its DW_AT_type attribute. */
5068 static struct type
*
5069 die_type (struct die_info
*die
, struct objfile
*objfile
,
5070 const struct comp_unit_head
*cu_header
)
5073 struct attribute
*type_attr
;
5074 struct die_info
*type_die
;
5077 type_attr
= dwarf_attr (die
, DW_AT_type
);
5080 /* A missing DW_AT_type represents a void type. */
5081 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5085 ref
= dwarf2_get_ref_die_offset (type_attr
);
5086 type_die
= follow_die_ref (ref
);
5089 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5093 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5096 dump_die (type_die
);
5097 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
5102 /* Return the containing type of the die in question using its
5103 DW_AT_containing_type attribute. */
5105 static struct type
*
5106 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5107 const struct comp_unit_head
*cu_header
)
5109 struct type
*type
= NULL
;
5110 struct attribute
*type_attr
;
5111 struct die_info
*type_die
= NULL
;
5114 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5117 ref
= dwarf2_get_ref_die_offset (type_attr
);
5118 type_die
= follow_die_ref (ref
);
5121 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5124 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5129 dump_die (type_die
);
5130 error ("Dwarf Error: Problem turning containing type into gdb type.");
5136 static struct type
*
5137 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5139 struct die_info
*die
;
5142 die
= follow_die_ref (offset
);
5145 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5148 type
= tag_type_to_type (die
, objfile
);
5153 static struct type
*
5154 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5155 const struct comp_unit_head
*cu_header
)
5163 read_type_die (die
, objfile
, cu_header
);
5167 error ("Dwarf Error: Cannot find type of die.");
5174 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5175 const struct comp_unit_head
*cu_header
)
5179 case DW_TAG_class_type
:
5180 case DW_TAG_structure_type
:
5181 case DW_TAG_union_type
:
5182 read_structure_scope (die
, objfile
, cu_header
);
5184 case DW_TAG_enumeration_type
:
5185 read_enumeration (die
, objfile
, cu_header
);
5187 case DW_TAG_subprogram
:
5188 case DW_TAG_subroutine_type
:
5189 read_subroutine_type (die
, objfile
, cu_header
);
5191 case DW_TAG_array_type
:
5192 read_array_type (die
, objfile
, cu_header
);
5194 case DW_TAG_pointer_type
:
5195 read_tag_pointer_type (die
, objfile
, cu_header
);
5197 case DW_TAG_ptr_to_member_type
:
5198 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5200 case DW_TAG_reference_type
:
5201 read_tag_reference_type (die
, objfile
, cu_header
);
5203 case DW_TAG_const_type
:
5204 read_tag_const_type (die
, objfile
, cu_header
);
5206 case DW_TAG_volatile_type
:
5207 read_tag_volatile_type (die
, objfile
, cu_header
);
5209 case DW_TAG_string_type
:
5210 read_tag_string_type (die
, objfile
);
5212 case DW_TAG_typedef
:
5213 read_typedef (die
, objfile
, cu_header
);
5215 case DW_TAG_base_type
:
5216 read_base_type (die
, objfile
);
5219 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
5224 static struct type
*
5225 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5227 /* FIXME - this should not produce a new (struct type *)
5228 every time. It should cache base types. */
5232 case DW_ATE_address
:
5233 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5235 case DW_ATE_boolean
:
5236 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5238 case DW_ATE_complex_float
:
5241 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5245 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5251 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5255 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5262 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5265 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5269 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5273 case DW_ATE_signed_char
:
5274 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5276 case DW_ATE_unsigned
:
5280 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5283 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5287 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5291 case DW_ATE_unsigned_char
:
5292 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5295 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5302 copy_die (struct die_info
*old_die
)
5304 struct die_info
*new_die
;
5307 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5308 memset (new_die
, 0, sizeof (struct die_info
));
5310 new_die
->tag
= old_die
->tag
;
5311 new_die
->has_children
= old_die
->has_children
;
5312 new_die
->abbrev
= old_die
->abbrev
;
5313 new_die
->offset
= old_die
->offset
;
5314 new_die
->type
= NULL
;
5316 num_attrs
= old_die
->num_attrs
;
5317 new_die
->num_attrs
= num_attrs
;
5318 new_die
->attrs
= (struct attribute
*)
5319 xmalloc (num_attrs
* sizeof (struct attribute
));
5321 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5323 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5324 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5325 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5328 new_die
->next
= NULL
;
5333 /* Return sibling of die, NULL if no sibling. */
5335 static struct die_info
*
5336 sibling_die (struct die_info
*die
)
5338 int nesting_level
= 0;
5340 if (!die
->has_children
)
5342 if (die
->next
&& (die
->next
->tag
== 0))
5355 if (die
->has_children
)
5365 while (nesting_level
);
5366 if (die
&& (die
->tag
== 0))
5377 /* Get linkage name of a die, return NULL if not found. */
5380 dwarf2_linkage_name (struct die_info
*die
)
5382 struct attribute
*attr
;
5384 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5385 if (attr
&& DW_STRING (attr
))
5386 return DW_STRING (attr
);
5387 attr
= dwarf_attr (die
, DW_AT_name
);
5388 if (attr
&& DW_STRING (attr
))
5389 return DW_STRING (attr
);
5393 /* Convert a DIE tag into its string name. */
5396 dwarf_tag_name (register unsigned tag
)
5400 case DW_TAG_padding
:
5401 return "DW_TAG_padding";
5402 case DW_TAG_array_type
:
5403 return "DW_TAG_array_type";
5404 case DW_TAG_class_type
:
5405 return "DW_TAG_class_type";
5406 case DW_TAG_entry_point
:
5407 return "DW_TAG_entry_point";
5408 case DW_TAG_enumeration_type
:
5409 return "DW_TAG_enumeration_type";
5410 case DW_TAG_formal_parameter
:
5411 return "DW_TAG_formal_parameter";
5412 case DW_TAG_imported_declaration
:
5413 return "DW_TAG_imported_declaration";
5415 return "DW_TAG_label";
5416 case DW_TAG_lexical_block
:
5417 return "DW_TAG_lexical_block";
5419 return "DW_TAG_member";
5420 case DW_TAG_pointer_type
:
5421 return "DW_TAG_pointer_type";
5422 case DW_TAG_reference_type
:
5423 return "DW_TAG_reference_type";
5424 case DW_TAG_compile_unit
:
5425 return "DW_TAG_compile_unit";
5426 case DW_TAG_string_type
:
5427 return "DW_TAG_string_type";
5428 case DW_TAG_structure_type
:
5429 return "DW_TAG_structure_type";
5430 case DW_TAG_subroutine_type
:
5431 return "DW_TAG_subroutine_type";
5432 case DW_TAG_typedef
:
5433 return "DW_TAG_typedef";
5434 case DW_TAG_union_type
:
5435 return "DW_TAG_union_type";
5436 case DW_TAG_unspecified_parameters
:
5437 return "DW_TAG_unspecified_parameters";
5438 case DW_TAG_variant
:
5439 return "DW_TAG_variant";
5440 case DW_TAG_common_block
:
5441 return "DW_TAG_common_block";
5442 case DW_TAG_common_inclusion
:
5443 return "DW_TAG_common_inclusion";
5444 case DW_TAG_inheritance
:
5445 return "DW_TAG_inheritance";
5446 case DW_TAG_inlined_subroutine
:
5447 return "DW_TAG_inlined_subroutine";
5449 return "DW_TAG_module";
5450 case DW_TAG_ptr_to_member_type
:
5451 return "DW_TAG_ptr_to_member_type";
5452 case DW_TAG_set_type
:
5453 return "DW_TAG_set_type";
5454 case DW_TAG_subrange_type
:
5455 return "DW_TAG_subrange_type";
5456 case DW_TAG_with_stmt
:
5457 return "DW_TAG_with_stmt";
5458 case DW_TAG_access_declaration
:
5459 return "DW_TAG_access_declaration";
5460 case DW_TAG_base_type
:
5461 return "DW_TAG_base_type";
5462 case DW_TAG_catch_block
:
5463 return "DW_TAG_catch_block";
5464 case DW_TAG_const_type
:
5465 return "DW_TAG_const_type";
5466 case DW_TAG_constant
:
5467 return "DW_TAG_constant";
5468 case DW_TAG_enumerator
:
5469 return "DW_TAG_enumerator";
5470 case DW_TAG_file_type
:
5471 return "DW_TAG_file_type";
5473 return "DW_TAG_friend";
5474 case DW_TAG_namelist
:
5475 return "DW_TAG_namelist";
5476 case DW_TAG_namelist_item
:
5477 return "DW_TAG_namelist_item";
5478 case DW_TAG_packed_type
:
5479 return "DW_TAG_packed_type";
5480 case DW_TAG_subprogram
:
5481 return "DW_TAG_subprogram";
5482 case DW_TAG_template_type_param
:
5483 return "DW_TAG_template_type_param";
5484 case DW_TAG_template_value_param
:
5485 return "DW_TAG_template_value_param";
5486 case DW_TAG_thrown_type
:
5487 return "DW_TAG_thrown_type";
5488 case DW_TAG_try_block
:
5489 return "DW_TAG_try_block";
5490 case DW_TAG_variant_part
:
5491 return "DW_TAG_variant_part";
5492 case DW_TAG_variable
:
5493 return "DW_TAG_variable";
5494 case DW_TAG_volatile_type
:
5495 return "DW_TAG_volatile_type";
5496 case DW_TAG_MIPS_loop
:
5497 return "DW_TAG_MIPS_loop";
5498 case DW_TAG_format_label
:
5499 return "DW_TAG_format_label";
5500 case DW_TAG_function_template
:
5501 return "DW_TAG_function_template";
5502 case DW_TAG_class_template
:
5503 return "DW_TAG_class_template";
5505 return "DW_TAG_<unknown>";
5509 /* Convert a DWARF attribute code into its string name. */
5512 dwarf_attr_name (register unsigned attr
)
5517 return "DW_AT_sibling";
5518 case DW_AT_location
:
5519 return "DW_AT_location";
5521 return "DW_AT_name";
5522 case DW_AT_ordering
:
5523 return "DW_AT_ordering";
5524 case DW_AT_subscr_data
:
5525 return "DW_AT_subscr_data";
5526 case DW_AT_byte_size
:
5527 return "DW_AT_byte_size";
5528 case DW_AT_bit_offset
:
5529 return "DW_AT_bit_offset";
5530 case DW_AT_bit_size
:
5531 return "DW_AT_bit_size";
5532 case DW_AT_element_list
:
5533 return "DW_AT_element_list";
5534 case DW_AT_stmt_list
:
5535 return "DW_AT_stmt_list";
5537 return "DW_AT_low_pc";
5539 return "DW_AT_high_pc";
5540 case DW_AT_language
:
5541 return "DW_AT_language";
5543 return "DW_AT_member";
5545 return "DW_AT_discr";
5546 case DW_AT_discr_value
:
5547 return "DW_AT_discr_value";
5548 case DW_AT_visibility
:
5549 return "DW_AT_visibility";
5551 return "DW_AT_import";
5552 case DW_AT_string_length
:
5553 return "DW_AT_string_length";
5554 case DW_AT_common_reference
:
5555 return "DW_AT_common_reference";
5556 case DW_AT_comp_dir
:
5557 return "DW_AT_comp_dir";
5558 case DW_AT_const_value
:
5559 return "DW_AT_const_value";
5560 case DW_AT_containing_type
:
5561 return "DW_AT_containing_type";
5562 case DW_AT_default_value
:
5563 return "DW_AT_default_value";
5565 return "DW_AT_inline";
5566 case DW_AT_is_optional
:
5567 return "DW_AT_is_optional";
5568 case DW_AT_lower_bound
:
5569 return "DW_AT_lower_bound";
5570 case DW_AT_producer
:
5571 return "DW_AT_producer";
5572 case DW_AT_prototyped
:
5573 return "DW_AT_prototyped";
5574 case DW_AT_return_addr
:
5575 return "DW_AT_return_addr";
5576 case DW_AT_start_scope
:
5577 return "DW_AT_start_scope";
5578 case DW_AT_stride_size
:
5579 return "DW_AT_stride_size";
5580 case DW_AT_upper_bound
:
5581 return "DW_AT_upper_bound";
5582 case DW_AT_abstract_origin
:
5583 return "DW_AT_abstract_origin";
5584 case DW_AT_accessibility
:
5585 return "DW_AT_accessibility";
5586 case DW_AT_address_class
:
5587 return "DW_AT_address_class";
5588 case DW_AT_artificial
:
5589 return "DW_AT_artificial";
5590 case DW_AT_base_types
:
5591 return "DW_AT_base_types";
5592 case DW_AT_calling_convention
:
5593 return "DW_AT_calling_convention";
5595 return "DW_AT_count";
5596 case DW_AT_data_member_location
:
5597 return "DW_AT_data_member_location";
5598 case DW_AT_decl_column
:
5599 return "DW_AT_decl_column";
5600 case DW_AT_decl_file
:
5601 return "DW_AT_decl_file";
5602 case DW_AT_decl_line
:
5603 return "DW_AT_decl_line";
5604 case DW_AT_declaration
:
5605 return "DW_AT_declaration";
5606 case DW_AT_discr_list
:
5607 return "DW_AT_discr_list";
5608 case DW_AT_encoding
:
5609 return "DW_AT_encoding";
5610 case DW_AT_external
:
5611 return "DW_AT_external";
5612 case DW_AT_frame_base
:
5613 return "DW_AT_frame_base";
5615 return "DW_AT_friend";
5616 case DW_AT_identifier_case
:
5617 return "DW_AT_identifier_case";
5618 case DW_AT_macro_info
:
5619 return "DW_AT_macro_info";
5620 case DW_AT_namelist_items
:
5621 return "DW_AT_namelist_items";
5622 case DW_AT_priority
:
5623 return "DW_AT_priority";
5625 return "DW_AT_segment";
5626 case DW_AT_specification
:
5627 return "DW_AT_specification";
5628 case DW_AT_static_link
:
5629 return "DW_AT_static_link";
5631 return "DW_AT_type";
5632 case DW_AT_use_location
:
5633 return "DW_AT_use_location";
5634 case DW_AT_variable_parameter
:
5635 return "DW_AT_variable_parameter";
5636 case DW_AT_virtuality
:
5637 return "DW_AT_virtuality";
5638 case DW_AT_vtable_elem_location
:
5639 return "DW_AT_vtable_elem_location";
5642 case DW_AT_MIPS_fde
:
5643 return "DW_AT_MIPS_fde";
5644 case DW_AT_MIPS_loop_begin
:
5645 return "DW_AT_MIPS_loop_begin";
5646 case DW_AT_MIPS_tail_loop_begin
:
5647 return "DW_AT_MIPS_tail_loop_begin";
5648 case DW_AT_MIPS_epilog_begin
:
5649 return "DW_AT_MIPS_epilog_begin";
5650 case DW_AT_MIPS_loop_unroll_factor
:
5651 return "DW_AT_MIPS_loop_unroll_factor";
5652 case DW_AT_MIPS_software_pipeline_depth
:
5653 return "DW_AT_MIPS_software_pipeline_depth";
5654 case DW_AT_MIPS_linkage_name
:
5655 return "DW_AT_MIPS_linkage_name";
5658 case DW_AT_sf_names
:
5659 return "DW_AT_sf_names";
5660 case DW_AT_src_info
:
5661 return "DW_AT_src_info";
5662 case DW_AT_mac_info
:
5663 return "DW_AT_mac_info";
5664 case DW_AT_src_coords
:
5665 return "DW_AT_src_coords";
5666 case DW_AT_body_begin
:
5667 return "DW_AT_body_begin";
5668 case DW_AT_body_end
:
5669 return "DW_AT_body_end";
5670 case DW_AT_GNU_vector
:
5671 return "DW_AT_GNU_vector";
5673 return "DW_AT_<unknown>";
5677 /* Convert a DWARF value form code into its string name. */
5680 dwarf_form_name (register unsigned form
)
5685 return "DW_FORM_addr";
5686 case DW_FORM_block2
:
5687 return "DW_FORM_block2";
5688 case DW_FORM_block4
:
5689 return "DW_FORM_block4";
5691 return "DW_FORM_data2";
5693 return "DW_FORM_data4";
5695 return "DW_FORM_data8";
5696 case DW_FORM_string
:
5697 return "DW_FORM_string";
5699 return "DW_FORM_block";
5700 case DW_FORM_block1
:
5701 return "DW_FORM_block1";
5703 return "DW_FORM_data1";
5705 return "DW_FORM_flag";
5707 return "DW_FORM_sdata";
5709 return "DW_FORM_strp";
5711 return "DW_FORM_udata";
5712 case DW_FORM_ref_addr
:
5713 return "DW_FORM_ref_addr";
5715 return "DW_FORM_ref1";
5717 return "DW_FORM_ref2";
5719 return "DW_FORM_ref4";
5721 return "DW_FORM_ref8";
5722 case DW_FORM_ref_udata
:
5723 return "DW_FORM_ref_udata";
5724 case DW_FORM_indirect
:
5725 return "DW_FORM_indirect";
5727 return "DW_FORM_<unknown>";
5731 /* Convert a DWARF stack opcode into its string name. */
5734 dwarf_stack_op_name (register unsigned op
)
5739 return "DW_OP_addr";
5741 return "DW_OP_deref";
5743 return "DW_OP_const1u";
5745 return "DW_OP_const1s";
5747 return "DW_OP_const2u";
5749 return "DW_OP_const2s";
5751 return "DW_OP_const4u";
5753 return "DW_OP_const4s";
5755 return "DW_OP_const8u";
5757 return "DW_OP_const8s";
5759 return "DW_OP_constu";
5761 return "DW_OP_consts";
5765 return "DW_OP_drop";
5767 return "DW_OP_over";
5769 return "DW_OP_pick";
5771 return "DW_OP_swap";
5775 return "DW_OP_xderef";
5783 return "DW_OP_minus";
5795 return "DW_OP_plus";
5796 case DW_OP_plus_uconst
:
5797 return "DW_OP_plus_uconst";
5803 return "DW_OP_shra";
5821 return "DW_OP_skip";
5823 return "DW_OP_lit0";
5825 return "DW_OP_lit1";
5827 return "DW_OP_lit2";
5829 return "DW_OP_lit3";
5831 return "DW_OP_lit4";
5833 return "DW_OP_lit5";
5835 return "DW_OP_lit6";
5837 return "DW_OP_lit7";
5839 return "DW_OP_lit8";
5841 return "DW_OP_lit9";
5843 return "DW_OP_lit10";
5845 return "DW_OP_lit11";
5847 return "DW_OP_lit12";
5849 return "DW_OP_lit13";
5851 return "DW_OP_lit14";
5853 return "DW_OP_lit15";
5855 return "DW_OP_lit16";
5857 return "DW_OP_lit17";
5859 return "DW_OP_lit18";
5861 return "DW_OP_lit19";
5863 return "DW_OP_lit20";
5865 return "DW_OP_lit21";
5867 return "DW_OP_lit22";
5869 return "DW_OP_lit23";
5871 return "DW_OP_lit24";
5873 return "DW_OP_lit25";
5875 return "DW_OP_lit26";
5877 return "DW_OP_lit27";
5879 return "DW_OP_lit28";
5881 return "DW_OP_lit29";
5883 return "DW_OP_lit30";
5885 return "DW_OP_lit31";
5887 return "DW_OP_reg0";
5889 return "DW_OP_reg1";
5891 return "DW_OP_reg2";
5893 return "DW_OP_reg3";
5895 return "DW_OP_reg4";
5897 return "DW_OP_reg5";
5899 return "DW_OP_reg6";
5901 return "DW_OP_reg7";
5903 return "DW_OP_reg8";
5905 return "DW_OP_reg9";
5907 return "DW_OP_reg10";
5909 return "DW_OP_reg11";
5911 return "DW_OP_reg12";
5913 return "DW_OP_reg13";
5915 return "DW_OP_reg14";
5917 return "DW_OP_reg15";
5919 return "DW_OP_reg16";
5921 return "DW_OP_reg17";
5923 return "DW_OP_reg18";
5925 return "DW_OP_reg19";
5927 return "DW_OP_reg20";
5929 return "DW_OP_reg21";
5931 return "DW_OP_reg22";
5933 return "DW_OP_reg23";
5935 return "DW_OP_reg24";
5937 return "DW_OP_reg25";
5939 return "DW_OP_reg26";
5941 return "DW_OP_reg27";
5943 return "DW_OP_reg28";
5945 return "DW_OP_reg29";
5947 return "DW_OP_reg30";
5949 return "DW_OP_reg31";
5951 return "DW_OP_breg0";
5953 return "DW_OP_breg1";
5955 return "DW_OP_breg2";
5957 return "DW_OP_breg3";
5959 return "DW_OP_breg4";
5961 return "DW_OP_breg5";
5963 return "DW_OP_breg6";
5965 return "DW_OP_breg7";
5967 return "DW_OP_breg8";
5969 return "DW_OP_breg9";
5971 return "DW_OP_breg10";
5973 return "DW_OP_breg11";
5975 return "DW_OP_breg12";
5977 return "DW_OP_breg13";
5979 return "DW_OP_breg14";
5981 return "DW_OP_breg15";
5983 return "DW_OP_breg16";
5985 return "DW_OP_breg17";
5987 return "DW_OP_breg18";
5989 return "DW_OP_breg19";
5991 return "DW_OP_breg20";
5993 return "DW_OP_breg21";
5995 return "DW_OP_breg22";
5997 return "DW_OP_breg23";
5999 return "DW_OP_breg24";
6001 return "DW_OP_breg25";
6003 return "DW_OP_breg26";
6005 return "DW_OP_breg27";
6007 return "DW_OP_breg28";
6009 return "DW_OP_breg29";
6011 return "DW_OP_breg30";
6013 return "DW_OP_breg31";
6015 return "DW_OP_regx";
6017 return "DW_OP_fbreg";
6019 return "DW_OP_bregx";
6021 return "DW_OP_piece";
6022 case DW_OP_deref_size
:
6023 return "DW_OP_deref_size";
6024 case DW_OP_xderef_size
:
6025 return "DW_OP_xderef_size";
6028 /* DWARF 3 extensions. */
6029 case DW_OP_push_object_address
:
6030 return "DW_OP_push_object_address";
6032 return "DW_OP_call2";
6034 return "DW_OP_call4";
6035 case DW_OP_call_ref
:
6036 return "DW_OP_call_ref";
6037 /* GNU extensions. */
6038 case DW_OP_GNU_push_tls_address
:
6039 return "DW_OP_GNU_push_tls_address";
6041 return "OP_<unknown>";
6046 dwarf_bool_name (unsigned mybool
)
6054 /* Convert a DWARF type code into its string name. */
6057 dwarf_type_encoding_name (register unsigned enc
)
6061 case DW_ATE_address
:
6062 return "DW_ATE_address";
6063 case DW_ATE_boolean
:
6064 return "DW_ATE_boolean";
6065 case DW_ATE_complex_float
:
6066 return "DW_ATE_complex_float";
6068 return "DW_ATE_float";
6070 return "DW_ATE_signed";
6071 case DW_ATE_signed_char
:
6072 return "DW_ATE_signed_char";
6073 case DW_ATE_unsigned
:
6074 return "DW_ATE_unsigned";
6075 case DW_ATE_unsigned_char
:
6076 return "DW_ATE_unsigned_char";
6078 return "DW_ATE_<unknown>";
6082 /* Convert a DWARF call frame info operation to its string name. */
6086 dwarf_cfi_name (register unsigned cfi_opc
)
6090 case DW_CFA_advance_loc
:
6091 return "DW_CFA_advance_loc";
6093 return "DW_CFA_offset";
6094 case DW_CFA_restore
:
6095 return "DW_CFA_restore";
6097 return "DW_CFA_nop";
6098 case DW_CFA_set_loc
:
6099 return "DW_CFA_set_loc";
6100 case DW_CFA_advance_loc1
:
6101 return "DW_CFA_advance_loc1";
6102 case DW_CFA_advance_loc2
:
6103 return "DW_CFA_advance_loc2";
6104 case DW_CFA_advance_loc4
:
6105 return "DW_CFA_advance_loc4";
6106 case DW_CFA_offset_extended
:
6107 return "DW_CFA_offset_extended";
6108 case DW_CFA_restore_extended
:
6109 return "DW_CFA_restore_extended";
6110 case DW_CFA_undefined
:
6111 return "DW_CFA_undefined";
6112 case DW_CFA_same_value
:
6113 return "DW_CFA_same_value";
6114 case DW_CFA_register
:
6115 return "DW_CFA_register";
6116 case DW_CFA_remember_state
:
6117 return "DW_CFA_remember_state";
6118 case DW_CFA_restore_state
:
6119 return "DW_CFA_restore_state";
6120 case DW_CFA_def_cfa
:
6121 return "DW_CFA_def_cfa";
6122 case DW_CFA_def_cfa_register
:
6123 return "DW_CFA_def_cfa_register";
6124 case DW_CFA_def_cfa_offset
:
6125 return "DW_CFA_def_cfa_offset";
6128 case DW_CFA_def_cfa_expression
:
6129 return "DW_CFA_def_cfa_expression";
6130 case DW_CFA_expression
:
6131 return "DW_CFA_expression";
6132 case DW_CFA_offset_extended_sf
:
6133 return "DW_CFA_offset_extended_sf";
6134 case DW_CFA_def_cfa_sf
:
6135 return "DW_CFA_def_cfa_sf";
6136 case DW_CFA_def_cfa_offset_sf
:
6137 return "DW_CFA_def_cfa_offset_sf";
6139 /* SGI/MIPS specific */
6140 case DW_CFA_MIPS_advance_loc8
:
6141 return "DW_CFA_MIPS_advance_loc8";
6143 /* GNU extensions */
6144 case DW_CFA_GNU_window_save
:
6145 return "DW_CFA_GNU_window_save";
6146 case DW_CFA_GNU_args_size
:
6147 return "DW_CFA_GNU_args_size";
6148 case DW_CFA_GNU_negative_offset_extended
:
6149 return "DW_CFA_GNU_negative_offset_extended";
6152 return "DW_CFA_<unknown>";
6158 dump_die (struct die_info
*die
)
6162 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6163 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6164 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6165 dwarf_bool_name (die
->has_children
));
6167 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6168 for (i
= 0; i
< die
->num_attrs
; ++i
)
6170 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6171 dwarf_attr_name (die
->attrs
[i
].name
),
6172 dwarf_form_name (die
->attrs
[i
].form
));
6173 switch (die
->attrs
[i
].form
)
6175 case DW_FORM_ref_addr
:
6177 fprintf_unfiltered (gdb_stderr
, "address: ");
6178 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6180 case DW_FORM_block2
:
6181 case DW_FORM_block4
:
6183 case DW_FORM_block1
:
6184 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6195 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6197 case DW_FORM_string
:
6199 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6200 DW_STRING (&die
->attrs
[i
])
6201 ? DW_STRING (&die
->attrs
[i
]) : "");
6204 if (DW_UNSND (&die
->attrs
[i
]))
6205 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6207 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6209 case DW_FORM_indirect
:
6210 /* the reader will have reduced the indirect form to
6211 the "base form" so this form should not occur */
6212 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6215 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6216 die
->attrs
[i
].form
);
6218 fprintf_unfiltered (gdb_stderr
, "\n");
6223 dump_die_list (struct die_info
*die
)
6233 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6236 struct die_info
*old
;
6238 h
= (offset
% REF_HASH_SIZE
);
6239 old
= die_ref_table
[h
];
6240 die
->next_ref
= old
;
6241 die_ref_table
[h
] = die
;
6246 dwarf2_empty_hash_tables (void)
6248 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6252 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6254 unsigned int result
= 0;
6258 case DW_FORM_ref_addr
:
6259 result
= DW_ADDR (attr
);
6265 case DW_FORM_ref_udata
:
6266 result
= cu_header_offset
+ DW_UNSND (attr
);
6269 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
6274 static struct die_info
*
6275 follow_die_ref (unsigned int offset
)
6277 struct die_info
*die
;
6280 h
= (offset
% REF_HASH_SIZE
);
6281 die
= die_ref_table
[h
];
6284 if (die
->offset
== offset
)
6288 die
= die
->next_ref
;
6293 static struct type
*
6294 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6296 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6298 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
6302 /* Look for this particular type in the fundamental type vector. If
6303 one is not found, create and install one appropriate for the
6304 current language and the current target machine. */
6306 if (ftypes
[typeid] == NULL
)
6308 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6311 return (ftypes
[typeid]);
6314 /* Decode simple location descriptions.
6315 Given a pointer to a dwarf block that defines a location, compute
6316 the location and return the value.
6318 FIXME: This is a kludge until we figure out a better
6319 way to handle the location descriptions.
6320 Gdb's design does not mesh well with the DWARF2 notion of a location
6321 computing interpreter, which is a shame because the flexibility goes unused.
6322 FIXME: Implement more operations as necessary.
6324 A location description containing no operations indicates that the
6325 object is optimized out. The global optimized_out flag is set for
6326 those, the return value is meaningless.
6328 When the result is a register number, the global isreg flag is set,
6329 otherwise it is cleared.
6331 When the result is a base register offset, the global offreg flag is set
6332 and the register number is returned in basereg, otherwise it is cleared.
6334 When the DW_OP_fbreg operation is encountered without a corresponding
6335 DW_AT_frame_base attribute, the global islocal flag is set.
6336 Hopefully the machine dependent code knows how to set up a virtual
6337 frame pointer for the local references.
6339 Note that stack[0] is unused except as a default error return.
6340 Note that stack overflow is not yet handled. */
6343 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6344 const struct comp_unit_head
*cu_header
)
6347 int size
= blk
->size
;
6348 char *data
= blk
->data
;
6349 CORE_ADDR stack
[64];
6351 unsigned int bytes_read
, unsnd
;
6401 stack
[++stacki
] = op
- DW_OP_lit0
;
6437 stack
[++stacki
] = op
- DW_OP_reg0
;
6442 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6444 stack
[++stacki
] = unsnd
;
6480 basereg
= op
- DW_OP_breg0
;
6481 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6487 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6489 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6494 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6496 if (frame_base_reg
>= 0)
6499 basereg
= frame_base_reg
;
6500 stack
[stacki
] += frame_base_offset
;
6504 complain (&dwarf2_missing_at_frame_base
);
6510 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6511 cu_header
, &bytes_read
);
6516 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6521 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6526 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6531 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6536 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6541 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6546 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6552 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6557 stack
[stacki
+ 1] = stack
[stacki
];
6562 stack
[stacki
- 1] += stack
[stacki
];
6566 case DW_OP_plus_uconst
:
6567 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6572 stack
[stacki
- 1] -= stack
[stacki
];
6578 /* If we're not the last op, then we definitely can't encode
6579 this using GDB's address_class enum. */
6581 complain (&dwarf2_complex_location_expr
);
6585 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
6586 return (stack
[stacki
]);
6589 return (stack
[stacki
]);
6592 /* memory allocation interface */
6596 dwarf2_free_tmp_obstack (PTR ignore
)
6598 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6601 static struct dwarf_block
*
6602 dwarf_alloc_block (void)
6604 struct dwarf_block
*blk
;
6606 blk
= (struct dwarf_block
*)
6607 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6611 static struct abbrev_info
*
6612 dwarf_alloc_abbrev (void)
6614 struct abbrev_info
*abbrev
;
6616 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6617 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6621 static struct die_info
*
6622 dwarf_alloc_die (void)
6624 struct die_info
*die
;
6626 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6627 memset (die
, 0, sizeof (struct die_info
));
6632 /* Macro support. */
6635 /* Return the full name of file number I in *LH's file name table.
6636 Use COMP_DIR as the name of the current directory of the
6637 compilation. The result is allocated using xmalloc; the caller is
6638 responsible for freeing it. */
6640 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
6642 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6644 if (IS_ABSOLUTE_PATH (fe
->name
))
6645 return xstrdup (fe
->name
);
6653 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6659 dir_len
= strlen (dir
);
6660 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
6661 strcpy (full_name
, dir
);
6662 full_name
[dir_len
] = '/';
6663 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
6667 return xstrdup (fe
->name
);
6672 static struct macro_source_file
*
6673 macro_start_file (int file
, int line
,
6674 struct macro_source_file
*current_file
,
6675 const char *comp_dir
,
6676 struct line_header
*lh
, struct objfile
*objfile
)
6678 /* The full name of this source file. */
6679 char *full_name
= file_full_name (file
, lh
, comp_dir
);
6681 /* We don't create a macro table for this compilation unit
6682 at all until we actually get a filename. */
6683 if (! pending_macros
)
6684 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
6685 objfile
->macro_cache
);
6688 /* If we have no current file, then this must be the start_file
6689 directive for the compilation unit's main source file. */
6690 current_file
= macro_set_main (pending_macros
, full_name
);
6692 current_file
= macro_include (current_file
, line
, full_name
);
6696 return current_file
;
6700 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
6701 followed by a null byte. */
6703 copy_string (const char *buf
, int len
)
6705 char *s
= xmalloc (len
+ 1);
6706 memcpy (s
, buf
, len
);
6714 consume_improper_spaces (const char *p
, const char *body
)
6718 complain (&dwarf2_macro_spaces_in_definition
, body
);
6729 parse_macro_definition (struct macro_source_file
*file
, int line
,
6734 /* The body string takes one of two forms. For object-like macro
6735 definitions, it should be:
6737 <macro name> " " <definition>
6739 For function-like macro definitions, it should be:
6741 <macro name> "() " <definition>
6743 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
6745 Spaces may appear only where explicitly indicated, and in the
6748 The Dwarf 2 spec says that an object-like macro's name is always
6749 followed by a space, but versions of GCC around March 2002 omit
6750 the space when the macro's definition is the empty string.
6752 The Dwarf 2 spec says that there should be no spaces between the
6753 formal arguments in a function-like macro's formal argument list,
6754 but versions of GCC around March 2002 include spaces after the
6758 /* Find the extent of the macro name. The macro name is terminated
6759 by either a space or null character (for an object-like macro) or
6760 an opening paren (for a function-like macro). */
6761 for (p
= body
; *p
; p
++)
6762 if (*p
== ' ' || *p
== '(')
6765 if (*p
== ' ' || *p
== '\0')
6767 /* It's an object-like macro. */
6768 int name_len
= p
- body
;
6769 char *name
= copy_string (body
, name_len
);
6770 const char *replacement
;
6773 replacement
= body
+ name_len
+ 1;
6776 complain (&dwarf2_macro_malformed_definition
, body
);
6777 replacement
= body
+ name_len
;
6780 macro_define_object (file
, line
, name
, replacement
);
6786 /* It's a function-like macro. */
6787 char *name
= copy_string (body
, p
- body
);
6790 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
6794 p
= consume_improper_spaces (p
, body
);
6796 /* Parse the formal argument list. */
6797 while (*p
&& *p
!= ')')
6799 /* Find the extent of the current argument name. */
6800 const char *arg_start
= p
;
6802 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
6805 if (! *p
|| p
== arg_start
)
6806 complain (&dwarf2_macro_malformed_definition
,
6810 /* Make sure argv has room for the new argument. */
6811 if (argc
>= argv_size
)
6814 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
6817 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
6820 p
= consume_improper_spaces (p
, body
);
6822 /* Consume the comma, if present. */
6827 p
= consume_improper_spaces (p
, body
);
6836 /* Perfectly formed definition, no complaints. */
6837 macro_define_function (file
, line
, name
,
6838 argc
, (const char **) argv
,
6840 else if (*p
== '\0')
6842 /* Complain, but do define it. */
6843 complain (&dwarf2_macro_malformed_definition
, body
);
6844 macro_define_function (file
, line
, name
,
6845 argc
, (const char **) argv
,
6849 /* Just complain. */
6850 complain (&dwarf2_macro_malformed_definition
, body
);
6853 /* Just complain. */
6854 complain (&dwarf2_macro_malformed_definition
, body
);
6860 for (i
= 0; i
< argc
; i
++)
6866 complain (&dwarf2_macro_malformed_definition
, body
);
6871 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
6872 char *comp_dir
, bfd
*abfd
,
6873 const struct comp_unit_head
*cu_header
,
6874 struct objfile
*objfile
)
6876 char *mac_ptr
, *mac_end
;
6877 struct macro_source_file
*current_file
= 0;
6879 if (dwarf_macinfo_buffer
== NULL
)
6881 complain (&dwarf2_missing_macinfo_section
);
6885 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
6886 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
6890 enum dwarf_macinfo_record_type macinfo_type
;
6892 /* Do we at least have room for a macinfo type byte? */
6893 if (mac_ptr
>= mac_end
)
6895 complain (&dwarf2_macros_too_long
);
6899 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
6902 switch (macinfo_type
)
6904 /* A zero macinfo type indicates the end of the macro
6909 case DW_MACINFO_define
:
6910 case DW_MACINFO_undef
:
6916 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6917 mac_ptr
+= bytes_read
;
6918 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
6919 mac_ptr
+= bytes_read
;
6922 complain (&dwarf2_macro_outside_file
,
6923 macinfo_type
== DW_MACINFO_define
? "definition" :
6924 macinfo_type
== DW_MACINFO_undef
? "undefinition" :
6925 "something-or-other",
6929 if (macinfo_type
== DW_MACINFO_define
)
6930 parse_macro_definition (current_file
, line
, body
);
6931 else if (macinfo_type
== DW_MACINFO_undef
)
6932 macro_undef (current_file
, line
, body
);
6937 case DW_MACINFO_start_file
:
6942 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6943 mac_ptr
+= bytes_read
;
6944 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6945 mac_ptr
+= bytes_read
;
6947 current_file
= macro_start_file (file
, line
,
6948 current_file
, comp_dir
,
6953 case DW_MACINFO_end_file
:
6955 complain (&dwarf2_macro_unmatched_end_file
);
6958 current_file
= current_file
->included_by
;
6961 enum dwarf_macinfo_record_type next_type
;
6963 /* GCC circa March 2002 doesn't produce the zero
6964 type byte marking the end of the compilation
6965 unit. Complain if it's not there, but exit no
6968 /* Do we at least have room for a macinfo type byte? */
6969 if (mac_ptr
>= mac_end
)
6971 complain (&dwarf2_macros_too_long
);
6975 /* We don't increment mac_ptr here, so this is just
6977 next_type
= read_1_byte (abfd
, mac_ptr
);
6979 complain (&dwarf2_macros_not_terminated
);
6986 case DW_MACINFO_vendor_ext
:
6992 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
6993 mac_ptr
+= bytes_read
;
6994 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
6995 mac_ptr
+= bytes_read
;
6997 /* We don't recognize any vendor extensions. */
7004 /* Check if the attribute's form is a DW_FORM_block*
7005 if so return true else false. */
7007 attr_form_is_block (struct attribute
*attr
)
7009 return (attr
== NULL
? 0 :
7010 attr
->form
== DW_FORM_block1
7011 || attr
->form
== DW_FORM_block2
7012 || attr
->form
== DW_FORM_block4
7013 || attr
->form
== DW_FORM_block
);