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"
48 #include "gdb_string.h"
49 #include "gdb_assert.h"
50 #include <sys/types.h>
52 #ifndef DWARF2_REG_TO_REGNUM
53 #define DWARF2_REG_TO_REGNUM(REG) (REG)
57 /* .debug_info header for a compilation unit
58 Because of alignment constraints, this structure has padding and cannot
59 be mapped directly onto the beginning of the .debug_info section. */
60 typedef struct comp_unit_header
62 unsigned int length
; /* length of the .debug_info
64 unsigned short version
; /* version number -- 2 for DWARF
66 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
67 unsigned char addr_size
; /* byte size of an address -- 4 */
70 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
73 /* .debug_pubnames header
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct pubnames_header
78 unsigned int length
; /* length of the .debug_pubnames
80 unsigned char version
; /* version number -- 2 for DWARF
82 unsigned int info_offset
; /* offset into .debug_info section */
83 unsigned int info_size
; /* byte size of .debug_info section
87 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct aranges_header
94 unsigned int length
; /* byte len of the .debug_aranges
96 unsigned short version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned char addr_size
; /* byte size of an address */
100 unsigned char seg_size
; /* byte size of segment descriptor */
103 #define _ACTUAL_ARANGES_HEADER_SIZE 12
105 /* .debug_line statement program prologue
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct statement_prologue
110 unsigned int total_length
; /* byte length of the statement
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int prologue_length
; /* # bytes between prologue &
116 unsigned char minimum_instruction_length
; /* byte size of
118 unsigned char default_is_stmt
; /* initial value of is_stmt
121 unsigned char line_range
;
122 unsigned char opcode_base
; /* number assigned to first special
124 unsigned char *standard_opcode_lengths
;
128 /* offsets and sizes of debugging sections */
130 static file_ptr dwarf_info_offset
;
131 static file_ptr dwarf_abbrev_offset
;
132 static file_ptr dwarf_line_offset
;
133 static file_ptr dwarf_pubnames_offset
;
134 static file_ptr dwarf_aranges_offset
;
135 static file_ptr dwarf_loc_offset
;
136 static file_ptr dwarf_macinfo_offset
;
137 static file_ptr dwarf_str_offset
;
138 static file_ptr dwarf_ranges_offset
;
139 file_ptr dwarf_frame_offset
;
140 file_ptr dwarf_eh_frame_offset
;
142 static unsigned int dwarf_info_size
;
143 static unsigned int dwarf_abbrev_size
;
144 static unsigned int dwarf_line_size
;
145 static unsigned int dwarf_pubnames_size
;
146 static unsigned int dwarf_aranges_size
;
147 static unsigned int dwarf_loc_size
;
148 static unsigned int dwarf_macinfo_size
;
149 static unsigned int dwarf_str_size
;
150 static unsigned int dwarf_ranges_size
;
151 unsigned int dwarf_frame_size
;
152 unsigned int dwarf_eh_frame_size
;
154 static asection
*dwarf_info_section
;
155 static asection
*dwarf_abbrev_section
;
156 static asection
*dwarf_line_section
;
157 static asection
*dwarf_pubnames_section
;
158 static asection
*dwarf_aranges_section
;
159 static asection
*dwarf_loc_section
;
160 static asection
*dwarf_macinfo_section
;
161 static asection
*dwarf_str_section
;
162 static asection
*dwarf_ranges_section
;
163 asection
*dwarf_frame_section
;
164 asection
*dwarf_eh_frame_section
;
166 /* names of the debugging sections */
168 #define INFO_SECTION ".debug_info"
169 #define ABBREV_SECTION ".debug_abbrev"
170 #define LINE_SECTION ".debug_line"
171 #define PUBNAMES_SECTION ".debug_pubnames"
172 #define ARANGES_SECTION ".debug_aranges"
173 #define LOC_SECTION ".debug_loc"
174 #define MACINFO_SECTION ".debug_macinfo"
175 #define STR_SECTION ".debug_str"
176 #define RANGES_SECTION ".debug_ranges"
177 #define FRAME_SECTION ".debug_frame"
178 #define EH_FRAME_SECTION ".eh_frame"
180 /* local data types */
182 /* We hold several abbreviation tables in memory at the same time. */
183 #ifndef ABBREV_HASH_SIZE
184 #define ABBREV_HASH_SIZE 121
187 /* The data in a compilation unit header, after target2host
188 translation, looks like this. */
189 struct comp_unit_head
191 unsigned long length
;
193 unsigned int abbrev_offset
;
194 unsigned char addr_size
;
195 unsigned char signed_addr_p
;
196 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
197 unsigned int initial_length_size
; /* size of the length field; either
200 /* Offset to the first byte of this compilation unit header in the
201 * .debug_info section, for resolving relative reference dies. */
205 /* Pointer to this compilation unit header in the .debug_info
210 /* Pointer to the first die of this compilatio unit. This will
211 * be the first byte following the compilation unit header. */
215 /* Pointer to the next compilation unit header in the program. */
217 struct comp_unit_head
*next
;
219 /* DWARF abbreviation table associated with this compilation unit */
221 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
223 /* Pointer to the DIE associated with the compilation unit. */
225 struct die_info
*die
;
228 /* The line number information for a compilation unit (found in the
229 .debug_line section) begins with a "statement program header",
230 which contains the following information. */
233 unsigned int total_length
;
234 unsigned short version
;
235 unsigned int header_length
;
236 unsigned char minimum_instruction_length
;
237 unsigned char default_is_stmt
;
239 unsigned char line_range
;
240 unsigned char opcode_base
;
242 /* standard_opcode_lengths[i] is the number of operands for the
243 standard opcode whose value is i. This means that
244 standard_opcode_lengths[0] is unused, and the last meaningful
245 element is standard_opcode_lengths[opcode_base - 1]. */
246 unsigned char *standard_opcode_lengths
;
248 /* The include_directories table. NOTE! These strings are not
249 allocated with xmalloc; instead, they are pointers into
250 debug_line_buffer. If you try to free them, `free' will get
252 unsigned int num_include_dirs
, include_dirs_size
;
255 /* The file_names table. NOTE! These strings are not allocated
256 with xmalloc; instead, they are pointers into debug_line_buffer.
257 Don't try to free them directly. */
258 unsigned int num_file_names
, file_names_size
;
262 unsigned int dir_index
;
263 unsigned int mod_time
;
267 /* The start and end of the statement program following this
268 header. These point into dwarf_line_buffer. */
269 char *statement_program_start
, *statement_program_end
;
272 /* When we construct a partial symbol table entry we only
273 need this much information. */
274 struct partial_die_info
277 unsigned char has_children
;
278 unsigned char is_external
;
279 unsigned char is_declaration
;
280 unsigned char has_type
;
287 struct dwarf_block
*locdesc
;
288 unsigned int language
;
292 /* This data structure holds the information of an abbrev. */
295 unsigned int number
; /* number identifying abbrev */
296 enum dwarf_tag tag
; /* dwarf tag */
297 int has_children
; /* boolean */
298 unsigned int num_attrs
; /* number of attributes */
299 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
300 struct abbrev_info
*next
; /* next in chain */
305 enum dwarf_attribute name
;
306 enum dwarf_form form
;
309 /* This data structure holds a complete die structure. */
312 enum dwarf_tag tag
; /* Tag indicating type of die */
313 unsigned short has_children
; /* Does the die have children */
314 unsigned int abbrev
; /* Abbrev number */
315 unsigned int offset
; /* Offset in .debug_info section */
316 unsigned int num_attrs
; /* Number of attributes */
317 struct attribute
*attrs
; /* An array of attributes */
318 struct die_info
*next_ref
; /* Next die in ref hash table */
319 struct die_info
*next
; /* Next die in linked list */
320 struct type
*type
; /* Cached type information */
323 /* Attributes have a name and a value */
326 enum dwarf_attribute name
;
327 enum dwarf_form form
;
331 struct dwarf_block
*blk
;
339 struct function_range
342 CORE_ADDR lowpc
, highpc
;
344 struct function_range
*next
;
347 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
349 /* Get at parts of an attribute structure */
351 #define DW_STRING(attr) ((attr)->u.str)
352 #define DW_UNSND(attr) ((attr)->u.unsnd)
353 #define DW_BLOCK(attr) ((attr)->u.blk)
354 #define DW_SND(attr) ((attr)->u.snd)
355 #define DW_ADDR(attr) ((attr)->u.addr)
357 /* Blocks are a bunch of untyped bytes. */
364 #ifndef ATTR_ALLOC_CHUNK
365 #define ATTR_ALLOC_CHUNK 4
368 /* A hash table of die offsets for following references. */
369 #ifndef REF_HASH_SIZE
370 #define REF_HASH_SIZE 1021
373 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
375 /* Obstack for allocating temporary storage used during symbol reading. */
376 static struct obstack dwarf2_tmp_obstack
;
378 /* Offset to the first byte of the current compilation unit header,
379 for resolving relative reference dies. */
380 static unsigned int cu_header_offset
;
382 /* Allocate fields for structs, unions and enums in this size. */
383 #ifndef DW_FIELD_ALLOC_CHUNK
384 #define DW_FIELD_ALLOC_CHUNK 4
387 /* The language we are debugging. */
388 static enum language cu_language
;
389 static const struct language_defn
*cu_language_defn
;
391 /* Actually data from the sections. */
392 static char *dwarf_info_buffer
;
393 static char *dwarf_abbrev_buffer
;
394 static char *dwarf_line_buffer
;
395 static char *dwarf_str_buffer
;
396 static char *dwarf_macinfo_buffer
;
397 static char *dwarf_ranges_buffer
;
399 /* A zeroed version of a partial die for initialization purposes. */
400 static struct partial_die_info zeroed_partial_die
;
402 /* The generic symbol table building routines have separate lists for
403 file scope symbols and all all other scopes (local scopes). So
404 we need to select the right one to pass to add_symbol_to_list().
405 We do it by keeping a pointer to the correct list in list_in_scope.
407 FIXME: The original dwarf code just treated the file scope as the first
408 local scope, and all other local scopes as nested local scopes, and worked
409 fine. Check to see if we really need to distinguish these
411 static struct pending
**list_in_scope
= &file_symbols
;
413 /* FIXME: decode_locdesc sets these variables to describe the location
414 to the caller. These ought to be a structure or something. If
415 none of the flags are set, the object lives at the address returned
416 by decode_locdesc. */
418 static int optimized_out
; /* No ops in location in expression,
419 so object was optimized out. */
420 static int isreg
; /* Object lives in register.
421 decode_locdesc's return value is
422 the register number. */
423 static int offreg
; /* Object's address is the sum of the
424 register specified by basereg, plus
425 the offset returned. */
426 static int basereg
; /* See `offreg'. */
427 static int isderef
; /* Value described by flags above is
428 the address of a pointer to the object. */
429 static int islocal
; /* Variable is at the returned offset
430 from the frame start, but there's
431 no identified frame pointer for
432 this function, so we can't say
433 which register it's relative to;
435 static int is_thread_local
; /* Variable is at a constant offset in the
436 thread-local storage block for the
437 current thread and the dynamic linker
438 module containing this expression.
439 decode_locdesc returns the offset from
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
;
516 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
517 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
518 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
519 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
520 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
521 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
522 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
523 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
524 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
525 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
526 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
527 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
528 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
530 /* Maintain an array of referenced fundamental types for the current
531 compilation unit being read. For DWARF version 1, we have to construct
532 the fundamental types on the fly, since no information about the
533 fundamental types is supplied. Each such fundamental type is created by
534 calling a language dependent routine to create the type, and then a
535 pointer to that type is then placed in the array at the index specified
536 by it's FT_<TYPENAME> value. The array has a fixed size set by the
537 FT_NUM_MEMBERS compile time constant, which is the number of predefined
538 fundamental types gdb knows how to construct. */
539 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
541 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
542 but this would require a corresponding change in unpack_field_as_long
544 static int bits_per_byte
= 8;
546 /* The routines that read and process dies for a C struct or C++ class
547 pass lists of data member fields and lists of member function fields
548 in an instance of a field_info structure, as defined below. */
551 /* List of data member and baseclasses fields. */
554 struct nextfield
*next
;
561 /* Number of fields. */
564 /* Number of baseclasses. */
567 /* Set if the accesibility of one of the fields is not public. */
568 int non_public_fields
;
570 /* Member function fields array, entries are allocated in the order they
571 are encountered in the object file. */
574 struct nextfnfield
*next
;
575 struct fn_field fnfield
;
579 /* Member function fieldlist array, contains name of possibly overloaded
580 member function, number of overloaded member functions and a pointer
581 to the head of the member function field chain. */
586 struct nextfnfield
*head
;
590 /* Number of entries in the fnfieldlists array. */
594 /* Various complaints about symbol reading that don't abort the process */
597 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
599 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
604 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
606 complaint (&symfile_complaints
,
607 "statement list doesn't fit in .debug_line section");
611 dwarf2_complex_location_expr_complaint (void)
613 complaint (&symfile_complaints
, "location expression too complex");
617 dwarf2_unsupported_at_frame_base_complaint (const char *arg1
)
619 complaint (&symfile_complaints
,
620 "unsupported DW_AT_frame_base for function '%s'", arg1
);
624 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
627 complaint (&symfile_complaints
,
628 "const value length mismatch for '%s', got %d, expected %d", arg1
,
633 dwarf2_macros_too_long_complaint (void)
635 complaint (&symfile_complaints
,
636 "macro info runs off end of `.debug_macinfo' section");
640 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
642 complaint (&symfile_complaints
,
643 "macro debug info contains a malformed macro definition:\n`%s'",
648 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
650 complaint (&symfile_complaints
,
651 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
654 /* local function prototypes */
656 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
659 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
662 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
664 static char *scan_partial_symbols (char *, struct objfile
*,
665 CORE_ADDR
*, CORE_ADDR
*,
666 const struct comp_unit_head
*);
668 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
669 const struct comp_unit_head
*);
671 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
673 static void psymtab_to_symtab_1 (struct partial_symtab
*);
675 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int,
678 static void dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
);
680 static void dwarf2_empty_abbrev_table (void *);
682 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
683 const struct comp_unit_head
*cu_header
);
685 static char *read_partial_die (struct partial_die_info
*,
687 const struct comp_unit_head
*);
689 static char *read_full_die (struct die_info
**, bfd
*, char *,
690 const struct comp_unit_head
*);
692 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
693 bfd
*, char *, const struct comp_unit_head
*);
695 static char *read_attribute_value (struct attribute
*, unsigned,
696 bfd
*, char *, const struct comp_unit_head
*);
698 static unsigned int read_1_byte (bfd
*, char *);
700 static int read_1_signed_byte (bfd
*, char *);
702 static unsigned int read_2_bytes (bfd
*, char *);
704 static unsigned int read_4_bytes (bfd
*, char *);
706 static unsigned long read_8_bytes (bfd
*, char *);
708 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
711 static LONGEST
read_initial_length (bfd
*, char *,
712 struct comp_unit_head
*, int *bytes_read
);
714 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
717 static char *read_n_bytes (bfd
*, char *, unsigned int);
719 static char *read_string (bfd
*, char *, unsigned int *);
721 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
724 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
726 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
728 static void set_cu_language (unsigned int);
730 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
732 static int die_is_declaration (struct die_info
*);
734 static void free_line_header (struct line_header
*lh
);
736 static struct line_header
*(dwarf_decode_line_header
737 (unsigned int offset
,
739 const struct comp_unit_head
*cu_header
));
741 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
742 const struct comp_unit_head
*);
744 static void dwarf2_start_subfile (char *, char *);
746 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
747 struct objfile
*, const struct comp_unit_head
*);
749 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
750 struct objfile
*, const struct comp_unit_head
*);
752 static void dwarf2_const_value_data (struct attribute
*attr
,
756 static struct type
*die_type (struct die_info
*, struct objfile
*,
757 const struct comp_unit_head
*);
759 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
760 const struct comp_unit_head
*);
763 static struct type
*type_at_offset (unsigned int, struct objfile
*);
766 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
767 const struct comp_unit_head
*);
769 static void read_type_die (struct die_info
*, struct objfile
*,
770 const struct comp_unit_head
*);
772 static void read_typedef (struct die_info
*, struct objfile
*,
773 const struct comp_unit_head
*);
775 static void read_base_type (struct die_info
*, struct objfile
*);
777 static void read_file_scope (struct die_info
*, struct objfile
*,
778 const struct comp_unit_head
*);
780 static void read_func_scope (struct die_info
*, struct objfile
*,
781 const struct comp_unit_head
*);
783 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
784 const struct comp_unit_head
*);
786 static int dwarf2_get_pc_bounds (struct die_info
*,
787 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*,
788 const struct comp_unit_head
*);
790 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
791 struct objfile
*, const struct comp_unit_head
*);
793 static void dwarf2_attach_fields_to_type (struct field_info
*,
794 struct type
*, struct objfile
*);
796 static void dwarf2_add_member_fn (struct field_info
*,
797 struct die_info
*, struct type
*,
798 struct objfile
*objfile
,
799 const struct comp_unit_head
*);
801 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
802 struct type
*, struct objfile
*);
804 static void read_structure_scope (struct die_info
*, struct objfile
*,
805 const struct comp_unit_head
*);
807 static void read_common_block (struct die_info
*, struct objfile
*,
808 const struct comp_unit_head
*);
810 static void read_namespace (struct die_info
*die
, struct objfile
*objfile
,
811 const struct comp_unit_head
*cu_header
);
813 static void read_enumeration (struct die_info
*, struct objfile
*,
814 const struct comp_unit_head
*);
816 static struct type
*dwarf_base_type (int, int, struct objfile
*);
818 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
819 const struct comp_unit_head
*);
821 static void read_array_type (struct die_info
*, struct objfile
*,
822 const struct comp_unit_head
*);
824 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
825 const struct comp_unit_head
*);
827 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
828 const struct comp_unit_head
*);
830 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
831 const struct comp_unit_head
*);
833 static void read_tag_const_type (struct die_info
*, struct objfile
*,
834 const struct comp_unit_head
*);
836 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
837 const struct comp_unit_head
*);
839 static void read_tag_string_type (struct die_info
*, struct objfile
*);
841 static void read_subroutine_type (struct die_info
*, struct objfile
*,
842 const struct comp_unit_head
*);
844 static struct die_info
*read_comp_unit (char *, bfd
*,
845 const struct comp_unit_head
*);
847 static void free_die_list (struct die_info
*);
849 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
851 static void process_die (struct die_info
*, struct objfile
*,
852 const struct comp_unit_head
*);
854 static char *dwarf2_linkage_name (struct die_info
*);
856 static char *dwarf_tag_name (unsigned int);
858 static char *dwarf_attr_name (unsigned int);
860 static char *dwarf_form_name (unsigned int);
862 static char *dwarf_stack_op_name (unsigned int);
864 static char *dwarf_bool_name (unsigned int);
866 static char *dwarf_type_encoding_name (unsigned int);
869 static char *dwarf_cfi_name (unsigned int);
871 struct die_info
*copy_die (struct die_info
*);
874 static struct die_info
*sibling_die (struct die_info
*);
876 static void dump_die (struct die_info
*);
878 static void dump_die_list (struct die_info
*);
880 static void store_in_ref_table (unsigned int, struct die_info
*);
882 static void dwarf2_empty_hash_tables (void);
884 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
886 static struct die_info
*follow_die_ref (unsigned int);
888 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
890 /* memory allocation interface */
892 static void dwarf2_free_tmp_obstack (void *);
894 static struct dwarf_block
*dwarf_alloc_block (void);
896 static struct abbrev_info
*dwarf_alloc_abbrev (void);
898 static struct die_info
*dwarf_alloc_die (void);
900 static void initialize_cu_func_list (void);
902 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
904 static void dwarf_decode_macros (struct line_header
*, unsigned int,
905 char *, bfd
*, const struct comp_unit_head
*,
908 static int attr_form_is_block (struct attribute
*);
911 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
912 const struct comp_unit_head
*,
913 struct objfile
*objfile
);
915 /* Try to locate the sections we need for DWARF 2 debugging
916 information and return true if we have enough to do something. */
919 dwarf2_has_info (bfd
*abfd
)
921 dwarf_info_offset
= 0;
922 dwarf_abbrev_offset
= 0;
923 dwarf_line_offset
= 0;
924 dwarf_str_offset
= 0;
925 dwarf_macinfo_offset
= 0;
926 dwarf_frame_offset
= 0;
927 dwarf_eh_frame_offset
= 0;
928 dwarf_ranges_offset
= 0;
930 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
931 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
941 /* This function is mapped across the sections and remembers the
942 offset and size of each of the debugging sections we are interested
946 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
948 if (STREQ (sectp
->name
, INFO_SECTION
))
950 dwarf_info_offset
= sectp
->filepos
;
951 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
952 dwarf_info_section
= sectp
;
954 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
956 dwarf_abbrev_offset
= sectp
->filepos
;
957 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
958 dwarf_abbrev_section
= sectp
;
960 else if (STREQ (sectp
->name
, LINE_SECTION
))
962 dwarf_line_offset
= sectp
->filepos
;
963 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
964 dwarf_line_section
= sectp
;
966 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
968 dwarf_pubnames_offset
= sectp
->filepos
;
969 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
970 dwarf_pubnames_section
= sectp
;
972 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
974 dwarf_aranges_offset
= sectp
->filepos
;
975 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
976 dwarf_aranges_section
= sectp
;
978 else if (STREQ (sectp
->name
, LOC_SECTION
))
980 dwarf_loc_offset
= sectp
->filepos
;
981 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
982 dwarf_loc_section
= sectp
;
984 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
986 dwarf_macinfo_offset
= sectp
->filepos
;
987 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
988 dwarf_macinfo_section
= sectp
;
990 else if (STREQ (sectp
->name
, STR_SECTION
))
992 dwarf_str_offset
= sectp
->filepos
;
993 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
994 dwarf_str_section
= sectp
;
996 else if (STREQ (sectp
->name
, FRAME_SECTION
))
998 dwarf_frame_offset
= sectp
->filepos
;
999 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1000 dwarf_frame_section
= sectp
;
1002 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
1004 dwarf_eh_frame_offset
= sectp
->filepos
;
1005 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1006 dwarf_eh_frame_section
= sectp
;
1008 else if (STREQ (sectp
->name
, RANGES_SECTION
))
1010 dwarf_ranges_offset
= sectp
->filepos
;
1011 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1012 dwarf_ranges_section
= sectp
;
1016 /* Build a partial symbol table. */
1019 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1022 /* We definitely need the .debug_info and .debug_abbrev sections */
1024 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1027 dwarf_info_section
);
1028 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1029 dwarf_abbrev_offset
,
1031 dwarf_abbrev_section
);
1033 if (dwarf_line_offset
)
1034 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1037 dwarf_line_section
);
1039 dwarf_line_buffer
= NULL
;
1041 if (dwarf_str_offset
)
1042 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1047 dwarf_str_buffer
= NULL
;
1049 if (dwarf_macinfo_offset
)
1050 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1051 dwarf_macinfo_offset
,
1053 dwarf_macinfo_section
);
1055 dwarf_macinfo_buffer
= NULL
;
1057 if (dwarf_ranges_offset
)
1058 dwarf_ranges_buffer
= dwarf2_read_section (objfile
,
1059 dwarf_ranges_offset
,
1061 dwarf_ranges_section
);
1063 dwarf_ranges_buffer
= NULL
;
1066 || (objfile
->global_psymbols
.size
== 0
1067 && objfile
->static_psymbols
.size
== 0))
1069 init_psymbol_list (objfile
, 1024);
1073 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1075 /* Things are significantly easier if we have .debug_aranges and
1076 .debug_pubnames sections */
1078 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1082 /* only test this case for now */
1084 /* In this case we have to work a bit harder */
1085 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1090 /* Build the partial symbol table from the information in the
1091 .debug_pubnames and .debug_aranges sections. */
1094 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1096 bfd
*abfd
= objfile
->obfd
;
1097 char *aranges_buffer
, *pubnames_buffer
;
1098 char *aranges_ptr
, *pubnames_ptr
;
1099 unsigned int entry_length
, version
, info_offset
, info_size
;
1101 pubnames_buffer
= dwarf2_read_section (objfile
,
1102 dwarf_pubnames_offset
,
1103 dwarf_pubnames_size
,
1104 dwarf_pubnames_section
);
1105 pubnames_ptr
= pubnames_buffer
;
1106 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1108 struct comp_unit_head cu_header
;
1111 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1113 pubnames_ptr
+= bytes_read
;
1114 version
= read_1_byte (abfd
, pubnames_ptr
);
1116 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1118 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1122 aranges_buffer
= dwarf2_read_section (objfile
,
1123 dwarf_aranges_offset
,
1125 dwarf_aranges_section
);
1130 /* Read in the comp unit header information from the debug_info at
1134 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1135 char *info_ptr
, bfd
*abfd
)
1139 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1141 info_ptr
+= bytes_read
;
1142 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1144 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1146 info_ptr
+= bytes_read
;
1147 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1149 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1150 if (signed_addr
< 0)
1151 internal_error (__FILE__
, __LINE__
,
1152 "read_comp_unit_head: dwarf from non elf file");
1153 cu_header
->signed_addr_p
= signed_addr
;
1157 /* Build the partial symbol table by doing a quick pass through the
1158 .debug_info and .debug_abbrev sections. */
1161 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1163 /* Instead of reading this into a big buffer, we should probably use
1164 mmap() on architectures that support it. (FIXME) */
1165 bfd
*abfd
= objfile
->obfd
;
1166 char *info_ptr
, *abbrev_ptr
;
1167 char *beg_of_comp_unit
;
1168 struct partial_die_info comp_unit_die
;
1169 struct partial_symtab
*pst
;
1170 struct cleanup
*back_to
;
1171 CORE_ADDR lowpc
, highpc
;
1173 info_ptr
= dwarf_info_buffer
;
1174 abbrev_ptr
= dwarf_abbrev_buffer
;
1176 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1177 the partial symbol scan, like attribute values.
1179 We could reduce our peak memory consumption during partial symbol
1180 table construction by freeing stuff from this obstack more often
1181 --- say, after processing each compilation unit, or each die ---
1182 but it turns out that this saves almost nothing. For an
1183 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1184 on dwarf2_tmp_obstack. Some investigation showed:
1186 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1187 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1188 all fixed-length values not requiring dynamic allocation.
1190 2) 30% of the attributes used the form DW_FORM_string. For
1191 DW_FORM_string, read_attribute simply hands back a pointer to
1192 the null-terminated string in dwarf_info_buffer, so no dynamic
1193 allocation is needed there either.
1195 3) The remaining 1% of the attributes all used DW_FORM_block1.
1196 75% of those were DW_AT_frame_base location lists for
1197 functions; the rest were DW_AT_location attributes, probably
1198 for the global variables.
1200 Anyway, what this all means is that the memory the dwarf2
1201 reader uses as temporary space reading partial symbols is about
1202 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1204 obstack_init (&dwarf2_tmp_obstack
);
1205 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1207 /* Since the objects we're extracting from dwarf_info_buffer vary in
1208 length, only the individual functions to extract them (like
1209 read_comp_unit_head and read_partial_die) can really know whether
1210 the buffer is large enough to hold another complete object.
1212 At the moment, they don't actually check that. If
1213 dwarf_info_buffer holds just one extra byte after the last
1214 compilation unit's dies, then read_comp_unit_head will happily
1215 read off the end of the buffer. read_partial_die is similarly
1216 casual. Those functions should be fixed.
1218 For this loop condition, simply checking whether there's any data
1219 left at all should be sufficient. */
1220 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1222 struct comp_unit_head cu_header
;
1223 beg_of_comp_unit
= info_ptr
;
1224 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1226 if (cu_header
.version
!= 2)
1228 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
));
1231 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1233 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1234 (long) cu_header
.abbrev_offset
,
1235 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1236 bfd_get_filename (abfd
));
1239 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1240 > dwarf_info_buffer
+ dwarf_info_size
)
1242 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1243 (long) cu_header
.length
,
1244 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1245 bfd_get_filename (abfd
));
1248 /* Complete the cu_header */
1249 cu_header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1250 cu_header
.first_die_ptr
= info_ptr
;
1251 cu_header
.cu_head_ptr
= beg_of_comp_unit
;
1253 /* Read the abbrevs for this compilation unit into a table */
1254 dwarf2_read_abbrevs (abfd
, &cu_header
);
1255 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1257 /* Read the compilation unit die */
1258 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1261 /* Set the language we're debugging */
1262 set_cu_language (comp_unit_die
.language
);
1264 /* Allocate a new partial symbol table structure */
1265 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1266 comp_unit_die
.name
? comp_unit_die
.name
: "",
1267 comp_unit_die
.lowpc
,
1268 objfile
->global_psymbols
.next
,
1269 objfile
->static_psymbols
.next
);
1271 pst
->read_symtab_private
= (char *)
1272 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1273 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1274 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1275 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1276 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1277 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1278 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1279 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1280 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1281 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1282 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1283 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1284 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1285 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1286 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1288 /* Store the function that reads in the rest of the symbol table */
1289 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1291 /* Check if comp unit has_children.
1292 If so, read the rest of the partial symbols from this comp unit.
1293 If not, there's no more debug_info for this comp unit. */
1294 if (comp_unit_die
.has_children
)
1296 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1299 /* If the compilation unit didn't have an explicit address range,
1300 then use the information extracted from its child dies. */
1301 if (! comp_unit_die
.has_pc_info
)
1303 comp_unit_die
.lowpc
= lowpc
;
1304 comp_unit_die
.highpc
= highpc
;
1307 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1308 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1310 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1311 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1312 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1313 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1314 sort_pst_symbols (pst
);
1316 /* If there is already a psymtab or symtab for a file of this
1317 name, remove it. (If there is a symtab, more drastic things
1318 also happen.) This happens in VxWorks. */
1319 free_named_symtabs (pst
->filename
);
1321 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1322 + cu_header
.initial_length_size
;
1324 do_cleanups (back_to
);
1327 /* Read in all interesting dies to the end of the compilation unit. */
1330 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1331 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1332 const struct comp_unit_head
*cu_header
)
1334 bfd
*abfd
= objfile
->obfd
;
1335 struct partial_die_info pdi
;
1337 /* This function is called after we've read in the comp_unit_die in
1338 order to read its children. We start the nesting level at 1 since
1339 we have pushed 1 level down in order to read the comp unit's children.
1340 The comp unit itself is at level 0, so we stop reading when we pop
1341 back to that level. */
1343 int nesting_level
= 1;
1345 /* We only want to read in symbols corresponding to variables or
1346 other similar objects that are global or static. Normally, these
1347 are all children of the DW_TAG_compile_unit die, so are all at
1348 level 1. But C++ namespaces give ries to DW_TAG_namespace dies
1349 whose children are global objects. So we keep track of what
1350 level we currently think of as referring to file scope; this
1351 should always equal 1 plus the number of namespaces that we are
1352 currently nested within. */
1354 int file_scope_level
= 1;
1356 *lowpc
= ((CORE_ADDR
) -1);
1357 *highpc
= ((CORE_ADDR
) 0);
1359 while (nesting_level
)
1361 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1363 /* Anonymous namespaces have no name but are interesting. */
1365 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
)
1369 case DW_TAG_subprogram
:
1370 if (pdi
.has_pc_info
)
1372 if (pdi
.lowpc
< *lowpc
)
1376 if (pdi
.highpc
> *highpc
)
1378 *highpc
= pdi
.highpc
;
1380 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1381 && !pdi
.is_declaration
)
1383 add_partial_symbol (&pdi
, objfile
, cu_header
);
1387 case DW_TAG_variable
:
1388 case DW_TAG_typedef
:
1389 case DW_TAG_class_type
:
1390 case DW_TAG_structure_type
:
1391 case DW_TAG_union_type
:
1392 case DW_TAG_enumeration_type
:
1393 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1394 && !pdi
.is_declaration
)
1396 add_partial_symbol (&pdi
, objfile
, cu_header
);
1399 case DW_TAG_enumerator
:
1400 /* File scope enumerators are added to the partial
1401 symbol table. They're children of the enumeration
1402 type die, so they occur at a level one higher than we
1403 normally look for. */
1404 if (nesting_level
== file_scope_level
+ 1)
1405 add_partial_symbol (&pdi
, objfile
, cu_header
);
1407 case DW_TAG_base_type
:
1408 /* File scope base type definitions are added to the partial
1410 if (nesting_level
== file_scope_level
)
1411 add_partial_symbol (&pdi
, objfile
, cu_header
);
1413 case DW_TAG_namespace
:
1414 /* FIXME: carlton/2002-10-16: we're not yet doing
1415 anything useful with this, but for now make sure that
1416 these tags at least don't cause us to miss any
1417 important symbols. */
1418 if (pdi
.has_children
)
1425 /* If the die has a sibling, skip to the sibling. Do not skip
1426 enumeration types, we want to record their enumerators. Do
1427 not skip namespaces, we want to record symbols inside
1430 && pdi
.tag
!= DW_TAG_enumeration_type
1431 && pdi
.tag
!= DW_TAG_namespace
)
1433 info_ptr
= pdi
.sibling
;
1435 else if (pdi
.has_children
)
1437 /* Die has children, but either the optional DW_AT_sibling
1438 attribute is missing or we want to look at them. */
1445 /* If this is the end of a DW_TAG_namespace entry, then
1446 decrease the file_scope_level, too. */
1447 if (nesting_level
< file_scope_level
)
1450 gdb_assert (nesting_level
== file_scope_level
);
1455 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1456 from `maint check'. */
1457 if (*lowpc
== ((CORE_ADDR
) -1))
1463 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1464 const struct comp_unit_head
*cu_header
)
1470 case DW_TAG_subprogram
:
1471 if (pdi
->is_external
)
1473 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1474 mst_text, objfile); */
1475 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1476 VAR_NAMESPACE
, LOC_BLOCK
,
1477 &objfile
->global_psymbols
,
1478 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1482 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1483 mst_file_text, objfile); */
1484 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1485 VAR_NAMESPACE
, LOC_BLOCK
,
1486 &objfile
->static_psymbols
,
1487 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1490 case DW_TAG_variable
:
1491 if (pdi
->is_external
)
1494 Don't enter into the minimal symbol tables as there is
1495 a minimal symbol table entry from the ELF symbols already.
1496 Enter into partial symbol table if it has a location
1497 descriptor or a type.
1498 If the location descriptor is missing, new_symbol will create
1499 a LOC_UNRESOLVED symbol, the address of the variable will then
1500 be determined from the minimal symbol table whenever the variable
1502 The address for the partial symbol table entry is not
1503 used by GDB, but it comes in handy for debugging partial symbol
1507 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1508 if (pdi
->locdesc
|| pdi
->has_type
)
1509 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1510 VAR_NAMESPACE
, LOC_STATIC
,
1511 &objfile
->global_psymbols
,
1512 0, addr
+ baseaddr
, cu_language
, objfile
);
1516 /* Static Variable. Skip symbols without location descriptors. */
1517 if (pdi
->locdesc
== NULL
)
1519 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1520 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1521 mst_file_data, objfile); */
1522 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1523 VAR_NAMESPACE
, LOC_STATIC
,
1524 &objfile
->static_psymbols
,
1525 0, addr
+ baseaddr
, cu_language
, objfile
);
1528 case DW_TAG_typedef
:
1529 case DW_TAG_base_type
:
1530 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1531 VAR_NAMESPACE
, LOC_TYPEDEF
,
1532 &objfile
->static_psymbols
,
1533 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1535 case DW_TAG_class_type
:
1536 case DW_TAG_structure_type
:
1537 case DW_TAG_union_type
:
1538 case DW_TAG_enumeration_type
:
1539 /* Skip aggregate types without children, these are external
1541 if (pdi
->has_children
== 0)
1543 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1544 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1545 &objfile
->static_psymbols
,
1546 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1548 if (cu_language
== language_cplus
)
1550 /* For C++, these implicitly act as typedefs as well. */
1551 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1552 VAR_NAMESPACE
, LOC_TYPEDEF
,
1553 &objfile
->static_psymbols
,
1554 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1557 case DW_TAG_enumerator
:
1558 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1559 VAR_NAMESPACE
, LOC_CONST
,
1560 &objfile
->static_psymbols
,
1561 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1568 /* Expand this partial symbol table into a full symbol table. */
1571 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1573 /* FIXME: This is barely more than a stub. */
1578 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1584 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1585 gdb_flush (gdb_stdout
);
1588 psymtab_to_symtab_1 (pst
);
1590 /* Finish up the debug error message. */
1592 printf_filtered ("done.\n");
1598 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1600 struct objfile
*objfile
= pst
->objfile
;
1601 bfd
*abfd
= objfile
->obfd
;
1602 struct comp_unit_head cu_header
;
1603 struct die_info
*dies
;
1604 unsigned long offset
;
1605 CORE_ADDR lowpc
, highpc
;
1606 struct die_info
*child_die
;
1608 struct symtab
*symtab
;
1609 struct cleanup
*back_to
;
1611 /* Set local variables from the partial symbol table info. */
1612 offset
= DWARF_INFO_OFFSET (pst
);
1613 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1614 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1615 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1616 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1617 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1618 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1619 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1620 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1621 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1622 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1623 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1624 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1625 cu_header_offset
= offset
;
1626 info_ptr
= dwarf_info_buffer
+ offset
;
1628 obstack_init (&dwarf2_tmp_obstack
);
1629 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1632 make_cleanup (really_free_pendings
, NULL
);
1634 /* read in the comp_unit header */
1635 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1637 /* Read the abbrevs for this compilation unit */
1638 dwarf2_read_abbrevs (abfd
, &cu_header
);
1639 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1641 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1643 make_cleanup_free_die_list (dies
);
1645 /* Do line number decoding in read_file_scope () */
1646 cu_header
.die
= dies
;
1647 process_die (dies
, objfile
, &cu_header
);
1649 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
, &cu_header
))
1651 /* Some compilers don't define a DW_AT_high_pc attribute for
1652 the compilation unit. If the DW_AT_high_pc is missing,
1653 synthesize it, by scanning the DIE's below the compilation unit. */
1655 if (dies
->has_children
)
1657 child_die
= dies
->next
;
1658 while (child_die
&& child_die
->tag
)
1660 if (child_die
->tag
== DW_TAG_subprogram
)
1662 CORE_ADDR low
, high
;
1664 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1665 objfile
, &cu_header
))
1667 highpc
= max (highpc
, high
);
1670 child_die
= sibling_die (child_die
);
1674 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1676 /* Set symtab language to language from DW_AT_language.
1677 If the compilation is from a C file generated by language preprocessors,
1678 do not set the language if it was already deduced by start_subfile. */
1680 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1682 symtab
->language
= cu_language
;
1684 pst
->symtab
= symtab
;
1686 sort_symtab_syms (pst
->symtab
);
1688 do_cleanups (back_to
);
1691 /* Process a die and its children. */
1694 process_die (struct die_info
*die
, struct objfile
*objfile
,
1695 const struct comp_unit_head
*cu_header
)
1699 case DW_TAG_padding
:
1701 case DW_TAG_compile_unit
:
1702 read_file_scope (die
, objfile
, cu_header
);
1704 case DW_TAG_subprogram
:
1705 read_subroutine_type (die
, objfile
, cu_header
);
1706 read_func_scope (die
, objfile
, cu_header
);
1708 case DW_TAG_inlined_subroutine
:
1709 /* FIXME: These are ignored for now.
1710 They could be used to set breakpoints on all inlined instances
1711 of a function and make GDB `next' properly over inlined functions. */
1713 case DW_TAG_lexical_block
:
1714 read_lexical_block_scope (die
, objfile
, cu_header
);
1716 case DW_TAG_class_type
:
1717 case DW_TAG_structure_type
:
1718 case DW_TAG_union_type
:
1719 read_structure_scope (die
, objfile
, cu_header
);
1721 case DW_TAG_enumeration_type
:
1722 read_enumeration (die
, objfile
, cu_header
);
1724 case DW_TAG_subroutine_type
:
1725 read_subroutine_type (die
, objfile
, cu_header
);
1727 case DW_TAG_array_type
:
1728 read_array_type (die
, objfile
, cu_header
);
1730 case DW_TAG_pointer_type
:
1731 read_tag_pointer_type (die
, objfile
, cu_header
);
1733 case DW_TAG_ptr_to_member_type
:
1734 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1736 case DW_TAG_reference_type
:
1737 read_tag_reference_type (die
, objfile
, cu_header
);
1739 case DW_TAG_string_type
:
1740 read_tag_string_type (die
, objfile
);
1742 case DW_TAG_base_type
:
1743 read_base_type (die
, objfile
);
1744 if (dwarf_attr (die
, DW_AT_name
))
1746 /* Add a typedef symbol for the base type definition. */
1747 new_symbol (die
, die
->type
, objfile
, cu_header
);
1750 case DW_TAG_common_block
:
1751 read_common_block (die
, objfile
, cu_header
);
1753 case DW_TAG_common_inclusion
:
1755 case DW_TAG_namespace
:
1756 read_namespace (die
, objfile
, cu_header
);
1758 case DW_TAG_imported_declaration
:
1759 case DW_TAG_imported_module
:
1760 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1761 information contained in these. DW_TAG_imported_declaration
1762 dies shouldn't have children; DW_TAG_imported_module dies
1763 shouldn't in the C++ case, but conceivably could in the
1764 Fortran case, so we'll have to replace this gdb_assert if
1765 Fortran compilers start generating that info. */
1766 gdb_assert (!die
->has_children
);
1769 new_symbol (die
, NULL
, objfile
, cu_header
);
1775 initialize_cu_func_list (void)
1777 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1781 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1782 const struct comp_unit_head
*cu_header
)
1784 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1785 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1786 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1787 struct attribute
*attr
;
1788 char *name
= "<unknown>";
1789 char *comp_dir
= NULL
;
1790 struct die_info
*child_die
;
1791 bfd
*abfd
= objfile
->obfd
;
1792 struct line_header
*line_header
= 0;
1794 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
1796 if (die
->has_children
)
1798 child_die
= die
->next
;
1799 while (child_die
&& child_die
->tag
)
1801 if (child_die
->tag
== DW_TAG_subprogram
)
1803 CORE_ADDR low
, high
;
1805 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1806 objfile
, cu_header
))
1808 lowpc
= min (lowpc
, low
);
1809 highpc
= max (highpc
, high
);
1812 child_die
= sibling_die (child_die
);
1817 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1818 from finish_block. */
1819 if (lowpc
== ((CORE_ADDR
) -1))
1824 attr
= dwarf_attr (die
, DW_AT_name
);
1827 name
= DW_STRING (attr
);
1829 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1832 comp_dir
= DW_STRING (attr
);
1835 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1836 directory, get rid of it. */
1837 char *cp
= strchr (comp_dir
, ':');
1839 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1844 if (objfile
->ei
.entry_point
>= lowpc
&&
1845 objfile
->ei
.entry_point
< highpc
)
1847 objfile
->ei
.entry_file_lowpc
= lowpc
;
1848 objfile
->ei
.entry_file_highpc
= highpc
;
1851 attr
= dwarf_attr (die
, DW_AT_language
);
1854 set_cu_language (DW_UNSND (attr
));
1857 /* We assume that we're processing GCC output. */
1858 processing_gcc_compilation
= 2;
1860 /* FIXME:Do something here. */
1861 if (dip
->at_producer
!= NULL
)
1863 handle_producer (dip
->at_producer
);
1867 /* The compilation unit may be in a different language or objfile,
1868 zero out all remembered fundamental types. */
1869 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1871 start_symtab (name
, comp_dir
, lowpc
);
1872 record_debugformat ("DWARF 2");
1874 initialize_cu_func_list ();
1876 /* Process all dies in compilation unit. */
1877 if (die
->has_children
)
1879 child_die
= die
->next
;
1880 while (child_die
&& child_die
->tag
)
1882 process_die (child_die
, objfile
, cu_header
);
1883 child_die
= sibling_die (child_die
);
1887 /* Decode line number information if present. */
1888 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1891 unsigned int line_offset
= DW_UNSND (attr
);
1892 line_header
= dwarf_decode_line_header (line_offset
,
1896 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1897 (void *) line_header
);
1898 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1902 /* Decode macro information, if present. Dwarf 2 macro information
1903 refers to information in the line number info statement program
1904 header, so we can only read it if we've read the header
1906 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1907 if (attr
&& line_header
)
1909 unsigned int macro_offset
= DW_UNSND (attr
);
1910 dwarf_decode_macros (line_header
, macro_offset
,
1911 comp_dir
, abfd
, cu_header
, objfile
);
1913 do_cleanups (back_to
);
1917 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1919 struct function_range
*thisfn
;
1921 thisfn
= (struct function_range
*)
1922 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1923 thisfn
->name
= name
;
1924 thisfn
->lowpc
= lowpc
;
1925 thisfn
->highpc
= highpc
;
1926 thisfn
->seen_line
= 0;
1927 thisfn
->next
= NULL
;
1929 if (cu_last_fn
== NULL
)
1930 cu_first_fn
= thisfn
;
1932 cu_last_fn
->next
= thisfn
;
1934 cu_last_fn
= thisfn
;
1938 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1939 const struct comp_unit_head
*cu_header
)
1941 register struct context_stack
*new;
1944 struct die_info
*child_die
;
1945 struct attribute
*attr
;
1948 name
= dwarf2_linkage_name (die
);
1950 /* Ignore functions with missing or empty names and functions with
1951 missing or invalid low and high pc attributes. */
1952 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
1958 /* Record the function range for dwarf_decode_lines. */
1959 add_to_cu_func_list (name
, lowpc
, highpc
);
1961 if (objfile
->ei
.entry_point
>= lowpc
&&
1962 objfile
->ei
.entry_point
< highpc
)
1964 objfile
->ei
.entry_func_lowpc
= lowpc
;
1965 objfile
->ei
.entry_func_highpc
= highpc
;
1968 /* Decode DW_AT_frame_base location descriptor if present, keep result
1969 for DW_OP_fbreg operands in decode_locdesc. */
1970 frame_base_reg
= -1;
1971 frame_base_offset
= 0;
1972 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1977 /* Support the .debug_loc offsets */
1978 if (attr_form_is_block (attr
))
1980 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1982 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
1984 dwarf2_complex_location_expr_complaint ();
1989 dwarf2_invalid_attrib_class_complaint ("DW_AT_frame_base", name
);
1994 dwarf2_unsupported_at_frame_base_complaint (name
);
1996 frame_base_reg
= addr
;
1999 frame_base_reg
= basereg
;
2000 frame_base_offset
= addr
;
2003 dwarf2_unsupported_at_frame_base_complaint (name
);
2006 new = push_context (0, lowpc
);
2007 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
2009 /* If there was a location expression for DW_AT_frame_base above,
2010 record it. We still need to decode it above because not all
2011 symbols use location expressions exclusively. */
2013 dwarf2_symbol_mark_computed (attr
, new->name
, cu_header
, objfile
);
2015 list_in_scope
= &local_symbols
;
2017 if (die
->has_children
)
2019 child_die
= die
->next
;
2020 while (child_die
&& child_die
->tag
)
2022 process_die (child_die
, objfile
, cu_header
);
2023 child_die
= sibling_die (child_die
);
2027 new = pop_context ();
2028 /* Make a block for the local symbols within. */
2029 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2030 lowpc
, highpc
, objfile
);
2032 /* In C++, we can have functions nested inside functions (e.g., when
2033 a function declares a class that has methods). This means that
2034 when we finish processing a function scope, we may need to go
2035 back to building a containing block's symbol lists. */
2036 local_symbols
= new->locals
;
2037 param_symbols
= new->params
;
2039 /* If we've finished processing a top-level function, subsequent
2040 symbols go in the file symbol list. */
2041 if (outermost_context_p ())
2042 list_in_scope
= &file_symbols
;
2045 /* Process all the DIES contained within a lexical block scope. Start
2046 a new scope, process the dies, and then close the scope. */
2049 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
2050 const struct comp_unit_head
*cu_header
)
2052 register struct context_stack
*new;
2053 CORE_ADDR lowpc
, highpc
;
2054 struct die_info
*child_die
;
2056 /* Ignore blocks with missing or invalid low and high pc attributes. */
2057 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2058 as multiple lexical blocks? Handling children in a sane way would
2059 be nasty. Might be easier to properly extend generic blocks to
2061 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2066 push_context (0, lowpc
);
2067 if (die
->has_children
)
2069 child_die
= die
->next
;
2070 while (child_die
&& child_die
->tag
)
2072 process_die (child_die
, objfile
, cu_header
);
2073 child_die
= sibling_die (child_die
);
2076 new = pop_context ();
2078 if (local_symbols
!= NULL
)
2080 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2083 local_symbols
= new->locals
;
2086 /* Get low and high pc attributes from a die. Return 1 if the attributes
2087 are present and valid, otherwise, return 0. Return -1 if the range is
2088 discontinuous, i.e. derived from DW_AT_ranges information. */
2090 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2091 CORE_ADDR
*highpc
, struct objfile
*objfile
,
2092 const struct comp_unit_head
*cu_header
)
2094 struct attribute
*attr
;
2095 bfd
*obfd
= objfile
->obfd
;
2100 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2103 high
= DW_ADDR (attr
);
2104 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2106 low
= DW_ADDR (attr
);
2108 /* Found high w/o low attribute. */
2111 /* Found consecutive range of addresses. */
2116 attr
= dwarf_attr (die
, DW_AT_ranges
);
2119 unsigned int addr_size
= cu_header
->addr_size
;
2120 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2121 /* Value of the DW_AT_ranges attribute is the offset in the
2122 .debug_renges section. */
2123 unsigned int offset
= DW_UNSND (attr
);
2124 /* Base address selection entry. */
2133 /* The applicable base address is determined by (1) the closest
2134 preceding base address selection entry in the range list or
2135 (2) the DW_AT_low_pc of the compilation unit. */
2137 /* ??? Was in dwarf3 draft4, and has since been removed.
2138 GCC still uses it though. */
2139 attr
= dwarf_attr (cu_header
->die
, DW_AT_entry_pc
);
2142 base
= DW_ADDR (attr
);
2148 attr
= dwarf_attr (cu_header
->die
, DW_AT_low_pc
);
2151 base
= DW_ADDR (attr
);
2156 buffer
= dwarf_ranges_buffer
+ offset
;
2159 /* Read in the largest possible address. */
2160 marker
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2161 if ((marker
& mask
) == mask
)
2163 /* If we found the largest possible address, then
2164 read the base address. */
2165 base
= read_address (obfd
, buffer
+ addr_size
,
2167 buffer
+= 2 * addr_size
;
2168 offset
+= 2 * addr_size
;
2176 CORE_ADDR range_beginning
, range_end
;
2178 range_beginning
= read_address (obfd
, buffer
,
2180 buffer
+= addr_size
;
2181 range_end
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2182 buffer
+= addr_size
;
2183 offset
+= 2 * addr_size
;
2185 /* An end of list marker is a pair of zero addresses. */
2186 if (range_beginning
== 0 && range_end
== 0)
2187 /* Found the end of list entry. */
2190 /* Each base address selection entry is a pair of 2 values.
2191 The first is the largest possible address, the second is
2192 the base address. Check for a base address here. */
2193 if ((range_beginning
& mask
) == mask
)
2195 /* If we found the largest possible address, then
2196 read the base address. */
2197 base
= read_address (obfd
, buffer
+ addr_size
,
2205 /* We have no valid base address for the ranges
2207 complaint (&symfile_complaints
,
2208 "Invalid .debug_ranges data (no base address)");
2212 range_beginning
+= base
;
2215 /* FIXME: This is recording everything as a low-high
2216 segment of consecutive addresses. We should have a
2217 data structure for discontiguous block ranges
2221 low
= range_beginning
;
2227 if (range_beginning
< low
)
2228 low
= range_beginning
;
2229 if (range_end
> high
)
2235 /* If the first entry is an end-of-list marker, the range
2236 describes an empty scope, i.e. no instructions. */
2246 /* When using the GNU linker, .gnu.linkonce. sections are used to
2247 eliminate duplicate copies of functions and vtables and such.
2248 The linker will arbitrarily choose one and discard the others.
2249 The AT_*_pc values for such functions refer to local labels in
2250 these sections. If the section from that file was discarded, the
2251 labels are not in the output, so the relocs get a value of 0.
2252 If this is a discarded function, mark the pc bounds as invalid,
2253 so that GDB will ignore it. */
2254 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2262 /* Add an aggregate field to the field list. */
2265 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2266 struct objfile
*objfile
,
2267 const struct comp_unit_head
*cu_header
)
2269 struct nextfield
*new_field
;
2270 struct attribute
*attr
;
2272 char *fieldname
= "";
2274 /* Allocate a new field list entry and link it in. */
2275 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2276 make_cleanup (xfree
, new_field
);
2277 memset (new_field
, 0, sizeof (struct nextfield
));
2278 new_field
->next
= fip
->fields
;
2279 fip
->fields
= new_field
;
2282 /* Handle accessibility and virtuality of field.
2283 The default accessibility for members is public, the default
2284 accessibility for inheritance is private. */
2285 if (die
->tag
!= DW_TAG_inheritance
)
2286 new_field
->accessibility
= DW_ACCESS_public
;
2288 new_field
->accessibility
= DW_ACCESS_private
;
2289 new_field
->virtuality
= DW_VIRTUALITY_none
;
2291 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2293 new_field
->accessibility
= DW_UNSND (attr
);
2294 if (new_field
->accessibility
!= DW_ACCESS_public
)
2295 fip
->non_public_fields
= 1;
2296 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2298 new_field
->virtuality
= DW_UNSND (attr
);
2300 fp
= &new_field
->field
;
2302 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2304 /* Data member other than a C++ static data member. */
2306 /* Get type of field. */
2307 fp
->type
= die_type (die
, objfile
, cu_header
);
2309 FIELD_STATIC_KIND (*fp
) = 0;
2311 /* Get bit size of field (zero if none). */
2312 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2315 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2319 FIELD_BITSIZE (*fp
) = 0;
2322 /* Get bit offset of field. */
2323 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2326 FIELD_BITPOS (*fp
) =
2327 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2330 FIELD_BITPOS (*fp
) = 0;
2331 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2334 if (BITS_BIG_ENDIAN
)
2336 /* For big endian bits, the DW_AT_bit_offset gives the
2337 additional bit offset from the MSB of the containing
2338 anonymous object to the MSB of the field. We don't
2339 have to do anything special since we don't need to
2340 know the size of the anonymous object. */
2341 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2345 /* For little endian bits, compute the bit offset to the
2346 MSB of the anonymous object, subtract off the number of
2347 bits from the MSB of the field to the MSB of the
2348 object, and then subtract off the number of bits of
2349 the field itself. The result is the bit offset of
2350 the LSB of the field. */
2352 int bit_offset
= DW_UNSND (attr
);
2354 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2357 /* The size of the anonymous object containing
2358 the bit field is explicit, so use the
2359 indicated size (in bytes). */
2360 anonymous_size
= DW_UNSND (attr
);
2364 /* The size of the anonymous object containing
2365 the bit field must be inferred from the type
2366 attribute of the data member containing the
2368 anonymous_size
= TYPE_LENGTH (fp
->type
);
2370 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2371 - bit_offset
- FIELD_BITSIZE (*fp
);
2375 /* Get name of field. */
2376 attr
= dwarf_attr (die
, DW_AT_name
);
2377 if (attr
&& DW_STRING (attr
))
2378 fieldname
= DW_STRING (attr
);
2379 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2380 &objfile
->type_obstack
);
2382 /* Change accessibility for artificial fields (e.g. virtual table
2383 pointer or virtual base class pointer) to private. */
2384 if (dwarf_attr (die
, DW_AT_artificial
))
2386 new_field
->accessibility
= DW_ACCESS_private
;
2387 fip
->non_public_fields
= 1;
2390 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2392 /* C++ static member. */
2394 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2395 is a declaration, but all versions of G++ as of this writing
2396 (so through at least 3.2.1) incorrectly generate
2397 DW_TAG_variable tags. */
2401 /* Get name of field. */
2402 attr
= dwarf_attr (die
, DW_AT_name
);
2403 if (attr
&& DW_STRING (attr
))
2404 fieldname
= DW_STRING (attr
);
2408 /* Get physical name. */
2409 physname
= dwarf2_linkage_name (die
);
2411 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2412 &objfile
->type_obstack
));
2413 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2414 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2415 &objfile
->type_obstack
);
2417 else if (die
->tag
== DW_TAG_inheritance
)
2419 /* C++ base class field. */
2420 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2422 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2424 FIELD_BITSIZE (*fp
) = 0;
2425 FIELD_STATIC_KIND (*fp
) = 0;
2426 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2427 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2428 fip
->nbaseclasses
++;
2432 /* Create the vector of fields, and attach it to the type. */
2435 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2436 struct objfile
*objfile
)
2438 int nfields
= fip
->nfields
;
2440 /* Record the field count, allocate space for the array of fields,
2441 and create blank accessibility bitfields if necessary. */
2442 TYPE_NFIELDS (type
) = nfields
;
2443 TYPE_FIELDS (type
) = (struct field
*)
2444 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2445 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2447 if (fip
->non_public_fields
)
2449 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2451 TYPE_FIELD_PRIVATE_BITS (type
) =
2452 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2453 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2455 TYPE_FIELD_PROTECTED_BITS (type
) =
2456 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2457 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2459 TYPE_FIELD_IGNORE_BITS (type
) =
2460 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2461 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2464 /* If the type has baseclasses, allocate and clear a bit vector for
2465 TYPE_FIELD_VIRTUAL_BITS. */
2466 if (fip
->nbaseclasses
)
2468 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2471 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2472 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2473 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2474 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2475 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2478 /* Copy the saved-up fields into the field vector. Start from the head
2479 of the list, adding to the tail of the field array, so that they end
2480 up in the same order in the array in which they were added to the list. */
2481 while (nfields
-- > 0)
2483 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2484 switch (fip
->fields
->accessibility
)
2486 case DW_ACCESS_private
:
2487 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2490 case DW_ACCESS_protected
:
2491 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2494 case DW_ACCESS_public
:
2498 /* Unknown accessibility. Complain and treat it as public. */
2500 complaint (&symfile_complaints
, "unsupported accessibility %d",
2501 fip
->fields
->accessibility
);
2505 if (nfields
< fip
->nbaseclasses
)
2507 switch (fip
->fields
->virtuality
)
2509 case DW_VIRTUALITY_virtual
:
2510 case DW_VIRTUALITY_pure_virtual
:
2511 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2515 fip
->fields
= fip
->fields
->next
;
2519 /* Add a member function to the proper fieldlist. */
2522 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2523 struct type
*type
, struct objfile
*objfile
,
2524 const struct comp_unit_head
*cu_header
)
2526 struct attribute
*attr
;
2527 struct fnfieldlist
*flp
;
2529 struct fn_field
*fnp
;
2532 struct nextfnfield
*new_fnfield
;
2534 /* Get name of member function. */
2535 attr
= dwarf_attr (die
, DW_AT_name
);
2536 if (attr
&& DW_STRING (attr
))
2537 fieldname
= DW_STRING (attr
);
2541 /* Get the mangled name. */
2542 physname
= dwarf2_linkage_name (die
);
2544 /* Look up member function name in fieldlist. */
2545 for (i
= 0; i
< fip
->nfnfields
; i
++)
2547 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2551 /* Create new list element if necessary. */
2552 if (i
< fip
->nfnfields
)
2553 flp
= &fip
->fnfieldlists
[i
];
2556 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2558 fip
->fnfieldlists
= (struct fnfieldlist
*)
2559 xrealloc (fip
->fnfieldlists
,
2560 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2561 * sizeof (struct fnfieldlist
));
2562 if (fip
->nfnfields
== 0)
2563 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2565 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2566 flp
->name
= fieldname
;
2572 /* Create a new member function field and chain it to the field list
2574 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2575 make_cleanup (xfree
, new_fnfield
);
2576 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2577 new_fnfield
->next
= flp
->head
;
2578 flp
->head
= new_fnfield
;
2581 /* Fill in the member function field info. */
2582 fnp
= &new_fnfield
->fnfield
;
2583 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2584 &objfile
->type_obstack
);
2585 fnp
->type
= alloc_type (objfile
);
2586 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2588 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2589 int nparams
= TYPE_NFIELDS (die
->type
);
2591 /* TYPE is the domain of this method, and DIE->TYPE is the type
2592 of the method itself (TYPE_CODE_METHOD). */
2593 smash_to_method_type (fnp
->type
, type
,
2594 TYPE_TARGET_TYPE (die
->type
),
2595 TYPE_FIELDS (die
->type
),
2596 TYPE_NFIELDS (die
->type
),
2597 TYPE_VARARGS (die
->type
));
2599 /* Handle static member functions.
2600 Dwarf2 has no clean way to discern C++ static and non-static
2601 member functions. G++ helps GDB by marking the first
2602 parameter for non-static member functions (which is the
2603 this pointer) as artificial. We obtain this information
2604 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2605 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2606 fnp
->voffset
= VOFFSET_STATIC
;
2609 complaint (&symfile_complaints
, "member function type missing for '%s'",
2612 /* Get fcontext from DW_AT_containing_type if present. */
2613 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2614 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2616 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2617 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2619 /* Get accessibility. */
2620 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2623 switch (DW_UNSND (attr
))
2625 case DW_ACCESS_private
:
2626 fnp
->is_private
= 1;
2628 case DW_ACCESS_protected
:
2629 fnp
->is_protected
= 1;
2634 /* Check for artificial methods. */
2635 attr
= dwarf_attr (die
, DW_AT_artificial
);
2636 if (attr
&& DW_UNSND (attr
) != 0)
2637 fnp
->is_artificial
= 1;
2639 /* Get index in virtual function table if it is a virtual member function. */
2640 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2643 /* Support the .debug_loc offsets */
2644 if (attr_form_is_block (attr
))
2646 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2648 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2650 dwarf2_complex_location_expr_complaint ();
2654 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2660 /* Create the vector of member function fields, and attach it to the type. */
2663 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2664 struct objfile
*objfile
)
2666 struct fnfieldlist
*flp
;
2667 int total_length
= 0;
2670 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2671 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2672 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2674 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2676 struct nextfnfield
*nfp
= flp
->head
;
2677 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2680 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2681 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2682 fn_flp
->fn_fields
= (struct fn_field
*)
2683 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2684 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2685 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2687 total_length
+= flp
->length
;
2690 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2691 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2694 /* Called when we find the DIE that starts a structure or union scope
2695 (definition) to process all dies that define the members of the
2698 NOTE: we need to call struct_type regardless of whether or not the
2699 DIE has an at_name attribute, since it might be an anonymous
2700 structure or union. This gets the type entered into our set of
2703 However, if the structure is incomplete (an opaque struct/union)
2704 then suppress creating a symbol table entry for it since gdb only
2705 wants to find the one with the complete definition. Note that if
2706 it is complete, we just call new_symbol, which does it's own
2707 checking about whether the struct/union is anonymous or not (and
2708 suppresses creating a symbol table entry itself). */
2711 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2712 const struct comp_unit_head
*cu_header
)
2715 struct attribute
*attr
;
2717 type
= alloc_type (objfile
);
2719 INIT_CPLUS_SPECIFIC (type
);
2720 attr
= dwarf_attr (die
, DW_AT_name
);
2721 if (attr
&& DW_STRING (attr
))
2723 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2724 strlen (DW_STRING (attr
)),
2725 &objfile
->type_obstack
);
2728 if (die
->tag
== DW_TAG_structure_type
)
2730 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2732 else if (die
->tag
== DW_TAG_union_type
)
2734 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2738 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2740 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2743 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2746 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2750 TYPE_LENGTH (type
) = 0;
2753 /* We need to add the type field to the die immediately so we don't
2754 infinitely recurse when dealing with pointers to the structure
2755 type within the structure itself. */
2758 if (die
->has_children
&& ! die_is_declaration (die
))
2760 struct field_info fi
;
2761 struct die_info
*child_die
;
2762 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2764 memset (&fi
, 0, sizeof (struct field_info
));
2766 child_die
= die
->next
;
2768 while (child_die
&& child_die
->tag
)
2770 if (child_die
->tag
== DW_TAG_member
2771 || child_die
->tag
== DW_TAG_variable
)
2773 /* NOTE: carlton/2002-11-05: A C++ static data member
2774 should be a DW_TAG_member that is a declaration, but
2775 all versions of G++ as of this writing (so through at
2776 least 3.2.1) incorrectly generate DW_TAG_variable
2777 tags for them instead. */
2778 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2780 else if (child_die
->tag
== DW_TAG_subprogram
)
2782 /* C++ member function. */
2783 process_die (child_die
, objfile
, cu_header
);
2784 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2786 else if (child_die
->tag
== DW_TAG_inheritance
)
2788 /* C++ base class field. */
2789 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2793 process_die (child_die
, objfile
, cu_header
);
2795 child_die
= sibling_die (child_die
);
2798 /* Attach fields and member functions to the type. */
2800 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2803 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2805 /* Get the type which refers to the base class (possibly this
2806 class itself) which contains the vtable pointer for the current
2807 class from the DW_AT_containing_type attribute. */
2809 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2811 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2813 TYPE_VPTR_BASETYPE (type
) = t
;
2816 static const char vptr_name
[] =
2817 {'_', 'v', 'p', 't', 'r', '\0'};
2820 /* Our own class provides vtbl ptr. */
2821 for (i
= TYPE_NFIELDS (t
) - 1;
2822 i
>= TYPE_N_BASECLASSES (t
);
2825 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2827 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2828 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2830 TYPE_VPTR_FIELDNO (type
) = i
;
2835 /* Complain if virtual function table field not found. */
2836 if (i
< TYPE_N_BASECLASSES (t
))
2837 complaint (&symfile_complaints
,
2838 "virtual function table pointer not found when defining class '%s'",
2839 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2844 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2849 new_symbol (die
, type
, objfile
, cu_header
);
2851 do_cleanups (back_to
);
2855 /* No children, must be stub. */
2856 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2860 /* Given a pointer to a die which begins an enumeration, process all
2861 the dies that define the members of the enumeration.
2863 This will be much nicer in draft 6 of the DWARF spec when our
2864 members will be dies instead squished into the DW_AT_element_list
2867 NOTE: We reverse the order of the element list. */
2870 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2871 const struct comp_unit_head
*cu_header
)
2873 struct die_info
*child_die
;
2875 struct field
*fields
;
2876 struct attribute
*attr
;
2879 int unsigned_enum
= 1;
2881 type
= alloc_type (objfile
);
2883 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2884 attr
= dwarf_attr (die
, DW_AT_name
);
2885 if (attr
&& DW_STRING (attr
))
2887 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2888 strlen (DW_STRING (attr
)),
2889 &objfile
->type_obstack
);
2892 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2895 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2899 TYPE_LENGTH (type
) = 0;
2904 if (die
->has_children
)
2906 child_die
= die
->next
;
2907 while (child_die
&& child_die
->tag
)
2909 if (child_die
->tag
!= DW_TAG_enumerator
)
2911 process_die (child_die
, objfile
, cu_header
);
2915 attr
= dwarf_attr (child_die
, DW_AT_name
);
2918 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2919 if (SYMBOL_VALUE (sym
) < 0)
2922 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2924 fields
= (struct field
*)
2926 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2927 * sizeof (struct field
));
2930 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
2931 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2932 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2933 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2934 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
2940 child_die
= sibling_die (child_die
);
2945 TYPE_NFIELDS (type
) = num_fields
;
2946 TYPE_FIELDS (type
) = (struct field
*)
2947 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2948 memcpy (TYPE_FIELDS (type
), fields
,
2949 sizeof (struct field
) * num_fields
);
2953 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2956 new_symbol (die
, type
, objfile
, cu_header
);
2959 /* Extract all information from a DW_TAG_array_type DIE and put it in
2960 the DIE's type field. For now, this only handles one dimensional
2964 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2965 const struct comp_unit_head
*cu_header
)
2967 struct die_info
*child_die
;
2968 struct type
*type
= NULL
;
2969 struct type
*element_type
, *range_type
, *index_type
;
2970 struct type
**range_types
= NULL
;
2971 struct attribute
*attr
;
2973 struct cleanup
*back_to
;
2975 /* Return if we've already decoded this type. */
2981 element_type
= die_type (die
, objfile
, cu_header
);
2983 /* Irix 6.2 native cc creates array types without children for
2984 arrays with unspecified length. */
2985 if (die
->has_children
== 0)
2987 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2988 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2989 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2993 back_to
= make_cleanup (null_cleanup
, NULL
);
2994 child_die
= die
->next
;
2995 while (child_die
&& child_die
->tag
)
2997 if (child_die
->tag
== DW_TAG_subrange_type
)
2999 unsigned int low
, high
;
3001 /* Default bounds to an array with unspecified length. */
3004 if (cu_language
== language_fortran
)
3006 /* FORTRAN implies a lower bound of 1, if not given. */
3010 index_type
= die_type (child_die
, objfile
, cu_header
);
3011 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3014 if (attr
->form
== DW_FORM_sdata
)
3016 low
= DW_SND (attr
);
3018 else if (attr
->form
== DW_FORM_udata
3019 || attr
->form
== DW_FORM_data1
3020 || attr
->form
== DW_FORM_data2
3021 || attr
->form
== DW_FORM_data4
3022 || attr
->form
== DW_FORM_data8
)
3024 low
= DW_UNSND (attr
);
3028 dwarf2_non_const_array_bound_ignored_complaint
3029 (dwarf_form_name (attr
->form
));
3031 die
->type
= lookup_pointer_type (element_type
);
3038 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3041 if (attr
->form
== DW_FORM_sdata
)
3043 high
= DW_SND (attr
);
3045 else if (attr
->form
== DW_FORM_udata
3046 || attr
->form
== DW_FORM_data1
3047 || attr
->form
== DW_FORM_data2
3048 || attr
->form
== DW_FORM_data4
3049 || attr
->form
== DW_FORM_data8
)
3051 high
= DW_UNSND (attr
);
3053 else if (attr
->form
== DW_FORM_block1
)
3055 /* GCC encodes arrays with unspecified or dynamic length
3056 with a DW_FORM_block1 attribute.
3057 FIXME: GDB does not yet know how to handle dynamic
3058 arrays properly, treat them as arrays with unspecified
3064 dwarf2_non_const_array_bound_ignored_complaint
3065 (dwarf_form_name (attr
->form
));
3067 die
->type
= lookup_pointer_type (element_type
);
3075 /* Create a range type and save it for array type creation. */
3076 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3078 range_types
= (struct type
**)
3079 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3080 * sizeof (struct type
*));
3082 make_cleanup (free_current_contents
, &range_types
);
3084 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3086 child_die
= sibling_die (child_die
);
3089 /* Dwarf2 dimensions are output from left to right, create the
3090 necessary array types in backwards order. */
3091 type
= element_type
;
3093 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3095 /* Understand Dwarf2 support for vector types (like they occur on
3096 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3097 array type. This is not part of the Dwarf2/3 standard yet, but a
3098 custom vendor extension. The main difference between a regular
3099 array and the vector variant is that vectors are passed by value
3101 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3103 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3105 do_cleanups (back_to
);
3107 /* Install the type in the die. */
3111 /* First cut: install each common block member as a global variable. */
3114 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
3115 const struct comp_unit_head
*cu_header
)
3117 struct die_info
*child_die
;
3118 struct attribute
*attr
;
3120 CORE_ADDR base
= (CORE_ADDR
) 0;
3122 attr
= dwarf_attr (die
, DW_AT_location
);
3125 /* Support the .debug_loc offsets */
3126 if (attr_form_is_block (attr
))
3128 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3130 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3132 dwarf2_complex_location_expr_complaint ();
3136 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3137 "common block member");
3140 if (die
->has_children
)
3142 child_die
= die
->next
;
3143 while (child_die
&& child_die
->tag
)
3145 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
3146 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3149 SYMBOL_VALUE_ADDRESS (sym
) =
3150 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3151 add_symbol_to_list (sym
, &global_symbols
);
3153 child_die
= sibling_die (child_die
);
3158 /* Read a C++ namespace. */
3160 /* FIXME: carlton/2002-10-16: For now, we don't actually do anything
3161 useful with the namespace data: we just process its children. */
3164 read_namespace (struct die_info
*die
, struct objfile
*objfile
,
3165 const struct comp_unit_head
*cu_header
)
3167 if (die
->has_children
)
3169 struct die_info
*child_die
= die
->next
;
3171 while (child_die
&& child_die
->tag
)
3173 process_die (child_die
, objfile
, cu_header
);
3174 child_die
= sibling_die (child_die
);
3179 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3180 the user defined type vector. */
3183 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
3184 const struct comp_unit_head
*cu_header
)
3187 struct attribute
*attr_byte_size
;
3188 struct attribute
*attr_address_class
;
3189 int byte_size
, addr_class
;
3196 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
3198 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3200 byte_size
= DW_UNSND (attr_byte_size
);
3202 byte_size
= cu_header
->addr_size
;
3204 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3205 if (attr_address_class
)
3206 addr_class
= DW_UNSND (attr_address_class
);
3208 addr_class
= DW_ADDR_none
;
3210 /* If the pointer size or address class is different than the
3211 default, create a type variant marked as such and set the
3212 length accordingly. */
3213 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3215 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3219 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3220 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3221 type
= make_type_with_address_space (type
, type_flags
);
3223 else if (TYPE_LENGTH (type
) != byte_size
)
3225 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3228 /* Should we also complain about unhandled address classes? */
3232 TYPE_LENGTH (type
) = byte_size
;
3236 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3237 the user defined type vector. */
3240 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
3241 const struct comp_unit_head
*cu_header
)
3244 struct type
*to_type
;
3245 struct type
*domain
;
3252 type
= alloc_type (objfile
);
3253 to_type
= die_type (die
, objfile
, cu_header
);
3254 domain
= die_containing_type (die
, objfile
, cu_header
);
3255 smash_to_member_type (type
, domain
, to_type
);
3260 /* Extract all information from a DW_TAG_reference_type DIE and add to
3261 the user defined type vector. */
3264 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
3265 const struct comp_unit_head
*cu_header
)
3268 struct attribute
*attr
;
3275 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
3276 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3279 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3283 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3289 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
3290 const struct comp_unit_head
*cu_header
)
3292 struct type
*base_type
;
3299 base_type
= die_type (die
, objfile
, cu_header
);
3300 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3304 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
3305 const struct comp_unit_head
*cu_header
)
3307 struct type
*base_type
;
3314 base_type
= die_type (die
, objfile
, cu_header
);
3315 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3318 /* Extract all information from a DW_TAG_string_type DIE and add to
3319 the user defined type vector. It isn't really a user defined type,
3320 but it behaves like one, with other DIE's using an AT_user_def_type
3321 attribute to reference it. */
3324 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3326 struct type
*type
, *range_type
, *index_type
, *char_type
;
3327 struct attribute
*attr
;
3328 unsigned int length
;
3335 attr
= dwarf_attr (die
, DW_AT_string_length
);
3338 length
= DW_UNSND (attr
);
3342 /* check for the DW_AT_byte_size attribute */
3343 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3346 length
= DW_UNSND (attr
);
3353 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3354 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3355 if (cu_language
== language_fortran
)
3357 /* Need to create a unique string type for bounds
3359 type
= create_string_type (0, range_type
);
3363 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3364 type
= create_string_type (char_type
, range_type
);
3369 /* Handle DIES due to C code like:
3373 int (*funcp)(int a, long l);
3377 ('funcp' generates a DW_TAG_subroutine_type DIE)
3381 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3382 const struct comp_unit_head
*cu_header
)
3384 struct type
*type
; /* Type that this function returns */
3385 struct type
*ftype
; /* Function that returns above type */
3386 struct attribute
*attr
;
3388 /* Decode the type that this subroutine returns */
3393 type
= die_type (die
, objfile
, cu_header
);
3394 ftype
= lookup_function_type (type
);
3396 /* All functions in C++ have prototypes. */
3397 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3398 if ((attr
&& (DW_UNSND (attr
) != 0))
3399 || cu_language
== language_cplus
)
3400 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3402 if (die
->has_children
)
3404 struct die_info
*child_die
;
3408 /* Count the number of parameters.
3409 FIXME: GDB currently ignores vararg functions, but knows about
3410 vararg member functions. */
3411 child_die
= die
->next
;
3412 while (child_die
&& child_die
->tag
)
3414 if (child_die
->tag
== DW_TAG_formal_parameter
)
3416 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3417 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3418 child_die
= sibling_die (child_die
);
3421 /* Allocate storage for parameters and fill them in. */
3422 TYPE_NFIELDS (ftype
) = nparams
;
3423 TYPE_FIELDS (ftype
) = (struct field
*)
3424 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3426 child_die
= die
->next
;
3427 while (child_die
&& child_die
->tag
)
3429 if (child_die
->tag
== DW_TAG_formal_parameter
)
3431 /* Dwarf2 has no clean way to discern C++ static and non-static
3432 member functions. G++ helps GDB by marking the first
3433 parameter for non-static member functions (which is the
3434 this pointer) as artificial. We pass this information
3435 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3436 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3438 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3440 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3441 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3445 child_die
= sibling_die (child_die
);
3453 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3454 const struct comp_unit_head
*cu_header
)
3456 struct attribute
*attr
;
3461 attr
= dwarf_attr (die
, DW_AT_name
);
3462 if (attr
&& DW_STRING (attr
))
3464 name
= DW_STRING (attr
);
3466 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3467 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3471 /* Find a representation of a given base type and install
3472 it in the TYPE field of the die. */
3475 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3478 struct attribute
*attr
;
3479 int encoding
= 0, size
= 0;
3481 /* If we've already decoded this die, this is a no-op. */
3487 attr
= dwarf_attr (die
, DW_AT_encoding
);
3490 encoding
= DW_UNSND (attr
);
3492 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3495 size
= DW_UNSND (attr
);
3497 attr
= dwarf_attr (die
, DW_AT_name
);
3498 if (attr
&& DW_STRING (attr
))
3500 enum type_code code
= TYPE_CODE_INT
;
3505 case DW_ATE_address
:
3506 /* Turn DW_ATE_address into a void * pointer. */
3507 code
= TYPE_CODE_PTR
;
3508 type_flags
|= TYPE_FLAG_UNSIGNED
;
3510 case DW_ATE_boolean
:
3511 code
= TYPE_CODE_BOOL
;
3512 type_flags
|= TYPE_FLAG_UNSIGNED
;
3514 case DW_ATE_complex_float
:
3515 code
= TYPE_CODE_COMPLEX
;
3518 code
= TYPE_CODE_FLT
;
3521 case DW_ATE_signed_char
:
3523 case DW_ATE_unsigned
:
3524 case DW_ATE_unsigned_char
:
3525 type_flags
|= TYPE_FLAG_UNSIGNED
;
3528 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3529 dwarf_type_encoding_name (encoding
));
3532 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3533 if (encoding
== DW_ATE_address
)
3534 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3535 else if (encoding
== DW_ATE_complex_float
)
3538 TYPE_TARGET_TYPE (type
)
3539 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3540 else if (size
== 16)
3541 TYPE_TARGET_TYPE (type
)
3542 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3544 TYPE_TARGET_TYPE (type
)
3545 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3550 type
= dwarf_base_type (encoding
, size
, objfile
);
3555 /* Read a whole compilation unit into a linked list of dies. */
3557 static struct die_info
*
3558 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3559 const struct comp_unit_head
*cu_header
)
3561 struct die_info
*first_die
, *last_die
, *die
;
3565 /* Reset die reference table; we are
3566 building new ones now. */
3567 dwarf2_empty_hash_tables ();
3571 first_die
= last_die
= NULL
;
3574 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3575 if (die
->has_children
)
3586 /* Enter die in reference hash table */
3587 store_in_ref_table (die
->offset
, die
);
3591 first_die
= last_die
= die
;
3595 last_die
->next
= die
;
3599 while (nesting_level
> 0);
3603 /* Free a linked list of dies. */
3606 free_die_list (struct die_info
*dies
)
3608 struct die_info
*die
, *next
;
3621 do_free_die_list_cleanup (void *dies
)
3623 free_die_list (dies
);
3626 static struct cleanup
*
3627 make_cleanup_free_die_list (struct die_info
*dies
)
3629 return make_cleanup (do_free_die_list_cleanup
, dies
);
3633 /* Read the contents of the section at OFFSET and of size SIZE from the
3634 object file specified by OBJFILE into the psymbol_obstack and return it. */
3637 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3638 unsigned int size
, asection
*sectp
)
3640 bfd
*abfd
= objfile
->obfd
;
3646 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3648 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3652 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3653 (bfd_bread (buf
, size
, abfd
) != size
))
3656 error ("Dwarf Error: Can't read DWARF data from '%s'",
3657 bfd_get_filename (abfd
));
3662 /* In DWARF version 2, the description of the debugging information is
3663 stored in a separate .debug_abbrev section. Before we read any
3664 dies from a section we read in all abbreviations and install them
3668 dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
)
3671 struct abbrev_info
*cur_abbrev
;
3672 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3673 unsigned int abbrev_form
, hash_number
;
3675 /* Initialize dwarf2 abbrevs */
3676 memset (cu_header
->dwarf2_abbrevs
, 0,
3677 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3679 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3680 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3681 abbrev_ptr
+= bytes_read
;
3683 /* loop until we reach an abbrev number of 0 */
3684 while (abbrev_number
)
3686 cur_abbrev
= dwarf_alloc_abbrev ();
3688 /* read in abbrev header */
3689 cur_abbrev
->number
= abbrev_number
;
3690 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3691 abbrev_ptr
+= bytes_read
;
3692 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3695 /* now read in declarations */
3696 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3697 abbrev_ptr
+= bytes_read
;
3698 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3699 abbrev_ptr
+= bytes_read
;
3702 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3704 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3705 xrealloc (cur_abbrev
->attrs
,
3706 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3707 * sizeof (struct attr_abbrev
));
3709 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3710 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3711 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3712 abbrev_ptr
+= bytes_read
;
3713 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3714 abbrev_ptr
+= bytes_read
;
3717 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3718 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3719 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3721 /* Get next abbreviation.
3722 Under Irix6 the abbreviations for a compilation unit are not
3723 always properly terminated with an abbrev number of 0.
3724 Exit loop if we encounter an abbreviation which we have
3725 already read (which means we are about to read the abbreviations
3726 for the next compile unit) or if the end of the abbreviation
3727 table is reached. */
3728 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3729 >= dwarf_abbrev_size
)
3731 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3732 abbrev_ptr
+= bytes_read
;
3733 if (dwarf2_lookup_abbrev (abbrev_number
, cu_header
) != NULL
)
3738 /* Empty the abbrev table for a new compilation unit. */
3742 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3745 struct abbrev_info
*abbrev
, *next
;
3746 struct abbrev_info
**abbrevs
;
3748 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3750 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3753 abbrev
= abbrevs
[i
];
3756 next
= abbrev
->next
;
3757 xfree (abbrev
->attrs
);
3765 /* Lookup an abbrev_info structure in the abbrev hash table. */
3767 static struct abbrev_info
*
3768 dwarf2_lookup_abbrev (unsigned int number
, const struct comp_unit_head
*cu_header
)
3770 unsigned int hash_number
;
3771 struct abbrev_info
*abbrev
;
3773 hash_number
= number
% ABBREV_HASH_SIZE
;
3774 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3778 if (abbrev
->number
== number
)
3781 abbrev
= abbrev
->next
;
3786 /* Read a minimal amount of information into the minimal die structure. */
3789 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3790 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3792 unsigned int abbrev_number
, bytes_read
, i
;
3793 struct abbrev_info
*abbrev
;
3794 struct attribute attr
;
3795 struct attribute spec_attr
;
3796 int found_spec_attr
= 0;
3797 int has_low_pc_attr
= 0;
3798 int has_high_pc_attr
= 0;
3800 *part_die
= zeroed_partial_die
;
3801 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3802 info_ptr
+= bytes_read
;
3806 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3809 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
3810 bfd_get_filename (abfd
));
3812 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3813 part_die
->tag
= abbrev
->tag
;
3814 part_die
->has_children
= abbrev
->has_children
;
3815 part_die
->abbrev
= abbrev_number
;
3817 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3819 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3820 info_ptr
, cu_header
);
3822 /* Store the data if it is of an attribute we want to keep in a
3823 partial symbol table. */
3828 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3829 if (part_die
->name
== NULL
)
3830 part_die
->name
= DW_STRING (&attr
);
3832 case DW_AT_MIPS_linkage_name
:
3833 part_die
->name
= DW_STRING (&attr
);
3836 has_low_pc_attr
= 1;
3837 part_die
->lowpc
= DW_ADDR (&attr
);
3840 has_high_pc_attr
= 1;
3841 part_die
->highpc
= DW_ADDR (&attr
);
3843 case DW_AT_location
:
3844 /* Support the .debug_loc offsets */
3845 if (attr_form_is_block (&attr
))
3847 part_die
->locdesc
= DW_BLOCK (&attr
);
3849 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
3851 dwarf2_complex_location_expr_complaint ();
3855 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3856 "partial symbol information");
3859 case DW_AT_language
:
3860 part_die
->language
= DW_UNSND (&attr
);
3862 case DW_AT_external
:
3863 part_die
->is_external
= DW_UNSND (&attr
);
3865 case DW_AT_declaration
:
3866 part_die
->is_declaration
= DW_UNSND (&attr
);
3869 part_die
->has_type
= 1;
3871 case DW_AT_abstract_origin
:
3872 case DW_AT_specification
:
3873 found_spec_attr
= 1;
3877 /* Ignore absolute siblings, they might point outside of
3878 the current compile unit. */
3879 if (attr
.form
== DW_FORM_ref_addr
)
3880 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
3883 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3890 /* If we found a reference attribute and the die has no name, try
3891 to find a name in the referred to die. */
3893 if (found_spec_attr
&& part_die
->name
== NULL
)
3895 struct partial_die_info spec_die
;
3899 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3900 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3903 part_die
->name
= spec_die
.name
;
3905 /* Copy DW_AT_external attribute if it is set. */
3906 if (spec_die
.is_external
)
3907 part_die
->is_external
= spec_die
.is_external
;
3911 /* When using the GNU linker, .gnu.linkonce. sections are used to
3912 eliminate duplicate copies of functions and vtables and such.
3913 The linker will arbitrarily choose one and discard the others.
3914 The AT_*_pc values for such functions refer to local labels in
3915 these sections. If the section from that file was discarded, the
3916 labels are not in the output, so the relocs get a value of 0.
3917 If this is a discarded function, mark the pc bounds as invalid,
3918 so that GDB will ignore it. */
3919 if (has_low_pc_attr
&& has_high_pc_attr
3920 && part_die
->lowpc
< part_die
->highpc
3921 && (part_die
->lowpc
!= 0
3922 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3923 part_die
->has_pc_info
= 1;
3927 /* Read the die from the .debug_info section buffer. And set diep to
3928 point to a newly allocated die with its information. */
3931 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3932 const struct comp_unit_head
*cu_header
)
3934 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3935 struct abbrev_info
*abbrev
;
3936 struct die_info
*die
;
3938 offset
= info_ptr
- dwarf_info_buffer
;
3939 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3940 info_ptr
+= bytes_read
;
3943 die
= dwarf_alloc_die ();
3945 die
->abbrev
= abbrev_number
;
3951 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3954 error ("Dwarf Error: could not find abbrev number %d [in module %s]", abbrev_number
,
3955 bfd_get_filename (abfd
));
3957 die
= dwarf_alloc_die ();
3958 die
->offset
= offset
;
3959 die
->tag
= abbrev
->tag
;
3960 die
->has_children
= abbrev
->has_children
;
3961 die
->abbrev
= abbrev_number
;
3964 die
->num_attrs
= abbrev
->num_attrs
;
3965 die
->attrs
= (struct attribute
*)
3966 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3968 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3970 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3971 abfd
, info_ptr
, cu_header
);
3978 /* Read an attribute value described by an attribute form. */
3981 read_attribute_value (struct attribute
*attr
, unsigned form
,
3982 bfd
*abfd
, char *info_ptr
,
3983 const struct comp_unit_head
*cu_header
)
3985 unsigned int bytes_read
;
3986 struct dwarf_block
*blk
;
3992 case DW_FORM_ref_addr
:
3993 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3994 info_ptr
+= bytes_read
;
3996 case DW_FORM_block2
:
3997 blk
= dwarf_alloc_block ();
3998 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4000 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4001 info_ptr
+= blk
->size
;
4002 DW_BLOCK (attr
) = blk
;
4004 case DW_FORM_block4
:
4005 blk
= dwarf_alloc_block ();
4006 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4008 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4009 info_ptr
+= blk
->size
;
4010 DW_BLOCK (attr
) = blk
;
4013 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4017 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4021 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4024 case DW_FORM_string
:
4025 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4026 info_ptr
+= bytes_read
;
4029 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4031 info_ptr
+= bytes_read
;
4034 blk
= dwarf_alloc_block ();
4035 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4036 info_ptr
+= bytes_read
;
4037 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4038 info_ptr
+= blk
->size
;
4039 DW_BLOCK (attr
) = blk
;
4041 case DW_FORM_block1
:
4042 blk
= dwarf_alloc_block ();
4043 blk
->size
= read_1_byte (abfd
, info_ptr
);
4045 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4046 info_ptr
+= blk
->size
;
4047 DW_BLOCK (attr
) = blk
;
4050 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4054 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4058 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4059 info_ptr
+= bytes_read
;
4062 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4063 info_ptr
+= bytes_read
;
4066 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4070 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4074 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4078 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4081 case DW_FORM_ref_udata
:
4082 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4083 info_ptr
+= bytes_read
;
4085 case DW_FORM_indirect
:
4086 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4087 info_ptr
+= bytes_read
;
4088 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
4091 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4092 dwarf_form_name (form
),
4093 bfd_get_filename (abfd
));
4098 /* Read an attribute described by an abbreviated attribute. */
4101 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4102 bfd
*abfd
, char *info_ptr
,
4103 const struct comp_unit_head
*cu_header
)
4105 attr
->name
= abbrev
->name
;
4106 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
4109 /* read dwarf information from a buffer */
4112 read_1_byte (bfd
*abfd
, char *buf
)
4114 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4118 read_1_signed_byte (bfd
*abfd
, char *buf
)
4120 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4124 read_2_bytes (bfd
*abfd
, char *buf
)
4126 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4130 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4132 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4136 read_4_bytes (bfd
*abfd
, char *buf
)
4138 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4142 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4144 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4147 static unsigned long
4148 read_8_bytes (bfd
*abfd
, char *buf
)
4150 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4154 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4157 CORE_ADDR retval
= 0;
4159 if (cu_header
->signed_addr_p
)
4161 switch (cu_header
->addr_size
)
4164 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4167 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4170 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4173 internal_error (__FILE__
, __LINE__
,
4174 "read_address: bad switch, signed [in module %s]",
4175 bfd_get_filename (abfd
));
4180 switch (cu_header
->addr_size
)
4183 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4186 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4189 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4192 internal_error (__FILE__
, __LINE__
,
4193 "read_address: bad switch, unsigned [in module %s]",
4194 bfd_get_filename (abfd
));
4198 *bytes_read
= cu_header
->addr_size
;
4202 /* Read the initial length from a section. The (draft) DWARF 3
4203 specification allows the initial length to take up either 4 bytes
4204 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4205 bytes describe the length and all offsets will be 8 bytes in length
4208 An older, non-standard 64-bit format is also handled by this
4209 function. The older format in question stores the initial length
4210 as an 8-byte quantity without an escape value. Lengths greater
4211 than 2^32 aren't very common which means that the initial 4 bytes
4212 is almost always zero. Since a length value of zero doesn't make
4213 sense for the 32-bit format, this initial zero can be considered to
4214 be an escape value which indicates the presence of the older 64-bit
4215 format. As written, the code can't detect (old format) lengths
4216 greater than 4GB. If it becomes necessary to handle lengths somewhat
4217 larger than 4GB, we could allow other small values (such as the
4218 non-sensical values of 1, 2, and 3) to also be used as escape values
4219 indicating the presence of the old format.
4221 The value returned via bytes_read should be used to increment
4222 the relevant pointer after calling read_initial_length().
4224 As a side effect, this function sets the fields initial_length_size
4225 and offset_size in cu_header to the values appropriate for the
4226 length field. (The format of the initial length field determines
4227 the width of file offsets to be fetched later with fetch_offset().)
4229 [ Note: read_initial_length() and read_offset() are based on the
4230 document entitled "DWARF Debugging Information Format", revision
4231 3, draft 8, dated November 19, 2001. This document was obtained
4234 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4236 This document is only a draft and is subject to change. (So beware.)
4238 Details regarding the older, non-standard 64-bit format were
4239 determined empirically by examining 64-bit ELF files produced
4240 by the SGI toolchain on an IRIX 6.5 machine.
4242 - Kevin, July 16, 2002
4246 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4251 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4253 if (retval
== 0xffffffff)
4255 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4257 if (cu_header
!= NULL
)
4259 cu_header
->initial_length_size
= 12;
4260 cu_header
->offset_size
= 8;
4263 else if (retval
== 0)
4265 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4267 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4269 if (cu_header
!= NULL
)
4271 cu_header
->initial_length_size
= 8;
4272 cu_header
->offset_size
= 8;
4278 if (cu_header
!= NULL
)
4280 cu_header
->initial_length_size
= 4;
4281 cu_header
->offset_size
= 4;
4288 /* Read an offset from the data stream. The size of the offset is
4289 given by cu_header->offset_size. */
4292 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4297 switch (cu_header
->offset_size
)
4300 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4304 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4308 internal_error (__FILE__
, __LINE__
,
4309 "read_offset: bad switch [in module %s]",
4310 bfd_get_filename (abfd
));
4317 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4319 /* If the size of a host char is 8 bits, we can return a pointer
4320 to the buffer, otherwise we have to copy the data to a buffer
4321 allocated on the temporary obstack. */
4322 gdb_assert (HOST_CHAR_BIT
== 8);
4327 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4329 /* If the size of a host char is 8 bits, we can return a pointer
4330 to the string, otherwise we have to copy the string to a buffer
4331 allocated on the temporary obstack. */
4332 gdb_assert (HOST_CHAR_BIT
== 8);
4335 *bytes_read_ptr
= 1;
4338 *bytes_read_ptr
= strlen (buf
) + 1;
4343 read_indirect_string (bfd
*abfd
, char *buf
,
4344 const struct comp_unit_head
*cu_header
,
4345 unsigned int *bytes_read_ptr
)
4347 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4348 (int *) bytes_read_ptr
);
4350 if (dwarf_str_buffer
== NULL
)
4352 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4353 bfd_get_filename (abfd
));
4356 if (str_offset
>= dwarf_str_size
)
4358 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4359 bfd_get_filename (abfd
));
4362 gdb_assert (HOST_CHAR_BIT
== 8);
4363 if (dwarf_str_buffer
[str_offset
] == '\0')
4365 return dwarf_str_buffer
+ str_offset
;
4368 static unsigned long
4369 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4371 unsigned long result
;
4372 unsigned int num_read
;
4382 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4385 result
|= ((unsigned long)(byte
& 127) << shift
);
4386 if ((byte
& 128) == 0)
4392 *bytes_read_ptr
= num_read
;
4397 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4400 int i
, shift
, size
, num_read
;
4410 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4413 result
|= ((long)(byte
& 127) << shift
);
4415 if ((byte
& 128) == 0)
4420 if ((shift
< size
) && (byte
& 0x40))
4422 result
|= -(1 << shift
);
4424 *bytes_read_ptr
= num_read
;
4429 set_cu_language (unsigned int lang
)
4435 cu_language
= language_c
;
4437 case DW_LANG_C_plus_plus
:
4438 cu_language
= language_cplus
;
4440 case DW_LANG_Fortran77
:
4441 case DW_LANG_Fortran90
:
4442 case DW_LANG_Fortran95
:
4443 cu_language
= language_fortran
;
4445 case DW_LANG_Mips_Assembler
:
4446 cu_language
= language_asm
;
4449 cu_language
= language_java
;
4453 case DW_LANG_Cobol74
:
4454 case DW_LANG_Cobol85
:
4455 case DW_LANG_Pascal83
:
4456 case DW_LANG_Modula2
:
4458 cu_language
= language_unknown
;
4461 cu_language_defn
= language_def (cu_language
);
4464 /* Return the named attribute or NULL if not there. */
4466 static struct attribute
*
4467 dwarf_attr (struct die_info
*die
, unsigned int name
)
4470 struct attribute
*spec
= NULL
;
4472 for (i
= 0; i
< die
->num_attrs
; ++i
)
4474 if (die
->attrs
[i
].name
== name
)
4476 return &die
->attrs
[i
];
4478 if (die
->attrs
[i
].name
== DW_AT_specification
4479 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4480 spec
= &die
->attrs
[i
];
4484 struct die_info
*ref_die
=
4485 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4488 return dwarf_attr (ref_die
, name
);
4495 die_is_declaration (struct die_info
*die
)
4497 return (dwarf_attr (die
, DW_AT_declaration
)
4498 && ! dwarf_attr (die
, DW_AT_specification
));
4502 /* Free the line_header structure *LH, and any arrays and strings it
4505 free_line_header (struct line_header
*lh
)
4507 if (lh
->standard_opcode_lengths
)
4508 xfree (lh
->standard_opcode_lengths
);
4510 /* Remember that all the lh->file_names[i].name pointers are
4511 pointers into debug_line_buffer, and don't need to be freed. */
4513 xfree (lh
->file_names
);
4515 /* Similarly for the include directory names. */
4516 if (lh
->include_dirs
)
4517 xfree (lh
->include_dirs
);
4523 /* Add an entry to LH's include directory table. */
4525 add_include_dir (struct line_header
*lh
, char *include_dir
)
4527 /* Grow the array if necessary. */
4528 if (lh
->include_dirs_size
== 0)
4530 lh
->include_dirs_size
= 1; /* for testing */
4531 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4532 * sizeof (*lh
->include_dirs
));
4534 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4536 lh
->include_dirs_size
*= 2;
4537 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4538 (lh
->include_dirs_size
4539 * sizeof (*lh
->include_dirs
)));
4542 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4546 /* Add an entry to LH's file name table. */
4548 add_file_name (struct line_header
*lh
,
4550 unsigned int dir_index
,
4551 unsigned int mod_time
,
4552 unsigned int length
)
4554 struct file_entry
*fe
;
4556 /* Grow the array if necessary. */
4557 if (lh
->file_names_size
== 0)
4559 lh
->file_names_size
= 1; /* for testing */
4560 lh
->file_names
= xmalloc (lh
->file_names_size
4561 * sizeof (*lh
->file_names
));
4563 else if (lh
->num_file_names
>= lh
->file_names_size
)
4565 lh
->file_names_size
*= 2;
4566 lh
->file_names
= xrealloc (lh
->file_names
,
4567 (lh
->file_names_size
4568 * sizeof (*lh
->file_names
)));
4571 fe
= &lh
->file_names
[lh
->num_file_names
++];
4573 fe
->dir_index
= dir_index
;
4574 fe
->mod_time
= mod_time
;
4575 fe
->length
= length
;
4579 /* Read the statement program header starting at OFFSET in
4580 dwarf_line_buffer, according to the endianness of ABFD. Return a
4581 pointer to a struct line_header, allocated using xmalloc.
4583 NOTE: the strings in the include directory and file name tables of
4584 the returned object point into debug_line_buffer, and must not be
4586 static struct line_header
*
4587 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4588 const struct comp_unit_head
*cu_header
)
4590 struct cleanup
*back_to
;
4591 struct line_header
*lh
;
4595 char *cur_dir
, *cur_file
;
4597 if (dwarf_line_buffer
== NULL
)
4599 complaint (&symfile_complaints
, "missing .debug_line section");
4603 /* Make sure that at least there's room for the total_length field. That
4604 could be 12 bytes long, but we're just going to fudge that. */
4605 if (offset
+ 4 >= dwarf_line_size
)
4607 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4611 lh
= xmalloc (sizeof (*lh
));
4612 memset (lh
, 0, sizeof (*lh
));
4613 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4616 line_ptr
= dwarf_line_buffer
+ offset
;
4618 /* read in the header */
4619 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4620 line_ptr
+= bytes_read
;
4621 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4623 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4626 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4627 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4629 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4630 line_ptr
+= bytes_read
;
4631 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4633 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4635 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4637 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4639 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4641 lh
->standard_opcode_lengths
4642 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4644 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4645 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4647 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4651 /* Read directory table */
4652 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4654 line_ptr
+= bytes_read
;
4655 add_include_dir (lh
, cur_dir
);
4657 line_ptr
+= bytes_read
;
4659 /* Read file name table */
4660 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4662 unsigned int dir_index
, mod_time
, length
;
4664 line_ptr
+= bytes_read
;
4665 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4666 line_ptr
+= bytes_read
;
4667 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4668 line_ptr
+= bytes_read
;
4669 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4670 line_ptr
+= bytes_read
;
4672 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4674 line_ptr
+= bytes_read
;
4675 lh
->statement_program_start
= line_ptr
;
4677 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4678 complaint (&symfile_complaints
,
4679 "line number info header doesn't fit in `.debug_line' section");
4681 discard_cleanups (back_to
);
4685 /* This function exists to work around a bug in certain compilers
4686 (particularly GCC 2.95), in which the first line number marker of a
4687 function does not show up until after the prologue, right before
4688 the second line number marker. This function shifts ADDRESS down
4689 to the beginning of the function if necessary, and is called on
4690 addresses passed to record_line. */
4693 check_cu_functions (CORE_ADDR address
)
4695 struct function_range
*fn
;
4697 /* Find the function_range containing address. */
4702 cu_cached_fn
= cu_first_fn
;
4706 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4712 while (fn
&& fn
!= cu_cached_fn
)
4713 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4723 if (address
!= fn
->lowpc
)
4724 complaint (&symfile_complaints
,
4725 "misplaced first line number at 0x%lx for '%s'",
4726 (unsigned long) address
, fn
->name
);
4731 /* Decode the line number information for the compilation unit whose
4732 line number info is at OFFSET in the .debug_line section.
4733 The compilation directory of the file is passed in COMP_DIR. */
4736 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4737 const struct comp_unit_head
*cu_header
)
4741 unsigned int i
, bytes_read
;
4743 unsigned char op_code
, extended_op
, adj_opcode
;
4745 line_ptr
= lh
->statement_program_start
;
4746 line_end
= lh
->statement_program_end
;
4748 /* Read the statement sequences until there's nothing left. */
4749 while (line_ptr
< line_end
)
4751 /* state machine registers */
4752 CORE_ADDR address
= 0;
4753 unsigned int file
= 1;
4754 unsigned int line
= 1;
4755 unsigned int column
= 0;
4756 int is_stmt
= lh
->default_is_stmt
;
4757 int basic_block
= 0;
4758 int end_sequence
= 0;
4760 /* Start a subfile for the current file of the state machine. */
4761 if (lh
->num_file_names
>= file
)
4763 /* lh->include_dirs and lh->file_names are 0-based, but the
4764 directory and file name numbers in the statement program
4766 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4769 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4772 dwarf2_start_subfile (fe
->name
, dir
);
4775 /* Decode the table. */
4776 while (!end_sequence
)
4778 op_code
= read_1_byte (abfd
, line_ptr
);
4781 if (op_code
>= lh
->opcode_base
)
4782 { /* Special operand. */
4783 adj_opcode
= op_code
- lh
->opcode_base
;
4784 address
+= (adj_opcode
/ lh
->line_range
)
4785 * lh
->minimum_instruction_length
;
4786 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4787 /* append row to matrix using current values */
4788 address
= check_cu_functions (address
);
4789 record_line (current_subfile
, line
, address
);
4792 else switch (op_code
)
4794 case DW_LNS_extended_op
:
4795 line_ptr
+= 1; /* ignore length */
4796 extended_op
= read_1_byte (abfd
, line_ptr
);
4798 switch (extended_op
)
4800 case DW_LNE_end_sequence
:
4802 record_line (current_subfile
, 0, address
);
4804 case DW_LNE_set_address
:
4805 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4806 line_ptr
+= bytes_read
;
4807 address
+= baseaddr
;
4809 case DW_LNE_define_file
:
4812 unsigned int dir_index
, mod_time
, length
;
4814 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4815 line_ptr
+= bytes_read
;
4817 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4818 line_ptr
+= bytes_read
;
4820 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4821 line_ptr
+= bytes_read
;
4823 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4824 line_ptr
+= bytes_read
;
4825 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4829 complaint (&symfile_complaints
,
4830 "mangled .debug_line section");
4835 address
= check_cu_functions (address
);
4836 record_line (current_subfile
, line
, address
);
4839 case DW_LNS_advance_pc
:
4840 address
+= lh
->minimum_instruction_length
4841 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4842 line_ptr
+= bytes_read
;
4844 case DW_LNS_advance_line
:
4845 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4846 line_ptr
+= bytes_read
;
4848 case DW_LNS_set_file
:
4850 /* lh->include_dirs and lh->file_names are 0-based,
4851 but the directory and file name numbers in the
4852 statement program are 1-based. */
4853 struct file_entry
*fe
;
4855 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4856 line_ptr
+= bytes_read
;
4857 fe
= &lh
->file_names
[file
- 1];
4859 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4862 dwarf2_start_subfile (fe
->name
, dir
);
4865 case DW_LNS_set_column
:
4866 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4867 line_ptr
+= bytes_read
;
4869 case DW_LNS_negate_stmt
:
4870 is_stmt
= (!is_stmt
);
4872 case DW_LNS_set_basic_block
:
4875 /* Add to the address register of the state machine the
4876 address increment value corresponding to special opcode
4877 255. Ie, this value is scaled by the minimum instruction
4878 length since special opcode 255 would have scaled the
4880 case DW_LNS_const_add_pc
:
4881 address
+= (lh
->minimum_instruction_length
4882 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4884 case DW_LNS_fixed_advance_pc
:
4885 address
+= read_2_bytes (abfd
, line_ptr
);
4889 { /* Unknown standard opcode, ignore it. */
4891 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4893 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4894 line_ptr
+= bytes_read
;
4902 /* Start a subfile for DWARF. FILENAME is the name of the file and
4903 DIRNAME the name of the source directory which contains FILENAME
4904 or NULL if not known.
4905 This routine tries to keep line numbers from identical absolute and
4906 relative file names in a common subfile.
4908 Using the `list' example from the GDB testsuite, which resides in
4909 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4910 of /srcdir/list0.c yields the following debugging information for list0.c:
4912 DW_AT_name: /srcdir/list0.c
4913 DW_AT_comp_dir: /compdir
4914 files.files[0].name: list0.h
4915 files.files[0].dir: /srcdir
4916 files.files[1].name: list0.c
4917 files.files[1].dir: /srcdir
4919 The line number information for list0.c has to end up in a single
4920 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4923 dwarf2_start_subfile (char *filename
, char *dirname
)
4925 /* If the filename isn't absolute, try to match an existing subfile
4926 with the full pathname. */
4928 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4930 struct subfile
*subfile
;
4931 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4933 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4935 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4937 current_subfile
= subfile
;
4944 start_subfile (filename
, dirname
);
4948 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
4949 struct objfile
*objfile
,
4950 const struct comp_unit_head
*cu_header
)
4952 /* NOTE drow/2003-01-30: There used to be a comment and some special
4953 code here to turn a symbol with DW_AT_external and a
4954 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
4955 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
4956 with some versions of binutils) where shared libraries could have
4957 relocations against symbols in their debug information - the
4958 minimal symbol would have the right address, but the debug info
4959 would not. It's no longer necessary, because we will explicitly
4960 apply relocations when we read in the debug information now. */
4962 /* A DW_AT_location attribute with no contents indicates that a
4963 variable has been optimized away. */
4964 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
4966 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4970 /* Handle one degenerate form of location expression specially, to
4971 preserve GDB's previous behavior when section offsets are
4972 specified. If this is just a DW_OP_addr then mark this symbol
4975 if (attr_form_is_block (attr
)
4976 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
4977 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
4981 SYMBOL_VALUE_ADDRESS (sym
) =
4982 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu_header
,
4984 fixup_symbol_section (sym
, objfile
);
4985 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
4986 SYMBOL_SECTION (sym
));
4987 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4991 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
4992 expression evaluator, and use LOC_COMPUTED only when necessary
4993 (i.e. when the value of a register or memory location is
4994 referenced, or a thread-local block, etc.). Then again, it might
4995 not be worthwhile. I'm assuming that it isn't unless performance
4996 or memory numbers show me otherwise. */
4998 dwarf2_symbol_mark_computed (attr
, sym
, cu_header
, objfile
);
4999 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5002 /* Given a pointer to a DWARF information entry, figure out if we need
5003 to make a symbol table entry for it, and if so, create a new entry
5004 and return a pointer to it.
5005 If TYPE is NULL, determine symbol type from the die, otherwise
5006 used the passed type. */
5008 static struct symbol
*
5009 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
5010 const struct comp_unit_head
*cu_header
)
5012 struct symbol
*sym
= NULL
;
5014 struct attribute
*attr
= NULL
;
5015 struct attribute
*attr2
= NULL
;
5018 name
= dwarf2_linkage_name (die
);
5021 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5022 sizeof (struct symbol
));
5023 OBJSTAT (objfile
, n_syms
++);
5024 memset (sym
, 0, sizeof (struct symbol
));
5026 /* Cache this symbol's name and the name's demangled form (if any). */
5027 SYMBOL_LANGUAGE (sym
) = cu_language
;
5028 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5030 /* Default assumptions.
5031 Use the passed type or decode it from the die. */
5032 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
5033 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5035 SYMBOL_TYPE (sym
) = type
;
5037 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
5038 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5041 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5046 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5049 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5051 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5053 case DW_TAG_subprogram
:
5054 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5056 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5057 attr2
= dwarf_attr (die
, DW_AT_external
);
5058 if (attr2
&& (DW_UNSND (attr2
) != 0))
5060 add_symbol_to_list (sym
, &global_symbols
);
5064 add_symbol_to_list (sym
, list_in_scope
);
5067 case DW_TAG_variable
:
5068 /* Compilation with minimal debug info may result in variables
5069 with missing type entries. Change the misleading `void' type
5070 to something sensible. */
5071 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5072 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5073 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5074 "<variable, no debug info>",
5076 attr
= dwarf_attr (die
, DW_AT_const_value
);
5079 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5080 attr2
= dwarf_attr (die
, DW_AT_external
);
5081 if (attr2
&& (DW_UNSND (attr2
) != 0))
5082 add_symbol_to_list (sym
, &global_symbols
);
5084 add_symbol_to_list (sym
, list_in_scope
);
5087 attr
= dwarf_attr (die
, DW_AT_location
);
5090 var_decode_location (attr
, sym
, objfile
, cu_header
);
5091 attr2
= dwarf_attr (die
, DW_AT_external
);
5092 if (attr2
&& (DW_UNSND (attr2
) != 0))
5093 add_symbol_to_list (sym
, &global_symbols
);
5095 add_symbol_to_list (sym
, list_in_scope
);
5099 /* We do not know the address of this symbol.
5100 If it is an external symbol and we have type information
5101 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5102 The address of the variable will then be determined from
5103 the minimal symbol table whenever the variable is
5105 attr2
= dwarf_attr (die
, DW_AT_external
);
5106 if (attr2
&& (DW_UNSND (attr2
) != 0)
5107 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5109 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5110 add_symbol_to_list (sym
, &global_symbols
);
5114 case DW_TAG_formal_parameter
:
5115 attr
= dwarf_attr (die
, DW_AT_location
);
5118 SYMBOL_VALUE (sym
) =
5119 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
5122 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
5123 SYMBOL_VALUE (sym
) =
5124 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
5130 if (basereg
!= frame_base_reg
)
5131 dwarf2_complex_location_expr_complaint ();
5132 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
5136 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
5137 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
5142 SYMBOL_CLASS (sym
) = LOC_ARG
;
5145 attr
= dwarf_attr (die
, DW_AT_const_value
);
5148 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5150 add_symbol_to_list (sym
, list_in_scope
);
5152 case DW_TAG_unspecified_parameters
:
5153 /* From varargs functions; gdb doesn't seem to have any
5154 interest in this information, so just ignore it for now.
5157 case DW_TAG_class_type
:
5158 case DW_TAG_structure_type
:
5159 case DW_TAG_union_type
:
5160 case DW_TAG_enumeration_type
:
5161 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5162 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
5163 add_symbol_to_list (sym
, list_in_scope
);
5165 /* The semantics of C++ state that "struct foo { ... }" also
5166 defines a typedef for "foo". Synthesize a typedef symbol so
5167 that "ptype foo" works as expected. */
5168 if (cu_language
== language_cplus
)
5170 struct symbol
*typedef_sym
= (struct symbol
*)
5171 obstack_alloc (&objfile
->symbol_obstack
,
5172 sizeof (struct symbol
));
5173 *typedef_sym
= *sym
;
5174 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
5175 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5176 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5177 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5178 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5179 &objfile
->type_obstack
);
5180 add_symbol_to_list (typedef_sym
, list_in_scope
);
5183 case DW_TAG_typedef
:
5184 case DW_TAG_base_type
:
5185 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5186 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
5187 add_symbol_to_list (sym
, list_in_scope
);
5189 case DW_TAG_enumerator
:
5190 attr
= dwarf_attr (die
, DW_AT_const_value
);
5193 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5195 add_symbol_to_list (sym
, list_in_scope
);
5198 /* Not a tag we recognize. Hopefully we aren't processing
5199 trash data, but since we must specifically ignore things
5200 we don't recognize, there is nothing else we should do at
5202 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5203 dwarf_tag_name (die
->tag
));
5210 /* Copy constant value from an attribute to a symbol. */
5213 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5214 struct objfile
*objfile
,
5215 const struct comp_unit_head
*cu_header
)
5217 struct dwarf_block
*blk
;
5222 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5223 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5224 cu_header
->addr_size
,
5225 TYPE_LENGTH (SYMBOL_TYPE
5227 SYMBOL_VALUE_BYTES (sym
) = (char *)
5228 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5229 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5231 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5233 case DW_FORM_block1
:
5234 case DW_FORM_block2
:
5235 case DW_FORM_block4
:
5237 blk
= DW_BLOCK (attr
);
5238 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5239 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5241 TYPE_LENGTH (SYMBOL_TYPE
5243 SYMBOL_VALUE_BYTES (sym
) = (char *)
5244 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5245 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5246 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5249 /* The DW_AT_const_value attributes are supposed to carry the
5250 symbol's value "represented as it would be on the target
5251 architecture." By the time we get here, it's already been
5252 converted to host endianness, so we just need to sign- or
5253 zero-extend it as appropriate. */
5255 dwarf2_const_value_data (attr
, sym
, 8);
5258 dwarf2_const_value_data (attr
, sym
, 16);
5261 dwarf2_const_value_data (attr
, sym
, 32);
5264 dwarf2_const_value_data (attr
, sym
, 64);
5268 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5269 SYMBOL_CLASS (sym
) = LOC_CONST
;
5273 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5274 SYMBOL_CLASS (sym
) = LOC_CONST
;
5278 complaint (&symfile_complaints
,
5279 "unsupported const value attribute form: '%s'",
5280 dwarf_form_name (attr
->form
));
5281 SYMBOL_VALUE (sym
) = 0;
5282 SYMBOL_CLASS (sym
) = LOC_CONST
;
5288 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5289 or zero-extend it as appropriate for the symbol's type. */
5291 dwarf2_const_value_data (struct attribute
*attr
,
5295 LONGEST l
= DW_UNSND (attr
);
5297 if (bits
< sizeof (l
) * 8)
5299 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5300 l
&= ((LONGEST
) 1 << bits
) - 1;
5302 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5305 SYMBOL_VALUE (sym
) = l
;
5306 SYMBOL_CLASS (sym
) = LOC_CONST
;
5310 /* Return the type of the die in question using its DW_AT_type attribute. */
5312 static struct type
*
5313 die_type (struct die_info
*die
, struct objfile
*objfile
,
5314 const struct comp_unit_head
*cu_header
)
5317 struct attribute
*type_attr
;
5318 struct die_info
*type_die
;
5321 type_attr
= dwarf_attr (die
, DW_AT_type
);
5324 /* A missing DW_AT_type represents a void type. */
5325 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5329 ref
= dwarf2_get_ref_die_offset (type_attr
);
5330 type_die
= follow_die_ref (ref
);
5333 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5334 ref
, objfile
->name
);
5338 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5341 dump_die (type_die
);
5342 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5348 /* Return the containing type of the die in question using its
5349 DW_AT_containing_type attribute. */
5351 static struct type
*
5352 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5353 const struct comp_unit_head
*cu_header
)
5355 struct type
*type
= NULL
;
5356 struct attribute
*type_attr
;
5357 struct die_info
*type_die
= NULL
;
5360 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5363 ref
= dwarf2_get_ref_die_offset (type_attr
);
5364 type_die
= follow_die_ref (ref
);
5367 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5371 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5376 dump_die (type_die
);
5377 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5384 static struct type
*
5385 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5387 struct die_info
*die
;
5390 die
= follow_die_ref (offset
);
5393 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5396 type
= tag_type_to_type (die
, objfile
);
5401 static struct type
*
5402 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5403 const struct comp_unit_head
*cu_header
)
5411 read_type_die (die
, objfile
, cu_header
);
5415 error ("Dwarf Error: Cannot find type of die [in module %s]",
5423 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5424 const struct comp_unit_head
*cu_header
)
5428 case DW_TAG_class_type
:
5429 case DW_TAG_structure_type
:
5430 case DW_TAG_union_type
:
5431 read_structure_scope (die
, objfile
, cu_header
);
5433 case DW_TAG_enumeration_type
:
5434 read_enumeration (die
, objfile
, cu_header
);
5436 case DW_TAG_subprogram
:
5437 case DW_TAG_subroutine_type
:
5438 read_subroutine_type (die
, objfile
, cu_header
);
5440 case DW_TAG_array_type
:
5441 read_array_type (die
, objfile
, cu_header
);
5443 case DW_TAG_pointer_type
:
5444 read_tag_pointer_type (die
, objfile
, cu_header
);
5446 case DW_TAG_ptr_to_member_type
:
5447 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5449 case DW_TAG_reference_type
:
5450 read_tag_reference_type (die
, objfile
, cu_header
);
5452 case DW_TAG_const_type
:
5453 read_tag_const_type (die
, objfile
, cu_header
);
5455 case DW_TAG_volatile_type
:
5456 read_tag_volatile_type (die
, objfile
, cu_header
);
5458 case DW_TAG_string_type
:
5459 read_tag_string_type (die
, objfile
);
5461 case DW_TAG_typedef
:
5462 read_typedef (die
, objfile
, cu_header
);
5464 case DW_TAG_base_type
:
5465 read_base_type (die
, objfile
);
5468 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5469 dwarf_tag_name (die
->tag
));
5474 static struct type
*
5475 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5477 /* FIXME - this should not produce a new (struct type *)
5478 every time. It should cache base types. */
5482 case DW_ATE_address
:
5483 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5485 case DW_ATE_boolean
:
5486 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5488 case DW_ATE_complex_float
:
5491 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5495 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5501 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5505 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5512 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5515 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5519 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5523 case DW_ATE_signed_char
:
5524 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5526 case DW_ATE_unsigned
:
5530 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5533 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5537 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5541 case DW_ATE_unsigned_char
:
5542 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5545 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5552 copy_die (struct die_info
*old_die
)
5554 struct die_info
*new_die
;
5557 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5558 memset (new_die
, 0, sizeof (struct die_info
));
5560 new_die
->tag
= old_die
->tag
;
5561 new_die
->has_children
= old_die
->has_children
;
5562 new_die
->abbrev
= old_die
->abbrev
;
5563 new_die
->offset
= old_die
->offset
;
5564 new_die
->type
= NULL
;
5566 num_attrs
= old_die
->num_attrs
;
5567 new_die
->num_attrs
= num_attrs
;
5568 new_die
->attrs
= (struct attribute
*)
5569 xmalloc (num_attrs
* sizeof (struct attribute
));
5571 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5573 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5574 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5575 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5578 new_die
->next
= NULL
;
5583 /* Return sibling of die, NULL if no sibling. */
5585 static struct die_info
*
5586 sibling_die (struct die_info
*die
)
5588 int nesting_level
= 0;
5590 if (!die
->has_children
)
5592 if (die
->next
&& (die
->next
->tag
== 0))
5605 if (die
->has_children
)
5615 while (nesting_level
);
5616 if (die
&& (die
->tag
== 0))
5627 /* Get linkage name of a die, return NULL if not found. */
5630 dwarf2_linkage_name (struct die_info
*die
)
5632 struct attribute
*attr
;
5634 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5635 if (attr
&& DW_STRING (attr
))
5636 return DW_STRING (attr
);
5637 attr
= dwarf_attr (die
, DW_AT_name
);
5638 if (attr
&& DW_STRING (attr
))
5639 return DW_STRING (attr
);
5643 /* Convert a DIE tag into its string name. */
5646 dwarf_tag_name (register unsigned tag
)
5650 case DW_TAG_padding
:
5651 return "DW_TAG_padding";
5652 case DW_TAG_array_type
:
5653 return "DW_TAG_array_type";
5654 case DW_TAG_class_type
:
5655 return "DW_TAG_class_type";
5656 case DW_TAG_entry_point
:
5657 return "DW_TAG_entry_point";
5658 case DW_TAG_enumeration_type
:
5659 return "DW_TAG_enumeration_type";
5660 case DW_TAG_formal_parameter
:
5661 return "DW_TAG_formal_parameter";
5662 case DW_TAG_imported_declaration
:
5663 return "DW_TAG_imported_declaration";
5665 return "DW_TAG_label";
5666 case DW_TAG_lexical_block
:
5667 return "DW_TAG_lexical_block";
5669 return "DW_TAG_member";
5670 case DW_TAG_pointer_type
:
5671 return "DW_TAG_pointer_type";
5672 case DW_TAG_reference_type
:
5673 return "DW_TAG_reference_type";
5674 case DW_TAG_compile_unit
:
5675 return "DW_TAG_compile_unit";
5676 case DW_TAG_string_type
:
5677 return "DW_TAG_string_type";
5678 case DW_TAG_structure_type
:
5679 return "DW_TAG_structure_type";
5680 case DW_TAG_subroutine_type
:
5681 return "DW_TAG_subroutine_type";
5682 case DW_TAG_typedef
:
5683 return "DW_TAG_typedef";
5684 case DW_TAG_union_type
:
5685 return "DW_TAG_union_type";
5686 case DW_TAG_unspecified_parameters
:
5687 return "DW_TAG_unspecified_parameters";
5688 case DW_TAG_variant
:
5689 return "DW_TAG_variant";
5690 case DW_TAG_common_block
:
5691 return "DW_TAG_common_block";
5692 case DW_TAG_common_inclusion
:
5693 return "DW_TAG_common_inclusion";
5694 case DW_TAG_inheritance
:
5695 return "DW_TAG_inheritance";
5696 case DW_TAG_inlined_subroutine
:
5697 return "DW_TAG_inlined_subroutine";
5699 return "DW_TAG_module";
5700 case DW_TAG_ptr_to_member_type
:
5701 return "DW_TAG_ptr_to_member_type";
5702 case DW_TAG_set_type
:
5703 return "DW_TAG_set_type";
5704 case DW_TAG_subrange_type
:
5705 return "DW_TAG_subrange_type";
5706 case DW_TAG_with_stmt
:
5707 return "DW_TAG_with_stmt";
5708 case DW_TAG_access_declaration
:
5709 return "DW_TAG_access_declaration";
5710 case DW_TAG_base_type
:
5711 return "DW_TAG_base_type";
5712 case DW_TAG_catch_block
:
5713 return "DW_TAG_catch_block";
5714 case DW_TAG_const_type
:
5715 return "DW_TAG_const_type";
5716 case DW_TAG_constant
:
5717 return "DW_TAG_constant";
5718 case DW_TAG_enumerator
:
5719 return "DW_TAG_enumerator";
5720 case DW_TAG_file_type
:
5721 return "DW_TAG_file_type";
5723 return "DW_TAG_friend";
5724 case DW_TAG_namelist
:
5725 return "DW_TAG_namelist";
5726 case DW_TAG_namelist_item
:
5727 return "DW_TAG_namelist_item";
5728 case DW_TAG_packed_type
:
5729 return "DW_TAG_packed_type";
5730 case DW_TAG_subprogram
:
5731 return "DW_TAG_subprogram";
5732 case DW_TAG_template_type_param
:
5733 return "DW_TAG_template_type_param";
5734 case DW_TAG_template_value_param
:
5735 return "DW_TAG_template_value_param";
5736 case DW_TAG_thrown_type
:
5737 return "DW_TAG_thrown_type";
5738 case DW_TAG_try_block
:
5739 return "DW_TAG_try_block";
5740 case DW_TAG_variant_part
:
5741 return "DW_TAG_variant_part";
5742 case DW_TAG_variable
:
5743 return "DW_TAG_variable";
5744 case DW_TAG_volatile_type
:
5745 return "DW_TAG_volatile_type";
5746 case DW_TAG_dwarf_procedure
:
5747 return "DW_TAG_dwarf_procedure";
5748 case DW_TAG_restrict_type
:
5749 return "DW_TAG_restrict_type";
5750 case DW_TAG_interface_type
:
5751 return "DW_TAG_interface_type";
5752 case DW_TAG_namespace
:
5753 return "DW_TAG_namespace";
5754 case DW_TAG_imported_module
:
5755 return "DW_TAG_imported_module";
5756 case DW_TAG_unspecified_type
:
5757 return "DW_TAG_unspecified_type";
5758 case DW_TAG_partial_unit
:
5759 return "DW_TAG_partial_unit";
5760 case DW_TAG_imported_unit
:
5761 return "DW_TAG_imported_unit";
5762 case DW_TAG_MIPS_loop
:
5763 return "DW_TAG_MIPS_loop";
5764 case DW_TAG_format_label
:
5765 return "DW_TAG_format_label";
5766 case DW_TAG_function_template
:
5767 return "DW_TAG_function_template";
5768 case DW_TAG_class_template
:
5769 return "DW_TAG_class_template";
5771 return "DW_TAG_<unknown>";
5775 /* Convert a DWARF attribute code into its string name. */
5778 dwarf_attr_name (register unsigned attr
)
5783 return "DW_AT_sibling";
5784 case DW_AT_location
:
5785 return "DW_AT_location";
5787 return "DW_AT_name";
5788 case DW_AT_ordering
:
5789 return "DW_AT_ordering";
5790 case DW_AT_subscr_data
:
5791 return "DW_AT_subscr_data";
5792 case DW_AT_byte_size
:
5793 return "DW_AT_byte_size";
5794 case DW_AT_bit_offset
:
5795 return "DW_AT_bit_offset";
5796 case DW_AT_bit_size
:
5797 return "DW_AT_bit_size";
5798 case DW_AT_element_list
:
5799 return "DW_AT_element_list";
5800 case DW_AT_stmt_list
:
5801 return "DW_AT_stmt_list";
5803 return "DW_AT_low_pc";
5805 return "DW_AT_high_pc";
5806 case DW_AT_language
:
5807 return "DW_AT_language";
5809 return "DW_AT_member";
5811 return "DW_AT_discr";
5812 case DW_AT_discr_value
:
5813 return "DW_AT_discr_value";
5814 case DW_AT_visibility
:
5815 return "DW_AT_visibility";
5817 return "DW_AT_import";
5818 case DW_AT_string_length
:
5819 return "DW_AT_string_length";
5820 case DW_AT_common_reference
:
5821 return "DW_AT_common_reference";
5822 case DW_AT_comp_dir
:
5823 return "DW_AT_comp_dir";
5824 case DW_AT_const_value
:
5825 return "DW_AT_const_value";
5826 case DW_AT_containing_type
:
5827 return "DW_AT_containing_type";
5828 case DW_AT_default_value
:
5829 return "DW_AT_default_value";
5831 return "DW_AT_inline";
5832 case DW_AT_is_optional
:
5833 return "DW_AT_is_optional";
5834 case DW_AT_lower_bound
:
5835 return "DW_AT_lower_bound";
5836 case DW_AT_producer
:
5837 return "DW_AT_producer";
5838 case DW_AT_prototyped
:
5839 return "DW_AT_prototyped";
5840 case DW_AT_return_addr
:
5841 return "DW_AT_return_addr";
5842 case DW_AT_start_scope
:
5843 return "DW_AT_start_scope";
5844 case DW_AT_stride_size
:
5845 return "DW_AT_stride_size";
5846 case DW_AT_upper_bound
:
5847 return "DW_AT_upper_bound";
5848 case DW_AT_abstract_origin
:
5849 return "DW_AT_abstract_origin";
5850 case DW_AT_accessibility
:
5851 return "DW_AT_accessibility";
5852 case DW_AT_address_class
:
5853 return "DW_AT_address_class";
5854 case DW_AT_artificial
:
5855 return "DW_AT_artificial";
5856 case DW_AT_base_types
:
5857 return "DW_AT_base_types";
5858 case DW_AT_calling_convention
:
5859 return "DW_AT_calling_convention";
5861 return "DW_AT_count";
5862 case DW_AT_data_member_location
:
5863 return "DW_AT_data_member_location";
5864 case DW_AT_decl_column
:
5865 return "DW_AT_decl_column";
5866 case DW_AT_decl_file
:
5867 return "DW_AT_decl_file";
5868 case DW_AT_decl_line
:
5869 return "DW_AT_decl_line";
5870 case DW_AT_declaration
:
5871 return "DW_AT_declaration";
5872 case DW_AT_discr_list
:
5873 return "DW_AT_discr_list";
5874 case DW_AT_encoding
:
5875 return "DW_AT_encoding";
5876 case DW_AT_external
:
5877 return "DW_AT_external";
5878 case DW_AT_frame_base
:
5879 return "DW_AT_frame_base";
5881 return "DW_AT_friend";
5882 case DW_AT_identifier_case
:
5883 return "DW_AT_identifier_case";
5884 case DW_AT_macro_info
:
5885 return "DW_AT_macro_info";
5886 case DW_AT_namelist_items
:
5887 return "DW_AT_namelist_items";
5888 case DW_AT_priority
:
5889 return "DW_AT_priority";
5891 return "DW_AT_segment";
5892 case DW_AT_specification
:
5893 return "DW_AT_specification";
5894 case DW_AT_static_link
:
5895 return "DW_AT_static_link";
5897 return "DW_AT_type";
5898 case DW_AT_use_location
:
5899 return "DW_AT_use_location";
5900 case DW_AT_variable_parameter
:
5901 return "DW_AT_variable_parameter";
5902 case DW_AT_virtuality
:
5903 return "DW_AT_virtuality";
5904 case DW_AT_vtable_elem_location
:
5905 return "DW_AT_vtable_elem_location";
5906 case DW_AT_allocated
:
5907 return "DW_AT_allocated";
5908 case DW_AT_associated
:
5909 return "DW_AT_associated";
5910 case DW_AT_data_location
:
5911 return "DW_AT_data_location";
5913 return "DW_AT_stride";
5914 case DW_AT_entry_pc
:
5915 return "DW_AT_entry_pc";
5916 case DW_AT_use_UTF8
:
5917 return "DW_AT_use_UTF8";
5918 case DW_AT_extension
:
5919 return "DW_AT_extension";
5921 return "DW_AT_ranges";
5922 case DW_AT_trampoline
:
5923 return "DW_AT_trampoline";
5924 case DW_AT_call_column
:
5925 return "DW_AT_call_column";
5926 case DW_AT_call_file
:
5927 return "DW_AT_call_file";
5928 case DW_AT_call_line
:
5929 return "DW_AT_call_line";
5931 case DW_AT_MIPS_fde
:
5932 return "DW_AT_MIPS_fde";
5933 case DW_AT_MIPS_loop_begin
:
5934 return "DW_AT_MIPS_loop_begin";
5935 case DW_AT_MIPS_tail_loop_begin
:
5936 return "DW_AT_MIPS_tail_loop_begin";
5937 case DW_AT_MIPS_epilog_begin
:
5938 return "DW_AT_MIPS_epilog_begin";
5939 case DW_AT_MIPS_loop_unroll_factor
:
5940 return "DW_AT_MIPS_loop_unroll_factor";
5941 case DW_AT_MIPS_software_pipeline_depth
:
5942 return "DW_AT_MIPS_software_pipeline_depth";
5943 case DW_AT_MIPS_linkage_name
:
5944 return "DW_AT_MIPS_linkage_name";
5947 case DW_AT_sf_names
:
5948 return "DW_AT_sf_names";
5949 case DW_AT_src_info
:
5950 return "DW_AT_src_info";
5951 case DW_AT_mac_info
:
5952 return "DW_AT_mac_info";
5953 case DW_AT_src_coords
:
5954 return "DW_AT_src_coords";
5955 case DW_AT_body_begin
:
5956 return "DW_AT_body_begin";
5957 case DW_AT_body_end
:
5958 return "DW_AT_body_end";
5959 case DW_AT_GNU_vector
:
5960 return "DW_AT_GNU_vector";
5962 return "DW_AT_<unknown>";
5966 /* Convert a DWARF value form code into its string name. */
5969 dwarf_form_name (register unsigned form
)
5974 return "DW_FORM_addr";
5975 case DW_FORM_block2
:
5976 return "DW_FORM_block2";
5977 case DW_FORM_block4
:
5978 return "DW_FORM_block4";
5980 return "DW_FORM_data2";
5982 return "DW_FORM_data4";
5984 return "DW_FORM_data8";
5985 case DW_FORM_string
:
5986 return "DW_FORM_string";
5988 return "DW_FORM_block";
5989 case DW_FORM_block1
:
5990 return "DW_FORM_block1";
5992 return "DW_FORM_data1";
5994 return "DW_FORM_flag";
5996 return "DW_FORM_sdata";
5998 return "DW_FORM_strp";
6000 return "DW_FORM_udata";
6001 case DW_FORM_ref_addr
:
6002 return "DW_FORM_ref_addr";
6004 return "DW_FORM_ref1";
6006 return "DW_FORM_ref2";
6008 return "DW_FORM_ref4";
6010 return "DW_FORM_ref8";
6011 case DW_FORM_ref_udata
:
6012 return "DW_FORM_ref_udata";
6013 case DW_FORM_indirect
:
6014 return "DW_FORM_indirect";
6016 return "DW_FORM_<unknown>";
6020 /* Convert a DWARF stack opcode into its string name. */
6023 dwarf_stack_op_name (register unsigned op
)
6028 return "DW_OP_addr";
6030 return "DW_OP_deref";
6032 return "DW_OP_const1u";
6034 return "DW_OP_const1s";
6036 return "DW_OP_const2u";
6038 return "DW_OP_const2s";
6040 return "DW_OP_const4u";
6042 return "DW_OP_const4s";
6044 return "DW_OP_const8u";
6046 return "DW_OP_const8s";
6048 return "DW_OP_constu";
6050 return "DW_OP_consts";
6054 return "DW_OP_drop";
6056 return "DW_OP_over";
6058 return "DW_OP_pick";
6060 return "DW_OP_swap";
6064 return "DW_OP_xderef";
6072 return "DW_OP_minus";
6084 return "DW_OP_plus";
6085 case DW_OP_plus_uconst
:
6086 return "DW_OP_plus_uconst";
6092 return "DW_OP_shra";
6110 return "DW_OP_skip";
6112 return "DW_OP_lit0";
6114 return "DW_OP_lit1";
6116 return "DW_OP_lit2";
6118 return "DW_OP_lit3";
6120 return "DW_OP_lit4";
6122 return "DW_OP_lit5";
6124 return "DW_OP_lit6";
6126 return "DW_OP_lit7";
6128 return "DW_OP_lit8";
6130 return "DW_OP_lit9";
6132 return "DW_OP_lit10";
6134 return "DW_OP_lit11";
6136 return "DW_OP_lit12";
6138 return "DW_OP_lit13";
6140 return "DW_OP_lit14";
6142 return "DW_OP_lit15";
6144 return "DW_OP_lit16";
6146 return "DW_OP_lit17";
6148 return "DW_OP_lit18";
6150 return "DW_OP_lit19";
6152 return "DW_OP_lit20";
6154 return "DW_OP_lit21";
6156 return "DW_OP_lit22";
6158 return "DW_OP_lit23";
6160 return "DW_OP_lit24";
6162 return "DW_OP_lit25";
6164 return "DW_OP_lit26";
6166 return "DW_OP_lit27";
6168 return "DW_OP_lit28";
6170 return "DW_OP_lit29";
6172 return "DW_OP_lit30";
6174 return "DW_OP_lit31";
6176 return "DW_OP_reg0";
6178 return "DW_OP_reg1";
6180 return "DW_OP_reg2";
6182 return "DW_OP_reg3";
6184 return "DW_OP_reg4";
6186 return "DW_OP_reg5";
6188 return "DW_OP_reg6";
6190 return "DW_OP_reg7";
6192 return "DW_OP_reg8";
6194 return "DW_OP_reg9";
6196 return "DW_OP_reg10";
6198 return "DW_OP_reg11";
6200 return "DW_OP_reg12";
6202 return "DW_OP_reg13";
6204 return "DW_OP_reg14";
6206 return "DW_OP_reg15";
6208 return "DW_OP_reg16";
6210 return "DW_OP_reg17";
6212 return "DW_OP_reg18";
6214 return "DW_OP_reg19";
6216 return "DW_OP_reg20";
6218 return "DW_OP_reg21";
6220 return "DW_OP_reg22";
6222 return "DW_OP_reg23";
6224 return "DW_OP_reg24";
6226 return "DW_OP_reg25";
6228 return "DW_OP_reg26";
6230 return "DW_OP_reg27";
6232 return "DW_OP_reg28";
6234 return "DW_OP_reg29";
6236 return "DW_OP_reg30";
6238 return "DW_OP_reg31";
6240 return "DW_OP_breg0";
6242 return "DW_OP_breg1";
6244 return "DW_OP_breg2";
6246 return "DW_OP_breg3";
6248 return "DW_OP_breg4";
6250 return "DW_OP_breg5";
6252 return "DW_OP_breg6";
6254 return "DW_OP_breg7";
6256 return "DW_OP_breg8";
6258 return "DW_OP_breg9";
6260 return "DW_OP_breg10";
6262 return "DW_OP_breg11";
6264 return "DW_OP_breg12";
6266 return "DW_OP_breg13";
6268 return "DW_OP_breg14";
6270 return "DW_OP_breg15";
6272 return "DW_OP_breg16";
6274 return "DW_OP_breg17";
6276 return "DW_OP_breg18";
6278 return "DW_OP_breg19";
6280 return "DW_OP_breg20";
6282 return "DW_OP_breg21";
6284 return "DW_OP_breg22";
6286 return "DW_OP_breg23";
6288 return "DW_OP_breg24";
6290 return "DW_OP_breg25";
6292 return "DW_OP_breg26";
6294 return "DW_OP_breg27";
6296 return "DW_OP_breg28";
6298 return "DW_OP_breg29";
6300 return "DW_OP_breg30";
6302 return "DW_OP_breg31";
6304 return "DW_OP_regx";
6306 return "DW_OP_fbreg";
6308 return "DW_OP_bregx";
6310 return "DW_OP_piece";
6311 case DW_OP_deref_size
:
6312 return "DW_OP_deref_size";
6313 case DW_OP_xderef_size
:
6314 return "DW_OP_xderef_size";
6317 /* DWARF 3 extensions. */
6318 case DW_OP_push_object_address
:
6319 return "DW_OP_push_object_address";
6321 return "DW_OP_call2";
6323 return "DW_OP_call4";
6324 case DW_OP_call_ref
:
6325 return "DW_OP_call_ref";
6326 /* GNU extensions. */
6327 case DW_OP_GNU_push_tls_address
:
6328 return "DW_OP_GNU_push_tls_address";
6330 return "OP_<unknown>";
6335 dwarf_bool_name (unsigned mybool
)
6343 /* Convert a DWARF type code into its string name. */
6346 dwarf_type_encoding_name (register unsigned enc
)
6350 case DW_ATE_address
:
6351 return "DW_ATE_address";
6352 case DW_ATE_boolean
:
6353 return "DW_ATE_boolean";
6354 case DW_ATE_complex_float
:
6355 return "DW_ATE_complex_float";
6357 return "DW_ATE_float";
6359 return "DW_ATE_signed";
6360 case DW_ATE_signed_char
:
6361 return "DW_ATE_signed_char";
6362 case DW_ATE_unsigned
:
6363 return "DW_ATE_unsigned";
6364 case DW_ATE_unsigned_char
:
6365 return "DW_ATE_unsigned_char";
6366 case DW_ATE_imaginary_float
:
6367 return "DW_ATE_imaginary_float";
6369 return "DW_ATE_<unknown>";
6373 /* Convert a DWARF call frame info operation to its string name. */
6377 dwarf_cfi_name (register unsigned cfi_opc
)
6381 case DW_CFA_advance_loc
:
6382 return "DW_CFA_advance_loc";
6384 return "DW_CFA_offset";
6385 case DW_CFA_restore
:
6386 return "DW_CFA_restore";
6388 return "DW_CFA_nop";
6389 case DW_CFA_set_loc
:
6390 return "DW_CFA_set_loc";
6391 case DW_CFA_advance_loc1
:
6392 return "DW_CFA_advance_loc1";
6393 case DW_CFA_advance_loc2
:
6394 return "DW_CFA_advance_loc2";
6395 case DW_CFA_advance_loc4
:
6396 return "DW_CFA_advance_loc4";
6397 case DW_CFA_offset_extended
:
6398 return "DW_CFA_offset_extended";
6399 case DW_CFA_restore_extended
:
6400 return "DW_CFA_restore_extended";
6401 case DW_CFA_undefined
:
6402 return "DW_CFA_undefined";
6403 case DW_CFA_same_value
:
6404 return "DW_CFA_same_value";
6405 case DW_CFA_register
:
6406 return "DW_CFA_register";
6407 case DW_CFA_remember_state
:
6408 return "DW_CFA_remember_state";
6409 case DW_CFA_restore_state
:
6410 return "DW_CFA_restore_state";
6411 case DW_CFA_def_cfa
:
6412 return "DW_CFA_def_cfa";
6413 case DW_CFA_def_cfa_register
:
6414 return "DW_CFA_def_cfa_register";
6415 case DW_CFA_def_cfa_offset
:
6416 return "DW_CFA_def_cfa_offset";
6419 case DW_CFA_def_cfa_expression
:
6420 return "DW_CFA_def_cfa_expression";
6421 case DW_CFA_expression
:
6422 return "DW_CFA_expression";
6423 case DW_CFA_offset_extended_sf
:
6424 return "DW_CFA_offset_extended_sf";
6425 case DW_CFA_def_cfa_sf
:
6426 return "DW_CFA_def_cfa_sf";
6427 case DW_CFA_def_cfa_offset_sf
:
6428 return "DW_CFA_def_cfa_offset_sf";
6430 /* SGI/MIPS specific */
6431 case DW_CFA_MIPS_advance_loc8
:
6432 return "DW_CFA_MIPS_advance_loc8";
6434 /* GNU extensions */
6435 case DW_CFA_GNU_window_save
:
6436 return "DW_CFA_GNU_window_save";
6437 case DW_CFA_GNU_args_size
:
6438 return "DW_CFA_GNU_args_size";
6439 case DW_CFA_GNU_negative_offset_extended
:
6440 return "DW_CFA_GNU_negative_offset_extended";
6443 return "DW_CFA_<unknown>";
6449 dump_die (struct die_info
*die
)
6453 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6454 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6455 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6456 dwarf_bool_name (die
->has_children
));
6458 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6459 for (i
= 0; i
< die
->num_attrs
; ++i
)
6461 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6462 dwarf_attr_name (die
->attrs
[i
].name
),
6463 dwarf_form_name (die
->attrs
[i
].form
));
6464 switch (die
->attrs
[i
].form
)
6466 case DW_FORM_ref_addr
:
6468 fprintf_unfiltered (gdb_stderr
, "address: ");
6469 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6471 case DW_FORM_block2
:
6472 case DW_FORM_block4
:
6474 case DW_FORM_block1
:
6475 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6486 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6488 case DW_FORM_string
:
6490 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6491 DW_STRING (&die
->attrs
[i
])
6492 ? DW_STRING (&die
->attrs
[i
]) : "");
6495 if (DW_UNSND (&die
->attrs
[i
]))
6496 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6498 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6500 case DW_FORM_indirect
:
6501 /* the reader will have reduced the indirect form to
6502 the "base form" so this form should not occur */
6503 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6506 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6507 die
->attrs
[i
].form
);
6509 fprintf_unfiltered (gdb_stderr
, "\n");
6514 dump_die_list (struct die_info
*die
)
6524 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6527 struct die_info
*old
;
6529 h
= (offset
% REF_HASH_SIZE
);
6530 old
= die_ref_table
[h
];
6531 die
->next_ref
= old
;
6532 die_ref_table
[h
] = die
;
6537 dwarf2_empty_hash_tables (void)
6539 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6543 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6545 unsigned int result
= 0;
6549 case DW_FORM_ref_addr
:
6550 result
= DW_ADDR (attr
);
6556 case DW_FORM_ref_udata
:
6557 result
= cu_header_offset
+ DW_UNSND (attr
);
6560 complaint (&symfile_complaints
,
6561 "unsupported die ref attribute form: '%s'",
6562 dwarf_form_name (attr
->form
));
6567 static struct die_info
*
6568 follow_die_ref (unsigned int offset
)
6570 struct die_info
*die
;
6573 h
= (offset
% REF_HASH_SIZE
);
6574 die
= die_ref_table
[h
];
6577 if (die
->offset
== offset
)
6581 die
= die
->next_ref
;
6586 static struct type
*
6587 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6589 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6591 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6592 typeid, objfile
->name
);
6595 /* Look for this particular type in the fundamental type vector. If
6596 one is not found, create and install one appropriate for the
6597 current language and the current target machine. */
6599 if (ftypes
[typeid] == NULL
)
6601 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6604 return (ftypes
[typeid]);
6607 /* Decode simple location descriptions.
6608 Given a pointer to a dwarf block that defines a location, compute
6609 the location and return the value.
6611 FIXME: This is a kludge until we figure out a better
6612 way to handle the location descriptions.
6613 Gdb's design does not mesh well with the DWARF2 notion of a location
6614 computing interpreter, which is a shame because the flexibility goes unused.
6615 FIXME: Implement more operations as necessary.
6617 A location description containing no operations indicates that the
6618 object is optimized out. The global optimized_out flag is set for
6619 those, the return value is meaningless.
6621 When the result is a register number, the global isreg flag is set,
6622 otherwise it is cleared.
6624 When the result is a base register offset, the global offreg flag is set
6625 and the register number is returned in basereg, otherwise it is cleared.
6627 When the DW_OP_fbreg operation is encountered without a corresponding
6628 DW_AT_frame_base attribute, the global islocal flag is set.
6629 Hopefully the machine dependent code knows how to set up a virtual
6630 frame pointer for the local references.
6632 Note that stack[0] is unused except as a default error return.
6633 Note that stack overflow is not yet handled. */
6636 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6637 const struct comp_unit_head
*cu_header
)
6640 int size
= blk
->size
;
6641 char *data
= blk
->data
;
6642 CORE_ADDR stack
[64];
6644 unsigned int bytes_read
, unsnd
;
6654 is_thread_local
= 0;
6695 stack
[++stacki
] = op
- DW_OP_lit0
;
6731 stack
[++stacki
] = op
- DW_OP_reg0
;
6736 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6738 stack
[++stacki
] = unsnd
;
6774 basereg
= op
- DW_OP_breg0
;
6775 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6781 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6783 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6788 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6790 if (frame_base_reg
>= 0)
6793 basereg
= frame_base_reg
;
6794 stack
[stacki
] += frame_base_offset
;
6798 complaint (&symfile_complaints
,
6799 "DW_AT_frame_base missing for DW_OP_fbreg");
6805 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6806 cu_header
, &bytes_read
);
6811 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6816 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6821 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6826 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6831 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6836 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6841 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6847 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6852 stack
[stacki
+ 1] = stack
[stacki
];
6857 stack
[stacki
- 1] += stack
[stacki
];
6861 case DW_OP_plus_uconst
:
6862 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6867 stack
[stacki
- 1] -= stack
[stacki
];
6873 /* If we're not the last op, then we definitely can't encode
6874 this using GDB's address_class enum. */
6876 dwarf2_complex_location_expr_complaint ();
6879 case DW_OP_GNU_push_tls_address
:
6880 is_thread_local
= 1;
6881 /* The top of the stack has the offset from the beginning
6882 of the thread control block at which the variable is located. */
6883 /* Nothing should follow this operator, so the top of stack would
6886 dwarf2_complex_location_expr_complaint ();
6890 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
6891 dwarf_stack_op_name (op
));
6892 return (stack
[stacki
]);
6895 return (stack
[stacki
]);
6898 /* memory allocation interface */
6902 dwarf2_free_tmp_obstack (void *ignore
)
6904 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6907 static struct dwarf_block
*
6908 dwarf_alloc_block (void)
6910 struct dwarf_block
*blk
;
6912 blk
= (struct dwarf_block
*)
6913 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6917 static struct abbrev_info
*
6918 dwarf_alloc_abbrev (void)
6920 struct abbrev_info
*abbrev
;
6922 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6923 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6927 static struct die_info
*
6928 dwarf_alloc_die (void)
6930 struct die_info
*die
;
6932 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6933 memset (die
, 0, sizeof (struct die_info
));
6938 /* Macro support. */
6941 /* Return the full name of file number I in *LH's file name table.
6942 Use COMP_DIR as the name of the current directory of the
6943 compilation. The result is allocated using xmalloc; the caller is
6944 responsible for freeing it. */
6946 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
6948 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6950 if (IS_ABSOLUTE_PATH (fe
->name
))
6951 return xstrdup (fe
->name
);
6959 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6965 dir_len
= strlen (dir
);
6966 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
6967 strcpy (full_name
, dir
);
6968 full_name
[dir_len
] = '/';
6969 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
6973 return xstrdup (fe
->name
);
6978 static struct macro_source_file
*
6979 macro_start_file (int file
, int line
,
6980 struct macro_source_file
*current_file
,
6981 const char *comp_dir
,
6982 struct line_header
*lh
, struct objfile
*objfile
)
6984 /* The full name of this source file. */
6985 char *full_name
= file_full_name (file
, lh
, comp_dir
);
6987 /* We don't create a macro table for this compilation unit
6988 at all until we actually get a filename. */
6989 if (! pending_macros
)
6990 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
6991 objfile
->macro_cache
);
6994 /* If we have no current file, then this must be the start_file
6995 directive for the compilation unit's main source file. */
6996 current_file
= macro_set_main (pending_macros
, full_name
);
6998 current_file
= macro_include (current_file
, line
, full_name
);
7002 return current_file
;
7006 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7007 followed by a null byte. */
7009 copy_string (const char *buf
, int len
)
7011 char *s
= xmalloc (len
+ 1);
7012 memcpy (s
, buf
, len
);
7020 consume_improper_spaces (const char *p
, const char *body
)
7024 complaint (&symfile_complaints
,
7025 "macro definition contains spaces in formal argument list:\n`%s'",
7037 parse_macro_definition (struct macro_source_file
*file
, int line
,
7042 /* The body string takes one of two forms. For object-like macro
7043 definitions, it should be:
7045 <macro name> " " <definition>
7047 For function-like macro definitions, it should be:
7049 <macro name> "() " <definition>
7051 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7053 Spaces may appear only where explicitly indicated, and in the
7056 The Dwarf 2 spec says that an object-like macro's name is always
7057 followed by a space, but versions of GCC around March 2002 omit
7058 the space when the macro's definition is the empty string.
7060 The Dwarf 2 spec says that there should be no spaces between the
7061 formal arguments in a function-like macro's formal argument list,
7062 but versions of GCC around March 2002 include spaces after the
7066 /* Find the extent of the macro name. The macro name is terminated
7067 by either a space or null character (for an object-like macro) or
7068 an opening paren (for a function-like macro). */
7069 for (p
= body
; *p
; p
++)
7070 if (*p
== ' ' || *p
== '(')
7073 if (*p
== ' ' || *p
== '\0')
7075 /* It's an object-like macro. */
7076 int name_len
= p
- body
;
7077 char *name
= copy_string (body
, name_len
);
7078 const char *replacement
;
7081 replacement
= body
+ name_len
+ 1;
7084 dwarf2_macro_malformed_definition_complaint (body
);
7085 replacement
= body
+ name_len
;
7088 macro_define_object (file
, line
, name
, replacement
);
7094 /* It's a function-like macro. */
7095 char *name
= copy_string (body
, p
- body
);
7098 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7102 p
= consume_improper_spaces (p
, body
);
7104 /* Parse the formal argument list. */
7105 while (*p
&& *p
!= ')')
7107 /* Find the extent of the current argument name. */
7108 const char *arg_start
= p
;
7110 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7113 if (! *p
|| p
== arg_start
)
7114 dwarf2_macro_malformed_definition_complaint (body
);
7117 /* Make sure argv has room for the new argument. */
7118 if (argc
>= argv_size
)
7121 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7124 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7127 p
= consume_improper_spaces (p
, body
);
7129 /* Consume the comma, if present. */
7134 p
= consume_improper_spaces (p
, body
);
7143 /* Perfectly formed definition, no complaints. */
7144 macro_define_function (file
, line
, name
,
7145 argc
, (const char **) argv
,
7147 else if (*p
== '\0')
7149 /* Complain, but do define it. */
7150 dwarf2_macro_malformed_definition_complaint (body
);
7151 macro_define_function (file
, line
, name
,
7152 argc
, (const char **) argv
,
7156 /* Just complain. */
7157 dwarf2_macro_malformed_definition_complaint (body
);
7160 /* Just complain. */
7161 dwarf2_macro_malformed_definition_complaint (body
);
7167 for (i
= 0; i
< argc
; i
++)
7173 dwarf2_macro_malformed_definition_complaint (body
);
7178 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7179 char *comp_dir
, bfd
*abfd
,
7180 const struct comp_unit_head
*cu_header
,
7181 struct objfile
*objfile
)
7183 char *mac_ptr
, *mac_end
;
7184 struct macro_source_file
*current_file
= 0;
7186 if (dwarf_macinfo_buffer
== NULL
)
7188 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7192 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7193 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7197 enum dwarf_macinfo_record_type macinfo_type
;
7199 /* Do we at least have room for a macinfo type byte? */
7200 if (mac_ptr
>= mac_end
)
7202 dwarf2_macros_too_long_complaint ();
7206 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7209 switch (macinfo_type
)
7211 /* A zero macinfo type indicates the end of the macro
7216 case DW_MACINFO_define
:
7217 case DW_MACINFO_undef
:
7223 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7224 mac_ptr
+= bytes_read
;
7225 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7226 mac_ptr
+= bytes_read
;
7229 complaint (&symfile_complaints
,
7230 "debug info gives macro %s outside of any file: %s",
7232 DW_MACINFO_define
? "definition" : macinfo_type
==
7233 DW_MACINFO_undef
? "undefinition" :
7234 "something-or-other", body
);
7237 if (macinfo_type
== DW_MACINFO_define
)
7238 parse_macro_definition (current_file
, line
, body
);
7239 else if (macinfo_type
== DW_MACINFO_undef
)
7240 macro_undef (current_file
, line
, body
);
7245 case DW_MACINFO_start_file
:
7250 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7251 mac_ptr
+= bytes_read
;
7252 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7253 mac_ptr
+= bytes_read
;
7255 current_file
= macro_start_file (file
, line
,
7256 current_file
, comp_dir
,
7261 case DW_MACINFO_end_file
:
7263 complaint (&symfile_complaints
,
7264 "macro debug info has an unmatched `close_file' directive");
7267 current_file
= current_file
->included_by
;
7270 enum dwarf_macinfo_record_type next_type
;
7272 /* GCC circa March 2002 doesn't produce the zero
7273 type byte marking the end of the compilation
7274 unit. Complain if it's not there, but exit no
7277 /* Do we at least have room for a macinfo type byte? */
7278 if (mac_ptr
>= mac_end
)
7280 dwarf2_macros_too_long_complaint ();
7284 /* We don't increment mac_ptr here, so this is just
7286 next_type
= read_1_byte (abfd
, mac_ptr
);
7288 complaint (&symfile_complaints
,
7289 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7296 case DW_MACINFO_vendor_ext
:
7302 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7303 mac_ptr
+= bytes_read
;
7304 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7305 mac_ptr
+= bytes_read
;
7307 /* We don't recognize any vendor extensions. */
7314 /* Check if the attribute's form is a DW_FORM_block*
7315 if so return true else false. */
7317 attr_form_is_block (struct attribute
*attr
)
7319 return (attr
== NULL
? 0 :
7320 attr
->form
== DW_FORM_block1
7321 || attr
->form
== DW_FORM_block2
7322 || attr
->form
== DW_FORM_block4
7323 || attr
->form
== DW_FORM_block
);
7327 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7328 const struct comp_unit_head
*cu_header
,
7329 struct objfile
*objfile
)
7331 struct dwarf2_locexpr_baton
*baton
;
7333 /* When support for location lists is added, this will go away. */
7334 if (!attr_form_is_block (attr
))
7336 dwarf2_complex_location_expr_complaint ();
7340 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7341 sizeof (struct dwarf2_locexpr_baton
));
7342 baton
->objfile
= objfile
;
7344 /* Note that we're just copying the block's data pointer here, not
7345 the actual data. We're still pointing into the dwarf_info_buffer
7346 for SYM's objfile; right now we never release that buffer, but
7347 when we do clean up properly this may need to change. */
7348 baton
->size
= DW_BLOCK (attr
)->size
;
7349 baton
->data
= DW_BLOCK (attr
)->data
;
7351 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7352 SYMBOL_LOCATION_BATON (sym
) = baton
;