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;
442 /* DW_AT_frame_base values for the current function.
443 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
444 contains the register number for the frame register.
445 frame_base_offset is the offset from the frame register to the
446 virtual stack frame. */
447 static int frame_base_reg
;
448 static CORE_ADDR frame_base_offset
;
450 /* This value is added to each symbol value. FIXME: Generalize to
451 the section_offsets structure used by dbxread (once this is done,
452 pass the appropriate section number to end_symtab). */
453 static CORE_ADDR baseaddr
; /* Add to each symbol value */
455 /* We put a pointer to this structure in the read_symtab_private field
457 The complete dwarf information for an objfile is kept in the
458 psymbol_obstack, so that absolute die references can be handled.
459 Most of the information in this structure is related to an entire
460 object file and could be passed via the sym_private field of the objfile.
461 It is however conceivable that dwarf2 might not be the only type
462 of symbols read from an object file. */
466 /* Pointer to start of dwarf info buffer for the objfile. */
468 char *dwarf_info_buffer
;
470 /* Offset in dwarf_info_buffer for this compilation unit. */
472 unsigned long dwarf_info_offset
;
474 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
476 char *dwarf_abbrev_buffer
;
478 /* Size of dwarf abbreviation section for the objfile. */
480 unsigned int dwarf_abbrev_size
;
482 /* Pointer to start of dwarf line buffer for the objfile. */
484 char *dwarf_line_buffer
;
486 /* Size of dwarf_line_buffer, in bytes. */
488 unsigned int dwarf_line_size
;
490 /* Pointer to start of dwarf string buffer for the objfile. */
492 char *dwarf_str_buffer
;
494 /* Size of dwarf string section for the objfile. */
496 unsigned int dwarf_str_size
;
498 /* Pointer to start of dwarf macro buffer for the objfile. */
500 char *dwarf_macinfo_buffer
;
502 /* Size of dwarf macinfo section for the objfile. */
504 unsigned int dwarf_macinfo_size
;
506 /* Pointer to start of dwarf ranges buffer for the objfile. */
508 char *dwarf_ranges_buffer
;
510 /* Size of dwarf ranges buffer for the objfile. */
512 unsigned int dwarf_ranges_size
;
514 /* Pointer to start of dwarf locations buffer for the objfile. */
516 char *dwarf_loc_buffer
;
518 /* Size of dwarf locations buffer for the objfile. */
520 unsigned int dwarf_loc_size
;
523 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
524 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
525 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
526 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
527 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
528 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
529 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
530 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
531 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
532 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
533 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
534 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
535 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
536 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
537 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
539 /* Maintain an array of referenced fundamental types for the current
540 compilation unit being read. For DWARF version 1, we have to construct
541 the fundamental types on the fly, since no information about the
542 fundamental types is supplied. Each such fundamental type is created by
543 calling a language dependent routine to create the type, and then a
544 pointer to that type is then placed in the array at the index specified
545 by it's FT_<TYPENAME> value. The array has a fixed size set by the
546 FT_NUM_MEMBERS compile time constant, which is the number of predefined
547 fundamental types gdb knows how to construct. */
548 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
550 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
551 but this would require a corresponding change in unpack_field_as_long
553 static int bits_per_byte
= 8;
555 /* The routines that read and process dies for a C struct or C++ class
556 pass lists of data member fields and lists of member function fields
557 in an instance of a field_info structure, as defined below. */
560 /* List of data member and baseclasses fields. */
563 struct nextfield
*next
;
570 /* Number of fields. */
573 /* Number of baseclasses. */
576 /* Set if the accesibility of one of the fields is not public. */
577 int non_public_fields
;
579 /* Member function fields array, entries are allocated in the order they
580 are encountered in the object file. */
583 struct nextfnfield
*next
;
584 struct fn_field fnfield
;
588 /* Member function fieldlist array, contains name of possibly overloaded
589 member function, number of overloaded member functions and a pointer
590 to the head of the member function field chain. */
595 struct nextfnfield
*head
;
599 /* Number of entries in the fnfieldlists array. */
603 /* Various complaints about symbol reading that don't abort the process */
606 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
608 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
613 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
615 complaint (&symfile_complaints
,
616 "statement list doesn't fit in .debug_line section");
620 dwarf2_complex_location_expr_complaint (void)
622 complaint (&symfile_complaints
, "location expression too complex");
626 dwarf2_unsupported_at_frame_base_complaint (const char *arg1
)
628 complaint (&symfile_complaints
,
629 "unsupported DW_AT_frame_base for function '%s'", arg1
);
633 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
636 complaint (&symfile_complaints
,
637 "const value length mismatch for '%s', got %d, expected %d", arg1
,
642 dwarf2_macros_too_long_complaint (void)
644 complaint (&symfile_complaints
,
645 "macro info runs off end of `.debug_macinfo' section");
649 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
651 complaint (&symfile_complaints
,
652 "macro debug info contains a malformed macro definition:\n`%s'",
657 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
659 complaint (&symfile_complaints
,
660 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
663 /* local function prototypes */
665 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
668 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
671 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
673 static char *scan_partial_symbols (char *, struct objfile
*,
674 CORE_ADDR
*, CORE_ADDR
*,
675 const struct comp_unit_head
*);
677 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
678 const struct comp_unit_head
*);
680 static char *add_partial_namespace (struct partial_die_info
*pdi
,
682 struct objfile
*objfile
,
683 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
684 const struct comp_unit_head
*cu_header
);
686 static char *add_partial_enumeration (struct partial_die_info
*enum_pdi
,
688 struct objfile
*objfile
,
689 const struct comp_unit_head
*cu_header
);
691 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
694 const struct comp_unit_head
*cu_header
);
696 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
698 static void psymtab_to_symtab_1 (struct partial_symtab
*);
700 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int,
703 static void dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
);
705 static void dwarf2_empty_abbrev_table (void *);
707 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
708 const struct comp_unit_head
*cu_header
);
710 static char *read_partial_die (struct partial_die_info
*,
712 const struct comp_unit_head
*);
714 static char *read_full_die (struct die_info
**, bfd
*, char *,
715 const struct comp_unit_head
*);
717 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
718 bfd
*, char *, const struct comp_unit_head
*);
720 static char *read_attribute_value (struct attribute
*, unsigned,
721 bfd
*, char *, const struct comp_unit_head
*);
723 static unsigned int read_1_byte (bfd
*, char *);
725 static int read_1_signed_byte (bfd
*, char *);
727 static unsigned int read_2_bytes (bfd
*, char *);
729 static unsigned int read_4_bytes (bfd
*, char *);
731 static unsigned long read_8_bytes (bfd
*, char *);
733 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
736 static LONGEST
read_initial_length (bfd
*, char *,
737 struct comp_unit_head
*, int *bytes_read
);
739 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
742 static char *read_n_bytes (bfd
*, char *, unsigned int);
744 static char *read_string (bfd
*, char *, unsigned int *);
746 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
749 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
751 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
753 static void set_cu_language (unsigned int);
755 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
757 static int die_is_declaration (struct die_info
*);
759 static void free_line_header (struct line_header
*lh
);
761 static struct line_header
*(dwarf_decode_line_header
762 (unsigned int offset
,
764 const struct comp_unit_head
*cu_header
));
766 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
767 const struct comp_unit_head
*);
769 static void dwarf2_start_subfile (char *, char *);
771 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
772 struct objfile
*, const struct comp_unit_head
*);
774 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
775 struct objfile
*, const struct comp_unit_head
*);
777 static void dwarf2_const_value_data (struct attribute
*attr
,
781 static struct type
*die_type (struct die_info
*, struct objfile
*,
782 const struct comp_unit_head
*);
784 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
785 const struct comp_unit_head
*);
788 static struct type
*type_at_offset (unsigned int, struct objfile
*);
791 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
792 const struct comp_unit_head
*);
794 static void read_type_die (struct die_info
*, struct objfile
*,
795 const struct comp_unit_head
*);
797 static void read_typedef (struct die_info
*, struct objfile
*,
798 const struct comp_unit_head
*);
800 static void read_base_type (struct die_info
*, struct objfile
*);
802 static void read_file_scope (struct die_info
*, struct objfile
*,
803 const struct comp_unit_head
*);
805 static void read_func_scope (struct die_info
*, struct objfile
*,
806 const struct comp_unit_head
*);
808 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
809 const struct comp_unit_head
*);
811 static int dwarf2_get_pc_bounds (struct die_info
*,
812 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*,
813 const struct comp_unit_head
*);
815 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
816 struct objfile
*, const struct comp_unit_head
*);
818 static void dwarf2_attach_fields_to_type (struct field_info
*,
819 struct type
*, struct objfile
*);
821 static void dwarf2_add_member_fn (struct field_info
*,
822 struct die_info
*, struct type
*,
823 struct objfile
*objfile
,
824 const struct comp_unit_head
*);
826 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
827 struct type
*, struct objfile
*);
829 static void read_structure_scope (struct die_info
*, struct objfile
*,
830 const struct comp_unit_head
*);
832 static void read_common_block (struct die_info
*, struct objfile
*,
833 const struct comp_unit_head
*);
835 static void read_namespace (struct die_info
*die
, struct objfile
*objfile
,
836 const struct comp_unit_head
*cu_header
);
838 static void read_enumeration (struct die_info
*, struct objfile
*,
839 const struct comp_unit_head
*);
841 static struct type
*dwarf_base_type (int, int, struct objfile
*);
843 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
844 const struct comp_unit_head
*);
846 static void read_array_type (struct die_info
*, struct objfile
*,
847 const struct comp_unit_head
*);
849 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
850 const struct comp_unit_head
*);
852 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
853 const struct comp_unit_head
*);
855 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
856 const struct comp_unit_head
*);
858 static void read_tag_const_type (struct die_info
*, struct objfile
*,
859 const struct comp_unit_head
*);
861 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
862 const struct comp_unit_head
*);
864 static void read_tag_string_type (struct die_info
*, struct objfile
*);
866 static void read_subroutine_type (struct die_info
*, struct objfile
*,
867 const struct comp_unit_head
*);
869 static struct die_info
*read_comp_unit (char *, bfd
*,
870 const struct comp_unit_head
*);
872 static void free_die_list (struct die_info
*);
874 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
876 static void process_die (struct die_info
*, struct objfile
*,
877 const struct comp_unit_head
*);
879 static char *dwarf2_linkage_name (struct die_info
*);
881 static char *dwarf2_name (struct die_info
*die
);
883 static struct die_info
*dwarf2_extension (struct die_info
*die
);
885 static char *dwarf_tag_name (unsigned int);
887 static char *dwarf_attr_name (unsigned int);
889 static char *dwarf_form_name (unsigned int);
891 static char *dwarf_stack_op_name (unsigned int);
893 static char *dwarf_bool_name (unsigned int);
895 static char *dwarf_type_encoding_name (unsigned int);
898 static char *dwarf_cfi_name (unsigned int);
900 struct die_info
*copy_die (struct die_info
*);
903 static struct die_info
*sibling_die (struct die_info
*);
905 static void dump_die (struct die_info
*);
907 static void dump_die_list (struct die_info
*);
909 static void store_in_ref_table (unsigned int, struct die_info
*);
911 static void dwarf2_empty_hash_tables (void);
913 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
915 static struct die_info
*follow_die_ref (unsigned int);
917 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
919 /* memory allocation interface */
921 static void dwarf2_free_tmp_obstack (void *);
923 static struct dwarf_block
*dwarf_alloc_block (void);
925 static struct abbrev_info
*dwarf_alloc_abbrev (void);
927 static struct die_info
*dwarf_alloc_die (void);
929 static void initialize_cu_func_list (void);
931 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
933 static void dwarf_decode_macros (struct line_header
*, unsigned int,
934 char *, bfd
*, const struct comp_unit_head
*,
937 static int attr_form_is_block (struct attribute
*);
940 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
941 const struct comp_unit_head
*,
942 struct objfile
*objfile
);
944 /* Try to locate the sections we need for DWARF 2 debugging
945 information and return true if we have enough to do something. */
948 dwarf2_has_info (bfd
*abfd
)
950 dwarf_info_offset
= 0;
951 dwarf_abbrev_offset
= 0;
952 dwarf_line_offset
= 0;
953 dwarf_str_offset
= 0;
954 dwarf_macinfo_offset
= 0;
955 dwarf_frame_offset
= 0;
956 dwarf_eh_frame_offset
= 0;
957 dwarf_ranges_offset
= 0;
958 dwarf_loc_offset
= 0;
960 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
961 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
971 /* This function is mapped across the sections and remembers the
972 offset and size of each of the debugging sections we are interested
976 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
978 if (STREQ (sectp
->name
, INFO_SECTION
))
980 dwarf_info_offset
= sectp
->filepos
;
981 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
982 dwarf_info_section
= sectp
;
984 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
986 dwarf_abbrev_offset
= sectp
->filepos
;
987 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
988 dwarf_abbrev_section
= sectp
;
990 else if (STREQ (sectp
->name
, LINE_SECTION
))
992 dwarf_line_offset
= sectp
->filepos
;
993 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
994 dwarf_line_section
= sectp
;
996 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
998 dwarf_pubnames_offset
= sectp
->filepos
;
999 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
1000 dwarf_pubnames_section
= sectp
;
1002 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
1004 dwarf_aranges_offset
= sectp
->filepos
;
1005 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
1006 dwarf_aranges_section
= sectp
;
1008 else if (STREQ (sectp
->name
, LOC_SECTION
))
1010 dwarf_loc_offset
= sectp
->filepos
;
1011 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
1012 dwarf_loc_section
= sectp
;
1014 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
1016 dwarf_macinfo_offset
= sectp
->filepos
;
1017 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1018 dwarf_macinfo_section
= sectp
;
1020 else if (STREQ (sectp
->name
, STR_SECTION
))
1022 dwarf_str_offset
= sectp
->filepos
;
1023 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1024 dwarf_str_section
= sectp
;
1026 else if (STREQ (sectp
->name
, FRAME_SECTION
))
1028 dwarf_frame_offset
= sectp
->filepos
;
1029 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1030 dwarf_frame_section
= sectp
;
1032 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
1034 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1035 if (aflag
& SEC_HAS_CONTENTS
)
1037 dwarf_eh_frame_offset
= sectp
->filepos
;
1038 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1039 dwarf_eh_frame_section
= sectp
;
1042 else if (STREQ (sectp
->name
, RANGES_SECTION
))
1044 dwarf_ranges_offset
= sectp
->filepos
;
1045 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1046 dwarf_ranges_section
= sectp
;
1050 /* Build a partial symbol table. */
1053 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1056 /* We definitely need the .debug_info and .debug_abbrev sections */
1058 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1061 dwarf_info_section
);
1062 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1063 dwarf_abbrev_offset
,
1065 dwarf_abbrev_section
);
1067 if (dwarf_line_offset
)
1068 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1071 dwarf_line_section
);
1073 dwarf_line_buffer
= NULL
;
1075 if (dwarf_str_offset
)
1076 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1081 dwarf_str_buffer
= NULL
;
1083 if (dwarf_macinfo_offset
)
1084 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1085 dwarf_macinfo_offset
,
1087 dwarf_macinfo_section
);
1089 dwarf_macinfo_buffer
= NULL
;
1091 if (dwarf_ranges_offset
)
1092 dwarf_ranges_buffer
= dwarf2_read_section (objfile
,
1093 dwarf_ranges_offset
,
1095 dwarf_ranges_section
);
1097 dwarf_ranges_buffer
= NULL
;
1099 if (dwarf_loc_offset
)
1100 dwarf_loc_buffer
= dwarf2_read_section (objfile
,
1105 dwarf_loc_buffer
= NULL
;
1108 || (objfile
->global_psymbols
.size
== 0
1109 && objfile
->static_psymbols
.size
== 0))
1111 init_psymbol_list (objfile
, 1024);
1115 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1117 /* Things are significantly easier if we have .debug_aranges and
1118 .debug_pubnames sections */
1120 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1124 /* only test this case for now */
1126 /* In this case we have to work a bit harder */
1127 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1132 /* Build the partial symbol table from the information in the
1133 .debug_pubnames and .debug_aranges sections. */
1136 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1138 bfd
*abfd
= objfile
->obfd
;
1139 char *aranges_buffer
, *pubnames_buffer
;
1140 char *aranges_ptr
, *pubnames_ptr
;
1141 unsigned int entry_length
, version
, info_offset
, info_size
;
1143 pubnames_buffer
= dwarf2_read_section (objfile
,
1144 dwarf_pubnames_offset
,
1145 dwarf_pubnames_size
,
1146 dwarf_pubnames_section
);
1147 pubnames_ptr
= pubnames_buffer
;
1148 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1150 struct comp_unit_head cu_header
;
1153 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1155 pubnames_ptr
+= bytes_read
;
1156 version
= read_1_byte (abfd
, pubnames_ptr
);
1158 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1160 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1164 aranges_buffer
= dwarf2_read_section (objfile
,
1165 dwarf_aranges_offset
,
1167 dwarf_aranges_section
);
1172 /* Read in the comp unit header information from the debug_info at
1176 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1177 char *info_ptr
, bfd
*abfd
)
1181 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1183 info_ptr
+= bytes_read
;
1184 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1186 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1188 info_ptr
+= bytes_read
;
1189 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1191 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1192 if (signed_addr
< 0)
1193 internal_error (__FILE__
, __LINE__
,
1194 "read_comp_unit_head: dwarf from non elf file");
1195 cu_header
->signed_addr_p
= signed_addr
;
1199 /* Build the partial symbol table by doing a quick pass through the
1200 .debug_info and .debug_abbrev sections. */
1203 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1205 /* Instead of reading this into a big buffer, we should probably use
1206 mmap() on architectures that support it. (FIXME) */
1207 bfd
*abfd
= objfile
->obfd
;
1208 char *info_ptr
, *abbrev_ptr
;
1209 char *beg_of_comp_unit
;
1210 struct partial_die_info comp_unit_die
;
1211 struct partial_symtab
*pst
;
1212 struct cleanup
*back_to
;
1213 CORE_ADDR lowpc
, highpc
;
1215 info_ptr
= dwarf_info_buffer
;
1216 abbrev_ptr
= dwarf_abbrev_buffer
;
1218 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1219 the partial symbol scan, like attribute values.
1221 We could reduce our peak memory consumption during partial symbol
1222 table construction by freeing stuff from this obstack more often
1223 --- say, after processing each compilation unit, or each die ---
1224 but it turns out that this saves almost nothing. For an
1225 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1226 on dwarf2_tmp_obstack. Some investigation showed:
1228 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1229 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1230 all fixed-length values not requiring dynamic allocation.
1232 2) 30% of the attributes used the form DW_FORM_string. For
1233 DW_FORM_string, read_attribute simply hands back a pointer to
1234 the null-terminated string in dwarf_info_buffer, so no dynamic
1235 allocation is needed there either.
1237 3) The remaining 1% of the attributes all used DW_FORM_block1.
1238 75% of those were DW_AT_frame_base location lists for
1239 functions; the rest were DW_AT_location attributes, probably
1240 for the global variables.
1242 Anyway, what this all means is that the memory the dwarf2
1243 reader uses as temporary space reading partial symbols is about
1244 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1246 obstack_init (&dwarf2_tmp_obstack
);
1247 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1249 /* Since the objects we're extracting from dwarf_info_buffer vary in
1250 length, only the individual functions to extract them (like
1251 read_comp_unit_head and read_partial_die) can really know whether
1252 the buffer is large enough to hold another complete object.
1254 At the moment, they don't actually check that. If
1255 dwarf_info_buffer holds just one extra byte after the last
1256 compilation unit's dies, then read_comp_unit_head will happily
1257 read off the end of the buffer. read_partial_die is similarly
1258 casual. Those functions should be fixed.
1260 For this loop condition, simply checking whether there's any data
1261 left at all should be sufficient. */
1262 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1264 struct comp_unit_head cu_header
;
1265 beg_of_comp_unit
= info_ptr
;
1266 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1268 if (cu_header
.version
!= 2)
1270 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
));
1273 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1275 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1276 (long) cu_header
.abbrev_offset
,
1277 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1278 bfd_get_filename (abfd
));
1281 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1282 > dwarf_info_buffer
+ dwarf_info_size
)
1284 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1285 (long) cu_header
.length
,
1286 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1287 bfd_get_filename (abfd
));
1290 /* Complete the cu_header */
1291 cu_header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1292 cu_header
.first_die_ptr
= info_ptr
;
1293 cu_header
.cu_head_ptr
= beg_of_comp_unit
;
1295 /* Read the abbrevs for this compilation unit into a table */
1296 dwarf2_read_abbrevs (abfd
, &cu_header
);
1297 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1299 /* Read the compilation unit die */
1300 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1303 /* Set the language we're debugging */
1304 set_cu_language (comp_unit_die
.language
);
1306 /* Allocate a new partial symbol table structure */
1307 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1308 comp_unit_die
.name
? comp_unit_die
.name
: "",
1309 comp_unit_die
.lowpc
,
1310 objfile
->global_psymbols
.next
,
1311 objfile
->static_psymbols
.next
);
1313 pst
->read_symtab_private
= (char *)
1314 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1315 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1316 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1317 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1318 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1319 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1320 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1321 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1322 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1323 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1324 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1325 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1326 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1327 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1328 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1329 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1330 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1332 /* Store the function that reads in the rest of the symbol table */
1333 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1335 /* Check if comp unit has_children.
1336 If so, read the rest of the partial symbols from this comp unit.
1337 If not, there's no more debug_info for this comp unit. */
1338 if (comp_unit_die
.has_children
)
1340 lowpc
= ((CORE_ADDR
) -1);
1341 highpc
= ((CORE_ADDR
) 0);
1343 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1346 /* If we didn't find a lowpc, set it to highpc to avoid
1347 complaints from `maint check'. */
1348 if (lowpc
== ((CORE_ADDR
) -1))
1351 /* If the compilation unit didn't have an explicit address range,
1352 then use the information extracted from its child dies. */
1353 if (! comp_unit_die
.has_pc_info
)
1355 comp_unit_die
.lowpc
= lowpc
;
1356 comp_unit_die
.highpc
= highpc
;
1359 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1360 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1362 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1363 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1364 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1365 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1366 sort_pst_symbols (pst
);
1368 /* If there is already a psymtab or symtab for a file of this
1369 name, remove it. (If there is a symtab, more drastic things
1370 also happen.) This happens in VxWorks. */
1371 free_named_symtabs (pst
->filename
);
1373 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1374 + cu_header
.initial_length_size
;
1376 do_cleanups (back_to
);
1379 /* Read in all interesting dies to the end of the compilation unit or
1380 to the end of the current namespace. */
1383 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1384 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1385 const struct comp_unit_head
*cu_header
)
1387 bfd
*abfd
= objfile
->obfd
;
1388 struct partial_die_info pdi
;
1390 /* Now, march along the PDI's, descending into ones which have
1391 interesting children but skipping the children of the other ones,
1392 until we reach the end of the compilation unit. */
1396 /* This flag tells whether or not info_ptr has gotten updated
1398 int info_ptr_updated
= 0;
1400 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1402 /* Anonymous namespaces have no name but have interesting
1403 children, so we need to look at them. Ditto for anonymous
1406 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1407 || pdi
.tag
== DW_TAG_enumeration_type
)
1411 case DW_TAG_subprogram
:
1412 if (pdi
.has_pc_info
)
1414 if (pdi
.lowpc
< *lowpc
)
1418 if (pdi
.highpc
> *highpc
)
1420 *highpc
= pdi
.highpc
;
1422 if (!pdi
.is_declaration
)
1424 add_partial_symbol (&pdi
, objfile
, cu_header
);
1428 case DW_TAG_variable
:
1429 case DW_TAG_typedef
:
1430 case DW_TAG_union_type
:
1431 case DW_TAG_class_type
:
1432 case DW_TAG_structure_type
:
1433 if (!pdi
.is_declaration
)
1435 add_partial_symbol (&pdi
, objfile
, cu_header
);
1438 case DW_TAG_enumeration_type
:
1439 if (!pdi
.is_declaration
)
1441 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
,
1442 objfile
, cu_header
);
1443 info_ptr_updated
= 1;
1446 case DW_TAG_base_type
:
1447 /* File scope base type definitions are added to the partial
1449 add_partial_symbol (&pdi
, objfile
, cu_header
);
1451 case DW_TAG_namespace
:
1452 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, objfile
,
1453 lowpc
, highpc
, cu_header
);
1454 info_ptr_updated
= 1;
1464 /* If the die has a sibling, skip to the sibling, unless another
1465 function has already updated info_ptr for us. */
1467 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1468 or not we want to update this depends on enough stuff (not
1469 only pdi.tag but also whether or not pdi.name is NULL) that
1470 this seems like the easiest way to handle the issue. */
1472 if (!info_ptr_updated
)
1473 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu_header
);
1480 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1481 const struct comp_unit_head
*cu_header
)
1487 case DW_TAG_subprogram
:
1488 if (pdi
->is_external
)
1490 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1491 mst_text, objfile); */
1492 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1493 VAR_DOMAIN
, LOC_BLOCK
,
1494 &objfile
->global_psymbols
,
1495 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1499 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1500 mst_file_text, objfile); */
1501 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1502 VAR_DOMAIN
, LOC_BLOCK
,
1503 &objfile
->static_psymbols
,
1504 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1507 case DW_TAG_variable
:
1508 if (pdi
->is_external
)
1511 Don't enter into the minimal symbol tables as there is
1512 a minimal symbol table entry from the ELF symbols already.
1513 Enter into partial symbol table if it has a location
1514 descriptor or a type.
1515 If the location descriptor is missing, new_symbol will create
1516 a LOC_UNRESOLVED symbol, the address of the variable will then
1517 be determined from the minimal symbol table whenever the variable
1519 The address for the partial symbol table entry is not
1520 used by GDB, but it comes in handy for debugging partial symbol
1524 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1525 if (pdi
->locdesc
|| pdi
->has_type
)
1526 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1527 VAR_DOMAIN
, LOC_STATIC
,
1528 &objfile
->global_psymbols
,
1529 0, addr
+ baseaddr
, cu_language
, objfile
);
1533 /* Static Variable. Skip symbols without location descriptors. */
1534 if (pdi
->locdesc
== NULL
)
1536 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1537 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1538 mst_file_data, objfile); */
1539 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1540 VAR_DOMAIN
, LOC_STATIC
,
1541 &objfile
->static_psymbols
,
1542 0, addr
+ baseaddr
, cu_language
, objfile
);
1545 case DW_TAG_typedef
:
1546 case DW_TAG_base_type
:
1547 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1548 VAR_DOMAIN
, LOC_TYPEDEF
,
1549 &objfile
->static_psymbols
,
1550 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1552 case DW_TAG_class_type
:
1553 case DW_TAG_structure_type
:
1554 case DW_TAG_union_type
:
1555 case DW_TAG_enumeration_type
:
1556 /* Skip aggregate types without children, these are external
1558 if (pdi
->has_children
== 0)
1560 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1561 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1562 &objfile
->static_psymbols
,
1563 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1565 if (cu_language
== language_cplus
)
1567 /* For C++, these implicitly act as typedefs as well. */
1568 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1569 VAR_DOMAIN
, LOC_TYPEDEF
,
1570 &objfile
->static_psymbols
,
1571 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1574 case DW_TAG_enumerator
:
1575 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1576 VAR_DOMAIN
, LOC_CONST
,
1577 &objfile
->static_psymbols
,
1578 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1585 /* Read a partial die corresponding to a namespace. For now, we don't
1586 do anything with the fact that we're in a namespace; we just read
1587 the symbols inside of it. */
1590 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1591 struct objfile
*objfile
,
1592 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1593 const struct comp_unit_head
*cu_header
)
1595 if (pdi
->has_children
)
1596 info_ptr
= scan_partial_symbols (info_ptr
, objfile
,
1603 /* Read a partial die corresponding to an enumeration type. */
1606 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1607 struct objfile
*objfile
,
1608 const struct comp_unit_head
*cu_header
)
1610 bfd
*abfd
= objfile
->obfd
;
1611 struct partial_die_info pdi
;
1613 if (enum_pdi
->name
!= NULL
)
1614 add_partial_symbol (enum_pdi
, objfile
, cu_header
);
1618 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1621 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1622 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1624 add_partial_symbol (&pdi
, objfile
, cu_header
);
1630 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1634 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1635 bfd
*abfd
, const struct comp_unit_head
*cu_header
)
1637 /* Do we know the sibling already? */
1639 if (orig_pdi
->sibling
)
1640 return orig_pdi
->sibling
;
1642 /* Are there any children to deal with? */
1644 if (!orig_pdi
->has_children
)
1647 /* Okay, we don't know the sibling, but we have children that we
1648 want to skip. So read children until we run into one without a
1649 tag; return whatever follows it. */
1653 struct partial_die_info pdi
;
1655 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1660 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu_header
);
1664 /* Expand this partial symbol table into a full symbol table. */
1667 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1669 /* FIXME: This is barely more than a stub. */
1674 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1680 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1681 gdb_flush (gdb_stdout
);
1684 psymtab_to_symtab_1 (pst
);
1686 /* Finish up the debug error message. */
1688 printf_filtered ("done.\n");
1694 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1696 struct objfile
*objfile
= pst
->objfile
;
1697 bfd
*abfd
= objfile
->obfd
;
1698 struct comp_unit_head cu_header
;
1699 struct die_info
*dies
;
1700 unsigned long offset
;
1701 CORE_ADDR lowpc
, highpc
;
1702 struct die_info
*child_die
;
1704 struct symtab
*symtab
;
1705 struct cleanup
*back_to
;
1706 struct attribute
*attr
;
1708 /* Set local variables from the partial symbol table info. */
1709 offset
= DWARF_INFO_OFFSET (pst
);
1710 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1711 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1712 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1713 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1714 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1715 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1716 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1717 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1718 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1719 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1720 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1721 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1722 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1723 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1724 cu_header_offset
= offset
;
1725 info_ptr
= dwarf_info_buffer
+ offset
;
1727 obstack_init (&dwarf2_tmp_obstack
);
1728 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1731 make_cleanup (really_free_pendings
, NULL
);
1733 /* read in the comp_unit header */
1734 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1736 /* Read the abbrevs for this compilation unit */
1737 dwarf2_read_abbrevs (abfd
, &cu_header
);
1738 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1740 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1742 make_cleanup_free_die_list (dies
);
1744 /* Find the base address of the compilation unit for range lists and
1745 location lists. It will normally be specified by DW_AT_low_pc.
1746 In DWARF-3 draft 4, the base address could be overridden by
1747 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1748 compilation units with discontinuous ranges. */
1750 cu_header
.base_known
= 0;
1751 cu_header
.base_address
= 0;
1753 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1756 cu_header
.base_address
= DW_ADDR (attr
);
1757 cu_header
.base_known
= 1;
1761 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1764 cu_header
.base_address
= DW_ADDR (attr
);
1765 cu_header
.base_known
= 1;
1769 /* Do line number decoding in read_file_scope () */
1770 process_die (dies
, objfile
, &cu_header
);
1772 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
, &cu_header
))
1774 /* Some compilers don't define a DW_AT_high_pc attribute for
1775 the compilation unit. If the DW_AT_high_pc is missing,
1776 synthesize it, by scanning the DIE's below the compilation unit. */
1778 if (dies
->has_children
)
1780 child_die
= dies
->next
;
1781 while (child_die
&& child_die
->tag
)
1783 if (child_die
->tag
== DW_TAG_subprogram
)
1785 CORE_ADDR low
, high
;
1787 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1788 objfile
, &cu_header
))
1790 highpc
= max (highpc
, high
);
1793 child_die
= sibling_die (child_die
);
1797 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1799 /* Set symtab language to language from DW_AT_language.
1800 If the compilation is from a C file generated by language preprocessors,
1801 do not set the language if it was already deduced by start_subfile. */
1803 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1805 symtab
->language
= cu_language
;
1807 pst
->symtab
= symtab
;
1810 do_cleanups (back_to
);
1813 /* Process a die and its children. */
1816 process_die (struct die_info
*die
, struct objfile
*objfile
,
1817 const struct comp_unit_head
*cu_header
)
1821 case DW_TAG_padding
:
1823 case DW_TAG_compile_unit
:
1824 read_file_scope (die
, objfile
, cu_header
);
1826 case DW_TAG_subprogram
:
1827 read_subroutine_type (die
, objfile
, cu_header
);
1828 read_func_scope (die
, objfile
, cu_header
);
1830 case DW_TAG_inlined_subroutine
:
1831 /* FIXME: These are ignored for now.
1832 They could be used to set breakpoints on all inlined instances
1833 of a function and make GDB `next' properly over inlined functions. */
1835 case DW_TAG_lexical_block
:
1836 case DW_TAG_try_block
:
1837 case DW_TAG_catch_block
:
1838 read_lexical_block_scope (die
, objfile
, cu_header
);
1840 case DW_TAG_class_type
:
1841 case DW_TAG_structure_type
:
1842 case DW_TAG_union_type
:
1843 read_structure_scope (die
, objfile
, cu_header
);
1845 case DW_TAG_enumeration_type
:
1846 read_enumeration (die
, objfile
, cu_header
);
1848 case DW_TAG_subroutine_type
:
1849 read_subroutine_type (die
, objfile
, cu_header
);
1851 case DW_TAG_array_type
:
1852 read_array_type (die
, objfile
, cu_header
);
1854 case DW_TAG_pointer_type
:
1855 read_tag_pointer_type (die
, objfile
, cu_header
);
1857 case DW_TAG_ptr_to_member_type
:
1858 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1860 case DW_TAG_reference_type
:
1861 read_tag_reference_type (die
, objfile
, cu_header
);
1863 case DW_TAG_string_type
:
1864 read_tag_string_type (die
, objfile
);
1866 case DW_TAG_base_type
:
1867 read_base_type (die
, objfile
);
1868 if (dwarf_attr (die
, DW_AT_name
))
1870 /* Add a typedef symbol for the base type definition. */
1871 new_symbol (die
, die
->type
, objfile
, cu_header
);
1874 case DW_TAG_common_block
:
1875 read_common_block (die
, objfile
, cu_header
);
1877 case DW_TAG_common_inclusion
:
1879 case DW_TAG_namespace
:
1880 if (!processing_has_namespace_info
)
1882 processing_has_namespace_info
= 1;
1883 processing_current_namespace
= "";
1885 read_namespace (die
, objfile
, cu_header
);
1887 case DW_TAG_imported_declaration
:
1888 case DW_TAG_imported_module
:
1889 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1890 information contained in these. DW_TAG_imported_declaration
1891 dies shouldn't have children; DW_TAG_imported_module dies
1892 shouldn't in the C++ case, but conceivably could in the
1893 Fortran case, so we'll have to replace this gdb_assert if
1894 Fortran compilers start generating that info. */
1895 if (!processing_has_namespace_info
)
1897 processing_has_namespace_info
= 1;
1898 processing_current_namespace
= "";
1900 gdb_assert (!die
->has_children
);
1903 new_symbol (die
, NULL
, objfile
, cu_header
);
1909 initialize_cu_func_list (void)
1911 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1915 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1916 const struct comp_unit_head
*cu_header
)
1918 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1919 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1920 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1921 struct attribute
*attr
;
1922 char *name
= "<unknown>";
1923 char *comp_dir
= NULL
;
1924 struct die_info
*child_die
;
1925 bfd
*abfd
= objfile
->obfd
;
1926 struct line_header
*line_header
= 0;
1928 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
1930 if (die
->has_children
)
1932 child_die
= die
->next
;
1933 while (child_die
&& child_die
->tag
)
1935 if (child_die
->tag
== DW_TAG_subprogram
)
1937 CORE_ADDR low
, high
;
1939 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1940 objfile
, cu_header
))
1942 lowpc
= min (lowpc
, low
);
1943 highpc
= max (highpc
, high
);
1946 child_die
= sibling_die (child_die
);
1951 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1952 from finish_block. */
1953 if (lowpc
== ((CORE_ADDR
) -1))
1958 attr
= dwarf_attr (die
, DW_AT_name
);
1961 name
= DW_STRING (attr
);
1963 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1966 comp_dir
= DW_STRING (attr
);
1969 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1970 directory, get rid of it. */
1971 char *cp
= strchr (comp_dir
, ':');
1973 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1978 if (objfile
->ei
.entry_point
>= lowpc
&&
1979 objfile
->ei
.entry_point
< highpc
)
1981 objfile
->ei
.entry_file_lowpc
= lowpc
;
1982 objfile
->ei
.entry_file_highpc
= highpc
;
1985 attr
= dwarf_attr (die
, DW_AT_language
);
1988 set_cu_language (DW_UNSND (attr
));
1991 /* We assume that we're processing GCC output. */
1992 processing_gcc_compilation
= 2;
1994 /* FIXME:Do something here. */
1995 if (dip
->at_producer
!= NULL
)
1997 handle_producer (dip
->at_producer
);
2001 /* The compilation unit may be in a different language or objfile,
2002 zero out all remembered fundamental types. */
2003 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2005 start_symtab (name
, comp_dir
, lowpc
);
2006 record_debugformat ("DWARF 2");
2008 initialize_cu_func_list ();
2010 /* Process all dies in compilation unit. */
2011 if (die
->has_children
)
2013 child_die
= die
->next
;
2014 while (child_die
&& child_die
->tag
)
2016 process_die (child_die
, objfile
, cu_header
);
2017 child_die
= sibling_die (child_die
);
2021 /* Decode line number information if present. */
2022 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
2025 unsigned int line_offset
= DW_UNSND (attr
);
2026 line_header
= dwarf_decode_line_header (line_offset
,
2030 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2031 (void *) line_header
);
2032 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
2036 /* Decode macro information, if present. Dwarf 2 macro information
2037 refers to information in the line number info statement program
2038 header, so we can only read it if we've read the header
2040 attr
= dwarf_attr (die
, DW_AT_macro_info
);
2041 if (attr
&& line_header
)
2043 unsigned int macro_offset
= DW_UNSND (attr
);
2044 dwarf_decode_macros (line_header
, macro_offset
,
2045 comp_dir
, abfd
, cu_header
, objfile
);
2047 do_cleanups (back_to
);
2051 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
2053 struct function_range
*thisfn
;
2055 thisfn
= (struct function_range
*)
2056 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2057 thisfn
->name
= name
;
2058 thisfn
->lowpc
= lowpc
;
2059 thisfn
->highpc
= highpc
;
2060 thisfn
->seen_line
= 0;
2061 thisfn
->next
= NULL
;
2063 if (cu_last_fn
== NULL
)
2064 cu_first_fn
= thisfn
;
2066 cu_last_fn
->next
= thisfn
;
2068 cu_last_fn
= thisfn
;
2072 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
2073 const struct comp_unit_head
*cu_header
)
2075 register struct context_stack
*new;
2078 struct die_info
*child_die
;
2079 struct attribute
*attr
;
2082 name
= dwarf2_linkage_name (die
);
2084 /* Ignore functions with missing or empty names and functions with
2085 missing or invalid low and high pc attributes. */
2086 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2092 /* Record the function range for dwarf_decode_lines. */
2093 add_to_cu_func_list (name
, lowpc
, highpc
);
2095 if (objfile
->ei
.entry_point
>= lowpc
&&
2096 objfile
->ei
.entry_point
< highpc
)
2098 objfile
->ei
.entry_func_lowpc
= lowpc
;
2099 objfile
->ei
.entry_func_highpc
= highpc
;
2102 /* Decode DW_AT_frame_base location descriptor if present, keep result
2103 for DW_OP_fbreg operands in decode_locdesc. */
2104 frame_base_reg
= -1;
2105 frame_base_offset
= 0;
2106 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2111 /* Support the .debug_loc offsets */
2112 if (attr_form_is_block (attr
))
2114 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2116 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2118 dwarf2_complex_location_expr_complaint ();
2123 dwarf2_invalid_attrib_class_complaint ("DW_AT_frame_base", name
);
2128 dwarf2_unsupported_at_frame_base_complaint (name
);
2130 frame_base_reg
= addr
;
2133 frame_base_reg
= basereg
;
2134 frame_base_offset
= addr
;
2137 dwarf2_unsupported_at_frame_base_complaint (name
);
2140 new = push_context (0, lowpc
);
2141 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
2143 /* If there was a location expression for DW_AT_frame_base above,
2144 record it. We still need to decode it above because not all
2145 symbols use location expressions exclusively. */
2147 dwarf2_symbol_mark_computed (attr
, new->name
, cu_header
, objfile
);
2149 list_in_scope
= &local_symbols
;
2151 if (die
->has_children
)
2153 child_die
= die
->next
;
2154 while (child_die
&& child_die
->tag
)
2156 process_die (child_die
, objfile
, cu_header
);
2157 child_die
= sibling_die (child_die
);
2161 new = pop_context ();
2162 /* Make a block for the local symbols within. */
2163 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2164 lowpc
, highpc
, objfile
);
2166 /* In C++, we can have functions nested inside functions (e.g., when
2167 a function declares a class that has methods). This means that
2168 when we finish processing a function scope, we may need to go
2169 back to building a containing block's symbol lists. */
2170 local_symbols
= new->locals
;
2171 param_symbols
= new->params
;
2173 /* If we've finished processing a top-level function, subsequent
2174 symbols go in the file symbol list. */
2175 if (outermost_context_p ())
2176 list_in_scope
= &file_symbols
;
2179 /* Process all the DIES contained within a lexical block scope. Start
2180 a new scope, process the dies, and then close the scope. */
2183 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
2184 const struct comp_unit_head
*cu_header
)
2186 register struct context_stack
*new;
2187 CORE_ADDR lowpc
, highpc
;
2188 struct die_info
*child_die
;
2190 /* Ignore blocks with missing or invalid low and high pc attributes. */
2191 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2192 as multiple lexical blocks? Handling children in a sane way would
2193 be nasty. Might be easier to properly extend generic blocks to
2195 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2200 push_context (0, lowpc
);
2201 if (die
->has_children
)
2203 child_die
= die
->next
;
2204 while (child_die
&& child_die
->tag
)
2206 process_die (child_die
, objfile
, cu_header
);
2207 child_die
= sibling_die (child_die
);
2210 new = pop_context ();
2212 if (local_symbols
!= NULL
)
2214 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2217 local_symbols
= new->locals
;
2220 /* Get low and high pc attributes from a die. Return 1 if the attributes
2221 are present and valid, otherwise, return 0. Return -1 if the range is
2222 discontinuous, i.e. derived from DW_AT_ranges information. */
2224 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2225 CORE_ADDR
*highpc
, struct objfile
*objfile
,
2226 const struct comp_unit_head
*cu_header
)
2228 struct attribute
*attr
;
2229 bfd
*obfd
= objfile
->obfd
;
2234 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2237 high
= DW_ADDR (attr
);
2238 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2240 low
= DW_ADDR (attr
);
2242 /* Found high w/o low attribute. */
2245 /* Found consecutive range of addresses. */
2250 attr
= dwarf_attr (die
, DW_AT_ranges
);
2253 unsigned int addr_size
= cu_header
->addr_size
;
2254 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2255 /* Value of the DW_AT_ranges attribute is the offset in the
2256 .debug_renges section. */
2257 unsigned int offset
= DW_UNSND (attr
);
2258 /* Base address selection entry. */
2267 found_base
= cu_header
->base_known
;
2268 base
= cu_header
->base_address
;
2269 buffer
= dwarf_ranges_buffer
+ offset
;
2271 /* Read in the largest possible address. */
2272 marker
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2273 if ((marker
& mask
) == mask
)
2275 /* If we found the largest possible address, then
2276 read the base address. */
2277 base
= read_address (obfd
, buffer
+ addr_size
,
2279 buffer
+= 2 * addr_size
;
2280 offset
+= 2 * addr_size
;
2288 CORE_ADDR range_beginning
, range_end
;
2290 range_beginning
= read_address (obfd
, buffer
,
2292 buffer
+= addr_size
;
2293 range_end
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2294 buffer
+= addr_size
;
2295 offset
+= 2 * addr_size
;
2297 /* An end of list marker is a pair of zero addresses. */
2298 if (range_beginning
== 0 && range_end
== 0)
2299 /* Found the end of list entry. */
2302 /* Each base address selection entry is a pair of 2 values.
2303 The first is the largest possible address, the second is
2304 the base address. Check for a base address here. */
2305 if ((range_beginning
& mask
) == mask
)
2307 /* If we found the largest possible address, then
2308 read the base address. */
2309 base
= read_address (obfd
, buffer
+ addr_size
,
2317 /* We have no valid base address for the ranges
2319 complaint (&symfile_complaints
,
2320 "Invalid .debug_ranges data (no base address)");
2324 range_beginning
+= base
;
2327 /* FIXME: This is recording everything as a low-high
2328 segment of consecutive addresses. We should have a
2329 data structure for discontiguous block ranges
2333 low
= range_beginning
;
2339 if (range_beginning
< low
)
2340 low
= range_beginning
;
2341 if (range_end
> high
)
2347 /* If the first entry is an end-of-list marker, the range
2348 describes an empty scope, i.e. no instructions. */
2358 /* When using the GNU linker, .gnu.linkonce. sections are used to
2359 eliminate duplicate copies of functions and vtables and such.
2360 The linker will arbitrarily choose one and discard the others.
2361 The AT_*_pc values for such functions refer to local labels in
2362 these sections. If the section from that file was discarded, the
2363 labels are not in the output, so the relocs get a value of 0.
2364 If this is a discarded function, mark the pc bounds as invalid,
2365 so that GDB will ignore it. */
2366 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2374 /* Add an aggregate field to the field list. */
2377 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2378 struct objfile
*objfile
,
2379 const struct comp_unit_head
*cu_header
)
2381 struct nextfield
*new_field
;
2382 struct attribute
*attr
;
2384 char *fieldname
= "";
2386 /* Allocate a new field list entry and link it in. */
2387 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2388 make_cleanup (xfree
, new_field
);
2389 memset (new_field
, 0, sizeof (struct nextfield
));
2390 new_field
->next
= fip
->fields
;
2391 fip
->fields
= new_field
;
2394 /* Handle accessibility and virtuality of field.
2395 The default accessibility for members is public, the default
2396 accessibility for inheritance is private. */
2397 if (die
->tag
!= DW_TAG_inheritance
)
2398 new_field
->accessibility
= DW_ACCESS_public
;
2400 new_field
->accessibility
= DW_ACCESS_private
;
2401 new_field
->virtuality
= DW_VIRTUALITY_none
;
2403 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2405 new_field
->accessibility
= DW_UNSND (attr
);
2406 if (new_field
->accessibility
!= DW_ACCESS_public
)
2407 fip
->non_public_fields
= 1;
2408 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2410 new_field
->virtuality
= DW_UNSND (attr
);
2412 fp
= &new_field
->field
;
2414 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2416 /* Data member other than a C++ static data member. */
2418 /* Get type of field. */
2419 fp
->type
= die_type (die
, objfile
, cu_header
);
2421 FIELD_STATIC_KIND (*fp
) = 0;
2423 /* Get bit size of field (zero if none). */
2424 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2427 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2431 FIELD_BITSIZE (*fp
) = 0;
2434 /* Get bit offset of field. */
2435 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2438 FIELD_BITPOS (*fp
) =
2439 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2442 FIELD_BITPOS (*fp
) = 0;
2443 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2446 if (BITS_BIG_ENDIAN
)
2448 /* For big endian bits, the DW_AT_bit_offset gives the
2449 additional bit offset from the MSB of the containing
2450 anonymous object to the MSB of the field. We don't
2451 have to do anything special since we don't need to
2452 know the size of the anonymous object. */
2453 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2457 /* For little endian bits, compute the bit offset to the
2458 MSB of the anonymous object, subtract off the number of
2459 bits from the MSB of the field to the MSB of the
2460 object, and then subtract off the number of bits of
2461 the field itself. The result is the bit offset of
2462 the LSB of the field. */
2464 int bit_offset
= DW_UNSND (attr
);
2466 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2469 /* The size of the anonymous object containing
2470 the bit field is explicit, so use the
2471 indicated size (in bytes). */
2472 anonymous_size
= DW_UNSND (attr
);
2476 /* The size of the anonymous object containing
2477 the bit field must be inferred from the type
2478 attribute of the data member containing the
2480 anonymous_size
= TYPE_LENGTH (fp
->type
);
2482 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2483 - bit_offset
- FIELD_BITSIZE (*fp
);
2487 /* Get name of field. */
2488 attr
= dwarf_attr (die
, DW_AT_name
);
2489 if (attr
&& DW_STRING (attr
))
2490 fieldname
= DW_STRING (attr
);
2491 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2492 &objfile
->type_obstack
);
2494 /* Change accessibility for artificial fields (e.g. virtual table
2495 pointer or virtual base class pointer) to private. */
2496 if (dwarf_attr (die
, DW_AT_artificial
))
2498 new_field
->accessibility
= DW_ACCESS_private
;
2499 fip
->non_public_fields
= 1;
2502 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2504 /* C++ static member. */
2506 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2507 is a declaration, but all versions of G++ as of this writing
2508 (so through at least 3.2.1) incorrectly generate
2509 DW_TAG_variable tags. */
2513 /* Get name of field. */
2514 attr
= dwarf_attr (die
, DW_AT_name
);
2515 if (attr
&& DW_STRING (attr
))
2516 fieldname
= DW_STRING (attr
);
2520 /* Get physical name. */
2521 physname
= dwarf2_linkage_name (die
);
2523 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2524 &objfile
->type_obstack
));
2525 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2526 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2527 &objfile
->type_obstack
);
2529 else if (die
->tag
== DW_TAG_inheritance
)
2531 /* C++ base class field. */
2532 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2534 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2536 FIELD_BITSIZE (*fp
) = 0;
2537 FIELD_STATIC_KIND (*fp
) = 0;
2538 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2539 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2540 fip
->nbaseclasses
++;
2544 /* Create the vector of fields, and attach it to the type. */
2547 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2548 struct objfile
*objfile
)
2550 int nfields
= fip
->nfields
;
2552 /* Record the field count, allocate space for the array of fields,
2553 and create blank accessibility bitfields if necessary. */
2554 TYPE_NFIELDS (type
) = nfields
;
2555 TYPE_FIELDS (type
) = (struct field
*)
2556 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2557 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2559 if (fip
->non_public_fields
)
2561 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2563 TYPE_FIELD_PRIVATE_BITS (type
) =
2564 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2565 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2567 TYPE_FIELD_PROTECTED_BITS (type
) =
2568 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2569 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2571 TYPE_FIELD_IGNORE_BITS (type
) =
2572 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2573 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2576 /* If the type has baseclasses, allocate and clear a bit vector for
2577 TYPE_FIELD_VIRTUAL_BITS. */
2578 if (fip
->nbaseclasses
)
2580 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2583 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2584 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2585 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2586 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2587 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2590 /* Copy the saved-up fields into the field vector. Start from the head
2591 of the list, adding to the tail of the field array, so that they end
2592 up in the same order in the array in which they were added to the list. */
2593 while (nfields
-- > 0)
2595 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2596 switch (fip
->fields
->accessibility
)
2598 case DW_ACCESS_private
:
2599 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2602 case DW_ACCESS_protected
:
2603 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2606 case DW_ACCESS_public
:
2610 /* Unknown accessibility. Complain and treat it as public. */
2612 complaint (&symfile_complaints
, "unsupported accessibility %d",
2613 fip
->fields
->accessibility
);
2617 if (nfields
< fip
->nbaseclasses
)
2619 switch (fip
->fields
->virtuality
)
2621 case DW_VIRTUALITY_virtual
:
2622 case DW_VIRTUALITY_pure_virtual
:
2623 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2627 fip
->fields
= fip
->fields
->next
;
2631 /* Add a member function to the proper fieldlist. */
2634 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2635 struct type
*type
, struct objfile
*objfile
,
2636 const struct comp_unit_head
*cu_header
)
2638 struct attribute
*attr
;
2639 struct fnfieldlist
*flp
;
2641 struct fn_field
*fnp
;
2644 struct nextfnfield
*new_fnfield
;
2646 /* Get name of member function. */
2647 attr
= dwarf_attr (die
, DW_AT_name
);
2648 if (attr
&& DW_STRING (attr
))
2649 fieldname
= DW_STRING (attr
);
2653 /* Get the mangled name. */
2654 physname
= dwarf2_linkage_name (die
);
2656 /* Look up member function name in fieldlist. */
2657 for (i
= 0; i
< fip
->nfnfields
; i
++)
2659 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2663 /* Create new list element if necessary. */
2664 if (i
< fip
->nfnfields
)
2665 flp
= &fip
->fnfieldlists
[i
];
2668 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2670 fip
->fnfieldlists
= (struct fnfieldlist
*)
2671 xrealloc (fip
->fnfieldlists
,
2672 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2673 * sizeof (struct fnfieldlist
));
2674 if (fip
->nfnfields
== 0)
2675 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2677 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2678 flp
->name
= fieldname
;
2684 /* Create a new member function field and chain it to the field list
2686 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2687 make_cleanup (xfree
, new_fnfield
);
2688 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2689 new_fnfield
->next
= flp
->head
;
2690 flp
->head
= new_fnfield
;
2693 /* Fill in the member function field info. */
2694 fnp
= &new_fnfield
->fnfield
;
2695 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2696 &objfile
->type_obstack
);
2697 fnp
->type
= alloc_type (objfile
);
2698 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2700 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2701 int nparams
= TYPE_NFIELDS (die
->type
);
2703 /* TYPE is the domain of this method, and DIE->TYPE is the type
2704 of the method itself (TYPE_CODE_METHOD). */
2705 smash_to_method_type (fnp
->type
, type
,
2706 TYPE_TARGET_TYPE (die
->type
),
2707 TYPE_FIELDS (die
->type
),
2708 TYPE_NFIELDS (die
->type
),
2709 TYPE_VARARGS (die
->type
));
2711 /* Handle static member functions.
2712 Dwarf2 has no clean way to discern C++ static and non-static
2713 member functions. G++ helps GDB by marking the first
2714 parameter for non-static member functions (which is the
2715 this pointer) as artificial. We obtain this information
2716 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2717 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2718 fnp
->voffset
= VOFFSET_STATIC
;
2721 complaint (&symfile_complaints
, "member function type missing for '%s'",
2724 /* Get fcontext from DW_AT_containing_type if present. */
2725 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2726 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2728 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2729 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2731 /* Get accessibility. */
2732 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2735 switch (DW_UNSND (attr
))
2737 case DW_ACCESS_private
:
2738 fnp
->is_private
= 1;
2740 case DW_ACCESS_protected
:
2741 fnp
->is_protected
= 1;
2746 /* Check for artificial methods. */
2747 attr
= dwarf_attr (die
, DW_AT_artificial
);
2748 if (attr
&& DW_UNSND (attr
) != 0)
2749 fnp
->is_artificial
= 1;
2751 /* Get index in virtual function table if it is a virtual member function. */
2752 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2755 /* Support the .debug_loc offsets */
2756 if (attr_form_is_block (attr
))
2758 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2760 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2762 dwarf2_complex_location_expr_complaint ();
2766 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2772 /* Create the vector of member function fields, and attach it to the type. */
2775 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2776 struct objfile
*objfile
)
2778 struct fnfieldlist
*flp
;
2779 int total_length
= 0;
2782 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2783 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2784 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2786 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2788 struct nextfnfield
*nfp
= flp
->head
;
2789 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2792 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2793 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2794 fn_flp
->fn_fields
= (struct fn_field
*)
2795 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2796 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2797 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2799 total_length
+= flp
->length
;
2802 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2803 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2806 /* Called when we find the DIE that starts a structure or union scope
2807 (definition) to process all dies that define the members of the
2810 NOTE: we need to call struct_type regardless of whether or not the
2811 DIE has an at_name attribute, since it might be an anonymous
2812 structure or union. This gets the type entered into our set of
2815 However, if the structure is incomplete (an opaque struct/union)
2816 then suppress creating a symbol table entry for it since gdb only
2817 wants to find the one with the complete definition. Note that if
2818 it is complete, we just call new_symbol, which does it's own
2819 checking about whether the struct/union is anonymous or not (and
2820 suppresses creating a symbol table entry itself). */
2823 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2824 const struct comp_unit_head
*cu_header
)
2827 struct attribute
*attr
;
2829 type
= alloc_type (objfile
);
2831 INIT_CPLUS_SPECIFIC (type
);
2832 attr
= dwarf_attr (die
, DW_AT_name
);
2833 if (attr
&& DW_STRING (attr
))
2835 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2836 strlen (DW_STRING (attr
)),
2837 &objfile
->type_obstack
);
2840 if (die
->tag
== DW_TAG_structure_type
)
2842 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2844 else if (die
->tag
== DW_TAG_union_type
)
2846 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2850 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2852 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2855 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2858 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2862 TYPE_LENGTH (type
) = 0;
2865 /* We need to add the type field to the die immediately so we don't
2866 infinitely recurse when dealing with pointers to the structure
2867 type within the structure itself. */
2870 if (die
->has_children
&& ! die_is_declaration (die
))
2872 struct field_info fi
;
2873 struct die_info
*child_die
;
2874 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2876 memset (&fi
, 0, sizeof (struct field_info
));
2878 child_die
= die
->next
;
2880 while (child_die
&& child_die
->tag
)
2882 if (child_die
->tag
== DW_TAG_member
2883 || child_die
->tag
== DW_TAG_variable
)
2885 /* NOTE: carlton/2002-11-05: A C++ static data member
2886 should be a DW_TAG_member that is a declaration, but
2887 all versions of G++ as of this writing (so through at
2888 least 3.2.1) incorrectly generate DW_TAG_variable
2889 tags for them instead. */
2890 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2892 else if (child_die
->tag
== DW_TAG_subprogram
)
2894 /* C++ member function. */
2895 process_die (child_die
, objfile
, cu_header
);
2896 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2898 else if (child_die
->tag
== DW_TAG_inheritance
)
2900 /* C++ base class field. */
2901 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2905 process_die (child_die
, objfile
, cu_header
);
2907 child_die
= sibling_die (child_die
);
2910 /* Attach fields and member functions to the type. */
2912 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2915 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2917 /* Get the type which refers to the base class (possibly this
2918 class itself) which contains the vtable pointer for the current
2919 class from the DW_AT_containing_type attribute. */
2921 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2923 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2925 TYPE_VPTR_BASETYPE (type
) = t
;
2928 static const char vptr_name
[] =
2929 {'_', 'v', 'p', 't', 'r', '\0'};
2932 /* Our own class provides vtbl ptr. */
2933 for (i
= TYPE_NFIELDS (t
) - 1;
2934 i
>= TYPE_N_BASECLASSES (t
);
2937 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2939 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2940 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2942 TYPE_VPTR_FIELDNO (type
) = i
;
2947 /* Complain if virtual function table field not found. */
2948 if (i
< TYPE_N_BASECLASSES (t
))
2949 complaint (&symfile_complaints
,
2950 "virtual function table pointer not found when defining class '%s'",
2951 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2956 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2961 new_symbol (die
, type
, objfile
, cu_header
);
2963 do_cleanups (back_to
);
2967 /* No children, must be stub. */
2968 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2972 /* Given a pointer to a die which begins an enumeration, process all
2973 the dies that define the members of the enumeration.
2975 This will be much nicer in draft 6 of the DWARF spec when our
2976 members will be dies instead squished into the DW_AT_element_list
2979 NOTE: We reverse the order of the element list. */
2982 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2983 const struct comp_unit_head
*cu_header
)
2985 struct die_info
*child_die
;
2987 struct field
*fields
;
2988 struct attribute
*attr
;
2991 int unsigned_enum
= 1;
2993 type
= alloc_type (objfile
);
2995 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2996 attr
= dwarf_attr (die
, DW_AT_name
);
2997 if (attr
&& DW_STRING (attr
))
2999 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
3000 strlen (DW_STRING (attr
)),
3001 &objfile
->type_obstack
);
3004 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3007 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3011 TYPE_LENGTH (type
) = 0;
3016 if (die
->has_children
)
3018 child_die
= die
->next
;
3019 while (child_die
&& child_die
->tag
)
3021 if (child_die
->tag
!= DW_TAG_enumerator
)
3023 process_die (child_die
, objfile
, cu_header
);
3027 attr
= dwarf_attr (child_die
, DW_AT_name
);
3030 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
3031 if (SYMBOL_VALUE (sym
) < 0)
3034 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3036 fields
= (struct field
*)
3038 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3039 * sizeof (struct field
));
3042 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3043 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3044 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3045 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3046 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3052 child_die
= sibling_die (child_die
);
3057 TYPE_NFIELDS (type
) = num_fields
;
3058 TYPE_FIELDS (type
) = (struct field
*)
3059 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3060 memcpy (TYPE_FIELDS (type
), fields
,
3061 sizeof (struct field
) * num_fields
);
3065 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3068 new_symbol (die
, type
, objfile
, cu_header
);
3071 /* Extract all information from a DW_TAG_array_type DIE and put it in
3072 the DIE's type field. For now, this only handles one dimensional
3076 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
3077 const struct comp_unit_head
*cu_header
)
3079 struct die_info
*child_die
;
3080 struct type
*type
= NULL
;
3081 struct type
*element_type
, *range_type
, *index_type
;
3082 struct type
**range_types
= NULL
;
3083 struct attribute
*attr
;
3085 struct cleanup
*back_to
;
3087 /* Return if we've already decoded this type. */
3093 element_type
= die_type (die
, objfile
, cu_header
);
3095 /* Irix 6.2 native cc creates array types without children for
3096 arrays with unspecified length. */
3097 if (die
->has_children
== 0)
3099 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3100 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3101 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3105 back_to
= make_cleanup (null_cleanup
, NULL
);
3106 child_die
= die
->next
;
3107 while (child_die
&& child_die
->tag
)
3109 if (child_die
->tag
== DW_TAG_subrange_type
)
3111 unsigned int low
, high
;
3113 /* Default bounds to an array with unspecified length. */
3116 if (cu_language
== language_fortran
)
3118 /* FORTRAN implies a lower bound of 1, if not given. */
3122 index_type
= die_type (child_die
, objfile
, cu_header
);
3123 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3126 if (attr
->form
== DW_FORM_sdata
)
3128 low
= DW_SND (attr
);
3130 else if (attr
->form
== DW_FORM_udata
3131 || attr
->form
== DW_FORM_data1
3132 || attr
->form
== DW_FORM_data2
3133 || attr
->form
== DW_FORM_data4
3134 || attr
->form
== DW_FORM_data8
)
3136 low
= DW_UNSND (attr
);
3140 dwarf2_non_const_array_bound_ignored_complaint
3141 (dwarf_form_name (attr
->form
));
3143 die
->type
= lookup_pointer_type (element_type
);
3150 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3153 if (attr
->form
== DW_FORM_sdata
)
3155 high
= DW_SND (attr
);
3157 else if (attr
->form
== DW_FORM_udata
3158 || attr
->form
== DW_FORM_data1
3159 || attr
->form
== DW_FORM_data2
3160 || attr
->form
== DW_FORM_data4
3161 || attr
->form
== DW_FORM_data8
)
3163 high
= DW_UNSND (attr
);
3165 else if (attr
->form
== DW_FORM_block1
)
3167 /* GCC encodes arrays with unspecified or dynamic length
3168 with a DW_FORM_block1 attribute.
3169 FIXME: GDB does not yet know how to handle dynamic
3170 arrays properly, treat them as arrays with unspecified
3176 dwarf2_non_const_array_bound_ignored_complaint
3177 (dwarf_form_name (attr
->form
));
3179 die
->type
= lookup_pointer_type (element_type
);
3187 /* Create a range type and save it for array type creation. */
3188 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3190 range_types
= (struct type
**)
3191 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3192 * sizeof (struct type
*));
3194 make_cleanup (free_current_contents
, &range_types
);
3196 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3198 child_die
= sibling_die (child_die
);
3201 /* Dwarf2 dimensions are output from left to right, create the
3202 necessary array types in backwards order. */
3203 type
= element_type
;
3205 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3207 /* Understand Dwarf2 support for vector types (like they occur on
3208 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3209 array type. This is not part of the Dwarf2/3 standard yet, but a
3210 custom vendor extension. The main difference between a regular
3211 array and the vector variant is that vectors are passed by value
3213 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3215 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3217 do_cleanups (back_to
);
3219 /* Install the type in the die. */
3223 /* First cut: install each common block member as a global variable. */
3226 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
3227 const struct comp_unit_head
*cu_header
)
3229 struct die_info
*child_die
;
3230 struct attribute
*attr
;
3232 CORE_ADDR base
= (CORE_ADDR
) 0;
3234 attr
= dwarf_attr (die
, DW_AT_location
);
3237 /* Support the .debug_loc offsets */
3238 if (attr_form_is_block (attr
))
3240 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3242 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3244 dwarf2_complex_location_expr_complaint ();
3248 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3249 "common block member");
3252 if (die
->has_children
)
3254 child_die
= die
->next
;
3255 while (child_die
&& child_die
->tag
)
3257 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
3258 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3261 SYMBOL_VALUE_ADDRESS (sym
) =
3262 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3263 add_symbol_to_list (sym
, &global_symbols
);
3265 child_die
= sibling_die (child_die
);
3270 /* Read a C++ namespace. */
3273 read_namespace (struct die_info
*die
, struct objfile
*objfile
,
3274 const struct comp_unit_head
*cu_header
)
3276 const char *previous_namespace
= processing_current_namespace
;
3277 const char *name
= NULL
;
3279 struct die_info
*current_die
;
3281 /* Loop through the extensions until we find a name. */
3283 for (current_die
= die
;
3284 current_die
!= NULL
;
3285 current_die
= dwarf2_extension (die
))
3287 name
= dwarf2_name (current_die
);
3292 /* Is it an anonymous namespace? */
3294 is_anonymous
= (name
== NULL
);
3296 name
= "(anonymous namespace)";
3298 /* Now build the name of the current namespace. */
3300 if (previous_namespace
[0] == '\0')
3302 processing_current_namespace
= name
;
3306 /* We need temp_name around because processing_current_namespace
3307 is a const char *. */
3308 char *temp_name
= alloca (strlen (previous_namespace
)
3309 + 2 + strlen(name
) + 1);
3310 strcpy (temp_name
, previous_namespace
);
3311 strcat (temp_name
, "::");
3312 strcat (temp_name
, name
);
3314 processing_current_namespace
= temp_name
;
3317 /* If it's an anonymous namespace that we're seeing for the first
3318 time, add a using directive. */
3320 if (is_anonymous
&& dwarf_attr (die
, DW_AT_extension
) == NULL
)
3321 cp_add_using_directive (processing_current_namespace
,
3322 strlen (previous_namespace
),
3323 strlen (processing_current_namespace
));
3325 if (die
->has_children
)
3327 struct die_info
*child_die
= die
->next
;
3329 while (child_die
&& child_die
->tag
)
3331 process_die (child_die
, objfile
, cu_header
);
3332 child_die
= sibling_die (child_die
);
3336 processing_current_namespace
= previous_namespace
;
3339 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3340 the user defined type vector. */
3343 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
3344 const struct comp_unit_head
*cu_header
)
3347 struct attribute
*attr_byte_size
;
3348 struct attribute
*attr_address_class
;
3349 int byte_size
, addr_class
;
3356 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
3358 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3360 byte_size
= DW_UNSND (attr_byte_size
);
3362 byte_size
= cu_header
->addr_size
;
3364 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3365 if (attr_address_class
)
3366 addr_class
= DW_UNSND (attr_address_class
);
3368 addr_class
= DW_ADDR_none
;
3370 /* If the pointer size or address class is different than the
3371 default, create a type variant marked as such and set the
3372 length accordingly. */
3373 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3375 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3379 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3380 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3381 type
= make_type_with_address_space (type
, type_flags
);
3383 else if (TYPE_LENGTH (type
) != byte_size
)
3385 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3388 /* Should we also complain about unhandled address classes? */
3392 TYPE_LENGTH (type
) = byte_size
;
3396 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3397 the user defined type vector. */
3400 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
3401 const struct comp_unit_head
*cu_header
)
3404 struct type
*to_type
;
3405 struct type
*domain
;
3412 type
= alloc_type (objfile
);
3413 to_type
= die_type (die
, objfile
, cu_header
);
3414 domain
= die_containing_type (die
, objfile
, cu_header
);
3415 smash_to_member_type (type
, domain
, to_type
);
3420 /* Extract all information from a DW_TAG_reference_type DIE and add to
3421 the user defined type vector. */
3424 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
3425 const struct comp_unit_head
*cu_header
)
3428 struct attribute
*attr
;
3435 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
3436 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3439 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3443 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3449 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
3450 const struct comp_unit_head
*cu_header
)
3452 struct type
*base_type
;
3459 base_type
= die_type (die
, objfile
, cu_header
);
3460 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3464 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
3465 const struct comp_unit_head
*cu_header
)
3467 struct type
*base_type
;
3474 base_type
= die_type (die
, objfile
, cu_header
);
3475 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3478 /* Extract all information from a DW_TAG_string_type DIE and add to
3479 the user defined type vector. It isn't really a user defined type,
3480 but it behaves like one, with other DIE's using an AT_user_def_type
3481 attribute to reference it. */
3484 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3486 struct type
*type
, *range_type
, *index_type
, *char_type
;
3487 struct attribute
*attr
;
3488 unsigned int length
;
3495 attr
= dwarf_attr (die
, DW_AT_string_length
);
3498 length
= DW_UNSND (attr
);
3502 /* check for the DW_AT_byte_size attribute */
3503 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3506 length
= DW_UNSND (attr
);
3513 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3514 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3515 if (cu_language
== language_fortran
)
3517 /* Need to create a unique string type for bounds
3519 type
= create_string_type (0, range_type
);
3523 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3524 type
= create_string_type (char_type
, range_type
);
3529 /* Handle DIES due to C code like:
3533 int (*funcp)(int a, long l);
3537 ('funcp' generates a DW_TAG_subroutine_type DIE)
3541 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3542 const struct comp_unit_head
*cu_header
)
3544 struct type
*type
; /* Type that this function returns */
3545 struct type
*ftype
; /* Function that returns above type */
3546 struct attribute
*attr
;
3548 /* Decode the type that this subroutine returns */
3553 type
= die_type (die
, objfile
, cu_header
);
3554 ftype
= lookup_function_type (type
);
3556 /* All functions in C++ have prototypes. */
3557 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3558 if ((attr
&& (DW_UNSND (attr
) != 0))
3559 || cu_language
== language_cplus
)
3560 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3562 if (die
->has_children
)
3564 struct die_info
*child_die
;
3568 /* Count the number of parameters.
3569 FIXME: GDB currently ignores vararg functions, but knows about
3570 vararg member functions. */
3571 child_die
= die
->next
;
3572 while (child_die
&& child_die
->tag
)
3574 if (child_die
->tag
== DW_TAG_formal_parameter
)
3576 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3577 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3578 child_die
= sibling_die (child_die
);
3581 /* Allocate storage for parameters and fill them in. */
3582 TYPE_NFIELDS (ftype
) = nparams
;
3583 TYPE_FIELDS (ftype
) = (struct field
*)
3584 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3586 child_die
= die
->next
;
3587 while (child_die
&& child_die
->tag
)
3589 if (child_die
->tag
== DW_TAG_formal_parameter
)
3591 /* Dwarf2 has no clean way to discern C++ static and non-static
3592 member functions. G++ helps GDB by marking the first
3593 parameter for non-static member functions (which is the
3594 this pointer) as artificial. We pass this information
3595 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3596 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3598 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3600 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3601 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3605 child_die
= sibling_die (child_die
);
3613 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3614 const struct comp_unit_head
*cu_header
)
3616 struct attribute
*attr
;
3621 attr
= dwarf_attr (die
, DW_AT_name
);
3622 if (attr
&& DW_STRING (attr
))
3624 name
= DW_STRING (attr
);
3626 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3627 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3631 /* Find a representation of a given base type and install
3632 it in the TYPE field of the die. */
3635 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3638 struct attribute
*attr
;
3639 int encoding
= 0, size
= 0;
3641 /* If we've already decoded this die, this is a no-op. */
3647 attr
= dwarf_attr (die
, DW_AT_encoding
);
3650 encoding
= DW_UNSND (attr
);
3652 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3655 size
= DW_UNSND (attr
);
3657 attr
= dwarf_attr (die
, DW_AT_name
);
3658 if (attr
&& DW_STRING (attr
))
3660 enum type_code code
= TYPE_CODE_INT
;
3665 case DW_ATE_address
:
3666 /* Turn DW_ATE_address into a void * pointer. */
3667 code
= TYPE_CODE_PTR
;
3668 type_flags
|= TYPE_FLAG_UNSIGNED
;
3670 case DW_ATE_boolean
:
3671 code
= TYPE_CODE_BOOL
;
3672 type_flags
|= TYPE_FLAG_UNSIGNED
;
3674 case DW_ATE_complex_float
:
3675 code
= TYPE_CODE_COMPLEX
;
3678 code
= TYPE_CODE_FLT
;
3681 case DW_ATE_signed_char
:
3683 case DW_ATE_unsigned
:
3684 case DW_ATE_unsigned_char
:
3685 type_flags
|= TYPE_FLAG_UNSIGNED
;
3688 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3689 dwarf_type_encoding_name (encoding
));
3692 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3693 if (encoding
== DW_ATE_address
)
3694 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3695 else if (encoding
== DW_ATE_complex_float
)
3698 TYPE_TARGET_TYPE (type
)
3699 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3700 else if (size
== 16)
3701 TYPE_TARGET_TYPE (type
)
3702 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3704 TYPE_TARGET_TYPE (type
)
3705 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3710 type
= dwarf_base_type (encoding
, size
, objfile
);
3715 /* Read a whole compilation unit into a linked list of dies. */
3717 static struct die_info
*
3718 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3719 const struct comp_unit_head
*cu_header
)
3721 struct die_info
*first_die
, *last_die
, *die
;
3725 /* Reset die reference table; we are
3726 building new ones now. */
3727 dwarf2_empty_hash_tables ();
3731 first_die
= last_die
= NULL
;
3734 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3735 if (die
->has_children
)
3746 /* Enter die in reference hash table */
3747 store_in_ref_table (die
->offset
, die
);
3751 first_die
= last_die
= die
;
3755 last_die
->next
= die
;
3759 while (nesting_level
> 0);
3763 /* Free a linked list of dies. */
3766 free_die_list (struct die_info
*dies
)
3768 struct die_info
*die
, *next
;
3781 do_free_die_list_cleanup (void *dies
)
3783 free_die_list (dies
);
3786 static struct cleanup
*
3787 make_cleanup_free_die_list (struct die_info
*dies
)
3789 return make_cleanup (do_free_die_list_cleanup
, dies
);
3793 /* Read the contents of the section at OFFSET and of size SIZE from the
3794 object file specified by OBJFILE into the psymbol_obstack and return it. */
3797 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3798 unsigned int size
, asection
*sectp
)
3800 bfd
*abfd
= objfile
->obfd
;
3806 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3808 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3812 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3813 (bfd_bread (buf
, size
, abfd
) != size
))
3816 error ("Dwarf Error: Can't read DWARF data from '%s'",
3817 bfd_get_filename (abfd
));
3822 /* In DWARF version 2, the description of the debugging information is
3823 stored in a separate .debug_abbrev section. Before we read any
3824 dies from a section we read in all abbreviations and install them
3828 dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
)
3831 struct abbrev_info
*cur_abbrev
;
3832 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3833 unsigned int abbrev_form
, hash_number
;
3835 /* Initialize dwarf2 abbrevs */
3836 memset (cu_header
->dwarf2_abbrevs
, 0,
3837 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3839 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3840 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3841 abbrev_ptr
+= bytes_read
;
3843 /* loop until we reach an abbrev number of 0 */
3844 while (abbrev_number
)
3846 cur_abbrev
= dwarf_alloc_abbrev ();
3848 /* read in abbrev header */
3849 cur_abbrev
->number
= abbrev_number
;
3850 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3851 abbrev_ptr
+= bytes_read
;
3852 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3855 /* now read in declarations */
3856 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3857 abbrev_ptr
+= bytes_read
;
3858 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3859 abbrev_ptr
+= bytes_read
;
3862 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3864 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3865 xrealloc (cur_abbrev
->attrs
,
3866 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3867 * sizeof (struct attr_abbrev
));
3869 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3870 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3871 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3872 abbrev_ptr
+= bytes_read
;
3873 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3874 abbrev_ptr
+= bytes_read
;
3877 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3878 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3879 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3881 /* Get next abbreviation.
3882 Under Irix6 the abbreviations for a compilation unit are not
3883 always properly terminated with an abbrev number of 0.
3884 Exit loop if we encounter an abbreviation which we have
3885 already read (which means we are about to read the abbreviations
3886 for the next compile unit) or if the end of the abbreviation
3887 table is reached. */
3888 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3889 >= dwarf_abbrev_size
)
3891 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3892 abbrev_ptr
+= bytes_read
;
3893 if (dwarf2_lookup_abbrev (abbrev_number
, cu_header
) != NULL
)
3898 /* Empty the abbrev table for a new compilation unit. */
3902 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3905 struct abbrev_info
*abbrev
, *next
;
3906 struct abbrev_info
**abbrevs
;
3908 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3910 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3913 abbrev
= abbrevs
[i
];
3916 next
= abbrev
->next
;
3917 xfree (abbrev
->attrs
);
3925 /* Lookup an abbrev_info structure in the abbrev hash table. */
3927 static struct abbrev_info
*
3928 dwarf2_lookup_abbrev (unsigned int number
, const struct comp_unit_head
*cu_header
)
3930 unsigned int hash_number
;
3931 struct abbrev_info
*abbrev
;
3933 hash_number
= number
% ABBREV_HASH_SIZE
;
3934 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3938 if (abbrev
->number
== number
)
3941 abbrev
= abbrev
->next
;
3946 /* Read a minimal amount of information into the minimal die structure. */
3949 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3950 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3952 unsigned int abbrev_number
, bytes_read
, i
;
3953 struct abbrev_info
*abbrev
;
3954 struct attribute attr
;
3955 struct attribute spec_attr
;
3956 int found_spec_attr
= 0;
3957 int has_low_pc_attr
= 0;
3958 int has_high_pc_attr
= 0;
3960 *part_die
= zeroed_partial_die
;
3961 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3962 info_ptr
+= bytes_read
;
3966 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3969 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
3970 bfd_get_filename (abfd
));
3972 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3973 part_die
->tag
= abbrev
->tag
;
3974 part_die
->has_children
= abbrev
->has_children
;
3975 part_die
->abbrev
= abbrev_number
;
3977 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3979 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3980 info_ptr
, cu_header
);
3982 /* Store the data if it is of an attribute we want to keep in a
3983 partial symbol table. */
3988 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3989 if (part_die
->name
== NULL
)
3990 part_die
->name
= DW_STRING (&attr
);
3992 case DW_AT_MIPS_linkage_name
:
3993 part_die
->name
= DW_STRING (&attr
);
3996 has_low_pc_attr
= 1;
3997 part_die
->lowpc
= DW_ADDR (&attr
);
4000 has_high_pc_attr
= 1;
4001 part_die
->highpc
= DW_ADDR (&attr
);
4003 case DW_AT_location
:
4004 /* Support the .debug_loc offsets */
4005 if (attr_form_is_block (&attr
))
4007 part_die
->locdesc
= DW_BLOCK (&attr
);
4009 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4011 dwarf2_complex_location_expr_complaint ();
4015 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4016 "partial symbol information");
4019 case DW_AT_language
:
4020 part_die
->language
= DW_UNSND (&attr
);
4022 case DW_AT_external
:
4023 part_die
->is_external
= DW_UNSND (&attr
);
4025 case DW_AT_declaration
:
4026 part_die
->is_declaration
= DW_UNSND (&attr
);
4029 part_die
->has_type
= 1;
4031 case DW_AT_abstract_origin
:
4032 case DW_AT_specification
:
4033 found_spec_attr
= 1;
4037 /* Ignore absolute siblings, they might point outside of
4038 the current compile unit. */
4039 if (attr
.form
== DW_FORM_ref_addr
)
4040 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4043 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
4050 /* If we found a reference attribute and the die has no name, try
4051 to find a name in the referred to die. */
4053 if (found_spec_attr
&& part_die
->name
== NULL
)
4055 struct partial_die_info spec_die
;
4059 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
4060 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
4063 part_die
->name
= spec_die
.name
;
4065 /* Copy DW_AT_external attribute if it is set. */
4066 if (spec_die
.is_external
)
4067 part_die
->is_external
= spec_die
.is_external
;
4071 /* When using the GNU linker, .gnu.linkonce. sections are used to
4072 eliminate duplicate copies of functions and vtables and such.
4073 The linker will arbitrarily choose one and discard the others.
4074 The AT_*_pc values for such functions refer to local labels in
4075 these sections. If the section from that file was discarded, the
4076 labels are not in the output, so the relocs get a value of 0.
4077 If this is a discarded function, mark the pc bounds as invalid,
4078 so that GDB will ignore it. */
4079 if (has_low_pc_attr
&& has_high_pc_attr
4080 && part_die
->lowpc
< part_die
->highpc
4081 && (part_die
->lowpc
!= 0
4082 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4083 part_die
->has_pc_info
= 1;
4087 /* Read the die from the .debug_info section buffer. And set diep to
4088 point to a newly allocated die with its information. */
4091 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4092 const struct comp_unit_head
*cu_header
)
4094 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4095 struct abbrev_info
*abbrev
;
4096 struct die_info
*die
;
4098 offset
= info_ptr
- dwarf_info_buffer
;
4099 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4100 info_ptr
+= bytes_read
;
4103 die
= dwarf_alloc_die ();
4105 die
->abbrev
= abbrev_number
;
4111 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
4114 error ("Dwarf Error: could not find abbrev number %d [in module %s]", abbrev_number
,
4115 bfd_get_filename (abfd
));
4117 die
= dwarf_alloc_die ();
4118 die
->offset
= offset
;
4119 die
->tag
= abbrev
->tag
;
4120 die
->has_children
= abbrev
->has_children
;
4121 die
->abbrev
= abbrev_number
;
4124 die
->num_attrs
= abbrev
->num_attrs
;
4125 die
->attrs
= (struct attribute
*)
4126 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4128 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4130 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4131 abfd
, info_ptr
, cu_header
);
4138 /* Read an attribute value described by an attribute form. */
4141 read_attribute_value (struct attribute
*attr
, unsigned form
,
4142 bfd
*abfd
, char *info_ptr
,
4143 const struct comp_unit_head
*cu_header
)
4145 unsigned int bytes_read
;
4146 struct dwarf_block
*blk
;
4152 case DW_FORM_ref_addr
:
4153 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
4154 info_ptr
+= bytes_read
;
4156 case DW_FORM_block2
:
4157 blk
= dwarf_alloc_block ();
4158 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4160 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4161 info_ptr
+= blk
->size
;
4162 DW_BLOCK (attr
) = blk
;
4164 case DW_FORM_block4
:
4165 blk
= dwarf_alloc_block ();
4166 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4168 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4169 info_ptr
+= blk
->size
;
4170 DW_BLOCK (attr
) = blk
;
4173 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4177 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4181 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4184 case DW_FORM_string
:
4185 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4186 info_ptr
+= bytes_read
;
4189 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4191 info_ptr
+= bytes_read
;
4194 blk
= dwarf_alloc_block ();
4195 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4196 info_ptr
+= bytes_read
;
4197 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4198 info_ptr
+= blk
->size
;
4199 DW_BLOCK (attr
) = blk
;
4201 case DW_FORM_block1
:
4202 blk
= dwarf_alloc_block ();
4203 blk
->size
= read_1_byte (abfd
, info_ptr
);
4205 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4206 info_ptr
+= blk
->size
;
4207 DW_BLOCK (attr
) = blk
;
4210 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4214 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4218 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4219 info_ptr
+= bytes_read
;
4222 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4223 info_ptr
+= bytes_read
;
4226 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4230 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4234 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4238 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4241 case DW_FORM_ref_udata
:
4242 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4243 info_ptr
+= bytes_read
;
4245 case DW_FORM_indirect
:
4246 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4247 info_ptr
+= bytes_read
;
4248 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
4251 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4252 dwarf_form_name (form
),
4253 bfd_get_filename (abfd
));
4258 /* Read an attribute described by an abbreviated attribute. */
4261 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4262 bfd
*abfd
, char *info_ptr
,
4263 const struct comp_unit_head
*cu_header
)
4265 attr
->name
= abbrev
->name
;
4266 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
4269 /* read dwarf information from a buffer */
4272 read_1_byte (bfd
*abfd
, char *buf
)
4274 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4278 read_1_signed_byte (bfd
*abfd
, char *buf
)
4280 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4284 read_2_bytes (bfd
*abfd
, char *buf
)
4286 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4290 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4292 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4296 read_4_bytes (bfd
*abfd
, char *buf
)
4298 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4302 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4304 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4307 static unsigned long
4308 read_8_bytes (bfd
*abfd
, char *buf
)
4310 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4314 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4317 CORE_ADDR retval
= 0;
4319 if (cu_header
->signed_addr_p
)
4321 switch (cu_header
->addr_size
)
4324 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4327 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4330 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4333 internal_error (__FILE__
, __LINE__
,
4334 "read_address: bad switch, signed [in module %s]",
4335 bfd_get_filename (abfd
));
4340 switch (cu_header
->addr_size
)
4343 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4346 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4349 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4352 internal_error (__FILE__
, __LINE__
,
4353 "read_address: bad switch, unsigned [in module %s]",
4354 bfd_get_filename (abfd
));
4358 *bytes_read
= cu_header
->addr_size
;
4362 /* Read the initial length from a section. The (draft) DWARF 3
4363 specification allows the initial length to take up either 4 bytes
4364 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4365 bytes describe the length and all offsets will be 8 bytes in length
4368 An older, non-standard 64-bit format is also handled by this
4369 function. The older format in question stores the initial length
4370 as an 8-byte quantity without an escape value. Lengths greater
4371 than 2^32 aren't very common which means that the initial 4 bytes
4372 is almost always zero. Since a length value of zero doesn't make
4373 sense for the 32-bit format, this initial zero can be considered to
4374 be an escape value which indicates the presence of the older 64-bit
4375 format. As written, the code can't detect (old format) lengths
4376 greater than 4GB. If it becomes necessary to handle lengths somewhat
4377 larger than 4GB, we could allow other small values (such as the
4378 non-sensical values of 1, 2, and 3) to also be used as escape values
4379 indicating the presence of the old format.
4381 The value returned via bytes_read should be used to increment
4382 the relevant pointer after calling read_initial_length().
4384 As a side effect, this function sets the fields initial_length_size
4385 and offset_size in cu_header to the values appropriate for the
4386 length field. (The format of the initial length field determines
4387 the width of file offsets to be fetched later with fetch_offset().)
4389 [ Note: read_initial_length() and read_offset() are based on the
4390 document entitled "DWARF Debugging Information Format", revision
4391 3, draft 8, dated November 19, 2001. This document was obtained
4394 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4396 This document is only a draft and is subject to change. (So beware.)
4398 Details regarding the older, non-standard 64-bit format were
4399 determined empirically by examining 64-bit ELF files produced
4400 by the SGI toolchain on an IRIX 6.5 machine.
4402 - Kevin, July 16, 2002
4406 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4411 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4413 if (retval
== 0xffffffff)
4415 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4417 if (cu_header
!= NULL
)
4419 cu_header
->initial_length_size
= 12;
4420 cu_header
->offset_size
= 8;
4423 else if (retval
== 0)
4425 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4427 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4429 if (cu_header
!= NULL
)
4431 cu_header
->initial_length_size
= 8;
4432 cu_header
->offset_size
= 8;
4438 if (cu_header
!= NULL
)
4440 cu_header
->initial_length_size
= 4;
4441 cu_header
->offset_size
= 4;
4448 /* Read an offset from the data stream. The size of the offset is
4449 given by cu_header->offset_size. */
4452 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4457 switch (cu_header
->offset_size
)
4460 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4464 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4468 internal_error (__FILE__
, __LINE__
,
4469 "read_offset: bad switch [in module %s]",
4470 bfd_get_filename (abfd
));
4477 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4479 /* If the size of a host char is 8 bits, we can return a pointer
4480 to the buffer, otherwise we have to copy the data to a buffer
4481 allocated on the temporary obstack. */
4482 gdb_assert (HOST_CHAR_BIT
== 8);
4487 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4489 /* If the size of a host char is 8 bits, we can return a pointer
4490 to the string, otherwise we have to copy the string to a buffer
4491 allocated on the temporary obstack. */
4492 gdb_assert (HOST_CHAR_BIT
== 8);
4495 *bytes_read_ptr
= 1;
4498 *bytes_read_ptr
= strlen (buf
) + 1;
4503 read_indirect_string (bfd
*abfd
, char *buf
,
4504 const struct comp_unit_head
*cu_header
,
4505 unsigned int *bytes_read_ptr
)
4507 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4508 (int *) bytes_read_ptr
);
4510 if (dwarf_str_buffer
== NULL
)
4512 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4513 bfd_get_filename (abfd
));
4516 if (str_offset
>= dwarf_str_size
)
4518 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4519 bfd_get_filename (abfd
));
4522 gdb_assert (HOST_CHAR_BIT
== 8);
4523 if (dwarf_str_buffer
[str_offset
] == '\0')
4525 return dwarf_str_buffer
+ str_offset
;
4528 static unsigned long
4529 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4531 unsigned long result
;
4532 unsigned int num_read
;
4542 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4545 result
|= ((unsigned long)(byte
& 127) << shift
);
4546 if ((byte
& 128) == 0)
4552 *bytes_read_ptr
= num_read
;
4557 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4560 int i
, shift
, size
, num_read
;
4570 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4573 result
|= ((long)(byte
& 127) << shift
);
4575 if ((byte
& 128) == 0)
4580 if ((shift
< size
) && (byte
& 0x40))
4582 result
|= -(1 << shift
);
4584 *bytes_read_ptr
= num_read
;
4589 set_cu_language (unsigned int lang
)
4595 cu_language
= language_c
;
4597 case DW_LANG_C_plus_plus
:
4598 cu_language
= language_cplus
;
4600 case DW_LANG_Fortran77
:
4601 case DW_LANG_Fortran90
:
4602 case DW_LANG_Fortran95
:
4603 cu_language
= language_fortran
;
4605 case DW_LANG_Mips_Assembler
:
4606 cu_language
= language_asm
;
4609 cu_language
= language_java
;
4613 case DW_LANG_Cobol74
:
4614 case DW_LANG_Cobol85
:
4615 case DW_LANG_Pascal83
:
4616 case DW_LANG_Modula2
:
4618 cu_language
= language_minimal
;
4621 cu_language_defn
= language_def (cu_language
);
4624 /* Return the named attribute or NULL if not there. */
4626 static struct attribute
*
4627 dwarf_attr (struct die_info
*die
, unsigned int name
)
4630 struct attribute
*spec
= NULL
;
4632 for (i
= 0; i
< die
->num_attrs
; ++i
)
4634 if (die
->attrs
[i
].name
== name
)
4636 return &die
->attrs
[i
];
4638 if (die
->attrs
[i
].name
== DW_AT_specification
4639 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4640 spec
= &die
->attrs
[i
];
4644 struct die_info
*ref_die
=
4645 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4648 return dwarf_attr (ref_die
, name
);
4655 die_is_declaration (struct die_info
*die
)
4657 return (dwarf_attr (die
, DW_AT_declaration
)
4658 && ! dwarf_attr (die
, DW_AT_specification
));
4662 /* Free the line_header structure *LH, and any arrays and strings it
4665 free_line_header (struct line_header
*lh
)
4667 if (lh
->standard_opcode_lengths
)
4668 xfree (lh
->standard_opcode_lengths
);
4670 /* Remember that all the lh->file_names[i].name pointers are
4671 pointers into debug_line_buffer, and don't need to be freed. */
4673 xfree (lh
->file_names
);
4675 /* Similarly for the include directory names. */
4676 if (lh
->include_dirs
)
4677 xfree (lh
->include_dirs
);
4683 /* Add an entry to LH's include directory table. */
4685 add_include_dir (struct line_header
*lh
, char *include_dir
)
4687 /* Grow the array if necessary. */
4688 if (lh
->include_dirs_size
== 0)
4690 lh
->include_dirs_size
= 1; /* for testing */
4691 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4692 * sizeof (*lh
->include_dirs
));
4694 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4696 lh
->include_dirs_size
*= 2;
4697 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4698 (lh
->include_dirs_size
4699 * sizeof (*lh
->include_dirs
)));
4702 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4706 /* Add an entry to LH's file name table. */
4708 add_file_name (struct line_header
*lh
,
4710 unsigned int dir_index
,
4711 unsigned int mod_time
,
4712 unsigned int length
)
4714 struct file_entry
*fe
;
4716 /* Grow the array if necessary. */
4717 if (lh
->file_names_size
== 0)
4719 lh
->file_names_size
= 1; /* for testing */
4720 lh
->file_names
= xmalloc (lh
->file_names_size
4721 * sizeof (*lh
->file_names
));
4723 else if (lh
->num_file_names
>= lh
->file_names_size
)
4725 lh
->file_names_size
*= 2;
4726 lh
->file_names
= xrealloc (lh
->file_names
,
4727 (lh
->file_names_size
4728 * sizeof (*lh
->file_names
)));
4731 fe
= &lh
->file_names
[lh
->num_file_names
++];
4733 fe
->dir_index
= dir_index
;
4734 fe
->mod_time
= mod_time
;
4735 fe
->length
= length
;
4739 /* Read the statement program header starting at OFFSET in
4740 dwarf_line_buffer, according to the endianness of ABFD. Return a
4741 pointer to a struct line_header, allocated using xmalloc.
4743 NOTE: the strings in the include directory and file name tables of
4744 the returned object point into debug_line_buffer, and must not be
4746 static struct line_header
*
4747 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4748 const struct comp_unit_head
*cu_header
)
4750 struct cleanup
*back_to
;
4751 struct line_header
*lh
;
4755 char *cur_dir
, *cur_file
;
4757 if (dwarf_line_buffer
== NULL
)
4759 complaint (&symfile_complaints
, "missing .debug_line section");
4763 /* Make sure that at least there's room for the total_length field. That
4764 could be 12 bytes long, but we're just going to fudge that. */
4765 if (offset
+ 4 >= dwarf_line_size
)
4767 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4771 lh
= xmalloc (sizeof (*lh
));
4772 memset (lh
, 0, sizeof (*lh
));
4773 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4776 line_ptr
= dwarf_line_buffer
+ offset
;
4778 /* read in the header */
4779 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4780 line_ptr
+= bytes_read
;
4781 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4783 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4786 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4787 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4789 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4790 line_ptr
+= bytes_read
;
4791 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4793 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4795 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4797 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4799 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4801 lh
->standard_opcode_lengths
4802 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4804 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4805 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4807 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4811 /* Read directory table */
4812 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4814 line_ptr
+= bytes_read
;
4815 add_include_dir (lh
, cur_dir
);
4817 line_ptr
+= bytes_read
;
4819 /* Read file name table */
4820 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4822 unsigned int dir_index
, mod_time
, length
;
4824 line_ptr
+= bytes_read
;
4825 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4826 line_ptr
+= bytes_read
;
4827 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4828 line_ptr
+= bytes_read
;
4829 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4830 line_ptr
+= bytes_read
;
4832 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4834 line_ptr
+= bytes_read
;
4835 lh
->statement_program_start
= line_ptr
;
4837 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4838 complaint (&symfile_complaints
,
4839 "line number info header doesn't fit in `.debug_line' section");
4841 discard_cleanups (back_to
);
4845 /* This function exists to work around a bug in certain compilers
4846 (particularly GCC 2.95), in which the first line number marker of a
4847 function does not show up until after the prologue, right before
4848 the second line number marker. This function shifts ADDRESS down
4849 to the beginning of the function if necessary, and is called on
4850 addresses passed to record_line. */
4853 check_cu_functions (CORE_ADDR address
)
4855 struct function_range
*fn
;
4857 /* Find the function_range containing address. */
4862 cu_cached_fn
= cu_first_fn
;
4866 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4872 while (fn
&& fn
!= cu_cached_fn
)
4873 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4883 if (address
!= fn
->lowpc
)
4884 complaint (&symfile_complaints
,
4885 "misplaced first line number at 0x%lx for '%s'",
4886 (unsigned long) address
, fn
->name
);
4891 /* Decode the line number information for the compilation unit whose
4892 line number info is at OFFSET in the .debug_line section.
4893 The compilation directory of the file is passed in COMP_DIR. */
4896 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4897 const struct comp_unit_head
*cu_header
)
4901 unsigned int i
, bytes_read
;
4903 unsigned char op_code
, extended_op
, adj_opcode
;
4905 line_ptr
= lh
->statement_program_start
;
4906 line_end
= lh
->statement_program_end
;
4908 /* Read the statement sequences until there's nothing left. */
4909 while (line_ptr
< line_end
)
4911 /* state machine registers */
4912 CORE_ADDR address
= 0;
4913 unsigned int file
= 1;
4914 unsigned int line
= 1;
4915 unsigned int column
= 0;
4916 int is_stmt
= lh
->default_is_stmt
;
4917 int basic_block
= 0;
4918 int end_sequence
= 0;
4920 /* Start a subfile for the current file of the state machine. */
4921 if (lh
->num_file_names
>= file
)
4923 /* lh->include_dirs and lh->file_names are 0-based, but the
4924 directory and file name numbers in the statement program
4926 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4929 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4932 dwarf2_start_subfile (fe
->name
, dir
);
4935 /* Decode the table. */
4936 while (!end_sequence
)
4938 op_code
= read_1_byte (abfd
, line_ptr
);
4941 if (op_code
>= lh
->opcode_base
)
4942 { /* Special operand. */
4943 adj_opcode
= op_code
- lh
->opcode_base
;
4944 address
+= (adj_opcode
/ lh
->line_range
)
4945 * lh
->minimum_instruction_length
;
4946 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4947 /* append row to matrix using current values */
4948 record_line (current_subfile
, line
,
4949 check_cu_functions (address
));
4952 else switch (op_code
)
4954 case DW_LNS_extended_op
:
4955 line_ptr
+= 1; /* ignore length */
4956 extended_op
= read_1_byte (abfd
, line_ptr
);
4958 switch (extended_op
)
4960 case DW_LNE_end_sequence
:
4962 record_line (current_subfile
, 0, address
);
4964 case DW_LNE_set_address
:
4965 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4966 line_ptr
+= bytes_read
;
4967 address
+= baseaddr
;
4969 case DW_LNE_define_file
:
4972 unsigned int dir_index
, mod_time
, length
;
4974 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4975 line_ptr
+= bytes_read
;
4977 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4978 line_ptr
+= bytes_read
;
4980 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4981 line_ptr
+= bytes_read
;
4983 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4984 line_ptr
+= bytes_read
;
4985 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4989 complaint (&symfile_complaints
,
4990 "mangled .debug_line section");
4995 record_line (current_subfile
, line
,
4996 check_cu_functions (address
));
4999 case DW_LNS_advance_pc
:
5000 address
+= lh
->minimum_instruction_length
5001 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5002 line_ptr
+= bytes_read
;
5004 case DW_LNS_advance_line
:
5005 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5006 line_ptr
+= bytes_read
;
5008 case DW_LNS_set_file
:
5010 /* lh->include_dirs and lh->file_names are 0-based,
5011 but the directory and file name numbers in the
5012 statement program are 1-based. */
5013 struct file_entry
*fe
;
5015 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5016 line_ptr
+= bytes_read
;
5017 fe
= &lh
->file_names
[file
- 1];
5019 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5022 dwarf2_start_subfile (fe
->name
, dir
);
5025 case DW_LNS_set_column
:
5026 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5027 line_ptr
+= bytes_read
;
5029 case DW_LNS_negate_stmt
:
5030 is_stmt
= (!is_stmt
);
5032 case DW_LNS_set_basic_block
:
5035 /* Add to the address register of the state machine the
5036 address increment value corresponding to special opcode
5037 255. Ie, this value is scaled by the minimum instruction
5038 length since special opcode 255 would have scaled the
5040 case DW_LNS_const_add_pc
:
5041 address
+= (lh
->minimum_instruction_length
5042 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5044 case DW_LNS_fixed_advance_pc
:
5045 address
+= read_2_bytes (abfd
, line_ptr
);
5049 { /* Unknown standard opcode, ignore it. */
5051 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5053 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5054 line_ptr
+= bytes_read
;
5062 /* Start a subfile for DWARF. FILENAME is the name of the file and
5063 DIRNAME the name of the source directory which contains FILENAME
5064 or NULL if not known.
5065 This routine tries to keep line numbers from identical absolute and
5066 relative file names in a common subfile.
5068 Using the `list' example from the GDB testsuite, which resides in
5069 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5070 of /srcdir/list0.c yields the following debugging information for list0.c:
5072 DW_AT_name: /srcdir/list0.c
5073 DW_AT_comp_dir: /compdir
5074 files.files[0].name: list0.h
5075 files.files[0].dir: /srcdir
5076 files.files[1].name: list0.c
5077 files.files[1].dir: /srcdir
5079 The line number information for list0.c has to end up in a single
5080 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5083 dwarf2_start_subfile (char *filename
, char *dirname
)
5085 /* If the filename isn't absolute, try to match an existing subfile
5086 with the full pathname. */
5088 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5090 struct subfile
*subfile
;
5091 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5093 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5095 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5097 current_subfile
= subfile
;
5104 start_subfile (filename
, dirname
);
5108 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5109 struct objfile
*objfile
,
5110 const struct comp_unit_head
*cu_header
)
5112 /* NOTE drow/2003-01-30: There used to be a comment and some special
5113 code here to turn a symbol with DW_AT_external and a
5114 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5115 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5116 with some versions of binutils) where shared libraries could have
5117 relocations against symbols in their debug information - the
5118 minimal symbol would have the right address, but the debug info
5119 would not. It's no longer necessary, because we will explicitly
5120 apply relocations when we read in the debug information now. */
5122 /* A DW_AT_location attribute with no contents indicates that a
5123 variable has been optimized away. */
5124 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5126 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5130 /* Handle one degenerate form of location expression specially, to
5131 preserve GDB's previous behavior when section offsets are
5132 specified. If this is just a DW_OP_addr then mark this symbol
5135 if (attr_form_is_block (attr
)
5136 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5137 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5141 SYMBOL_VALUE_ADDRESS (sym
) =
5142 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu_header
,
5144 fixup_symbol_section (sym
, objfile
);
5145 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5146 SYMBOL_SECTION (sym
));
5147 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5151 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5152 expression evaluator, and use LOC_COMPUTED only when necessary
5153 (i.e. when the value of a register or memory location is
5154 referenced, or a thread-local block, etc.). Then again, it might
5155 not be worthwhile. I'm assuming that it isn't unless performance
5156 or memory numbers show me otherwise. */
5158 dwarf2_symbol_mark_computed (attr
, sym
, cu_header
, objfile
);
5159 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5162 /* Given a pointer to a DWARF information entry, figure out if we need
5163 to make a symbol table entry for it, and if so, create a new entry
5164 and return a pointer to it.
5165 If TYPE is NULL, determine symbol type from the die, otherwise
5166 used the passed type. */
5168 static struct symbol
*
5169 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
5170 const struct comp_unit_head
*cu_header
)
5172 struct symbol
*sym
= NULL
;
5174 struct attribute
*attr
= NULL
;
5175 struct attribute
*attr2
= NULL
;
5178 name
= dwarf2_linkage_name (die
);
5181 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5182 sizeof (struct symbol
));
5183 OBJSTAT (objfile
, n_syms
++);
5184 memset (sym
, 0, sizeof (struct symbol
));
5186 /* Cache this symbol's name and the name's demangled form (if any). */
5187 SYMBOL_LANGUAGE (sym
) = cu_language
;
5188 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5190 /* Default assumptions.
5191 Use the passed type or decode it from the die. */
5192 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5193 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5195 SYMBOL_TYPE (sym
) = type
;
5197 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
5198 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5201 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5206 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5209 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5211 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5213 case DW_TAG_subprogram
:
5214 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5216 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5217 attr2
= dwarf_attr (die
, DW_AT_external
);
5218 if (attr2
&& (DW_UNSND (attr2
) != 0))
5220 add_symbol_to_list (sym
, &global_symbols
);
5224 add_symbol_to_list (sym
, list_in_scope
);
5227 case DW_TAG_variable
:
5228 /* Compilation with minimal debug info may result in variables
5229 with missing type entries. Change the misleading `void' type
5230 to something sensible. */
5231 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5232 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5233 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5234 "<variable, no debug info>",
5236 attr
= dwarf_attr (die
, DW_AT_const_value
);
5239 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5240 attr2
= dwarf_attr (die
, DW_AT_external
);
5241 if (attr2
&& (DW_UNSND (attr2
) != 0))
5242 add_symbol_to_list (sym
, &global_symbols
);
5244 add_symbol_to_list (sym
, list_in_scope
);
5247 attr
= dwarf_attr (die
, DW_AT_location
);
5250 var_decode_location (attr
, sym
, objfile
, cu_header
);
5251 attr2
= dwarf_attr (die
, DW_AT_external
);
5252 if (attr2
&& (DW_UNSND (attr2
) != 0))
5253 add_symbol_to_list (sym
, &global_symbols
);
5255 add_symbol_to_list (sym
, list_in_scope
);
5259 /* We do not know the address of this symbol.
5260 If it is an external symbol and we have type information
5261 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5262 The address of the variable will then be determined from
5263 the minimal symbol table whenever the variable is
5265 attr2
= dwarf_attr (die
, DW_AT_external
);
5266 if (attr2
&& (DW_UNSND (attr2
) != 0)
5267 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5269 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5270 add_symbol_to_list (sym
, &global_symbols
);
5274 case DW_TAG_formal_parameter
:
5275 attr
= dwarf_attr (die
, DW_AT_location
);
5278 var_decode_location (attr
, sym
, objfile
, cu_header
);
5279 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5280 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5281 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5283 attr
= dwarf_attr (die
, DW_AT_const_value
);
5286 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5288 add_symbol_to_list (sym
, list_in_scope
);
5290 case DW_TAG_unspecified_parameters
:
5291 /* From varargs functions; gdb doesn't seem to have any
5292 interest in this information, so just ignore it for now.
5295 case DW_TAG_class_type
:
5296 case DW_TAG_structure_type
:
5297 case DW_TAG_union_type
:
5298 case DW_TAG_enumeration_type
:
5299 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5300 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5301 add_symbol_to_list (sym
, list_in_scope
);
5303 /* The semantics of C++ state that "struct foo { ... }" also
5304 defines a typedef for "foo". Synthesize a typedef symbol so
5305 that "ptype foo" works as expected. */
5306 if (cu_language
== language_cplus
)
5308 struct symbol
*typedef_sym
= (struct symbol
*)
5309 obstack_alloc (&objfile
->symbol_obstack
,
5310 sizeof (struct symbol
));
5311 *typedef_sym
= *sym
;
5312 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5313 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5314 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5315 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5316 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5317 &objfile
->type_obstack
);
5318 add_symbol_to_list (typedef_sym
, list_in_scope
);
5321 case DW_TAG_typedef
:
5322 case DW_TAG_base_type
:
5323 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5324 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5325 add_symbol_to_list (sym
, list_in_scope
);
5327 case DW_TAG_enumerator
:
5328 attr
= dwarf_attr (die
, DW_AT_const_value
);
5331 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5333 add_symbol_to_list (sym
, list_in_scope
);
5336 /* Not a tag we recognize. Hopefully we aren't processing
5337 trash data, but since we must specifically ignore things
5338 we don't recognize, there is nothing else we should do at
5340 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5341 dwarf_tag_name (die
->tag
));
5348 /* Copy constant value from an attribute to a symbol. */
5351 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5352 struct objfile
*objfile
,
5353 const struct comp_unit_head
*cu_header
)
5355 struct dwarf_block
*blk
;
5360 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5361 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5362 cu_header
->addr_size
,
5363 TYPE_LENGTH (SYMBOL_TYPE
5365 SYMBOL_VALUE_BYTES (sym
) = (char *)
5366 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5367 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5368 it's body - store_unsigned_integer. */
5369 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5371 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5373 case DW_FORM_block1
:
5374 case DW_FORM_block2
:
5375 case DW_FORM_block4
:
5377 blk
= DW_BLOCK (attr
);
5378 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5379 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5381 TYPE_LENGTH (SYMBOL_TYPE
5383 SYMBOL_VALUE_BYTES (sym
) = (char *)
5384 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5385 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5386 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5389 /* The DW_AT_const_value attributes are supposed to carry the
5390 symbol's value "represented as it would be on the target
5391 architecture." By the time we get here, it's already been
5392 converted to host endianness, so we just need to sign- or
5393 zero-extend it as appropriate. */
5395 dwarf2_const_value_data (attr
, sym
, 8);
5398 dwarf2_const_value_data (attr
, sym
, 16);
5401 dwarf2_const_value_data (attr
, sym
, 32);
5404 dwarf2_const_value_data (attr
, sym
, 64);
5408 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5409 SYMBOL_CLASS (sym
) = LOC_CONST
;
5413 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5414 SYMBOL_CLASS (sym
) = LOC_CONST
;
5418 complaint (&symfile_complaints
,
5419 "unsupported const value attribute form: '%s'",
5420 dwarf_form_name (attr
->form
));
5421 SYMBOL_VALUE (sym
) = 0;
5422 SYMBOL_CLASS (sym
) = LOC_CONST
;
5428 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5429 or zero-extend it as appropriate for the symbol's type. */
5431 dwarf2_const_value_data (struct attribute
*attr
,
5435 LONGEST l
= DW_UNSND (attr
);
5437 if (bits
< sizeof (l
) * 8)
5439 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5440 l
&= ((LONGEST
) 1 << bits
) - 1;
5442 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5445 SYMBOL_VALUE (sym
) = l
;
5446 SYMBOL_CLASS (sym
) = LOC_CONST
;
5450 /* Return the type of the die in question using its DW_AT_type attribute. */
5452 static struct type
*
5453 die_type (struct die_info
*die
, struct objfile
*objfile
,
5454 const struct comp_unit_head
*cu_header
)
5457 struct attribute
*type_attr
;
5458 struct die_info
*type_die
;
5461 type_attr
= dwarf_attr (die
, DW_AT_type
);
5464 /* A missing DW_AT_type represents a void type. */
5465 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5469 ref
= dwarf2_get_ref_die_offset (type_attr
);
5470 type_die
= follow_die_ref (ref
);
5473 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5474 ref
, objfile
->name
);
5478 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5481 dump_die (type_die
);
5482 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5488 /* Return the containing type of the die in question using its
5489 DW_AT_containing_type attribute. */
5491 static struct type
*
5492 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5493 const struct comp_unit_head
*cu_header
)
5495 struct type
*type
= NULL
;
5496 struct attribute
*type_attr
;
5497 struct die_info
*type_die
= NULL
;
5500 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5503 ref
= dwarf2_get_ref_die_offset (type_attr
);
5504 type_die
= follow_die_ref (ref
);
5507 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5511 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5516 dump_die (type_die
);
5517 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5524 static struct type
*
5525 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5527 struct die_info
*die
;
5530 die
= follow_die_ref (offset
);
5533 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5536 type
= tag_type_to_type (die
, objfile
);
5541 static struct type
*
5542 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5543 const struct comp_unit_head
*cu_header
)
5551 read_type_die (die
, objfile
, cu_header
);
5555 error ("Dwarf Error: Cannot find type of die [in module %s]",
5563 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5564 const struct comp_unit_head
*cu_header
)
5568 case DW_TAG_class_type
:
5569 case DW_TAG_structure_type
:
5570 case DW_TAG_union_type
:
5571 read_structure_scope (die
, objfile
, cu_header
);
5573 case DW_TAG_enumeration_type
:
5574 read_enumeration (die
, objfile
, cu_header
);
5576 case DW_TAG_subprogram
:
5577 case DW_TAG_subroutine_type
:
5578 read_subroutine_type (die
, objfile
, cu_header
);
5580 case DW_TAG_array_type
:
5581 read_array_type (die
, objfile
, cu_header
);
5583 case DW_TAG_pointer_type
:
5584 read_tag_pointer_type (die
, objfile
, cu_header
);
5586 case DW_TAG_ptr_to_member_type
:
5587 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5589 case DW_TAG_reference_type
:
5590 read_tag_reference_type (die
, objfile
, cu_header
);
5592 case DW_TAG_const_type
:
5593 read_tag_const_type (die
, objfile
, cu_header
);
5595 case DW_TAG_volatile_type
:
5596 read_tag_volatile_type (die
, objfile
, cu_header
);
5598 case DW_TAG_string_type
:
5599 read_tag_string_type (die
, objfile
);
5601 case DW_TAG_typedef
:
5602 read_typedef (die
, objfile
, cu_header
);
5604 case DW_TAG_base_type
:
5605 read_base_type (die
, objfile
);
5608 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5609 dwarf_tag_name (die
->tag
));
5614 static struct type
*
5615 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5617 /* FIXME - this should not produce a new (struct type *)
5618 every time. It should cache base types. */
5622 case DW_ATE_address
:
5623 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5625 case DW_ATE_boolean
:
5626 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5628 case DW_ATE_complex_float
:
5631 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5635 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5641 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5645 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5652 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5655 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5659 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5663 case DW_ATE_signed_char
:
5664 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5666 case DW_ATE_unsigned
:
5670 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5673 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5677 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5681 case DW_ATE_unsigned_char
:
5682 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5685 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5692 copy_die (struct die_info
*old_die
)
5694 struct die_info
*new_die
;
5697 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5698 memset (new_die
, 0, sizeof (struct die_info
));
5700 new_die
->tag
= old_die
->tag
;
5701 new_die
->has_children
= old_die
->has_children
;
5702 new_die
->abbrev
= old_die
->abbrev
;
5703 new_die
->offset
= old_die
->offset
;
5704 new_die
->type
= NULL
;
5706 num_attrs
= old_die
->num_attrs
;
5707 new_die
->num_attrs
= num_attrs
;
5708 new_die
->attrs
= (struct attribute
*)
5709 xmalloc (num_attrs
* sizeof (struct attribute
));
5711 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5713 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5714 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5715 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5718 new_die
->next
= NULL
;
5723 /* Return sibling of die, NULL if no sibling. */
5725 static struct die_info
*
5726 sibling_die (struct die_info
*die
)
5728 int nesting_level
= 0;
5730 if (!die
->has_children
)
5732 if (die
->next
&& (die
->next
->tag
== 0))
5745 if (die
->has_children
)
5755 while (nesting_level
);
5756 if (die
&& (die
->tag
== 0))
5767 /* Get linkage name of a die, return NULL if not found. */
5770 dwarf2_linkage_name (struct die_info
*die
)
5772 struct attribute
*attr
;
5774 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5775 if (attr
&& DW_STRING (attr
))
5776 return DW_STRING (attr
);
5777 attr
= dwarf_attr (die
, DW_AT_name
);
5778 if (attr
&& DW_STRING (attr
))
5779 return DW_STRING (attr
);
5783 /* Get name of a die, return NULL if not found. */
5786 dwarf2_name (struct die_info
*die
)
5788 struct attribute
*attr
;
5790 attr
= dwarf_attr (die
, DW_AT_name
);
5791 if (attr
&& DW_STRING (attr
))
5792 return DW_STRING (attr
);
5796 /* Return the die that this die in an extension of, or NULL if there
5799 static struct die_info
*
5800 dwarf2_extension (struct die_info
*die
)
5802 struct attribute
*attr
;
5803 struct die_info
*extension_die
;
5806 attr
= dwarf_attr (die
, DW_AT_extension
);
5810 ref
= dwarf2_get_ref_die_offset (attr
);
5811 extension_die
= follow_die_ref (ref
);
5814 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5817 return extension_die
;
5820 /* Convert a DIE tag into its string name. */
5823 dwarf_tag_name (register unsigned tag
)
5827 case DW_TAG_padding
:
5828 return "DW_TAG_padding";
5829 case DW_TAG_array_type
:
5830 return "DW_TAG_array_type";
5831 case DW_TAG_class_type
:
5832 return "DW_TAG_class_type";
5833 case DW_TAG_entry_point
:
5834 return "DW_TAG_entry_point";
5835 case DW_TAG_enumeration_type
:
5836 return "DW_TAG_enumeration_type";
5837 case DW_TAG_formal_parameter
:
5838 return "DW_TAG_formal_parameter";
5839 case DW_TAG_imported_declaration
:
5840 return "DW_TAG_imported_declaration";
5842 return "DW_TAG_label";
5843 case DW_TAG_lexical_block
:
5844 return "DW_TAG_lexical_block";
5846 return "DW_TAG_member";
5847 case DW_TAG_pointer_type
:
5848 return "DW_TAG_pointer_type";
5849 case DW_TAG_reference_type
:
5850 return "DW_TAG_reference_type";
5851 case DW_TAG_compile_unit
:
5852 return "DW_TAG_compile_unit";
5853 case DW_TAG_string_type
:
5854 return "DW_TAG_string_type";
5855 case DW_TAG_structure_type
:
5856 return "DW_TAG_structure_type";
5857 case DW_TAG_subroutine_type
:
5858 return "DW_TAG_subroutine_type";
5859 case DW_TAG_typedef
:
5860 return "DW_TAG_typedef";
5861 case DW_TAG_union_type
:
5862 return "DW_TAG_union_type";
5863 case DW_TAG_unspecified_parameters
:
5864 return "DW_TAG_unspecified_parameters";
5865 case DW_TAG_variant
:
5866 return "DW_TAG_variant";
5867 case DW_TAG_common_block
:
5868 return "DW_TAG_common_block";
5869 case DW_TAG_common_inclusion
:
5870 return "DW_TAG_common_inclusion";
5871 case DW_TAG_inheritance
:
5872 return "DW_TAG_inheritance";
5873 case DW_TAG_inlined_subroutine
:
5874 return "DW_TAG_inlined_subroutine";
5876 return "DW_TAG_module";
5877 case DW_TAG_ptr_to_member_type
:
5878 return "DW_TAG_ptr_to_member_type";
5879 case DW_TAG_set_type
:
5880 return "DW_TAG_set_type";
5881 case DW_TAG_subrange_type
:
5882 return "DW_TAG_subrange_type";
5883 case DW_TAG_with_stmt
:
5884 return "DW_TAG_with_stmt";
5885 case DW_TAG_access_declaration
:
5886 return "DW_TAG_access_declaration";
5887 case DW_TAG_base_type
:
5888 return "DW_TAG_base_type";
5889 case DW_TAG_catch_block
:
5890 return "DW_TAG_catch_block";
5891 case DW_TAG_const_type
:
5892 return "DW_TAG_const_type";
5893 case DW_TAG_constant
:
5894 return "DW_TAG_constant";
5895 case DW_TAG_enumerator
:
5896 return "DW_TAG_enumerator";
5897 case DW_TAG_file_type
:
5898 return "DW_TAG_file_type";
5900 return "DW_TAG_friend";
5901 case DW_TAG_namelist
:
5902 return "DW_TAG_namelist";
5903 case DW_TAG_namelist_item
:
5904 return "DW_TAG_namelist_item";
5905 case DW_TAG_packed_type
:
5906 return "DW_TAG_packed_type";
5907 case DW_TAG_subprogram
:
5908 return "DW_TAG_subprogram";
5909 case DW_TAG_template_type_param
:
5910 return "DW_TAG_template_type_param";
5911 case DW_TAG_template_value_param
:
5912 return "DW_TAG_template_value_param";
5913 case DW_TAG_thrown_type
:
5914 return "DW_TAG_thrown_type";
5915 case DW_TAG_try_block
:
5916 return "DW_TAG_try_block";
5917 case DW_TAG_variant_part
:
5918 return "DW_TAG_variant_part";
5919 case DW_TAG_variable
:
5920 return "DW_TAG_variable";
5921 case DW_TAG_volatile_type
:
5922 return "DW_TAG_volatile_type";
5923 case DW_TAG_dwarf_procedure
:
5924 return "DW_TAG_dwarf_procedure";
5925 case DW_TAG_restrict_type
:
5926 return "DW_TAG_restrict_type";
5927 case DW_TAG_interface_type
:
5928 return "DW_TAG_interface_type";
5929 case DW_TAG_namespace
:
5930 return "DW_TAG_namespace";
5931 case DW_TAG_imported_module
:
5932 return "DW_TAG_imported_module";
5933 case DW_TAG_unspecified_type
:
5934 return "DW_TAG_unspecified_type";
5935 case DW_TAG_partial_unit
:
5936 return "DW_TAG_partial_unit";
5937 case DW_TAG_imported_unit
:
5938 return "DW_TAG_imported_unit";
5939 case DW_TAG_MIPS_loop
:
5940 return "DW_TAG_MIPS_loop";
5941 case DW_TAG_format_label
:
5942 return "DW_TAG_format_label";
5943 case DW_TAG_function_template
:
5944 return "DW_TAG_function_template";
5945 case DW_TAG_class_template
:
5946 return "DW_TAG_class_template";
5948 return "DW_TAG_<unknown>";
5952 /* Convert a DWARF attribute code into its string name. */
5955 dwarf_attr_name (register unsigned attr
)
5960 return "DW_AT_sibling";
5961 case DW_AT_location
:
5962 return "DW_AT_location";
5964 return "DW_AT_name";
5965 case DW_AT_ordering
:
5966 return "DW_AT_ordering";
5967 case DW_AT_subscr_data
:
5968 return "DW_AT_subscr_data";
5969 case DW_AT_byte_size
:
5970 return "DW_AT_byte_size";
5971 case DW_AT_bit_offset
:
5972 return "DW_AT_bit_offset";
5973 case DW_AT_bit_size
:
5974 return "DW_AT_bit_size";
5975 case DW_AT_element_list
:
5976 return "DW_AT_element_list";
5977 case DW_AT_stmt_list
:
5978 return "DW_AT_stmt_list";
5980 return "DW_AT_low_pc";
5982 return "DW_AT_high_pc";
5983 case DW_AT_language
:
5984 return "DW_AT_language";
5986 return "DW_AT_member";
5988 return "DW_AT_discr";
5989 case DW_AT_discr_value
:
5990 return "DW_AT_discr_value";
5991 case DW_AT_visibility
:
5992 return "DW_AT_visibility";
5994 return "DW_AT_import";
5995 case DW_AT_string_length
:
5996 return "DW_AT_string_length";
5997 case DW_AT_common_reference
:
5998 return "DW_AT_common_reference";
5999 case DW_AT_comp_dir
:
6000 return "DW_AT_comp_dir";
6001 case DW_AT_const_value
:
6002 return "DW_AT_const_value";
6003 case DW_AT_containing_type
:
6004 return "DW_AT_containing_type";
6005 case DW_AT_default_value
:
6006 return "DW_AT_default_value";
6008 return "DW_AT_inline";
6009 case DW_AT_is_optional
:
6010 return "DW_AT_is_optional";
6011 case DW_AT_lower_bound
:
6012 return "DW_AT_lower_bound";
6013 case DW_AT_producer
:
6014 return "DW_AT_producer";
6015 case DW_AT_prototyped
:
6016 return "DW_AT_prototyped";
6017 case DW_AT_return_addr
:
6018 return "DW_AT_return_addr";
6019 case DW_AT_start_scope
:
6020 return "DW_AT_start_scope";
6021 case DW_AT_stride_size
:
6022 return "DW_AT_stride_size";
6023 case DW_AT_upper_bound
:
6024 return "DW_AT_upper_bound";
6025 case DW_AT_abstract_origin
:
6026 return "DW_AT_abstract_origin";
6027 case DW_AT_accessibility
:
6028 return "DW_AT_accessibility";
6029 case DW_AT_address_class
:
6030 return "DW_AT_address_class";
6031 case DW_AT_artificial
:
6032 return "DW_AT_artificial";
6033 case DW_AT_base_types
:
6034 return "DW_AT_base_types";
6035 case DW_AT_calling_convention
:
6036 return "DW_AT_calling_convention";
6038 return "DW_AT_count";
6039 case DW_AT_data_member_location
:
6040 return "DW_AT_data_member_location";
6041 case DW_AT_decl_column
:
6042 return "DW_AT_decl_column";
6043 case DW_AT_decl_file
:
6044 return "DW_AT_decl_file";
6045 case DW_AT_decl_line
:
6046 return "DW_AT_decl_line";
6047 case DW_AT_declaration
:
6048 return "DW_AT_declaration";
6049 case DW_AT_discr_list
:
6050 return "DW_AT_discr_list";
6051 case DW_AT_encoding
:
6052 return "DW_AT_encoding";
6053 case DW_AT_external
:
6054 return "DW_AT_external";
6055 case DW_AT_frame_base
:
6056 return "DW_AT_frame_base";
6058 return "DW_AT_friend";
6059 case DW_AT_identifier_case
:
6060 return "DW_AT_identifier_case";
6061 case DW_AT_macro_info
:
6062 return "DW_AT_macro_info";
6063 case DW_AT_namelist_items
:
6064 return "DW_AT_namelist_items";
6065 case DW_AT_priority
:
6066 return "DW_AT_priority";
6068 return "DW_AT_segment";
6069 case DW_AT_specification
:
6070 return "DW_AT_specification";
6071 case DW_AT_static_link
:
6072 return "DW_AT_static_link";
6074 return "DW_AT_type";
6075 case DW_AT_use_location
:
6076 return "DW_AT_use_location";
6077 case DW_AT_variable_parameter
:
6078 return "DW_AT_variable_parameter";
6079 case DW_AT_virtuality
:
6080 return "DW_AT_virtuality";
6081 case DW_AT_vtable_elem_location
:
6082 return "DW_AT_vtable_elem_location";
6083 case DW_AT_allocated
:
6084 return "DW_AT_allocated";
6085 case DW_AT_associated
:
6086 return "DW_AT_associated";
6087 case DW_AT_data_location
:
6088 return "DW_AT_data_location";
6090 return "DW_AT_stride";
6091 case DW_AT_entry_pc
:
6092 return "DW_AT_entry_pc";
6093 case DW_AT_use_UTF8
:
6094 return "DW_AT_use_UTF8";
6095 case DW_AT_extension
:
6096 return "DW_AT_extension";
6098 return "DW_AT_ranges";
6099 case DW_AT_trampoline
:
6100 return "DW_AT_trampoline";
6101 case DW_AT_call_column
:
6102 return "DW_AT_call_column";
6103 case DW_AT_call_file
:
6104 return "DW_AT_call_file";
6105 case DW_AT_call_line
:
6106 return "DW_AT_call_line";
6108 case DW_AT_MIPS_fde
:
6109 return "DW_AT_MIPS_fde";
6110 case DW_AT_MIPS_loop_begin
:
6111 return "DW_AT_MIPS_loop_begin";
6112 case DW_AT_MIPS_tail_loop_begin
:
6113 return "DW_AT_MIPS_tail_loop_begin";
6114 case DW_AT_MIPS_epilog_begin
:
6115 return "DW_AT_MIPS_epilog_begin";
6116 case DW_AT_MIPS_loop_unroll_factor
:
6117 return "DW_AT_MIPS_loop_unroll_factor";
6118 case DW_AT_MIPS_software_pipeline_depth
:
6119 return "DW_AT_MIPS_software_pipeline_depth";
6121 case DW_AT_MIPS_linkage_name
:
6122 return "DW_AT_MIPS_linkage_name";
6124 case DW_AT_sf_names
:
6125 return "DW_AT_sf_names";
6126 case DW_AT_src_info
:
6127 return "DW_AT_src_info";
6128 case DW_AT_mac_info
:
6129 return "DW_AT_mac_info";
6130 case DW_AT_src_coords
:
6131 return "DW_AT_src_coords";
6132 case DW_AT_body_begin
:
6133 return "DW_AT_body_begin";
6134 case DW_AT_body_end
:
6135 return "DW_AT_body_end";
6136 case DW_AT_GNU_vector
:
6137 return "DW_AT_GNU_vector";
6139 return "DW_AT_<unknown>";
6143 /* Convert a DWARF value form code into its string name. */
6146 dwarf_form_name (register unsigned form
)
6151 return "DW_FORM_addr";
6152 case DW_FORM_block2
:
6153 return "DW_FORM_block2";
6154 case DW_FORM_block4
:
6155 return "DW_FORM_block4";
6157 return "DW_FORM_data2";
6159 return "DW_FORM_data4";
6161 return "DW_FORM_data8";
6162 case DW_FORM_string
:
6163 return "DW_FORM_string";
6165 return "DW_FORM_block";
6166 case DW_FORM_block1
:
6167 return "DW_FORM_block1";
6169 return "DW_FORM_data1";
6171 return "DW_FORM_flag";
6173 return "DW_FORM_sdata";
6175 return "DW_FORM_strp";
6177 return "DW_FORM_udata";
6178 case DW_FORM_ref_addr
:
6179 return "DW_FORM_ref_addr";
6181 return "DW_FORM_ref1";
6183 return "DW_FORM_ref2";
6185 return "DW_FORM_ref4";
6187 return "DW_FORM_ref8";
6188 case DW_FORM_ref_udata
:
6189 return "DW_FORM_ref_udata";
6190 case DW_FORM_indirect
:
6191 return "DW_FORM_indirect";
6193 return "DW_FORM_<unknown>";
6197 /* Convert a DWARF stack opcode into its string name. */
6200 dwarf_stack_op_name (register unsigned op
)
6205 return "DW_OP_addr";
6207 return "DW_OP_deref";
6209 return "DW_OP_const1u";
6211 return "DW_OP_const1s";
6213 return "DW_OP_const2u";
6215 return "DW_OP_const2s";
6217 return "DW_OP_const4u";
6219 return "DW_OP_const4s";
6221 return "DW_OP_const8u";
6223 return "DW_OP_const8s";
6225 return "DW_OP_constu";
6227 return "DW_OP_consts";
6231 return "DW_OP_drop";
6233 return "DW_OP_over";
6235 return "DW_OP_pick";
6237 return "DW_OP_swap";
6241 return "DW_OP_xderef";
6249 return "DW_OP_minus";
6261 return "DW_OP_plus";
6262 case DW_OP_plus_uconst
:
6263 return "DW_OP_plus_uconst";
6269 return "DW_OP_shra";
6287 return "DW_OP_skip";
6289 return "DW_OP_lit0";
6291 return "DW_OP_lit1";
6293 return "DW_OP_lit2";
6295 return "DW_OP_lit3";
6297 return "DW_OP_lit4";
6299 return "DW_OP_lit5";
6301 return "DW_OP_lit6";
6303 return "DW_OP_lit7";
6305 return "DW_OP_lit8";
6307 return "DW_OP_lit9";
6309 return "DW_OP_lit10";
6311 return "DW_OP_lit11";
6313 return "DW_OP_lit12";
6315 return "DW_OP_lit13";
6317 return "DW_OP_lit14";
6319 return "DW_OP_lit15";
6321 return "DW_OP_lit16";
6323 return "DW_OP_lit17";
6325 return "DW_OP_lit18";
6327 return "DW_OP_lit19";
6329 return "DW_OP_lit20";
6331 return "DW_OP_lit21";
6333 return "DW_OP_lit22";
6335 return "DW_OP_lit23";
6337 return "DW_OP_lit24";
6339 return "DW_OP_lit25";
6341 return "DW_OP_lit26";
6343 return "DW_OP_lit27";
6345 return "DW_OP_lit28";
6347 return "DW_OP_lit29";
6349 return "DW_OP_lit30";
6351 return "DW_OP_lit31";
6353 return "DW_OP_reg0";
6355 return "DW_OP_reg1";
6357 return "DW_OP_reg2";
6359 return "DW_OP_reg3";
6361 return "DW_OP_reg4";
6363 return "DW_OP_reg5";
6365 return "DW_OP_reg6";
6367 return "DW_OP_reg7";
6369 return "DW_OP_reg8";
6371 return "DW_OP_reg9";
6373 return "DW_OP_reg10";
6375 return "DW_OP_reg11";
6377 return "DW_OP_reg12";
6379 return "DW_OP_reg13";
6381 return "DW_OP_reg14";
6383 return "DW_OP_reg15";
6385 return "DW_OP_reg16";
6387 return "DW_OP_reg17";
6389 return "DW_OP_reg18";
6391 return "DW_OP_reg19";
6393 return "DW_OP_reg20";
6395 return "DW_OP_reg21";
6397 return "DW_OP_reg22";
6399 return "DW_OP_reg23";
6401 return "DW_OP_reg24";
6403 return "DW_OP_reg25";
6405 return "DW_OP_reg26";
6407 return "DW_OP_reg27";
6409 return "DW_OP_reg28";
6411 return "DW_OP_reg29";
6413 return "DW_OP_reg30";
6415 return "DW_OP_reg31";
6417 return "DW_OP_breg0";
6419 return "DW_OP_breg1";
6421 return "DW_OP_breg2";
6423 return "DW_OP_breg3";
6425 return "DW_OP_breg4";
6427 return "DW_OP_breg5";
6429 return "DW_OP_breg6";
6431 return "DW_OP_breg7";
6433 return "DW_OP_breg8";
6435 return "DW_OP_breg9";
6437 return "DW_OP_breg10";
6439 return "DW_OP_breg11";
6441 return "DW_OP_breg12";
6443 return "DW_OP_breg13";
6445 return "DW_OP_breg14";
6447 return "DW_OP_breg15";
6449 return "DW_OP_breg16";
6451 return "DW_OP_breg17";
6453 return "DW_OP_breg18";
6455 return "DW_OP_breg19";
6457 return "DW_OP_breg20";
6459 return "DW_OP_breg21";
6461 return "DW_OP_breg22";
6463 return "DW_OP_breg23";
6465 return "DW_OP_breg24";
6467 return "DW_OP_breg25";
6469 return "DW_OP_breg26";
6471 return "DW_OP_breg27";
6473 return "DW_OP_breg28";
6475 return "DW_OP_breg29";
6477 return "DW_OP_breg30";
6479 return "DW_OP_breg31";
6481 return "DW_OP_regx";
6483 return "DW_OP_fbreg";
6485 return "DW_OP_bregx";
6487 return "DW_OP_piece";
6488 case DW_OP_deref_size
:
6489 return "DW_OP_deref_size";
6490 case DW_OP_xderef_size
:
6491 return "DW_OP_xderef_size";
6494 /* DWARF 3 extensions. */
6495 case DW_OP_push_object_address
:
6496 return "DW_OP_push_object_address";
6498 return "DW_OP_call2";
6500 return "DW_OP_call4";
6501 case DW_OP_call_ref
:
6502 return "DW_OP_call_ref";
6503 /* GNU extensions. */
6504 case DW_OP_GNU_push_tls_address
:
6505 return "DW_OP_GNU_push_tls_address";
6507 return "OP_<unknown>";
6512 dwarf_bool_name (unsigned mybool
)
6520 /* Convert a DWARF type code into its string name. */
6523 dwarf_type_encoding_name (register unsigned enc
)
6527 case DW_ATE_address
:
6528 return "DW_ATE_address";
6529 case DW_ATE_boolean
:
6530 return "DW_ATE_boolean";
6531 case DW_ATE_complex_float
:
6532 return "DW_ATE_complex_float";
6534 return "DW_ATE_float";
6536 return "DW_ATE_signed";
6537 case DW_ATE_signed_char
:
6538 return "DW_ATE_signed_char";
6539 case DW_ATE_unsigned
:
6540 return "DW_ATE_unsigned";
6541 case DW_ATE_unsigned_char
:
6542 return "DW_ATE_unsigned_char";
6543 case DW_ATE_imaginary_float
:
6544 return "DW_ATE_imaginary_float";
6546 return "DW_ATE_<unknown>";
6550 /* Convert a DWARF call frame info operation to its string name. */
6554 dwarf_cfi_name (register unsigned cfi_opc
)
6558 case DW_CFA_advance_loc
:
6559 return "DW_CFA_advance_loc";
6561 return "DW_CFA_offset";
6562 case DW_CFA_restore
:
6563 return "DW_CFA_restore";
6565 return "DW_CFA_nop";
6566 case DW_CFA_set_loc
:
6567 return "DW_CFA_set_loc";
6568 case DW_CFA_advance_loc1
:
6569 return "DW_CFA_advance_loc1";
6570 case DW_CFA_advance_loc2
:
6571 return "DW_CFA_advance_loc2";
6572 case DW_CFA_advance_loc4
:
6573 return "DW_CFA_advance_loc4";
6574 case DW_CFA_offset_extended
:
6575 return "DW_CFA_offset_extended";
6576 case DW_CFA_restore_extended
:
6577 return "DW_CFA_restore_extended";
6578 case DW_CFA_undefined
:
6579 return "DW_CFA_undefined";
6580 case DW_CFA_same_value
:
6581 return "DW_CFA_same_value";
6582 case DW_CFA_register
:
6583 return "DW_CFA_register";
6584 case DW_CFA_remember_state
:
6585 return "DW_CFA_remember_state";
6586 case DW_CFA_restore_state
:
6587 return "DW_CFA_restore_state";
6588 case DW_CFA_def_cfa
:
6589 return "DW_CFA_def_cfa";
6590 case DW_CFA_def_cfa_register
:
6591 return "DW_CFA_def_cfa_register";
6592 case DW_CFA_def_cfa_offset
:
6593 return "DW_CFA_def_cfa_offset";
6596 case DW_CFA_def_cfa_expression
:
6597 return "DW_CFA_def_cfa_expression";
6598 case DW_CFA_expression
:
6599 return "DW_CFA_expression";
6600 case DW_CFA_offset_extended_sf
:
6601 return "DW_CFA_offset_extended_sf";
6602 case DW_CFA_def_cfa_sf
:
6603 return "DW_CFA_def_cfa_sf";
6604 case DW_CFA_def_cfa_offset_sf
:
6605 return "DW_CFA_def_cfa_offset_sf";
6607 /* SGI/MIPS specific */
6608 case DW_CFA_MIPS_advance_loc8
:
6609 return "DW_CFA_MIPS_advance_loc8";
6611 /* GNU extensions */
6612 case DW_CFA_GNU_window_save
:
6613 return "DW_CFA_GNU_window_save";
6614 case DW_CFA_GNU_args_size
:
6615 return "DW_CFA_GNU_args_size";
6616 case DW_CFA_GNU_negative_offset_extended
:
6617 return "DW_CFA_GNU_negative_offset_extended";
6620 return "DW_CFA_<unknown>";
6626 dump_die (struct die_info
*die
)
6630 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6631 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6632 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6633 dwarf_bool_name (die
->has_children
));
6635 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6636 for (i
= 0; i
< die
->num_attrs
; ++i
)
6638 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6639 dwarf_attr_name (die
->attrs
[i
].name
),
6640 dwarf_form_name (die
->attrs
[i
].form
));
6641 switch (die
->attrs
[i
].form
)
6643 case DW_FORM_ref_addr
:
6645 fprintf_unfiltered (gdb_stderr
, "address: ");
6646 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6648 case DW_FORM_block2
:
6649 case DW_FORM_block4
:
6651 case DW_FORM_block1
:
6652 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6663 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6665 case DW_FORM_string
:
6667 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6668 DW_STRING (&die
->attrs
[i
])
6669 ? DW_STRING (&die
->attrs
[i
]) : "");
6672 if (DW_UNSND (&die
->attrs
[i
]))
6673 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6675 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6677 case DW_FORM_indirect
:
6678 /* the reader will have reduced the indirect form to
6679 the "base form" so this form should not occur */
6680 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6683 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6684 die
->attrs
[i
].form
);
6686 fprintf_unfiltered (gdb_stderr
, "\n");
6691 dump_die_list (struct die_info
*die
)
6701 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6704 struct die_info
*old
;
6706 h
= (offset
% REF_HASH_SIZE
);
6707 old
= die_ref_table
[h
];
6708 die
->next_ref
= old
;
6709 die_ref_table
[h
] = die
;
6714 dwarf2_empty_hash_tables (void)
6716 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6720 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6722 unsigned int result
= 0;
6726 case DW_FORM_ref_addr
:
6727 result
= DW_ADDR (attr
);
6733 case DW_FORM_ref_udata
:
6734 result
= cu_header_offset
+ DW_UNSND (attr
);
6737 complaint (&symfile_complaints
,
6738 "unsupported die ref attribute form: '%s'",
6739 dwarf_form_name (attr
->form
));
6744 static struct die_info
*
6745 follow_die_ref (unsigned int offset
)
6747 struct die_info
*die
;
6750 h
= (offset
% REF_HASH_SIZE
);
6751 die
= die_ref_table
[h
];
6754 if (die
->offset
== offset
)
6758 die
= die
->next_ref
;
6763 static struct type
*
6764 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6766 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6768 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6769 typeid, objfile
->name
);
6772 /* Look for this particular type in the fundamental type vector. If
6773 one is not found, create and install one appropriate for the
6774 current language and the current target machine. */
6776 if (ftypes
[typeid] == NULL
)
6778 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6781 return (ftypes
[typeid]);
6784 /* Decode simple location descriptions.
6785 Given a pointer to a dwarf block that defines a location, compute
6786 the location and return the value.
6788 FIXME: This is a kludge until we figure out a better
6789 way to handle the location descriptions.
6790 Gdb's design does not mesh well with the DWARF2 notion of a location
6791 computing interpreter, which is a shame because the flexibility goes unused.
6792 FIXME: Implement more operations as necessary.
6794 A location description containing no operations indicates that the
6795 object is optimized out. The global optimized_out flag is set for
6796 those, the return value is meaningless.
6798 When the result is a register number, the global isreg flag is set,
6799 otherwise it is cleared.
6801 When the result is a base register offset, the global offreg flag is set
6802 and the register number is returned in basereg, otherwise it is cleared.
6804 When the DW_OP_fbreg operation is encountered without a corresponding
6805 DW_AT_frame_base attribute, the global islocal flag is set.
6806 Hopefully the machine dependent code knows how to set up a virtual
6807 frame pointer for the local references.
6809 Note that stack[0] is unused except as a default error return.
6810 Note that stack overflow is not yet handled. */
6813 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6814 const struct comp_unit_head
*cu_header
)
6817 int size
= blk
->size
;
6818 char *data
= blk
->data
;
6819 CORE_ADDR stack
[64];
6821 unsigned int bytes_read
, unsnd
;
6871 stack
[++stacki
] = op
- DW_OP_lit0
;
6907 stack
[++stacki
] = op
- DW_OP_reg0
;
6912 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6914 stack
[++stacki
] = unsnd
;
6950 basereg
= op
- DW_OP_breg0
;
6951 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6957 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6959 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6964 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6966 if (frame_base_reg
>= 0)
6969 basereg
= frame_base_reg
;
6970 stack
[stacki
] += frame_base_offset
;
6974 complaint (&symfile_complaints
,
6975 "DW_AT_frame_base missing for DW_OP_fbreg");
6981 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6982 cu_header
, &bytes_read
);
6987 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6992 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6997 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
7002 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
7007 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
7012 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
7017 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
7023 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7028 stack
[stacki
+ 1] = stack
[stacki
];
7033 stack
[stacki
- 1] += stack
[stacki
];
7037 case DW_OP_plus_uconst
:
7038 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7043 stack
[stacki
- 1] -= stack
[stacki
];
7049 /* If we're not the last op, then we definitely can't encode
7050 this using GDB's address_class enum. */
7052 dwarf2_complex_location_expr_complaint ();
7055 case DW_OP_GNU_push_tls_address
:
7056 /* The top of the stack has the offset from the beginning
7057 of the thread control block at which the variable is located. */
7058 /* Nothing should follow this operator, so the top of stack would
7061 dwarf2_complex_location_expr_complaint ();
7065 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7066 dwarf_stack_op_name (op
));
7067 return (stack
[stacki
]);
7070 return (stack
[stacki
]);
7073 /* memory allocation interface */
7077 dwarf2_free_tmp_obstack (void *ignore
)
7079 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7082 static struct dwarf_block
*
7083 dwarf_alloc_block (void)
7085 struct dwarf_block
*blk
;
7087 blk
= (struct dwarf_block
*)
7088 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7092 static struct abbrev_info
*
7093 dwarf_alloc_abbrev (void)
7095 struct abbrev_info
*abbrev
;
7097 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7098 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7102 static struct die_info
*
7103 dwarf_alloc_die (void)
7105 struct die_info
*die
;
7107 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7108 memset (die
, 0, sizeof (struct die_info
));
7113 /* Macro support. */
7116 /* Return the full name of file number I in *LH's file name table.
7117 Use COMP_DIR as the name of the current directory of the
7118 compilation. The result is allocated using xmalloc; the caller is
7119 responsible for freeing it. */
7121 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7123 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7125 if (IS_ABSOLUTE_PATH (fe
->name
))
7126 return xstrdup (fe
->name
);
7134 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7140 dir_len
= strlen (dir
);
7141 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7142 strcpy (full_name
, dir
);
7143 full_name
[dir_len
] = '/';
7144 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7148 return xstrdup (fe
->name
);
7153 static struct macro_source_file
*
7154 macro_start_file (int file
, int line
,
7155 struct macro_source_file
*current_file
,
7156 const char *comp_dir
,
7157 struct line_header
*lh
, struct objfile
*objfile
)
7159 /* The full name of this source file. */
7160 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7162 /* We don't create a macro table for this compilation unit
7163 at all until we actually get a filename. */
7164 if (! pending_macros
)
7165 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7166 objfile
->macro_cache
);
7169 /* If we have no current file, then this must be the start_file
7170 directive for the compilation unit's main source file. */
7171 current_file
= macro_set_main (pending_macros
, full_name
);
7173 current_file
= macro_include (current_file
, line
, full_name
);
7177 return current_file
;
7181 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7182 followed by a null byte. */
7184 copy_string (const char *buf
, int len
)
7186 char *s
= xmalloc (len
+ 1);
7187 memcpy (s
, buf
, len
);
7195 consume_improper_spaces (const char *p
, const char *body
)
7199 complaint (&symfile_complaints
,
7200 "macro definition contains spaces in formal argument list:\n`%s'",
7212 parse_macro_definition (struct macro_source_file
*file
, int line
,
7217 /* The body string takes one of two forms. For object-like macro
7218 definitions, it should be:
7220 <macro name> " " <definition>
7222 For function-like macro definitions, it should be:
7224 <macro name> "() " <definition>
7226 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7228 Spaces may appear only where explicitly indicated, and in the
7231 The Dwarf 2 spec says that an object-like macro's name is always
7232 followed by a space, but versions of GCC around March 2002 omit
7233 the space when the macro's definition is the empty string.
7235 The Dwarf 2 spec says that there should be no spaces between the
7236 formal arguments in a function-like macro's formal argument list,
7237 but versions of GCC around March 2002 include spaces after the
7241 /* Find the extent of the macro name. The macro name is terminated
7242 by either a space or null character (for an object-like macro) or
7243 an opening paren (for a function-like macro). */
7244 for (p
= body
; *p
; p
++)
7245 if (*p
== ' ' || *p
== '(')
7248 if (*p
== ' ' || *p
== '\0')
7250 /* It's an object-like macro. */
7251 int name_len
= p
- body
;
7252 char *name
= copy_string (body
, name_len
);
7253 const char *replacement
;
7256 replacement
= body
+ name_len
+ 1;
7259 dwarf2_macro_malformed_definition_complaint (body
);
7260 replacement
= body
+ name_len
;
7263 macro_define_object (file
, line
, name
, replacement
);
7269 /* It's a function-like macro. */
7270 char *name
= copy_string (body
, p
- body
);
7273 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7277 p
= consume_improper_spaces (p
, body
);
7279 /* Parse the formal argument list. */
7280 while (*p
&& *p
!= ')')
7282 /* Find the extent of the current argument name. */
7283 const char *arg_start
= p
;
7285 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7288 if (! *p
|| p
== arg_start
)
7289 dwarf2_macro_malformed_definition_complaint (body
);
7292 /* Make sure argv has room for the new argument. */
7293 if (argc
>= argv_size
)
7296 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7299 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7302 p
= consume_improper_spaces (p
, body
);
7304 /* Consume the comma, if present. */
7309 p
= consume_improper_spaces (p
, body
);
7318 /* Perfectly formed definition, no complaints. */
7319 macro_define_function (file
, line
, name
,
7320 argc
, (const char **) argv
,
7322 else if (*p
== '\0')
7324 /* Complain, but do define it. */
7325 dwarf2_macro_malformed_definition_complaint (body
);
7326 macro_define_function (file
, line
, name
,
7327 argc
, (const char **) argv
,
7331 /* Just complain. */
7332 dwarf2_macro_malformed_definition_complaint (body
);
7335 /* Just complain. */
7336 dwarf2_macro_malformed_definition_complaint (body
);
7342 for (i
= 0; i
< argc
; i
++)
7348 dwarf2_macro_malformed_definition_complaint (body
);
7353 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7354 char *comp_dir
, bfd
*abfd
,
7355 const struct comp_unit_head
*cu_header
,
7356 struct objfile
*objfile
)
7358 char *mac_ptr
, *mac_end
;
7359 struct macro_source_file
*current_file
= 0;
7361 if (dwarf_macinfo_buffer
== NULL
)
7363 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7367 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7368 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7372 enum dwarf_macinfo_record_type macinfo_type
;
7374 /* Do we at least have room for a macinfo type byte? */
7375 if (mac_ptr
>= mac_end
)
7377 dwarf2_macros_too_long_complaint ();
7381 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7384 switch (macinfo_type
)
7386 /* A zero macinfo type indicates the end of the macro
7391 case DW_MACINFO_define
:
7392 case DW_MACINFO_undef
:
7398 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7399 mac_ptr
+= bytes_read
;
7400 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7401 mac_ptr
+= bytes_read
;
7404 complaint (&symfile_complaints
,
7405 "debug info gives macro %s outside of any file: %s",
7407 DW_MACINFO_define
? "definition" : macinfo_type
==
7408 DW_MACINFO_undef
? "undefinition" :
7409 "something-or-other", body
);
7412 if (macinfo_type
== DW_MACINFO_define
)
7413 parse_macro_definition (current_file
, line
, body
);
7414 else if (macinfo_type
== DW_MACINFO_undef
)
7415 macro_undef (current_file
, line
, body
);
7420 case DW_MACINFO_start_file
:
7425 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7426 mac_ptr
+= bytes_read
;
7427 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7428 mac_ptr
+= bytes_read
;
7430 current_file
= macro_start_file (file
, line
,
7431 current_file
, comp_dir
,
7436 case DW_MACINFO_end_file
:
7438 complaint (&symfile_complaints
,
7439 "macro debug info has an unmatched `close_file' directive");
7442 current_file
= current_file
->included_by
;
7445 enum dwarf_macinfo_record_type next_type
;
7447 /* GCC circa March 2002 doesn't produce the zero
7448 type byte marking the end of the compilation
7449 unit. Complain if it's not there, but exit no
7452 /* Do we at least have room for a macinfo type byte? */
7453 if (mac_ptr
>= mac_end
)
7455 dwarf2_macros_too_long_complaint ();
7459 /* We don't increment mac_ptr here, so this is just
7461 next_type
= read_1_byte (abfd
, mac_ptr
);
7463 complaint (&symfile_complaints
,
7464 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7471 case DW_MACINFO_vendor_ext
:
7477 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7478 mac_ptr
+= bytes_read
;
7479 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7480 mac_ptr
+= bytes_read
;
7482 /* We don't recognize any vendor extensions. */
7489 /* Check if the attribute's form is a DW_FORM_block*
7490 if so return true else false. */
7492 attr_form_is_block (struct attribute
*attr
)
7494 return (attr
== NULL
? 0 :
7495 attr
->form
== DW_FORM_block1
7496 || attr
->form
== DW_FORM_block2
7497 || attr
->form
== DW_FORM_block4
7498 || attr
->form
== DW_FORM_block
);
7502 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7503 const struct comp_unit_head
*cu_header
,
7504 struct objfile
*objfile
)
7506 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7508 struct dwarf2_loclist_baton
*baton
;
7510 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7511 sizeof (struct dwarf2_loclist_baton
));
7512 baton
->objfile
= objfile
;
7514 /* We don't know how long the location list is, but make sure we
7515 don't run off the edge of the section. */
7516 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7517 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7518 baton
->base_address
= cu_header
->base_address
;
7519 if (cu_header
->base_known
== 0)
7520 complaint (&symfile_complaints
,
7521 "Location list used without specifying the CU base address.");
7523 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7524 SYMBOL_LOCATION_BATON (sym
) = baton
;
7528 struct dwarf2_locexpr_baton
*baton
;
7530 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7531 sizeof (struct dwarf2_locexpr_baton
));
7532 baton
->objfile
= objfile
;
7534 if (attr_form_is_block (attr
))
7536 /* Note that we're just copying the block's data pointer
7537 here, not the actual data. We're still pointing into the
7538 dwarf_info_buffer for SYM's objfile; right now we never
7539 release that buffer, but when we do clean up properly
7540 this may need to change. */
7541 baton
->size
= DW_BLOCK (attr
)->size
;
7542 baton
->data
= DW_BLOCK (attr
)->data
;
7546 dwarf2_invalid_attrib_class_complaint ("location description",
7547 SYMBOL_NATURAL_NAME (sym
));
7552 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7553 SYMBOL_LOCATION_BATON (sym
) = baton
;