1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
5 Inc. with support from Florida State University (under contract
6 with the Ada Joint Program Office), and Silicon Graphics, Inc.
7 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or (at
16 your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
40 #include "complaints.h"
43 #include "gdb_string.h"
44 #include <sys/types.h>
47 /* .debug_info header for a compilation unit
48 Because of alignment constraints, this structure has padding and cannot
49 be mapped directly onto the beginning of the .debug_info section. */
50 typedef struct comp_unit_header
52 unsigned int length
; /* length of the .debug_info
54 unsigned short version
; /* version number -- 2 for DWARF
56 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
57 unsigned char addr_size
; /* byte size of an address -- 4 */
60 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
63 /* .debug_pubnames header
64 Because of alignment constraints, this structure has padding and cannot
65 be mapped directly onto the beginning of the .debug_info section. */
66 typedef struct pubnames_header
68 unsigned int length
; /* length of the .debug_pubnames
70 unsigned char version
; /* version number -- 2 for DWARF
72 unsigned int info_offset
; /* offset into .debug_info section */
73 unsigned int info_size
; /* byte size of .debug_info section
77 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
79 /* .debug_pubnames header
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct aranges_header
84 unsigned int length
; /* byte len of the .debug_aranges
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int info_offset
; /* offset into .debug_info section */
89 unsigned char addr_size
; /* byte size of an address */
90 unsigned char seg_size
; /* byte size of segment descriptor */
93 #define _ACTUAL_ARANGES_HEADER_SIZE 12
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* offsets and sizes of debugging sections */
120 static file_ptr dwarf_info_offset
;
121 static file_ptr dwarf_abbrev_offset
;
122 static file_ptr dwarf_line_offset
;
123 static file_ptr dwarf_pubnames_offset
;
124 static file_ptr dwarf_aranges_offset
;
125 static file_ptr dwarf_loc_offset
;
126 static file_ptr dwarf_macinfo_offset
;
127 static file_ptr dwarf_str_offset
;
129 static unsigned int dwarf_info_size
;
130 static unsigned int dwarf_abbrev_size
;
131 static unsigned int dwarf_line_size
;
132 static unsigned int dwarf_pubnames_size
;
133 static unsigned int dwarf_aranges_size
;
134 static unsigned int dwarf_loc_size
;
135 static unsigned int dwarf_macinfo_size
;
136 static unsigned int dwarf_str_size
;
138 /* names of the debugging sections */
140 #define INFO_SECTION ".debug_info"
141 #define ABBREV_SECTION ".debug_abbrev"
142 #define LINE_SECTION ".debug_line"
143 #define PUBNAMES_SECTION ".debug_pubnames"
144 #define ARANGES_SECTION ".debug_aranges"
145 #define LOC_SECTION ".debug_loc"
146 #define MACINFO_SECTION ".debug_macinfo"
147 #define STR_SECTION ".debug_str"
149 /* local data types */
151 /* The data in a compilation unit header, after target2host
152 translation, looks like this. */
153 struct comp_unit_head
157 unsigned int abbrev_offset
;
158 unsigned char addr_size
;
159 unsigned char signed_addr_p
;
162 /* The data in the .debug_line statement prologue looks like this. */
165 unsigned int total_length
;
166 unsigned short version
;
167 unsigned int prologue_length
;
168 unsigned char minimum_instruction_length
;
169 unsigned char default_is_stmt
;
171 unsigned char line_range
;
172 unsigned char opcode_base
;
173 unsigned char *standard_opcode_lengths
;
176 /* When we construct a partial symbol table entry we only
177 need this much information. */
178 struct partial_die_info
181 unsigned char has_children
;
182 unsigned char is_external
;
183 unsigned char is_declaration
;
184 unsigned char has_type
;
190 struct dwarf_block
*locdesc
;
191 unsigned int language
;
195 /* This data structure holds the information of an abbrev. */
198 unsigned int number
; /* number identifying abbrev */
199 enum dwarf_tag tag
; /* dwarf tag */
200 int has_children
; /* boolean */
201 unsigned int num_attrs
; /* number of attributes */
202 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
203 struct abbrev_info
*next
; /* next in chain */
208 enum dwarf_attribute name
;
209 enum dwarf_form form
;
212 /* This data structure holds a complete die structure. */
215 enum dwarf_tag tag
; /* Tag indicating type of die */
216 unsigned short has_children
; /* Does the die have children */
217 unsigned int abbrev
; /* Abbrev number */
218 unsigned int offset
; /* Offset in .debug_info section */
219 unsigned int num_attrs
; /* Number of attributes */
220 struct attribute
*attrs
; /* An array of attributes */
221 struct die_info
*next_ref
; /* Next die in ref hash table */
222 struct die_info
*next
; /* Next die in linked list */
223 struct type
*type
; /* Cached type information */
226 /* Attributes have a name and a value */
229 enum dwarf_attribute name
;
230 enum dwarf_form form
;
234 struct dwarf_block
*blk
;
242 /* Get at parts of an attribute structure */
244 #define DW_STRING(attr) ((attr)->u.str)
245 #define DW_UNSND(attr) ((attr)->u.unsnd)
246 #define DW_BLOCK(attr) ((attr)->u.blk)
247 #define DW_SND(attr) ((attr)->u.snd)
248 #define DW_ADDR(attr) ((attr)->u.addr)
250 /* Blocks are a bunch of untyped bytes. */
257 /* We only hold one compilation unit's abbrevs in
258 memory at any one time. */
259 #ifndef ABBREV_HASH_SIZE
260 #define ABBREV_HASH_SIZE 121
262 #ifndef ATTR_ALLOC_CHUNK
263 #define ATTR_ALLOC_CHUNK 4
266 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
268 /* A hash table of die offsets for following references. */
269 #ifndef REF_HASH_SIZE
270 #define REF_HASH_SIZE 1021
273 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
275 #ifndef TYPE_HASH_SIZE
276 #define TYPE_HASH_SIZE 4096
278 static struct type
*dwarf2_cached_types
[TYPE_HASH_SIZE
];
280 /* Obstack for allocating temporary storage used during symbol reading. */
281 static struct obstack dwarf2_tmp_obstack
;
283 /* Offset to the first byte of the current compilation unit header,
284 for resolving relative reference dies. */
285 static unsigned int cu_header_offset
;
287 /* Allocate fields for structs, unions and enums in this size. */
288 #ifndef DW_FIELD_ALLOC_CHUNK
289 #define DW_FIELD_ALLOC_CHUNK 4
292 /* The language we are debugging. */
293 static enum language cu_language
;
294 static const struct language_defn
*cu_language_defn
;
296 /* Actually data from the sections. */
297 static char *dwarf_info_buffer
;
298 static char *dwarf_abbrev_buffer
;
299 static char *dwarf_line_buffer
;
301 /* A zeroed version of a partial die for initialization purposes. */
302 static struct partial_die_info zeroed_partial_die
;
304 /* The generic symbol table building routines have separate lists for
305 file scope symbols and all all other scopes (local scopes). So
306 we need to select the right one to pass to add_symbol_to_list().
307 We do it by keeping a pointer to the correct list in list_in_scope.
309 FIXME: The original dwarf code just treated the file scope as the first
310 local scope, and all other local scopes as nested local scopes, and worked
311 fine. Check to see if we really need to distinguish these
313 static struct pending
**list_in_scope
= &file_symbols
;
315 /* FIXME: decode_locdesc sets these variables to describe the location
316 to the caller. These ought to be a structure or something. If
317 none of the flags are set, the object lives at the address returned
318 by decode_locdesc. */
320 static int optimized_out
; /* No ops in location in expression,
321 so object was optimized out. */
322 static int isreg
; /* Object lives in register.
323 decode_locdesc's return value is
324 the register number. */
325 static int offreg
; /* Object's address is the sum of the
326 register specified by basereg, plus
327 the offset returned. */
328 static int basereg
; /* See `offreg'. */
329 static int isderef
; /* Value described by flags above is
330 the address of a pointer to the object. */
331 static int islocal
; /* Variable is at the returned offset
332 from the frame start, but there's
333 no identified frame pointer for
334 this function, so we can't say
335 which register it's relative to;
338 /* DW_AT_frame_base values for the current function.
339 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
340 contains the register number for the frame register.
341 frame_base_offset is the offset from the frame register to the
342 virtual stack frame. */
343 static int frame_base_reg
;
344 static CORE_ADDR frame_base_offset
;
346 /* This value is added to each symbol value. FIXME: Generalize to
347 the section_offsets structure used by dbxread (once this is done,
348 pass the appropriate section number to end_symtab). */
349 static CORE_ADDR baseaddr
; /* Add to each symbol value */
351 /* We put a pointer to this structure in the read_symtab_private field
353 The complete dwarf information for an objfile is kept in the
354 psymbol_obstack, so that absolute die references can be handled.
355 Most of the information in this structure is related to an entire
356 object file and could be passed via the sym_private field of the objfile.
357 It is however conceivable that dwarf2 might not be the only type
358 of symbols read from an object file. */
362 /* Pointer to start of dwarf info buffer for the objfile. */
364 char *dwarf_info_buffer
;
366 /* Offset in dwarf_info_buffer for this compilation unit. */
368 unsigned long dwarf_info_offset
;
370 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
372 char *dwarf_abbrev_buffer
;
374 /* Size of dwarf abbreviation section for the objfile. */
376 unsigned int dwarf_abbrev_size
;
378 /* Pointer to start of dwarf line buffer for the objfile. */
380 char *dwarf_line_buffer
;
383 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
384 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
385 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
386 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
387 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
388 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
390 /* Maintain an array of referenced fundamental types for the current
391 compilation unit being read. For DWARF version 1, we have to construct
392 the fundamental types on the fly, since no information about the
393 fundamental types is supplied. Each such fundamental type is created by
394 calling a language dependent routine to create the type, and then a
395 pointer to that type is then placed in the array at the index specified
396 by it's FT_<TYPENAME> value. The array has a fixed size set by the
397 FT_NUM_MEMBERS compile time constant, which is the number of predefined
398 fundamental types gdb knows how to construct. */
399 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
401 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
402 but this would require a corresponding change in unpack_field_as_long
404 static int bits_per_byte
= 8;
406 /* The routines that read and process dies for a C struct or C++ class
407 pass lists of data member fields and lists of member function fields
408 in an instance of a field_info structure, as defined below. */
411 /* List of data member and baseclasses fields. */
414 struct nextfield
*next
;
421 /* Number of fields. */
424 /* Number of baseclasses. */
427 /* Set if the accesibility of one of the fields is not public. */
428 int non_public_fields
;
430 /* Member function fields array, entries are allocated in the order they
431 are encountered in the object file. */
434 struct nextfnfield
*next
;
435 struct fn_field fnfield
;
439 /* Member function fieldlist array, contains name of possibly overloaded
440 member function, number of overloaded member functions and a pointer
441 to the head of the member function field chain. */
446 struct nextfnfield
*head
;
450 /* Number of entries in the fnfieldlists array. */
454 /* FIXME: Kludge to mark a varargs function type for C++ member function
455 argument processing. */
456 #define TYPE_FLAG_VARARGS (1 << 10)
458 /* Dwarf2 has no clean way to discern C++ static and non-static member
459 functions. G++ helps GDB by marking the first parameter for non-static
460 member functions (which is the this pointer) as artificial.
461 We pass this information between dwarf2_add_member_fn and
462 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
463 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
465 /* Various complaints about symbol reading that don't abort the process */
467 static struct complaint dwarf2_const_ignored
=
469 "type qualifier 'const' ignored", 0, 0
471 static struct complaint dwarf2_volatile_ignored
=
473 "type qualifier 'volatile' ignored", 0, 0
475 static struct complaint dwarf2_non_const_array_bound_ignored
=
477 "non-constant array bounds form '%s' ignored", 0, 0
479 static struct complaint dwarf2_missing_line_number_section
=
481 "missing .debug_line section", 0, 0
483 static struct complaint dwarf2_mangled_line_number_section
=
485 "mangled .debug_line section", 0, 0
487 static struct complaint dwarf2_unsupported_die_ref_attr
=
489 "unsupported die ref attribute form: '%s'", 0, 0
491 static struct complaint dwarf2_unsupported_stack_op
=
493 "unsupported stack op: '%s'", 0, 0
495 static struct complaint dwarf2_complex_location_expr
=
497 "location expression too complex", 0, 0
499 static struct complaint dwarf2_unsupported_tag
=
501 "unsupported tag: '%s'", 0, 0
503 static struct complaint dwarf2_unsupported_at_encoding
=
505 "unsupported DW_AT_encoding: '%s'", 0, 0
507 static struct complaint dwarf2_unsupported_at_frame_base
=
509 "unsupported DW_AT_frame_base for function '%s'", 0, 0
511 static struct complaint dwarf2_unexpected_tag
=
513 "unexepected tag in read_type_die: '%s'", 0, 0
515 static struct complaint dwarf2_missing_at_frame_base
=
517 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
519 static struct complaint dwarf2_bad_static_member_name
=
521 "unrecognized static data member name '%s'", 0, 0
523 static struct complaint dwarf2_unsupported_accessibility
=
525 "unsupported accessibility %d", 0, 0
527 static struct complaint dwarf2_bad_member_name_complaint
=
529 "cannot extract member name from '%s'", 0, 0
531 static struct complaint dwarf2_missing_member_fn_type_complaint
=
533 "member function type missing for '%s'", 0, 0
535 static struct complaint dwarf2_vtbl_not_found_complaint
=
537 "virtual function table pointer not found when defining class '%s'", 0, 0
539 static struct complaint dwarf2_absolute_sibling_complaint
=
541 "ignoring absolute DW_AT_sibling", 0, 0
543 static struct complaint dwarf2_const_value_length_mismatch
=
545 "const value length mismatch for '%s', got %d, expected %d", 0, 0
547 static struct complaint dwarf2_unsupported_const_value_attr
=
549 "unsupported const value attribute form: '%s'", 0, 0
552 /* Externals references. */
553 extern int info_verbose
; /* From main.c; nonzero => verbose */
555 /* local function prototypes */
557 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
560 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
563 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
565 static char *scan_partial_symbols (char *, struct objfile
*,
566 CORE_ADDR
*, CORE_ADDR
*,
567 const struct comp_unit_head
*);
569 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
570 const struct comp_unit_head
*);
572 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
574 static void psymtab_to_symtab_1 (struct partial_symtab
*);
576 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
578 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
580 static void dwarf2_empty_abbrev_table (PTR
);
582 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
584 static char *read_partial_die (struct partial_die_info
*,
585 bfd
*, char *, int *,
586 const struct comp_unit_head
*);
588 static char *read_full_die (struct die_info
**, bfd
*, char *,
589 const struct comp_unit_head
*);
591 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
592 bfd
*, char *, const struct comp_unit_head
*);
594 static unsigned int read_1_byte (bfd
*, char *);
596 static int read_1_signed_byte (bfd
*, char *);
598 static unsigned int read_2_bytes (bfd
*, char *);
600 static unsigned int read_4_bytes (bfd
*, char *);
602 static unsigned long read_8_bytes (bfd
*, char *);
604 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
607 static char *read_n_bytes (bfd
*, char *, unsigned int);
609 static char *read_string (bfd
*, char *, unsigned int *);
611 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
613 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
615 static void set_cu_language (unsigned int);
617 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
619 static int die_is_declaration (struct die_info
*);
621 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
622 const struct comp_unit_head
*);
624 static void dwarf2_start_subfile (char *, char *);
626 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
627 struct objfile
*, const struct comp_unit_head
*);
629 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
630 struct objfile
*, const struct comp_unit_head
*);
632 static void dwarf2_const_value_data (struct attribute
*attr
,
636 static struct type
*die_type (struct die_info
*, struct objfile
*,
637 const struct comp_unit_head
*);
639 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
640 const struct comp_unit_head
*);
643 static struct type
*type_at_offset (unsigned int, struct objfile
*);
646 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
647 const struct comp_unit_head
*);
649 static void read_type_die (struct die_info
*, struct objfile
*,
650 const struct comp_unit_head
*);
652 static void read_typedef (struct die_info
*, struct objfile
*,
653 const struct comp_unit_head
*);
655 static void read_base_type (struct die_info
*, struct objfile
*);
657 static void read_file_scope (struct die_info
*, struct objfile
*,
658 const struct comp_unit_head
*);
660 static void read_func_scope (struct die_info
*, struct objfile
*,
661 const struct comp_unit_head
*);
663 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
664 const struct comp_unit_head
*);
666 static int dwarf2_get_pc_bounds (struct die_info
*,
667 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
669 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
670 struct objfile
*, const struct comp_unit_head
*);
672 static void dwarf2_attach_fields_to_type (struct field_info
*,
673 struct type
*, struct objfile
*);
675 static void dwarf2_add_member_fn (struct field_info
*,
676 struct die_info
*, struct type
*,
677 struct objfile
*objfile
,
678 const struct comp_unit_head
*);
680 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
681 struct type
*, struct objfile
*);
683 static void read_structure_scope (struct die_info
*, struct objfile
*,
684 const struct comp_unit_head
*);
686 static void read_common_block (struct die_info
*, struct objfile
*,
687 const struct comp_unit_head
*);
689 static void read_enumeration (struct die_info
*, struct objfile
*,
690 const struct comp_unit_head
*);
692 static struct type
*dwarf_base_type (int, int, struct objfile
*);
694 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
695 const struct comp_unit_head
*);
697 static void read_array_type (struct die_info
*, struct objfile
*,
698 const struct comp_unit_head
*);
700 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
701 const struct comp_unit_head
*);
703 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
704 const struct comp_unit_head
*);
706 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
707 const struct comp_unit_head
*);
709 static void read_tag_const_type (struct die_info
*, struct objfile
*,
710 const struct comp_unit_head
*);
712 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
713 const struct comp_unit_head
*);
715 static void read_tag_string_type (struct die_info
*, struct objfile
*);
717 static void read_subroutine_type (struct die_info
*, struct objfile
*,
718 const struct comp_unit_head
*);
720 struct die_info
*read_comp_unit (char *, bfd
*, const struct comp_unit_head
*);
722 static void free_die_list (struct die_info
*);
724 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
726 static void process_die (struct die_info
*, struct objfile
*,
727 const struct comp_unit_head
*);
729 static char *dwarf2_linkage_name (struct die_info
*);
731 static char *dwarf_tag_name (unsigned int);
733 static char *dwarf_attr_name (unsigned int);
735 static char *dwarf_form_name (unsigned int);
737 static char *dwarf_stack_op_name (unsigned int);
739 static char *dwarf_bool_name (unsigned int);
741 static char *dwarf_type_encoding_name (unsigned int);
744 static char *dwarf_cfi_name (unsigned int);
746 struct die_info
*copy_die (struct die_info
*);
749 struct die_info
*sibling_die (struct die_info
*);
751 void dump_die (struct die_info
*);
753 void dump_die_list (struct die_info
*);
755 void store_in_ref_table (unsigned int, struct die_info
*);
757 static void dwarf2_empty_hash_tables (void);
759 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
761 struct die_info
*follow_die_ref (unsigned int);
763 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
765 /* memory allocation interface */
767 static void dwarf2_free_tmp_obstack (PTR
);
769 static struct dwarf_block
*dwarf_alloc_block (void);
771 static struct abbrev_info
*dwarf_alloc_abbrev (void);
773 static struct die_info
*dwarf_alloc_die (void);
775 /* Try to locate the sections we need for DWARF 2 debugging
776 information and return true if we have enough to do something. */
779 dwarf2_has_info (abfd
)
782 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
783 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
784 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
794 /* This function is mapped across the sections and remembers the
795 offset and size of each of the debugging sections we are interested
799 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
804 if (STREQ (sectp
->name
, INFO_SECTION
))
806 dwarf_info_offset
= sectp
->filepos
;
807 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
809 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
811 dwarf_abbrev_offset
= sectp
->filepos
;
812 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
814 else if (STREQ (sectp
->name
, LINE_SECTION
))
816 dwarf_line_offset
= sectp
->filepos
;
817 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
819 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
821 dwarf_pubnames_offset
= sectp
->filepos
;
822 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
824 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
826 dwarf_aranges_offset
= sectp
->filepos
;
827 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
829 else if (STREQ (sectp
->name
, LOC_SECTION
))
831 dwarf_loc_offset
= sectp
->filepos
;
832 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
834 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
836 dwarf_macinfo_offset
= sectp
->filepos
;
837 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
839 else if (STREQ (sectp
->name
, STR_SECTION
))
841 dwarf_str_offset
= sectp
->filepos
;
842 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
846 /* Build a partial symbol table. */
849 dwarf2_build_psymtabs (objfile
, mainline
)
850 struct objfile
*objfile
;
854 /* We definitely need the .debug_info and .debug_abbrev sections */
856 dwarf_info_buffer
= dwarf2_read_section (objfile
,
859 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
862 dwarf_line_buffer
= dwarf2_read_section (objfile
,
866 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
867 objfile
->static_psymbols
.size
== 0)
869 init_psymbol_list (objfile
, 1024);
873 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
875 /* Things are significantly easier if we have .debug_aranges and
876 .debug_pubnames sections */
878 dwarf2_build_psymtabs_easy (objfile
, mainline
);
882 /* only test this case for now */
884 /* In this case we have to work a bit harder */
885 dwarf2_build_psymtabs_hard (objfile
, mainline
);
890 /* Build the partial symbol table from the information in the
891 .debug_pubnames and .debug_aranges sections. */
894 dwarf2_build_psymtabs_easy (objfile
, mainline
)
895 struct objfile
*objfile
;
898 bfd
*abfd
= objfile
->obfd
;
899 char *aranges_buffer
, *pubnames_buffer
;
900 char *aranges_ptr
, *pubnames_ptr
;
901 unsigned int entry_length
, version
, info_offset
, info_size
;
903 pubnames_buffer
= dwarf2_read_section (objfile
,
904 dwarf_pubnames_offset
,
905 dwarf_pubnames_size
);
906 pubnames_ptr
= pubnames_buffer
;
907 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
909 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
911 version
= read_1_byte (abfd
, pubnames_ptr
);
913 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
915 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
919 aranges_buffer
= dwarf2_read_section (objfile
,
920 dwarf_aranges_offset
,
926 /* Read in the comp unit header information from the debug_info at
930 read_comp_unit_head (struct comp_unit_head
*cu_header
,
931 char *info_ptr
, bfd
*abfd
)
934 cu_header
->length
= read_4_bytes (abfd
, info_ptr
);
936 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
938 cu_header
->abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
940 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
942 signed_addr
= bfd_get_sign_extend_vma (abfd
);
944 internal_error ("dwarf2_build_psymtabs_hard: dwarf from non elf file");
945 cu_header
->signed_addr_p
= signed_addr
;
949 /* Build the partial symbol table by doing a quick pass through the
950 .debug_info and .debug_abbrev sections. */
953 dwarf2_build_psymtabs_hard (objfile
, mainline
)
954 struct objfile
*objfile
;
957 /* Instead of reading this into a big buffer, we should probably use
958 mmap() on architectures that support it. (FIXME) */
959 bfd
*abfd
= objfile
->obfd
;
960 char *info_ptr
, *abbrev_ptr
;
961 char *beg_of_comp_unit
;
962 struct partial_die_info comp_unit_die
;
963 struct partial_symtab
*pst
;
964 struct cleanup
*back_to
;
965 int comp_unit_has_pc_info
;
966 CORE_ADDR lowpc
, highpc
;
968 info_ptr
= dwarf_info_buffer
;
969 abbrev_ptr
= dwarf_abbrev_buffer
;
971 obstack_init (&dwarf2_tmp_obstack
);
972 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
974 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
975 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
977 struct comp_unit_head cu_header
;
978 beg_of_comp_unit
= info_ptr
;
979 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
981 if (cu_header
.version
!= 2)
983 error ("Dwarf Error: wrong version in compilation unit header.");
986 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
988 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
989 (long) cu_header
.abbrev_offset
,
990 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
993 if (beg_of_comp_unit
+ cu_header
.length
+ 4
994 > dwarf_info_buffer
+ dwarf_info_size
)
996 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
997 (long) cu_header
.length
,
998 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1001 /* Read the abbrevs for this compilation unit into a table */
1002 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1003 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1005 /* Read the compilation unit die */
1006 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1007 &comp_unit_has_pc_info
, &cu_header
);
1009 /* Set the language we're debugging */
1010 set_cu_language (comp_unit_die
.language
);
1012 /* Allocate a new partial symbol table structure */
1013 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1014 comp_unit_die
.name
? comp_unit_die
.name
: "",
1015 comp_unit_die
.lowpc
,
1016 objfile
->global_psymbols
.next
,
1017 objfile
->static_psymbols
.next
);
1019 pst
->read_symtab_private
= (char *)
1020 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1021 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1022 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1023 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1024 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1025 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1026 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1027 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
1029 /* Store the function that reads in the rest of the symbol table */
1030 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1032 /* Check if comp unit has_children.
1033 If so, read the rest of the partial symbols from this comp unit.
1034 If not, there's no more debug_info for this comp unit. */
1035 if (comp_unit_die
.has_children
)
1037 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1040 /* If the compilation unit didn't have an explicit address range,
1041 then use the information extracted from its child dies. */
1042 if (!comp_unit_has_pc_info
)
1044 comp_unit_die
.lowpc
= lowpc
;
1045 comp_unit_die
.highpc
= highpc
;
1048 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1049 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1051 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1052 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1053 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1054 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1055 sort_pst_symbols (pst
);
1057 /* If there is already a psymtab or symtab for a file of this
1058 name, remove it. (If there is a symtab, more drastic things
1059 also happen.) This happens in VxWorks. */
1060 free_named_symtabs (pst
->filename
);
1062 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1064 do_cleanups (back_to
);
1067 /* Read in all interesting dies to the end of the compilation unit. */
1070 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1071 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1072 const struct comp_unit_head
*cu_header
)
1074 bfd
*abfd
= objfile
->obfd
;
1075 struct partial_die_info pdi
;
1077 /* This function is called after we've read in the comp_unit_die in
1078 order to read its children. We start the nesting level at 1 since
1079 we have pushed 1 level down in order to read the comp unit's children.
1080 The comp unit itself is at level 0, so we stop reading when we pop
1081 back to that level. */
1083 int nesting_level
= 1;
1086 *lowpc
= ((CORE_ADDR
) -1);
1087 *highpc
= ((CORE_ADDR
) 0);
1089 while (nesting_level
)
1091 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
,
1092 &has_pc_info
, cu_header
);
1098 case DW_TAG_subprogram
:
1101 if (pdi
.lowpc
< *lowpc
)
1105 if (pdi
.highpc
> *highpc
)
1107 *highpc
= pdi
.highpc
;
1109 if ((pdi
.is_external
|| nesting_level
== 1)
1110 && !pdi
.is_declaration
)
1112 add_partial_symbol (&pdi
, objfile
, cu_header
);
1116 case DW_TAG_variable
:
1117 case DW_TAG_typedef
:
1118 case DW_TAG_class_type
:
1119 case DW_TAG_structure_type
:
1120 case DW_TAG_union_type
:
1121 case DW_TAG_enumeration_type
:
1122 if ((pdi
.is_external
|| nesting_level
== 1)
1123 && !pdi
.is_declaration
)
1125 add_partial_symbol (&pdi
, objfile
, cu_header
);
1128 case DW_TAG_enumerator
:
1129 /* File scope enumerators are added to the partial symbol
1131 if (nesting_level
== 2)
1132 add_partial_symbol (&pdi
, objfile
, cu_header
);
1134 case DW_TAG_base_type
:
1135 /* File scope base type definitions are added to the partial
1137 if (nesting_level
== 1)
1138 add_partial_symbol (&pdi
, objfile
, cu_header
);
1145 /* If the die has a sibling, skip to the sibling.
1146 Do not skip enumeration types, we want to record their
1148 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1150 info_ptr
= pdi
.sibling
;
1152 else if (pdi
.has_children
)
1154 /* Die has children, but the optional DW_AT_sibling attribute
1165 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1166 from `maint check'. */
1167 if (*lowpc
== ((CORE_ADDR
) -1))
1173 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1174 const struct comp_unit_head
*cu_header
)
1180 case DW_TAG_subprogram
:
1181 if (pdi
->is_external
)
1183 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1184 mst_text, objfile); */
1185 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1186 VAR_NAMESPACE
, LOC_BLOCK
,
1187 &objfile
->global_psymbols
,
1188 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1192 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1193 mst_file_text, objfile); */
1194 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1195 VAR_NAMESPACE
, LOC_BLOCK
,
1196 &objfile
->static_psymbols
,
1197 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1200 case DW_TAG_variable
:
1201 if (pdi
->is_external
)
1204 Don't enter into the minimal symbol tables as there is
1205 a minimal symbol table entry from the ELF symbols already.
1206 Enter into partial symbol table if it has a location
1207 descriptor or a type.
1208 If the location descriptor is missing, new_symbol will create
1209 a LOC_UNRESOLVED symbol, the address of the variable will then
1210 be determined from the minimal symbol table whenever the variable
1212 The address for the partial symbol table entry is not
1213 used by GDB, but it comes in handy for debugging partial symbol
1217 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1218 if (pdi
->locdesc
|| pdi
->has_type
)
1219 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1220 VAR_NAMESPACE
, LOC_STATIC
,
1221 &objfile
->global_psymbols
,
1222 0, addr
+ baseaddr
, cu_language
, objfile
);
1226 /* Static Variable. Skip symbols without location descriptors. */
1227 if (pdi
->locdesc
== NULL
)
1229 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1230 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1231 mst_file_data, objfile); */
1232 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1233 VAR_NAMESPACE
, LOC_STATIC
,
1234 &objfile
->static_psymbols
,
1235 0, addr
+ baseaddr
, cu_language
, objfile
);
1238 case DW_TAG_typedef
:
1239 case DW_TAG_base_type
:
1240 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1241 VAR_NAMESPACE
, LOC_TYPEDEF
,
1242 &objfile
->static_psymbols
,
1243 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1245 case DW_TAG_class_type
:
1246 case DW_TAG_structure_type
:
1247 case DW_TAG_union_type
:
1248 case DW_TAG_enumeration_type
:
1249 /* Skip aggregate types without children, these are external
1251 if (pdi
->has_children
== 0)
1253 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1254 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1255 &objfile
->static_psymbols
,
1256 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1258 if (cu_language
== language_cplus
)
1260 /* For C++, these implicitly act as typedefs as well. */
1261 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1262 VAR_NAMESPACE
, LOC_TYPEDEF
,
1263 &objfile
->static_psymbols
,
1264 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1267 case DW_TAG_enumerator
:
1268 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1269 VAR_NAMESPACE
, LOC_CONST
,
1270 &objfile
->static_psymbols
,
1271 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1278 /* Expand this partial symbol table into a full symbol table. */
1281 dwarf2_psymtab_to_symtab (pst
)
1282 struct partial_symtab
*pst
;
1284 /* FIXME: This is barely more than a stub. */
1289 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1295 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1296 gdb_flush (gdb_stdout
);
1299 psymtab_to_symtab_1 (pst
);
1301 /* Finish up the debug error message. */
1303 printf_filtered ("done.\n");
1309 psymtab_to_symtab_1 (pst
)
1310 struct partial_symtab
*pst
;
1312 struct objfile
*objfile
= pst
->objfile
;
1313 bfd
*abfd
= objfile
->obfd
;
1314 struct comp_unit_head cu_header
;
1315 struct die_info
*dies
;
1316 unsigned long offset
;
1317 CORE_ADDR lowpc
, highpc
;
1318 struct die_info
*child_die
;
1320 struct symtab
*symtab
;
1321 struct cleanup
*back_to
;
1323 /* Set local variables from the partial symbol table info. */
1324 offset
= DWARF_INFO_OFFSET (pst
);
1325 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1326 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1327 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1328 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1329 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1330 cu_header_offset
= offset
;
1331 info_ptr
= dwarf_info_buffer
+ offset
;
1333 obstack_init (&dwarf2_tmp_obstack
);
1334 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1337 make_cleanup (really_free_pendings
, NULL
);
1339 /* read in the comp_unit header */
1340 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1342 /* Read the abbrevs for this compilation unit */
1343 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1344 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1346 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1348 make_cleanup_free_die_list (dies
);
1350 /* Do line number decoding in read_file_scope () */
1351 process_die (dies
, objfile
, &cu_header
);
1353 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1355 /* Some compilers don't define a DW_AT_high_pc attribute for
1356 the compilation unit. If the DW_AT_high_pc is missing,
1357 synthesize it, by scanning the DIE's below the compilation unit. */
1359 if (dies
->has_children
)
1361 child_die
= dies
->next
;
1362 while (child_die
&& child_die
->tag
)
1364 if (child_die
->tag
== DW_TAG_subprogram
)
1366 CORE_ADDR low
, high
;
1368 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1370 highpc
= max (highpc
, high
);
1373 child_die
= sibling_die (child_die
);
1377 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1379 /* Set symtab language to language from DW_AT_language.
1380 If the compilation is from a C file generated by language preprocessors,
1381 do not set the language if it was already deduced by start_subfile. */
1383 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1385 symtab
->language
= cu_language
;
1387 pst
->symtab
= symtab
;
1389 sort_symtab_syms (pst
->symtab
);
1391 do_cleanups (back_to
);
1394 /* Process a die and its children. */
1397 process_die (struct die_info
*die
, struct objfile
*objfile
,
1398 const struct comp_unit_head
*cu_header
)
1402 case DW_TAG_padding
:
1404 case DW_TAG_compile_unit
:
1405 read_file_scope (die
, objfile
, cu_header
);
1407 case DW_TAG_subprogram
:
1408 read_subroutine_type (die
, objfile
, cu_header
);
1409 read_func_scope (die
, objfile
, cu_header
);
1411 case DW_TAG_inlined_subroutine
:
1412 /* FIXME: These are ignored for now.
1413 They could be used to set breakpoints on all inlined instances
1414 of a function and make GDB `next' properly over inlined functions. */
1416 case DW_TAG_lexical_block
:
1417 read_lexical_block_scope (die
, objfile
, cu_header
);
1419 case DW_TAG_class_type
:
1420 case DW_TAG_structure_type
:
1421 case DW_TAG_union_type
:
1422 read_structure_scope (die
, objfile
, cu_header
);
1424 case DW_TAG_enumeration_type
:
1425 read_enumeration (die
, objfile
, cu_header
);
1427 case DW_TAG_subroutine_type
:
1428 read_subroutine_type (die
, objfile
, cu_header
);
1430 case DW_TAG_array_type
:
1431 read_array_type (die
, objfile
, cu_header
);
1433 case DW_TAG_pointer_type
:
1434 read_tag_pointer_type (die
, objfile
, cu_header
);
1436 case DW_TAG_ptr_to_member_type
:
1437 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1439 case DW_TAG_reference_type
:
1440 read_tag_reference_type (die
, objfile
, cu_header
);
1442 case DW_TAG_string_type
:
1443 read_tag_string_type (die
, objfile
);
1445 case DW_TAG_base_type
:
1446 read_base_type (die
, objfile
);
1447 if (dwarf_attr (die
, DW_AT_name
))
1449 /* Add a typedef symbol for the base type definition. */
1450 new_symbol (die
, die
->type
, objfile
, cu_header
);
1453 case DW_TAG_common_block
:
1454 read_common_block (die
, objfile
, cu_header
);
1456 case DW_TAG_common_inclusion
:
1459 new_symbol (die
, NULL
, objfile
, cu_header
);
1465 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1466 const struct comp_unit_head
*cu_header
)
1468 unsigned int line_offset
= 0;
1469 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1470 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1471 struct attribute
*attr
;
1472 char *name
= "<unknown>";
1473 char *comp_dir
= NULL
;
1474 struct die_info
*child_die
;
1475 bfd
*abfd
= objfile
->obfd
;
1477 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1479 if (die
->has_children
)
1481 child_die
= die
->next
;
1482 while (child_die
&& child_die
->tag
)
1484 if (child_die
->tag
== DW_TAG_subprogram
)
1486 CORE_ADDR low
, high
;
1488 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1490 lowpc
= min (lowpc
, low
);
1491 highpc
= max (highpc
, high
);
1494 child_die
= sibling_die (child_die
);
1499 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1500 from finish_block. */
1501 if (lowpc
== ((CORE_ADDR
) -1))
1506 attr
= dwarf_attr (die
, DW_AT_name
);
1509 name
= DW_STRING (attr
);
1511 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1514 comp_dir
= DW_STRING (attr
);
1517 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1518 directory, get rid of it. */
1519 char *cp
= strchr (comp_dir
, ':');
1521 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1526 if (objfile
->ei
.entry_point
>= lowpc
&&
1527 objfile
->ei
.entry_point
< highpc
)
1529 objfile
->ei
.entry_file_lowpc
= lowpc
;
1530 objfile
->ei
.entry_file_highpc
= highpc
;
1533 attr
= dwarf_attr (die
, DW_AT_language
);
1536 set_cu_language (DW_UNSND (attr
));
1539 /* We assume that we're processing GCC output. */
1540 processing_gcc_compilation
= 2;
1542 /* FIXME:Do something here. */
1543 if (dip
->at_producer
!= NULL
)
1545 handle_producer (dip
->at_producer
);
1549 /* The compilation unit may be in a different language or objfile,
1550 zero out all remembered fundamental types. */
1551 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1553 start_symtab (name
, comp_dir
, lowpc
);
1554 record_debugformat ("DWARF 2");
1556 /* Decode line number information if present. */
1557 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1560 line_offset
= DW_UNSND (attr
);
1561 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1564 /* Process all dies in compilation unit. */
1565 if (die
->has_children
)
1567 child_die
= die
->next
;
1568 while (child_die
&& child_die
->tag
)
1570 process_die (child_die
, objfile
, cu_header
);
1571 child_die
= sibling_die (child_die
);
1577 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1578 const struct comp_unit_head
*cu_header
)
1580 register struct context_stack
*new;
1583 struct die_info
*child_die
;
1584 struct attribute
*attr
;
1587 name
= dwarf2_linkage_name (die
);
1589 /* Ignore functions with missing or empty names and functions with
1590 missing or invalid low and high pc attributes. */
1591 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1597 if (objfile
->ei
.entry_point
>= lowpc
&&
1598 objfile
->ei
.entry_point
< highpc
)
1600 objfile
->ei
.entry_func_lowpc
= lowpc
;
1601 objfile
->ei
.entry_func_highpc
= highpc
;
1604 /* Decode DW_AT_frame_base location descriptor if present, keep result
1605 for DW_OP_fbreg operands in decode_locdesc. */
1606 frame_base_reg
= -1;
1607 frame_base_offset
= 0;
1608 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1611 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1613 complain (&dwarf2_unsupported_at_frame_base
, name
);
1615 frame_base_reg
= addr
;
1618 frame_base_reg
= basereg
;
1619 frame_base_offset
= addr
;
1622 complain (&dwarf2_unsupported_at_frame_base
, name
);
1625 new = push_context (0, lowpc
);
1626 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1627 list_in_scope
= &local_symbols
;
1629 if (die
->has_children
)
1631 child_die
= die
->next
;
1632 while (child_die
&& child_die
->tag
)
1634 process_die (child_die
, objfile
, cu_header
);
1635 child_die
= sibling_die (child_die
);
1639 new = pop_context ();
1640 /* Make a block for the local symbols within. */
1641 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1642 lowpc
, highpc
, objfile
);
1643 list_in_scope
= &file_symbols
;
1646 /* Process all the DIES contained within a lexical block scope. Start
1647 a new scope, process the dies, and then close the scope. */
1650 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1651 const struct comp_unit_head
*cu_header
)
1653 register struct context_stack
*new;
1654 CORE_ADDR lowpc
, highpc
;
1655 struct die_info
*child_die
;
1657 /* Ignore blocks with missing or invalid low and high pc attributes. */
1658 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1663 push_context (0, lowpc
);
1664 if (die
->has_children
)
1666 child_die
= die
->next
;
1667 while (child_die
&& child_die
->tag
)
1669 process_die (child_die
, objfile
, cu_header
);
1670 child_die
= sibling_die (child_die
);
1673 new = pop_context ();
1675 if (local_symbols
!= NULL
)
1677 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1680 local_symbols
= new->locals
;
1683 /* Get low and high pc attributes from a die.
1684 Return 1 if the attributes are present and valid, otherwise, return 0. */
1687 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1688 struct die_info
*die
;
1691 struct objfile
*objfile
;
1693 struct attribute
*attr
;
1697 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1699 low
= DW_ADDR (attr
);
1702 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1704 high
= DW_ADDR (attr
);
1711 /* When using the GNU linker, .gnu.linkonce. sections are used to
1712 eliminate duplicate copies of functions and vtables and such.
1713 The linker will arbitrarily choose one and discard the others.
1714 The AT_*_pc values for such functions refer to local labels in
1715 these sections. If the section from that file was discarded, the
1716 labels are not in the output, so the relocs get a value of 0.
1717 If this is a discarded function, mark the pc bounds as invalid,
1718 so that GDB will ignore it. */
1719 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1727 /* Add an aggregate field to the field list. */
1730 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1731 struct objfile
*objfile
,
1732 const struct comp_unit_head
*cu_header
)
1734 struct nextfield
*new_field
;
1735 struct attribute
*attr
;
1737 char *fieldname
= "";
1739 /* Allocate a new field list entry and link it in. */
1740 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1741 make_cleanup (free
, new_field
);
1742 memset (new_field
, 0, sizeof (struct nextfield
));
1743 new_field
->next
= fip
->fields
;
1744 fip
->fields
= new_field
;
1747 /* Handle accessibility and virtuality of field.
1748 The default accessibility for members is public, the default
1749 accessibility for inheritance is private. */
1750 if (die
->tag
!= DW_TAG_inheritance
)
1751 new_field
->accessibility
= DW_ACCESS_public
;
1753 new_field
->accessibility
= DW_ACCESS_private
;
1754 new_field
->virtuality
= DW_VIRTUALITY_none
;
1756 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1758 new_field
->accessibility
= DW_UNSND (attr
);
1759 if (new_field
->accessibility
!= DW_ACCESS_public
)
1760 fip
->non_public_fields
= 1;
1761 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1763 new_field
->virtuality
= DW_UNSND (attr
);
1765 fp
= &new_field
->field
;
1766 if (die
->tag
== DW_TAG_member
)
1768 /* Get type of field. */
1769 fp
->type
= die_type (die
, objfile
, cu_header
);
1771 /* Get bit size of field (zero if none). */
1772 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1775 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1779 FIELD_BITSIZE (*fp
) = 0;
1782 /* Get bit offset of field. */
1783 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1786 FIELD_BITPOS (*fp
) =
1787 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1790 FIELD_BITPOS (*fp
) = 0;
1791 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1794 if (BITS_BIG_ENDIAN
)
1796 /* For big endian bits, the DW_AT_bit_offset gives the
1797 additional bit offset from the MSB of the containing
1798 anonymous object to the MSB of the field. We don't
1799 have to do anything special since we don't need to
1800 know the size of the anonymous object. */
1801 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1805 /* For little endian bits, compute the bit offset to the
1806 MSB of the anonymous object, subtract off the number of
1807 bits from the MSB of the field to the MSB of the
1808 object, and then subtract off the number of bits of
1809 the field itself. The result is the bit offset of
1810 the LSB of the field. */
1812 int bit_offset
= DW_UNSND (attr
);
1814 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1817 /* The size of the anonymous object containing
1818 the bit field is explicit, so use the
1819 indicated size (in bytes). */
1820 anonymous_size
= DW_UNSND (attr
);
1824 /* The size of the anonymous object containing
1825 the bit field must be inferred from the type
1826 attribute of the data member containing the
1828 anonymous_size
= TYPE_LENGTH (fp
->type
);
1830 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1831 - bit_offset
- FIELD_BITSIZE (*fp
);
1835 /* Get name of field. */
1836 attr
= dwarf_attr (die
, DW_AT_name
);
1837 if (attr
&& DW_STRING (attr
))
1838 fieldname
= DW_STRING (attr
);
1839 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1840 &objfile
->type_obstack
);
1842 /* Change accessibility for artificial fields (e.g. virtual table
1843 pointer or virtual base class pointer) to private. */
1844 if (dwarf_attr (die
, DW_AT_artificial
))
1846 new_field
->accessibility
= DW_ACCESS_private
;
1847 fip
->non_public_fields
= 1;
1850 else if (die
->tag
== DW_TAG_variable
)
1854 /* C++ static member.
1855 Get name of field. */
1856 attr
= dwarf_attr (die
, DW_AT_name
);
1857 if (attr
&& DW_STRING (attr
))
1858 fieldname
= DW_STRING (attr
);
1862 /* Get physical name. */
1863 physname
= dwarf2_linkage_name (die
);
1865 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1866 &objfile
->type_obstack
));
1867 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1868 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1869 &objfile
->type_obstack
);
1871 else if (die
->tag
== DW_TAG_inheritance
)
1873 /* C++ base class field. */
1874 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1876 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1878 FIELD_BITSIZE (*fp
) = 0;
1879 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1880 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1881 fip
->nbaseclasses
++;
1885 /* Create the vector of fields, and attach it to the type. */
1888 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1889 struct field_info
*fip
;
1891 struct objfile
*objfile
;
1893 int nfields
= fip
->nfields
;
1895 /* Record the field count, allocate space for the array of fields,
1896 and create blank accessibility bitfields if necessary. */
1897 TYPE_NFIELDS (type
) = nfields
;
1898 TYPE_FIELDS (type
) = (struct field
*)
1899 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1900 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1902 if (fip
->non_public_fields
)
1904 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1906 TYPE_FIELD_PRIVATE_BITS (type
) =
1907 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1908 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1910 TYPE_FIELD_PROTECTED_BITS (type
) =
1911 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1912 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1914 TYPE_FIELD_IGNORE_BITS (type
) =
1915 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1916 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1919 /* If the type has baseclasses, allocate and clear a bit vector for
1920 TYPE_FIELD_VIRTUAL_BITS. */
1921 if (fip
->nbaseclasses
)
1923 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1926 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1927 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1928 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1929 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1930 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1933 /* Copy the saved-up fields into the field vector. Start from the head
1934 of the list, adding to the tail of the field array, so that they end
1935 up in the same order in the array in which they were added to the list. */
1936 while (nfields
-- > 0)
1938 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1939 switch (fip
->fields
->accessibility
)
1941 case DW_ACCESS_private
:
1942 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1945 case DW_ACCESS_protected
:
1946 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1949 case DW_ACCESS_public
:
1953 /* Unknown accessibility. Complain and treat it as public. */
1955 complain (&dwarf2_unsupported_accessibility
,
1956 fip
->fields
->accessibility
);
1960 if (nfields
< fip
->nbaseclasses
)
1962 switch (fip
->fields
->virtuality
)
1964 case DW_VIRTUALITY_virtual
:
1965 case DW_VIRTUALITY_pure_virtual
:
1966 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1970 fip
->fields
= fip
->fields
->next
;
1974 /* Add a member function to the proper fieldlist. */
1977 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
1978 struct type
*type
, struct objfile
*objfile
,
1979 const struct comp_unit_head
*cu_header
)
1981 struct attribute
*attr
;
1982 struct fnfieldlist
*flp
;
1984 struct fn_field
*fnp
;
1987 struct nextfnfield
*new_fnfield
;
1989 /* Get name of member function. */
1990 attr
= dwarf_attr (die
, DW_AT_name
);
1991 if (attr
&& DW_STRING (attr
))
1992 fieldname
= DW_STRING (attr
);
1996 /* Get the mangled name. */
1997 physname
= dwarf2_linkage_name (die
);
1999 /* Look up member function name in fieldlist. */
2000 for (i
= 0; i
< fip
->nfnfields
; i
++)
2002 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2006 /* Create new list element if necessary. */
2007 if (i
< fip
->nfnfields
)
2008 flp
= &fip
->fnfieldlists
[i
];
2011 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2013 fip
->fnfieldlists
= (struct fnfieldlist
*)
2014 xrealloc (fip
->fnfieldlists
,
2015 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2016 * sizeof (struct fnfieldlist
));
2017 if (fip
->nfnfields
== 0)
2018 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2020 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2021 flp
->name
= fieldname
;
2027 /* Create a new member function field and chain it to the field list
2029 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2030 make_cleanup (free
, new_fnfield
);
2031 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2032 new_fnfield
->next
= flp
->head
;
2033 flp
->head
= new_fnfield
;
2036 /* Fill in the member function field info. */
2037 fnp
= &new_fnfield
->fnfield
;
2038 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2039 &objfile
->type_obstack
);
2040 fnp
->type
= alloc_type (objfile
);
2041 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2043 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2044 struct type
**arg_types
;
2045 int nparams
= TYPE_NFIELDS (die
->type
);
2048 /* Copy argument types from the subroutine type. */
2049 arg_types
= (struct type
**)
2050 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2051 for (iparams
= 0; iparams
< nparams
; iparams
++)
2052 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2054 /* Set last entry in argument type vector. */
2055 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2056 arg_types
[nparams
] = NULL
;
2058 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2060 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2062 /* Handle static member functions.
2063 Dwarf2 has no clean way to discern C++ static and non-static
2064 member functions. G++ helps GDB by marking the first
2065 parameter for non-static member functions (which is the
2066 this pointer) as artificial. We obtain this information
2067 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2068 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2069 fnp
->voffset
= VOFFSET_STATIC
;
2072 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2074 /* Get fcontext from DW_AT_containing_type if present. */
2075 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2076 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2078 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2079 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2081 /* Get accessibility. */
2082 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2085 switch (DW_UNSND (attr
))
2087 case DW_ACCESS_private
:
2088 fnp
->is_private
= 1;
2090 case DW_ACCESS_protected
:
2091 fnp
->is_protected
= 1;
2096 /* Get index in virtual function table if it is a virtual member function. */
2097 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2099 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2102 /* Create the vector of member function fields, and attach it to the type. */
2105 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2106 struct field_info
*fip
;
2108 struct objfile
*objfile
;
2110 struct fnfieldlist
*flp
;
2111 int total_length
= 0;
2114 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2115 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2116 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2118 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2120 struct nextfnfield
*nfp
= flp
->head
;
2121 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2124 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2125 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2126 fn_flp
->fn_fields
= (struct fn_field
*)
2127 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2128 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2129 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2131 total_length
+= flp
->length
;
2134 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2135 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2138 /* Called when we find the DIE that starts a structure or union scope
2139 (definition) to process all dies that define the members of the
2142 NOTE: we need to call struct_type regardless of whether or not the
2143 DIE has an at_name attribute, since it might be an anonymous
2144 structure or union. This gets the type entered into our set of
2147 However, if the structure is incomplete (an opaque struct/union)
2148 then suppress creating a symbol table entry for it since gdb only
2149 wants to find the one with the complete definition. Note that if
2150 it is complete, we just call new_symbol, which does it's own
2151 checking about whether the struct/union is anonymous or not (and
2152 suppresses creating a symbol table entry itself). */
2155 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2156 const struct comp_unit_head
*cu_header
)
2159 struct attribute
*attr
;
2161 type
= alloc_type (objfile
);
2163 INIT_CPLUS_SPECIFIC (type
);
2164 attr
= dwarf_attr (die
, DW_AT_name
);
2165 if (attr
&& DW_STRING (attr
))
2167 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2168 strlen (DW_STRING (attr
)),
2169 &objfile
->type_obstack
);
2172 if (die
->tag
== DW_TAG_structure_type
)
2174 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2176 else if (die
->tag
== DW_TAG_union_type
)
2178 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2182 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2184 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2187 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2190 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2194 TYPE_LENGTH (type
) = 0;
2197 /* We need to add the type field to the die immediately so we don't
2198 infinitely recurse when dealing with pointers to the structure
2199 type within the structure itself. */
2202 if (die
->has_children
&& ! die_is_declaration (die
))
2204 struct field_info fi
;
2205 struct die_info
*child_die
;
2206 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2208 memset (&fi
, 0, sizeof (struct field_info
));
2210 child_die
= die
->next
;
2212 while (child_die
&& child_die
->tag
)
2214 if (child_die
->tag
== DW_TAG_member
)
2216 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2218 else if (child_die
->tag
== DW_TAG_variable
)
2220 /* C++ static member. */
2221 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2223 else if (child_die
->tag
== DW_TAG_subprogram
, cu_header
)
2225 /* C++ member function. */
2226 process_die (child_die
, objfile
, cu_header
);
2227 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2229 else if (child_die
->tag
== DW_TAG_inheritance
)
2231 /* C++ base class field. */
2232 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2236 process_die (child_die
, objfile
, cu_header
);
2238 child_die
= sibling_die (child_die
);
2241 /* Attach fields and member functions to the type. */
2243 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2246 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2248 /* Get the type which refers to the base class (possibly this
2249 class itself) which contains the vtable pointer for the current
2250 class from the DW_AT_containing_type attribute. */
2252 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2254 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2256 TYPE_VPTR_BASETYPE (type
) = t
;
2259 static const char vptr_name
[] =
2260 {'_', 'v', 'p', 't', 'r', '\0'};
2263 /* Our own class provides vtbl ptr. */
2264 for (i
= TYPE_NFIELDS (t
) - 1;
2265 i
>= TYPE_N_BASECLASSES (t
);
2268 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2270 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2271 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2273 TYPE_VPTR_FIELDNO (type
) = i
;
2278 /* Complain if virtual function table field not found. */
2279 if (i
< TYPE_N_BASECLASSES (t
))
2280 complain (&dwarf2_vtbl_not_found_complaint
,
2281 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2285 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2290 new_symbol (die
, type
, objfile
, cu_header
);
2292 do_cleanups (back_to
);
2296 /* No children, must be stub. */
2297 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2303 /* Given a pointer to a die which begins an enumeration, process all
2304 the dies that define the members of the enumeration.
2306 This will be much nicer in draft 6 of the DWARF spec when our
2307 members will be dies instead squished into the DW_AT_element_list
2310 NOTE: We reverse the order of the element list. */
2313 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2314 const struct comp_unit_head
*cu_header
)
2316 struct die_info
*child_die
;
2318 struct field
*fields
;
2319 struct attribute
*attr
;
2322 int unsigned_enum
= 1;
2324 type
= alloc_type (objfile
);
2326 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2327 attr
= dwarf_attr (die
, DW_AT_name
);
2328 if (attr
&& DW_STRING (attr
))
2330 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2331 strlen (DW_STRING (attr
)),
2332 &objfile
->type_obstack
);
2335 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2338 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2342 TYPE_LENGTH (type
) = 0;
2347 if (die
->has_children
)
2349 child_die
= die
->next
;
2350 while (child_die
&& child_die
->tag
)
2352 if (child_die
->tag
!= DW_TAG_enumerator
)
2354 process_die (child_die
, objfile
, cu_header
);
2358 attr
= dwarf_attr (child_die
, DW_AT_name
);
2361 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2362 if (SYMBOL_VALUE (sym
) < 0)
2365 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2367 fields
= (struct field
*)
2369 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2370 * sizeof (struct field
));
2373 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2374 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2375 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2376 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2382 child_die
= sibling_die (child_die
);
2387 TYPE_NFIELDS (type
) = num_fields
;
2388 TYPE_FIELDS (type
) = (struct field
*)
2389 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2390 memcpy (TYPE_FIELDS (type
), fields
,
2391 sizeof (struct field
) * num_fields
);
2395 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2398 new_symbol (die
, type
, objfile
, cu_header
);
2401 /* Extract all information from a DW_TAG_array_type DIE and put it in
2402 the DIE's type field. For now, this only handles one dimensional
2406 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2407 const struct comp_unit_head
*cu_header
)
2409 struct die_info
*child_die
;
2410 struct type
*type
= NULL
;
2411 struct type
*element_type
, *range_type
, *index_type
;
2412 struct type
**range_types
= NULL
;
2413 struct attribute
*attr
;
2415 struct cleanup
*back_to
;
2417 /* Return if we've already decoded this type. */
2423 element_type
= die_type (die
, objfile
, cu_header
);
2425 /* Irix 6.2 native cc creates array types without children for
2426 arrays with unspecified length. */
2427 if (die
->has_children
== 0)
2429 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2430 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2431 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2435 back_to
= make_cleanup (null_cleanup
, NULL
);
2436 child_die
= die
->next
;
2437 while (child_die
&& child_die
->tag
)
2439 if (child_die
->tag
== DW_TAG_subrange_type
)
2441 unsigned int low
, high
;
2443 /* Default bounds to an array with unspecified length. */
2446 if (cu_language
== language_fortran
)
2448 /* FORTRAN implies a lower bound of 1, if not given. */
2452 index_type
= die_type (child_die
, objfile
, cu_header
);
2453 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2456 if (attr
->form
== DW_FORM_sdata
)
2458 low
= DW_SND (attr
);
2460 else if (attr
->form
== DW_FORM_udata
2461 || attr
->form
== DW_FORM_data1
2462 || attr
->form
== DW_FORM_data2
2463 || attr
->form
== DW_FORM_data4
)
2465 low
= DW_UNSND (attr
);
2469 complain (&dwarf2_non_const_array_bound_ignored
,
2470 dwarf_form_name (attr
->form
));
2472 die
->type
= lookup_pointer_type (element_type
);
2479 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2482 if (attr
->form
== DW_FORM_sdata
)
2484 high
= DW_SND (attr
);
2486 else if (attr
->form
== DW_FORM_udata
2487 || attr
->form
== DW_FORM_data1
2488 || attr
->form
== DW_FORM_data2
2489 || attr
->form
== DW_FORM_data4
)
2491 high
= DW_UNSND (attr
);
2493 else if (attr
->form
== DW_FORM_block1
)
2495 /* GCC encodes arrays with unspecified or dynamic length
2496 with a DW_FORM_block1 attribute.
2497 FIXME: GDB does not yet know how to handle dynamic
2498 arrays properly, treat them as arrays with unspecified
2504 complain (&dwarf2_non_const_array_bound_ignored
,
2505 dwarf_form_name (attr
->form
));
2507 die
->type
= lookup_pointer_type (element_type
);
2515 /* Create a range type and save it for array type creation. */
2516 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2518 range_types
= (struct type
**)
2519 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2520 * sizeof (struct type
*));
2522 make_cleanup (free_current_contents
, &range_types
);
2524 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2526 child_die
= sibling_die (child_die
);
2529 /* Dwarf2 dimensions are output from left to right, create the
2530 necessary array types in backwards order. */
2531 type
= element_type
;
2533 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2535 do_cleanups (back_to
);
2537 /* Install the type in the die. */
2541 /* First cut: install each common block member as a global variable. */
2544 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2545 const struct comp_unit_head
*cu_header
)
2547 struct die_info
*child_die
;
2548 struct attribute
*attr
;
2550 CORE_ADDR base
= (CORE_ADDR
) 0;
2552 attr
= dwarf_attr (die
, DW_AT_location
);
2555 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2557 if (die
->has_children
)
2559 child_die
= die
->next
;
2560 while (child_die
&& child_die
->tag
)
2562 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2563 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2566 SYMBOL_VALUE_ADDRESS (sym
) =
2567 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2568 add_symbol_to_list (sym
, &global_symbols
);
2570 child_die
= sibling_die (child_die
);
2575 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2576 the user defined type vector. */
2579 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2580 const struct comp_unit_head
*cu_header
)
2583 struct attribute
*attr
;
2590 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2591 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2594 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2598 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2603 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2604 the user defined type vector. */
2607 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2608 const struct comp_unit_head
*cu_header
)
2611 struct type
*to_type
;
2612 struct type
*domain
;
2619 type
= alloc_type (objfile
);
2620 to_type
= die_type (die
, objfile
, cu_header
);
2621 domain
= die_containing_type (die
, objfile
, cu_header
);
2622 smash_to_member_type (type
, domain
, to_type
);
2627 /* Extract all information from a DW_TAG_reference_type DIE and add to
2628 the user defined type vector. */
2631 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2632 const struct comp_unit_head
*cu_header
)
2635 struct attribute
*attr
;
2642 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2643 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2646 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2650 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2656 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2657 const struct comp_unit_head
*cu_header
)
2664 complain (&dwarf2_const_ignored
);
2665 die
->type
= die_type (die
, objfile
, cu_header
);
2669 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2670 const struct comp_unit_head
*cu_header
)
2677 complain (&dwarf2_volatile_ignored
);
2678 die
->type
= die_type (die
, objfile
, cu_header
);
2681 /* Extract all information from a DW_TAG_string_type DIE and add to
2682 the user defined type vector. It isn't really a user defined type,
2683 but it behaves like one, with other DIE's using an AT_user_def_type
2684 attribute to reference it. */
2687 read_tag_string_type (die
, objfile
)
2688 struct die_info
*die
;
2689 struct objfile
*objfile
;
2691 struct type
*type
, *range_type
, *index_type
, *char_type
;
2692 struct attribute
*attr
;
2693 unsigned int length
;
2700 attr
= dwarf_attr (die
, DW_AT_string_length
);
2703 length
= DW_UNSND (attr
);
2709 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2710 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2711 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2712 type
= create_string_type (char_type
, range_type
);
2716 /* Handle DIES due to C code like:
2720 int (*funcp)(int a, long l);
2724 ('funcp' generates a DW_TAG_subroutine_type DIE)
2728 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2729 const struct comp_unit_head
*cu_header
)
2731 struct type
*type
; /* Type that this function returns */
2732 struct type
*ftype
; /* Function that returns above type */
2733 struct attribute
*attr
;
2735 /* Decode the type that this subroutine returns */
2740 type
= die_type (die
, objfile
, cu_header
);
2741 ftype
= lookup_function_type (type
);
2743 /* All functions in C++ have prototypes. */
2744 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2745 if ((attr
&& (DW_UNSND (attr
) != 0))
2746 || cu_language
== language_cplus
)
2747 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2749 if (die
->has_children
)
2751 struct die_info
*child_die
;
2755 /* Count the number of parameters.
2756 FIXME: GDB currently ignores vararg functions, but knows about
2757 vararg member functions. */
2758 child_die
= die
->next
;
2759 while (child_die
&& child_die
->tag
)
2761 if (child_die
->tag
== DW_TAG_formal_parameter
)
2763 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2764 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2765 child_die
= sibling_die (child_die
);
2768 /* Allocate storage for parameters and fill them in. */
2769 TYPE_NFIELDS (ftype
) = nparams
;
2770 TYPE_FIELDS (ftype
) = (struct field
*)
2771 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2773 child_die
= die
->next
;
2774 while (child_die
&& child_die
->tag
)
2776 if (child_die
->tag
== DW_TAG_formal_parameter
)
2778 /* Dwarf2 has no clean way to discern C++ static and non-static
2779 member functions. G++ helps GDB by marking the first
2780 parameter for non-static member functions (which is the
2781 this pointer) as artificial. We pass this information
2782 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2783 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2785 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2787 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2788 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2792 child_die
= sibling_die (child_die
);
2800 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2801 const struct comp_unit_head
*cu_header
)
2807 struct attribute
*attr
;
2810 xtype
= die_type (die
, objfile
, cu_header
);
2812 type
= alloc_type (objfile
);
2813 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2814 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2815 TYPE_TARGET_TYPE (type
) = xtype
;
2816 attr
= dwarf_attr (die
, DW_AT_name
);
2817 if (attr
&& DW_STRING (attr
))
2818 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2819 strlen (DW_STRING (attr
)),
2820 &objfile
->type_obstack
);
2826 /* Find a representation of a given base type and install
2827 it in the TYPE field of the die. */
2830 read_base_type (die
, objfile
)
2831 struct die_info
*die
;
2832 struct objfile
*objfile
;
2835 struct attribute
*attr
;
2836 int encoding
= 0, size
= 0;
2838 /* If we've already decoded this die, this is a no-op. */
2844 attr
= dwarf_attr (die
, DW_AT_encoding
);
2847 encoding
= DW_UNSND (attr
);
2849 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2852 size
= DW_UNSND (attr
);
2854 attr
= dwarf_attr (die
, DW_AT_name
);
2855 if (attr
&& DW_STRING (attr
))
2857 enum type_code code
= TYPE_CODE_INT
;
2858 int is_unsigned
= 0;
2862 case DW_ATE_address
:
2863 /* Turn DW_ATE_address into a void * pointer. */
2864 code
= TYPE_CODE_PTR
;
2867 case DW_ATE_boolean
:
2868 code
= TYPE_CODE_BOOL
;
2871 case DW_ATE_complex_float
:
2872 code
= TYPE_CODE_COMPLEX
;
2875 code
= TYPE_CODE_FLT
;
2878 case DW_ATE_signed_char
:
2880 case DW_ATE_unsigned
:
2881 case DW_ATE_unsigned_char
:
2885 complain (&dwarf2_unsupported_at_encoding
,
2886 dwarf_type_encoding_name (encoding
));
2889 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2890 if (encoding
== DW_ATE_address
)
2891 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2895 type
= dwarf_base_type (encoding
, size
, objfile
);
2900 /* Read a whole compilation unit into a linked list of dies. */
2903 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2904 const struct comp_unit_head
*cu_header
)
2906 struct die_info
*first_die
, *last_die
, *die
;
2910 /* Reset die reference table and cached types table; we are
2911 building new ones now. */
2912 dwarf2_empty_hash_tables ();
2916 first_die
= last_die
= NULL
;
2919 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2920 if (die
->has_children
)
2931 /* Enter die in reference hash table */
2932 store_in_ref_table (die
->offset
, die
);
2936 first_die
= last_die
= die
;
2940 last_die
->next
= die
;
2944 while (nesting_level
> 0);
2948 /* Free a linked list of dies. */
2951 free_die_list (dies
)
2952 struct die_info
*dies
;
2954 struct die_info
*die
, *next
;
2967 do_free_die_list_cleanup (void *dies
)
2969 free_die_list (dies
);
2972 static struct cleanup
*
2973 make_cleanup_free_die_list (struct die_info
*dies
)
2975 return make_cleanup (do_free_die_list_cleanup
, dies
);
2979 /* Read the contents of the section at OFFSET and of size SIZE from the
2980 object file specified by OBJFILE into the psymbol_obstack and return it. */
2983 dwarf2_read_section (objfile
, offset
, size
)
2984 struct objfile
*objfile
;
2988 bfd
*abfd
= objfile
->obfd
;
2994 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2995 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2996 (bfd_read (buf
, size
, 1, abfd
) != size
))
2999 error ("Dwarf Error: Can't read DWARF data from '%s'",
3000 bfd_get_filename (abfd
));
3005 /* In DWARF version 2, the description of the debugging information is
3006 stored in a separate .debug_abbrev section. Before we read any
3007 dies from a section we read in all abbreviations and install them
3011 dwarf2_read_abbrevs (abfd
, offset
)
3013 unsigned int offset
;
3016 struct abbrev_info
*cur_abbrev
;
3017 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3018 unsigned int abbrev_form
, hash_number
;
3020 /* empty the table */
3021 dwarf2_empty_abbrev_table (NULL
);
3023 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3024 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3025 abbrev_ptr
+= bytes_read
;
3027 /* loop until we reach an abbrev number of 0 */
3028 while (abbrev_number
)
3030 cur_abbrev
= dwarf_alloc_abbrev ();
3032 /* read in abbrev header */
3033 cur_abbrev
->number
= abbrev_number
;
3034 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3035 abbrev_ptr
+= bytes_read
;
3036 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3039 /* now read in declarations */
3040 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3041 abbrev_ptr
+= bytes_read
;
3042 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3043 abbrev_ptr
+= bytes_read
;
3046 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3048 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3049 xrealloc (cur_abbrev
->attrs
,
3050 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3051 * sizeof (struct attr_abbrev
));
3053 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3054 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3055 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3056 abbrev_ptr
+= bytes_read
;
3057 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3058 abbrev_ptr
+= bytes_read
;
3061 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3062 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3063 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3065 /* Get next abbreviation.
3066 Under Irix6 the abbreviations for a compilation unit are not
3067 always properly terminated with an abbrev number of 0.
3068 Exit loop if we encounter an abbreviation which we have
3069 already read (which means we are about to read the abbreviations
3070 for the next compile unit) or if the end of the abbreviation
3071 table is reached. */
3072 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3073 >= dwarf_abbrev_size
)
3075 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3076 abbrev_ptr
+= bytes_read
;
3077 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3082 /* Empty the abbrev table for a new compilation unit. */
3086 dwarf2_empty_abbrev_table (ignore
)
3090 struct abbrev_info
*abbrev
, *next
;
3092 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3095 abbrev
= dwarf2_abbrevs
[i
];
3098 next
= abbrev
->next
;
3099 free (abbrev
->attrs
);
3103 dwarf2_abbrevs
[i
] = NULL
;
3107 /* Lookup an abbrev_info structure in the abbrev hash table. */
3109 static struct abbrev_info
*
3110 dwarf2_lookup_abbrev (number
)
3111 unsigned int number
;
3113 unsigned int hash_number
;
3114 struct abbrev_info
*abbrev
;
3116 hash_number
= number
% ABBREV_HASH_SIZE
;
3117 abbrev
= dwarf2_abbrevs
[hash_number
];
3121 if (abbrev
->number
== number
)
3124 abbrev
= abbrev
->next
;
3129 /* Read a minimal amount of information into the minimal die structure. */
3132 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3133 char *info_ptr
, int *has_pc_info
,
3134 const struct comp_unit_head
*cu_header
)
3136 unsigned int abbrev_number
, bytes_read
, i
;
3137 struct abbrev_info
*abbrev
;
3138 struct attribute attr
;
3139 struct attribute spec_attr
;
3140 int found_spec_attr
= 0;
3141 int has_low_pc_attr
= 0;
3142 int has_high_pc_attr
= 0;
3144 *part_die
= zeroed_partial_die
;
3146 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3147 info_ptr
+= bytes_read
;
3151 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3154 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3156 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3157 part_die
->tag
= abbrev
->tag
;
3158 part_die
->has_children
= abbrev
->has_children
;
3159 part_die
->abbrev
= abbrev_number
;
3161 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3163 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3164 info_ptr
, cu_header
);
3166 /* Store the data if it is of an attribute we want to keep in a
3167 partial symbol table. */
3172 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3173 if (part_die
->name
== NULL
)
3174 part_die
->name
= DW_STRING (&attr
);
3176 case DW_AT_MIPS_linkage_name
:
3177 part_die
->name
= DW_STRING (&attr
);
3180 has_low_pc_attr
= 1;
3181 part_die
->lowpc
= DW_ADDR (&attr
);
3184 has_high_pc_attr
= 1;
3185 part_die
->highpc
= DW_ADDR (&attr
);
3187 case DW_AT_location
:
3188 part_die
->locdesc
= DW_BLOCK (&attr
);
3190 case DW_AT_language
:
3191 part_die
->language
= DW_UNSND (&attr
);
3193 case DW_AT_external
:
3194 part_die
->is_external
= DW_UNSND (&attr
);
3196 case DW_AT_declaration
:
3197 part_die
->is_declaration
= DW_UNSND (&attr
);
3200 part_die
->has_type
= 1;
3202 case DW_AT_abstract_origin
:
3203 case DW_AT_specification
:
3204 found_spec_attr
= 1;
3208 /* Ignore absolute siblings, they might point outside of
3209 the current compile unit. */
3210 if (attr
.form
== DW_FORM_ref_addr
)
3211 complain (&dwarf2_absolute_sibling_complaint
);
3214 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3221 /* If we found a reference attribute and the die has no name, try
3222 to find a name in the referred to die. */
3224 if (found_spec_attr
&& part_die
->name
== NULL
)
3226 struct partial_die_info spec_die
;
3230 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3231 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
, cu_header
);
3234 part_die
->name
= spec_die
.name
;
3236 /* Copy DW_AT_external attribute if it is set. */
3237 if (spec_die
.is_external
)
3238 part_die
->is_external
= spec_die
.is_external
;
3242 /* When using the GNU linker, .gnu.linkonce. sections are used to
3243 eliminate duplicate copies of functions and vtables and such.
3244 The linker will arbitrarily choose one and discard the others.
3245 The AT_*_pc values for such functions refer to local labels in
3246 these sections. If the section from that file was discarded, the
3247 labels are not in the output, so the relocs get a value of 0.
3248 If this is a discarded function, mark the pc bounds as invalid,
3249 so that GDB will ignore it. */
3250 if (has_low_pc_attr
&& has_high_pc_attr
3251 && part_die
->lowpc
< part_die
->highpc
3252 && (part_die
->lowpc
!= 0
3253 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3258 /* Read the die from the .debug_info section buffer. And set diep to
3259 point to a newly allocated die with its information. */
3262 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3263 const struct comp_unit_head
*cu_header
)
3265 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3266 struct abbrev_info
*abbrev
;
3267 struct die_info
*die
;
3269 offset
= info_ptr
- dwarf_info_buffer
;
3270 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3271 info_ptr
+= bytes_read
;
3274 die
= dwarf_alloc_die ();
3276 die
->abbrev
= abbrev_number
;
3282 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3285 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3287 die
= dwarf_alloc_die ();
3288 die
->offset
= offset
;
3289 die
->tag
= abbrev
->tag
;
3290 die
->has_children
= abbrev
->has_children
;
3291 die
->abbrev
= abbrev_number
;
3294 die
->num_attrs
= abbrev
->num_attrs
;
3295 die
->attrs
= (struct attribute
*)
3296 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3298 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3300 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3301 abfd
, info_ptr
, cu_header
);
3308 /* Read an attribute described by an abbreviated attribute. */
3311 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3312 bfd
*abfd
, char *info_ptr
,
3313 const struct comp_unit_head
*cu_header
)
3315 unsigned int bytes_read
;
3316 struct dwarf_block
*blk
;
3318 attr
->name
= abbrev
->name
;
3319 attr
->form
= abbrev
->form
;
3320 switch (abbrev
->form
)
3323 case DW_FORM_ref_addr
:
3324 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3325 info_ptr
+= bytes_read
;
3327 case DW_FORM_block2
:
3328 blk
= dwarf_alloc_block ();
3329 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3331 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3332 info_ptr
+= blk
->size
;
3333 DW_BLOCK (attr
) = blk
;
3335 case DW_FORM_block4
:
3336 blk
= dwarf_alloc_block ();
3337 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3339 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3340 info_ptr
+= blk
->size
;
3341 DW_BLOCK (attr
) = blk
;
3344 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3348 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3352 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3355 case DW_FORM_string
:
3356 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3357 info_ptr
+= bytes_read
;
3360 blk
= dwarf_alloc_block ();
3361 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3362 info_ptr
+= bytes_read
;
3363 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3364 info_ptr
+= blk
->size
;
3365 DW_BLOCK (attr
) = blk
;
3367 case DW_FORM_block1
:
3368 blk
= dwarf_alloc_block ();
3369 blk
->size
= read_1_byte (abfd
, info_ptr
);
3371 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3372 info_ptr
+= blk
->size
;
3373 DW_BLOCK (attr
) = blk
;
3376 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3380 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3384 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3385 info_ptr
+= bytes_read
;
3388 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3389 info_ptr
+= bytes_read
;
3392 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3396 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3400 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3403 case DW_FORM_ref_udata
:
3404 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3405 info_ptr
+= bytes_read
;
3408 case DW_FORM_indirect
:
3410 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3411 dwarf_form_name (abbrev
->form
));
3416 /* read dwarf information from a buffer */
3419 read_1_byte (abfd
, buf
)
3423 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3427 read_1_signed_byte (abfd
, buf
)
3431 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3435 read_2_bytes (abfd
, buf
)
3439 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3443 read_2_signed_bytes (abfd
, buf
)
3447 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3451 read_4_bytes (abfd
, buf
)
3455 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3459 read_4_signed_bytes (abfd
, buf
)
3463 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3466 static unsigned long
3467 read_8_bytes (abfd
, buf
)
3471 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3475 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3478 CORE_ADDR retval
= 0;
3480 if (cu_header
->signed_addr_p
)
3482 switch (cu_header
->addr_size
)
3485 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3488 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3491 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3494 internal_error ("read_address: bad switch, signed");
3499 switch (cu_header
->addr_size
)
3502 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3505 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3508 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3511 internal_error ("read_address: bad switch, unsigned");
3515 *bytes_read
= cu_header
->addr_size
;
3520 read_n_bytes (abfd
, buf
, size
)
3525 /* If the size of a host char is 8 bits, we can return a pointer
3526 to the buffer, otherwise we have to copy the data to a buffer
3527 allocated on the temporary obstack. */
3528 #if HOST_CHAR_BIT == 8
3534 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3535 for (i
= 0; i
< size
; ++i
)
3537 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3545 read_string (abfd
, buf
, bytes_read_ptr
)
3548 unsigned int *bytes_read_ptr
;
3550 /* If the size of a host char is 8 bits, we can return a pointer
3551 to the string, otherwise we have to copy the string to a buffer
3552 allocated on the temporary obstack. */
3553 #if HOST_CHAR_BIT == 8
3556 *bytes_read_ptr
= 1;
3559 *bytes_read_ptr
= strlen (buf
) + 1;
3565 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3567 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3573 *bytes_read_ptr
= 1;
3576 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3577 *bytes_read_ptr
= i
+ 1;
3578 return obstack_finish (&dwarf2_tmp_obstack
);
3582 static unsigned long
3583 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3586 unsigned int *bytes_read_ptr
;
3588 unsigned long result
;
3589 unsigned int num_read
;
3599 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3602 result
|= ((unsigned long)(byte
& 127) << shift
);
3603 if ((byte
& 128) == 0)
3609 *bytes_read_ptr
= num_read
;
3614 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3617 unsigned int *bytes_read_ptr
;
3620 int i
, shift
, size
, num_read
;
3630 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3633 result
|= ((long)(byte
& 127) << shift
);
3635 if ((byte
& 128) == 0)
3640 if ((shift
< size
) && (byte
& 0x40))
3642 result
|= -(1 << shift
);
3644 *bytes_read_ptr
= num_read
;
3649 set_cu_language (lang
)
3656 cu_language
= language_c
;
3658 case DW_LANG_C_plus_plus
:
3659 cu_language
= language_cplus
;
3661 case DW_LANG_Fortran77
:
3662 case DW_LANG_Fortran90
:
3663 cu_language
= language_fortran
;
3665 case DW_LANG_Mips_Assembler
:
3666 cu_language
= language_asm
;
3669 case DW_LANG_Cobol74
:
3670 case DW_LANG_Cobol85
:
3671 case DW_LANG_Pascal83
:
3672 case DW_LANG_Modula2
:
3674 cu_language
= language_unknown
;
3677 cu_language_defn
= language_def (cu_language
);
3680 /* Return the named attribute or NULL if not there. */
3682 static struct attribute
*
3683 dwarf_attr (die
, name
)
3684 struct die_info
*die
;
3688 struct attribute
*spec
= NULL
;
3690 for (i
= 0; i
< die
->num_attrs
; ++i
)
3692 if (die
->attrs
[i
].name
== name
)
3694 return &die
->attrs
[i
];
3696 if (die
->attrs
[i
].name
== DW_AT_specification
3697 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3698 spec
= &die
->attrs
[i
];
3702 struct die_info
*ref_die
=
3703 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3706 return dwarf_attr (ref_die
, name
);
3713 die_is_declaration (struct die_info
*die
)
3715 return (dwarf_attr (die
, DW_AT_declaration
)
3716 && ! dwarf_attr (die
, DW_AT_specification
));
3719 /* Decode the line number information for the compilation unit whose
3720 line number info is at OFFSET in the .debug_line section.
3721 The compilation directory of the file is passed in COMP_DIR. */
3725 unsigned int num_files
;
3738 unsigned int num_dirs
;
3743 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3744 const struct comp_unit_head
*cu_header
)
3748 struct line_head lh
;
3749 struct cleanup
*back_to
;
3750 unsigned int i
, bytes_read
;
3751 char *cur_file
, *cur_dir
;
3752 unsigned char op_code
, extended_op
, adj_opcode
;
3754 #define FILE_ALLOC_CHUNK 5
3755 #define DIR_ALLOC_CHUNK 5
3757 struct filenames files
;
3758 struct directories dirs
;
3760 if (dwarf_line_buffer
== NULL
)
3762 complain (&dwarf2_missing_line_number_section
);
3766 files
.num_files
= 0;
3772 line_ptr
= dwarf_line_buffer
+ offset
;
3774 /* read in the prologue */
3775 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3777 line_end
= line_ptr
+ lh
.total_length
;
3778 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3780 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3782 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3784 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3786 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3788 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3790 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3792 lh
.standard_opcode_lengths
= (unsigned char *)
3793 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3794 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3796 lh
.standard_opcode_lengths
[0] = 1;
3797 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3799 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3803 /* Read directory table */
3804 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3806 line_ptr
+= bytes_read
;
3807 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3809 dirs
.dirs
= (char **)
3810 xrealloc (dirs
.dirs
,
3811 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3812 if (dirs
.num_dirs
== 0)
3813 make_cleanup (free_current_contents
, &dirs
.dirs
);
3815 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3817 line_ptr
+= bytes_read
;
3819 /* Read file name table */
3820 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3822 line_ptr
+= bytes_read
;
3823 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3825 files
.files
= (struct fileinfo
*)
3826 xrealloc (files
.files
,
3827 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3828 * sizeof (struct fileinfo
));
3829 if (files
.num_files
== 0)
3830 make_cleanup (free_current_contents
, &files
.files
);
3832 files
.files
[files
.num_files
].name
= cur_file
;
3833 files
.files
[files
.num_files
].dir
=
3834 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3835 line_ptr
+= bytes_read
;
3836 files
.files
[files
.num_files
].time
=
3837 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3838 line_ptr
+= bytes_read
;
3839 files
.files
[files
.num_files
].size
=
3840 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3841 line_ptr
+= bytes_read
;
3844 line_ptr
+= bytes_read
;
3846 /* Read the statement sequences until there's nothing left. */
3847 while (line_ptr
< line_end
)
3849 /* state machine registers */
3850 CORE_ADDR address
= 0;
3851 unsigned int file
= 1;
3852 unsigned int line
= 1;
3853 unsigned int column
= 0;
3854 int is_stmt
= lh
.default_is_stmt
;
3855 int basic_block
= 0;
3856 int end_sequence
= 0;
3858 /* Start a subfile for the current file of the state machine. */
3859 if (files
.num_files
>= file
)
3861 /* The file and directory tables are 0 based, the references
3863 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3864 (files
.files
[file
- 1].dir
3865 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3869 /* Decode the table. */
3870 while (!end_sequence
)
3872 op_code
= read_1_byte (abfd
, line_ptr
);
3876 case DW_LNS_extended_op
:
3877 line_ptr
+= 1; /* ignore length */
3878 extended_op
= read_1_byte (abfd
, line_ptr
);
3880 switch (extended_op
)
3882 case DW_LNE_end_sequence
:
3884 /* Don't call record_line here. The end_sequence
3885 instruction provides the address of the first byte
3886 *after* the last line in the sequence; it's not the
3887 address of any real source line. However, the GDB
3888 linetable structure only records the starts of lines,
3889 not the ends. This is a weakness of GDB. */
3891 case DW_LNE_set_address
:
3892 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
3893 line_ptr
+= bytes_read
;
3894 address
+= baseaddr
;
3896 case DW_LNE_define_file
:
3897 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3898 line_ptr
+= bytes_read
;
3899 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3901 files
.files
= (struct fileinfo
*)
3902 xrealloc (files
.files
,
3903 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3904 * sizeof (struct fileinfo
));
3905 if (files
.num_files
== 0)
3906 make_cleanup (free_current_contents
, &files
.files
);
3908 files
.files
[files
.num_files
].name
= cur_file
;
3909 files
.files
[files
.num_files
].dir
=
3910 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3911 line_ptr
+= bytes_read
;
3912 files
.files
[files
.num_files
].time
=
3913 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3914 line_ptr
+= bytes_read
;
3915 files
.files
[files
.num_files
].size
=
3916 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3917 line_ptr
+= bytes_read
;
3921 complain (&dwarf2_mangled_line_number_section
);
3926 record_line (current_subfile
, line
, address
);
3929 case DW_LNS_advance_pc
:
3930 address
+= lh
.minimum_instruction_length
3931 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3932 line_ptr
+= bytes_read
;
3934 case DW_LNS_advance_line
:
3935 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3936 line_ptr
+= bytes_read
;
3938 case DW_LNS_set_file
:
3939 /* The file and directory tables are 0 based, the references
3941 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3942 line_ptr
+= bytes_read
;
3943 dwarf2_start_subfile
3944 (files
.files
[file
- 1].name
,
3945 (files
.files
[file
- 1].dir
3946 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3949 case DW_LNS_set_column
:
3950 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3951 line_ptr
+= bytes_read
;
3953 case DW_LNS_negate_stmt
:
3954 is_stmt
= (!is_stmt
);
3956 case DW_LNS_set_basic_block
:
3959 /* Add to the address register of the state machine the
3960 address increment value corresponding to special opcode
3961 255. Ie, this value is scaled by the minimum instruction
3962 length since special opcode 255 would have scaled the
3964 case DW_LNS_const_add_pc
:
3965 address
+= (lh
.minimum_instruction_length
3966 * ((255 - lh
.opcode_base
) / lh
.line_range
));
3968 case DW_LNS_fixed_advance_pc
:
3969 address
+= read_2_bytes (abfd
, line_ptr
);
3972 default: /* special operand */
3973 adj_opcode
= op_code
- lh
.opcode_base
;
3974 address
+= (adj_opcode
/ lh
.line_range
)
3975 * lh
.minimum_instruction_length
;
3976 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3977 /* append row to matrix using current values */
3978 record_line (current_subfile
, line
, address
);
3984 do_cleanups (back_to
);
3987 /* Start a subfile for DWARF. FILENAME is the name of the file and
3988 DIRNAME the name of the source directory which contains FILENAME
3989 or NULL if not known.
3990 This routine tries to keep line numbers from identical absolute and
3991 relative file names in a common subfile.
3993 Using the `list' example from the GDB testsuite, which resides in
3994 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3995 of /srcdir/list0.c yields the following debugging information for list0.c:
3997 DW_AT_name: /srcdir/list0.c
3998 DW_AT_comp_dir: /compdir
3999 files.files[0].name: list0.h
4000 files.files[0].dir: /srcdir
4001 files.files[1].name: list0.c
4002 files.files[1].dir: /srcdir
4004 The line number information for list0.c has to end up in a single
4005 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4008 dwarf2_start_subfile (filename
, dirname
)
4012 /* If the filename isn't absolute, try to match an existing subfile
4013 with the full pathname. */
4015 if (*filename
!= '/' && dirname
!= NULL
)
4017 struct subfile
*subfile
;
4018 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4020 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4022 if (STREQ (subfile
->name
, fullname
))
4024 current_subfile
= subfile
;
4031 start_subfile (filename
, dirname
);
4034 /* Given a pointer to a DWARF information entry, figure out if we need
4035 to make a symbol table entry for it, and if so, create a new entry
4036 and return a pointer to it.
4037 If TYPE is NULL, determine symbol type from the die, otherwise
4038 used the passed type. */
4040 static struct symbol
*
4041 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4042 const struct comp_unit_head
*cu_header
)
4044 struct symbol
*sym
= NULL
;
4046 struct attribute
*attr
= NULL
;
4047 struct attribute
*attr2
= NULL
;
4050 name
= dwarf2_linkage_name (die
);
4053 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4054 sizeof (struct symbol
));
4055 OBJSTAT (objfile
, n_syms
++);
4056 memset (sym
, 0, sizeof (struct symbol
));
4057 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4058 &objfile
->symbol_obstack
);
4060 /* Default assumptions.
4061 Use the passed type or decode it from the die. */
4062 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4063 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4065 SYMBOL_TYPE (sym
) = type
;
4067 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4068 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4071 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4074 /* If this symbol is from a C++ compilation, then attempt to
4075 cache the demangled form for future reference. This is a
4076 typical time versus space tradeoff, that was decided in favor
4077 of time because it sped up C++ symbol lookups by a factor of
4080 SYMBOL_LANGUAGE (sym
) = cu_language
;
4081 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4085 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4088 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4090 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4092 case DW_TAG_subprogram
:
4093 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4095 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4096 attr2
= dwarf_attr (die
, DW_AT_external
);
4097 if (attr2
&& (DW_UNSND (attr2
) != 0))
4099 add_symbol_to_list (sym
, &global_symbols
);
4103 add_symbol_to_list (sym
, list_in_scope
);
4106 case DW_TAG_variable
:
4107 /* Compilation with minimal debug info may result in variables
4108 with missing type entries. Change the misleading `void' type
4109 to something sensible. */
4110 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4111 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4112 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4113 "<variable, no debug info>",
4115 attr
= dwarf_attr (die
, DW_AT_const_value
);
4118 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4119 attr2
= dwarf_attr (die
, DW_AT_external
);
4120 if (attr2
&& (DW_UNSND (attr2
) != 0))
4121 add_symbol_to_list (sym
, &global_symbols
);
4123 add_symbol_to_list (sym
, list_in_scope
);
4126 attr
= dwarf_attr (die
, DW_AT_location
);
4129 attr2
= dwarf_attr (die
, DW_AT_external
);
4130 if (attr2
&& (DW_UNSND (attr2
) != 0))
4132 SYMBOL_VALUE_ADDRESS (sym
) =
4133 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4134 add_symbol_to_list (sym
, &global_symbols
);
4136 /* In shared libraries the address of the variable
4137 in the location descriptor might still be relocatable,
4138 so its value could be zero.
4139 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4140 value is zero, the address of the variable will then
4141 be determined from the minimal symbol table whenever
4142 the variable is referenced. */
4143 if (SYMBOL_VALUE_ADDRESS (sym
))
4145 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4146 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4149 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4153 SYMBOL_VALUE (sym
) = addr
=
4154 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4155 add_symbol_to_list (sym
, list_in_scope
);
4158 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4162 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4166 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4167 SYMBOL_BASEREG (sym
) = basereg
;
4171 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4175 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4176 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4182 /* We do not know the address of this symbol.
4183 If it is an external symbol and we have type information
4184 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4185 The address of the variable will then be determined from
4186 the minimal symbol table whenever the variable is
4188 attr2
= dwarf_attr (die
, DW_AT_external
);
4189 if (attr2
&& (DW_UNSND (attr2
) != 0)
4190 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4192 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4193 add_symbol_to_list (sym
, &global_symbols
);
4197 case DW_TAG_formal_parameter
:
4198 attr
= dwarf_attr (die
, DW_AT_location
);
4201 SYMBOL_VALUE (sym
) =
4202 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4205 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4211 if (basereg
!= frame_base_reg
)
4212 complain (&dwarf2_complex_location_expr
);
4213 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4217 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4218 SYMBOL_BASEREG (sym
) = basereg
;
4223 SYMBOL_CLASS (sym
) = LOC_ARG
;
4226 attr
= dwarf_attr (die
, DW_AT_const_value
);
4229 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4231 add_symbol_to_list (sym
, list_in_scope
);
4233 case DW_TAG_unspecified_parameters
:
4234 /* From varargs functions; gdb doesn't seem to have any
4235 interest in this information, so just ignore it for now.
4238 case DW_TAG_class_type
:
4239 case DW_TAG_structure_type
:
4240 case DW_TAG_union_type
:
4241 case DW_TAG_enumeration_type
:
4242 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4243 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4244 add_symbol_to_list (sym
, list_in_scope
);
4246 /* The semantics of C++ state that "struct foo { ... }" also
4247 defines a typedef for "foo". Synthesize a typedef symbol so
4248 that "ptype foo" works as expected. */
4249 if (cu_language
== language_cplus
)
4251 struct symbol
*typedef_sym
= (struct symbol
*)
4252 obstack_alloc (&objfile
->symbol_obstack
,
4253 sizeof (struct symbol
));
4254 *typedef_sym
= *sym
;
4255 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4256 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4257 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4258 obsavestring (SYMBOL_NAME (sym
),
4259 strlen (SYMBOL_NAME (sym
)),
4260 &objfile
->type_obstack
);
4261 add_symbol_to_list (typedef_sym
, list_in_scope
);
4264 case DW_TAG_typedef
:
4265 case DW_TAG_base_type
:
4266 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4267 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4268 add_symbol_to_list (sym
, list_in_scope
);
4270 case DW_TAG_enumerator
:
4271 attr
= dwarf_attr (die
, DW_AT_const_value
);
4274 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4276 add_symbol_to_list (sym
, list_in_scope
);
4279 /* Not a tag we recognize. Hopefully we aren't processing
4280 trash data, but since we must specifically ignore things
4281 we don't recognize, there is nothing else we should do at
4283 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4290 /* Copy constant value from an attribute to a symbol. */
4293 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4294 struct objfile
*objfile
,
4295 const struct comp_unit_head
*cu_header
)
4297 struct dwarf_block
*blk
;
4302 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4303 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4304 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4305 SYMBOL_VALUE_BYTES (sym
) = (char *)
4306 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4307 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4309 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4311 case DW_FORM_block1
:
4312 case DW_FORM_block2
:
4313 case DW_FORM_block4
:
4315 blk
= DW_BLOCK (attr
);
4316 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4317 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4318 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4319 SYMBOL_VALUE_BYTES (sym
) = (char *)
4320 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4321 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4322 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4325 /* The DW_AT_const_value attributes are supposed to carry the
4326 symbol's value "represented as it would be on the target
4327 architecture." By the time we get here, it's already been
4328 converted to host endianness, so we just need to sign- or
4329 zero-extend it as appropriate. */
4331 dwarf2_const_value_data (attr
, sym
, 8);
4334 dwarf2_const_value_data (attr
, sym
, 16);
4337 dwarf2_const_value_data (attr
, sym
, 32);
4340 dwarf2_const_value_data (attr
, sym
, 64);
4344 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4345 SYMBOL_CLASS (sym
) = LOC_CONST
;
4349 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4350 SYMBOL_CLASS (sym
) = LOC_CONST
;
4354 complain (&dwarf2_unsupported_const_value_attr
,
4355 dwarf_form_name (attr
->form
));
4356 SYMBOL_VALUE (sym
) = 0;
4357 SYMBOL_CLASS (sym
) = LOC_CONST
;
4363 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4364 or zero-extend it as appropriate for the symbol's type. */
4366 dwarf2_const_value_data (struct attribute
*attr
,
4370 LONGEST l
= DW_UNSND (attr
);
4372 if (bits
< sizeof (l
) * 8)
4374 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4375 l
&= ((LONGEST
) 1 << bits
) - 1;
4377 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4380 SYMBOL_VALUE (sym
) = l
;
4381 SYMBOL_CLASS (sym
) = LOC_CONST
;
4385 /* Return the type of the die in question using its DW_AT_type attribute. */
4387 static struct type
*
4388 die_type (struct die_info
*die
, struct objfile
*objfile
,
4389 const struct comp_unit_head
*cu_header
)
4392 struct attribute
*type_attr
;
4393 struct die_info
*type_die
;
4396 type_attr
= dwarf_attr (die
, DW_AT_type
);
4399 /* A missing DW_AT_type represents a void type. */
4400 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4404 ref
= dwarf2_get_ref_die_offset (type_attr
);
4405 type_die
= follow_die_ref (ref
);
4408 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4412 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4415 dump_die (type_die
);
4416 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4421 /* Return the containing type of the die in question using its
4422 DW_AT_containing_type attribute. */
4424 static struct type
*
4425 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4426 const struct comp_unit_head
*cu_header
)
4428 struct type
*type
= NULL
;
4429 struct attribute
*type_attr
;
4430 struct die_info
*type_die
= NULL
;
4433 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4436 ref
= dwarf2_get_ref_die_offset (type_attr
);
4437 type_die
= follow_die_ref (ref
);
4440 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4443 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4448 dump_die (type_die
);
4449 error ("Dwarf Error: Problem turning containing type into gdb type.");
4455 static struct type
*
4456 type_at_offset (offset
, objfile
)
4457 unsigned int offset
;
4458 struct objfile
*objfile
;
4460 struct die_info
*die
;
4463 die
= follow_die_ref (offset
);
4466 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4469 type
= tag_type_to_type (die
, objfile
);
4474 static struct type
*
4475 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4476 const struct comp_unit_head
*cu_header
)
4484 struct attribute
*attr
;
4485 attr
= dwarf_attr (die
, DW_AT_name
);
4486 if (attr
&& DW_STRING (attr
))
4488 char *attrname
=DW_STRING (attr
);
4489 unsigned long hashval
=hash(attrname
, strlen(attrname
)) % TYPE_HASH_SIZE
;
4491 if (dwarf2_cached_types
[hashval
] != NULL
)
4493 const char *nameoftype
;
4494 nameoftype
= TYPE_NAME(dwarf2_cached_types
[hashval
]) == NULL
? TYPE_TAG_NAME(dwarf2_cached_types
[hashval
]) : TYPE_NAME(dwarf2_cached_types
[hashval
]);
4495 if (strcmp(attrname
, nameoftype
) == 0)
4497 die
->type
=dwarf2_cached_types
[hashval
];
4501 read_type_die (die
, objfile
, cu_header
);
4502 dwarf2_cached_types
[hashval
] = die
->type
;
4507 read_type_die (die
, objfile
, cu_header
);
4508 dwarf2_cached_types
[hashval
] = die
->type
;
4513 read_type_die (die
, objfile
, cu_header
);
4519 error ("Dwarf Error: Cannot find type of die.");
4526 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4527 const struct comp_unit_head
*cu_header
)
4531 case DW_TAG_class_type
:
4532 case DW_TAG_structure_type
:
4533 case DW_TAG_union_type
:
4534 read_structure_scope (die
, objfile
, cu_header
);
4536 case DW_TAG_enumeration_type
:
4537 read_enumeration (die
, objfile
, cu_header
);
4539 case DW_TAG_subprogram
:
4540 case DW_TAG_subroutine_type
:
4541 read_subroutine_type (die
, objfile
, cu_header
);
4543 case DW_TAG_array_type
:
4544 read_array_type (die
, objfile
, cu_header
);
4546 case DW_TAG_pointer_type
:
4547 read_tag_pointer_type (die
, objfile
, cu_header
);
4549 case DW_TAG_ptr_to_member_type
:
4550 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4552 case DW_TAG_reference_type
:
4553 read_tag_reference_type (die
, objfile
, cu_header
);
4555 case DW_TAG_const_type
:
4556 read_tag_const_type (die
, objfile
, cu_header
);
4558 case DW_TAG_volatile_type
:
4559 read_tag_volatile_type (die
, objfile
, cu_header
);
4561 case DW_TAG_string_type
:
4562 read_tag_string_type (die
, objfile
);
4564 case DW_TAG_typedef
:
4565 read_typedef (die
, objfile
, cu_header
);
4567 case DW_TAG_base_type
:
4568 read_base_type (die
, objfile
);
4571 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4576 static struct type
*
4577 dwarf_base_type (encoding
, size
, objfile
)
4580 struct objfile
*objfile
;
4582 /* FIXME - this should not produce a new (struct type *)
4583 every time. It should cache base types. */
4587 case DW_ATE_address
:
4588 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4590 case DW_ATE_boolean
:
4591 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4593 case DW_ATE_complex_float
:
4596 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4600 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4606 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4610 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4617 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4620 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4624 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4628 case DW_ATE_signed_char
:
4629 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4631 case DW_ATE_unsigned
:
4635 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4638 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4642 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4646 case DW_ATE_unsigned_char
:
4647 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4650 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4658 struct die_info
*old_die
;
4660 struct die_info
*new_die
;
4663 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4664 memset (new_die
, 0, sizeof (struct die_info
));
4666 new_die
->tag
= old_die
->tag
;
4667 new_die
->has_children
= old_die
->has_children
;
4668 new_die
->abbrev
= old_die
->abbrev
;
4669 new_die
->offset
= old_die
->offset
;
4670 new_die
->type
= NULL
;
4672 num_attrs
= old_die
->num_attrs
;
4673 new_die
->num_attrs
= num_attrs
;
4674 new_die
->attrs
= (struct attribute
*)
4675 xmalloc (num_attrs
* sizeof (struct attribute
));
4677 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4679 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4680 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4681 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4684 new_die
->next
= NULL
;
4689 /* Return sibling of die, NULL if no sibling. */
4693 struct die_info
*die
;
4695 int nesting_level
= 0;
4697 if (!die
->has_children
)
4699 if (die
->next
&& (die
->next
->tag
== 0))
4712 if (die
->has_children
)
4722 while (nesting_level
);
4723 if (die
&& (die
->tag
== 0))
4734 /* Get linkage name of a die, return NULL if not found. */
4737 dwarf2_linkage_name (die
)
4738 struct die_info
*die
;
4740 struct attribute
*attr
;
4742 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4743 if (attr
&& DW_STRING (attr
))
4744 return DW_STRING (attr
);
4745 attr
= dwarf_attr (die
, DW_AT_name
);
4746 if (attr
&& DW_STRING (attr
))
4747 return DW_STRING (attr
);
4751 /* Convert a DIE tag into its string name. */
4754 dwarf_tag_name (tag
)
4755 register unsigned tag
;
4759 case DW_TAG_padding
:
4760 return "DW_TAG_padding";
4761 case DW_TAG_array_type
:
4762 return "DW_TAG_array_type";
4763 case DW_TAG_class_type
:
4764 return "DW_TAG_class_type";
4765 case DW_TAG_entry_point
:
4766 return "DW_TAG_entry_point";
4767 case DW_TAG_enumeration_type
:
4768 return "DW_TAG_enumeration_type";
4769 case DW_TAG_formal_parameter
:
4770 return "DW_TAG_formal_parameter";
4771 case DW_TAG_imported_declaration
:
4772 return "DW_TAG_imported_declaration";
4774 return "DW_TAG_label";
4775 case DW_TAG_lexical_block
:
4776 return "DW_TAG_lexical_block";
4778 return "DW_TAG_member";
4779 case DW_TAG_pointer_type
:
4780 return "DW_TAG_pointer_type";
4781 case DW_TAG_reference_type
:
4782 return "DW_TAG_reference_type";
4783 case DW_TAG_compile_unit
:
4784 return "DW_TAG_compile_unit";
4785 case DW_TAG_string_type
:
4786 return "DW_TAG_string_type";
4787 case DW_TAG_structure_type
:
4788 return "DW_TAG_structure_type";
4789 case DW_TAG_subroutine_type
:
4790 return "DW_TAG_subroutine_type";
4791 case DW_TAG_typedef
:
4792 return "DW_TAG_typedef";
4793 case DW_TAG_union_type
:
4794 return "DW_TAG_union_type";
4795 case DW_TAG_unspecified_parameters
:
4796 return "DW_TAG_unspecified_parameters";
4797 case DW_TAG_variant
:
4798 return "DW_TAG_variant";
4799 case DW_TAG_common_block
:
4800 return "DW_TAG_common_block";
4801 case DW_TAG_common_inclusion
:
4802 return "DW_TAG_common_inclusion";
4803 case DW_TAG_inheritance
:
4804 return "DW_TAG_inheritance";
4805 case DW_TAG_inlined_subroutine
:
4806 return "DW_TAG_inlined_subroutine";
4808 return "DW_TAG_module";
4809 case DW_TAG_ptr_to_member_type
:
4810 return "DW_TAG_ptr_to_member_type";
4811 case DW_TAG_set_type
:
4812 return "DW_TAG_set_type";
4813 case DW_TAG_subrange_type
:
4814 return "DW_TAG_subrange_type";
4815 case DW_TAG_with_stmt
:
4816 return "DW_TAG_with_stmt";
4817 case DW_TAG_access_declaration
:
4818 return "DW_TAG_access_declaration";
4819 case DW_TAG_base_type
:
4820 return "DW_TAG_base_type";
4821 case DW_TAG_catch_block
:
4822 return "DW_TAG_catch_block";
4823 case DW_TAG_const_type
:
4824 return "DW_TAG_const_type";
4825 case DW_TAG_constant
:
4826 return "DW_TAG_constant";
4827 case DW_TAG_enumerator
:
4828 return "DW_TAG_enumerator";
4829 case DW_TAG_file_type
:
4830 return "DW_TAG_file_type";
4832 return "DW_TAG_friend";
4833 case DW_TAG_namelist
:
4834 return "DW_TAG_namelist";
4835 case DW_TAG_namelist_item
:
4836 return "DW_TAG_namelist_item";
4837 case DW_TAG_packed_type
:
4838 return "DW_TAG_packed_type";
4839 case DW_TAG_subprogram
:
4840 return "DW_TAG_subprogram";
4841 case DW_TAG_template_type_param
:
4842 return "DW_TAG_template_type_param";
4843 case DW_TAG_template_value_param
:
4844 return "DW_TAG_template_value_param";
4845 case DW_TAG_thrown_type
:
4846 return "DW_TAG_thrown_type";
4847 case DW_TAG_try_block
:
4848 return "DW_TAG_try_block";
4849 case DW_TAG_variant_part
:
4850 return "DW_TAG_variant_part";
4851 case DW_TAG_variable
:
4852 return "DW_TAG_variable";
4853 case DW_TAG_volatile_type
:
4854 return "DW_TAG_volatile_type";
4855 case DW_TAG_MIPS_loop
:
4856 return "DW_TAG_MIPS_loop";
4857 case DW_TAG_format_label
:
4858 return "DW_TAG_format_label";
4859 case DW_TAG_function_template
:
4860 return "DW_TAG_function_template";
4861 case DW_TAG_class_template
:
4862 return "DW_TAG_class_template";
4864 return "DW_TAG_<unknown>";
4868 /* Convert a DWARF attribute code into its string name. */
4871 dwarf_attr_name (attr
)
4872 register unsigned attr
;
4877 return "DW_AT_sibling";
4878 case DW_AT_location
:
4879 return "DW_AT_location";
4881 return "DW_AT_name";
4882 case DW_AT_ordering
:
4883 return "DW_AT_ordering";
4884 case DW_AT_subscr_data
:
4885 return "DW_AT_subscr_data";
4886 case DW_AT_byte_size
:
4887 return "DW_AT_byte_size";
4888 case DW_AT_bit_offset
:
4889 return "DW_AT_bit_offset";
4890 case DW_AT_bit_size
:
4891 return "DW_AT_bit_size";
4892 case DW_AT_element_list
:
4893 return "DW_AT_element_list";
4894 case DW_AT_stmt_list
:
4895 return "DW_AT_stmt_list";
4897 return "DW_AT_low_pc";
4899 return "DW_AT_high_pc";
4900 case DW_AT_language
:
4901 return "DW_AT_language";
4903 return "DW_AT_member";
4905 return "DW_AT_discr";
4906 case DW_AT_discr_value
:
4907 return "DW_AT_discr_value";
4908 case DW_AT_visibility
:
4909 return "DW_AT_visibility";
4911 return "DW_AT_import";
4912 case DW_AT_string_length
:
4913 return "DW_AT_string_length";
4914 case DW_AT_common_reference
:
4915 return "DW_AT_common_reference";
4916 case DW_AT_comp_dir
:
4917 return "DW_AT_comp_dir";
4918 case DW_AT_const_value
:
4919 return "DW_AT_const_value";
4920 case DW_AT_containing_type
:
4921 return "DW_AT_containing_type";
4922 case DW_AT_default_value
:
4923 return "DW_AT_default_value";
4925 return "DW_AT_inline";
4926 case DW_AT_is_optional
:
4927 return "DW_AT_is_optional";
4928 case DW_AT_lower_bound
:
4929 return "DW_AT_lower_bound";
4930 case DW_AT_producer
:
4931 return "DW_AT_producer";
4932 case DW_AT_prototyped
:
4933 return "DW_AT_prototyped";
4934 case DW_AT_return_addr
:
4935 return "DW_AT_return_addr";
4936 case DW_AT_start_scope
:
4937 return "DW_AT_start_scope";
4938 case DW_AT_stride_size
:
4939 return "DW_AT_stride_size";
4940 case DW_AT_upper_bound
:
4941 return "DW_AT_upper_bound";
4942 case DW_AT_abstract_origin
:
4943 return "DW_AT_abstract_origin";
4944 case DW_AT_accessibility
:
4945 return "DW_AT_accessibility";
4946 case DW_AT_address_class
:
4947 return "DW_AT_address_class";
4948 case DW_AT_artificial
:
4949 return "DW_AT_artificial";
4950 case DW_AT_base_types
:
4951 return "DW_AT_base_types";
4952 case DW_AT_calling_convention
:
4953 return "DW_AT_calling_convention";
4955 return "DW_AT_count";
4956 case DW_AT_data_member_location
:
4957 return "DW_AT_data_member_location";
4958 case DW_AT_decl_column
:
4959 return "DW_AT_decl_column";
4960 case DW_AT_decl_file
:
4961 return "DW_AT_decl_file";
4962 case DW_AT_decl_line
:
4963 return "DW_AT_decl_line";
4964 case DW_AT_declaration
:
4965 return "DW_AT_declaration";
4966 case DW_AT_discr_list
:
4967 return "DW_AT_discr_list";
4968 case DW_AT_encoding
:
4969 return "DW_AT_encoding";
4970 case DW_AT_external
:
4971 return "DW_AT_external";
4972 case DW_AT_frame_base
:
4973 return "DW_AT_frame_base";
4975 return "DW_AT_friend";
4976 case DW_AT_identifier_case
:
4977 return "DW_AT_identifier_case";
4978 case DW_AT_macro_info
:
4979 return "DW_AT_macro_info";
4980 case DW_AT_namelist_items
:
4981 return "DW_AT_namelist_items";
4982 case DW_AT_priority
:
4983 return "DW_AT_priority";
4985 return "DW_AT_segment";
4986 case DW_AT_specification
:
4987 return "DW_AT_specification";
4988 case DW_AT_static_link
:
4989 return "DW_AT_static_link";
4991 return "DW_AT_type";
4992 case DW_AT_use_location
:
4993 return "DW_AT_use_location";
4994 case DW_AT_variable_parameter
:
4995 return "DW_AT_variable_parameter";
4996 case DW_AT_virtuality
:
4997 return "DW_AT_virtuality";
4998 case DW_AT_vtable_elem_location
:
4999 return "DW_AT_vtable_elem_location";
5002 case DW_AT_MIPS_fde
:
5003 return "DW_AT_MIPS_fde";
5004 case DW_AT_MIPS_loop_begin
:
5005 return "DW_AT_MIPS_loop_begin";
5006 case DW_AT_MIPS_tail_loop_begin
:
5007 return "DW_AT_MIPS_tail_loop_begin";
5008 case DW_AT_MIPS_epilog_begin
:
5009 return "DW_AT_MIPS_epilog_begin";
5010 case DW_AT_MIPS_loop_unroll_factor
:
5011 return "DW_AT_MIPS_loop_unroll_factor";
5012 case DW_AT_MIPS_software_pipeline_depth
:
5013 return "DW_AT_MIPS_software_pipeline_depth";
5014 case DW_AT_MIPS_linkage_name
:
5015 return "DW_AT_MIPS_linkage_name";
5018 case DW_AT_sf_names
:
5019 return "DW_AT_sf_names";
5020 case DW_AT_src_info
:
5021 return "DW_AT_src_info";
5022 case DW_AT_mac_info
:
5023 return "DW_AT_mac_info";
5024 case DW_AT_src_coords
:
5025 return "DW_AT_src_coords";
5026 case DW_AT_body_begin
:
5027 return "DW_AT_body_begin";
5028 case DW_AT_body_end
:
5029 return "DW_AT_body_end";
5031 return "DW_AT_<unknown>";
5035 /* Convert a DWARF value form code into its string name. */
5038 dwarf_form_name (form
)
5039 register unsigned form
;
5044 return "DW_FORM_addr";
5045 case DW_FORM_block2
:
5046 return "DW_FORM_block2";
5047 case DW_FORM_block4
:
5048 return "DW_FORM_block4";
5050 return "DW_FORM_data2";
5052 return "DW_FORM_data4";
5054 return "DW_FORM_data8";
5055 case DW_FORM_string
:
5056 return "DW_FORM_string";
5058 return "DW_FORM_block";
5059 case DW_FORM_block1
:
5060 return "DW_FORM_block1";
5062 return "DW_FORM_data1";
5064 return "DW_FORM_flag";
5066 return "DW_FORM_sdata";
5068 return "DW_FORM_strp";
5070 return "DW_FORM_udata";
5071 case DW_FORM_ref_addr
:
5072 return "DW_FORM_ref_addr";
5074 return "DW_FORM_ref1";
5076 return "DW_FORM_ref2";
5078 return "DW_FORM_ref4";
5080 return "DW_FORM_ref8";
5081 case DW_FORM_ref_udata
:
5082 return "DW_FORM_ref_udata";
5083 case DW_FORM_indirect
:
5084 return "DW_FORM_indirect";
5086 return "DW_FORM_<unknown>";
5090 /* Convert a DWARF stack opcode into its string name. */
5093 dwarf_stack_op_name (op
)
5094 register unsigned op
;
5099 return "DW_OP_addr";
5101 return "DW_OP_deref";
5103 return "DW_OP_const1u";
5105 return "DW_OP_const1s";
5107 return "DW_OP_const2u";
5109 return "DW_OP_const2s";
5111 return "DW_OP_const4u";
5113 return "DW_OP_const4s";
5115 return "DW_OP_const8u";
5117 return "DW_OP_const8s";
5119 return "DW_OP_constu";
5121 return "DW_OP_consts";
5125 return "DW_OP_drop";
5127 return "DW_OP_over";
5129 return "DW_OP_pick";
5131 return "DW_OP_swap";
5135 return "DW_OP_xderef";
5143 return "DW_OP_minus";
5155 return "DW_OP_plus";
5156 case DW_OP_plus_uconst
:
5157 return "DW_OP_plus_uconst";
5163 return "DW_OP_shra";
5181 return "DW_OP_skip";
5183 return "DW_OP_lit0";
5185 return "DW_OP_lit1";
5187 return "DW_OP_lit2";
5189 return "DW_OP_lit3";
5191 return "DW_OP_lit4";
5193 return "DW_OP_lit5";
5195 return "DW_OP_lit6";
5197 return "DW_OP_lit7";
5199 return "DW_OP_lit8";
5201 return "DW_OP_lit9";
5203 return "DW_OP_lit10";
5205 return "DW_OP_lit11";
5207 return "DW_OP_lit12";
5209 return "DW_OP_lit13";
5211 return "DW_OP_lit14";
5213 return "DW_OP_lit15";
5215 return "DW_OP_lit16";
5217 return "DW_OP_lit17";
5219 return "DW_OP_lit18";
5221 return "DW_OP_lit19";
5223 return "DW_OP_lit20";
5225 return "DW_OP_lit21";
5227 return "DW_OP_lit22";
5229 return "DW_OP_lit23";
5231 return "DW_OP_lit24";
5233 return "DW_OP_lit25";
5235 return "DW_OP_lit26";
5237 return "DW_OP_lit27";
5239 return "DW_OP_lit28";
5241 return "DW_OP_lit29";
5243 return "DW_OP_lit30";
5245 return "DW_OP_lit31";
5247 return "DW_OP_reg0";
5249 return "DW_OP_reg1";
5251 return "DW_OP_reg2";
5253 return "DW_OP_reg3";
5255 return "DW_OP_reg4";
5257 return "DW_OP_reg5";
5259 return "DW_OP_reg6";
5261 return "DW_OP_reg7";
5263 return "DW_OP_reg8";
5265 return "DW_OP_reg9";
5267 return "DW_OP_reg10";
5269 return "DW_OP_reg11";
5271 return "DW_OP_reg12";
5273 return "DW_OP_reg13";
5275 return "DW_OP_reg14";
5277 return "DW_OP_reg15";
5279 return "DW_OP_reg16";
5281 return "DW_OP_reg17";
5283 return "DW_OP_reg18";
5285 return "DW_OP_reg19";
5287 return "DW_OP_reg20";
5289 return "DW_OP_reg21";
5291 return "DW_OP_reg22";
5293 return "DW_OP_reg23";
5295 return "DW_OP_reg24";
5297 return "DW_OP_reg25";
5299 return "DW_OP_reg26";
5301 return "DW_OP_reg27";
5303 return "DW_OP_reg28";
5305 return "DW_OP_reg29";
5307 return "DW_OP_reg30";
5309 return "DW_OP_reg31";
5311 return "DW_OP_breg0";
5313 return "DW_OP_breg1";
5315 return "DW_OP_breg2";
5317 return "DW_OP_breg3";
5319 return "DW_OP_breg4";
5321 return "DW_OP_breg5";
5323 return "DW_OP_breg6";
5325 return "DW_OP_breg7";
5327 return "DW_OP_breg8";
5329 return "DW_OP_breg9";
5331 return "DW_OP_breg10";
5333 return "DW_OP_breg11";
5335 return "DW_OP_breg12";
5337 return "DW_OP_breg13";
5339 return "DW_OP_breg14";
5341 return "DW_OP_breg15";
5343 return "DW_OP_breg16";
5345 return "DW_OP_breg17";
5347 return "DW_OP_breg18";
5349 return "DW_OP_breg19";
5351 return "DW_OP_breg20";
5353 return "DW_OP_breg21";
5355 return "DW_OP_breg22";
5357 return "DW_OP_breg23";
5359 return "DW_OP_breg24";
5361 return "DW_OP_breg25";
5363 return "DW_OP_breg26";
5365 return "DW_OP_breg27";
5367 return "DW_OP_breg28";
5369 return "DW_OP_breg29";
5371 return "DW_OP_breg30";
5373 return "DW_OP_breg31";
5375 return "DW_OP_regx";
5377 return "DW_OP_fbreg";
5379 return "DW_OP_bregx";
5381 return "DW_OP_piece";
5382 case DW_OP_deref_size
:
5383 return "DW_OP_deref_size";
5384 case DW_OP_xderef_size
:
5385 return "DW_OP_xderef_size";
5389 return "OP_<unknown>";
5394 dwarf_bool_name (mybool
)
5403 /* Convert a DWARF type code into its string name. */
5406 dwarf_type_encoding_name (enc
)
5407 register unsigned enc
;
5411 case DW_ATE_address
:
5412 return "DW_ATE_address";
5413 case DW_ATE_boolean
:
5414 return "DW_ATE_boolean";
5415 case DW_ATE_complex_float
:
5416 return "DW_ATE_complex_float";
5418 return "DW_ATE_float";
5420 return "DW_ATE_signed";
5421 case DW_ATE_signed_char
:
5422 return "DW_ATE_signed_char";
5423 case DW_ATE_unsigned
:
5424 return "DW_ATE_unsigned";
5425 case DW_ATE_unsigned_char
:
5426 return "DW_ATE_unsigned_char";
5428 return "DW_ATE_<unknown>";
5432 /* Convert a DWARF call frame info operation to its string name. */
5436 dwarf_cfi_name (cfi_opc
)
5437 register unsigned cfi_opc
;
5441 case DW_CFA_advance_loc
:
5442 return "DW_CFA_advance_loc";
5444 return "DW_CFA_offset";
5445 case DW_CFA_restore
:
5446 return "DW_CFA_restore";
5448 return "DW_CFA_nop";
5449 case DW_CFA_set_loc
:
5450 return "DW_CFA_set_loc";
5451 case DW_CFA_advance_loc1
:
5452 return "DW_CFA_advance_loc1";
5453 case DW_CFA_advance_loc2
:
5454 return "DW_CFA_advance_loc2";
5455 case DW_CFA_advance_loc4
:
5456 return "DW_CFA_advance_loc4";
5457 case DW_CFA_offset_extended
:
5458 return "DW_CFA_offset_extended";
5459 case DW_CFA_restore_extended
:
5460 return "DW_CFA_restore_extended";
5461 case DW_CFA_undefined
:
5462 return "DW_CFA_undefined";
5463 case DW_CFA_same_value
:
5464 return "DW_CFA_same_value";
5465 case DW_CFA_register
:
5466 return "DW_CFA_register";
5467 case DW_CFA_remember_state
:
5468 return "DW_CFA_remember_state";
5469 case DW_CFA_restore_state
:
5470 return "DW_CFA_restore_state";
5471 case DW_CFA_def_cfa
:
5472 return "DW_CFA_def_cfa";
5473 case DW_CFA_def_cfa_register
:
5474 return "DW_CFA_def_cfa_register";
5475 case DW_CFA_def_cfa_offset
:
5476 return "DW_CFA_def_cfa_offset";
5477 /* SGI/MIPS specific */
5478 case DW_CFA_MIPS_advance_loc8
:
5479 return "DW_CFA_MIPS_advance_loc8";
5481 return "DW_CFA_<unknown>";
5488 struct die_info
*die
;
5492 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5493 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5494 fprintf (stderr
, "\thas children: %s\n",
5495 dwarf_bool_name (die
->has_children
));
5497 fprintf (stderr
, "\tattributes:\n");
5498 for (i
= 0; i
< die
->num_attrs
; ++i
)
5500 fprintf (stderr
, "\t\t%s (%s) ",
5501 dwarf_attr_name (die
->attrs
[i
].name
),
5502 dwarf_form_name (die
->attrs
[i
].form
));
5503 switch (die
->attrs
[i
].form
)
5505 case DW_FORM_ref_addr
:
5507 fprintf (stderr
, "address: ");
5508 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5510 case DW_FORM_block2
:
5511 case DW_FORM_block4
:
5513 case DW_FORM_block1
:
5514 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5525 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5527 case DW_FORM_string
:
5528 fprintf (stderr
, "string: \"%s\"",
5529 DW_STRING (&die
->attrs
[i
])
5530 ? DW_STRING (&die
->attrs
[i
]) : "");
5533 if (DW_UNSND (&die
->attrs
[i
]))
5534 fprintf (stderr
, "flag: TRUE");
5536 fprintf (stderr
, "flag: FALSE");
5538 case DW_FORM_strp
: /* we do not support separate string
5540 case DW_FORM_indirect
: /* we do not handle indirect yet */
5542 fprintf (stderr
, "unsupported attribute form: %d.",
5543 die
->attrs
[i
].form
);
5545 fprintf (stderr
, "\n");
5551 struct die_info
*die
;
5561 store_in_ref_table (offset
, die
)
5562 unsigned int offset
;
5563 struct die_info
*die
;
5566 struct die_info
*old
;
5568 h
= (offset
% REF_HASH_SIZE
);
5569 old
= die_ref_table
[h
];
5570 die
->next_ref
= old
;
5571 die_ref_table
[h
] = die
;
5576 dwarf2_empty_hash_tables ()
5578 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5579 memset (dwarf2_cached_types
, 0, sizeof(dwarf2_cached_types
));
5583 dwarf2_get_ref_die_offset (attr
)
5584 struct attribute
*attr
;
5586 unsigned int result
= 0;
5590 case DW_FORM_ref_addr
:
5591 result
= DW_ADDR (attr
);
5596 case DW_FORM_ref_udata
:
5597 result
= cu_header_offset
+ DW_UNSND (attr
);
5600 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5606 follow_die_ref (offset
)
5607 unsigned int offset
;
5609 struct die_info
*die
;
5612 h
= (offset
% REF_HASH_SIZE
);
5613 die
= die_ref_table
[h
];
5616 if (die
->offset
== offset
)
5620 die
= die
->next_ref
;
5625 static struct type
*
5626 dwarf2_fundamental_type (objfile
, typeid)
5627 struct objfile
*objfile
;
5630 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5632 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5636 /* Look for this particular type in the fundamental type vector. If
5637 one is not found, create and install one appropriate for the
5638 current language and the current target machine. */
5640 if (ftypes
[typeid] == NULL
)
5642 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5645 return (ftypes
[typeid]);
5648 /* Decode simple location descriptions.
5649 Given a pointer to a dwarf block that defines a location, compute
5650 the location and return the value.
5652 FIXME: This is a kludge until we figure out a better
5653 way to handle the location descriptions.
5654 Gdb's design does not mesh well with the DWARF2 notion of a location
5655 computing interpreter, which is a shame because the flexibility goes unused.
5656 FIXME: Implement more operations as necessary.
5658 A location description containing no operations indicates that the
5659 object is optimized out. The global optimized_out flag is set for
5660 those, the return value is meaningless.
5662 When the result is a register number, the global isreg flag is set,
5663 otherwise it is cleared.
5665 When the result is a base register offset, the global offreg flag is set
5666 and the register number is returned in basereg, otherwise it is cleared.
5668 When the DW_OP_fbreg operation is encountered without a corresponding
5669 DW_AT_frame_base attribute, the global islocal flag is set.
5670 Hopefully the machine dependent code knows how to set up a virtual
5671 frame pointer for the local references.
5673 Note that stack[0] is unused except as a default error return.
5674 Note that stack overflow is not yet handled. */
5677 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5678 const struct comp_unit_head
*cu_header
)
5681 int size
= blk
->size
;
5682 char *data
= blk
->data
;
5683 CORE_ADDR stack
[64];
5685 unsigned int bytes_read
, unsnd
;
5736 stack
[++stacki
] = op
- DW_OP_reg0
;
5741 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5743 #if defined(HARRIS_TARGET) && defined(_M88K)
5744 /* The Harris 88110 gdb ports have long kept their special reg
5745 numbers between their gp-regs and their x-regs. This is
5746 not how our dwarf is generated. Punt. */
5749 stack
[++stacki
] = unsnd
;
5785 basereg
= op
- DW_OP_breg0
;
5786 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5792 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5794 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5799 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5801 if (frame_base_reg
>= 0)
5804 basereg
= frame_base_reg
;
5805 stack
[stacki
] += frame_base_offset
;
5809 complain (&dwarf2_missing_at_frame_base
);
5815 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5816 cu_header
, &bytes_read
);
5821 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5826 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5831 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5836 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5841 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5846 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5851 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5857 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5862 stack
[stacki
- 1] += stack
[stacki
];
5866 case DW_OP_plus_uconst
:
5867 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5872 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5878 /* If we're not the last op, then we definitely can't encode
5879 this using GDB's address_class enum. */
5881 complain (&dwarf2_complex_location_expr
);
5885 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5886 return (stack
[stacki
]);
5889 return (stack
[stacki
]);
5892 /* memory allocation interface */
5896 dwarf2_free_tmp_obstack (ignore
)
5899 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5902 static struct dwarf_block
*
5903 dwarf_alloc_block ()
5905 struct dwarf_block
*blk
;
5907 blk
= (struct dwarf_block
*)
5908 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5912 static struct abbrev_info
*
5913 dwarf_alloc_abbrev ()
5915 struct abbrev_info
*abbrev
;
5917 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5918 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5922 static struct die_info
*
5925 struct die_info
*die
;
5927 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5928 memset (die
, 0, sizeof (struct die_info
));