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 void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
682 static void psymtab_to_symtab_1 (struct partial_symtab
*);
684 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int,
687 static void dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
);
689 static void dwarf2_empty_abbrev_table (void *);
691 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
692 const struct comp_unit_head
*cu_header
);
694 static char *read_partial_die (struct partial_die_info
*,
696 const struct comp_unit_head
*);
698 static char *read_full_die (struct die_info
**, bfd
*, char *,
699 const struct comp_unit_head
*);
701 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
702 bfd
*, char *, const struct comp_unit_head
*);
704 static char *read_attribute_value (struct attribute
*, unsigned,
705 bfd
*, char *, const struct comp_unit_head
*);
707 static unsigned int read_1_byte (bfd
*, char *);
709 static int read_1_signed_byte (bfd
*, char *);
711 static unsigned int read_2_bytes (bfd
*, char *);
713 static unsigned int read_4_bytes (bfd
*, char *);
715 static unsigned long read_8_bytes (bfd
*, char *);
717 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
720 static LONGEST
read_initial_length (bfd
*, char *,
721 struct comp_unit_head
*, int *bytes_read
);
723 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
726 static char *read_n_bytes (bfd
*, char *, unsigned int);
728 static char *read_string (bfd
*, char *, unsigned int *);
730 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
733 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
735 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
737 static void set_cu_language (unsigned int);
739 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
741 static int die_is_declaration (struct die_info
*);
743 static void free_line_header (struct line_header
*lh
);
745 static struct line_header
*(dwarf_decode_line_header
746 (unsigned int offset
,
748 const struct comp_unit_head
*cu_header
));
750 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
751 const struct comp_unit_head
*);
753 static void dwarf2_start_subfile (char *, char *);
755 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
756 struct objfile
*, const struct comp_unit_head
*);
758 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
759 struct objfile
*, const struct comp_unit_head
*);
761 static void dwarf2_const_value_data (struct attribute
*attr
,
765 static struct type
*die_type (struct die_info
*, struct objfile
*,
766 const struct comp_unit_head
*);
768 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
769 const struct comp_unit_head
*);
772 static struct type
*type_at_offset (unsigned int, struct objfile
*);
775 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
776 const struct comp_unit_head
*);
778 static void read_type_die (struct die_info
*, struct objfile
*,
779 const struct comp_unit_head
*);
781 static void read_typedef (struct die_info
*, struct objfile
*,
782 const struct comp_unit_head
*);
784 static void read_base_type (struct die_info
*, struct objfile
*);
786 static void read_file_scope (struct die_info
*, struct objfile
*,
787 const struct comp_unit_head
*);
789 static void read_func_scope (struct die_info
*, struct objfile
*,
790 const struct comp_unit_head
*);
792 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
793 const struct comp_unit_head
*);
795 static int dwarf2_get_pc_bounds (struct die_info
*,
796 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*,
797 const struct comp_unit_head
*);
799 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
800 struct objfile
*, const struct comp_unit_head
*);
802 static void dwarf2_attach_fields_to_type (struct field_info
*,
803 struct type
*, struct objfile
*);
805 static void dwarf2_add_member_fn (struct field_info
*,
806 struct die_info
*, struct type
*,
807 struct objfile
*objfile
,
808 const struct comp_unit_head
*);
810 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
811 struct type
*, struct objfile
*);
813 static void read_structure_scope (struct die_info
*, struct objfile
*,
814 const struct comp_unit_head
*);
816 static void read_common_block (struct die_info
*, struct objfile
*,
817 const struct comp_unit_head
*);
819 static void read_namespace (struct die_info
*die
, struct objfile
*objfile
,
820 const struct comp_unit_head
*cu_header
);
822 static void read_enumeration (struct die_info
*, struct objfile
*,
823 const struct comp_unit_head
*);
825 static struct type
*dwarf_base_type (int, int, struct objfile
*);
827 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
828 const struct comp_unit_head
*);
830 static void read_array_type (struct die_info
*, struct objfile
*,
831 const struct comp_unit_head
*);
833 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
834 const struct comp_unit_head
*);
836 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
837 const struct comp_unit_head
*);
839 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
840 const struct comp_unit_head
*);
842 static void read_tag_const_type (struct die_info
*, struct objfile
*,
843 const struct comp_unit_head
*);
845 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
846 const struct comp_unit_head
*);
848 static void read_tag_string_type (struct die_info
*, struct objfile
*);
850 static void read_subroutine_type (struct die_info
*, struct objfile
*,
851 const struct comp_unit_head
*);
853 static struct die_info
*read_comp_unit (char *, bfd
*,
854 const struct comp_unit_head
*);
856 static void free_die_list (struct die_info
*);
858 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
860 static void process_die (struct die_info
*, struct objfile
*,
861 const struct comp_unit_head
*);
863 static char *dwarf2_linkage_name (struct die_info
*);
865 static char *dwarf2_name (struct die_info
*die
);
867 static struct die_info
*dwarf2_extension (struct die_info
*die
);
869 static char *dwarf_tag_name (unsigned int);
871 static char *dwarf_attr_name (unsigned int);
873 static char *dwarf_form_name (unsigned int);
875 static char *dwarf_stack_op_name (unsigned int);
877 static char *dwarf_bool_name (unsigned int);
879 static char *dwarf_type_encoding_name (unsigned int);
882 static char *dwarf_cfi_name (unsigned int);
884 struct die_info
*copy_die (struct die_info
*);
887 static struct die_info
*sibling_die (struct die_info
*);
889 static void dump_die (struct die_info
*);
891 static void dump_die_list (struct die_info
*);
893 static void store_in_ref_table (unsigned int, struct die_info
*);
895 static void dwarf2_empty_hash_tables (void);
897 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
899 static struct die_info
*follow_die_ref (unsigned int);
901 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
903 /* memory allocation interface */
905 static void dwarf2_free_tmp_obstack (void *);
907 static struct dwarf_block
*dwarf_alloc_block (void);
909 static struct abbrev_info
*dwarf_alloc_abbrev (void);
911 static struct die_info
*dwarf_alloc_die (void);
913 static void initialize_cu_func_list (void);
915 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
917 static void dwarf_decode_macros (struct line_header
*, unsigned int,
918 char *, bfd
*, const struct comp_unit_head
*,
921 static int attr_form_is_block (struct attribute
*);
924 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
925 const struct comp_unit_head
*,
926 struct objfile
*objfile
);
928 /* Try to locate the sections we need for DWARF 2 debugging
929 information and return true if we have enough to do something. */
932 dwarf2_has_info (bfd
*abfd
)
934 dwarf_info_offset
= 0;
935 dwarf_abbrev_offset
= 0;
936 dwarf_line_offset
= 0;
937 dwarf_str_offset
= 0;
938 dwarf_macinfo_offset
= 0;
939 dwarf_frame_offset
= 0;
940 dwarf_eh_frame_offset
= 0;
941 dwarf_ranges_offset
= 0;
942 dwarf_loc_offset
= 0;
944 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
945 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
955 /* This function is mapped across the sections and remembers the
956 offset and size of each of the debugging sections we are interested
960 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
962 if (STREQ (sectp
->name
, INFO_SECTION
))
964 dwarf_info_offset
= sectp
->filepos
;
965 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
966 dwarf_info_section
= sectp
;
968 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
970 dwarf_abbrev_offset
= sectp
->filepos
;
971 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
972 dwarf_abbrev_section
= sectp
;
974 else if (STREQ (sectp
->name
, LINE_SECTION
))
976 dwarf_line_offset
= sectp
->filepos
;
977 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
978 dwarf_line_section
= sectp
;
980 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
982 dwarf_pubnames_offset
= sectp
->filepos
;
983 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
984 dwarf_pubnames_section
= sectp
;
986 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
988 dwarf_aranges_offset
= sectp
->filepos
;
989 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
990 dwarf_aranges_section
= sectp
;
992 else if (STREQ (sectp
->name
, LOC_SECTION
))
994 dwarf_loc_offset
= sectp
->filepos
;
995 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
996 dwarf_loc_section
= sectp
;
998 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
1000 dwarf_macinfo_offset
= sectp
->filepos
;
1001 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1002 dwarf_macinfo_section
= sectp
;
1004 else if (STREQ (sectp
->name
, STR_SECTION
))
1006 dwarf_str_offset
= sectp
->filepos
;
1007 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1008 dwarf_str_section
= sectp
;
1010 else if (STREQ (sectp
->name
, FRAME_SECTION
))
1012 dwarf_frame_offset
= sectp
->filepos
;
1013 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1014 dwarf_frame_section
= sectp
;
1016 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
1018 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1019 if (aflag
& SEC_HAS_CONTENTS
)
1021 dwarf_eh_frame_offset
= sectp
->filepos
;
1022 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1023 dwarf_eh_frame_section
= sectp
;
1026 else if (STREQ (sectp
->name
, RANGES_SECTION
))
1028 dwarf_ranges_offset
= sectp
->filepos
;
1029 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1030 dwarf_ranges_section
= sectp
;
1034 /* Build a partial symbol table. */
1037 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1040 /* We definitely need the .debug_info and .debug_abbrev sections */
1042 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1045 dwarf_info_section
);
1046 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1047 dwarf_abbrev_offset
,
1049 dwarf_abbrev_section
);
1051 if (dwarf_line_offset
)
1052 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1055 dwarf_line_section
);
1057 dwarf_line_buffer
= NULL
;
1059 if (dwarf_str_offset
)
1060 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1065 dwarf_str_buffer
= NULL
;
1067 if (dwarf_macinfo_offset
)
1068 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1069 dwarf_macinfo_offset
,
1071 dwarf_macinfo_section
);
1073 dwarf_macinfo_buffer
= NULL
;
1075 if (dwarf_ranges_offset
)
1076 dwarf_ranges_buffer
= dwarf2_read_section (objfile
,
1077 dwarf_ranges_offset
,
1079 dwarf_ranges_section
);
1081 dwarf_ranges_buffer
= NULL
;
1083 if (dwarf_loc_offset
)
1084 dwarf_loc_buffer
= dwarf2_read_section (objfile
,
1089 dwarf_loc_buffer
= NULL
;
1092 || (objfile
->global_psymbols
.size
== 0
1093 && objfile
->static_psymbols
.size
== 0))
1095 init_psymbol_list (objfile
, 1024);
1099 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1101 /* Things are significantly easier if we have .debug_aranges and
1102 .debug_pubnames sections */
1104 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1108 /* only test this case for now */
1110 /* In this case we have to work a bit harder */
1111 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1116 /* Build the partial symbol table from the information in the
1117 .debug_pubnames and .debug_aranges sections. */
1120 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1122 bfd
*abfd
= objfile
->obfd
;
1123 char *aranges_buffer
, *pubnames_buffer
;
1124 char *aranges_ptr
, *pubnames_ptr
;
1125 unsigned int entry_length
, version
, info_offset
, info_size
;
1127 pubnames_buffer
= dwarf2_read_section (objfile
,
1128 dwarf_pubnames_offset
,
1129 dwarf_pubnames_size
,
1130 dwarf_pubnames_section
);
1131 pubnames_ptr
= pubnames_buffer
;
1132 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1134 struct comp_unit_head cu_header
;
1137 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1139 pubnames_ptr
+= bytes_read
;
1140 version
= read_1_byte (abfd
, pubnames_ptr
);
1142 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1144 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1148 aranges_buffer
= dwarf2_read_section (objfile
,
1149 dwarf_aranges_offset
,
1151 dwarf_aranges_section
);
1156 /* Read in the comp unit header information from the debug_info at
1160 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1161 char *info_ptr
, bfd
*abfd
)
1165 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1167 info_ptr
+= bytes_read
;
1168 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1170 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1172 info_ptr
+= bytes_read
;
1173 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1175 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1176 if (signed_addr
< 0)
1177 internal_error (__FILE__
, __LINE__
,
1178 "read_comp_unit_head: dwarf from non elf file");
1179 cu_header
->signed_addr_p
= signed_addr
;
1183 /* Build the partial symbol table by doing a quick pass through the
1184 .debug_info and .debug_abbrev sections. */
1187 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1189 /* Instead of reading this into a big buffer, we should probably use
1190 mmap() on architectures that support it. (FIXME) */
1191 bfd
*abfd
= objfile
->obfd
;
1192 char *info_ptr
, *abbrev_ptr
;
1193 char *beg_of_comp_unit
;
1194 struct partial_die_info comp_unit_die
;
1195 struct partial_symtab
*pst
;
1196 struct cleanup
*back_to
;
1197 CORE_ADDR lowpc
, highpc
;
1199 info_ptr
= dwarf_info_buffer
;
1200 abbrev_ptr
= dwarf_abbrev_buffer
;
1202 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1203 the partial symbol scan, like attribute values.
1205 We could reduce our peak memory consumption during partial symbol
1206 table construction by freeing stuff from this obstack more often
1207 --- say, after processing each compilation unit, or each die ---
1208 but it turns out that this saves almost nothing. For an
1209 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1210 on dwarf2_tmp_obstack. Some investigation showed:
1212 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1213 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1214 all fixed-length values not requiring dynamic allocation.
1216 2) 30% of the attributes used the form DW_FORM_string. For
1217 DW_FORM_string, read_attribute simply hands back a pointer to
1218 the null-terminated string in dwarf_info_buffer, so no dynamic
1219 allocation is needed there either.
1221 3) The remaining 1% of the attributes all used DW_FORM_block1.
1222 75% of those were DW_AT_frame_base location lists for
1223 functions; the rest were DW_AT_location attributes, probably
1224 for the global variables.
1226 Anyway, what this all means is that the memory the dwarf2
1227 reader uses as temporary space reading partial symbols is about
1228 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1230 obstack_init (&dwarf2_tmp_obstack
);
1231 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1233 /* Since the objects we're extracting from dwarf_info_buffer vary in
1234 length, only the individual functions to extract them (like
1235 read_comp_unit_head and read_partial_die) can really know whether
1236 the buffer is large enough to hold another complete object.
1238 At the moment, they don't actually check that. If
1239 dwarf_info_buffer holds just one extra byte after the last
1240 compilation unit's dies, then read_comp_unit_head will happily
1241 read off the end of the buffer. read_partial_die is similarly
1242 casual. Those functions should be fixed.
1244 For this loop condition, simply checking whether there's any data
1245 left at all should be sufficient. */
1246 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1248 struct comp_unit_head cu_header
;
1249 beg_of_comp_unit
= info_ptr
;
1250 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1252 if (cu_header
.version
!= 2)
1254 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
));
1257 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1259 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1260 (long) cu_header
.abbrev_offset
,
1261 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1262 bfd_get_filename (abfd
));
1265 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1266 > dwarf_info_buffer
+ dwarf_info_size
)
1268 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1269 (long) cu_header
.length
,
1270 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1271 bfd_get_filename (abfd
));
1274 /* Complete the cu_header */
1275 cu_header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1276 cu_header
.first_die_ptr
= info_ptr
;
1277 cu_header
.cu_head_ptr
= beg_of_comp_unit
;
1279 /* Read the abbrevs for this compilation unit into a table */
1280 dwarf2_read_abbrevs (abfd
, &cu_header
);
1281 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1283 /* Read the compilation unit die */
1284 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1287 /* Set the language we're debugging */
1288 set_cu_language (comp_unit_die
.language
);
1290 /* Allocate a new partial symbol table structure */
1291 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1292 comp_unit_die
.name
? comp_unit_die
.name
: "",
1293 comp_unit_die
.lowpc
,
1294 objfile
->global_psymbols
.next
,
1295 objfile
->static_psymbols
.next
);
1297 pst
->read_symtab_private
= (char *)
1298 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1299 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1300 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1301 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1302 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1303 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1304 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1305 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1306 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1307 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1308 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1309 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1310 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1311 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1312 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1313 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1314 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1316 /* Store the function that reads in the rest of the symbol table */
1317 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1319 /* Check if comp unit has_children.
1320 If so, read the rest of the partial symbols from this comp unit.
1321 If not, there's no more debug_info for this comp unit. */
1322 if (comp_unit_die
.has_children
)
1324 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1327 /* If the compilation unit didn't have an explicit address range,
1328 then use the information extracted from its child dies. */
1329 if (! comp_unit_die
.has_pc_info
)
1331 comp_unit_die
.lowpc
= lowpc
;
1332 comp_unit_die
.highpc
= highpc
;
1335 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1336 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1338 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1339 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1340 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1341 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1342 sort_pst_symbols (pst
);
1344 /* If there is already a psymtab or symtab for a file of this
1345 name, remove it. (If there is a symtab, more drastic things
1346 also happen.) This happens in VxWorks. */
1347 free_named_symtabs (pst
->filename
);
1349 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1350 + cu_header
.initial_length_size
;
1352 do_cleanups (back_to
);
1355 /* Read in all interesting dies to the end of the compilation unit. */
1358 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1359 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1360 const struct comp_unit_head
*cu_header
)
1362 bfd
*abfd
= objfile
->obfd
;
1363 struct partial_die_info pdi
;
1365 /* This function is called after we've read in the comp_unit_die in
1366 order to read its children. We start the nesting level at 1 since
1367 we have pushed 1 level down in order to read the comp unit's children.
1368 The comp unit itself is at level 0, so we stop reading when we pop
1369 back to that level. */
1371 int nesting_level
= 1;
1373 /* We only want to read in symbols corresponding to variables or
1374 other similar objects that are global or static. Normally, these
1375 are all children of the DW_TAG_compile_unit die, so are all at
1376 level 1. But C++ namespaces give ries to DW_TAG_namespace dies
1377 whose children are global objects. So we keep track of what
1378 level we currently think of as referring to file scope; this
1379 should always equal 1 plus the number of namespaces that we are
1380 currently nested within. */
1382 int file_scope_level
= 1;
1384 *lowpc
= ((CORE_ADDR
) -1);
1385 *highpc
= ((CORE_ADDR
) 0);
1387 while (nesting_level
)
1389 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1391 /* Anonymous namespaces have no name but are interesting. */
1393 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
)
1397 case DW_TAG_subprogram
:
1398 if (pdi
.has_pc_info
)
1400 if (pdi
.lowpc
< *lowpc
)
1404 if (pdi
.highpc
> *highpc
)
1406 *highpc
= pdi
.highpc
;
1408 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1409 && !pdi
.is_declaration
)
1411 add_partial_symbol (&pdi
, objfile
, cu_header
);
1415 case DW_TAG_variable
:
1416 case DW_TAG_typedef
:
1417 case DW_TAG_class_type
:
1418 case DW_TAG_structure_type
:
1419 case DW_TAG_union_type
:
1420 case DW_TAG_enumeration_type
:
1421 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1422 && !pdi
.is_declaration
)
1424 add_partial_symbol (&pdi
, objfile
, cu_header
);
1427 case DW_TAG_enumerator
:
1428 /* File scope enumerators are added to the partial
1429 symbol table. They're children of the enumeration
1430 type die, so they occur at a level one higher than we
1431 normally look for. */
1432 if (nesting_level
== file_scope_level
+ 1)
1433 add_partial_symbol (&pdi
, objfile
, cu_header
);
1435 case DW_TAG_base_type
:
1436 /* File scope base type definitions are added to the partial
1438 if (nesting_level
== file_scope_level
)
1439 add_partial_symbol (&pdi
, objfile
, cu_header
);
1441 case DW_TAG_namespace
:
1442 /* FIXME: carlton/2002-10-16: we're not yet doing
1443 anything useful with this, but for now make sure that
1444 these tags at least don't cause us to miss any
1445 important symbols. */
1446 if (pdi
.has_children
)
1453 /* If the die has a sibling, skip to the sibling. Do not skip
1454 enumeration types, we want to record their enumerators. Do
1455 not skip namespaces, we want to record symbols inside
1458 && pdi
.tag
!= DW_TAG_enumeration_type
1459 && pdi
.tag
!= DW_TAG_namespace
)
1461 info_ptr
= pdi
.sibling
;
1463 else if (pdi
.has_children
)
1465 /* Die has children, but either the optional DW_AT_sibling
1466 attribute is missing or we want to look at them. */
1473 /* If this is the end of a DW_TAG_namespace entry, then
1474 decrease the file_scope_level, too. */
1475 if (nesting_level
< file_scope_level
)
1478 gdb_assert (nesting_level
== file_scope_level
);
1483 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1484 from `maint check'. */
1485 if (*lowpc
== ((CORE_ADDR
) -1))
1491 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1492 const struct comp_unit_head
*cu_header
)
1498 case DW_TAG_subprogram
:
1499 if (pdi
->is_external
)
1501 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1502 mst_text, objfile); */
1503 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1504 VAR_DOMAIN
, LOC_BLOCK
,
1505 &objfile
->global_psymbols
,
1506 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1510 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1511 mst_file_text, objfile); */
1512 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1513 VAR_DOMAIN
, LOC_BLOCK
,
1514 &objfile
->static_psymbols
,
1515 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1518 case DW_TAG_variable
:
1519 if (pdi
->is_external
)
1522 Don't enter into the minimal symbol tables as there is
1523 a minimal symbol table entry from the ELF symbols already.
1524 Enter into partial symbol table if it has a location
1525 descriptor or a type.
1526 If the location descriptor is missing, new_symbol will create
1527 a LOC_UNRESOLVED symbol, the address of the variable will then
1528 be determined from the minimal symbol table whenever the variable
1530 The address for the partial symbol table entry is not
1531 used by GDB, but it comes in handy for debugging partial symbol
1535 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1536 if (pdi
->locdesc
|| pdi
->has_type
)
1537 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1538 VAR_DOMAIN
, LOC_STATIC
,
1539 &objfile
->global_psymbols
,
1540 0, addr
+ baseaddr
, cu_language
, objfile
);
1544 /* Static Variable. Skip symbols without location descriptors. */
1545 if (pdi
->locdesc
== NULL
)
1547 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1548 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1549 mst_file_data, objfile); */
1550 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1551 VAR_DOMAIN
, LOC_STATIC
,
1552 &objfile
->static_psymbols
,
1553 0, addr
+ baseaddr
, cu_language
, objfile
);
1556 case DW_TAG_typedef
:
1557 case DW_TAG_base_type
:
1558 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1559 VAR_DOMAIN
, LOC_TYPEDEF
,
1560 &objfile
->static_psymbols
,
1561 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1563 case DW_TAG_class_type
:
1564 case DW_TAG_structure_type
:
1565 case DW_TAG_union_type
:
1566 case DW_TAG_enumeration_type
:
1567 /* Skip aggregate types without children, these are external
1569 if (pdi
->has_children
== 0)
1571 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1572 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1573 &objfile
->static_psymbols
,
1574 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1576 if (cu_language
== language_cplus
)
1578 /* For C++, these implicitly act as typedefs as well. */
1579 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1580 VAR_DOMAIN
, LOC_TYPEDEF
,
1581 &objfile
->static_psymbols
,
1582 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1585 case DW_TAG_enumerator
:
1586 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1587 VAR_DOMAIN
, LOC_CONST
,
1588 &objfile
->static_psymbols
,
1589 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1596 /* Expand this partial symbol table into a full symbol table. */
1599 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1601 /* FIXME: This is barely more than a stub. */
1606 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1612 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1613 gdb_flush (gdb_stdout
);
1616 psymtab_to_symtab_1 (pst
);
1618 /* Finish up the debug error message. */
1620 printf_filtered ("done.\n");
1626 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1628 struct objfile
*objfile
= pst
->objfile
;
1629 bfd
*abfd
= objfile
->obfd
;
1630 struct comp_unit_head cu_header
;
1631 struct die_info
*dies
;
1632 unsigned long offset
;
1633 CORE_ADDR lowpc
, highpc
;
1634 struct die_info
*child_die
;
1636 struct symtab
*symtab
;
1637 struct cleanup
*back_to
;
1638 struct attribute
*attr
;
1640 /* Set local variables from the partial symbol table info. */
1641 offset
= DWARF_INFO_OFFSET (pst
);
1642 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1643 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1644 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1645 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1646 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1647 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1648 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1649 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1650 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1651 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1652 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1653 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1654 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1655 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1656 cu_header_offset
= offset
;
1657 info_ptr
= dwarf_info_buffer
+ offset
;
1659 obstack_init (&dwarf2_tmp_obstack
);
1660 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1663 make_cleanup (really_free_pendings
, NULL
);
1665 /* read in the comp_unit header */
1666 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1668 /* Read the abbrevs for this compilation unit */
1669 dwarf2_read_abbrevs (abfd
, &cu_header
);
1670 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1672 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1674 make_cleanup_free_die_list (dies
);
1676 /* Find the base address of the compilation unit for range lists and
1677 location lists. It will normally be specified by DW_AT_low_pc.
1678 In DWARF-3 draft 4, the base address could be overridden by
1679 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1680 compilation units with discontinuous ranges. */
1682 cu_header
.base_known
= 0;
1683 cu_header
.base_address
= 0;
1685 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1688 cu_header
.base_address
= DW_ADDR (attr
);
1689 cu_header
.base_known
= 1;
1693 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1696 cu_header
.base_address
= DW_ADDR (attr
);
1697 cu_header
.base_known
= 1;
1701 /* Do line number decoding in read_file_scope () */
1702 process_die (dies
, objfile
, &cu_header
);
1704 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
, &cu_header
))
1706 /* Some compilers don't define a DW_AT_high_pc attribute for
1707 the compilation unit. If the DW_AT_high_pc is missing,
1708 synthesize it, by scanning the DIE's below the compilation unit. */
1710 if (dies
->has_children
)
1712 child_die
= dies
->next
;
1713 while (child_die
&& child_die
->tag
)
1715 if (child_die
->tag
== DW_TAG_subprogram
)
1717 CORE_ADDR low
, high
;
1719 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1720 objfile
, &cu_header
))
1722 highpc
= max (highpc
, high
);
1725 child_die
= sibling_die (child_die
);
1729 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1731 /* Set symtab language to language from DW_AT_language.
1732 If the compilation is from a C file generated by language preprocessors,
1733 do not set the language if it was already deduced by start_subfile. */
1735 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1737 symtab
->language
= cu_language
;
1739 pst
->symtab
= symtab
;
1742 do_cleanups (back_to
);
1745 /* Process a die and its children. */
1748 process_die (struct die_info
*die
, struct objfile
*objfile
,
1749 const struct comp_unit_head
*cu_header
)
1753 case DW_TAG_padding
:
1755 case DW_TAG_compile_unit
:
1756 read_file_scope (die
, objfile
, cu_header
);
1758 case DW_TAG_subprogram
:
1759 read_subroutine_type (die
, objfile
, cu_header
);
1760 read_func_scope (die
, objfile
, cu_header
);
1762 case DW_TAG_inlined_subroutine
:
1763 /* FIXME: These are ignored for now.
1764 They could be used to set breakpoints on all inlined instances
1765 of a function and make GDB `next' properly over inlined functions. */
1767 case DW_TAG_lexical_block
:
1768 case DW_TAG_try_block
:
1769 case DW_TAG_catch_block
:
1770 read_lexical_block_scope (die
, objfile
, cu_header
);
1772 case DW_TAG_class_type
:
1773 case DW_TAG_structure_type
:
1774 case DW_TAG_union_type
:
1775 read_structure_scope (die
, objfile
, cu_header
);
1777 case DW_TAG_enumeration_type
:
1778 read_enumeration (die
, objfile
, cu_header
);
1780 case DW_TAG_subroutine_type
:
1781 read_subroutine_type (die
, objfile
, cu_header
);
1783 case DW_TAG_array_type
:
1784 read_array_type (die
, objfile
, cu_header
);
1786 case DW_TAG_pointer_type
:
1787 read_tag_pointer_type (die
, objfile
, cu_header
);
1789 case DW_TAG_ptr_to_member_type
:
1790 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1792 case DW_TAG_reference_type
:
1793 read_tag_reference_type (die
, objfile
, cu_header
);
1795 case DW_TAG_string_type
:
1796 read_tag_string_type (die
, objfile
);
1798 case DW_TAG_base_type
:
1799 read_base_type (die
, objfile
);
1800 if (dwarf_attr (die
, DW_AT_name
))
1802 /* Add a typedef symbol for the base type definition. */
1803 new_symbol (die
, die
->type
, objfile
, cu_header
);
1806 case DW_TAG_common_block
:
1807 read_common_block (die
, objfile
, cu_header
);
1809 case DW_TAG_common_inclusion
:
1811 case DW_TAG_namespace
:
1812 if (!processing_has_namespace_info
)
1814 processing_has_namespace_info
= 1;
1815 processing_current_namespace
= "";
1817 read_namespace (die
, objfile
, cu_header
);
1819 case DW_TAG_imported_declaration
:
1820 case DW_TAG_imported_module
:
1821 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1822 information contained in these. DW_TAG_imported_declaration
1823 dies shouldn't have children; DW_TAG_imported_module dies
1824 shouldn't in the C++ case, but conceivably could in the
1825 Fortran case, so we'll have to replace this gdb_assert if
1826 Fortran compilers start generating that info. */
1827 if (!processing_has_namespace_info
)
1829 processing_has_namespace_info
= 1;
1830 processing_current_namespace
= "";
1832 gdb_assert (!die
->has_children
);
1835 new_symbol (die
, NULL
, objfile
, cu_header
);
1841 initialize_cu_func_list (void)
1843 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1847 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1848 const struct comp_unit_head
*cu_header
)
1850 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1851 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1852 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1853 struct attribute
*attr
;
1854 char *name
= "<unknown>";
1855 char *comp_dir
= NULL
;
1856 struct die_info
*child_die
;
1857 bfd
*abfd
= objfile
->obfd
;
1858 struct line_header
*line_header
= 0;
1860 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
1862 if (die
->has_children
)
1864 child_die
= die
->next
;
1865 while (child_die
&& child_die
->tag
)
1867 if (child_die
->tag
== DW_TAG_subprogram
)
1869 CORE_ADDR low
, high
;
1871 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1872 objfile
, cu_header
))
1874 lowpc
= min (lowpc
, low
);
1875 highpc
= max (highpc
, high
);
1878 child_die
= sibling_die (child_die
);
1883 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1884 from finish_block. */
1885 if (lowpc
== ((CORE_ADDR
) -1))
1890 attr
= dwarf_attr (die
, DW_AT_name
);
1893 name
= DW_STRING (attr
);
1895 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1898 comp_dir
= DW_STRING (attr
);
1901 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1902 directory, get rid of it. */
1903 char *cp
= strchr (comp_dir
, ':');
1905 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1910 if (objfile
->ei
.entry_point
>= lowpc
&&
1911 objfile
->ei
.entry_point
< highpc
)
1913 objfile
->ei
.entry_file_lowpc
= lowpc
;
1914 objfile
->ei
.entry_file_highpc
= highpc
;
1917 attr
= dwarf_attr (die
, DW_AT_language
);
1920 set_cu_language (DW_UNSND (attr
));
1923 /* We assume that we're processing GCC output. */
1924 processing_gcc_compilation
= 2;
1926 /* FIXME:Do something here. */
1927 if (dip
->at_producer
!= NULL
)
1929 handle_producer (dip
->at_producer
);
1933 /* The compilation unit may be in a different language or objfile,
1934 zero out all remembered fundamental types. */
1935 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1937 start_symtab (name
, comp_dir
, lowpc
);
1938 record_debugformat ("DWARF 2");
1940 initialize_cu_func_list ();
1942 /* Process all dies in compilation unit. */
1943 if (die
->has_children
)
1945 child_die
= die
->next
;
1946 while (child_die
&& child_die
->tag
)
1948 process_die (child_die
, objfile
, cu_header
);
1949 child_die
= sibling_die (child_die
);
1953 /* Decode line number information if present. */
1954 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1957 unsigned int line_offset
= DW_UNSND (attr
);
1958 line_header
= dwarf_decode_line_header (line_offset
,
1962 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1963 (void *) line_header
);
1964 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1968 /* Decode macro information, if present. Dwarf 2 macro information
1969 refers to information in the line number info statement program
1970 header, so we can only read it if we've read the header
1972 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1973 if (attr
&& line_header
)
1975 unsigned int macro_offset
= DW_UNSND (attr
);
1976 dwarf_decode_macros (line_header
, macro_offset
,
1977 comp_dir
, abfd
, cu_header
, objfile
);
1979 do_cleanups (back_to
);
1983 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1985 struct function_range
*thisfn
;
1987 thisfn
= (struct function_range
*)
1988 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1989 thisfn
->name
= name
;
1990 thisfn
->lowpc
= lowpc
;
1991 thisfn
->highpc
= highpc
;
1992 thisfn
->seen_line
= 0;
1993 thisfn
->next
= NULL
;
1995 if (cu_last_fn
== NULL
)
1996 cu_first_fn
= thisfn
;
1998 cu_last_fn
->next
= thisfn
;
2000 cu_last_fn
= thisfn
;
2004 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
2005 const struct comp_unit_head
*cu_header
)
2007 register struct context_stack
*new;
2010 struct die_info
*child_die
;
2011 struct attribute
*attr
;
2014 name
= dwarf2_linkage_name (die
);
2016 /* Ignore functions with missing or empty names and functions with
2017 missing or invalid low and high pc attributes. */
2018 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2024 /* Record the function range for dwarf_decode_lines. */
2025 add_to_cu_func_list (name
, lowpc
, highpc
);
2027 if (objfile
->ei
.entry_point
>= lowpc
&&
2028 objfile
->ei
.entry_point
< highpc
)
2030 objfile
->ei
.entry_func_lowpc
= lowpc
;
2031 objfile
->ei
.entry_func_highpc
= highpc
;
2034 /* Decode DW_AT_frame_base location descriptor if present, keep result
2035 for DW_OP_fbreg operands in decode_locdesc. */
2036 frame_base_reg
= -1;
2037 frame_base_offset
= 0;
2038 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2043 /* Support the .debug_loc offsets */
2044 if (attr_form_is_block (attr
))
2046 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2048 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2050 dwarf2_complex_location_expr_complaint ();
2055 dwarf2_invalid_attrib_class_complaint ("DW_AT_frame_base", name
);
2060 dwarf2_unsupported_at_frame_base_complaint (name
);
2062 frame_base_reg
= addr
;
2065 frame_base_reg
= basereg
;
2066 frame_base_offset
= addr
;
2069 dwarf2_unsupported_at_frame_base_complaint (name
);
2072 new = push_context (0, lowpc
);
2073 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
2075 /* If there was a location expression for DW_AT_frame_base above,
2076 record it. We still need to decode it above because not all
2077 symbols use location expressions exclusively. */
2079 dwarf2_symbol_mark_computed (attr
, new->name
, cu_header
, objfile
);
2081 list_in_scope
= &local_symbols
;
2083 if (die
->has_children
)
2085 child_die
= die
->next
;
2086 while (child_die
&& child_die
->tag
)
2088 process_die (child_die
, objfile
, cu_header
);
2089 child_die
= sibling_die (child_die
);
2093 new = pop_context ();
2094 /* Make a block for the local symbols within. */
2095 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2096 lowpc
, highpc
, objfile
);
2098 /* In C++, we can have functions nested inside functions (e.g., when
2099 a function declares a class that has methods). This means that
2100 when we finish processing a function scope, we may need to go
2101 back to building a containing block's symbol lists. */
2102 local_symbols
= new->locals
;
2103 param_symbols
= new->params
;
2105 /* If we've finished processing a top-level function, subsequent
2106 symbols go in the file symbol list. */
2107 if (outermost_context_p ())
2108 list_in_scope
= &file_symbols
;
2111 /* Process all the DIES contained within a lexical block scope. Start
2112 a new scope, process the dies, and then close the scope. */
2115 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
2116 const struct comp_unit_head
*cu_header
)
2118 register struct context_stack
*new;
2119 CORE_ADDR lowpc
, highpc
;
2120 struct die_info
*child_die
;
2122 /* Ignore blocks with missing or invalid low and high pc attributes. */
2123 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2124 as multiple lexical blocks? Handling children in a sane way would
2125 be nasty. Might be easier to properly extend generic blocks to
2127 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2132 push_context (0, lowpc
);
2133 if (die
->has_children
)
2135 child_die
= die
->next
;
2136 while (child_die
&& child_die
->tag
)
2138 process_die (child_die
, objfile
, cu_header
);
2139 child_die
= sibling_die (child_die
);
2142 new = pop_context ();
2144 if (local_symbols
!= NULL
)
2146 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2149 local_symbols
= new->locals
;
2152 /* Get low and high pc attributes from a die. Return 1 if the attributes
2153 are present and valid, otherwise, return 0. Return -1 if the range is
2154 discontinuous, i.e. derived from DW_AT_ranges information. */
2156 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2157 CORE_ADDR
*highpc
, struct objfile
*objfile
,
2158 const struct comp_unit_head
*cu_header
)
2160 struct attribute
*attr
;
2161 bfd
*obfd
= objfile
->obfd
;
2166 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2169 high
= DW_ADDR (attr
);
2170 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2172 low
= DW_ADDR (attr
);
2174 /* Found high w/o low attribute. */
2177 /* Found consecutive range of addresses. */
2182 attr
= dwarf_attr (die
, DW_AT_ranges
);
2185 unsigned int addr_size
= cu_header
->addr_size
;
2186 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2187 /* Value of the DW_AT_ranges attribute is the offset in the
2188 .debug_renges section. */
2189 unsigned int offset
= DW_UNSND (attr
);
2190 /* Base address selection entry. */
2199 found_base
= cu_header
->base_known
;
2200 base
= cu_header
->base_address
;
2201 buffer
= dwarf_ranges_buffer
+ offset
;
2203 /* Read in the largest possible address. */
2204 marker
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2205 if ((marker
& mask
) == mask
)
2207 /* If we found the largest possible address, then
2208 read the base address. */
2209 base
= read_address (obfd
, buffer
+ addr_size
,
2211 buffer
+= 2 * addr_size
;
2212 offset
+= 2 * addr_size
;
2220 CORE_ADDR range_beginning
, range_end
;
2222 range_beginning
= read_address (obfd
, buffer
,
2224 buffer
+= addr_size
;
2225 range_end
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2226 buffer
+= addr_size
;
2227 offset
+= 2 * addr_size
;
2229 /* An end of list marker is a pair of zero addresses. */
2230 if (range_beginning
== 0 && range_end
== 0)
2231 /* Found the end of list entry. */
2234 /* Each base address selection entry is a pair of 2 values.
2235 The first is the largest possible address, the second is
2236 the base address. Check for a base address here. */
2237 if ((range_beginning
& mask
) == mask
)
2239 /* If we found the largest possible address, then
2240 read the base address. */
2241 base
= read_address (obfd
, buffer
+ addr_size
,
2249 /* We have no valid base address for the ranges
2251 complaint (&symfile_complaints
,
2252 "Invalid .debug_ranges data (no base address)");
2256 range_beginning
+= base
;
2259 /* FIXME: This is recording everything as a low-high
2260 segment of consecutive addresses. We should have a
2261 data structure for discontiguous block ranges
2265 low
= range_beginning
;
2271 if (range_beginning
< low
)
2272 low
= range_beginning
;
2273 if (range_end
> high
)
2279 /* If the first entry is an end-of-list marker, the range
2280 describes an empty scope, i.e. no instructions. */
2290 /* When using the GNU linker, .gnu.linkonce. sections are used to
2291 eliminate duplicate copies of functions and vtables and such.
2292 The linker will arbitrarily choose one and discard the others.
2293 The AT_*_pc values for such functions refer to local labels in
2294 these sections. If the section from that file was discarded, the
2295 labels are not in the output, so the relocs get a value of 0.
2296 If this is a discarded function, mark the pc bounds as invalid,
2297 so that GDB will ignore it. */
2298 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2306 /* Add an aggregate field to the field list. */
2309 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2310 struct objfile
*objfile
,
2311 const struct comp_unit_head
*cu_header
)
2313 struct nextfield
*new_field
;
2314 struct attribute
*attr
;
2316 char *fieldname
= "";
2318 /* Allocate a new field list entry and link it in. */
2319 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2320 make_cleanup (xfree
, new_field
);
2321 memset (new_field
, 0, sizeof (struct nextfield
));
2322 new_field
->next
= fip
->fields
;
2323 fip
->fields
= new_field
;
2326 /* Handle accessibility and virtuality of field.
2327 The default accessibility for members is public, the default
2328 accessibility for inheritance is private. */
2329 if (die
->tag
!= DW_TAG_inheritance
)
2330 new_field
->accessibility
= DW_ACCESS_public
;
2332 new_field
->accessibility
= DW_ACCESS_private
;
2333 new_field
->virtuality
= DW_VIRTUALITY_none
;
2335 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2337 new_field
->accessibility
= DW_UNSND (attr
);
2338 if (new_field
->accessibility
!= DW_ACCESS_public
)
2339 fip
->non_public_fields
= 1;
2340 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2342 new_field
->virtuality
= DW_UNSND (attr
);
2344 fp
= &new_field
->field
;
2346 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2348 /* Data member other than a C++ static data member. */
2350 /* Get type of field. */
2351 fp
->type
= die_type (die
, objfile
, cu_header
);
2353 FIELD_STATIC_KIND (*fp
) = 0;
2355 /* Get bit size of field (zero if none). */
2356 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2359 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2363 FIELD_BITSIZE (*fp
) = 0;
2366 /* Get bit offset of field. */
2367 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2370 FIELD_BITPOS (*fp
) =
2371 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2374 FIELD_BITPOS (*fp
) = 0;
2375 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2378 if (BITS_BIG_ENDIAN
)
2380 /* For big endian bits, the DW_AT_bit_offset gives the
2381 additional bit offset from the MSB of the containing
2382 anonymous object to the MSB of the field. We don't
2383 have to do anything special since we don't need to
2384 know the size of the anonymous object. */
2385 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2389 /* For little endian bits, compute the bit offset to the
2390 MSB of the anonymous object, subtract off the number of
2391 bits from the MSB of the field to the MSB of the
2392 object, and then subtract off the number of bits of
2393 the field itself. The result is the bit offset of
2394 the LSB of the field. */
2396 int bit_offset
= DW_UNSND (attr
);
2398 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2401 /* The size of the anonymous object containing
2402 the bit field is explicit, so use the
2403 indicated size (in bytes). */
2404 anonymous_size
= DW_UNSND (attr
);
2408 /* The size of the anonymous object containing
2409 the bit field must be inferred from the type
2410 attribute of the data member containing the
2412 anonymous_size
= TYPE_LENGTH (fp
->type
);
2414 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2415 - bit_offset
- FIELD_BITSIZE (*fp
);
2419 /* Get name of field. */
2420 attr
= dwarf_attr (die
, DW_AT_name
);
2421 if (attr
&& DW_STRING (attr
))
2422 fieldname
= DW_STRING (attr
);
2423 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2424 &objfile
->type_obstack
);
2426 /* Change accessibility for artificial fields (e.g. virtual table
2427 pointer or virtual base class pointer) to private. */
2428 if (dwarf_attr (die
, DW_AT_artificial
))
2430 new_field
->accessibility
= DW_ACCESS_private
;
2431 fip
->non_public_fields
= 1;
2434 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2436 /* C++ static member. */
2438 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2439 is a declaration, but all versions of G++ as of this writing
2440 (so through at least 3.2.1) incorrectly generate
2441 DW_TAG_variable tags. */
2445 /* Get name of field. */
2446 attr
= dwarf_attr (die
, DW_AT_name
);
2447 if (attr
&& DW_STRING (attr
))
2448 fieldname
= DW_STRING (attr
);
2452 /* Get physical name. */
2453 physname
= dwarf2_linkage_name (die
);
2455 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2456 &objfile
->type_obstack
));
2457 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2458 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2459 &objfile
->type_obstack
);
2461 else if (die
->tag
== DW_TAG_inheritance
)
2463 /* C++ base class field. */
2464 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2466 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2468 FIELD_BITSIZE (*fp
) = 0;
2469 FIELD_STATIC_KIND (*fp
) = 0;
2470 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2471 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2472 fip
->nbaseclasses
++;
2476 /* Create the vector of fields, and attach it to the type. */
2479 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2480 struct objfile
*objfile
)
2482 int nfields
= fip
->nfields
;
2484 /* Record the field count, allocate space for the array of fields,
2485 and create blank accessibility bitfields if necessary. */
2486 TYPE_NFIELDS (type
) = nfields
;
2487 TYPE_FIELDS (type
) = (struct field
*)
2488 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2489 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2491 if (fip
->non_public_fields
)
2493 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2495 TYPE_FIELD_PRIVATE_BITS (type
) =
2496 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2497 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2499 TYPE_FIELD_PROTECTED_BITS (type
) =
2500 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2501 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2503 TYPE_FIELD_IGNORE_BITS (type
) =
2504 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2505 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2508 /* If the type has baseclasses, allocate and clear a bit vector for
2509 TYPE_FIELD_VIRTUAL_BITS. */
2510 if (fip
->nbaseclasses
)
2512 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2515 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2516 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2517 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2518 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2519 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2522 /* Copy the saved-up fields into the field vector. Start from the head
2523 of the list, adding to the tail of the field array, so that they end
2524 up in the same order in the array in which they were added to the list. */
2525 while (nfields
-- > 0)
2527 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2528 switch (fip
->fields
->accessibility
)
2530 case DW_ACCESS_private
:
2531 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2534 case DW_ACCESS_protected
:
2535 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2538 case DW_ACCESS_public
:
2542 /* Unknown accessibility. Complain and treat it as public. */
2544 complaint (&symfile_complaints
, "unsupported accessibility %d",
2545 fip
->fields
->accessibility
);
2549 if (nfields
< fip
->nbaseclasses
)
2551 switch (fip
->fields
->virtuality
)
2553 case DW_VIRTUALITY_virtual
:
2554 case DW_VIRTUALITY_pure_virtual
:
2555 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2559 fip
->fields
= fip
->fields
->next
;
2563 /* Add a member function to the proper fieldlist. */
2566 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2567 struct type
*type
, struct objfile
*objfile
,
2568 const struct comp_unit_head
*cu_header
)
2570 struct attribute
*attr
;
2571 struct fnfieldlist
*flp
;
2573 struct fn_field
*fnp
;
2576 struct nextfnfield
*new_fnfield
;
2578 /* Get name of member function. */
2579 attr
= dwarf_attr (die
, DW_AT_name
);
2580 if (attr
&& DW_STRING (attr
))
2581 fieldname
= DW_STRING (attr
);
2585 /* Get the mangled name. */
2586 physname
= dwarf2_linkage_name (die
);
2588 /* Look up member function name in fieldlist. */
2589 for (i
= 0; i
< fip
->nfnfields
; i
++)
2591 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2595 /* Create new list element if necessary. */
2596 if (i
< fip
->nfnfields
)
2597 flp
= &fip
->fnfieldlists
[i
];
2600 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2602 fip
->fnfieldlists
= (struct fnfieldlist
*)
2603 xrealloc (fip
->fnfieldlists
,
2604 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2605 * sizeof (struct fnfieldlist
));
2606 if (fip
->nfnfields
== 0)
2607 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2609 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2610 flp
->name
= fieldname
;
2616 /* Create a new member function field and chain it to the field list
2618 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2619 make_cleanup (xfree
, new_fnfield
);
2620 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2621 new_fnfield
->next
= flp
->head
;
2622 flp
->head
= new_fnfield
;
2625 /* Fill in the member function field info. */
2626 fnp
= &new_fnfield
->fnfield
;
2627 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2628 &objfile
->type_obstack
);
2629 fnp
->type
= alloc_type (objfile
);
2630 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2632 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2633 int nparams
= TYPE_NFIELDS (die
->type
);
2635 /* TYPE is the domain of this method, and DIE->TYPE is the type
2636 of the method itself (TYPE_CODE_METHOD). */
2637 smash_to_method_type (fnp
->type
, type
,
2638 TYPE_TARGET_TYPE (die
->type
),
2639 TYPE_FIELDS (die
->type
),
2640 TYPE_NFIELDS (die
->type
),
2641 TYPE_VARARGS (die
->type
));
2643 /* Handle static member functions.
2644 Dwarf2 has no clean way to discern C++ static and non-static
2645 member functions. G++ helps GDB by marking the first
2646 parameter for non-static member functions (which is the
2647 this pointer) as artificial. We obtain this information
2648 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2649 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2650 fnp
->voffset
= VOFFSET_STATIC
;
2653 complaint (&symfile_complaints
, "member function type missing for '%s'",
2656 /* Get fcontext from DW_AT_containing_type if present. */
2657 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2658 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2660 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2661 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2663 /* Get accessibility. */
2664 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2667 switch (DW_UNSND (attr
))
2669 case DW_ACCESS_private
:
2670 fnp
->is_private
= 1;
2672 case DW_ACCESS_protected
:
2673 fnp
->is_protected
= 1;
2678 /* Check for artificial methods. */
2679 attr
= dwarf_attr (die
, DW_AT_artificial
);
2680 if (attr
&& DW_UNSND (attr
) != 0)
2681 fnp
->is_artificial
= 1;
2683 /* Get index in virtual function table if it is a virtual member function. */
2684 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2687 /* Support the .debug_loc offsets */
2688 if (attr_form_is_block (attr
))
2690 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2692 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2694 dwarf2_complex_location_expr_complaint ();
2698 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2704 /* Create the vector of member function fields, and attach it to the type. */
2707 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2708 struct objfile
*objfile
)
2710 struct fnfieldlist
*flp
;
2711 int total_length
= 0;
2714 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2715 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2716 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2718 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2720 struct nextfnfield
*nfp
= flp
->head
;
2721 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2724 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2725 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2726 fn_flp
->fn_fields
= (struct fn_field
*)
2727 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2728 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2729 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2731 total_length
+= flp
->length
;
2734 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2735 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2738 /* Called when we find the DIE that starts a structure or union scope
2739 (definition) to process all dies that define the members of the
2742 NOTE: we need to call struct_type regardless of whether or not the
2743 DIE has an at_name attribute, since it might be an anonymous
2744 structure or union. This gets the type entered into our set of
2747 However, if the structure is incomplete (an opaque struct/union)
2748 then suppress creating a symbol table entry for it since gdb only
2749 wants to find the one with the complete definition. Note that if
2750 it is complete, we just call new_symbol, which does it's own
2751 checking about whether the struct/union is anonymous or not (and
2752 suppresses creating a symbol table entry itself). */
2755 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2756 const struct comp_unit_head
*cu_header
)
2759 struct attribute
*attr
;
2761 type
= alloc_type (objfile
);
2763 INIT_CPLUS_SPECIFIC (type
);
2764 attr
= dwarf_attr (die
, DW_AT_name
);
2765 if (attr
&& DW_STRING (attr
))
2767 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2768 strlen (DW_STRING (attr
)),
2769 &objfile
->type_obstack
);
2772 if (die
->tag
== DW_TAG_structure_type
)
2774 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2776 else if (die
->tag
== DW_TAG_union_type
)
2778 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2782 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2784 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2787 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2790 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2794 TYPE_LENGTH (type
) = 0;
2797 /* We need to add the type field to the die immediately so we don't
2798 infinitely recurse when dealing with pointers to the structure
2799 type within the structure itself. */
2802 if (die
->has_children
&& ! die_is_declaration (die
))
2804 struct field_info fi
;
2805 struct die_info
*child_die
;
2806 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2808 memset (&fi
, 0, sizeof (struct field_info
));
2810 child_die
= die
->next
;
2812 while (child_die
&& child_die
->tag
)
2814 if (child_die
->tag
== DW_TAG_member
2815 || child_die
->tag
== DW_TAG_variable
)
2817 /* NOTE: carlton/2002-11-05: A C++ static data member
2818 should be a DW_TAG_member that is a declaration, but
2819 all versions of G++ as of this writing (so through at
2820 least 3.2.1) incorrectly generate DW_TAG_variable
2821 tags for them instead. */
2822 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2824 else if (child_die
->tag
== DW_TAG_subprogram
)
2826 /* C++ member function. */
2827 process_die (child_die
, objfile
, cu_header
);
2828 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2830 else if (child_die
->tag
== DW_TAG_inheritance
)
2832 /* C++ base class field. */
2833 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2837 process_die (child_die
, objfile
, cu_header
);
2839 child_die
= sibling_die (child_die
);
2842 /* Attach fields and member functions to the type. */
2844 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2847 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2849 /* Get the type which refers to the base class (possibly this
2850 class itself) which contains the vtable pointer for the current
2851 class from the DW_AT_containing_type attribute. */
2853 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2855 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2857 TYPE_VPTR_BASETYPE (type
) = t
;
2860 static const char vptr_name
[] =
2861 {'_', 'v', 'p', 't', 'r', '\0'};
2864 /* Our own class provides vtbl ptr. */
2865 for (i
= TYPE_NFIELDS (t
) - 1;
2866 i
>= TYPE_N_BASECLASSES (t
);
2869 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2871 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2872 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2874 TYPE_VPTR_FIELDNO (type
) = i
;
2879 /* Complain if virtual function table field not found. */
2880 if (i
< TYPE_N_BASECLASSES (t
))
2881 complaint (&symfile_complaints
,
2882 "virtual function table pointer not found when defining class '%s'",
2883 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2888 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2893 new_symbol (die
, type
, objfile
, cu_header
);
2895 do_cleanups (back_to
);
2899 /* No children, must be stub. */
2900 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2904 /* Given a pointer to a die which begins an enumeration, process all
2905 the dies that define the members of the enumeration.
2907 This will be much nicer in draft 6 of the DWARF spec when our
2908 members will be dies instead squished into the DW_AT_element_list
2911 NOTE: We reverse the order of the element list. */
2914 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2915 const struct comp_unit_head
*cu_header
)
2917 struct die_info
*child_die
;
2919 struct field
*fields
;
2920 struct attribute
*attr
;
2923 int unsigned_enum
= 1;
2925 type
= alloc_type (objfile
);
2927 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2928 attr
= dwarf_attr (die
, DW_AT_name
);
2929 if (attr
&& DW_STRING (attr
))
2931 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2932 strlen (DW_STRING (attr
)),
2933 &objfile
->type_obstack
);
2936 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2939 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2943 TYPE_LENGTH (type
) = 0;
2948 if (die
->has_children
)
2950 child_die
= die
->next
;
2951 while (child_die
&& child_die
->tag
)
2953 if (child_die
->tag
!= DW_TAG_enumerator
)
2955 process_die (child_die
, objfile
, cu_header
);
2959 attr
= dwarf_attr (child_die
, DW_AT_name
);
2962 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2963 if (SYMBOL_VALUE (sym
) < 0)
2966 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2968 fields
= (struct field
*)
2970 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2971 * sizeof (struct field
));
2974 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
2975 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2976 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2977 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2978 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
2984 child_die
= sibling_die (child_die
);
2989 TYPE_NFIELDS (type
) = num_fields
;
2990 TYPE_FIELDS (type
) = (struct field
*)
2991 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2992 memcpy (TYPE_FIELDS (type
), fields
,
2993 sizeof (struct field
) * num_fields
);
2997 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3000 new_symbol (die
, type
, objfile
, cu_header
);
3003 /* Extract all information from a DW_TAG_array_type DIE and put it in
3004 the DIE's type field. For now, this only handles one dimensional
3008 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
3009 const struct comp_unit_head
*cu_header
)
3011 struct die_info
*child_die
;
3012 struct type
*type
= NULL
;
3013 struct type
*element_type
, *range_type
, *index_type
;
3014 struct type
**range_types
= NULL
;
3015 struct attribute
*attr
;
3017 struct cleanup
*back_to
;
3019 /* Return if we've already decoded this type. */
3025 element_type
= die_type (die
, objfile
, cu_header
);
3027 /* Irix 6.2 native cc creates array types without children for
3028 arrays with unspecified length. */
3029 if (die
->has_children
== 0)
3031 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3032 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3033 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3037 back_to
= make_cleanup (null_cleanup
, NULL
);
3038 child_die
= die
->next
;
3039 while (child_die
&& child_die
->tag
)
3041 if (child_die
->tag
== DW_TAG_subrange_type
)
3043 unsigned int low
, high
;
3045 /* Default bounds to an array with unspecified length. */
3048 if (cu_language
== language_fortran
)
3050 /* FORTRAN implies a lower bound of 1, if not given. */
3054 index_type
= die_type (child_die
, objfile
, cu_header
);
3055 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3058 if (attr
->form
== DW_FORM_sdata
)
3060 low
= DW_SND (attr
);
3062 else if (attr
->form
== DW_FORM_udata
3063 || attr
->form
== DW_FORM_data1
3064 || attr
->form
== DW_FORM_data2
3065 || attr
->form
== DW_FORM_data4
3066 || attr
->form
== DW_FORM_data8
)
3068 low
= DW_UNSND (attr
);
3072 dwarf2_non_const_array_bound_ignored_complaint
3073 (dwarf_form_name (attr
->form
));
3075 die
->type
= lookup_pointer_type (element_type
);
3082 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3085 if (attr
->form
== DW_FORM_sdata
)
3087 high
= DW_SND (attr
);
3089 else if (attr
->form
== DW_FORM_udata
3090 || attr
->form
== DW_FORM_data1
3091 || attr
->form
== DW_FORM_data2
3092 || attr
->form
== DW_FORM_data4
3093 || attr
->form
== DW_FORM_data8
)
3095 high
= DW_UNSND (attr
);
3097 else if (attr
->form
== DW_FORM_block1
)
3099 /* GCC encodes arrays with unspecified or dynamic length
3100 with a DW_FORM_block1 attribute.
3101 FIXME: GDB does not yet know how to handle dynamic
3102 arrays properly, treat them as arrays with unspecified
3108 dwarf2_non_const_array_bound_ignored_complaint
3109 (dwarf_form_name (attr
->form
));
3111 die
->type
= lookup_pointer_type (element_type
);
3119 /* Create a range type and save it for array type creation. */
3120 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3122 range_types
= (struct type
**)
3123 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3124 * sizeof (struct type
*));
3126 make_cleanup (free_current_contents
, &range_types
);
3128 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3130 child_die
= sibling_die (child_die
);
3133 /* Dwarf2 dimensions are output from left to right, create the
3134 necessary array types in backwards order. */
3135 type
= element_type
;
3137 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3139 /* Understand Dwarf2 support for vector types (like they occur on
3140 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3141 array type. This is not part of the Dwarf2/3 standard yet, but a
3142 custom vendor extension. The main difference between a regular
3143 array and the vector variant is that vectors are passed by value
3145 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3147 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3149 do_cleanups (back_to
);
3151 /* Install the type in the die. */
3155 /* First cut: install each common block member as a global variable. */
3158 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
3159 const struct comp_unit_head
*cu_header
)
3161 struct die_info
*child_die
;
3162 struct attribute
*attr
;
3164 CORE_ADDR base
= (CORE_ADDR
) 0;
3166 attr
= dwarf_attr (die
, DW_AT_location
);
3169 /* Support the .debug_loc offsets */
3170 if (attr_form_is_block (attr
))
3172 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3174 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3176 dwarf2_complex_location_expr_complaint ();
3180 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3181 "common block member");
3184 if (die
->has_children
)
3186 child_die
= die
->next
;
3187 while (child_die
&& child_die
->tag
)
3189 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
3190 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3193 SYMBOL_VALUE_ADDRESS (sym
) =
3194 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3195 add_symbol_to_list (sym
, &global_symbols
);
3197 child_die
= sibling_die (child_die
);
3202 /* Read a C++ namespace. */
3205 read_namespace (struct die_info
*die
, struct objfile
*objfile
,
3206 const struct comp_unit_head
*cu_header
)
3208 const char *previous_namespace
= processing_current_namespace
;
3209 const char *name
= NULL
;
3211 struct die_info
*current_die
;
3213 /* Loop through the extensions until we find a name. */
3215 for (current_die
= die
;
3216 current_die
!= NULL
;
3217 current_die
= dwarf2_extension (die
))
3219 name
= dwarf2_name (current_die
);
3224 /* Is it an anonymous namespace? */
3226 is_anonymous
= (name
== NULL
);
3228 name
= "(anonymous namespace)";
3230 /* Now build the name of the current namespace. */
3232 if (previous_namespace
[0] == '\0')
3234 processing_current_namespace
= name
;
3238 /* We need temp_name around because processing_current_namespace
3239 is a const char *. */
3240 char *temp_name
= alloca (strlen (previous_namespace
)
3241 + 2 + strlen(name
) + 1);
3242 strcpy (temp_name
, previous_namespace
);
3243 strcat (temp_name
, "::");
3244 strcat (temp_name
, name
);
3246 processing_current_namespace
= temp_name
;
3249 /* If it's an anonymous namespace that we're seeing for the first
3250 time, add a using directive. */
3252 if (is_anonymous
&& dwarf_attr (die
, DW_AT_extension
) == NULL
)
3253 cp_add_using_directive (processing_current_namespace
,
3254 strlen (previous_namespace
),
3255 strlen (processing_current_namespace
));
3257 if (die
->has_children
)
3259 struct die_info
*child_die
= die
->next
;
3261 while (child_die
&& child_die
->tag
)
3263 process_die (child_die
, objfile
, cu_header
);
3264 child_die
= sibling_die (child_die
);
3268 processing_current_namespace
= previous_namespace
;
3271 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3272 the user defined type vector. */
3275 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
3276 const struct comp_unit_head
*cu_header
)
3279 struct attribute
*attr_byte_size
;
3280 struct attribute
*attr_address_class
;
3281 int byte_size
, addr_class
;
3288 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
3290 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3292 byte_size
= DW_UNSND (attr_byte_size
);
3294 byte_size
= cu_header
->addr_size
;
3296 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3297 if (attr_address_class
)
3298 addr_class
= DW_UNSND (attr_address_class
);
3300 addr_class
= DW_ADDR_none
;
3302 /* If the pointer size or address class is different than the
3303 default, create a type variant marked as such and set the
3304 length accordingly. */
3305 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3307 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3311 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3312 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3313 type
= make_type_with_address_space (type
, type_flags
);
3315 else if (TYPE_LENGTH (type
) != byte_size
)
3317 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3320 /* Should we also complain about unhandled address classes? */
3324 TYPE_LENGTH (type
) = byte_size
;
3328 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3329 the user defined type vector. */
3332 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
3333 const struct comp_unit_head
*cu_header
)
3336 struct type
*to_type
;
3337 struct type
*domain
;
3344 type
= alloc_type (objfile
);
3345 to_type
= die_type (die
, objfile
, cu_header
);
3346 domain
= die_containing_type (die
, objfile
, cu_header
);
3347 smash_to_member_type (type
, domain
, to_type
);
3352 /* Extract all information from a DW_TAG_reference_type DIE and add to
3353 the user defined type vector. */
3356 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
3357 const struct comp_unit_head
*cu_header
)
3360 struct attribute
*attr
;
3367 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
3368 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3371 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3375 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3381 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
3382 const struct comp_unit_head
*cu_header
)
3384 struct type
*base_type
;
3391 base_type
= die_type (die
, objfile
, cu_header
);
3392 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3396 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
3397 const struct comp_unit_head
*cu_header
)
3399 struct type
*base_type
;
3406 base_type
= die_type (die
, objfile
, cu_header
);
3407 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3410 /* Extract all information from a DW_TAG_string_type DIE and add to
3411 the user defined type vector. It isn't really a user defined type,
3412 but it behaves like one, with other DIE's using an AT_user_def_type
3413 attribute to reference it. */
3416 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3418 struct type
*type
, *range_type
, *index_type
, *char_type
;
3419 struct attribute
*attr
;
3420 unsigned int length
;
3427 attr
= dwarf_attr (die
, DW_AT_string_length
);
3430 length
= DW_UNSND (attr
);
3434 /* check for the DW_AT_byte_size attribute */
3435 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3438 length
= DW_UNSND (attr
);
3445 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3446 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3447 if (cu_language
== language_fortran
)
3449 /* Need to create a unique string type for bounds
3451 type
= create_string_type (0, range_type
);
3455 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3456 type
= create_string_type (char_type
, range_type
);
3461 /* Handle DIES due to C code like:
3465 int (*funcp)(int a, long l);
3469 ('funcp' generates a DW_TAG_subroutine_type DIE)
3473 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3474 const struct comp_unit_head
*cu_header
)
3476 struct type
*type
; /* Type that this function returns */
3477 struct type
*ftype
; /* Function that returns above type */
3478 struct attribute
*attr
;
3480 /* Decode the type that this subroutine returns */
3485 type
= die_type (die
, objfile
, cu_header
);
3486 ftype
= lookup_function_type (type
);
3488 /* All functions in C++ have prototypes. */
3489 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3490 if ((attr
&& (DW_UNSND (attr
) != 0))
3491 || cu_language
== language_cplus
)
3492 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3494 if (die
->has_children
)
3496 struct die_info
*child_die
;
3500 /* Count the number of parameters.
3501 FIXME: GDB currently ignores vararg functions, but knows about
3502 vararg member functions. */
3503 child_die
= die
->next
;
3504 while (child_die
&& child_die
->tag
)
3506 if (child_die
->tag
== DW_TAG_formal_parameter
)
3508 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3509 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3510 child_die
= sibling_die (child_die
);
3513 /* Allocate storage for parameters and fill them in. */
3514 TYPE_NFIELDS (ftype
) = nparams
;
3515 TYPE_FIELDS (ftype
) = (struct field
*)
3516 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3518 child_die
= die
->next
;
3519 while (child_die
&& child_die
->tag
)
3521 if (child_die
->tag
== DW_TAG_formal_parameter
)
3523 /* Dwarf2 has no clean way to discern C++ static and non-static
3524 member functions. G++ helps GDB by marking the first
3525 parameter for non-static member functions (which is the
3526 this pointer) as artificial. We pass this information
3527 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3528 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3530 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3532 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3533 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3537 child_die
= sibling_die (child_die
);
3545 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3546 const struct comp_unit_head
*cu_header
)
3548 struct attribute
*attr
;
3553 attr
= dwarf_attr (die
, DW_AT_name
);
3554 if (attr
&& DW_STRING (attr
))
3556 name
= DW_STRING (attr
);
3558 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3559 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3563 /* Find a representation of a given base type and install
3564 it in the TYPE field of the die. */
3567 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3570 struct attribute
*attr
;
3571 int encoding
= 0, size
= 0;
3573 /* If we've already decoded this die, this is a no-op. */
3579 attr
= dwarf_attr (die
, DW_AT_encoding
);
3582 encoding
= DW_UNSND (attr
);
3584 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3587 size
= DW_UNSND (attr
);
3589 attr
= dwarf_attr (die
, DW_AT_name
);
3590 if (attr
&& DW_STRING (attr
))
3592 enum type_code code
= TYPE_CODE_INT
;
3597 case DW_ATE_address
:
3598 /* Turn DW_ATE_address into a void * pointer. */
3599 code
= TYPE_CODE_PTR
;
3600 type_flags
|= TYPE_FLAG_UNSIGNED
;
3602 case DW_ATE_boolean
:
3603 code
= TYPE_CODE_BOOL
;
3604 type_flags
|= TYPE_FLAG_UNSIGNED
;
3606 case DW_ATE_complex_float
:
3607 code
= TYPE_CODE_COMPLEX
;
3610 code
= TYPE_CODE_FLT
;
3613 case DW_ATE_signed_char
:
3615 case DW_ATE_unsigned
:
3616 case DW_ATE_unsigned_char
:
3617 type_flags
|= TYPE_FLAG_UNSIGNED
;
3620 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3621 dwarf_type_encoding_name (encoding
));
3624 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3625 if (encoding
== DW_ATE_address
)
3626 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3627 else if (encoding
== DW_ATE_complex_float
)
3630 TYPE_TARGET_TYPE (type
)
3631 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3632 else if (size
== 16)
3633 TYPE_TARGET_TYPE (type
)
3634 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3636 TYPE_TARGET_TYPE (type
)
3637 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3642 type
= dwarf_base_type (encoding
, size
, objfile
);
3647 /* Read a whole compilation unit into a linked list of dies. */
3649 static struct die_info
*
3650 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3651 const struct comp_unit_head
*cu_header
)
3653 struct die_info
*first_die
, *last_die
, *die
;
3657 /* Reset die reference table; we are
3658 building new ones now. */
3659 dwarf2_empty_hash_tables ();
3663 first_die
= last_die
= NULL
;
3666 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3667 if (die
->has_children
)
3678 /* Enter die in reference hash table */
3679 store_in_ref_table (die
->offset
, die
);
3683 first_die
= last_die
= die
;
3687 last_die
->next
= die
;
3691 while (nesting_level
> 0);
3695 /* Free a linked list of dies. */
3698 free_die_list (struct die_info
*dies
)
3700 struct die_info
*die
, *next
;
3713 do_free_die_list_cleanup (void *dies
)
3715 free_die_list (dies
);
3718 static struct cleanup
*
3719 make_cleanup_free_die_list (struct die_info
*dies
)
3721 return make_cleanup (do_free_die_list_cleanup
, dies
);
3725 /* Read the contents of the section at OFFSET and of size SIZE from the
3726 object file specified by OBJFILE into the psymbol_obstack and return it. */
3729 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3730 unsigned int size
, asection
*sectp
)
3732 bfd
*abfd
= objfile
->obfd
;
3738 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3740 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3744 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3745 (bfd_bread (buf
, size
, abfd
) != size
))
3748 error ("Dwarf Error: Can't read DWARF data from '%s'",
3749 bfd_get_filename (abfd
));
3754 /* In DWARF version 2, the description of the debugging information is
3755 stored in a separate .debug_abbrev section. Before we read any
3756 dies from a section we read in all abbreviations and install them
3760 dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
)
3763 struct abbrev_info
*cur_abbrev
;
3764 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3765 unsigned int abbrev_form
, hash_number
;
3767 /* Initialize dwarf2 abbrevs */
3768 memset (cu_header
->dwarf2_abbrevs
, 0,
3769 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3771 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3772 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3773 abbrev_ptr
+= bytes_read
;
3775 /* loop until we reach an abbrev number of 0 */
3776 while (abbrev_number
)
3778 cur_abbrev
= dwarf_alloc_abbrev ();
3780 /* read in abbrev header */
3781 cur_abbrev
->number
= abbrev_number
;
3782 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3783 abbrev_ptr
+= bytes_read
;
3784 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3787 /* now read in declarations */
3788 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3789 abbrev_ptr
+= bytes_read
;
3790 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3791 abbrev_ptr
+= bytes_read
;
3794 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3796 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3797 xrealloc (cur_abbrev
->attrs
,
3798 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3799 * sizeof (struct attr_abbrev
));
3801 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3802 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3803 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3804 abbrev_ptr
+= bytes_read
;
3805 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3806 abbrev_ptr
+= bytes_read
;
3809 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3810 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3811 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3813 /* Get next abbreviation.
3814 Under Irix6 the abbreviations for a compilation unit are not
3815 always properly terminated with an abbrev number of 0.
3816 Exit loop if we encounter an abbreviation which we have
3817 already read (which means we are about to read the abbreviations
3818 for the next compile unit) or if the end of the abbreviation
3819 table is reached. */
3820 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3821 >= dwarf_abbrev_size
)
3823 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3824 abbrev_ptr
+= bytes_read
;
3825 if (dwarf2_lookup_abbrev (abbrev_number
, cu_header
) != NULL
)
3830 /* Empty the abbrev table for a new compilation unit. */
3834 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3837 struct abbrev_info
*abbrev
, *next
;
3838 struct abbrev_info
**abbrevs
;
3840 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3842 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3845 abbrev
= abbrevs
[i
];
3848 next
= abbrev
->next
;
3849 xfree (abbrev
->attrs
);
3857 /* Lookup an abbrev_info structure in the abbrev hash table. */
3859 static struct abbrev_info
*
3860 dwarf2_lookup_abbrev (unsigned int number
, const struct comp_unit_head
*cu_header
)
3862 unsigned int hash_number
;
3863 struct abbrev_info
*abbrev
;
3865 hash_number
= number
% ABBREV_HASH_SIZE
;
3866 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3870 if (abbrev
->number
== number
)
3873 abbrev
= abbrev
->next
;
3878 /* Read a minimal amount of information into the minimal die structure. */
3881 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3882 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3884 unsigned int abbrev_number
, bytes_read
, i
;
3885 struct abbrev_info
*abbrev
;
3886 struct attribute attr
;
3887 struct attribute spec_attr
;
3888 int found_spec_attr
= 0;
3889 int has_low_pc_attr
= 0;
3890 int has_high_pc_attr
= 0;
3892 *part_die
= zeroed_partial_die
;
3893 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3894 info_ptr
+= bytes_read
;
3898 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3901 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
3902 bfd_get_filename (abfd
));
3904 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3905 part_die
->tag
= abbrev
->tag
;
3906 part_die
->has_children
= abbrev
->has_children
;
3907 part_die
->abbrev
= abbrev_number
;
3909 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3911 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3912 info_ptr
, cu_header
);
3914 /* Store the data if it is of an attribute we want to keep in a
3915 partial symbol table. */
3920 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3921 if (part_die
->name
== NULL
)
3922 part_die
->name
= DW_STRING (&attr
);
3924 case DW_AT_MIPS_linkage_name
:
3925 part_die
->name
= DW_STRING (&attr
);
3928 has_low_pc_attr
= 1;
3929 part_die
->lowpc
= DW_ADDR (&attr
);
3932 has_high_pc_attr
= 1;
3933 part_die
->highpc
= DW_ADDR (&attr
);
3935 case DW_AT_location
:
3936 /* Support the .debug_loc offsets */
3937 if (attr_form_is_block (&attr
))
3939 part_die
->locdesc
= DW_BLOCK (&attr
);
3941 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
3943 dwarf2_complex_location_expr_complaint ();
3947 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3948 "partial symbol information");
3951 case DW_AT_language
:
3952 part_die
->language
= DW_UNSND (&attr
);
3954 case DW_AT_external
:
3955 part_die
->is_external
= DW_UNSND (&attr
);
3957 case DW_AT_declaration
:
3958 part_die
->is_declaration
= DW_UNSND (&attr
);
3961 part_die
->has_type
= 1;
3963 case DW_AT_abstract_origin
:
3964 case DW_AT_specification
:
3965 found_spec_attr
= 1;
3969 /* Ignore absolute siblings, they might point outside of
3970 the current compile unit. */
3971 if (attr
.form
== DW_FORM_ref_addr
)
3972 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
3975 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3982 /* If we found a reference attribute and the die has no name, try
3983 to find a name in the referred to die. */
3985 if (found_spec_attr
&& part_die
->name
== NULL
)
3987 struct partial_die_info spec_die
;
3991 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3992 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3995 part_die
->name
= spec_die
.name
;
3997 /* Copy DW_AT_external attribute if it is set. */
3998 if (spec_die
.is_external
)
3999 part_die
->is_external
= spec_die
.is_external
;
4003 /* When using the GNU linker, .gnu.linkonce. sections are used to
4004 eliminate duplicate copies of functions and vtables and such.
4005 The linker will arbitrarily choose one and discard the others.
4006 The AT_*_pc values for such functions refer to local labels in
4007 these sections. If the section from that file was discarded, the
4008 labels are not in the output, so the relocs get a value of 0.
4009 If this is a discarded function, mark the pc bounds as invalid,
4010 so that GDB will ignore it. */
4011 if (has_low_pc_attr
&& has_high_pc_attr
4012 && part_die
->lowpc
< part_die
->highpc
4013 && (part_die
->lowpc
!= 0
4014 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4015 part_die
->has_pc_info
= 1;
4019 /* Read the die from the .debug_info section buffer. And set diep to
4020 point to a newly allocated die with its information. */
4023 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4024 const struct comp_unit_head
*cu_header
)
4026 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4027 struct abbrev_info
*abbrev
;
4028 struct die_info
*die
;
4030 offset
= info_ptr
- dwarf_info_buffer
;
4031 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4032 info_ptr
+= bytes_read
;
4035 die
= dwarf_alloc_die ();
4037 die
->abbrev
= abbrev_number
;
4043 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
4046 error ("Dwarf Error: could not find abbrev number %d [in module %s]", abbrev_number
,
4047 bfd_get_filename (abfd
));
4049 die
= dwarf_alloc_die ();
4050 die
->offset
= offset
;
4051 die
->tag
= abbrev
->tag
;
4052 die
->has_children
= abbrev
->has_children
;
4053 die
->abbrev
= abbrev_number
;
4056 die
->num_attrs
= abbrev
->num_attrs
;
4057 die
->attrs
= (struct attribute
*)
4058 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4060 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4062 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4063 abfd
, info_ptr
, cu_header
);
4070 /* Read an attribute value described by an attribute form. */
4073 read_attribute_value (struct attribute
*attr
, unsigned form
,
4074 bfd
*abfd
, char *info_ptr
,
4075 const struct comp_unit_head
*cu_header
)
4077 unsigned int bytes_read
;
4078 struct dwarf_block
*blk
;
4084 case DW_FORM_ref_addr
:
4085 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
4086 info_ptr
+= bytes_read
;
4088 case DW_FORM_block2
:
4089 blk
= dwarf_alloc_block ();
4090 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4092 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4093 info_ptr
+= blk
->size
;
4094 DW_BLOCK (attr
) = blk
;
4096 case DW_FORM_block4
:
4097 blk
= dwarf_alloc_block ();
4098 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4100 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4101 info_ptr
+= blk
->size
;
4102 DW_BLOCK (attr
) = blk
;
4105 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4109 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4113 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4116 case DW_FORM_string
:
4117 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4118 info_ptr
+= bytes_read
;
4121 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4123 info_ptr
+= bytes_read
;
4126 blk
= dwarf_alloc_block ();
4127 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4128 info_ptr
+= bytes_read
;
4129 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4130 info_ptr
+= blk
->size
;
4131 DW_BLOCK (attr
) = blk
;
4133 case DW_FORM_block1
:
4134 blk
= dwarf_alloc_block ();
4135 blk
->size
= read_1_byte (abfd
, info_ptr
);
4137 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4138 info_ptr
+= blk
->size
;
4139 DW_BLOCK (attr
) = blk
;
4142 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4146 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4150 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4151 info_ptr
+= bytes_read
;
4154 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4155 info_ptr
+= bytes_read
;
4158 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4162 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4166 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4170 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4173 case DW_FORM_ref_udata
:
4174 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4175 info_ptr
+= bytes_read
;
4177 case DW_FORM_indirect
:
4178 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4179 info_ptr
+= bytes_read
;
4180 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
4183 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4184 dwarf_form_name (form
),
4185 bfd_get_filename (abfd
));
4190 /* Read an attribute described by an abbreviated attribute. */
4193 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4194 bfd
*abfd
, char *info_ptr
,
4195 const struct comp_unit_head
*cu_header
)
4197 attr
->name
= abbrev
->name
;
4198 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
4201 /* read dwarf information from a buffer */
4204 read_1_byte (bfd
*abfd
, char *buf
)
4206 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4210 read_1_signed_byte (bfd
*abfd
, char *buf
)
4212 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4216 read_2_bytes (bfd
*abfd
, char *buf
)
4218 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4222 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4224 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4228 read_4_bytes (bfd
*abfd
, char *buf
)
4230 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4234 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4236 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4239 static unsigned long
4240 read_8_bytes (bfd
*abfd
, char *buf
)
4242 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4246 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4249 CORE_ADDR retval
= 0;
4251 if (cu_header
->signed_addr_p
)
4253 switch (cu_header
->addr_size
)
4256 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4259 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4262 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4265 internal_error (__FILE__
, __LINE__
,
4266 "read_address: bad switch, signed [in module %s]",
4267 bfd_get_filename (abfd
));
4272 switch (cu_header
->addr_size
)
4275 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4278 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4281 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4284 internal_error (__FILE__
, __LINE__
,
4285 "read_address: bad switch, unsigned [in module %s]",
4286 bfd_get_filename (abfd
));
4290 *bytes_read
= cu_header
->addr_size
;
4294 /* Read the initial length from a section. The (draft) DWARF 3
4295 specification allows the initial length to take up either 4 bytes
4296 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4297 bytes describe the length and all offsets will be 8 bytes in length
4300 An older, non-standard 64-bit format is also handled by this
4301 function. The older format in question stores the initial length
4302 as an 8-byte quantity without an escape value. Lengths greater
4303 than 2^32 aren't very common which means that the initial 4 bytes
4304 is almost always zero. Since a length value of zero doesn't make
4305 sense for the 32-bit format, this initial zero can be considered to
4306 be an escape value which indicates the presence of the older 64-bit
4307 format. As written, the code can't detect (old format) lengths
4308 greater than 4GB. If it becomes necessary to handle lengths somewhat
4309 larger than 4GB, we could allow other small values (such as the
4310 non-sensical values of 1, 2, and 3) to also be used as escape values
4311 indicating the presence of the old format.
4313 The value returned via bytes_read should be used to increment
4314 the relevant pointer after calling read_initial_length().
4316 As a side effect, this function sets the fields initial_length_size
4317 and offset_size in cu_header to the values appropriate for the
4318 length field. (The format of the initial length field determines
4319 the width of file offsets to be fetched later with fetch_offset().)
4321 [ Note: read_initial_length() and read_offset() are based on the
4322 document entitled "DWARF Debugging Information Format", revision
4323 3, draft 8, dated November 19, 2001. This document was obtained
4326 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4328 This document is only a draft and is subject to change. (So beware.)
4330 Details regarding the older, non-standard 64-bit format were
4331 determined empirically by examining 64-bit ELF files produced
4332 by the SGI toolchain on an IRIX 6.5 machine.
4334 - Kevin, July 16, 2002
4338 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4343 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4345 if (retval
== 0xffffffff)
4347 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4349 if (cu_header
!= NULL
)
4351 cu_header
->initial_length_size
= 12;
4352 cu_header
->offset_size
= 8;
4355 else if (retval
== 0)
4357 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4359 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4361 if (cu_header
!= NULL
)
4363 cu_header
->initial_length_size
= 8;
4364 cu_header
->offset_size
= 8;
4370 if (cu_header
!= NULL
)
4372 cu_header
->initial_length_size
= 4;
4373 cu_header
->offset_size
= 4;
4380 /* Read an offset from the data stream. The size of the offset is
4381 given by cu_header->offset_size. */
4384 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4389 switch (cu_header
->offset_size
)
4392 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4396 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4400 internal_error (__FILE__
, __LINE__
,
4401 "read_offset: bad switch [in module %s]",
4402 bfd_get_filename (abfd
));
4409 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4411 /* If the size of a host char is 8 bits, we can return a pointer
4412 to the buffer, otherwise we have to copy the data to a buffer
4413 allocated on the temporary obstack. */
4414 gdb_assert (HOST_CHAR_BIT
== 8);
4419 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4421 /* If the size of a host char is 8 bits, we can return a pointer
4422 to the string, otherwise we have to copy the string to a buffer
4423 allocated on the temporary obstack. */
4424 gdb_assert (HOST_CHAR_BIT
== 8);
4427 *bytes_read_ptr
= 1;
4430 *bytes_read_ptr
= strlen (buf
) + 1;
4435 read_indirect_string (bfd
*abfd
, char *buf
,
4436 const struct comp_unit_head
*cu_header
,
4437 unsigned int *bytes_read_ptr
)
4439 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4440 (int *) bytes_read_ptr
);
4442 if (dwarf_str_buffer
== NULL
)
4444 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4445 bfd_get_filename (abfd
));
4448 if (str_offset
>= dwarf_str_size
)
4450 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4451 bfd_get_filename (abfd
));
4454 gdb_assert (HOST_CHAR_BIT
== 8);
4455 if (dwarf_str_buffer
[str_offset
] == '\0')
4457 return dwarf_str_buffer
+ str_offset
;
4460 static unsigned long
4461 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4463 unsigned long result
;
4464 unsigned int num_read
;
4474 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4477 result
|= ((unsigned long)(byte
& 127) << shift
);
4478 if ((byte
& 128) == 0)
4484 *bytes_read_ptr
= num_read
;
4489 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4492 int i
, shift
, size
, num_read
;
4502 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4505 result
|= ((long)(byte
& 127) << shift
);
4507 if ((byte
& 128) == 0)
4512 if ((shift
< size
) && (byte
& 0x40))
4514 result
|= -(1 << shift
);
4516 *bytes_read_ptr
= num_read
;
4521 set_cu_language (unsigned int lang
)
4527 cu_language
= language_c
;
4529 case DW_LANG_C_plus_plus
:
4530 cu_language
= language_cplus
;
4532 case DW_LANG_Fortran77
:
4533 case DW_LANG_Fortran90
:
4534 case DW_LANG_Fortran95
:
4535 cu_language
= language_fortran
;
4537 case DW_LANG_Mips_Assembler
:
4538 cu_language
= language_asm
;
4541 cu_language
= language_java
;
4545 case DW_LANG_Cobol74
:
4546 case DW_LANG_Cobol85
:
4547 case DW_LANG_Pascal83
:
4548 case DW_LANG_Modula2
:
4550 cu_language
= language_minimal
;
4553 cu_language_defn
= language_def (cu_language
);
4556 /* Return the named attribute or NULL if not there. */
4558 static struct attribute
*
4559 dwarf_attr (struct die_info
*die
, unsigned int name
)
4562 struct attribute
*spec
= NULL
;
4564 for (i
= 0; i
< die
->num_attrs
; ++i
)
4566 if (die
->attrs
[i
].name
== name
)
4568 return &die
->attrs
[i
];
4570 if (die
->attrs
[i
].name
== DW_AT_specification
4571 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4572 spec
= &die
->attrs
[i
];
4576 struct die_info
*ref_die
=
4577 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4580 return dwarf_attr (ref_die
, name
);
4587 die_is_declaration (struct die_info
*die
)
4589 return (dwarf_attr (die
, DW_AT_declaration
)
4590 && ! dwarf_attr (die
, DW_AT_specification
));
4594 /* Free the line_header structure *LH, and any arrays and strings it
4597 free_line_header (struct line_header
*lh
)
4599 if (lh
->standard_opcode_lengths
)
4600 xfree (lh
->standard_opcode_lengths
);
4602 /* Remember that all the lh->file_names[i].name pointers are
4603 pointers into debug_line_buffer, and don't need to be freed. */
4605 xfree (lh
->file_names
);
4607 /* Similarly for the include directory names. */
4608 if (lh
->include_dirs
)
4609 xfree (lh
->include_dirs
);
4615 /* Add an entry to LH's include directory table. */
4617 add_include_dir (struct line_header
*lh
, char *include_dir
)
4619 /* Grow the array if necessary. */
4620 if (lh
->include_dirs_size
== 0)
4622 lh
->include_dirs_size
= 1; /* for testing */
4623 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4624 * sizeof (*lh
->include_dirs
));
4626 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4628 lh
->include_dirs_size
*= 2;
4629 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4630 (lh
->include_dirs_size
4631 * sizeof (*lh
->include_dirs
)));
4634 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4638 /* Add an entry to LH's file name table. */
4640 add_file_name (struct line_header
*lh
,
4642 unsigned int dir_index
,
4643 unsigned int mod_time
,
4644 unsigned int length
)
4646 struct file_entry
*fe
;
4648 /* Grow the array if necessary. */
4649 if (lh
->file_names_size
== 0)
4651 lh
->file_names_size
= 1; /* for testing */
4652 lh
->file_names
= xmalloc (lh
->file_names_size
4653 * sizeof (*lh
->file_names
));
4655 else if (lh
->num_file_names
>= lh
->file_names_size
)
4657 lh
->file_names_size
*= 2;
4658 lh
->file_names
= xrealloc (lh
->file_names
,
4659 (lh
->file_names_size
4660 * sizeof (*lh
->file_names
)));
4663 fe
= &lh
->file_names
[lh
->num_file_names
++];
4665 fe
->dir_index
= dir_index
;
4666 fe
->mod_time
= mod_time
;
4667 fe
->length
= length
;
4671 /* Read the statement program header starting at OFFSET in
4672 dwarf_line_buffer, according to the endianness of ABFD. Return a
4673 pointer to a struct line_header, allocated using xmalloc.
4675 NOTE: the strings in the include directory and file name tables of
4676 the returned object point into debug_line_buffer, and must not be
4678 static struct line_header
*
4679 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4680 const struct comp_unit_head
*cu_header
)
4682 struct cleanup
*back_to
;
4683 struct line_header
*lh
;
4687 char *cur_dir
, *cur_file
;
4689 if (dwarf_line_buffer
== NULL
)
4691 complaint (&symfile_complaints
, "missing .debug_line section");
4695 /* Make sure that at least there's room for the total_length field. That
4696 could be 12 bytes long, but we're just going to fudge that. */
4697 if (offset
+ 4 >= dwarf_line_size
)
4699 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4703 lh
= xmalloc (sizeof (*lh
));
4704 memset (lh
, 0, sizeof (*lh
));
4705 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4708 line_ptr
= dwarf_line_buffer
+ offset
;
4710 /* read in the header */
4711 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4712 line_ptr
+= bytes_read
;
4713 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4715 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4718 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4719 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4721 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4722 line_ptr
+= bytes_read
;
4723 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4725 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4727 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4729 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4731 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4733 lh
->standard_opcode_lengths
4734 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4736 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4737 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4739 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4743 /* Read directory table */
4744 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4746 line_ptr
+= bytes_read
;
4747 add_include_dir (lh
, cur_dir
);
4749 line_ptr
+= bytes_read
;
4751 /* Read file name table */
4752 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4754 unsigned int dir_index
, mod_time
, length
;
4756 line_ptr
+= bytes_read
;
4757 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4758 line_ptr
+= bytes_read
;
4759 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4760 line_ptr
+= bytes_read
;
4761 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4762 line_ptr
+= bytes_read
;
4764 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4766 line_ptr
+= bytes_read
;
4767 lh
->statement_program_start
= line_ptr
;
4769 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4770 complaint (&symfile_complaints
,
4771 "line number info header doesn't fit in `.debug_line' section");
4773 discard_cleanups (back_to
);
4777 /* This function exists to work around a bug in certain compilers
4778 (particularly GCC 2.95), in which the first line number marker of a
4779 function does not show up until after the prologue, right before
4780 the second line number marker. This function shifts ADDRESS down
4781 to the beginning of the function if necessary, and is called on
4782 addresses passed to record_line. */
4785 check_cu_functions (CORE_ADDR address
)
4787 struct function_range
*fn
;
4789 /* Find the function_range containing address. */
4794 cu_cached_fn
= cu_first_fn
;
4798 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4804 while (fn
&& fn
!= cu_cached_fn
)
4805 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4815 if (address
!= fn
->lowpc
)
4816 complaint (&symfile_complaints
,
4817 "misplaced first line number at 0x%lx for '%s'",
4818 (unsigned long) address
, fn
->name
);
4823 /* Decode the line number information for the compilation unit whose
4824 line number info is at OFFSET in the .debug_line section.
4825 The compilation directory of the file is passed in COMP_DIR. */
4828 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4829 const struct comp_unit_head
*cu_header
)
4833 unsigned int i
, bytes_read
;
4835 unsigned char op_code
, extended_op
, adj_opcode
;
4837 line_ptr
= lh
->statement_program_start
;
4838 line_end
= lh
->statement_program_end
;
4840 /* Read the statement sequences until there's nothing left. */
4841 while (line_ptr
< line_end
)
4843 /* state machine registers */
4844 CORE_ADDR address
= 0;
4845 unsigned int file
= 1;
4846 unsigned int line
= 1;
4847 unsigned int column
= 0;
4848 int is_stmt
= lh
->default_is_stmt
;
4849 int basic_block
= 0;
4850 int end_sequence
= 0;
4852 /* Start a subfile for the current file of the state machine. */
4853 if (lh
->num_file_names
>= file
)
4855 /* lh->include_dirs and lh->file_names are 0-based, but the
4856 directory and file name numbers in the statement program
4858 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4861 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4864 dwarf2_start_subfile (fe
->name
, dir
);
4867 /* Decode the table. */
4868 while (!end_sequence
)
4870 op_code
= read_1_byte (abfd
, line_ptr
);
4873 if (op_code
>= lh
->opcode_base
)
4874 { /* Special operand. */
4875 adj_opcode
= op_code
- lh
->opcode_base
;
4876 address
+= (adj_opcode
/ lh
->line_range
)
4877 * lh
->minimum_instruction_length
;
4878 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4879 /* append row to matrix using current values */
4880 record_line (current_subfile
, line
,
4881 check_cu_functions (address
));
4884 else switch (op_code
)
4886 case DW_LNS_extended_op
:
4887 line_ptr
+= 1; /* ignore length */
4888 extended_op
= read_1_byte (abfd
, line_ptr
);
4890 switch (extended_op
)
4892 case DW_LNE_end_sequence
:
4894 record_line (current_subfile
, 0, address
);
4896 case DW_LNE_set_address
:
4897 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4898 line_ptr
+= bytes_read
;
4899 address
+= baseaddr
;
4901 case DW_LNE_define_file
:
4904 unsigned int dir_index
, mod_time
, length
;
4906 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4907 line_ptr
+= bytes_read
;
4909 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4910 line_ptr
+= bytes_read
;
4912 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4913 line_ptr
+= bytes_read
;
4915 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4916 line_ptr
+= bytes_read
;
4917 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4921 complaint (&symfile_complaints
,
4922 "mangled .debug_line section");
4927 record_line (current_subfile
, line
,
4928 check_cu_functions (address
));
4931 case DW_LNS_advance_pc
:
4932 address
+= lh
->minimum_instruction_length
4933 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4934 line_ptr
+= bytes_read
;
4936 case DW_LNS_advance_line
:
4937 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4938 line_ptr
+= bytes_read
;
4940 case DW_LNS_set_file
:
4942 /* lh->include_dirs and lh->file_names are 0-based,
4943 but the directory and file name numbers in the
4944 statement program are 1-based. */
4945 struct file_entry
*fe
;
4947 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4948 line_ptr
+= bytes_read
;
4949 fe
= &lh
->file_names
[file
- 1];
4951 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4954 dwarf2_start_subfile (fe
->name
, dir
);
4957 case DW_LNS_set_column
:
4958 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4959 line_ptr
+= bytes_read
;
4961 case DW_LNS_negate_stmt
:
4962 is_stmt
= (!is_stmt
);
4964 case DW_LNS_set_basic_block
:
4967 /* Add to the address register of the state machine the
4968 address increment value corresponding to special opcode
4969 255. Ie, this value is scaled by the minimum instruction
4970 length since special opcode 255 would have scaled the
4972 case DW_LNS_const_add_pc
:
4973 address
+= (lh
->minimum_instruction_length
4974 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4976 case DW_LNS_fixed_advance_pc
:
4977 address
+= read_2_bytes (abfd
, line_ptr
);
4981 { /* Unknown standard opcode, ignore it. */
4983 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4985 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4986 line_ptr
+= bytes_read
;
4994 /* Start a subfile for DWARF. FILENAME is the name of the file and
4995 DIRNAME the name of the source directory which contains FILENAME
4996 or NULL if not known.
4997 This routine tries to keep line numbers from identical absolute and
4998 relative file names in a common subfile.
5000 Using the `list' example from the GDB testsuite, which resides in
5001 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5002 of /srcdir/list0.c yields the following debugging information for list0.c:
5004 DW_AT_name: /srcdir/list0.c
5005 DW_AT_comp_dir: /compdir
5006 files.files[0].name: list0.h
5007 files.files[0].dir: /srcdir
5008 files.files[1].name: list0.c
5009 files.files[1].dir: /srcdir
5011 The line number information for list0.c has to end up in a single
5012 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5015 dwarf2_start_subfile (char *filename
, char *dirname
)
5017 /* If the filename isn't absolute, try to match an existing subfile
5018 with the full pathname. */
5020 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5022 struct subfile
*subfile
;
5023 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5025 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5027 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5029 current_subfile
= subfile
;
5036 start_subfile (filename
, dirname
);
5040 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5041 struct objfile
*objfile
,
5042 const struct comp_unit_head
*cu_header
)
5044 /* NOTE drow/2003-01-30: There used to be a comment and some special
5045 code here to turn a symbol with DW_AT_external and a
5046 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5047 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5048 with some versions of binutils) where shared libraries could have
5049 relocations against symbols in their debug information - the
5050 minimal symbol would have the right address, but the debug info
5051 would not. It's no longer necessary, because we will explicitly
5052 apply relocations when we read in the debug information now. */
5054 /* A DW_AT_location attribute with no contents indicates that a
5055 variable has been optimized away. */
5056 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5058 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5062 /* Handle one degenerate form of location expression specially, to
5063 preserve GDB's previous behavior when section offsets are
5064 specified. If this is just a DW_OP_addr then mark this symbol
5067 if (attr_form_is_block (attr
)
5068 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5069 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5073 SYMBOL_VALUE_ADDRESS (sym
) =
5074 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu_header
,
5076 fixup_symbol_section (sym
, objfile
);
5077 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5078 SYMBOL_SECTION (sym
));
5079 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5083 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5084 expression evaluator, and use LOC_COMPUTED only when necessary
5085 (i.e. when the value of a register or memory location is
5086 referenced, or a thread-local block, etc.). Then again, it might
5087 not be worthwhile. I'm assuming that it isn't unless performance
5088 or memory numbers show me otherwise. */
5090 dwarf2_symbol_mark_computed (attr
, sym
, cu_header
, objfile
);
5091 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5094 /* Given a pointer to a DWARF information entry, figure out if we need
5095 to make a symbol table entry for it, and if so, create a new entry
5096 and return a pointer to it.
5097 If TYPE is NULL, determine symbol type from the die, otherwise
5098 used the passed type. */
5100 static struct symbol
*
5101 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
5102 const struct comp_unit_head
*cu_header
)
5104 struct symbol
*sym
= NULL
;
5106 struct attribute
*attr
= NULL
;
5107 struct attribute
*attr2
= NULL
;
5110 name
= dwarf2_linkage_name (die
);
5113 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5114 sizeof (struct symbol
));
5115 OBJSTAT (objfile
, n_syms
++);
5116 memset (sym
, 0, sizeof (struct symbol
));
5118 /* Cache this symbol's name and the name's demangled form (if any). */
5119 SYMBOL_LANGUAGE (sym
) = cu_language
;
5120 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5122 /* Default assumptions.
5123 Use the passed type or decode it from the die. */
5124 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5125 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5127 SYMBOL_TYPE (sym
) = type
;
5129 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
5130 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5133 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5138 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5141 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5143 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5145 case DW_TAG_subprogram
:
5146 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5148 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5149 attr2
= dwarf_attr (die
, DW_AT_external
);
5150 if (attr2
&& (DW_UNSND (attr2
) != 0))
5152 add_symbol_to_list (sym
, &global_symbols
);
5156 add_symbol_to_list (sym
, list_in_scope
);
5159 case DW_TAG_variable
:
5160 /* Compilation with minimal debug info may result in variables
5161 with missing type entries. Change the misleading `void' type
5162 to something sensible. */
5163 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5164 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5165 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5166 "<variable, no debug info>",
5168 attr
= dwarf_attr (die
, DW_AT_const_value
);
5171 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5172 attr2
= dwarf_attr (die
, DW_AT_external
);
5173 if (attr2
&& (DW_UNSND (attr2
) != 0))
5174 add_symbol_to_list (sym
, &global_symbols
);
5176 add_symbol_to_list (sym
, list_in_scope
);
5179 attr
= dwarf_attr (die
, DW_AT_location
);
5182 var_decode_location (attr
, sym
, objfile
, cu_header
);
5183 attr2
= dwarf_attr (die
, DW_AT_external
);
5184 if (attr2
&& (DW_UNSND (attr2
) != 0))
5185 add_symbol_to_list (sym
, &global_symbols
);
5187 add_symbol_to_list (sym
, list_in_scope
);
5191 /* We do not know the address of this symbol.
5192 If it is an external symbol and we have type information
5193 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5194 The address of the variable will then be determined from
5195 the minimal symbol table whenever the variable is
5197 attr2
= dwarf_attr (die
, DW_AT_external
);
5198 if (attr2
&& (DW_UNSND (attr2
) != 0)
5199 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5201 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5202 add_symbol_to_list (sym
, &global_symbols
);
5206 case DW_TAG_formal_parameter
:
5207 attr
= dwarf_attr (die
, DW_AT_location
);
5210 var_decode_location (attr
, sym
, objfile
, cu_header
);
5211 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5212 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5213 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5215 attr
= dwarf_attr (die
, DW_AT_const_value
);
5218 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5220 add_symbol_to_list (sym
, list_in_scope
);
5222 case DW_TAG_unspecified_parameters
:
5223 /* From varargs functions; gdb doesn't seem to have any
5224 interest in this information, so just ignore it for now.
5227 case DW_TAG_class_type
:
5228 case DW_TAG_structure_type
:
5229 case DW_TAG_union_type
:
5230 case DW_TAG_enumeration_type
:
5231 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5232 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5233 add_symbol_to_list (sym
, list_in_scope
);
5235 /* The semantics of C++ state that "struct foo { ... }" also
5236 defines a typedef for "foo". Synthesize a typedef symbol so
5237 that "ptype foo" works as expected. */
5238 if (cu_language
== language_cplus
)
5240 struct symbol
*typedef_sym
= (struct symbol
*)
5241 obstack_alloc (&objfile
->symbol_obstack
,
5242 sizeof (struct symbol
));
5243 *typedef_sym
= *sym
;
5244 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5245 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5246 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5247 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5248 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5249 &objfile
->type_obstack
);
5250 add_symbol_to_list (typedef_sym
, list_in_scope
);
5253 case DW_TAG_typedef
:
5254 case DW_TAG_base_type
:
5255 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5256 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5257 add_symbol_to_list (sym
, list_in_scope
);
5259 case DW_TAG_enumerator
:
5260 attr
= dwarf_attr (die
, DW_AT_const_value
);
5263 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5265 add_symbol_to_list (sym
, list_in_scope
);
5268 /* Not a tag we recognize. Hopefully we aren't processing
5269 trash data, but since we must specifically ignore things
5270 we don't recognize, there is nothing else we should do at
5272 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5273 dwarf_tag_name (die
->tag
));
5280 /* Copy constant value from an attribute to a symbol. */
5283 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5284 struct objfile
*objfile
,
5285 const struct comp_unit_head
*cu_header
)
5287 struct dwarf_block
*blk
;
5292 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5293 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5294 cu_header
->addr_size
,
5295 TYPE_LENGTH (SYMBOL_TYPE
5297 SYMBOL_VALUE_BYTES (sym
) = (char *)
5298 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5299 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5300 it's body - store_unsigned_integer. */
5301 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5303 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5305 case DW_FORM_block1
:
5306 case DW_FORM_block2
:
5307 case DW_FORM_block4
:
5309 blk
= DW_BLOCK (attr
);
5310 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5311 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5313 TYPE_LENGTH (SYMBOL_TYPE
5315 SYMBOL_VALUE_BYTES (sym
) = (char *)
5316 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5317 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5318 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5321 /* The DW_AT_const_value attributes are supposed to carry the
5322 symbol's value "represented as it would be on the target
5323 architecture." By the time we get here, it's already been
5324 converted to host endianness, so we just need to sign- or
5325 zero-extend it as appropriate. */
5327 dwarf2_const_value_data (attr
, sym
, 8);
5330 dwarf2_const_value_data (attr
, sym
, 16);
5333 dwarf2_const_value_data (attr
, sym
, 32);
5336 dwarf2_const_value_data (attr
, sym
, 64);
5340 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5341 SYMBOL_CLASS (sym
) = LOC_CONST
;
5345 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5346 SYMBOL_CLASS (sym
) = LOC_CONST
;
5350 complaint (&symfile_complaints
,
5351 "unsupported const value attribute form: '%s'",
5352 dwarf_form_name (attr
->form
));
5353 SYMBOL_VALUE (sym
) = 0;
5354 SYMBOL_CLASS (sym
) = LOC_CONST
;
5360 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5361 or zero-extend it as appropriate for the symbol's type. */
5363 dwarf2_const_value_data (struct attribute
*attr
,
5367 LONGEST l
= DW_UNSND (attr
);
5369 if (bits
< sizeof (l
) * 8)
5371 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5372 l
&= ((LONGEST
) 1 << bits
) - 1;
5374 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5377 SYMBOL_VALUE (sym
) = l
;
5378 SYMBOL_CLASS (sym
) = LOC_CONST
;
5382 /* Return the type of the die in question using its DW_AT_type attribute. */
5384 static struct type
*
5385 die_type (struct die_info
*die
, struct objfile
*objfile
,
5386 const struct comp_unit_head
*cu_header
)
5389 struct attribute
*type_attr
;
5390 struct die_info
*type_die
;
5393 type_attr
= dwarf_attr (die
, DW_AT_type
);
5396 /* A missing DW_AT_type represents a void type. */
5397 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5401 ref
= dwarf2_get_ref_die_offset (type_attr
);
5402 type_die
= follow_die_ref (ref
);
5405 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5406 ref
, objfile
->name
);
5410 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5413 dump_die (type_die
);
5414 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5420 /* Return the containing type of the die in question using its
5421 DW_AT_containing_type attribute. */
5423 static struct type
*
5424 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5425 const struct comp_unit_head
*cu_header
)
5427 struct type
*type
= NULL
;
5428 struct attribute
*type_attr
;
5429 struct die_info
*type_die
= NULL
;
5432 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5435 ref
= dwarf2_get_ref_die_offset (type_attr
);
5436 type_die
= follow_die_ref (ref
);
5439 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5443 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5448 dump_die (type_die
);
5449 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5456 static struct type
*
5457 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5459 struct die_info
*die
;
5462 die
= follow_die_ref (offset
);
5465 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5468 type
= tag_type_to_type (die
, objfile
);
5473 static struct type
*
5474 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5475 const struct comp_unit_head
*cu_header
)
5483 read_type_die (die
, objfile
, cu_header
);
5487 error ("Dwarf Error: Cannot find type of die [in module %s]",
5495 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5496 const struct comp_unit_head
*cu_header
)
5500 case DW_TAG_class_type
:
5501 case DW_TAG_structure_type
:
5502 case DW_TAG_union_type
:
5503 read_structure_scope (die
, objfile
, cu_header
);
5505 case DW_TAG_enumeration_type
:
5506 read_enumeration (die
, objfile
, cu_header
);
5508 case DW_TAG_subprogram
:
5509 case DW_TAG_subroutine_type
:
5510 read_subroutine_type (die
, objfile
, cu_header
);
5512 case DW_TAG_array_type
:
5513 read_array_type (die
, objfile
, cu_header
);
5515 case DW_TAG_pointer_type
:
5516 read_tag_pointer_type (die
, objfile
, cu_header
);
5518 case DW_TAG_ptr_to_member_type
:
5519 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5521 case DW_TAG_reference_type
:
5522 read_tag_reference_type (die
, objfile
, cu_header
);
5524 case DW_TAG_const_type
:
5525 read_tag_const_type (die
, objfile
, cu_header
);
5527 case DW_TAG_volatile_type
:
5528 read_tag_volatile_type (die
, objfile
, cu_header
);
5530 case DW_TAG_string_type
:
5531 read_tag_string_type (die
, objfile
);
5533 case DW_TAG_typedef
:
5534 read_typedef (die
, objfile
, cu_header
);
5536 case DW_TAG_base_type
:
5537 read_base_type (die
, objfile
);
5540 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5541 dwarf_tag_name (die
->tag
));
5546 static struct type
*
5547 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5549 /* FIXME - this should not produce a new (struct type *)
5550 every time. It should cache base types. */
5554 case DW_ATE_address
:
5555 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5557 case DW_ATE_boolean
:
5558 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5560 case DW_ATE_complex_float
:
5563 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5567 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5573 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5577 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5584 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5587 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5591 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5595 case DW_ATE_signed_char
:
5596 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5598 case DW_ATE_unsigned
:
5602 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5605 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5609 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5613 case DW_ATE_unsigned_char
:
5614 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5617 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5624 copy_die (struct die_info
*old_die
)
5626 struct die_info
*new_die
;
5629 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5630 memset (new_die
, 0, sizeof (struct die_info
));
5632 new_die
->tag
= old_die
->tag
;
5633 new_die
->has_children
= old_die
->has_children
;
5634 new_die
->abbrev
= old_die
->abbrev
;
5635 new_die
->offset
= old_die
->offset
;
5636 new_die
->type
= NULL
;
5638 num_attrs
= old_die
->num_attrs
;
5639 new_die
->num_attrs
= num_attrs
;
5640 new_die
->attrs
= (struct attribute
*)
5641 xmalloc (num_attrs
* sizeof (struct attribute
));
5643 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5645 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5646 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5647 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5650 new_die
->next
= NULL
;
5655 /* Return sibling of die, NULL if no sibling. */
5657 static struct die_info
*
5658 sibling_die (struct die_info
*die
)
5660 int nesting_level
= 0;
5662 if (!die
->has_children
)
5664 if (die
->next
&& (die
->next
->tag
== 0))
5677 if (die
->has_children
)
5687 while (nesting_level
);
5688 if (die
&& (die
->tag
== 0))
5699 /* Get linkage name of a die, return NULL if not found. */
5702 dwarf2_linkage_name (struct die_info
*die
)
5704 struct attribute
*attr
;
5706 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5707 if (attr
&& DW_STRING (attr
))
5708 return DW_STRING (attr
);
5709 attr
= dwarf_attr (die
, DW_AT_name
);
5710 if (attr
&& DW_STRING (attr
))
5711 return DW_STRING (attr
);
5715 /* Get name of a die, return NULL if not found. */
5718 dwarf2_name (struct die_info
*die
)
5720 struct attribute
*attr
;
5722 attr
= dwarf_attr (die
, DW_AT_name
);
5723 if (attr
&& DW_STRING (attr
))
5724 return DW_STRING (attr
);
5728 /* Return the die that this die in an extension of, or NULL if there
5731 static struct die_info
*
5732 dwarf2_extension (struct die_info
*die
)
5734 struct attribute
*attr
;
5735 struct die_info
*extension_die
;
5738 attr
= dwarf_attr (die
, DW_AT_extension
);
5742 ref
= dwarf2_get_ref_die_offset (attr
);
5743 extension_die
= follow_die_ref (ref
);
5746 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5749 return extension_die
;
5752 /* Convert a DIE tag into its string name. */
5755 dwarf_tag_name (register unsigned tag
)
5759 case DW_TAG_padding
:
5760 return "DW_TAG_padding";
5761 case DW_TAG_array_type
:
5762 return "DW_TAG_array_type";
5763 case DW_TAG_class_type
:
5764 return "DW_TAG_class_type";
5765 case DW_TAG_entry_point
:
5766 return "DW_TAG_entry_point";
5767 case DW_TAG_enumeration_type
:
5768 return "DW_TAG_enumeration_type";
5769 case DW_TAG_formal_parameter
:
5770 return "DW_TAG_formal_parameter";
5771 case DW_TAG_imported_declaration
:
5772 return "DW_TAG_imported_declaration";
5774 return "DW_TAG_label";
5775 case DW_TAG_lexical_block
:
5776 return "DW_TAG_lexical_block";
5778 return "DW_TAG_member";
5779 case DW_TAG_pointer_type
:
5780 return "DW_TAG_pointer_type";
5781 case DW_TAG_reference_type
:
5782 return "DW_TAG_reference_type";
5783 case DW_TAG_compile_unit
:
5784 return "DW_TAG_compile_unit";
5785 case DW_TAG_string_type
:
5786 return "DW_TAG_string_type";
5787 case DW_TAG_structure_type
:
5788 return "DW_TAG_structure_type";
5789 case DW_TAG_subroutine_type
:
5790 return "DW_TAG_subroutine_type";
5791 case DW_TAG_typedef
:
5792 return "DW_TAG_typedef";
5793 case DW_TAG_union_type
:
5794 return "DW_TAG_union_type";
5795 case DW_TAG_unspecified_parameters
:
5796 return "DW_TAG_unspecified_parameters";
5797 case DW_TAG_variant
:
5798 return "DW_TAG_variant";
5799 case DW_TAG_common_block
:
5800 return "DW_TAG_common_block";
5801 case DW_TAG_common_inclusion
:
5802 return "DW_TAG_common_inclusion";
5803 case DW_TAG_inheritance
:
5804 return "DW_TAG_inheritance";
5805 case DW_TAG_inlined_subroutine
:
5806 return "DW_TAG_inlined_subroutine";
5808 return "DW_TAG_module";
5809 case DW_TAG_ptr_to_member_type
:
5810 return "DW_TAG_ptr_to_member_type";
5811 case DW_TAG_set_type
:
5812 return "DW_TAG_set_type";
5813 case DW_TAG_subrange_type
:
5814 return "DW_TAG_subrange_type";
5815 case DW_TAG_with_stmt
:
5816 return "DW_TAG_with_stmt";
5817 case DW_TAG_access_declaration
:
5818 return "DW_TAG_access_declaration";
5819 case DW_TAG_base_type
:
5820 return "DW_TAG_base_type";
5821 case DW_TAG_catch_block
:
5822 return "DW_TAG_catch_block";
5823 case DW_TAG_const_type
:
5824 return "DW_TAG_const_type";
5825 case DW_TAG_constant
:
5826 return "DW_TAG_constant";
5827 case DW_TAG_enumerator
:
5828 return "DW_TAG_enumerator";
5829 case DW_TAG_file_type
:
5830 return "DW_TAG_file_type";
5832 return "DW_TAG_friend";
5833 case DW_TAG_namelist
:
5834 return "DW_TAG_namelist";
5835 case DW_TAG_namelist_item
:
5836 return "DW_TAG_namelist_item";
5837 case DW_TAG_packed_type
:
5838 return "DW_TAG_packed_type";
5839 case DW_TAG_subprogram
:
5840 return "DW_TAG_subprogram";
5841 case DW_TAG_template_type_param
:
5842 return "DW_TAG_template_type_param";
5843 case DW_TAG_template_value_param
:
5844 return "DW_TAG_template_value_param";
5845 case DW_TAG_thrown_type
:
5846 return "DW_TAG_thrown_type";
5847 case DW_TAG_try_block
:
5848 return "DW_TAG_try_block";
5849 case DW_TAG_variant_part
:
5850 return "DW_TAG_variant_part";
5851 case DW_TAG_variable
:
5852 return "DW_TAG_variable";
5853 case DW_TAG_volatile_type
:
5854 return "DW_TAG_volatile_type";
5855 case DW_TAG_dwarf_procedure
:
5856 return "DW_TAG_dwarf_procedure";
5857 case DW_TAG_restrict_type
:
5858 return "DW_TAG_restrict_type";
5859 case DW_TAG_interface_type
:
5860 return "DW_TAG_interface_type";
5861 case DW_TAG_namespace
:
5862 return "DW_TAG_namespace";
5863 case DW_TAG_imported_module
:
5864 return "DW_TAG_imported_module";
5865 case DW_TAG_unspecified_type
:
5866 return "DW_TAG_unspecified_type";
5867 case DW_TAG_partial_unit
:
5868 return "DW_TAG_partial_unit";
5869 case DW_TAG_imported_unit
:
5870 return "DW_TAG_imported_unit";
5871 case DW_TAG_MIPS_loop
:
5872 return "DW_TAG_MIPS_loop";
5873 case DW_TAG_format_label
:
5874 return "DW_TAG_format_label";
5875 case DW_TAG_function_template
:
5876 return "DW_TAG_function_template";
5877 case DW_TAG_class_template
:
5878 return "DW_TAG_class_template";
5880 return "DW_TAG_<unknown>";
5884 /* Convert a DWARF attribute code into its string name. */
5887 dwarf_attr_name (register unsigned attr
)
5892 return "DW_AT_sibling";
5893 case DW_AT_location
:
5894 return "DW_AT_location";
5896 return "DW_AT_name";
5897 case DW_AT_ordering
:
5898 return "DW_AT_ordering";
5899 case DW_AT_subscr_data
:
5900 return "DW_AT_subscr_data";
5901 case DW_AT_byte_size
:
5902 return "DW_AT_byte_size";
5903 case DW_AT_bit_offset
:
5904 return "DW_AT_bit_offset";
5905 case DW_AT_bit_size
:
5906 return "DW_AT_bit_size";
5907 case DW_AT_element_list
:
5908 return "DW_AT_element_list";
5909 case DW_AT_stmt_list
:
5910 return "DW_AT_stmt_list";
5912 return "DW_AT_low_pc";
5914 return "DW_AT_high_pc";
5915 case DW_AT_language
:
5916 return "DW_AT_language";
5918 return "DW_AT_member";
5920 return "DW_AT_discr";
5921 case DW_AT_discr_value
:
5922 return "DW_AT_discr_value";
5923 case DW_AT_visibility
:
5924 return "DW_AT_visibility";
5926 return "DW_AT_import";
5927 case DW_AT_string_length
:
5928 return "DW_AT_string_length";
5929 case DW_AT_common_reference
:
5930 return "DW_AT_common_reference";
5931 case DW_AT_comp_dir
:
5932 return "DW_AT_comp_dir";
5933 case DW_AT_const_value
:
5934 return "DW_AT_const_value";
5935 case DW_AT_containing_type
:
5936 return "DW_AT_containing_type";
5937 case DW_AT_default_value
:
5938 return "DW_AT_default_value";
5940 return "DW_AT_inline";
5941 case DW_AT_is_optional
:
5942 return "DW_AT_is_optional";
5943 case DW_AT_lower_bound
:
5944 return "DW_AT_lower_bound";
5945 case DW_AT_producer
:
5946 return "DW_AT_producer";
5947 case DW_AT_prototyped
:
5948 return "DW_AT_prototyped";
5949 case DW_AT_return_addr
:
5950 return "DW_AT_return_addr";
5951 case DW_AT_start_scope
:
5952 return "DW_AT_start_scope";
5953 case DW_AT_stride_size
:
5954 return "DW_AT_stride_size";
5955 case DW_AT_upper_bound
:
5956 return "DW_AT_upper_bound";
5957 case DW_AT_abstract_origin
:
5958 return "DW_AT_abstract_origin";
5959 case DW_AT_accessibility
:
5960 return "DW_AT_accessibility";
5961 case DW_AT_address_class
:
5962 return "DW_AT_address_class";
5963 case DW_AT_artificial
:
5964 return "DW_AT_artificial";
5965 case DW_AT_base_types
:
5966 return "DW_AT_base_types";
5967 case DW_AT_calling_convention
:
5968 return "DW_AT_calling_convention";
5970 return "DW_AT_count";
5971 case DW_AT_data_member_location
:
5972 return "DW_AT_data_member_location";
5973 case DW_AT_decl_column
:
5974 return "DW_AT_decl_column";
5975 case DW_AT_decl_file
:
5976 return "DW_AT_decl_file";
5977 case DW_AT_decl_line
:
5978 return "DW_AT_decl_line";
5979 case DW_AT_declaration
:
5980 return "DW_AT_declaration";
5981 case DW_AT_discr_list
:
5982 return "DW_AT_discr_list";
5983 case DW_AT_encoding
:
5984 return "DW_AT_encoding";
5985 case DW_AT_external
:
5986 return "DW_AT_external";
5987 case DW_AT_frame_base
:
5988 return "DW_AT_frame_base";
5990 return "DW_AT_friend";
5991 case DW_AT_identifier_case
:
5992 return "DW_AT_identifier_case";
5993 case DW_AT_macro_info
:
5994 return "DW_AT_macro_info";
5995 case DW_AT_namelist_items
:
5996 return "DW_AT_namelist_items";
5997 case DW_AT_priority
:
5998 return "DW_AT_priority";
6000 return "DW_AT_segment";
6001 case DW_AT_specification
:
6002 return "DW_AT_specification";
6003 case DW_AT_static_link
:
6004 return "DW_AT_static_link";
6006 return "DW_AT_type";
6007 case DW_AT_use_location
:
6008 return "DW_AT_use_location";
6009 case DW_AT_variable_parameter
:
6010 return "DW_AT_variable_parameter";
6011 case DW_AT_virtuality
:
6012 return "DW_AT_virtuality";
6013 case DW_AT_vtable_elem_location
:
6014 return "DW_AT_vtable_elem_location";
6015 case DW_AT_allocated
:
6016 return "DW_AT_allocated";
6017 case DW_AT_associated
:
6018 return "DW_AT_associated";
6019 case DW_AT_data_location
:
6020 return "DW_AT_data_location";
6022 return "DW_AT_stride";
6023 case DW_AT_entry_pc
:
6024 return "DW_AT_entry_pc";
6025 case DW_AT_use_UTF8
:
6026 return "DW_AT_use_UTF8";
6027 case DW_AT_extension
:
6028 return "DW_AT_extension";
6030 return "DW_AT_ranges";
6031 case DW_AT_trampoline
:
6032 return "DW_AT_trampoline";
6033 case DW_AT_call_column
:
6034 return "DW_AT_call_column";
6035 case DW_AT_call_file
:
6036 return "DW_AT_call_file";
6037 case DW_AT_call_line
:
6038 return "DW_AT_call_line";
6040 case DW_AT_MIPS_fde
:
6041 return "DW_AT_MIPS_fde";
6042 case DW_AT_MIPS_loop_begin
:
6043 return "DW_AT_MIPS_loop_begin";
6044 case DW_AT_MIPS_tail_loop_begin
:
6045 return "DW_AT_MIPS_tail_loop_begin";
6046 case DW_AT_MIPS_epilog_begin
:
6047 return "DW_AT_MIPS_epilog_begin";
6048 case DW_AT_MIPS_loop_unroll_factor
:
6049 return "DW_AT_MIPS_loop_unroll_factor";
6050 case DW_AT_MIPS_software_pipeline_depth
:
6051 return "DW_AT_MIPS_software_pipeline_depth";
6053 case DW_AT_MIPS_linkage_name
:
6054 return "DW_AT_MIPS_linkage_name";
6056 case DW_AT_sf_names
:
6057 return "DW_AT_sf_names";
6058 case DW_AT_src_info
:
6059 return "DW_AT_src_info";
6060 case DW_AT_mac_info
:
6061 return "DW_AT_mac_info";
6062 case DW_AT_src_coords
:
6063 return "DW_AT_src_coords";
6064 case DW_AT_body_begin
:
6065 return "DW_AT_body_begin";
6066 case DW_AT_body_end
:
6067 return "DW_AT_body_end";
6068 case DW_AT_GNU_vector
:
6069 return "DW_AT_GNU_vector";
6071 return "DW_AT_<unknown>";
6075 /* Convert a DWARF value form code into its string name. */
6078 dwarf_form_name (register unsigned form
)
6083 return "DW_FORM_addr";
6084 case DW_FORM_block2
:
6085 return "DW_FORM_block2";
6086 case DW_FORM_block4
:
6087 return "DW_FORM_block4";
6089 return "DW_FORM_data2";
6091 return "DW_FORM_data4";
6093 return "DW_FORM_data8";
6094 case DW_FORM_string
:
6095 return "DW_FORM_string";
6097 return "DW_FORM_block";
6098 case DW_FORM_block1
:
6099 return "DW_FORM_block1";
6101 return "DW_FORM_data1";
6103 return "DW_FORM_flag";
6105 return "DW_FORM_sdata";
6107 return "DW_FORM_strp";
6109 return "DW_FORM_udata";
6110 case DW_FORM_ref_addr
:
6111 return "DW_FORM_ref_addr";
6113 return "DW_FORM_ref1";
6115 return "DW_FORM_ref2";
6117 return "DW_FORM_ref4";
6119 return "DW_FORM_ref8";
6120 case DW_FORM_ref_udata
:
6121 return "DW_FORM_ref_udata";
6122 case DW_FORM_indirect
:
6123 return "DW_FORM_indirect";
6125 return "DW_FORM_<unknown>";
6129 /* Convert a DWARF stack opcode into its string name. */
6132 dwarf_stack_op_name (register unsigned op
)
6137 return "DW_OP_addr";
6139 return "DW_OP_deref";
6141 return "DW_OP_const1u";
6143 return "DW_OP_const1s";
6145 return "DW_OP_const2u";
6147 return "DW_OP_const2s";
6149 return "DW_OP_const4u";
6151 return "DW_OP_const4s";
6153 return "DW_OP_const8u";
6155 return "DW_OP_const8s";
6157 return "DW_OP_constu";
6159 return "DW_OP_consts";
6163 return "DW_OP_drop";
6165 return "DW_OP_over";
6167 return "DW_OP_pick";
6169 return "DW_OP_swap";
6173 return "DW_OP_xderef";
6181 return "DW_OP_minus";
6193 return "DW_OP_plus";
6194 case DW_OP_plus_uconst
:
6195 return "DW_OP_plus_uconst";
6201 return "DW_OP_shra";
6219 return "DW_OP_skip";
6221 return "DW_OP_lit0";
6223 return "DW_OP_lit1";
6225 return "DW_OP_lit2";
6227 return "DW_OP_lit3";
6229 return "DW_OP_lit4";
6231 return "DW_OP_lit5";
6233 return "DW_OP_lit6";
6235 return "DW_OP_lit7";
6237 return "DW_OP_lit8";
6239 return "DW_OP_lit9";
6241 return "DW_OP_lit10";
6243 return "DW_OP_lit11";
6245 return "DW_OP_lit12";
6247 return "DW_OP_lit13";
6249 return "DW_OP_lit14";
6251 return "DW_OP_lit15";
6253 return "DW_OP_lit16";
6255 return "DW_OP_lit17";
6257 return "DW_OP_lit18";
6259 return "DW_OP_lit19";
6261 return "DW_OP_lit20";
6263 return "DW_OP_lit21";
6265 return "DW_OP_lit22";
6267 return "DW_OP_lit23";
6269 return "DW_OP_lit24";
6271 return "DW_OP_lit25";
6273 return "DW_OP_lit26";
6275 return "DW_OP_lit27";
6277 return "DW_OP_lit28";
6279 return "DW_OP_lit29";
6281 return "DW_OP_lit30";
6283 return "DW_OP_lit31";
6285 return "DW_OP_reg0";
6287 return "DW_OP_reg1";
6289 return "DW_OP_reg2";
6291 return "DW_OP_reg3";
6293 return "DW_OP_reg4";
6295 return "DW_OP_reg5";
6297 return "DW_OP_reg6";
6299 return "DW_OP_reg7";
6301 return "DW_OP_reg8";
6303 return "DW_OP_reg9";
6305 return "DW_OP_reg10";
6307 return "DW_OP_reg11";
6309 return "DW_OP_reg12";
6311 return "DW_OP_reg13";
6313 return "DW_OP_reg14";
6315 return "DW_OP_reg15";
6317 return "DW_OP_reg16";
6319 return "DW_OP_reg17";
6321 return "DW_OP_reg18";
6323 return "DW_OP_reg19";
6325 return "DW_OP_reg20";
6327 return "DW_OP_reg21";
6329 return "DW_OP_reg22";
6331 return "DW_OP_reg23";
6333 return "DW_OP_reg24";
6335 return "DW_OP_reg25";
6337 return "DW_OP_reg26";
6339 return "DW_OP_reg27";
6341 return "DW_OP_reg28";
6343 return "DW_OP_reg29";
6345 return "DW_OP_reg30";
6347 return "DW_OP_reg31";
6349 return "DW_OP_breg0";
6351 return "DW_OP_breg1";
6353 return "DW_OP_breg2";
6355 return "DW_OP_breg3";
6357 return "DW_OP_breg4";
6359 return "DW_OP_breg5";
6361 return "DW_OP_breg6";
6363 return "DW_OP_breg7";
6365 return "DW_OP_breg8";
6367 return "DW_OP_breg9";
6369 return "DW_OP_breg10";
6371 return "DW_OP_breg11";
6373 return "DW_OP_breg12";
6375 return "DW_OP_breg13";
6377 return "DW_OP_breg14";
6379 return "DW_OP_breg15";
6381 return "DW_OP_breg16";
6383 return "DW_OP_breg17";
6385 return "DW_OP_breg18";
6387 return "DW_OP_breg19";
6389 return "DW_OP_breg20";
6391 return "DW_OP_breg21";
6393 return "DW_OP_breg22";
6395 return "DW_OP_breg23";
6397 return "DW_OP_breg24";
6399 return "DW_OP_breg25";
6401 return "DW_OP_breg26";
6403 return "DW_OP_breg27";
6405 return "DW_OP_breg28";
6407 return "DW_OP_breg29";
6409 return "DW_OP_breg30";
6411 return "DW_OP_breg31";
6413 return "DW_OP_regx";
6415 return "DW_OP_fbreg";
6417 return "DW_OP_bregx";
6419 return "DW_OP_piece";
6420 case DW_OP_deref_size
:
6421 return "DW_OP_deref_size";
6422 case DW_OP_xderef_size
:
6423 return "DW_OP_xderef_size";
6426 /* DWARF 3 extensions. */
6427 case DW_OP_push_object_address
:
6428 return "DW_OP_push_object_address";
6430 return "DW_OP_call2";
6432 return "DW_OP_call4";
6433 case DW_OP_call_ref
:
6434 return "DW_OP_call_ref";
6435 /* GNU extensions. */
6436 case DW_OP_GNU_push_tls_address
:
6437 return "DW_OP_GNU_push_tls_address";
6439 return "OP_<unknown>";
6444 dwarf_bool_name (unsigned mybool
)
6452 /* Convert a DWARF type code into its string name. */
6455 dwarf_type_encoding_name (register unsigned enc
)
6459 case DW_ATE_address
:
6460 return "DW_ATE_address";
6461 case DW_ATE_boolean
:
6462 return "DW_ATE_boolean";
6463 case DW_ATE_complex_float
:
6464 return "DW_ATE_complex_float";
6466 return "DW_ATE_float";
6468 return "DW_ATE_signed";
6469 case DW_ATE_signed_char
:
6470 return "DW_ATE_signed_char";
6471 case DW_ATE_unsigned
:
6472 return "DW_ATE_unsigned";
6473 case DW_ATE_unsigned_char
:
6474 return "DW_ATE_unsigned_char";
6475 case DW_ATE_imaginary_float
:
6476 return "DW_ATE_imaginary_float";
6478 return "DW_ATE_<unknown>";
6482 /* Convert a DWARF call frame info operation to its string name. */
6486 dwarf_cfi_name (register unsigned cfi_opc
)
6490 case DW_CFA_advance_loc
:
6491 return "DW_CFA_advance_loc";
6493 return "DW_CFA_offset";
6494 case DW_CFA_restore
:
6495 return "DW_CFA_restore";
6497 return "DW_CFA_nop";
6498 case DW_CFA_set_loc
:
6499 return "DW_CFA_set_loc";
6500 case DW_CFA_advance_loc1
:
6501 return "DW_CFA_advance_loc1";
6502 case DW_CFA_advance_loc2
:
6503 return "DW_CFA_advance_loc2";
6504 case DW_CFA_advance_loc4
:
6505 return "DW_CFA_advance_loc4";
6506 case DW_CFA_offset_extended
:
6507 return "DW_CFA_offset_extended";
6508 case DW_CFA_restore_extended
:
6509 return "DW_CFA_restore_extended";
6510 case DW_CFA_undefined
:
6511 return "DW_CFA_undefined";
6512 case DW_CFA_same_value
:
6513 return "DW_CFA_same_value";
6514 case DW_CFA_register
:
6515 return "DW_CFA_register";
6516 case DW_CFA_remember_state
:
6517 return "DW_CFA_remember_state";
6518 case DW_CFA_restore_state
:
6519 return "DW_CFA_restore_state";
6520 case DW_CFA_def_cfa
:
6521 return "DW_CFA_def_cfa";
6522 case DW_CFA_def_cfa_register
:
6523 return "DW_CFA_def_cfa_register";
6524 case DW_CFA_def_cfa_offset
:
6525 return "DW_CFA_def_cfa_offset";
6528 case DW_CFA_def_cfa_expression
:
6529 return "DW_CFA_def_cfa_expression";
6530 case DW_CFA_expression
:
6531 return "DW_CFA_expression";
6532 case DW_CFA_offset_extended_sf
:
6533 return "DW_CFA_offset_extended_sf";
6534 case DW_CFA_def_cfa_sf
:
6535 return "DW_CFA_def_cfa_sf";
6536 case DW_CFA_def_cfa_offset_sf
:
6537 return "DW_CFA_def_cfa_offset_sf";
6539 /* SGI/MIPS specific */
6540 case DW_CFA_MIPS_advance_loc8
:
6541 return "DW_CFA_MIPS_advance_loc8";
6543 /* GNU extensions */
6544 case DW_CFA_GNU_window_save
:
6545 return "DW_CFA_GNU_window_save";
6546 case DW_CFA_GNU_args_size
:
6547 return "DW_CFA_GNU_args_size";
6548 case DW_CFA_GNU_negative_offset_extended
:
6549 return "DW_CFA_GNU_negative_offset_extended";
6552 return "DW_CFA_<unknown>";
6558 dump_die (struct die_info
*die
)
6562 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6563 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6564 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6565 dwarf_bool_name (die
->has_children
));
6567 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6568 for (i
= 0; i
< die
->num_attrs
; ++i
)
6570 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6571 dwarf_attr_name (die
->attrs
[i
].name
),
6572 dwarf_form_name (die
->attrs
[i
].form
));
6573 switch (die
->attrs
[i
].form
)
6575 case DW_FORM_ref_addr
:
6577 fprintf_unfiltered (gdb_stderr
, "address: ");
6578 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6580 case DW_FORM_block2
:
6581 case DW_FORM_block4
:
6583 case DW_FORM_block1
:
6584 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6595 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6597 case DW_FORM_string
:
6599 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6600 DW_STRING (&die
->attrs
[i
])
6601 ? DW_STRING (&die
->attrs
[i
]) : "");
6604 if (DW_UNSND (&die
->attrs
[i
]))
6605 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6607 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6609 case DW_FORM_indirect
:
6610 /* the reader will have reduced the indirect form to
6611 the "base form" so this form should not occur */
6612 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6615 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6616 die
->attrs
[i
].form
);
6618 fprintf_unfiltered (gdb_stderr
, "\n");
6623 dump_die_list (struct die_info
*die
)
6633 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6636 struct die_info
*old
;
6638 h
= (offset
% REF_HASH_SIZE
);
6639 old
= die_ref_table
[h
];
6640 die
->next_ref
= old
;
6641 die_ref_table
[h
] = die
;
6646 dwarf2_empty_hash_tables (void)
6648 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6652 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6654 unsigned int result
= 0;
6658 case DW_FORM_ref_addr
:
6659 result
= DW_ADDR (attr
);
6665 case DW_FORM_ref_udata
:
6666 result
= cu_header_offset
+ DW_UNSND (attr
);
6669 complaint (&symfile_complaints
,
6670 "unsupported die ref attribute form: '%s'",
6671 dwarf_form_name (attr
->form
));
6676 static struct die_info
*
6677 follow_die_ref (unsigned int offset
)
6679 struct die_info
*die
;
6682 h
= (offset
% REF_HASH_SIZE
);
6683 die
= die_ref_table
[h
];
6686 if (die
->offset
== offset
)
6690 die
= die
->next_ref
;
6695 static struct type
*
6696 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6698 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6700 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6701 typeid, objfile
->name
);
6704 /* Look for this particular type in the fundamental type vector. If
6705 one is not found, create and install one appropriate for the
6706 current language and the current target machine. */
6708 if (ftypes
[typeid] == NULL
)
6710 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6713 return (ftypes
[typeid]);
6716 /* Decode simple location descriptions.
6717 Given a pointer to a dwarf block that defines a location, compute
6718 the location and return the value.
6720 FIXME: This is a kludge until we figure out a better
6721 way to handle the location descriptions.
6722 Gdb's design does not mesh well with the DWARF2 notion of a location
6723 computing interpreter, which is a shame because the flexibility goes unused.
6724 FIXME: Implement more operations as necessary.
6726 A location description containing no operations indicates that the
6727 object is optimized out. The global optimized_out flag is set for
6728 those, the return value is meaningless.
6730 When the result is a register number, the global isreg flag is set,
6731 otherwise it is cleared.
6733 When the result is a base register offset, the global offreg flag is set
6734 and the register number is returned in basereg, otherwise it is cleared.
6736 When the DW_OP_fbreg operation is encountered without a corresponding
6737 DW_AT_frame_base attribute, the global islocal flag is set.
6738 Hopefully the machine dependent code knows how to set up a virtual
6739 frame pointer for the local references.
6741 Note that stack[0] is unused except as a default error return.
6742 Note that stack overflow is not yet handled. */
6745 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6746 const struct comp_unit_head
*cu_header
)
6749 int size
= blk
->size
;
6750 char *data
= blk
->data
;
6751 CORE_ADDR stack
[64];
6753 unsigned int bytes_read
, unsnd
;
6803 stack
[++stacki
] = op
- DW_OP_lit0
;
6839 stack
[++stacki
] = op
- DW_OP_reg0
;
6844 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6846 stack
[++stacki
] = unsnd
;
6882 basereg
= op
- DW_OP_breg0
;
6883 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6889 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6891 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6896 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6898 if (frame_base_reg
>= 0)
6901 basereg
= frame_base_reg
;
6902 stack
[stacki
] += frame_base_offset
;
6906 complaint (&symfile_complaints
,
6907 "DW_AT_frame_base missing for DW_OP_fbreg");
6913 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6914 cu_header
, &bytes_read
);
6919 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6924 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6929 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6934 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6939 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6944 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6949 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6955 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6960 stack
[stacki
+ 1] = stack
[stacki
];
6965 stack
[stacki
- 1] += stack
[stacki
];
6969 case DW_OP_plus_uconst
:
6970 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6975 stack
[stacki
- 1] -= stack
[stacki
];
6981 /* If we're not the last op, then we definitely can't encode
6982 this using GDB's address_class enum. */
6984 dwarf2_complex_location_expr_complaint ();
6987 case DW_OP_GNU_push_tls_address
:
6988 /* The top of the stack has the offset from the beginning
6989 of the thread control block at which the variable is located. */
6990 /* Nothing should follow this operator, so the top of stack would
6993 dwarf2_complex_location_expr_complaint ();
6997 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
6998 dwarf_stack_op_name (op
));
6999 return (stack
[stacki
]);
7002 return (stack
[stacki
]);
7005 /* memory allocation interface */
7009 dwarf2_free_tmp_obstack (void *ignore
)
7011 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7014 static struct dwarf_block
*
7015 dwarf_alloc_block (void)
7017 struct dwarf_block
*blk
;
7019 blk
= (struct dwarf_block
*)
7020 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7024 static struct abbrev_info
*
7025 dwarf_alloc_abbrev (void)
7027 struct abbrev_info
*abbrev
;
7029 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7030 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7034 static struct die_info
*
7035 dwarf_alloc_die (void)
7037 struct die_info
*die
;
7039 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7040 memset (die
, 0, sizeof (struct die_info
));
7045 /* Macro support. */
7048 /* Return the full name of file number I in *LH's file name table.
7049 Use COMP_DIR as the name of the current directory of the
7050 compilation. The result is allocated using xmalloc; the caller is
7051 responsible for freeing it. */
7053 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7055 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7057 if (IS_ABSOLUTE_PATH (fe
->name
))
7058 return xstrdup (fe
->name
);
7066 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7072 dir_len
= strlen (dir
);
7073 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7074 strcpy (full_name
, dir
);
7075 full_name
[dir_len
] = '/';
7076 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7080 return xstrdup (fe
->name
);
7085 static struct macro_source_file
*
7086 macro_start_file (int file
, int line
,
7087 struct macro_source_file
*current_file
,
7088 const char *comp_dir
,
7089 struct line_header
*lh
, struct objfile
*objfile
)
7091 /* The full name of this source file. */
7092 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7094 /* We don't create a macro table for this compilation unit
7095 at all until we actually get a filename. */
7096 if (! pending_macros
)
7097 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7098 objfile
->macro_cache
);
7101 /* If we have no current file, then this must be the start_file
7102 directive for the compilation unit's main source file. */
7103 current_file
= macro_set_main (pending_macros
, full_name
);
7105 current_file
= macro_include (current_file
, line
, full_name
);
7109 return current_file
;
7113 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7114 followed by a null byte. */
7116 copy_string (const char *buf
, int len
)
7118 char *s
= xmalloc (len
+ 1);
7119 memcpy (s
, buf
, len
);
7127 consume_improper_spaces (const char *p
, const char *body
)
7131 complaint (&symfile_complaints
,
7132 "macro definition contains spaces in formal argument list:\n`%s'",
7144 parse_macro_definition (struct macro_source_file
*file
, int line
,
7149 /* The body string takes one of two forms. For object-like macro
7150 definitions, it should be:
7152 <macro name> " " <definition>
7154 For function-like macro definitions, it should be:
7156 <macro name> "() " <definition>
7158 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7160 Spaces may appear only where explicitly indicated, and in the
7163 The Dwarf 2 spec says that an object-like macro's name is always
7164 followed by a space, but versions of GCC around March 2002 omit
7165 the space when the macro's definition is the empty string.
7167 The Dwarf 2 spec says that there should be no spaces between the
7168 formal arguments in a function-like macro's formal argument list,
7169 but versions of GCC around March 2002 include spaces after the
7173 /* Find the extent of the macro name. The macro name is terminated
7174 by either a space or null character (for an object-like macro) or
7175 an opening paren (for a function-like macro). */
7176 for (p
= body
; *p
; p
++)
7177 if (*p
== ' ' || *p
== '(')
7180 if (*p
== ' ' || *p
== '\0')
7182 /* It's an object-like macro. */
7183 int name_len
= p
- body
;
7184 char *name
= copy_string (body
, name_len
);
7185 const char *replacement
;
7188 replacement
= body
+ name_len
+ 1;
7191 dwarf2_macro_malformed_definition_complaint (body
);
7192 replacement
= body
+ name_len
;
7195 macro_define_object (file
, line
, name
, replacement
);
7201 /* It's a function-like macro. */
7202 char *name
= copy_string (body
, p
- body
);
7205 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7209 p
= consume_improper_spaces (p
, body
);
7211 /* Parse the formal argument list. */
7212 while (*p
&& *p
!= ')')
7214 /* Find the extent of the current argument name. */
7215 const char *arg_start
= p
;
7217 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7220 if (! *p
|| p
== arg_start
)
7221 dwarf2_macro_malformed_definition_complaint (body
);
7224 /* Make sure argv has room for the new argument. */
7225 if (argc
>= argv_size
)
7228 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7231 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7234 p
= consume_improper_spaces (p
, body
);
7236 /* Consume the comma, if present. */
7241 p
= consume_improper_spaces (p
, body
);
7250 /* Perfectly formed definition, no complaints. */
7251 macro_define_function (file
, line
, name
,
7252 argc
, (const char **) argv
,
7254 else if (*p
== '\0')
7256 /* Complain, but do define it. */
7257 dwarf2_macro_malformed_definition_complaint (body
);
7258 macro_define_function (file
, line
, name
,
7259 argc
, (const char **) argv
,
7263 /* Just complain. */
7264 dwarf2_macro_malformed_definition_complaint (body
);
7267 /* Just complain. */
7268 dwarf2_macro_malformed_definition_complaint (body
);
7274 for (i
= 0; i
< argc
; i
++)
7280 dwarf2_macro_malformed_definition_complaint (body
);
7285 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7286 char *comp_dir
, bfd
*abfd
,
7287 const struct comp_unit_head
*cu_header
,
7288 struct objfile
*objfile
)
7290 char *mac_ptr
, *mac_end
;
7291 struct macro_source_file
*current_file
= 0;
7293 if (dwarf_macinfo_buffer
== NULL
)
7295 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7299 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7300 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7304 enum dwarf_macinfo_record_type macinfo_type
;
7306 /* Do we at least have room for a macinfo type byte? */
7307 if (mac_ptr
>= mac_end
)
7309 dwarf2_macros_too_long_complaint ();
7313 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7316 switch (macinfo_type
)
7318 /* A zero macinfo type indicates the end of the macro
7323 case DW_MACINFO_define
:
7324 case DW_MACINFO_undef
:
7330 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7331 mac_ptr
+= bytes_read
;
7332 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7333 mac_ptr
+= bytes_read
;
7336 complaint (&symfile_complaints
,
7337 "debug info gives macro %s outside of any file: %s",
7339 DW_MACINFO_define
? "definition" : macinfo_type
==
7340 DW_MACINFO_undef
? "undefinition" :
7341 "something-or-other", body
);
7344 if (macinfo_type
== DW_MACINFO_define
)
7345 parse_macro_definition (current_file
, line
, body
);
7346 else if (macinfo_type
== DW_MACINFO_undef
)
7347 macro_undef (current_file
, line
, body
);
7352 case DW_MACINFO_start_file
:
7357 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7358 mac_ptr
+= bytes_read
;
7359 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7360 mac_ptr
+= bytes_read
;
7362 current_file
= macro_start_file (file
, line
,
7363 current_file
, comp_dir
,
7368 case DW_MACINFO_end_file
:
7370 complaint (&symfile_complaints
,
7371 "macro debug info has an unmatched `close_file' directive");
7374 current_file
= current_file
->included_by
;
7377 enum dwarf_macinfo_record_type next_type
;
7379 /* GCC circa March 2002 doesn't produce the zero
7380 type byte marking the end of the compilation
7381 unit. Complain if it's not there, but exit no
7384 /* Do we at least have room for a macinfo type byte? */
7385 if (mac_ptr
>= mac_end
)
7387 dwarf2_macros_too_long_complaint ();
7391 /* We don't increment mac_ptr here, so this is just
7393 next_type
= read_1_byte (abfd
, mac_ptr
);
7395 complaint (&symfile_complaints
,
7396 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7403 case DW_MACINFO_vendor_ext
:
7409 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7410 mac_ptr
+= bytes_read
;
7411 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7412 mac_ptr
+= bytes_read
;
7414 /* We don't recognize any vendor extensions. */
7421 /* Check if the attribute's form is a DW_FORM_block*
7422 if so return true else false. */
7424 attr_form_is_block (struct attribute
*attr
)
7426 return (attr
== NULL
? 0 :
7427 attr
->form
== DW_FORM_block1
7428 || attr
->form
== DW_FORM_block2
7429 || attr
->form
== DW_FORM_block4
7430 || attr
->form
== DW_FORM_block
);
7434 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7435 const struct comp_unit_head
*cu_header
,
7436 struct objfile
*objfile
)
7438 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7440 struct dwarf2_loclist_baton
*baton
;
7442 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7443 sizeof (struct dwarf2_loclist_baton
));
7444 baton
->objfile
= objfile
;
7446 /* We don't know how long the location list is, but make sure we
7447 don't run off the edge of the section. */
7448 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7449 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7450 baton
->base_address
= cu_header
->base_address
;
7451 if (cu_header
->base_known
== 0)
7452 complaint (&symfile_complaints
,
7453 "Location list used without specifying the CU base address.");
7455 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7456 SYMBOL_LOCATION_BATON (sym
) = baton
;
7460 struct dwarf2_locexpr_baton
*baton
;
7462 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7463 sizeof (struct dwarf2_locexpr_baton
));
7464 baton
->objfile
= objfile
;
7466 if (attr_form_is_block (attr
))
7468 /* Note that we're just copying the block's data pointer
7469 here, not the actual data. We're still pointing into the
7470 dwarf_info_buffer for SYM's objfile; right now we never
7471 release that buffer, but when we do clean up properly
7472 this may need to change. */
7473 baton
->size
= DW_BLOCK (attr
)->size
;
7474 baton
->data
= DW_BLOCK (attr
)->data
;
7478 dwarf2_invalid_attrib_class_complaint ("location description",
7479 SYMBOL_NATURAL_NAME (sym
));
7484 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7485 SYMBOL_LOCATION_BATON (sym
) = baton
;