1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
36 #include "elf/dwarf2.h"
39 #include "expression.h"
40 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
45 #include "dwarf2expr.h"
46 #include "dwarf2loc.h"
47 #include "cp-support.h"
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
54 #ifndef DWARF2_REG_TO_REGNUM
55 #define DWARF2_REG_TO_REGNUM(REG) (REG)
59 /* .debug_info header for a compilation unit
60 Because of alignment constraints, this structure has padding and cannot
61 be mapped directly onto the beginning of the .debug_info section. */
62 typedef struct comp_unit_header
64 unsigned int length
; /* length of the .debug_info
66 unsigned short version
; /* version number -- 2 for DWARF
68 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
69 unsigned char addr_size
; /* byte size of an address -- 4 */
72 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
75 /* .debug_pubnames header
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct pubnames_header
80 unsigned int length
; /* length of the .debug_pubnames
82 unsigned char version
; /* version number -- 2 for DWARF
84 unsigned int info_offset
; /* offset into .debug_info section */
85 unsigned int info_size
; /* byte size of .debug_info section
89 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
91 /* .debug_pubnames header
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct aranges_header
96 unsigned int length
; /* byte len of the .debug_aranges
98 unsigned short version
; /* version number -- 2 for DWARF
100 unsigned int info_offset
; /* offset into .debug_info section */
101 unsigned char addr_size
; /* byte size of an address */
102 unsigned char seg_size
; /* byte size of segment descriptor */
105 #define _ACTUAL_ARANGES_HEADER_SIZE 12
107 /* .debug_line statement program prologue
108 Because of alignment constraints, this structure has padding and cannot
109 be mapped directly onto the beginning of the .debug_info section. */
110 typedef struct statement_prologue
112 unsigned int total_length
; /* byte length of the statement
114 unsigned short version
; /* version number -- 2 for DWARF
116 unsigned int prologue_length
; /* # bytes between prologue &
118 unsigned char minimum_instruction_length
; /* byte size of
120 unsigned char default_is_stmt
; /* initial value of is_stmt
123 unsigned char line_range
;
124 unsigned char opcode_base
; /* number assigned to first special
126 unsigned char *standard_opcode_lengths
;
130 /* offsets and sizes of debugging sections */
132 static unsigned int dwarf_info_size
;
133 static unsigned int dwarf_abbrev_size
;
134 static unsigned int dwarf_line_size
;
135 static unsigned int dwarf_pubnames_size
;
136 static unsigned int dwarf_aranges_size
;
137 static unsigned int dwarf_loc_size
;
138 static unsigned int dwarf_macinfo_size
;
139 static unsigned int dwarf_str_size
;
140 static unsigned int dwarf_ranges_size
;
141 unsigned int dwarf_frame_size
;
142 unsigned int dwarf_eh_frame_size
;
144 static asection
*dwarf_info_section
;
145 static asection
*dwarf_abbrev_section
;
146 static asection
*dwarf_line_section
;
147 static asection
*dwarf_pubnames_section
;
148 static asection
*dwarf_aranges_section
;
149 static asection
*dwarf_loc_section
;
150 static asection
*dwarf_macinfo_section
;
151 static asection
*dwarf_str_section
;
152 static asection
*dwarf_ranges_section
;
153 asection
*dwarf_frame_section
;
154 asection
*dwarf_eh_frame_section
;
156 /* names of the debugging sections */
158 #define INFO_SECTION ".debug_info"
159 #define ABBREV_SECTION ".debug_abbrev"
160 #define LINE_SECTION ".debug_line"
161 #define PUBNAMES_SECTION ".debug_pubnames"
162 #define ARANGES_SECTION ".debug_aranges"
163 #define LOC_SECTION ".debug_loc"
164 #define MACINFO_SECTION ".debug_macinfo"
165 #define STR_SECTION ".debug_str"
166 #define RANGES_SECTION ".debug_ranges"
167 #define FRAME_SECTION ".debug_frame"
168 #define EH_FRAME_SECTION ".eh_frame"
170 /* local data types */
172 /* We hold several abbreviation tables in memory at the same time. */
173 #ifndef ABBREV_HASH_SIZE
174 #define ABBREV_HASH_SIZE 121
177 /* The data in a compilation unit header, after target2host
178 translation, looks like this. */
179 struct comp_unit_head
181 unsigned long length
;
183 unsigned int abbrev_offset
;
184 unsigned char addr_size
;
185 unsigned char signed_addr_p
;
186 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
187 unsigned int initial_length_size
; /* size of the length field; either
190 /* Offset to the first byte of this compilation unit header in the
191 * .debug_info section, for resolving relative reference dies. */
195 /* Pointer to this compilation unit header in the .debug_info
200 /* Pointer to the first die of this compilatio unit. This will
201 * be the first byte following the compilation unit header. */
205 /* Pointer to the next compilation unit header in the program. */
207 struct comp_unit_head
*next
;
209 /* DWARF abbreviation table associated with this compilation unit */
211 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
213 /* Base address of this compilation unit. */
215 CORE_ADDR base_address
;
217 /* Non-zero if base_address has been set. */
222 /* Internal state when decoding a particular compilation unit. */
225 /* The objfile containing this compilation unit. */
226 struct objfile
*objfile
;
228 /* The header of the compilation unit.
230 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
231 should be moved to the dwarf2_cu structure; for instance the abbrevs
233 struct comp_unit_head header
;
235 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
237 /* The language we are debugging. */
238 enum language language
;
239 const struct language_defn
*language_defn
;
241 /* The generic symbol table building routines have separate lists for
242 file scope symbols and all all other scopes (local scopes). So
243 we need to select the right one to pass to add_symbol_to_list().
244 We do it by keeping a pointer to the correct list in list_in_scope.
246 FIXME: The original dwarf code just treated the file scope as the
247 first local scope, and all other local scopes as nested local
248 scopes, and worked fine. Check to see if we really need to
249 distinguish these in buildsym.c. */
250 struct pending
**list_in_scope
;
252 /* Maintain an array of referenced fundamental types for the current
253 compilation unit being read. For DWARF version 1, we have to construct
254 the fundamental types on the fly, since no information about the
255 fundamental types is supplied. Each such fundamental type is created by
256 calling a language dependent routine to create the type, and then a
257 pointer to that type is then placed in the array at the index specified
258 by it's FT_<TYPENAME> value. The array has a fixed size set by the
259 FT_NUM_MEMBERS compile time constant, which is the number of predefined
260 fundamental types gdb knows how to construct. */
261 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
264 /* The line number information for a compilation unit (found in the
265 .debug_line section) begins with a "statement program header",
266 which contains the following information. */
269 unsigned int total_length
;
270 unsigned short version
;
271 unsigned int header_length
;
272 unsigned char minimum_instruction_length
;
273 unsigned char default_is_stmt
;
275 unsigned char line_range
;
276 unsigned char opcode_base
;
278 /* standard_opcode_lengths[i] is the number of operands for the
279 standard opcode whose value is i. This means that
280 standard_opcode_lengths[0] is unused, and the last meaningful
281 element is standard_opcode_lengths[opcode_base - 1]. */
282 unsigned char *standard_opcode_lengths
;
284 /* The include_directories table. NOTE! These strings are not
285 allocated with xmalloc; instead, they are pointers into
286 debug_line_buffer. If you try to free them, `free' will get
288 unsigned int num_include_dirs
, include_dirs_size
;
291 /* The file_names table. NOTE! These strings are not allocated
292 with xmalloc; instead, they are pointers into debug_line_buffer.
293 Don't try to free them directly. */
294 unsigned int num_file_names
, file_names_size
;
298 unsigned int dir_index
;
299 unsigned int mod_time
;
303 /* The start and end of the statement program following this
304 header. These point into dwarf_line_buffer. */
305 char *statement_program_start
, *statement_program_end
;
308 /* When we construct a partial symbol table entry we only
309 need this much information. */
310 struct partial_die_info
313 unsigned char has_children
;
314 unsigned char is_external
;
315 unsigned char is_declaration
;
316 unsigned char has_type
;
323 struct dwarf_block
*locdesc
;
324 unsigned int language
;
328 /* This data structure holds the information of an abbrev. */
331 unsigned int number
; /* number identifying abbrev */
332 enum dwarf_tag tag
; /* dwarf tag */
333 int has_children
; /* boolean */
334 unsigned int num_attrs
; /* number of attributes */
335 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
336 struct abbrev_info
*next
; /* next in chain */
341 enum dwarf_attribute name
;
342 enum dwarf_form form
;
345 /* This data structure holds a complete die structure. */
348 enum dwarf_tag tag
; /* Tag indicating type of die */
349 unsigned int abbrev
; /* Abbrev number */
350 unsigned int offset
; /* Offset in .debug_info section */
351 unsigned int num_attrs
; /* Number of attributes */
352 struct attribute
*attrs
; /* An array of attributes */
353 struct die_info
*next_ref
; /* Next die in ref hash table */
355 /* The dies in a compilation unit form an n-ary tree. PARENT
356 points to this die's parent; CHILD points to the first child of
357 this node; and all the children of a given node are chained
358 together via their SIBLING fields, terminated by a die whose
360 struct die_info
*child
; /* Its first child, if any. */
361 struct die_info
*sibling
; /* Its next sibling, if any. */
362 struct die_info
*parent
; /* Its parent, if any. */
364 struct type
*type
; /* Cached type information */
367 /* Attributes have a name and a value */
370 enum dwarf_attribute name
;
371 enum dwarf_form form
;
375 struct dwarf_block
*blk
;
383 struct function_range
386 CORE_ADDR lowpc
, highpc
;
388 struct function_range
*next
;
391 /* Get at parts of an attribute structure */
393 #define DW_STRING(attr) ((attr)->u.str)
394 #define DW_UNSND(attr) ((attr)->u.unsnd)
395 #define DW_BLOCK(attr) ((attr)->u.blk)
396 #define DW_SND(attr) ((attr)->u.snd)
397 #define DW_ADDR(attr) ((attr)->u.addr)
399 /* Blocks are a bunch of untyped bytes. */
406 #ifndef ATTR_ALLOC_CHUNK
407 #define ATTR_ALLOC_CHUNK 4
410 /* A hash table of die offsets for following references. */
411 #ifndef REF_HASH_SIZE
412 #define REF_HASH_SIZE 1021
415 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
417 /* Obstack for allocating temporary storage used during symbol reading. */
418 static struct obstack dwarf2_tmp_obstack
;
420 /* Allocate fields for structs, unions and enums in this size. */
421 #ifndef DW_FIELD_ALLOC_CHUNK
422 #define DW_FIELD_ALLOC_CHUNK 4
425 /* Actually data from the sections. */
426 static char *dwarf_info_buffer
;
427 static char *dwarf_abbrev_buffer
;
428 static char *dwarf_line_buffer
;
429 static char *dwarf_str_buffer
;
430 static char *dwarf_macinfo_buffer
;
431 static char *dwarf_ranges_buffer
;
432 static char *dwarf_loc_buffer
;
434 /* A zeroed version of a partial die for initialization purposes. */
435 static struct partial_die_info zeroed_partial_die
;
437 /* FIXME: decode_locdesc sets these variables to describe the location
438 to the caller. These ought to be a structure or something. If
439 none of the flags are set, the object lives at the address returned
440 by decode_locdesc. */
442 static int isreg
; /* Object lives in register.
443 decode_locdesc's return value is
444 the register number. */
446 /* We put a pointer to this structure in the read_symtab_private field
448 The complete dwarf information for an objfile is kept in the
449 psymbol_obstack, so that absolute die references can be handled.
450 Most of the information in this structure is related to an entire
451 object file and could be passed via the sym_private field of the objfile.
452 It is however conceivable that dwarf2 might not be the only type
453 of symbols read from an object file. */
457 /* Pointer to start of dwarf info buffer for the objfile. */
459 char *dwarf_info_buffer
;
461 /* Offset in dwarf_info_buffer for this compilation unit. */
463 unsigned long dwarf_info_offset
;
465 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
467 char *dwarf_abbrev_buffer
;
469 /* Size of dwarf abbreviation section for the objfile. */
471 unsigned int dwarf_abbrev_size
;
473 /* Pointer to start of dwarf line buffer for the objfile. */
475 char *dwarf_line_buffer
;
477 /* Size of dwarf_line_buffer, in bytes. */
479 unsigned int dwarf_line_size
;
481 /* Pointer to start of dwarf string buffer for the objfile. */
483 char *dwarf_str_buffer
;
485 /* Size of dwarf string section for the objfile. */
487 unsigned int dwarf_str_size
;
489 /* Pointer to start of dwarf macro buffer for the objfile. */
491 char *dwarf_macinfo_buffer
;
493 /* Size of dwarf macinfo section for the objfile. */
495 unsigned int dwarf_macinfo_size
;
497 /* Pointer to start of dwarf ranges buffer for the objfile. */
499 char *dwarf_ranges_buffer
;
501 /* Size of dwarf ranges buffer for the objfile. */
503 unsigned int dwarf_ranges_size
;
505 /* Pointer to start of dwarf locations buffer for the objfile. */
507 char *dwarf_loc_buffer
;
509 /* Size of dwarf locations buffer for the objfile. */
511 unsigned int dwarf_loc_size
;
514 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
515 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
516 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
517 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
518 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
519 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
520 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
521 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
522 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
523 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
524 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
525 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
526 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
527 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
528 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
530 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
531 but this would require a corresponding change in unpack_field_as_long
533 static int bits_per_byte
= 8;
535 /* The routines that read and process dies for a C struct or C++ class
536 pass lists of data member fields and lists of member function fields
537 in an instance of a field_info structure, as defined below. */
540 /* List of data member and baseclasses fields. */
543 struct nextfield
*next
;
550 /* Number of fields. */
553 /* Number of baseclasses. */
556 /* Set if the accesibility of one of the fields is not public. */
557 int non_public_fields
;
559 /* Member function fields array, entries are allocated in the order they
560 are encountered in the object file. */
563 struct nextfnfield
*next
;
564 struct fn_field fnfield
;
568 /* Member function fieldlist array, contains name of possibly overloaded
569 member function, number of overloaded member functions and a pointer
570 to the head of the member function field chain. */
575 struct nextfnfield
*head
;
579 /* Number of entries in the fnfieldlists array. */
583 /* Various complaints about symbol reading that don't abort the process */
586 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
588 complaint (&symfile_complaints
,
589 "statement list doesn't fit in .debug_line section");
593 dwarf2_complex_location_expr_complaint (void)
595 complaint (&symfile_complaints
, "location expression too complex");
599 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
602 complaint (&symfile_complaints
,
603 "const value length mismatch for '%s', got %d, expected %d", arg1
,
608 dwarf2_macros_too_long_complaint (void)
610 complaint (&symfile_complaints
,
611 "macro info runs off end of `.debug_macinfo' section");
615 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
617 complaint (&symfile_complaints
,
618 "macro debug info contains a malformed macro definition:\n`%s'",
623 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
625 complaint (&symfile_complaints
,
626 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
629 /* local function prototypes */
631 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
634 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
637 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
639 static char *scan_partial_symbols (char *, CORE_ADDR
*, CORE_ADDR
*,
641 const char *namespace);
643 static void add_partial_symbol (struct partial_die_info
*, struct dwarf2_cu
*,
644 const char *namespace);
646 static int pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace);
648 static char *add_partial_namespace (struct partial_die_info
*pdi
,
650 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
651 struct dwarf2_cu
*cu
,
652 const char *namespace);
654 static char *add_partial_structure (struct partial_die_info
*struct_pdi
,
656 struct dwarf2_cu
*cu
,
657 const char *namespace);
659 static char *add_partial_enumeration (struct partial_die_info
*enum_pdi
,
661 struct dwarf2_cu
*cu
,
662 const char *namespace);
664 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
667 struct dwarf2_cu
*cu
);
669 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
671 static void psymtab_to_symtab_1 (struct partial_symtab
*);
673 char *dwarf2_read_section (struct objfile
*, asection
*);
675 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
677 static void dwarf2_empty_abbrev_table (void *);
679 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
682 static char *read_partial_die (struct partial_die_info
*,
683 bfd
*, char *, struct dwarf2_cu
*);
685 static char *read_full_die (struct die_info
**, bfd
*, char *,
686 struct dwarf2_cu
*, int *);
688 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
689 bfd
*, char *, struct dwarf2_cu
*);
691 static char *read_attribute_value (struct attribute
*, unsigned,
692 bfd
*, char *, struct dwarf2_cu
*);
694 static unsigned int read_1_byte (bfd
*, char *);
696 static int read_1_signed_byte (bfd
*, char *);
698 static unsigned int read_2_bytes (bfd
*, char *);
700 static unsigned int read_4_bytes (bfd
*, char *);
702 static unsigned long read_8_bytes (bfd
*, char *);
704 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
707 static LONGEST
read_initial_length (bfd
*, char *,
708 struct comp_unit_head
*, int *bytes_read
);
710 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
713 static char *read_n_bytes (bfd
*, char *, unsigned int);
715 static char *read_string (bfd
*, char *, unsigned int *);
717 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
720 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
722 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
724 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
726 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
729 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
731 static struct die_info
*die_specification (struct die_info
*die
,
734 static void free_line_header (struct line_header
*lh
);
736 static struct line_header
*(dwarf_decode_line_header
737 (unsigned int offset
,
738 bfd
*abfd
, struct dwarf2_cu
*cu
));
740 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
743 static void dwarf2_start_subfile (char *, char *);
745 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
748 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
751 static void dwarf2_const_value_data (struct attribute
*attr
,
755 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
757 static struct type
*die_containing_type (struct die_info
*,
761 static struct type
*type_at_offset (unsigned int, struct objfile
*);
764 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
766 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
768 static char *determine_prefix_aux (struct die_info
*die
, struct dwarf2_cu
*);
770 static char *determine_prefix_aux (struct die_info
*die
, struct dwarf2_cu
*);
772 static char *typename_concat (const char *prefix
, const char *suffix
);
774 static char *class_name (struct die_info
*die
, struct dwarf2_cu
*);
776 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
778 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
780 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
782 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
784 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
786 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
788 static int dwarf2_get_pc_bounds (struct die_info
*,
789 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
791 static void get_scope_pc_bounds (struct die_info
*,
792 CORE_ADDR
*, CORE_ADDR
*,
795 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
798 static void dwarf2_attach_fields_to_type (struct field_info
*,
799 struct type
*, struct dwarf2_cu
*);
801 static void dwarf2_add_member_fn (struct field_info
*,
802 struct die_info
*, struct type
*,
805 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
806 struct type
*, struct dwarf2_cu
*);
808 static void read_structure_scope (struct die_info
*, struct dwarf2_cu
*);
810 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
812 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
814 static const char *namespace_name (struct die_info
*die
,
815 int *is_anonymous
, struct dwarf2_cu
*);
817 static void read_enumeration (struct die_info
*, struct dwarf2_cu
*);
819 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
821 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
823 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
825 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
827 static void read_tag_ptr_to_member_type (struct die_info
*,
830 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
832 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
834 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
836 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
838 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
840 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
842 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
845 struct die_info
*parent
);
847 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
850 struct die_info
*parent
);
852 static void free_die_list (struct die_info
*);
854 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
856 static void process_die (struct die_info
*, struct dwarf2_cu
*);
858 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
860 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
862 static struct die_info
*dwarf2_extension (struct die_info
*die
,
865 static char *dwarf_tag_name (unsigned int);
867 static char *dwarf_attr_name (unsigned int);
869 static char *dwarf_form_name (unsigned int);
871 static char *dwarf_stack_op_name (unsigned int);
873 static char *dwarf_bool_name (unsigned int);
875 static char *dwarf_type_encoding_name (unsigned int);
878 static char *dwarf_cfi_name (unsigned int);
880 struct die_info
*copy_die (struct die_info
*);
883 static struct die_info
*sibling_die (struct die_info
*);
885 static void dump_die (struct die_info
*);
887 static void dump_die_list (struct die_info
*);
889 static void store_in_ref_table (unsigned int, struct die_info
*);
891 static void dwarf2_empty_hash_tables (void);
893 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
896 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
898 static struct die_info
*follow_die_ref (unsigned int);
900 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
903 /* memory allocation interface */
905 static void dwarf2_free_tmp_obstack (void *);
907 static struct dwarf_block
*dwarf_alloc_block (void);
909 static struct abbrev_info
*dwarf_alloc_abbrev (void);
911 static struct die_info
*dwarf_alloc_die (void);
913 static void initialize_cu_func_list (struct dwarf2_cu
*);
915 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
918 static void dwarf_decode_macros (struct line_header
*, unsigned int,
919 char *, bfd
*, struct dwarf2_cu
*);
921 static int attr_form_is_block (struct attribute
*);
924 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
925 struct dwarf2_cu
*cu
);
927 /* Try to locate the sections we need for DWARF 2 debugging
928 information and return true if we have enough to do something. */
931 dwarf2_has_info (bfd
*abfd
)
933 dwarf_info_section
= 0;
934 dwarf_abbrev_section
= 0;
935 dwarf_line_section
= 0;
936 dwarf_str_section
= 0;
937 dwarf_macinfo_section
= 0;
938 dwarf_frame_section
= 0;
939 dwarf_eh_frame_section
= 0;
940 dwarf_ranges_section
= 0;
941 dwarf_loc_section
= 0;
943 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
944 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
947 /* This function is mapped across the sections and remembers the
948 offset and size of each of the debugging sections we are interested
952 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
954 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
956 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
957 dwarf_info_section
= sectp
;
959 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
961 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
962 dwarf_abbrev_section
= sectp
;
964 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
966 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
967 dwarf_line_section
= sectp
;
969 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
971 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
972 dwarf_pubnames_section
= sectp
;
974 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
976 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
977 dwarf_aranges_section
= sectp
;
979 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
981 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
982 dwarf_loc_section
= sectp
;
984 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
986 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
987 dwarf_macinfo_section
= sectp
;
989 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
991 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
992 dwarf_str_section
= sectp
;
994 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
996 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
997 dwarf_frame_section
= sectp
;
999 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1001 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1002 if (aflag
& SEC_HAS_CONTENTS
)
1004 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
1005 dwarf_eh_frame_section
= sectp
;
1008 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1010 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
1011 dwarf_ranges_section
= sectp
;
1015 /* Build a partial symbol table. */
1018 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1021 /* We definitely need the .debug_info and .debug_abbrev sections */
1023 dwarf_info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1024 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1026 if (dwarf_line_section
)
1027 dwarf_line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1029 dwarf_line_buffer
= NULL
;
1031 if (dwarf_str_section
)
1032 dwarf_str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1034 dwarf_str_buffer
= NULL
;
1036 if (dwarf_macinfo_section
)
1037 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1038 dwarf_macinfo_section
);
1040 dwarf_macinfo_buffer
= NULL
;
1042 if (dwarf_ranges_section
)
1043 dwarf_ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1045 dwarf_ranges_buffer
= NULL
;
1047 if (dwarf_loc_section
)
1048 dwarf_loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1050 dwarf_loc_buffer
= NULL
;
1053 || (objfile
->global_psymbols
.size
== 0
1054 && objfile
->static_psymbols
.size
== 0))
1056 init_psymbol_list (objfile
, 1024);
1060 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1062 /* Things are significantly easier if we have .debug_aranges and
1063 .debug_pubnames sections */
1065 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1069 /* only test this case for now */
1071 /* In this case we have to work a bit harder */
1072 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1077 /* Build the partial symbol table from the information in the
1078 .debug_pubnames and .debug_aranges sections. */
1081 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1083 bfd
*abfd
= objfile
->obfd
;
1084 char *aranges_buffer
, *pubnames_buffer
;
1085 char *aranges_ptr
, *pubnames_ptr
;
1086 unsigned int entry_length
, version
, info_offset
, info_size
;
1088 pubnames_buffer
= dwarf2_read_section (objfile
,
1089 dwarf_pubnames_section
);
1090 pubnames_ptr
= pubnames_buffer
;
1091 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1093 struct comp_unit_head cu_header
;
1096 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1098 pubnames_ptr
+= bytes_read
;
1099 version
= read_1_byte (abfd
, pubnames_ptr
);
1101 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1103 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1107 aranges_buffer
= dwarf2_read_section (objfile
,
1108 dwarf_aranges_section
);
1113 /* Read in the comp unit header information from the debug_info at
1117 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1118 char *info_ptr
, bfd
*abfd
)
1122 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1124 info_ptr
+= bytes_read
;
1125 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1127 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1129 info_ptr
+= bytes_read
;
1130 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1132 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1133 if (signed_addr
< 0)
1134 internal_error (__FILE__
, __LINE__
,
1135 "read_comp_unit_head: dwarf from non elf file");
1136 cu_header
->signed_addr_p
= signed_addr
;
1140 /* Build the partial symbol table by doing a quick pass through the
1141 .debug_info and .debug_abbrev sections. */
1144 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1146 /* Instead of reading this into a big buffer, we should probably use
1147 mmap() on architectures that support it. (FIXME) */
1148 bfd
*abfd
= objfile
->obfd
;
1149 char *info_ptr
, *abbrev_ptr
;
1150 char *beg_of_comp_unit
;
1151 struct partial_die_info comp_unit_die
;
1152 struct partial_symtab
*pst
;
1153 struct cleanup
*back_to
;
1154 CORE_ADDR lowpc
, highpc
, baseaddr
;
1156 info_ptr
= dwarf_info_buffer
;
1157 abbrev_ptr
= dwarf_abbrev_buffer
;
1159 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1160 the partial symbol scan, like attribute values.
1162 We could reduce our peak memory consumption during partial symbol
1163 table construction by freeing stuff from this obstack more often
1164 --- say, after processing each compilation unit, or each die ---
1165 but it turns out that this saves almost nothing. For an
1166 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1167 on dwarf2_tmp_obstack. Some investigation showed:
1169 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1170 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1171 all fixed-length values not requiring dynamic allocation.
1173 2) 30% of the attributes used the form DW_FORM_string. For
1174 DW_FORM_string, read_attribute simply hands back a pointer to
1175 the null-terminated string in dwarf_info_buffer, so no dynamic
1176 allocation is needed there either.
1178 3) The remaining 1% of the attributes all used DW_FORM_block1.
1179 75% of those were DW_AT_frame_base location lists for
1180 functions; the rest were DW_AT_location attributes, probably
1181 for the global variables.
1183 Anyway, what this all means is that the memory the dwarf2
1184 reader uses as temporary space reading partial symbols is about
1185 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1187 obstack_init (&dwarf2_tmp_obstack
);
1188 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1190 /* Since the objects we're extracting from dwarf_info_buffer vary in
1191 length, only the individual functions to extract them (like
1192 read_comp_unit_head and read_partial_die) can really know whether
1193 the buffer is large enough to hold another complete object.
1195 At the moment, they don't actually check that. If
1196 dwarf_info_buffer holds just one extra byte after the last
1197 compilation unit's dies, then read_comp_unit_head will happily
1198 read off the end of the buffer. read_partial_die is similarly
1199 casual. Those functions should be fixed.
1201 For this loop condition, simply checking whether there's any data
1202 left at all should be sufficient. */
1203 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1205 struct dwarf2_cu cu
;
1206 beg_of_comp_unit
= info_ptr
;
1208 cu
.objfile
= objfile
;
1209 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1211 if (cu
.header
.version
!= 2)
1213 error ("Dwarf Error: wrong version in compilation unit header (is %d, should be %d) [in module %s]", cu
.header
.version
, 2, bfd_get_filename (abfd
));
1216 if (cu
.header
.abbrev_offset
>= dwarf_abbrev_size
)
1218 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1219 (long) cu
.header
.abbrev_offset
,
1220 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1221 bfd_get_filename (abfd
));
1224 if (beg_of_comp_unit
+ cu
.header
.length
+ cu
.header
.initial_length_size
1225 > dwarf_info_buffer
+ dwarf_info_size
)
1227 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1228 (long) cu
.header
.length
,
1229 (long) (beg_of_comp_unit
- dwarf_info_buffer
),
1230 bfd_get_filename (abfd
));
1233 /* Complete the cu_header */
1234 cu
.header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1235 cu
.header
.first_die_ptr
= info_ptr
;
1236 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1238 cu
.list_in_scope
= &file_symbols
;
1240 /* Read the abbrevs for this compilation unit into a table */
1241 dwarf2_read_abbrevs (abfd
, &cu
);
1242 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1244 /* Read the compilation unit die */
1245 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1248 /* Set the language we're debugging */
1249 set_cu_language (comp_unit_die
.language
, &cu
);
1251 /* Allocate a new partial symbol table structure */
1252 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1253 comp_unit_die
.name
? comp_unit_die
.name
: "",
1254 comp_unit_die
.lowpc
,
1255 objfile
->global_psymbols
.next
,
1256 objfile
->static_psymbols
.next
);
1258 pst
->read_symtab_private
= (char *)
1259 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1260 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1261 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1262 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1263 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1264 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1265 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1266 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1267 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1268 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1269 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1270 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1271 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1272 DWARF_LOC_BUFFER (pst
) = dwarf_loc_buffer
;
1273 DWARF_LOC_SIZE (pst
) = dwarf_loc_size
;
1274 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1276 /* Store the function that reads in the rest of the symbol table */
1277 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1279 /* Check if comp unit has_children.
1280 If so, read the rest of the partial symbols from this comp unit.
1281 If not, there's no more debug_info for this comp unit. */
1282 if (comp_unit_die
.has_children
)
1284 lowpc
= ((CORE_ADDR
) -1);
1285 highpc
= ((CORE_ADDR
) 0);
1287 info_ptr
= scan_partial_symbols (info_ptr
, &lowpc
, &highpc
,
1290 /* If we didn't find a lowpc, set it to highpc to avoid
1291 complaints from `maint check'. */
1292 if (lowpc
== ((CORE_ADDR
) -1))
1295 /* If the compilation unit didn't have an explicit address range,
1296 then use the information extracted from its child dies. */
1297 if (! comp_unit_die
.has_pc_info
)
1299 comp_unit_die
.lowpc
= lowpc
;
1300 comp_unit_die
.highpc
= highpc
;
1303 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1304 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1306 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1307 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1308 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1309 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1310 sort_pst_symbols (pst
);
1312 /* If there is already a psymtab or symtab for a file of this
1313 name, remove it. (If there is a symtab, more drastic things
1314 also happen.) This happens in VxWorks. */
1315 free_named_symtabs (pst
->filename
);
1317 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1318 + cu
.header
.initial_length_size
;
1320 do_cleanups (back_to
);
1323 /* Read in all interesting dies to the end of the compilation unit or
1324 to the end of the current namespace. NAMESPACE is NULL if we
1325 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1326 it's the name of the current namespace. In particular, it's the
1327 empty string if we're currently in the global namespace but have
1328 previously encountered a DW_TAG_namespace. */
1331 scan_partial_symbols (char *info_ptr
, CORE_ADDR
*lowpc
,
1332 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
1333 const char *namespace)
1335 struct objfile
*objfile
= cu
->objfile
;
1336 bfd
*abfd
= objfile
->obfd
;
1337 struct partial_die_info pdi
;
1339 /* Now, march along the PDI's, descending into ones which have
1340 interesting children but skipping the children of the other ones,
1341 until we reach the end of the compilation unit. */
1345 /* This flag tells whether or not info_ptr has gotten updated
1347 int info_ptr_updated
= 0;
1349 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1351 /* Anonymous namespaces have no name but have interesting
1352 children, so we need to look at them. Ditto for anonymous
1355 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
1356 || pdi
.tag
== DW_TAG_enumeration_type
)
1360 case DW_TAG_subprogram
:
1361 if (pdi
.has_pc_info
)
1363 if (pdi
.lowpc
< *lowpc
)
1367 if (pdi
.highpc
> *highpc
)
1369 *highpc
= pdi
.highpc
;
1371 if (!pdi
.is_declaration
)
1373 add_partial_symbol (&pdi
, cu
, namespace);
1377 case DW_TAG_variable
:
1378 case DW_TAG_typedef
:
1379 case DW_TAG_union_type
:
1380 if (!pdi
.is_declaration
)
1382 add_partial_symbol (&pdi
, cu
, namespace);
1385 case DW_TAG_class_type
:
1386 case DW_TAG_structure_type
:
1387 if (!pdi
.is_declaration
)
1389 info_ptr
= add_partial_structure (&pdi
, info_ptr
, cu
,
1391 info_ptr_updated
= 1;
1394 case DW_TAG_enumeration_type
:
1395 if (!pdi
.is_declaration
)
1397 info_ptr
= add_partial_enumeration (&pdi
, info_ptr
, cu
,
1399 info_ptr_updated
= 1;
1402 case DW_TAG_base_type
:
1403 case DW_TAG_subrange_type
:
1404 /* File scope base type definitions are added to the partial
1406 add_partial_symbol (&pdi
, cu
, namespace);
1408 case DW_TAG_namespace
:
1409 /* We've hit a DW_TAG_namespace entry, so we know this
1410 file has been compiled using a compiler that
1411 generates them; update NAMESPACE to reflect that. */
1412 if (namespace == NULL
)
1414 info_ptr
= add_partial_namespace (&pdi
, info_ptr
, lowpc
, highpc
,
1416 info_ptr_updated
= 1;
1426 /* If the die has a sibling, skip to the sibling, unless another
1427 function has already updated info_ptr for us. */
1429 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1430 or not we want to update this depends on enough stuff (not
1431 only pdi.tag but also whether or not pdi.name is NULL) that
1432 this seems like the easiest way to handle the issue. */
1434 if (!info_ptr_updated
)
1435 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1442 add_partial_symbol (struct partial_die_info
*pdi
,
1443 struct dwarf2_cu
*cu
, const char *namespace)
1445 struct objfile
*objfile
= cu
->objfile
;
1447 char *actual_name
= pdi
->name
;
1448 const struct partial_symbol
*psym
= NULL
;
1451 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1453 /* If we're not in the global namespace and if the namespace name
1454 isn't encoded in a mangled actual_name, add it. */
1456 if (pdi_needs_namespace (pdi
->tag
, namespace))
1458 actual_name
= alloca (strlen (pdi
->name
) + 2 + strlen (namespace) + 1);
1459 strcpy (actual_name
, namespace);
1460 strcat (actual_name
, "::");
1461 strcat (actual_name
, pdi
->name
);
1466 case DW_TAG_subprogram
:
1467 if (pdi
->is_external
)
1469 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1470 mst_text, objfile); */
1471 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1472 VAR_DOMAIN
, LOC_BLOCK
,
1473 &objfile
->global_psymbols
,
1474 0, pdi
->lowpc
+ baseaddr
,
1475 cu
->language
, objfile
);
1479 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1480 mst_file_text, objfile); */
1481 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1482 VAR_DOMAIN
, LOC_BLOCK
,
1483 &objfile
->static_psymbols
,
1484 0, pdi
->lowpc
+ baseaddr
,
1485 cu
->language
, objfile
);
1488 case DW_TAG_variable
:
1489 if (pdi
->is_external
)
1492 Don't enter into the minimal symbol tables as there is
1493 a minimal symbol table entry from the ELF symbols already.
1494 Enter into partial symbol table if it has a location
1495 descriptor or a type.
1496 If the location descriptor is missing, new_symbol will create
1497 a LOC_UNRESOLVED symbol, the address of the variable will then
1498 be determined from the minimal symbol table whenever the variable
1500 The address for the partial symbol table entry is not
1501 used by GDB, but it comes in handy for debugging partial symbol
1505 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1506 if (pdi
->locdesc
|| pdi
->has_type
)
1507 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1508 VAR_DOMAIN
, LOC_STATIC
,
1509 &objfile
->global_psymbols
,
1511 cu
->language
, objfile
);
1515 /* Static Variable. Skip symbols without location descriptors. */
1516 if (pdi
->locdesc
== NULL
)
1518 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1519 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1520 mst_file_data, objfile); */
1521 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1522 VAR_DOMAIN
, LOC_STATIC
,
1523 &objfile
->static_psymbols
,
1525 cu
->language
, objfile
);
1528 case DW_TAG_typedef
:
1529 case DW_TAG_base_type
:
1530 case DW_TAG_subrange_type
:
1531 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1532 VAR_DOMAIN
, LOC_TYPEDEF
,
1533 &objfile
->static_psymbols
,
1534 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1536 case DW_TAG_class_type
:
1537 case DW_TAG_structure_type
:
1538 case DW_TAG_union_type
:
1539 case DW_TAG_enumeration_type
:
1540 /* Skip aggregate types without children, these are external
1542 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1543 static vs. global. */
1544 if (pdi
->has_children
== 0)
1546 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1547 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1548 cu
->language
== language_cplus
1549 ? &objfile
->global_psymbols
1550 : &objfile
->static_psymbols
,
1551 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1553 if (cu
->language
== language_cplus
)
1555 /* For C++, these implicitly act as typedefs as well. */
1556 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1557 VAR_DOMAIN
, LOC_TYPEDEF
,
1558 &objfile
->global_psymbols
,
1559 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1562 case DW_TAG_enumerator
:
1563 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1564 VAR_DOMAIN
, LOC_CONST
,
1565 cu
->language
== language_cplus
1566 ? &objfile
->static_psymbols
1567 : &objfile
->global_psymbols
,
1568 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1574 /* Check to see if we should scan the name for possible namespace
1575 info. Only do this if this is C++, if we don't have namespace
1576 debugging info in the file, if the psym is of an appropriate type
1577 (otherwise we'll have psym == NULL), and if we actually had a
1578 mangled name to begin with. */
1580 if (cu
->language
== language_cplus
1581 && namespace == NULL
1583 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
1584 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
1588 /* Determine whether a die of type TAG living in the C++ namespace
1589 NAMESPACE needs to have the name of the namespace prepended to the
1590 name listed in the die. */
1593 pdi_needs_namespace (enum dwarf_tag tag
, const char *namespace)
1595 if (namespace == NULL
|| namespace[0] == '\0')
1600 case DW_TAG_typedef
:
1601 case DW_TAG_class_type
:
1602 case DW_TAG_structure_type
:
1603 case DW_TAG_union_type
:
1604 case DW_TAG_enumeration_type
:
1605 case DW_TAG_enumerator
:
1612 /* Read a partial die corresponding to a namespace; also, add a symbol
1613 corresponding to that namespace to the symbol table. NAMESPACE is
1614 the name of the enclosing namespace. */
1617 add_partial_namespace (struct partial_die_info
*pdi
, char *info_ptr
,
1618 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1619 struct dwarf2_cu
*cu
, const char *namespace)
1621 struct objfile
*objfile
= cu
->objfile
;
1622 const char *new_name
= pdi
->name
;
1625 /* Calculate the full name of the namespace that we just entered. */
1627 if (new_name
== NULL
)
1628 new_name
= "(anonymous namespace)";
1629 full_name
= alloca (strlen (namespace) + 2 + strlen (new_name
) + 1);
1630 strcpy (full_name
, namespace);
1631 if (*namespace != '\0')
1632 strcat (full_name
, "::");
1633 strcat (full_name
, new_name
);
1635 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1636 to add_partial_symbol, because we don't have a way to pass in the
1637 full name to that function; that might be a flaw in
1638 add_partial_symbol's interface. */
1640 add_psymbol_to_list (full_name
, strlen (full_name
),
1641 VAR_DOMAIN
, LOC_TYPEDEF
,
1642 &objfile
->global_psymbols
,
1643 0, 0, cu
->language
, objfile
);
1645 /* Now scan partial symbols in that namespace. */
1647 if (pdi
->has_children
)
1648 info_ptr
= scan_partial_symbols (info_ptr
, lowpc
, highpc
, cu
, full_name
);
1653 /* Read a partial die corresponding to a class or structure. */
1656 add_partial_structure (struct partial_die_info
*struct_pdi
, char *info_ptr
,
1657 struct dwarf2_cu
*cu
,
1658 const char *namespace)
1660 bfd
*abfd
= cu
->objfile
->obfd
;
1661 char *actual_class_name
= NULL
;
1663 if (cu
->language
== language_cplus
1664 && namespace == NULL
1665 && struct_pdi
->name
!= NULL
1666 && struct_pdi
->has_children
)
1668 /* We don't have namespace debugging information, so see if we
1669 can figure out if this structure lives in a namespace. Look
1670 for a member function; its demangled name will contain
1671 namespace info, if there is any. */
1673 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1674 what template types look like, because the demangler
1675 frequently doesn't give the same name as the debug info. We
1676 could fix this by only using the demangled name to get the
1677 prefix (but see comment in read_structure_scope). */
1679 char *next_child
= info_ptr
;
1683 struct partial_die_info child_pdi
;
1685 next_child
= read_partial_die (&child_pdi
, abfd
, next_child
,
1689 if (child_pdi
.tag
== DW_TAG_subprogram
)
1691 actual_class_name
= class_name_from_physname (child_pdi
.name
);
1692 if (actual_class_name
!= NULL
)
1693 struct_pdi
->name
= actual_class_name
;
1698 next_child
= locate_pdi_sibling (&child_pdi
, next_child
,
1704 add_partial_symbol (struct_pdi
, cu
, namespace);
1705 xfree (actual_class_name
);
1707 return locate_pdi_sibling (struct_pdi
, info_ptr
, abfd
, cu
);
1710 /* Read a partial die corresponding to an enumeration type. */
1713 add_partial_enumeration (struct partial_die_info
*enum_pdi
, char *info_ptr
,
1714 struct dwarf2_cu
*cu
, const char *namespace)
1716 struct objfile
*objfile
= cu
->objfile
;
1717 bfd
*abfd
= objfile
->obfd
;
1718 struct partial_die_info pdi
;
1720 if (enum_pdi
->name
!= NULL
)
1721 add_partial_symbol (enum_pdi
, cu
, namespace);
1725 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1728 if (pdi
.tag
!= DW_TAG_enumerator
|| pdi
.name
== NULL
)
1729 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
1731 add_partial_symbol (&pdi
, cu
, namespace);
1737 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1741 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
1742 bfd
*abfd
, struct dwarf2_cu
*cu
)
1744 /* Do we know the sibling already? */
1746 if (orig_pdi
->sibling
)
1747 return orig_pdi
->sibling
;
1749 /* Are there any children to deal with? */
1751 if (!orig_pdi
->has_children
)
1754 /* Okay, we don't know the sibling, but we have children that we
1755 want to skip. So read children until we run into one without a
1756 tag; return whatever follows it. */
1760 struct partial_die_info pdi
;
1762 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu
);
1767 info_ptr
= locate_pdi_sibling (&pdi
, info_ptr
, abfd
, cu
);
1771 /* Expand this partial symbol table into a full symbol table. */
1774 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1776 /* FIXME: This is barely more than a stub. */
1781 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1787 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1788 gdb_flush (gdb_stdout
);
1791 psymtab_to_symtab_1 (pst
);
1793 /* Finish up the debug error message. */
1795 printf_filtered ("done.\n");
1801 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1803 struct objfile
*objfile
= pst
->objfile
;
1804 bfd
*abfd
= objfile
->obfd
;
1805 struct dwarf2_cu cu
;
1806 struct die_info
*dies
;
1807 unsigned long offset
;
1808 CORE_ADDR lowpc
, highpc
;
1809 struct die_info
*child_die
;
1811 struct symtab
*symtab
;
1812 struct cleanup
*back_to
;
1813 struct attribute
*attr
;
1816 /* Set local variables from the partial symbol table info. */
1817 offset
= DWARF_INFO_OFFSET (pst
);
1818 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1819 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1820 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1821 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1822 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1823 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1824 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1825 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1826 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1827 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1828 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1829 dwarf_loc_buffer
= DWARF_LOC_BUFFER (pst
);
1830 dwarf_loc_size
= DWARF_LOC_SIZE (pst
);
1831 info_ptr
= dwarf_info_buffer
+ offset
;
1832 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1834 /* We're in the global namespace. */
1835 processing_current_prefix
= "";
1837 obstack_init (&dwarf2_tmp_obstack
);
1838 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1841 make_cleanup (really_free_pendings
, NULL
);
1843 cu
.objfile
= objfile
;
1845 /* read in the comp_unit header */
1846 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1848 /* Read the abbrevs for this compilation unit */
1849 dwarf2_read_abbrevs (abfd
, &cu
);
1850 make_cleanup (dwarf2_empty_abbrev_table
, cu
.header
.dwarf2_abbrevs
);
1852 cu
.header
.offset
= offset
;
1854 cu
.list_in_scope
= &file_symbols
;
1856 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
1858 make_cleanup_free_die_list (dies
);
1860 /* Find the base address of the compilation unit for range lists and
1861 location lists. It will normally be specified by DW_AT_low_pc.
1862 In DWARF-3 draft 4, the base address could be overridden by
1863 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1864 compilation units with discontinuous ranges. */
1866 cu
.header
.base_known
= 0;
1867 cu
.header
.base_address
= 0;
1869 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
1872 cu
.header
.base_address
= DW_ADDR (attr
);
1873 cu
.header
.base_known
= 1;
1877 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
1880 cu
.header
.base_address
= DW_ADDR (attr
);
1881 cu
.header
.base_known
= 1;
1885 /* Do line number decoding in read_file_scope () */
1886 process_die (dies
, &cu
);
1888 /* Some compilers don't define a DW_AT_high_pc attribute for the
1889 compilation unit. If the DW_AT_high_pc is missing, synthesize
1890 it, by scanning the DIE's below the compilation unit. */
1891 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
1893 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1895 /* Set symtab language to language from DW_AT_language.
1896 If the compilation is from a C file generated by language preprocessors,
1897 do not set the language if it was already deduced by start_subfile. */
1899 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
1901 symtab
->language
= cu
.language
;
1903 pst
->symtab
= symtab
;
1906 do_cleanups (back_to
);
1909 /* Process a die and its children. */
1912 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
1916 case DW_TAG_padding
:
1918 case DW_TAG_compile_unit
:
1919 read_file_scope (die
, cu
);
1921 case DW_TAG_subprogram
:
1922 read_subroutine_type (die
, cu
);
1923 read_func_scope (die
, cu
);
1925 case DW_TAG_inlined_subroutine
:
1926 /* FIXME: These are ignored for now.
1927 They could be used to set breakpoints on all inlined instances
1928 of a function and make GDB `next' properly over inlined functions. */
1930 case DW_TAG_lexical_block
:
1931 case DW_TAG_try_block
:
1932 case DW_TAG_catch_block
:
1933 read_lexical_block_scope (die
, cu
);
1935 case DW_TAG_class_type
:
1936 case DW_TAG_structure_type
:
1937 case DW_TAG_union_type
:
1938 read_structure_scope (die
, cu
);
1940 case DW_TAG_enumeration_type
:
1941 read_enumeration (die
, cu
);
1943 case DW_TAG_subroutine_type
:
1944 read_subroutine_type (die
, cu
);
1946 case DW_TAG_array_type
:
1947 read_array_type (die
, cu
);
1949 case DW_TAG_pointer_type
:
1950 read_tag_pointer_type (die
, cu
);
1952 case DW_TAG_ptr_to_member_type
:
1953 read_tag_ptr_to_member_type (die
, cu
);
1955 case DW_TAG_reference_type
:
1956 read_tag_reference_type (die
, cu
);
1958 case DW_TAG_string_type
:
1959 read_tag_string_type (die
, cu
);
1961 case DW_TAG_base_type
:
1962 read_base_type (die
, cu
);
1963 if (dwarf2_attr (die
, DW_AT_name
, cu
))
1965 /* Add a typedef symbol for the base type definition. */
1966 new_symbol (die
, die
->type
, cu
);
1969 case DW_TAG_subrange_type
:
1970 read_subrange_type (die
, cu
);
1971 if (dwarf2_attr (die
, DW_AT_name
, cu
))
1973 /* Add a typedef symbol for the base type definition. */
1974 new_symbol (die
, die
->type
, cu
);
1977 case DW_TAG_common_block
:
1978 read_common_block (die
, cu
);
1980 case DW_TAG_common_inclusion
:
1982 case DW_TAG_namespace
:
1983 processing_has_namespace_info
= 1;
1984 read_namespace (die
, cu
);
1986 case DW_TAG_imported_declaration
:
1987 case DW_TAG_imported_module
:
1988 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1989 information contained in these. DW_TAG_imported_declaration
1990 dies shouldn't have children; DW_TAG_imported_module dies
1991 shouldn't in the C++ case, but conceivably could in the
1992 Fortran case, so we'll have to replace this gdb_assert if
1993 Fortran compilers start generating that info. */
1994 processing_has_namespace_info
= 1;
1995 gdb_assert (die
->child
== NULL
);
1998 new_symbol (die
, NULL
, cu
);
2004 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2006 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2010 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2012 struct objfile
*objfile
= cu
->objfile
;
2013 struct comp_unit_head
*cu_header
= &cu
->header
;
2014 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2015 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2016 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2017 struct attribute
*attr
;
2018 char *name
= "<unknown>";
2019 char *comp_dir
= NULL
;
2020 struct die_info
*child_die
;
2021 bfd
*abfd
= objfile
->obfd
;
2022 struct line_header
*line_header
= 0;
2025 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2027 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2029 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2030 from finish_block. */
2031 if (lowpc
== ((CORE_ADDR
) -1))
2036 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2039 name
= DW_STRING (attr
);
2041 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2044 comp_dir
= DW_STRING (attr
);
2047 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2048 directory, get rid of it. */
2049 char *cp
= strchr (comp_dir
, ':');
2051 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2056 if (objfile
->ei
.entry_point
>= lowpc
&&
2057 objfile
->ei
.entry_point
< highpc
)
2059 objfile
->ei
.deprecated_entry_file_lowpc
= lowpc
;
2060 objfile
->ei
.deprecated_entry_file_highpc
= highpc
;
2063 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2066 set_cu_language (DW_UNSND (attr
), cu
);
2069 /* We assume that we're processing GCC output. */
2070 processing_gcc_compilation
= 2;
2072 /* FIXME:Do something here. */
2073 if (dip
->at_producer
!= NULL
)
2075 handle_producer (dip
->at_producer
);
2079 /* The compilation unit may be in a different language or objfile,
2080 zero out all remembered fundamental types. */
2081 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2083 start_symtab (name
, comp_dir
, lowpc
);
2084 record_debugformat ("DWARF 2");
2086 initialize_cu_func_list (cu
);
2088 /* Process all dies in compilation unit. */
2089 if (die
->child
!= NULL
)
2091 child_die
= die
->child
;
2092 while (child_die
&& child_die
->tag
)
2094 process_die (child_die
, cu
);
2095 child_die
= sibling_die (child_die
);
2099 /* Decode line number information if present. */
2100 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2103 unsigned int line_offset
= DW_UNSND (attr
);
2104 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2107 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2108 (void *) line_header
);
2109 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
);
2113 /* Decode macro information, if present. Dwarf 2 macro information
2114 refers to information in the line number info statement program
2115 header, so we can only read it if we've read the header
2117 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2118 if (attr
&& line_header
)
2120 unsigned int macro_offset
= DW_UNSND (attr
);
2121 dwarf_decode_macros (line_header
, macro_offset
,
2122 comp_dir
, abfd
, cu
);
2124 do_cleanups (back_to
);
2128 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2129 struct dwarf2_cu
*cu
)
2131 struct function_range
*thisfn
;
2133 thisfn
= (struct function_range
*)
2134 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
2135 thisfn
->name
= name
;
2136 thisfn
->lowpc
= lowpc
;
2137 thisfn
->highpc
= highpc
;
2138 thisfn
->seen_line
= 0;
2139 thisfn
->next
= NULL
;
2141 if (cu
->last_fn
== NULL
)
2142 cu
->first_fn
= thisfn
;
2144 cu
->last_fn
->next
= thisfn
;
2146 cu
->last_fn
= thisfn
;
2150 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2152 struct objfile
*objfile
= cu
->objfile
;
2153 struct context_stack
*new;
2156 struct die_info
*child_die
;
2157 struct attribute
*attr
;
2159 const char *previous_prefix
= processing_current_prefix
;
2160 struct cleanup
*back_to
= NULL
;
2163 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2165 name
= dwarf2_linkage_name (die
, cu
);
2167 /* Ignore functions with missing or empty names and functions with
2168 missing or invalid low and high pc attributes. */
2169 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2172 if (cu_language
== language_cplus
)
2174 struct die_info
*spec_die
= die_specification (die
);
2176 /* NOTE: carlton/2004-01-23: We have to be careful in the
2177 presence of DW_AT_specification. For example, with GCC
2182 // Definition of N::foo.
2186 then we'll have a tree of DIEs like this:
2188 1: DW_TAG_compile_unit
2189 2: DW_TAG_namespace // N
2190 3: DW_TAG_subprogram // declaration of N::foo
2191 4: DW_TAG_subprogram // definition of N::foo
2192 DW_AT_specification // refers to die #3
2194 Thus, when processing die #4, we have to pretend that
2195 we're in the context of its DW_AT_specification, namely
2196 the contex of die #3. */
2198 if (spec_die
!= NULL
)
2200 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2201 processing_current_prefix
= specification_prefix
;
2202 back_to
= make_cleanup (xfree
, specification_prefix
);
2209 /* Record the function range for dwarf_decode_lines. */
2210 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2212 if (objfile
->ei
.entry_point
>= lowpc
&&
2213 objfile
->ei
.entry_point
< highpc
)
2215 objfile
->ei
.entry_func_lowpc
= lowpc
;
2216 objfile
->ei
.entry_func_highpc
= highpc
;
2219 new = push_context (0, lowpc
);
2220 new->name
= new_symbol (die
, die
->type
, cu
);
2222 /* If there is a location expression for DW_AT_frame_base, record
2224 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2226 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2227 expression is being recorded directly in the function's symbol
2228 and not in a separate frame-base object. I guess this hack is
2229 to avoid adding some sort of frame-base adjunct/annex to the
2230 function's symbol :-(. The problem with doing this is that it
2231 results in a function symbol with a location expression that
2232 has nothing to do with the location of the function, ouch! The
2233 relationship should be: a function's symbol has-a frame base; a
2234 frame-base has-a location expression. */
2235 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2237 cu
->list_in_scope
= &local_symbols
;
2239 if (die
->child
!= NULL
)
2241 child_die
= die
->child
;
2242 while (child_die
&& child_die
->tag
)
2244 process_die (child_die
, cu
);
2245 child_die
= sibling_die (child_die
);
2249 new = pop_context ();
2250 /* Make a block for the local symbols within. */
2251 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2252 lowpc
, highpc
, objfile
);
2254 /* In C++, we can have functions nested inside functions (e.g., when
2255 a function declares a class that has methods). This means that
2256 when we finish processing a function scope, we may need to go
2257 back to building a containing block's symbol lists. */
2258 local_symbols
= new->locals
;
2259 param_symbols
= new->params
;
2261 /* If we've finished processing a top-level function, subsequent
2262 symbols go in the file symbol list. */
2263 if (outermost_context_p ())
2264 cu
->list_in_scope
= &file_symbols
;
2266 processing_current_prefix
= previous_prefix
;
2267 if (back_to
!= NULL
)
2268 do_cleanups (back_to
);
2271 /* Process all the DIES contained within a lexical block scope. Start
2272 a new scope, process the dies, and then close the scope. */
2275 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2277 struct objfile
*objfile
= cu
->objfile
;
2278 struct context_stack
*new;
2279 CORE_ADDR lowpc
, highpc
;
2280 struct die_info
*child_die
;
2283 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2285 /* Ignore blocks with missing or invalid low and high pc attributes. */
2286 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2287 as multiple lexical blocks? Handling children in a sane way would
2288 be nasty. Might be easier to properly extend generic blocks to
2290 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2295 push_context (0, lowpc
);
2296 if (die
->child
!= NULL
)
2298 child_die
= die
->child
;
2299 while (child_die
&& child_die
->tag
)
2301 process_die (child_die
, cu
);
2302 child_die
= sibling_die (child_die
);
2305 new = pop_context ();
2307 if (local_symbols
!= NULL
)
2309 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2312 local_symbols
= new->locals
;
2315 /* Get low and high pc attributes from a die. Return 1 if the attributes
2316 are present and valid, otherwise, return 0. Return -1 if the range is
2317 discontinuous, i.e. derived from DW_AT_ranges information. */
2319 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2320 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2322 struct objfile
*objfile
= cu
->objfile
;
2323 struct comp_unit_head
*cu_header
= &cu
->header
;
2324 struct attribute
*attr
;
2325 bfd
*obfd
= objfile
->obfd
;
2330 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2333 high
= DW_ADDR (attr
);
2334 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2336 low
= DW_ADDR (attr
);
2338 /* Found high w/o low attribute. */
2341 /* Found consecutive range of addresses. */
2346 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2349 unsigned int addr_size
= cu_header
->addr_size
;
2350 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2351 /* Value of the DW_AT_ranges attribute is the offset in the
2352 .debug_ranges section. */
2353 unsigned int offset
= DW_UNSND (attr
);
2354 /* Base address selection entry. */
2362 found_base
= cu_header
->base_known
;
2363 base
= cu_header
->base_address
;
2365 if (offset
>= dwarf_ranges_size
)
2367 complaint (&symfile_complaints
,
2368 "Offset %d out of bounds for DW_AT_ranges attribute",
2372 buffer
= dwarf_ranges_buffer
+ offset
;
2374 /* Read in the largest possible address. */
2375 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2376 if ((marker
& mask
) == mask
)
2378 /* If we found the largest possible address, then
2379 read the base address. */
2380 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2381 buffer
+= 2 * addr_size
;
2382 offset
+= 2 * addr_size
;
2390 CORE_ADDR range_beginning
, range_end
;
2392 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2393 buffer
+= addr_size
;
2394 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2395 buffer
+= addr_size
;
2396 offset
+= 2 * addr_size
;
2398 /* An end of list marker is a pair of zero addresses. */
2399 if (range_beginning
== 0 && range_end
== 0)
2400 /* Found the end of list entry. */
2403 /* Each base address selection entry is a pair of 2 values.
2404 The first is the largest possible address, the second is
2405 the base address. Check for a base address here. */
2406 if ((range_beginning
& mask
) == mask
)
2408 /* If we found the largest possible address, then
2409 read the base address. */
2410 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2417 /* We have no valid base address for the ranges
2419 complaint (&symfile_complaints
,
2420 "Invalid .debug_ranges data (no base address)");
2424 range_beginning
+= base
;
2427 /* FIXME: This is recording everything as a low-high
2428 segment of consecutive addresses. We should have a
2429 data structure for discontiguous block ranges
2433 low
= range_beginning
;
2439 if (range_beginning
< low
)
2440 low
= range_beginning
;
2441 if (range_end
> high
)
2447 /* If the first entry is an end-of-list marker, the range
2448 describes an empty scope, i.e. no instructions. */
2458 /* When using the GNU linker, .gnu.linkonce. sections are used to
2459 eliminate duplicate copies of functions and vtables and such.
2460 The linker will arbitrarily choose one and discard the others.
2461 The AT_*_pc values for such functions refer to local labels in
2462 these sections. If the section from that file was discarded, the
2463 labels are not in the output, so the relocs get a value of 0.
2464 If this is a discarded function, mark the pc bounds as invalid,
2465 so that GDB will ignore it. */
2466 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2474 /* Get the low and high pc's represented by the scope DIE, and store
2475 them in *LOWPC and *HIGHPC. If the correct values can't be
2476 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2479 get_scope_pc_bounds (struct die_info
*die
,
2480 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2481 struct dwarf2_cu
*cu
)
2483 CORE_ADDR best_low
= (CORE_ADDR
) -1;
2484 CORE_ADDR best_high
= (CORE_ADDR
) 0;
2485 CORE_ADDR current_low
, current_high
;
2487 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
2489 best_low
= current_low
;
2490 best_high
= current_high
;
2494 struct die_info
*child
= die
->child
;
2496 while (child
&& child
->tag
)
2498 switch (child
->tag
) {
2499 case DW_TAG_subprogram
:
2500 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
2502 best_low
= min (best_low
, current_low
);
2503 best_high
= max (best_high
, current_high
);
2506 case DW_TAG_namespace
:
2507 /* FIXME: carlton/2004-01-16: Should we do this for
2508 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2509 that current GCC's always emit the DIEs corresponding
2510 to definitions of methods of classes as children of a
2511 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2512 the DIEs giving the declarations, which could be
2513 anywhere). But I don't see any reason why the
2514 standards says that they have to be there. */
2515 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
2517 if (current_low
!= ((CORE_ADDR
) -1))
2519 best_low
= min (best_low
, current_low
);
2520 best_high
= max (best_high
, current_high
);
2528 child
= sibling_die (child
);
2533 *highpc
= best_high
;
2536 /* Add an aggregate field to the field list. */
2539 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2540 struct dwarf2_cu
*cu
)
2542 struct objfile
*objfile
= cu
->objfile
;
2543 struct nextfield
*new_field
;
2544 struct attribute
*attr
;
2546 char *fieldname
= "";
2548 /* Allocate a new field list entry and link it in. */
2549 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2550 make_cleanup (xfree
, new_field
);
2551 memset (new_field
, 0, sizeof (struct nextfield
));
2552 new_field
->next
= fip
->fields
;
2553 fip
->fields
= new_field
;
2556 /* Handle accessibility and virtuality of field.
2557 The default accessibility for members is public, the default
2558 accessibility for inheritance is private. */
2559 if (die
->tag
!= DW_TAG_inheritance
)
2560 new_field
->accessibility
= DW_ACCESS_public
;
2562 new_field
->accessibility
= DW_ACCESS_private
;
2563 new_field
->virtuality
= DW_VIRTUALITY_none
;
2565 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2567 new_field
->accessibility
= DW_UNSND (attr
);
2568 if (new_field
->accessibility
!= DW_ACCESS_public
)
2569 fip
->non_public_fields
= 1;
2570 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
2572 new_field
->virtuality
= DW_UNSND (attr
);
2574 fp
= &new_field
->field
;
2576 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
2578 /* Data member other than a C++ static data member. */
2580 /* Get type of field. */
2581 fp
->type
= die_type (die
, cu
);
2583 FIELD_STATIC_KIND (*fp
) = 0;
2585 /* Get bit size of field (zero if none). */
2586 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
2589 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2593 FIELD_BITSIZE (*fp
) = 0;
2596 /* Get bit offset of field. */
2597 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2600 FIELD_BITPOS (*fp
) =
2601 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
2604 FIELD_BITPOS (*fp
) = 0;
2605 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
2608 if (BITS_BIG_ENDIAN
)
2610 /* For big endian bits, the DW_AT_bit_offset gives the
2611 additional bit offset from the MSB of the containing
2612 anonymous object to the MSB of the field. We don't
2613 have to do anything special since we don't need to
2614 know the size of the anonymous object. */
2615 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2619 /* For little endian bits, compute the bit offset to the
2620 MSB of the anonymous object, subtract off the number of
2621 bits from the MSB of the field to the MSB of the
2622 object, and then subtract off the number of bits of
2623 the field itself. The result is the bit offset of
2624 the LSB of the field. */
2626 int bit_offset
= DW_UNSND (attr
);
2628 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
2631 /* The size of the anonymous object containing
2632 the bit field is explicit, so use the
2633 indicated size (in bytes). */
2634 anonymous_size
= DW_UNSND (attr
);
2638 /* The size of the anonymous object containing
2639 the bit field must be inferred from the type
2640 attribute of the data member containing the
2642 anonymous_size
= TYPE_LENGTH (fp
->type
);
2644 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2645 - bit_offset
- FIELD_BITSIZE (*fp
);
2649 /* Get name of field. */
2650 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2651 if (attr
&& DW_STRING (attr
))
2652 fieldname
= DW_STRING (attr
);
2653 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2654 &objfile
->type_obstack
);
2656 /* Change accessibility for artificial fields (e.g. virtual table
2657 pointer or virtual base class pointer) to private. */
2658 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
2660 new_field
->accessibility
= DW_ACCESS_private
;
2661 fip
->non_public_fields
= 1;
2664 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2666 /* C++ static member. */
2668 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2669 is a declaration, but all versions of G++ as of this writing
2670 (so through at least 3.2.1) incorrectly generate
2671 DW_TAG_variable tags. */
2675 /* Get name of field. */
2676 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2677 if (attr
&& DW_STRING (attr
))
2678 fieldname
= DW_STRING (attr
);
2682 /* Get physical name. */
2683 physname
= dwarf2_linkage_name (die
, cu
);
2685 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2686 &objfile
->type_obstack
));
2687 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2688 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2689 &objfile
->type_obstack
);
2691 else if (die
->tag
== DW_TAG_inheritance
)
2693 /* C++ base class field. */
2694 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
2696 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
2698 FIELD_BITSIZE (*fp
) = 0;
2699 FIELD_STATIC_KIND (*fp
) = 0;
2700 FIELD_TYPE (*fp
) = die_type (die
, cu
);
2701 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2702 fip
->nbaseclasses
++;
2706 /* Create the vector of fields, and attach it to the type. */
2709 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2710 struct dwarf2_cu
*cu
)
2712 int nfields
= fip
->nfields
;
2714 /* Record the field count, allocate space for the array of fields,
2715 and create blank accessibility bitfields if necessary. */
2716 TYPE_NFIELDS (type
) = nfields
;
2717 TYPE_FIELDS (type
) = (struct field
*)
2718 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2719 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2721 if (fip
->non_public_fields
)
2723 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2725 TYPE_FIELD_PRIVATE_BITS (type
) =
2726 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2727 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2729 TYPE_FIELD_PROTECTED_BITS (type
) =
2730 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2731 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2733 TYPE_FIELD_IGNORE_BITS (type
) =
2734 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2735 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2738 /* If the type has baseclasses, allocate and clear a bit vector for
2739 TYPE_FIELD_VIRTUAL_BITS. */
2740 if (fip
->nbaseclasses
)
2742 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2745 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2746 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2747 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2748 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2749 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2752 /* Copy the saved-up fields into the field vector. Start from the head
2753 of the list, adding to the tail of the field array, so that they end
2754 up in the same order in the array in which they were added to the list. */
2755 while (nfields
-- > 0)
2757 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2758 switch (fip
->fields
->accessibility
)
2760 case DW_ACCESS_private
:
2761 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2764 case DW_ACCESS_protected
:
2765 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2768 case DW_ACCESS_public
:
2772 /* Unknown accessibility. Complain and treat it as public. */
2774 complaint (&symfile_complaints
, "unsupported accessibility %d",
2775 fip
->fields
->accessibility
);
2779 if (nfields
< fip
->nbaseclasses
)
2781 switch (fip
->fields
->virtuality
)
2783 case DW_VIRTUALITY_virtual
:
2784 case DW_VIRTUALITY_pure_virtual
:
2785 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2789 fip
->fields
= fip
->fields
->next
;
2793 /* Add a member function to the proper fieldlist. */
2796 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2797 struct type
*type
, struct dwarf2_cu
*cu
)
2799 struct objfile
*objfile
= cu
->objfile
;
2800 struct attribute
*attr
;
2801 struct fnfieldlist
*flp
;
2803 struct fn_field
*fnp
;
2806 struct nextfnfield
*new_fnfield
;
2808 /* Get name of member function. */
2809 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2810 if (attr
&& DW_STRING (attr
))
2811 fieldname
= DW_STRING (attr
);
2815 /* Get the mangled name. */
2816 physname
= dwarf2_linkage_name (die
, cu
);
2818 /* Look up member function name in fieldlist. */
2819 for (i
= 0; i
< fip
->nfnfields
; i
++)
2821 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
2825 /* Create new list element if necessary. */
2826 if (i
< fip
->nfnfields
)
2827 flp
= &fip
->fnfieldlists
[i
];
2830 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2832 fip
->fnfieldlists
= (struct fnfieldlist
*)
2833 xrealloc (fip
->fnfieldlists
,
2834 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2835 * sizeof (struct fnfieldlist
));
2836 if (fip
->nfnfields
== 0)
2837 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2839 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2840 flp
->name
= fieldname
;
2846 /* Create a new member function field and chain it to the field list
2848 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2849 make_cleanup (xfree
, new_fnfield
);
2850 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2851 new_fnfield
->next
= flp
->head
;
2852 flp
->head
= new_fnfield
;
2855 /* Fill in the member function field info. */
2856 fnp
= &new_fnfield
->fnfield
;
2857 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2858 &objfile
->type_obstack
);
2859 fnp
->type
= alloc_type (objfile
);
2860 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2862 int nparams
= TYPE_NFIELDS (die
->type
);
2864 /* TYPE is the domain of this method, and DIE->TYPE is the type
2865 of the method itself (TYPE_CODE_METHOD). */
2866 smash_to_method_type (fnp
->type
, type
,
2867 TYPE_TARGET_TYPE (die
->type
),
2868 TYPE_FIELDS (die
->type
),
2869 TYPE_NFIELDS (die
->type
),
2870 TYPE_VARARGS (die
->type
));
2872 /* Handle static member functions.
2873 Dwarf2 has no clean way to discern C++ static and non-static
2874 member functions. G++ helps GDB by marking the first
2875 parameter for non-static member functions (which is the
2876 this pointer) as artificial. We obtain this information
2877 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2878 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2879 fnp
->voffset
= VOFFSET_STATIC
;
2882 complaint (&symfile_complaints
, "member function type missing for '%s'",
2885 /* Get fcontext from DW_AT_containing_type if present. */
2886 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
2887 fnp
->fcontext
= die_containing_type (die
, cu
);
2889 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2890 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2892 /* Get accessibility. */
2893 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
2896 switch (DW_UNSND (attr
))
2898 case DW_ACCESS_private
:
2899 fnp
->is_private
= 1;
2901 case DW_ACCESS_protected
:
2902 fnp
->is_protected
= 1;
2907 /* Check for artificial methods. */
2908 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
2909 if (attr
&& DW_UNSND (attr
) != 0)
2910 fnp
->is_artificial
= 1;
2912 /* Get index in virtual function table if it is a virtual member function. */
2913 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
2916 /* Support the .debug_loc offsets */
2917 if (attr_form_is_block (attr
))
2919 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
2921 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2923 dwarf2_complex_location_expr_complaint ();
2927 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2933 /* Create the vector of member function fields, and attach it to the type. */
2936 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2937 struct dwarf2_cu
*cu
)
2939 struct fnfieldlist
*flp
;
2940 int total_length
= 0;
2943 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2944 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2945 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2947 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2949 struct nextfnfield
*nfp
= flp
->head
;
2950 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2953 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2954 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2955 fn_flp
->fn_fields
= (struct fn_field
*)
2956 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2957 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2958 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2960 total_length
+= flp
->length
;
2963 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2964 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2967 /* Called when we find the DIE that starts a structure or union scope
2968 (definition) to process all dies that define the members of the
2971 NOTE: we need to call struct_type regardless of whether or not the
2972 DIE has an at_name attribute, since it might be an anonymous
2973 structure or union. This gets the type entered into our set of
2976 However, if the structure is incomplete (an opaque struct/union)
2977 then suppress creating a symbol table entry for it since gdb only
2978 wants to find the one with the complete definition. Note that if
2979 it is complete, we just call new_symbol, which does it's own
2980 checking about whether the struct/union is anonymous or not (and
2981 suppresses creating a symbol table entry itself). */
2984 read_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2986 struct objfile
*objfile
= cu
->objfile
;
2988 struct attribute
*attr
;
2989 const char *name
= NULL
;
2990 const char *previous_prefix
= processing_current_prefix
;
2991 struct cleanup
*back_to
= NULL
;
2992 /* This says whether or not we want to try to update the structure's
2993 name to include enclosing namespace/class information, if
2995 int need_to_update_name
= 0;
2997 type
= alloc_type (objfile
);
2999 INIT_CPLUS_SPECIFIC (type
);
3000 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3001 if (attr
&& DW_STRING (attr
))
3003 name
= DW_STRING (attr
);
3005 if (cu
->language
== language_cplus
)
3007 struct die_info
*spec_die
= die_specification (die
, cu
);
3009 if (spec_die
!= NULL
)
3011 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3012 processing_current_prefix
= specification_prefix
;
3013 back_to
= make_cleanup (xfree
, specification_prefix
);
3017 if (processing_has_namespace_info
)
3019 /* FIXME: carlton/2003-11-10: This variable exists only for
3020 const-correctness reasons. When I tried to change
3021 TYPE_TAG_NAME to be a const char *, I ran into a cascade
3022 of changes which would have forced decode_line_1 to take
3024 char *new_prefix
= obconcat (&objfile
->type_obstack
,
3025 processing_current_prefix
,
3026 processing_current_prefix
[0] == '\0'
3029 TYPE_TAG_NAME (type
) = new_prefix
;
3030 processing_current_prefix
= new_prefix
;
3034 TYPE_TAG_NAME (type
) = obsavestring (name
, strlen (name
),
3035 &objfile
->type_obstack
);
3036 need_to_update_name
= (cu
->language
== language_cplus
);
3040 if (die
->tag
== DW_TAG_structure_type
)
3042 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3044 else if (die
->tag
== DW_TAG_union_type
)
3046 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3050 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3052 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3055 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3058 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3062 TYPE_LENGTH (type
) = 0;
3065 /* We need to add the type field to the die immediately so we don't
3066 infinitely recurse when dealing with pointers to the structure
3067 type within the structure itself. */
3070 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3072 struct field_info fi
;
3073 struct die_info
*child_die
;
3074 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3076 memset (&fi
, 0, sizeof (struct field_info
));
3078 child_die
= die
->child
;
3080 while (child_die
&& child_die
->tag
)
3082 if (child_die
->tag
== DW_TAG_member
3083 || child_die
->tag
== DW_TAG_variable
)
3085 /* NOTE: carlton/2002-11-05: A C++ static data member
3086 should be a DW_TAG_member that is a declaration, but
3087 all versions of G++ as of this writing (so through at
3088 least 3.2.1) incorrectly generate DW_TAG_variable
3089 tags for them instead. */
3090 dwarf2_add_field (&fi
, child_die
, cu
);
3092 else if (child_die
->tag
== DW_TAG_subprogram
)
3094 /* C++ member function. */
3095 process_die (child_die
, cu
);
3096 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3097 if (need_to_update_name
)
3099 /* The demangled names of member functions contain
3100 information about enclosing namespaces/classes,
3103 /* FIXME: carlton/2003-11-10: The excessive
3104 demangling here is a bit wasteful, as is the
3105 memory usage for names. */
3107 /* NOTE: carlton/2003-11-10: As commented in
3108 add_partial_structure, the demangler sometimes
3109 prints the type info in a different form from the
3110 debug info. We could solve this by using the
3111 demangled name to get the prefix; if doing so,
3112 however, we'd need to be careful when reading a
3113 class that's nested inside a template class.
3114 That would also cause problems when trying to
3115 determine RTTI information, since we use the
3116 demangler to determine the appropriate class
3118 char *actual_class_name
3119 = class_name_from_physname (dwarf2_linkage_name
3121 if (actual_class_name
!= NULL
3122 && strcmp (actual_class_name
, name
) != 0)
3124 TYPE_TAG_NAME (type
)
3125 = obsavestring (actual_class_name
,
3126 strlen (actual_class_name
),
3127 &objfile
->type_obstack
);
3129 xfree (actual_class_name
);
3130 need_to_update_name
= 0;
3133 else if (child_die
->tag
== DW_TAG_inheritance
)
3135 /* C++ base class field. */
3136 dwarf2_add_field (&fi
, child_die
, cu
);
3140 process_die (child_die
, cu
);
3142 child_die
= sibling_die (child_die
);
3145 /* Attach fields and member functions to the type. */
3147 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3150 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3152 /* Get the type which refers to the base class (possibly this
3153 class itself) which contains the vtable pointer for the current
3154 class from the DW_AT_containing_type attribute. */
3156 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3158 struct type
*t
= die_containing_type (die
, cu
);
3160 TYPE_VPTR_BASETYPE (type
) = t
;
3163 static const char vptr_name
[] =
3164 {'_', 'v', 'p', 't', 'r', '\0'};
3167 /* Our own class provides vtbl ptr. */
3168 for (i
= TYPE_NFIELDS (t
) - 1;
3169 i
>= TYPE_N_BASECLASSES (t
);
3172 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3174 if ((strncmp (fieldname
, vptr_name
,
3175 strlen (vptr_name
) - 1)
3177 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
3179 TYPE_VPTR_FIELDNO (type
) = i
;
3184 /* Complain if virtual function table field not found. */
3185 if (i
< TYPE_N_BASECLASSES (t
))
3186 complaint (&symfile_complaints
,
3187 "virtual function table pointer not found when defining class '%s'",
3188 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3193 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3198 new_symbol (die
, type
, cu
);
3200 do_cleanups (back_to
);
3204 /* No children, must be stub. */
3205 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3208 processing_current_prefix
= previous_prefix
;
3209 if (back_to
!= NULL
)
3210 do_cleanups (back_to
);
3213 /* Given a pointer to a die which begins an enumeration, process all
3214 the dies that define the members of the enumeration.
3216 This will be much nicer in draft 6 of the DWARF spec when our
3217 members will be dies instead squished into the DW_AT_element_list
3220 NOTE: We reverse the order of the element list. */
3223 read_enumeration (struct die_info
*die
, struct dwarf2_cu
*cu
)
3225 struct objfile
*objfile
= cu
->objfile
;
3226 struct die_info
*child_die
;
3228 struct field
*fields
;
3229 struct attribute
*attr
;
3232 int unsigned_enum
= 1;
3234 type
= alloc_type (objfile
);
3236 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3237 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3238 if (attr
&& DW_STRING (attr
))
3240 const char *name
= DW_STRING (attr
);
3242 if (processing_has_namespace_info
)
3244 TYPE_TAG_NAME (type
) = obconcat (&objfile
->type_obstack
,
3245 processing_current_prefix
,
3246 processing_current_prefix
[0] == '\0'
3252 TYPE_TAG_NAME (type
) = obsavestring (name
, strlen (name
),
3253 &objfile
->type_obstack
);
3257 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3260 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3264 TYPE_LENGTH (type
) = 0;
3269 if (die
->child
!= NULL
)
3271 child_die
= die
->child
;
3272 while (child_die
&& child_die
->tag
)
3274 if (child_die
->tag
!= DW_TAG_enumerator
)
3276 process_die (child_die
, cu
);
3280 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3283 sym
= new_symbol (child_die
, type
, cu
);
3284 if (SYMBOL_VALUE (sym
) < 0)
3287 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3289 fields
= (struct field
*)
3291 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3292 * sizeof (struct field
));
3295 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3296 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3297 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3298 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3299 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3305 child_die
= sibling_die (child_die
);
3310 TYPE_NFIELDS (type
) = num_fields
;
3311 TYPE_FIELDS (type
) = (struct field
*)
3312 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
3313 memcpy (TYPE_FIELDS (type
), fields
,
3314 sizeof (struct field
) * num_fields
);
3318 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3321 new_symbol (die
, type
, cu
);
3324 /* Extract all information from a DW_TAG_array_type DIE and put it in
3325 the DIE's type field. For now, this only handles one dimensional
3329 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3331 struct objfile
*objfile
= cu
->objfile
;
3332 struct die_info
*child_die
;
3333 struct type
*type
= NULL
;
3334 struct type
*element_type
, *range_type
, *index_type
;
3335 struct type
**range_types
= NULL
;
3336 struct attribute
*attr
;
3338 struct cleanup
*back_to
;
3340 /* Return if we've already decoded this type. */
3346 element_type
= die_type (die
, cu
);
3348 /* Irix 6.2 native cc creates array types without children for
3349 arrays with unspecified length. */
3350 if (die
->child
== NULL
)
3352 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3353 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3354 die
->type
= create_array_type (NULL
, element_type
, range_type
);
3358 back_to
= make_cleanup (null_cleanup
, NULL
);
3359 child_die
= die
->child
;
3360 while (child_die
&& child_die
->tag
)
3362 if (child_die
->tag
== DW_TAG_subrange_type
)
3364 read_subrange_type (child_die
, cu
);
3366 if (child_die
->type
!= NULL
)
3368 /* The range type was succesfully read. Save it for
3369 the array type creation. */
3370 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3372 range_types
= (struct type
**)
3373 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3374 * sizeof (struct type
*));
3376 make_cleanup (free_current_contents
, &range_types
);
3378 range_types
[ndim
++] = child_die
->type
;
3381 child_die
= sibling_die (child_die
);
3384 /* Dwarf2 dimensions are output from left to right, create the
3385 necessary array types in backwards order. */
3386 type
= element_type
;
3388 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3390 /* Understand Dwarf2 support for vector types (like they occur on
3391 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3392 array type. This is not part of the Dwarf2/3 standard yet, but a
3393 custom vendor extension. The main difference between a regular
3394 array and the vector variant is that vectors are passed by value
3396 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
3398 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3400 do_cleanups (back_to
);
3402 /* Install the type in the die. */
3406 /* First cut: install each common block member as a global variable. */
3409 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
3411 struct die_info
*child_die
;
3412 struct attribute
*attr
;
3414 CORE_ADDR base
= (CORE_ADDR
) 0;
3416 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
3419 /* Support the .debug_loc offsets */
3420 if (attr_form_is_block (attr
))
3422 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
3424 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3426 dwarf2_complex_location_expr_complaint ();
3430 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3431 "common block member");
3434 if (die
->child
!= NULL
)
3436 child_die
= die
->child
;
3437 while (child_die
&& child_die
->tag
)
3439 sym
= new_symbol (child_die
, NULL
, cu
);
3440 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
3443 SYMBOL_VALUE_ADDRESS (sym
) =
3444 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
3445 add_symbol_to_list (sym
, &global_symbols
);
3447 child_die
= sibling_die (child_die
);
3452 /* Read a C++ namespace. */
3455 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3457 struct objfile
*objfile
= cu
->objfile
;
3458 const char *previous_prefix
= processing_current_prefix
;
3461 struct die_info
*current_die
;
3463 name
= namespace_name (die
, &is_anonymous
, cu
);
3465 /* Now build the name of the current namespace. */
3467 if (previous_prefix
[0] == '\0')
3469 processing_current_prefix
= name
;
3473 /* We need temp_name around because processing_current_prefix
3474 is a const char *. */
3475 char *temp_name
= alloca (strlen (previous_prefix
)
3476 + 2 + strlen(name
) + 1);
3477 strcpy (temp_name
, previous_prefix
);
3478 strcat (temp_name
, "::");
3479 strcat (temp_name
, name
);
3481 processing_current_prefix
= temp_name
;
3484 /* Add a symbol associated to this if we haven't seen the namespace
3485 before. Also, add a using directive if it's an anonymous
3488 if (dwarf2_extension (die
, cu
) == NULL
)
3492 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3493 this cast will hopefully become unnecessary. */
3494 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
3495 (char *) processing_current_prefix
,
3497 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
3499 new_symbol (die
, type
, cu
);
3502 cp_add_using_directive (processing_current_prefix
,
3503 strlen (previous_prefix
),
3504 strlen (processing_current_prefix
));
3507 if (die
->child
!= NULL
)
3509 struct die_info
*child_die
= die
->child
;
3511 while (child_die
&& child_die
->tag
)
3513 process_die (child_die
, cu
);
3514 child_die
= sibling_die (child_die
);
3518 processing_current_prefix
= previous_prefix
;
3521 /* Return the name of the namespace represented by DIE. Set
3522 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3526 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
3528 struct die_info
*current_die
;
3529 const char *name
= NULL
;
3531 /* Loop through the extensions until we find a name. */
3533 for (current_die
= die
;
3534 current_die
!= NULL
;
3535 current_die
= dwarf2_extension (die
, cu
))
3537 name
= dwarf2_name (current_die
, cu
);
3542 /* Is it an anonymous namespace? */
3544 *is_anonymous
= (name
== NULL
);
3546 name
= "(anonymous namespace)";
3551 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3552 the user defined type vector. */
3555 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3557 struct comp_unit_head
*cu_header
= &cu
->header
;
3559 struct attribute
*attr_byte_size
;
3560 struct attribute
*attr_address_class
;
3561 int byte_size
, addr_class
;
3568 type
= lookup_pointer_type (die_type (die
, cu
));
3570 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3572 byte_size
= DW_UNSND (attr_byte_size
);
3574 byte_size
= cu_header
->addr_size
;
3576 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
3577 if (attr_address_class
)
3578 addr_class
= DW_UNSND (attr_address_class
);
3580 addr_class
= DW_ADDR_none
;
3582 /* If the pointer size or address class is different than the
3583 default, create a type variant marked as such and set the
3584 length accordingly. */
3585 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3587 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3591 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3592 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3593 type
= make_type_with_address_space (type
, type_flags
);
3595 else if (TYPE_LENGTH (type
) != byte_size
)
3597 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3600 /* Should we also complain about unhandled address classes? */
3604 TYPE_LENGTH (type
) = byte_size
;
3608 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3609 the user defined type vector. */
3612 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3614 struct objfile
*objfile
= cu
->objfile
;
3616 struct type
*to_type
;
3617 struct type
*domain
;
3624 type
= alloc_type (objfile
);
3625 to_type
= die_type (die
, cu
);
3626 domain
= die_containing_type (die
, cu
);
3627 smash_to_member_type (type
, domain
, to_type
);
3632 /* Extract all information from a DW_TAG_reference_type DIE and add to
3633 the user defined type vector. */
3636 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3638 struct comp_unit_head
*cu_header
= &cu
->header
;
3640 struct attribute
*attr
;
3647 type
= lookup_reference_type (die_type (die
, cu
));
3648 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3651 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3655 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3661 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3663 struct type
*base_type
;
3670 base_type
= die_type (die
, cu
);
3671 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3675 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3677 struct type
*base_type
;
3684 base_type
= die_type (die
, cu
);
3685 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3688 /* Extract all information from a DW_TAG_string_type DIE and add to
3689 the user defined type vector. It isn't really a user defined type,
3690 but it behaves like one, with other DIE's using an AT_user_def_type
3691 attribute to reference it. */
3694 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3696 struct objfile
*objfile
= cu
->objfile
;
3697 struct type
*type
, *range_type
, *index_type
, *char_type
;
3698 struct attribute
*attr
;
3699 unsigned int length
;
3706 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
3709 length
= DW_UNSND (attr
);
3713 /* check for the DW_AT_byte_size attribute */
3714 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3717 length
= DW_UNSND (attr
);
3724 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3725 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3726 if (cu
->language
== language_fortran
)
3728 /* Need to create a unique string type for bounds
3730 type
= create_string_type (0, range_type
);
3734 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
3735 type
= create_string_type (char_type
, range_type
);
3740 /* Handle DIES due to C code like:
3744 int (*funcp)(int a, long l);
3748 ('funcp' generates a DW_TAG_subroutine_type DIE)
3752 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3754 struct type
*type
; /* Type that this function returns */
3755 struct type
*ftype
; /* Function that returns above type */
3756 struct attribute
*attr
;
3758 /* Decode the type that this subroutine returns */
3763 type
= die_type (die
, cu
);
3764 ftype
= lookup_function_type (type
);
3766 /* All functions in C++ have prototypes. */
3767 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
3768 if ((attr
&& (DW_UNSND (attr
) != 0))
3769 || cu
->language
== language_cplus
)
3770 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3772 if (die
->child
!= NULL
)
3774 struct die_info
*child_die
;
3778 /* Count the number of parameters.
3779 FIXME: GDB currently ignores vararg functions, but knows about
3780 vararg member functions. */
3781 child_die
= die
->child
;
3782 while (child_die
&& child_die
->tag
)
3784 if (child_die
->tag
== DW_TAG_formal_parameter
)
3786 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3787 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3788 child_die
= sibling_die (child_die
);
3791 /* Allocate storage for parameters and fill them in. */
3792 TYPE_NFIELDS (ftype
) = nparams
;
3793 TYPE_FIELDS (ftype
) = (struct field
*)
3794 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3796 child_die
= die
->child
;
3797 while (child_die
&& child_die
->tag
)
3799 if (child_die
->tag
== DW_TAG_formal_parameter
)
3801 /* Dwarf2 has no clean way to discern C++ static and non-static
3802 member functions. G++ helps GDB by marking the first
3803 parameter for non-static member functions (which is the
3804 this pointer) as artificial. We pass this information
3805 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3806 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
3808 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3810 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3811 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
3814 child_die
= sibling_die (child_die
);
3822 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
3824 struct objfile
*objfile
= cu
->objfile
;
3825 struct attribute
*attr
;
3830 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3831 if (attr
&& DW_STRING (attr
))
3833 name
= DW_STRING (attr
);
3835 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3836 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
3840 /* Find a representation of a given base type and install
3841 it in the TYPE field of the die. */
3844 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3846 struct objfile
*objfile
= cu
->objfile
;
3848 struct attribute
*attr
;
3849 int encoding
= 0, size
= 0;
3851 /* If we've already decoded this die, this is a no-op. */
3857 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
3860 encoding
= DW_UNSND (attr
);
3862 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3865 size
= DW_UNSND (attr
);
3867 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3868 if (attr
&& DW_STRING (attr
))
3870 enum type_code code
= TYPE_CODE_INT
;
3875 case DW_ATE_address
:
3876 /* Turn DW_ATE_address into a void * pointer. */
3877 code
= TYPE_CODE_PTR
;
3878 type_flags
|= TYPE_FLAG_UNSIGNED
;
3880 case DW_ATE_boolean
:
3881 code
= TYPE_CODE_BOOL
;
3882 type_flags
|= TYPE_FLAG_UNSIGNED
;
3884 case DW_ATE_complex_float
:
3885 code
= TYPE_CODE_COMPLEX
;
3888 code
= TYPE_CODE_FLT
;
3891 case DW_ATE_signed_char
:
3893 case DW_ATE_unsigned
:
3894 case DW_ATE_unsigned_char
:
3895 type_flags
|= TYPE_FLAG_UNSIGNED
;
3898 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3899 dwarf_type_encoding_name (encoding
));
3902 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3903 if (encoding
== DW_ATE_address
)
3904 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
3906 else if (encoding
== DW_ATE_complex_float
)
3909 TYPE_TARGET_TYPE (type
)
3910 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
3911 else if (size
== 16)
3912 TYPE_TARGET_TYPE (type
)
3913 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
3915 TYPE_TARGET_TYPE (type
)
3916 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
3921 type
= dwarf_base_type (encoding
, size
, cu
);
3926 /* Read the given DW_AT_subrange DIE. */
3929 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3931 struct type
*base_type
;
3932 struct type
*range_type
;
3933 struct attribute
*attr
;
3937 /* If we have already decoded this die, then nothing more to do. */
3941 base_type
= die_type (die
, cu
);
3942 if (base_type
== NULL
)
3944 complaint (&symfile_complaints
,
3945 "DW_AT_type missing from DW_TAG_subrange_type");
3949 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
3950 base_type
= alloc_type (NULL
);
3952 if (cu
->language
== language_fortran
)
3954 /* FORTRAN implies a lower bound of 1, if not given. */
3958 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
3960 low
= dwarf2_get_attr_constant_value (attr
, 0);
3962 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
3965 if (attr
->form
== DW_FORM_block1
)
3967 /* GCC encodes arrays with unspecified or dynamic length
3968 with a DW_FORM_block1 attribute.
3969 FIXME: GDB does not yet know how to handle dynamic
3970 arrays properly, treat them as arrays with unspecified
3973 FIXME: jimb/2003-09-22: GDB does not really know
3974 how to handle arrays of unspecified length
3975 either; we just represent them as zero-length
3976 arrays. Choose an appropriate upper bound given
3977 the lower bound we've computed above. */
3981 high
= dwarf2_get_attr_constant_value (attr
, 1);
3984 range_type
= create_range_type (NULL
, base_type
, low
, high
);
3986 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3987 if (attr
&& DW_STRING (attr
))
3988 TYPE_NAME (range_type
) = DW_STRING (attr
);
3990 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3992 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
3994 die
->type
= range_type
;
3998 /* Read a whole compilation unit into a linked list of dies. */
4000 static struct die_info
*
4001 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4003 /* Reset die reference table; we are
4004 building new ones now. */
4005 dwarf2_empty_hash_tables ();
4007 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4010 /* Read a single die and all its descendents. Set the die's sibling
4011 field to NULL; set other fields in the die correctly, and set all
4012 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4013 location of the info_ptr after reading all of those dies. PARENT
4014 is the parent of the die in question. */
4016 static struct die_info
*
4017 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4018 struct dwarf2_cu
*cu
,
4019 char **new_info_ptr
,
4020 struct die_info
*parent
)
4022 struct die_info
*die
;
4026 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4027 store_in_ref_table (die
->offset
, die
);
4031 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4037 *new_info_ptr
= cur_ptr
;
4040 die
->sibling
= NULL
;
4041 die
->parent
= parent
;
4045 /* Read a die, all of its descendents, and all of its siblings; set
4046 all of the fields of all of the dies correctly. Arguments are as
4047 in read_die_and_children. */
4049 static struct die_info
*
4050 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4051 struct dwarf2_cu
*cu
,
4052 char **new_info_ptr
,
4053 struct die_info
*parent
)
4055 struct die_info
*first_die
, *last_sibling
;
4059 first_die
= last_sibling
= NULL
;
4063 struct die_info
*die
4064 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4072 last_sibling
->sibling
= die
;
4077 *new_info_ptr
= cur_ptr
;
4087 /* Free a linked list of dies. */
4090 free_die_list (struct die_info
*dies
)
4092 struct die_info
*die
, *next
;
4097 if (die
->child
!= NULL
)
4098 free_die_list (die
->child
);
4099 next
= die
->sibling
;
4107 do_free_die_list_cleanup (void *dies
)
4109 free_die_list (dies
);
4112 static struct cleanup
*
4113 make_cleanup_free_die_list (struct die_info
*dies
)
4115 return make_cleanup (do_free_die_list_cleanup
, dies
);
4119 /* Read the contents of the section at OFFSET and of size SIZE from the
4120 object file specified by OBJFILE into the psymbol_obstack and return it. */
4123 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4125 bfd
*abfd
= objfile
->obfd
;
4127 bfd_size_type size
= bfd_get_section_size_before_reloc (sectp
);
4132 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
4134 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4138 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4139 || bfd_bread (buf
, size
, abfd
) != size
)
4140 error ("Dwarf Error: Can't read DWARF data from '%s'",
4141 bfd_get_filename (abfd
));
4146 /* In DWARF version 2, the description of the debugging information is
4147 stored in a separate .debug_abbrev section. Before we read any
4148 dies from a section we read in all abbreviations and install them
4152 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4154 struct comp_unit_head
*cu_header
= &cu
->header
;
4156 struct abbrev_info
*cur_abbrev
;
4157 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4158 unsigned int abbrev_form
, hash_number
;
4160 /* Initialize dwarf2 abbrevs */
4161 memset (cu_header
->dwarf2_abbrevs
, 0,
4162 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
4164 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
4165 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4166 abbrev_ptr
+= bytes_read
;
4168 /* loop until we reach an abbrev number of 0 */
4169 while (abbrev_number
)
4171 cur_abbrev
= dwarf_alloc_abbrev ();
4173 /* read in abbrev header */
4174 cur_abbrev
->number
= abbrev_number
;
4175 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4176 abbrev_ptr
+= bytes_read
;
4177 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4180 /* now read in declarations */
4181 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4182 abbrev_ptr
+= bytes_read
;
4183 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4184 abbrev_ptr
+= bytes_read
;
4187 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
4189 cur_abbrev
->attrs
= (struct attr_abbrev
*)
4190 xrealloc (cur_abbrev
->attrs
,
4191 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
4192 * sizeof (struct attr_abbrev
));
4194 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4195 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4196 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4197 abbrev_ptr
+= bytes_read
;
4198 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4199 abbrev_ptr
+= bytes_read
;
4202 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4203 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
4204 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4206 /* Get next abbreviation.
4207 Under Irix6 the abbreviations for a compilation unit are not
4208 always properly terminated with an abbrev number of 0.
4209 Exit loop if we encounter an abbreviation which we have
4210 already read (which means we are about to read the abbreviations
4211 for the next compile unit) or if the end of the abbreviation
4212 table is reached. */
4213 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
4214 >= dwarf_abbrev_size
)
4216 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4217 abbrev_ptr
+= bytes_read
;
4218 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4223 /* Empty the abbrev table for a new compilation unit. */
4226 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
4229 struct abbrev_info
*abbrev
, *next
;
4230 struct abbrev_info
**abbrevs
;
4232 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
4234 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
4237 abbrev
= abbrevs
[i
];
4240 next
= abbrev
->next
;
4241 xfree (abbrev
->attrs
);
4249 /* Lookup an abbrev_info structure in the abbrev hash table. */
4251 static struct abbrev_info
*
4252 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4254 struct comp_unit_head
*cu_header
= &cu
->header
;
4255 unsigned int hash_number
;
4256 struct abbrev_info
*abbrev
;
4258 hash_number
= number
% ABBREV_HASH_SIZE
;
4259 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
4263 if (abbrev
->number
== number
)
4266 abbrev
= abbrev
->next
;
4271 /* Read a minimal amount of information into the minimal die structure. */
4274 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
4275 char *info_ptr
, struct dwarf2_cu
*cu
)
4277 unsigned int abbrev_number
, bytes_read
, i
;
4278 struct abbrev_info
*abbrev
;
4279 struct attribute attr
;
4280 struct attribute spec_attr
;
4281 int found_spec_attr
= 0;
4282 int has_low_pc_attr
= 0;
4283 int has_high_pc_attr
= 0;
4285 *part_die
= zeroed_partial_die
;
4286 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4287 info_ptr
+= bytes_read
;
4291 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4294 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
4295 bfd_get_filename (abfd
));
4297 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
4298 part_die
->tag
= abbrev
->tag
;
4299 part_die
->has_children
= abbrev
->has_children
;
4300 part_die
->abbrev
= abbrev_number
;
4302 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4304 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
4306 /* Store the data if it is of an attribute we want to keep in a
4307 partial symbol table. */
4312 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4313 if (part_die
->name
== NULL
)
4314 part_die
->name
= DW_STRING (&attr
);
4316 case DW_AT_MIPS_linkage_name
:
4317 part_die
->name
= DW_STRING (&attr
);
4320 has_low_pc_attr
= 1;
4321 part_die
->lowpc
= DW_ADDR (&attr
);
4324 has_high_pc_attr
= 1;
4325 part_die
->highpc
= DW_ADDR (&attr
);
4327 case DW_AT_location
:
4328 /* Support the .debug_loc offsets */
4329 if (attr_form_is_block (&attr
))
4331 part_die
->locdesc
= DW_BLOCK (&attr
);
4333 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
4335 dwarf2_complex_location_expr_complaint ();
4339 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4340 "partial symbol information");
4343 case DW_AT_language
:
4344 part_die
->language
= DW_UNSND (&attr
);
4346 case DW_AT_external
:
4347 part_die
->is_external
= DW_UNSND (&attr
);
4349 case DW_AT_declaration
:
4350 part_die
->is_declaration
= DW_UNSND (&attr
);
4353 part_die
->has_type
= 1;
4355 case DW_AT_abstract_origin
:
4356 case DW_AT_specification
:
4357 found_spec_attr
= 1;
4361 /* Ignore absolute siblings, they might point outside of
4362 the current compile unit. */
4363 if (attr
.form
== DW_FORM_ref_addr
)
4364 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
4367 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
, cu
);
4374 /* If we found a reference attribute and the die has no name, try
4375 to find a name in the referred to die. */
4377 if (found_spec_attr
&& part_die
->name
== NULL
)
4379 struct partial_die_info spec_die
;
4382 spec_ptr
= dwarf_info_buffer
4383 + dwarf2_get_ref_die_offset (&spec_attr
, cu
);
4384 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu
);
4387 part_die
->name
= spec_die
.name
;
4389 /* Copy DW_AT_external attribute if it is set. */
4390 if (spec_die
.is_external
)
4391 part_die
->is_external
= spec_die
.is_external
;
4395 /* When using the GNU linker, .gnu.linkonce. sections are used to
4396 eliminate duplicate copies of functions and vtables and such.
4397 The linker will arbitrarily choose one and discard the others.
4398 The AT_*_pc values for such functions refer to local labels in
4399 these sections. If the section from that file was discarded, the
4400 labels are not in the output, so the relocs get a value of 0.
4401 If this is a discarded function, mark the pc bounds as invalid,
4402 so that GDB will ignore it. */
4403 if (has_low_pc_attr
&& has_high_pc_attr
4404 && part_die
->lowpc
< part_die
->highpc
4405 && (part_die
->lowpc
!= 0
4406 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
4407 part_die
->has_pc_info
= 1;
4411 /* Read the die from the .debug_info section buffer. Set DIEP to
4412 point to a newly allocated die with its information, except for its
4413 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4414 whether the die has children or not. */
4417 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
4418 struct dwarf2_cu
*cu
, int *has_children
)
4420 unsigned int abbrev_number
, bytes_read
, i
, offset
;
4421 struct abbrev_info
*abbrev
;
4422 struct die_info
*die
;
4424 offset
= info_ptr
- dwarf_info_buffer
;
4425 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4426 info_ptr
+= bytes_read
;
4429 die
= dwarf_alloc_die ();
4431 die
->abbrev
= abbrev_number
;
4438 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4441 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4443 bfd_get_filename (abfd
));
4445 die
= dwarf_alloc_die ();
4446 die
->offset
= offset
;
4447 die
->tag
= abbrev
->tag
;
4448 die
->abbrev
= abbrev_number
;
4451 die
->num_attrs
= abbrev
->num_attrs
;
4452 die
->attrs
= (struct attribute
*)
4453 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
4455 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
4457 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
4458 abfd
, info_ptr
, cu
);
4462 *has_children
= abbrev
->has_children
;
4466 /* Read an attribute value described by an attribute form. */
4469 read_attribute_value (struct attribute
*attr
, unsigned form
,
4470 bfd
*abfd
, char *info_ptr
,
4471 struct dwarf2_cu
*cu
)
4473 struct comp_unit_head
*cu_header
= &cu
->header
;
4474 unsigned int bytes_read
;
4475 struct dwarf_block
*blk
;
4481 case DW_FORM_ref_addr
:
4482 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
4483 info_ptr
+= bytes_read
;
4485 case DW_FORM_block2
:
4486 blk
= dwarf_alloc_block ();
4487 blk
->size
= read_2_bytes (abfd
, info_ptr
);
4489 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4490 info_ptr
+= blk
->size
;
4491 DW_BLOCK (attr
) = blk
;
4493 case DW_FORM_block4
:
4494 blk
= dwarf_alloc_block ();
4495 blk
->size
= read_4_bytes (abfd
, info_ptr
);
4497 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4498 info_ptr
+= blk
->size
;
4499 DW_BLOCK (attr
) = blk
;
4502 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4506 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4510 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4513 case DW_FORM_string
:
4514 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
4515 info_ptr
+= bytes_read
;
4518 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
4520 info_ptr
+= bytes_read
;
4523 blk
= dwarf_alloc_block ();
4524 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4525 info_ptr
+= bytes_read
;
4526 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4527 info_ptr
+= blk
->size
;
4528 DW_BLOCK (attr
) = blk
;
4530 case DW_FORM_block1
:
4531 blk
= dwarf_alloc_block ();
4532 blk
->size
= read_1_byte (abfd
, info_ptr
);
4534 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
4535 info_ptr
+= blk
->size
;
4536 DW_BLOCK (attr
) = blk
;
4539 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4543 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4547 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4548 info_ptr
+= bytes_read
;
4551 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4552 info_ptr
+= bytes_read
;
4555 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4559 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4563 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4567 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4570 case DW_FORM_ref_udata
:
4571 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4572 info_ptr
+= bytes_read
;
4574 case DW_FORM_indirect
:
4575 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4576 info_ptr
+= bytes_read
;
4577 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
4580 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4581 dwarf_form_name (form
),
4582 bfd_get_filename (abfd
));
4587 /* Read an attribute described by an abbreviated attribute. */
4590 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4591 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
4593 attr
->name
= abbrev
->name
;
4594 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
4597 /* read dwarf information from a buffer */
4600 read_1_byte (bfd
*abfd
, char *buf
)
4602 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4606 read_1_signed_byte (bfd
*abfd
, char *buf
)
4608 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4612 read_2_bytes (bfd
*abfd
, char *buf
)
4614 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4618 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4620 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4624 read_4_bytes (bfd
*abfd
, char *buf
)
4626 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4630 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4632 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4635 static unsigned long
4636 read_8_bytes (bfd
*abfd
, char *buf
)
4638 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4642 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
4644 struct comp_unit_head
*cu_header
= &cu
->header
;
4645 CORE_ADDR retval
= 0;
4647 if (cu_header
->signed_addr_p
)
4649 switch (cu_header
->addr_size
)
4652 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4655 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4658 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4661 internal_error (__FILE__
, __LINE__
,
4662 "read_address: bad switch, signed [in module %s]",
4663 bfd_get_filename (abfd
));
4668 switch (cu_header
->addr_size
)
4671 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4674 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4677 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4680 internal_error (__FILE__
, __LINE__
,
4681 "read_address: bad switch, unsigned [in module %s]",
4682 bfd_get_filename (abfd
));
4686 *bytes_read
= cu_header
->addr_size
;
4690 /* Read the initial length from a section. The (draft) DWARF 3
4691 specification allows the initial length to take up either 4 bytes
4692 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4693 bytes describe the length and all offsets will be 8 bytes in length
4696 An older, non-standard 64-bit format is also handled by this
4697 function. The older format in question stores the initial length
4698 as an 8-byte quantity without an escape value. Lengths greater
4699 than 2^32 aren't very common which means that the initial 4 bytes
4700 is almost always zero. Since a length value of zero doesn't make
4701 sense for the 32-bit format, this initial zero can be considered to
4702 be an escape value which indicates the presence of the older 64-bit
4703 format. As written, the code can't detect (old format) lengths
4704 greater than 4GB. If it becomes necessary to handle lengths somewhat
4705 larger than 4GB, we could allow other small values (such as the
4706 non-sensical values of 1, 2, and 3) to also be used as escape values
4707 indicating the presence of the old format.
4709 The value returned via bytes_read should be used to increment
4710 the relevant pointer after calling read_initial_length().
4712 As a side effect, this function sets the fields initial_length_size
4713 and offset_size in cu_header to the values appropriate for the
4714 length field. (The format of the initial length field determines
4715 the width of file offsets to be fetched later with fetch_offset().)
4717 [ Note: read_initial_length() and read_offset() are based on the
4718 document entitled "DWARF Debugging Information Format", revision
4719 3, draft 8, dated November 19, 2001. This document was obtained
4722 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4724 This document is only a draft and is subject to change. (So beware.)
4726 Details regarding the older, non-standard 64-bit format were
4727 determined empirically by examining 64-bit ELF files produced
4728 by the SGI toolchain on an IRIX 6.5 machine.
4730 - Kevin, July 16, 2002
4734 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4739 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4741 if (retval
== 0xffffffff)
4743 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4745 if (cu_header
!= NULL
)
4747 cu_header
->initial_length_size
= 12;
4748 cu_header
->offset_size
= 8;
4751 else if (retval
== 0)
4753 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4755 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4757 if (cu_header
!= NULL
)
4759 cu_header
->initial_length_size
= 8;
4760 cu_header
->offset_size
= 8;
4766 if (cu_header
!= NULL
)
4768 cu_header
->initial_length_size
= 4;
4769 cu_header
->offset_size
= 4;
4776 /* Read an offset from the data stream. The size of the offset is
4777 given by cu_header->offset_size. */
4780 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4785 switch (cu_header
->offset_size
)
4788 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4792 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4796 internal_error (__FILE__
, __LINE__
,
4797 "read_offset: bad switch [in module %s]",
4798 bfd_get_filename (abfd
));
4805 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4807 /* If the size of a host char is 8 bits, we can return a pointer
4808 to the buffer, otherwise we have to copy the data to a buffer
4809 allocated on the temporary obstack. */
4810 gdb_assert (HOST_CHAR_BIT
== 8);
4815 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4817 /* If the size of a host char is 8 bits, we can return a pointer
4818 to the string, otherwise we have to copy the string to a buffer
4819 allocated on the temporary obstack. */
4820 gdb_assert (HOST_CHAR_BIT
== 8);
4823 *bytes_read_ptr
= 1;
4826 *bytes_read_ptr
= strlen (buf
) + 1;
4831 read_indirect_string (bfd
*abfd
, char *buf
,
4832 const struct comp_unit_head
*cu_header
,
4833 unsigned int *bytes_read_ptr
)
4835 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4836 (int *) bytes_read_ptr
);
4838 if (dwarf_str_buffer
== NULL
)
4840 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4841 bfd_get_filename (abfd
));
4844 if (str_offset
>= dwarf_str_size
)
4846 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4847 bfd_get_filename (abfd
));
4850 gdb_assert (HOST_CHAR_BIT
== 8);
4851 if (dwarf_str_buffer
[str_offset
] == '\0')
4853 return dwarf_str_buffer
+ str_offset
;
4856 static unsigned long
4857 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4859 unsigned long result
;
4860 unsigned int num_read
;
4870 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4873 result
|= ((unsigned long)(byte
& 127) << shift
);
4874 if ((byte
& 128) == 0)
4880 *bytes_read_ptr
= num_read
;
4885 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4888 int i
, shift
, size
, num_read
;
4898 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4901 result
|= ((long)(byte
& 127) << shift
);
4903 if ((byte
& 128) == 0)
4908 if ((shift
< size
) && (byte
& 0x40))
4910 result
|= -(1 << shift
);
4912 *bytes_read_ptr
= num_read
;
4917 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
4923 cu
->language
= language_c
;
4925 case DW_LANG_C_plus_plus
:
4926 cu
->language
= language_cplus
;
4928 case DW_LANG_Fortran77
:
4929 case DW_LANG_Fortran90
:
4930 case DW_LANG_Fortran95
:
4931 cu
->language
= language_fortran
;
4933 case DW_LANG_Mips_Assembler
:
4934 cu
->language
= language_asm
;
4937 cu
->language
= language_java
;
4941 case DW_LANG_Cobol74
:
4942 case DW_LANG_Cobol85
:
4943 case DW_LANG_Pascal83
:
4944 case DW_LANG_Modula2
:
4946 cu
->language
= language_minimal
;
4949 cu
->language_defn
= language_def (cu
->language
);
4952 /* Return the named attribute or NULL if not there. */
4954 static struct attribute
*
4955 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
4958 struct attribute
*spec
= NULL
;
4960 for (i
= 0; i
< die
->num_attrs
; ++i
)
4962 if (die
->attrs
[i
].name
== name
)
4964 return &die
->attrs
[i
];
4966 if (die
->attrs
[i
].name
== DW_AT_specification
4967 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4968 spec
= &die
->attrs
[i
];
4972 struct die_info
*ref_die
=
4973 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
4976 return dwarf2_attr (ref_die
, name
, cu
);
4983 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
4985 return (dwarf2_attr (die
, DW_AT_declaration
, cu
)
4986 && ! dwarf2_attr (die
, DW_AT_specification
, cu
));
4989 /* Return the die giving the specification for DIE, if there is
4992 static struct die_info
*
4993 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
4995 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
4997 if (spec_attr
== NULL
)
5000 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
5003 /* Free the line_header structure *LH, and any arrays and strings it
5006 free_line_header (struct line_header
*lh
)
5008 if (lh
->standard_opcode_lengths
)
5009 xfree (lh
->standard_opcode_lengths
);
5011 /* Remember that all the lh->file_names[i].name pointers are
5012 pointers into debug_line_buffer, and don't need to be freed. */
5014 xfree (lh
->file_names
);
5016 /* Similarly for the include directory names. */
5017 if (lh
->include_dirs
)
5018 xfree (lh
->include_dirs
);
5024 /* Add an entry to LH's include directory table. */
5026 add_include_dir (struct line_header
*lh
, char *include_dir
)
5028 /* Grow the array if necessary. */
5029 if (lh
->include_dirs_size
== 0)
5031 lh
->include_dirs_size
= 1; /* for testing */
5032 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
5033 * sizeof (*lh
->include_dirs
));
5035 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
5037 lh
->include_dirs_size
*= 2;
5038 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
5039 (lh
->include_dirs_size
5040 * sizeof (*lh
->include_dirs
)));
5043 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
5047 /* Add an entry to LH's file name table. */
5049 add_file_name (struct line_header
*lh
,
5051 unsigned int dir_index
,
5052 unsigned int mod_time
,
5053 unsigned int length
)
5055 struct file_entry
*fe
;
5057 /* Grow the array if necessary. */
5058 if (lh
->file_names_size
== 0)
5060 lh
->file_names_size
= 1; /* for testing */
5061 lh
->file_names
= xmalloc (lh
->file_names_size
5062 * sizeof (*lh
->file_names
));
5064 else if (lh
->num_file_names
>= lh
->file_names_size
)
5066 lh
->file_names_size
*= 2;
5067 lh
->file_names
= xrealloc (lh
->file_names
,
5068 (lh
->file_names_size
5069 * sizeof (*lh
->file_names
)));
5072 fe
= &lh
->file_names
[lh
->num_file_names
++];
5074 fe
->dir_index
= dir_index
;
5075 fe
->mod_time
= mod_time
;
5076 fe
->length
= length
;
5080 /* Read the statement program header starting at OFFSET in
5081 dwarf_line_buffer, according to the endianness of ABFD. Return a
5082 pointer to a struct line_header, allocated using xmalloc.
5084 NOTE: the strings in the include directory and file name tables of
5085 the returned object point into debug_line_buffer, and must not be
5087 static struct line_header
*
5088 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
5089 struct dwarf2_cu
*cu
)
5091 struct cleanup
*back_to
;
5092 struct line_header
*lh
;
5096 char *cur_dir
, *cur_file
;
5098 if (dwarf_line_buffer
== NULL
)
5100 complaint (&symfile_complaints
, "missing .debug_line section");
5104 /* Make sure that at least there's room for the total_length field. That
5105 could be 12 bytes long, but we're just going to fudge that. */
5106 if (offset
+ 4 >= dwarf_line_size
)
5108 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5112 lh
= xmalloc (sizeof (*lh
));
5113 memset (lh
, 0, sizeof (*lh
));
5114 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
5117 line_ptr
= dwarf_line_buffer
+ offset
;
5119 /* read in the header */
5120 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
5121 line_ptr
+= bytes_read
;
5122 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
5124 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5127 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
5128 lh
->version
= read_2_bytes (abfd
, line_ptr
);
5130 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
5131 line_ptr
+= bytes_read
;
5132 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
5134 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
5136 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
5138 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
5140 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
5142 lh
->standard_opcode_lengths
5143 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
5145 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
5146 for (i
= 1; i
< lh
->opcode_base
; ++i
)
5148 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
5152 /* Read directory table */
5153 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5155 line_ptr
+= bytes_read
;
5156 add_include_dir (lh
, cur_dir
);
5158 line_ptr
+= bytes_read
;
5160 /* Read file name table */
5161 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
5163 unsigned int dir_index
, mod_time
, length
;
5165 line_ptr
+= bytes_read
;
5166 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5167 line_ptr
+= bytes_read
;
5168 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5169 line_ptr
+= bytes_read
;
5170 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5171 line_ptr
+= bytes_read
;
5173 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5175 line_ptr
+= bytes_read
;
5176 lh
->statement_program_start
= line_ptr
;
5178 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
5179 complaint (&symfile_complaints
,
5180 "line number info header doesn't fit in `.debug_line' section");
5182 discard_cleanups (back_to
);
5186 /* This function exists to work around a bug in certain compilers
5187 (particularly GCC 2.95), in which the first line number marker of a
5188 function does not show up until after the prologue, right before
5189 the second line number marker. This function shifts ADDRESS down
5190 to the beginning of the function if necessary, and is called on
5191 addresses passed to record_line. */
5194 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
5196 struct function_range
*fn
;
5198 /* Find the function_range containing address. */
5203 cu
->cached_fn
= cu
->first_fn
;
5207 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5213 while (fn
&& fn
!= cu
->cached_fn
)
5214 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
5224 if (address
!= fn
->lowpc
)
5225 complaint (&symfile_complaints
,
5226 "misplaced first line number at 0x%lx for '%s'",
5227 (unsigned long) address
, fn
->name
);
5232 /* Decode the line number information for the compilation unit whose
5233 line number info is at OFFSET in the .debug_line section.
5234 The compilation directory of the file is passed in COMP_DIR. */
5237 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
5238 struct dwarf2_cu
*cu
)
5242 unsigned int bytes_read
;
5243 unsigned char op_code
, extended_op
, adj_opcode
;
5245 struct objfile
*objfile
= cu
->objfile
;
5247 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5249 line_ptr
= lh
->statement_program_start
;
5250 line_end
= lh
->statement_program_end
;
5252 /* Read the statement sequences until there's nothing left. */
5253 while (line_ptr
< line_end
)
5255 /* state machine registers */
5256 CORE_ADDR address
= 0;
5257 unsigned int file
= 1;
5258 unsigned int line
= 1;
5259 unsigned int column
= 0;
5260 int is_stmt
= lh
->default_is_stmt
;
5261 int basic_block
= 0;
5262 int end_sequence
= 0;
5264 /* Start a subfile for the current file of the state machine. */
5265 if (lh
->num_file_names
>= file
)
5267 /* lh->include_dirs and lh->file_names are 0-based, but the
5268 directory and file name numbers in the statement program
5270 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
5273 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5276 dwarf2_start_subfile (fe
->name
, dir
);
5279 /* Decode the table. */
5280 while (!end_sequence
)
5282 op_code
= read_1_byte (abfd
, line_ptr
);
5285 if (op_code
>= lh
->opcode_base
)
5286 { /* Special operand. */
5287 adj_opcode
= op_code
- lh
->opcode_base
;
5288 address
+= (adj_opcode
/ lh
->line_range
)
5289 * lh
->minimum_instruction_length
;
5290 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
5291 /* append row to matrix using current values */
5292 record_line (current_subfile
, line
,
5293 check_cu_functions (address
, cu
));
5296 else switch (op_code
)
5298 case DW_LNS_extended_op
:
5299 line_ptr
+= 1; /* ignore length */
5300 extended_op
= read_1_byte (abfd
, line_ptr
);
5302 switch (extended_op
)
5304 case DW_LNE_end_sequence
:
5306 record_line (current_subfile
, 0, address
);
5308 case DW_LNE_set_address
:
5309 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
5310 line_ptr
+= bytes_read
;
5311 address
+= baseaddr
;
5313 case DW_LNE_define_file
:
5316 unsigned int dir_index
, mod_time
, length
;
5318 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
5319 line_ptr
+= bytes_read
;
5321 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5322 line_ptr
+= bytes_read
;
5324 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5325 line_ptr
+= bytes_read
;
5327 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5328 line_ptr
+= bytes_read
;
5329 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
5333 complaint (&symfile_complaints
,
5334 "mangled .debug_line section");
5339 record_line (current_subfile
, line
,
5340 check_cu_functions (address
, cu
));
5343 case DW_LNS_advance_pc
:
5344 address
+= lh
->minimum_instruction_length
5345 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5346 line_ptr
+= bytes_read
;
5348 case DW_LNS_advance_line
:
5349 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
5350 line_ptr
+= bytes_read
;
5352 case DW_LNS_set_file
:
5354 /* lh->include_dirs and lh->file_names are 0-based,
5355 but the directory and file name numbers in the
5356 statement program are 1-based. */
5357 struct file_entry
*fe
;
5359 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5360 line_ptr
+= bytes_read
;
5361 fe
= &lh
->file_names
[file
- 1];
5363 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
5366 dwarf2_start_subfile (fe
->name
, dir
);
5369 case DW_LNS_set_column
:
5370 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5371 line_ptr
+= bytes_read
;
5373 case DW_LNS_negate_stmt
:
5374 is_stmt
= (!is_stmt
);
5376 case DW_LNS_set_basic_block
:
5379 /* Add to the address register of the state machine the
5380 address increment value corresponding to special opcode
5381 255. Ie, this value is scaled by the minimum instruction
5382 length since special opcode 255 would have scaled the
5384 case DW_LNS_const_add_pc
:
5385 address
+= (lh
->minimum_instruction_length
5386 * ((255 - lh
->opcode_base
) / lh
->line_range
));
5388 case DW_LNS_fixed_advance_pc
:
5389 address
+= read_2_bytes (abfd
, line_ptr
);
5393 { /* Unknown standard opcode, ignore it. */
5395 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
5397 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
5398 line_ptr
+= bytes_read
;
5406 /* Start a subfile for DWARF. FILENAME is the name of the file and
5407 DIRNAME the name of the source directory which contains FILENAME
5408 or NULL if not known.
5409 This routine tries to keep line numbers from identical absolute and
5410 relative file names in a common subfile.
5412 Using the `list' example from the GDB testsuite, which resides in
5413 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5414 of /srcdir/list0.c yields the following debugging information for list0.c:
5416 DW_AT_name: /srcdir/list0.c
5417 DW_AT_comp_dir: /compdir
5418 files.files[0].name: list0.h
5419 files.files[0].dir: /srcdir
5420 files.files[1].name: list0.c
5421 files.files[1].dir: /srcdir
5423 The line number information for list0.c has to end up in a single
5424 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5427 dwarf2_start_subfile (char *filename
, char *dirname
)
5429 /* If the filename isn't absolute, try to match an existing subfile
5430 with the full pathname. */
5432 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
5434 struct subfile
*subfile
;
5435 char *fullname
= concat (dirname
, "/", filename
, NULL
);
5437 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
5439 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
5441 current_subfile
= subfile
;
5448 start_subfile (filename
, dirname
);
5452 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
5453 struct dwarf2_cu
*cu
)
5455 struct objfile
*objfile
= cu
->objfile
;
5456 struct comp_unit_head
*cu_header
= &cu
->header
;
5458 /* NOTE drow/2003-01-30: There used to be a comment and some special
5459 code here to turn a symbol with DW_AT_external and a
5460 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5461 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5462 with some versions of binutils) where shared libraries could have
5463 relocations against symbols in their debug information - the
5464 minimal symbol would have the right address, but the debug info
5465 would not. It's no longer necessary, because we will explicitly
5466 apply relocations when we read in the debug information now. */
5468 /* A DW_AT_location attribute with no contents indicates that a
5469 variable has been optimized away. */
5470 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
5472 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5476 /* Handle one degenerate form of location expression specially, to
5477 preserve GDB's previous behavior when section offsets are
5478 specified. If this is just a DW_OP_addr then mark this symbol
5481 if (attr_form_is_block (attr
)
5482 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
5483 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
5487 SYMBOL_VALUE_ADDRESS (sym
) =
5488 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
5489 fixup_symbol_section (sym
, objfile
);
5490 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
5491 SYMBOL_SECTION (sym
));
5492 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5496 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5497 expression evaluator, and use LOC_COMPUTED only when necessary
5498 (i.e. when the value of a register or memory location is
5499 referenced, or a thread-local block, etc.). Then again, it might
5500 not be worthwhile. I'm assuming that it isn't unless performance
5501 or memory numbers show me otherwise. */
5503 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
5504 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
5507 /* Given a pointer to a DWARF information entry, figure out if we need
5508 to make a symbol table entry for it, and if so, create a new entry
5509 and return a pointer to it.
5510 If TYPE is NULL, determine symbol type from the die, otherwise
5511 used the passed type. */
5513 static struct symbol
*
5514 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
5516 struct objfile
*objfile
= cu
->objfile
;
5517 struct symbol
*sym
= NULL
;
5519 struct attribute
*attr
= NULL
;
5520 struct attribute
*attr2
= NULL
;
5523 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5525 if (die
->tag
!= DW_TAG_namespace
)
5526 name
= dwarf2_linkage_name (die
, cu
);
5528 name
= TYPE_NAME (type
);
5532 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
5533 sizeof (struct symbol
));
5534 OBJSTAT (objfile
, n_syms
++);
5535 memset (sym
, 0, sizeof (struct symbol
));
5537 /* Cache this symbol's name and the name's demangled form (if any). */
5538 SYMBOL_LANGUAGE (sym
) = cu
->language
;
5539 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
5541 /* Default assumptions.
5542 Use the passed type or decode it from the die. */
5543 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5544 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5546 SYMBOL_TYPE (sym
) = type
;
5548 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
5549 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
5552 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
5557 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5560 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
5562 SYMBOL_CLASS (sym
) = LOC_LABEL
;
5564 case DW_TAG_subprogram
:
5565 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5567 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
5568 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5569 if (attr2
&& (DW_UNSND (attr2
) != 0))
5571 add_symbol_to_list (sym
, &global_symbols
);
5575 add_symbol_to_list (sym
, cu
->list_in_scope
);
5578 case DW_TAG_variable
:
5579 /* Compilation with minimal debug info may result in variables
5580 with missing type entries. Change the misleading `void' type
5581 to something sensible. */
5582 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
5583 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
5584 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
5585 "<variable, no debug info>",
5587 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5590 dwarf2_const_value (attr
, sym
, cu
);
5591 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5592 if (attr2
&& (DW_UNSND (attr2
) != 0))
5593 add_symbol_to_list (sym
, &global_symbols
);
5595 add_symbol_to_list (sym
, cu
->list_in_scope
);
5598 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5601 var_decode_location (attr
, sym
, cu
);
5602 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5603 if (attr2
&& (DW_UNSND (attr2
) != 0))
5604 add_symbol_to_list (sym
, &global_symbols
);
5606 add_symbol_to_list (sym
, cu
->list_in_scope
);
5610 /* We do not know the address of this symbol.
5611 If it is an external symbol and we have type information
5612 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5613 The address of the variable will then be determined from
5614 the minimal symbol table whenever the variable is
5616 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
5617 if (attr2
&& (DW_UNSND (attr2
) != 0)
5618 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
5620 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5621 add_symbol_to_list (sym
, &global_symbols
);
5625 case DW_TAG_formal_parameter
:
5626 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5629 var_decode_location (attr
, sym
, cu
);
5630 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5631 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
5632 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
5634 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5637 dwarf2_const_value (attr
, sym
, cu
);
5639 add_symbol_to_list (sym
, cu
->list_in_scope
);
5641 case DW_TAG_unspecified_parameters
:
5642 /* From varargs functions; gdb doesn't seem to have any
5643 interest in this information, so just ignore it for now.
5646 case DW_TAG_class_type
:
5647 case DW_TAG_structure_type
:
5648 case DW_TAG_union_type
:
5649 case DW_TAG_enumeration_type
:
5650 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5651 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5653 /* Make sure that the symbol includes appropriate enclosing
5654 classes/namespaces in its name. These are calculated in
5655 read_structure_scope, and the correct name is saved in
5658 if (cu
->language
== language_cplus
)
5660 struct type
*type
= SYMBOL_TYPE (sym
);
5662 if (TYPE_TAG_NAME (type
) != NULL
)
5664 /* FIXME: carlton/2003-11-10: Should this use
5665 SYMBOL_SET_NAMES instead? (The same problem also
5666 arises a further down in the function.) */
5667 SYMBOL_LINKAGE_NAME (sym
)
5668 = obsavestring (TYPE_TAG_NAME (type
),
5669 strlen (TYPE_TAG_NAME (type
)),
5670 &objfile
->symbol_obstack
);
5675 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5676 really ever be static objects: otherwise, if you try
5677 to, say, break of a class's method and you're in a file
5678 which doesn't mention that class, it won't work unless
5679 the check for all static symbols in lookup_symbol_aux
5680 saves you. See the OtherFileClass tests in
5681 gdb.c++/namespace.exp. */
5683 struct pending
**list_to_add
;
5685 list_to_add
= (cu
->list_in_scope
== &file_symbols
5686 && cu
->language
== language_cplus
5687 ? &global_symbols
: cu
->list_in_scope
);
5689 add_symbol_to_list (sym
, list_to_add
);
5691 /* The semantics of C++ state that "struct foo { ... }" also
5692 defines a typedef for "foo". Synthesize a typedef symbol so
5693 that "ptype foo" works as expected. */
5694 if (cu
->language
== language_cplus
)
5696 struct symbol
*typedef_sym
= (struct symbol
*)
5697 obstack_alloc (&objfile
->symbol_obstack
,
5698 sizeof (struct symbol
));
5699 *typedef_sym
= *sym
;
5700 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
5701 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5702 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5703 obsavestring (SYMBOL_NATURAL_NAME (sym
),
5704 strlen (SYMBOL_NATURAL_NAME (sym
)),
5705 &objfile
->type_obstack
);
5706 add_symbol_to_list (typedef_sym
, list_to_add
);
5710 case DW_TAG_typedef
:
5711 if (processing_has_namespace_info
5712 && processing_current_prefix
[0] != '\0')
5714 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->symbol_obstack
,
5715 processing_current_prefix
,
5719 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5720 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5721 add_symbol_to_list (sym
, cu
->list_in_scope
);
5723 case DW_TAG_base_type
:
5724 case DW_TAG_subrange_type
:
5725 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5726 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
5727 add_symbol_to_list (sym
, cu
->list_in_scope
);
5729 case DW_TAG_enumerator
:
5730 if (processing_has_namespace_info
5731 && processing_current_prefix
[0] != '\0')
5733 SYMBOL_LINKAGE_NAME (sym
) = obconcat (&objfile
->symbol_obstack
,
5734 processing_current_prefix
,
5738 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5741 dwarf2_const_value (attr
, sym
, cu
);
5744 /* NOTE: carlton/2003-11-10: See comment above in the
5745 DW_TAG_class_type, etc. block. */
5747 struct pending
**list_to_add
;
5749 list_to_add
= (cu
->list_in_scope
== &file_symbols
5750 && cu
->language
== language_cplus
5751 ? &global_symbols
: cu
->list_in_scope
);
5753 add_symbol_to_list (sym
, list_to_add
);
5756 case DW_TAG_namespace
:
5757 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5758 add_symbol_to_list (sym
, &global_symbols
);
5761 /* Not a tag we recognize. Hopefully we aren't processing
5762 trash data, but since we must specifically ignore things
5763 we don't recognize, there is nothing else we should do at
5765 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5766 dwarf_tag_name (die
->tag
));
5773 /* Copy constant value from an attribute to a symbol. */
5776 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5777 struct dwarf2_cu
*cu
)
5779 struct objfile
*objfile
= cu
->objfile
;
5780 struct comp_unit_head
*cu_header
= &cu
->header
;
5781 struct dwarf_block
*blk
;
5786 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5787 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5788 cu_header
->addr_size
,
5789 TYPE_LENGTH (SYMBOL_TYPE
5791 SYMBOL_VALUE_BYTES (sym
) = (char *)
5792 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5793 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5794 it's body - store_unsigned_integer. */
5795 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5797 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5799 case DW_FORM_block1
:
5800 case DW_FORM_block2
:
5801 case DW_FORM_block4
:
5803 blk
= DW_BLOCK (attr
);
5804 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5805 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
5807 TYPE_LENGTH (SYMBOL_TYPE
5809 SYMBOL_VALUE_BYTES (sym
) = (char *)
5810 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5811 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5812 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5815 /* The DW_AT_const_value attributes are supposed to carry the
5816 symbol's value "represented as it would be on the target
5817 architecture." By the time we get here, it's already been
5818 converted to host endianness, so we just need to sign- or
5819 zero-extend it as appropriate. */
5821 dwarf2_const_value_data (attr
, sym
, 8);
5824 dwarf2_const_value_data (attr
, sym
, 16);
5827 dwarf2_const_value_data (attr
, sym
, 32);
5830 dwarf2_const_value_data (attr
, sym
, 64);
5834 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5835 SYMBOL_CLASS (sym
) = LOC_CONST
;
5839 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5840 SYMBOL_CLASS (sym
) = LOC_CONST
;
5844 complaint (&symfile_complaints
,
5845 "unsupported const value attribute form: '%s'",
5846 dwarf_form_name (attr
->form
));
5847 SYMBOL_VALUE (sym
) = 0;
5848 SYMBOL_CLASS (sym
) = LOC_CONST
;
5854 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5855 or zero-extend it as appropriate for the symbol's type. */
5857 dwarf2_const_value_data (struct attribute
*attr
,
5861 LONGEST l
= DW_UNSND (attr
);
5863 if (bits
< sizeof (l
) * 8)
5865 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5866 l
&= ((LONGEST
) 1 << bits
) - 1;
5868 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5871 SYMBOL_VALUE (sym
) = l
;
5872 SYMBOL_CLASS (sym
) = LOC_CONST
;
5876 /* Return the type of the die in question using its DW_AT_type attribute. */
5878 static struct type
*
5879 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5882 struct attribute
*type_attr
;
5883 struct die_info
*type_die
;
5886 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
5889 /* A missing DW_AT_type represents a void type. */
5890 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
5894 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
5895 type_die
= follow_die_ref (ref
);
5898 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5899 ref
, cu
->objfile
->name
);
5903 type
= tag_type_to_type (type_die
, cu
);
5906 dump_die (type_die
);
5907 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5913 /* Return the containing type of the die in question using its
5914 DW_AT_containing_type attribute. */
5916 static struct type
*
5917 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5919 struct type
*type
= NULL
;
5920 struct attribute
*type_attr
;
5921 struct die_info
*type_die
= NULL
;
5924 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
5927 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
5928 type_die
= follow_die_ref (ref
);
5931 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
5935 type
= tag_type_to_type (type_die
, cu
);
5940 dump_die (type_die
);
5941 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5948 static struct type
*
5949 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
5951 struct die_info
*die
;
5954 die
= follow_die_ref (offset
);
5957 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5960 type
= tag_type_to_type (die
, cu
);
5965 static struct type
*
5966 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5974 read_type_die (die
, cu
);
5978 error ("Dwarf Error: Cannot find type of die [in module %s]",
5986 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5988 char *prefix
= determine_prefix (die
, cu
);
5989 const char *old_prefix
= processing_current_prefix
;
5990 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
5991 processing_current_prefix
= prefix
;
5995 case DW_TAG_class_type
:
5996 case DW_TAG_structure_type
:
5997 case DW_TAG_union_type
:
5998 read_structure_scope (die
, cu
);
6000 case DW_TAG_enumeration_type
:
6001 read_enumeration (die
, cu
);
6003 case DW_TAG_subprogram
:
6004 case DW_TAG_subroutine_type
:
6005 read_subroutine_type (die
, cu
);
6007 case DW_TAG_array_type
:
6008 read_array_type (die
, cu
);
6010 case DW_TAG_pointer_type
:
6011 read_tag_pointer_type (die
, cu
);
6013 case DW_TAG_ptr_to_member_type
:
6014 read_tag_ptr_to_member_type (die
, cu
);
6016 case DW_TAG_reference_type
:
6017 read_tag_reference_type (die
, cu
);
6019 case DW_TAG_const_type
:
6020 read_tag_const_type (die
, cu
);
6022 case DW_TAG_volatile_type
:
6023 read_tag_volatile_type (die
, cu
);
6025 case DW_TAG_string_type
:
6026 read_tag_string_type (die
, cu
);
6028 case DW_TAG_typedef
:
6029 read_typedef (die
, cu
);
6031 case DW_TAG_subrange_type
:
6032 read_subrange_type (die
, cu
);
6034 case DW_TAG_base_type
:
6035 read_base_type (die
, cu
);
6038 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
6039 dwarf_tag_name (die
->tag
));
6043 processing_current_prefix
= old_prefix
;
6044 do_cleanups (back_to
);
6047 /* Return the name of the namespace/class that DIE is defined within,
6048 or "" if we can't tell. The caller should xfree the result. */
6050 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6051 therein) for an example of how to use this function to deal with
6052 DW_AT_specification. */
6055 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
6057 char *prefix
= determine_prefix_aux (die
, cu
);
6059 return prefix
? prefix
: xstrdup ("");
6062 /* Return the name of the namespace/class that DIE is defined
6063 within, or NULL if we can't tell. The caller should xfree the
6067 determine_prefix_aux (struct die_info
*die
, struct dwarf2_cu
*cu
)
6069 struct die_info
*parent
;
6071 if (cu
->language
!= language_cplus
)
6074 parent
= die
->parent
;
6078 return (processing_has_namespace_info
? xstrdup ("") : NULL
);
6082 char *parent_prefix
= determine_prefix_aux (parent
, cu
);
6085 switch (parent
->tag
) {
6086 case DW_TAG_namespace
:
6090 retval
= typename_concat (parent_prefix
,
6091 namespace_name (parent
, &dummy
, cu
));
6094 case DW_TAG_class_type
:
6095 case DW_TAG_structure_type
:
6097 if (parent_prefix
!= NULL
)
6099 const char *parent_name
= dwarf2_name (parent
, cu
);
6101 if (parent_name
!= NULL
)
6102 retval
= typename_concat (parent_prefix
, dwarf2_name (parent
, cu
));
6104 /* FIXME: carlton/2003-11-10: I'm not sure what the
6105 best thing to do here is. */
6106 retval
= typename_concat (parent_prefix
,
6107 "<<anonymous class>>");
6110 retval
= class_name (parent
, cu
);
6114 retval
= parent_prefix
;
6118 if (retval
!= parent_prefix
)
6119 xfree (parent_prefix
);
6124 /* Return a newly-allocated string formed by concatenating PREFIX,
6125 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6126 string, just return a copy of SUFFIX. */
6129 typename_concat (const char *prefix
, const char *suffix
)
6131 if (prefix
== NULL
|| prefix
[0] == '\0')
6132 return xstrdup (suffix
);
6135 char *retval
= xmalloc (strlen (prefix
) + 2 + strlen (suffix
) + 1);
6137 strcpy (retval
, prefix
);
6138 strcat (retval
, "::");
6139 strcat (retval
, suffix
);
6145 /* Return a newly-allocated string giving the name of the class given
6149 class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6151 struct die_info
*child
;
6154 for (child
= die
->child
; child
!= NULL
; child
= sibling_die (child
))
6156 if (child
->tag
== DW_TAG_subprogram
)
6157 return class_name_from_physname (dwarf2_linkage_name (child
, cu
));
6160 name
= dwarf2_name (die
, cu
);
6162 return xstrdup (name
);
6164 return xstrdup ("");
6167 static struct type
*
6168 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
6170 struct objfile
*objfile
= cu
->objfile
;
6172 /* FIXME - this should not produce a new (struct type *)
6173 every time. It should cache base types. */
6177 case DW_ATE_address
:
6178 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
6180 case DW_ATE_boolean
:
6181 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
6183 case DW_ATE_complex_float
:
6186 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
6190 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
6196 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
6200 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
6207 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6210 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
6214 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6218 case DW_ATE_signed_char
:
6219 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
6221 case DW_ATE_unsigned
:
6225 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6228 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
6232 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
6236 case DW_ATE_unsigned_char
:
6237 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
6240 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
6247 copy_die (struct die_info
*old_die
)
6249 struct die_info
*new_die
;
6252 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6253 memset (new_die
, 0, sizeof (struct die_info
));
6255 new_die
->tag
= old_die
->tag
;
6256 new_die
->has_children
= old_die
->has_children
;
6257 new_die
->abbrev
= old_die
->abbrev
;
6258 new_die
->offset
= old_die
->offset
;
6259 new_die
->type
= NULL
;
6261 num_attrs
= old_die
->num_attrs
;
6262 new_die
->num_attrs
= num_attrs
;
6263 new_die
->attrs
= (struct attribute
*)
6264 xmalloc (num_attrs
* sizeof (struct attribute
));
6266 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
6268 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
6269 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
6270 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
6273 new_die
->next
= NULL
;
6278 /* Return sibling of die, NULL if no sibling. */
6280 static struct die_info
*
6281 sibling_die (struct die_info
*die
)
6283 return die
->sibling
;
6286 /* Get linkage name of a die, return NULL if not found. */
6289 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6291 struct attribute
*attr
;
6293 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6294 if (attr
&& DW_STRING (attr
))
6295 return DW_STRING (attr
);
6296 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6297 if (attr
&& DW_STRING (attr
))
6298 return DW_STRING (attr
);
6302 /* Get name of a die, return NULL if not found. */
6305 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6307 struct attribute
*attr
;
6309 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6310 if (attr
&& DW_STRING (attr
))
6311 return DW_STRING (attr
);
6315 /* Return the die that this die in an extension of, or NULL if there
6318 static struct die_info
*
6319 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
6321 struct attribute
*attr
;
6322 struct die_info
*extension_die
;
6325 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
6329 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
6330 extension_die
= follow_die_ref (ref
);
6333 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
6336 return extension_die
;
6339 /* Convert a DIE tag into its string name. */
6342 dwarf_tag_name (unsigned tag
)
6346 case DW_TAG_padding
:
6347 return "DW_TAG_padding";
6348 case DW_TAG_array_type
:
6349 return "DW_TAG_array_type";
6350 case DW_TAG_class_type
:
6351 return "DW_TAG_class_type";
6352 case DW_TAG_entry_point
:
6353 return "DW_TAG_entry_point";
6354 case DW_TAG_enumeration_type
:
6355 return "DW_TAG_enumeration_type";
6356 case DW_TAG_formal_parameter
:
6357 return "DW_TAG_formal_parameter";
6358 case DW_TAG_imported_declaration
:
6359 return "DW_TAG_imported_declaration";
6361 return "DW_TAG_label";
6362 case DW_TAG_lexical_block
:
6363 return "DW_TAG_lexical_block";
6365 return "DW_TAG_member";
6366 case DW_TAG_pointer_type
:
6367 return "DW_TAG_pointer_type";
6368 case DW_TAG_reference_type
:
6369 return "DW_TAG_reference_type";
6370 case DW_TAG_compile_unit
:
6371 return "DW_TAG_compile_unit";
6372 case DW_TAG_string_type
:
6373 return "DW_TAG_string_type";
6374 case DW_TAG_structure_type
:
6375 return "DW_TAG_structure_type";
6376 case DW_TAG_subroutine_type
:
6377 return "DW_TAG_subroutine_type";
6378 case DW_TAG_typedef
:
6379 return "DW_TAG_typedef";
6380 case DW_TAG_union_type
:
6381 return "DW_TAG_union_type";
6382 case DW_TAG_unspecified_parameters
:
6383 return "DW_TAG_unspecified_parameters";
6384 case DW_TAG_variant
:
6385 return "DW_TAG_variant";
6386 case DW_TAG_common_block
:
6387 return "DW_TAG_common_block";
6388 case DW_TAG_common_inclusion
:
6389 return "DW_TAG_common_inclusion";
6390 case DW_TAG_inheritance
:
6391 return "DW_TAG_inheritance";
6392 case DW_TAG_inlined_subroutine
:
6393 return "DW_TAG_inlined_subroutine";
6395 return "DW_TAG_module";
6396 case DW_TAG_ptr_to_member_type
:
6397 return "DW_TAG_ptr_to_member_type";
6398 case DW_TAG_set_type
:
6399 return "DW_TAG_set_type";
6400 case DW_TAG_subrange_type
:
6401 return "DW_TAG_subrange_type";
6402 case DW_TAG_with_stmt
:
6403 return "DW_TAG_with_stmt";
6404 case DW_TAG_access_declaration
:
6405 return "DW_TAG_access_declaration";
6406 case DW_TAG_base_type
:
6407 return "DW_TAG_base_type";
6408 case DW_TAG_catch_block
:
6409 return "DW_TAG_catch_block";
6410 case DW_TAG_const_type
:
6411 return "DW_TAG_const_type";
6412 case DW_TAG_constant
:
6413 return "DW_TAG_constant";
6414 case DW_TAG_enumerator
:
6415 return "DW_TAG_enumerator";
6416 case DW_TAG_file_type
:
6417 return "DW_TAG_file_type";
6419 return "DW_TAG_friend";
6420 case DW_TAG_namelist
:
6421 return "DW_TAG_namelist";
6422 case DW_TAG_namelist_item
:
6423 return "DW_TAG_namelist_item";
6424 case DW_TAG_packed_type
:
6425 return "DW_TAG_packed_type";
6426 case DW_TAG_subprogram
:
6427 return "DW_TAG_subprogram";
6428 case DW_TAG_template_type_param
:
6429 return "DW_TAG_template_type_param";
6430 case DW_TAG_template_value_param
:
6431 return "DW_TAG_template_value_param";
6432 case DW_TAG_thrown_type
:
6433 return "DW_TAG_thrown_type";
6434 case DW_TAG_try_block
:
6435 return "DW_TAG_try_block";
6436 case DW_TAG_variant_part
:
6437 return "DW_TAG_variant_part";
6438 case DW_TAG_variable
:
6439 return "DW_TAG_variable";
6440 case DW_TAG_volatile_type
:
6441 return "DW_TAG_volatile_type";
6442 case DW_TAG_dwarf_procedure
:
6443 return "DW_TAG_dwarf_procedure";
6444 case DW_TAG_restrict_type
:
6445 return "DW_TAG_restrict_type";
6446 case DW_TAG_interface_type
:
6447 return "DW_TAG_interface_type";
6448 case DW_TAG_namespace
:
6449 return "DW_TAG_namespace";
6450 case DW_TAG_imported_module
:
6451 return "DW_TAG_imported_module";
6452 case DW_TAG_unspecified_type
:
6453 return "DW_TAG_unspecified_type";
6454 case DW_TAG_partial_unit
:
6455 return "DW_TAG_partial_unit";
6456 case DW_TAG_imported_unit
:
6457 return "DW_TAG_imported_unit";
6458 case DW_TAG_MIPS_loop
:
6459 return "DW_TAG_MIPS_loop";
6460 case DW_TAG_format_label
:
6461 return "DW_TAG_format_label";
6462 case DW_TAG_function_template
:
6463 return "DW_TAG_function_template";
6464 case DW_TAG_class_template
:
6465 return "DW_TAG_class_template";
6467 return "DW_TAG_<unknown>";
6471 /* Convert a DWARF attribute code into its string name. */
6474 dwarf_attr_name (unsigned attr
)
6479 return "DW_AT_sibling";
6480 case DW_AT_location
:
6481 return "DW_AT_location";
6483 return "DW_AT_name";
6484 case DW_AT_ordering
:
6485 return "DW_AT_ordering";
6486 case DW_AT_subscr_data
:
6487 return "DW_AT_subscr_data";
6488 case DW_AT_byte_size
:
6489 return "DW_AT_byte_size";
6490 case DW_AT_bit_offset
:
6491 return "DW_AT_bit_offset";
6492 case DW_AT_bit_size
:
6493 return "DW_AT_bit_size";
6494 case DW_AT_element_list
:
6495 return "DW_AT_element_list";
6496 case DW_AT_stmt_list
:
6497 return "DW_AT_stmt_list";
6499 return "DW_AT_low_pc";
6501 return "DW_AT_high_pc";
6502 case DW_AT_language
:
6503 return "DW_AT_language";
6505 return "DW_AT_member";
6507 return "DW_AT_discr";
6508 case DW_AT_discr_value
:
6509 return "DW_AT_discr_value";
6510 case DW_AT_visibility
:
6511 return "DW_AT_visibility";
6513 return "DW_AT_import";
6514 case DW_AT_string_length
:
6515 return "DW_AT_string_length";
6516 case DW_AT_common_reference
:
6517 return "DW_AT_common_reference";
6518 case DW_AT_comp_dir
:
6519 return "DW_AT_comp_dir";
6520 case DW_AT_const_value
:
6521 return "DW_AT_const_value";
6522 case DW_AT_containing_type
:
6523 return "DW_AT_containing_type";
6524 case DW_AT_default_value
:
6525 return "DW_AT_default_value";
6527 return "DW_AT_inline";
6528 case DW_AT_is_optional
:
6529 return "DW_AT_is_optional";
6530 case DW_AT_lower_bound
:
6531 return "DW_AT_lower_bound";
6532 case DW_AT_producer
:
6533 return "DW_AT_producer";
6534 case DW_AT_prototyped
:
6535 return "DW_AT_prototyped";
6536 case DW_AT_return_addr
:
6537 return "DW_AT_return_addr";
6538 case DW_AT_start_scope
:
6539 return "DW_AT_start_scope";
6540 case DW_AT_stride_size
:
6541 return "DW_AT_stride_size";
6542 case DW_AT_upper_bound
:
6543 return "DW_AT_upper_bound";
6544 case DW_AT_abstract_origin
:
6545 return "DW_AT_abstract_origin";
6546 case DW_AT_accessibility
:
6547 return "DW_AT_accessibility";
6548 case DW_AT_address_class
:
6549 return "DW_AT_address_class";
6550 case DW_AT_artificial
:
6551 return "DW_AT_artificial";
6552 case DW_AT_base_types
:
6553 return "DW_AT_base_types";
6554 case DW_AT_calling_convention
:
6555 return "DW_AT_calling_convention";
6557 return "DW_AT_count";
6558 case DW_AT_data_member_location
:
6559 return "DW_AT_data_member_location";
6560 case DW_AT_decl_column
:
6561 return "DW_AT_decl_column";
6562 case DW_AT_decl_file
:
6563 return "DW_AT_decl_file";
6564 case DW_AT_decl_line
:
6565 return "DW_AT_decl_line";
6566 case DW_AT_declaration
:
6567 return "DW_AT_declaration";
6568 case DW_AT_discr_list
:
6569 return "DW_AT_discr_list";
6570 case DW_AT_encoding
:
6571 return "DW_AT_encoding";
6572 case DW_AT_external
:
6573 return "DW_AT_external";
6574 case DW_AT_frame_base
:
6575 return "DW_AT_frame_base";
6577 return "DW_AT_friend";
6578 case DW_AT_identifier_case
:
6579 return "DW_AT_identifier_case";
6580 case DW_AT_macro_info
:
6581 return "DW_AT_macro_info";
6582 case DW_AT_namelist_items
:
6583 return "DW_AT_namelist_items";
6584 case DW_AT_priority
:
6585 return "DW_AT_priority";
6587 return "DW_AT_segment";
6588 case DW_AT_specification
:
6589 return "DW_AT_specification";
6590 case DW_AT_static_link
:
6591 return "DW_AT_static_link";
6593 return "DW_AT_type";
6594 case DW_AT_use_location
:
6595 return "DW_AT_use_location";
6596 case DW_AT_variable_parameter
:
6597 return "DW_AT_variable_parameter";
6598 case DW_AT_virtuality
:
6599 return "DW_AT_virtuality";
6600 case DW_AT_vtable_elem_location
:
6601 return "DW_AT_vtable_elem_location";
6602 case DW_AT_allocated
:
6603 return "DW_AT_allocated";
6604 case DW_AT_associated
:
6605 return "DW_AT_associated";
6606 case DW_AT_data_location
:
6607 return "DW_AT_data_location";
6609 return "DW_AT_stride";
6610 case DW_AT_entry_pc
:
6611 return "DW_AT_entry_pc";
6612 case DW_AT_use_UTF8
:
6613 return "DW_AT_use_UTF8";
6614 case DW_AT_extension
:
6615 return "DW_AT_extension";
6617 return "DW_AT_ranges";
6618 case DW_AT_trampoline
:
6619 return "DW_AT_trampoline";
6620 case DW_AT_call_column
:
6621 return "DW_AT_call_column";
6622 case DW_AT_call_file
:
6623 return "DW_AT_call_file";
6624 case DW_AT_call_line
:
6625 return "DW_AT_call_line";
6627 case DW_AT_MIPS_fde
:
6628 return "DW_AT_MIPS_fde";
6629 case DW_AT_MIPS_loop_begin
:
6630 return "DW_AT_MIPS_loop_begin";
6631 case DW_AT_MIPS_tail_loop_begin
:
6632 return "DW_AT_MIPS_tail_loop_begin";
6633 case DW_AT_MIPS_epilog_begin
:
6634 return "DW_AT_MIPS_epilog_begin";
6635 case DW_AT_MIPS_loop_unroll_factor
:
6636 return "DW_AT_MIPS_loop_unroll_factor";
6637 case DW_AT_MIPS_software_pipeline_depth
:
6638 return "DW_AT_MIPS_software_pipeline_depth";
6640 case DW_AT_MIPS_linkage_name
:
6641 return "DW_AT_MIPS_linkage_name";
6643 case DW_AT_sf_names
:
6644 return "DW_AT_sf_names";
6645 case DW_AT_src_info
:
6646 return "DW_AT_src_info";
6647 case DW_AT_mac_info
:
6648 return "DW_AT_mac_info";
6649 case DW_AT_src_coords
:
6650 return "DW_AT_src_coords";
6651 case DW_AT_body_begin
:
6652 return "DW_AT_body_begin";
6653 case DW_AT_body_end
:
6654 return "DW_AT_body_end";
6655 case DW_AT_GNU_vector
:
6656 return "DW_AT_GNU_vector";
6658 return "DW_AT_<unknown>";
6662 /* Convert a DWARF value form code into its string name. */
6665 dwarf_form_name (unsigned form
)
6670 return "DW_FORM_addr";
6671 case DW_FORM_block2
:
6672 return "DW_FORM_block2";
6673 case DW_FORM_block4
:
6674 return "DW_FORM_block4";
6676 return "DW_FORM_data2";
6678 return "DW_FORM_data4";
6680 return "DW_FORM_data8";
6681 case DW_FORM_string
:
6682 return "DW_FORM_string";
6684 return "DW_FORM_block";
6685 case DW_FORM_block1
:
6686 return "DW_FORM_block1";
6688 return "DW_FORM_data1";
6690 return "DW_FORM_flag";
6692 return "DW_FORM_sdata";
6694 return "DW_FORM_strp";
6696 return "DW_FORM_udata";
6697 case DW_FORM_ref_addr
:
6698 return "DW_FORM_ref_addr";
6700 return "DW_FORM_ref1";
6702 return "DW_FORM_ref2";
6704 return "DW_FORM_ref4";
6706 return "DW_FORM_ref8";
6707 case DW_FORM_ref_udata
:
6708 return "DW_FORM_ref_udata";
6709 case DW_FORM_indirect
:
6710 return "DW_FORM_indirect";
6712 return "DW_FORM_<unknown>";
6716 /* Convert a DWARF stack opcode into its string name. */
6719 dwarf_stack_op_name (unsigned op
)
6724 return "DW_OP_addr";
6726 return "DW_OP_deref";
6728 return "DW_OP_const1u";
6730 return "DW_OP_const1s";
6732 return "DW_OP_const2u";
6734 return "DW_OP_const2s";
6736 return "DW_OP_const4u";
6738 return "DW_OP_const4s";
6740 return "DW_OP_const8u";
6742 return "DW_OP_const8s";
6744 return "DW_OP_constu";
6746 return "DW_OP_consts";
6750 return "DW_OP_drop";
6752 return "DW_OP_over";
6754 return "DW_OP_pick";
6756 return "DW_OP_swap";
6760 return "DW_OP_xderef";
6768 return "DW_OP_minus";
6780 return "DW_OP_plus";
6781 case DW_OP_plus_uconst
:
6782 return "DW_OP_plus_uconst";
6788 return "DW_OP_shra";
6806 return "DW_OP_skip";
6808 return "DW_OP_lit0";
6810 return "DW_OP_lit1";
6812 return "DW_OP_lit2";
6814 return "DW_OP_lit3";
6816 return "DW_OP_lit4";
6818 return "DW_OP_lit5";
6820 return "DW_OP_lit6";
6822 return "DW_OP_lit7";
6824 return "DW_OP_lit8";
6826 return "DW_OP_lit9";
6828 return "DW_OP_lit10";
6830 return "DW_OP_lit11";
6832 return "DW_OP_lit12";
6834 return "DW_OP_lit13";
6836 return "DW_OP_lit14";
6838 return "DW_OP_lit15";
6840 return "DW_OP_lit16";
6842 return "DW_OP_lit17";
6844 return "DW_OP_lit18";
6846 return "DW_OP_lit19";
6848 return "DW_OP_lit20";
6850 return "DW_OP_lit21";
6852 return "DW_OP_lit22";
6854 return "DW_OP_lit23";
6856 return "DW_OP_lit24";
6858 return "DW_OP_lit25";
6860 return "DW_OP_lit26";
6862 return "DW_OP_lit27";
6864 return "DW_OP_lit28";
6866 return "DW_OP_lit29";
6868 return "DW_OP_lit30";
6870 return "DW_OP_lit31";
6872 return "DW_OP_reg0";
6874 return "DW_OP_reg1";
6876 return "DW_OP_reg2";
6878 return "DW_OP_reg3";
6880 return "DW_OP_reg4";
6882 return "DW_OP_reg5";
6884 return "DW_OP_reg6";
6886 return "DW_OP_reg7";
6888 return "DW_OP_reg8";
6890 return "DW_OP_reg9";
6892 return "DW_OP_reg10";
6894 return "DW_OP_reg11";
6896 return "DW_OP_reg12";
6898 return "DW_OP_reg13";
6900 return "DW_OP_reg14";
6902 return "DW_OP_reg15";
6904 return "DW_OP_reg16";
6906 return "DW_OP_reg17";
6908 return "DW_OP_reg18";
6910 return "DW_OP_reg19";
6912 return "DW_OP_reg20";
6914 return "DW_OP_reg21";
6916 return "DW_OP_reg22";
6918 return "DW_OP_reg23";
6920 return "DW_OP_reg24";
6922 return "DW_OP_reg25";
6924 return "DW_OP_reg26";
6926 return "DW_OP_reg27";
6928 return "DW_OP_reg28";
6930 return "DW_OP_reg29";
6932 return "DW_OP_reg30";
6934 return "DW_OP_reg31";
6936 return "DW_OP_breg0";
6938 return "DW_OP_breg1";
6940 return "DW_OP_breg2";
6942 return "DW_OP_breg3";
6944 return "DW_OP_breg4";
6946 return "DW_OP_breg5";
6948 return "DW_OP_breg6";
6950 return "DW_OP_breg7";
6952 return "DW_OP_breg8";
6954 return "DW_OP_breg9";
6956 return "DW_OP_breg10";
6958 return "DW_OP_breg11";
6960 return "DW_OP_breg12";
6962 return "DW_OP_breg13";
6964 return "DW_OP_breg14";
6966 return "DW_OP_breg15";
6968 return "DW_OP_breg16";
6970 return "DW_OP_breg17";
6972 return "DW_OP_breg18";
6974 return "DW_OP_breg19";
6976 return "DW_OP_breg20";
6978 return "DW_OP_breg21";
6980 return "DW_OP_breg22";
6982 return "DW_OP_breg23";
6984 return "DW_OP_breg24";
6986 return "DW_OP_breg25";
6988 return "DW_OP_breg26";
6990 return "DW_OP_breg27";
6992 return "DW_OP_breg28";
6994 return "DW_OP_breg29";
6996 return "DW_OP_breg30";
6998 return "DW_OP_breg31";
7000 return "DW_OP_regx";
7002 return "DW_OP_fbreg";
7004 return "DW_OP_bregx";
7006 return "DW_OP_piece";
7007 case DW_OP_deref_size
:
7008 return "DW_OP_deref_size";
7009 case DW_OP_xderef_size
:
7010 return "DW_OP_xderef_size";
7013 /* DWARF 3 extensions. */
7014 case DW_OP_push_object_address
:
7015 return "DW_OP_push_object_address";
7017 return "DW_OP_call2";
7019 return "DW_OP_call4";
7020 case DW_OP_call_ref
:
7021 return "DW_OP_call_ref";
7022 /* GNU extensions. */
7023 case DW_OP_GNU_push_tls_address
:
7024 return "DW_OP_GNU_push_tls_address";
7026 return "OP_<unknown>";
7031 dwarf_bool_name (unsigned mybool
)
7039 /* Convert a DWARF type code into its string name. */
7042 dwarf_type_encoding_name (unsigned enc
)
7046 case DW_ATE_address
:
7047 return "DW_ATE_address";
7048 case DW_ATE_boolean
:
7049 return "DW_ATE_boolean";
7050 case DW_ATE_complex_float
:
7051 return "DW_ATE_complex_float";
7053 return "DW_ATE_float";
7055 return "DW_ATE_signed";
7056 case DW_ATE_signed_char
:
7057 return "DW_ATE_signed_char";
7058 case DW_ATE_unsigned
:
7059 return "DW_ATE_unsigned";
7060 case DW_ATE_unsigned_char
:
7061 return "DW_ATE_unsigned_char";
7062 case DW_ATE_imaginary_float
:
7063 return "DW_ATE_imaginary_float";
7065 return "DW_ATE_<unknown>";
7069 /* Convert a DWARF call frame info operation to its string name. */
7073 dwarf_cfi_name (unsigned cfi_opc
)
7077 case DW_CFA_advance_loc
:
7078 return "DW_CFA_advance_loc";
7080 return "DW_CFA_offset";
7081 case DW_CFA_restore
:
7082 return "DW_CFA_restore";
7084 return "DW_CFA_nop";
7085 case DW_CFA_set_loc
:
7086 return "DW_CFA_set_loc";
7087 case DW_CFA_advance_loc1
:
7088 return "DW_CFA_advance_loc1";
7089 case DW_CFA_advance_loc2
:
7090 return "DW_CFA_advance_loc2";
7091 case DW_CFA_advance_loc4
:
7092 return "DW_CFA_advance_loc4";
7093 case DW_CFA_offset_extended
:
7094 return "DW_CFA_offset_extended";
7095 case DW_CFA_restore_extended
:
7096 return "DW_CFA_restore_extended";
7097 case DW_CFA_undefined
:
7098 return "DW_CFA_undefined";
7099 case DW_CFA_same_value
:
7100 return "DW_CFA_same_value";
7101 case DW_CFA_register
:
7102 return "DW_CFA_register";
7103 case DW_CFA_remember_state
:
7104 return "DW_CFA_remember_state";
7105 case DW_CFA_restore_state
:
7106 return "DW_CFA_restore_state";
7107 case DW_CFA_def_cfa
:
7108 return "DW_CFA_def_cfa";
7109 case DW_CFA_def_cfa_register
:
7110 return "DW_CFA_def_cfa_register";
7111 case DW_CFA_def_cfa_offset
:
7112 return "DW_CFA_def_cfa_offset";
7115 case DW_CFA_def_cfa_expression
:
7116 return "DW_CFA_def_cfa_expression";
7117 case DW_CFA_expression
:
7118 return "DW_CFA_expression";
7119 case DW_CFA_offset_extended_sf
:
7120 return "DW_CFA_offset_extended_sf";
7121 case DW_CFA_def_cfa_sf
:
7122 return "DW_CFA_def_cfa_sf";
7123 case DW_CFA_def_cfa_offset_sf
:
7124 return "DW_CFA_def_cfa_offset_sf";
7126 /* SGI/MIPS specific */
7127 case DW_CFA_MIPS_advance_loc8
:
7128 return "DW_CFA_MIPS_advance_loc8";
7130 /* GNU extensions */
7131 case DW_CFA_GNU_window_save
:
7132 return "DW_CFA_GNU_window_save";
7133 case DW_CFA_GNU_args_size
:
7134 return "DW_CFA_GNU_args_size";
7135 case DW_CFA_GNU_negative_offset_extended
:
7136 return "DW_CFA_GNU_negative_offset_extended";
7139 return "DW_CFA_<unknown>";
7145 dump_die (struct die_info
*die
)
7149 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
7150 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
7151 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
7152 dwarf_bool_name (die
->child
!= NULL
));
7154 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
7155 for (i
= 0; i
< die
->num_attrs
; ++i
)
7157 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
7158 dwarf_attr_name (die
->attrs
[i
].name
),
7159 dwarf_form_name (die
->attrs
[i
].form
));
7160 switch (die
->attrs
[i
].form
)
7162 case DW_FORM_ref_addr
:
7164 fprintf_unfiltered (gdb_stderr
, "address: ");
7165 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
7167 case DW_FORM_block2
:
7168 case DW_FORM_block4
:
7170 case DW_FORM_block1
:
7171 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
7182 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
7184 case DW_FORM_string
:
7186 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
7187 DW_STRING (&die
->attrs
[i
])
7188 ? DW_STRING (&die
->attrs
[i
]) : "");
7191 if (DW_UNSND (&die
->attrs
[i
]))
7192 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
7194 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
7196 case DW_FORM_indirect
:
7197 /* the reader will have reduced the indirect form to
7198 the "base form" so this form should not occur */
7199 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
7202 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
7203 die
->attrs
[i
].form
);
7205 fprintf_unfiltered (gdb_stderr
, "\n");
7210 dump_die_list (struct die_info
*die
)
7215 if (die
->child
!= NULL
)
7216 dump_die_list (die
->child
);
7217 if (die
->sibling
!= NULL
)
7218 dump_die_list (die
->sibling
);
7223 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
7226 struct die_info
*old
;
7228 h
= (offset
% REF_HASH_SIZE
);
7229 old
= die_ref_table
[h
];
7230 die
->next_ref
= old
;
7231 die_ref_table
[h
] = die
;
7236 dwarf2_empty_hash_tables (void)
7238 memset (die_ref_table
, 0, sizeof (die_ref_table
));
7242 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
7244 unsigned int result
= 0;
7248 case DW_FORM_ref_addr
:
7249 result
= DW_ADDR (attr
);
7255 case DW_FORM_ref_udata
:
7256 result
= cu
->header
.offset
+ DW_UNSND (attr
);
7259 complaint (&symfile_complaints
,
7260 "unsupported die ref attribute form: '%s'",
7261 dwarf_form_name (attr
->form
));
7266 /* Return the constant value held by the given attribute. Return -1
7267 if the value held by the attribute is not constant. */
7270 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
7272 if (attr
->form
== DW_FORM_sdata
)
7273 return DW_SND (attr
);
7274 else if (attr
->form
== DW_FORM_udata
7275 || attr
->form
== DW_FORM_data1
7276 || attr
->form
== DW_FORM_data2
7277 || attr
->form
== DW_FORM_data4
7278 || attr
->form
== DW_FORM_data8
)
7279 return DW_UNSND (attr
);
7282 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
7283 dwarf_form_name (attr
->form
));
7284 return default_value
;
7288 static struct die_info
*
7289 follow_die_ref (unsigned int offset
)
7291 struct die_info
*die
;
7294 h
= (offset
% REF_HASH_SIZE
);
7295 die
= die_ref_table
[h
];
7298 if (die
->offset
== offset
)
7302 die
= die
->next_ref
;
7307 static struct type
*
7308 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
7309 struct dwarf2_cu
*cu
)
7311 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
7313 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7314 typeid, objfile
->name
);
7317 /* Look for this particular type in the fundamental type vector. If
7318 one is not found, create and install one appropriate for the
7319 current language and the current target machine. */
7321 if (cu
->ftypes
[typeid] == NULL
)
7323 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
7326 return (cu
->ftypes
[typeid]);
7329 /* Decode simple location descriptions.
7330 Given a pointer to a dwarf block that defines a location, compute
7331 the location and return the value.
7333 NOTE drow/2003-11-18: This function is called in two situations
7334 now: for the address of static or global variables (partial symbols
7335 only) and for offsets into structures which are expected to be
7336 (more or less) constant. The partial symbol case should go away,
7337 and only the constant case should remain. That will let this
7338 function complain more accurately. A few special modes are allowed
7339 without complaint for global variables (for instance, global
7340 register values and thread-local values).
7342 A location description containing no operations indicates that the
7343 object is optimized out. The return value is 0 for that case.
7344 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7345 callers will only want a very basic result and this can become a
7348 When the result is a register number, the global isreg flag is set,
7349 otherwise it is cleared.
7351 Note that stack[0] is unused except as a default error return.
7352 Note that stack overflow is not yet handled. */
7355 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
7357 struct objfile
*objfile
= cu
->objfile
;
7358 struct comp_unit_head
*cu_header
= &cu
->header
;
7360 int size
= blk
->size
;
7361 char *data
= blk
->data
;
7362 CORE_ADDR stack
[64];
7364 unsigned int bytes_read
, unsnd
;
7409 stack
[++stacki
] = op
- DW_OP_lit0
;
7445 stack
[++stacki
] = op
- DW_OP_reg0
;
7447 dwarf2_complex_location_expr_complaint ();
7452 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7454 stack
[++stacki
] = unsnd
;
7456 dwarf2_complex_location_expr_complaint ();
7460 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
7466 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
7471 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
7476 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
7481 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
7486 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
7491 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
7496 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
7502 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
7507 stack
[stacki
+ 1] = stack
[stacki
];
7512 stack
[stacki
- 1] += stack
[stacki
];
7516 case DW_OP_plus_uconst
:
7517 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
7522 stack
[stacki
- 1] -= stack
[stacki
];
7527 /* If we're not the last op, then we definitely can't encode
7528 this using GDB's address_class enum. This is valid for partial
7529 global symbols, although the variable's address will be bogus
7532 dwarf2_complex_location_expr_complaint ();
7535 case DW_OP_GNU_push_tls_address
:
7536 /* The top of the stack has the offset from the beginning
7537 of the thread control block at which the variable is located. */
7538 /* Nothing should follow this operator, so the top of stack would
7540 /* This is valid for partial global symbols, but the variable's
7541 address will be bogus in the psymtab. */
7543 dwarf2_complex_location_expr_complaint ();
7547 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
7548 dwarf_stack_op_name (op
));
7549 return (stack
[stacki
]);
7552 return (stack
[stacki
]);
7555 /* memory allocation interface */
7558 dwarf2_free_tmp_obstack (void *ignore
)
7560 obstack_free (&dwarf2_tmp_obstack
, NULL
);
7563 static struct dwarf_block
*
7564 dwarf_alloc_block (void)
7566 struct dwarf_block
*blk
;
7568 blk
= (struct dwarf_block
*)
7569 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
7573 static struct abbrev_info
*
7574 dwarf_alloc_abbrev (void)
7576 struct abbrev_info
*abbrev
;
7578 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
7579 memset (abbrev
, 0, sizeof (struct abbrev_info
));
7583 static struct die_info
*
7584 dwarf_alloc_die (void)
7586 struct die_info
*die
;
7588 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7589 memset (die
, 0, sizeof (struct die_info
));
7594 /* Macro support. */
7597 /* Return the full name of file number I in *LH's file name table.
7598 Use COMP_DIR as the name of the current directory of the
7599 compilation. The result is allocated using xmalloc; the caller is
7600 responsible for freeing it. */
7602 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
7604 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7606 if (IS_ABSOLUTE_PATH (fe
->name
))
7607 return xstrdup (fe
->name
);
7615 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7621 dir_len
= strlen (dir
);
7622 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
7623 strcpy (full_name
, dir
);
7624 full_name
[dir_len
] = '/';
7625 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
7629 return xstrdup (fe
->name
);
7634 static struct macro_source_file
*
7635 macro_start_file (int file
, int line
,
7636 struct macro_source_file
*current_file
,
7637 const char *comp_dir
,
7638 struct line_header
*lh
, struct objfile
*objfile
)
7640 /* The full name of this source file. */
7641 char *full_name
= file_full_name (file
, lh
, comp_dir
);
7643 /* We don't create a macro table for this compilation unit
7644 at all until we actually get a filename. */
7645 if (! pending_macros
)
7646 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
7647 objfile
->macro_cache
);
7650 /* If we have no current file, then this must be the start_file
7651 directive for the compilation unit's main source file. */
7652 current_file
= macro_set_main (pending_macros
, full_name
);
7654 current_file
= macro_include (current_file
, line
, full_name
);
7658 return current_file
;
7662 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7663 followed by a null byte. */
7665 copy_string (const char *buf
, int len
)
7667 char *s
= xmalloc (len
+ 1);
7668 memcpy (s
, buf
, len
);
7676 consume_improper_spaces (const char *p
, const char *body
)
7680 complaint (&symfile_complaints
,
7681 "macro definition contains spaces in formal argument list:\n`%s'",
7693 parse_macro_definition (struct macro_source_file
*file
, int line
,
7698 /* The body string takes one of two forms. For object-like macro
7699 definitions, it should be:
7701 <macro name> " " <definition>
7703 For function-like macro definitions, it should be:
7705 <macro name> "() " <definition>
7707 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7709 Spaces may appear only where explicitly indicated, and in the
7712 The Dwarf 2 spec says that an object-like macro's name is always
7713 followed by a space, but versions of GCC around March 2002 omit
7714 the space when the macro's definition is the empty string.
7716 The Dwarf 2 spec says that there should be no spaces between the
7717 formal arguments in a function-like macro's formal argument list,
7718 but versions of GCC around March 2002 include spaces after the
7722 /* Find the extent of the macro name. The macro name is terminated
7723 by either a space or null character (for an object-like macro) or
7724 an opening paren (for a function-like macro). */
7725 for (p
= body
; *p
; p
++)
7726 if (*p
== ' ' || *p
== '(')
7729 if (*p
== ' ' || *p
== '\0')
7731 /* It's an object-like macro. */
7732 int name_len
= p
- body
;
7733 char *name
= copy_string (body
, name_len
);
7734 const char *replacement
;
7737 replacement
= body
+ name_len
+ 1;
7740 dwarf2_macro_malformed_definition_complaint (body
);
7741 replacement
= body
+ name_len
;
7744 macro_define_object (file
, line
, name
, replacement
);
7750 /* It's a function-like macro. */
7751 char *name
= copy_string (body
, p
- body
);
7754 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7758 p
= consume_improper_spaces (p
, body
);
7760 /* Parse the formal argument list. */
7761 while (*p
&& *p
!= ')')
7763 /* Find the extent of the current argument name. */
7764 const char *arg_start
= p
;
7766 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7769 if (! *p
|| p
== arg_start
)
7770 dwarf2_macro_malformed_definition_complaint (body
);
7773 /* Make sure argv has room for the new argument. */
7774 if (argc
>= argv_size
)
7777 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7780 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7783 p
= consume_improper_spaces (p
, body
);
7785 /* Consume the comma, if present. */
7790 p
= consume_improper_spaces (p
, body
);
7799 /* Perfectly formed definition, no complaints. */
7800 macro_define_function (file
, line
, name
,
7801 argc
, (const char **) argv
,
7803 else if (*p
== '\0')
7805 /* Complain, but do define it. */
7806 dwarf2_macro_malformed_definition_complaint (body
);
7807 macro_define_function (file
, line
, name
,
7808 argc
, (const char **) argv
,
7812 /* Just complain. */
7813 dwarf2_macro_malformed_definition_complaint (body
);
7816 /* Just complain. */
7817 dwarf2_macro_malformed_definition_complaint (body
);
7823 for (i
= 0; i
< argc
; i
++)
7829 dwarf2_macro_malformed_definition_complaint (body
);
7834 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7835 char *comp_dir
, bfd
*abfd
,
7836 struct dwarf2_cu
*cu
)
7838 char *mac_ptr
, *mac_end
;
7839 struct macro_source_file
*current_file
= 0;
7841 if (dwarf_macinfo_buffer
== NULL
)
7843 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7847 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7848 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7852 enum dwarf_macinfo_record_type macinfo_type
;
7854 /* Do we at least have room for a macinfo type byte? */
7855 if (mac_ptr
>= mac_end
)
7857 dwarf2_macros_too_long_complaint ();
7861 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7864 switch (macinfo_type
)
7866 /* A zero macinfo type indicates the end of the macro
7871 case DW_MACINFO_define
:
7872 case DW_MACINFO_undef
:
7878 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7879 mac_ptr
+= bytes_read
;
7880 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7881 mac_ptr
+= bytes_read
;
7884 complaint (&symfile_complaints
,
7885 "debug info gives macro %s outside of any file: %s",
7887 DW_MACINFO_define
? "definition" : macinfo_type
==
7888 DW_MACINFO_undef
? "undefinition" :
7889 "something-or-other", body
);
7892 if (macinfo_type
== DW_MACINFO_define
)
7893 parse_macro_definition (current_file
, line
, body
);
7894 else if (macinfo_type
== DW_MACINFO_undef
)
7895 macro_undef (current_file
, line
, body
);
7900 case DW_MACINFO_start_file
:
7905 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7906 mac_ptr
+= bytes_read
;
7907 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7908 mac_ptr
+= bytes_read
;
7910 current_file
= macro_start_file (file
, line
,
7911 current_file
, comp_dir
,
7916 case DW_MACINFO_end_file
:
7918 complaint (&symfile_complaints
,
7919 "macro debug info has an unmatched `close_file' directive");
7922 current_file
= current_file
->included_by
;
7925 enum dwarf_macinfo_record_type next_type
;
7927 /* GCC circa March 2002 doesn't produce the zero
7928 type byte marking the end of the compilation
7929 unit. Complain if it's not there, but exit no
7932 /* Do we at least have room for a macinfo type byte? */
7933 if (mac_ptr
>= mac_end
)
7935 dwarf2_macros_too_long_complaint ();
7939 /* We don't increment mac_ptr here, so this is just
7941 next_type
= read_1_byte (abfd
, mac_ptr
);
7943 complaint (&symfile_complaints
,
7944 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7951 case DW_MACINFO_vendor_ext
:
7957 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7958 mac_ptr
+= bytes_read
;
7959 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7960 mac_ptr
+= bytes_read
;
7962 /* We don't recognize any vendor extensions. */
7969 /* Check if the attribute's form is a DW_FORM_block*
7970 if so return true else false. */
7972 attr_form_is_block (struct attribute
*attr
)
7974 return (attr
== NULL
? 0 :
7975 attr
->form
== DW_FORM_block1
7976 || attr
->form
== DW_FORM_block2
7977 || attr
->form
== DW_FORM_block4
7978 || attr
->form
== DW_FORM_block
);
7982 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
7983 struct dwarf2_cu
*cu
)
7985 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
7987 struct dwarf2_loclist_baton
*baton
;
7989 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
7990 sizeof (struct dwarf2_loclist_baton
));
7991 baton
->objfile
= cu
->objfile
;
7993 /* We don't know how long the location list is, but make sure we
7994 don't run off the edge of the section. */
7995 baton
->size
= dwarf_loc_size
- DW_UNSND (attr
);
7996 baton
->data
= dwarf_loc_buffer
+ DW_UNSND (attr
);
7997 baton
->base_address
= cu
->header
.base_address
;
7998 if (cu
->header
.base_known
== 0)
7999 complaint (&symfile_complaints
,
8000 "Location list used without specifying the CU base address.");
8002 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
8003 SYMBOL_LOCATION_BATON (sym
) = baton
;
8007 struct dwarf2_locexpr_baton
*baton
;
8009 baton
= obstack_alloc (&cu
->objfile
->symbol_obstack
,
8010 sizeof (struct dwarf2_locexpr_baton
));
8011 baton
->objfile
= cu
->objfile
;
8013 if (attr_form_is_block (attr
))
8015 /* Note that we're just copying the block's data pointer
8016 here, not the actual data. We're still pointing into the
8017 dwarf_info_buffer for SYM's objfile; right now we never
8018 release that buffer, but when we do clean up properly
8019 this may need to change. */
8020 baton
->size
= DW_BLOCK (attr
)->size
;
8021 baton
->data
= DW_BLOCK (attr
)->data
;
8025 dwarf2_invalid_attrib_class_complaint ("location description",
8026 SYMBOL_NATURAL_NAME (sym
));
8031 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
8032 SYMBOL_LOCATION_BATON (sym
) = baton
;