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 /* Base address of this compilation unit. */
225 CORE_ADDR base_address
;
227 /* Non-zero if base_address has been set. */
232 /* The line number information for a compilation unit (found in the
233 .debug_line section) begins with a "statement program header",
234 which contains the following information. */
237 unsigned int total_length
;
238 unsigned short version
;
239 unsigned int header_length
;
240 unsigned char minimum_instruction_length
;
241 unsigned char default_is_stmt
;
243 unsigned char line_range
;
244 unsigned char opcode_base
;
246 /* standard_opcode_lengths[i] is the number of operands for the
247 standard opcode whose value is i. This means that
248 standard_opcode_lengths[0] is unused, and the last meaningful
249 element is standard_opcode_lengths[opcode_base - 1]. */
250 unsigned char *standard_opcode_lengths
;
252 /* The include_directories table. NOTE! These strings are not
253 allocated with xmalloc; instead, they are pointers into
254 debug_line_buffer. If you try to free them, `free' will get
256 unsigned int num_include_dirs
, include_dirs_size
;
259 /* The file_names table. NOTE! These strings are not allocated
260 with xmalloc; instead, they are pointers into debug_line_buffer.
261 Don't try to free them directly. */
262 unsigned int num_file_names
, file_names_size
;
266 unsigned int dir_index
;
267 unsigned int mod_time
;
271 /* The start and end of the statement program following this
272 header. These point into dwarf_line_buffer. */
273 char *statement_program_start
, *statement_program_end
;
276 /* When we construct a partial symbol table entry we only
277 need this much information. */
278 struct partial_die_info
281 unsigned char has_children
;
282 unsigned char is_external
;
283 unsigned char is_declaration
;
284 unsigned char has_type
;
291 struct dwarf_block
*locdesc
;
292 unsigned int language
;
296 /* This data structure holds the information of an abbrev. */
299 unsigned int number
; /* number identifying abbrev */
300 enum dwarf_tag tag
; /* dwarf tag */
301 int has_children
; /* boolean */
302 unsigned int num_attrs
; /* number of attributes */
303 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
304 struct abbrev_info
*next
; /* next in chain */
309 enum dwarf_attribute name
;
310 enum dwarf_form form
;
313 /* This data structure holds a complete die structure. */
316 enum dwarf_tag tag
; /* Tag indicating type of die */
317 unsigned short has_children
; /* Does the die have children */
318 unsigned int abbrev
; /* Abbrev number */
319 unsigned int offset
; /* Offset in .debug_info section */
320 unsigned int num_attrs
; /* Number of attributes */
321 struct attribute
*attrs
; /* An array of attributes */
322 struct die_info
*next_ref
; /* Next die in ref hash table */
323 struct die_info
*next
; /* Next die in linked list */
324 struct type
*type
; /* Cached type information */
327 /* Attributes have a name and a value */
330 enum dwarf_attribute name
;
331 enum dwarf_form form
;
335 struct dwarf_block
*blk
;
343 struct function_range
346 CORE_ADDR lowpc
, highpc
;
348 struct function_range
*next
;
351 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
353 /* Get at parts of an attribute structure */
355 #define DW_STRING(attr) ((attr)->u.str)
356 #define DW_UNSND(attr) ((attr)->u.unsnd)
357 #define DW_BLOCK(attr) ((attr)->u.blk)
358 #define DW_SND(attr) ((attr)->u.snd)
359 #define DW_ADDR(attr) ((attr)->u.addr)
361 /* Blocks are a bunch of untyped bytes. */
368 #ifndef ATTR_ALLOC_CHUNK
369 #define ATTR_ALLOC_CHUNK 4
372 /* A hash table of die offsets for following references. */
373 #ifndef REF_HASH_SIZE
374 #define REF_HASH_SIZE 1021
377 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
379 /* Obstack for allocating temporary storage used during symbol reading. */
380 static struct obstack dwarf2_tmp_obstack
;
382 /* Offset to the first byte of the current compilation unit header,
383 for resolving relative reference dies. */
384 static unsigned int cu_header_offset
;
386 /* Allocate fields for structs, unions and enums in this size. */
387 #ifndef DW_FIELD_ALLOC_CHUNK
388 #define DW_FIELD_ALLOC_CHUNK 4
391 /* The language we are debugging. */
392 static enum language cu_language
;
393 static const struct language_defn
*cu_language_defn
;
395 /* Actually data from the sections. */
396 static char *dwarf_info_buffer
;
397 static char *dwarf_abbrev_buffer
;
398 static char *dwarf_line_buffer
;
399 static char *dwarf_str_buffer
;
400 static char *dwarf_macinfo_buffer
;
401 static char *dwarf_ranges_buffer
;
402 static char *dwarf_loc_buffer
;
404 /* A zeroed version of a partial die for initialization purposes. */
405 static struct partial_die_info zeroed_partial_die
;
407 /* The generic symbol table building routines have separate lists for
408 file scope symbols and all all other scopes (local scopes). So
409 we need to select the right one to pass to add_symbol_to_list().
410 We do it by keeping a pointer to the correct list in list_in_scope.
412 FIXME: The original dwarf code just treated the file scope as the first
413 local scope, and all other local scopes as nested local scopes, and worked
414 fine. Check to see if we really need to distinguish these
416 static struct pending
**list_in_scope
= &file_symbols
;
418 /* FIXME: decode_locdesc sets these variables to describe the location
419 to the caller. These ought to be a structure or something. If
420 none of the flags are set, the object lives at the address returned
421 by decode_locdesc. */
423 static int optimized_out
; /* No ops in location in expression,
424 so object was optimized out. */
425 static int isreg
; /* Object lives in register.
426 decode_locdesc's return value is
427 the register number. */
428 static int offreg
; /* Object's address is the sum of the
429 register specified by basereg, plus
430 the offset returned. */
431 static int basereg
; /* See `offreg'. */
432 static int isderef
; /* Value described by flags above is
433 the address of a pointer to the object. */
434 static int islocal
; /* Variable is at the returned offset
435 from the frame start, but there's
436 no identified frame pointer for
437 this function, so we can't say
438 which register it's relative to;
440 static int is_thread_local
; /* Variable is at a constant offset in the
441 thread-local storage block for the
442 current thread and the dynamic linker
443 module containing this expression.
444 decode_locdesc returns the offset from
447 /* DW_AT_frame_base values for the current function.
448 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
449 contains the register number for the frame register.
450 frame_base_offset is the offset from the frame register to the
451 virtual stack frame. */
452 static int frame_base_reg
;
453 static CORE_ADDR frame_base_offset
;
455 /* This value is added to each symbol value. FIXME: Generalize to
456 the section_offsets structure used by dbxread (once this is done,
457 pass the appropriate section number to end_symtab). */
458 static CORE_ADDR baseaddr
; /* Add to each symbol value */
460 /* We put a pointer to this structure in the read_symtab_private field
462 The complete dwarf information for an objfile is kept in the
463 psymbol_obstack, so that absolute die references can be handled.
464 Most of the information in this structure is related to an entire
465 object file and could be passed via the sym_private field of the objfile.
466 It is however conceivable that dwarf2 might not be the only type
467 of symbols read from an object file. */
471 /* Pointer to start of dwarf info buffer for the objfile. */
473 char *dwarf_info_buffer
;
475 /* Offset in dwarf_info_buffer for this compilation unit. */
477 unsigned long dwarf_info_offset
;
479 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
481 char *dwarf_abbrev_buffer
;
483 /* Size of dwarf abbreviation section for the objfile. */
485 unsigned int dwarf_abbrev_size
;
487 /* Pointer to start of dwarf line buffer for the objfile. */
489 char *dwarf_line_buffer
;
491 /* Size of dwarf_line_buffer, in bytes. */
493 unsigned int dwarf_line_size
;
495 /* Pointer to start of dwarf string buffer for the objfile. */
497 char *dwarf_str_buffer
;
499 /* Size of dwarf string section for the objfile. */
501 unsigned int dwarf_str_size
;
503 /* Pointer to start of dwarf macro buffer for the objfile. */
505 char *dwarf_macinfo_buffer
;
507 /* Size of dwarf macinfo section for the objfile. */
509 unsigned int dwarf_macinfo_size
;
511 /* Pointer to start of dwarf ranges buffer for the objfile. */
513 char *dwarf_ranges_buffer
;
515 /* Size of dwarf ranges buffer for the objfile. */
517 unsigned int dwarf_ranges_size
;
519 /* Pointer to start of dwarf locations buffer for the objfile. */
521 char *dwarf_loc_buffer
;
523 /* Size of dwarf locations buffer for the objfile. */
525 unsigned int dwarf_loc_size
;
528 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
529 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
530 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
531 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
532 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
533 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
534 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
535 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
536 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
537 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
538 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
539 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
540 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
541 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
542 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
544 /* Maintain an array of referenced fundamental types for the current
545 compilation unit being read. For DWARF version 1, we have to construct
546 the fundamental types on the fly, since no information about the
547 fundamental types is supplied. Each such fundamental type is created by
548 calling a language dependent routine to create the type, and then a
549 pointer to that type is then placed in the array at the index specified
550 by it's FT_<TYPENAME> value. The array has a fixed size set by the
551 FT_NUM_MEMBERS compile time constant, which is the number of predefined
552 fundamental types gdb knows how to construct. */
553 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
555 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
556 but this would require a corresponding change in unpack_field_as_long
558 static int bits_per_byte
= 8;
560 /* The routines that read and process dies for a C struct or C++ class
561 pass lists of data member fields and lists of member function fields
562 in an instance of a field_info structure, as defined below. */
565 /* List of data member and baseclasses fields. */
568 struct nextfield
*next
;
575 /* Number of fields. */
578 /* Number of baseclasses. */
581 /* Set if the accesibility of one of the fields is not public. */
582 int non_public_fields
;
584 /* Member function fields array, entries are allocated in the order they
585 are encountered in the object file. */
588 struct nextfnfield
*next
;
589 struct fn_field fnfield
;
593 /* Member function fieldlist array, contains name of possibly overloaded
594 member function, number of overloaded member functions and a pointer
595 to the head of the member function field chain. */
600 struct nextfnfield
*head
;
604 /* Number of entries in the fnfieldlists array. */
608 /* Various complaints about symbol reading that don't abort the process */
611 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
613 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
618 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
620 complaint (&symfile_complaints
,
621 "statement list doesn't fit in .debug_line section");
625 dwarf2_complex_location_expr_complaint (void)
627 complaint (&symfile_complaints
, "location expression too complex");
631 dwarf2_unsupported_at_frame_base_complaint (const char *arg1
)
633 complaint (&symfile_complaints
,
634 "unsupported DW_AT_frame_base for function '%s'", arg1
);
638 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
641 complaint (&symfile_complaints
,
642 "const value length mismatch for '%s', got %d, expected %d", arg1
,
647 dwarf2_macros_too_long_complaint (void)
649 complaint (&symfile_complaints
,
650 "macro info runs off end of `.debug_macinfo' section");
654 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
656 complaint (&symfile_complaints
,
657 "macro debug info contains a malformed macro definition:\n`%s'",
662 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
664 complaint (&symfile_complaints
,
665 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
668 /* local function prototypes */
670 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
673 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
676 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
678 static char *scan_partial_symbols (char *, struct objfile
*,
679 CORE_ADDR
*, CORE_ADDR
*,
680 const struct comp_unit_head
*);
682 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
683 const struct comp_unit_head
*);
685 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
687 static void psymtab_to_symtab_1 (struct partial_symtab
*);
689 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int,
692 static void dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
);
694 static void dwarf2_empty_abbrev_table (void *);
696 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
697 const struct comp_unit_head
*cu_header
);
699 static char *read_partial_die (struct partial_die_info
*,
701 const struct comp_unit_head
*);
703 static char *read_full_die (struct die_info
**, bfd
*, char *,
704 const struct comp_unit_head
*);
706 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
707 bfd
*, char *, const struct comp_unit_head
*);
709 static char *read_attribute_value (struct attribute
*, unsigned,
710 bfd
*, char *, const struct comp_unit_head
*);
712 static unsigned int read_1_byte (bfd
*, char *);
714 static int read_1_signed_byte (bfd
*, char *);
716 static unsigned int read_2_bytes (bfd
*, char *);
718 static unsigned int read_4_bytes (bfd
*, char *);
720 static unsigned long read_8_bytes (bfd
*, char *);
722 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
725 static LONGEST
read_initial_length (bfd
*, char *,
726 struct comp_unit_head
*, int *bytes_read
);
728 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
731 static char *read_n_bytes (bfd
*, char *, unsigned int);
733 static char *read_string (bfd
*, char *, unsigned int *);
735 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
738 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
740 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
742 static void set_cu_language (unsigned int);
744 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
746 static int die_is_declaration (struct die_info
*);
748 static void free_line_header (struct line_header
*lh
);
750 static struct line_header
*(dwarf_decode_line_header
751 (unsigned int offset
,
753 const struct comp_unit_head
*cu_header
));
755 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
756 const struct comp_unit_head
*);
758 static void dwarf2_start_subfile (char *, char *);
760 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
761 struct objfile
*, const struct comp_unit_head
*);
763 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
764 struct objfile
*, const struct comp_unit_head
*);
766 static void dwarf2_const_value_data (struct attribute
*attr
,
770 static struct type
*die_type (struct die_info
*, struct objfile
*,
771 const struct comp_unit_head
*);
773 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
774 const struct comp_unit_head
*);
777 static struct type
*type_at_offset (unsigned int, struct objfile
*);
780 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
781 const struct comp_unit_head
*);
783 static void read_type_die (struct die_info
*, struct objfile
*,
784 const struct comp_unit_head
*);
786 static void read_typedef (struct die_info
*, struct objfile
*,
787 const struct comp_unit_head
*);
789 static void read_base_type (struct die_info
*, struct objfile
*);
791 static void read_file_scope (struct die_info
*, struct objfile
*,
792 const struct comp_unit_head
*);
794 static void read_func_scope (struct die_info
*, struct objfile
*,
795 const struct comp_unit_head
*);
797 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
798 const struct comp_unit_head
*);
800 static int dwarf2_get_pc_bounds (struct die_info
*,
801 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*,
802 const struct comp_unit_head
*);
804 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
805 struct objfile
*, const struct comp_unit_head
*);
807 static void dwarf2_attach_fields_to_type (struct field_info
*,
808 struct type
*, struct objfile
*);
810 static void dwarf2_add_member_fn (struct field_info
*,
811 struct die_info
*, struct type
*,
812 struct objfile
*objfile
,
813 const struct comp_unit_head
*);
815 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
816 struct type
*, struct objfile
*);
818 static void read_structure_scope (struct die_info
*, struct objfile
*,
819 const struct comp_unit_head
*);
821 static void read_common_block (struct die_info
*, struct objfile
*,
822 const struct comp_unit_head
*);
824 static void read_namespace (struct die_info
*die
, struct objfile
*objfile
,
825 const struct comp_unit_head
*cu_header
);
827 static void read_enumeration (struct die_info
*, struct objfile
*,
828 const struct comp_unit_head
*);
830 static struct type
*dwarf_base_type (int, int, struct objfile
*);
832 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
833 const struct comp_unit_head
*);
835 static void read_array_type (struct die_info
*, struct objfile
*,
836 const struct comp_unit_head
*);
838 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
839 const struct comp_unit_head
*);
841 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
842 const struct comp_unit_head
*);
844 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
845 const struct comp_unit_head
*);
847 static void read_tag_const_type (struct die_info
*, struct objfile
*,
848 const struct comp_unit_head
*);
850 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
851 const struct comp_unit_head
*);
853 static void read_tag_string_type (struct die_info
*, struct objfile
*);
855 static void read_subroutine_type (struct die_info
*, struct objfile
*,
856 const struct comp_unit_head
*);
858 static struct die_info
*read_comp_unit (char *, bfd
*,
859 const struct comp_unit_head
*);
861 static void free_die_list (struct die_info
*);
863 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
865 static void process_die (struct die_info
*, struct objfile
*,
866 const struct comp_unit_head
*);
868 static char *dwarf2_linkage_name (struct die_info
*);
870 static char *dwarf_tag_name (unsigned int);
872 static char *dwarf_attr_name (unsigned int);
874 static char *dwarf_form_name (unsigned int);
876 static char *dwarf_stack_op_name (unsigned int);
878 static char *dwarf_bool_name (unsigned int);
880 static char *dwarf_type_encoding_name (unsigned int);
883 static char *dwarf_cfi_name (unsigned int);
885 struct die_info
*copy_die (struct die_info
*);
888 static struct die_info
*sibling_die (struct die_info
*);
890 static void dump_die (struct die_info
*);
892 static void dump_die_list (struct die_info
*);
894 static void store_in_ref_table (unsigned int, struct die_info
*);
896 static void dwarf2_empty_hash_tables (void);
898 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
900 static struct die_info
*follow_die_ref (unsigned int);
902 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
904 /* memory allocation interface */
906 static void dwarf2_free_tmp_obstack (void *);
908 static struct dwarf_block
*dwarf_alloc_block (void);
910 static struct abbrev_info
*dwarf_alloc_abbrev (void);
912 static struct die_info
*dwarf_alloc_die (void);
914 static void initialize_cu_func_list (void);
916 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
918 static void dwarf_decode_macros (struct line_header
*, unsigned int,
919 char *, bfd
*, const struct comp_unit_head
*,
922 static int attr_form_is_block (struct attribute
*);
925 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
926 const struct comp_unit_head
*,
927 struct objfile
*objfile
);
929 /* Try to locate the sections we need for DWARF 2 debugging
930 information and return true if we have enough to do something. */
933 dwarf2_has_info (bfd
*abfd
)
935 dwarf_info_offset
= 0;
936 dwarf_abbrev_offset
= 0;
937 dwarf_line_offset
= 0;
938 dwarf_str_offset
= 0;
939 dwarf_macinfo_offset
= 0;
940 dwarf_frame_offset
= 0;
941 dwarf_eh_frame_offset
= 0;
942 dwarf_ranges_offset
= 0;
943 dwarf_loc_offset
= 0;
945 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
946 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
956 /* This function is mapped across the sections and remembers the
957 offset and size of each of the debugging sections we are interested
961 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
963 if (STREQ (sectp
->name
, INFO_SECTION
))
965 dwarf_info_offset
= sectp
->filepos
;
966 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
967 dwarf_info_section
= sectp
;
969 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
971 dwarf_abbrev_offset
= sectp
->filepos
;
972 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
973 dwarf_abbrev_section
= sectp
;
975 else if (STREQ (sectp
->name
, LINE_SECTION
))
977 dwarf_line_offset
= sectp
->filepos
;
978 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
979 dwarf_line_section
= sectp
;
981 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
983 dwarf_pubnames_offset
= sectp
->filepos
;
984 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
985 dwarf_pubnames_section
= sectp
;
987 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
989 dwarf_aranges_offset
= sectp
->filepos
;
990 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
991 dwarf_aranges_section
= sectp
;
993 else if (STREQ (sectp
->name
, LOC_SECTION
))
995 dwarf_loc_offset
= sectp
->filepos
;
996 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
997 dwarf_loc_section
= sectp
;
999 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
1001 dwarf_macinfo_offset
= sectp
->filepos
;
1002 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
1003 dwarf_macinfo_section
= sectp
;
1005 else if (STREQ (sectp
->name
, STR_SECTION
))
1007 dwarf_str_offset
= sectp
->filepos
;
1008 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
1009 dwarf_str_section
= sectp
;
1011 else if (STREQ (sectp
->name
, FRAME_SECTION
))
1013 dwarf_frame_offset
= sectp
->filepos
;
1014 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1015 dwarf_frame_section
= sectp
;
1017 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
1019 dwarf_eh_frame_offset
= sectp
->filepos
;
1020 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1021 dwarf_eh_frame_section
= sectp
;
1023 else if (STREQ (sectp
->name
, RANGES_SECTION
))
1025 dwarf_ranges_offset
= sectp
->filepos
;
1026 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1027 dwarf_ranges_section
= sectp
;
1031 /* Build a partial symbol table. */
1034 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1037 /* We definitely need the .debug_info and .debug_abbrev sections */
1039 dwarf_info_buffer
= dwarf2_read_section (objfile
,
1042 dwarf_info_section
);
1043 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1044 dwarf_abbrev_offset
,
1046 dwarf_abbrev_section
);
1048 if (dwarf_line_offset
)
1049 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1052 dwarf_line_section
);
1054 dwarf_line_buffer
= NULL
;
1056 if (dwarf_str_offset
)
1057 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1062 dwarf_str_buffer
= NULL
;
1064 if (dwarf_macinfo_offset
)
1065 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1066 dwarf_macinfo_offset
,
1068 dwarf_macinfo_section
);
1070 dwarf_macinfo_buffer
= NULL
;
1072 if (dwarf_ranges_offset
)
1073 dwarf_ranges_buffer
= dwarf2_read_section (objfile
,
1074 dwarf_ranges_offset
,
1076 dwarf_ranges_section
);
1078 dwarf_ranges_buffer
= NULL
;
1080 if (dwarf_loc_offset
)
1081 dwarf_loc_buffer
= dwarf2_read_section (objfile
,
1086 dwarf_loc_buffer
= NULL
;
1089 || (objfile
->global_psymbols
.size
== 0
1090 && objfile
->static_psymbols
.size
== 0))
1092 init_psymbol_list (objfile
, 1024);
1096 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1098 /* Things are significantly easier if we have .debug_aranges and
1099 .debug_pubnames sections */
1101 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1105 /* only test this case for now */
1107 /* In this case we have to work a bit harder */
1108 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1113 /* Build the partial symbol table from the information in the
1114 .debug_pubnames and .debug_aranges sections. */
1117 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1119 bfd
*abfd
= objfile
->obfd
;
1120 char *aranges_buffer
, *pubnames_buffer
;
1121 char *aranges_ptr
, *pubnames_ptr
;
1122 unsigned int entry_length
, version
, info_offset
, info_size
;
1124 pubnames_buffer
= dwarf2_read_section (objfile
,
1125 dwarf_pubnames_offset
,
1126 dwarf_pubnames_size
,
1127 dwarf_pubnames_section
);
1128 pubnames_ptr
= pubnames_buffer
;
1129 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1131 struct comp_unit_head cu_header
;
1134 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1136 pubnames_ptr
+= bytes_read
;
1137 version
= read_1_byte (abfd
, pubnames_ptr
);
1139 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1141 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1145 aranges_buffer
= dwarf2_read_section (objfile
,
1146 dwarf_aranges_offset
,
1148 dwarf_aranges_section
);
1153 /* Read in the comp unit header information from the debug_info at
1157 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1158 char *info_ptr
, bfd
*abfd
)
1162 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1164 info_ptr
+= bytes_read
;
1165 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1167 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1169 info_ptr
+= bytes_read
;
1170 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1172 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1173 if (signed_addr
< 0)
1174 internal_error (__FILE__
, __LINE__
,
1175 "read_comp_unit_head: dwarf from non elf file");
1176 cu_header
->signed_addr_p
= signed_addr
;
1180 /* Build the partial symbol table by doing a quick pass through the
1181 .debug_info and .debug_abbrev sections. */
1184 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1186 /* Instead of reading this into a big buffer, we should probably use
1187 mmap() on architectures that support it. (FIXME) */
1188 bfd
*abfd
= objfile
->obfd
;
1189 char *info_ptr
, *abbrev_ptr
;
1190 char *beg_of_comp_unit
;
1191 struct partial_die_info comp_unit_die
;
1192 struct partial_symtab
*pst
;
1193 struct cleanup
*back_to
;
1194 CORE_ADDR lowpc
, highpc
;
1196 info_ptr
= dwarf_info_buffer
;
1197 abbrev_ptr
= dwarf_abbrev_buffer
;
1199 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1200 the partial symbol scan, like attribute values.
1202 We could reduce our peak memory consumption during partial symbol
1203 table construction by freeing stuff from this obstack more often
1204 --- say, after processing each compilation unit, or each die ---
1205 but it turns out that this saves almost nothing. For an
1206 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1207 on dwarf2_tmp_obstack. Some investigation showed:
1209 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1210 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1211 all fixed-length values not requiring dynamic allocation.
1213 2) 30% of the attributes used the form DW_FORM_string. For
1214 DW_FORM_string, read_attribute simply hands back a pointer to
1215 the null-terminated string in dwarf_info_buffer, so no dynamic
1216 allocation is needed there either.
1218 3) The remaining 1% of the attributes all used DW_FORM_block1.
1219 75% of those were DW_AT_frame_base location lists for
1220 functions; the rest were DW_AT_location attributes, probably
1221 for the global variables.
1223 Anyway, what this all means is that the memory the dwarf2
1224 reader uses as temporary space reading partial symbols is about
1225 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1227 obstack_init (&dwarf2_tmp_obstack
);
1228 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1230 /* Since the objects we're extracting from dwarf_info_buffer vary in
1231 length, only the individual functions to extract them (like
1232 read_comp_unit_head and read_partial_die) can really know whether
1233 the buffer is large enough to hold another complete object.
1235 At the moment, they don't actually check that. If
1236 dwarf_info_buffer holds just one extra byte after the last
1237 compilation unit's dies, then read_comp_unit_head will happily
1238 read off the end of the buffer. read_partial_die is similarly
1239 casual. Those functions should be fixed.
1241 For this loop condition, simply checking whether there's any data
1242 left at all should be sufficient. */
1243 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1245 struct comp_unit_head cu_header
;
1246 beg_of_comp_unit
= info_ptr
;
1247 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1249 if (cu_header
.version
!= 2)
1251 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
));
1254 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1256 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1257 (long) cu_header
.abbrev_offset
,
1258 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1259 bfd_get_filename (abfd
));
1262 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1263 > dwarf_info_buffer
+ dwarf_info_size
)
1265 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1266 (long) cu_header
.length
,
1267 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1268 bfd_get_filename (abfd
));
1271 /* Complete the cu_header */
1272 cu_header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1273 cu_header
.first_die_ptr
= info_ptr
;
1274 cu_header
.cu_head_ptr
= beg_of_comp_unit
;
1276 /* Read the abbrevs for this compilation unit into a table */
1277 dwarf2_read_abbrevs (abfd
, &cu_header
);
1278 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1280 /* Read the compilation unit die */
1281 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1284 /* Set the language we're debugging */
1285 set_cu_language (comp_unit_die
.language
);
1287 /* Allocate a new partial symbol table structure */
1288 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1289 comp_unit_die
.name
? comp_unit_die
.name
: "",
1290 comp_unit_die
.lowpc
,
1291 objfile
->global_psymbols
.next
,
1292 objfile
->static_psymbols
.next
);
1294 pst
->read_symtab_private
= (char *)
1295 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1296 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1297 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1298 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1299 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1300 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1301 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1302 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1303 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1304 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1305 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1306 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1307 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1308 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1309 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1310 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1311 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1313 /* Store the function that reads in the rest of the symbol table */
1314 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1316 /* Check if comp unit has_children.
1317 If so, read the rest of the partial symbols from this comp unit.
1318 If not, there's no more debug_info for this comp unit. */
1319 if (comp_unit_die
.has_children
)
1321 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1324 /* If the compilation unit didn't have an explicit address range,
1325 then use the information extracted from its child dies. */
1326 if (! comp_unit_die
.has_pc_info
)
1328 comp_unit_die
.lowpc
= lowpc
;
1329 comp_unit_die
.highpc
= highpc
;
1332 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1333 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1335 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1336 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1337 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1338 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1339 sort_pst_symbols (pst
);
1341 /* If there is already a psymtab or symtab for a file of this
1342 name, remove it. (If there is a symtab, more drastic things
1343 also happen.) This happens in VxWorks. */
1344 free_named_symtabs (pst
->filename
);
1346 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1347 + cu_header
.initial_length_size
;
1349 do_cleanups (back_to
);
1352 /* Read in all interesting dies to the end of the compilation unit. */
1355 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1356 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1357 const struct comp_unit_head
*cu_header
)
1359 bfd
*abfd
= objfile
->obfd
;
1360 struct partial_die_info pdi
;
1362 /* This function is called after we've read in the comp_unit_die in
1363 order to read its children. We start the nesting level at 1 since
1364 we have pushed 1 level down in order to read the comp unit's children.
1365 The comp unit itself is at level 0, so we stop reading when we pop
1366 back to that level. */
1368 int nesting_level
= 1;
1370 /* We only want to read in symbols corresponding to variables or
1371 other similar objects that are global or static. Normally, these
1372 are all children of the DW_TAG_compile_unit die, so are all at
1373 level 1. But C++ namespaces give ries to DW_TAG_namespace dies
1374 whose children are global objects. So we keep track of what
1375 level we currently think of as referring to file scope; this
1376 should always equal 1 plus the number of namespaces that we are
1377 currently nested within. */
1379 int file_scope_level
= 1;
1381 *lowpc
= ((CORE_ADDR
) -1);
1382 *highpc
= ((CORE_ADDR
) 0);
1384 while (nesting_level
)
1386 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1388 /* Anonymous namespaces have no name but are interesting. */
1390 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
)
1394 case DW_TAG_subprogram
:
1395 if (pdi
.has_pc_info
)
1397 if (pdi
.lowpc
< *lowpc
)
1401 if (pdi
.highpc
> *highpc
)
1403 *highpc
= pdi
.highpc
;
1405 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1406 && !pdi
.is_declaration
)
1408 add_partial_symbol (&pdi
, objfile
, cu_header
);
1412 case DW_TAG_variable
:
1413 case DW_TAG_typedef
:
1414 case DW_TAG_class_type
:
1415 case DW_TAG_structure_type
:
1416 case DW_TAG_union_type
:
1417 case DW_TAG_enumeration_type
:
1418 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1419 && !pdi
.is_declaration
)
1421 add_partial_symbol (&pdi
, objfile
, cu_header
);
1424 case DW_TAG_enumerator
:
1425 /* File scope enumerators are added to the partial
1426 symbol table. They're children of the enumeration
1427 type die, so they occur at a level one higher than we
1428 normally look for. */
1429 if (nesting_level
== file_scope_level
+ 1)
1430 add_partial_symbol (&pdi
, objfile
, cu_header
);
1432 case DW_TAG_base_type
:
1433 /* File scope base type definitions are added to the partial
1435 if (nesting_level
== file_scope_level
)
1436 add_partial_symbol (&pdi
, objfile
, cu_header
);
1438 case DW_TAG_namespace
:
1439 /* FIXME: carlton/2002-10-16: we're not yet doing
1440 anything useful with this, but for now make sure that
1441 these tags at least don't cause us to miss any
1442 important symbols. */
1443 if (pdi
.has_children
)
1450 /* If the die has a sibling, skip to the sibling. Do not skip
1451 enumeration types, we want to record their enumerators. Do
1452 not skip namespaces, we want to record symbols inside
1455 && pdi
.tag
!= DW_TAG_enumeration_type
1456 && pdi
.tag
!= DW_TAG_namespace
)
1458 info_ptr
= pdi
.sibling
;
1460 else if (pdi
.has_children
)
1462 /* Die has children, but either the optional DW_AT_sibling
1463 attribute is missing or we want to look at them. */
1470 /* If this is the end of a DW_TAG_namespace entry, then
1471 decrease the file_scope_level, too. */
1472 if (nesting_level
< file_scope_level
)
1475 gdb_assert (nesting_level
== file_scope_level
);
1480 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1481 from `maint check'. */
1482 if (*lowpc
== ((CORE_ADDR
) -1))
1488 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1489 const struct comp_unit_head
*cu_header
)
1495 case DW_TAG_subprogram
:
1496 if (pdi
->is_external
)
1498 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1499 mst_text, objfile); */
1500 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1501 VAR_NAMESPACE
, LOC_BLOCK
,
1502 &objfile
->global_psymbols
,
1503 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1507 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1508 mst_file_text, objfile); */
1509 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1510 VAR_NAMESPACE
, LOC_BLOCK
,
1511 &objfile
->static_psymbols
,
1512 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1515 case DW_TAG_variable
:
1516 if (pdi
->is_external
)
1519 Don't enter into the minimal symbol tables as there is
1520 a minimal symbol table entry from the ELF symbols already.
1521 Enter into partial symbol table if it has a location
1522 descriptor or a type.
1523 If the location descriptor is missing, new_symbol will create
1524 a LOC_UNRESOLVED symbol, the address of the variable will then
1525 be determined from the minimal symbol table whenever the variable
1527 The address for the partial symbol table entry is not
1528 used by GDB, but it comes in handy for debugging partial symbol
1532 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1533 if (pdi
->locdesc
|| pdi
->has_type
)
1534 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1535 VAR_NAMESPACE
, LOC_STATIC
,
1536 &objfile
->global_psymbols
,
1537 0, addr
+ baseaddr
, cu_language
, objfile
);
1541 /* Static Variable. Skip symbols without location descriptors. */
1542 if (pdi
->locdesc
== NULL
)
1544 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1545 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1546 mst_file_data, objfile); */
1547 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1548 VAR_NAMESPACE
, LOC_STATIC
,
1549 &objfile
->static_psymbols
,
1550 0, addr
+ baseaddr
, cu_language
, objfile
);
1553 case DW_TAG_typedef
:
1554 case DW_TAG_base_type
:
1555 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1556 VAR_NAMESPACE
, LOC_TYPEDEF
,
1557 &objfile
->static_psymbols
,
1558 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1560 case DW_TAG_class_type
:
1561 case DW_TAG_structure_type
:
1562 case DW_TAG_union_type
:
1563 case DW_TAG_enumeration_type
:
1564 /* Skip aggregate types without children, these are external
1566 if (pdi
->has_children
== 0)
1568 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1569 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1570 &objfile
->static_psymbols
,
1571 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1573 if (cu_language
== language_cplus
)
1575 /* For C++, these implicitly act as typedefs as well. */
1576 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1577 VAR_NAMESPACE
, LOC_TYPEDEF
,
1578 &objfile
->static_psymbols
,
1579 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1582 case DW_TAG_enumerator
:
1583 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1584 VAR_NAMESPACE
, LOC_CONST
,
1585 &objfile
->static_psymbols
,
1586 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1593 /* Expand this partial symbol table into a full symbol table. */
1596 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1598 /* FIXME: This is barely more than a stub. */
1603 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1609 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1610 gdb_flush (gdb_stdout
);
1613 psymtab_to_symtab_1 (pst
);
1615 /* Finish up the debug error message. */
1617 printf_filtered ("done.\n");
1623 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1625 struct objfile
*objfile
= pst
->objfile
;
1626 bfd
*abfd
= objfile
->obfd
;
1627 struct comp_unit_head cu_header
;
1628 struct die_info
*dies
;
1629 unsigned long offset
;
1630 CORE_ADDR lowpc
, highpc
;
1631 struct die_info
*child_die
;
1633 struct symtab
*symtab
;
1634 struct cleanup
*back_to
;
1635 struct attribute
*attr
;
1637 /* Set local variables from the partial symbol table info. */
1638 offset
= DWARF_INFO_OFFSET (pst
);
1639 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1640 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1641 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1642 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1643 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1644 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1645 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1646 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1647 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1648 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1649 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1650 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1651 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1652 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1653 cu_header_offset
= offset
;
1654 info_ptr
= dwarf_info_buffer
+ offset
;
1656 obstack_init (&dwarf2_tmp_obstack
);
1657 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1660 make_cleanup (really_free_pendings
, NULL
);
1662 /* read in the comp_unit header */
1663 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1665 /* Read the abbrevs for this compilation unit */
1666 dwarf2_read_abbrevs (abfd
, &cu_header
);
1667 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1669 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1671 make_cleanup_free_die_list (dies
);
1673 /* Find the base address of the compilation unit for range lists and
1674 location lists. It will normally be specified by DW_AT_low_pc.
1675 In DWARF-3 draft 4, the base address could be overridden by
1676 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1677 compilation units with discontinuous ranges. */
1679 cu_header
.base_known
= 0;
1680 cu_header
.base_address
= 0;
1682 attr
= dwarf_attr (dies
, DW_AT_entry_pc
);
1685 cu_header
.base_address
= DW_ADDR (attr
);
1686 cu_header
.base_known
= 1;
1690 attr
= dwarf_attr (dies
, DW_AT_low_pc
);
1693 cu_header
.base_address
= DW_ADDR (attr
);
1694 cu_header
.base_known
= 1;
1698 /* Do line number decoding in read_file_scope () */
1699 process_die (dies
, objfile
, &cu_header
);
1701 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
, &cu_header
))
1703 /* Some compilers don't define a DW_AT_high_pc attribute for
1704 the compilation unit. If the DW_AT_high_pc is missing,
1705 synthesize it, by scanning the DIE's below the compilation unit. */
1707 if (dies
->has_children
)
1709 child_die
= dies
->next
;
1710 while (child_die
&& child_die
->tag
)
1712 if (child_die
->tag
== DW_TAG_subprogram
)
1714 CORE_ADDR low
, high
;
1716 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1717 objfile
, &cu_header
))
1719 highpc
= max (highpc
, high
);
1722 child_die
= sibling_die (child_die
);
1726 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1728 /* Set symtab language to language from DW_AT_language.
1729 If the compilation is from a C file generated by language preprocessors,
1730 do not set the language if it was already deduced by start_subfile. */
1732 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1734 symtab
->language
= cu_language
;
1736 pst
->symtab
= symtab
;
1738 sort_symtab_syms (pst
->symtab
);
1740 do_cleanups (back_to
);
1743 /* Process a die and its children. */
1746 process_die (struct die_info
*die
, struct objfile
*objfile
,
1747 const struct comp_unit_head
*cu_header
)
1751 case DW_TAG_padding
:
1753 case DW_TAG_compile_unit
:
1754 read_file_scope (die
, objfile
, cu_header
);
1756 case DW_TAG_subprogram
:
1757 read_subroutine_type (die
, objfile
, cu_header
);
1758 read_func_scope (die
, objfile
, cu_header
);
1760 case DW_TAG_inlined_subroutine
:
1761 /* FIXME: These are ignored for now.
1762 They could be used to set breakpoints on all inlined instances
1763 of a function and make GDB `next' properly over inlined functions. */
1765 case DW_TAG_lexical_block
:
1766 read_lexical_block_scope (die
, objfile
, cu_header
);
1768 case DW_TAG_class_type
:
1769 case DW_TAG_structure_type
:
1770 case DW_TAG_union_type
:
1771 read_structure_scope (die
, objfile
, cu_header
);
1773 case DW_TAG_enumeration_type
:
1774 read_enumeration (die
, objfile
, cu_header
);
1776 case DW_TAG_subroutine_type
:
1777 read_subroutine_type (die
, objfile
, cu_header
);
1779 case DW_TAG_array_type
:
1780 read_array_type (die
, objfile
, cu_header
);
1782 case DW_TAG_pointer_type
:
1783 read_tag_pointer_type (die
, objfile
, cu_header
);
1785 case DW_TAG_ptr_to_member_type
:
1786 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1788 case DW_TAG_reference_type
:
1789 read_tag_reference_type (die
, objfile
, cu_header
);
1791 case DW_TAG_string_type
:
1792 read_tag_string_type (die
, objfile
);
1794 case DW_TAG_base_type
:
1795 read_base_type (die
, objfile
);
1796 if (dwarf_attr (die
, DW_AT_name
))
1798 /* Add a typedef symbol for the base type definition. */
1799 new_symbol (die
, die
->type
, objfile
, cu_header
);
1802 case DW_TAG_common_block
:
1803 read_common_block (die
, objfile
, cu_header
);
1805 case DW_TAG_common_inclusion
:
1807 case DW_TAG_namespace
:
1808 read_namespace (die
, objfile
, cu_header
);
1810 case DW_TAG_imported_declaration
:
1811 case DW_TAG_imported_module
:
1812 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1813 information contained in these. DW_TAG_imported_declaration
1814 dies shouldn't have children; DW_TAG_imported_module dies
1815 shouldn't in the C++ case, but conceivably could in the
1816 Fortran case, so we'll have to replace this gdb_assert if
1817 Fortran compilers start generating that info. */
1818 gdb_assert (!die
->has_children
);
1821 new_symbol (die
, NULL
, objfile
, cu_header
);
1827 initialize_cu_func_list (void)
1829 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1833 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1834 const struct comp_unit_head
*cu_header
)
1836 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1837 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1838 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1839 struct attribute
*attr
;
1840 char *name
= "<unknown>";
1841 char *comp_dir
= NULL
;
1842 struct die_info
*child_die
;
1843 bfd
*abfd
= objfile
->obfd
;
1844 struct line_header
*line_header
= 0;
1846 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
1848 if (die
->has_children
)
1850 child_die
= die
->next
;
1851 while (child_die
&& child_die
->tag
)
1853 if (child_die
->tag
== DW_TAG_subprogram
)
1855 CORE_ADDR low
, high
;
1857 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1858 objfile
, cu_header
))
1860 lowpc
= min (lowpc
, low
);
1861 highpc
= max (highpc
, high
);
1864 child_die
= sibling_die (child_die
);
1869 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1870 from finish_block. */
1871 if (lowpc
== ((CORE_ADDR
) -1))
1876 attr
= dwarf_attr (die
, DW_AT_name
);
1879 name
= DW_STRING (attr
);
1881 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1884 comp_dir
= DW_STRING (attr
);
1887 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1888 directory, get rid of it. */
1889 char *cp
= strchr (comp_dir
, ':');
1891 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1896 if (objfile
->ei
.entry_point
>= lowpc
&&
1897 objfile
->ei
.entry_point
< highpc
)
1899 objfile
->ei
.entry_file_lowpc
= lowpc
;
1900 objfile
->ei
.entry_file_highpc
= highpc
;
1903 attr
= dwarf_attr (die
, DW_AT_language
);
1906 set_cu_language (DW_UNSND (attr
));
1909 /* We assume that we're processing GCC output. */
1910 processing_gcc_compilation
= 2;
1912 /* FIXME:Do something here. */
1913 if (dip
->at_producer
!= NULL
)
1915 handle_producer (dip
->at_producer
);
1919 /* The compilation unit may be in a different language or objfile,
1920 zero out all remembered fundamental types. */
1921 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1923 start_symtab (name
, comp_dir
, lowpc
);
1924 record_debugformat ("DWARF 2");
1926 initialize_cu_func_list ();
1928 /* Process all dies in compilation unit. */
1929 if (die
->has_children
)
1931 child_die
= die
->next
;
1932 while (child_die
&& child_die
->tag
)
1934 process_die (child_die
, objfile
, cu_header
);
1935 child_die
= sibling_die (child_die
);
1939 /* Decode line number information if present. */
1940 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1943 unsigned int line_offset
= DW_UNSND (attr
);
1944 line_header
= dwarf_decode_line_header (line_offset
,
1948 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1949 (void *) line_header
);
1950 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1954 /* Decode macro information, if present. Dwarf 2 macro information
1955 refers to information in the line number info statement program
1956 header, so we can only read it if we've read the header
1958 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1959 if (attr
&& line_header
)
1961 unsigned int macro_offset
= DW_UNSND (attr
);
1962 dwarf_decode_macros (line_header
, macro_offset
,
1963 comp_dir
, abfd
, cu_header
, objfile
);
1965 do_cleanups (back_to
);
1969 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1971 struct function_range
*thisfn
;
1973 thisfn
= (struct function_range
*)
1974 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1975 thisfn
->name
= name
;
1976 thisfn
->lowpc
= lowpc
;
1977 thisfn
->highpc
= highpc
;
1978 thisfn
->seen_line
= 0;
1979 thisfn
->next
= NULL
;
1981 if (cu_last_fn
== NULL
)
1982 cu_first_fn
= thisfn
;
1984 cu_last_fn
->next
= thisfn
;
1986 cu_last_fn
= thisfn
;
1990 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1991 const struct comp_unit_head
*cu_header
)
1993 register struct context_stack
*new;
1996 struct die_info
*child_die
;
1997 struct attribute
*attr
;
2000 name
= dwarf2_linkage_name (die
);
2002 /* Ignore functions with missing or empty names and functions with
2003 missing or invalid low and high pc attributes. */
2004 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2010 /* Record the function range for dwarf_decode_lines. */
2011 add_to_cu_func_list (name
, lowpc
, highpc
);
2013 if (objfile
->ei
.entry_point
>= lowpc
&&
2014 objfile
->ei
.entry_point
< highpc
)
2016 objfile
->ei
.entry_func_lowpc
= lowpc
;
2017 objfile
->ei
.entry_func_highpc
= highpc
;
2020 /* Decode DW_AT_frame_base location descriptor if present, keep result
2021 for DW_OP_fbreg operands in decode_locdesc. */
2022 frame_base_reg
= -1;
2023 frame_base_offset
= 0;
2024 attr
= dwarf_attr (die
, DW_AT_frame_base
);
2029 /* Support the .debug_loc offsets */
2030 if (attr_form_is_block (attr
))
2032 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2034 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2036 dwarf2_complex_location_expr_complaint ();
2041 dwarf2_invalid_attrib_class_complaint ("DW_AT_frame_base", name
);
2046 dwarf2_unsupported_at_frame_base_complaint (name
);
2048 frame_base_reg
= addr
;
2051 frame_base_reg
= basereg
;
2052 frame_base_offset
= addr
;
2055 dwarf2_unsupported_at_frame_base_complaint (name
);
2058 new = push_context (0, lowpc
);
2059 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
2061 /* If there was a location expression for DW_AT_frame_base above,
2062 record it. We still need to decode it above because not all
2063 symbols use location expressions exclusively. */
2065 dwarf2_symbol_mark_computed (attr
, new->name
, cu_header
, objfile
);
2067 list_in_scope
= &local_symbols
;
2069 if (die
->has_children
)
2071 child_die
= die
->next
;
2072 while (child_die
&& child_die
->tag
)
2074 process_die (child_die
, objfile
, cu_header
);
2075 child_die
= sibling_die (child_die
);
2079 new = pop_context ();
2080 /* Make a block for the local symbols within. */
2081 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2082 lowpc
, highpc
, objfile
);
2084 /* In C++, we can have functions nested inside functions (e.g., when
2085 a function declares a class that has methods). This means that
2086 when we finish processing a function scope, we may need to go
2087 back to building a containing block's symbol lists. */
2088 local_symbols
= new->locals
;
2089 param_symbols
= new->params
;
2091 /* If we've finished processing a top-level function, subsequent
2092 symbols go in the file symbol list. */
2093 if (outermost_context_p ())
2094 list_in_scope
= &file_symbols
;
2097 /* Process all the DIES contained within a lexical block scope. Start
2098 a new scope, process the dies, and then close the scope. */
2101 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
2102 const struct comp_unit_head
*cu_header
)
2104 register struct context_stack
*new;
2105 CORE_ADDR lowpc
, highpc
;
2106 struct die_info
*child_die
;
2108 /* Ignore blocks with missing or invalid low and high pc attributes. */
2109 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2110 as multiple lexical blocks? Handling children in a sane way would
2111 be nasty. Might be easier to properly extend generic blocks to
2113 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2118 push_context (0, lowpc
);
2119 if (die
->has_children
)
2121 child_die
= die
->next
;
2122 while (child_die
&& child_die
->tag
)
2124 process_die (child_die
, objfile
, cu_header
);
2125 child_die
= sibling_die (child_die
);
2128 new = pop_context ();
2130 if (local_symbols
!= NULL
)
2132 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2135 local_symbols
= new->locals
;
2138 /* Get low and high pc attributes from a die. Return 1 if the attributes
2139 are present and valid, otherwise, return 0. Return -1 if the range is
2140 discontinuous, i.e. derived from DW_AT_ranges information. */
2142 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2143 CORE_ADDR
*highpc
, struct objfile
*objfile
,
2144 const struct comp_unit_head
*cu_header
)
2146 struct attribute
*attr
;
2147 bfd
*obfd
= objfile
->obfd
;
2152 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2155 high
= DW_ADDR (attr
);
2156 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2158 low
= DW_ADDR (attr
);
2160 /* Found high w/o low attribute. */
2163 /* Found consecutive range of addresses. */
2168 attr
= dwarf_attr (die
, DW_AT_ranges
);
2171 unsigned int addr_size
= cu_header
->addr_size
;
2172 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2173 /* Value of the DW_AT_ranges attribute is the offset in the
2174 .debug_renges section. */
2175 unsigned int offset
= DW_UNSND (attr
);
2176 /* Base address selection entry. */
2185 found_base
= cu_header
->base_known
;
2186 base
= cu_header
->base_address
;
2187 buffer
= dwarf_ranges_buffer
+ offset
;
2189 /* Read in the largest possible address. */
2190 marker
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2191 if ((marker
& mask
) == mask
)
2193 /* If we found the largest possible address, then
2194 read the base address. */
2195 base
= read_address (obfd
, buffer
+ addr_size
,
2197 buffer
+= 2 * addr_size
;
2198 offset
+= 2 * addr_size
;
2206 CORE_ADDR range_beginning
, range_end
;
2208 range_beginning
= read_address (obfd
, buffer
,
2210 buffer
+= addr_size
;
2211 range_end
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2212 buffer
+= addr_size
;
2213 offset
+= 2 * addr_size
;
2215 /* An end of list marker is a pair of zero addresses. */
2216 if (range_beginning
== 0 && range_end
== 0)
2217 /* Found the end of list entry. */
2220 /* Each base address selection entry is a pair of 2 values.
2221 The first is the largest possible address, the second is
2222 the base address. Check for a base address here. */
2223 if ((range_beginning
& mask
) == mask
)
2225 /* If we found the largest possible address, then
2226 read the base address. */
2227 base
= read_address (obfd
, buffer
+ addr_size
,
2235 /* We have no valid base address for the ranges
2237 complaint (&symfile_complaints
,
2238 "Invalid .debug_ranges data (no base address)");
2242 range_beginning
+= base
;
2245 /* FIXME: This is recording everything as a low-high
2246 segment of consecutive addresses. We should have a
2247 data structure for discontiguous block ranges
2251 low
= range_beginning
;
2257 if (range_beginning
< low
)
2258 low
= range_beginning
;
2259 if (range_end
> high
)
2265 /* If the first entry is an end-of-list marker, the range
2266 describes an empty scope, i.e. no instructions. */
2276 /* When using the GNU linker, .gnu.linkonce. sections are used to
2277 eliminate duplicate copies of functions and vtables and such.
2278 The linker will arbitrarily choose one and discard the others.
2279 The AT_*_pc values for such functions refer to local labels in
2280 these sections. If the section from that file was discarded, the
2281 labels are not in the output, so the relocs get a value of 0.
2282 If this is a discarded function, mark the pc bounds as invalid,
2283 so that GDB will ignore it. */
2284 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2292 /* Add an aggregate field to the field list. */
2295 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2296 struct objfile
*objfile
,
2297 const struct comp_unit_head
*cu_header
)
2299 struct nextfield
*new_field
;
2300 struct attribute
*attr
;
2302 char *fieldname
= "";
2304 /* Allocate a new field list entry and link it in. */
2305 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2306 make_cleanup (xfree
, new_field
);
2307 memset (new_field
, 0, sizeof (struct nextfield
));
2308 new_field
->next
= fip
->fields
;
2309 fip
->fields
= new_field
;
2312 /* Handle accessibility and virtuality of field.
2313 The default accessibility for members is public, the default
2314 accessibility for inheritance is private. */
2315 if (die
->tag
!= DW_TAG_inheritance
)
2316 new_field
->accessibility
= DW_ACCESS_public
;
2318 new_field
->accessibility
= DW_ACCESS_private
;
2319 new_field
->virtuality
= DW_VIRTUALITY_none
;
2321 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2323 new_field
->accessibility
= DW_UNSND (attr
);
2324 if (new_field
->accessibility
!= DW_ACCESS_public
)
2325 fip
->non_public_fields
= 1;
2326 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2328 new_field
->virtuality
= DW_UNSND (attr
);
2330 fp
= &new_field
->field
;
2332 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2334 /* Data member other than a C++ static data member. */
2336 /* Get type of field. */
2337 fp
->type
= die_type (die
, objfile
, cu_header
);
2339 FIELD_STATIC_KIND (*fp
) = 0;
2341 /* Get bit size of field (zero if none). */
2342 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2345 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2349 FIELD_BITSIZE (*fp
) = 0;
2352 /* Get bit offset of field. */
2353 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2356 FIELD_BITPOS (*fp
) =
2357 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2360 FIELD_BITPOS (*fp
) = 0;
2361 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2364 if (BITS_BIG_ENDIAN
)
2366 /* For big endian bits, the DW_AT_bit_offset gives the
2367 additional bit offset from the MSB of the containing
2368 anonymous object to the MSB of the field. We don't
2369 have to do anything special since we don't need to
2370 know the size of the anonymous object. */
2371 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2375 /* For little endian bits, compute the bit offset to the
2376 MSB of the anonymous object, subtract off the number of
2377 bits from the MSB of the field to the MSB of the
2378 object, and then subtract off the number of bits of
2379 the field itself. The result is the bit offset of
2380 the LSB of the field. */
2382 int bit_offset
= DW_UNSND (attr
);
2384 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2387 /* The size of the anonymous object containing
2388 the bit field is explicit, so use the
2389 indicated size (in bytes). */
2390 anonymous_size
= DW_UNSND (attr
);
2394 /* The size of the anonymous object containing
2395 the bit field must be inferred from the type
2396 attribute of the data member containing the
2398 anonymous_size
= TYPE_LENGTH (fp
->type
);
2400 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2401 - bit_offset
- FIELD_BITSIZE (*fp
);
2405 /* Get name of field. */
2406 attr
= dwarf_attr (die
, DW_AT_name
);
2407 if (attr
&& DW_STRING (attr
))
2408 fieldname
= DW_STRING (attr
);
2409 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2410 &objfile
->type_obstack
);
2412 /* Change accessibility for artificial fields (e.g. virtual table
2413 pointer or virtual base class pointer) to private. */
2414 if (dwarf_attr (die
, DW_AT_artificial
))
2416 new_field
->accessibility
= DW_ACCESS_private
;
2417 fip
->non_public_fields
= 1;
2420 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2422 /* C++ static member. */
2424 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2425 is a declaration, but all versions of G++ as of this writing
2426 (so through at least 3.2.1) incorrectly generate
2427 DW_TAG_variable tags. */
2431 /* Get name of field. */
2432 attr
= dwarf_attr (die
, DW_AT_name
);
2433 if (attr
&& DW_STRING (attr
))
2434 fieldname
= DW_STRING (attr
);
2438 /* Get physical name. */
2439 physname
= dwarf2_linkage_name (die
);
2441 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2442 &objfile
->type_obstack
));
2443 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2444 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2445 &objfile
->type_obstack
);
2447 else if (die
->tag
== DW_TAG_inheritance
)
2449 /* C++ base class field. */
2450 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2452 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2454 FIELD_BITSIZE (*fp
) = 0;
2455 FIELD_STATIC_KIND (*fp
) = 0;
2456 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2457 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2458 fip
->nbaseclasses
++;
2462 /* Create the vector of fields, and attach it to the type. */
2465 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2466 struct objfile
*objfile
)
2468 int nfields
= fip
->nfields
;
2470 /* Record the field count, allocate space for the array of fields,
2471 and create blank accessibility bitfields if necessary. */
2472 TYPE_NFIELDS (type
) = nfields
;
2473 TYPE_FIELDS (type
) = (struct field
*)
2474 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2475 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2477 if (fip
->non_public_fields
)
2479 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2481 TYPE_FIELD_PRIVATE_BITS (type
) =
2482 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2483 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2485 TYPE_FIELD_PROTECTED_BITS (type
) =
2486 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2487 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2489 TYPE_FIELD_IGNORE_BITS (type
) =
2490 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2491 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2494 /* If the type has baseclasses, allocate and clear a bit vector for
2495 TYPE_FIELD_VIRTUAL_BITS. */
2496 if (fip
->nbaseclasses
)
2498 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2501 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2502 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2503 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2504 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2505 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2508 /* Copy the saved-up fields into the field vector. Start from the head
2509 of the list, adding to the tail of the field array, so that they end
2510 up in the same order in the array in which they were added to the list. */
2511 while (nfields
-- > 0)
2513 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2514 switch (fip
->fields
->accessibility
)
2516 case DW_ACCESS_private
:
2517 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2520 case DW_ACCESS_protected
:
2521 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2524 case DW_ACCESS_public
:
2528 /* Unknown accessibility. Complain and treat it as public. */
2530 complaint (&symfile_complaints
, "unsupported accessibility %d",
2531 fip
->fields
->accessibility
);
2535 if (nfields
< fip
->nbaseclasses
)
2537 switch (fip
->fields
->virtuality
)
2539 case DW_VIRTUALITY_virtual
:
2540 case DW_VIRTUALITY_pure_virtual
:
2541 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2545 fip
->fields
= fip
->fields
->next
;
2549 /* Add a member function to the proper fieldlist. */
2552 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2553 struct type
*type
, struct objfile
*objfile
,
2554 const struct comp_unit_head
*cu_header
)
2556 struct attribute
*attr
;
2557 struct fnfieldlist
*flp
;
2559 struct fn_field
*fnp
;
2562 struct nextfnfield
*new_fnfield
;
2564 /* Get name of member function. */
2565 attr
= dwarf_attr (die
, DW_AT_name
);
2566 if (attr
&& DW_STRING (attr
))
2567 fieldname
= DW_STRING (attr
);
2571 /* Get the mangled name. */
2572 physname
= dwarf2_linkage_name (die
);
2574 /* Look up member function name in fieldlist. */
2575 for (i
= 0; i
< fip
->nfnfields
; i
++)
2577 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2581 /* Create new list element if necessary. */
2582 if (i
< fip
->nfnfields
)
2583 flp
= &fip
->fnfieldlists
[i
];
2586 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2588 fip
->fnfieldlists
= (struct fnfieldlist
*)
2589 xrealloc (fip
->fnfieldlists
,
2590 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2591 * sizeof (struct fnfieldlist
));
2592 if (fip
->nfnfields
== 0)
2593 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2595 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2596 flp
->name
= fieldname
;
2602 /* Create a new member function field and chain it to the field list
2604 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2605 make_cleanup (xfree
, new_fnfield
);
2606 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2607 new_fnfield
->next
= flp
->head
;
2608 flp
->head
= new_fnfield
;
2611 /* Fill in the member function field info. */
2612 fnp
= &new_fnfield
->fnfield
;
2613 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2614 &objfile
->type_obstack
);
2615 fnp
->type
= alloc_type (objfile
);
2616 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2618 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2619 int nparams
= TYPE_NFIELDS (die
->type
);
2621 /* TYPE is the domain of this method, and DIE->TYPE is the type
2622 of the method itself (TYPE_CODE_METHOD). */
2623 smash_to_method_type (fnp
->type
, type
,
2624 TYPE_TARGET_TYPE (die
->type
),
2625 TYPE_FIELDS (die
->type
),
2626 TYPE_NFIELDS (die
->type
),
2627 TYPE_VARARGS (die
->type
));
2629 /* Handle static member functions.
2630 Dwarf2 has no clean way to discern C++ static and non-static
2631 member functions. G++ helps GDB by marking the first
2632 parameter for non-static member functions (which is the
2633 this pointer) as artificial. We obtain this information
2634 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2635 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2636 fnp
->voffset
= VOFFSET_STATIC
;
2639 complaint (&symfile_complaints
, "member function type missing for '%s'",
2642 /* Get fcontext from DW_AT_containing_type if present. */
2643 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2644 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2646 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2647 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2649 /* Get accessibility. */
2650 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2653 switch (DW_UNSND (attr
))
2655 case DW_ACCESS_private
:
2656 fnp
->is_private
= 1;
2658 case DW_ACCESS_protected
:
2659 fnp
->is_protected
= 1;
2664 /* Check for artificial methods. */
2665 attr
= dwarf_attr (die
, DW_AT_artificial
);
2666 if (attr
&& DW_UNSND (attr
) != 0)
2667 fnp
->is_artificial
= 1;
2669 /* Get index in virtual function table if it is a virtual member function. */
2670 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2673 /* Support the .debug_loc offsets */
2674 if (attr_form_is_block (attr
))
2676 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2678 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2680 dwarf2_complex_location_expr_complaint ();
2684 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2690 /* Create the vector of member function fields, and attach it to the type. */
2693 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2694 struct objfile
*objfile
)
2696 struct fnfieldlist
*flp
;
2697 int total_length
= 0;
2700 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2701 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2702 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2704 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2706 struct nextfnfield
*nfp
= flp
->head
;
2707 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2710 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2711 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2712 fn_flp
->fn_fields
= (struct fn_field
*)
2713 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2714 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2715 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2717 total_length
+= flp
->length
;
2720 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2721 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2724 /* Called when we find the DIE that starts a structure or union scope
2725 (definition) to process all dies that define the members of the
2728 NOTE: we need to call struct_type regardless of whether or not the
2729 DIE has an at_name attribute, since it might be an anonymous
2730 structure or union. This gets the type entered into our set of
2733 However, if the structure is incomplete (an opaque struct/union)
2734 then suppress creating a symbol table entry for it since gdb only
2735 wants to find the one with the complete definition. Note that if
2736 it is complete, we just call new_symbol, which does it's own
2737 checking about whether the struct/union is anonymous or not (and
2738 suppresses creating a symbol table entry itself). */
2741 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2742 const struct comp_unit_head
*cu_header
)
2745 struct attribute
*attr
;
2747 type
= alloc_type (objfile
);
2749 INIT_CPLUS_SPECIFIC (type
);
2750 attr
= dwarf_attr (die
, DW_AT_name
);
2751 if (attr
&& DW_STRING (attr
))
2753 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2754 strlen (DW_STRING (attr
)),
2755 &objfile
->type_obstack
);
2758 if (die
->tag
== DW_TAG_structure_type
)
2760 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2762 else if (die
->tag
== DW_TAG_union_type
)
2764 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2768 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2770 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2773 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2776 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2780 TYPE_LENGTH (type
) = 0;
2783 /* We need to add the type field to the die immediately so we don't
2784 infinitely recurse when dealing with pointers to the structure
2785 type within the structure itself. */
2788 if (die
->has_children
&& ! die_is_declaration (die
))
2790 struct field_info fi
;
2791 struct die_info
*child_die
;
2792 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2794 memset (&fi
, 0, sizeof (struct field_info
));
2796 child_die
= die
->next
;
2798 while (child_die
&& child_die
->tag
)
2800 if (child_die
->tag
== DW_TAG_member
2801 || child_die
->tag
== DW_TAG_variable
)
2803 /* NOTE: carlton/2002-11-05: A C++ static data member
2804 should be a DW_TAG_member that is a declaration, but
2805 all versions of G++ as of this writing (so through at
2806 least 3.2.1) incorrectly generate DW_TAG_variable
2807 tags for them instead. */
2808 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2810 else if (child_die
->tag
== DW_TAG_subprogram
)
2812 /* C++ member function. */
2813 process_die (child_die
, objfile
, cu_header
);
2814 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2816 else if (child_die
->tag
== DW_TAG_inheritance
)
2818 /* C++ base class field. */
2819 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2823 process_die (child_die
, objfile
, cu_header
);
2825 child_die
= sibling_die (child_die
);
2828 /* Attach fields and member functions to the type. */
2830 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2833 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2835 /* Get the type which refers to the base class (possibly this
2836 class itself) which contains the vtable pointer for the current
2837 class from the DW_AT_containing_type attribute. */
2839 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2841 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2843 TYPE_VPTR_BASETYPE (type
) = t
;
2846 static const char vptr_name
[] =
2847 {'_', 'v', 'p', 't', 'r', '\0'};
2850 /* Our own class provides vtbl ptr. */
2851 for (i
= TYPE_NFIELDS (t
) - 1;
2852 i
>= TYPE_N_BASECLASSES (t
);
2855 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2857 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2858 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2860 TYPE_VPTR_FIELDNO (type
) = i
;
2865 /* Complain if virtual function table field not found. */
2866 if (i
< TYPE_N_BASECLASSES (t
))
2867 complaint (&symfile_complaints
,
2868 "virtual function table pointer not found when defining class '%s'",
2869 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2874 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2879 new_symbol (die
, type
, objfile
, cu_header
);
2881 do_cleanups (back_to
);
2885 /* No children, must be stub. */
2886 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2890 /* Given a pointer to a die which begins an enumeration, process all
2891 the dies that define the members of the enumeration.
2893 This will be much nicer in draft 6 of the DWARF spec when our
2894 members will be dies instead squished into the DW_AT_element_list
2897 NOTE: We reverse the order of the element list. */
2900 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2901 const struct comp_unit_head
*cu_header
)
2903 struct die_info
*child_die
;
2905 struct field
*fields
;
2906 struct attribute
*attr
;
2909 int unsigned_enum
= 1;
2911 type
= alloc_type (objfile
);
2913 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2914 attr
= dwarf_attr (die
, DW_AT_name
);
2915 if (attr
&& DW_STRING (attr
))
2917 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2918 strlen (DW_STRING (attr
)),
2919 &objfile
->type_obstack
);
2922 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2925 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2929 TYPE_LENGTH (type
) = 0;
2934 if (die
->has_children
)
2936 child_die
= die
->next
;
2937 while (child_die
&& child_die
->tag
)
2939 if (child_die
->tag
!= DW_TAG_enumerator
)
2941 process_die (child_die
, objfile
, cu_header
);
2945 attr
= dwarf_attr (child_die
, DW_AT_name
);
2948 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2949 if (SYMBOL_VALUE (sym
) < 0)
2952 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2954 fields
= (struct field
*)
2956 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2957 * sizeof (struct field
));
2960 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
2961 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2962 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2963 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2964 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
2970 child_die
= sibling_die (child_die
);
2975 TYPE_NFIELDS (type
) = num_fields
;
2976 TYPE_FIELDS (type
) = (struct field
*)
2977 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2978 memcpy (TYPE_FIELDS (type
), fields
,
2979 sizeof (struct field
) * num_fields
);
2983 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2986 new_symbol (die
, type
, objfile
, cu_header
);
2989 /* Extract all information from a DW_TAG_array_type DIE and put it in
2990 the DIE's type field. For now, this only handles one dimensional
2994 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2995 const struct comp_unit_head
*cu_header
)
2997 struct die_info
*child_die
;
2998 struct type
*type
= NULL
;
2999 struct type
*element_type
, *range_type
, *index_type
;
3000 struct type
**range_types
= NULL
;
3001 struct attribute
*attr
;
3003 struct cleanup
*back_to
;
3005 /* Return if we've already decoded this type. */
3011 element_type
= die_type (die
, objfile
, cu_header
);
3013 /* Irix 6.2 native cc creates array types without children for
3014 arrays with unspecified length. */
3015 if (die
->has_children
== 0)
3017 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3018 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3019 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3023 back_to
= make_cleanup (null_cleanup
, NULL
);
3024 child_die
= die
->next
;
3025 while (child_die
&& child_die
->tag
)
3027 if (child_die
->tag
== DW_TAG_subrange_type
)
3029 unsigned int low
, high
;
3031 /* Default bounds to an array with unspecified length. */
3034 if (cu_language
== language_fortran
)
3036 /* FORTRAN implies a lower bound of 1, if not given. */
3040 index_type
= die_type (child_die
, objfile
, cu_header
);
3041 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
3044 if (attr
->form
== DW_FORM_sdata
)
3046 low
= DW_SND (attr
);
3048 else if (attr
->form
== DW_FORM_udata
3049 || attr
->form
== DW_FORM_data1
3050 || attr
->form
== DW_FORM_data2
3051 || attr
->form
== DW_FORM_data4
3052 || attr
->form
== DW_FORM_data8
)
3054 low
= DW_UNSND (attr
);
3058 dwarf2_non_const_array_bound_ignored_complaint
3059 (dwarf_form_name (attr
->form
));
3061 die
->type
= lookup_pointer_type (element_type
);
3068 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
3071 if (attr
->form
== DW_FORM_sdata
)
3073 high
= DW_SND (attr
);
3075 else if (attr
->form
== DW_FORM_udata
3076 || attr
->form
== DW_FORM_data1
3077 || attr
->form
== DW_FORM_data2
3078 || attr
->form
== DW_FORM_data4
3079 || attr
->form
== DW_FORM_data8
)
3081 high
= DW_UNSND (attr
);
3083 else if (attr
->form
== DW_FORM_block1
)
3085 /* GCC encodes arrays with unspecified or dynamic length
3086 with a DW_FORM_block1 attribute.
3087 FIXME: GDB does not yet know how to handle dynamic
3088 arrays properly, treat them as arrays with unspecified
3094 dwarf2_non_const_array_bound_ignored_complaint
3095 (dwarf_form_name (attr
->form
));
3097 die
->type
= lookup_pointer_type (element_type
);
3105 /* Create a range type and save it for array type creation. */
3106 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3108 range_types
= (struct type
**)
3109 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3110 * sizeof (struct type
*));
3112 make_cleanup (free_current_contents
, &range_types
);
3114 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3116 child_die
= sibling_die (child_die
);
3119 /* Dwarf2 dimensions are output from left to right, create the
3120 necessary array types in backwards order. */
3121 type
= element_type
;
3123 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3125 /* Understand Dwarf2 support for vector types (like they occur on
3126 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3127 array type. This is not part of the Dwarf2/3 standard yet, but a
3128 custom vendor extension. The main difference between a regular
3129 array and the vector variant is that vectors are passed by value
3131 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3133 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3135 do_cleanups (back_to
);
3137 /* Install the type in the die. */
3141 /* First cut: install each common block member as a global variable. */
3144 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
3145 const struct comp_unit_head
*cu_header
)
3147 struct die_info
*child_die
;
3148 struct attribute
*attr
;
3150 CORE_ADDR base
= (CORE_ADDR
) 0;
3152 attr
= dwarf_attr (die
, DW_AT_location
);
3155 /* Support the .debug_loc offsets */
3156 if (attr_form_is_block (attr
))
3158 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3160 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3162 dwarf2_complex_location_expr_complaint ();
3166 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3167 "common block member");
3170 if (die
->has_children
)
3172 child_die
= die
->next
;
3173 while (child_die
&& child_die
->tag
)
3175 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
3176 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3179 SYMBOL_VALUE_ADDRESS (sym
) =
3180 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3181 add_symbol_to_list (sym
, &global_symbols
);
3183 child_die
= sibling_die (child_die
);
3188 /* Read a C++ namespace. */
3190 /* FIXME: carlton/2002-10-16: For now, we don't actually do anything
3191 useful with the namespace data: we just process its children. */
3194 read_namespace (struct die_info
*die
, struct objfile
*objfile
,
3195 const struct comp_unit_head
*cu_header
)
3197 if (die
->has_children
)
3199 struct die_info
*child_die
= die
->next
;
3201 while (child_die
&& child_die
->tag
)
3203 process_die (child_die
, objfile
, cu_header
);
3204 child_die
= sibling_die (child_die
);
3209 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3210 the user defined type vector. */
3213 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
3214 const struct comp_unit_head
*cu_header
)
3217 struct attribute
*attr_byte_size
;
3218 struct attribute
*attr_address_class
;
3219 int byte_size
, addr_class
;
3226 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
3228 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3230 byte_size
= DW_UNSND (attr_byte_size
);
3232 byte_size
= cu_header
->addr_size
;
3234 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3235 if (attr_address_class
)
3236 addr_class
= DW_UNSND (attr_address_class
);
3238 addr_class
= DW_ADDR_none
;
3240 /* If the pointer size or address class is different than the
3241 default, create a type variant marked as such and set the
3242 length accordingly. */
3243 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3245 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3249 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3250 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3251 type
= make_type_with_address_space (type
, type_flags
);
3253 else if (TYPE_LENGTH (type
) != byte_size
)
3255 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3258 /* Should we also complain about unhandled address classes? */
3262 TYPE_LENGTH (type
) = byte_size
;
3266 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3267 the user defined type vector. */
3270 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
3271 const struct comp_unit_head
*cu_header
)
3274 struct type
*to_type
;
3275 struct type
*domain
;
3282 type
= alloc_type (objfile
);
3283 to_type
= die_type (die
, objfile
, cu_header
);
3284 domain
= die_containing_type (die
, objfile
, cu_header
);
3285 smash_to_member_type (type
, domain
, to_type
);
3290 /* Extract all information from a DW_TAG_reference_type DIE and add to
3291 the user defined type vector. */
3294 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
3295 const struct comp_unit_head
*cu_header
)
3298 struct attribute
*attr
;
3305 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
3306 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3309 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3313 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3319 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
3320 const struct comp_unit_head
*cu_header
)
3322 struct type
*base_type
;
3329 base_type
= die_type (die
, objfile
, cu_header
);
3330 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3334 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
3335 const struct comp_unit_head
*cu_header
)
3337 struct type
*base_type
;
3344 base_type
= die_type (die
, objfile
, cu_header
);
3345 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3348 /* Extract all information from a DW_TAG_string_type DIE and add to
3349 the user defined type vector. It isn't really a user defined type,
3350 but it behaves like one, with other DIE's using an AT_user_def_type
3351 attribute to reference it. */
3354 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3356 struct type
*type
, *range_type
, *index_type
, *char_type
;
3357 struct attribute
*attr
;
3358 unsigned int length
;
3365 attr
= dwarf_attr (die
, DW_AT_string_length
);
3368 length
= DW_UNSND (attr
);
3372 /* check for the DW_AT_byte_size attribute */
3373 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3376 length
= DW_UNSND (attr
);
3383 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3384 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3385 if (cu_language
== language_fortran
)
3387 /* Need to create a unique string type for bounds
3389 type
= create_string_type (0, range_type
);
3393 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3394 type
= create_string_type (char_type
, range_type
);
3399 /* Handle DIES due to C code like:
3403 int (*funcp)(int a, long l);
3407 ('funcp' generates a DW_TAG_subroutine_type DIE)
3411 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3412 const struct comp_unit_head
*cu_header
)
3414 struct type
*type
; /* Type that this function returns */
3415 struct type
*ftype
; /* Function that returns above type */
3416 struct attribute
*attr
;
3418 /* Decode the type that this subroutine returns */
3423 type
= die_type (die
, objfile
, cu_header
);
3424 ftype
= lookup_function_type (type
);
3426 /* All functions in C++ have prototypes. */
3427 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3428 if ((attr
&& (DW_UNSND (attr
) != 0))
3429 || cu_language
== language_cplus
)
3430 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3432 if (die
->has_children
)
3434 struct die_info
*child_die
;
3438 /* Count the number of parameters.
3439 FIXME: GDB currently ignores vararg functions, but knows about
3440 vararg member functions. */
3441 child_die
= die
->next
;
3442 while (child_die
&& child_die
->tag
)
3444 if (child_die
->tag
== DW_TAG_formal_parameter
)
3446 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3447 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3448 child_die
= sibling_die (child_die
);
3451 /* Allocate storage for parameters and fill them in. */
3452 TYPE_NFIELDS (ftype
) = nparams
;
3453 TYPE_FIELDS (ftype
) = (struct field
*)
3454 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3456 child_die
= die
->next
;
3457 while (child_die
&& child_die
->tag
)
3459 if (child_die
->tag
== DW_TAG_formal_parameter
)
3461 /* Dwarf2 has no clean way to discern C++ static and non-static
3462 member functions. G++ helps GDB by marking the first
3463 parameter for non-static member functions (which is the
3464 this pointer) as artificial. We pass this information
3465 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3466 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3468 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3470 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3471 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3475 child_die
= sibling_die (child_die
);
3483 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3484 const struct comp_unit_head
*cu_header
)
3486 struct attribute
*attr
;
3491 attr
= dwarf_attr (die
, DW_AT_name
);
3492 if (attr
&& DW_STRING (attr
))
3494 name
= DW_STRING (attr
);
3496 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3497 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3501 /* Find a representation of a given base type and install
3502 it in the TYPE field of the die. */
3505 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3508 struct attribute
*attr
;
3509 int encoding
= 0, size
= 0;
3511 /* If we've already decoded this die, this is a no-op. */
3517 attr
= dwarf_attr (die
, DW_AT_encoding
);
3520 encoding
= DW_UNSND (attr
);
3522 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3525 size
= DW_UNSND (attr
);
3527 attr
= dwarf_attr (die
, DW_AT_name
);
3528 if (attr
&& DW_STRING (attr
))
3530 enum type_code code
= TYPE_CODE_INT
;
3535 case DW_ATE_address
:
3536 /* Turn DW_ATE_address into a void * pointer. */
3537 code
= TYPE_CODE_PTR
;
3538 type_flags
|= TYPE_FLAG_UNSIGNED
;
3540 case DW_ATE_boolean
:
3541 code
= TYPE_CODE_BOOL
;
3542 type_flags
|= TYPE_FLAG_UNSIGNED
;
3544 case DW_ATE_complex_float
:
3545 code
= TYPE_CODE_COMPLEX
;
3548 code
= TYPE_CODE_FLT
;
3551 case DW_ATE_signed_char
:
3553 case DW_ATE_unsigned
:
3554 case DW_ATE_unsigned_char
:
3555 type_flags
|= TYPE_FLAG_UNSIGNED
;
3558 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3559 dwarf_type_encoding_name (encoding
));
3562 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3563 if (encoding
== DW_ATE_address
)
3564 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3565 else if (encoding
== DW_ATE_complex_float
)
3568 TYPE_TARGET_TYPE (type
)
3569 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3570 else if (size
== 16)
3571 TYPE_TARGET_TYPE (type
)
3572 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3574 TYPE_TARGET_TYPE (type
)
3575 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3580 type
= dwarf_base_type (encoding
, size
, objfile
);
3585 /* Read a whole compilation unit into a linked list of dies. */
3587 static struct die_info
*
3588 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3589 const struct comp_unit_head
*cu_header
)
3591 struct die_info
*first_die
, *last_die
, *die
;
3595 /* Reset die reference table; we are
3596 building new ones now. */
3597 dwarf2_empty_hash_tables ();
3601 first_die
= last_die
= NULL
;
3604 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3605 if (die
->has_children
)
3616 /* Enter die in reference hash table */
3617 store_in_ref_table (die
->offset
, die
);
3621 first_die
= last_die
= die
;
3625 last_die
->next
= die
;
3629 while (nesting_level
> 0);
3633 /* Free a linked list of dies. */
3636 free_die_list (struct die_info
*dies
)
3638 struct die_info
*die
, *next
;
3651 do_free_die_list_cleanup (void *dies
)
3653 free_die_list (dies
);
3656 static struct cleanup
*
3657 make_cleanup_free_die_list (struct die_info
*dies
)
3659 return make_cleanup (do_free_die_list_cleanup
, dies
);
3663 /* Read the contents of the section at OFFSET and of size SIZE from the
3664 object file specified by OBJFILE into the psymbol_obstack and return it. */
3667 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3668 unsigned int size
, asection
*sectp
)
3670 bfd
*abfd
= objfile
->obfd
;
3676 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3678 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
3682 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3683 (bfd_bread (buf
, size
, abfd
) != size
))
3686 error ("Dwarf Error: Can't read DWARF data from '%s'",
3687 bfd_get_filename (abfd
));
3692 /* In DWARF version 2, the description of the debugging information is
3693 stored in a separate .debug_abbrev section. Before we read any
3694 dies from a section we read in all abbreviations and install them
3698 dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
)
3701 struct abbrev_info
*cur_abbrev
;
3702 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3703 unsigned int abbrev_form
, hash_number
;
3705 /* Initialize dwarf2 abbrevs */
3706 memset (cu_header
->dwarf2_abbrevs
, 0,
3707 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3709 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3710 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3711 abbrev_ptr
+= bytes_read
;
3713 /* loop until we reach an abbrev number of 0 */
3714 while (abbrev_number
)
3716 cur_abbrev
= dwarf_alloc_abbrev ();
3718 /* read in abbrev header */
3719 cur_abbrev
->number
= abbrev_number
;
3720 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3721 abbrev_ptr
+= bytes_read
;
3722 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3725 /* now read in declarations */
3726 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3727 abbrev_ptr
+= bytes_read
;
3728 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3729 abbrev_ptr
+= bytes_read
;
3732 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3734 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3735 xrealloc (cur_abbrev
->attrs
,
3736 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3737 * sizeof (struct attr_abbrev
));
3739 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3740 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3741 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3742 abbrev_ptr
+= bytes_read
;
3743 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3744 abbrev_ptr
+= bytes_read
;
3747 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3748 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3749 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3751 /* Get next abbreviation.
3752 Under Irix6 the abbreviations for a compilation unit are not
3753 always properly terminated with an abbrev number of 0.
3754 Exit loop if we encounter an abbreviation which we have
3755 already read (which means we are about to read the abbreviations
3756 for the next compile unit) or if the end of the abbreviation
3757 table is reached. */
3758 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3759 >= dwarf_abbrev_size
)
3761 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3762 abbrev_ptr
+= bytes_read
;
3763 if (dwarf2_lookup_abbrev (abbrev_number
, cu_header
) != NULL
)
3768 /* Empty the abbrev table for a new compilation unit. */
3772 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3775 struct abbrev_info
*abbrev
, *next
;
3776 struct abbrev_info
**abbrevs
;
3778 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3780 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3783 abbrev
= abbrevs
[i
];
3786 next
= abbrev
->next
;
3787 xfree (abbrev
->attrs
);
3795 /* Lookup an abbrev_info structure in the abbrev hash table. */
3797 static struct abbrev_info
*
3798 dwarf2_lookup_abbrev (unsigned int number
, const struct comp_unit_head
*cu_header
)
3800 unsigned int hash_number
;
3801 struct abbrev_info
*abbrev
;
3803 hash_number
= number
% ABBREV_HASH_SIZE
;
3804 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3808 if (abbrev
->number
== number
)
3811 abbrev
= abbrev
->next
;
3816 /* Read a minimal amount of information into the minimal die structure. */
3819 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3820 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3822 unsigned int abbrev_number
, bytes_read
, i
;
3823 struct abbrev_info
*abbrev
;
3824 struct attribute attr
;
3825 struct attribute spec_attr
;
3826 int found_spec_attr
= 0;
3827 int has_low_pc_attr
= 0;
3828 int has_high_pc_attr
= 0;
3830 *part_die
= zeroed_partial_die
;
3831 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3832 info_ptr
+= bytes_read
;
3836 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3839 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
3840 bfd_get_filename (abfd
));
3842 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3843 part_die
->tag
= abbrev
->tag
;
3844 part_die
->has_children
= abbrev
->has_children
;
3845 part_die
->abbrev
= abbrev_number
;
3847 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3849 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3850 info_ptr
, cu_header
);
3852 /* Store the data if it is of an attribute we want to keep in a
3853 partial symbol table. */
3858 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3859 if (part_die
->name
== NULL
)
3860 part_die
->name
= DW_STRING (&attr
);
3862 case DW_AT_MIPS_linkage_name
:
3863 part_die
->name
= DW_STRING (&attr
);
3866 has_low_pc_attr
= 1;
3867 part_die
->lowpc
= DW_ADDR (&attr
);
3870 has_high_pc_attr
= 1;
3871 part_die
->highpc
= DW_ADDR (&attr
);
3873 case DW_AT_location
:
3874 /* Support the .debug_loc offsets */
3875 if (attr_form_is_block (&attr
))
3877 part_die
->locdesc
= DW_BLOCK (&attr
);
3879 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
3881 dwarf2_complex_location_expr_complaint ();
3885 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3886 "partial symbol information");
3889 case DW_AT_language
:
3890 part_die
->language
= DW_UNSND (&attr
);
3892 case DW_AT_external
:
3893 part_die
->is_external
= DW_UNSND (&attr
);
3895 case DW_AT_declaration
:
3896 part_die
->is_declaration
= DW_UNSND (&attr
);
3899 part_die
->has_type
= 1;
3901 case DW_AT_abstract_origin
:
3902 case DW_AT_specification
:
3903 found_spec_attr
= 1;
3907 /* Ignore absolute siblings, they might point outside of
3908 the current compile unit. */
3909 if (attr
.form
== DW_FORM_ref_addr
)
3910 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
3913 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3920 /* If we found a reference attribute and the die has no name, try
3921 to find a name in the referred to die. */
3923 if (found_spec_attr
&& part_die
->name
== NULL
)
3925 struct partial_die_info spec_die
;
3929 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3930 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3933 part_die
->name
= spec_die
.name
;
3935 /* Copy DW_AT_external attribute if it is set. */
3936 if (spec_die
.is_external
)
3937 part_die
->is_external
= spec_die
.is_external
;
3941 /* When using the GNU linker, .gnu.linkonce. sections are used to
3942 eliminate duplicate copies of functions and vtables and such.
3943 The linker will arbitrarily choose one and discard the others.
3944 The AT_*_pc values for such functions refer to local labels in
3945 these sections. If the section from that file was discarded, the
3946 labels are not in the output, so the relocs get a value of 0.
3947 If this is a discarded function, mark the pc bounds as invalid,
3948 so that GDB will ignore it. */
3949 if (has_low_pc_attr
&& has_high_pc_attr
3950 && part_die
->lowpc
< part_die
->highpc
3951 && (part_die
->lowpc
!= 0
3952 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3953 part_die
->has_pc_info
= 1;
3957 /* Read the die from the .debug_info section buffer. And set diep to
3958 point to a newly allocated die with its information. */
3961 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3962 const struct comp_unit_head
*cu_header
)
3964 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3965 struct abbrev_info
*abbrev
;
3966 struct die_info
*die
;
3968 offset
= info_ptr
- dwarf_info_buffer
;
3969 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3970 info_ptr
+= bytes_read
;
3973 die
= dwarf_alloc_die ();
3975 die
->abbrev
= abbrev_number
;
3981 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3984 error ("Dwarf Error: could not find abbrev number %d [in module %s]", abbrev_number
,
3985 bfd_get_filename (abfd
));
3987 die
= dwarf_alloc_die ();
3988 die
->offset
= offset
;
3989 die
->tag
= abbrev
->tag
;
3990 die
->has_children
= abbrev
->has_children
;
3991 die
->abbrev
= abbrev_number
;
3994 die
->num_attrs
= abbrev
->num_attrs
;
3995 die
->attrs
= (struct attribute
*)
3996 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3998 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4000 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4001 abfd
, info_ptr
, cu_header
);
4008 /* Read an attribute value described by an attribute form. */
4011 read_attribute_value (struct attribute
*attr
, unsigned form
,
4012 bfd
*abfd
, char *info_ptr
,
4013 const struct comp_unit_head
*cu_header
)
4015 unsigned int bytes_read
;
4016 struct dwarf_block
*blk
;
4022 case DW_FORM_ref_addr
:
4023 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
4024 info_ptr
+= bytes_read
;
4026 case DW_FORM_block2
:
4027 blk
= dwarf_alloc_block ();
4028 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4030 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4031 info_ptr
+= blk
->size
;
4032 DW_BLOCK (attr
) = blk
;
4034 case DW_FORM_block4
:
4035 blk
= dwarf_alloc_block ();
4036 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4038 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4039 info_ptr
+= blk
->size
;
4040 DW_BLOCK (attr
) = blk
;
4043 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4047 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4051 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4054 case DW_FORM_string
:
4055 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4056 info_ptr
+= bytes_read
;
4059 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4061 info_ptr
+= bytes_read
;
4064 blk
= dwarf_alloc_block ();
4065 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4066 info_ptr
+= bytes_read
;
4067 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4068 info_ptr
+= blk
->size
;
4069 DW_BLOCK (attr
) = blk
;
4071 case DW_FORM_block1
:
4072 blk
= dwarf_alloc_block ();
4073 blk
->size
= read_1_byte (abfd
, info_ptr
);
4075 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4076 info_ptr
+= blk
->size
;
4077 DW_BLOCK (attr
) = blk
;
4080 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4084 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4088 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4089 info_ptr
+= bytes_read
;
4092 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4093 info_ptr
+= bytes_read
;
4096 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4100 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4104 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4108 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4111 case DW_FORM_ref_udata
:
4112 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4113 info_ptr
+= bytes_read
;
4115 case DW_FORM_indirect
:
4116 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4117 info_ptr
+= bytes_read
;
4118 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
4121 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4122 dwarf_form_name (form
),
4123 bfd_get_filename (abfd
));
4128 /* Read an attribute described by an abbreviated attribute. */
4131 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4132 bfd
*abfd
, char *info_ptr
,
4133 const struct comp_unit_head
*cu_header
)
4135 attr
->name
= abbrev
->name
;
4136 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
4139 /* read dwarf information from a buffer */
4142 read_1_byte (bfd
*abfd
, char *buf
)
4144 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4148 read_1_signed_byte (bfd
*abfd
, char *buf
)
4150 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4154 read_2_bytes (bfd
*abfd
, char *buf
)
4156 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4160 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4162 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4166 read_4_bytes (bfd
*abfd
, char *buf
)
4168 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4172 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4174 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4177 static unsigned long
4178 read_8_bytes (bfd
*abfd
, char *buf
)
4180 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4184 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4187 CORE_ADDR retval
= 0;
4189 if (cu_header
->signed_addr_p
)
4191 switch (cu_header
->addr_size
)
4194 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4197 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4200 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4203 internal_error (__FILE__
, __LINE__
,
4204 "read_address: bad switch, signed [in module %s]",
4205 bfd_get_filename (abfd
));
4210 switch (cu_header
->addr_size
)
4213 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4216 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4219 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4222 internal_error (__FILE__
, __LINE__
,
4223 "read_address: bad switch, unsigned [in module %s]",
4224 bfd_get_filename (abfd
));
4228 *bytes_read
= cu_header
->addr_size
;
4232 /* Read the initial length from a section. The (draft) DWARF 3
4233 specification allows the initial length to take up either 4 bytes
4234 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4235 bytes describe the length and all offsets will be 8 bytes in length
4238 An older, non-standard 64-bit format is also handled by this
4239 function. The older format in question stores the initial length
4240 as an 8-byte quantity without an escape value. Lengths greater
4241 than 2^32 aren't very common which means that the initial 4 bytes
4242 is almost always zero. Since a length value of zero doesn't make
4243 sense for the 32-bit format, this initial zero can be considered to
4244 be an escape value which indicates the presence of the older 64-bit
4245 format. As written, the code can't detect (old format) lengths
4246 greater than 4GB. If it becomes necessary to handle lengths somewhat
4247 larger than 4GB, we could allow other small values (such as the
4248 non-sensical values of 1, 2, and 3) to also be used as escape values
4249 indicating the presence of the old format.
4251 The value returned via bytes_read should be used to increment
4252 the relevant pointer after calling read_initial_length().
4254 As a side effect, this function sets the fields initial_length_size
4255 and offset_size in cu_header to the values appropriate for the
4256 length field. (The format of the initial length field determines
4257 the width of file offsets to be fetched later with fetch_offset().)
4259 [ Note: read_initial_length() and read_offset() are based on the
4260 document entitled "DWARF Debugging Information Format", revision
4261 3, draft 8, dated November 19, 2001. This document was obtained
4264 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4266 This document is only a draft and is subject to change. (So beware.)
4268 Details regarding the older, non-standard 64-bit format were
4269 determined empirically by examining 64-bit ELF files produced
4270 by the SGI toolchain on an IRIX 6.5 machine.
4272 - Kevin, July 16, 2002
4276 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4281 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4283 if (retval
== 0xffffffff)
4285 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4287 if (cu_header
!= NULL
)
4289 cu_header
->initial_length_size
= 12;
4290 cu_header
->offset_size
= 8;
4293 else if (retval
== 0)
4295 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4297 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4299 if (cu_header
!= NULL
)
4301 cu_header
->initial_length_size
= 8;
4302 cu_header
->offset_size
= 8;
4308 if (cu_header
!= NULL
)
4310 cu_header
->initial_length_size
= 4;
4311 cu_header
->offset_size
= 4;
4318 /* Read an offset from the data stream. The size of the offset is
4319 given by cu_header->offset_size. */
4322 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4327 switch (cu_header
->offset_size
)
4330 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4334 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4338 internal_error (__FILE__
, __LINE__
,
4339 "read_offset: bad switch [in module %s]",
4340 bfd_get_filename (abfd
));
4347 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4349 /* If the size of a host char is 8 bits, we can return a pointer
4350 to the buffer, otherwise we have to copy the data to a buffer
4351 allocated on the temporary obstack. */
4352 gdb_assert (HOST_CHAR_BIT
== 8);
4357 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4359 /* If the size of a host char is 8 bits, we can return a pointer
4360 to the string, otherwise we have to copy the string to a buffer
4361 allocated on the temporary obstack. */
4362 gdb_assert (HOST_CHAR_BIT
== 8);
4365 *bytes_read_ptr
= 1;
4368 *bytes_read_ptr
= strlen (buf
) + 1;
4373 read_indirect_string (bfd
*abfd
, char *buf
,
4374 const struct comp_unit_head
*cu_header
,
4375 unsigned int *bytes_read_ptr
)
4377 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4378 (int *) bytes_read_ptr
);
4380 if (dwarf_str_buffer
== NULL
)
4382 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4383 bfd_get_filename (abfd
));
4386 if (str_offset
>= dwarf_str_size
)
4388 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4389 bfd_get_filename (abfd
));
4392 gdb_assert (HOST_CHAR_BIT
== 8);
4393 if (dwarf_str_buffer
[str_offset
] == '\0')
4395 return dwarf_str_buffer
+ str_offset
;
4398 static unsigned long
4399 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4401 unsigned long result
;
4402 unsigned int num_read
;
4412 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4415 result
|= ((unsigned long)(byte
& 127) << shift
);
4416 if ((byte
& 128) == 0)
4422 *bytes_read_ptr
= num_read
;
4427 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4430 int i
, shift
, size
, num_read
;
4440 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4443 result
|= ((long)(byte
& 127) << shift
);
4445 if ((byte
& 128) == 0)
4450 if ((shift
< size
) && (byte
& 0x40))
4452 result
|= -(1 << shift
);
4454 *bytes_read_ptr
= num_read
;
4459 set_cu_language (unsigned int lang
)
4465 cu_language
= language_c
;
4467 case DW_LANG_C_plus_plus
:
4468 cu_language
= language_cplus
;
4470 case DW_LANG_Fortran77
:
4471 case DW_LANG_Fortran90
:
4472 case DW_LANG_Fortran95
:
4473 cu_language
= language_fortran
;
4475 case DW_LANG_Mips_Assembler
:
4476 cu_language
= language_asm
;
4479 cu_language
= language_java
;
4483 case DW_LANG_Cobol74
:
4484 case DW_LANG_Cobol85
:
4485 case DW_LANG_Pascal83
:
4486 case DW_LANG_Modula2
:
4488 cu_language
= language_unknown
;
4491 cu_language_defn
= language_def (cu_language
);
4494 /* Return the named attribute or NULL if not there. */
4496 static struct attribute
*
4497 dwarf_attr (struct die_info
*die
, unsigned int name
)
4500 struct attribute
*spec
= NULL
;
4502 for (i
= 0; i
< die
->num_attrs
; ++i
)
4504 if (die
->attrs
[i
].name
== name
)
4506 return &die
->attrs
[i
];
4508 if (die
->attrs
[i
].name
== DW_AT_specification
4509 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4510 spec
= &die
->attrs
[i
];
4514 struct die_info
*ref_die
=
4515 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4518 return dwarf_attr (ref_die
, name
);
4525 die_is_declaration (struct die_info
*die
)
4527 return (dwarf_attr (die
, DW_AT_declaration
)
4528 && ! dwarf_attr (die
, DW_AT_specification
));
4532 /* Free the line_header structure *LH, and any arrays and strings it
4535 free_line_header (struct line_header
*lh
)
4537 if (lh
->standard_opcode_lengths
)
4538 xfree (lh
->standard_opcode_lengths
);
4540 /* Remember that all the lh->file_names[i].name pointers are
4541 pointers into debug_line_buffer, and don't need to be freed. */
4543 xfree (lh
->file_names
);
4545 /* Similarly for the include directory names. */
4546 if (lh
->include_dirs
)
4547 xfree (lh
->include_dirs
);
4553 /* Add an entry to LH's include directory table. */
4555 add_include_dir (struct line_header
*lh
, char *include_dir
)
4557 /* Grow the array if necessary. */
4558 if (lh
->include_dirs_size
== 0)
4560 lh
->include_dirs_size
= 1; /* for testing */
4561 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4562 * sizeof (*lh
->include_dirs
));
4564 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4566 lh
->include_dirs_size
*= 2;
4567 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4568 (lh
->include_dirs_size
4569 * sizeof (*lh
->include_dirs
)));
4572 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4576 /* Add an entry to LH's file name table. */
4578 add_file_name (struct line_header
*lh
,
4580 unsigned int dir_index
,
4581 unsigned int mod_time
,
4582 unsigned int length
)
4584 struct file_entry
*fe
;
4586 /* Grow the array if necessary. */
4587 if (lh
->file_names_size
== 0)
4589 lh
->file_names_size
= 1; /* for testing */
4590 lh
->file_names
= xmalloc (lh
->file_names_size
4591 * sizeof (*lh
->file_names
));
4593 else if (lh
->num_file_names
>= lh
->file_names_size
)
4595 lh
->file_names_size
*= 2;
4596 lh
->file_names
= xrealloc (lh
->file_names
,
4597 (lh
->file_names_size
4598 * sizeof (*lh
->file_names
)));
4601 fe
= &lh
->file_names
[lh
->num_file_names
++];
4603 fe
->dir_index
= dir_index
;
4604 fe
->mod_time
= mod_time
;
4605 fe
->length
= length
;
4609 /* Read the statement program header starting at OFFSET in
4610 dwarf_line_buffer, according to the endianness of ABFD. Return a
4611 pointer to a struct line_header, allocated using xmalloc.
4613 NOTE: the strings in the include directory and file name tables of
4614 the returned object point into debug_line_buffer, and must not be
4616 static struct line_header
*
4617 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4618 const struct comp_unit_head
*cu_header
)
4620 struct cleanup
*back_to
;
4621 struct line_header
*lh
;
4625 char *cur_dir
, *cur_file
;
4627 if (dwarf_line_buffer
== NULL
)
4629 complaint (&symfile_complaints
, "missing .debug_line section");
4633 /* Make sure that at least there's room for the total_length field. That
4634 could be 12 bytes long, but we're just going to fudge that. */
4635 if (offset
+ 4 >= dwarf_line_size
)
4637 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4641 lh
= xmalloc (sizeof (*lh
));
4642 memset (lh
, 0, sizeof (*lh
));
4643 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4646 line_ptr
= dwarf_line_buffer
+ offset
;
4648 /* read in the header */
4649 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4650 line_ptr
+= bytes_read
;
4651 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4653 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4656 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4657 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4659 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4660 line_ptr
+= bytes_read
;
4661 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4663 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4665 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4667 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4669 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4671 lh
->standard_opcode_lengths
4672 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4674 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4675 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4677 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4681 /* Read directory table */
4682 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4684 line_ptr
+= bytes_read
;
4685 add_include_dir (lh
, cur_dir
);
4687 line_ptr
+= bytes_read
;
4689 /* Read file name table */
4690 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4692 unsigned int dir_index
, mod_time
, length
;
4694 line_ptr
+= bytes_read
;
4695 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4696 line_ptr
+= bytes_read
;
4697 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4698 line_ptr
+= bytes_read
;
4699 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4700 line_ptr
+= bytes_read
;
4702 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4704 line_ptr
+= bytes_read
;
4705 lh
->statement_program_start
= line_ptr
;
4707 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4708 complaint (&symfile_complaints
,
4709 "line number info header doesn't fit in `.debug_line' section");
4711 discard_cleanups (back_to
);
4715 /* This function exists to work around a bug in certain compilers
4716 (particularly GCC 2.95), in which the first line number marker of a
4717 function does not show up until after the prologue, right before
4718 the second line number marker. This function shifts ADDRESS down
4719 to the beginning of the function if necessary, and is called on
4720 addresses passed to record_line. */
4723 check_cu_functions (CORE_ADDR address
)
4725 struct function_range
*fn
;
4727 /* Find the function_range containing address. */
4732 cu_cached_fn
= cu_first_fn
;
4736 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4742 while (fn
&& fn
!= cu_cached_fn
)
4743 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4753 if (address
!= fn
->lowpc
)
4754 complaint (&symfile_complaints
,
4755 "misplaced first line number at 0x%lx for '%s'",
4756 (unsigned long) address
, fn
->name
);
4761 /* Decode the line number information for the compilation unit whose
4762 line number info is at OFFSET in the .debug_line section.
4763 The compilation directory of the file is passed in COMP_DIR. */
4766 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4767 const struct comp_unit_head
*cu_header
)
4771 unsigned int i
, bytes_read
;
4773 unsigned char op_code
, extended_op
, adj_opcode
;
4775 line_ptr
= lh
->statement_program_start
;
4776 line_end
= lh
->statement_program_end
;
4778 /* Read the statement sequences until there's nothing left. */
4779 while (line_ptr
< line_end
)
4781 /* state machine registers */
4782 CORE_ADDR address
= 0;
4783 unsigned int file
= 1;
4784 unsigned int line
= 1;
4785 unsigned int column
= 0;
4786 int is_stmt
= lh
->default_is_stmt
;
4787 int basic_block
= 0;
4788 int end_sequence
= 0;
4790 /* Start a subfile for the current file of the state machine. */
4791 if (lh
->num_file_names
>= file
)
4793 /* lh->include_dirs and lh->file_names are 0-based, but the
4794 directory and file name numbers in the statement program
4796 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4799 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4802 dwarf2_start_subfile (fe
->name
, dir
);
4805 /* Decode the table. */
4806 while (!end_sequence
)
4808 op_code
= read_1_byte (abfd
, line_ptr
);
4811 if (op_code
>= lh
->opcode_base
)
4812 { /* Special operand. */
4813 adj_opcode
= op_code
- lh
->opcode_base
;
4814 address
+= (adj_opcode
/ lh
->line_range
)
4815 * lh
->minimum_instruction_length
;
4816 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4817 /* append row to matrix using current values */
4818 address
= check_cu_functions (address
);
4819 record_line (current_subfile
, line
, address
);
4822 else switch (op_code
)
4824 case DW_LNS_extended_op
:
4825 line_ptr
+= 1; /* ignore length */
4826 extended_op
= read_1_byte (abfd
, line_ptr
);
4828 switch (extended_op
)
4830 case DW_LNE_end_sequence
:
4832 record_line (current_subfile
, 0, address
);
4834 case DW_LNE_set_address
:
4835 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4836 line_ptr
+= bytes_read
;
4837 address
+= baseaddr
;
4839 case DW_LNE_define_file
:
4842 unsigned int dir_index
, mod_time
, length
;
4844 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4845 line_ptr
+= bytes_read
;
4847 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4848 line_ptr
+= bytes_read
;
4850 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4851 line_ptr
+= bytes_read
;
4853 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4854 line_ptr
+= bytes_read
;
4855 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4859 complaint (&symfile_complaints
,
4860 "mangled .debug_line section");
4865 address
= check_cu_functions (address
);
4866 record_line (current_subfile
, line
, address
);
4869 case DW_LNS_advance_pc
:
4870 address
+= lh
->minimum_instruction_length
4871 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4872 line_ptr
+= bytes_read
;
4874 case DW_LNS_advance_line
:
4875 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4876 line_ptr
+= bytes_read
;
4878 case DW_LNS_set_file
:
4880 /* lh->include_dirs and lh->file_names are 0-based,
4881 but the directory and file name numbers in the
4882 statement program are 1-based. */
4883 struct file_entry
*fe
;
4885 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4886 line_ptr
+= bytes_read
;
4887 fe
= &lh
->file_names
[file
- 1];
4889 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4892 dwarf2_start_subfile (fe
->name
, dir
);
4895 case DW_LNS_set_column
:
4896 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4897 line_ptr
+= bytes_read
;
4899 case DW_LNS_negate_stmt
:
4900 is_stmt
= (!is_stmt
);
4902 case DW_LNS_set_basic_block
:
4905 /* Add to the address register of the state machine the
4906 address increment value corresponding to special opcode
4907 255. Ie, this value is scaled by the minimum instruction
4908 length since special opcode 255 would have scaled the
4910 case DW_LNS_const_add_pc
:
4911 address
+= (lh
->minimum_instruction_length
4912 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4914 case DW_LNS_fixed_advance_pc
:
4915 address
+= read_2_bytes (abfd
, line_ptr
);
4919 { /* Unknown standard opcode, ignore it. */
4921 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4923 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4924 line_ptr
+= bytes_read
;
4932 /* Start a subfile for DWARF. FILENAME is the name of the file and
4933 DIRNAME the name of the source directory which contains FILENAME
4934 or NULL if not known.
4935 This routine tries to keep line numbers from identical absolute and
4936 relative file names in a common subfile.
4938 Using the `list' example from the GDB testsuite, which resides in
4939 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4940 of /srcdir/list0.c yields the following debugging information for list0.c:
4942 DW_AT_name: /srcdir/list0.c
4943 DW_AT_comp_dir: /compdir
4944 files.files[0].name: list0.h
4945 files.files[0].dir: /srcdir
4946 files.files[1].name: list0.c
4947 files.files[1].dir: /srcdir
4949 The line number information for list0.c has to end up in a single
4950 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4953 dwarf2_start_subfile (char *filename
, char *dirname
)
4955 /* If the filename isn't absolute, try to match an existing subfile
4956 with the full pathname. */
4958 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4960 struct subfile
*subfile
;
4961 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4963 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4965 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4967 current_subfile
= subfile
;
4974 start_subfile (filename
, dirname
);
4978 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
4979 struct objfile
*objfile
,
4980 const struct comp_unit_head
*cu_header
)
4982 /* NOTE drow/2003-01-30: There used to be a comment and some special
4983 code here to turn a symbol with DW_AT_external and a
4984 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
4985 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
4986 with some versions of binutils) where shared libraries could have
4987 relocations against symbols in their debug information - the
4988 minimal symbol would have the right address, but the debug info
4989 would not. It's no longer necessary, because we will explicitly
4990 apply relocations when we read in the debug information now. */
4992 /* A DW_AT_location attribute with no contents indicates that a
4993 variable has been optimized away. */
4994 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
4996 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5000 /* Handle one degenerate form of location expression specially, to
5001 preserve GDB's previous behavior when section offsets are
5002 specified. If this is just a DW_OP_addr then mark this symbol
5005 if (attr_form_is_block (attr
)
5006 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5007 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5011 SYMBOL_VALUE_ADDRESS (sym
) =
5012 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu_header
,
5014 fixup_symbol_section (sym
, objfile
);
5015 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5016 SYMBOL_SECTION (sym
));
5017 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5021 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5022 expression evaluator, and use LOC_COMPUTED only when necessary
5023 (i.e. when the value of a register or memory location is
5024 referenced, or a thread-local block, etc.). Then again, it might
5025 not be worthwhile. I'm assuming that it isn't unless performance
5026 or memory numbers show me otherwise. */
5028 dwarf2_symbol_mark_computed (attr
, sym
, cu_header
, objfile
);
5029 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5032 /* Given a pointer to a DWARF information entry, figure out if we need
5033 to make a symbol table entry for it, and if so, create a new entry
5034 and return a pointer to it.
5035 If TYPE is NULL, determine symbol type from the die, otherwise
5036 used the passed type. */
5038 static struct symbol
*
5039 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
5040 const struct comp_unit_head
*cu_header
)
5042 struct symbol
*sym
= NULL
;
5044 struct attribute
*attr
= NULL
;
5045 struct attribute
*attr2
= NULL
;
5048 name
= dwarf2_linkage_name (die
);
5051 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5052 sizeof (struct symbol
));
5053 OBJSTAT (objfile
, n_syms
++);
5054 memset (sym
, 0, sizeof (struct symbol
));
5056 /* Cache this symbol's name and the name's demangled form (if any). */
5057 SYMBOL_LANGUAGE (sym
) = cu_language
;
5058 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5060 /* Default assumptions.
5061 Use the passed type or decode it from the die. */
5062 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
5063 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5065 SYMBOL_TYPE (sym
) = type
;
5067 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
5068 attr
= dwarf_attr (die
, DW_AT_decl_line
);
5071 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5076 attr
= dwarf_attr (die
, DW_AT_low_pc
);
5079 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5081 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5083 case DW_TAG_subprogram
:
5084 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5086 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5087 attr2
= dwarf_attr (die
, DW_AT_external
);
5088 if (attr2
&& (DW_UNSND (attr2
) != 0))
5090 add_symbol_to_list (sym
, &global_symbols
);
5094 add_symbol_to_list (sym
, list_in_scope
);
5097 case DW_TAG_variable
:
5098 /* Compilation with minimal debug info may result in variables
5099 with missing type entries. Change the misleading `void' type
5100 to something sensible. */
5101 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5102 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5103 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5104 "<variable, no debug info>",
5106 attr
= dwarf_attr (die
, DW_AT_const_value
);
5109 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5110 attr2
= dwarf_attr (die
, DW_AT_external
);
5111 if (attr2
&& (DW_UNSND (attr2
) != 0))
5112 add_symbol_to_list (sym
, &global_symbols
);
5114 add_symbol_to_list (sym
, list_in_scope
);
5117 attr
= dwarf_attr (die
, DW_AT_location
);
5120 var_decode_location (attr
, sym
, objfile
, cu_header
);
5121 attr2
= dwarf_attr (die
, DW_AT_external
);
5122 if (attr2
&& (DW_UNSND (attr2
) != 0))
5123 add_symbol_to_list (sym
, &global_symbols
);
5125 add_symbol_to_list (sym
, list_in_scope
);
5129 /* We do not know the address of this symbol.
5130 If it is an external symbol and we have type information
5131 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5132 The address of the variable will then be determined from
5133 the minimal symbol table whenever the variable is
5135 attr2
= dwarf_attr (die
, DW_AT_external
);
5136 if (attr2
&& (DW_UNSND (attr2
) != 0)
5137 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5139 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5140 add_symbol_to_list (sym
, &global_symbols
);
5144 case DW_TAG_formal_parameter
:
5145 attr
= dwarf_attr (die
, DW_AT_location
);
5148 SYMBOL_VALUE (sym
) =
5149 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
5152 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
5153 SYMBOL_VALUE (sym
) =
5154 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
5160 if (basereg
!= frame_base_reg
)
5161 dwarf2_complex_location_expr_complaint ();
5162 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
5166 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
5167 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
5172 SYMBOL_CLASS (sym
) = LOC_ARG
;
5175 attr
= dwarf_attr (die
, DW_AT_const_value
);
5178 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5180 add_symbol_to_list (sym
, list_in_scope
);
5182 case DW_TAG_unspecified_parameters
:
5183 /* From varargs functions; gdb doesn't seem to have any
5184 interest in this information, so just ignore it for now.
5187 case DW_TAG_class_type
:
5188 case DW_TAG_structure_type
:
5189 case DW_TAG_union_type
:
5190 case DW_TAG_enumeration_type
:
5191 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5192 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
5193 add_symbol_to_list (sym
, list_in_scope
);
5195 /* The semantics of C++ state that "struct foo { ... }" also
5196 defines a typedef for "foo". Synthesize a typedef symbol so
5197 that "ptype foo" works as expected. */
5198 if (cu_language
== language_cplus
)
5200 struct symbol
*typedef_sym
= (struct symbol
*)
5201 obstack_alloc (&objfile
->symbol_obstack
,
5202 sizeof (struct symbol
));
5203 *typedef_sym
= *sym
;
5204 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
5205 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5206 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5207 obsavestring (DEPRECATED_SYMBOL_NAME (sym
),
5208 strlen (DEPRECATED_SYMBOL_NAME (sym
)),
5209 &objfile
->type_obstack
);
5210 add_symbol_to_list (typedef_sym
, list_in_scope
);
5213 case DW_TAG_typedef
:
5214 case DW_TAG_base_type
:
5215 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5216 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
5217 add_symbol_to_list (sym
, list_in_scope
);
5219 case DW_TAG_enumerator
:
5220 attr
= dwarf_attr (die
, DW_AT_const_value
);
5223 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5225 add_symbol_to_list (sym
, list_in_scope
);
5228 /* Not a tag we recognize. Hopefully we aren't processing
5229 trash data, but since we must specifically ignore things
5230 we don't recognize, there is nothing else we should do at
5232 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5233 dwarf_tag_name (die
->tag
));
5240 /* Copy constant value from an attribute to a symbol. */
5243 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5244 struct objfile
*objfile
,
5245 const struct comp_unit_head
*cu_header
)
5247 struct dwarf_block
*blk
;
5252 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5253 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5254 cu_header
->addr_size
,
5255 TYPE_LENGTH (SYMBOL_TYPE
5257 SYMBOL_VALUE_BYTES (sym
) = (char *)
5258 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5259 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5261 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5263 case DW_FORM_block1
:
5264 case DW_FORM_block2
:
5265 case DW_FORM_block4
:
5267 blk
= DW_BLOCK (attr
);
5268 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5269 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5271 TYPE_LENGTH (SYMBOL_TYPE
5273 SYMBOL_VALUE_BYTES (sym
) = (char *)
5274 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5275 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5276 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5279 /* The DW_AT_const_value attributes are supposed to carry the
5280 symbol's value "represented as it would be on the target
5281 architecture." By the time we get here, it's already been
5282 converted to host endianness, so we just need to sign- or
5283 zero-extend it as appropriate. */
5285 dwarf2_const_value_data (attr
, sym
, 8);
5288 dwarf2_const_value_data (attr
, sym
, 16);
5291 dwarf2_const_value_data (attr
, sym
, 32);
5294 dwarf2_const_value_data (attr
, sym
, 64);
5298 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5299 SYMBOL_CLASS (sym
) = LOC_CONST
;
5303 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5304 SYMBOL_CLASS (sym
) = LOC_CONST
;
5308 complaint (&symfile_complaints
,
5309 "unsupported const value attribute form: '%s'",
5310 dwarf_form_name (attr
->form
));
5311 SYMBOL_VALUE (sym
) = 0;
5312 SYMBOL_CLASS (sym
) = LOC_CONST
;
5318 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5319 or zero-extend it as appropriate for the symbol's type. */
5321 dwarf2_const_value_data (struct attribute
*attr
,
5325 LONGEST l
= DW_UNSND (attr
);
5327 if (bits
< sizeof (l
) * 8)
5329 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5330 l
&= ((LONGEST
) 1 << bits
) - 1;
5332 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5335 SYMBOL_VALUE (sym
) = l
;
5336 SYMBOL_CLASS (sym
) = LOC_CONST
;
5340 /* Return the type of the die in question using its DW_AT_type attribute. */
5342 static struct type
*
5343 die_type (struct die_info
*die
, struct objfile
*objfile
,
5344 const struct comp_unit_head
*cu_header
)
5347 struct attribute
*type_attr
;
5348 struct die_info
*type_die
;
5351 type_attr
= dwarf_attr (die
, DW_AT_type
);
5354 /* A missing DW_AT_type represents a void type. */
5355 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5359 ref
= dwarf2_get_ref_die_offset (type_attr
);
5360 type_die
= follow_die_ref (ref
);
5363 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5364 ref
, objfile
->name
);
5368 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5371 dump_die (type_die
);
5372 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5378 /* Return the containing type of the die in question using its
5379 DW_AT_containing_type attribute. */
5381 static struct type
*
5382 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5383 const struct comp_unit_head
*cu_header
)
5385 struct type
*type
= NULL
;
5386 struct attribute
*type_attr
;
5387 struct die_info
*type_die
= NULL
;
5390 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5393 ref
= dwarf2_get_ref_die_offset (type_attr
);
5394 type_die
= follow_die_ref (ref
);
5397 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5401 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5406 dump_die (type_die
);
5407 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5414 static struct type
*
5415 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5417 struct die_info
*die
;
5420 die
= follow_die_ref (offset
);
5423 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5426 type
= tag_type_to_type (die
, objfile
);
5431 static struct type
*
5432 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5433 const struct comp_unit_head
*cu_header
)
5441 read_type_die (die
, objfile
, cu_header
);
5445 error ("Dwarf Error: Cannot find type of die [in module %s]",
5453 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5454 const struct comp_unit_head
*cu_header
)
5458 case DW_TAG_class_type
:
5459 case DW_TAG_structure_type
:
5460 case DW_TAG_union_type
:
5461 read_structure_scope (die
, objfile
, cu_header
);
5463 case DW_TAG_enumeration_type
:
5464 read_enumeration (die
, objfile
, cu_header
);
5466 case DW_TAG_subprogram
:
5467 case DW_TAG_subroutine_type
:
5468 read_subroutine_type (die
, objfile
, cu_header
);
5470 case DW_TAG_array_type
:
5471 read_array_type (die
, objfile
, cu_header
);
5473 case DW_TAG_pointer_type
:
5474 read_tag_pointer_type (die
, objfile
, cu_header
);
5476 case DW_TAG_ptr_to_member_type
:
5477 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5479 case DW_TAG_reference_type
:
5480 read_tag_reference_type (die
, objfile
, cu_header
);
5482 case DW_TAG_const_type
:
5483 read_tag_const_type (die
, objfile
, cu_header
);
5485 case DW_TAG_volatile_type
:
5486 read_tag_volatile_type (die
, objfile
, cu_header
);
5488 case DW_TAG_string_type
:
5489 read_tag_string_type (die
, objfile
);
5491 case DW_TAG_typedef
:
5492 read_typedef (die
, objfile
, cu_header
);
5494 case DW_TAG_base_type
:
5495 read_base_type (die
, objfile
);
5498 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5499 dwarf_tag_name (die
->tag
));
5504 static struct type
*
5505 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5507 /* FIXME - this should not produce a new (struct type *)
5508 every time. It should cache base types. */
5512 case DW_ATE_address
:
5513 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5515 case DW_ATE_boolean
:
5516 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5518 case DW_ATE_complex_float
:
5521 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5525 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5531 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5535 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5542 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5545 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5549 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5553 case DW_ATE_signed_char
:
5554 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5556 case DW_ATE_unsigned
:
5560 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5563 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5567 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5571 case DW_ATE_unsigned_char
:
5572 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5575 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5582 copy_die (struct die_info
*old_die
)
5584 struct die_info
*new_die
;
5587 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5588 memset (new_die
, 0, sizeof (struct die_info
));
5590 new_die
->tag
= old_die
->tag
;
5591 new_die
->has_children
= old_die
->has_children
;
5592 new_die
->abbrev
= old_die
->abbrev
;
5593 new_die
->offset
= old_die
->offset
;
5594 new_die
->type
= NULL
;
5596 num_attrs
= old_die
->num_attrs
;
5597 new_die
->num_attrs
= num_attrs
;
5598 new_die
->attrs
= (struct attribute
*)
5599 xmalloc (num_attrs
* sizeof (struct attribute
));
5601 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5603 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5604 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5605 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5608 new_die
->next
= NULL
;
5613 /* Return sibling of die, NULL if no sibling. */
5615 static struct die_info
*
5616 sibling_die (struct die_info
*die
)
5618 int nesting_level
= 0;
5620 if (!die
->has_children
)
5622 if (die
->next
&& (die
->next
->tag
== 0))
5635 if (die
->has_children
)
5645 while (nesting_level
);
5646 if (die
&& (die
->tag
== 0))
5657 /* Get linkage name of a die, return NULL if not found. */
5660 dwarf2_linkage_name (struct die_info
*die
)
5662 struct attribute
*attr
;
5664 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5665 if (attr
&& DW_STRING (attr
))
5666 return DW_STRING (attr
);
5667 attr
= dwarf_attr (die
, DW_AT_name
);
5668 if (attr
&& DW_STRING (attr
))
5669 return DW_STRING (attr
);
5673 /* Convert a DIE tag into its string name. */
5676 dwarf_tag_name (register unsigned tag
)
5680 case DW_TAG_padding
:
5681 return "DW_TAG_padding";
5682 case DW_TAG_array_type
:
5683 return "DW_TAG_array_type";
5684 case DW_TAG_class_type
:
5685 return "DW_TAG_class_type";
5686 case DW_TAG_entry_point
:
5687 return "DW_TAG_entry_point";
5688 case DW_TAG_enumeration_type
:
5689 return "DW_TAG_enumeration_type";
5690 case DW_TAG_formal_parameter
:
5691 return "DW_TAG_formal_parameter";
5692 case DW_TAG_imported_declaration
:
5693 return "DW_TAG_imported_declaration";
5695 return "DW_TAG_label";
5696 case DW_TAG_lexical_block
:
5697 return "DW_TAG_lexical_block";
5699 return "DW_TAG_member";
5700 case DW_TAG_pointer_type
:
5701 return "DW_TAG_pointer_type";
5702 case DW_TAG_reference_type
:
5703 return "DW_TAG_reference_type";
5704 case DW_TAG_compile_unit
:
5705 return "DW_TAG_compile_unit";
5706 case DW_TAG_string_type
:
5707 return "DW_TAG_string_type";
5708 case DW_TAG_structure_type
:
5709 return "DW_TAG_structure_type";
5710 case DW_TAG_subroutine_type
:
5711 return "DW_TAG_subroutine_type";
5712 case DW_TAG_typedef
:
5713 return "DW_TAG_typedef";
5714 case DW_TAG_union_type
:
5715 return "DW_TAG_union_type";
5716 case DW_TAG_unspecified_parameters
:
5717 return "DW_TAG_unspecified_parameters";
5718 case DW_TAG_variant
:
5719 return "DW_TAG_variant";
5720 case DW_TAG_common_block
:
5721 return "DW_TAG_common_block";
5722 case DW_TAG_common_inclusion
:
5723 return "DW_TAG_common_inclusion";
5724 case DW_TAG_inheritance
:
5725 return "DW_TAG_inheritance";
5726 case DW_TAG_inlined_subroutine
:
5727 return "DW_TAG_inlined_subroutine";
5729 return "DW_TAG_module";
5730 case DW_TAG_ptr_to_member_type
:
5731 return "DW_TAG_ptr_to_member_type";
5732 case DW_TAG_set_type
:
5733 return "DW_TAG_set_type";
5734 case DW_TAG_subrange_type
:
5735 return "DW_TAG_subrange_type";
5736 case DW_TAG_with_stmt
:
5737 return "DW_TAG_with_stmt";
5738 case DW_TAG_access_declaration
:
5739 return "DW_TAG_access_declaration";
5740 case DW_TAG_base_type
:
5741 return "DW_TAG_base_type";
5742 case DW_TAG_catch_block
:
5743 return "DW_TAG_catch_block";
5744 case DW_TAG_const_type
:
5745 return "DW_TAG_const_type";
5746 case DW_TAG_constant
:
5747 return "DW_TAG_constant";
5748 case DW_TAG_enumerator
:
5749 return "DW_TAG_enumerator";
5750 case DW_TAG_file_type
:
5751 return "DW_TAG_file_type";
5753 return "DW_TAG_friend";
5754 case DW_TAG_namelist
:
5755 return "DW_TAG_namelist";
5756 case DW_TAG_namelist_item
:
5757 return "DW_TAG_namelist_item";
5758 case DW_TAG_packed_type
:
5759 return "DW_TAG_packed_type";
5760 case DW_TAG_subprogram
:
5761 return "DW_TAG_subprogram";
5762 case DW_TAG_template_type_param
:
5763 return "DW_TAG_template_type_param";
5764 case DW_TAG_template_value_param
:
5765 return "DW_TAG_template_value_param";
5766 case DW_TAG_thrown_type
:
5767 return "DW_TAG_thrown_type";
5768 case DW_TAG_try_block
:
5769 return "DW_TAG_try_block";
5770 case DW_TAG_variant_part
:
5771 return "DW_TAG_variant_part";
5772 case DW_TAG_variable
:
5773 return "DW_TAG_variable";
5774 case DW_TAG_volatile_type
:
5775 return "DW_TAG_volatile_type";
5776 case DW_TAG_dwarf_procedure
:
5777 return "DW_TAG_dwarf_procedure";
5778 case DW_TAG_restrict_type
:
5779 return "DW_TAG_restrict_type";
5780 case DW_TAG_interface_type
:
5781 return "DW_TAG_interface_type";
5782 case DW_TAG_namespace
:
5783 return "DW_TAG_namespace";
5784 case DW_TAG_imported_module
:
5785 return "DW_TAG_imported_module";
5786 case DW_TAG_unspecified_type
:
5787 return "DW_TAG_unspecified_type";
5788 case DW_TAG_partial_unit
:
5789 return "DW_TAG_partial_unit";
5790 case DW_TAG_imported_unit
:
5791 return "DW_TAG_imported_unit";
5792 case DW_TAG_MIPS_loop
:
5793 return "DW_TAG_MIPS_loop";
5794 case DW_TAG_format_label
:
5795 return "DW_TAG_format_label";
5796 case DW_TAG_function_template
:
5797 return "DW_TAG_function_template";
5798 case DW_TAG_class_template
:
5799 return "DW_TAG_class_template";
5801 return "DW_TAG_<unknown>";
5805 /* Convert a DWARF attribute code into its string name. */
5808 dwarf_attr_name (register unsigned attr
)
5813 return "DW_AT_sibling";
5814 case DW_AT_location
:
5815 return "DW_AT_location";
5817 return "DW_AT_name";
5818 case DW_AT_ordering
:
5819 return "DW_AT_ordering";
5820 case DW_AT_subscr_data
:
5821 return "DW_AT_subscr_data";
5822 case DW_AT_byte_size
:
5823 return "DW_AT_byte_size";
5824 case DW_AT_bit_offset
:
5825 return "DW_AT_bit_offset";
5826 case DW_AT_bit_size
:
5827 return "DW_AT_bit_size";
5828 case DW_AT_element_list
:
5829 return "DW_AT_element_list";
5830 case DW_AT_stmt_list
:
5831 return "DW_AT_stmt_list";
5833 return "DW_AT_low_pc";
5835 return "DW_AT_high_pc";
5836 case DW_AT_language
:
5837 return "DW_AT_language";
5839 return "DW_AT_member";
5841 return "DW_AT_discr";
5842 case DW_AT_discr_value
:
5843 return "DW_AT_discr_value";
5844 case DW_AT_visibility
:
5845 return "DW_AT_visibility";
5847 return "DW_AT_import";
5848 case DW_AT_string_length
:
5849 return "DW_AT_string_length";
5850 case DW_AT_common_reference
:
5851 return "DW_AT_common_reference";
5852 case DW_AT_comp_dir
:
5853 return "DW_AT_comp_dir";
5854 case DW_AT_const_value
:
5855 return "DW_AT_const_value";
5856 case DW_AT_containing_type
:
5857 return "DW_AT_containing_type";
5858 case DW_AT_default_value
:
5859 return "DW_AT_default_value";
5861 return "DW_AT_inline";
5862 case DW_AT_is_optional
:
5863 return "DW_AT_is_optional";
5864 case DW_AT_lower_bound
:
5865 return "DW_AT_lower_bound";
5866 case DW_AT_producer
:
5867 return "DW_AT_producer";
5868 case DW_AT_prototyped
:
5869 return "DW_AT_prototyped";
5870 case DW_AT_return_addr
:
5871 return "DW_AT_return_addr";
5872 case DW_AT_start_scope
:
5873 return "DW_AT_start_scope";
5874 case DW_AT_stride_size
:
5875 return "DW_AT_stride_size";
5876 case DW_AT_upper_bound
:
5877 return "DW_AT_upper_bound";
5878 case DW_AT_abstract_origin
:
5879 return "DW_AT_abstract_origin";
5880 case DW_AT_accessibility
:
5881 return "DW_AT_accessibility";
5882 case DW_AT_address_class
:
5883 return "DW_AT_address_class";
5884 case DW_AT_artificial
:
5885 return "DW_AT_artificial";
5886 case DW_AT_base_types
:
5887 return "DW_AT_base_types";
5888 case DW_AT_calling_convention
:
5889 return "DW_AT_calling_convention";
5891 return "DW_AT_count";
5892 case DW_AT_data_member_location
:
5893 return "DW_AT_data_member_location";
5894 case DW_AT_decl_column
:
5895 return "DW_AT_decl_column";
5896 case DW_AT_decl_file
:
5897 return "DW_AT_decl_file";
5898 case DW_AT_decl_line
:
5899 return "DW_AT_decl_line";
5900 case DW_AT_declaration
:
5901 return "DW_AT_declaration";
5902 case DW_AT_discr_list
:
5903 return "DW_AT_discr_list";
5904 case DW_AT_encoding
:
5905 return "DW_AT_encoding";
5906 case DW_AT_external
:
5907 return "DW_AT_external";
5908 case DW_AT_frame_base
:
5909 return "DW_AT_frame_base";
5911 return "DW_AT_friend";
5912 case DW_AT_identifier_case
:
5913 return "DW_AT_identifier_case";
5914 case DW_AT_macro_info
:
5915 return "DW_AT_macro_info";
5916 case DW_AT_namelist_items
:
5917 return "DW_AT_namelist_items";
5918 case DW_AT_priority
:
5919 return "DW_AT_priority";
5921 return "DW_AT_segment";
5922 case DW_AT_specification
:
5923 return "DW_AT_specification";
5924 case DW_AT_static_link
:
5925 return "DW_AT_static_link";
5927 return "DW_AT_type";
5928 case DW_AT_use_location
:
5929 return "DW_AT_use_location";
5930 case DW_AT_variable_parameter
:
5931 return "DW_AT_variable_parameter";
5932 case DW_AT_virtuality
:
5933 return "DW_AT_virtuality";
5934 case DW_AT_vtable_elem_location
:
5935 return "DW_AT_vtable_elem_location";
5936 case DW_AT_allocated
:
5937 return "DW_AT_allocated";
5938 case DW_AT_associated
:
5939 return "DW_AT_associated";
5940 case DW_AT_data_location
:
5941 return "DW_AT_data_location";
5943 return "DW_AT_stride";
5944 case DW_AT_entry_pc
:
5945 return "DW_AT_entry_pc";
5946 case DW_AT_use_UTF8
:
5947 return "DW_AT_use_UTF8";
5948 case DW_AT_extension
:
5949 return "DW_AT_extension";
5951 return "DW_AT_ranges";
5952 case DW_AT_trampoline
:
5953 return "DW_AT_trampoline";
5954 case DW_AT_call_column
:
5955 return "DW_AT_call_column";
5956 case DW_AT_call_file
:
5957 return "DW_AT_call_file";
5958 case DW_AT_call_line
:
5959 return "DW_AT_call_line";
5961 case DW_AT_MIPS_fde
:
5962 return "DW_AT_MIPS_fde";
5963 case DW_AT_MIPS_loop_begin
:
5964 return "DW_AT_MIPS_loop_begin";
5965 case DW_AT_MIPS_tail_loop_begin
:
5966 return "DW_AT_MIPS_tail_loop_begin";
5967 case DW_AT_MIPS_epilog_begin
:
5968 return "DW_AT_MIPS_epilog_begin";
5969 case DW_AT_MIPS_loop_unroll_factor
:
5970 return "DW_AT_MIPS_loop_unroll_factor";
5971 case DW_AT_MIPS_software_pipeline_depth
:
5972 return "DW_AT_MIPS_software_pipeline_depth";
5973 case DW_AT_MIPS_linkage_name
:
5974 return "DW_AT_MIPS_linkage_name";
5977 case DW_AT_sf_names
:
5978 return "DW_AT_sf_names";
5979 case DW_AT_src_info
:
5980 return "DW_AT_src_info";
5981 case DW_AT_mac_info
:
5982 return "DW_AT_mac_info";
5983 case DW_AT_src_coords
:
5984 return "DW_AT_src_coords";
5985 case DW_AT_body_begin
:
5986 return "DW_AT_body_begin";
5987 case DW_AT_body_end
:
5988 return "DW_AT_body_end";
5989 case DW_AT_GNU_vector
:
5990 return "DW_AT_GNU_vector";
5992 return "DW_AT_<unknown>";
5996 /* Convert a DWARF value form code into its string name. */
5999 dwarf_form_name (register unsigned form
)
6004 return "DW_FORM_addr";
6005 case DW_FORM_block2
:
6006 return "DW_FORM_block2";
6007 case DW_FORM_block4
:
6008 return "DW_FORM_block4";
6010 return "DW_FORM_data2";
6012 return "DW_FORM_data4";
6014 return "DW_FORM_data8";
6015 case DW_FORM_string
:
6016 return "DW_FORM_string";
6018 return "DW_FORM_block";
6019 case DW_FORM_block1
:
6020 return "DW_FORM_block1";
6022 return "DW_FORM_data1";
6024 return "DW_FORM_flag";
6026 return "DW_FORM_sdata";
6028 return "DW_FORM_strp";
6030 return "DW_FORM_udata";
6031 case DW_FORM_ref_addr
:
6032 return "DW_FORM_ref_addr";
6034 return "DW_FORM_ref1";
6036 return "DW_FORM_ref2";
6038 return "DW_FORM_ref4";
6040 return "DW_FORM_ref8";
6041 case DW_FORM_ref_udata
:
6042 return "DW_FORM_ref_udata";
6043 case DW_FORM_indirect
:
6044 return "DW_FORM_indirect";
6046 return "DW_FORM_<unknown>";
6050 /* Convert a DWARF stack opcode into its string name. */
6053 dwarf_stack_op_name (register unsigned op
)
6058 return "DW_OP_addr";
6060 return "DW_OP_deref";
6062 return "DW_OP_const1u";
6064 return "DW_OP_const1s";
6066 return "DW_OP_const2u";
6068 return "DW_OP_const2s";
6070 return "DW_OP_const4u";
6072 return "DW_OP_const4s";
6074 return "DW_OP_const8u";
6076 return "DW_OP_const8s";
6078 return "DW_OP_constu";
6080 return "DW_OP_consts";
6084 return "DW_OP_drop";
6086 return "DW_OP_over";
6088 return "DW_OP_pick";
6090 return "DW_OP_swap";
6094 return "DW_OP_xderef";
6102 return "DW_OP_minus";
6114 return "DW_OP_plus";
6115 case DW_OP_plus_uconst
:
6116 return "DW_OP_plus_uconst";
6122 return "DW_OP_shra";
6140 return "DW_OP_skip";
6142 return "DW_OP_lit0";
6144 return "DW_OP_lit1";
6146 return "DW_OP_lit2";
6148 return "DW_OP_lit3";
6150 return "DW_OP_lit4";
6152 return "DW_OP_lit5";
6154 return "DW_OP_lit6";
6156 return "DW_OP_lit7";
6158 return "DW_OP_lit8";
6160 return "DW_OP_lit9";
6162 return "DW_OP_lit10";
6164 return "DW_OP_lit11";
6166 return "DW_OP_lit12";
6168 return "DW_OP_lit13";
6170 return "DW_OP_lit14";
6172 return "DW_OP_lit15";
6174 return "DW_OP_lit16";
6176 return "DW_OP_lit17";
6178 return "DW_OP_lit18";
6180 return "DW_OP_lit19";
6182 return "DW_OP_lit20";
6184 return "DW_OP_lit21";
6186 return "DW_OP_lit22";
6188 return "DW_OP_lit23";
6190 return "DW_OP_lit24";
6192 return "DW_OP_lit25";
6194 return "DW_OP_lit26";
6196 return "DW_OP_lit27";
6198 return "DW_OP_lit28";
6200 return "DW_OP_lit29";
6202 return "DW_OP_lit30";
6204 return "DW_OP_lit31";
6206 return "DW_OP_reg0";
6208 return "DW_OP_reg1";
6210 return "DW_OP_reg2";
6212 return "DW_OP_reg3";
6214 return "DW_OP_reg4";
6216 return "DW_OP_reg5";
6218 return "DW_OP_reg6";
6220 return "DW_OP_reg7";
6222 return "DW_OP_reg8";
6224 return "DW_OP_reg9";
6226 return "DW_OP_reg10";
6228 return "DW_OP_reg11";
6230 return "DW_OP_reg12";
6232 return "DW_OP_reg13";
6234 return "DW_OP_reg14";
6236 return "DW_OP_reg15";
6238 return "DW_OP_reg16";
6240 return "DW_OP_reg17";
6242 return "DW_OP_reg18";
6244 return "DW_OP_reg19";
6246 return "DW_OP_reg20";
6248 return "DW_OP_reg21";
6250 return "DW_OP_reg22";
6252 return "DW_OP_reg23";
6254 return "DW_OP_reg24";
6256 return "DW_OP_reg25";
6258 return "DW_OP_reg26";
6260 return "DW_OP_reg27";
6262 return "DW_OP_reg28";
6264 return "DW_OP_reg29";
6266 return "DW_OP_reg30";
6268 return "DW_OP_reg31";
6270 return "DW_OP_breg0";
6272 return "DW_OP_breg1";
6274 return "DW_OP_breg2";
6276 return "DW_OP_breg3";
6278 return "DW_OP_breg4";
6280 return "DW_OP_breg5";
6282 return "DW_OP_breg6";
6284 return "DW_OP_breg7";
6286 return "DW_OP_breg8";
6288 return "DW_OP_breg9";
6290 return "DW_OP_breg10";
6292 return "DW_OP_breg11";
6294 return "DW_OP_breg12";
6296 return "DW_OP_breg13";
6298 return "DW_OP_breg14";
6300 return "DW_OP_breg15";
6302 return "DW_OP_breg16";
6304 return "DW_OP_breg17";
6306 return "DW_OP_breg18";
6308 return "DW_OP_breg19";
6310 return "DW_OP_breg20";
6312 return "DW_OP_breg21";
6314 return "DW_OP_breg22";
6316 return "DW_OP_breg23";
6318 return "DW_OP_breg24";
6320 return "DW_OP_breg25";
6322 return "DW_OP_breg26";
6324 return "DW_OP_breg27";
6326 return "DW_OP_breg28";
6328 return "DW_OP_breg29";
6330 return "DW_OP_breg30";
6332 return "DW_OP_breg31";
6334 return "DW_OP_regx";
6336 return "DW_OP_fbreg";
6338 return "DW_OP_bregx";
6340 return "DW_OP_piece";
6341 case DW_OP_deref_size
:
6342 return "DW_OP_deref_size";
6343 case DW_OP_xderef_size
:
6344 return "DW_OP_xderef_size";
6347 /* DWARF 3 extensions. */
6348 case DW_OP_push_object_address
:
6349 return "DW_OP_push_object_address";
6351 return "DW_OP_call2";
6353 return "DW_OP_call4";
6354 case DW_OP_call_ref
:
6355 return "DW_OP_call_ref";
6356 /* GNU extensions. */
6357 case DW_OP_GNU_push_tls_address
:
6358 return "DW_OP_GNU_push_tls_address";
6360 return "OP_<unknown>";
6365 dwarf_bool_name (unsigned mybool
)
6373 /* Convert a DWARF type code into its string name. */
6376 dwarf_type_encoding_name (register unsigned enc
)
6380 case DW_ATE_address
:
6381 return "DW_ATE_address";
6382 case DW_ATE_boolean
:
6383 return "DW_ATE_boolean";
6384 case DW_ATE_complex_float
:
6385 return "DW_ATE_complex_float";
6387 return "DW_ATE_float";
6389 return "DW_ATE_signed";
6390 case DW_ATE_signed_char
:
6391 return "DW_ATE_signed_char";
6392 case DW_ATE_unsigned
:
6393 return "DW_ATE_unsigned";
6394 case DW_ATE_unsigned_char
:
6395 return "DW_ATE_unsigned_char";
6396 case DW_ATE_imaginary_float
:
6397 return "DW_ATE_imaginary_float";
6399 return "DW_ATE_<unknown>";
6403 /* Convert a DWARF call frame info operation to its string name. */
6407 dwarf_cfi_name (register unsigned cfi_opc
)
6411 case DW_CFA_advance_loc
:
6412 return "DW_CFA_advance_loc";
6414 return "DW_CFA_offset";
6415 case DW_CFA_restore
:
6416 return "DW_CFA_restore";
6418 return "DW_CFA_nop";
6419 case DW_CFA_set_loc
:
6420 return "DW_CFA_set_loc";
6421 case DW_CFA_advance_loc1
:
6422 return "DW_CFA_advance_loc1";
6423 case DW_CFA_advance_loc2
:
6424 return "DW_CFA_advance_loc2";
6425 case DW_CFA_advance_loc4
:
6426 return "DW_CFA_advance_loc4";
6427 case DW_CFA_offset_extended
:
6428 return "DW_CFA_offset_extended";
6429 case DW_CFA_restore_extended
:
6430 return "DW_CFA_restore_extended";
6431 case DW_CFA_undefined
:
6432 return "DW_CFA_undefined";
6433 case DW_CFA_same_value
:
6434 return "DW_CFA_same_value";
6435 case DW_CFA_register
:
6436 return "DW_CFA_register";
6437 case DW_CFA_remember_state
:
6438 return "DW_CFA_remember_state";
6439 case DW_CFA_restore_state
:
6440 return "DW_CFA_restore_state";
6441 case DW_CFA_def_cfa
:
6442 return "DW_CFA_def_cfa";
6443 case DW_CFA_def_cfa_register
:
6444 return "DW_CFA_def_cfa_register";
6445 case DW_CFA_def_cfa_offset
:
6446 return "DW_CFA_def_cfa_offset";
6449 case DW_CFA_def_cfa_expression
:
6450 return "DW_CFA_def_cfa_expression";
6451 case DW_CFA_expression
:
6452 return "DW_CFA_expression";
6453 case DW_CFA_offset_extended_sf
:
6454 return "DW_CFA_offset_extended_sf";
6455 case DW_CFA_def_cfa_sf
:
6456 return "DW_CFA_def_cfa_sf";
6457 case DW_CFA_def_cfa_offset_sf
:
6458 return "DW_CFA_def_cfa_offset_sf";
6460 /* SGI/MIPS specific */
6461 case DW_CFA_MIPS_advance_loc8
:
6462 return "DW_CFA_MIPS_advance_loc8";
6464 /* GNU extensions */
6465 case DW_CFA_GNU_window_save
:
6466 return "DW_CFA_GNU_window_save";
6467 case DW_CFA_GNU_args_size
:
6468 return "DW_CFA_GNU_args_size";
6469 case DW_CFA_GNU_negative_offset_extended
:
6470 return "DW_CFA_GNU_negative_offset_extended";
6473 return "DW_CFA_<unknown>";
6479 dump_die (struct die_info
*die
)
6483 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6484 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6485 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6486 dwarf_bool_name (die
->has_children
));
6488 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6489 for (i
= 0; i
< die
->num_attrs
; ++i
)
6491 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6492 dwarf_attr_name (die
->attrs
[i
].name
),
6493 dwarf_form_name (die
->attrs
[i
].form
));
6494 switch (die
->attrs
[i
].form
)
6496 case DW_FORM_ref_addr
:
6498 fprintf_unfiltered (gdb_stderr
, "address: ");
6499 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6501 case DW_FORM_block2
:
6502 case DW_FORM_block4
:
6504 case DW_FORM_block1
:
6505 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6516 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6518 case DW_FORM_string
:
6520 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6521 DW_STRING (&die
->attrs
[i
])
6522 ? DW_STRING (&die
->attrs
[i
]) : "");
6525 if (DW_UNSND (&die
->attrs
[i
]))
6526 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6528 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6530 case DW_FORM_indirect
:
6531 /* the reader will have reduced the indirect form to
6532 the "base form" so this form should not occur */
6533 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6536 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6537 die
->attrs
[i
].form
);
6539 fprintf_unfiltered (gdb_stderr
, "\n");
6544 dump_die_list (struct die_info
*die
)
6554 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6557 struct die_info
*old
;
6559 h
= (offset
% REF_HASH_SIZE
);
6560 old
= die_ref_table
[h
];
6561 die
->next_ref
= old
;
6562 die_ref_table
[h
] = die
;
6567 dwarf2_empty_hash_tables (void)
6569 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6573 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6575 unsigned int result
= 0;
6579 case DW_FORM_ref_addr
:
6580 result
= DW_ADDR (attr
);
6586 case DW_FORM_ref_udata
:
6587 result
= cu_header_offset
+ DW_UNSND (attr
);
6590 complaint (&symfile_complaints
,
6591 "unsupported die ref attribute form: '%s'",
6592 dwarf_form_name (attr
->form
));
6597 static struct die_info
*
6598 follow_die_ref (unsigned int offset
)
6600 struct die_info
*die
;
6603 h
= (offset
% REF_HASH_SIZE
);
6604 die
= die_ref_table
[h
];
6607 if (die
->offset
== offset
)
6611 die
= die
->next_ref
;
6616 static struct type
*
6617 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6619 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6621 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6622 typeid, objfile
->name
);
6625 /* Look for this particular type in the fundamental type vector. If
6626 one is not found, create and install one appropriate for the
6627 current language and the current target machine. */
6629 if (ftypes
[typeid] == NULL
)
6631 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6634 return (ftypes
[typeid]);
6637 /* Decode simple location descriptions.
6638 Given a pointer to a dwarf block that defines a location, compute
6639 the location and return the value.
6641 FIXME: This is a kludge until we figure out a better
6642 way to handle the location descriptions.
6643 Gdb's design does not mesh well with the DWARF2 notion of a location
6644 computing interpreter, which is a shame because the flexibility goes unused.
6645 FIXME: Implement more operations as necessary.
6647 A location description containing no operations indicates that the
6648 object is optimized out. The global optimized_out flag is set for
6649 those, the return value is meaningless.
6651 When the result is a register number, the global isreg flag is set,
6652 otherwise it is cleared.
6654 When the result is a base register offset, the global offreg flag is set
6655 and the register number is returned in basereg, otherwise it is cleared.
6657 When the DW_OP_fbreg operation is encountered without a corresponding
6658 DW_AT_frame_base attribute, the global islocal flag is set.
6659 Hopefully the machine dependent code knows how to set up a virtual
6660 frame pointer for the local references.
6662 Note that stack[0] is unused except as a default error return.
6663 Note that stack overflow is not yet handled. */
6666 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6667 const struct comp_unit_head
*cu_header
)
6670 int size
= blk
->size
;
6671 char *data
= blk
->data
;
6672 CORE_ADDR stack
[64];
6674 unsigned int bytes_read
, unsnd
;
6684 is_thread_local
= 0;
6725 stack
[++stacki
] = op
- DW_OP_lit0
;
6761 stack
[++stacki
] = op
- DW_OP_reg0
;
6766 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6768 stack
[++stacki
] = unsnd
;
6804 basereg
= op
- DW_OP_breg0
;
6805 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6811 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6813 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6818 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6820 if (frame_base_reg
>= 0)
6823 basereg
= frame_base_reg
;
6824 stack
[stacki
] += frame_base_offset
;
6828 complaint (&symfile_complaints
,
6829 "DW_AT_frame_base missing for DW_OP_fbreg");
6835 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6836 cu_header
, &bytes_read
);
6841 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6846 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6851 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6856 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6861 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6866 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6871 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6877 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6882 stack
[stacki
+ 1] = stack
[stacki
];
6887 stack
[stacki
- 1] += stack
[stacki
];
6891 case DW_OP_plus_uconst
:
6892 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6897 stack
[stacki
- 1] -= stack
[stacki
];
6903 /* If we're not the last op, then we definitely can't encode
6904 this using GDB's address_class enum. */
6906 dwarf2_complex_location_expr_complaint ();
6909 case DW_OP_GNU_push_tls_address
:
6910 is_thread_local
= 1;
6911 /* The top of the stack has the offset from the beginning
6912 of the thread control block at which the variable is located. */
6913 /* Nothing should follow this operator, so the top of stack would
6916 dwarf2_complex_location_expr_complaint ();
6920 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
6921 dwarf_stack_op_name (op
));
6922 return (stack
[stacki
]);
6925 return (stack
[stacki
]);
6928 /* memory allocation interface */
6932 dwarf2_free_tmp_obstack (void *ignore
)
6934 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6937 static struct dwarf_block
*
6938 dwarf_alloc_block (void)
6940 struct dwarf_block
*blk
;
6942 blk
= (struct dwarf_block
*)
6943 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6947 static struct abbrev_info
*
6948 dwarf_alloc_abbrev (void)
6950 struct abbrev_info
*abbrev
;
6952 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6953 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6957 static struct die_info
*
6958 dwarf_alloc_die (void)
6960 struct die_info
*die
;
6962 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6963 memset (die
, 0, sizeof (struct die_info
));
6968 /* Macro support. */
6971 /* Return the full name of file number I in *LH's file name table.
6972 Use COMP_DIR as the name of the current directory of the
6973 compilation. The result is allocated using xmalloc; the caller is
6974 responsible for freeing it. */
6976 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
6978 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6980 if (IS_ABSOLUTE_PATH (fe
->name
))
6981 return xstrdup (fe
->name
);
6989 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6995 dir_len
= strlen (dir
);
6996 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
6997 strcpy (full_name
, dir
);
6998 full_name
[dir_len
] = '/';
6999 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7003 return xstrdup (fe
->name
);
7008 static struct macro_source_file
*
7009 macro_start_file (int file
, int line
,
7010 struct macro_source_file
*current_file
,
7011 const char *comp_dir
,
7012 struct line_header
*lh
, struct objfile
*objfile
)
7014 /* The full name of this source file. */
7015 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7017 /* We don't create a macro table for this compilation unit
7018 at all until we actually get a filename. */
7019 if (! pending_macros
)
7020 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7021 objfile
->macro_cache
);
7024 /* If we have no current file, then this must be the start_file
7025 directive for the compilation unit's main source file. */
7026 current_file
= macro_set_main (pending_macros
, full_name
);
7028 current_file
= macro_include (current_file
, line
, full_name
);
7032 return current_file
;
7036 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7037 followed by a null byte. */
7039 copy_string (const char *buf
, int len
)
7041 char *s
= xmalloc (len
+ 1);
7042 memcpy (s
, buf
, len
);
7050 consume_improper_spaces (const char *p
, const char *body
)
7054 complaint (&symfile_complaints
,
7055 "macro definition contains spaces in formal argument list:\n`%s'",
7067 parse_macro_definition (struct macro_source_file
*file
, int line
,
7072 /* The body string takes one of two forms. For object-like macro
7073 definitions, it should be:
7075 <macro name> " " <definition>
7077 For function-like macro definitions, it should be:
7079 <macro name> "() " <definition>
7081 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7083 Spaces may appear only where explicitly indicated, and in the
7086 The Dwarf 2 spec says that an object-like macro's name is always
7087 followed by a space, but versions of GCC around March 2002 omit
7088 the space when the macro's definition is the empty string.
7090 The Dwarf 2 spec says that there should be no spaces between the
7091 formal arguments in a function-like macro's formal argument list,
7092 but versions of GCC around March 2002 include spaces after the
7096 /* Find the extent of the macro name. The macro name is terminated
7097 by either a space or null character (for an object-like macro) or
7098 an opening paren (for a function-like macro). */
7099 for (p
= body
; *p
; p
++)
7100 if (*p
== ' ' || *p
== '(')
7103 if (*p
== ' ' || *p
== '\0')
7105 /* It's an object-like macro. */
7106 int name_len
= p
- body
;
7107 char *name
= copy_string (body
, name_len
);
7108 const char *replacement
;
7111 replacement
= body
+ name_len
+ 1;
7114 dwarf2_macro_malformed_definition_complaint (body
);
7115 replacement
= body
+ name_len
;
7118 macro_define_object (file
, line
, name
, replacement
);
7124 /* It's a function-like macro. */
7125 char *name
= copy_string (body
, p
- body
);
7128 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7132 p
= consume_improper_spaces (p
, body
);
7134 /* Parse the formal argument list. */
7135 while (*p
&& *p
!= ')')
7137 /* Find the extent of the current argument name. */
7138 const char *arg_start
= p
;
7140 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7143 if (! *p
|| p
== arg_start
)
7144 dwarf2_macro_malformed_definition_complaint (body
);
7147 /* Make sure argv has room for the new argument. */
7148 if (argc
>= argv_size
)
7151 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7154 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7157 p
= consume_improper_spaces (p
, body
);
7159 /* Consume the comma, if present. */
7164 p
= consume_improper_spaces (p
, body
);
7173 /* Perfectly formed definition, no complaints. */
7174 macro_define_function (file
, line
, name
,
7175 argc
, (const char **) argv
,
7177 else if (*p
== '\0')
7179 /* Complain, but do define it. */
7180 dwarf2_macro_malformed_definition_complaint (body
);
7181 macro_define_function (file
, line
, name
,
7182 argc
, (const char **) argv
,
7186 /* Just complain. */
7187 dwarf2_macro_malformed_definition_complaint (body
);
7190 /* Just complain. */
7191 dwarf2_macro_malformed_definition_complaint (body
);
7197 for (i
= 0; i
< argc
; i
++)
7203 dwarf2_macro_malformed_definition_complaint (body
);
7208 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7209 char *comp_dir
, bfd
*abfd
,
7210 const struct comp_unit_head
*cu_header
,
7211 struct objfile
*objfile
)
7213 char *mac_ptr
, *mac_end
;
7214 struct macro_source_file
*current_file
= 0;
7216 if (dwarf_macinfo_buffer
== NULL
)
7218 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7222 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7223 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7227 enum dwarf_macinfo_record_type macinfo_type
;
7229 /* Do we at least have room for a macinfo type byte? */
7230 if (mac_ptr
>= mac_end
)
7232 dwarf2_macros_too_long_complaint ();
7236 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7239 switch (macinfo_type
)
7241 /* A zero macinfo type indicates the end of the macro
7246 case DW_MACINFO_define
:
7247 case DW_MACINFO_undef
:
7253 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7254 mac_ptr
+= bytes_read
;
7255 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7256 mac_ptr
+= bytes_read
;
7259 complaint (&symfile_complaints
,
7260 "debug info gives macro %s outside of any file: %s",
7262 DW_MACINFO_define
? "definition" : macinfo_type
==
7263 DW_MACINFO_undef
? "undefinition" :
7264 "something-or-other", body
);
7267 if (macinfo_type
== DW_MACINFO_define
)
7268 parse_macro_definition (current_file
, line
, body
);
7269 else if (macinfo_type
== DW_MACINFO_undef
)
7270 macro_undef (current_file
, line
, body
);
7275 case DW_MACINFO_start_file
:
7280 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7281 mac_ptr
+= bytes_read
;
7282 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7283 mac_ptr
+= bytes_read
;
7285 current_file
= macro_start_file (file
, line
,
7286 current_file
, comp_dir
,
7291 case DW_MACINFO_end_file
:
7293 complaint (&symfile_complaints
,
7294 "macro debug info has an unmatched `close_file' directive");
7297 current_file
= current_file
->included_by
;
7300 enum dwarf_macinfo_record_type next_type
;
7302 /* GCC circa March 2002 doesn't produce the zero
7303 type byte marking the end of the compilation
7304 unit. Complain if it's not there, but exit no
7307 /* Do we at least have room for a macinfo type byte? */
7308 if (mac_ptr
>= mac_end
)
7310 dwarf2_macros_too_long_complaint ();
7314 /* We don't increment mac_ptr here, so this is just
7316 next_type
= read_1_byte (abfd
, mac_ptr
);
7318 complaint (&symfile_complaints
,
7319 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7326 case DW_MACINFO_vendor_ext
:
7332 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7333 mac_ptr
+= bytes_read
;
7334 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7335 mac_ptr
+= bytes_read
;
7337 /* We don't recognize any vendor extensions. */
7344 /* Check if the attribute's form is a DW_FORM_block*
7345 if so return true else false. */
7347 attr_form_is_block (struct attribute
*attr
)
7349 return (attr
== NULL
? 0 :
7350 attr
->form
== DW_FORM_block1
7351 || attr
->form
== DW_FORM_block2
7352 || attr
->form
== DW_FORM_block4
7353 || attr
->form
== DW_FORM_block
);
7357 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7358 const struct comp_unit_head
*cu_header
,
7359 struct objfile
*objfile
)
7361 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7363 struct dwarf2_loclist_baton
*baton
;
7365 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7366 sizeof (struct dwarf2_loclist_baton
));
7367 baton
->objfile
= objfile
;
7369 /* We don't know how long the location list is, but make sure we
7370 don't run off the edge of the section. */
7371 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7372 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7373 baton
->base_address
= cu_header
->base_address
;
7374 if (cu_header
->base_known
== 0)
7375 complaint (&symfile_complaints
,
7376 "Location list used without specifying the CU base address.");
7378 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_loclist_funcs
;
7379 SYMBOL_LOCATION_BATON (sym
) = baton
;
7383 struct dwarf2_locexpr_baton
*baton
;
7385 baton
= obstack_alloc (&objfile
->symbol_obstack
,
7386 sizeof (struct dwarf2_locexpr_baton
));
7387 baton
->objfile
= objfile
;
7389 if (attr_form_is_block (attr
))
7391 /* Note that we're just copying the block's data pointer
7392 here, not the actual data. We're still pointing into the
7393 dwarf_info_buffer for SYM's objfile; right now we never
7394 release that buffer, but when we do clean up properly
7395 this may need to change. */
7396 baton
->size
= DW_BLOCK (attr
)->size
;
7397 baton
->data
= DW_BLOCK (attr
)->data
;
7401 dwarf2_invalid_attrib_class_complaint ("location description",
7402 SYMBOL_NATURAL_NAME (sym
));
7407 SYMBOL_LOCATION_FUNCS (sym
) = &dwarf2_locexpr_funcs
;
7408 SYMBOL_LOCATION_BATON (sym
) = baton
;