1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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 */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
49 #include "gdb_string.h"
50 #include "gdb_assert.h"
51 #include <sys/types.h>
53 #ifndef DWARF2_REG_TO_REGNUM
54 #define DWARF2_REG_TO_REGNUM(REG) (REG)
58 /* .debug_info header for a compilation unit
59 Because of alignment constraints, this structure has padding and cannot
60 be mapped directly onto the beginning of the .debug_info section. */
61 typedef struct comp_unit_header
63 unsigned int length
; /* length of the .debug_info
65 unsigned short version
; /* version number -- 2 for DWARF
67 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
68 unsigned char addr_size
; /* byte size of an address -- 4 */
71 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
74 /* .debug_pubnames header
75 Because of alignment constraints, this structure has padding and cannot
76 be mapped directly onto the beginning of the .debug_info section. */
77 typedef struct pubnames_header
79 unsigned int length
; /* length of the .debug_pubnames
81 unsigned char version
; /* version number -- 2 for DWARF
83 unsigned int info_offset
; /* offset into .debug_info section */
84 unsigned int info_size
; /* byte size of .debug_info section
88 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
90 /* .debug_pubnames header
91 Because of alignment constraints, this structure has padding and cannot
92 be mapped directly onto the beginning of the .debug_info section. */
93 typedef struct aranges_header
95 unsigned int length
; /* byte len of the .debug_aranges
97 unsigned short version
; /* version number -- 2 for DWARF
99 unsigned int info_offset
; /* offset into .debug_info section */
100 unsigned char addr_size
; /* byte size of an address */
101 unsigned char seg_size
; /* byte size of segment descriptor */
104 #define _ACTUAL_ARANGES_HEADER_SIZE 12
106 /* .debug_line statement program prologue
107 Because of alignment constraints, this structure has padding and cannot
108 be mapped directly onto the beginning of the .debug_info section. */
109 typedef struct statement_prologue
111 unsigned int total_length
; /* byte length of the statement
113 unsigned short version
; /* version number -- 2 for DWARF
115 unsigned int prologue_length
; /* # bytes between prologue &
117 unsigned char minimum_instruction_length
; /* byte size of
119 unsigned char default_is_stmt
; /* initial value of is_stmt
122 unsigned char line_range
;
123 unsigned char opcode_base
; /* number assigned to first special
125 unsigned char *standard_opcode_lengths
;
129 /* offsets and sizes of debugging sections */
131 static file_ptr dwarf_info_offset
;
132 static file_ptr dwarf_abbrev_offset
;
133 static file_ptr dwarf_line_offset
;
134 static file_ptr dwarf_pubnames_offset
;
135 static file_ptr dwarf_aranges_offset
;
136 static file_ptr dwarf_loc_offset
;
137 static file_ptr dwarf_macinfo_offset
;
138 static file_ptr dwarf_str_offset
;
139 static file_ptr dwarf_ranges_offset
;
140 file_ptr dwarf_frame_offset
;
141 file_ptr dwarf_eh_frame_offset
;
143 static unsigned int dwarf_info_size
;
144 static unsigned int dwarf_abbrev_size
;
145 static unsigned int dwarf_line_size
;
146 static unsigned int dwarf_pubnames_size
;
147 static unsigned int dwarf_aranges_size
;
148 static unsigned int dwarf_loc_size
;
149 static unsigned int dwarf_macinfo_size
;
150 static unsigned int dwarf_str_size
;
151 static unsigned int dwarf_ranges_size
;
152 unsigned int dwarf_frame_size
;
153 unsigned int dwarf_eh_frame_size
;
155 static asection
*dwarf_info_section
;
156 static asection
*dwarf_abbrev_section
;
157 static asection
*dwarf_line_section
;
158 static asection
*dwarf_pubnames_section
;
159 static asection
*dwarf_aranges_section
;
160 static asection
*dwarf_loc_section
;
161 static asection
*dwarf_macinfo_section
;
162 static asection
*dwarf_str_section
;
163 static asection
*dwarf_ranges_section
;
164 asection
*dwarf_frame_section
;
165 asection
*dwarf_eh_frame_section
;
167 /* names of the debugging sections */
169 #define INFO_SECTION ".debug_info"
170 #define ABBREV_SECTION ".debug_abbrev"
171 #define LINE_SECTION ".debug_line"
172 #define PUBNAMES_SECTION ".debug_pubnames"
173 #define ARANGES_SECTION ".debug_aranges"
174 #define LOC_SECTION ".debug_loc"
175 #define MACINFO_SECTION ".debug_macinfo"
176 #define STR_SECTION ".debug_str"
177 #define RANGES_SECTION ".debug_ranges"
178 #define FRAME_SECTION ".debug_frame"
179 #define EH_FRAME_SECTION ".eh_frame"
181 /* local data types */
183 /* We hold several abbreviation tables in memory at the same time. */
184 #ifndef ABBREV_HASH_SIZE
185 #define ABBREV_HASH_SIZE 121
188 /* The data in a compilation unit header, after target2host
189 translation, looks like this. */
190 struct comp_unit_head
192 unsigned long length
;
194 unsigned int abbrev_offset
;
195 unsigned char addr_size
;
196 unsigned char signed_addr_p
;
197 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
198 unsigned int initial_length_size
; /* size of the length field; either
201 /* Offset to the first byte of this compilation unit header in the
202 * .debug_info section, for resolving relative reference dies. */
206 /* Pointer to this compilation unit header in the .debug_info
211 /* Pointer to the first die of this compilatio unit. This will
212 * be the first byte following the compilation unit header. */
216 /* Pointer to the next compilation unit header in the program. */
218 struct comp_unit_head
*next
;
220 /* DWARF abbreviation table associated with this compilation unit */
222 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
224 /* Base address of this compilation unit. */
226 CORE_ADDR base_address
;
228 /* Non-zero if base_address has been set. */
233 /* The line number information for a compilation unit (found in the
234 .debug_line section) begins with a "statement program header",
235 which contains the following information. */
238 unsigned int total_length
;
239 unsigned short version
;
240 unsigned int header_length
;
241 unsigned char minimum_instruction_length
;
242 unsigned char default_is_stmt
;
244 unsigned char line_range
;
245 unsigned char opcode_base
;
247 /* standard_opcode_lengths[i] is the number of operands for the
248 standard opcode whose value is i. This means that
249 standard_opcode_lengths[0] is unused, and the last meaningful
250 element is standard_opcode_lengths[opcode_base - 1]. */
251 unsigned char *standard_opcode_lengths
;
253 /* The include_directories table. NOTE! These strings are not
254 allocated with xmalloc; instead, they are pointers into
255 debug_line_buffer. If you try to free them, `free' will get
257 unsigned int num_include_dirs
, include_dirs_size
;
260 /* The file_names table. NOTE! These strings are not allocated
261 with xmalloc; instead, they are pointers into debug_line_buffer.
262 Don't try to free them directly. */
263 unsigned int num_file_names
, file_names_size
;
267 unsigned int dir_index
;
268 unsigned int mod_time
;
272 /* The start and end of the statement program following this
273 header. These point into dwarf_line_buffer. */
274 char *statement_program_start
, *statement_program_end
;
277 /* When we construct a partial symbol table entry we only
278 need this much information. */
279 struct partial_die_info
282 unsigned char has_children
;
283 unsigned char is_external
;
284 unsigned char is_declaration
;
285 unsigned char has_type
;
292 struct dwarf_block
*locdesc
;
293 unsigned int language
;
297 /* This data structure holds the information of an abbrev. */
300 unsigned int number
; /* number identifying abbrev */
301 enum dwarf_tag tag
; /* dwarf tag */
302 int has_children
; /* boolean */
303 unsigned int num_attrs
; /* number of attributes */
304 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
305 struct abbrev_info
*next
; /* next in chain */
310 enum dwarf_attribute name
;
311 enum dwarf_form form
;
314 /* This data structure holds a complete die structure. */
317 enum dwarf_tag tag
; /* Tag indicating type of die */
318 unsigned short has_children
; /* Does the die have children */
319 unsigned int abbrev
; /* Abbrev number */
320 unsigned int offset
; /* Offset in .debug_info section */
321 unsigned int num_attrs
; /* Number of attributes */
322 struct attribute
*attrs
; /* An array of attributes */
323 struct die_info
*next_ref
; /* Next die in ref hash table */
324 struct die_info
*next
; /* Next die in linked list */
325 struct type
*type
; /* Cached type information */
328 /* Attributes have a name and a value */
331 enum dwarf_attribute name
;
332 enum dwarf_form form
;
336 struct dwarf_block
*blk
;
344 struct function_range
347 CORE_ADDR lowpc
, highpc
;
349 struct function_range
*next
;
352 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
354 /* Get at parts of an attribute structure */
356 #define DW_STRING(attr) ((attr)->u.str)
357 #define DW_UNSND(attr) ((attr)->u.unsnd)
358 #define DW_BLOCK(attr) ((attr)->u.blk)
359 #define DW_SND(attr) ((attr)->u.snd)
360 #define DW_ADDR(attr) ((attr)->u.addr)
362 /* Blocks are a bunch of untyped bytes. */
369 #ifndef ATTR_ALLOC_CHUNK
370 #define ATTR_ALLOC_CHUNK 4
373 /* A hash table of die offsets for following references. */
374 #ifndef REF_HASH_SIZE
375 #define REF_HASH_SIZE 1021
378 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
380 /* Obstack for allocating temporary storage used during symbol reading. */
381 static struct obstack dwarf2_tmp_obstack
;
383 /* Offset to the first byte of the current compilation unit header,
384 for resolving relative reference dies. */
385 static unsigned int cu_header_offset
;
387 /* Allocate fields for structs, unions and enums in this size. */
388 #ifndef DW_FIELD_ALLOC_CHUNK
389 #define DW_FIELD_ALLOC_CHUNK 4
392 /* The language we are debugging. */
393 static enum language cu_language
;
394 static const struct language_defn
*cu_language_defn
;
396 /* Actually data from the sections. */
397 static char *dwarf_info_buffer
;
398 static char *dwarf_abbrev_buffer
;
399 static char *dwarf_line_buffer
;
400 static char *dwarf_str_buffer
;
401 static char *dwarf_macinfo_buffer
;
402 static char *dwarf_ranges_buffer
;
403 static char *dwarf_loc_buffer
;
405 /* A zeroed version of a partial die for initialization purposes. */
406 static struct partial_die_info zeroed_partial_die
;
408 /* The generic symbol table building routines have separate lists for
409 file scope symbols and all all other scopes (local scopes). So
410 we need to select the right one to pass to add_symbol_to_list().
411 We do it by keeping a pointer to the correct list in list_in_scope.
413 FIXME: The original dwarf code just treated the file scope as the first
414 local scope, and all other local scopes as nested local scopes, and worked
415 fine. Check to see if we really need to distinguish these
417 static struct pending
**list_in_scope
= &file_symbols
;
419 /* FIXME: decode_locdesc sets these variables to describe the location
420 to the caller. These ought to be a structure or something. If
421 none of the flags are set, the object lives at the address returned
422 by decode_locdesc. */
424 static int optimized_out
; /* No ops in location in expression,
425 so object was optimized out. */
426 static int isreg
; /* Object lives in register.
427 decode_locdesc's return value is
428 the register number. */
429 static int offreg
; /* Object's address is the sum of the
430 register specified by basereg, plus
431 the offset returned. */
432 static int basereg
; /* See `offreg'. */
433 static int isderef
; /* Value described by flags above is
434 the address of a pointer to the object. */
435 static int islocal
; /* Variable is at the returned offset
436 from the frame start, but there's
437 no identified frame pointer for
438 this function, so we can't say
439 which register it's relative to;
441 static int is_thread_local
; /* Variable is at a constant offset in the
442 thread-local storage block for the
443 current thread and the dynamic linker
444 module containing this expression.
445 decode_locdesc returns the offset from
448 /* DW_AT_frame_base values for the current function.
449 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
450 contains the register number for the frame register.
451 frame_base_offset is the offset from the frame register to the
452 virtual stack frame. */
453 static int frame_base_reg
;
454 static CORE_ADDR frame_base_offset
;
456 /* This value is added to each symbol value. FIXME: Generalize to
457 the section_offsets structure used by dbxread (once this is done,
458 pass the appropriate section number to end_symtab). */
459 static CORE_ADDR baseaddr
; /* Add to each symbol value */
461 /* We put a pointer to this structure in the read_symtab_private field
463 The complete dwarf information for an objfile is kept in the
464 psymbol_obstack, so that absolute die references can be handled.
465 Most of the information in this structure is related to an entire
466 object file and could be passed via the sym_private field of the objfile.
467 It is however conceivable that dwarf2 might not be the only type
468 of symbols read from an object file. */
472 /* Pointer to start of dwarf info buffer for the objfile. */
474 char *dwarf_info_buffer
;
476 /* Offset in dwarf_info_buffer for this compilation unit. */
478 unsigned long dwarf_info_offset
;
480 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
482 char *dwarf_abbrev_buffer
;
484 /* Size of dwarf abbreviation section for the objfile. */
486 unsigned int dwarf_abbrev_size
;
488 /* Pointer to start of dwarf line buffer for the objfile. */
490 char *dwarf_line_buffer
;
492 /* Size of dwarf_line_buffer, in bytes. */
494 unsigned int dwarf_line_size
;
496 /* Pointer to start of dwarf string buffer for the objfile. */
498 char *dwarf_str_buffer
;
500 /* Size of dwarf string section for the objfile. */
502 unsigned int dwarf_str_size
;
504 /* Pointer to start of dwarf macro buffer for the objfile. */
506 char *dwarf_macinfo_buffer
;
508 /* Size of dwarf macinfo section for the objfile. */
510 unsigned int dwarf_macinfo_size
;
512 /* Pointer to start of dwarf ranges buffer for the objfile. */
514 char *dwarf_ranges_buffer
;
516 /* Size of dwarf ranges buffer for the objfile. */
518 unsigned int dwarf_ranges_size
;
520 /* Pointer to start of dwarf locations buffer for the objfile. */
522 char *dwarf_loc_buffer
;
524 /* Size of dwarf locations buffer for the objfile. */
526 unsigned int dwarf_loc_size
;
529 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
530 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
531 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
532 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
533 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
534 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
535 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
536 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
537 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
538 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
539 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
540 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
541 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
542 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
543 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
545 /* Maintain an array of referenced fundamental types for the current
546 compilation unit being read. For DWARF version 1, we have to construct
547 the fundamental types on the fly, since no information about the
548 fundamental types is supplied. Each such fundamental type is created by
549 calling a language dependent routine to create the type, and then a
550 pointer to that type is then placed in the array at the index specified
551 by it's FT_<TYPENAME> value. The array has a fixed size set by the
552 FT_NUM_MEMBERS compile time constant, which is the number of predefined
553 fundamental types gdb knows how to construct. */
554 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
556 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
557 but this would require a corresponding change in unpack_field_as_long
559 static int bits_per_byte
= 8;
561 /* The routines that read and process dies for a C struct or C++ class
562 pass lists of data member fields and lists of member function fields
563 in an instance of a field_info structure, as defined below. */
566 /* List of data member and baseclasses fields. */
569 struct nextfield
*next
;
576 /* Number of fields. */
579 /* Number of baseclasses. */
582 /* Set if the accesibility of one of the fields is not public. */
583 int non_public_fields
;
585 /* Member function fields array, entries are allocated in the order they
586 are encountered in the object file. */
589 struct nextfnfield
*next
;
590 struct fn_field fnfield
;
594 /* Member function fieldlist array, contains name of possibly overloaded
595 member function, number of overloaded member functions and a pointer
596 to the head of the member function field chain. */
601 struct nextfnfield
*head
;
605 /* Number of entries in the fnfieldlists array. */
609 /* Various complaints about symbol reading that don't abort the process */
612 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
614 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
619 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
621 complaint (&symfile_complaints
,
622 "statement list doesn't fit in .debug_line section");
626 dwarf2_complex_location_expr_complaint (void)
628 complaint (&symfile_complaints
, "location expression too complex");
632 dwarf2_unsupported_at_frame_base_complaint (const char *arg1
)
634 complaint (&symfile_complaints
,
635 "unsupported DW_AT_frame_base for function '%s'", arg1
);
639 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
642 complaint (&symfile_complaints
,
643 "const value length mismatch for '%s', got %d, expected %d", arg1
,
648 dwarf2_macros_too_long_complaint (void)
650 complaint (&symfile_complaints
,
651 "macro info runs off end of `.debug_macinfo' section");
655 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
657 complaint (&symfile_complaints
,
658 "macro debug info contains a malformed macro definition:\n`%s'",
663 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
665 complaint (&symfile_complaints
,
666 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
669 /* local function prototypes */
671 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
674 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
677 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
679 static char *scan_partial_symbols (char *, struct objfile
*,
680 CORE_ADDR
*, CORE_ADDR
*,
681 const struct comp_unit_head
*);
683 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
684 const struct comp_unit_head
*);
686 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
688 static void psymtab_to_symtab_1 (struct partial_symtab
*);
690 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int,
693 static void dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
);
695 static void dwarf2_empty_abbrev_table (void *);
697 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
698 const struct comp_unit_head
*cu_header
);
700 static char *read_partial_die (struct partial_die_info
*,
702 const struct comp_unit_head
*);
704 static char *read_full_die (struct die_info
**, bfd
*, char *,
705 const struct comp_unit_head
*);
707 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
708 bfd
*, char *, const struct comp_unit_head
*);
710 static char *read_attribute_value (struct attribute
*, unsigned,
711 bfd
*, char *, const struct comp_unit_head
*);
713 static unsigned int read_1_byte (bfd
*, char *);
715 static int read_1_signed_byte (bfd
*, char *);
717 static unsigned int read_2_bytes (bfd
*, char *);
719 static unsigned int read_4_bytes (bfd
*, char *);
721 static unsigned long read_8_bytes (bfd
*, char *);
723 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
726 static LONGEST
read_initial_length (bfd
*, char *,
727 struct comp_unit_head
*, int *bytes_read
);
729 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
732 static char *read_n_bytes (bfd
*, char *, unsigned int);
734 static char *read_string (bfd
*, char *, unsigned int *);
736 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
739 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
741 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
743 static void set_cu_language (unsigned int);
745 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
747 static int die_is_declaration (struct die_info
*);
749 static void free_line_header (struct line_header
*lh
);
751 static struct line_header
*(dwarf_decode_line_header
752 (unsigned int offset
,
754 const struct comp_unit_head
*cu_header
));
756 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
757 const struct comp_unit_head
*);
759 static void dwarf2_start_subfile (char *, char *);
761 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
762 struct objfile
*, const struct comp_unit_head
*);
764 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
765 struct objfile
*, const struct comp_unit_head
*);
767 static void dwarf2_const_value_data (struct attribute
*attr
,
771 static struct type
*die_type (struct die_info
*, struct objfile
*,
772 const struct comp_unit_head
*);
774 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
775 const struct comp_unit_head
*);
778 static struct type
*type_at_offset (unsigned int, struct objfile
*);
781 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
782 const struct comp_unit_head
*);
784 static void read_type_die (struct die_info
*, struct objfile
*,
785 const struct comp_unit_head
*);
787 static void read_typedef (struct die_info
*, struct objfile
*,
788 const struct comp_unit_head
*);
790 static void read_base_type (struct die_info
*, struct objfile
*);
792 static void read_file_scope (struct die_info
*, struct objfile
*,
793 const struct comp_unit_head
*);
795 static void read_func_scope (struct die_info
*, struct objfile
*,
796 const struct comp_unit_head
*);
798 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
799 const struct comp_unit_head
*);
801 static int dwarf2_get_pc_bounds (struct die_info
*,
802 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*,
803 const struct comp_unit_head
*);
805 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
806 struct objfile
*, const struct comp_unit_head
*);
808 static void dwarf2_attach_fields_to_type (struct field_info
*,
809 struct type
*, struct objfile
*);
811 static void dwarf2_add_member_fn (struct field_info
*,
812 struct die_info
*, struct type
*,
813 struct objfile
*objfile
,
814 const struct comp_unit_head
*);
816 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
817 struct type
*, struct objfile
*);
819 static void read_structure_scope (struct die_info
*, struct objfile
*,
820 const struct comp_unit_head
*);
822 static void read_common_block (struct die_info
*, struct objfile
*,
823 const struct comp_unit_head
*);
825 static void read_namespace (struct die_info
*die
, struct objfile
*objfile
,
826 const struct comp_unit_head
*cu_header
);
828 static void read_enumeration (struct die_info
*, struct objfile
*,
829 const struct comp_unit_head
*);
831 static struct type
*dwarf_base_type (int, int, struct objfile
*);
833 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
834 const struct comp_unit_head
*);
836 static void read_array_type (struct die_info
*, struct objfile
*,
837 const struct comp_unit_head
*);
839 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
840 const struct comp_unit_head
*);
842 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
843 const struct comp_unit_head
*);
845 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
846 const struct comp_unit_head
*);
848 static void read_tag_const_type (struct die_info
*, struct objfile
*,
849 const struct comp_unit_head
*);
851 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
852 const struct comp_unit_head
*);
854 static void read_tag_string_type (struct die_info
*, struct objfile
*);
856 static void read_subroutine_type (struct die_info
*, struct objfile
*,
857 const struct comp_unit_head
*);
859 static struct die_info
*read_comp_unit (char *, bfd
*,
860 const struct comp_unit_head
*);
862 static void free_die_list (struct die_info
*);
864 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
866 static void process_die (struct die_info
*, struct objfile
*,
867 const struct comp_unit_head
*);
869 static char *dwarf2_linkage_name (struct die_info
*);
871 static char *dwarf2_name (struct die_info
*die
);
873 static struct die_info
*dwarf2_extension (struct die_info
*die
);
875 static char *dwarf_tag_name (unsigned int);
877 static char *dwarf_attr_name (unsigned int);
879 static char *dwarf_form_name (unsigned int);
881 static char *dwarf_stack_op_name (unsigned int);
883 static char *dwarf_bool_name (unsigned int);
885 static char *dwarf_type_encoding_name (unsigned int);
888 static char *dwarf_cfi_name (unsigned int);
890 struct die_info
*copy_die (struct die_info
*);
893 static struct die_info
*sibling_die (struct die_info
*);
895 static void dump_die (struct die_info
*);
897 static void dump_die_list (struct die_info
*);
899 static void store_in_ref_table (unsigned int, struct die_info
*);
901 static void dwarf2_empty_hash_tables (void);
903 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
905 static struct die_info
*follow_die_ref (unsigned int);
907 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
909 /* memory allocation interface */
911 static void dwarf2_free_tmp_obstack (void *);
913 static struct dwarf_block
*dwarf_alloc_block (void);
915 static struct abbrev_info
*dwarf_alloc_abbrev (void);
917 static struct die_info
*dwarf_alloc_die (void);
919 static void initialize_cu_func_list (void);
921 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
923 static void dwarf_decode_macros (struct line_header
*, unsigned int,
924 char *, bfd
*, const struct comp_unit_head
*,
927 static int attr_form_is_block (struct attribute
*);
930 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
931 const struct comp_unit_head
*,
932 struct objfile
*objfile
);
934 /* Try to locate the sections we need for DWARF 2 debugging
935 information and return true if we have enough to do something. */
938 dwarf2_has_info (bfd
*abfd
)
940 dwarf_info_offset
= 0;
941 dwarf_abbrev_offset
= 0;
942 dwarf_line_offset
= 0;
943 dwarf_str_offset
= 0;
944 dwarf_macinfo_offset
= 0;
945 dwarf_frame_offset
= 0;
946 dwarf_eh_frame_offset
= 0;
947 dwarf_ranges_offset
= 0;
948 dwarf_loc_offset
= 0;
950 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
951 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
961 /* This function is mapped across the sections and remembers the
962 offset and size of each of the debugging sections we are interested
966 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
968 if (STREQ (sectp
->name
, INFO_SECTION
))
970 dwarf_info_offset
= sectp
->filepos
;
971 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
972 dwarf_info_section
= sectp
;
974 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
976 dwarf_abbrev_offset
= sectp
->filepos
;
977 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
978 dwarf_abbrev_section
= sectp
;
980 else if (STREQ (sectp
->name
, LINE_SECTION
))
982 dwarf_line_offset
= sectp
->filepos
;
983 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
984 dwarf_line_section
= sectp
;
986 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
988 dwarf_pubnames_offset
= sectp
->filepos
;
989 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
990 dwarf_pubnames_section
= sectp
;
992 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
994 dwarf_aranges_offset
= sectp
->filepos
;
995 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
996 dwarf_aranges_section
= 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
);
1002 dwarf_loc_section
= sectp
;
1004 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
1006 dwarf_macinfo_offset
= sectp
->filepos
;
1007 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1008 dwarf_macinfo_section
= sectp
;
1010 else if (STREQ (sectp
->name
, STR_SECTION
))
1012 dwarf_str_offset
= sectp
->filepos
;
1013 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1014 dwarf_str_section
= sectp
;
1016 else if (STREQ (sectp
->name
, FRAME_SECTION
))
1018 dwarf_frame_offset
= sectp
->filepos
;
1019 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1020 dwarf_frame_section
= sectp
;
1022 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
1024 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1025 if (aflag
& SEC_HAS_CONTENTS
)
1027 dwarf_eh_frame_offset
= sectp
->filepos
;
1028 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1029 dwarf_eh_frame_section
= sectp
;
1032 else if (STREQ (sectp
->name
, RANGES_SECTION
))
1034 dwarf_ranges_offset
= sectp
->filepos
;
1035 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1036 dwarf_ranges_section
= sectp
;
1040 /* Build a partial symbol table. */
1043 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1046 /* We definitely need the .debug_info and .debug_abbrev sections */
1048 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1051 dwarf_info_section
);
1052 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1053 dwarf_abbrev_offset
,
1055 dwarf_abbrev_section
);
1057 if (dwarf_line_offset
)
1058 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1061 dwarf_line_section
);
1063 dwarf_line_buffer
= NULL
;
1065 if (dwarf_str_offset
)
1066 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1071 dwarf_str_buffer
= NULL
;
1073 if (dwarf_macinfo_offset
)
1074 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1075 dwarf_macinfo_offset
,
1077 dwarf_macinfo_section
);
1079 dwarf_macinfo_buffer
= NULL
;
1081 if (dwarf_ranges_offset
)
1082 dwarf_ranges_buffer
= dwarf2_read_section (objfile
,
1083 dwarf_ranges_offset
,
1085 dwarf_ranges_section
);
1087 dwarf_ranges_buffer
= NULL
;
1089 if (dwarf_loc_offset
)
1090 dwarf_loc_buffer
= dwarf2_read_section (objfile
,
1095 dwarf_loc_buffer
= NULL
;
1098 || (objfile
->global_psymbols
.size
== 0
1099 && objfile
->static_psymbols
.size
== 0))
1101 init_psymbol_list (objfile
, 1024);
1105 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1107 /* Things are significantly easier if we have .debug_aranges and
1108 .debug_pubnames sections */
1110 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1114 /* only test this case for now */
1116 /* In this case we have to work a bit harder */
1117 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1122 /* Build the partial symbol table from the information in the
1123 .debug_pubnames and .debug_aranges sections. */
1126 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1128 bfd
*abfd
= objfile
->obfd
;
1129 char *aranges_buffer
, *pubnames_buffer
;
1130 char *aranges_ptr
, *pubnames_ptr
;
1131 unsigned int entry_length
, version
, info_offset
, info_size
;
1133 pubnames_buffer
= dwarf2_read_section (objfile
,
1134 dwarf_pubnames_offset
,
1135 dwarf_pubnames_size
,
1136 dwarf_pubnames_section
);
1137 pubnames_ptr
= pubnames_buffer
;
1138 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1140 struct comp_unit_head cu_header
;
1143 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1145 pubnames_ptr
+= bytes_read
;
1146 version
= read_1_byte (abfd
, pubnames_ptr
);
1148 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1150 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1154 aranges_buffer
= dwarf2_read_section (objfile
,
1155 dwarf_aranges_offset
,
1157 dwarf_aranges_section
);
1162 /* Read in the comp unit header information from the debug_info at
1166 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1167 char *info_ptr
, bfd
*abfd
)
1171 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1173 info_ptr
+= bytes_read
;
1174 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1176 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1178 info_ptr
+= bytes_read
;
1179 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1181 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1182 if (signed_addr
< 0)
1183 internal_error (__FILE__
, __LINE__
,
1184 "read_comp_unit_head: dwarf from non elf file");
1185 cu_header
->signed_addr_p
= signed_addr
;
1189 /* Build the partial symbol table by doing a quick pass through the
1190 .debug_info and .debug_abbrev sections. */
1193 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1195 /* Instead of reading this into a big buffer, we should probably use
1196 mmap() on architectures that support it. (FIXME) */
1197 bfd
*abfd
= objfile
->obfd
;
1198 char *info_ptr
, *abbrev_ptr
;
1199 char *beg_of_comp_unit
;
1200 struct partial_die_info comp_unit_die
;
1201 struct partial_symtab
*pst
;
1202 struct cleanup
*back_to
;
1203 CORE_ADDR lowpc
, highpc
;
1205 info_ptr
= dwarf_info_buffer
;
1206 abbrev_ptr
= dwarf_abbrev_buffer
;
1208 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1209 the partial symbol scan, like attribute values.
1211 We could reduce our peak memory consumption during partial symbol
1212 table construction by freeing stuff from this obstack more often
1213 --- say, after processing each compilation unit, or each die ---
1214 but it turns out that this saves almost nothing. For an
1215 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1216 on dwarf2_tmp_obstack. Some investigation showed:
1218 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1219 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1220 all fixed-length values not requiring dynamic allocation.
1222 2) 30% of the attributes used the form DW_FORM_string. For
1223 DW_FORM_string, read_attribute simply hands back a pointer to
1224 the null-terminated string in dwarf_info_buffer, so no dynamic
1225 allocation is needed there either.
1227 3) The remaining 1% of the attributes all used DW_FORM_block1.
1228 75% of those were DW_AT_frame_base location lists for
1229 functions; the rest were DW_AT_location attributes, probably
1230 for the global variables.
1232 Anyway, what this all means is that the memory the dwarf2
1233 reader uses as temporary space reading partial symbols is about
1234 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1236 obstack_init (&dwarf2_tmp_obstack
);
1237 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1239 /* Since the objects we're extracting from dwarf_info_buffer vary in
1240 length, only the individual functions to extract them (like
1241 read_comp_unit_head and read_partial_die) can really know whether
1242 the buffer is large enough to hold another complete object.
1244 At the moment, they don't actually check that. If
1245 dwarf_info_buffer holds just one extra byte after the last
1246 compilation unit's dies, then read_comp_unit_head will happily
1247 read off the end of the buffer. read_partial_die is similarly
1248 casual. Those functions should be fixed.
1250 For this loop condition, simply checking whether there's any data
1251 left at all should be sufficient. */
1252 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1254 struct comp_unit_head cu_header
;
1255 beg_of_comp_unit
= info_ptr
;
1256 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1258 if (cu_header
.version
!= 2)
1260 error ("Dwarf Error: wrong version in compilation unit header (is %d, should be %d) [in module %s]", cu_header
.version
, 2, bfd_get_filename (abfd
));
1263 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1265 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1266 (long) cu_header
.abbrev_offset
,
1267 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1268 bfd_get_filename (abfd
));
1271 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1272 > dwarf_info_buffer
+ dwarf_info_size
)
1274 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1275 (long) cu_header
.length
,
1276 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1277 bfd_get_filename (abfd
));
1280 /* Complete the cu_header */
1281 cu_header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1282 cu_header
.first_die_ptr
= info_ptr
;
1283 cu_header
.cu_head_ptr
= beg_of_comp_unit
;
1285 /* Read the abbrevs for this compilation unit into a table */
1286 dwarf2_read_abbrevs (abfd
, &cu_header
);
1287 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1289 /* Read the compilation unit die */
1290 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1293 /* Set the language we're debugging */
1294 set_cu_language (comp_unit_die
.language
);
1296 /* Allocate a new partial symbol table structure */
1297 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1298 comp_unit_die
.name
? comp_unit_die
.name
: "",
1299 comp_unit_die
.lowpc
,
1300 objfile
->global_psymbols
.next
,
1301 objfile
->static_psymbols
.next
);
1303 pst
->read_symtab_private
= (char *)
1304 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1305 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1306 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1307 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1308 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1309 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1310 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1311 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1312 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1313 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1314 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1315 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1316 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1317 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1318 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1319 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1320 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1322 /* Store the function that reads in the rest of the symbol table */
1323 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1325 /* Check if comp unit has_children.
1326 If so, read the rest of the partial symbols from this comp unit.
1327 If not, there's no more debug_info for this comp unit. */
1328 if (comp_unit_die
.has_children
)
1330 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1333 /* If the compilation unit didn't have an explicit address range,
1334 then use the information extracted from its child dies. */
1335 if (! comp_unit_die
.has_pc_info
)
1337 comp_unit_die
.lowpc
= lowpc
;
1338 comp_unit_die
.highpc
= highpc
;
1341 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1342 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1344 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1345 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1346 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1347 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1348 sort_pst_symbols (pst
);
1350 /* If there is already a psymtab or symtab for a file of this
1351 name, remove it. (If there is a symtab, more drastic things
1352 also happen.) This happens in VxWorks. */
1353 free_named_symtabs (pst
->filename
);
1355 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1356 + cu_header
.initial_length_size
;
1358 do_cleanups (back_to
);
1361 /* Read in all interesting dies to the end of the compilation unit. */
1364 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1365 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1366 const struct comp_unit_head
*cu_header
)
1368 bfd
*abfd
= objfile
->obfd
;
1369 struct partial_die_info pdi
;
1371 /* This function is called after we've read in the comp_unit_die in
1372 order to read its children. We start the nesting level at 1 since
1373 we have pushed 1 level down in order to read the comp unit's children.
1374 The comp unit itself is at level 0, so we stop reading when we pop
1375 back to that level. */
1377 int nesting_level
= 1;
1379 /* We only want to read in symbols corresponding to variables or
1380 other similar objects that are global or static. Normally, these
1381 are all children of the DW_TAG_compile_unit die, so are all at
1382 level 1. But C++ namespaces give ries to DW_TAG_namespace dies
1383 whose children are global objects. So we keep track of what
1384 level we currently think of as referring to file scope; this
1385 should always equal 1 plus the number of namespaces that we are
1386 currently nested within. */
1388 int file_scope_level
= 1;
1390 *lowpc
= ((CORE_ADDR
) -1);
1391 *highpc
= ((CORE_ADDR
) 0);
1393 while (nesting_level
)
1395 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1397 /* Anonymous namespaces have no name but are interesting. */
1399 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
)
1403 case DW_TAG_subprogram
:
1404 if (pdi
.has_pc_info
)
1406 if (pdi
.lowpc
< *lowpc
)
1410 if (pdi
.highpc
> *highpc
)
1412 *highpc
= pdi
.highpc
;
1414 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1415 && !pdi
.is_declaration
)
1417 add_partial_symbol (&pdi
, objfile
, cu_header
);
1421 case DW_TAG_variable
:
1422 case DW_TAG_typedef
:
1423 case DW_TAG_class_type
:
1424 case DW_TAG_structure_type
:
1425 case DW_TAG_union_type
:
1426 case DW_TAG_enumeration_type
:
1427 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1428 && !pdi
.is_declaration
)
1430 add_partial_symbol (&pdi
, objfile
, cu_header
);
1433 case DW_TAG_enumerator
:
1434 /* File scope enumerators are added to the partial
1435 symbol table. They're children of the enumeration
1436 type die, so they occur at a level one higher than we
1437 normally look for. */
1438 if (nesting_level
== file_scope_level
+ 1)
1439 add_partial_symbol (&pdi
, objfile
, cu_header
);
1441 case DW_TAG_base_type
:
1442 /* File scope base type definitions are added to the partial
1444 if (nesting_level
== file_scope_level
)
1445 add_partial_symbol (&pdi
, objfile
, cu_header
);
1447 case DW_TAG_namespace
:
1448 /* FIXME: carlton/2002-10-16: we're not yet doing
1449 anything useful with this, but for now make sure that
1450 these tags at least don't cause us to miss any
1451 important symbols. */
1452 if (pdi
.has_children
)
1459 /* If the die has a sibling, skip to the sibling. Do not skip
1460 enumeration types, we want to record their enumerators. Do
1461 not skip namespaces, we want to record symbols inside
1464 && pdi
.tag
!= DW_TAG_enumeration_type
1465 && pdi
.tag
!= DW_TAG_namespace
)
1467 info_ptr
= pdi
.sibling
;
1469 else if (pdi
.has_children
)
1471 /* Die has children, but either the optional DW_AT_sibling
1472 attribute is missing or we want to look at them. */
1479 /* If this is the end of a DW_TAG_namespace entry, then
1480 decrease the file_scope_level, too. */
1481 if (nesting_level
< file_scope_level
)
1484 gdb_assert (nesting_level
== file_scope_level
);
1489 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1490 from `maint check'. */
1491 if (*lowpc
== ((CORE_ADDR
) -1))
1497 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1498 const struct comp_unit_head
*cu_header
)
1504 case DW_TAG_subprogram
:
1505 if (pdi
->is_external
)
1507 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1508 mst_text, objfile); */
1509 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1510 VAR_DOMAIN
, LOC_BLOCK
,
1511 &objfile
->global_psymbols
,
1512 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1516 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1517 mst_file_text, objfile); */
1518 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1519 VAR_DOMAIN
, LOC_BLOCK
,
1520 &objfile
->static_psymbols
,
1521 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1524 case DW_TAG_variable
:
1525 if (pdi
->is_external
)
1528 Don't enter into the minimal symbol tables as there is
1529 a minimal symbol table entry from the ELF symbols already.
1530 Enter into partial symbol table if it has a location
1531 descriptor or a type.
1532 If the location descriptor is missing, new_symbol will create
1533 a LOC_UNRESOLVED symbol, the address of the variable will then
1534 be determined from the minimal symbol table whenever the variable
1536 The address for the partial symbol table entry is not
1537 used by GDB, but it comes in handy for debugging partial symbol
1541 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1542 if (pdi
->locdesc
|| pdi
->has_type
)
1543 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1544 VAR_DOMAIN
, LOC_STATIC
,
1545 &objfile
->global_psymbols
,
1546 0, addr
+ baseaddr
, cu_language
, objfile
);
1550 /* Static Variable. Skip symbols without location descriptors. */
1551 if (pdi
->locdesc
== NULL
)
1553 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1554 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1555 mst_file_data, objfile); */
1556 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1557 VAR_DOMAIN
, LOC_STATIC
,
1558 &objfile
->static_psymbols
,
1559 0, addr
+ baseaddr
, cu_language
, objfile
);
1562 case DW_TAG_typedef
:
1563 case DW_TAG_base_type
:
1564 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1565 VAR_DOMAIN
, LOC_TYPEDEF
,
1566 &objfile
->static_psymbols
,
1567 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1569 case DW_TAG_class_type
:
1570 case DW_TAG_structure_type
:
1571 case DW_TAG_union_type
:
1572 case DW_TAG_enumeration_type
:
1573 /* Skip aggregate types without children, these are external
1575 if (pdi
->has_children
== 0)
1577 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1578 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1579 &objfile
->static_psymbols
,
1580 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1582 if (cu_language
== language_cplus
)
1584 /* For C++, these implicitly act as typedefs as well. */
1585 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1586 VAR_DOMAIN
, LOC_TYPEDEF
,
1587 &objfile
->static_psymbols
,
1588 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1591 case DW_TAG_enumerator
:
1592 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1593 VAR_DOMAIN
, LOC_CONST
,
1594 &objfile
->static_psymbols
,
1595 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1602 /* Expand this partial symbol table into a full symbol table. */
1605 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1607 /* FIXME: This is barely more than a stub. */
1612 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1618 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1619 gdb_flush (gdb_stdout
);
1622 psymtab_to_symtab_1 (pst
);
1624 /* Finish up the debug error message. */
1626 printf_filtered ("done.\n");
1632 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1634 struct objfile
*objfile
= pst
->objfile
;
1635 bfd
*abfd
= objfile
->obfd
;
1636 struct comp_unit_head cu_header
;
1637 struct die_info
*dies
;
1638 unsigned long offset
;
1639 CORE_ADDR lowpc
, highpc
;
1640 struct die_info
*child_die
;
1642 struct symtab
*symtab
;
1643 struct cleanup
*back_to
;
1644 struct attribute
*attr
;
1646 /* Set local variables from the partial symbol table info. */
1647 offset
= DWARF_INFO_OFFSET (pst
);
1648 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1649 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1650 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1651 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1652 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1653 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1654 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1655 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1656 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1657 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1658 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1659 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1660 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1661 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1662 cu_header_offset
= offset
;
1663 info_ptr
= dwarf_info_buffer
+ offset
;
1665 obstack_init (&dwarf2_tmp_obstack
);
1666 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1669 make_cleanup (really_free_pendings
, NULL
);
1671 /* read in the comp_unit header */
1672 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1674 /* Read the abbrevs for this compilation unit */
1675 dwarf2_read_abbrevs (abfd
, &cu_header
);
1676 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1678 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1680 make_cleanup_free_die_list (dies
);
1682 /* Find the base address of the compilation unit for range lists and
1683 location lists. It will normally be specified by DW_AT_low_pc.
1684 In DWARF-3 draft 4, the base address could be overridden by
1685 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1686 compilation units with discontinuous ranges. */
1688 cu_header
.base_known
= 0;
1689 cu_header
.base_address
= 0;
1691 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1694 cu_header
.base_address
= DW_ADDR (attr
);
1695 cu_header
.base_known
= 1;
1699 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1702 cu_header
.base_address
= DW_ADDR (attr
);
1703 cu_header
.base_known
= 1;
1707 /* Do line number decoding in read_file_scope () */
1708 process_die (dies
, objfile
, &cu_header
);
1710 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
, &cu_header
))
1712 /* Some compilers don't define a DW_AT_high_pc attribute for
1713 the compilation unit. If the DW_AT_high_pc is missing,
1714 synthesize it, by scanning the DIE's below the compilation unit. */
1716 if (dies
->has_children
)
1718 child_die
= dies
->next
;
1719 while (child_die
&& child_die
->tag
)
1721 if (child_die
->tag
== DW_TAG_subprogram
)
1723 CORE_ADDR low
, high
;
1725 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1726 objfile
, &cu_header
))
1728 highpc
= max (highpc
, high
);
1731 child_die
= sibling_die (child_die
);
1735 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1737 /* Set symtab language to language from DW_AT_language.
1738 If the compilation is from a C file generated by language preprocessors,
1739 do not set the language if it was already deduced by start_subfile. */
1741 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1743 symtab
->language
= cu_language
;
1745 pst
->symtab
= symtab
;
1748 do_cleanups (back_to
);
1751 /* Process a die and its children. */
1754 process_die (struct die_info
*die
, struct objfile
*objfile
,
1755 const struct comp_unit_head
*cu_header
)
1759 case DW_TAG_padding
:
1761 case DW_TAG_compile_unit
:
1762 read_file_scope (die
, objfile
, cu_header
);
1764 case DW_TAG_subprogram
:
1765 read_subroutine_type (die
, objfile
, cu_header
);
1766 read_func_scope (die
, objfile
, cu_header
);
1768 case DW_TAG_inlined_subroutine
:
1769 /* FIXME: These are ignored for now.
1770 They could be used to set breakpoints on all inlined instances
1771 of a function and make GDB `next' properly over inlined functions. */
1773 case DW_TAG_lexical_block
:
1774 case DW_TAG_try_block
:
1775 case DW_TAG_catch_block
:
1776 read_lexical_block_scope (die
, objfile
, cu_header
);
1778 case DW_TAG_class_type
:
1779 case DW_TAG_structure_type
:
1780 case DW_TAG_union_type
:
1781 read_structure_scope (die
, objfile
, cu_header
);
1783 case DW_TAG_enumeration_type
:
1784 read_enumeration (die
, objfile
, cu_header
);
1786 case DW_TAG_subroutine_type
:
1787 read_subroutine_type (die
, objfile
, cu_header
);
1789 case DW_TAG_array_type
:
1790 read_array_type (die
, objfile
, cu_header
);
1792 case DW_TAG_pointer_type
:
1793 read_tag_pointer_type (die
, objfile
, cu_header
);
1795 case DW_TAG_ptr_to_member_type
:
1796 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1798 case DW_TAG_reference_type
:
1799 read_tag_reference_type (die
, objfile
, cu_header
);
1801 case DW_TAG_string_type
:
1802 read_tag_string_type (die
, objfile
);
1804 case DW_TAG_base_type
:
1805 read_base_type (die
, objfile
);
1806 if (dwarf_attr (die
, DW_AT_name
))
1808 /* Add a typedef symbol for the base type definition. */
1809 new_symbol (die
, die
->type
, objfile
, cu_header
);
1812 case DW_TAG_common_block
:
1813 read_common_block (die
, objfile
, cu_header
);
1815 case DW_TAG_common_inclusion
:
1817 case DW_TAG_namespace
:
1818 if (!processing_has_namespace_info
)
1820 processing_has_namespace_info
= 1;
1821 processing_current_namespace
= "";
1823 read_namespace (die
, objfile
, cu_header
);
1825 case DW_TAG_imported_declaration
:
1826 case DW_TAG_imported_module
:
1827 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1828 information contained in these. DW_TAG_imported_declaration
1829 dies shouldn't have children; DW_TAG_imported_module dies
1830 shouldn't in the C++ case, but conceivably could in the
1831 Fortran case, so we'll have to replace this gdb_assert if
1832 Fortran compilers start generating that info. */
1833 if (!processing_has_namespace_info
)
1835 processing_has_namespace_info
= 1;
1836 processing_current_namespace
= "";
1838 gdb_assert (!die
->has_children
);
1841 new_symbol (die
, NULL
, objfile
, cu_header
);
1847 initialize_cu_func_list (void)
1849 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1853 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1854 const struct comp_unit_head
*cu_header
)
1856 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1857 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1858 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1859 struct attribute
*attr
;
1860 char *name
= "<unknown>";
1861 char *comp_dir
= NULL
;
1862 struct die_info
*child_die
;
1863 bfd
*abfd
= objfile
->obfd
;
1864 struct line_header
*line_header
= 0;
1866 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
1868 if (die
->has_children
)
1870 child_die
= die
->next
;
1871 while (child_die
&& child_die
->tag
)
1873 if (child_die
->tag
== DW_TAG_subprogram
)
1875 CORE_ADDR low
, high
;
1877 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1878 objfile
, cu_header
))
1880 lowpc
= min (lowpc
, low
);
1881 highpc
= max (highpc
, high
);
1884 child_die
= sibling_die (child_die
);
1889 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1890 from finish_block. */
1891 if (lowpc
== ((CORE_ADDR
) -1))
1896 attr
= dwarf_attr (die
, DW_AT_name
);
1899 name
= DW_STRING (attr
);
1901 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1904 comp_dir
= DW_STRING (attr
);
1907 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1908 directory, get rid of it. */
1909 char *cp
= strchr (comp_dir
, ':');
1911 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1916 if (objfile
->ei
.entry_point
>= lowpc
&&
1917 objfile
->ei
.entry_point
< highpc
)
1919 objfile
->ei
.entry_file_lowpc
= lowpc
;
1920 objfile
->ei
.entry_file_highpc
= highpc
;
1923 attr
= dwarf_attr (die
, DW_AT_language
);
1926 set_cu_language (DW_UNSND (attr
));
1929 /* We assume that we're processing GCC output. */
1930 processing_gcc_compilation
= 2;
1932 /* FIXME:Do something here. */
1933 if (dip
->at_producer
!= NULL
)
1935 handle_producer (dip
->at_producer
);
1939 /* The compilation unit may be in a different language or objfile,
1940 zero out all remembered fundamental types. */
1941 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1943 start_symtab (name
, comp_dir
, lowpc
);
1944 record_debugformat ("DWARF 2");
1946 initialize_cu_func_list ();
1948 /* Process all dies in compilation unit. */
1949 if (die
->has_children
)
1951 child_die
= die
->next
;
1952 while (child_die
&& child_die
->tag
)
1954 process_die (child_die
, objfile
, cu_header
);
1955 child_die
= sibling_die (child_die
);
1959 /* Decode line number information if present. */
1960 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1963 unsigned int line_offset
= DW_UNSND (attr
);
1964 line_header
= dwarf_decode_line_header (line_offset
,
1968 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1969 (void *) line_header
);
1970 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1974 /* Decode macro information, if present. Dwarf 2 macro information
1975 refers to information in the line number info statement program
1976 header, so we can only read it if we've read the header
1978 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1979 if (attr
&& line_header
)
1981 unsigned int macro_offset
= DW_UNSND (attr
);
1982 dwarf_decode_macros (line_header
, macro_offset
,
1983 comp_dir
, abfd
, cu_header
, objfile
);
1985 do_cleanups (back_to
);
1989 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1991 struct function_range
*thisfn
;
1993 thisfn
= (struct function_range
*)
1994 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1995 thisfn
->name
= name
;
1996 thisfn
->lowpc
= lowpc
;
1997 thisfn
->highpc
= highpc
;
1998 thisfn
->seen_line
= 0;
1999 thisfn
->next
= NULL
;
2001 if (cu_last_fn
== NULL
)
2002 cu_first_fn
= thisfn
;
2004 cu_last_fn
->next
= thisfn
;
2006 cu_last_fn
= thisfn
;
2010 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
2011 const struct comp_unit_head
*cu_header
)
2013 register struct context_stack
*new;
2016 struct die_info
*child_die
;
2017 struct attribute
*attr
;
2020 name
= dwarf2_linkage_name (die
);
2022 /* Ignore functions with missing or empty names and functions with
2023 missing or invalid low and high pc attributes. */
2024 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2030 /* Record the function range for dwarf_decode_lines. */
2031 add_to_cu_func_list (name
, lowpc
, highpc
);
2033 if (objfile
->ei
.entry_point
>= lowpc
&&
2034 objfile
->ei
.entry_point
< highpc
)
2036 objfile
->ei
.entry_func_lowpc
= lowpc
;
2037 objfile
->ei
.entry_func_highpc
= highpc
;
2040 /* Decode DW_AT_frame_base location descriptor if present, keep result
2041 for DW_OP_fbreg operands in decode_locdesc. */
2042 frame_base_reg
= -1;
2043 frame_base_offset
= 0;
2044 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2049 /* Support the .debug_loc offsets */
2050 if (attr_form_is_block (attr
))
2052 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2054 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2056 dwarf2_complex_location_expr_complaint ();
2061 dwarf2_invalid_attrib_class_complaint ("DW_AT_frame_base", name
);
2066 dwarf2_unsupported_at_frame_base_complaint (name
);
2068 frame_base_reg
= addr
;
2071 frame_base_reg
= basereg
;
2072 frame_base_offset
= addr
;
2075 dwarf2_unsupported_at_frame_base_complaint (name
);
2078 new = push_context (0, lowpc
);
2079 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
2081 /* If there was a location expression for DW_AT_frame_base above,
2082 record it. We still need to decode it above because not all
2083 symbols use location expressions exclusively. */
2085 dwarf2_symbol_mark_computed (attr
, new->name
, cu_header
, objfile
);
2087 list_in_scope
= &local_symbols
;
2089 if (die
->has_children
)
2091 child_die
= die
->next
;
2092 while (child_die
&& child_die
->tag
)
2094 process_die (child_die
, objfile
, cu_header
);
2095 child_die
= sibling_die (child_die
);
2099 new = pop_context ();
2100 /* Make a block for the local symbols within. */
2101 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2102 lowpc
, highpc
, objfile
);
2104 /* In C++, we can have functions nested inside functions (e.g., when
2105 a function declares a class that has methods). This means that
2106 when we finish processing a function scope, we may need to go
2107 back to building a containing block's symbol lists. */
2108 local_symbols
= new->locals
;
2109 param_symbols
= new->params
;
2111 /* If we've finished processing a top-level function, subsequent
2112 symbols go in the file symbol list. */
2113 if (outermost_context_p ())
2114 list_in_scope
= &file_symbols
;
2117 /* Process all the DIES contained within a lexical block scope. Start
2118 a new scope, process the dies, and then close the scope. */
2121 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
2122 const struct comp_unit_head
*cu_header
)
2124 register struct context_stack
*new;
2125 CORE_ADDR lowpc
, highpc
;
2126 struct die_info
*child_die
;
2128 /* Ignore blocks with missing or invalid low and high pc attributes. */
2129 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2130 as multiple lexical blocks? Handling children in a sane way would
2131 be nasty. Might be easier to properly extend generic blocks to
2133 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2138 push_context (0, lowpc
);
2139 if (die
->has_children
)
2141 child_die
= die
->next
;
2142 while (child_die
&& child_die
->tag
)
2144 process_die (child_die
, objfile
, cu_header
);
2145 child_die
= sibling_die (child_die
);
2148 new = pop_context ();
2150 if (local_symbols
!= NULL
)
2152 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2155 local_symbols
= new->locals
;
2158 /* Get low and high pc attributes from a die. Return 1 if the attributes
2159 are present and valid, otherwise, return 0. Return -1 if the range is
2160 discontinuous, i.e. derived from DW_AT_ranges information. */
2162 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2163 CORE_ADDR
*highpc
, struct objfile
*objfile
,
2164 const struct comp_unit_head
*cu_header
)
2166 struct attribute
*attr
;
2167 bfd
*obfd
= objfile
->obfd
;
2172 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2175 high
= DW_ADDR (attr
);
2176 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2178 low
= DW_ADDR (attr
);
2180 /* Found high w/o low attribute. */
2183 /* Found consecutive range of addresses. */
2188 attr
= dwarf_attr (die
, DW_AT_ranges
);
2191 unsigned int addr_size
= cu_header
->addr_size
;
2192 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2193 /* Value of the DW_AT_ranges attribute is the offset in the
2194 .debug_renges section. */
2195 unsigned int offset
= DW_UNSND (attr
);
2196 /* Base address selection entry. */
2205 found_base
= cu_header
->base_known
;
2206 base
= cu_header
->base_address
;
2207 buffer
= dwarf_ranges_buffer
+ offset
;
2209 /* Read in the largest possible address. */
2210 marker
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2211 if ((marker
& mask
) == mask
)
2213 /* If we found the largest possible address, then
2214 read the base address. */
2215 base
= read_address (obfd
, buffer
+ addr_size
,
2217 buffer
+= 2 * addr_size
;
2218 offset
+= 2 * addr_size
;
2226 CORE_ADDR range_beginning
, range_end
;
2228 range_beginning
= read_address (obfd
, buffer
,
2230 buffer
+= addr_size
;
2231 range_end
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2232 buffer
+= addr_size
;
2233 offset
+= 2 * addr_size
;
2235 /* An end of list marker is a pair of zero addresses. */
2236 if (range_beginning
== 0 && range_end
== 0)
2237 /* Found the end of list entry. */
2240 /* Each base address selection entry is a pair of 2 values.
2241 The first is the largest possible address, the second is
2242 the base address. Check for a base address here. */
2243 if ((range_beginning
& mask
) == mask
)
2245 /* If we found the largest possible address, then
2246 read the base address. */
2247 base
= read_address (obfd
, buffer
+ addr_size
,
2255 /* We have no valid base address for the ranges
2257 complaint (&symfile_complaints
,
2258 "Invalid .debug_ranges data (no base address)");
2262 range_beginning
+= base
;
2265 /* FIXME: This is recording everything as a low-high
2266 segment of consecutive addresses. We should have a
2267 data structure for discontiguous block ranges
2271 low
= range_beginning
;
2277 if (range_beginning
< low
)
2278 low
= range_beginning
;
2279 if (range_end
> high
)
2285 /* If the first entry is an end-of-list marker, the range
2286 describes an empty scope, i.e. no instructions. */
2296 /* When using the GNU linker, .gnu.linkonce. sections are used to
2297 eliminate duplicate copies of functions and vtables and such.
2298 The linker will arbitrarily choose one and discard the others.
2299 The AT_*_pc values for such functions refer to local labels in
2300 these sections. If the section from that file was discarded, the
2301 labels are not in the output, so the relocs get a value of 0.
2302 If this is a discarded function, mark the pc bounds as invalid,
2303 so that GDB will ignore it. */
2304 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2312 /* Add an aggregate field to the field list. */
2315 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2316 struct objfile
*objfile
,
2317 const struct comp_unit_head
*cu_header
)
2319 struct nextfield
*new_field
;
2320 struct attribute
*attr
;
2322 char *fieldname
= "";
2324 /* Allocate a new field list entry and link it in. */
2325 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2326 make_cleanup (xfree
, new_field
);
2327 memset (new_field
, 0, sizeof (struct nextfield
));
2328 new_field
->next
= fip
->fields
;
2329 fip
->fields
= new_field
;
2332 /* Handle accessibility and virtuality of field.
2333 The default accessibility for members is public, the default
2334 accessibility for inheritance is private. */
2335 if (die
->tag
!= DW_TAG_inheritance
)
2336 new_field
->accessibility
= DW_ACCESS_public
;
2338 new_field
->accessibility
= DW_ACCESS_private
;
2339 new_field
->virtuality
= DW_VIRTUALITY_none
;
2341 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2343 new_field
->accessibility
= DW_UNSND (attr
);
2344 if (new_field
->accessibility
!= DW_ACCESS_public
)
2345 fip
->non_public_fields
= 1;
2346 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2348 new_field
->virtuality
= DW_UNSND (attr
);
2350 fp
= &new_field
->field
;
2352 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2354 /* Data member other than a C++ static data member. */
2356 /* Get type of field. */
2357 fp
->type
= die_type (die
, objfile
, cu_header
);
2359 FIELD_STATIC_KIND (*fp
) = 0;
2361 /* Get bit size of field (zero if none). */
2362 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2365 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2369 FIELD_BITSIZE (*fp
) = 0;
2372 /* Get bit offset of field. */
2373 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2376 FIELD_BITPOS (*fp
) =
2377 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2380 FIELD_BITPOS (*fp
) = 0;
2381 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2384 if (BITS_BIG_ENDIAN
)
2386 /* For big endian bits, the DW_AT_bit_offset gives the
2387 additional bit offset from the MSB of the containing
2388 anonymous object to the MSB of the field. We don't
2389 have to do anything special since we don't need to
2390 know the size of the anonymous object. */
2391 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2395 /* For little endian bits, compute the bit offset to the
2396 MSB of the anonymous object, subtract off the number of
2397 bits from the MSB of the field to the MSB of the
2398 object, and then subtract off the number of bits of
2399 the field itself. The result is the bit offset of
2400 the LSB of the field. */
2402 int bit_offset
= DW_UNSND (attr
);
2404 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2407 /* The size of the anonymous object containing
2408 the bit field is explicit, so use the
2409 indicated size (in bytes). */
2410 anonymous_size
= DW_UNSND (attr
);
2414 /* The size of the anonymous object containing
2415 the bit field must be inferred from the type
2416 attribute of the data member containing the
2418 anonymous_size
= TYPE_LENGTH (fp
->type
);
2420 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2421 - bit_offset
- FIELD_BITSIZE (*fp
);
2425 /* Get name of field. */
2426 attr
= dwarf_attr (die
, DW_AT_name
);
2427 if (attr
&& DW_STRING (attr
))
2428 fieldname
= DW_STRING (attr
);
2429 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2430 &objfile
->type_obstack
);
2432 /* Change accessibility for artificial fields (e.g. virtual table
2433 pointer or virtual base class pointer) to private. */
2434 if (dwarf_attr (die
, DW_AT_artificial
))
2436 new_field
->accessibility
= DW_ACCESS_private
;
2437 fip
->non_public_fields
= 1;
2440 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2442 /* C++ static member. */
2444 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2445 is a declaration, but all versions of G++ as of this writing
2446 (so through at least 3.2.1) incorrectly generate
2447 DW_TAG_variable tags. */
2451 /* Get name of field. */
2452 attr
= dwarf_attr (die
, DW_AT_name
);
2453 if (attr
&& DW_STRING (attr
))
2454 fieldname
= DW_STRING (attr
);
2458 /* Get physical name. */
2459 physname
= dwarf2_linkage_name (die
);
2461 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2462 &objfile
->type_obstack
));
2463 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2464 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2465 &objfile
->type_obstack
);
2467 else if (die
->tag
== DW_TAG_inheritance
)
2469 /* C++ base class field. */
2470 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2472 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2474 FIELD_BITSIZE (*fp
) = 0;
2475 FIELD_STATIC_KIND (*fp
) = 0;
2476 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2477 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2478 fip
->nbaseclasses
++;
2482 /* Create the vector of fields, and attach it to the type. */
2485 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2486 struct objfile
*objfile
)
2488 int nfields
= fip
->nfields
;
2490 /* Record the field count, allocate space for the array of fields,
2491 and create blank accessibility bitfields if necessary. */
2492 TYPE_NFIELDS (type
) = nfields
;
2493 TYPE_FIELDS (type
) = (struct field
*)
2494 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2495 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2497 if (fip
->non_public_fields
)
2499 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2501 TYPE_FIELD_PRIVATE_BITS (type
) =
2502 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2503 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2505 TYPE_FIELD_PROTECTED_BITS (type
) =
2506 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2507 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2509 TYPE_FIELD_IGNORE_BITS (type
) =
2510 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2511 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2514 /* If the type has baseclasses, allocate and clear a bit vector for
2515 TYPE_FIELD_VIRTUAL_BITS. */
2516 if (fip
->nbaseclasses
)
2518 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2521 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2522 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2523 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2524 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2525 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2528 /* Copy the saved-up fields into the field vector. Start from the head
2529 of the list, adding to the tail of the field array, so that they end
2530 up in the same order in the array in which they were added to the list. */
2531 while (nfields
-- > 0)
2533 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2534 switch (fip
->fields
->accessibility
)
2536 case DW_ACCESS_private
:
2537 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2540 case DW_ACCESS_protected
:
2541 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2544 case DW_ACCESS_public
:
2548 /* Unknown accessibility. Complain and treat it as public. */
2550 complaint (&symfile_complaints
, "unsupported accessibility %d",
2551 fip
->fields
->accessibility
);
2555 if (nfields
< fip
->nbaseclasses
)
2557 switch (fip
->fields
->virtuality
)
2559 case DW_VIRTUALITY_virtual
:
2560 case DW_VIRTUALITY_pure_virtual
:
2561 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2565 fip
->fields
= fip
->fields
->next
;
2569 /* Add a member function to the proper fieldlist. */
2572 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2573 struct type
*type
, struct objfile
*objfile
,
2574 const struct comp_unit_head
*cu_header
)
2576 struct attribute
*attr
;
2577 struct fnfieldlist
*flp
;
2579 struct fn_field
*fnp
;
2582 struct nextfnfield
*new_fnfield
;
2584 /* Get name of member function. */
2585 attr
= dwarf_attr (die
, DW_AT_name
);
2586 if (attr
&& DW_STRING (attr
))
2587 fieldname
= DW_STRING (attr
);
2591 /* Get the mangled name. */
2592 physname
= dwarf2_linkage_name (die
);
2594 /* Look up member function name in fieldlist. */
2595 for (i
= 0; i
< fip
->nfnfields
; i
++)
2597 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2601 /* Create new list element if necessary. */
2602 if (i
< fip
->nfnfields
)
2603 flp
= &fip
->fnfieldlists
[i
];
2606 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2608 fip
->fnfieldlists
= (struct fnfieldlist
*)
2609 xrealloc (fip
->fnfieldlists
,
2610 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2611 * sizeof (struct fnfieldlist
));
2612 if (fip
->nfnfields
== 0)
2613 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2615 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2616 flp
->name
= fieldname
;
2622 /* Create a new member function field and chain it to the field list
2624 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2625 make_cleanup (xfree
, new_fnfield
);
2626 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2627 new_fnfield
->next
= flp
->head
;
2628 flp
->head
= new_fnfield
;
2631 /* Fill in the member function field info. */
2632 fnp
= &new_fnfield
->fnfield
;
2633 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2634 &objfile
->type_obstack
);
2635 fnp
->type
= alloc_type (objfile
);
2636 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2638 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2639 int nparams
= TYPE_NFIELDS (die
->type
);
2641 /* TYPE is the domain of this method, and DIE->TYPE is the type
2642 of the method itself (TYPE_CODE_METHOD). */
2643 smash_to_method_type (fnp
->type
, type
,
2644 TYPE_TARGET_TYPE (die
->type
),
2645 TYPE_FIELDS (die
->type
),
2646 TYPE_NFIELDS (die
->type
),
2647 TYPE_VARARGS (die
->type
));
2649 /* Handle static member functions.
2650 Dwarf2 has no clean way to discern C++ static and non-static
2651 member functions. G++ helps GDB by marking the first
2652 parameter for non-static member functions (which is the
2653 this pointer) as artificial. We obtain this information
2654 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2655 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2656 fnp
->voffset
= VOFFSET_STATIC
;
2659 complaint (&symfile_complaints
, "member function type missing for '%s'",
2662 /* Get fcontext from DW_AT_containing_type if present. */
2663 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2664 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2666 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2667 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2669 /* Get accessibility. */
2670 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2673 switch (DW_UNSND (attr
))
2675 case DW_ACCESS_private
:
2676 fnp
->is_private
= 1;
2678 case DW_ACCESS_protected
:
2679 fnp
->is_protected
= 1;
2684 /* Check for artificial methods. */
2685 attr
= dwarf_attr (die
, DW_AT_artificial
);
2686 if (attr
&& DW_UNSND (attr
) != 0)
2687 fnp
->is_artificial
= 1;
2689 /* Get index in virtual function table if it is a virtual member function. */
2690 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2693 /* Support the .debug_loc offsets */
2694 if (attr_form_is_block (attr
))
2696 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2698 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2700 dwarf2_complex_location_expr_complaint ();
2704 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2710 /* Create the vector of member function fields, and attach it to the type. */
2713 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2714 struct objfile
*objfile
)
2716 struct fnfieldlist
*flp
;
2717 int total_length
= 0;
2720 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2721 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2722 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2724 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2726 struct nextfnfield
*nfp
= flp
->head
;
2727 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2730 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2731 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2732 fn_flp
->fn_fields
= (struct fn_field
*)
2733 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2734 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2735 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2737 total_length
+= flp
->length
;
2740 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2741 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2744 /* Called when we find the DIE that starts a structure or union scope
2745 (definition) to process all dies that define the members of the
2748 NOTE: we need to call struct_type regardless of whether or not the
2749 DIE has an at_name attribute, since it might be an anonymous
2750 structure or union. This gets the type entered into our set of
2753 However, if the structure is incomplete (an opaque struct/union)
2754 then suppress creating a symbol table entry for it since gdb only
2755 wants to find the one with the complete definition. Note that if
2756 it is complete, we just call new_symbol, which does it's own
2757 checking about whether the struct/union is anonymous or not (and
2758 suppresses creating a symbol table entry itself). */
2761 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2762 const struct comp_unit_head
*cu_header
)
2765 struct attribute
*attr
;
2767 type
= alloc_type (objfile
);
2769 INIT_CPLUS_SPECIFIC (type
);
2770 attr
= dwarf_attr (die
, DW_AT_name
);
2771 if (attr
&& DW_STRING (attr
))
2773 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2774 strlen (DW_STRING (attr
)),
2775 &objfile
->type_obstack
);
2778 if (die
->tag
== DW_TAG_structure_type
)
2780 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2782 else if (die
->tag
== DW_TAG_union_type
)
2784 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2788 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2790 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2793 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2796 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2800 TYPE_LENGTH (type
) = 0;
2803 /* We need to add the type field to the die immediately so we don't
2804 infinitely recurse when dealing with pointers to the structure
2805 type within the structure itself. */
2808 if (die
->has_children
&& ! die_is_declaration (die
))
2810 struct field_info fi
;
2811 struct die_info
*child_die
;
2812 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2814 memset (&fi
, 0, sizeof (struct field_info
));
2816 child_die
= die
->next
;
2818 while (child_die
&& child_die
->tag
)
2820 if (child_die
->tag
== DW_TAG_member
2821 || child_die
->tag
== DW_TAG_variable
)
2823 /* NOTE: carlton/2002-11-05: A C++ static data member
2824 should be a DW_TAG_member that is a declaration, but
2825 all versions of G++ as of this writing (so through at
2826 least 3.2.1) incorrectly generate DW_TAG_variable
2827 tags for them instead. */
2828 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2830 else if (child_die
->tag
== DW_TAG_subprogram
)
2832 /* C++ member function. */
2833 process_die (child_die
, objfile
, cu_header
);
2834 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2836 else if (child_die
->tag
== DW_TAG_inheritance
)
2838 /* C++ base class field. */
2839 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2843 process_die (child_die
, objfile
, cu_header
);
2845 child_die
= sibling_die (child_die
);
2848 /* Attach fields and member functions to the type. */
2850 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2853 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2855 /* Get the type which refers to the base class (possibly this
2856 class itself) which contains the vtable pointer for the current
2857 class from the DW_AT_containing_type attribute. */
2859 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2861 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2863 TYPE_VPTR_BASETYPE (type
) = t
;
2866 static const char vptr_name
[] =
2867 {'_', 'v', 'p', 't', 'r', '\0'};
2870 /* Our own class provides vtbl ptr. */
2871 for (i
= TYPE_NFIELDS (t
) - 1;
2872 i
>= TYPE_N_BASECLASSES (t
);
2875 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2877 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2878 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2880 TYPE_VPTR_FIELDNO (type
) = i
;
2885 /* Complain if virtual function table field not found. */
2886 if (i
< TYPE_N_BASECLASSES (t
))
2887 complaint (&symfile_complaints
,
2888 "virtual function table pointer not found when defining class '%s'",
2889 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2894 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2899 new_symbol (die
, type
, objfile
, cu_header
);
2901 do_cleanups (back_to
);
2905 /* No children, must be stub. */
2906 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2910 /* Given a pointer to a die which begins an enumeration, process all
2911 the dies that define the members of the enumeration.
2913 This will be much nicer in draft 6 of the DWARF spec when our
2914 members will be dies instead squished into the DW_AT_element_list
2917 NOTE: We reverse the order of the element list. */
2920 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2921 const struct comp_unit_head
*cu_header
)
2923 struct die_info
*child_die
;
2925 struct field
*fields
;
2926 struct attribute
*attr
;
2929 int unsigned_enum
= 1;
2931 type
= alloc_type (objfile
);
2933 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2934 attr
= dwarf_attr (die
, DW_AT_name
);
2935 if (attr
&& DW_STRING (attr
))
2937 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2938 strlen (DW_STRING (attr
)),
2939 &objfile
->type_obstack
);
2942 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2945 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2949 TYPE_LENGTH (type
) = 0;
2954 if (die
->has_children
)
2956 child_die
= die
->next
;
2957 while (child_die
&& child_die
->tag
)
2959 if (child_die
->tag
!= DW_TAG_enumerator
)
2961 process_die (child_die
, objfile
, cu_header
);
2965 attr
= dwarf_attr (child_die
, DW_AT_name
);
2968 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2969 if (SYMBOL_VALUE (sym
) < 0)
2972 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2974 fields
= (struct field
*)
2976 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2977 * sizeof (struct field
));
2980 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
2981 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2982 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2983 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2984 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
2990 child_die
= sibling_die (child_die
);
2995 TYPE_NFIELDS (type
) = num_fields
;
2996 TYPE_FIELDS (type
) = (struct field
*)
2997 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2998 memcpy (TYPE_FIELDS (type
), fields
,
2999 sizeof (struct field
) * num_fields
);
3003 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3006 new_symbol (die
, type
, objfile
, cu_header
);
3009 /* Extract all information from a DW_TAG_array_type DIE and put it in
3010 the DIE's type field. For now, this only handles one dimensional
3014 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
3015 const struct comp_unit_head
*cu_header
)
3017 struct die_info
*child_die
;
3018 struct type
*type
= NULL
;
3019 struct type
*element_type
, *range_type
, *index_type
;
3020 struct type
**range_types
= NULL
;
3021 struct attribute
*attr
;
3023 struct cleanup
*back_to
;
3025 /* Return if we've already decoded this type. */
3031 element_type
= die_type (die
, objfile
, cu_header
);
3033 /* Irix 6.2 native cc creates array types without children for
3034 arrays with unspecified length. */
3035 if (die
->has_children
== 0)
3037 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3038 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3039 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3043 back_to
= make_cleanup (null_cleanup
, NULL
);
3044 child_die
= die
->next
;
3045 while (child_die
&& child_die
->tag
)
3047 if (child_die
->tag
== DW_TAG_subrange_type
)
3049 unsigned int low
, high
;
3051 /* Default bounds to an array with unspecified length. */
3054 if (cu_language
== language_fortran
)
3056 /* FORTRAN implies a lower bound of 1, if not given. */
3060 index_type
= die_type (child_die
, objfile
, cu_header
);
3061 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3064 if (attr
->form
== DW_FORM_sdata
)
3066 low
= DW_SND (attr
);
3068 else if (attr
->form
== DW_FORM_udata
3069 || attr
->form
== DW_FORM_data1
3070 || attr
->form
== DW_FORM_data2
3071 || attr
->form
== DW_FORM_data4
3072 || attr
->form
== DW_FORM_data8
)
3074 low
= DW_UNSND (attr
);
3078 dwarf2_non_const_array_bound_ignored_complaint
3079 (dwarf_form_name (attr
->form
));
3081 die
->type
= lookup_pointer_type (element_type
);
3088 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3091 if (attr
->form
== DW_FORM_sdata
)
3093 high
= DW_SND (attr
);
3095 else if (attr
->form
== DW_FORM_udata
3096 || attr
->form
== DW_FORM_data1
3097 || attr
->form
== DW_FORM_data2
3098 || attr
->form
== DW_FORM_data4
3099 || attr
->form
== DW_FORM_data8
)
3101 high
= DW_UNSND (attr
);
3103 else if (attr
->form
== DW_FORM_block1
)
3105 /* GCC encodes arrays with unspecified or dynamic length
3106 with a DW_FORM_block1 attribute.
3107 FIXME: GDB does not yet know how to handle dynamic
3108 arrays properly, treat them as arrays with unspecified
3114 dwarf2_non_const_array_bound_ignored_complaint
3115 (dwarf_form_name (attr
->form
));
3117 die
->type
= lookup_pointer_type (element_type
);
3125 /* Create a range type and save it for array type creation. */
3126 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3128 range_types
= (struct type
**)
3129 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3130 * sizeof (struct type
*));
3132 make_cleanup (free_current_contents
, &range_types
);
3134 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3136 child_die
= sibling_die (child_die
);
3139 /* Dwarf2 dimensions are output from left to right, create the
3140 necessary array types in backwards order. */
3141 type
= element_type
;
3143 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3145 /* Understand Dwarf2 support for vector types (like they occur on
3146 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3147 array type. This is not part of the Dwarf2/3 standard yet, but a
3148 custom vendor extension. The main difference between a regular
3149 array and the vector variant is that vectors are passed by value
3151 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3153 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3155 do_cleanups (back_to
);
3157 /* Install the type in the die. */
3161 /* First cut: install each common block member as a global variable. */
3164 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
3165 const struct comp_unit_head
*cu_header
)
3167 struct die_info
*child_die
;
3168 struct attribute
*attr
;
3170 CORE_ADDR base
= (CORE_ADDR
) 0;
3172 attr
= dwarf_attr (die
, DW_AT_location
);
3175 /* Support the .debug_loc offsets */
3176 if (attr_form_is_block (attr
))
3178 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3180 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3182 dwarf2_complex_location_expr_complaint ();
3186 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3187 "common block member");
3190 if (die
->has_children
)
3192 child_die
= die
->next
;
3193 while (child_die
&& child_die
->tag
)
3195 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
3196 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3199 SYMBOL_VALUE_ADDRESS (sym
) =
3200 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3201 add_symbol_to_list (sym
, &global_symbols
);
3203 child_die
= sibling_die (child_die
);
3208 /* Read a C++ namespace. */
3211 read_namespace (struct die_info
*die
, struct objfile
*objfile
,
3212 const struct comp_unit_head
*cu_header
)
3214 const char *previous_namespace
= processing_current_namespace
;
3215 const char *name
= NULL
;
3217 struct die_info
*current_die
;
3219 /* Loop through the extensions until we find a name. */
3221 for (current_die
= die
;
3222 current_die
!= NULL
;
3223 current_die
= dwarf2_extension (die
))
3225 name
= dwarf2_name (current_die
);
3230 /* Is it an anonymous namespace? */
3232 is_anonymous
= (name
== NULL
);
3234 name
= "(anonymous namespace)";
3236 /* Now build the name of the current namespace. */
3238 if (previous_namespace
[0] == '\0')
3240 processing_current_namespace
= name
;
3244 /* We need temp_name around because processing_current_namespace
3245 is a const char *. */
3246 char *temp_name
= alloca (strlen (previous_namespace
)
3247 + 2 + strlen(name
) + 1);
3248 strcpy (temp_name
, previous_namespace
);
3249 strcat (temp_name
, "::");
3250 strcat (temp_name
, name
);
3252 processing_current_namespace
= temp_name
;
3255 /* If it's an anonymous namespace that we're seeing for the first
3256 time, add a using directive. */
3258 if (is_anonymous
&& dwarf_attr (die
, DW_AT_extension
) == NULL
)
3259 cp_add_using_directive (processing_current_namespace
,
3260 strlen (previous_namespace
),
3261 strlen (processing_current_namespace
));
3263 if (die
->has_children
)
3265 struct die_info
*child_die
= die
->next
;
3267 while (child_die
&& child_die
->tag
)
3269 process_die (child_die
, objfile
, cu_header
);
3270 child_die
= sibling_die (child_die
);
3274 processing_current_namespace
= previous_namespace
;
3277 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3278 the user defined type vector. */
3281 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
3282 const struct comp_unit_head
*cu_header
)
3285 struct attribute
*attr_byte_size
;
3286 struct attribute
*attr_address_class
;
3287 int byte_size
, addr_class
;
3294 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
3296 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3298 byte_size
= DW_UNSND (attr_byte_size
);
3300 byte_size
= cu_header
->addr_size
;
3302 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3303 if (attr_address_class
)
3304 addr_class
= DW_UNSND (attr_address_class
);
3306 addr_class
= DW_ADDR_none
;
3308 /* If the pointer size or address class is different than the
3309 default, create a type variant marked as such and set the
3310 length accordingly. */
3311 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3313 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3317 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3318 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3319 type
= make_type_with_address_space (type
, type_flags
);
3321 else if (TYPE_LENGTH (type
) != byte_size
)
3323 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3326 /* Should we also complain about unhandled address classes? */
3330 TYPE_LENGTH (type
) = byte_size
;
3334 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3335 the user defined type vector. */
3338 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
3339 const struct comp_unit_head
*cu_header
)
3342 struct type
*to_type
;
3343 struct type
*domain
;
3350 type
= alloc_type (objfile
);
3351 to_type
= die_type (die
, objfile
, cu_header
);
3352 domain
= die_containing_type (die
, objfile
, cu_header
);
3353 smash_to_member_type (type
, domain
, to_type
);
3358 /* Extract all information from a DW_TAG_reference_type DIE and add to
3359 the user defined type vector. */
3362 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
3363 const struct comp_unit_head
*cu_header
)
3366 struct attribute
*attr
;
3373 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
3374 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3377 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3381 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3387 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
3388 const struct comp_unit_head
*cu_header
)
3390 struct type
*base_type
;
3397 base_type
= die_type (die
, objfile
, cu_header
);
3398 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3402 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
3403 const struct comp_unit_head
*cu_header
)
3405 struct type
*base_type
;
3412 base_type
= die_type (die
, objfile
, cu_header
);
3413 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3416 /* Extract all information from a DW_TAG_string_type DIE and add to
3417 the user defined type vector. It isn't really a user defined type,
3418 but it behaves like one, with other DIE's using an AT_user_def_type
3419 attribute to reference it. */
3422 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3424 struct type
*type
, *range_type
, *index_type
, *char_type
;
3425 struct attribute
*attr
;
3426 unsigned int length
;
3433 attr
= dwarf_attr (die
, DW_AT_string_length
);
3436 length
= DW_UNSND (attr
);
3440 /* check for the DW_AT_byte_size attribute */
3441 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3444 length
= DW_UNSND (attr
);
3451 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3452 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3453 if (cu_language
== language_fortran
)
3455 /* Need to create a unique string type for bounds
3457 type
= create_string_type (0, range_type
);
3461 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3462 type
= create_string_type (char_type
, range_type
);
3467 /* Handle DIES due to C code like:
3471 int (*funcp)(int a, long l);
3475 ('funcp' generates a DW_TAG_subroutine_type DIE)
3479 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3480 const struct comp_unit_head
*cu_header
)
3482 struct type
*type
; /* Type that this function returns */
3483 struct type
*ftype
; /* Function that returns above type */
3484 struct attribute
*attr
;
3486 /* Decode the type that this subroutine returns */
3491 type
= die_type (die
, objfile
, cu_header
);
3492 ftype
= lookup_function_type (type
);
3494 /* All functions in C++ have prototypes. */
3495 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3496 if ((attr
&& (DW_UNSND (attr
) != 0))
3497 || cu_language
== language_cplus
)
3498 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3500 if (die
->has_children
)
3502 struct die_info
*child_die
;
3506 /* Count the number of parameters.
3507 FIXME: GDB currently ignores vararg functions, but knows about
3508 vararg member functions. */
3509 child_die
= die
->next
;
3510 while (child_die
&& child_die
->tag
)
3512 if (child_die
->tag
== DW_TAG_formal_parameter
)
3514 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3515 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3516 child_die
= sibling_die (child_die
);
3519 /* Allocate storage for parameters and fill them in. */
3520 TYPE_NFIELDS (ftype
) = nparams
;
3521 TYPE_FIELDS (ftype
) = (struct field
*)
3522 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3524 child_die
= die
->next
;
3525 while (child_die
&& child_die
->tag
)
3527 if (child_die
->tag
== DW_TAG_formal_parameter
)
3529 /* Dwarf2 has no clean way to discern C++ static and non-static
3530 member functions. G++ helps GDB by marking the first
3531 parameter for non-static member functions (which is the
3532 this pointer) as artificial. We pass this information
3533 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3534 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3536 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3538 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3539 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3543 child_die
= sibling_die (child_die
);
3551 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3552 const struct comp_unit_head
*cu_header
)
3554 struct attribute
*attr
;
3559 attr
= dwarf_attr (die
, DW_AT_name
);
3560 if (attr
&& DW_STRING (attr
))
3562 name
= DW_STRING (attr
);
3564 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3565 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3569 /* Find a representation of a given base type and install
3570 it in the TYPE field of the die. */
3573 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3576 struct attribute
*attr
;
3577 int encoding
= 0, size
= 0;
3579 /* If we've already decoded this die, this is a no-op. */
3585 attr
= dwarf_attr (die
, DW_AT_encoding
);
3588 encoding
= DW_UNSND (attr
);
3590 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3593 size
= DW_UNSND (attr
);
3595 attr
= dwarf_attr (die
, DW_AT_name
);
3596 if (attr
&& DW_STRING (attr
))
3598 enum type_code code
= TYPE_CODE_INT
;
3603 case DW_ATE_address
:
3604 /* Turn DW_ATE_address into a void * pointer. */
3605 code
= TYPE_CODE_PTR
;
3606 type_flags
|= TYPE_FLAG_UNSIGNED
;
3608 case DW_ATE_boolean
:
3609 code
= TYPE_CODE_BOOL
;
3610 type_flags
|= TYPE_FLAG_UNSIGNED
;
3612 case DW_ATE_complex_float
:
3613 code
= TYPE_CODE_COMPLEX
;
3616 code
= TYPE_CODE_FLT
;
3619 case DW_ATE_signed_char
:
3621 case DW_ATE_unsigned
:
3622 case DW_ATE_unsigned_char
:
3623 type_flags
|= TYPE_FLAG_UNSIGNED
;
3626 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3627 dwarf_type_encoding_name (encoding
));
3630 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3631 if (encoding
== DW_ATE_address
)
3632 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3633 else if (encoding
== DW_ATE_complex_float
)
3636 TYPE_TARGET_TYPE (type
)
3637 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3638 else if (size
== 16)
3639 TYPE_TARGET_TYPE (type
)
3640 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3642 TYPE_TARGET_TYPE (type
)
3643 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3648 type
= dwarf_base_type (encoding
, size
, objfile
);
3653 /* Read a whole compilation unit into a linked list of dies. */
3655 static struct die_info
*
3656 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3657 const struct comp_unit_head
*cu_header
)
3659 struct die_info
*first_die
, *last_die
, *die
;
3663 /* Reset die reference table; we are
3664 building new ones now. */
3665 dwarf2_empty_hash_tables ();
3669 first_die
= last_die
= NULL
;
3672 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3673 if (die
->has_children
)
3684 /* Enter die in reference hash table */
3685 store_in_ref_table (die
->offset
, die
);
3689 first_die
= last_die
= die
;
3693 last_die
->next
= die
;
3697 while (nesting_level
> 0);
3701 /* Free a linked list of dies. */
3704 free_die_list (struct die_info
*dies
)
3706 struct die_info
*die
, *next
;
3719 do_free_die_list_cleanup (void *dies
)
3721 free_die_list (dies
);
3724 static struct cleanup
*
3725 make_cleanup_free_die_list (struct die_info
*dies
)
3727 return make_cleanup (do_free_die_list_cleanup
, dies
);
3731 /* Read the contents of the section at OFFSET and of size SIZE from the
3732 object file specified by OBJFILE into the psymbol_obstack and return it. */
3735 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3736 unsigned int size
, asection
*sectp
)
3738 bfd
*abfd
= objfile
->obfd
;
3744 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3746 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3750 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3751 (bfd_bread (buf
, size
, abfd
) != size
))
3754 error ("Dwarf Error: Can't read DWARF data from '%s'",
3755 bfd_get_filename (abfd
));
3760 /* In DWARF version 2, the description of the debugging information is
3761 stored in a separate .debug_abbrev section. Before we read any
3762 dies from a section we read in all abbreviations and install them
3766 dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
)
3769 struct abbrev_info
*cur_abbrev
;
3770 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3771 unsigned int abbrev_form
, hash_number
;
3773 /* Initialize dwarf2 abbrevs */
3774 memset (cu_header
->dwarf2_abbrevs
, 0,
3775 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3777 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3778 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3779 abbrev_ptr
+= bytes_read
;
3781 /* loop until we reach an abbrev number of 0 */
3782 while (abbrev_number
)
3784 cur_abbrev
= dwarf_alloc_abbrev ();
3786 /* read in abbrev header */
3787 cur_abbrev
->number
= abbrev_number
;
3788 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3789 abbrev_ptr
+= bytes_read
;
3790 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3793 /* now read in declarations */
3794 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3795 abbrev_ptr
+= bytes_read
;
3796 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3797 abbrev_ptr
+= bytes_read
;
3800 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3802 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3803 xrealloc (cur_abbrev
->attrs
,
3804 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3805 * sizeof (struct attr_abbrev
));
3807 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3808 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3809 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3810 abbrev_ptr
+= bytes_read
;
3811 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3812 abbrev_ptr
+= bytes_read
;
3815 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3816 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3817 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3819 /* Get next abbreviation.
3820 Under Irix6 the abbreviations for a compilation unit are not
3821 always properly terminated with an abbrev number of 0.
3822 Exit loop if we encounter an abbreviation which we have
3823 already read (which means we are about to read the abbreviations
3824 for the next compile unit) or if the end of the abbreviation
3825 table is reached. */
3826 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3827 >= dwarf_abbrev_size
)
3829 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3830 abbrev_ptr
+= bytes_read
;
3831 if (dwarf2_lookup_abbrev (abbrev_number
, cu_header
) != NULL
)
3836 /* Empty the abbrev table for a new compilation unit. */
3840 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3843 struct abbrev_info
*abbrev
, *next
;
3844 struct abbrev_info
**abbrevs
;
3846 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3848 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3851 abbrev
= abbrevs
[i
];
3854 next
= abbrev
->next
;
3855 xfree (abbrev
->attrs
);
3863 /* Lookup an abbrev_info structure in the abbrev hash table. */
3865 static struct abbrev_info
*
3866 dwarf2_lookup_abbrev (unsigned int number
, const struct comp_unit_head
*cu_header
)
3868 unsigned int hash_number
;
3869 struct abbrev_info
*abbrev
;
3871 hash_number
= number
% ABBREV_HASH_SIZE
;
3872 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3876 if (abbrev
->number
== number
)
3879 abbrev
= abbrev
->next
;
3884 /* Read a minimal amount of information into the minimal die structure. */
3887 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3888 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3890 unsigned int abbrev_number
, bytes_read
, i
;
3891 struct abbrev_info
*abbrev
;
3892 struct attribute attr
;
3893 struct attribute spec_attr
;
3894 int found_spec_attr
= 0;
3895 int has_low_pc_attr
= 0;
3896 int has_high_pc_attr
= 0;
3898 *part_die
= zeroed_partial_die
;
3899 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3900 info_ptr
+= bytes_read
;
3904 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3907 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
3908 bfd_get_filename (abfd
));
3910 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3911 part_die
->tag
= abbrev
->tag
;
3912 part_die
->has_children
= abbrev
->has_children
;
3913 part_die
->abbrev
= abbrev_number
;
3915 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3917 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3918 info_ptr
, cu_header
);
3920 /* Store the data if it is of an attribute we want to keep in a
3921 partial symbol table. */
3926 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3927 if (part_die
->name
== NULL
)
3928 part_die
->name
= DW_STRING (&attr
);
3930 case DW_AT_MIPS_linkage_name
:
3931 part_die
->name
= DW_STRING (&attr
);
3934 has_low_pc_attr
= 1;
3935 part_die
->lowpc
= DW_ADDR (&attr
);
3938 has_high_pc_attr
= 1;
3939 part_die
->highpc
= DW_ADDR (&attr
);
3941 case DW_AT_location
:
3942 /* Support the .debug_loc offsets */
3943 if (attr_form_is_block (&attr
))
3945 part_die
->locdesc
= DW_BLOCK (&attr
);
3947 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
3949 dwarf2_complex_location_expr_complaint ();
3953 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3954 "partial symbol information");
3957 case DW_AT_language
:
3958 part_die
->language
= DW_UNSND (&attr
);
3960 case DW_AT_external
:
3961 part_die
->is_external
= DW_UNSND (&attr
);
3963 case DW_AT_declaration
:
3964 part_die
->is_declaration
= DW_UNSND (&attr
);
3967 part_die
->has_type
= 1;
3969 case DW_AT_abstract_origin
:
3970 case DW_AT_specification
:
3971 found_spec_attr
= 1;
3975 /* Ignore absolute siblings, they might point outside of
3976 the current compile unit. */
3977 if (attr
.form
== DW_FORM_ref_addr
)
3978 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
3981 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3988 /* If we found a reference attribute and the die has no name, try
3989 to find a name in the referred to die. */
3991 if (found_spec_attr
&& part_die
->name
== NULL
)
3993 struct partial_die_info spec_die
;
3997 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3998 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
4001 part_die
->name
= spec_die
.name
;
4003 /* Copy DW_AT_external attribute if it is set. */
4004 if (spec_die
.is_external
)
4005 part_die
->is_external
= spec_die
.is_external
;
4009 /* When using the GNU linker, .gnu.linkonce. sections are used to
4010 eliminate duplicate copies of functions and vtables and such.
4011 The linker will arbitrarily choose one and discard the others.
4012 The AT_*_pc values for such functions refer to local labels in
4013 these sections. If the section from that file was discarded, the
4014 labels are not in the output, so the relocs get a value of 0.
4015 If this is a discarded function, mark the pc bounds as invalid,
4016 so that GDB will ignore it. */
4017 if (has_low_pc_attr
&& has_high_pc_attr
4018 && part_die
->lowpc
< part_die
->highpc
4019 && (part_die
->lowpc
!= 0
4020 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4021 part_die
->has_pc_info
= 1;
4025 /* Read the die from the .debug_info section buffer. And set diep to
4026 point to a newly allocated die with its information. */
4029 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4030 const struct comp_unit_head
*cu_header
)
4032 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4033 struct abbrev_info
*abbrev
;
4034 struct die_info
*die
;
4036 offset
= info_ptr
- dwarf_info_buffer
;
4037 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4038 info_ptr
+= bytes_read
;
4041 die
= dwarf_alloc_die ();
4043 die
->abbrev
= abbrev_number
;
4049 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
4052 error ("Dwarf Error: could not find abbrev number %d [in module %s]", abbrev_number
,
4053 bfd_get_filename (abfd
));
4055 die
= dwarf_alloc_die ();
4056 die
->offset
= offset
;
4057 die
->tag
= abbrev
->tag
;
4058 die
->has_children
= abbrev
->has_children
;
4059 die
->abbrev
= abbrev_number
;
4062 die
->num_attrs
= abbrev
->num_attrs
;
4063 die
->attrs
= (struct attribute
*)
4064 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4066 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4068 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4069 abfd
, info_ptr
, cu_header
);
4076 /* Read an attribute value described by an attribute form. */
4079 read_attribute_value (struct attribute
*attr
, unsigned form
,
4080 bfd
*abfd
, char *info_ptr
,
4081 const struct comp_unit_head
*cu_header
)
4083 unsigned int bytes_read
;
4084 struct dwarf_block
*blk
;
4090 case DW_FORM_ref_addr
:
4091 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
4092 info_ptr
+= bytes_read
;
4094 case DW_FORM_block2
:
4095 blk
= dwarf_alloc_block ();
4096 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4098 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4099 info_ptr
+= blk
->size
;
4100 DW_BLOCK (attr
) = blk
;
4102 case DW_FORM_block4
:
4103 blk
= dwarf_alloc_block ();
4104 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4106 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4107 info_ptr
+= blk
->size
;
4108 DW_BLOCK (attr
) = blk
;
4111 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4115 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4119 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4122 case DW_FORM_string
:
4123 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4124 info_ptr
+= bytes_read
;
4127 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4129 info_ptr
+= bytes_read
;
4132 blk
= dwarf_alloc_block ();
4133 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4134 info_ptr
+= bytes_read
;
4135 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4136 info_ptr
+= blk
->size
;
4137 DW_BLOCK (attr
) = blk
;
4139 case DW_FORM_block1
:
4140 blk
= dwarf_alloc_block ();
4141 blk
->size
= read_1_byte (abfd
, info_ptr
);
4143 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4144 info_ptr
+= blk
->size
;
4145 DW_BLOCK (attr
) = blk
;
4148 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4152 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4156 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4157 info_ptr
+= bytes_read
;
4160 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4161 info_ptr
+= bytes_read
;
4164 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4168 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4172 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4176 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4179 case DW_FORM_ref_udata
:
4180 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4181 info_ptr
+= bytes_read
;
4183 case DW_FORM_indirect
:
4184 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4185 info_ptr
+= bytes_read
;
4186 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
4189 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4190 dwarf_form_name (form
),
4191 bfd_get_filename (abfd
));
4196 /* Read an attribute described by an abbreviated attribute. */
4199 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4200 bfd
*abfd
, char *info_ptr
,
4201 const struct comp_unit_head
*cu_header
)
4203 attr
->name
= abbrev
->name
;
4204 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
4207 /* read dwarf information from a buffer */
4210 read_1_byte (bfd
*abfd
, char *buf
)
4212 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4216 read_1_signed_byte (bfd
*abfd
, char *buf
)
4218 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4222 read_2_bytes (bfd
*abfd
, char *buf
)
4224 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4228 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4230 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4234 read_4_bytes (bfd
*abfd
, char *buf
)
4236 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4240 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4242 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4245 static unsigned long
4246 read_8_bytes (bfd
*abfd
, char *buf
)
4248 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4252 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4255 CORE_ADDR retval
= 0;
4257 if (cu_header
->signed_addr_p
)
4259 switch (cu_header
->addr_size
)
4262 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4265 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4268 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4271 internal_error (__FILE__
, __LINE__
,
4272 "read_address: bad switch, signed [in module %s]",
4273 bfd_get_filename (abfd
));
4278 switch (cu_header
->addr_size
)
4281 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4284 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4287 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4290 internal_error (__FILE__
, __LINE__
,
4291 "read_address: bad switch, unsigned [in module %s]",
4292 bfd_get_filename (abfd
));
4296 *bytes_read
= cu_header
->addr_size
;
4300 /* Read the initial length from a section. The (draft) DWARF 3
4301 specification allows the initial length to take up either 4 bytes
4302 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4303 bytes describe the length and all offsets will be 8 bytes in length
4306 An older, non-standard 64-bit format is also handled by this
4307 function. The older format in question stores the initial length
4308 as an 8-byte quantity without an escape value. Lengths greater
4309 than 2^32 aren't very common which means that the initial 4 bytes
4310 is almost always zero. Since a length value of zero doesn't make
4311 sense for the 32-bit format, this initial zero can be considered to
4312 be an escape value which indicates the presence of the older 64-bit
4313 format. As written, the code can't detect (old format) lengths
4314 greater than 4GB. If it becomes necessary to handle lengths somewhat
4315 larger than 4GB, we could allow other small values (such as the
4316 non-sensical values of 1, 2, and 3) to also be used as escape values
4317 indicating the presence of the old format.
4319 The value returned via bytes_read should be used to increment
4320 the relevant pointer after calling read_initial_length().
4322 As a side effect, this function sets the fields initial_length_size
4323 and offset_size in cu_header to the values appropriate for the
4324 length field. (The format of the initial length field determines
4325 the width of file offsets to be fetched later with fetch_offset().)
4327 [ Note: read_initial_length() and read_offset() are based on the
4328 document entitled "DWARF Debugging Information Format", revision
4329 3, draft 8, dated November 19, 2001. This document was obtained
4332 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4334 This document is only a draft and is subject to change. (So beware.)
4336 Details regarding the older, non-standard 64-bit format were
4337 determined empirically by examining 64-bit ELF files produced
4338 by the SGI toolchain on an IRIX 6.5 machine.
4340 - Kevin, July 16, 2002
4344 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4349 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4351 if (retval
== 0xffffffff)
4353 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4355 if (cu_header
!= NULL
)
4357 cu_header
->initial_length_size
= 12;
4358 cu_header
->offset_size
= 8;
4361 else if (retval
== 0)
4363 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4365 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4367 if (cu_header
!= NULL
)
4369 cu_header
->initial_length_size
= 8;
4370 cu_header
->offset_size
= 8;
4376 if (cu_header
!= NULL
)
4378 cu_header
->initial_length_size
= 4;
4379 cu_header
->offset_size
= 4;
4386 /* Read an offset from the data stream. The size of the offset is
4387 given by cu_header->offset_size. */
4390 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4395 switch (cu_header
->offset_size
)
4398 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4402 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4406 internal_error (__FILE__
, __LINE__
,
4407 "read_offset: bad switch [in module %s]",
4408 bfd_get_filename (abfd
));
4415 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4417 /* If the size of a host char is 8 bits, we can return a pointer
4418 to the buffer, otherwise we have to copy the data to a buffer
4419 allocated on the temporary obstack. */
4420 gdb_assert (HOST_CHAR_BIT
== 8);
4425 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4427 /* If the size of a host char is 8 bits, we can return a pointer
4428 to the string, otherwise we have to copy the string to a buffer
4429 allocated on the temporary obstack. */
4430 gdb_assert (HOST_CHAR_BIT
== 8);
4433 *bytes_read_ptr
= 1;
4436 *bytes_read_ptr
= strlen (buf
) + 1;
4441 read_indirect_string (bfd
*abfd
, char *buf
,
4442 const struct comp_unit_head
*cu_header
,
4443 unsigned int *bytes_read_ptr
)
4445 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4446 (int *) bytes_read_ptr
);
4448 if (dwarf_str_buffer
== NULL
)
4450 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4451 bfd_get_filename (abfd
));
4454 if (str_offset
>= dwarf_str_size
)
4456 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4457 bfd_get_filename (abfd
));
4460 gdb_assert (HOST_CHAR_BIT
== 8);
4461 if (dwarf_str_buffer
[str_offset
] == '\0')
4463 return dwarf_str_buffer
+ str_offset
;
4466 static unsigned long
4467 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4469 unsigned long result
;
4470 unsigned int num_read
;
4480 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4483 result
|= ((unsigned long)(byte
& 127) << shift
);
4484 if ((byte
& 128) == 0)
4490 *bytes_read_ptr
= num_read
;
4495 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4498 int i
, shift
, size
, num_read
;
4508 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4511 result
|= ((long)(byte
& 127) << shift
);
4513 if ((byte
& 128) == 0)
4518 if ((shift
< size
) && (byte
& 0x40))
4520 result
|= -(1 << shift
);
4522 *bytes_read_ptr
= num_read
;
4527 set_cu_language (unsigned int lang
)
4533 cu_language
= language_c
;
4535 case DW_LANG_C_plus_plus
:
4536 cu_language
= language_cplus
;
4538 case DW_LANG_Fortran77
:
4539 case DW_LANG_Fortran90
:
4540 case DW_LANG_Fortran95
:
4541 cu_language
= language_fortran
;
4543 case DW_LANG_Mips_Assembler
:
4544 cu_language
= language_asm
;
4547 cu_language
= language_java
;
4551 case DW_LANG_Cobol74
:
4552 case DW_LANG_Cobol85
:
4553 case DW_LANG_Pascal83
:
4554 case DW_LANG_Modula2
:
4556 cu_language
= language_minimal
;
4559 cu_language_defn
= language_def (cu_language
);
4562 /* Return the named attribute or NULL if not there. */
4564 static struct attribute
*
4565 dwarf_attr (struct die_info
*die
, unsigned int name
)
4568 struct attribute
*spec
= NULL
;
4570 for (i
= 0; i
< die
->num_attrs
; ++i
)
4572 if (die
->attrs
[i
].name
== name
)
4574 return &die
->attrs
[i
];
4576 if (die
->attrs
[i
].name
== DW_AT_specification
4577 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4578 spec
= &die
->attrs
[i
];
4582 struct die_info
*ref_die
=
4583 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4586 return dwarf_attr (ref_die
, name
);
4593 die_is_declaration (struct die_info
*die
)
4595 return (dwarf_attr (die
, DW_AT_declaration
)
4596 && ! dwarf_attr (die
, DW_AT_specification
));
4600 /* Free the line_header structure *LH, and any arrays and strings it
4603 free_line_header (struct line_header
*lh
)
4605 if (lh
->standard_opcode_lengths
)
4606 xfree (lh
->standard_opcode_lengths
);
4608 /* Remember that all the lh->file_names[i].name pointers are
4609 pointers into debug_line_buffer, and don't need to be freed. */
4611 xfree (lh
->file_names
);
4613 /* Similarly for the include directory names. */
4614 if (lh
->include_dirs
)
4615 xfree (lh
->include_dirs
);
4621 /* Add an entry to LH's include directory table. */
4623 add_include_dir (struct line_header
*lh
, char *include_dir
)
4625 /* Grow the array if necessary. */
4626 if (lh
->include_dirs_size
== 0)
4628 lh
->include_dirs_size
= 1; /* for testing */
4629 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4630 * sizeof (*lh
->include_dirs
));
4632 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4634 lh
->include_dirs_size
*= 2;
4635 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4636 (lh
->include_dirs_size
4637 * sizeof (*lh
->include_dirs
)));
4640 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4644 /* Add an entry to LH's file name table. */
4646 add_file_name (struct line_header
*lh
,
4648 unsigned int dir_index
,
4649 unsigned int mod_time
,
4650 unsigned int length
)
4652 struct file_entry
*fe
;
4654 /* Grow the array if necessary. */
4655 if (lh
->file_names_size
== 0)
4657 lh
->file_names_size
= 1; /* for testing */
4658 lh
->file_names
= xmalloc (lh
->file_names_size
4659 * sizeof (*lh
->file_names
));
4661 else if (lh
->num_file_names
>= lh
->file_names_size
)
4663 lh
->file_names_size
*= 2;
4664 lh
->file_names
= xrealloc (lh
->file_names
,
4665 (lh
->file_names_size
4666 * sizeof (*lh
->file_names
)));
4669 fe
= &lh
->file_names
[lh
->num_file_names
++];
4671 fe
->dir_index
= dir_index
;
4672 fe
->mod_time
= mod_time
;
4673 fe
->length
= length
;
4677 /* Read the statement program header starting at OFFSET in
4678 dwarf_line_buffer, according to the endianness of ABFD. Return a
4679 pointer to a struct line_header, allocated using xmalloc.
4681 NOTE: the strings in the include directory and file name tables of
4682 the returned object point into debug_line_buffer, and must not be
4684 static struct line_header
*
4685 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4686 const struct comp_unit_head
*cu_header
)
4688 struct cleanup
*back_to
;
4689 struct line_header
*lh
;
4693 char *cur_dir
, *cur_file
;
4695 if (dwarf_line_buffer
== NULL
)
4697 complaint (&symfile_complaints
, "missing .debug_line section");
4701 /* Make sure that at least there's room for the total_length field. That
4702 could be 12 bytes long, but we're just going to fudge that. */
4703 if (offset
+ 4 >= dwarf_line_size
)
4705 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4709 lh
= xmalloc (sizeof (*lh
));
4710 memset (lh
, 0, sizeof (*lh
));
4711 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4714 line_ptr
= dwarf_line_buffer
+ offset
;
4716 /* read in the header */
4717 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4718 line_ptr
+= bytes_read
;
4719 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4721 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4724 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4725 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4727 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4728 line_ptr
+= bytes_read
;
4729 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4731 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4733 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4735 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4737 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4739 lh
->standard_opcode_lengths
4740 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4742 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4743 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4745 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4749 /* Read directory table */
4750 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4752 line_ptr
+= bytes_read
;
4753 add_include_dir (lh
, cur_dir
);
4755 line_ptr
+= bytes_read
;
4757 /* Read file name table */
4758 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4760 unsigned int dir_index
, mod_time
, length
;
4762 line_ptr
+= bytes_read
;
4763 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4764 line_ptr
+= bytes_read
;
4765 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4766 line_ptr
+= bytes_read
;
4767 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4768 line_ptr
+= bytes_read
;
4770 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4772 line_ptr
+= bytes_read
;
4773 lh
->statement_program_start
= line_ptr
;
4775 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4776 complaint (&symfile_complaints
,
4777 "line number info header doesn't fit in `.debug_line' section");
4779 discard_cleanups (back_to
);
4783 /* This function exists to work around a bug in certain compilers
4784 (particularly GCC 2.95), in which the first line number marker of a
4785 function does not show up until after the prologue, right before
4786 the second line number marker. This function shifts ADDRESS down
4787 to the beginning of the function if necessary, and is called on
4788 addresses passed to record_line. */
4791 check_cu_functions (CORE_ADDR address
)
4793 struct function_range
*fn
;
4795 /* Find the function_range containing address. */
4800 cu_cached_fn
= cu_first_fn
;
4804 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4810 while (fn
&& fn
!= cu_cached_fn
)
4811 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4821 if (address
!= fn
->lowpc
)
4822 complaint (&symfile_complaints
,
4823 "misplaced first line number at 0x%lx for '%s'",
4824 (unsigned long) address
, fn
->name
);
4829 /* Decode the line number information for the compilation unit whose
4830 line number info is at OFFSET in the .debug_line section.
4831 The compilation directory of the file is passed in COMP_DIR. */
4834 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4835 const struct comp_unit_head
*cu_header
)
4839 unsigned int i
, bytes_read
;
4841 unsigned char op_code
, extended_op
, adj_opcode
;
4843 line_ptr
= lh
->statement_program_start
;
4844 line_end
= lh
->statement_program_end
;
4846 /* Read the statement sequences until there's nothing left. */
4847 while (line_ptr
< line_end
)
4849 /* state machine registers */
4850 CORE_ADDR address
= 0;
4851 unsigned int file
= 1;
4852 unsigned int line
= 1;
4853 unsigned int column
= 0;
4854 int is_stmt
= lh
->default_is_stmt
;
4855 int basic_block
= 0;
4856 int end_sequence
= 0;
4858 /* Start a subfile for the current file of the state machine. */
4859 if (lh
->num_file_names
>= file
)
4861 /* lh->include_dirs and lh->file_names are 0-based, but the
4862 directory and file name numbers in the statement program
4864 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4867 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4870 dwarf2_start_subfile (fe
->name
, dir
);
4873 /* Decode the table. */
4874 while (!end_sequence
)
4876 op_code
= read_1_byte (abfd
, line_ptr
);
4879 if (op_code
>= lh
->opcode_base
)
4880 { /* Special operand. */
4881 adj_opcode
= op_code
- lh
->opcode_base
;
4882 address
+= (adj_opcode
/ lh
->line_range
)
4883 * lh
->minimum_instruction_length
;
4884 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4885 /* append row to matrix using current values */
4886 record_line (current_subfile
, line
,
4887 check_cu_functions (address
));
4890 else switch (op_code
)
4892 case DW_LNS_extended_op
:
4893 line_ptr
+= 1; /* ignore length */
4894 extended_op
= read_1_byte (abfd
, line_ptr
);
4896 switch (extended_op
)
4898 case DW_LNE_end_sequence
:
4900 record_line (current_subfile
, 0, address
);
4902 case DW_LNE_set_address
:
4903 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4904 line_ptr
+= bytes_read
;
4905 address
+= baseaddr
;
4907 case DW_LNE_define_file
:
4910 unsigned int dir_index
, mod_time
, length
;
4912 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4913 line_ptr
+= bytes_read
;
4915 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4916 line_ptr
+= bytes_read
;
4918 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4919 line_ptr
+= bytes_read
;
4921 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4922 line_ptr
+= bytes_read
;
4923 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4927 complaint (&symfile_complaints
,
4928 "mangled .debug_line section");
4933 record_line (current_subfile
, line
,
4934 check_cu_functions (address
));
4937 case DW_LNS_advance_pc
:
4938 address
+= lh
->minimum_instruction_length
4939 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4940 line_ptr
+= bytes_read
;
4942 case DW_LNS_advance_line
:
4943 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4944 line_ptr
+= bytes_read
;
4946 case DW_LNS_set_file
:
4948 /* lh->include_dirs and lh->file_names are 0-based,
4949 but the directory and file name numbers in the
4950 statement program are 1-based. */
4951 struct file_entry
*fe
;
4953 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4954 line_ptr
+= bytes_read
;
4955 fe
= &lh
->file_names
[file
- 1];
4957 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4960 dwarf2_start_subfile (fe
->name
, dir
);
4963 case DW_LNS_set_column
:
4964 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4965 line_ptr
+= bytes_read
;
4967 case DW_LNS_negate_stmt
:
4968 is_stmt
= (!is_stmt
);
4970 case DW_LNS_set_basic_block
:
4973 /* Add to the address register of the state machine the
4974 address increment value corresponding to special opcode
4975 255. Ie, this value is scaled by the minimum instruction
4976 length since special opcode 255 would have scaled the
4978 case DW_LNS_const_add_pc
:
4979 address
+= (lh
->minimum_instruction_length
4980 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4982 case DW_LNS_fixed_advance_pc
:
4983 address
+= read_2_bytes (abfd
, line_ptr
);
4987 { /* Unknown standard opcode, ignore it. */
4989 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4991 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4992 line_ptr
+= bytes_read
;
5000 /* Start a subfile for DWARF. FILENAME is the name of the file and
5001 DIRNAME the name of the source directory which contains FILENAME
5002 or NULL if not known.
5003 This routine tries to keep line numbers from identical absolute and
5004 relative file names in a common subfile.
5006 Using the `list' example from the GDB testsuite, which resides in
5007 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5008 of /srcdir/list0.c yields the following debugging information for list0.c:
5010 DW_AT_name: /srcdir/list0.c
5011 DW_AT_comp_dir: /compdir
5012 files.files[0].name: list0.h
5013 files.files[0].dir: /srcdir
5014 files.files[1].name: list0.c
5015 files.files[1].dir: /srcdir
5017 The line number information for list0.c has to end up in a single
5018 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5021 dwarf2_start_subfile (char *filename
, char *dirname
)
5023 /* If the filename isn't absolute, try to match an existing subfile
5024 with the full pathname. */
5026 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5028 struct subfile
*subfile
;
5029 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5031 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5033 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5035 current_subfile
= subfile
;
5042 start_subfile (filename
, dirname
);
5046 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5047 struct objfile
*objfile
,
5048 const struct comp_unit_head
*cu_header
)
5050 /* NOTE drow/2003-01-30: There used to be a comment and some special
5051 code here to turn a symbol with DW_AT_external and a
5052 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5053 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5054 with some versions of binutils) where shared libraries could have
5055 relocations against symbols in their debug information - the
5056 minimal symbol would have the right address, but the debug info
5057 would not. It's no longer necessary, because we will explicitly
5058 apply relocations when we read in the debug information now. */
5060 /* A DW_AT_location attribute with no contents indicates that a
5061 variable has been optimized away. */
5062 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5064 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5068 /* Handle one degenerate form of location expression specially, to
5069 preserve GDB's previous behavior when section offsets are
5070 specified. If this is just a DW_OP_addr then mark this symbol
5073 if (attr_form_is_block (attr
)
5074 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5075 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5079 SYMBOL_VALUE_ADDRESS (sym
) =
5080 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu_header
,
5082 fixup_symbol_section (sym
, objfile
);
5083 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5084 SYMBOL_SECTION (sym
));
5085 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5089 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5090 expression evaluator, and use LOC_COMPUTED only when necessary
5091 (i.e. when the value of a register or memory location is
5092 referenced, or a thread-local block, etc.). Then again, it might
5093 not be worthwhile. I'm assuming that it isn't unless performance
5094 or memory numbers show me otherwise. */
5096 dwarf2_symbol_mark_computed (attr
, sym
, cu_header
, objfile
);
5097 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5100 /* Given a pointer to a DWARF information entry, figure out if we need
5101 to make a symbol table entry for it, and if so, create a new entry
5102 and return a pointer to it.
5103 If TYPE is NULL, determine symbol type from the die, otherwise
5104 used the passed type. */
5106 static struct symbol
*
5107 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
5108 const struct comp_unit_head
*cu_header
)
5110 struct symbol
*sym
= NULL
;
5112 struct attribute
*attr
= NULL
;
5113 struct attribute
*attr2
= NULL
;
5116 name
= dwarf2_linkage_name (die
);
5119 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5120 sizeof (struct symbol
));
5121 OBJSTAT (objfile
, n_syms
++);
5122 memset (sym
, 0, sizeof (struct symbol
));
5124 /* Cache this symbol's name and the name's demangled form (if any). */
5125 SYMBOL_LANGUAGE (sym
) = cu_language
;
5126 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5128 /* Default assumptions.
5129 Use the passed type or decode it from the die. */
5130 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5131 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5133 SYMBOL_TYPE (sym
) = type
;
5135 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
5136 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5139 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5144 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5147 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5149 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5151 case DW_TAG_subprogram
:
5152 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5154 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5155 attr2
= dwarf_attr (die
, DW_AT_external
);
5156 if (attr2
&& (DW_UNSND (attr2
) != 0))
5158 add_symbol_to_list (sym
, &global_symbols
);
5162 add_symbol_to_list (sym
, list_in_scope
);
5165 case DW_TAG_variable
:
5166 /* Compilation with minimal debug info may result in variables
5167 with missing type entries. Change the misleading `void' type
5168 to something sensible. */
5169 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5170 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5171 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5172 "<variable, no debug info>",
5174 attr
= dwarf_attr (die
, DW_AT_const_value
);
5177 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5178 attr2
= dwarf_attr (die
, DW_AT_external
);
5179 if (attr2
&& (DW_UNSND (attr2
) != 0))
5180 add_symbol_to_list (sym
, &global_symbols
);
5182 add_symbol_to_list (sym
, list_in_scope
);
5185 attr
= dwarf_attr (die
, DW_AT_location
);
5188 var_decode_location (attr
, sym
, objfile
, cu_header
);
5189 attr2
= dwarf_attr (die
, DW_AT_external
);
5190 if (attr2
&& (DW_UNSND (attr2
) != 0))
5191 add_symbol_to_list (sym
, &global_symbols
);
5193 add_symbol_to_list (sym
, list_in_scope
);
5197 /* We do not know the address of this symbol.
5198 If it is an external symbol and we have type information
5199 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5200 The address of the variable will then be determined from
5201 the minimal symbol table whenever the variable is
5203 attr2
= dwarf_attr (die
, DW_AT_external
);
5204 if (attr2
&& (DW_UNSND (attr2
) != 0)
5205 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5207 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5208 add_symbol_to_list (sym
, &global_symbols
);
5212 case DW_TAG_formal_parameter
:
5213 attr
= dwarf_attr (die
, DW_AT_location
);
5216 SYMBOL_VALUE (sym
) =
5217 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
5220 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
5221 SYMBOL_VALUE (sym
) =
5222 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
5228 if (basereg
!= frame_base_reg
)
5229 dwarf2_complex_location_expr_complaint ();
5230 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
5234 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
5235 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
5240 SYMBOL_CLASS (sym
) = LOC_ARG
;
5243 attr
= dwarf_attr (die
, DW_AT_const_value
);
5246 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5248 add_symbol_to_list (sym
, list_in_scope
);
5250 case DW_TAG_unspecified_parameters
:
5251 /* From varargs functions; gdb doesn't seem to have any
5252 interest in this information, so just ignore it for now.
5255 case DW_TAG_class_type
:
5256 case DW_TAG_structure_type
:
5257 case DW_TAG_union_type
:
5258 case DW_TAG_enumeration_type
:
5259 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5260 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5261 add_symbol_to_list (sym
, list_in_scope
);
5263 /* The semantics of C++ state that "struct foo { ... }" also
5264 defines a typedef for "foo". Synthesize a typedef symbol so
5265 that "ptype foo" works as expected. */
5266 if (cu_language
== language_cplus
)
5268 struct symbol
*typedef_sym
= (struct symbol
*)
5269 obstack_alloc (&objfile
->symbol_obstack
,
5270 sizeof (struct symbol
));
5271 *typedef_sym
= *sym
;
5272 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5273 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5274 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5275 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5276 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5277 &objfile
->type_obstack
);
5278 add_symbol_to_list (typedef_sym
, list_in_scope
);
5281 case DW_TAG_typedef
:
5282 case DW_TAG_base_type
:
5283 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5284 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5285 add_symbol_to_list (sym
, list_in_scope
);
5287 case DW_TAG_enumerator
:
5288 attr
= dwarf_attr (die
, DW_AT_const_value
);
5291 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5293 add_symbol_to_list (sym
, list_in_scope
);
5296 /* Not a tag we recognize. Hopefully we aren't processing
5297 trash data, but since we must specifically ignore things
5298 we don't recognize, there is nothing else we should do at
5300 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5301 dwarf_tag_name (die
->tag
));
5308 /* Copy constant value from an attribute to a symbol. */
5311 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5312 struct objfile
*objfile
,
5313 const struct comp_unit_head
*cu_header
)
5315 struct dwarf_block
*blk
;
5320 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5321 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5322 cu_header
->addr_size
,
5323 TYPE_LENGTH (SYMBOL_TYPE
5325 SYMBOL_VALUE_BYTES (sym
) = (char *)
5326 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5327 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5328 it's body - store_unsigned_integer. */
5329 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5331 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5333 case DW_FORM_block1
:
5334 case DW_FORM_block2
:
5335 case DW_FORM_block4
:
5337 blk
= DW_BLOCK (attr
);
5338 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5339 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5341 TYPE_LENGTH (SYMBOL_TYPE
5343 SYMBOL_VALUE_BYTES (sym
) = (char *)
5344 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5345 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5346 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5349 /* The DW_AT_const_value attributes are supposed to carry the
5350 symbol's value "represented as it would be on the target
5351 architecture." By the time we get here, it's already been
5352 converted to host endianness, so we just need to sign- or
5353 zero-extend it as appropriate. */
5355 dwarf2_const_value_data (attr
, sym
, 8);
5358 dwarf2_const_value_data (attr
, sym
, 16);
5361 dwarf2_const_value_data (attr
, sym
, 32);
5364 dwarf2_const_value_data (attr
, sym
, 64);
5368 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5369 SYMBOL_CLASS (sym
) = LOC_CONST
;
5373 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5374 SYMBOL_CLASS (sym
) = LOC_CONST
;
5378 complaint (&symfile_complaints
,
5379 "unsupported const value attribute form: '%s'",
5380 dwarf_form_name (attr
->form
));
5381 SYMBOL_VALUE (sym
) = 0;
5382 SYMBOL_CLASS (sym
) = LOC_CONST
;
5388 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5389 or zero-extend it as appropriate for the symbol's type. */
5391 dwarf2_const_value_data (struct attribute
*attr
,
5395 LONGEST l
= DW_UNSND (attr
);
5397 if (bits
< sizeof (l
) * 8)
5399 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5400 l
&= ((LONGEST
) 1 << bits
) - 1;
5402 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5405 SYMBOL_VALUE (sym
) = l
;
5406 SYMBOL_CLASS (sym
) = LOC_CONST
;
5410 /* Return the type of the die in question using its DW_AT_type attribute. */
5412 static struct type
*
5413 die_type (struct die_info
*die
, struct objfile
*objfile
,
5414 const struct comp_unit_head
*cu_header
)
5417 struct attribute
*type_attr
;
5418 struct die_info
*type_die
;
5421 type_attr
= dwarf_attr (die
, DW_AT_type
);
5424 /* A missing DW_AT_type represents a void type. */
5425 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5429 ref
= dwarf2_get_ref_die_offset (type_attr
);
5430 type_die
= follow_die_ref (ref
);
5433 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5434 ref
, objfile
->name
);
5438 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5441 dump_die (type_die
);
5442 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5448 /* Return the containing type of the die in question using its
5449 DW_AT_containing_type attribute. */
5451 static struct type
*
5452 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5453 const struct comp_unit_head
*cu_header
)
5455 struct type
*type
= NULL
;
5456 struct attribute
*type_attr
;
5457 struct die_info
*type_die
= NULL
;
5460 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5463 ref
= dwarf2_get_ref_die_offset (type_attr
);
5464 type_die
= follow_die_ref (ref
);
5467 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5471 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5476 dump_die (type_die
);
5477 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5484 static struct type
*
5485 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5487 struct die_info
*die
;
5490 die
= follow_die_ref (offset
);
5493 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5496 type
= tag_type_to_type (die
, objfile
);
5501 static struct type
*
5502 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5503 const struct comp_unit_head
*cu_header
)
5511 read_type_die (die
, objfile
, cu_header
);
5515 error ("Dwarf Error: Cannot find type of die [in module %s]",
5523 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5524 const struct comp_unit_head
*cu_header
)
5528 case DW_TAG_class_type
:
5529 case DW_TAG_structure_type
:
5530 case DW_TAG_union_type
:
5531 read_structure_scope (die
, objfile
, cu_header
);
5533 case DW_TAG_enumeration_type
:
5534 read_enumeration (die
, objfile
, cu_header
);
5536 case DW_TAG_subprogram
:
5537 case DW_TAG_subroutine_type
:
5538 read_subroutine_type (die
, objfile
, cu_header
);
5540 case DW_TAG_array_type
:
5541 read_array_type (die
, objfile
, cu_header
);
5543 case DW_TAG_pointer_type
:
5544 read_tag_pointer_type (die
, objfile
, cu_header
);
5546 case DW_TAG_ptr_to_member_type
:
5547 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5549 case DW_TAG_reference_type
:
5550 read_tag_reference_type (die
, objfile
, cu_header
);
5552 case DW_TAG_const_type
:
5553 read_tag_const_type (die
, objfile
, cu_header
);
5555 case DW_TAG_volatile_type
:
5556 read_tag_volatile_type (die
, objfile
, cu_header
);
5558 case DW_TAG_string_type
:
5559 read_tag_string_type (die
, objfile
);
5561 case DW_TAG_typedef
:
5562 read_typedef (die
, objfile
, cu_header
);
5564 case DW_TAG_base_type
:
5565 read_base_type (die
, objfile
);
5568 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5569 dwarf_tag_name (die
->tag
));
5574 static struct type
*
5575 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5577 /* FIXME - this should not produce a new (struct type *)
5578 every time. It should cache base types. */
5582 case DW_ATE_address
:
5583 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5585 case DW_ATE_boolean
:
5586 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5588 case DW_ATE_complex_float
:
5591 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5595 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5601 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5605 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5612 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5615 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5619 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5623 case DW_ATE_signed_char
:
5624 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5626 case DW_ATE_unsigned
:
5630 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5633 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5637 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5641 case DW_ATE_unsigned_char
:
5642 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5645 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5652 copy_die (struct die_info
*old_die
)
5654 struct die_info
*new_die
;
5657 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5658 memset (new_die
, 0, sizeof (struct die_info
));
5660 new_die
->tag
= old_die
->tag
;
5661 new_die
->has_children
= old_die
->has_children
;
5662 new_die
->abbrev
= old_die
->abbrev
;
5663 new_die
->offset
= old_die
->offset
;
5664 new_die
->type
= NULL
;
5666 num_attrs
= old_die
->num_attrs
;
5667 new_die
->num_attrs
= num_attrs
;
5668 new_die
->attrs
= (struct attribute
*)
5669 xmalloc (num_attrs
* sizeof (struct attribute
));
5671 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5673 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5674 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5675 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5678 new_die
->next
= NULL
;
5683 /* Return sibling of die, NULL if no sibling. */
5685 static struct die_info
*
5686 sibling_die (struct die_info
*die
)
5688 int nesting_level
= 0;
5690 if (!die
->has_children
)
5692 if (die
->next
&& (die
->next
->tag
== 0))
5705 if (die
->has_children
)
5715 while (nesting_level
);
5716 if (die
&& (die
->tag
== 0))
5727 /* Get linkage name of a die, return NULL if not found. */
5730 dwarf2_linkage_name (struct die_info
*die
)
5732 struct attribute
*attr
;
5734 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5735 if (attr
&& DW_STRING (attr
))
5736 return DW_STRING (attr
);
5737 attr
= dwarf_attr (die
, DW_AT_name
);
5738 if (attr
&& DW_STRING (attr
))
5739 return DW_STRING (attr
);
5743 /* Get name of a die, return NULL if not found. */
5746 dwarf2_name (struct die_info
*die
)
5748 struct attribute
*attr
;
5750 attr
= dwarf_attr (die
, DW_AT_name
);
5751 if (attr
&& DW_STRING (attr
))
5752 return DW_STRING (attr
);
5756 /* Return the die that this die in an extension of, or NULL if there
5759 static struct die_info
*
5760 dwarf2_extension (struct die_info
*die
)
5762 struct attribute
*attr
;
5763 struct die_info
*extension_die
;
5766 attr
= dwarf_attr (die
, DW_AT_extension
);
5770 ref
= dwarf2_get_ref_die_offset (attr
);
5771 extension_die
= follow_die_ref (ref
);
5774 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5777 return extension_die
;
5780 /* Convert a DIE tag into its string name. */
5783 dwarf_tag_name (register unsigned tag
)
5787 case DW_TAG_padding
:
5788 return "DW_TAG_padding";
5789 case DW_TAG_array_type
:
5790 return "DW_TAG_array_type";
5791 case DW_TAG_class_type
:
5792 return "DW_TAG_class_type";
5793 case DW_TAG_entry_point
:
5794 return "DW_TAG_entry_point";
5795 case DW_TAG_enumeration_type
:
5796 return "DW_TAG_enumeration_type";
5797 case DW_TAG_formal_parameter
:
5798 return "DW_TAG_formal_parameter";
5799 case DW_TAG_imported_declaration
:
5800 return "DW_TAG_imported_declaration";
5802 return "DW_TAG_label";
5803 case DW_TAG_lexical_block
:
5804 return "DW_TAG_lexical_block";
5806 return "DW_TAG_member";
5807 case DW_TAG_pointer_type
:
5808 return "DW_TAG_pointer_type";
5809 case DW_TAG_reference_type
:
5810 return "DW_TAG_reference_type";
5811 case DW_TAG_compile_unit
:
5812 return "DW_TAG_compile_unit";
5813 case DW_TAG_string_type
:
5814 return "DW_TAG_string_type";
5815 case DW_TAG_structure_type
:
5816 return "DW_TAG_structure_type";
5817 case DW_TAG_subroutine_type
:
5818 return "DW_TAG_subroutine_type";
5819 case DW_TAG_typedef
:
5820 return "DW_TAG_typedef";
5821 case DW_TAG_union_type
:
5822 return "DW_TAG_union_type";
5823 case DW_TAG_unspecified_parameters
:
5824 return "DW_TAG_unspecified_parameters";
5825 case DW_TAG_variant
:
5826 return "DW_TAG_variant";
5827 case DW_TAG_common_block
:
5828 return "DW_TAG_common_block";
5829 case DW_TAG_common_inclusion
:
5830 return "DW_TAG_common_inclusion";
5831 case DW_TAG_inheritance
:
5832 return "DW_TAG_inheritance";
5833 case DW_TAG_inlined_subroutine
:
5834 return "DW_TAG_inlined_subroutine";
5836 return "DW_TAG_module";
5837 case DW_TAG_ptr_to_member_type
:
5838 return "DW_TAG_ptr_to_member_type";
5839 case DW_TAG_set_type
:
5840 return "DW_TAG_set_type";
5841 case DW_TAG_subrange_type
:
5842 return "DW_TAG_subrange_type";
5843 case DW_TAG_with_stmt
:
5844 return "DW_TAG_with_stmt";
5845 case DW_TAG_access_declaration
:
5846 return "DW_TAG_access_declaration";
5847 case DW_TAG_base_type
:
5848 return "DW_TAG_base_type";
5849 case DW_TAG_catch_block
:
5850 return "DW_TAG_catch_block";
5851 case DW_TAG_const_type
:
5852 return "DW_TAG_const_type";
5853 case DW_TAG_constant
:
5854 return "DW_TAG_constant";
5855 case DW_TAG_enumerator
:
5856 return "DW_TAG_enumerator";
5857 case DW_TAG_file_type
:
5858 return "DW_TAG_file_type";
5860 return "DW_TAG_friend";
5861 case DW_TAG_namelist
:
5862 return "DW_TAG_namelist";
5863 case DW_TAG_namelist_item
:
5864 return "DW_TAG_namelist_item";
5865 case DW_TAG_packed_type
:
5866 return "DW_TAG_packed_type";
5867 case DW_TAG_subprogram
:
5868 return "DW_TAG_subprogram";
5869 case DW_TAG_template_type_param
:
5870 return "DW_TAG_template_type_param";
5871 case DW_TAG_template_value_param
:
5872 return "DW_TAG_template_value_param";
5873 case DW_TAG_thrown_type
:
5874 return "DW_TAG_thrown_type";
5875 case DW_TAG_try_block
:
5876 return "DW_TAG_try_block";
5877 case DW_TAG_variant_part
:
5878 return "DW_TAG_variant_part";
5879 case DW_TAG_variable
:
5880 return "DW_TAG_variable";
5881 case DW_TAG_volatile_type
:
5882 return "DW_TAG_volatile_type";
5883 case DW_TAG_dwarf_procedure
:
5884 return "DW_TAG_dwarf_procedure";
5885 case DW_TAG_restrict_type
:
5886 return "DW_TAG_restrict_type";
5887 case DW_TAG_interface_type
:
5888 return "DW_TAG_interface_type";
5889 case DW_TAG_namespace
:
5890 return "DW_TAG_namespace";
5891 case DW_TAG_imported_module
:
5892 return "DW_TAG_imported_module";
5893 case DW_TAG_unspecified_type
:
5894 return "DW_TAG_unspecified_type";
5895 case DW_TAG_partial_unit
:
5896 return "DW_TAG_partial_unit";
5897 case DW_TAG_imported_unit
:
5898 return "DW_TAG_imported_unit";
5899 case DW_TAG_MIPS_loop
:
5900 return "DW_TAG_MIPS_loop";
5901 case DW_TAG_format_label
:
5902 return "DW_TAG_format_label";
5903 case DW_TAG_function_template
:
5904 return "DW_TAG_function_template";
5905 case DW_TAG_class_template
:
5906 return "DW_TAG_class_template";
5908 return "DW_TAG_<unknown>";
5912 /* Convert a DWARF attribute code into its string name. */
5915 dwarf_attr_name (register unsigned attr
)
5920 return "DW_AT_sibling";
5921 case DW_AT_location
:
5922 return "DW_AT_location";
5924 return "DW_AT_name";
5925 case DW_AT_ordering
:
5926 return "DW_AT_ordering";
5927 case DW_AT_subscr_data
:
5928 return "DW_AT_subscr_data";
5929 case DW_AT_byte_size
:
5930 return "DW_AT_byte_size";
5931 case DW_AT_bit_offset
:
5932 return "DW_AT_bit_offset";
5933 case DW_AT_bit_size
:
5934 return "DW_AT_bit_size";
5935 case DW_AT_element_list
:
5936 return "DW_AT_element_list";
5937 case DW_AT_stmt_list
:
5938 return "DW_AT_stmt_list";
5940 return "DW_AT_low_pc";
5942 return "DW_AT_high_pc";
5943 case DW_AT_language
:
5944 return "DW_AT_language";
5946 return "DW_AT_member";
5948 return "DW_AT_discr";
5949 case DW_AT_discr_value
:
5950 return "DW_AT_discr_value";
5951 case DW_AT_visibility
:
5952 return "DW_AT_visibility";
5954 return "DW_AT_import";
5955 case DW_AT_string_length
:
5956 return "DW_AT_string_length";
5957 case DW_AT_common_reference
:
5958 return "DW_AT_common_reference";
5959 case DW_AT_comp_dir
:
5960 return "DW_AT_comp_dir";
5961 case DW_AT_const_value
:
5962 return "DW_AT_const_value";
5963 case DW_AT_containing_type
:
5964 return "DW_AT_containing_type";
5965 case DW_AT_default_value
:
5966 return "DW_AT_default_value";
5968 return "DW_AT_inline";
5969 case DW_AT_is_optional
:
5970 return "DW_AT_is_optional";
5971 case DW_AT_lower_bound
:
5972 return "DW_AT_lower_bound";
5973 case DW_AT_producer
:
5974 return "DW_AT_producer";
5975 case DW_AT_prototyped
:
5976 return "DW_AT_prototyped";
5977 case DW_AT_return_addr
:
5978 return "DW_AT_return_addr";
5979 case DW_AT_start_scope
:
5980 return "DW_AT_start_scope";
5981 case DW_AT_stride_size
:
5982 return "DW_AT_stride_size";
5983 case DW_AT_upper_bound
:
5984 return "DW_AT_upper_bound";
5985 case DW_AT_abstract_origin
:
5986 return "DW_AT_abstract_origin";
5987 case DW_AT_accessibility
:
5988 return "DW_AT_accessibility";
5989 case DW_AT_address_class
:
5990 return "DW_AT_address_class";
5991 case DW_AT_artificial
:
5992 return "DW_AT_artificial";
5993 case DW_AT_base_types
:
5994 return "DW_AT_base_types";
5995 case DW_AT_calling_convention
:
5996 return "DW_AT_calling_convention";
5998 return "DW_AT_count";
5999 case DW_AT_data_member_location
:
6000 return "DW_AT_data_member_location";
6001 case DW_AT_decl_column
:
6002 return "DW_AT_decl_column";
6003 case DW_AT_decl_file
:
6004 return "DW_AT_decl_file";
6005 case DW_AT_decl_line
:
6006 return "DW_AT_decl_line";
6007 case DW_AT_declaration
:
6008 return "DW_AT_declaration";
6009 case DW_AT_discr_list
:
6010 return "DW_AT_discr_list";
6011 case DW_AT_encoding
:
6012 return "DW_AT_encoding";
6013 case DW_AT_external
:
6014 return "DW_AT_external";
6015 case DW_AT_frame_base
:
6016 return "DW_AT_frame_base";
6018 return "DW_AT_friend";
6019 case DW_AT_identifier_case
:
6020 return "DW_AT_identifier_case";
6021 case DW_AT_macro_info
:
6022 return "DW_AT_macro_info";
6023 case DW_AT_namelist_items
:
6024 return "DW_AT_namelist_items";
6025 case DW_AT_priority
:
6026 return "DW_AT_priority";
6028 return "DW_AT_segment";
6029 case DW_AT_specification
:
6030 return "DW_AT_specification";
6031 case DW_AT_static_link
:
6032 return "DW_AT_static_link";
6034 return "DW_AT_type";
6035 case DW_AT_use_location
:
6036 return "DW_AT_use_location";
6037 case DW_AT_variable_parameter
:
6038 return "DW_AT_variable_parameter";
6039 case DW_AT_virtuality
:
6040 return "DW_AT_virtuality";
6041 case DW_AT_vtable_elem_location
:
6042 return "DW_AT_vtable_elem_location";
6043 case DW_AT_allocated
:
6044 return "DW_AT_allocated";
6045 case DW_AT_associated
:
6046 return "DW_AT_associated";
6047 case DW_AT_data_location
:
6048 return "DW_AT_data_location";
6050 return "DW_AT_stride";
6051 case DW_AT_entry_pc
:
6052 return "DW_AT_entry_pc";
6053 case DW_AT_use_UTF8
:
6054 return "DW_AT_use_UTF8";
6055 case DW_AT_extension
:
6056 return "DW_AT_extension";
6058 return "DW_AT_ranges";
6059 case DW_AT_trampoline
:
6060 return "DW_AT_trampoline";
6061 case DW_AT_call_column
:
6062 return "DW_AT_call_column";
6063 case DW_AT_call_file
:
6064 return "DW_AT_call_file";
6065 case DW_AT_call_line
:
6066 return "DW_AT_call_line";
6068 case DW_AT_MIPS_fde
:
6069 return "DW_AT_MIPS_fde";
6070 case DW_AT_MIPS_loop_begin
:
6071 return "DW_AT_MIPS_loop_begin";
6072 case DW_AT_MIPS_tail_loop_begin
:
6073 return "DW_AT_MIPS_tail_loop_begin";
6074 case DW_AT_MIPS_epilog_begin
:
6075 return "DW_AT_MIPS_epilog_begin";
6076 case DW_AT_MIPS_loop_unroll_factor
:
6077 return "DW_AT_MIPS_loop_unroll_factor";
6078 case DW_AT_MIPS_software_pipeline_depth
:
6079 return "DW_AT_MIPS_software_pipeline_depth";
6080 case DW_AT_MIPS_linkage_name
:
6081 return "DW_AT_MIPS_linkage_name";
6084 case DW_AT_sf_names
:
6085 return "DW_AT_sf_names";
6086 case DW_AT_src_info
:
6087 return "DW_AT_src_info";
6088 case DW_AT_mac_info
:
6089 return "DW_AT_mac_info";
6090 case DW_AT_src_coords
:
6091 return "DW_AT_src_coords";
6092 case DW_AT_body_begin
:
6093 return "DW_AT_body_begin";
6094 case DW_AT_body_end
:
6095 return "DW_AT_body_end";
6096 case DW_AT_GNU_vector
:
6097 return "DW_AT_GNU_vector";
6099 return "DW_AT_<unknown>";
6103 /* Convert a DWARF value form code into its string name. */
6106 dwarf_form_name (register unsigned form
)
6111 return "DW_FORM_addr";
6112 case DW_FORM_block2
:
6113 return "DW_FORM_block2";
6114 case DW_FORM_block4
:
6115 return "DW_FORM_block4";
6117 return "DW_FORM_data2";
6119 return "DW_FORM_data4";
6121 return "DW_FORM_data8";
6122 case DW_FORM_string
:
6123 return "DW_FORM_string";
6125 return "DW_FORM_block";
6126 case DW_FORM_block1
:
6127 return "DW_FORM_block1";
6129 return "DW_FORM_data1";
6131 return "DW_FORM_flag";
6133 return "DW_FORM_sdata";
6135 return "DW_FORM_strp";
6137 return "DW_FORM_udata";
6138 case DW_FORM_ref_addr
:
6139 return "DW_FORM_ref_addr";
6141 return "DW_FORM_ref1";
6143 return "DW_FORM_ref2";
6145 return "DW_FORM_ref4";
6147 return "DW_FORM_ref8";
6148 case DW_FORM_ref_udata
:
6149 return "DW_FORM_ref_udata";
6150 case DW_FORM_indirect
:
6151 return "DW_FORM_indirect";
6153 return "DW_FORM_<unknown>";
6157 /* Convert a DWARF stack opcode into its string name. */
6160 dwarf_stack_op_name (register unsigned op
)
6165 return "DW_OP_addr";
6167 return "DW_OP_deref";
6169 return "DW_OP_const1u";
6171 return "DW_OP_const1s";
6173 return "DW_OP_const2u";
6175 return "DW_OP_const2s";
6177 return "DW_OP_const4u";
6179 return "DW_OP_const4s";
6181 return "DW_OP_const8u";
6183 return "DW_OP_const8s";
6185 return "DW_OP_constu";
6187 return "DW_OP_consts";
6191 return "DW_OP_drop";
6193 return "DW_OP_over";
6195 return "DW_OP_pick";
6197 return "DW_OP_swap";
6201 return "DW_OP_xderef";
6209 return "DW_OP_minus";
6221 return "DW_OP_plus";
6222 case DW_OP_plus_uconst
:
6223 return "DW_OP_plus_uconst";
6229 return "DW_OP_shra";
6247 return "DW_OP_skip";
6249 return "DW_OP_lit0";
6251 return "DW_OP_lit1";
6253 return "DW_OP_lit2";
6255 return "DW_OP_lit3";
6257 return "DW_OP_lit4";
6259 return "DW_OP_lit5";
6261 return "DW_OP_lit6";
6263 return "DW_OP_lit7";
6265 return "DW_OP_lit8";
6267 return "DW_OP_lit9";
6269 return "DW_OP_lit10";
6271 return "DW_OP_lit11";
6273 return "DW_OP_lit12";
6275 return "DW_OP_lit13";
6277 return "DW_OP_lit14";
6279 return "DW_OP_lit15";
6281 return "DW_OP_lit16";
6283 return "DW_OP_lit17";
6285 return "DW_OP_lit18";
6287 return "DW_OP_lit19";
6289 return "DW_OP_lit20";
6291 return "DW_OP_lit21";
6293 return "DW_OP_lit22";
6295 return "DW_OP_lit23";
6297 return "DW_OP_lit24";
6299 return "DW_OP_lit25";
6301 return "DW_OP_lit26";
6303 return "DW_OP_lit27";
6305 return "DW_OP_lit28";
6307 return "DW_OP_lit29";
6309 return "DW_OP_lit30";
6311 return "DW_OP_lit31";
6313 return "DW_OP_reg0";
6315 return "DW_OP_reg1";
6317 return "DW_OP_reg2";
6319 return "DW_OP_reg3";
6321 return "DW_OP_reg4";
6323 return "DW_OP_reg5";
6325 return "DW_OP_reg6";
6327 return "DW_OP_reg7";
6329 return "DW_OP_reg8";
6331 return "DW_OP_reg9";
6333 return "DW_OP_reg10";
6335 return "DW_OP_reg11";
6337 return "DW_OP_reg12";
6339 return "DW_OP_reg13";
6341 return "DW_OP_reg14";
6343 return "DW_OP_reg15";
6345 return "DW_OP_reg16";
6347 return "DW_OP_reg17";
6349 return "DW_OP_reg18";
6351 return "DW_OP_reg19";
6353 return "DW_OP_reg20";
6355 return "DW_OP_reg21";
6357 return "DW_OP_reg22";
6359 return "DW_OP_reg23";
6361 return "DW_OP_reg24";
6363 return "DW_OP_reg25";
6365 return "DW_OP_reg26";
6367 return "DW_OP_reg27";
6369 return "DW_OP_reg28";
6371 return "DW_OP_reg29";
6373 return "DW_OP_reg30";
6375 return "DW_OP_reg31";
6377 return "DW_OP_breg0";
6379 return "DW_OP_breg1";
6381 return "DW_OP_breg2";
6383 return "DW_OP_breg3";
6385 return "DW_OP_breg4";
6387 return "DW_OP_breg5";
6389 return "DW_OP_breg6";
6391 return "DW_OP_breg7";
6393 return "DW_OP_breg8";
6395 return "DW_OP_breg9";
6397 return "DW_OP_breg10";
6399 return "DW_OP_breg11";
6401 return "DW_OP_breg12";
6403 return "DW_OP_breg13";
6405 return "DW_OP_breg14";
6407 return "DW_OP_breg15";
6409 return "DW_OP_breg16";
6411 return "DW_OP_breg17";
6413 return "DW_OP_breg18";
6415 return "DW_OP_breg19";
6417 return "DW_OP_breg20";
6419 return "DW_OP_breg21";
6421 return "DW_OP_breg22";
6423 return "DW_OP_breg23";
6425 return "DW_OP_breg24";
6427 return "DW_OP_breg25";
6429 return "DW_OP_breg26";
6431 return "DW_OP_breg27";
6433 return "DW_OP_breg28";
6435 return "DW_OP_breg29";
6437 return "DW_OP_breg30";
6439 return "DW_OP_breg31";
6441 return "DW_OP_regx";
6443 return "DW_OP_fbreg";
6445 return "DW_OP_bregx";
6447 return "DW_OP_piece";
6448 case DW_OP_deref_size
:
6449 return "DW_OP_deref_size";
6450 case DW_OP_xderef_size
:
6451 return "DW_OP_xderef_size";
6454 /* DWARF 3 extensions. */
6455 case DW_OP_push_object_address
:
6456 return "DW_OP_push_object_address";
6458 return "DW_OP_call2";
6460 return "DW_OP_call4";
6461 case DW_OP_call_ref
:
6462 return "DW_OP_call_ref";
6463 /* GNU extensions. */
6464 case DW_OP_GNU_push_tls_address
:
6465 return "DW_OP_GNU_push_tls_address";
6467 return "OP_<unknown>";
6472 dwarf_bool_name (unsigned mybool
)
6480 /* Convert a DWARF type code into its string name. */
6483 dwarf_type_encoding_name (register unsigned enc
)
6487 case DW_ATE_address
:
6488 return "DW_ATE_address";
6489 case DW_ATE_boolean
:
6490 return "DW_ATE_boolean";
6491 case DW_ATE_complex_float
:
6492 return "DW_ATE_complex_float";
6494 return "DW_ATE_float";
6496 return "DW_ATE_signed";
6497 case DW_ATE_signed_char
:
6498 return "DW_ATE_signed_char";
6499 case DW_ATE_unsigned
:
6500 return "DW_ATE_unsigned";
6501 case DW_ATE_unsigned_char
:
6502 return "DW_ATE_unsigned_char";
6503 case DW_ATE_imaginary_float
:
6504 return "DW_ATE_imaginary_float";
6506 return "DW_ATE_<unknown>";
6510 /* Convert a DWARF call frame info operation to its string name. */
6514 dwarf_cfi_name (register unsigned cfi_opc
)
6518 case DW_CFA_advance_loc
:
6519 return "DW_CFA_advance_loc";
6521 return "DW_CFA_offset";
6522 case DW_CFA_restore
:
6523 return "DW_CFA_restore";
6525 return "DW_CFA_nop";
6526 case DW_CFA_set_loc
:
6527 return "DW_CFA_set_loc";
6528 case DW_CFA_advance_loc1
:
6529 return "DW_CFA_advance_loc1";
6530 case DW_CFA_advance_loc2
:
6531 return "DW_CFA_advance_loc2";
6532 case DW_CFA_advance_loc4
:
6533 return "DW_CFA_advance_loc4";
6534 case DW_CFA_offset_extended
:
6535 return "DW_CFA_offset_extended";
6536 case DW_CFA_restore_extended
:
6537 return "DW_CFA_restore_extended";
6538 case DW_CFA_undefined
:
6539 return "DW_CFA_undefined";
6540 case DW_CFA_same_value
:
6541 return "DW_CFA_same_value";
6542 case DW_CFA_register
:
6543 return "DW_CFA_register";
6544 case DW_CFA_remember_state
:
6545 return "DW_CFA_remember_state";
6546 case DW_CFA_restore_state
:
6547 return "DW_CFA_restore_state";
6548 case DW_CFA_def_cfa
:
6549 return "DW_CFA_def_cfa";
6550 case DW_CFA_def_cfa_register
:
6551 return "DW_CFA_def_cfa_register";
6552 case DW_CFA_def_cfa_offset
:
6553 return "DW_CFA_def_cfa_offset";
6556 case DW_CFA_def_cfa_expression
:
6557 return "DW_CFA_def_cfa_expression";
6558 case DW_CFA_expression
:
6559 return "DW_CFA_expression";
6560 case DW_CFA_offset_extended_sf
:
6561 return "DW_CFA_offset_extended_sf";
6562 case DW_CFA_def_cfa_sf
:
6563 return "DW_CFA_def_cfa_sf";
6564 case DW_CFA_def_cfa_offset_sf
:
6565 return "DW_CFA_def_cfa_offset_sf";
6567 /* SGI/MIPS specific */
6568 case DW_CFA_MIPS_advance_loc8
:
6569 return "DW_CFA_MIPS_advance_loc8";
6571 /* GNU extensions */
6572 case DW_CFA_GNU_window_save
:
6573 return "DW_CFA_GNU_window_save";
6574 case DW_CFA_GNU_args_size
:
6575 return "DW_CFA_GNU_args_size";
6576 case DW_CFA_GNU_negative_offset_extended
:
6577 return "DW_CFA_GNU_negative_offset_extended";
6580 return "DW_CFA_<unknown>";
6586 dump_die (struct die_info
*die
)
6590 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6591 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6592 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6593 dwarf_bool_name (die
->has_children
));
6595 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6596 for (i
= 0; i
< die
->num_attrs
; ++i
)
6598 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6599 dwarf_attr_name (die
->attrs
[i
].name
),
6600 dwarf_form_name (die
->attrs
[i
].form
));
6601 switch (die
->attrs
[i
].form
)
6603 case DW_FORM_ref_addr
:
6605 fprintf_unfiltered (gdb_stderr
, "address: ");
6606 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6608 case DW_FORM_block2
:
6609 case DW_FORM_block4
:
6611 case DW_FORM_block1
:
6612 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6623 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6625 case DW_FORM_string
:
6627 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6628 DW_STRING (&die
->attrs
[i
])
6629 ? DW_STRING (&die
->attrs
[i
]) : "");
6632 if (DW_UNSND (&die
->attrs
[i
]))
6633 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6635 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6637 case DW_FORM_indirect
:
6638 /* the reader will have reduced the indirect form to
6639 the "base form" so this form should not occur */
6640 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6643 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6644 die
->attrs
[i
].form
);
6646 fprintf_unfiltered (gdb_stderr
, "\n");
6651 dump_die_list (struct die_info
*die
)
6661 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6664 struct die_info
*old
;
6666 h
= (offset
% REF_HASH_SIZE
);
6667 old
= die_ref_table
[h
];
6668 die
->next_ref
= old
;
6669 die_ref_table
[h
] = die
;
6674 dwarf2_empty_hash_tables (void)
6676 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6680 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6682 unsigned int result
= 0;
6686 case DW_FORM_ref_addr
:
6687 result
= DW_ADDR (attr
);
6693 case DW_FORM_ref_udata
:
6694 result
= cu_header_offset
+ DW_UNSND (attr
);
6697 complaint (&symfile_complaints
,
6698 "unsupported die ref attribute form: '%s'",
6699 dwarf_form_name (attr
->form
));
6704 static struct die_info
*
6705 follow_die_ref (unsigned int offset
)
6707 struct die_info
*die
;
6710 h
= (offset
% REF_HASH_SIZE
);
6711 die
= die_ref_table
[h
];
6714 if (die
->offset
== offset
)
6718 die
= die
->next_ref
;
6723 static struct type
*
6724 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6726 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6728 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6729 typeid, objfile
->name
);
6732 /* Look for this particular type in the fundamental type vector. If
6733 one is not found, create and install one appropriate for the
6734 current language and the current target machine. */
6736 if (ftypes
[typeid] == NULL
)
6738 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6741 return (ftypes
[typeid]);
6744 /* Decode simple location descriptions.
6745 Given a pointer to a dwarf block that defines a location, compute
6746 the location and return the value.
6748 FIXME: This is a kludge until we figure out a better
6749 way to handle the location descriptions.
6750 Gdb's design does not mesh well with the DWARF2 notion of a location
6751 computing interpreter, which is a shame because the flexibility goes unused.
6752 FIXME: Implement more operations as necessary.
6754 A location description containing no operations indicates that the
6755 object is optimized out. The global optimized_out flag is set for
6756 those, the return value is meaningless.
6758 When the result is a register number, the global isreg flag is set,
6759 otherwise it is cleared.
6761 When the result is a base register offset, the global offreg flag is set
6762 and the register number is returned in basereg, otherwise it is cleared.
6764 When the DW_OP_fbreg operation is encountered without a corresponding
6765 DW_AT_frame_base attribute, the global islocal flag is set.
6766 Hopefully the machine dependent code knows how to set up a virtual
6767 frame pointer for the local references.
6769 Note that stack[0] is unused except as a default error return.
6770 Note that stack overflow is not yet handled. */
6773 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6774 const struct comp_unit_head
*cu_header
)
6777 int size
= blk
->size
;
6778 char *data
= blk
->data
;
6779 CORE_ADDR stack
[64];
6781 unsigned int bytes_read
, unsnd
;
6791 is_thread_local
= 0;
6832 stack
[++stacki
] = op
- DW_OP_lit0
;
6868 stack
[++stacki
] = op
- DW_OP_reg0
;
6873 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6875 stack
[++stacki
] = unsnd
;
6911 basereg
= op
- DW_OP_breg0
;
6912 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6918 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6920 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6925 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6927 if (frame_base_reg
>= 0)
6930 basereg
= frame_base_reg
;
6931 stack
[stacki
] += frame_base_offset
;
6935 complaint (&symfile_complaints
,
6936 "DW_AT_frame_base missing for DW_OP_fbreg");
6942 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6943 cu_header
, &bytes_read
);
6948 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6953 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6958 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6963 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6968 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6973 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6978 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6984 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6989 stack
[stacki
+ 1] = stack
[stacki
];
6994 stack
[stacki
- 1] += stack
[stacki
];
6998 case DW_OP_plus_uconst
:
6999 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7004 stack
[stacki
- 1] -= stack
[stacki
];
7010 /* If we're not the last op, then we definitely can't encode
7011 this using GDB's address_class enum. */
7013 dwarf2_complex_location_expr_complaint ();
7016 case DW_OP_GNU_push_tls_address
:
7017 is_thread_local
= 1;
7018 /* The top of the stack has the offset from the beginning
7019 of the thread control block at which the variable is located. */
7020 /* Nothing should follow this operator, so the top of stack would
7023 dwarf2_complex_location_expr_complaint ();
7027 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7028 dwarf_stack_op_name (op
));
7029 return (stack
[stacki
]);
7032 return (stack
[stacki
]);
7035 /* memory allocation interface */
7039 dwarf2_free_tmp_obstack (void *ignore
)
7041 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7044 static struct dwarf_block
*
7045 dwarf_alloc_block (void)
7047 struct dwarf_block
*blk
;
7049 blk
= (struct dwarf_block
*)
7050 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7054 static struct abbrev_info
*
7055 dwarf_alloc_abbrev (void)
7057 struct abbrev_info
*abbrev
;
7059 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7060 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7064 static struct die_info
*
7065 dwarf_alloc_die (void)
7067 struct die_info
*die
;
7069 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7070 memset (die
, 0, sizeof (struct die_info
));
7075 /* Macro support. */
7078 /* Return the full name of file number I in *LH's file name table.
7079 Use COMP_DIR as the name of the current directory of the
7080 compilation. The result is allocated using xmalloc; the caller is
7081 responsible for freeing it. */
7083 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7085 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7087 if (IS_ABSOLUTE_PATH (fe
->name
))
7088 return xstrdup (fe
->name
);
7096 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7102 dir_len
= strlen (dir
);
7103 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7104 strcpy (full_name
, dir
);
7105 full_name
[dir_len
] = '/';
7106 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7110 return xstrdup (fe
->name
);
7115 static struct macro_source_file
*
7116 macro_start_file (int file
, int line
,
7117 struct macro_source_file
*current_file
,
7118 const char *comp_dir
,
7119 struct line_header
*lh
, struct objfile
*objfile
)
7121 /* The full name of this source file. */
7122 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7124 /* We don't create a macro table for this compilation unit
7125 at all until we actually get a filename. */
7126 if (! pending_macros
)
7127 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7128 objfile
->macro_cache
);
7131 /* If we have no current file, then this must be the start_file
7132 directive for the compilation unit's main source file. */
7133 current_file
= macro_set_main (pending_macros
, full_name
);
7135 current_file
= macro_include (current_file
, line
, full_name
);
7139 return current_file
;
7143 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7144 followed by a null byte. */
7146 copy_string (const char *buf
, int len
)
7148 char *s
= xmalloc (len
+ 1);
7149 memcpy (s
, buf
, len
);
7157 consume_improper_spaces (const char *p
, const char *body
)
7161 complaint (&symfile_complaints
,
7162 "macro definition contains spaces in formal argument list:\n`%s'",
7174 parse_macro_definition (struct macro_source_file
*file
, int line
,
7179 /* The body string takes one of two forms. For object-like macro
7180 definitions, it should be:
7182 <macro name> " " <definition>
7184 For function-like macro definitions, it should be:
7186 <macro name> "() " <definition>
7188 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7190 Spaces may appear only where explicitly indicated, and in the
7193 The Dwarf 2 spec says that an object-like macro's name is always
7194 followed by a space, but versions of GCC around March 2002 omit
7195 the space when the macro's definition is the empty string.
7197 The Dwarf 2 spec says that there should be no spaces between the
7198 formal arguments in a function-like macro's formal argument list,
7199 but versions of GCC around March 2002 include spaces after the
7203 /* Find the extent of the macro name. The macro name is terminated
7204 by either a space or null character (for an object-like macro) or
7205 an opening paren (for a function-like macro). */
7206 for (p
= body
; *p
; p
++)
7207 if (*p
== ' ' || *p
== '(')
7210 if (*p
== ' ' || *p
== '\0')
7212 /* It's an object-like macro. */
7213 int name_len
= p
- body
;
7214 char *name
= copy_string (body
, name_len
);
7215 const char *replacement
;
7218 replacement
= body
+ name_len
+ 1;
7221 dwarf2_macro_malformed_definition_complaint (body
);
7222 replacement
= body
+ name_len
;
7225 macro_define_object (file
, line
, name
, replacement
);
7231 /* It's a function-like macro. */
7232 char *name
= copy_string (body
, p
- body
);
7235 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7239 p
= consume_improper_spaces (p
, body
);
7241 /* Parse the formal argument list. */
7242 while (*p
&& *p
!= ')')
7244 /* Find the extent of the current argument name. */
7245 const char *arg_start
= p
;
7247 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7250 if (! *p
|| p
== arg_start
)
7251 dwarf2_macro_malformed_definition_complaint (body
);
7254 /* Make sure argv has room for the new argument. */
7255 if (argc
>= argv_size
)
7258 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7261 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7264 p
= consume_improper_spaces (p
, body
);
7266 /* Consume the comma, if present. */
7271 p
= consume_improper_spaces (p
, body
);
7280 /* Perfectly formed definition, no complaints. */
7281 macro_define_function (file
, line
, name
,
7282 argc
, (const char **) argv
,
7284 else if (*p
== '\0')
7286 /* Complain, but do define it. */
7287 dwarf2_macro_malformed_definition_complaint (body
);
7288 macro_define_function (file
, line
, name
,
7289 argc
, (const char **) argv
,
7293 /* Just complain. */
7294 dwarf2_macro_malformed_definition_complaint (body
);
7297 /* Just complain. */
7298 dwarf2_macro_malformed_definition_complaint (body
);
7304 for (i
= 0; i
< argc
; i
++)
7310 dwarf2_macro_malformed_definition_complaint (body
);
7315 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7316 char *comp_dir
, bfd
*abfd
,
7317 const struct comp_unit_head
*cu_header
,
7318 struct objfile
*objfile
)
7320 char *mac_ptr
, *mac_end
;
7321 struct macro_source_file
*current_file
= 0;
7323 if (dwarf_macinfo_buffer
== NULL
)
7325 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7329 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7330 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7334 enum dwarf_macinfo_record_type macinfo_type
;
7336 /* Do we at least have room for a macinfo type byte? */
7337 if (mac_ptr
>= mac_end
)
7339 dwarf2_macros_too_long_complaint ();
7343 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7346 switch (macinfo_type
)
7348 /* A zero macinfo type indicates the end of the macro
7353 case DW_MACINFO_define
:
7354 case DW_MACINFO_undef
:
7360 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7361 mac_ptr
+= bytes_read
;
7362 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7363 mac_ptr
+= bytes_read
;
7366 complaint (&symfile_complaints
,
7367 "debug info gives macro %s outside of any file: %s",
7369 DW_MACINFO_define
? "definition" : macinfo_type
==
7370 DW_MACINFO_undef
? "undefinition" :
7371 "something-or-other", body
);
7374 if (macinfo_type
== DW_MACINFO_define
)
7375 parse_macro_definition (current_file
, line
, body
);
7376 else if (macinfo_type
== DW_MACINFO_undef
)
7377 macro_undef (current_file
, line
, body
);
7382 case DW_MACINFO_start_file
:
7387 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7388 mac_ptr
+= bytes_read
;
7389 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7390 mac_ptr
+= bytes_read
;
7392 current_file
= macro_start_file (file
, line
,
7393 current_file
, comp_dir
,
7398 case DW_MACINFO_end_file
:
7400 complaint (&symfile_complaints
,
7401 "macro debug info has an unmatched `close_file' directive");
7404 current_file
= current_file
->included_by
;
7407 enum dwarf_macinfo_record_type next_type
;
7409 /* GCC circa March 2002 doesn't produce the zero
7410 type byte marking the end of the compilation
7411 unit. Complain if it's not there, but exit no
7414 /* Do we at least have room for a macinfo type byte? */
7415 if (mac_ptr
>= mac_end
)
7417 dwarf2_macros_too_long_complaint ();
7421 /* We don't increment mac_ptr here, so this is just
7423 next_type
= read_1_byte (abfd
, mac_ptr
);
7425 complaint (&symfile_complaints
,
7426 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7433 case DW_MACINFO_vendor_ext
:
7439 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7440 mac_ptr
+= bytes_read
;
7441 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7442 mac_ptr
+= bytes_read
;
7444 /* We don't recognize any vendor extensions. */
7451 /* Check if the attribute's form is a DW_FORM_block*
7452 if so return true else false. */
7454 attr_form_is_block (struct attribute
*attr
)
7456 return (attr
== NULL
? 0 :
7457 attr
->form
== DW_FORM_block1
7458 || attr
->form
== DW_FORM_block2
7459 || attr
->form
== DW_FORM_block4
7460 || attr
->form
== DW_FORM_block
);
7464 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7465 const struct comp_unit_head
*cu_header
,
7466 struct objfile
*objfile
)
7468 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7470 struct dwarf2_loclist_baton
*baton
;
7472 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7473 sizeof (struct dwarf2_loclist_baton
));
7474 baton
->objfile
= objfile
;
7476 /* We don't know how long the location list is, but make sure we
7477 don't run off the edge of the section. */
7478 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7479 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7480 baton
->base_address
= cu_header
->base_address
;
7481 if (cu_header
->base_known
== 0)
7482 complaint (&symfile_complaints
,
7483 "Location list used without specifying the CU base address.");
7485 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7486 SYMBOL_LOCATION_BATON (sym
) = baton
;
7490 struct dwarf2_locexpr_baton
*baton
;
7492 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7493 sizeof (struct dwarf2_locexpr_baton
));
7494 baton
->objfile
= objfile
;
7496 if (attr_form_is_block (attr
))
7498 /* Note that we're just copying the block's data pointer
7499 here, not the actual data. We're still pointing into the
7500 dwarf_info_buffer for SYM's objfile; right now we never
7501 release that buffer, but when we do clean up properly
7502 this may need to change. */
7503 baton
->size
= DW_BLOCK (attr
)->size
;
7504 baton
->data
= DW_BLOCK (attr
)->data
;
7508 dwarf2_invalid_attrib_class_complaint ("location description",
7509 SYMBOL_NATURAL_NAME (sym
));
7514 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7515 SYMBOL_LOCATION_BATON (sym
) = baton
;