1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 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
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 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU 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, see <http://www.gnu.org/licenses/>. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
51 #include "gdb_string.h"
52 #include "gdb_assert.h"
53 #include <sys/types.h>
58 /* A note on memory usage for this file.
60 At the present time, this code reads the debug info sections into
61 the objfile's objfile_obstack. A definite improvement for startup
62 time, on platforms which do not emit relocations for debug
63 sections, would be to use mmap instead. The object's complete
64 debug information is loaded into memory, partly to simplify
65 absolute DIE references.
67 Whether using obstacks or mmap, the sections should remain loaded
68 until the objfile is released, and pointers into the section data
69 can be used for any other data associated to the objfile (symbol
70 names, type names, location expressions to name a few). */
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 static const struct objfile_data
*dwarf2_objfile_data_key
;
146 struct dwarf2_per_objfile
148 /* Sizes of debugging sections. */
149 unsigned int info_size
;
150 unsigned int abbrev_size
;
151 unsigned int line_size
;
152 unsigned int pubnames_size
;
153 unsigned int aranges_size
;
154 unsigned int loc_size
;
155 unsigned int macinfo_size
;
156 unsigned int str_size
;
157 unsigned int ranges_size
;
158 unsigned int frame_size
;
159 unsigned int eh_frame_size
;
161 /* Loaded data from the sections. */
162 gdb_byte
*info_buffer
;
163 gdb_byte
*abbrev_buffer
;
164 gdb_byte
*line_buffer
;
165 gdb_byte
*str_buffer
;
166 gdb_byte
*macinfo_buffer
;
167 gdb_byte
*ranges_buffer
;
168 gdb_byte
*loc_buffer
;
170 /* A list of all the compilation units. This is used to locate
171 the target compilation unit of a particular reference. */
172 struct dwarf2_per_cu_data
**all_comp_units
;
174 /* The number of compilation units in ALL_COMP_UNITS. */
177 /* A chain of compilation units that are currently read in, so that
178 they can be freed later. */
179 struct dwarf2_per_cu_data
*read_in_chain
;
181 /* A flag indicating wether this objfile has a section loaded at a
183 int has_section_at_zero
;
186 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
188 static asection
*dwarf_info_section
;
189 static asection
*dwarf_abbrev_section
;
190 static asection
*dwarf_line_section
;
191 static asection
*dwarf_pubnames_section
;
192 static asection
*dwarf_aranges_section
;
193 static asection
*dwarf_loc_section
;
194 static asection
*dwarf_macinfo_section
;
195 static asection
*dwarf_str_section
;
196 static asection
*dwarf_ranges_section
;
197 asection
*dwarf_frame_section
;
198 asection
*dwarf_eh_frame_section
;
200 /* names of the debugging sections */
202 /* Note that if the debugging section has been compressed, it might
203 have a name like .zdebug_info. */
205 #define INFO_SECTION "debug_info"
206 #define ABBREV_SECTION "debug_abbrev"
207 #define LINE_SECTION "debug_line"
208 #define PUBNAMES_SECTION "debug_pubnames"
209 #define ARANGES_SECTION "debug_aranges"
210 #define LOC_SECTION "debug_loc"
211 #define MACINFO_SECTION "debug_macinfo"
212 #define STR_SECTION "debug_str"
213 #define RANGES_SECTION "debug_ranges"
214 #define FRAME_SECTION "debug_frame"
215 #define EH_FRAME_SECTION "eh_frame"
217 /* local data types */
219 /* We hold several abbreviation tables in memory at the same time. */
220 #ifndef ABBREV_HASH_SIZE
221 #define ABBREV_HASH_SIZE 121
224 /* The data in a compilation unit header, after target2host
225 translation, looks like this. */
226 struct comp_unit_head
228 unsigned long length
;
230 unsigned int abbrev_offset
;
231 unsigned char addr_size
;
232 unsigned char signed_addr_p
;
234 /* Size of file offsets; either 4 or 8. */
235 unsigned int offset_size
;
237 /* Size of the length field; either 4 or 12. */
238 unsigned int initial_length_size
;
240 /* Offset to the first byte of this compilation unit header in the
241 .debug_info section, for resolving relative reference dies. */
244 /* Pointer to this compilation unit header in the .debug_info
246 gdb_byte
*cu_head_ptr
;
248 /* Pointer to the first die of this compilation unit. This will be
249 the first byte following the compilation unit header. */
250 gdb_byte
*first_die_ptr
;
252 /* Pointer to the next compilation unit header in the program. */
253 struct comp_unit_head
*next
;
255 /* Base address of this compilation unit. */
256 CORE_ADDR base_address
;
258 /* Non-zero if base_address has been set. */
262 /* Fixed size for the DIE hash table. */
263 #ifndef REF_HASH_SIZE
264 #define REF_HASH_SIZE 1021
267 /* Internal state when decoding a particular compilation unit. */
270 /* The objfile containing this compilation unit. */
271 struct objfile
*objfile
;
273 /* The header of the compilation unit.
275 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
276 should logically be moved to the dwarf2_cu structure. */
277 struct comp_unit_head header
;
279 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
281 /* The language we are debugging. */
282 enum language language
;
283 const struct language_defn
*language_defn
;
285 const char *producer
;
287 /* The generic symbol table building routines have separate lists for
288 file scope symbols and all all other scopes (local scopes). So
289 we need to select the right one to pass to add_symbol_to_list().
290 We do it by keeping a pointer to the correct list in list_in_scope.
292 FIXME: The original dwarf code just treated the file scope as the
293 first local scope, and all other local scopes as nested local
294 scopes, and worked fine. Check to see if we really need to
295 distinguish these in buildsym.c. */
296 struct pending
**list_in_scope
;
298 /* DWARF abbreviation table associated with this compilation unit. */
299 struct abbrev_info
**dwarf2_abbrevs
;
301 /* Storage for the abbrev table. */
302 struct obstack abbrev_obstack
;
304 /* Hash table holding all the loaded partial DIEs. */
307 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
308 unsigned long ranges_offset
;
310 /* Storage for things with the same lifetime as this read-in compilation
311 unit, including partial DIEs. */
312 struct obstack comp_unit_obstack
;
314 /* When multiple dwarf2_cu structures are living in memory, this field
315 chains them all together, so that they can be released efficiently.
316 We will probably also want a generation counter so that most-recently-used
317 compilation units are cached... */
318 struct dwarf2_per_cu_data
*read_in_chain
;
320 /* Backchain to our per_cu entry if the tree has been built. */
321 struct dwarf2_per_cu_data
*per_cu
;
323 /* Pointer to the die -> type map. Although it is stored
324 permanently in per_cu, we copy it here to avoid double
328 /* How many compilation units ago was this CU last referenced? */
331 /* A hash table of die offsets for following references. */
332 struct die_info
*die_ref_table
[REF_HASH_SIZE
];
334 /* Full DIEs if read in. */
335 struct die_info
*dies
;
337 /* A set of pointers to dwarf2_per_cu_data objects for compilation
338 units referenced by this one. Only set during full symbol processing;
339 partial symbol tables do not have dependencies. */
342 /* Header data from the line table, during full symbol processing. */
343 struct line_header
*line_header
;
345 /* Mark used when releasing cached dies. */
346 unsigned int mark
: 1;
348 /* This flag will be set if this compilation unit might include
349 inter-compilation-unit references. */
350 unsigned int has_form_ref_addr
: 1;
352 /* This flag will be set if this compilation unit includes any
353 DW_TAG_namespace DIEs. If we know that there are explicit
354 DIEs for namespaces, we don't need to try to infer them
355 from mangled names. */
356 unsigned int has_namespace_info
: 1;
358 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
359 unsigned int has_ranges_offset
: 1;
362 /* Persistent data held for a compilation unit, even when not
363 processing it. We put a pointer to this structure in the
364 read_symtab_private field of the psymtab. If we encounter
365 inter-compilation-unit references, we also maintain a sorted
366 list of all compilation units. */
368 struct dwarf2_per_cu_data
370 /* The start offset and length of this compilation unit. 2**30-1
371 bytes should suffice to store the length of any compilation unit
372 - if it doesn't, GDB will fall over anyway. */
373 unsigned long offset
;
374 unsigned long length
: 30;
376 /* Flag indicating this compilation unit will be read in before
377 any of the current compilation units are processed. */
378 unsigned long queued
: 1;
380 /* This flag will be set if we need to load absolutely all DIEs
381 for this compilation unit, instead of just the ones we think
382 are interesting. It gets set if we look for a DIE in the
383 hash table and don't find it. */
384 unsigned int load_all_dies
: 1;
386 /* Set iff currently read in. */
387 struct dwarf2_cu
*cu
;
389 /* If full symbols for this CU have been read in, then this field
390 holds a map of DIE offsets to types. It isn't always possible
391 to reconstruct this information later, so we have to preserve
395 /* The partial symbol table associated with this compilation unit,
396 or NULL for partial units (which do not have an associated
398 struct partial_symtab
*psymtab
;
401 /* The line number information for a compilation unit (found in the
402 .debug_line section) begins with a "statement program header",
403 which contains the following information. */
406 unsigned int total_length
;
407 unsigned short version
;
408 unsigned int header_length
;
409 unsigned char minimum_instruction_length
;
410 unsigned char default_is_stmt
;
412 unsigned char line_range
;
413 unsigned char opcode_base
;
415 /* standard_opcode_lengths[i] is the number of operands for the
416 standard opcode whose value is i. This means that
417 standard_opcode_lengths[0] is unused, and the last meaningful
418 element is standard_opcode_lengths[opcode_base - 1]. */
419 unsigned char *standard_opcode_lengths
;
421 /* The include_directories table. NOTE! These strings are not
422 allocated with xmalloc; instead, they are pointers into
423 debug_line_buffer. If you try to free them, `free' will get
425 unsigned int num_include_dirs
, include_dirs_size
;
428 /* The file_names table. NOTE! These strings are not allocated
429 with xmalloc; instead, they are pointers into debug_line_buffer.
430 Don't try to free them directly. */
431 unsigned int num_file_names
, file_names_size
;
435 unsigned int dir_index
;
436 unsigned int mod_time
;
438 int included_p
; /* Non-zero if referenced by the Line Number Program. */
439 struct symtab
*symtab
; /* The associated symbol table, if any. */
442 /* The start and end of the statement program following this
443 header. These point into dwarf2_per_objfile->line_buffer. */
444 gdb_byte
*statement_program_start
, *statement_program_end
;
447 /* When we construct a partial symbol table entry we only
448 need this much information. */
449 struct partial_die_info
451 /* Offset of this DIE. */
454 /* DWARF-2 tag for this DIE. */
455 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
457 /* Language code associated with this DIE. This is only used
458 for the compilation unit DIE. */
459 unsigned int language
: 8;
461 /* Assorted flags describing the data found in this DIE. */
462 unsigned int has_children
: 1;
463 unsigned int is_external
: 1;
464 unsigned int is_declaration
: 1;
465 unsigned int has_type
: 1;
466 unsigned int has_specification
: 1;
467 unsigned int has_stmt_list
: 1;
468 unsigned int has_pc_info
: 1;
470 /* Flag set if the SCOPE field of this structure has been
472 unsigned int scope_set
: 1;
474 /* Flag set if the DIE has a byte_size attribute. */
475 unsigned int has_byte_size
: 1;
477 /* The name of this DIE. Normally the value of DW_AT_name, but
478 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
483 /* The scope to prepend to our children. This is generally
484 allocated on the comp_unit_obstack, so will disappear
485 when this compilation unit leaves the cache. */
488 /* The location description associated with this DIE, if any. */
489 struct dwarf_block
*locdesc
;
491 /* If HAS_PC_INFO, the PC range associated with this DIE. */
495 /* Pointer into the info_buffer pointing at the target of
496 DW_AT_sibling, if any. */
499 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
500 DW_AT_specification (or DW_AT_abstract_origin or
502 unsigned int spec_offset
;
504 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
505 unsigned int line_offset
;
507 /* Pointers to this DIE's parent, first child, and next sibling,
509 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
512 /* This data structure holds the information of an abbrev. */
515 unsigned int number
; /* number identifying abbrev */
516 enum dwarf_tag tag
; /* dwarf tag */
517 unsigned short has_children
; /* boolean */
518 unsigned short num_attrs
; /* number of attributes */
519 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
520 struct abbrev_info
*next
; /* next in chain */
525 enum dwarf_attribute name
;
526 enum dwarf_form form
;
529 /* This data structure holds a complete die structure. */
532 enum dwarf_tag tag
; /* Tag indicating type of die */
533 unsigned int abbrev
; /* Abbrev number */
534 unsigned int offset
; /* Offset in .debug_info section */
535 unsigned int num_attrs
; /* Number of attributes */
536 struct attribute
*attrs
; /* An array of attributes */
537 struct die_info
*next_ref
; /* Next die in ref hash table */
539 /* The dies in a compilation unit form an n-ary tree. PARENT
540 points to this die's parent; CHILD points to the first child of
541 this node; and all the children of a given node are chained
542 together via their SIBLING fields, terminated by a die whose
544 struct die_info
*child
; /* Its first child, if any. */
545 struct die_info
*sibling
; /* Its next sibling, if any. */
546 struct die_info
*parent
; /* Its parent, if any. */
549 /* Attributes have a name and a value */
552 enum dwarf_attribute name
;
553 enum dwarf_form form
;
557 struct dwarf_block
*blk
;
565 struct function_range
568 CORE_ADDR lowpc
, highpc
;
570 struct function_range
*next
;
573 /* Get at parts of an attribute structure */
575 #define DW_STRING(attr) ((attr)->u.str)
576 #define DW_UNSND(attr) ((attr)->u.unsnd)
577 #define DW_BLOCK(attr) ((attr)->u.blk)
578 #define DW_SND(attr) ((attr)->u.snd)
579 #define DW_ADDR(attr) ((attr)->u.addr)
581 /* Blocks are a bunch of untyped bytes. */
588 #ifndef ATTR_ALLOC_CHUNK
589 #define ATTR_ALLOC_CHUNK 4
592 /* Allocate fields for structs, unions and enums in this size. */
593 #ifndef DW_FIELD_ALLOC_CHUNK
594 #define DW_FIELD_ALLOC_CHUNK 4
597 /* A zeroed version of a partial die for initialization purposes. */
598 static struct partial_die_info zeroed_partial_die
;
600 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
601 but this would require a corresponding change in unpack_field_as_long
603 static int bits_per_byte
= 8;
605 /* The routines that read and process dies for a C struct or C++ class
606 pass lists of data member fields and lists of member function fields
607 in an instance of a field_info structure, as defined below. */
610 /* List of data member and baseclasses fields. */
613 struct nextfield
*next
;
620 /* Number of fields. */
623 /* Number of baseclasses. */
626 /* Set if the accesibility of one of the fields is not public. */
627 int non_public_fields
;
629 /* Member function fields array, entries are allocated in the order they
630 are encountered in the object file. */
633 struct nextfnfield
*next
;
634 struct fn_field fnfield
;
638 /* Member function fieldlist array, contains name of possibly overloaded
639 member function, number of overloaded member functions and a pointer
640 to the head of the member function field chain. */
645 struct nextfnfield
*head
;
649 /* Number of entries in the fnfieldlists array. */
653 /* One item on the queue of compilation units to read in full symbols
655 struct dwarf2_queue_item
657 struct dwarf2_per_cu_data
*per_cu
;
658 struct dwarf2_queue_item
*next
;
661 /* The current queue. */
662 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
664 /* Loaded secondary compilation units are kept in memory until they
665 have not been referenced for the processing of this many
666 compilation units. Set this to zero to disable caching. Cache
667 sizes of up to at least twenty will improve startup time for
668 typical inter-CU-reference binaries, at an obvious memory cost. */
669 static int dwarf2_max_cache_age
= 5;
671 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
672 struct cmd_list_element
*c
, const char *value
)
674 fprintf_filtered (file
, _("\
675 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
680 /* Various complaints about symbol reading that don't abort the process */
683 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
685 complaint (&symfile_complaints
,
686 _("statement list doesn't fit in .debug_line section"));
690 dwarf2_debug_line_missing_file_complaint (void)
692 complaint (&symfile_complaints
,
693 _(".debug_line section has line data without a file"));
697 dwarf2_complex_location_expr_complaint (void)
699 complaint (&symfile_complaints
, _("location expression too complex"));
703 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
706 complaint (&symfile_complaints
,
707 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
712 dwarf2_macros_too_long_complaint (void)
714 complaint (&symfile_complaints
,
715 _("macro info runs off end of `.debug_macinfo' section"));
719 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
721 complaint (&symfile_complaints
,
722 _("macro debug info contains a malformed macro definition:\n`%s'"),
727 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
729 complaint (&symfile_complaints
,
730 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
733 /* local function prototypes */
735 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
738 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
741 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
744 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
745 struct partial_die_info
*,
746 struct partial_symtab
*);
748 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
750 static void scan_partial_symbols (struct partial_die_info
*,
751 CORE_ADDR
*, CORE_ADDR
*,
754 static void add_partial_symbol (struct partial_die_info
*,
757 static int pdi_needs_namespace (enum dwarf_tag tag
);
759 static void add_partial_namespace (struct partial_die_info
*pdi
,
760 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
761 struct dwarf2_cu
*cu
);
763 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
764 struct dwarf2_cu
*cu
);
766 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
769 struct dwarf2_cu
*cu
);
771 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
773 static void psymtab_to_symtab_1 (struct partial_symtab
*);
775 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
777 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
779 static void dwarf2_free_abbrev_table (void *);
781 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
784 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
787 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
790 static gdb_byte
*read_partial_die (struct partial_die_info
*,
791 struct abbrev_info
*abbrev
, unsigned int,
792 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
794 static struct partial_die_info
*find_partial_die (unsigned long,
797 static void fixup_partial_die (struct partial_die_info
*,
800 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
801 struct dwarf2_cu
*, int *);
803 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
804 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
806 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
807 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
809 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
811 static int read_1_signed_byte (bfd
*, gdb_byte
*);
813 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
815 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
817 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
819 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
822 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
823 struct comp_unit_head
*, unsigned int *);
825 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
828 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
830 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
832 static char *read_indirect_string (bfd
*, gdb_byte
*,
833 const struct comp_unit_head
*,
836 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
838 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
840 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
842 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
844 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
847 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
848 struct dwarf2_cu
*cu
);
850 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
852 static struct die_info
*die_specification (struct die_info
*die
,
855 static void free_line_header (struct line_header
*lh
);
857 static void add_file_name (struct line_header
*, char *, unsigned int,
858 unsigned int, unsigned int);
860 static struct line_header
*(dwarf_decode_line_header
861 (unsigned int offset
,
862 bfd
*abfd
, struct dwarf2_cu
*cu
));
864 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
865 struct dwarf2_cu
*, struct partial_symtab
*);
867 static void dwarf2_start_subfile (char *, char *, char *);
869 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
872 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
875 static void dwarf2_const_value_data (struct attribute
*attr
,
879 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
881 static struct type
*die_containing_type (struct die_info
*,
884 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
886 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
888 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
890 static char *typename_concat (struct obstack
*,
895 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
897 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
899 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
901 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
902 struct dwarf2_cu
*, struct partial_symtab
*);
904 static int dwarf2_get_pc_bounds (struct die_info
*,
905 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
907 static void get_scope_pc_bounds (struct die_info
*,
908 CORE_ADDR
*, CORE_ADDR
*,
911 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
912 CORE_ADDR
, struct dwarf2_cu
*);
914 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
917 static void dwarf2_attach_fields_to_type (struct field_info
*,
918 struct type
*, struct dwarf2_cu
*);
920 static void dwarf2_add_member_fn (struct field_info
*,
921 struct die_info
*, struct type
*,
924 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
925 struct type
*, struct dwarf2_cu
*);
927 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
929 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
931 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
933 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
935 static const char *namespace_name (struct die_info
*die
,
936 int *is_anonymous
, struct dwarf2_cu
*);
938 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
940 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
942 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
945 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
947 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
949 gdb_byte
**new_info_ptr
,
950 struct die_info
*parent
);
952 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
954 gdb_byte
**new_info_ptr
,
955 struct die_info
*parent
);
957 static void free_die_list (struct die_info
*);
959 static void process_die (struct die_info
*, struct dwarf2_cu
*);
961 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
963 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
965 static struct die_info
*dwarf2_extension (struct die_info
*die
,
968 static char *dwarf_tag_name (unsigned int);
970 static char *dwarf_attr_name (unsigned int);
972 static char *dwarf_form_name (unsigned int);
974 static char *dwarf_stack_op_name (unsigned int);
976 static char *dwarf_bool_name (unsigned int);
978 static char *dwarf_type_encoding_name (unsigned int);
981 static char *dwarf_cfi_name (unsigned int);
983 struct die_info
*copy_die (struct die_info
*);
986 static struct die_info
*sibling_die (struct die_info
*);
988 static void dump_die (struct die_info
*);
990 static void dump_die_list (struct die_info
*);
992 static void store_in_ref_table (unsigned int, struct die_info
*,
995 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
998 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1000 static struct die_info
*follow_die_ref (struct die_info
*,
1002 struct dwarf2_cu
*);
1004 /* memory allocation interface */
1006 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1008 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1010 static struct die_info
*dwarf_alloc_die (void);
1012 static void initialize_cu_func_list (struct dwarf2_cu
*);
1014 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1015 struct dwarf2_cu
*);
1017 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1018 char *, bfd
*, struct dwarf2_cu
*);
1020 static int attr_form_is_block (struct attribute
*);
1022 static int attr_form_is_section_offset (struct attribute
*);
1024 static int attr_form_is_constant (struct attribute
*);
1026 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1028 struct dwarf2_cu
*cu
);
1030 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1031 struct dwarf2_cu
*cu
);
1033 static void free_stack_comp_unit (void *);
1035 static hashval_t
partial_die_hash (const void *item
);
1037 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1039 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1040 (unsigned long offset
, struct objfile
*objfile
);
1042 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1043 (unsigned long offset
, struct objfile
*objfile
);
1045 static void free_one_comp_unit (void *);
1047 static void free_cached_comp_units (void *);
1049 static void age_cached_comp_units (void);
1051 static void free_one_cached_comp_unit (void *);
1053 static struct type
*set_die_type (struct die_info
*, struct type
*,
1054 struct dwarf2_cu
*);
1056 static void create_all_comp_units (struct objfile
*);
1058 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1061 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1063 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1064 struct dwarf2_per_cu_data
*);
1066 static void dwarf2_mark (struct dwarf2_cu
*);
1068 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1070 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1072 /* Try to locate the sections we need for DWARF 2 debugging
1073 information and return true if we have enough to do something. */
1076 dwarf2_has_info (struct objfile
*objfile
)
1078 struct dwarf2_per_objfile
*data
;
1080 /* Initialize per-objfile state. */
1081 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1082 memset (data
, 0, sizeof (*data
));
1083 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1084 dwarf2_per_objfile
= data
;
1086 dwarf_info_section
= 0;
1087 dwarf_abbrev_section
= 0;
1088 dwarf_line_section
= 0;
1089 dwarf_str_section
= 0;
1090 dwarf_macinfo_section
= 0;
1091 dwarf_frame_section
= 0;
1092 dwarf_eh_frame_section
= 0;
1093 dwarf_ranges_section
= 0;
1094 dwarf_loc_section
= 0;
1096 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1097 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1100 /* When loading sections, we can either look for ".<name>", or for
1101 * ".z<name>", which indicates a compressed section. */
1104 section_is_p (asection
*sectp
, const char *name
)
1106 return ((sectp
->name
[0] == '.'
1107 && strcmp (sectp
->name
+ 1, name
) == 0)
1108 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1109 && strcmp (sectp
->name
+ 2, name
) == 0));
1112 /* This function is mapped across the sections and remembers the
1113 offset and size of each of the debugging sections we are interested
1117 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1119 if (section_is_p (sectp
, INFO_SECTION
))
1121 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1122 dwarf_info_section
= sectp
;
1124 else if (section_is_p (sectp
, ABBREV_SECTION
))
1126 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1127 dwarf_abbrev_section
= sectp
;
1129 else if (section_is_p (sectp
, LINE_SECTION
))
1131 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1132 dwarf_line_section
= sectp
;
1134 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1136 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1137 dwarf_pubnames_section
= sectp
;
1139 else if (section_is_p (sectp
, ARANGES_SECTION
))
1141 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1142 dwarf_aranges_section
= sectp
;
1144 else if (section_is_p (sectp
, LOC_SECTION
))
1146 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1147 dwarf_loc_section
= sectp
;
1149 else if (section_is_p (sectp
, MACINFO_SECTION
))
1151 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1152 dwarf_macinfo_section
= sectp
;
1154 else if (section_is_p (sectp
, STR_SECTION
))
1156 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1157 dwarf_str_section
= sectp
;
1159 else if (section_is_p (sectp
, FRAME_SECTION
))
1161 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1162 dwarf_frame_section
= sectp
;
1164 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1166 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1167 if (aflag
& SEC_HAS_CONTENTS
)
1169 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1170 dwarf_eh_frame_section
= sectp
;
1173 else if (section_is_p (sectp
, RANGES_SECTION
))
1175 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1176 dwarf_ranges_section
= sectp
;
1179 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1180 && bfd_section_vma (abfd
, sectp
) == 0)
1181 dwarf2_per_objfile
->has_section_at_zero
= 1;
1184 /* This function is called after decompressing a section, so
1185 dwarf2_per_objfile can record its new, uncompressed size. */
1188 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1190 if (section_is_p (sectp
, INFO_SECTION
))
1191 dwarf2_per_objfile
->info_size
= new_size
;
1192 else if (section_is_p (sectp
, ABBREV_SECTION
))
1193 dwarf2_per_objfile
->abbrev_size
= new_size
;
1194 else if (section_is_p (sectp
, LINE_SECTION
))
1195 dwarf2_per_objfile
->line_size
= new_size
;
1196 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1197 dwarf2_per_objfile
->pubnames_size
= new_size
;
1198 else if (section_is_p (sectp
, ARANGES_SECTION
))
1199 dwarf2_per_objfile
->aranges_size
= new_size
;
1200 else if (section_is_p (sectp
, LOC_SECTION
))
1201 dwarf2_per_objfile
->loc_size
= new_size
;
1202 else if (section_is_p (sectp
, MACINFO_SECTION
))
1203 dwarf2_per_objfile
->macinfo_size
= new_size
;
1204 else if (section_is_p (sectp
, STR_SECTION
))
1205 dwarf2_per_objfile
->str_size
= new_size
;
1206 else if (section_is_p (sectp
, FRAME_SECTION
))
1207 dwarf2_per_objfile
->frame_size
= new_size
;
1208 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1209 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1210 else if (section_is_p (sectp
, RANGES_SECTION
))
1211 dwarf2_per_objfile
->ranges_size
= new_size
;
1213 internal_error (__FILE__
, __LINE__
,
1214 _("dwarf2_resize_section: missing section_is_p check: %s"),
1218 /* Build a partial symbol table. */
1221 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1223 /* We definitely need the .debug_info and .debug_abbrev sections */
1225 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1226 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1228 if (dwarf_line_section
)
1229 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1231 dwarf2_per_objfile
->line_buffer
= NULL
;
1233 if (dwarf_str_section
)
1234 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1236 dwarf2_per_objfile
->str_buffer
= NULL
;
1238 if (dwarf_macinfo_section
)
1239 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1240 dwarf_macinfo_section
);
1242 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1244 if (dwarf_ranges_section
)
1245 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1247 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1249 if (dwarf_loc_section
)
1250 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1252 dwarf2_per_objfile
->loc_buffer
= NULL
;
1255 || (objfile
->global_psymbols
.size
== 0
1256 && objfile
->static_psymbols
.size
== 0))
1258 init_psymbol_list (objfile
, 1024);
1262 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1264 /* Things are significantly easier if we have .debug_aranges and
1265 .debug_pubnames sections */
1267 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1271 /* only test this case for now */
1273 /* In this case we have to work a bit harder */
1274 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1279 /* Build the partial symbol table from the information in the
1280 .debug_pubnames and .debug_aranges sections. */
1283 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1285 bfd
*abfd
= objfile
->obfd
;
1286 char *aranges_buffer
, *pubnames_buffer
;
1287 char *aranges_ptr
, *pubnames_ptr
;
1288 unsigned int entry_length
, version
, info_offset
, info_size
;
1290 pubnames_buffer
= dwarf2_read_section (objfile
,
1291 dwarf_pubnames_section
);
1292 pubnames_ptr
= pubnames_buffer
;
1293 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1295 struct comp_unit_head cu_header
;
1296 unsigned int bytes_read
;
1298 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1300 pubnames_ptr
+= bytes_read
;
1301 version
= read_1_byte (abfd
, pubnames_ptr
);
1303 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1305 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1309 aranges_buffer
= dwarf2_read_section (objfile
,
1310 dwarf_aranges_section
);
1315 /* Read in the comp unit header information from the debug_info at
1319 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1320 gdb_byte
*info_ptr
, bfd
*abfd
)
1323 unsigned int bytes_read
;
1324 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1326 info_ptr
+= bytes_read
;
1327 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1329 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1331 info_ptr
+= bytes_read
;
1332 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1334 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1335 if (signed_addr
< 0)
1336 internal_error (__FILE__
, __LINE__
,
1337 _("read_comp_unit_head: dwarf from non elf file"));
1338 cu_header
->signed_addr_p
= signed_addr
;
1343 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1346 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1348 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1350 if (header
->version
!= 2 && header
->version
!= 3)
1351 error (_("Dwarf Error: wrong version in compilation unit header "
1352 "(is %d, should be %d) [in module %s]"), header
->version
,
1353 2, bfd_get_filename (abfd
));
1355 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1356 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1357 "(offset 0x%lx + 6) [in module %s]"),
1358 (long) header
->abbrev_offset
,
1359 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1360 bfd_get_filename (abfd
));
1362 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1363 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1364 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1365 "(offset 0x%lx + 0) [in module %s]"),
1366 (long) header
->length
,
1367 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1368 bfd_get_filename (abfd
));
1373 /* Allocate a new partial symtab for file named NAME and mark this new
1374 partial symtab as being an include of PST. */
1377 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1378 struct objfile
*objfile
)
1380 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1382 subpst
->section_offsets
= pst
->section_offsets
;
1383 subpst
->textlow
= 0;
1384 subpst
->texthigh
= 0;
1386 subpst
->dependencies
= (struct partial_symtab
**)
1387 obstack_alloc (&objfile
->objfile_obstack
,
1388 sizeof (struct partial_symtab
*));
1389 subpst
->dependencies
[0] = pst
;
1390 subpst
->number_of_dependencies
= 1;
1392 subpst
->globals_offset
= 0;
1393 subpst
->n_global_syms
= 0;
1394 subpst
->statics_offset
= 0;
1395 subpst
->n_static_syms
= 0;
1396 subpst
->symtab
= NULL
;
1397 subpst
->read_symtab
= pst
->read_symtab
;
1400 /* No private part is necessary for include psymtabs. This property
1401 can be used to differentiate between such include psymtabs and
1402 the regular ones. */
1403 subpst
->read_symtab_private
= NULL
;
1406 /* Read the Line Number Program data and extract the list of files
1407 included by the source file represented by PST. Build an include
1408 partial symtab for each of these included files.
1410 This procedure assumes that there *is* a Line Number Program in
1411 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1412 before calling this procedure. */
1415 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1416 struct partial_die_info
*pdi
,
1417 struct partial_symtab
*pst
)
1419 struct objfile
*objfile
= cu
->objfile
;
1420 bfd
*abfd
= objfile
->obfd
;
1421 struct line_header
*lh
;
1423 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1425 return; /* No linetable, so no includes. */
1427 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1429 free_line_header (lh
);
1433 /* Build the partial symbol table by doing a quick pass through the
1434 .debug_info and .debug_abbrev sections. */
1437 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1439 /* Instead of reading this into a big buffer, we should probably use
1440 mmap() on architectures that support it. (FIXME) */
1441 bfd
*abfd
= objfile
->obfd
;
1443 gdb_byte
*beg_of_comp_unit
;
1444 struct partial_die_info comp_unit_die
;
1445 struct partial_symtab
*pst
;
1446 struct cleanup
*back_to
;
1447 CORE_ADDR lowpc
, highpc
, baseaddr
;
1449 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1451 /* Any cached compilation units will be linked by the per-objfile
1452 read_in_chain. Make sure to free them when we're done. */
1453 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1455 create_all_comp_units (objfile
);
1457 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1458 (&objfile
->objfile_obstack
);
1460 /* Since the objects we're extracting from .debug_info vary in
1461 length, only the individual functions to extract them (like
1462 read_comp_unit_head and load_partial_die) can really know whether
1463 the buffer is large enough to hold another complete object.
1465 At the moment, they don't actually check that. If .debug_info
1466 holds just one extra byte after the last compilation unit's dies,
1467 then read_comp_unit_head will happily read off the end of the
1468 buffer. read_partial_die is similarly casual. Those functions
1471 For this loop condition, simply checking whether there's any data
1472 left at all should be sufficient. */
1473 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1474 + dwarf2_per_objfile
->info_size
))
1476 struct cleanup
*back_to_inner
;
1477 struct dwarf2_cu cu
;
1478 struct abbrev_info
*abbrev
;
1479 unsigned int bytes_read
;
1480 struct dwarf2_per_cu_data
*this_cu
;
1482 beg_of_comp_unit
= info_ptr
;
1484 memset (&cu
, 0, sizeof (cu
));
1486 obstack_init (&cu
.comp_unit_obstack
);
1488 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1490 cu
.objfile
= objfile
;
1491 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1493 /* Complete the cu_header */
1494 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1495 cu
.header
.first_die_ptr
= info_ptr
;
1496 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1498 cu
.list_in_scope
= &file_symbols
;
1500 /* Read the abbrevs for this compilation unit into a table */
1501 dwarf2_read_abbrevs (abfd
, &cu
);
1502 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1504 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1506 /* Read the compilation unit die */
1507 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1508 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1509 abfd
, info_ptr
, &cu
);
1511 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1513 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1514 + cu
.header
.initial_length_size
);
1515 do_cleanups (back_to_inner
);
1519 /* Set the language we're debugging */
1520 set_cu_language (comp_unit_die
.language
, &cu
);
1522 /* Allocate a new partial symbol table structure */
1523 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1524 comp_unit_die
.name
? comp_unit_die
.name
: "",
1525 /* TEXTLOW and TEXTHIGH are set below. */
1527 objfile
->global_psymbols
.next
,
1528 objfile
->static_psymbols
.next
);
1530 if (comp_unit_die
.dirname
)
1531 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1533 pst
->read_symtab_private
= (char *) this_cu
;
1535 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1537 /* Store the function that reads in the rest of the symbol table */
1538 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1540 /* If this compilation unit was already read in, free the
1541 cached copy in order to read it in again. This is
1542 necessary because we skipped some symbols when we first
1543 read in the compilation unit (see load_partial_dies).
1544 This problem could be avoided, but the benefit is
1546 if (this_cu
->cu
!= NULL
)
1547 free_one_cached_comp_unit (this_cu
->cu
);
1549 cu
.per_cu
= this_cu
;
1551 /* Note that this is a pointer to our stack frame, being
1552 added to a global data structure. It will be cleaned up
1553 in free_stack_comp_unit when we finish with this
1554 compilation unit. */
1557 this_cu
->psymtab
= pst
;
1559 /* Possibly set the default values of LOWPC and HIGHPC from
1561 if (cu
.has_ranges_offset
)
1563 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1564 &comp_unit_die
.highpc
, &cu
, pst
))
1565 comp_unit_die
.has_pc_info
= 1;
1568 /* Check if comp unit has_children.
1569 If so, read the rest of the partial symbols from this comp unit.
1570 If not, there's no more debug_info for this comp unit. */
1571 if (comp_unit_die
.has_children
)
1573 struct partial_die_info
*first_die
;
1575 lowpc
= ((CORE_ADDR
) -1);
1576 highpc
= ((CORE_ADDR
) 0);
1578 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1580 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1582 /* If we didn't find a lowpc, set it to highpc to avoid
1583 complaints from `maint check'. */
1584 if (lowpc
== ((CORE_ADDR
) -1))
1587 /* If the compilation unit didn't have an explicit address range,
1588 then use the information extracted from its child dies. */
1589 if (! comp_unit_die
.has_pc_info
)
1591 comp_unit_die
.lowpc
= lowpc
;
1592 comp_unit_die
.highpc
= highpc
;
1595 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1596 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1598 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1599 range can be also empty for CUs with no code. */
1600 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1601 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1602 pst
->texthigh
- 1, pst
);
1604 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1605 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1606 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1607 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1608 sort_pst_symbols (pst
);
1610 /* If there is already a psymtab or symtab for a file of this
1611 name, remove it. (If there is a symtab, more drastic things
1612 also happen.) This happens in VxWorks. */
1613 free_named_symtabs (pst
->filename
);
1615 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1616 + cu
.header
.initial_length_size
;
1618 if (comp_unit_die
.has_stmt_list
)
1620 /* Get the list of files included in the current compilation unit,
1621 and build a psymtab for each of them. */
1622 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1625 do_cleanups (back_to_inner
);
1628 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1629 &objfile
->objfile_obstack
);
1631 do_cleanups (back_to
);
1634 /* Load the DIEs for a secondary CU into memory. */
1637 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1639 bfd
*abfd
= objfile
->obfd
;
1640 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1641 struct partial_die_info comp_unit_die
;
1642 struct dwarf2_cu
*cu
;
1643 struct abbrev_info
*abbrev
;
1644 unsigned int bytes_read
;
1645 struct cleanup
*back_to
;
1647 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1648 beg_of_comp_unit
= info_ptr
;
1650 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1651 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1653 obstack_init (&cu
->comp_unit_obstack
);
1655 cu
->objfile
= objfile
;
1656 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1658 /* Complete the cu_header. */
1659 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1660 cu
->header
.first_die_ptr
= info_ptr
;
1661 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1663 /* Read the abbrevs for this compilation unit into a table. */
1664 dwarf2_read_abbrevs (abfd
, cu
);
1665 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1667 /* Read the compilation unit die. */
1668 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1669 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1670 abfd
, info_ptr
, cu
);
1672 /* Set the language we're debugging. */
1673 set_cu_language (comp_unit_die
.language
, cu
);
1675 /* Link this compilation unit into the compilation unit tree. */
1677 cu
->per_cu
= this_cu
;
1678 cu
->type_hash
= cu
->per_cu
->type_hash
;
1680 /* Check if comp unit has_children.
1681 If so, read the rest of the partial symbols from this comp unit.
1682 If not, there's no more debug_info for this comp unit. */
1683 if (comp_unit_die
.has_children
)
1684 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1686 do_cleanups (back_to
);
1689 /* Create a list of all compilation units in OBJFILE. We do this only
1690 if an inter-comp-unit reference is found; presumably if there is one,
1691 there will be many, and one will occur early in the .debug_info section.
1692 So there's no point in building this list incrementally. */
1695 create_all_comp_units (struct objfile
*objfile
)
1699 struct dwarf2_per_cu_data
**all_comp_units
;
1700 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1704 all_comp_units
= xmalloc (n_allocated
1705 * sizeof (struct dwarf2_per_cu_data
*));
1707 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1709 struct comp_unit_head cu_header
;
1710 gdb_byte
*beg_of_comp_unit
;
1711 struct dwarf2_per_cu_data
*this_cu
;
1712 unsigned long offset
;
1713 unsigned int bytes_read
;
1715 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1717 /* Read just enough information to find out where the next
1718 compilation unit is. */
1719 cu_header
.initial_length_size
= 0;
1720 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1721 &cu_header
, &bytes_read
);
1723 /* Save the compilation unit for later lookup. */
1724 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1725 sizeof (struct dwarf2_per_cu_data
));
1726 memset (this_cu
, 0, sizeof (*this_cu
));
1727 this_cu
->offset
= offset
;
1728 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1730 if (n_comp_units
== n_allocated
)
1733 all_comp_units
= xrealloc (all_comp_units
,
1735 * sizeof (struct dwarf2_per_cu_data
*));
1737 all_comp_units
[n_comp_units
++] = this_cu
;
1739 info_ptr
= info_ptr
+ this_cu
->length
;
1742 dwarf2_per_objfile
->all_comp_units
1743 = obstack_alloc (&objfile
->objfile_obstack
,
1744 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1745 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1746 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1747 xfree (all_comp_units
);
1748 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1751 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1752 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1756 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1757 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1759 struct objfile
*objfile
= cu
->objfile
;
1760 bfd
*abfd
= objfile
->obfd
;
1761 struct partial_die_info
*pdi
;
1763 /* Now, march along the PDI's, descending into ones which have
1764 interesting children but skipping the children of the other ones,
1765 until we reach the end of the compilation unit. */
1771 fixup_partial_die (pdi
, cu
);
1773 /* Anonymous namespaces have no name but have interesting
1774 children, so we need to look at them. Ditto for anonymous
1777 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1778 || pdi
->tag
== DW_TAG_enumeration_type
)
1782 case DW_TAG_subprogram
:
1783 if (pdi
->has_pc_info
)
1785 if (pdi
->lowpc
< *lowpc
)
1787 *lowpc
= pdi
->lowpc
;
1789 if (pdi
->highpc
> *highpc
)
1791 *highpc
= pdi
->highpc
;
1793 if (!pdi
->is_declaration
)
1795 add_partial_symbol (pdi
, cu
);
1799 case DW_TAG_variable
:
1800 case DW_TAG_typedef
:
1801 case DW_TAG_union_type
:
1802 if (!pdi
->is_declaration
)
1804 add_partial_symbol (pdi
, cu
);
1807 case DW_TAG_class_type
:
1808 case DW_TAG_interface_type
:
1809 case DW_TAG_structure_type
:
1810 if (!pdi
->is_declaration
)
1812 add_partial_symbol (pdi
, cu
);
1815 case DW_TAG_enumeration_type
:
1816 if (!pdi
->is_declaration
)
1817 add_partial_enumeration (pdi
, cu
);
1819 case DW_TAG_base_type
:
1820 case DW_TAG_subrange_type
:
1821 /* File scope base type definitions are added to the partial
1823 add_partial_symbol (pdi
, cu
);
1825 case DW_TAG_namespace
:
1826 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1833 /* If the die has a sibling, skip to the sibling. */
1835 pdi
= pdi
->die_sibling
;
1839 /* Functions used to compute the fully scoped name of a partial DIE.
1841 Normally, this is simple. For C++, the parent DIE's fully scoped
1842 name is concatenated with "::" and the partial DIE's name. For
1843 Java, the same thing occurs except that "." is used instead of "::".
1844 Enumerators are an exception; they use the scope of their parent
1845 enumeration type, i.e. the name of the enumeration type is not
1846 prepended to the enumerator.
1848 There are two complexities. One is DW_AT_specification; in this
1849 case "parent" means the parent of the target of the specification,
1850 instead of the direct parent of the DIE. The other is compilers
1851 which do not emit DW_TAG_namespace; in this case we try to guess
1852 the fully qualified name of structure types from their members'
1853 linkage names. This must be done using the DIE's children rather
1854 than the children of any DW_AT_specification target. We only need
1855 to do this for structures at the top level, i.e. if the target of
1856 any DW_AT_specification (if any; otherwise the DIE itself) does not
1859 /* Compute the scope prefix associated with PDI's parent, in
1860 compilation unit CU. The result will be allocated on CU's
1861 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1862 field. NULL is returned if no prefix is necessary. */
1864 partial_die_parent_scope (struct partial_die_info
*pdi
,
1865 struct dwarf2_cu
*cu
)
1867 char *grandparent_scope
;
1868 struct partial_die_info
*parent
, *real_pdi
;
1870 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1871 then this means the parent of the specification DIE. */
1874 while (real_pdi
->has_specification
)
1875 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1877 parent
= real_pdi
->die_parent
;
1881 if (parent
->scope_set
)
1882 return parent
->scope
;
1884 fixup_partial_die (parent
, cu
);
1886 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1888 if (parent
->tag
== DW_TAG_namespace
1889 || parent
->tag
== DW_TAG_structure_type
1890 || parent
->tag
== DW_TAG_class_type
1891 || parent
->tag
== DW_TAG_interface_type
1892 || parent
->tag
== DW_TAG_union_type
)
1894 if (grandparent_scope
== NULL
)
1895 parent
->scope
= parent
->name
;
1897 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1900 else if (parent
->tag
== DW_TAG_enumeration_type
)
1901 /* Enumerators should not get the name of the enumeration as a prefix. */
1902 parent
->scope
= grandparent_scope
;
1905 /* FIXME drow/2004-04-01: What should we be doing with
1906 function-local names? For partial symbols, we should probably be
1908 complaint (&symfile_complaints
,
1909 _("unhandled containing DIE tag %d for DIE at %d"),
1910 parent
->tag
, pdi
->offset
);
1911 parent
->scope
= grandparent_scope
;
1914 parent
->scope_set
= 1;
1915 return parent
->scope
;
1918 /* Return the fully scoped name associated with PDI, from compilation unit
1919 CU. The result will be allocated with malloc. */
1921 partial_die_full_name (struct partial_die_info
*pdi
,
1922 struct dwarf2_cu
*cu
)
1926 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1927 if (parent_scope
== NULL
)
1930 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1934 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1936 struct objfile
*objfile
= cu
->objfile
;
1938 char *actual_name
= NULL
;
1939 const char *my_prefix
;
1940 const struct partial_symbol
*psym
= NULL
;
1942 int built_actual_name
= 0;
1944 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1946 if (pdi_needs_namespace (pdi
->tag
))
1948 actual_name
= partial_die_full_name (pdi
, cu
);
1950 built_actual_name
= 1;
1953 if (actual_name
== NULL
)
1954 actual_name
= pdi
->name
;
1958 case DW_TAG_subprogram
:
1959 if (pdi
->is_external
|| cu
->language
== language_ada
)
1961 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1962 of the global scope. But in Ada, we want to be able to access
1963 nested procedures globally. So all Ada subprograms are stored
1964 in the global scope. */
1965 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1966 mst_text, objfile); */
1967 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1968 VAR_DOMAIN
, LOC_BLOCK
,
1969 &objfile
->global_psymbols
,
1970 0, pdi
->lowpc
+ baseaddr
,
1971 cu
->language
, objfile
);
1975 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1976 mst_file_text, objfile); */
1977 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1978 VAR_DOMAIN
, LOC_BLOCK
,
1979 &objfile
->static_psymbols
,
1980 0, pdi
->lowpc
+ baseaddr
,
1981 cu
->language
, objfile
);
1984 case DW_TAG_variable
:
1985 if (pdi
->is_external
)
1988 Don't enter into the minimal symbol tables as there is
1989 a minimal symbol table entry from the ELF symbols already.
1990 Enter into partial symbol table if it has a location
1991 descriptor or a type.
1992 If the location descriptor is missing, new_symbol will create
1993 a LOC_UNRESOLVED symbol, the address of the variable will then
1994 be determined from the minimal symbol table whenever the variable
1996 The address for the partial symbol table entry is not
1997 used by GDB, but it comes in handy for debugging partial symbol
2001 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2002 if (pdi
->locdesc
|| pdi
->has_type
)
2003 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2004 VAR_DOMAIN
, LOC_STATIC
,
2005 &objfile
->global_psymbols
,
2007 cu
->language
, objfile
);
2011 /* Static Variable. Skip symbols without location descriptors. */
2012 if (pdi
->locdesc
== NULL
)
2014 if (built_actual_name
)
2015 xfree (actual_name
);
2018 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2019 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2020 mst_file_data, objfile); */
2021 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2022 VAR_DOMAIN
, LOC_STATIC
,
2023 &objfile
->static_psymbols
,
2025 cu
->language
, objfile
);
2028 case DW_TAG_typedef
:
2029 case DW_TAG_base_type
:
2030 case DW_TAG_subrange_type
:
2031 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2032 VAR_DOMAIN
, LOC_TYPEDEF
,
2033 &objfile
->static_psymbols
,
2034 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2036 case DW_TAG_namespace
:
2037 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2038 VAR_DOMAIN
, LOC_TYPEDEF
,
2039 &objfile
->global_psymbols
,
2040 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2042 case DW_TAG_class_type
:
2043 case DW_TAG_interface_type
:
2044 case DW_TAG_structure_type
:
2045 case DW_TAG_union_type
:
2046 case DW_TAG_enumeration_type
:
2047 /* Skip external references. The DWARF standard says in the section
2048 about "Structure, Union, and Class Type Entries": "An incomplete
2049 structure, union or class type is represented by a structure,
2050 union or class entry that does not have a byte size attribute
2051 and that has a DW_AT_declaration attribute." */
2052 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2054 if (built_actual_name
)
2055 xfree (actual_name
);
2059 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2060 static vs. global. */
2061 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2062 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2063 (cu
->language
== language_cplus
2064 || cu
->language
== language_java
)
2065 ? &objfile
->global_psymbols
2066 : &objfile
->static_psymbols
,
2067 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2069 if (cu
->language
== language_cplus
2070 || cu
->language
== language_java
2071 || cu
->language
== language_ada
)
2073 /* For C++ and Java, these implicitly act as typedefs as well. */
2074 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2075 VAR_DOMAIN
, LOC_TYPEDEF
,
2076 &objfile
->global_psymbols
,
2077 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2080 case DW_TAG_enumerator
:
2081 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2082 VAR_DOMAIN
, LOC_CONST
,
2083 (cu
->language
== language_cplus
2084 || cu
->language
== language_java
)
2085 ? &objfile
->global_psymbols
2086 : &objfile
->static_psymbols
,
2087 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2093 /* Check to see if we should scan the name for possible namespace
2094 info. Only do this if this is C++, if we don't have namespace
2095 debugging info in the file, if the psym is of an appropriate type
2096 (otherwise we'll have psym == NULL), and if we actually had a
2097 mangled name to begin with. */
2099 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2100 cases which do not set PSYM above? */
2102 if (cu
->language
== language_cplus
2103 && cu
->has_namespace_info
== 0
2105 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2106 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2109 if (built_actual_name
)
2110 xfree (actual_name
);
2113 /* Determine whether a die of type TAG living in a C++ class or
2114 namespace needs to have the name of the scope prepended to the
2115 name listed in the die. */
2118 pdi_needs_namespace (enum dwarf_tag tag
)
2122 case DW_TAG_namespace
:
2123 case DW_TAG_typedef
:
2124 case DW_TAG_class_type
:
2125 case DW_TAG_interface_type
:
2126 case DW_TAG_structure_type
:
2127 case DW_TAG_union_type
:
2128 case DW_TAG_enumeration_type
:
2129 case DW_TAG_enumerator
:
2136 /* Read a partial die corresponding to a namespace; also, add a symbol
2137 corresponding to that namespace to the symbol table. NAMESPACE is
2138 the name of the enclosing namespace. */
2141 add_partial_namespace (struct partial_die_info
*pdi
,
2142 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2143 struct dwarf2_cu
*cu
)
2145 struct objfile
*objfile
= cu
->objfile
;
2147 /* Add a symbol for the namespace. */
2149 add_partial_symbol (pdi
, cu
);
2151 /* Now scan partial symbols in that namespace. */
2153 if (pdi
->has_children
)
2154 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2157 /* See if we can figure out if the class lives in a namespace. We do
2158 this by looking for a member function; its demangled name will
2159 contain namespace info, if there is any. */
2162 guess_structure_name (struct partial_die_info
*struct_pdi
,
2163 struct dwarf2_cu
*cu
)
2165 if ((cu
->language
== language_cplus
2166 || cu
->language
== language_java
)
2167 && cu
->has_namespace_info
== 0
2168 && struct_pdi
->has_children
)
2170 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2171 what template types look like, because the demangler
2172 frequently doesn't give the same name as the debug info. We
2173 could fix this by only using the demangled name to get the
2174 prefix (but see comment in read_structure_type). */
2176 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2177 struct partial_die_info
*real_pdi
;
2179 /* If this DIE (this DIE's specification, if any) has a parent, then
2180 we should not do this. We'll prepend the parent's fully qualified
2181 name when we create the partial symbol. */
2183 real_pdi
= struct_pdi
;
2184 while (real_pdi
->has_specification
)
2185 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2187 if (real_pdi
->die_parent
!= NULL
)
2190 while (child_pdi
!= NULL
)
2192 if (child_pdi
->tag
== DW_TAG_subprogram
)
2194 char *actual_class_name
2195 = language_class_name_from_physname (cu
->language_defn
,
2197 if (actual_class_name
!= NULL
)
2200 = obsavestring (actual_class_name
,
2201 strlen (actual_class_name
),
2202 &cu
->comp_unit_obstack
);
2203 xfree (actual_class_name
);
2208 child_pdi
= child_pdi
->die_sibling
;
2213 /* Read a partial die corresponding to an enumeration type. */
2216 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2217 struct dwarf2_cu
*cu
)
2219 struct objfile
*objfile
= cu
->objfile
;
2220 bfd
*abfd
= objfile
->obfd
;
2221 struct partial_die_info
*pdi
;
2223 if (enum_pdi
->name
!= NULL
)
2224 add_partial_symbol (enum_pdi
, cu
);
2226 pdi
= enum_pdi
->die_child
;
2229 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2230 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2232 add_partial_symbol (pdi
, cu
);
2233 pdi
= pdi
->die_sibling
;
2237 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2238 Return the corresponding abbrev, or NULL if the number is zero (indicating
2239 an empty DIE). In either case *BYTES_READ will be set to the length of
2240 the initial number. */
2242 static struct abbrev_info
*
2243 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2244 struct dwarf2_cu
*cu
)
2246 bfd
*abfd
= cu
->objfile
->obfd
;
2247 unsigned int abbrev_number
;
2248 struct abbrev_info
*abbrev
;
2250 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2252 if (abbrev_number
== 0)
2255 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2258 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2259 bfd_get_filename (abfd
));
2265 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2266 pointer to the end of a series of DIEs, terminated by an empty
2267 DIE. Any children of the skipped DIEs will also be skipped. */
2270 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2272 struct abbrev_info
*abbrev
;
2273 unsigned int bytes_read
;
2277 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2279 return info_ptr
+ bytes_read
;
2281 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2285 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2286 should point just after the initial uleb128 of a DIE, and the
2287 abbrev corresponding to that skipped uleb128 should be passed in
2288 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2292 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2293 struct dwarf2_cu
*cu
)
2295 unsigned int bytes_read
;
2296 struct attribute attr
;
2297 bfd
*abfd
= cu
->objfile
->obfd
;
2298 unsigned int form
, i
;
2300 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2302 /* The only abbrev we care about is DW_AT_sibling. */
2303 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2305 read_attribute (&attr
, &abbrev
->attrs
[i
],
2306 abfd
, info_ptr
, cu
);
2307 if (attr
.form
== DW_FORM_ref_addr
)
2308 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2310 return dwarf2_per_objfile
->info_buffer
2311 + dwarf2_get_ref_die_offset (&attr
, cu
);
2314 /* If it isn't DW_AT_sibling, skip this attribute. */
2315 form
= abbrev
->attrs
[i
].form
;
2320 case DW_FORM_ref_addr
:
2321 info_ptr
+= cu
->header
.addr_size
;
2340 case DW_FORM_string
:
2341 read_string (abfd
, info_ptr
, &bytes_read
);
2342 info_ptr
+= bytes_read
;
2345 info_ptr
+= cu
->header
.offset_size
;
2348 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2349 info_ptr
+= bytes_read
;
2351 case DW_FORM_block1
:
2352 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2354 case DW_FORM_block2
:
2355 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2357 case DW_FORM_block4
:
2358 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2362 case DW_FORM_ref_udata
:
2363 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2365 case DW_FORM_indirect
:
2366 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2367 info_ptr
+= bytes_read
;
2368 /* We need to continue parsing from here, so just go back to
2370 goto skip_attribute
;
2373 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2374 dwarf_form_name (form
),
2375 bfd_get_filename (abfd
));
2379 if (abbrev
->has_children
)
2380 return skip_children (info_ptr
, cu
);
2385 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2386 the next DIE after ORIG_PDI. */
2389 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2390 bfd
*abfd
, struct dwarf2_cu
*cu
)
2392 /* Do we know the sibling already? */
2394 if (orig_pdi
->sibling
)
2395 return orig_pdi
->sibling
;
2397 /* Are there any children to deal with? */
2399 if (!orig_pdi
->has_children
)
2402 /* Skip the children the long way. */
2404 return skip_children (info_ptr
, cu
);
2407 /* Expand this partial symbol table into a full symbol table. */
2410 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2412 /* FIXME: This is barely more than a stub. */
2417 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2423 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2424 gdb_flush (gdb_stdout
);
2427 /* Restore our global data. */
2428 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2429 dwarf2_objfile_data_key
);
2431 psymtab_to_symtab_1 (pst
);
2433 /* Finish up the debug error message. */
2435 printf_filtered (_("done.\n"));
2440 /* Add PER_CU to the queue. */
2443 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2445 struct dwarf2_queue_item
*item
;
2448 item
= xmalloc (sizeof (*item
));
2449 item
->per_cu
= per_cu
;
2452 if (dwarf2_queue
== NULL
)
2453 dwarf2_queue
= item
;
2455 dwarf2_queue_tail
->next
= item
;
2457 dwarf2_queue_tail
= item
;
2460 /* Process the queue. */
2463 process_queue (struct objfile
*objfile
)
2465 struct dwarf2_queue_item
*item
, *next_item
;
2467 /* Initially, there is just one item on the queue. Load its DIEs,
2468 and the DIEs of any other compilation units it requires,
2471 for (item
= dwarf2_queue
; item
!= NULL
; item
= item
->next
)
2473 /* Read in this compilation unit. This may add new items to
2474 the end of the queue. */
2475 load_full_comp_unit (item
->per_cu
, objfile
);
2477 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2478 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2481 /* Now everything left on the queue needs to be read in. Process
2482 them, one at a time, removing from the queue as we finish. */
2483 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2485 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2486 process_full_comp_unit (item
->per_cu
);
2488 item
->per_cu
->queued
= 0;
2489 next_item
= item
->next
;
2493 dwarf2_queue_tail
= NULL
;
2496 /* Free all allocated queue entries. This function only releases anything if
2497 an error was thrown; if the queue was processed then it would have been
2498 freed as we went along. */
2501 dwarf2_release_queue (void *dummy
)
2503 struct dwarf2_queue_item
*item
, *last
;
2505 item
= dwarf2_queue
;
2508 /* Anything still marked queued is likely to be in an
2509 inconsistent state, so discard it. */
2510 if (item
->per_cu
->queued
)
2512 if (item
->per_cu
->cu
!= NULL
)
2513 free_one_cached_comp_unit (item
->per_cu
->cu
);
2514 item
->per_cu
->queued
= 0;
2522 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2525 /* Read in full symbols for PST, and anything it depends on. */
2528 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2530 struct dwarf2_per_cu_data
*per_cu
;
2531 struct cleanup
*back_to
;
2534 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2535 if (!pst
->dependencies
[i
]->readin
)
2537 /* Inform about additional files that need to be read in. */
2540 /* FIXME: i18n: Need to make this a single string. */
2541 fputs_filtered (" ", gdb_stdout
);
2543 fputs_filtered ("and ", gdb_stdout
);
2545 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2546 wrap_here (""); /* Flush output */
2547 gdb_flush (gdb_stdout
);
2549 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2552 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2556 /* It's an include file, no symbols to read for it.
2557 Everything is in the parent symtab. */
2562 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2564 queue_comp_unit (per_cu
);
2566 process_queue (pst
->objfile
);
2568 /* Age the cache, releasing compilation units that have not
2569 been used recently. */
2570 age_cached_comp_units ();
2572 do_cleanups (back_to
);
2575 /* Load the DIEs associated with PST and PER_CU into memory. */
2577 static struct dwarf2_cu
*
2578 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2580 bfd
*abfd
= objfile
->obfd
;
2581 struct dwarf2_cu
*cu
;
2582 unsigned long offset
;
2584 struct cleanup
*back_to
, *free_cu_cleanup
;
2585 struct attribute
*attr
;
2588 /* Set local variables from the partial symbol table info. */
2589 offset
= per_cu
->offset
;
2591 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2593 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2594 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2596 /* If an error occurs while loading, release our storage. */
2597 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2599 cu
->objfile
= objfile
;
2601 /* read in the comp_unit header */
2602 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2604 /* Read the abbrevs for this compilation unit */
2605 dwarf2_read_abbrevs (abfd
, cu
);
2606 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2608 cu
->header
.offset
= offset
;
2610 cu
->per_cu
= per_cu
;
2612 cu
->type_hash
= per_cu
->type_hash
;
2614 /* We use this obstack for block values in dwarf_alloc_block. */
2615 obstack_init (&cu
->comp_unit_obstack
);
2617 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2619 /* We try not to read any attributes in this function, because not
2620 all objfiles needed for references have been loaded yet, and symbol
2621 table processing isn't initialized. But we have to set the CU language,
2622 or we won't be able to build types correctly. */
2623 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2625 set_cu_language (DW_UNSND (attr
), cu
);
2627 set_cu_language (language_minimal
, cu
);
2629 do_cleanups (back_to
);
2631 /* We've successfully allocated this compilation unit. Let our caller
2632 clean it up when finished with it. */
2633 discard_cleanups (free_cu_cleanup
);
2638 /* Generate full symbol information for PST and CU, whose DIEs have
2639 already been loaded into memory. */
2642 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2644 struct partial_symtab
*pst
= per_cu
->psymtab
;
2645 struct dwarf2_cu
*cu
= per_cu
->cu
;
2646 struct objfile
*objfile
= pst
->objfile
;
2647 bfd
*abfd
= objfile
->obfd
;
2648 CORE_ADDR lowpc
, highpc
;
2649 struct symtab
*symtab
;
2650 struct cleanup
*back_to
;
2651 struct attribute
*attr
;
2654 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2656 /* We're in the global namespace. */
2657 processing_current_prefix
= "";
2660 back_to
= make_cleanup (really_free_pendings
, NULL
);
2662 cu
->list_in_scope
= &file_symbols
;
2664 /* Find the base address of the compilation unit for range lists and
2665 location lists. It will normally be specified by DW_AT_low_pc.
2666 In DWARF-3 draft 4, the base address could be overridden by
2667 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2668 compilation units with discontinuous ranges. */
2670 cu
->header
.base_known
= 0;
2671 cu
->header
.base_address
= 0;
2673 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2676 cu
->header
.base_address
= DW_ADDR (attr
);
2677 cu
->header
.base_known
= 1;
2681 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2684 cu
->header
.base_address
= DW_ADDR (attr
);
2685 cu
->header
.base_known
= 1;
2689 /* Do line number decoding in read_file_scope () */
2690 process_die (cu
->dies
, cu
);
2692 /* Some compilers don't define a DW_AT_high_pc attribute for the
2693 compilation unit. If the DW_AT_high_pc is missing, synthesize
2694 it, by scanning the DIE's below the compilation unit. */
2695 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2697 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2699 /* Set symtab language to language from DW_AT_language.
2700 If the compilation is from a C file generated by language preprocessors,
2701 do not set the language if it was already deduced by start_subfile. */
2703 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2705 symtab
->language
= cu
->language
;
2707 pst
->symtab
= symtab
;
2710 do_cleanups (back_to
);
2713 /* Process a die and its children. */
2716 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2720 case DW_TAG_padding
:
2722 case DW_TAG_compile_unit
:
2723 read_file_scope (die
, cu
);
2725 case DW_TAG_subprogram
:
2726 read_func_scope (die
, cu
);
2728 case DW_TAG_inlined_subroutine
:
2729 /* FIXME: These are ignored for now.
2730 They could be used to set breakpoints on all inlined instances
2731 of a function and make GDB `next' properly over inlined functions. */
2733 case DW_TAG_lexical_block
:
2734 case DW_TAG_try_block
:
2735 case DW_TAG_catch_block
:
2736 read_lexical_block_scope (die
, cu
);
2738 case DW_TAG_class_type
:
2739 case DW_TAG_interface_type
:
2740 case DW_TAG_structure_type
:
2741 case DW_TAG_union_type
:
2742 process_structure_scope (die
, cu
);
2744 case DW_TAG_enumeration_type
:
2745 process_enumeration_scope (die
, cu
);
2748 /* These dies have a type, but processing them does not create
2749 a symbol or recurse to process the children. Therefore we can
2750 read them on-demand through read_type_die. */
2751 case DW_TAG_subroutine_type
:
2752 case DW_TAG_set_type
:
2753 case DW_TAG_array_type
:
2754 case DW_TAG_pointer_type
:
2755 case DW_TAG_ptr_to_member_type
:
2756 case DW_TAG_reference_type
:
2757 case DW_TAG_string_type
:
2760 case DW_TAG_base_type
:
2761 case DW_TAG_subrange_type
:
2762 /* Add a typedef symbol for the type definition, if it has a
2764 new_symbol (die
, read_type_die (die
, cu
), cu
);
2766 case DW_TAG_common_block
:
2767 read_common_block (die
, cu
);
2769 case DW_TAG_common_inclusion
:
2771 case DW_TAG_namespace
:
2772 processing_has_namespace_info
= 1;
2773 read_namespace (die
, cu
);
2775 case DW_TAG_imported_declaration
:
2776 case DW_TAG_imported_module
:
2777 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2778 information contained in these. DW_TAG_imported_declaration
2779 dies shouldn't have children; DW_TAG_imported_module dies
2780 shouldn't in the C++ case, but conceivably could in the
2781 Fortran case, so we'll have to replace this gdb_assert if
2782 Fortran compilers start generating that info. */
2783 processing_has_namespace_info
= 1;
2784 gdb_assert (die
->child
== NULL
);
2787 new_symbol (die
, NULL
, cu
);
2793 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2795 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2799 free_cu_line_header (void *arg
)
2801 struct dwarf2_cu
*cu
= arg
;
2803 free_line_header (cu
->line_header
);
2804 cu
->line_header
= NULL
;
2808 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2810 struct objfile
*objfile
= cu
->objfile
;
2811 struct comp_unit_head
*cu_header
= &cu
->header
;
2812 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2813 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2814 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2815 struct attribute
*attr
;
2817 char *comp_dir
= NULL
;
2818 struct die_info
*child_die
;
2819 bfd
*abfd
= objfile
->obfd
;
2820 struct line_header
*line_header
= 0;
2823 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2825 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2827 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2828 from finish_block. */
2829 if (lowpc
== ((CORE_ADDR
) -1))
2834 /* Find the filename. Do not use dwarf2_name here, since the filename
2835 is not a source language identifier. */
2836 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2839 name
= DW_STRING (attr
);
2842 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2844 comp_dir
= DW_STRING (attr
);
2845 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2847 comp_dir
= ldirname (name
);
2848 if (comp_dir
!= NULL
)
2849 make_cleanup (xfree
, comp_dir
);
2851 if (comp_dir
!= NULL
)
2853 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2854 directory, get rid of it. */
2855 char *cp
= strchr (comp_dir
, ':');
2857 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2864 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2867 set_cu_language (DW_UNSND (attr
), cu
);
2870 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2872 cu
->producer
= DW_STRING (attr
);
2874 /* We assume that we're processing GCC output. */
2875 processing_gcc_compilation
= 2;
2877 start_symtab (name
, comp_dir
, lowpc
);
2878 record_debugformat ("DWARF 2");
2879 record_producer (cu
->producer
);
2881 initialize_cu_func_list (cu
);
2883 /* Decode line number information if present. We do this before
2884 processing child DIEs, so that the line header table is available
2885 for DW_AT_decl_file. */
2886 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2889 unsigned int line_offset
= DW_UNSND (attr
);
2890 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2893 cu
->line_header
= line_header
;
2894 make_cleanup (free_cu_line_header
, cu
);
2895 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2899 /* Process all dies in compilation unit. */
2900 if (die
->child
!= NULL
)
2902 child_die
= die
->child
;
2903 while (child_die
&& child_die
->tag
)
2905 process_die (child_die
, cu
);
2906 child_die
= sibling_die (child_die
);
2910 /* Decode macro information, if present. Dwarf 2 macro information
2911 refers to information in the line number info statement program
2912 header, so we can only read it if we've read the header
2914 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2915 if (attr
&& line_header
)
2917 unsigned int macro_offset
= DW_UNSND (attr
);
2918 dwarf_decode_macros (line_header
, macro_offset
,
2919 comp_dir
, abfd
, cu
);
2921 do_cleanups (back_to
);
2925 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2926 struct dwarf2_cu
*cu
)
2928 struct function_range
*thisfn
;
2930 thisfn
= (struct function_range
*)
2931 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2932 thisfn
->name
= name
;
2933 thisfn
->lowpc
= lowpc
;
2934 thisfn
->highpc
= highpc
;
2935 thisfn
->seen_line
= 0;
2936 thisfn
->next
= NULL
;
2938 if (cu
->last_fn
== NULL
)
2939 cu
->first_fn
= thisfn
;
2941 cu
->last_fn
->next
= thisfn
;
2943 cu
->last_fn
= thisfn
;
2947 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2949 struct objfile
*objfile
= cu
->objfile
;
2950 struct context_stack
*new;
2953 struct die_info
*child_die
;
2954 struct attribute
*attr
;
2956 const char *previous_prefix
= processing_current_prefix
;
2957 struct cleanup
*back_to
= NULL
;
2959 struct block
*block
;
2961 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2963 name
= dwarf2_linkage_name (die
, cu
);
2965 /* Ignore functions with missing or empty names and functions with
2966 missing or invalid low and high pc attributes. */
2967 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2970 if (cu
->language
== language_cplus
2971 || cu
->language
== language_java
)
2973 struct die_info
*spec_die
= die_specification (die
, cu
);
2975 /* NOTE: carlton/2004-01-23: We have to be careful in the
2976 presence of DW_AT_specification. For example, with GCC 3.4,
2981 // Definition of N::foo.
2985 then we'll have a tree of DIEs like this:
2987 1: DW_TAG_compile_unit
2988 2: DW_TAG_namespace // N
2989 3: DW_TAG_subprogram // declaration of N::foo
2990 4: DW_TAG_subprogram // definition of N::foo
2991 DW_AT_specification // refers to die #3
2993 Thus, when processing die #4, we have to pretend that we're
2994 in the context of its DW_AT_specification, namely the contex
2997 if (spec_die
!= NULL
)
2999 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3000 processing_current_prefix
= specification_prefix
;
3001 back_to
= make_cleanup (xfree
, specification_prefix
);
3008 /* Record the function range for dwarf_decode_lines. */
3009 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3011 new = push_context (0, lowpc
);
3012 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3014 /* If there is a location expression for DW_AT_frame_base, record
3016 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3018 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3019 expression is being recorded directly in the function's symbol
3020 and not in a separate frame-base object. I guess this hack is
3021 to avoid adding some sort of frame-base adjunct/annex to the
3022 function's symbol :-(. The problem with doing this is that it
3023 results in a function symbol with a location expression that
3024 has nothing to do with the location of the function, ouch! The
3025 relationship should be: a function's symbol has-a frame base; a
3026 frame-base has-a location expression. */
3027 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3029 cu
->list_in_scope
= &local_symbols
;
3031 if (die
->child
!= NULL
)
3033 child_die
= die
->child
;
3034 while (child_die
&& child_die
->tag
)
3036 process_die (child_die
, cu
);
3037 child_die
= sibling_die (child_die
);
3041 new = pop_context ();
3042 /* Make a block for the local symbols within. */
3043 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3044 lowpc
, highpc
, objfile
);
3046 /* If we have address ranges, record them. */
3047 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3049 /* In C++, we can have functions nested inside functions (e.g., when
3050 a function declares a class that has methods). This means that
3051 when we finish processing a function scope, we may need to go
3052 back to building a containing block's symbol lists. */
3053 local_symbols
= new->locals
;
3054 param_symbols
= new->params
;
3056 /* If we've finished processing a top-level function, subsequent
3057 symbols go in the file symbol list. */
3058 if (outermost_context_p ())
3059 cu
->list_in_scope
= &file_symbols
;
3061 processing_current_prefix
= previous_prefix
;
3062 if (back_to
!= NULL
)
3063 do_cleanups (back_to
);
3066 /* Process all the DIES contained within a lexical block scope. Start
3067 a new scope, process the dies, and then close the scope. */
3070 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3072 struct objfile
*objfile
= cu
->objfile
;
3073 struct context_stack
*new;
3074 CORE_ADDR lowpc
, highpc
;
3075 struct die_info
*child_die
;
3078 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3080 /* Ignore blocks with missing or invalid low and high pc attributes. */
3081 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3082 as multiple lexical blocks? Handling children in a sane way would
3083 be nasty. Might be easier to properly extend generic blocks to
3085 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3090 push_context (0, lowpc
);
3091 if (die
->child
!= NULL
)
3093 child_die
= die
->child
;
3094 while (child_die
&& child_die
->tag
)
3096 process_die (child_die
, cu
);
3097 child_die
= sibling_die (child_die
);
3100 new = pop_context ();
3102 if (local_symbols
!= NULL
)
3105 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3108 /* Note that recording ranges after traversing children, as we
3109 do here, means that recording a parent's ranges entails
3110 walking across all its children's ranges as they appear in
3111 the address map, which is quadratic behavior.
3113 It would be nicer to record the parent's ranges before
3114 traversing its children, simply overriding whatever you find
3115 there. But since we don't even decide whether to create a
3116 block until after we've traversed its children, that's hard
3118 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3120 local_symbols
= new->locals
;
3123 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3124 Return 1 if the attributes are present and valid, otherwise, return 0.
3125 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3128 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3129 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3130 struct partial_symtab
*ranges_pst
)
3132 struct objfile
*objfile
= cu
->objfile
;
3133 struct comp_unit_head
*cu_header
= &cu
->header
;
3134 bfd
*obfd
= objfile
->obfd
;
3135 unsigned int addr_size
= cu_header
->addr_size
;
3136 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3137 /* Base address selection entry. */
3148 found_base
= cu_header
->base_known
;
3149 base
= cu_header
->base_address
;
3151 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3153 complaint (&symfile_complaints
,
3154 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3158 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3160 /* Read in the largest possible address. */
3161 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3162 if ((marker
& mask
) == mask
)
3164 /* If we found the largest possible address, then
3165 read the base address. */
3166 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3167 buffer
+= 2 * addr_size
;
3168 offset
+= 2 * addr_size
;
3174 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3178 CORE_ADDR range_beginning
, range_end
;
3180 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3181 buffer
+= addr_size
;
3182 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3183 buffer
+= addr_size
;
3184 offset
+= 2 * addr_size
;
3186 /* An end of list marker is a pair of zero addresses. */
3187 if (range_beginning
== 0 && range_end
== 0)
3188 /* Found the end of list entry. */
3191 /* Each base address selection entry is a pair of 2 values.
3192 The first is the largest possible address, the second is
3193 the base address. Check for a base address here. */
3194 if ((range_beginning
& mask
) == mask
)
3196 /* If we found the largest possible address, then
3197 read the base address. */
3198 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3205 /* We have no valid base address for the ranges
3207 complaint (&symfile_complaints
,
3208 _("Invalid .debug_ranges data (no base address)"));
3212 range_beginning
+= base
;
3215 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3216 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3217 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3220 /* FIXME: This is recording everything as a low-high
3221 segment of consecutive addresses. We should have a
3222 data structure for discontiguous block ranges
3226 low
= range_beginning
;
3232 if (range_beginning
< low
)
3233 low
= range_beginning
;
3234 if (range_end
> high
)
3240 /* If the first entry is an end-of-list marker, the range
3241 describes an empty scope, i.e. no instructions. */
3247 *high_return
= high
;
3251 /* Get low and high pc attributes from a die. Return 1 if the attributes
3252 are present and valid, otherwise, return 0. Return -1 if the range is
3253 discontinuous, i.e. derived from DW_AT_ranges information. */
3255 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3256 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3258 struct attribute
*attr
;
3263 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3266 high
= DW_ADDR (attr
);
3267 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3269 low
= DW_ADDR (attr
);
3271 /* Found high w/o low attribute. */
3274 /* Found consecutive range of addresses. */
3279 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3282 /* Value of the DW_AT_ranges attribute is the offset in the
3283 .debug_ranges section. */
3284 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3286 /* Found discontinuous range of addresses. */
3294 /* When using the GNU linker, .gnu.linkonce. sections are used to
3295 eliminate duplicate copies of functions and vtables and such.
3296 The linker will arbitrarily choose one and discard the others.
3297 The AT_*_pc values for such functions refer to local labels in
3298 these sections. If the section from that file was discarded, the
3299 labels are not in the output, so the relocs get a value of 0.
3300 If this is a discarded function, mark the pc bounds as invalid,
3301 so that GDB will ignore it. */
3302 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3310 /* Get the low and high pc's represented by the scope DIE, and store
3311 them in *LOWPC and *HIGHPC. If the correct values can't be
3312 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3315 get_scope_pc_bounds (struct die_info
*die
,
3316 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3317 struct dwarf2_cu
*cu
)
3319 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3320 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3321 CORE_ADDR current_low
, current_high
;
3323 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3325 best_low
= current_low
;
3326 best_high
= current_high
;
3330 struct die_info
*child
= die
->child
;
3332 while (child
&& child
->tag
)
3334 switch (child
->tag
) {
3335 case DW_TAG_subprogram
:
3336 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3338 best_low
= min (best_low
, current_low
);
3339 best_high
= max (best_high
, current_high
);
3342 case DW_TAG_namespace
:
3343 /* FIXME: carlton/2004-01-16: Should we do this for
3344 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3345 that current GCC's always emit the DIEs corresponding
3346 to definitions of methods of classes as children of a
3347 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3348 the DIEs giving the declarations, which could be
3349 anywhere). But I don't see any reason why the
3350 standards says that they have to be there. */
3351 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3353 if (current_low
!= ((CORE_ADDR
) -1))
3355 best_low
= min (best_low
, current_low
);
3356 best_high
= max (best_high
, current_high
);
3364 child
= sibling_die (child
);
3369 *highpc
= best_high
;
3372 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3375 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3376 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3378 struct attribute
*attr
;
3380 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3383 CORE_ADDR high
= DW_ADDR (attr
);
3384 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3387 CORE_ADDR low
= DW_ADDR (attr
);
3388 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3392 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3395 bfd
*obfd
= cu
->objfile
->obfd
;
3397 /* The value of the DW_AT_ranges attribute is the offset of the
3398 address range list in the .debug_ranges section. */
3399 unsigned long offset
= DW_UNSND (attr
);
3400 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3402 /* For some target architectures, but not others, the
3403 read_address function sign-extends the addresses it returns.
3404 To recognize base address selection entries, we need a
3406 unsigned int addr_size
= cu
->header
.addr_size
;
3407 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3409 /* The base address, to which the next pair is relative. Note
3410 that this 'base' is a DWARF concept: most entries in a range
3411 list are relative, to reduce the number of relocs against the
3412 debugging information. This is separate from this function's
3413 'baseaddr' argument, which GDB uses to relocate debugging
3414 information from a shared library based on the address at
3415 which the library was loaded. */
3416 CORE_ADDR base
= cu
->header
.base_address
;
3417 int base_known
= cu
->header
.base_known
;
3419 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3421 complaint (&symfile_complaints
,
3422 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3429 unsigned int bytes_read
;
3430 CORE_ADDR start
, end
;
3432 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3433 buffer
+= bytes_read
;
3434 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3435 buffer
+= bytes_read
;
3437 /* Did we find the end of the range list? */
3438 if (start
== 0 && end
== 0)
3441 /* Did we find a base address selection entry? */
3442 else if ((start
& base_select_mask
) == base_select_mask
)
3448 /* We found an ordinary address range. */
3453 complaint (&symfile_complaints
,
3454 _("Invalid .debug_ranges data (no base address)"));
3458 record_block_range (block
,
3459 baseaddr
+ base
+ start
,
3460 baseaddr
+ base
+ end
- 1);
3466 /* Add an aggregate field to the field list. */
3469 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3470 struct dwarf2_cu
*cu
)
3472 struct objfile
*objfile
= cu
->objfile
;
3473 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3474 struct nextfield
*new_field
;
3475 struct attribute
*attr
;
3477 char *fieldname
= "";
3479 /* Allocate a new field list entry and link it in. */
3480 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3481 make_cleanup (xfree
, new_field
);
3482 memset (new_field
, 0, sizeof (struct nextfield
));
3483 new_field
->next
= fip
->fields
;
3484 fip
->fields
= new_field
;
3487 /* Handle accessibility and virtuality of field.
3488 The default accessibility for members is public, the default
3489 accessibility for inheritance is private. */
3490 if (die
->tag
!= DW_TAG_inheritance
)
3491 new_field
->accessibility
= DW_ACCESS_public
;
3493 new_field
->accessibility
= DW_ACCESS_private
;
3494 new_field
->virtuality
= DW_VIRTUALITY_none
;
3496 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3498 new_field
->accessibility
= DW_UNSND (attr
);
3499 if (new_field
->accessibility
!= DW_ACCESS_public
)
3500 fip
->non_public_fields
= 1;
3501 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3503 new_field
->virtuality
= DW_UNSND (attr
);
3505 fp
= &new_field
->field
;
3507 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3509 /* Data member other than a C++ static data member. */
3511 /* Get type of field. */
3512 fp
->type
= die_type (die
, cu
);
3514 FIELD_STATIC_KIND (*fp
) = 0;
3516 /* Get bit size of field (zero if none). */
3517 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3520 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3524 FIELD_BITSIZE (*fp
) = 0;
3527 /* Get bit offset of field. */
3528 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3533 if (attr_form_is_section_offset (attr
))
3535 dwarf2_complex_location_expr_complaint ();
3538 else if (attr_form_is_constant (attr
))
3539 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3541 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3543 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3546 FIELD_BITPOS (*fp
) = 0;
3547 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3550 if (gdbarch_bits_big_endian (gdbarch
))
3552 /* For big endian bits, the DW_AT_bit_offset gives the
3553 additional bit offset from the MSB of the containing
3554 anonymous object to the MSB of the field. We don't
3555 have to do anything special since we don't need to
3556 know the size of the anonymous object. */
3557 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3561 /* For little endian bits, compute the bit offset to the
3562 MSB of the anonymous object, subtract off the number of
3563 bits from the MSB of the field to the MSB of the
3564 object, and then subtract off the number of bits of
3565 the field itself. The result is the bit offset of
3566 the LSB of the field. */
3568 int bit_offset
= DW_UNSND (attr
);
3570 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3573 /* The size of the anonymous object containing
3574 the bit field is explicit, so use the
3575 indicated size (in bytes). */
3576 anonymous_size
= DW_UNSND (attr
);
3580 /* The size of the anonymous object containing
3581 the bit field must be inferred from the type
3582 attribute of the data member containing the
3584 anonymous_size
= TYPE_LENGTH (fp
->type
);
3586 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3587 - bit_offset
- FIELD_BITSIZE (*fp
);
3591 /* Get name of field. */
3592 fieldname
= dwarf2_name (die
, cu
);
3593 if (fieldname
== NULL
)
3596 /* The name is already allocated along with this objfile, so we don't
3597 need to duplicate it for the type. */
3598 fp
->name
= fieldname
;
3600 /* Change accessibility for artificial fields (e.g. virtual table
3601 pointer or virtual base class pointer) to private. */
3602 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3604 new_field
->accessibility
= DW_ACCESS_private
;
3605 fip
->non_public_fields
= 1;
3608 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3610 /* C++ static member. */
3612 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3613 is a declaration, but all versions of G++ as of this writing
3614 (so through at least 3.2.1) incorrectly generate
3615 DW_TAG_variable tags. */
3619 /* Get name of field. */
3620 fieldname
= dwarf2_name (die
, cu
);
3621 if (fieldname
== NULL
)
3624 /* Get physical name. */
3625 physname
= dwarf2_linkage_name (die
, cu
);
3627 /* The name is already allocated along with this objfile, so we don't
3628 need to duplicate it for the type. */
3629 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3630 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3631 FIELD_NAME (*fp
) = fieldname
;
3633 else if (die
->tag
== DW_TAG_inheritance
)
3635 /* C++ base class field. */
3636 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3638 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3640 FIELD_BITSIZE (*fp
) = 0;
3641 FIELD_STATIC_KIND (*fp
) = 0;
3642 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3643 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3644 fip
->nbaseclasses
++;
3648 /* Create the vector of fields, and attach it to the type. */
3651 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3652 struct dwarf2_cu
*cu
)
3654 int nfields
= fip
->nfields
;
3656 /* Record the field count, allocate space for the array of fields,
3657 and create blank accessibility bitfields if necessary. */
3658 TYPE_NFIELDS (type
) = nfields
;
3659 TYPE_FIELDS (type
) = (struct field
*)
3660 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3661 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3663 if (fip
->non_public_fields
)
3665 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3667 TYPE_FIELD_PRIVATE_BITS (type
) =
3668 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3669 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3671 TYPE_FIELD_PROTECTED_BITS (type
) =
3672 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3673 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3675 TYPE_FIELD_IGNORE_BITS (type
) =
3676 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3677 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3680 /* If the type has baseclasses, allocate and clear a bit vector for
3681 TYPE_FIELD_VIRTUAL_BITS. */
3682 if (fip
->nbaseclasses
)
3684 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3685 unsigned char *pointer
;
3687 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3688 pointer
= TYPE_ALLOC (type
, num_bytes
);
3689 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3690 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3691 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3694 /* Copy the saved-up fields into the field vector. Start from the head
3695 of the list, adding to the tail of the field array, so that they end
3696 up in the same order in the array in which they were added to the list. */
3697 while (nfields
-- > 0)
3699 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3700 switch (fip
->fields
->accessibility
)
3702 case DW_ACCESS_private
:
3703 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3706 case DW_ACCESS_protected
:
3707 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3710 case DW_ACCESS_public
:
3714 /* Unknown accessibility. Complain and treat it as public. */
3716 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3717 fip
->fields
->accessibility
);
3721 if (nfields
< fip
->nbaseclasses
)
3723 switch (fip
->fields
->virtuality
)
3725 case DW_VIRTUALITY_virtual
:
3726 case DW_VIRTUALITY_pure_virtual
:
3727 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3731 fip
->fields
= fip
->fields
->next
;
3735 /* Add a member function to the proper fieldlist. */
3738 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3739 struct type
*type
, struct dwarf2_cu
*cu
)
3741 struct objfile
*objfile
= cu
->objfile
;
3742 struct attribute
*attr
;
3743 struct fnfieldlist
*flp
;
3745 struct fn_field
*fnp
;
3748 struct nextfnfield
*new_fnfield
;
3749 struct type
*this_type
;
3751 /* Get name of member function. */
3752 fieldname
= dwarf2_name (die
, cu
);
3753 if (fieldname
== NULL
)
3756 /* Get the mangled name. */
3757 physname
= dwarf2_linkage_name (die
, cu
);
3759 /* Look up member function name in fieldlist. */
3760 for (i
= 0; i
< fip
->nfnfields
; i
++)
3762 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3766 /* Create new list element if necessary. */
3767 if (i
< fip
->nfnfields
)
3768 flp
= &fip
->fnfieldlists
[i
];
3771 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3773 fip
->fnfieldlists
= (struct fnfieldlist
*)
3774 xrealloc (fip
->fnfieldlists
,
3775 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3776 * sizeof (struct fnfieldlist
));
3777 if (fip
->nfnfields
== 0)
3778 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3780 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3781 flp
->name
= fieldname
;
3787 /* Create a new member function field and chain it to the field list
3789 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3790 make_cleanup (xfree
, new_fnfield
);
3791 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3792 new_fnfield
->next
= flp
->head
;
3793 flp
->head
= new_fnfield
;
3796 /* Fill in the member function field info. */
3797 fnp
= &new_fnfield
->fnfield
;
3798 /* The name is already allocated along with this objfile, so we don't
3799 need to duplicate it for the type. */
3800 fnp
->physname
= physname
? physname
: "";
3801 fnp
->type
= alloc_type (objfile
);
3802 this_type
= read_type_die (die
, cu
);
3803 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3805 int nparams
= TYPE_NFIELDS (this_type
);
3807 /* TYPE is the domain of this method, and THIS_TYPE is the type
3808 of the method itself (TYPE_CODE_METHOD). */
3809 smash_to_method_type (fnp
->type
, type
,
3810 TYPE_TARGET_TYPE (this_type
),
3811 TYPE_FIELDS (this_type
),
3812 TYPE_NFIELDS (this_type
),
3813 TYPE_VARARGS (this_type
));
3815 /* Handle static member functions.
3816 Dwarf2 has no clean way to discern C++ static and non-static
3817 member functions. G++ helps GDB by marking the first
3818 parameter for non-static member functions (which is the
3819 this pointer) as artificial. We obtain this information
3820 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3821 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3822 fnp
->voffset
= VOFFSET_STATIC
;
3825 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3828 /* Get fcontext from DW_AT_containing_type if present. */
3829 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3830 fnp
->fcontext
= die_containing_type (die
, cu
);
3832 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3833 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3835 /* Get accessibility. */
3836 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3839 switch (DW_UNSND (attr
))
3841 case DW_ACCESS_private
:
3842 fnp
->is_private
= 1;
3844 case DW_ACCESS_protected
:
3845 fnp
->is_protected
= 1;
3850 /* Check for artificial methods. */
3851 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3852 if (attr
&& DW_UNSND (attr
) != 0)
3853 fnp
->is_artificial
= 1;
3855 /* Get index in virtual function table if it is a virtual member function. */
3856 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3859 /* Support the .debug_loc offsets */
3860 if (attr_form_is_block (attr
))
3862 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3864 else if (attr_form_is_section_offset (attr
))
3866 dwarf2_complex_location_expr_complaint ();
3870 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3876 /* Create the vector of member function fields, and attach it to the type. */
3879 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3880 struct dwarf2_cu
*cu
)
3882 struct fnfieldlist
*flp
;
3883 int total_length
= 0;
3886 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3887 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3888 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3890 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3892 struct nextfnfield
*nfp
= flp
->head
;
3893 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3896 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3897 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3898 fn_flp
->fn_fields
= (struct fn_field
*)
3899 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3900 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3901 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3903 total_length
+= flp
->length
;
3906 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3907 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3910 /* Returns non-zero if NAME is the name of a vtable member in CU's
3911 language, zero otherwise. */
3913 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3915 static const char vptr
[] = "_vptr";
3916 static const char vtable
[] = "vtable";
3918 /* Look for the C++ and Java forms of the vtable. */
3919 if ((cu
->language
== language_java
3920 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3921 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3922 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3928 /* GCC outputs unnamed structures that are really pointers to member
3929 functions, with the ABI-specified layout. If DIE (from CU) describes
3930 such a structure, set its type, and return nonzero. Otherwise return
3933 GCC shouldn't do this; it should just output pointer to member DIEs.
3934 This is GCC PR debug/28767. */
3936 static struct type
*
3937 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3939 struct objfile
*objfile
= cu
->objfile
;
3941 struct die_info
*pfn_die
, *delta_die
;
3942 struct attribute
*pfn_name
, *delta_name
;
3943 struct type
*pfn_type
, *domain_type
;
3945 /* Check for a structure with no name and two children. */
3946 if (die
->tag
!= DW_TAG_structure_type
3947 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3948 || die
->child
== NULL
3949 || die
->child
->sibling
== NULL
3950 || (die
->child
->sibling
->sibling
!= NULL
3951 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3954 /* Check for __pfn and __delta members. */
3955 pfn_die
= die
->child
;
3956 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3957 if (pfn_die
->tag
!= DW_TAG_member
3959 || DW_STRING (pfn_name
) == NULL
3960 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3963 delta_die
= pfn_die
->sibling
;
3964 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3965 if (delta_die
->tag
!= DW_TAG_member
3966 || delta_name
== NULL
3967 || DW_STRING (delta_name
) == NULL
3968 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3971 /* Find the type of the method. */
3972 pfn_type
= die_type (pfn_die
, cu
);
3973 if (pfn_type
== NULL
3974 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3975 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3978 /* Look for the "this" argument. */
3979 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3980 if (TYPE_NFIELDS (pfn_type
) == 0
3981 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3984 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3985 type
= alloc_type (objfile
);
3986 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3987 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3988 TYPE_VARARGS (pfn_type
));
3989 type
= lookup_methodptr_type (type
);
3990 return set_die_type (die
, type
, cu
);
3993 /* Called when we find the DIE that starts a structure or union scope
3994 (definition) to process all dies that define the members of the
3997 NOTE: we need to call struct_type regardless of whether or not the
3998 DIE has an at_name attribute, since it might be an anonymous
3999 structure or union. This gets the type entered into our set of
4002 However, if the structure is incomplete (an opaque struct/union)
4003 then suppress creating a symbol table entry for it since gdb only
4004 wants to find the one with the complete definition. Note that if
4005 it is complete, we just call new_symbol, which does it's own
4006 checking about whether the struct/union is anonymous or not (and
4007 suppresses creating a symbol table entry itself). */
4009 static struct type
*
4010 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4012 struct objfile
*objfile
= cu
->objfile
;
4014 struct attribute
*attr
;
4015 const char *previous_prefix
= processing_current_prefix
;
4016 struct cleanup
*back_to
= NULL
;
4019 type
= quirk_gcc_member_function_pointer (die
, cu
);
4023 type
= alloc_type (objfile
);
4024 INIT_CPLUS_SPECIFIC (type
);
4025 name
= dwarf2_name (die
, cu
);
4028 if (cu
->language
== language_cplus
4029 || cu
->language
== language_java
)
4031 char *new_prefix
= determine_class_name (die
, cu
);
4032 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
4033 strlen (new_prefix
),
4034 &objfile
->objfile_obstack
);
4035 back_to
= make_cleanup (xfree
, new_prefix
);
4036 processing_current_prefix
= new_prefix
;
4040 /* The name is already allocated along with this objfile, so
4041 we don't need to duplicate it for the type. */
4042 TYPE_TAG_NAME (type
) = name
;
4046 if (die
->tag
== DW_TAG_structure_type
)
4048 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4050 else if (die
->tag
== DW_TAG_union_type
)
4052 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4056 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4058 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4061 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4064 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4068 TYPE_LENGTH (type
) = 0;
4071 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB_SUPPORTED
;
4072 if (die_is_declaration (die
, cu
))
4073 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4075 /* We need to add the type field to the die immediately so we don't
4076 infinitely recurse when dealing with pointers to the structure
4077 type within the structure itself. */
4078 set_die_type (die
, type
, cu
);
4080 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4082 struct field_info fi
;
4083 struct die_info
*child_die
;
4084 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
4086 memset (&fi
, 0, sizeof (struct field_info
));
4088 child_die
= die
->child
;
4090 while (child_die
&& child_die
->tag
)
4092 if (child_die
->tag
== DW_TAG_member
4093 || child_die
->tag
== DW_TAG_variable
)
4095 /* NOTE: carlton/2002-11-05: A C++ static data member
4096 should be a DW_TAG_member that is a declaration, but
4097 all versions of G++ as of this writing (so through at
4098 least 3.2.1) incorrectly generate DW_TAG_variable
4099 tags for them instead. */
4100 dwarf2_add_field (&fi
, child_die
, cu
);
4102 else if (child_die
->tag
== DW_TAG_subprogram
)
4104 /* C++ member function. */
4105 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4107 else if (child_die
->tag
== DW_TAG_inheritance
)
4109 /* C++ base class field. */
4110 dwarf2_add_field (&fi
, child_die
, cu
);
4112 child_die
= sibling_die (child_die
);
4115 /* Attach fields and member functions to the type. */
4117 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4120 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4122 /* Get the type which refers to the base class (possibly this
4123 class itself) which contains the vtable pointer for the current
4124 class from the DW_AT_containing_type attribute. */
4126 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4128 struct type
*t
= die_containing_type (die
, cu
);
4130 TYPE_VPTR_BASETYPE (type
) = t
;
4135 /* Our own class provides vtbl ptr. */
4136 for (i
= TYPE_NFIELDS (t
) - 1;
4137 i
>= TYPE_N_BASECLASSES (t
);
4140 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4142 if (is_vtable_name (fieldname
, cu
))
4144 TYPE_VPTR_FIELDNO (type
) = i
;
4149 /* Complain if virtual function table field not found. */
4150 if (i
< TYPE_N_BASECLASSES (t
))
4151 complaint (&symfile_complaints
,
4152 _("virtual function table pointer not found when defining class '%s'"),
4153 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4158 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4161 else if (cu
->producer
4162 && strncmp (cu
->producer
,
4163 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4165 /* The IBM XLC compiler does not provide direct indication
4166 of the containing type, but the vtable pointer is
4167 always named __vfp. */
4171 for (i
= TYPE_NFIELDS (type
) - 1;
4172 i
>= TYPE_N_BASECLASSES (type
);
4175 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4177 TYPE_VPTR_FIELDNO (type
) = i
;
4178 TYPE_VPTR_BASETYPE (type
) = type
;
4185 do_cleanups (back_to
);
4188 processing_current_prefix
= previous_prefix
;
4189 if (back_to
!= NULL
)
4190 do_cleanups (back_to
);
4196 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4198 struct objfile
*objfile
= cu
->objfile
;
4199 const char *previous_prefix
= processing_current_prefix
;
4200 struct die_info
*child_die
= die
->child
;
4201 struct type
*this_type
;
4203 this_type
= get_die_type (die
, cu
);
4204 if (this_type
== NULL
)
4205 this_type
= read_structure_type (die
, cu
);
4206 if (TYPE_TAG_NAME (this_type
) != NULL
)
4207 processing_current_prefix
= TYPE_TAG_NAME (this_type
);
4209 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4210 snapshots) has been known to create a die giving a declaration
4211 for a class that has, as a child, a die giving a definition for a
4212 nested class. So we have to process our children even if the
4213 current die is a declaration. Normally, of course, a declaration
4214 won't have any children at all. */
4216 while (child_die
!= NULL
&& child_die
->tag
)
4218 if (child_die
->tag
== DW_TAG_member
4219 || child_die
->tag
== DW_TAG_variable
4220 || child_die
->tag
== DW_TAG_inheritance
)
4225 process_die (child_die
, cu
);
4227 child_die
= sibling_die (child_die
);
4230 /* Do not consider external references. According to the DWARF standard,
4231 these DIEs are identified by the fact that they have no byte_size
4232 attribute, and a declaration attribute. */
4233 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4234 || !die_is_declaration (die
, cu
))
4235 new_symbol (die
, this_type
, cu
);
4237 processing_current_prefix
= previous_prefix
;
4240 /* Given a DW_AT_enumeration_type die, set its type. We do not
4241 complete the type's fields yet, or create any symbols. */
4243 static struct type
*
4244 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4246 struct objfile
*objfile
= cu
->objfile
;
4248 struct attribute
*attr
;
4251 type
= alloc_type (objfile
);
4253 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4254 name
= dwarf2_name (die
, cu
);
4257 if (processing_has_namespace_info
)
4259 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
4260 processing_current_prefix
,
4265 /* The name is already allocated along with this objfile, so
4266 we don't need to duplicate it for the type. */
4267 TYPE_TAG_NAME (type
) = name
;
4271 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4274 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4278 TYPE_LENGTH (type
) = 0;
4281 /* The enumeration DIE can be incomplete. In Ada, any type can be
4282 declared as private in the package spec, and then defined only
4283 inside the package body. Such types are known as Taft Amendment
4284 Types. When another package uses such a type, an incomplete DIE
4285 may be generated by the compiler. */
4286 if (die_is_declaration (die
, cu
))
4287 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4289 return set_die_type (die
, type
, cu
);
4292 /* Determine the name of the type represented by DIE, which should be
4293 a named C++ or Java compound type. Return the name in question; the caller
4294 is responsible for xfree()'ing it. */
4297 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4299 struct cleanup
*back_to
= NULL
;
4300 struct die_info
*spec_die
= die_specification (die
, cu
);
4301 char *new_prefix
= NULL
;
4303 /* If this is the definition of a class that is declared by another
4304 die, then processing_current_prefix may not be accurate; see
4305 read_func_scope for a similar example. */
4306 if (spec_die
!= NULL
)
4308 char *specification_prefix
= determine_prefix (spec_die
, cu
);
4309 processing_current_prefix
= specification_prefix
;
4310 back_to
= make_cleanup (xfree
, specification_prefix
);
4313 /* If we don't have namespace debug info, guess the name by trying
4314 to demangle the names of members, just like we did in
4315 guess_structure_name. */
4316 if (!processing_has_namespace_info
)
4318 struct die_info
*child
;
4320 for (child
= die
->child
;
4321 child
!= NULL
&& child
->tag
!= 0;
4322 child
= sibling_die (child
))
4324 if (child
->tag
== DW_TAG_subprogram
)
4327 = language_class_name_from_physname (cu
->language_defn
,
4331 if (new_prefix
!= NULL
)
4337 if (new_prefix
== NULL
)
4339 const char *name
= dwarf2_name (die
, cu
);
4340 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
4341 name
? name
: "<<anonymous>>",
4345 if (back_to
!= NULL
)
4346 do_cleanups (back_to
);
4351 /* Given a pointer to a die which begins an enumeration, process all
4352 the dies that define the members of the enumeration, and create the
4353 symbol for the enumeration type.
4355 NOTE: We reverse the order of the element list. */
4358 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4360 struct objfile
*objfile
= cu
->objfile
;
4361 struct die_info
*child_die
;
4362 struct field
*fields
;
4365 int unsigned_enum
= 1;
4367 struct type
*this_type
;
4371 this_type
= get_die_type (die
, cu
);
4372 if (this_type
== NULL
)
4373 this_type
= read_enumeration_type (die
, cu
);
4374 if (die
->child
!= NULL
)
4376 child_die
= die
->child
;
4377 while (child_die
&& child_die
->tag
)
4379 if (child_die
->tag
!= DW_TAG_enumerator
)
4381 process_die (child_die
, cu
);
4385 name
= dwarf2_name (child_die
, cu
);
4388 sym
= new_symbol (child_die
, this_type
, cu
);
4389 if (SYMBOL_VALUE (sym
) < 0)
4392 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4394 fields
= (struct field
*)
4396 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4397 * sizeof (struct field
));
4400 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
4401 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4402 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4403 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4404 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4410 child_die
= sibling_die (child_die
);
4415 TYPE_NFIELDS (this_type
) = num_fields
;
4416 TYPE_FIELDS (this_type
) = (struct field
*)
4417 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4418 memcpy (TYPE_FIELDS (this_type
), fields
,
4419 sizeof (struct field
) * num_fields
);
4423 TYPE_FLAGS (this_type
) |= TYPE_FLAG_UNSIGNED
;
4426 new_symbol (die
, this_type
, cu
);
4429 /* Extract all information from a DW_TAG_array_type DIE and put it in
4430 the DIE's type field. For now, this only handles one dimensional
4433 static struct type
*
4434 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4436 struct objfile
*objfile
= cu
->objfile
;
4437 struct die_info
*child_die
;
4438 struct type
*type
= NULL
;
4439 struct type
*element_type
, *range_type
, *index_type
;
4440 struct type
**range_types
= NULL
;
4441 struct attribute
*attr
;
4443 struct cleanup
*back_to
;
4446 element_type
= die_type (die
, cu
);
4448 /* Irix 6.2 native cc creates array types without children for
4449 arrays with unspecified length. */
4450 if (die
->child
== NULL
)
4452 index_type
= builtin_type_int32
;
4453 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4454 type
= create_array_type (NULL
, element_type
, range_type
);
4455 return set_die_type (die
, type
, cu
);
4458 back_to
= make_cleanup (null_cleanup
, NULL
);
4459 child_die
= die
->child
;
4460 while (child_die
&& child_die
->tag
)
4462 if (child_die
->tag
== DW_TAG_subrange_type
)
4464 struct type
*child_type
= read_type_die (child_die
, cu
);
4465 if (child_type
!= NULL
)
4467 /* The range type was succesfully read. Save it for
4468 the array type creation. */
4469 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4471 range_types
= (struct type
**)
4472 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4473 * sizeof (struct type
*));
4475 make_cleanup (free_current_contents
, &range_types
);
4477 range_types
[ndim
++] = child_type
;
4480 child_die
= sibling_die (child_die
);
4483 /* Dwarf2 dimensions are output from left to right, create the
4484 necessary array types in backwards order. */
4486 type
= element_type
;
4488 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4492 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4497 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4500 /* Understand Dwarf2 support for vector types (like they occur on
4501 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4502 array type. This is not part of the Dwarf2/3 standard yet, but a
4503 custom vendor extension. The main difference between a regular
4504 array and the vector variant is that vectors are passed by value
4506 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4508 make_vector_type (type
);
4510 name
= dwarf2_name (die
, cu
);
4512 TYPE_NAME (type
) = name
;
4514 do_cleanups (back_to
);
4516 /* Install the type in the die. */
4517 return set_die_type (die
, type
, cu
);
4520 static enum dwarf_array_dim_ordering
4521 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4523 struct attribute
*attr
;
4525 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4527 if (attr
) return DW_SND (attr
);
4530 GNU F77 is a special case, as at 08/2004 array type info is the
4531 opposite order to the dwarf2 specification, but data is still
4532 laid out as per normal fortran.
4534 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4538 if (cu
->language
== language_fortran
&&
4539 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4541 return DW_ORD_row_major
;
4544 switch (cu
->language_defn
->la_array_ordering
)
4546 case array_column_major
:
4547 return DW_ORD_col_major
;
4548 case array_row_major
:
4550 return DW_ORD_row_major
;
4554 /* Extract all information from a DW_TAG_set_type DIE and put it in
4555 the DIE's type field. */
4557 static struct type
*
4558 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4560 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4562 return set_die_type (die
, set_type
, cu
);
4565 /* First cut: install each common block member as a global variable. */
4568 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4570 struct die_info
*child_die
;
4571 struct attribute
*attr
;
4573 CORE_ADDR base
= (CORE_ADDR
) 0;
4575 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4578 /* Support the .debug_loc offsets */
4579 if (attr_form_is_block (attr
))
4581 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4583 else if (attr_form_is_section_offset (attr
))
4585 dwarf2_complex_location_expr_complaint ();
4589 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4590 "common block member");
4593 if (die
->child
!= NULL
)
4595 child_die
= die
->child
;
4596 while (child_die
&& child_die
->tag
)
4598 sym
= new_symbol (child_die
, NULL
, cu
);
4599 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4602 SYMBOL_VALUE_ADDRESS (sym
) =
4603 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4604 add_symbol_to_list (sym
, &global_symbols
);
4606 child_die
= sibling_die (child_die
);
4611 /* Read a C++ namespace. */
4614 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4616 struct objfile
*objfile
= cu
->objfile
;
4617 const char *previous_prefix
= processing_current_prefix
;
4620 struct die_info
*current_die
;
4621 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4623 name
= namespace_name (die
, &is_anonymous
, cu
);
4625 /* Now build the name of the current namespace. */
4627 if (previous_prefix
[0] == '\0')
4629 processing_current_prefix
= name
;
4633 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4634 make_cleanup (xfree
, temp_name
);
4635 processing_current_prefix
= temp_name
;
4638 /* Add a symbol associated to this if we haven't seen the namespace
4639 before. Also, add a using directive if it's an anonymous
4642 if (dwarf2_extension (die
, cu
) == NULL
)
4646 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4647 this cast will hopefully become unnecessary. */
4648 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4649 (char *) processing_current_prefix
,
4651 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4653 new_symbol (die
, type
, cu
);
4654 set_die_type (die
, type
, cu
);
4657 cp_add_using_directive (processing_current_prefix
,
4658 strlen (previous_prefix
),
4659 strlen (processing_current_prefix
));
4662 if (die
->child
!= NULL
)
4664 struct die_info
*child_die
= die
->child
;
4666 while (child_die
&& child_die
->tag
)
4668 process_die (child_die
, cu
);
4669 child_die
= sibling_die (child_die
);
4673 processing_current_prefix
= previous_prefix
;
4674 do_cleanups (back_to
);
4677 /* Return the name of the namespace represented by DIE. Set
4678 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4682 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4684 struct die_info
*current_die
;
4685 const char *name
= NULL
;
4687 /* Loop through the extensions until we find a name. */
4689 for (current_die
= die
;
4690 current_die
!= NULL
;
4691 current_die
= dwarf2_extension (die
, cu
))
4693 name
= dwarf2_name (current_die
, cu
);
4698 /* Is it an anonymous namespace? */
4700 *is_anonymous
= (name
== NULL
);
4702 name
= "(anonymous namespace)";
4707 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4708 the user defined type vector. */
4710 static struct type
*
4711 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4713 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4714 struct comp_unit_head
*cu_header
= &cu
->header
;
4716 struct attribute
*attr_byte_size
;
4717 struct attribute
*attr_address_class
;
4718 int byte_size
, addr_class
;
4720 type
= lookup_pointer_type (die_type (die
, cu
));
4722 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4724 byte_size
= DW_UNSND (attr_byte_size
);
4726 byte_size
= cu_header
->addr_size
;
4728 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4729 if (attr_address_class
)
4730 addr_class
= DW_UNSND (attr_address_class
);
4732 addr_class
= DW_ADDR_none
;
4734 /* If the pointer size or address class is different than the
4735 default, create a type variant marked as such and set the
4736 length accordingly. */
4737 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4739 if (gdbarch_address_class_type_flags_p (gdbarch
))
4743 type_flags
= gdbarch_address_class_type_flags
4744 (gdbarch
, byte_size
, addr_class
);
4745 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4746 type
= make_type_with_address_space (type
, type_flags
);
4748 else if (TYPE_LENGTH (type
) != byte_size
)
4750 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4753 /* Should we also complain about unhandled address classes? */
4757 TYPE_LENGTH (type
) = byte_size
;
4758 return set_die_type (die
, type
, cu
);
4761 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4762 the user defined type vector. */
4764 static struct type
*
4765 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4767 struct objfile
*objfile
= cu
->objfile
;
4769 struct type
*to_type
;
4770 struct type
*domain
;
4772 to_type
= die_type (die
, cu
);
4773 domain
= die_containing_type (die
, cu
);
4775 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4776 type
= lookup_methodptr_type (to_type
);
4778 type
= lookup_memberptr_type (to_type
, domain
);
4780 return set_die_type (die
, type
, cu
);
4783 /* Extract all information from a DW_TAG_reference_type DIE and add to
4784 the user defined type vector. */
4786 static struct type
*
4787 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4789 struct comp_unit_head
*cu_header
= &cu
->header
;
4791 struct attribute
*attr
;
4793 type
= lookup_reference_type (die_type (die
, cu
));
4794 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4797 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4801 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4803 return set_die_type (die
, type
, cu
);
4806 static struct type
*
4807 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4809 struct type
*base_type
, *cv_type
;
4811 base_type
= die_type (die
, cu
);
4812 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4813 return set_die_type (die
, cv_type
, cu
);
4816 static struct type
*
4817 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4819 struct type
*base_type
, *cv_type
;
4821 base_type
= die_type (die
, cu
);
4822 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4823 return set_die_type (die
, cv_type
, cu
);
4826 /* Extract all information from a DW_TAG_string_type DIE and add to
4827 the user defined type vector. It isn't really a user defined type,
4828 but it behaves like one, with other DIE's using an AT_user_def_type
4829 attribute to reference it. */
4831 static struct type
*
4832 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4834 struct objfile
*objfile
= cu
->objfile
;
4835 struct type
*type
, *range_type
, *index_type
, *char_type
;
4836 struct attribute
*attr
;
4837 unsigned int length
;
4839 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4842 length
= DW_UNSND (attr
);
4846 /* check for the DW_AT_byte_size attribute */
4847 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4850 length
= DW_UNSND (attr
);
4858 index_type
= builtin_type_int32
;
4859 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4860 type
= create_string_type (NULL
, range_type
);
4862 return set_die_type (die
, type
, cu
);
4865 /* Handle DIES due to C code like:
4869 int (*funcp)(int a, long l);
4873 ('funcp' generates a DW_TAG_subroutine_type DIE)
4876 static struct type
*
4877 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4879 struct type
*type
; /* Type that this function returns */
4880 struct type
*ftype
; /* Function that returns above type */
4881 struct attribute
*attr
;
4883 type
= die_type (die
, cu
);
4884 ftype
= make_function_type (type
, (struct type
**) 0);
4886 /* All functions in C++, Pascal and Java have prototypes. */
4887 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4888 if ((attr
&& (DW_UNSND (attr
) != 0))
4889 || cu
->language
== language_cplus
4890 || cu
->language
== language_java
4891 || cu
->language
== language_pascal
)
4892 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4894 /* Store the calling convention in the type if it's available in
4895 the subroutine die. Otherwise set the calling convention to
4896 the default value DW_CC_normal. */
4897 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4898 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4900 if (die
->child
!= NULL
)
4902 struct die_info
*child_die
;
4906 /* Count the number of parameters.
4907 FIXME: GDB currently ignores vararg functions, but knows about
4908 vararg member functions. */
4909 child_die
= die
->child
;
4910 while (child_die
&& child_die
->tag
)
4912 if (child_die
->tag
== DW_TAG_formal_parameter
)
4914 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4915 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4916 child_die
= sibling_die (child_die
);
4919 /* Allocate storage for parameters and fill them in. */
4920 TYPE_NFIELDS (ftype
) = nparams
;
4921 TYPE_FIELDS (ftype
) = (struct field
*)
4922 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4924 child_die
= die
->child
;
4925 while (child_die
&& child_die
->tag
)
4927 if (child_die
->tag
== DW_TAG_formal_parameter
)
4929 /* Dwarf2 has no clean way to discern C++ static and non-static
4930 member functions. G++ helps GDB by marking the first
4931 parameter for non-static member functions (which is the
4932 this pointer) as artificial. We pass this information
4933 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4934 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4936 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4938 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4939 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4942 child_die
= sibling_die (child_die
);
4946 return set_die_type (die
, ftype
, cu
);
4949 static struct type
*
4950 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4952 struct objfile
*objfile
= cu
->objfile
;
4953 struct attribute
*attr
;
4955 struct type
*this_type
;
4957 name
= dwarf2_name (die
, cu
);
4958 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4959 TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4960 set_die_type (die
, this_type
, cu
);
4961 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4965 /* Find a representation of a given base type and install
4966 it in the TYPE field of the die. */
4968 static struct type
*
4969 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4971 struct objfile
*objfile
= cu
->objfile
;
4973 struct attribute
*attr
;
4974 int encoding
= 0, size
= 0;
4976 enum type_code code
= TYPE_CODE_INT
;
4978 struct type
*target_type
= NULL
;
4980 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4983 encoding
= DW_UNSND (attr
);
4985 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4988 size
= DW_UNSND (attr
);
4990 name
= dwarf2_name (die
, cu
);
4993 complaint (&symfile_complaints
,
4994 _("DW_AT_name missing from DW_TAG_base_type"));
4999 case DW_ATE_address
:
5000 /* Turn DW_ATE_address into a void * pointer. */
5001 code
= TYPE_CODE_PTR
;
5002 type_flags
|= TYPE_FLAG_UNSIGNED
;
5003 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5005 case DW_ATE_boolean
:
5006 code
= TYPE_CODE_BOOL
;
5007 type_flags
|= TYPE_FLAG_UNSIGNED
;
5009 case DW_ATE_complex_float
:
5010 code
= TYPE_CODE_COMPLEX
;
5011 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5013 case DW_ATE_decimal_float
:
5014 code
= TYPE_CODE_DECFLOAT
;
5017 code
= TYPE_CODE_FLT
;
5021 case DW_ATE_unsigned
:
5022 type_flags
|= TYPE_FLAG_UNSIGNED
;
5024 case DW_ATE_signed_char
:
5025 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5026 code
= TYPE_CODE_CHAR
;
5028 case DW_ATE_unsigned_char
:
5029 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5030 code
= TYPE_CODE_CHAR
;
5031 type_flags
|= TYPE_FLAG_UNSIGNED
;
5034 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5035 dwarf_type_encoding_name (encoding
));
5039 type
= init_type (code
, size
, type_flags
, name
, objfile
);
5040 TYPE_TARGET_TYPE (type
) = target_type
;
5042 return set_die_type (die
, type
, cu
);
5045 /* Read the given DW_AT_subrange DIE. */
5047 static struct type
*
5048 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5050 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5051 struct type
*base_type
;
5052 struct type
*range_type
;
5053 struct attribute
*attr
;
5058 base_type
= die_type (die
, cu
);
5059 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5061 complaint (&symfile_complaints
,
5062 _("DW_AT_type missing from DW_TAG_subrange_type"));
5064 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5065 0, NULL
, cu
->objfile
);
5068 if (cu
->language
== language_fortran
)
5070 /* FORTRAN implies a lower bound of 1, if not given. */
5074 /* FIXME: For variable sized arrays either of these could be
5075 a variable rather than a constant value. We'll allow it,
5076 but we don't know how to handle it. */
5077 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5079 low
= dwarf2_get_attr_constant_value (attr
, 0);
5081 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5084 if (attr
->form
== DW_FORM_block1
)
5086 /* GCC encodes arrays with unspecified or dynamic length
5087 with a DW_FORM_block1 attribute.
5088 FIXME: GDB does not yet know how to handle dynamic
5089 arrays properly, treat them as arrays with unspecified
5092 FIXME: jimb/2003-09-22: GDB does not really know
5093 how to handle arrays of unspecified length
5094 either; we just represent them as zero-length
5095 arrays. Choose an appropriate upper bound given
5096 the lower bound we've computed above. */
5100 high
= dwarf2_get_attr_constant_value (attr
, 1);
5103 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5105 name
= dwarf2_name (die
, cu
);
5107 TYPE_NAME (range_type
) = name
;
5109 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5111 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5113 return set_die_type (die
, range_type
, cu
);
5116 static struct type
*
5117 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5121 /* For now, we only support the C meaning of an unspecified type: void. */
5123 type
= init_type (TYPE_CODE_VOID
, 0, 0, dwarf2_name (die
, cu
),
5126 return set_die_type (die
, type
, cu
);
5129 /* Read a whole compilation unit into a linked list of dies. */
5131 static struct die_info
*
5132 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5134 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5137 /* Read a single die and all its descendents. Set the die's sibling
5138 field to NULL; set other fields in the die correctly, and set all
5139 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5140 location of the info_ptr after reading all of those dies. PARENT
5141 is the parent of the die in question. */
5143 static struct die_info
*
5144 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5145 struct dwarf2_cu
*cu
,
5146 gdb_byte
**new_info_ptr
,
5147 struct die_info
*parent
)
5149 struct die_info
*die
;
5153 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5154 store_in_ref_table (die
->offset
, die
, cu
);
5158 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5164 *new_info_ptr
= cur_ptr
;
5167 die
->sibling
= NULL
;
5168 die
->parent
= parent
;
5172 /* Read a die, all of its descendents, and all of its siblings; set
5173 all of the fields of all of the dies correctly. Arguments are as
5174 in read_die_and_children. */
5176 static struct die_info
*
5177 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5178 struct dwarf2_cu
*cu
,
5179 gdb_byte
**new_info_ptr
,
5180 struct die_info
*parent
)
5182 struct die_info
*first_die
, *last_sibling
;
5186 first_die
= last_sibling
= NULL
;
5190 struct die_info
*die
5191 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5199 last_sibling
->sibling
= die
;
5204 *new_info_ptr
= cur_ptr
;
5214 /* Free a linked list of dies. */
5217 free_die_list (struct die_info
*dies
)
5219 struct die_info
*die
, *next
;
5224 if (die
->child
!= NULL
)
5225 free_die_list (die
->child
);
5226 next
= die
->sibling
;
5233 /* Decompress a section that was compressed using zlib. Store the
5234 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5237 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5238 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5240 bfd
*abfd
= objfile
->obfd
;
5242 error (_("Support for zlib-compressed DWARF data (from '%s') "
5243 "is disabled in this copy of GDB"),
5244 bfd_get_filename (abfd
));
5246 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5247 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5248 bfd_size_type uncompressed_size
;
5249 gdb_byte
*uncompressed_buffer
;
5252 int header_size
= 12;
5254 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5255 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5256 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5257 bfd_get_filename (abfd
));
5259 /* Read the zlib header. In this case, it should be "ZLIB" followed
5260 by the uncompressed section size, 8 bytes in big-endian order. */
5261 if (compressed_size
< header_size
5262 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5263 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5264 bfd_get_filename (abfd
));
5265 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5266 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5267 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5268 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5269 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5270 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5271 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5272 uncompressed_size
+= compressed_buffer
[11];
5274 /* It is possible the section consists of several compressed
5275 buffers concatenated together, so we uncompress in a loop. */
5279 strm
.avail_in
= compressed_size
- header_size
;
5280 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5281 strm
.avail_out
= uncompressed_size
;
5282 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5284 rc
= inflateInit (&strm
);
5285 while (strm
.avail_in
> 0)
5288 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5289 bfd_get_filename (abfd
), rc
);
5290 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5291 + (uncompressed_size
- strm
.avail_out
));
5292 rc
= inflate (&strm
, Z_FINISH
);
5293 if (rc
!= Z_STREAM_END
)
5294 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5295 bfd_get_filename (abfd
), rc
);
5296 rc
= inflateReset (&strm
);
5298 rc
= inflateEnd (&strm
);
5300 || strm
.avail_out
!= 0)
5301 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5302 bfd_get_filename (abfd
), rc
);
5304 xfree (compressed_buffer
);
5305 *outbuf
= uncompressed_buffer
;
5306 *outsize
= uncompressed_size
;
5311 /* Read the contents of the section at OFFSET and of size SIZE from the
5312 object file specified by OBJFILE into the objfile_obstack and return it.
5313 If the section is compressed, uncompress it before returning. */
5316 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5318 bfd
*abfd
= objfile
->obfd
;
5319 gdb_byte
*buf
, *retbuf
;
5320 bfd_size_type size
= bfd_get_section_size (sectp
);
5321 unsigned char header
[4];
5326 /* Check if the file has a 4-byte header indicating compression. */
5327 if (size
> sizeof (header
)
5328 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5329 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5331 /* Upon decompression, update the buffer and its size. */
5332 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5334 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5335 dwarf2_resize_section (sectp
, size
);
5340 /* If we get here, we are a normal, not-compressed section. */
5341 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5342 /* When debugging .o files, we may need to apply relocations; see
5343 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5344 We never compress sections in .o files, so we only need to
5345 try this when the section is not compressed. */
5346 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5350 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5351 || bfd_bread (buf
, size
, abfd
) != size
)
5352 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5353 bfd_get_filename (abfd
));
5358 /* In DWARF version 2, the description of the debugging information is
5359 stored in a separate .debug_abbrev section. Before we read any
5360 dies from a section we read in all abbreviations and install them
5361 in a hash table. This function also sets flags in CU describing
5362 the data found in the abbrev table. */
5365 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5367 struct comp_unit_head
*cu_header
= &cu
->header
;
5368 gdb_byte
*abbrev_ptr
;
5369 struct abbrev_info
*cur_abbrev
;
5370 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5371 unsigned int abbrev_form
, hash_number
;
5372 struct attr_abbrev
*cur_attrs
;
5373 unsigned int allocated_attrs
;
5375 /* Initialize dwarf2 abbrevs */
5376 obstack_init (&cu
->abbrev_obstack
);
5377 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5379 * sizeof (struct abbrev_info
*)));
5380 memset (cu
->dwarf2_abbrevs
, 0,
5381 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5383 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5384 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5385 abbrev_ptr
+= bytes_read
;
5387 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5388 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5390 /* loop until we reach an abbrev number of 0 */
5391 while (abbrev_number
)
5393 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5395 /* read in abbrev header */
5396 cur_abbrev
->number
= abbrev_number
;
5397 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5398 abbrev_ptr
+= bytes_read
;
5399 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5402 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5403 cu
->has_namespace_info
= 1;
5405 /* now read in declarations */
5406 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5407 abbrev_ptr
+= bytes_read
;
5408 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5409 abbrev_ptr
+= bytes_read
;
5412 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5414 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5416 = xrealloc (cur_attrs
, (allocated_attrs
5417 * sizeof (struct attr_abbrev
)));
5420 /* Record whether this compilation unit might have
5421 inter-compilation-unit references. If we don't know what form
5422 this attribute will have, then it might potentially be a
5423 DW_FORM_ref_addr, so we conservatively expect inter-CU
5426 if (abbrev_form
== DW_FORM_ref_addr
5427 || abbrev_form
== DW_FORM_indirect
)
5428 cu
->has_form_ref_addr
= 1;
5430 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5431 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5432 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5433 abbrev_ptr
+= bytes_read
;
5434 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5435 abbrev_ptr
+= bytes_read
;
5438 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5439 (cur_abbrev
->num_attrs
5440 * sizeof (struct attr_abbrev
)));
5441 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5442 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5444 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5445 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5446 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5448 /* Get next abbreviation.
5449 Under Irix6 the abbreviations for a compilation unit are not
5450 always properly terminated with an abbrev number of 0.
5451 Exit loop if we encounter an abbreviation which we have
5452 already read (which means we are about to read the abbreviations
5453 for the next compile unit) or if the end of the abbreviation
5454 table is reached. */
5455 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5456 >= dwarf2_per_objfile
->abbrev_size
)
5458 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5459 abbrev_ptr
+= bytes_read
;
5460 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5467 /* Release the memory used by the abbrev table for a compilation unit. */
5470 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5472 struct dwarf2_cu
*cu
= ptr_to_cu
;
5474 obstack_free (&cu
->abbrev_obstack
, NULL
);
5475 cu
->dwarf2_abbrevs
= NULL
;
5478 /* Lookup an abbrev_info structure in the abbrev hash table. */
5480 static struct abbrev_info
*
5481 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5483 unsigned int hash_number
;
5484 struct abbrev_info
*abbrev
;
5486 hash_number
= number
% ABBREV_HASH_SIZE
;
5487 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5491 if (abbrev
->number
== number
)
5494 abbrev
= abbrev
->next
;
5499 /* Returns nonzero if TAG represents a type that we might generate a partial
5503 is_type_tag_for_partial (int tag
)
5508 /* Some types that would be reasonable to generate partial symbols for,
5509 that we don't at present. */
5510 case DW_TAG_array_type
:
5511 case DW_TAG_file_type
:
5512 case DW_TAG_ptr_to_member_type
:
5513 case DW_TAG_set_type
:
5514 case DW_TAG_string_type
:
5515 case DW_TAG_subroutine_type
:
5517 case DW_TAG_base_type
:
5518 case DW_TAG_class_type
:
5519 case DW_TAG_interface_type
:
5520 case DW_TAG_enumeration_type
:
5521 case DW_TAG_structure_type
:
5522 case DW_TAG_subrange_type
:
5523 case DW_TAG_typedef
:
5524 case DW_TAG_union_type
:
5531 /* Load all DIEs that are interesting for partial symbols into memory. */
5533 static struct partial_die_info
*
5534 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5535 struct dwarf2_cu
*cu
)
5537 struct partial_die_info
*part_die
;
5538 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5539 struct abbrev_info
*abbrev
;
5540 unsigned int bytes_read
;
5541 unsigned int load_all
= 0;
5543 int nesting_level
= 1;
5548 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5552 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5556 &cu
->comp_unit_obstack
,
5557 hashtab_obstack_allocate
,
5558 dummy_obstack_deallocate
);
5560 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5561 sizeof (struct partial_die_info
));
5565 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5567 /* A NULL abbrev means the end of a series of children. */
5570 if (--nesting_level
== 0)
5572 /* PART_DIE was probably the last thing allocated on the
5573 comp_unit_obstack, so we could call obstack_free
5574 here. We don't do that because the waste is small,
5575 and will be cleaned up when we're done with this
5576 compilation unit. This way, we're also more robust
5577 against other users of the comp_unit_obstack. */
5580 info_ptr
+= bytes_read
;
5581 last_die
= parent_die
;
5582 parent_die
= parent_die
->die_parent
;
5586 /* Check whether this DIE is interesting enough to save. Normally
5587 we would not be interested in members here, but there may be
5588 later variables referencing them via DW_AT_specification (for
5591 && !is_type_tag_for_partial (abbrev
->tag
)
5592 && abbrev
->tag
!= DW_TAG_enumerator
5593 && abbrev
->tag
!= DW_TAG_subprogram
5594 && abbrev
->tag
!= DW_TAG_variable
5595 && abbrev
->tag
!= DW_TAG_namespace
5596 && abbrev
->tag
!= DW_TAG_member
)
5598 /* Otherwise we skip to the next sibling, if any. */
5599 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5603 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5604 abfd
, info_ptr
, cu
);
5606 /* This two-pass algorithm for processing partial symbols has a
5607 high cost in cache pressure. Thus, handle some simple cases
5608 here which cover the majority of C partial symbols. DIEs
5609 which neither have specification tags in them, nor could have
5610 specification tags elsewhere pointing at them, can simply be
5611 processed and discarded.
5613 This segment is also optional; scan_partial_symbols and
5614 add_partial_symbol will handle these DIEs if we chain
5615 them in normally. When compilers which do not emit large
5616 quantities of duplicate debug information are more common,
5617 this code can probably be removed. */
5619 /* Any complete simple types at the top level (pretty much all
5620 of them, for a language without namespaces), can be processed
5622 if (parent_die
== NULL
5623 && part_die
->has_specification
== 0
5624 && part_die
->is_declaration
== 0
5625 && (part_die
->tag
== DW_TAG_typedef
5626 || part_die
->tag
== DW_TAG_base_type
5627 || part_die
->tag
== DW_TAG_subrange_type
))
5629 if (building_psymtab
&& part_die
->name
!= NULL
)
5630 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5631 VAR_DOMAIN
, LOC_TYPEDEF
,
5632 &cu
->objfile
->static_psymbols
,
5633 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5634 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5638 /* If we're at the second level, and we're an enumerator, and
5639 our parent has no specification (meaning possibly lives in a
5640 namespace elsewhere), then we can add the partial symbol now
5641 instead of queueing it. */
5642 if (part_die
->tag
== DW_TAG_enumerator
5643 && parent_die
!= NULL
5644 && parent_die
->die_parent
== NULL
5645 && parent_die
->tag
== DW_TAG_enumeration_type
5646 && parent_die
->has_specification
== 0)
5648 if (part_die
->name
== NULL
)
5649 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5650 else if (building_psymtab
)
5651 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5652 VAR_DOMAIN
, LOC_CONST
,
5653 (cu
->language
== language_cplus
5654 || cu
->language
== language_java
)
5655 ? &cu
->objfile
->global_psymbols
5656 : &cu
->objfile
->static_psymbols
,
5657 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5659 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5663 /* We'll save this DIE so link it in. */
5664 part_die
->die_parent
= parent_die
;
5665 part_die
->die_sibling
= NULL
;
5666 part_die
->die_child
= NULL
;
5668 if (last_die
&& last_die
== parent_die
)
5669 last_die
->die_child
= part_die
;
5671 last_die
->die_sibling
= part_die
;
5673 last_die
= part_die
;
5675 if (first_die
== NULL
)
5676 first_die
= part_die
;
5678 /* Maybe add the DIE to the hash table. Not all DIEs that we
5679 find interesting need to be in the hash table, because we
5680 also have the parent/sibling/child chains; only those that we
5681 might refer to by offset later during partial symbol reading.
5683 For now this means things that might have be the target of a
5684 DW_AT_specification, DW_AT_abstract_origin, or
5685 DW_AT_extension. DW_AT_extension will refer only to
5686 namespaces; DW_AT_abstract_origin refers to functions (and
5687 many things under the function DIE, but we do not recurse
5688 into function DIEs during partial symbol reading) and
5689 possibly variables as well; DW_AT_specification refers to
5690 declarations. Declarations ought to have the DW_AT_declaration
5691 flag. It happens that GCC forgets to put it in sometimes, but
5692 only for functions, not for types.
5694 Adding more things than necessary to the hash table is harmless
5695 except for the performance cost. Adding too few will result in
5696 wasted time in find_partial_die, when we reread the compilation
5697 unit with load_all_dies set. */
5700 || abbrev
->tag
== DW_TAG_subprogram
5701 || abbrev
->tag
== DW_TAG_variable
5702 || abbrev
->tag
== DW_TAG_namespace
5703 || part_die
->is_declaration
)
5707 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5708 part_die
->offset
, INSERT
);
5712 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5713 sizeof (struct partial_die_info
));
5715 /* For some DIEs we want to follow their children (if any). For C
5716 we have no reason to follow the children of structures; for other
5717 languages we have to, both so that we can get at method physnames
5718 to infer fully qualified class names, and for DW_AT_specification. */
5719 if (last_die
->has_children
5721 || last_die
->tag
== DW_TAG_namespace
5722 || last_die
->tag
== DW_TAG_enumeration_type
5723 || (cu
->language
!= language_c
5724 && (last_die
->tag
== DW_TAG_class_type
5725 || last_die
->tag
== DW_TAG_interface_type
5726 || last_die
->tag
== DW_TAG_structure_type
5727 || last_die
->tag
== DW_TAG_union_type
))))
5730 parent_die
= last_die
;
5734 /* Otherwise we skip to the next sibling, if any. */
5735 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5737 /* Back to the top, do it again. */
5741 /* Read a minimal amount of information into the minimal die structure. */
5744 read_partial_die (struct partial_die_info
*part_die
,
5745 struct abbrev_info
*abbrev
,
5746 unsigned int abbrev_len
, bfd
*abfd
,
5747 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5749 unsigned int bytes_read
, i
;
5750 struct attribute attr
;
5751 int has_low_pc_attr
= 0;
5752 int has_high_pc_attr
= 0;
5753 CORE_ADDR base_address
= 0;
5757 base_address_low_pc
,
5758 /* Overrides BASE_ADDRESS_LOW_PC. */
5759 base_address_entry_pc
5761 base_address_type
= base_address_none
;
5763 memset (part_die
, 0, sizeof (struct partial_die_info
));
5765 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5767 info_ptr
+= abbrev_len
;
5772 part_die
->tag
= abbrev
->tag
;
5773 part_die
->has_children
= abbrev
->has_children
;
5775 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5777 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5779 /* Store the data if it is of an attribute we want to keep in a
5780 partial symbol table. */
5785 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5786 if (part_die
->name
== NULL
)
5787 part_die
->name
= DW_STRING (&attr
);
5789 case DW_AT_comp_dir
:
5790 if (part_die
->dirname
== NULL
)
5791 part_die
->dirname
= DW_STRING (&attr
);
5793 case DW_AT_MIPS_linkage_name
:
5794 part_die
->name
= DW_STRING (&attr
);
5797 has_low_pc_attr
= 1;
5798 part_die
->lowpc
= DW_ADDR (&attr
);
5799 if (part_die
->tag
== DW_TAG_compile_unit
5800 && base_address_type
< base_address_low_pc
)
5802 base_address
= DW_ADDR (&attr
);
5803 base_address_type
= base_address_low_pc
;
5807 has_high_pc_attr
= 1;
5808 part_die
->highpc
= DW_ADDR (&attr
);
5810 case DW_AT_entry_pc
:
5811 if (part_die
->tag
== DW_TAG_compile_unit
5812 && base_address_type
< base_address_entry_pc
)
5814 base_address
= DW_ADDR (&attr
);
5815 base_address_type
= base_address_entry_pc
;
5819 if (part_die
->tag
== DW_TAG_compile_unit
)
5821 cu
->ranges_offset
= DW_UNSND (&attr
);
5822 cu
->has_ranges_offset
= 1;
5825 case DW_AT_location
:
5826 /* Support the .debug_loc offsets */
5827 if (attr_form_is_block (&attr
))
5829 part_die
->locdesc
= DW_BLOCK (&attr
);
5831 else if (attr_form_is_section_offset (&attr
))
5833 dwarf2_complex_location_expr_complaint ();
5837 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5838 "partial symbol information");
5841 case DW_AT_language
:
5842 part_die
->language
= DW_UNSND (&attr
);
5844 case DW_AT_external
:
5845 part_die
->is_external
= DW_UNSND (&attr
);
5847 case DW_AT_declaration
:
5848 part_die
->is_declaration
= DW_UNSND (&attr
);
5851 part_die
->has_type
= 1;
5853 case DW_AT_abstract_origin
:
5854 case DW_AT_specification
:
5855 case DW_AT_extension
:
5856 part_die
->has_specification
= 1;
5857 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5860 /* Ignore absolute siblings, they might point outside of
5861 the current compile unit. */
5862 if (attr
.form
== DW_FORM_ref_addr
)
5863 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5865 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5866 + dwarf2_get_ref_die_offset (&attr
, cu
);
5868 case DW_AT_stmt_list
:
5869 part_die
->has_stmt_list
= 1;
5870 part_die
->line_offset
= DW_UNSND (&attr
);
5872 case DW_AT_byte_size
:
5873 part_die
->has_byte_size
= 1;
5875 case DW_AT_calling_convention
:
5876 /* DWARF doesn't provide a way to identify a program's source-level
5877 entry point. DW_AT_calling_convention attributes are only meant
5878 to describe functions' calling conventions.
5880 However, because it's a necessary piece of information in
5881 Fortran, and because DW_CC_program is the only piece of debugging
5882 information whose definition refers to a 'main program' at all,
5883 several compilers have begun marking Fortran main programs with
5884 DW_CC_program --- even when those functions use the standard
5885 calling conventions.
5887 So until DWARF specifies a way to provide this information and
5888 compilers pick up the new representation, we'll support this
5890 if (DW_UNSND (&attr
) == DW_CC_program
5891 && cu
->language
== language_fortran
)
5892 set_main_name (part_die
->name
);
5899 /* When using the GNU linker, .gnu.linkonce. sections are used to
5900 eliminate duplicate copies of functions and vtables and such.
5901 The linker will arbitrarily choose one and discard the others.
5902 The AT_*_pc values for such functions refer to local labels in
5903 these sections. If the section from that file was discarded, the
5904 labels are not in the output, so the relocs get a value of 0.
5905 If this is a discarded function, mark the pc bounds as invalid,
5906 so that GDB will ignore it. */
5907 if (has_low_pc_attr
&& has_high_pc_attr
5908 && part_die
->lowpc
< part_die
->highpc
5909 && (part_die
->lowpc
!= 0
5910 || dwarf2_per_objfile
->has_section_at_zero
))
5911 part_die
->has_pc_info
= 1;
5913 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
5915 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5916 cu
->header
.base_known
= 1;
5917 cu
->header
.base_address
= base_address
;
5923 /* Find a cached partial DIE at OFFSET in CU. */
5925 static struct partial_die_info
*
5926 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5928 struct partial_die_info
*lookup_die
= NULL
;
5929 struct partial_die_info part_die
;
5931 part_die
.offset
= offset
;
5932 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5937 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5939 static struct partial_die_info
*
5940 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5942 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5943 struct partial_die_info
*pd
= NULL
;
5945 if (offset
>= cu
->header
.offset
5946 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5948 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5953 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5955 if (per_cu
->cu
== NULL
)
5957 load_comp_unit (per_cu
, cu
->objfile
);
5958 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5959 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5962 per_cu
->cu
->last_used
= 0;
5963 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5965 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5967 struct cleanup
*back_to
;
5968 struct partial_die_info comp_unit_die
;
5969 struct abbrev_info
*abbrev
;
5970 unsigned int bytes_read
;
5973 per_cu
->load_all_dies
= 1;
5975 /* Re-read the DIEs. */
5976 back_to
= make_cleanup (null_cleanup
, 0);
5977 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5979 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5980 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5982 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
5983 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5984 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5985 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5987 if (comp_unit_die
.has_children
)
5988 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5989 do_cleanups (back_to
);
5991 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5995 internal_error (__FILE__
, __LINE__
,
5996 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
5997 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6001 /* Adjust PART_DIE before generating a symbol for it. This function
6002 may set the is_external flag or change the DIE's name. */
6005 fixup_partial_die (struct partial_die_info
*part_die
,
6006 struct dwarf2_cu
*cu
)
6008 /* If we found a reference attribute and the DIE has no name, try
6009 to find a name in the referred to DIE. */
6011 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6013 struct partial_die_info
*spec_die
;
6015 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6017 fixup_partial_die (spec_die
, cu
);
6021 part_die
->name
= spec_die
->name
;
6023 /* Copy DW_AT_external attribute if it is set. */
6024 if (spec_die
->is_external
)
6025 part_die
->is_external
= spec_die
->is_external
;
6029 /* Set default names for some unnamed DIEs. */
6030 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6031 || part_die
->tag
== DW_TAG_class_type
))
6032 part_die
->name
= "(anonymous class)";
6034 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6035 part_die
->name
= "(anonymous namespace)";
6037 if (part_die
->tag
== DW_TAG_structure_type
6038 || part_die
->tag
== DW_TAG_class_type
6039 || part_die
->tag
== DW_TAG_union_type
)
6040 guess_structure_name (part_die
, cu
);
6043 /* Read the die from the .debug_info section buffer. Set DIEP to
6044 point to a newly allocated die with its information, except for its
6045 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6046 whether the die has children or not. */
6049 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6050 struct dwarf2_cu
*cu
, int *has_children
)
6052 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6053 struct abbrev_info
*abbrev
;
6054 struct die_info
*die
;
6056 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6057 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6058 info_ptr
+= bytes_read
;
6061 die
= dwarf_alloc_die ();
6063 die
->abbrev
= abbrev_number
;
6069 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6072 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6074 bfd_get_filename (abfd
));
6076 die
= dwarf_alloc_die ();
6077 die
->offset
= offset
;
6078 die
->tag
= abbrev
->tag
;
6079 die
->abbrev
= abbrev_number
;
6081 die
->num_attrs
= abbrev
->num_attrs
;
6082 die
->attrs
= (struct attribute
*)
6083 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
6085 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6087 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6088 abfd
, info_ptr
, cu
);
6090 /* If this attribute is an absolute reference to a different
6091 compilation unit, make sure that compilation unit is loaded
6093 if (die
->attrs
[i
].form
== DW_FORM_ref_addr
6094 && (DW_ADDR (&die
->attrs
[i
]) < cu
->header
.offset
6095 || (DW_ADDR (&die
->attrs
[i
])
6096 >= cu
->header
.offset
+ cu
->header
.length
)))
6098 struct dwarf2_per_cu_data
*per_cu
;
6099 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (&die
->attrs
[i
]),
6102 /* Mark the dependence relation so that we don't flush PER_CU
6104 dwarf2_add_dependence (cu
, per_cu
);
6106 /* If it's already on the queue, we have nothing to do. */
6110 /* If the compilation unit is already loaded, just mark it as
6112 if (per_cu
->cu
!= NULL
)
6114 per_cu
->cu
->last_used
= 0;
6118 /* Add it to the queue. */
6119 queue_comp_unit (per_cu
);
6124 *has_children
= abbrev
->has_children
;
6128 /* Read an attribute value described by an attribute form. */
6131 read_attribute_value (struct attribute
*attr
, unsigned form
,
6132 bfd
*abfd
, gdb_byte
*info_ptr
,
6133 struct dwarf2_cu
*cu
)
6135 struct comp_unit_head
*cu_header
= &cu
->header
;
6136 unsigned int bytes_read
;
6137 struct dwarf_block
*blk
;
6143 case DW_FORM_ref_addr
:
6144 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6145 info_ptr
+= bytes_read
;
6147 case DW_FORM_block2
:
6148 blk
= dwarf_alloc_block (cu
);
6149 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6151 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6152 info_ptr
+= blk
->size
;
6153 DW_BLOCK (attr
) = blk
;
6155 case DW_FORM_block4
:
6156 blk
= dwarf_alloc_block (cu
);
6157 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6159 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6160 info_ptr
+= blk
->size
;
6161 DW_BLOCK (attr
) = blk
;
6164 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6168 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6172 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6175 case DW_FORM_string
:
6176 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6177 info_ptr
+= bytes_read
;
6180 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6182 info_ptr
+= bytes_read
;
6185 blk
= dwarf_alloc_block (cu
);
6186 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6187 info_ptr
+= bytes_read
;
6188 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6189 info_ptr
+= blk
->size
;
6190 DW_BLOCK (attr
) = blk
;
6192 case DW_FORM_block1
:
6193 blk
= dwarf_alloc_block (cu
);
6194 blk
->size
= read_1_byte (abfd
, info_ptr
);
6196 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6197 info_ptr
+= blk
->size
;
6198 DW_BLOCK (attr
) = blk
;
6201 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6205 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6209 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6210 info_ptr
+= bytes_read
;
6213 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6214 info_ptr
+= bytes_read
;
6217 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6221 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6225 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6229 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6232 case DW_FORM_ref_udata
:
6233 DW_ADDR (attr
) = (cu
->header
.offset
6234 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6235 info_ptr
+= bytes_read
;
6237 case DW_FORM_indirect
:
6238 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6239 info_ptr
+= bytes_read
;
6240 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6243 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6244 dwarf_form_name (form
),
6245 bfd_get_filename (abfd
));
6250 /* Read an attribute described by an abbreviated attribute. */
6253 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6254 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6256 attr
->name
= abbrev
->name
;
6257 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6260 /* read dwarf information from a buffer */
6263 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6265 return bfd_get_8 (abfd
, buf
);
6269 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6271 return bfd_get_signed_8 (abfd
, buf
);
6275 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6277 return bfd_get_16 (abfd
, buf
);
6281 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6283 return bfd_get_signed_16 (abfd
, buf
);
6287 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6289 return bfd_get_32 (abfd
, buf
);
6293 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6295 return bfd_get_signed_32 (abfd
, buf
);
6298 static unsigned long
6299 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6301 return bfd_get_64 (abfd
, buf
);
6305 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6306 unsigned int *bytes_read
)
6308 struct comp_unit_head
*cu_header
= &cu
->header
;
6309 CORE_ADDR retval
= 0;
6311 if (cu_header
->signed_addr_p
)
6313 switch (cu_header
->addr_size
)
6316 retval
= bfd_get_signed_16 (abfd
, buf
);
6319 retval
= bfd_get_signed_32 (abfd
, buf
);
6322 retval
= bfd_get_signed_64 (abfd
, buf
);
6325 internal_error (__FILE__
, __LINE__
,
6326 _("read_address: bad switch, signed [in module %s]"),
6327 bfd_get_filename (abfd
));
6332 switch (cu_header
->addr_size
)
6335 retval
= bfd_get_16 (abfd
, buf
);
6338 retval
= bfd_get_32 (abfd
, buf
);
6341 retval
= bfd_get_64 (abfd
, buf
);
6344 internal_error (__FILE__
, __LINE__
,
6345 _("read_address: bad switch, unsigned [in module %s]"),
6346 bfd_get_filename (abfd
));
6350 *bytes_read
= cu_header
->addr_size
;
6354 /* Read the initial length from a section. The (draft) DWARF 3
6355 specification allows the initial length to take up either 4 bytes
6356 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6357 bytes describe the length and all offsets will be 8 bytes in length
6360 An older, non-standard 64-bit format is also handled by this
6361 function. The older format in question stores the initial length
6362 as an 8-byte quantity without an escape value. Lengths greater
6363 than 2^32 aren't very common which means that the initial 4 bytes
6364 is almost always zero. Since a length value of zero doesn't make
6365 sense for the 32-bit format, this initial zero can be considered to
6366 be an escape value which indicates the presence of the older 64-bit
6367 format. As written, the code can't detect (old format) lengths
6368 greater than 4GB. If it becomes necessary to handle lengths
6369 somewhat larger than 4GB, we could allow other small values (such
6370 as the non-sensical values of 1, 2, and 3) to also be used as
6371 escape values indicating the presence of the old format.
6373 The value returned via bytes_read should be used to increment the
6374 relevant pointer after calling read_initial_length().
6376 As a side effect, this function sets the fields initial_length_size
6377 and offset_size in cu_header to the values appropriate for the
6378 length field. (The format of the initial length field determines
6379 the width of file offsets to be fetched later with read_offset().)
6381 [ Note: read_initial_length() and read_offset() are based on the
6382 document entitled "DWARF Debugging Information Format", revision
6383 3, draft 8, dated November 19, 2001. This document was obtained
6386 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6388 This document is only a draft and is subject to change. (So beware.)
6390 Details regarding the older, non-standard 64-bit format were
6391 determined empirically by examining 64-bit ELF files produced by
6392 the SGI toolchain on an IRIX 6.5 machine.
6394 - Kevin, July 16, 2002
6398 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6399 unsigned int *bytes_read
)
6401 LONGEST length
= bfd_get_32 (abfd
, buf
);
6403 if (length
== 0xffffffff)
6405 length
= bfd_get_64 (abfd
, buf
+ 4);
6408 else if (length
== 0)
6410 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6411 length
= bfd_get_64 (abfd
, buf
);
6421 gdb_assert (cu_header
->initial_length_size
== 0
6422 || cu_header
->initial_length_size
== 4
6423 || cu_header
->initial_length_size
== 8
6424 || cu_header
->initial_length_size
== 12);
6426 if (cu_header
->initial_length_size
!= 0
6427 && cu_header
->initial_length_size
!= *bytes_read
)
6428 complaint (&symfile_complaints
,
6429 _("intermixed 32-bit and 64-bit DWARF sections"));
6431 cu_header
->initial_length_size
= *bytes_read
;
6432 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6438 /* Read an offset from the data stream. The size of the offset is
6439 given by cu_header->offset_size. */
6442 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6443 unsigned int *bytes_read
)
6447 switch (cu_header
->offset_size
)
6450 retval
= bfd_get_32 (abfd
, buf
);
6454 retval
= bfd_get_64 (abfd
, buf
);
6458 internal_error (__FILE__
, __LINE__
,
6459 _("read_offset: bad switch [in module %s]"),
6460 bfd_get_filename (abfd
));
6467 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6469 /* If the size of a host char is 8 bits, we can return a pointer
6470 to the buffer, otherwise we have to copy the data to a buffer
6471 allocated on the temporary obstack. */
6472 gdb_assert (HOST_CHAR_BIT
== 8);
6477 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6479 /* If the size of a host char is 8 bits, we can return a pointer
6480 to the string, otherwise we have to copy the string to a buffer
6481 allocated on the temporary obstack. */
6482 gdb_assert (HOST_CHAR_BIT
== 8);
6485 *bytes_read_ptr
= 1;
6488 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6489 return (char *) buf
;
6493 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6494 const struct comp_unit_head
*cu_header
,
6495 unsigned int *bytes_read_ptr
)
6497 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6500 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6502 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6503 bfd_get_filename (abfd
));
6506 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6508 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6509 bfd_get_filename (abfd
));
6512 gdb_assert (HOST_CHAR_BIT
== 8);
6513 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6515 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6518 static unsigned long
6519 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6521 unsigned long result
;
6522 unsigned int num_read
;
6532 byte
= bfd_get_8 (abfd
, buf
);
6535 result
|= ((unsigned long)(byte
& 127) << shift
);
6536 if ((byte
& 128) == 0)
6542 *bytes_read_ptr
= num_read
;
6547 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6550 int i
, shift
, num_read
;
6559 byte
= bfd_get_8 (abfd
, buf
);
6562 result
|= ((long)(byte
& 127) << shift
);
6564 if ((byte
& 128) == 0)
6569 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6570 result
|= -(((long)1) << shift
);
6571 *bytes_read_ptr
= num_read
;
6575 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6578 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6584 byte
= bfd_get_8 (abfd
, buf
);
6586 if ((byte
& 128) == 0)
6592 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6598 cu
->language
= language_c
;
6600 case DW_LANG_C_plus_plus
:
6601 cu
->language
= language_cplus
;
6603 case DW_LANG_Fortran77
:
6604 case DW_LANG_Fortran90
:
6605 case DW_LANG_Fortran95
:
6606 cu
->language
= language_fortran
;
6608 case DW_LANG_Mips_Assembler
:
6609 cu
->language
= language_asm
;
6612 cu
->language
= language_java
;
6616 cu
->language
= language_ada
;
6618 case DW_LANG_Modula2
:
6619 cu
->language
= language_m2
;
6621 case DW_LANG_Pascal83
:
6622 cu
->language
= language_pascal
;
6625 cu
->language
= language_objc
;
6627 case DW_LANG_Cobol74
:
6628 case DW_LANG_Cobol85
:
6630 cu
->language
= language_minimal
;
6633 cu
->language_defn
= language_def (cu
->language
);
6636 /* Return the named attribute or NULL if not there. */
6638 static struct attribute
*
6639 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6642 struct attribute
*spec
= NULL
;
6644 for (i
= 0; i
< die
->num_attrs
; ++i
)
6646 if (die
->attrs
[i
].name
== name
)
6647 return &die
->attrs
[i
];
6648 if (die
->attrs
[i
].name
== DW_AT_specification
6649 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6650 spec
= &die
->attrs
[i
];
6654 return dwarf2_attr (follow_die_ref (die
, spec
, cu
), name
, cu
);
6659 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6660 and holds a non-zero value. This function should only be used for
6661 DW_FORM_flag attributes. */
6664 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6666 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6668 return (attr
&& DW_UNSND (attr
));
6672 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6674 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6675 which value is non-zero. However, we have to be careful with
6676 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6677 (via dwarf2_flag_true_p) follows this attribute. So we may
6678 end up accidently finding a declaration attribute that belongs
6679 to a different DIE referenced by the specification attribute,
6680 even though the given DIE does not have a declaration attribute. */
6681 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6682 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6685 /* Return the die giving the specification for DIE, if there is
6688 static struct die_info
*
6689 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6691 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6693 if (spec_attr
== NULL
)
6696 return follow_die_ref (die
, spec_attr
, cu
);
6699 /* Free the line_header structure *LH, and any arrays and strings it
6702 free_line_header (struct line_header
*lh
)
6704 if (lh
->standard_opcode_lengths
)
6705 xfree (lh
->standard_opcode_lengths
);
6707 /* Remember that all the lh->file_names[i].name pointers are
6708 pointers into debug_line_buffer, and don't need to be freed. */
6710 xfree (lh
->file_names
);
6712 /* Similarly for the include directory names. */
6713 if (lh
->include_dirs
)
6714 xfree (lh
->include_dirs
);
6720 /* Add an entry to LH's include directory table. */
6722 add_include_dir (struct line_header
*lh
, char *include_dir
)
6724 /* Grow the array if necessary. */
6725 if (lh
->include_dirs_size
== 0)
6727 lh
->include_dirs_size
= 1; /* for testing */
6728 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6729 * sizeof (*lh
->include_dirs
));
6731 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6733 lh
->include_dirs_size
*= 2;
6734 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6735 (lh
->include_dirs_size
6736 * sizeof (*lh
->include_dirs
)));
6739 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6743 /* Add an entry to LH's file name table. */
6745 add_file_name (struct line_header
*lh
,
6747 unsigned int dir_index
,
6748 unsigned int mod_time
,
6749 unsigned int length
)
6751 struct file_entry
*fe
;
6753 /* Grow the array if necessary. */
6754 if (lh
->file_names_size
== 0)
6756 lh
->file_names_size
= 1; /* for testing */
6757 lh
->file_names
= xmalloc (lh
->file_names_size
6758 * sizeof (*lh
->file_names
));
6760 else if (lh
->num_file_names
>= lh
->file_names_size
)
6762 lh
->file_names_size
*= 2;
6763 lh
->file_names
= xrealloc (lh
->file_names
,
6764 (lh
->file_names_size
6765 * sizeof (*lh
->file_names
)));
6768 fe
= &lh
->file_names
[lh
->num_file_names
++];
6770 fe
->dir_index
= dir_index
;
6771 fe
->mod_time
= mod_time
;
6772 fe
->length
= length
;
6778 /* Read the statement program header starting at OFFSET in
6779 .debug_line, according to the endianness of ABFD. Return a pointer
6780 to a struct line_header, allocated using xmalloc.
6782 NOTE: the strings in the include directory and file name tables of
6783 the returned object point into debug_line_buffer, and must not be
6785 static struct line_header
*
6786 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6787 struct dwarf2_cu
*cu
)
6789 struct cleanup
*back_to
;
6790 struct line_header
*lh
;
6792 unsigned int bytes_read
;
6794 char *cur_dir
, *cur_file
;
6796 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6798 complaint (&symfile_complaints
, _("missing .debug_line section"));
6802 /* Make sure that at least there's room for the total_length field.
6803 That could be 12 bytes long, but we're just going to fudge that. */
6804 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6806 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6810 lh
= xmalloc (sizeof (*lh
));
6811 memset (lh
, 0, sizeof (*lh
));
6812 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6815 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6817 /* Read in the header. */
6819 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6820 line_ptr
+= bytes_read
;
6821 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6822 + dwarf2_per_objfile
->line_size
))
6824 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6827 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6828 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6830 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6831 line_ptr
+= bytes_read
;
6832 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6834 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6836 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6838 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6840 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6842 lh
->standard_opcode_lengths
6843 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6845 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6846 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6848 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6852 /* Read directory table. */
6853 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6855 line_ptr
+= bytes_read
;
6856 add_include_dir (lh
, cur_dir
);
6858 line_ptr
+= bytes_read
;
6860 /* Read file name table. */
6861 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6863 unsigned int dir_index
, mod_time
, length
;
6865 line_ptr
+= bytes_read
;
6866 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6867 line_ptr
+= bytes_read
;
6868 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6869 line_ptr
+= bytes_read
;
6870 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6871 line_ptr
+= bytes_read
;
6873 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6875 line_ptr
+= bytes_read
;
6876 lh
->statement_program_start
= line_ptr
;
6878 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6879 + dwarf2_per_objfile
->line_size
))
6880 complaint (&symfile_complaints
,
6881 _("line number info header doesn't fit in `.debug_line' section"));
6883 discard_cleanups (back_to
);
6887 /* This function exists to work around a bug in certain compilers
6888 (particularly GCC 2.95), in which the first line number marker of a
6889 function does not show up until after the prologue, right before
6890 the second line number marker. This function shifts ADDRESS down
6891 to the beginning of the function if necessary, and is called on
6892 addresses passed to record_line. */
6895 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6897 struct function_range
*fn
;
6899 /* Find the function_range containing address. */
6904 cu
->cached_fn
= cu
->first_fn
;
6908 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6914 while (fn
&& fn
!= cu
->cached_fn
)
6915 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6925 if (address
!= fn
->lowpc
)
6926 complaint (&symfile_complaints
,
6927 _("misplaced first line number at 0x%lx for '%s'"),
6928 (unsigned long) address
, fn
->name
);
6933 /* Decode the Line Number Program (LNP) for the given line_header
6934 structure and CU. The actual information extracted and the type
6935 of structures created from the LNP depends on the value of PST.
6937 1. If PST is NULL, then this procedure uses the data from the program
6938 to create all necessary symbol tables, and their linetables.
6939 The compilation directory of the file is passed in COMP_DIR,
6940 and must not be NULL.
6942 2. If PST is not NULL, this procedure reads the program to determine
6943 the list of files included by the unit represented by PST, and
6944 builds all the associated partial symbol tables. In this case,
6945 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6946 is not used to compute the full name of the symtab, and therefore
6947 omitting it when building the partial symtab does not introduce
6948 the potential for inconsistency - a partial symtab and its associated
6949 symbtab having a different fullname -). */
6952 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6953 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6955 gdb_byte
*line_ptr
, *extended_end
;
6957 unsigned int bytes_read
, extended_len
;
6958 unsigned char op_code
, extended_op
, adj_opcode
;
6960 struct objfile
*objfile
= cu
->objfile
;
6961 const int decode_for_pst_p
= (pst
!= NULL
);
6962 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6964 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6966 line_ptr
= lh
->statement_program_start
;
6967 line_end
= lh
->statement_program_end
;
6969 /* Read the statement sequences until there's nothing left. */
6970 while (line_ptr
< line_end
)
6972 /* state machine registers */
6973 CORE_ADDR address
= 0;
6974 unsigned int file
= 1;
6975 unsigned int line
= 1;
6976 unsigned int column
= 0;
6977 int is_stmt
= lh
->default_is_stmt
;
6978 int basic_block
= 0;
6979 int end_sequence
= 0;
6981 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6983 /* Start a subfile for the current file of the state machine. */
6984 /* lh->include_dirs and lh->file_names are 0-based, but the
6985 directory and file name numbers in the statement program
6987 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6991 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6993 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6996 /* Decode the table. */
6997 while (!end_sequence
)
6999 op_code
= read_1_byte (abfd
, line_ptr
);
7002 if (op_code
>= lh
->opcode_base
)
7004 /* Special operand. */
7005 adj_opcode
= op_code
- lh
->opcode_base
;
7006 address
+= (adj_opcode
/ lh
->line_range
)
7007 * lh
->minimum_instruction_length
;
7008 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7009 if (lh
->num_file_names
< file
)
7010 dwarf2_debug_line_missing_file_complaint ();
7013 lh
->file_names
[file
- 1].included_p
= 1;
7014 if (!decode_for_pst_p
)
7016 if (last_subfile
!= current_subfile
)
7019 record_line (last_subfile
, 0, address
);
7020 last_subfile
= current_subfile
;
7022 /* Append row to matrix using current values. */
7023 record_line (current_subfile
, line
,
7024 check_cu_functions (address
, cu
));
7029 else switch (op_code
)
7031 case DW_LNS_extended_op
:
7032 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7033 line_ptr
+= bytes_read
;
7034 extended_end
= line_ptr
+ extended_len
;
7035 extended_op
= read_1_byte (abfd
, line_ptr
);
7037 switch (extended_op
)
7039 case DW_LNE_end_sequence
:
7042 if (lh
->num_file_names
< file
)
7043 dwarf2_debug_line_missing_file_complaint ();
7046 lh
->file_names
[file
- 1].included_p
= 1;
7047 if (!decode_for_pst_p
)
7048 record_line (current_subfile
, 0, address
);
7051 case DW_LNE_set_address
:
7052 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7053 line_ptr
+= bytes_read
;
7054 address
+= baseaddr
;
7056 case DW_LNE_define_file
:
7059 unsigned int dir_index
, mod_time
, length
;
7061 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7062 line_ptr
+= bytes_read
;
7064 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7065 line_ptr
+= bytes_read
;
7067 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7068 line_ptr
+= bytes_read
;
7070 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7071 line_ptr
+= bytes_read
;
7072 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7076 complaint (&symfile_complaints
,
7077 _("mangled .debug_line section"));
7080 /* Make sure that we parsed the extended op correctly. If e.g.
7081 we expected a different address size than the producer used,
7082 we may have read the wrong number of bytes. */
7083 if (line_ptr
!= extended_end
)
7085 complaint (&symfile_complaints
,
7086 _("mangled .debug_line section"));
7091 if (lh
->num_file_names
< file
)
7092 dwarf2_debug_line_missing_file_complaint ();
7095 lh
->file_names
[file
- 1].included_p
= 1;
7096 if (!decode_for_pst_p
)
7098 if (last_subfile
!= current_subfile
)
7101 record_line (last_subfile
, 0, address
);
7102 last_subfile
= current_subfile
;
7104 record_line (current_subfile
, line
,
7105 check_cu_functions (address
, cu
));
7110 case DW_LNS_advance_pc
:
7111 address
+= lh
->minimum_instruction_length
7112 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7113 line_ptr
+= bytes_read
;
7115 case DW_LNS_advance_line
:
7116 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7117 line_ptr
+= bytes_read
;
7119 case DW_LNS_set_file
:
7121 /* The arrays lh->include_dirs and lh->file_names are
7122 0-based, but the directory and file name numbers in
7123 the statement program are 1-based. */
7124 struct file_entry
*fe
;
7127 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7128 line_ptr
+= bytes_read
;
7129 if (lh
->num_file_names
< file
)
7130 dwarf2_debug_line_missing_file_complaint ();
7133 fe
= &lh
->file_names
[file
- 1];
7135 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7136 if (!decode_for_pst_p
)
7138 last_subfile
= current_subfile
;
7139 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7144 case DW_LNS_set_column
:
7145 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7146 line_ptr
+= bytes_read
;
7148 case DW_LNS_negate_stmt
:
7149 is_stmt
= (!is_stmt
);
7151 case DW_LNS_set_basic_block
:
7154 /* Add to the address register of the state machine the
7155 address increment value corresponding to special opcode
7156 255. I.e., this value is scaled by the minimum
7157 instruction length since special opcode 255 would have
7158 scaled the the increment. */
7159 case DW_LNS_const_add_pc
:
7160 address
+= (lh
->minimum_instruction_length
7161 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7163 case DW_LNS_fixed_advance_pc
:
7164 address
+= read_2_bytes (abfd
, line_ptr
);
7169 /* Unknown standard opcode, ignore it. */
7172 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7174 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7175 line_ptr
+= bytes_read
;
7182 if (decode_for_pst_p
)
7186 /* Now that we're done scanning the Line Header Program, we can
7187 create the psymtab of each included file. */
7188 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7189 if (lh
->file_names
[file_index
].included_p
== 1)
7191 const struct file_entry fe
= lh
->file_names
[file_index
];
7192 char *include_name
= fe
.name
;
7193 char *dir_name
= NULL
;
7194 char *pst_filename
= pst
->filename
;
7197 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7199 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7201 include_name
= concat (dir_name
, SLASH_STRING
,
7202 include_name
, (char *)NULL
);
7203 make_cleanup (xfree
, include_name
);
7206 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7208 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7209 pst_filename
, (char *)NULL
);
7210 make_cleanup (xfree
, pst_filename
);
7213 if (strcmp (include_name
, pst_filename
) != 0)
7214 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7219 /* Make sure a symtab is created for every file, even files
7220 which contain only variables (i.e. no code with associated
7224 struct file_entry
*fe
;
7226 for (i
= 0; i
< lh
->num_file_names
; i
++)
7229 fe
= &lh
->file_names
[i
];
7231 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7232 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7234 /* Skip the main file; we don't need it, and it must be
7235 allocated last, so that it will show up before the
7236 non-primary symtabs in the objfile's symtab list. */
7237 if (current_subfile
== first_subfile
)
7240 if (current_subfile
->symtab
== NULL
)
7241 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7243 fe
->symtab
= current_subfile
->symtab
;
7248 /* Start a subfile for DWARF. FILENAME is the name of the file and
7249 DIRNAME the name of the source directory which contains FILENAME
7250 or NULL if not known. COMP_DIR is the compilation directory for the
7251 linetable's compilation unit or NULL if not known.
7252 This routine tries to keep line numbers from identical absolute and
7253 relative file names in a common subfile.
7255 Using the `list' example from the GDB testsuite, which resides in
7256 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7257 of /srcdir/list0.c yields the following debugging information for list0.c:
7259 DW_AT_name: /srcdir/list0.c
7260 DW_AT_comp_dir: /compdir
7261 files.files[0].name: list0.h
7262 files.files[0].dir: /srcdir
7263 files.files[1].name: list0.c
7264 files.files[1].dir: /srcdir
7266 The line number information for list0.c has to end up in a single
7267 subfile, so that `break /srcdir/list0.c:1' works as expected.
7268 start_subfile will ensure that this happens provided that we pass the
7269 concatenation of files.files[1].dir and files.files[1].name as the
7273 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7277 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7278 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7279 second argument to start_subfile. To be consistent, we do the
7280 same here. In order not to lose the line information directory,
7281 we concatenate it to the filename when it makes sense.
7282 Note that the Dwarf3 standard says (speaking of filenames in line
7283 information): ``The directory index is ignored for file names
7284 that represent full path names''. Thus ignoring dirname in the
7285 `else' branch below isn't an issue. */
7287 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7288 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7290 fullname
= filename
;
7292 start_subfile (fullname
, comp_dir
);
7294 if (fullname
!= filename
)
7299 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7300 struct dwarf2_cu
*cu
)
7302 struct objfile
*objfile
= cu
->objfile
;
7303 struct comp_unit_head
*cu_header
= &cu
->header
;
7305 /* NOTE drow/2003-01-30: There used to be a comment and some special
7306 code here to turn a symbol with DW_AT_external and a
7307 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7308 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7309 with some versions of binutils) where shared libraries could have
7310 relocations against symbols in their debug information - the
7311 minimal symbol would have the right address, but the debug info
7312 would not. It's no longer necessary, because we will explicitly
7313 apply relocations when we read in the debug information now. */
7315 /* A DW_AT_location attribute with no contents indicates that a
7316 variable has been optimized away. */
7317 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7319 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7323 /* Handle one degenerate form of location expression specially, to
7324 preserve GDB's previous behavior when section offsets are
7325 specified. If this is just a DW_OP_addr then mark this symbol
7328 if (attr_form_is_block (attr
)
7329 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7330 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7334 SYMBOL_VALUE_ADDRESS (sym
) =
7335 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7336 fixup_symbol_section (sym
, objfile
);
7337 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7338 SYMBOL_SECTION (sym
));
7339 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7343 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7344 expression evaluator, and use LOC_COMPUTED only when necessary
7345 (i.e. when the value of a register or memory location is
7346 referenced, or a thread-local block, etc.). Then again, it might
7347 not be worthwhile. I'm assuming that it isn't unless performance
7348 or memory numbers show me otherwise. */
7350 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7351 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7354 /* Given a pointer to a DWARF information entry, figure out if we need
7355 to make a symbol table entry for it, and if so, create a new entry
7356 and return a pointer to it.
7357 If TYPE is NULL, determine symbol type from the die, otherwise
7358 used the passed type. */
7360 static struct symbol
*
7361 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7363 struct objfile
*objfile
= cu
->objfile
;
7364 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7365 struct symbol
*sym
= NULL
;
7367 struct attribute
*attr
= NULL
;
7368 struct attribute
*attr2
= NULL
;
7371 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7373 if (die
->tag
!= DW_TAG_namespace
)
7374 name
= dwarf2_linkage_name (die
, cu
);
7376 name
= TYPE_NAME (type
);
7380 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7381 sizeof (struct symbol
));
7382 OBJSTAT (objfile
, n_syms
++);
7383 memset (sym
, 0, sizeof (struct symbol
));
7385 /* Cache this symbol's name and the name's demangled form (if any). */
7386 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7387 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7389 /* Default assumptions.
7390 Use the passed type or decode it from the die. */
7391 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7392 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7394 SYMBOL_TYPE (sym
) = type
;
7396 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7397 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7400 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7403 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7406 int file_index
= DW_UNSND (attr
);
7407 if (cu
->line_header
== NULL
7408 || file_index
> cu
->line_header
->num_file_names
)
7409 complaint (&symfile_complaints
,
7410 _("file index out of range"));
7411 else if (file_index
> 0)
7413 struct file_entry
*fe
;
7414 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7415 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7422 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7425 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7427 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7429 case DW_TAG_subprogram
:
7430 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7432 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7433 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7434 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7435 || cu
->language
== language_ada
)
7437 /* Subprograms marked external are stored as a global symbol.
7438 Ada subprograms, whether marked external or not, are always
7439 stored as a global symbol, because we want to be able to
7440 access them globally. For instance, we want to be able
7441 to break on a nested subprogram without having to
7442 specify the context. */
7443 add_symbol_to_list (sym
, &global_symbols
);
7447 add_symbol_to_list (sym
, cu
->list_in_scope
);
7450 case DW_TAG_variable
:
7451 /* Compilation with minimal debug info may result in variables
7452 with missing type entries. Change the misleading `void' type
7453 to something sensible. */
7454 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7456 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7458 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7461 dwarf2_const_value (attr
, sym
, cu
);
7462 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7463 if (attr2
&& (DW_UNSND (attr2
) != 0))
7464 add_symbol_to_list (sym
, &global_symbols
);
7466 add_symbol_to_list (sym
, cu
->list_in_scope
);
7469 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7472 var_decode_location (attr
, sym
, cu
);
7473 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7474 if (attr2
&& (DW_UNSND (attr2
) != 0))
7475 add_symbol_to_list (sym
, &global_symbols
);
7477 add_symbol_to_list (sym
, cu
->list_in_scope
);
7481 /* We do not know the address of this symbol.
7482 If it is an external symbol and we have type information
7483 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7484 The address of the variable will then be determined from
7485 the minimal symbol table whenever the variable is
7487 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7488 if (attr2
&& (DW_UNSND (attr2
) != 0)
7489 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7491 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7492 add_symbol_to_list (sym
, &global_symbols
);
7496 case DW_TAG_formal_parameter
:
7497 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7500 var_decode_location (attr
, sym
, cu
);
7501 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
7502 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
7503 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
7505 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7508 dwarf2_const_value (attr
, sym
, cu
);
7510 add_symbol_to_list (sym
, cu
->list_in_scope
);
7512 case DW_TAG_unspecified_parameters
:
7513 /* From varargs functions; gdb doesn't seem to have any
7514 interest in this information, so just ignore it for now.
7517 case DW_TAG_class_type
:
7518 case DW_TAG_interface_type
:
7519 case DW_TAG_structure_type
:
7520 case DW_TAG_union_type
:
7521 case DW_TAG_set_type
:
7522 case DW_TAG_enumeration_type
:
7523 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7524 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7526 /* Make sure that the symbol includes appropriate enclosing
7527 classes/namespaces in its name. These are calculated in
7528 read_structure_type, and the correct name is saved in
7531 if (cu
->language
== language_cplus
7532 || cu
->language
== language_java
)
7534 struct type
*type
= SYMBOL_TYPE (sym
);
7536 if (TYPE_TAG_NAME (type
) != NULL
)
7538 /* FIXME: carlton/2003-11-10: Should this use
7539 SYMBOL_SET_NAMES instead? (The same problem also
7540 arises further down in this function.) */
7541 /* The type's name is already allocated along with
7542 this objfile, so we don't need to duplicate it
7544 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7549 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7550 really ever be static objects: otherwise, if you try
7551 to, say, break of a class's method and you're in a file
7552 which doesn't mention that class, it won't work unless
7553 the check for all static symbols in lookup_symbol_aux
7554 saves you. See the OtherFileClass tests in
7555 gdb.c++/namespace.exp. */
7557 struct pending
**list_to_add
;
7559 list_to_add
= (cu
->list_in_scope
== &file_symbols
7560 && (cu
->language
== language_cplus
7561 || cu
->language
== language_java
)
7562 ? &global_symbols
: cu
->list_in_scope
);
7564 add_symbol_to_list (sym
, list_to_add
);
7566 /* The semantics of C++ state that "struct foo { ... }" also
7567 defines a typedef for "foo". A Java class declaration also
7568 defines a typedef for the class. Synthesize a typedef symbol
7569 so that "ptype foo" works as expected. */
7570 if (cu
->language
== language_cplus
7571 || cu
->language
== language_java
7572 || cu
->language
== language_ada
)
7574 struct symbol
*typedef_sym
= (struct symbol
*)
7575 obstack_alloc (&objfile
->objfile_obstack
,
7576 sizeof (struct symbol
));
7577 *typedef_sym
= *sym
;
7578 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
7579 /* The symbol's name is already allocated along with
7580 this objfile, so we don't need to duplicate it for
7582 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7583 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7584 add_symbol_to_list (typedef_sym
, list_to_add
);
7588 case DW_TAG_typedef
:
7589 if (processing_has_namespace_info
7590 && processing_current_prefix
[0] != '\0')
7592 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7593 processing_current_prefix
,
7596 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7597 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7598 add_symbol_to_list (sym
, cu
->list_in_scope
);
7600 case DW_TAG_base_type
:
7601 case DW_TAG_subrange_type
:
7602 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7603 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7604 add_symbol_to_list (sym
, cu
->list_in_scope
);
7606 case DW_TAG_enumerator
:
7607 if (processing_has_namespace_info
7608 && processing_current_prefix
[0] != '\0')
7610 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7611 processing_current_prefix
,
7614 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7617 dwarf2_const_value (attr
, sym
, cu
);
7620 /* NOTE: carlton/2003-11-10: See comment above in the
7621 DW_TAG_class_type, etc. block. */
7623 struct pending
**list_to_add
;
7625 list_to_add
= (cu
->list_in_scope
== &file_symbols
7626 && (cu
->language
== language_cplus
7627 || cu
->language
== language_java
)
7628 ? &global_symbols
: cu
->list_in_scope
);
7630 add_symbol_to_list (sym
, list_to_add
);
7633 case DW_TAG_namespace
:
7634 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7635 add_symbol_to_list (sym
, &global_symbols
);
7638 /* Not a tag we recognize. Hopefully we aren't processing
7639 trash data, but since we must specifically ignore things
7640 we don't recognize, there is nothing else we should do at
7642 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7643 dwarf_tag_name (die
->tag
));
7650 /* Copy constant value from an attribute to a symbol. */
7653 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7654 struct dwarf2_cu
*cu
)
7656 struct objfile
*objfile
= cu
->objfile
;
7657 struct comp_unit_head
*cu_header
= &cu
->header
;
7658 struct dwarf_block
*blk
;
7663 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7664 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7665 cu_header
->addr_size
,
7666 TYPE_LENGTH (SYMBOL_TYPE
7668 SYMBOL_VALUE_BYTES (sym
) =
7669 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7670 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7671 it's body - store_unsigned_integer. */
7672 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7674 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7677 /* DW_STRING is already allocated on the obstack, point directly
7679 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7680 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7682 case DW_FORM_block1
:
7683 case DW_FORM_block2
:
7684 case DW_FORM_block4
:
7686 blk
= DW_BLOCK (attr
);
7687 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7688 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7690 TYPE_LENGTH (SYMBOL_TYPE
7692 SYMBOL_VALUE_BYTES (sym
) =
7693 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7694 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7695 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7698 /* The DW_AT_const_value attributes are supposed to carry the
7699 symbol's value "represented as it would be on the target
7700 architecture." By the time we get here, it's already been
7701 converted to host endianness, so we just need to sign- or
7702 zero-extend it as appropriate. */
7704 dwarf2_const_value_data (attr
, sym
, 8);
7707 dwarf2_const_value_data (attr
, sym
, 16);
7710 dwarf2_const_value_data (attr
, sym
, 32);
7713 dwarf2_const_value_data (attr
, sym
, 64);
7717 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7718 SYMBOL_CLASS (sym
) = LOC_CONST
;
7722 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7723 SYMBOL_CLASS (sym
) = LOC_CONST
;
7727 complaint (&symfile_complaints
,
7728 _("unsupported const value attribute form: '%s'"),
7729 dwarf_form_name (attr
->form
));
7730 SYMBOL_VALUE (sym
) = 0;
7731 SYMBOL_CLASS (sym
) = LOC_CONST
;
7737 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7738 or zero-extend it as appropriate for the symbol's type. */
7740 dwarf2_const_value_data (struct attribute
*attr
,
7744 LONGEST l
= DW_UNSND (attr
);
7746 if (bits
< sizeof (l
) * 8)
7748 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7749 l
&= ((LONGEST
) 1 << bits
) - 1;
7751 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7754 SYMBOL_VALUE (sym
) = l
;
7755 SYMBOL_CLASS (sym
) = LOC_CONST
;
7759 /* Return the type of the die in question using its DW_AT_type attribute. */
7761 static struct type
*
7762 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7764 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7766 struct attribute
*type_attr
;
7767 struct die_info
*type_die
;
7769 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7772 /* A missing DW_AT_type represents a void type. */
7773 return builtin_type (gdbarch
)->builtin_void
;
7776 type_die
= follow_die_ref (die
, type_attr
, cu
);
7778 type
= tag_type_to_type (type_die
, cu
);
7781 dump_die (type_die
);
7782 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7788 /* Return the containing type of the die in question using its
7789 DW_AT_containing_type attribute. */
7791 static struct type
*
7792 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7794 struct type
*type
= NULL
;
7795 struct attribute
*type_attr
;
7796 struct die_info
*type_die
= NULL
;
7798 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7801 type_die
= follow_die_ref (die
, type_attr
, cu
);
7802 type
= tag_type_to_type (type_die
, cu
);
7807 dump_die (type_die
);
7808 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7814 static struct type
*
7815 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7817 struct type
*this_type
;
7819 this_type
= read_type_die (die
, cu
);
7823 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7829 static struct type
*
7830 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7833 const char *old_prefix
;
7834 struct cleanup
*back_to
;
7835 struct type
*this_type
;
7837 this_type
= get_die_type (die
, cu
);
7841 prefix
= determine_prefix (die
, cu
);
7842 old_prefix
= processing_current_prefix
;
7843 back_to
= make_cleanup (xfree
, prefix
);
7844 processing_current_prefix
= prefix
;
7848 case DW_TAG_class_type
:
7849 case DW_TAG_interface_type
:
7850 case DW_TAG_structure_type
:
7851 case DW_TAG_union_type
:
7852 this_type
= read_structure_type (die
, cu
);
7854 case DW_TAG_enumeration_type
:
7855 this_type
= read_enumeration_type (die
, cu
);
7857 case DW_TAG_subprogram
:
7858 case DW_TAG_subroutine_type
:
7859 this_type
= read_subroutine_type (die
, cu
);
7861 case DW_TAG_array_type
:
7862 this_type
= read_array_type (die
, cu
);
7864 case DW_TAG_set_type
:
7865 this_type
= read_set_type (die
, cu
);
7867 case DW_TAG_pointer_type
:
7868 this_type
= read_tag_pointer_type (die
, cu
);
7870 case DW_TAG_ptr_to_member_type
:
7871 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7873 case DW_TAG_reference_type
:
7874 this_type
= read_tag_reference_type (die
, cu
);
7876 case DW_TAG_const_type
:
7877 this_type
= read_tag_const_type (die
, cu
);
7879 case DW_TAG_volatile_type
:
7880 this_type
= read_tag_volatile_type (die
, cu
);
7882 case DW_TAG_string_type
:
7883 this_type
= read_tag_string_type (die
, cu
);
7885 case DW_TAG_typedef
:
7886 this_type
= read_typedef (die
, cu
);
7888 case DW_TAG_subrange_type
:
7889 this_type
= read_subrange_type (die
, cu
);
7891 case DW_TAG_base_type
:
7892 this_type
= read_base_type (die
, cu
);
7894 case DW_TAG_unspecified_type
:
7895 this_type
= read_unspecified_type (die
, cu
);
7898 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7899 dwarf_tag_name (die
->tag
));
7903 processing_current_prefix
= old_prefix
;
7904 do_cleanups (back_to
);
7908 /* Return the name of the namespace/class that DIE is defined within,
7909 or "" if we can't tell. The caller should xfree the result. */
7911 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7912 therein) for an example of how to use this function to deal with
7913 DW_AT_specification. */
7916 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7918 struct die_info
*parent
;
7920 if (cu
->language
!= language_cplus
7921 && cu
->language
!= language_java
)
7924 parent
= die
->parent
;
7928 return xstrdup ("");
7932 switch (parent
->tag
) {
7933 case DW_TAG_namespace
:
7935 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7936 before doing this check? */
7937 struct type
*parent_type
= get_die_type (parent
, cu
);
7938 if (parent_type
!= NULL
&& TYPE_TAG_NAME (parent_type
) != NULL
)
7940 return xstrdup (TYPE_TAG_NAME (parent_type
));
7945 char *parent_prefix
= determine_prefix (parent
, cu
);
7946 char *retval
= typename_concat (NULL
, parent_prefix
,
7947 namespace_name (parent
, &dummy
,
7950 xfree (parent_prefix
);
7955 case DW_TAG_class_type
:
7956 case DW_TAG_interface_type
:
7957 case DW_TAG_structure_type
:
7959 struct type
*parent_type
= get_die_type (parent
, cu
);
7960 if (parent_type
!= NULL
&& TYPE_TAG_NAME (parent_type
) != NULL
)
7962 return xstrdup (TYPE_TAG_NAME (parent_type
));
7966 const char *old_prefix
= processing_current_prefix
;
7967 char *new_prefix
= determine_prefix (parent
, cu
);
7970 processing_current_prefix
= new_prefix
;
7971 retval
= determine_class_name (parent
, cu
);
7972 processing_current_prefix
= old_prefix
;
7979 return determine_prefix (parent
, cu
);
7984 /* Return a newly-allocated string formed by concatenating PREFIX and
7985 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7986 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7987 perform an obconcat, otherwise allocate storage for the result. The CU argument
7988 is used to determine the language and hence, the appropriate separator. */
7990 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7993 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7994 struct dwarf2_cu
*cu
)
7998 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8000 else if (cu
->language
== language_java
)
8007 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8012 strcpy (retval
, prefix
);
8013 strcat (retval
, sep
);
8016 strcat (retval
, suffix
);
8022 /* We have an obstack. */
8023 return obconcat (obs
, prefix
, sep
, suffix
);
8029 copy_die (struct die_info
*old_die
)
8031 struct die_info
*new_die
;
8034 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8035 memset (new_die
, 0, sizeof (struct die_info
));
8037 new_die
->tag
= old_die
->tag
;
8038 new_die
->has_children
= old_die
->has_children
;
8039 new_die
->abbrev
= old_die
->abbrev
;
8040 new_die
->offset
= old_die
->offset
;
8042 num_attrs
= old_die
->num_attrs
;
8043 new_die
->num_attrs
= num_attrs
;
8044 new_die
->attrs
= (struct attribute
*)
8045 xmalloc (num_attrs
* sizeof (struct attribute
));
8047 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
8049 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
8050 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
8051 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
8054 new_die
->next
= NULL
;
8059 /* Return sibling of die, NULL if no sibling. */
8061 static struct die_info
*
8062 sibling_die (struct die_info
*die
)
8064 return die
->sibling
;
8067 /* Get linkage name of a die, return NULL if not found. */
8070 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8072 struct attribute
*attr
;
8074 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8075 if (attr
&& DW_STRING (attr
))
8076 return DW_STRING (attr
);
8077 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8078 if (attr
&& DW_STRING (attr
))
8079 return DW_STRING (attr
);
8083 /* Get name of a die, return NULL if not found. */
8086 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8088 struct attribute
*attr
;
8090 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8091 if (attr
&& DW_STRING (attr
))
8092 return DW_STRING (attr
);
8096 /* Return the die that this die in an extension of, or NULL if there
8099 static struct die_info
*
8100 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
8102 struct attribute
*attr
;
8104 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
8108 return follow_die_ref (die
, attr
, cu
);
8111 /* Convert a DIE tag into its string name. */
8114 dwarf_tag_name (unsigned tag
)
8118 case DW_TAG_padding
:
8119 return "DW_TAG_padding";
8120 case DW_TAG_array_type
:
8121 return "DW_TAG_array_type";
8122 case DW_TAG_class_type
:
8123 return "DW_TAG_class_type";
8124 case DW_TAG_entry_point
:
8125 return "DW_TAG_entry_point";
8126 case DW_TAG_enumeration_type
:
8127 return "DW_TAG_enumeration_type";
8128 case DW_TAG_formal_parameter
:
8129 return "DW_TAG_formal_parameter";
8130 case DW_TAG_imported_declaration
:
8131 return "DW_TAG_imported_declaration";
8133 return "DW_TAG_label";
8134 case DW_TAG_lexical_block
:
8135 return "DW_TAG_lexical_block";
8137 return "DW_TAG_member";
8138 case DW_TAG_pointer_type
:
8139 return "DW_TAG_pointer_type";
8140 case DW_TAG_reference_type
:
8141 return "DW_TAG_reference_type";
8142 case DW_TAG_compile_unit
:
8143 return "DW_TAG_compile_unit";
8144 case DW_TAG_string_type
:
8145 return "DW_TAG_string_type";
8146 case DW_TAG_structure_type
:
8147 return "DW_TAG_structure_type";
8148 case DW_TAG_subroutine_type
:
8149 return "DW_TAG_subroutine_type";
8150 case DW_TAG_typedef
:
8151 return "DW_TAG_typedef";
8152 case DW_TAG_union_type
:
8153 return "DW_TAG_union_type";
8154 case DW_TAG_unspecified_parameters
:
8155 return "DW_TAG_unspecified_parameters";
8156 case DW_TAG_variant
:
8157 return "DW_TAG_variant";
8158 case DW_TAG_common_block
:
8159 return "DW_TAG_common_block";
8160 case DW_TAG_common_inclusion
:
8161 return "DW_TAG_common_inclusion";
8162 case DW_TAG_inheritance
:
8163 return "DW_TAG_inheritance";
8164 case DW_TAG_inlined_subroutine
:
8165 return "DW_TAG_inlined_subroutine";
8167 return "DW_TAG_module";
8168 case DW_TAG_ptr_to_member_type
:
8169 return "DW_TAG_ptr_to_member_type";
8170 case DW_TAG_set_type
:
8171 return "DW_TAG_set_type";
8172 case DW_TAG_subrange_type
:
8173 return "DW_TAG_subrange_type";
8174 case DW_TAG_with_stmt
:
8175 return "DW_TAG_with_stmt";
8176 case DW_TAG_access_declaration
:
8177 return "DW_TAG_access_declaration";
8178 case DW_TAG_base_type
:
8179 return "DW_TAG_base_type";
8180 case DW_TAG_catch_block
:
8181 return "DW_TAG_catch_block";
8182 case DW_TAG_const_type
:
8183 return "DW_TAG_const_type";
8184 case DW_TAG_constant
:
8185 return "DW_TAG_constant";
8186 case DW_TAG_enumerator
:
8187 return "DW_TAG_enumerator";
8188 case DW_TAG_file_type
:
8189 return "DW_TAG_file_type";
8191 return "DW_TAG_friend";
8192 case DW_TAG_namelist
:
8193 return "DW_TAG_namelist";
8194 case DW_TAG_namelist_item
:
8195 return "DW_TAG_namelist_item";
8196 case DW_TAG_packed_type
:
8197 return "DW_TAG_packed_type";
8198 case DW_TAG_subprogram
:
8199 return "DW_TAG_subprogram";
8200 case DW_TAG_template_type_param
:
8201 return "DW_TAG_template_type_param";
8202 case DW_TAG_template_value_param
:
8203 return "DW_TAG_template_value_param";
8204 case DW_TAG_thrown_type
:
8205 return "DW_TAG_thrown_type";
8206 case DW_TAG_try_block
:
8207 return "DW_TAG_try_block";
8208 case DW_TAG_variant_part
:
8209 return "DW_TAG_variant_part";
8210 case DW_TAG_variable
:
8211 return "DW_TAG_variable";
8212 case DW_TAG_volatile_type
:
8213 return "DW_TAG_volatile_type";
8214 case DW_TAG_dwarf_procedure
:
8215 return "DW_TAG_dwarf_procedure";
8216 case DW_TAG_restrict_type
:
8217 return "DW_TAG_restrict_type";
8218 case DW_TAG_interface_type
:
8219 return "DW_TAG_interface_type";
8220 case DW_TAG_namespace
:
8221 return "DW_TAG_namespace";
8222 case DW_TAG_imported_module
:
8223 return "DW_TAG_imported_module";
8224 case DW_TAG_unspecified_type
:
8225 return "DW_TAG_unspecified_type";
8226 case DW_TAG_partial_unit
:
8227 return "DW_TAG_partial_unit";
8228 case DW_TAG_imported_unit
:
8229 return "DW_TAG_imported_unit";
8230 case DW_TAG_condition
:
8231 return "DW_TAG_condition";
8232 case DW_TAG_shared_type
:
8233 return "DW_TAG_shared_type";
8234 case DW_TAG_MIPS_loop
:
8235 return "DW_TAG_MIPS_loop";
8236 case DW_TAG_HP_array_descriptor
:
8237 return "DW_TAG_HP_array_descriptor";
8238 case DW_TAG_format_label
:
8239 return "DW_TAG_format_label";
8240 case DW_TAG_function_template
:
8241 return "DW_TAG_function_template";
8242 case DW_TAG_class_template
:
8243 return "DW_TAG_class_template";
8244 case DW_TAG_GNU_BINCL
:
8245 return "DW_TAG_GNU_BINCL";
8246 case DW_TAG_GNU_EINCL
:
8247 return "DW_TAG_GNU_EINCL";
8248 case DW_TAG_upc_shared_type
:
8249 return "DW_TAG_upc_shared_type";
8250 case DW_TAG_upc_strict_type
:
8251 return "DW_TAG_upc_strict_type";
8252 case DW_TAG_upc_relaxed_type
:
8253 return "DW_TAG_upc_relaxed_type";
8254 case DW_TAG_PGI_kanji_type
:
8255 return "DW_TAG_PGI_kanji_type";
8256 case DW_TAG_PGI_interface_block
:
8257 return "DW_TAG_PGI_interface_block";
8259 return "DW_TAG_<unknown>";
8263 /* Convert a DWARF attribute code into its string name. */
8266 dwarf_attr_name (unsigned attr
)
8271 return "DW_AT_sibling";
8272 case DW_AT_location
:
8273 return "DW_AT_location";
8275 return "DW_AT_name";
8276 case DW_AT_ordering
:
8277 return "DW_AT_ordering";
8278 case DW_AT_subscr_data
:
8279 return "DW_AT_subscr_data";
8280 case DW_AT_byte_size
:
8281 return "DW_AT_byte_size";
8282 case DW_AT_bit_offset
:
8283 return "DW_AT_bit_offset";
8284 case DW_AT_bit_size
:
8285 return "DW_AT_bit_size";
8286 case DW_AT_element_list
:
8287 return "DW_AT_element_list";
8288 case DW_AT_stmt_list
:
8289 return "DW_AT_stmt_list";
8291 return "DW_AT_low_pc";
8293 return "DW_AT_high_pc";
8294 case DW_AT_language
:
8295 return "DW_AT_language";
8297 return "DW_AT_member";
8299 return "DW_AT_discr";
8300 case DW_AT_discr_value
:
8301 return "DW_AT_discr_value";
8302 case DW_AT_visibility
:
8303 return "DW_AT_visibility";
8305 return "DW_AT_import";
8306 case DW_AT_string_length
:
8307 return "DW_AT_string_length";
8308 case DW_AT_common_reference
:
8309 return "DW_AT_common_reference";
8310 case DW_AT_comp_dir
:
8311 return "DW_AT_comp_dir";
8312 case DW_AT_const_value
:
8313 return "DW_AT_const_value";
8314 case DW_AT_containing_type
:
8315 return "DW_AT_containing_type";
8316 case DW_AT_default_value
:
8317 return "DW_AT_default_value";
8319 return "DW_AT_inline";
8320 case DW_AT_is_optional
:
8321 return "DW_AT_is_optional";
8322 case DW_AT_lower_bound
:
8323 return "DW_AT_lower_bound";
8324 case DW_AT_producer
:
8325 return "DW_AT_producer";
8326 case DW_AT_prototyped
:
8327 return "DW_AT_prototyped";
8328 case DW_AT_return_addr
:
8329 return "DW_AT_return_addr";
8330 case DW_AT_start_scope
:
8331 return "DW_AT_start_scope";
8332 case DW_AT_bit_stride
:
8333 return "DW_AT_bit_stride";
8334 case DW_AT_upper_bound
:
8335 return "DW_AT_upper_bound";
8336 case DW_AT_abstract_origin
:
8337 return "DW_AT_abstract_origin";
8338 case DW_AT_accessibility
:
8339 return "DW_AT_accessibility";
8340 case DW_AT_address_class
:
8341 return "DW_AT_address_class";
8342 case DW_AT_artificial
:
8343 return "DW_AT_artificial";
8344 case DW_AT_base_types
:
8345 return "DW_AT_base_types";
8346 case DW_AT_calling_convention
:
8347 return "DW_AT_calling_convention";
8349 return "DW_AT_count";
8350 case DW_AT_data_member_location
:
8351 return "DW_AT_data_member_location";
8352 case DW_AT_decl_column
:
8353 return "DW_AT_decl_column";
8354 case DW_AT_decl_file
:
8355 return "DW_AT_decl_file";
8356 case DW_AT_decl_line
:
8357 return "DW_AT_decl_line";
8358 case DW_AT_declaration
:
8359 return "DW_AT_declaration";
8360 case DW_AT_discr_list
:
8361 return "DW_AT_discr_list";
8362 case DW_AT_encoding
:
8363 return "DW_AT_encoding";
8364 case DW_AT_external
:
8365 return "DW_AT_external";
8366 case DW_AT_frame_base
:
8367 return "DW_AT_frame_base";
8369 return "DW_AT_friend";
8370 case DW_AT_identifier_case
:
8371 return "DW_AT_identifier_case";
8372 case DW_AT_macro_info
:
8373 return "DW_AT_macro_info";
8374 case DW_AT_namelist_items
:
8375 return "DW_AT_namelist_items";
8376 case DW_AT_priority
:
8377 return "DW_AT_priority";
8379 return "DW_AT_segment";
8380 case DW_AT_specification
:
8381 return "DW_AT_specification";
8382 case DW_AT_static_link
:
8383 return "DW_AT_static_link";
8385 return "DW_AT_type";
8386 case DW_AT_use_location
:
8387 return "DW_AT_use_location";
8388 case DW_AT_variable_parameter
:
8389 return "DW_AT_variable_parameter";
8390 case DW_AT_virtuality
:
8391 return "DW_AT_virtuality";
8392 case DW_AT_vtable_elem_location
:
8393 return "DW_AT_vtable_elem_location";
8394 /* DWARF 3 values. */
8395 case DW_AT_allocated
:
8396 return "DW_AT_allocated";
8397 case DW_AT_associated
:
8398 return "DW_AT_associated";
8399 case DW_AT_data_location
:
8400 return "DW_AT_data_location";
8401 case DW_AT_byte_stride
:
8402 return "DW_AT_byte_stride";
8403 case DW_AT_entry_pc
:
8404 return "DW_AT_entry_pc";
8405 case DW_AT_use_UTF8
:
8406 return "DW_AT_use_UTF8";
8407 case DW_AT_extension
:
8408 return "DW_AT_extension";
8410 return "DW_AT_ranges";
8411 case DW_AT_trampoline
:
8412 return "DW_AT_trampoline";
8413 case DW_AT_call_column
:
8414 return "DW_AT_call_column";
8415 case DW_AT_call_file
:
8416 return "DW_AT_call_file";
8417 case DW_AT_call_line
:
8418 return "DW_AT_call_line";
8419 case DW_AT_description
:
8420 return "DW_AT_description";
8421 case DW_AT_binary_scale
:
8422 return "DW_AT_binary_scale";
8423 case DW_AT_decimal_scale
:
8424 return "DW_AT_decimal_scale";
8426 return "DW_AT_small";
8427 case DW_AT_decimal_sign
:
8428 return "DW_AT_decimal_sign";
8429 case DW_AT_digit_count
:
8430 return "DW_AT_digit_count";
8431 case DW_AT_picture_string
:
8432 return "DW_AT_picture_string";
8434 return "DW_AT_mutable";
8435 case DW_AT_threads_scaled
:
8436 return "DW_AT_threads_scaled";
8437 case DW_AT_explicit
:
8438 return "DW_AT_explicit";
8439 case DW_AT_object_pointer
:
8440 return "DW_AT_object_pointer";
8441 case DW_AT_endianity
:
8442 return "DW_AT_endianity";
8443 case DW_AT_elemental
:
8444 return "DW_AT_elemental";
8446 return "DW_AT_pure";
8447 case DW_AT_recursive
:
8448 return "DW_AT_recursive";
8450 /* SGI/MIPS extensions. */
8451 case DW_AT_MIPS_fde
:
8452 return "DW_AT_MIPS_fde";
8453 case DW_AT_MIPS_loop_begin
:
8454 return "DW_AT_MIPS_loop_begin";
8455 case DW_AT_MIPS_tail_loop_begin
:
8456 return "DW_AT_MIPS_tail_loop_begin";
8457 case DW_AT_MIPS_epilog_begin
:
8458 return "DW_AT_MIPS_epilog_begin";
8459 case DW_AT_MIPS_loop_unroll_factor
:
8460 return "DW_AT_MIPS_loop_unroll_factor";
8461 case DW_AT_MIPS_software_pipeline_depth
:
8462 return "DW_AT_MIPS_software_pipeline_depth";
8463 case DW_AT_MIPS_linkage_name
:
8464 return "DW_AT_MIPS_linkage_name";
8465 case DW_AT_MIPS_stride
:
8466 return "DW_AT_MIPS_stride";
8467 case DW_AT_MIPS_abstract_name
:
8468 return "DW_AT_MIPS_abstract_name";
8469 case DW_AT_MIPS_clone_origin
:
8470 return "DW_AT_MIPS_clone_origin";
8471 case DW_AT_MIPS_has_inlines
:
8472 return "DW_AT_MIPS_has_inlines";
8474 /* HP extensions. */
8475 case DW_AT_HP_block_index
:
8476 return "DW_AT_HP_block_index";
8477 case DW_AT_HP_unmodifiable
:
8478 return "DW_AT_HP_unmodifiable";
8479 case DW_AT_HP_actuals_stmt_list
:
8480 return "DW_AT_HP_actuals_stmt_list";
8481 case DW_AT_HP_proc_per_section
:
8482 return "DW_AT_HP_proc_per_section";
8483 case DW_AT_HP_raw_data_ptr
:
8484 return "DW_AT_HP_raw_data_ptr";
8485 case DW_AT_HP_pass_by_reference
:
8486 return "DW_AT_HP_pass_by_reference";
8487 case DW_AT_HP_opt_level
:
8488 return "DW_AT_HP_opt_level";
8489 case DW_AT_HP_prof_version_id
:
8490 return "DW_AT_HP_prof_version_id";
8491 case DW_AT_HP_opt_flags
:
8492 return "DW_AT_HP_opt_flags";
8493 case DW_AT_HP_cold_region_low_pc
:
8494 return "DW_AT_HP_cold_region_low_pc";
8495 case DW_AT_HP_cold_region_high_pc
:
8496 return "DW_AT_HP_cold_region_high_pc";
8497 case DW_AT_HP_all_variables_modifiable
:
8498 return "DW_AT_HP_all_variables_modifiable";
8499 case DW_AT_HP_linkage_name
:
8500 return "DW_AT_HP_linkage_name";
8501 case DW_AT_HP_prof_flags
:
8502 return "DW_AT_HP_prof_flags";
8503 /* GNU extensions. */
8504 case DW_AT_sf_names
:
8505 return "DW_AT_sf_names";
8506 case DW_AT_src_info
:
8507 return "DW_AT_src_info";
8508 case DW_AT_mac_info
:
8509 return "DW_AT_mac_info";
8510 case DW_AT_src_coords
:
8511 return "DW_AT_src_coords";
8512 case DW_AT_body_begin
:
8513 return "DW_AT_body_begin";
8514 case DW_AT_body_end
:
8515 return "DW_AT_body_end";
8516 case DW_AT_GNU_vector
:
8517 return "DW_AT_GNU_vector";
8518 /* VMS extensions. */
8519 case DW_AT_VMS_rtnbeg_pd_address
:
8520 return "DW_AT_VMS_rtnbeg_pd_address";
8521 /* UPC extension. */
8522 case DW_AT_upc_threads_scaled
:
8523 return "DW_AT_upc_threads_scaled";
8524 /* PGI (STMicroelectronics) extensions. */
8525 case DW_AT_PGI_lbase
:
8526 return "DW_AT_PGI_lbase";
8527 case DW_AT_PGI_soffset
:
8528 return "DW_AT_PGI_soffset";
8529 case DW_AT_PGI_lstride
:
8530 return "DW_AT_PGI_lstride";
8532 return "DW_AT_<unknown>";
8536 /* Convert a DWARF value form code into its string name. */
8539 dwarf_form_name (unsigned form
)
8544 return "DW_FORM_addr";
8545 case DW_FORM_block2
:
8546 return "DW_FORM_block2";
8547 case DW_FORM_block4
:
8548 return "DW_FORM_block4";
8550 return "DW_FORM_data2";
8552 return "DW_FORM_data4";
8554 return "DW_FORM_data8";
8555 case DW_FORM_string
:
8556 return "DW_FORM_string";
8558 return "DW_FORM_block";
8559 case DW_FORM_block1
:
8560 return "DW_FORM_block1";
8562 return "DW_FORM_data1";
8564 return "DW_FORM_flag";
8566 return "DW_FORM_sdata";
8568 return "DW_FORM_strp";
8570 return "DW_FORM_udata";
8571 case DW_FORM_ref_addr
:
8572 return "DW_FORM_ref_addr";
8574 return "DW_FORM_ref1";
8576 return "DW_FORM_ref2";
8578 return "DW_FORM_ref4";
8580 return "DW_FORM_ref8";
8581 case DW_FORM_ref_udata
:
8582 return "DW_FORM_ref_udata";
8583 case DW_FORM_indirect
:
8584 return "DW_FORM_indirect";
8586 return "DW_FORM_<unknown>";
8590 /* Convert a DWARF stack opcode into its string name. */
8593 dwarf_stack_op_name (unsigned op
)
8598 return "DW_OP_addr";
8600 return "DW_OP_deref";
8602 return "DW_OP_const1u";
8604 return "DW_OP_const1s";
8606 return "DW_OP_const2u";
8608 return "DW_OP_const2s";
8610 return "DW_OP_const4u";
8612 return "DW_OP_const4s";
8614 return "DW_OP_const8u";
8616 return "DW_OP_const8s";
8618 return "DW_OP_constu";
8620 return "DW_OP_consts";
8624 return "DW_OP_drop";
8626 return "DW_OP_over";
8628 return "DW_OP_pick";
8630 return "DW_OP_swap";
8634 return "DW_OP_xderef";
8642 return "DW_OP_minus";
8654 return "DW_OP_plus";
8655 case DW_OP_plus_uconst
:
8656 return "DW_OP_plus_uconst";
8662 return "DW_OP_shra";
8680 return "DW_OP_skip";
8682 return "DW_OP_lit0";
8684 return "DW_OP_lit1";
8686 return "DW_OP_lit2";
8688 return "DW_OP_lit3";
8690 return "DW_OP_lit4";
8692 return "DW_OP_lit5";
8694 return "DW_OP_lit6";
8696 return "DW_OP_lit7";
8698 return "DW_OP_lit8";
8700 return "DW_OP_lit9";
8702 return "DW_OP_lit10";
8704 return "DW_OP_lit11";
8706 return "DW_OP_lit12";
8708 return "DW_OP_lit13";
8710 return "DW_OP_lit14";
8712 return "DW_OP_lit15";
8714 return "DW_OP_lit16";
8716 return "DW_OP_lit17";
8718 return "DW_OP_lit18";
8720 return "DW_OP_lit19";
8722 return "DW_OP_lit20";
8724 return "DW_OP_lit21";
8726 return "DW_OP_lit22";
8728 return "DW_OP_lit23";
8730 return "DW_OP_lit24";
8732 return "DW_OP_lit25";
8734 return "DW_OP_lit26";
8736 return "DW_OP_lit27";
8738 return "DW_OP_lit28";
8740 return "DW_OP_lit29";
8742 return "DW_OP_lit30";
8744 return "DW_OP_lit31";
8746 return "DW_OP_reg0";
8748 return "DW_OP_reg1";
8750 return "DW_OP_reg2";
8752 return "DW_OP_reg3";
8754 return "DW_OP_reg4";
8756 return "DW_OP_reg5";
8758 return "DW_OP_reg6";
8760 return "DW_OP_reg7";
8762 return "DW_OP_reg8";
8764 return "DW_OP_reg9";
8766 return "DW_OP_reg10";
8768 return "DW_OP_reg11";
8770 return "DW_OP_reg12";
8772 return "DW_OP_reg13";
8774 return "DW_OP_reg14";
8776 return "DW_OP_reg15";
8778 return "DW_OP_reg16";
8780 return "DW_OP_reg17";
8782 return "DW_OP_reg18";
8784 return "DW_OP_reg19";
8786 return "DW_OP_reg20";
8788 return "DW_OP_reg21";
8790 return "DW_OP_reg22";
8792 return "DW_OP_reg23";
8794 return "DW_OP_reg24";
8796 return "DW_OP_reg25";
8798 return "DW_OP_reg26";
8800 return "DW_OP_reg27";
8802 return "DW_OP_reg28";
8804 return "DW_OP_reg29";
8806 return "DW_OP_reg30";
8808 return "DW_OP_reg31";
8810 return "DW_OP_breg0";
8812 return "DW_OP_breg1";
8814 return "DW_OP_breg2";
8816 return "DW_OP_breg3";
8818 return "DW_OP_breg4";
8820 return "DW_OP_breg5";
8822 return "DW_OP_breg6";
8824 return "DW_OP_breg7";
8826 return "DW_OP_breg8";
8828 return "DW_OP_breg9";
8830 return "DW_OP_breg10";
8832 return "DW_OP_breg11";
8834 return "DW_OP_breg12";
8836 return "DW_OP_breg13";
8838 return "DW_OP_breg14";
8840 return "DW_OP_breg15";
8842 return "DW_OP_breg16";
8844 return "DW_OP_breg17";
8846 return "DW_OP_breg18";
8848 return "DW_OP_breg19";
8850 return "DW_OP_breg20";
8852 return "DW_OP_breg21";
8854 return "DW_OP_breg22";
8856 return "DW_OP_breg23";
8858 return "DW_OP_breg24";
8860 return "DW_OP_breg25";
8862 return "DW_OP_breg26";
8864 return "DW_OP_breg27";
8866 return "DW_OP_breg28";
8868 return "DW_OP_breg29";
8870 return "DW_OP_breg30";
8872 return "DW_OP_breg31";
8874 return "DW_OP_regx";
8876 return "DW_OP_fbreg";
8878 return "DW_OP_bregx";
8880 return "DW_OP_piece";
8881 case DW_OP_deref_size
:
8882 return "DW_OP_deref_size";
8883 case DW_OP_xderef_size
:
8884 return "DW_OP_xderef_size";
8887 /* DWARF 3 extensions. */
8888 case DW_OP_push_object_address
:
8889 return "DW_OP_push_object_address";
8891 return "DW_OP_call2";
8893 return "DW_OP_call4";
8894 case DW_OP_call_ref
:
8895 return "DW_OP_call_ref";
8896 /* GNU extensions. */
8897 case DW_OP_form_tls_address
:
8898 return "DW_OP_form_tls_address";
8899 case DW_OP_call_frame_cfa
:
8900 return "DW_OP_call_frame_cfa";
8901 case DW_OP_bit_piece
:
8902 return "DW_OP_bit_piece";
8903 case DW_OP_GNU_push_tls_address
:
8904 return "DW_OP_GNU_push_tls_address";
8905 case DW_OP_GNU_uninit
:
8906 return "DW_OP_GNU_uninit";
8907 /* HP extensions. */
8908 case DW_OP_HP_is_value
:
8909 return "DW_OP_HP_is_value";
8910 case DW_OP_HP_fltconst4
:
8911 return "DW_OP_HP_fltconst4";
8912 case DW_OP_HP_fltconst8
:
8913 return "DW_OP_HP_fltconst8";
8914 case DW_OP_HP_mod_range
:
8915 return "DW_OP_HP_mod_range";
8916 case DW_OP_HP_unmod_range
:
8917 return "DW_OP_HP_unmod_range";
8919 return "DW_OP_HP_tls";
8921 return "OP_<unknown>";
8926 dwarf_bool_name (unsigned mybool
)
8934 /* Convert a DWARF type code into its string name. */
8937 dwarf_type_encoding_name (unsigned enc
)
8942 return "DW_ATE_void";
8943 case DW_ATE_address
:
8944 return "DW_ATE_address";
8945 case DW_ATE_boolean
:
8946 return "DW_ATE_boolean";
8947 case DW_ATE_complex_float
:
8948 return "DW_ATE_complex_float";
8950 return "DW_ATE_float";
8952 return "DW_ATE_signed";
8953 case DW_ATE_signed_char
:
8954 return "DW_ATE_signed_char";
8955 case DW_ATE_unsigned
:
8956 return "DW_ATE_unsigned";
8957 case DW_ATE_unsigned_char
:
8958 return "DW_ATE_unsigned_char";
8960 case DW_ATE_imaginary_float
:
8961 return "DW_ATE_imaginary_float";
8962 case DW_ATE_packed_decimal
:
8963 return "DW_ATE_packed_decimal";
8964 case DW_ATE_numeric_string
:
8965 return "DW_ATE_numeric_string";
8967 return "DW_ATE_edited";
8968 case DW_ATE_signed_fixed
:
8969 return "DW_ATE_signed_fixed";
8970 case DW_ATE_unsigned_fixed
:
8971 return "DW_ATE_unsigned_fixed";
8972 case DW_ATE_decimal_float
:
8973 return "DW_ATE_decimal_float";
8974 /* HP extensions. */
8975 case DW_ATE_HP_float80
:
8976 return "DW_ATE_HP_float80";
8977 case DW_ATE_HP_complex_float80
:
8978 return "DW_ATE_HP_complex_float80";
8979 case DW_ATE_HP_float128
:
8980 return "DW_ATE_HP_float128";
8981 case DW_ATE_HP_complex_float128
:
8982 return "DW_ATE_HP_complex_float128";
8983 case DW_ATE_HP_floathpintel
:
8984 return "DW_ATE_HP_floathpintel";
8985 case DW_ATE_HP_imaginary_float80
:
8986 return "DW_ATE_HP_imaginary_float80";
8987 case DW_ATE_HP_imaginary_float128
:
8988 return "DW_ATE_HP_imaginary_float128";
8990 return "DW_ATE_<unknown>";
8994 /* Convert a DWARF call frame info operation to its string name. */
8998 dwarf_cfi_name (unsigned cfi_opc
)
9002 case DW_CFA_advance_loc
:
9003 return "DW_CFA_advance_loc";
9005 return "DW_CFA_offset";
9006 case DW_CFA_restore
:
9007 return "DW_CFA_restore";
9009 return "DW_CFA_nop";
9010 case DW_CFA_set_loc
:
9011 return "DW_CFA_set_loc";
9012 case DW_CFA_advance_loc1
:
9013 return "DW_CFA_advance_loc1";
9014 case DW_CFA_advance_loc2
:
9015 return "DW_CFA_advance_loc2";
9016 case DW_CFA_advance_loc4
:
9017 return "DW_CFA_advance_loc4";
9018 case DW_CFA_offset_extended
:
9019 return "DW_CFA_offset_extended";
9020 case DW_CFA_restore_extended
:
9021 return "DW_CFA_restore_extended";
9022 case DW_CFA_undefined
:
9023 return "DW_CFA_undefined";
9024 case DW_CFA_same_value
:
9025 return "DW_CFA_same_value";
9026 case DW_CFA_register
:
9027 return "DW_CFA_register";
9028 case DW_CFA_remember_state
:
9029 return "DW_CFA_remember_state";
9030 case DW_CFA_restore_state
:
9031 return "DW_CFA_restore_state";
9032 case DW_CFA_def_cfa
:
9033 return "DW_CFA_def_cfa";
9034 case DW_CFA_def_cfa_register
:
9035 return "DW_CFA_def_cfa_register";
9036 case DW_CFA_def_cfa_offset
:
9037 return "DW_CFA_def_cfa_offset";
9039 case DW_CFA_def_cfa_expression
:
9040 return "DW_CFA_def_cfa_expression";
9041 case DW_CFA_expression
:
9042 return "DW_CFA_expression";
9043 case DW_CFA_offset_extended_sf
:
9044 return "DW_CFA_offset_extended_sf";
9045 case DW_CFA_def_cfa_sf
:
9046 return "DW_CFA_def_cfa_sf";
9047 case DW_CFA_def_cfa_offset_sf
:
9048 return "DW_CFA_def_cfa_offset_sf";
9049 case DW_CFA_val_offset
:
9050 return "DW_CFA_val_offset";
9051 case DW_CFA_val_offset_sf
:
9052 return "DW_CFA_val_offset_sf";
9053 case DW_CFA_val_expression
:
9054 return "DW_CFA_val_expression";
9055 /* SGI/MIPS specific. */
9056 case DW_CFA_MIPS_advance_loc8
:
9057 return "DW_CFA_MIPS_advance_loc8";
9058 /* GNU extensions. */
9059 case DW_CFA_GNU_window_save
:
9060 return "DW_CFA_GNU_window_save";
9061 case DW_CFA_GNU_args_size
:
9062 return "DW_CFA_GNU_args_size";
9063 case DW_CFA_GNU_negative_offset_extended
:
9064 return "DW_CFA_GNU_negative_offset_extended";
9066 return "DW_CFA_<unknown>";
9072 dump_die (struct die_info
*die
)
9076 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9077 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9078 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9079 dwarf_bool_name (die
->child
!= NULL
));
9081 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9082 for (i
= 0; i
< die
->num_attrs
; ++i
)
9084 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9085 dwarf_attr_name (die
->attrs
[i
].name
),
9086 dwarf_form_name (die
->attrs
[i
].form
));
9087 switch (die
->attrs
[i
].form
)
9089 case DW_FORM_ref_addr
:
9091 fprintf_unfiltered (gdb_stderr
, "address: ");
9092 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9094 case DW_FORM_block2
:
9095 case DW_FORM_block4
:
9097 case DW_FORM_block1
:
9098 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9103 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9104 (long) (DW_ADDR (&die
->attrs
[i
])));
9112 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9114 case DW_FORM_string
:
9116 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9117 DW_STRING (&die
->attrs
[i
])
9118 ? DW_STRING (&die
->attrs
[i
]) : "");
9121 if (DW_UNSND (&die
->attrs
[i
]))
9122 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9124 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9126 case DW_FORM_indirect
:
9127 /* the reader will have reduced the indirect form to
9128 the "base form" so this form should not occur */
9129 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9132 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9133 die
->attrs
[i
].form
);
9135 fprintf_unfiltered (gdb_stderr
, "\n");
9140 dump_die_list (struct die_info
*die
)
9145 if (die
->child
!= NULL
)
9146 dump_die_list (die
->child
);
9147 if (die
->sibling
!= NULL
)
9148 dump_die_list (die
->sibling
);
9153 store_in_ref_table (unsigned int offset
, struct die_info
*die
,
9154 struct dwarf2_cu
*cu
)
9157 struct die_info
*old
;
9159 h
= (offset
% REF_HASH_SIZE
);
9160 old
= cu
->die_ref_table
[h
];
9161 die
->next_ref
= old
;
9162 cu
->die_ref_table
[h
] = die
;
9166 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9168 unsigned int result
= 0;
9172 case DW_FORM_ref_addr
:
9177 case DW_FORM_ref_udata
:
9178 result
= DW_ADDR (attr
);
9181 complaint (&symfile_complaints
,
9182 _("unsupported die ref attribute form: '%s'"),
9183 dwarf_form_name (attr
->form
));
9188 /* Return the constant value held by the given attribute. Return -1
9189 if the value held by the attribute is not constant. */
9192 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9194 if (attr
->form
== DW_FORM_sdata
)
9195 return DW_SND (attr
);
9196 else if (attr
->form
== DW_FORM_udata
9197 || attr
->form
== DW_FORM_data1
9198 || attr
->form
== DW_FORM_data2
9199 || attr
->form
== DW_FORM_data4
9200 || attr
->form
== DW_FORM_data8
)
9201 return DW_UNSND (attr
);
9204 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9205 dwarf_form_name (attr
->form
));
9206 return default_value
;
9210 static struct die_info
*
9211 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9212 struct dwarf2_cu
*cu
)
9214 struct die_info
*die
;
9215 unsigned int offset
;
9217 struct die_info temp_die
;
9218 struct dwarf2_cu
*target_cu
;
9220 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9222 if (DW_ADDR (attr
) < cu
->header
.offset
9223 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9225 struct dwarf2_per_cu_data
*per_cu
;
9226 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9228 target_cu
= per_cu
->cu
;
9233 h
= (offset
% REF_HASH_SIZE
);
9234 die
= target_cu
->die_ref_table
[h
];
9237 if (die
->offset
== offset
)
9239 die
= die
->next_ref
;
9242 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9243 "at 0x%lx [in module %s]"),
9244 (long) src_die
->offset
, (long) offset
, cu
->objfile
->name
);
9249 /* Decode simple location descriptions.
9250 Given a pointer to a dwarf block that defines a location, compute
9251 the location and return the value.
9253 NOTE drow/2003-11-18: This function is called in two situations
9254 now: for the address of static or global variables (partial symbols
9255 only) and for offsets into structures which are expected to be
9256 (more or less) constant. The partial symbol case should go away,
9257 and only the constant case should remain. That will let this
9258 function complain more accurately. A few special modes are allowed
9259 without complaint for global variables (for instance, global
9260 register values and thread-local values).
9262 A location description containing no operations indicates that the
9263 object is optimized out. The return value is 0 for that case.
9264 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9265 callers will only want a very basic result and this can become a
9268 Note that stack[0] is unused except as a default error return.
9269 Note that stack overflow is not yet handled. */
9272 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9274 struct objfile
*objfile
= cu
->objfile
;
9275 struct comp_unit_head
*cu_header
= &cu
->header
;
9277 int size
= blk
->size
;
9278 gdb_byte
*data
= blk
->data
;
9279 CORE_ADDR stack
[64];
9281 unsigned int bytes_read
, unsnd
;
9325 stack
[++stacki
] = op
- DW_OP_lit0
;
9360 stack
[++stacki
] = op
- DW_OP_reg0
;
9362 dwarf2_complex_location_expr_complaint ();
9366 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9368 stack
[++stacki
] = unsnd
;
9370 dwarf2_complex_location_expr_complaint ();
9374 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9380 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9385 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9390 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9395 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9400 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9405 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9410 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9416 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9421 stack
[stacki
+ 1] = stack
[stacki
];
9426 stack
[stacki
- 1] += stack
[stacki
];
9430 case DW_OP_plus_uconst
:
9431 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9436 stack
[stacki
- 1] -= stack
[stacki
];
9441 /* If we're not the last op, then we definitely can't encode
9442 this using GDB's address_class enum. This is valid for partial
9443 global symbols, although the variable's address will be bogus
9446 dwarf2_complex_location_expr_complaint ();
9449 case DW_OP_GNU_push_tls_address
:
9450 /* The top of the stack has the offset from the beginning
9451 of the thread control block at which the variable is located. */
9452 /* Nothing should follow this operator, so the top of stack would
9454 /* This is valid for partial global symbols, but the variable's
9455 address will be bogus in the psymtab. */
9457 dwarf2_complex_location_expr_complaint ();
9460 case DW_OP_GNU_uninit
:
9464 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9465 dwarf_stack_op_name (op
));
9466 return (stack
[stacki
]);
9469 return (stack
[stacki
]);
9472 /* memory allocation interface */
9474 static struct dwarf_block
*
9475 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9477 struct dwarf_block
*blk
;
9479 blk
= (struct dwarf_block
*)
9480 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9484 static struct abbrev_info
*
9485 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9487 struct abbrev_info
*abbrev
;
9489 abbrev
= (struct abbrev_info
*)
9490 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9491 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9495 static struct die_info
*
9496 dwarf_alloc_die (void)
9498 struct die_info
*die
;
9500 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
9501 memset (die
, 0, sizeof (struct die_info
));
9506 /* Macro support. */
9509 /* Return the full name of file number I in *LH's file name table.
9510 Use COMP_DIR as the name of the current directory of the
9511 compilation. The result is allocated using xmalloc; the caller is
9512 responsible for freeing it. */
9514 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9516 /* Is the file number a valid index into the line header's file name
9517 table? Remember that file numbers start with one, not zero. */
9518 if (1 <= file
&& file
<= lh
->num_file_names
)
9520 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9522 if (IS_ABSOLUTE_PATH (fe
->name
))
9523 return xstrdup (fe
->name
);
9531 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9537 dir_len
= strlen (dir
);
9538 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9539 strcpy (full_name
, dir
);
9540 full_name
[dir_len
] = '/';
9541 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9545 return xstrdup (fe
->name
);
9550 /* The compiler produced a bogus file number. We can at least
9551 record the macro definitions made in the file, even if we
9552 won't be able to find the file by name. */
9554 sprintf (fake_name
, "<bad macro file number %d>", file
);
9556 complaint (&symfile_complaints
,
9557 _("bad file number in macro information (%d)"),
9560 return xstrdup (fake_name
);
9565 static struct macro_source_file
*
9566 macro_start_file (int file
, int line
,
9567 struct macro_source_file
*current_file
,
9568 const char *comp_dir
,
9569 struct line_header
*lh
, struct objfile
*objfile
)
9571 /* The full name of this source file. */
9572 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9574 /* We don't create a macro table for this compilation unit
9575 at all until we actually get a filename. */
9576 if (! pending_macros
)
9577 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9578 objfile
->macro_cache
);
9581 /* If we have no current file, then this must be the start_file
9582 directive for the compilation unit's main source file. */
9583 current_file
= macro_set_main (pending_macros
, full_name
);
9585 current_file
= macro_include (current_file
, line
, full_name
);
9589 return current_file
;
9593 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9594 followed by a null byte. */
9596 copy_string (const char *buf
, int len
)
9598 char *s
= xmalloc (len
+ 1);
9599 memcpy (s
, buf
, len
);
9607 consume_improper_spaces (const char *p
, const char *body
)
9611 complaint (&symfile_complaints
,
9612 _("macro definition contains spaces in formal argument list:\n`%s'"),
9624 parse_macro_definition (struct macro_source_file
*file
, int line
,
9629 /* The body string takes one of two forms. For object-like macro
9630 definitions, it should be:
9632 <macro name> " " <definition>
9634 For function-like macro definitions, it should be:
9636 <macro name> "() " <definition>
9638 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9640 Spaces may appear only where explicitly indicated, and in the
9643 The Dwarf 2 spec says that an object-like macro's name is always
9644 followed by a space, but versions of GCC around March 2002 omit
9645 the space when the macro's definition is the empty string.
9647 The Dwarf 2 spec says that there should be no spaces between the
9648 formal arguments in a function-like macro's formal argument list,
9649 but versions of GCC around March 2002 include spaces after the
9653 /* Find the extent of the macro name. The macro name is terminated
9654 by either a space or null character (for an object-like macro) or
9655 an opening paren (for a function-like macro). */
9656 for (p
= body
; *p
; p
++)
9657 if (*p
== ' ' || *p
== '(')
9660 if (*p
== ' ' || *p
== '\0')
9662 /* It's an object-like macro. */
9663 int name_len
= p
- body
;
9664 char *name
= copy_string (body
, name_len
);
9665 const char *replacement
;
9668 replacement
= body
+ name_len
+ 1;
9671 dwarf2_macro_malformed_definition_complaint (body
);
9672 replacement
= body
+ name_len
;
9675 macro_define_object (file
, line
, name
, replacement
);
9681 /* It's a function-like macro. */
9682 char *name
= copy_string (body
, p
- body
);
9685 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9689 p
= consume_improper_spaces (p
, body
);
9691 /* Parse the formal argument list. */
9692 while (*p
&& *p
!= ')')
9694 /* Find the extent of the current argument name. */
9695 const char *arg_start
= p
;
9697 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9700 if (! *p
|| p
== arg_start
)
9701 dwarf2_macro_malformed_definition_complaint (body
);
9704 /* Make sure argv has room for the new argument. */
9705 if (argc
>= argv_size
)
9708 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9711 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9714 p
= consume_improper_spaces (p
, body
);
9716 /* Consume the comma, if present. */
9721 p
= consume_improper_spaces (p
, body
);
9730 /* Perfectly formed definition, no complaints. */
9731 macro_define_function (file
, line
, name
,
9732 argc
, (const char **) argv
,
9734 else if (*p
== '\0')
9736 /* Complain, but do define it. */
9737 dwarf2_macro_malformed_definition_complaint (body
);
9738 macro_define_function (file
, line
, name
,
9739 argc
, (const char **) argv
,
9743 /* Just complain. */
9744 dwarf2_macro_malformed_definition_complaint (body
);
9747 /* Just complain. */
9748 dwarf2_macro_malformed_definition_complaint (body
);
9754 for (i
= 0; i
< argc
; i
++)
9760 dwarf2_macro_malformed_definition_complaint (body
);
9765 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9766 char *comp_dir
, bfd
*abfd
,
9767 struct dwarf2_cu
*cu
)
9769 gdb_byte
*mac_ptr
, *mac_end
;
9770 struct macro_source_file
*current_file
= 0;
9772 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9774 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9778 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9779 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9780 + dwarf2_per_objfile
->macinfo_size
;
9784 enum dwarf_macinfo_record_type macinfo_type
;
9786 /* Do we at least have room for a macinfo type byte? */
9787 if (mac_ptr
>= mac_end
)
9789 dwarf2_macros_too_long_complaint ();
9793 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9796 switch (macinfo_type
)
9798 /* A zero macinfo type indicates the end of the macro
9803 case DW_MACINFO_define
:
9804 case DW_MACINFO_undef
:
9806 unsigned int bytes_read
;
9810 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9811 mac_ptr
+= bytes_read
;
9812 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9813 mac_ptr
+= bytes_read
;
9816 complaint (&symfile_complaints
,
9817 _("debug info gives macro %s outside of any file: %s"),
9819 DW_MACINFO_define
? "definition" : macinfo_type
==
9820 DW_MACINFO_undef
? "undefinition" :
9821 "something-or-other", body
);
9824 if (macinfo_type
== DW_MACINFO_define
)
9825 parse_macro_definition (current_file
, line
, body
);
9826 else if (macinfo_type
== DW_MACINFO_undef
)
9827 macro_undef (current_file
, line
, body
);
9832 case DW_MACINFO_start_file
:
9834 unsigned int bytes_read
;
9837 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9838 mac_ptr
+= bytes_read
;
9839 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9840 mac_ptr
+= bytes_read
;
9842 current_file
= macro_start_file (file
, line
,
9843 current_file
, comp_dir
,
9848 case DW_MACINFO_end_file
:
9850 complaint (&symfile_complaints
,
9851 _("macro debug info has an unmatched `close_file' directive"));
9854 current_file
= current_file
->included_by
;
9857 enum dwarf_macinfo_record_type next_type
;
9859 /* GCC circa March 2002 doesn't produce the zero
9860 type byte marking the end of the compilation
9861 unit. Complain if it's not there, but exit no
9864 /* Do we at least have room for a macinfo type byte? */
9865 if (mac_ptr
>= mac_end
)
9867 dwarf2_macros_too_long_complaint ();
9871 /* We don't increment mac_ptr here, so this is just
9873 next_type
= read_1_byte (abfd
, mac_ptr
);
9875 complaint (&symfile_complaints
,
9876 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9883 case DW_MACINFO_vendor_ext
:
9885 unsigned int bytes_read
;
9889 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9890 mac_ptr
+= bytes_read
;
9891 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9892 mac_ptr
+= bytes_read
;
9894 /* We don't recognize any vendor extensions. */
9901 /* Check if the attribute's form is a DW_FORM_block*
9902 if so return true else false. */
9904 attr_form_is_block (struct attribute
*attr
)
9906 return (attr
== NULL
? 0 :
9907 attr
->form
== DW_FORM_block1
9908 || attr
->form
== DW_FORM_block2
9909 || attr
->form
== DW_FORM_block4
9910 || attr
->form
== DW_FORM_block
);
9913 /* Return non-zero if ATTR's value is a section offset --- classes
9914 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9915 You may use DW_UNSND (attr) to retrieve such offsets.
9917 Section 7.5.4, "Attribute Encodings", explains that no attribute
9918 may have a value that belongs to more than one of these classes; it
9919 would be ambiguous if we did, because we use the same forms for all
9922 attr_form_is_section_offset (struct attribute
*attr
)
9924 return (attr
->form
== DW_FORM_data4
9925 || attr
->form
== DW_FORM_data8
);
9929 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9930 zero otherwise. When this function returns true, you can apply
9931 dwarf2_get_attr_constant_value to it.
9933 However, note that for some attributes you must check
9934 attr_form_is_section_offset before using this test. DW_FORM_data4
9935 and DW_FORM_data8 are members of both the constant class, and of
9936 the classes that contain offsets into other debug sections
9937 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9938 that, if an attribute's can be either a constant or one of the
9939 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9940 taken as section offsets, not constants. */
9942 attr_form_is_constant (struct attribute
*attr
)
9959 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9960 struct dwarf2_cu
*cu
)
9962 if (attr_form_is_section_offset (attr
)
9963 /* ".debug_loc" may not exist at all, or the offset may be outside
9964 the section. If so, fall through to the complaint in the
9966 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9968 struct dwarf2_loclist_baton
*baton
;
9970 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9971 sizeof (struct dwarf2_loclist_baton
));
9972 baton
->per_cu
= cu
->per_cu
;
9973 gdb_assert (baton
->per_cu
);
9975 /* We don't know how long the location list is, but make sure we
9976 don't run off the edge of the section. */
9977 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9978 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9979 baton
->base_address
= cu
->header
.base_address
;
9980 if (cu
->header
.base_known
== 0)
9981 complaint (&symfile_complaints
,
9982 _("Location list used without specifying the CU base address."));
9984 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9985 SYMBOL_LOCATION_BATON (sym
) = baton
;
9989 struct dwarf2_locexpr_baton
*baton
;
9991 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9992 sizeof (struct dwarf2_locexpr_baton
));
9993 baton
->per_cu
= cu
->per_cu
;
9994 gdb_assert (baton
->per_cu
);
9996 if (attr_form_is_block (attr
))
9998 /* Note that we're just copying the block's data pointer
9999 here, not the actual data. We're still pointing into the
10000 info_buffer for SYM's objfile; right now we never release
10001 that buffer, but when we do clean up properly this may
10003 baton
->size
= DW_BLOCK (attr
)->size
;
10004 baton
->data
= DW_BLOCK (attr
)->data
;
10008 dwarf2_invalid_attrib_class_complaint ("location description",
10009 SYMBOL_NATURAL_NAME (sym
));
10011 baton
->data
= NULL
;
10014 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10015 SYMBOL_LOCATION_BATON (sym
) = baton
;
10019 /* Return the OBJFILE associated with the compilation unit CU. */
10022 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10024 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10026 /* Return the master objfile, so that we can report and look up the
10027 correct file containing this variable. */
10028 if (objfile
->separate_debug_objfile_backlink
)
10029 objfile
= objfile
->separate_debug_objfile_backlink
;
10034 /* Return the address size given in the compilation unit header for CU. */
10037 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10040 return per_cu
->cu
->header
.addr_size
;
10043 /* If the CU is not currently read in, we re-read its header. */
10044 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10045 struct dwarf2_per_objfile
*per_objfile
10046 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10047 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10049 struct comp_unit_head cu_header
;
10050 memset (&cu_header
, 0, sizeof cu_header
);
10051 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10052 return cu_header
.addr_size
;
10056 /* Locate the compilation unit from CU's objfile which contains the
10057 DIE at OFFSET. Raises an error on failure. */
10059 static struct dwarf2_per_cu_data
*
10060 dwarf2_find_containing_comp_unit (unsigned long offset
,
10061 struct objfile
*objfile
)
10063 struct dwarf2_per_cu_data
*this_cu
;
10067 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10070 int mid
= low
+ (high
- low
) / 2;
10071 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10076 gdb_assert (low
== high
);
10077 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10080 error (_("Dwarf Error: could not find partial DIE containing "
10081 "offset 0x%lx [in module %s]"),
10082 (long) offset
, bfd_get_filename (objfile
->obfd
));
10084 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10085 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10089 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10090 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10091 && offset
>= this_cu
->offset
+ this_cu
->length
)
10092 error (_("invalid dwarf2 offset %ld"), offset
);
10093 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10098 /* Locate the compilation unit from OBJFILE which is located at exactly
10099 OFFSET. Raises an error on failure. */
10101 static struct dwarf2_per_cu_data
*
10102 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10104 struct dwarf2_per_cu_data
*this_cu
;
10105 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10106 if (this_cu
->offset
!= offset
)
10107 error (_("no compilation unit with offset %ld."), offset
);
10111 /* Release one cached compilation unit, CU. We unlink it from the tree
10112 of compilation units, but we don't remove it from the read_in_chain;
10113 the caller is responsible for that. */
10116 free_one_comp_unit (void *data
)
10118 struct dwarf2_cu
*cu
= data
;
10120 if (cu
->per_cu
!= NULL
)
10121 cu
->per_cu
->cu
= NULL
;
10124 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10126 free_die_list (cu
->dies
);
10131 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10132 when we're finished with it. We can't free the pointer itself, but be
10133 sure to unlink it from the cache. Also release any associated storage
10134 and perform cache maintenance.
10136 Only used during partial symbol parsing. */
10139 free_stack_comp_unit (void *data
)
10141 struct dwarf2_cu
*cu
= data
;
10143 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10144 cu
->partial_dies
= NULL
;
10146 if (cu
->per_cu
!= NULL
)
10148 /* This compilation unit is on the stack in our caller, so we
10149 should not xfree it. Just unlink it. */
10150 cu
->per_cu
->cu
= NULL
;
10153 /* If we had a per-cu pointer, then we may have other compilation
10154 units loaded, so age them now. */
10155 age_cached_comp_units ();
10159 /* Free all cached compilation units. */
10162 free_cached_comp_units (void *data
)
10164 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10166 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10167 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10168 while (per_cu
!= NULL
)
10170 struct dwarf2_per_cu_data
*next_cu
;
10172 next_cu
= per_cu
->cu
->read_in_chain
;
10174 free_one_comp_unit (per_cu
->cu
);
10175 *last_chain
= next_cu
;
10181 /* Increase the age counter on each cached compilation unit, and free
10182 any that are too old. */
10185 age_cached_comp_units (void)
10187 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10189 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10190 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10191 while (per_cu
!= NULL
)
10193 per_cu
->cu
->last_used
++;
10194 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10195 dwarf2_mark (per_cu
->cu
);
10196 per_cu
= per_cu
->cu
->read_in_chain
;
10199 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10200 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10201 while (per_cu
!= NULL
)
10203 struct dwarf2_per_cu_data
*next_cu
;
10205 next_cu
= per_cu
->cu
->read_in_chain
;
10207 if (!per_cu
->cu
->mark
)
10209 free_one_comp_unit (per_cu
->cu
);
10210 *last_chain
= next_cu
;
10213 last_chain
= &per_cu
->cu
->read_in_chain
;
10219 /* Remove a single compilation unit from the cache. */
10222 free_one_cached_comp_unit (void *target_cu
)
10224 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10226 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10227 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10228 while (per_cu
!= NULL
)
10230 struct dwarf2_per_cu_data
*next_cu
;
10232 next_cu
= per_cu
->cu
->read_in_chain
;
10234 if (per_cu
->cu
== target_cu
)
10236 free_one_comp_unit (per_cu
->cu
);
10237 *last_chain
= next_cu
;
10241 last_chain
= &per_cu
->cu
->read_in_chain
;
10247 /* Release all extra memory associated with OBJFILE. */
10250 dwarf2_free_objfile (struct objfile
*objfile
)
10252 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10254 if (dwarf2_per_objfile
== NULL
)
10257 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10258 free_cached_comp_units (NULL
);
10260 /* Everything else should be on the objfile obstack. */
10263 /* A pair of DIE offset and GDB type pointer. We store these
10264 in a hash table separate from the DIEs, and preserve them
10265 when the DIEs are flushed out of cache. */
10267 struct dwarf2_offset_and_type
10269 unsigned int offset
;
10273 /* Hash function for a dwarf2_offset_and_type. */
10276 offset_and_type_hash (const void *item
)
10278 const struct dwarf2_offset_and_type
*ofs
= item
;
10279 return ofs
->offset
;
10282 /* Equality function for a dwarf2_offset_and_type. */
10285 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10287 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10288 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10289 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10292 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10293 table if necessary. For convenience, return TYPE. */
10295 static struct type
*
10296 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10298 struct dwarf2_offset_and_type
**slot
, ofs
;
10300 if (cu
->type_hash
== NULL
)
10302 gdb_assert (cu
->per_cu
!= NULL
);
10303 cu
->per_cu
->type_hash
10304 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10305 offset_and_type_hash
,
10306 offset_and_type_eq
,
10308 &cu
->objfile
->objfile_obstack
,
10309 hashtab_obstack_allocate
,
10310 dummy_obstack_deallocate
);
10311 cu
->type_hash
= cu
->per_cu
->type_hash
;
10314 ofs
.offset
= die
->offset
;
10316 slot
= (struct dwarf2_offset_and_type
**)
10317 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10318 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10323 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10324 not have a saved type. */
10326 static struct type
*
10327 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10329 struct dwarf2_offset_and_type
*slot
, ofs
;
10330 htab_t type_hash
= cu
->type_hash
;
10332 if (type_hash
== NULL
)
10335 ofs
.offset
= die
->offset
;
10336 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10343 /* Set the mark field in CU and in every other compilation unit in the
10344 cache that we must keep because we are keeping CU. */
10346 /* Add a dependence relationship from CU to REF_PER_CU. */
10349 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10350 struct dwarf2_per_cu_data
*ref_per_cu
)
10354 if (cu
->dependencies
== NULL
)
10356 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10357 NULL
, &cu
->comp_unit_obstack
,
10358 hashtab_obstack_allocate
,
10359 dummy_obstack_deallocate
);
10361 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10363 *slot
= ref_per_cu
;
10366 /* Set the mark field in CU and in every other compilation unit in the
10367 cache that we must keep because we are keeping CU. */
10370 dwarf2_mark_helper (void **slot
, void *data
)
10372 struct dwarf2_per_cu_data
*per_cu
;
10374 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10375 if (per_cu
->cu
->mark
)
10377 per_cu
->cu
->mark
= 1;
10379 if (per_cu
->cu
->dependencies
!= NULL
)
10380 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10386 dwarf2_mark (struct dwarf2_cu
*cu
)
10391 if (cu
->dependencies
!= NULL
)
10392 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10396 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10400 per_cu
->cu
->mark
= 0;
10401 per_cu
= per_cu
->cu
->read_in_chain
;
10405 /* Trivial hash function for partial_die_info: the hash value of a DIE
10406 is its offset in .debug_info for this objfile. */
10409 partial_die_hash (const void *item
)
10411 const struct partial_die_info
*part_die
= item
;
10412 return part_die
->offset
;
10415 /* Trivial comparison function for partial_die_info structures: two DIEs
10416 are equal if they have the same offset. */
10419 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10421 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10422 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10423 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10426 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10427 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10430 set_dwarf2_cmd (char *args
, int from_tty
)
10432 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10436 show_dwarf2_cmd (char *args
, int from_tty
)
10438 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10441 void _initialize_dwarf2_read (void);
10444 _initialize_dwarf2_read (void)
10446 dwarf2_objfile_data_key
= register_objfile_data ();
10448 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10449 Set DWARF 2 specific variables.\n\
10450 Configure DWARF 2 variables such as the cache size"),
10451 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10452 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10454 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10455 Show DWARF 2 specific variables\n\
10456 Show DWARF 2 variables such as the cache size"),
10457 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10458 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10460 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10461 &dwarf2_max_cache_age
, _("\
10462 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10463 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10464 A higher limit means that cached compilation units will be stored\n\
10465 in memory longer, and more total memory will be used. Zero disables\n\
10466 caching, which can slow down startup."),
10468 show_dwarf2_max_cache_age
,
10469 &set_dwarf2_cmdlist
,
10470 &show_dwarf2_cmdlist
);