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
);
2070 case DW_TAG_enumerator
:
2071 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2072 VAR_DOMAIN
, LOC_CONST
,
2073 (cu
->language
== language_cplus
2074 || cu
->language
== language_java
)
2075 ? &objfile
->global_psymbols
2076 : &objfile
->static_psymbols
,
2077 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2083 /* Check to see if we should scan the name for possible namespace
2084 info. Only do this if this is C++, if we don't have namespace
2085 debugging info in the file, if the psym is of an appropriate type
2086 (otherwise we'll have psym == NULL), and if we actually had a
2087 mangled name to begin with. */
2089 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2090 cases which do not set PSYM above? */
2092 if (cu
->language
== language_cplus
2093 && cu
->has_namespace_info
== 0
2095 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2096 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2099 if (built_actual_name
)
2100 xfree (actual_name
);
2103 /* Determine whether a die of type TAG living in a C++ class or
2104 namespace needs to have the name of the scope prepended to the
2105 name listed in the die. */
2108 pdi_needs_namespace (enum dwarf_tag tag
)
2112 case DW_TAG_namespace
:
2113 case DW_TAG_typedef
:
2114 case DW_TAG_class_type
:
2115 case DW_TAG_interface_type
:
2116 case DW_TAG_structure_type
:
2117 case DW_TAG_union_type
:
2118 case DW_TAG_enumeration_type
:
2119 case DW_TAG_enumerator
:
2126 /* Read a partial die corresponding to a namespace; also, add a symbol
2127 corresponding to that namespace to the symbol table. NAMESPACE is
2128 the name of the enclosing namespace. */
2131 add_partial_namespace (struct partial_die_info
*pdi
,
2132 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2133 struct dwarf2_cu
*cu
)
2135 struct objfile
*objfile
= cu
->objfile
;
2137 /* Add a symbol for the namespace. */
2139 add_partial_symbol (pdi
, cu
);
2141 /* Now scan partial symbols in that namespace. */
2143 if (pdi
->has_children
)
2144 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2147 /* See if we can figure out if the class lives in a namespace. We do
2148 this by looking for a member function; its demangled name will
2149 contain namespace info, if there is any. */
2152 guess_structure_name (struct partial_die_info
*struct_pdi
,
2153 struct dwarf2_cu
*cu
)
2155 if ((cu
->language
== language_cplus
2156 || cu
->language
== language_java
)
2157 && cu
->has_namespace_info
== 0
2158 && struct_pdi
->has_children
)
2160 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2161 what template types look like, because the demangler
2162 frequently doesn't give the same name as the debug info. We
2163 could fix this by only using the demangled name to get the
2164 prefix (but see comment in read_structure_type). */
2166 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2167 struct partial_die_info
*real_pdi
;
2169 /* If this DIE (this DIE's specification, if any) has a parent, then
2170 we should not do this. We'll prepend the parent's fully qualified
2171 name when we create the partial symbol. */
2173 real_pdi
= struct_pdi
;
2174 while (real_pdi
->has_specification
)
2175 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2177 if (real_pdi
->die_parent
!= NULL
)
2180 while (child_pdi
!= NULL
)
2182 if (child_pdi
->tag
== DW_TAG_subprogram
)
2184 char *actual_class_name
2185 = language_class_name_from_physname (cu
->language_defn
,
2187 if (actual_class_name
!= NULL
)
2190 = obsavestring (actual_class_name
,
2191 strlen (actual_class_name
),
2192 &cu
->comp_unit_obstack
);
2193 xfree (actual_class_name
);
2198 child_pdi
= child_pdi
->die_sibling
;
2203 /* Read a partial die corresponding to an enumeration type. */
2206 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2207 struct dwarf2_cu
*cu
)
2209 struct objfile
*objfile
= cu
->objfile
;
2210 bfd
*abfd
= objfile
->obfd
;
2211 struct partial_die_info
*pdi
;
2213 if (enum_pdi
->name
!= NULL
)
2214 add_partial_symbol (enum_pdi
, cu
);
2216 pdi
= enum_pdi
->die_child
;
2219 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2220 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2222 add_partial_symbol (pdi
, cu
);
2223 pdi
= pdi
->die_sibling
;
2227 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2228 Return the corresponding abbrev, or NULL if the number is zero (indicating
2229 an empty DIE). In either case *BYTES_READ will be set to the length of
2230 the initial number. */
2232 static struct abbrev_info
*
2233 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2234 struct dwarf2_cu
*cu
)
2236 bfd
*abfd
= cu
->objfile
->obfd
;
2237 unsigned int abbrev_number
;
2238 struct abbrev_info
*abbrev
;
2240 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2242 if (abbrev_number
== 0)
2245 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2248 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2249 bfd_get_filename (abfd
));
2255 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2256 pointer to the end of a series of DIEs, terminated by an empty
2257 DIE. Any children of the skipped DIEs will also be skipped. */
2260 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2262 struct abbrev_info
*abbrev
;
2263 unsigned int bytes_read
;
2267 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2269 return info_ptr
+ bytes_read
;
2271 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2275 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2276 should point just after the initial uleb128 of a DIE, and the
2277 abbrev corresponding to that skipped uleb128 should be passed in
2278 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2282 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2283 struct dwarf2_cu
*cu
)
2285 unsigned int bytes_read
;
2286 struct attribute attr
;
2287 bfd
*abfd
= cu
->objfile
->obfd
;
2288 unsigned int form
, i
;
2290 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2292 /* The only abbrev we care about is DW_AT_sibling. */
2293 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2295 read_attribute (&attr
, &abbrev
->attrs
[i
],
2296 abfd
, info_ptr
, cu
);
2297 if (attr
.form
== DW_FORM_ref_addr
)
2298 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2300 return dwarf2_per_objfile
->info_buffer
2301 + dwarf2_get_ref_die_offset (&attr
, cu
);
2304 /* If it isn't DW_AT_sibling, skip this attribute. */
2305 form
= abbrev
->attrs
[i
].form
;
2310 case DW_FORM_ref_addr
:
2311 info_ptr
+= cu
->header
.addr_size
;
2330 case DW_FORM_string
:
2331 read_string (abfd
, info_ptr
, &bytes_read
);
2332 info_ptr
+= bytes_read
;
2335 info_ptr
+= cu
->header
.offset_size
;
2338 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2339 info_ptr
+= bytes_read
;
2341 case DW_FORM_block1
:
2342 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2344 case DW_FORM_block2
:
2345 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2347 case DW_FORM_block4
:
2348 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2352 case DW_FORM_ref_udata
:
2353 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2355 case DW_FORM_indirect
:
2356 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2357 info_ptr
+= bytes_read
;
2358 /* We need to continue parsing from here, so just go back to
2360 goto skip_attribute
;
2363 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2364 dwarf_form_name (form
),
2365 bfd_get_filename (abfd
));
2369 if (abbrev
->has_children
)
2370 return skip_children (info_ptr
, cu
);
2375 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2376 the next DIE after ORIG_PDI. */
2379 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2380 bfd
*abfd
, struct dwarf2_cu
*cu
)
2382 /* Do we know the sibling already? */
2384 if (orig_pdi
->sibling
)
2385 return orig_pdi
->sibling
;
2387 /* Are there any children to deal with? */
2389 if (!orig_pdi
->has_children
)
2392 /* Skip the children the long way. */
2394 return skip_children (info_ptr
, cu
);
2397 /* Expand this partial symbol table into a full symbol table. */
2400 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2402 /* FIXME: This is barely more than a stub. */
2407 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2413 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2414 gdb_flush (gdb_stdout
);
2417 /* Restore our global data. */
2418 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2419 dwarf2_objfile_data_key
);
2421 psymtab_to_symtab_1 (pst
);
2423 /* Finish up the debug error message. */
2425 printf_filtered (_("done.\n"));
2430 /* Add PER_CU to the queue. */
2433 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2435 struct dwarf2_queue_item
*item
;
2438 item
= xmalloc (sizeof (*item
));
2439 item
->per_cu
= per_cu
;
2442 if (dwarf2_queue
== NULL
)
2443 dwarf2_queue
= item
;
2445 dwarf2_queue_tail
->next
= item
;
2447 dwarf2_queue_tail
= item
;
2450 /* Process the queue. */
2453 process_queue (struct objfile
*objfile
)
2455 struct dwarf2_queue_item
*item
, *next_item
;
2457 /* Initially, there is just one item on the queue. Load its DIEs,
2458 and the DIEs of any other compilation units it requires,
2461 for (item
= dwarf2_queue
; item
!= NULL
; item
= item
->next
)
2463 /* Read in this compilation unit. This may add new items to
2464 the end of the queue. */
2465 load_full_comp_unit (item
->per_cu
, objfile
);
2467 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2468 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2471 /* Now everything left on the queue needs to be read in. Process
2472 them, one at a time, removing from the queue as we finish. */
2473 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2475 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2476 process_full_comp_unit (item
->per_cu
);
2478 item
->per_cu
->queued
= 0;
2479 next_item
= item
->next
;
2483 dwarf2_queue_tail
= NULL
;
2486 /* Free all allocated queue entries. This function only releases anything if
2487 an error was thrown; if the queue was processed then it would have been
2488 freed as we went along. */
2491 dwarf2_release_queue (void *dummy
)
2493 struct dwarf2_queue_item
*item
, *last
;
2495 item
= dwarf2_queue
;
2498 /* Anything still marked queued is likely to be in an
2499 inconsistent state, so discard it. */
2500 if (item
->per_cu
->queued
)
2502 if (item
->per_cu
->cu
!= NULL
)
2503 free_one_cached_comp_unit (item
->per_cu
->cu
);
2504 item
->per_cu
->queued
= 0;
2512 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2515 /* Read in full symbols for PST, and anything it depends on. */
2518 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2520 struct dwarf2_per_cu_data
*per_cu
;
2521 struct cleanup
*back_to
;
2524 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2525 if (!pst
->dependencies
[i
]->readin
)
2527 /* Inform about additional files that need to be read in. */
2530 /* FIXME: i18n: Need to make this a single string. */
2531 fputs_filtered (" ", gdb_stdout
);
2533 fputs_filtered ("and ", gdb_stdout
);
2535 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2536 wrap_here (""); /* Flush output */
2537 gdb_flush (gdb_stdout
);
2539 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2542 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2546 /* It's an include file, no symbols to read for it.
2547 Everything is in the parent symtab. */
2552 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2554 queue_comp_unit (per_cu
);
2556 process_queue (pst
->objfile
);
2558 /* Age the cache, releasing compilation units that have not
2559 been used recently. */
2560 age_cached_comp_units ();
2562 do_cleanups (back_to
);
2565 /* Load the DIEs associated with PST and PER_CU into memory. */
2567 static struct dwarf2_cu
*
2568 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2570 bfd
*abfd
= objfile
->obfd
;
2571 struct dwarf2_cu
*cu
;
2572 unsigned long offset
;
2574 struct cleanup
*back_to
, *free_cu_cleanup
;
2575 struct attribute
*attr
;
2578 /* Set local variables from the partial symbol table info. */
2579 offset
= per_cu
->offset
;
2581 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2583 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2584 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2586 /* If an error occurs while loading, release our storage. */
2587 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2589 cu
->objfile
= objfile
;
2591 /* read in the comp_unit header */
2592 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2594 /* Read the abbrevs for this compilation unit */
2595 dwarf2_read_abbrevs (abfd
, cu
);
2596 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2598 cu
->header
.offset
= offset
;
2600 cu
->per_cu
= per_cu
;
2602 cu
->type_hash
= per_cu
->type_hash
;
2604 /* We use this obstack for block values in dwarf_alloc_block. */
2605 obstack_init (&cu
->comp_unit_obstack
);
2607 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2609 /* We try not to read any attributes in this function, because not
2610 all objfiles needed for references have been loaded yet, and symbol
2611 table processing isn't initialized. But we have to set the CU language,
2612 or we won't be able to build types correctly. */
2613 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2615 set_cu_language (DW_UNSND (attr
), cu
);
2617 set_cu_language (language_minimal
, cu
);
2619 do_cleanups (back_to
);
2621 /* We've successfully allocated this compilation unit. Let our caller
2622 clean it up when finished with it. */
2623 discard_cleanups (free_cu_cleanup
);
2628 /* Generate full symbol information for PST and CU, whose DIEs have
2629 already been loaded into memory. */
2632 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2634 struct partial_symtab
*pst
= per_cu
->psymtab
;
2635 struct dwarf2_cu
*cu
= per_cu
->cu
;
2636 struct objfile
*objfile
= pst
->objfile
;
2637 bfd
*abfd
= objfile
->obfd
;
2638 CORE_ADDR lowpc
, highpc
;
2639 struct symtab
*symtab
;
2640 struct cleanup
*back_to
;
2641 struct attribute
*attr
;
2644 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2646 /* We're in the global namespace. */
2647 processing_current_prefix
= "";
2650 back_to
= make_cleanup (really_free_pendings
, NULL
);
2652 cu
->list_in_scope
= &file_symbols
;
2654 /* Find the base address of the compilation unit for range lists and
2655 location lists. It will normally be specified by DW_AT_low_pc.
2656 In DWARF-3 draft 4, the base address could be overridden by
2657 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2658 compilation units with discontinuous ranges. */
2660 cu
->header
.base_known
= 0;
2661 cu
->header
.base_address
= 0;
2663 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2666 cu
->header
.base_address
= DW_ADDR (attr
);
2667 cu
->header
.base_known
= 1;
2671 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2674 cu
->header
.base_address
= DW_ADDR (attr
);
2675 cu
->header
.base_known
= 1;
2679 /* Do line number decoding in read_file_scope () */
2680 process_die (cu
->dies
, cu
);
2682 /* Some compilers don't define a DW_AT_high_pc attribute for the
2683 compilation unit. If the DW_AT_high_pc is missing, synthesize
2684 it, by scanning the DIE's below the compilation unit. */
2685 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2687 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2689 /* Set symtab language to language from DW_AT_language.
2690 If the compilation is from a C file generated by language preprocessors,
2691 do not set the language if it was already deduced by start_subfile. */
2693 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2695 symtab
->language
= cu
->language
;
2697 pst
->symtab
= symtab
;
2700 do_cleanups (back_to
);
2703 /* Process a die and its children. */
2706 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2710 case DW_TAG_padding
:
2712 case DW_TAG_compile_unit
:
2713 read_file_scope (die
, cu
);
2715 case DW_TAG_subprogram
:
2716 read_func_scope (die
, cu
);
2718 case DW_TAG_inlined_subroutine
:
2719 /* FIXME: These are ignored for now.
2720 They could be used to set breakpoints on all inlined instances
2721 of a function and make GDB `next' properly over inlined functions. */
2723 case DW_TAG_lexical_block
:
2724 case DW_TAG_try_block
:
2725 case DW_TAG_catch_block
:
2726 read_lexical_block_scope (die
, cu
);
2728 case DW_TAG_class_type
:
2729 case DW_TAG_interface_type
:
2730 case DW_TAG_structure_type
:
2731 case DW_TAG_union_type
:
2732 process_structure_scope (die
, cu
);
2734 case DW_TAG_enumeration_type
:
2735 process_enumeration_scope (die
, cu
);
2738 /* These dies have a type, but processing them does not create
2739 a symbol or recurse to process the children. Therefore we can
2740 read them on-demand through read_type_die. */
2741 case DW_TAG_subroutine_type
:
2742 case DW_TAG_set_type
:
2743 case DW_TAG_array_type
:
2744 case DW_TAG_pointer_type
:
2745 case DW_TAG_ptr_to_member_type
:
2746 case DW_TAG_reference_type
:
2747 case DW_TAG_string_type
:
2750 case DW_TAG_base_type
:
2751 case DW_TAG_subrange_type
:
2752 /* Add a typedef symbol for the type definition, if it has a
2754 new_symbol (die
, read_type_die (die
, cu
), cu
);
2756 case DW_TAG_common_block
:
2757 read_common_block (die
, cu
);
2759 case DW_TAG_common_inclusion
:
2761 case DW_TAG_namespace
:
2762 processing_has_namespace_info
= 1;
2763 read_namespace (die
, cu
);
2765 case DW_TAG_imported_declaration
:
2766 case DW_TAG_imported_module
:
2767 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2768 information contained in these. DW_TAG_imported_declaration
2769 dies shouldn't have children; DW_TAG_imported_module dies
2770 shouldn't in the C++ case, but conceivably could in the
2771 Fortran case, so we'll have to replace this gdb_assert if
2772 Fortran compilers start generating that info. */
2773 processing_has_namespace_info
= 1;
2774 gdb_assert (die
->child
== NULL
);
2777 new_symbol (die
, NULL
, cu
);
2783 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2785 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2789 free_cu_line_header (void *arg
)
2791 struct dwarf2_cu
*cu
= arg
;
2793 free_line_header (cu
->line_header
);
2794 cu
->line_header
= NULL
;
2798 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2800 struct objfile
*objfile
= cu
->objfile
;
2801 struct comp_unit_head
*cu_header
= &cu
->header
;
2802 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2803 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2804 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2805 struct attribute
*attr
;
2807 char *comp_dir
= NULL
;
2808 struct die_info
*child_die
;
2809 bfd
*abfd
= objfile
->obfd
;
2810 struct line_header
*line_header
= 0;
2813 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2815 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2817 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2818 from finish_block. */
2819 if (lowpc
== ((CORE_ADDR
) -1))
2824 /* Find the filename. Do not use dwarf2_name here, since the filename
2825 is not a source language identifier. */
2826 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2829 name
= DW_STRING (attr
);
2832 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2834 comp_dir
= DW_STRING (attr
);
2835 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2837 comp_dir
= ldirname (name
);
2838 if (comp_dir
!= NULL
)
2839 make_cleanup (xfree
, comp_dir
);
2841 if (comp_dir
!= NULL
)
2843 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2844 directory, get rid of it. */
2845 char *cp
= strchr (comp_dir
, ':');
2847 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2854 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2857 set_cu_language (DW_UNSND (attr
), cu
);
2860 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2862 cu
->producer
= DW_STRING (attr
);
2864 /* We assume that we're processing GCC output. */
2865 processing_gcc_compilation
= 2;
2867 start_symtab (name
, comp_dir
, lowpc
);
2868 record_debugformat ("DWARF 2");
2869 record_producer (cu
->producer
);
2871 initialize_cu_func_list (cu
);
2873 /* Decode line number information if present. We do this before
2874 processing child DIEs, so that the line header table is available
2875 for DW_AT_decl_file. */
2876 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2879 unsigned int line_offset
= DW_UNSND (attr
);
2880 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2883 cu
->line_header
= line_header
;
2884 make_cleanup (free_cu_line_header
, cu
);
2885 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2889 /* Process all dies in compilation unit. */
2890 if (die
->child
!= NULL
)
2892 child_die
= die
->child
;
2893 while (child_die
&& child_die
->tag
)
2895 process_die (child_die
, cu
);
2896 child_die
= sibling_die (child_die
);
2900 /* Decode macro information, if present. Dwarf 2 macro information
2901 refers to information in the line number info statement program
2902 header, so we can only read it if we've read the header
2904 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2905 if (attr
&& line_header
)
2907 unsigned int macro_offset
= DW_UNSND (attr
);
2908 dwarf_decode_macros (line_header
, macro_offset
,
2909 comp_dir
, abfd
, cu
);
2911 do_cleanups (back_to
);
2915 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2916 struct dwarf2_cu
*cu
)
2918 struct function_range
*thisfn
;
2920 thisfn
= (struct function_range
*)
2921 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2922 thisfn
->name
= name
;
2923 thisfn
->lowpc
= lowpc
;
2924 thisfn
->highpc
= highpc
;
2925 thisfn
->seen_line
= 0;
2926 thisfn
->next
= NULL
;
2928 if (cu
->last_fn
== NULL
)
2929 cu
->first_fn
= thisfn
;
2931 cu
->last_fn
->next
= thisfn
;
2933 cu
->last_fn
= thisfn
;
2937 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2939 struct objfile
*objfile
= cu
->objfile
;
2940 struct context_stack
*new;
2943 struct die_info
*child_die
;
2944 struct attribute
*attr
;
2946 const char *previous_prefix
= processing_current_prefix
;
2947 struct cleanup
*back_to
= NULL
;
2949 struct block
*block
;
2951 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2953 name
= dwarf2_linkage_name (die
, cu
);
2955 /* Ignore functions with missing or empty names and functions with
2956 missing or invalid low and high pc attributes. */
2957 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2960 if (cu
->language
== language_cplus
2961 || cu
->language
== language_java
)
2963 struct die_info
*spec_die
= die_specification (die
, cu
);
2965 /* NOTE: carlton/2004-01-23: We have to be careful in the
2966 presence of DW_AT_specification. For example, with GCC 3.4,
2971 // Definition of N::foo.
2975 then we'll have a tree of DIEs like this:
2977 1: DW_TAG_compile_unit
2978 2: DW_TAG_namespace // N
2979 3: DW_TAG_subprogram // declaration of N::foo
2980 4: DW_TAG_subprogram // definition of N::foo
2981 DW_AT_specification // refers to die #3
2983 Thus, when processing die #4, we have to pretend that we're
2984 in the context of its DW_AT_specification, namely the contex
2987 if (spec_die
!= NULL
)
2989 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2990 processing_current_prefix
= specification_prefix
;
2991 back_to
= make_cleanup (xfree
, specification_prefix
);
2998 /* Record the function range for dwarf_decode_lines. */
2999 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3001 new = push_context (0, lowpc
);
3002 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3004 /* If there is a location expression for DW_AT_frame_base, record
3006 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3008 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3009 expression is being recorded directly in the function's symbol
3010 and not in a separate frame-base object. I guess this hack is
3011 to avoid adding some sort of frame-base adjunct/annex to the
3012 function's symbol :-(. The problem with doing this is that it
3013 results in a function symbol with a location expression that
3014 has nothing to do with the location of the function, ouch! The
3015 relationship should be: a function's symbol has-a frame base; a
3016 frame-base has-a location expression. */
3017 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3019 cu
->list_in_scope
= &local_symbols
;
3021 if (die
->child
!= NULL
)
3023 child_die
= die
->child
;
3024 while (child_die
&& child_die
->tag
)
3026 process_die (child_die
, cu
);
3027 child_die
= sibling_die (child_die
);
3031 new = pop_context ();
3032 /* Make a block for the local symbols within. */
3033 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3034 lowpc
, highpc
, objfile
);
3036 /* If we have address ranges, record them. */
3037 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3039 /* In C++, we can have functions nested inside functions (e.g., when
3040 a function declares a class that has methods). This means that
3041 when we finish processing a function scope, we may need to go
3042 back to building a containing block's symbol lists. */
3043 local_symbols
= new->locals
;
3044 param_symbols
= new->params
;
3046 /* If we've finished processing a top-level function, subsequent
3047 symbols go in the file symbol list. */
3048 if (outermost_context_p ())
3049 cu
->list_in_scope
= &file_symbols
;
3051 processing_current_prefix
= previous_prefix
;
3052 if (back_to
!= NULL
)
3053 do_cleanups (back_to
);
3056 /* Process all the DIES contained within a lexical block scope. Start
3057 a new scope, process the dies, and then close the scope. */
3060 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3062 struct objfile
*objfile
= cu
->objfile
;
3063 struct context_stack
*new;
3064 CORE_ADDR lowpc
, highpc
;
3065 struct die_info
*child_die
;
3068 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3070 /* Ignore blocks with missing or invalid low and high pc attributes. */
3071 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3072 as multiple lexical blocks? Handling children in a sane way would
3073 be nasty. Might be easier to properly extend generic blocks to
3075 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3080 push_context (0, lowpc
);
3081 if (die
->child
!= NULL
)
3083 child_die
= die
->child
;
3084 while (child_die
&& child_die
->tag
)
3086 process_die (child_die
, cu
);
3087 child_die
= sibling_die (child_die
);
3090 new = pop_context ();
3092 if (local_symbols
!= NULL
)
3095 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3098 /* Note that recording ranges after traversing children, as we
3099 do here, means that recording a parent's ranges entails
3100 walking across all its children's ranges as they appear in
3101 the address map, which is quadratic behavior.
3103 It would be nicer to record the parent's ranges before
3104 traversing its children, simply overriding whatever you find
3105 there. But since we don't even decide whether to create a
3106 block until after we've traversed its children, that's hard
3108 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3110 local_symbols
= new->locals
;
3113 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3114 Return 1 if the attributes are present and valid, otherwise, return 0.
3115 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3118 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3119 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3120 struct partial_symtab
*ranges_pst
)
3122 struct objfile
*objfile
= cu
->objfile
;
3123 struct comp_unit_head
*cu_header
= &cu
->header
;
3124 bfd
*obfd
= objfile
->obfd
;
3125 unsigned int addr_size
= cu_header
->addr_size
;
3126 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3127 /* Base address selection entry. */
3138 found_base
= cu_header
->base_known
;
3139 base
= cu_header
->base_address
;
3141 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3143 complaint (&symfile_complaints
,
3144 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3148 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3150 /* Read in the largest possible address. */
3151 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3152 if ((marker
& mask
) == mask
)
3154 /* If we found the largest possible address, then
3155 read the base address. */
3156 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3157 buffer
+= 2 * addr_size
;
3158 offset
+= 2 * addr_size
;
3164 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3168 CORE_ADDR range_beginning
, range_end
;
3170 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3171 buffer
+= addr_size
;
3172 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3173 buffer
+= addr_size
;
3174 offset
+= 2 * addr_size
;
3176 /* An end of list marker is a pair of zero addresses. */
3177 if (range_beginning
== 0 && range_end
== 0)
3178 /* Found the end of list entry. */
3181 /* Each base address selection entry is a pair of 2 values.
3182 The first is the largest possible address, the second is
3183 the base address. Check for a base address here. */
3184 if ((range_beginning
& mask
) == mask
)
3186 /* If we found the largest possible address, then
3187 read the base address. */
3188 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3195 /* We have no valid base address for the ranges
3197 complaint (&symfile_complaints
,
3198 _("Invalid .debug_ranges data (no base address)"));
3202 range_beginning
+= base
;
3205 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3206 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3207 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3210 /* FIXME: This is recording everything as a low-high
3211 segment of consecutive addresses. We should have a
3212 data structure for discontiguous block ranges
3216 low
= range_beginning
;
3222 if (range_beginning
< low
)
3223 low
= range_beginning
;
3224 if (range_end
> high
)
3230 /* If the first entry is an end-of-list marker, the range
3231 describes an empty scope, i.e. no instructions. */
3237 *high_return
= high
;
3241 /* Get low and high pc attributes from a die. Return 1 if the attributes
3242 are present and valid, otherwise, return 0. Return -1 if the range is
3243 discontinuous, i.e. derived from DW_AT_ranges information. */
3245 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3246 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3248 struct attribute
*attr
;
3253 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3256 high
= DW_ADDR (attr
);
3257 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3259 low
= DW_ADDR (attr
);
3261 /* Found high w/o low attribute. */
3264 /* Found consecutive range of addresses. */
3269 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3272 /* Value of the DW_AT_ranges attribute is the offset in the
3273 .debug_ranges section. */
3274 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3276 /* Found discontinuous range of addresses. */
3284 /* When using the GNU linker, .gnu.linkonce. sections are used to
3285 eliminate duplicate copies of functions and vtables and such.
3286 The linker will arbitrarily choose one and discard the others.
3287 The AT_*_pc values for such functions refer to local labels in
3288 these sections. If the section from that file was discarded, the
3289 labels are not in the output, so the relocs get a value of 0.
3290 If this is a discarded function, mark the pc bounds as invalid,
3291 so that GDB will ignore it. */
3292 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3300 /* Get the low and high pc's represented by the scope DIE, and store
3301 them in *LOWPC and *HIGHPC. If the correct values can't be
3302 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3305 get_scope_pc_bounds (struct die_info
*die
,
3306 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3307 struct dwarf2_cu
*cu
)
3309 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3310 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3311 CORE_ADDR current_low
, current_high
;
3313 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3315 best_low
= current_low
;
3316 best_high
= current_high
;
3320 struct die_info
*child
= die
->child
;
3322 while (child
&& child
->tag
)
3324 switch (child
->tag
) {
3325 case DW_TAG_subprogram
:
3326 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3328 best_low
= min (best_low
, current_low
);
3329 best_high
= max (best_high
, current_high
);
3332 case DW_TAG_namespace
:
3333 /* FIXME: carlton/2004-01-16: Should we do this for
3334 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3335 that current GCC's always emit the DIEs corresponding
3336 to definitions of methods of classes as children of a
3337 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3338 the DIEs giving the declarations, which could be
3339 anywhere). But I don't see any reason why the
3340 standards says that they have to be there. */
3341 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3343 if (current_low
!= ((CORE_ADDR
) -1))
3345 best_low
= min (best_low
, current_low
);
3346 best_high
= max (best_high
, current_high
);
3354 child
= sibling_die (child
);
3359 *highpc
= best_high
;
3362 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3365 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3366 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3368 struct attribute
*attr
;
3370 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3373 CORE_ADDR high
= DW_ADDR (attr
);
3374 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3377 CORE_ADDR low
= DW_ADDR (attr
);
3378 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3382 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3385 bfd
*obfd
= cu
->objfile
->obfd
;
3387 /* The value of the DW_AT_ranges attribute is the offset of the
3388 address range list in the .debug_ranges section. */
3389 unsigned long offset
= DW_UNSND (attr
);
3390 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3392 /* For some target architectures, but not others, the
3393 read_address function sign-extends the addresses it returns.
3394 To recognize base address selection entries, we need a
3396 unsigned int addr_size
= cu
->header
.addr_size
;
3397 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3399 /* The base address, to which the next pair is relative. Note
3400 that this 'base' is a DWARF concept: most entries in a range
3401 list are relative, to reduce the number of relocs against the
3402 debugging information. This is separate from this function's
3403 'baseaddr' argument, which GDB uses to relocate debugging
3404 information from a shared library based on the address at
3405 which the library was loaded. */
3406 CORE_ADDR base
= cu
->header
.base_address
;
3407 int base_known
= cu
->header
.base_known
;
3409 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3411 complaint (&symfile_complaints
,
3412 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3419 unsigned int bytes_read
;
3420 CORE_ADDR start
, end
;
3422 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3423 buffer
+= bytes_read
;
3424 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3425 buffer
+= bytes_read
;
3427 /* Did we find the end of the range list? */
3428 if (start
== 0 && end
== 0)
3431 /* Did we find a base address selection entry? */
3432 else if ((start
& base_select_mask
) == base_select_mask
)
3438 /* We found an ordinary address range. */
3443 complaint (&symfile_complaints
,
3444 _("Invalid .debug_ranges data (no base address)"));
3448 record_block_range (block
,
3449 baseaddr
+ base
+ start
,
3450 baseaddr
+ base
+ end
- 1);
3456 /* Add an aggregate field to the field list. */
3459 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3460 struct dwarf2_cu
*cu
)
3462 struct objfile
*objfile
= cu
->objfile
;
3463 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3464 struct nextfield
*new_field
;
3465 struct attribute
*attr
;
3467 char *fieldname
= "";
3469 /* Allocate a new field list entry and link it in. */
3470 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3471 make_cleanup (xfree
, new_field
);
3472 memset (new_field
, 0, sizeof (struct nextfield
));
3473 new_field
->next
= fip
->fields
;
3474 fip
->fields
= new_field
;
3477 /* Handle accessibility and virtuality of field.
3478 The default accessibility for members is public, the default
3479 accessibility for inheritance is private. */
3480 if (die
->tag
!= DW_TAG_inheritance
)
3481 new_field
->accessibility
= DW_ACCESS_public
;
3483 new_field
->accessibility
= DW_ACCESS_private
;
3484 new_field
->virtuality
= DW_VIRTUALITY_none
;
3486 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3488 new_field
->accessibility
= DW_UNSND (attr
);
3489 if (new_field
->accessibility
!= DW_ACCESS_public
)
3490 fip
->non_public_fields
= 1;
3491 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3493 new_field
->virtuality
= DW_UNSND (attr
);
3495 fp
= &new_field
->field
;
3497 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3499 /* Data member other than a C++ static data member. */
3501 /* Get type of field. */
3502 fp
->type
= die_type (die
, cu
);
3504 FIELD_STATIC_KIND (*fp
) = 0;
3506 /* Get bit size of field (zero if none). */
3507 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3510 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3514 FIELD_BITSIZE (*fp
) = 0;
3517 /* Get bit offset of field. */
3518 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3523 if (attr_form_is_section_offset (attr
))
3525 dwarf2_complex_location_expr_complaint ();
3528 else if (attr_form_is_constant (attr
))
3529 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3531 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3533 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3536 FIELD_BITPOS (*fp
) = 0;
3537 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3540 if (gdbarch_bits_big_endian (gdbarch
))
3542 /* For big endian bits, the DW_AT_bit_offset gives the
3543 additional bit offset from the MSB of the containing
3544 anonymous object to the MSB of the field. We don't
3545 have to do anything special since we don't need to
3546 know the size of the anonymous object. */
3547 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3551 /* For little endian bits, compute the bit offset to the
3552 MSB of the anonymous object, subtract off the number of
3553 bits from the MSB of the field to the MSB of the
3554 object, and then subtract off the number of bits of
3555 the field itself. The result is the bit offset of
3556 the LSB of the field. */
3558 int bit_offset
= DW_UNSND (attr
);
3560 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3563 /* The size of the anonymous object containing
3564 the bit field is explicit, so use the
3565 indicated size (in bytes). */
3566 anonymous_size
= DW_UNSND (attr
);
3570 /* The size of the anonymous object containing
3571 the bit field must be inferred from the type
3572 attribute of the data member containing the
3574 anonymous_size
= TYPE_LENGTH (fp
->type
);
3576 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3577 - bit_offset
- FIELD_BITSIZE (*fp
);
3581 /* Get name of field. */
3582 fieldname
= dwarf2_name (die
, cu
);
3583 if (fieldname
== NULL
)
3586 /* The name is already allocated along with this objfile, so we don't
3587 need to duplicate it for the type. */
3588 fp
->name
= fieldname
;
3590 /* Change accessibility for artificial fields (e.g. virtual table
3591 pointer or virtual base class pointer) to private. */
3592 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3594 new_field
->accessibility
= DW_ACCESS_private
;
3595 fip
->non_public_fields
= 1;
3598 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3600 /* C++ static member. */
3602 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3603 is a declaration, but all versions of G++ as of this writing
3604 (so through at least 3.2.1) incorrectly generate
3605 DW_TAG_variable tags. */
3609 /* Get name of field. */
3610 fieldname
= dwarf2_name (die
, cu
);
3611 if (fieldname
== NULL
)
3614 /* Get physical name. */
3615 physname
= dwarf2_linkage_name (die
, cu
);
3617 /* The name is already allocated along with this objfile, so we don't
3618 need to duplicate it for the type. */
3619 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3620 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3621 FIELD_NAME (*fp
) = fieldname
;
3623 else if (die
->tag
== DW_TAG_inheritance
)
3625 /* C++ base class field. */
3626 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3628 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3630 FIELD_BITSIZE (*fp
) = 0;
3631 FIELD_STATIC_KIND (*fp
) = 0;
3632 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3633 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3634 fip
->nbaseclasses
++;
3638 /* Create the vector of fields, and attach it to the type. */
3641 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3642 struct dwarf2_cu
*cu
)
3644 int nfields
= fip
->nfields
;
3646 /* Record the field count, allocate space for the array of fields,
3647 and create blank accessibility bitfields if necessary. */
3648 TYPE_NFIELDS (type
) = nfields
;
3649 TYPE_FIELDS (type
) = (struct field
*)
3650 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3651 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3653 if (fip
->non_public_fields
)
3655 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3657 TYPE_FIELD_PRIVATE_BITS (type
) =
3658 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3659 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3661 TYPE_FIELD_PROTECTED_BITS (type
) =
3662 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3663 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3665 TYPE_FIELD_IGNORE_BITS (type
) =
3666 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3667 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3670 /* If the type has baseclasses, allocate and clear a bit vector for
3671 TYPE_FIELD_VIRTUAL_BITS. */
3672 if (fip
->nbaseclasses
)
3674 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3675 unsigned char *pointer
;
3677 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3678 pointer
= TYPE_ALLOC (type
, num_bytes
);
3679 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3680 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3681 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3684 /* Copy the saved-up fields into the field vector. Start from the head
3685 of the list, adding to the tail of the field array, so that they end
3686 up in the same order in the array in which they were added to the list. */
3687 while (nfields
-- > 0)
3689 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3690 switch (fip
->fields
->accessibility
)
3692 case DW_ACCESS_private
:
3693 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3696 case DW_ACCESS_protected
:
3697 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3700 case DW_ACCESS_public
:
3704 /* Unknown accessibility. Complain and treat it as public. */
3706 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3707 fip
->fields
->accessibility
);
3711 if (nfields
< fip
->nbaseclasses
)
3713 switch (fip
->fields
->virtuality
)
3715 case DW_VIRTUALITY_virtual
:
3716 case DW_VIRTUALITY_pure_virtual
:
3717 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3721 fip
->fields
= fip
->fields
->next
;
3725 /* Add a member function to the proper fieldlist. */
3728 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3729 struct type
*type
, struct dwarf2_cu
*cu
)
3731 struct objfile
*objfile
= cu
->objfile
;
3732 struct attribute
*attr
;
3733 struct fnfieldlist
*flp
;
3735 struct fn_field
*fnp
;
3738 struct nextfnfield
*new_fnfield
;
3739 struct type
*this_type
;
3741 /* Get name of member function. */
3742 fieldname
= dwarf2_name (die
, cu
);
3743 if (fieldname
== NULL
)
3746 /* Get the mangled name. */
3747 physname
= dwarf2_linkage_name (die
, cu
);
3749 /* Look up member function name in fieldlist. */
3750 for (i
= 0; i
< fip
->nfnfields
; i
++)
3752 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3756 /* Create new list element if necessary. */
3757 if (i
< fip
->nfnfields
)
3758 flp
= &fip
->fnfieldlists
[i
];
3761 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3763 fip
->fnfieldlists
= (struct fnfieldlist
*)
3764 xrealloc (fip
->fnfieldlists
,
3765 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3766 * sizeof (struct fnfieldlist
));
3767 if (fip
->nfnfields
== 0)
3768 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3770 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3771 flp
->name
= fieldname
;
3777 /* Create a new member function field and chain it to the field list
3779 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3780 make_cleanup (xfree
, new_fnfield
);
3781 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3782 new_fnfield
->next
= flp
->head
;
3783 flp
->head
= new_fnfield
;
3786 /* Fill in the member function field info. */
3787 fnp
= &new_fnfield
->fnfield
;
3788 /* The name is already allocated along with this objfile, so we don't
3789 need to duplicate it for the type. */
3790 fnp
->physname
= physname
? physname
: "";
3791 fnp
->type
= alloc_type (objfile
);
3792 this_type
= read_type_die (die
, cu
);
3793 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3795 int nparams
= TYPE_NFIELDS (this_type
);
3797 /* TYPE is the domain of this method, and THIS_TYPE is the type
3798 of the method itself (TYPE_CODE_METHOD). */
3799 smash_to_method_type (fnp
->type
, type
,
3800 TYPE_TARGET_TYPE (this_type
),
3801 TYPE_FIELDS (this_type
),
3802 TYPE_NFIELDS (this_type
),
3803 TYPE_VARARGS (this_type
));
3805 /* Handle static member functions.
3806 Dwarf2 has no clean way to discern C++ static and non-static
3807 member functions. G++ helps GDB by marking the first
3808 parameter for non-static member functions (which is the
3809 this pointer) as artificial. We obtain this information
3810 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3811 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3812 fnp
->voffset
= VOFFSET_STATIC
;
3815 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3818 /* Get fcontext from DW_AT_containing_type if present. */
3819 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3820 fnp
->fcontext
= die_containing_type (die
, cu
);
3822 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3823 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3825 /* Get accessibility. */
3826 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3829 switch (DW_UNSND (attr
))
3831 case DW_ACCESS_private
:
3832 fnp
->is_private
= 1;
3834 case DW_ACCESS_protected
:
3835 fnp
->is_protected
= 1;
3840 /* Check for artificial methods. */
3841 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3842 if (attr
&& DW_UNSND (attr
) != 0)
3843 fnp
->is_artificial
= 1;
3845 /* Get index in virtual function table if it is a virtual member function. */
3846 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3849 /* Support the .debug_loc offsets */
3850 if (attr_form_is_block (attr
))
3852 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3854 else if (attr_form_is_section_offset (attr
))
3856 dwarf2_complex_location_expr_complaint ();
3860 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3866 /* Create the vector of member function fields, and attach it to the type. */
3869 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3870 struct dwarf2_cu
*cu
)
3872 struct fnfieldlist
*flp
;
3873 int total_length
= 0;
3876 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3877 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3878 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3880 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3882 struct nextfnfield
*nfp
= flp
->head
;
3883 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3886 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3887 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3888 fn_flp
->fn_fields
= (struct fn_field
*)
3889 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3890 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3891 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3893 total_length
+= flp
->length
;
3896 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3897 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3900 /* Returns non-zero if NAME is the name of a vtable member in CU's
3901 language, zero otherwise. */
3903 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3905 static const char vptr
[] = "_vptr";
3906 static const char vtable
[] = "vtable";
3908 /* Look for the C++ and Java forms of the vtable. */
3909 if ((cu
->language
== language_java
3910 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3911 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3912 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3918 /* GCC outputs unnamed structures that are really pointers to member
3919 functions, with the ABI-specified layout. If DIE (from CU) describes
3920 such a structure, set its type, and return nonzero. Otherwise return
3923 GCC shouldn't do this; it should just output pointer to member DIEs.
3924 This is GCC PR debug/28767. */
3926 static struct type
*
3927 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3929 struct objfile
*objfile
= cu
->objfile
;
3931 struct die_info
*pfn_die
, *delta_die
;
3932 struct attribute
*pfn_name
, *delta_name
;
3933 struct type
*pfn_type
, *domain_type
;
3935 /* Check for a structure with no name and two children. */
3936 if (die
->tag
!= DW_TAG_structure_type
3937 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3938 || die
->child
== NULL
3939 || die
->child
->sibling
== NULL
3940 || (die
->child
->sibling
->sibling
!= NULL
3941 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3944 /* Check for __pfn and __delta members. */
3945 pfn_die
= die
->child
;
3946 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3947 if (pfn_die
->tag
!= DW_TAG_member
3949 || DW_STRING (pfn_name
) == NULL
3950 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3953 delta_die
= pfn_die
->sibling
;
3954 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3955 if (delta_die
->tag
!= DW_TAG_member
3956 || delta_name
== NULL
3957 || DW_STRING (delta_name
) == NULL
3958 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3961 /* Find the type of the method. */
3962 pfn_type
= die_type (pfn_die
, cu
);
3963 if (pfn_type
== NULL
3964 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3965 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3968 /* Look for the "this" argument. */
3969 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3970 if (TYPE_NFIELDS (pfn_type
) == 0
3971 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3974 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3975 type
= alloc_type (objfile
);
3976 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3977 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3978 TYPE_VARARGS (pfn_type
));
3979 type
= lookup_methodptr_type (type
);
3980 return set_die_type (die
, type
, cu
);
3983 /* Called when we find the DIE that starts a structure or union scope
3984 (definition) to process all dies that define the members of the
3987 NOTE: we need to call struct_type regardless of whether or not the
3988 DIE has an at_name attribute, since it might be an anonymous
3989 structure or union. This gets the type entered into our set of
3992 However, if the structure is incomplete (an opaque struct/union)
3993 then suppress creating a symbol table entry for it since gdb only
3994 wants to find the one with the complete definition. Note that if
3995 it is complete, we just call new_symbol, which does it's own
3996 checking about whether the struct/union is anonymous or not (and
3997 suppresses creating a symbol table entry itself). */
3999 static struct type
*
4000 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4002 struct objfile
*objfile
= cu
->objfile
;
4004 struct attribute
*attr
;
4005 const char *previous_prefix
= processing_current_prefix
;
4006 struct cleanup
*back_to
= NULL
;
4009 type
= quirk_gcc_member_function_pointer (die
, cu
);
4013 type
= alloc_type (objfile
);
4014 INIT_CPLUS_SPECIFIC (type
);
4015 name
= dwarf2_name (die
, cu
);
4018 if (cu
->language
== language_cplus
4019 || cu
->language
== language_java
)
4021 char *new_prefix
= determine_class_name (die
, cu
);
4022 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
4023 strlen (new_prefix
),
4024 &objfile
->objfile_obstack
);
4025 back_to
= make_cleanup (xfree
, new_prefix
);
4026 processing_current_prefix
= new_prefix
;
4030 /* The name is already allocated along with this objfile, so
4031 we don't need to duplicate it for the type. */
4032 TYPE_TAG_NAME (type
) = name
;
4036 if (die
->tag
== DW_TAG_structure_type
)
4038 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4040 else if (die
->tag
== DW_TAG_union_type
)
4042 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4046 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4048 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4051 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4054 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4058 TYPE_LENGTH (type
) = 0;
4061 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB_SUPPORTED
;
4062 if (die_is_declaration (die
, cu
))
4063 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4065 /* We need to add the type field to the die immediately so we don't
4066 infinitely recurse when dealing with pointers to the structure
4067 type within the structure itself. */
4068 set_die_type (die
, type
, cu
);
4070 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4072 struct field_info fi
;
4073 struct die_info
*child_die
;
4074 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
4076 memset (&fi
, 0, sizeof (struct field_info
));
4078 child_die
= die
->child
;
4080 while (child_die
&& child_die
->tag
)
4082 if (child_die
->tag
== DW_TAG_member
4083 || child_die
->tag
== DW_TAG_variable
)
4085 /* NOTE: carlton/2002-11-05: A C++ static data member
4086 should be a DW_TAG_member that is a declaration, but
4087 all versions of G++ as of this writing (so through at
4088 least 3.2.1) incorrectly generate DW_TAG_variable
4089 tags for them instead. */
4090 dwarf2_add_field (&fi
, child_die
, cu
);
4092 else if (child_die
->tag
== DW_TAG_subprogram
)
4094 /* C++ member function. */
4095 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4097 else if (child_die
->tag
== DW_TAG_inheritance
)
4099 /* C++ base class field. */
4100 dwarf2_add_field (&fi
, child_die
, cu
);
4102 child_die
= sibling_die (child_die
);
4105 /* Attach fields and member functions to the type. */
4107 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4110 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4112 /* Get the type which refers to the base class (possibly this
4113 class itself) which contains the vtable pointer for the current
4114 class from the DW_AT_containing_type attribute. */
4116 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4118 struct type
*t
= die_containing_type (die
, cu
);
4120 TYPE_VPTR_BASETYPE (type
) = t
;
4125 /* Our own class provides vtbl ptr. */
4126 for (i
= TYPE_NFIELDS (t
) - 1;
4127 i
>= TYPE_N_BASECLASSES (t
);
4130 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4132 if (is_vtable_name (fieldname
, cu
))
4134 TYPE_VPTR_FIELDNO (type
) = i
;
4139 /* Complain if virtual function table field not found. */
4140 if (i
< TYPE_N_BASECLASSES (t
))
4141 complaint (&symfile_complaints
,
4142 _("virtual function table pointer not found when defining class '%s'"),
4143 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4148 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4151 else if (cu
->producer
4152 && strncmp (cu
->producer
,
4153 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4155 /* The IBM XLC compiler does not provide direct indication
4156 of the containing type, but the vtable pointer is
4157 always named __vfp. */
4161 for (i
= TYPE_NFIELDS (type
) - 1;
4162 i
>= TYPE_N_BASECLASSES (type
);
4165 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4167 TYPE_VPTR_FIELDNO (type
) = i
;
4168 TYPE_VPTR_BASETYPE (type
) = type
;
4175 do_cleanups (back_to
);
4178 processing_current_prefix
= previous_prefix
;
4179 if (back_to
!= NULL
)
4180 do_cleanups (back_to
);
4186 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4188 struct objfile
*objfile
= cu
->objfile
;
4189 const char *previous_prefix
= processing_current_prefix
;
4190 struct die_info
*child_die
= die
->child
;
4191 struct type
*this_type
;
4193 this_type
= get_die_type (die
, cu
);
4194 if (this_type
== NULL
)
4195 this_type
= read_structure_type (die
, cu
);
4196 if (TYPE_TAG_NAME (this_type
) != NULL
)
4197 processing_current_prefix
= TYPE_TAG_NAME (this_type
);
4199 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4200 snapshots) has been known to create a die giving a declaration
4201 for a class that has, as a child, a die giving a definition for a
4202 nested class. So we have to process our children even if the
4203 current die is a declaration. Normally, of course, a declaration
4204 won't have any children at all. */
4206 while (child_die
!= NULL
&& child_die
->tag
)
4208 if (child_die
->tag
== DW_TAG_member
4209 || child_die
->tag
== DW_TAG_variable
4210 || child_die
->tag
== DW_TAG_inheritance
)
4215 process_die (child_die
, cu
);
4217 child_die
= sibling_die (child_die
);
4220 /* Do not consider external references. According to the DWARF standard,
4221 these DIEs are identified by the fact that they have no byte_size
4222 attribute, and a declaration attribute. */
4223 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4224 || !die_is_declaration (die
, cu
))
4225 new_symbol (die
, this_type
, cu
);
4227 processing_current_prefix
= previous_prefix
;
4230 /* Given a DW_AT_enumeration_type die, set its type. We do not
4231 complete the type's fields yet, or create any symbols. */
4233 static struct type
*
4234 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4236 struct objfile
*objfile
= cu
->objfile
;
4238 struct attribute
*attr
;
4241 type
= alloc_type (objfile
);
4243 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4244 name
= dwarf2_name (die
, cu
);
4247 if (processing_has_namespace_info
)
4249 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
4250 processing_current_prefix
,
4255 /* The name is already allocated along with this objfile, so
4256 we don't need to duplicate it for the type. */
4257 TYPE_TAG_NAME (type
) = name
;
4261 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4264 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4268 TYPE_LENGTH (type
) = 0;
4271 /* The enumeration DIE can be incomplete. In Ada, any type can be
4272 declared as private in the package spec, and then defined only
4273 inside the package body. Such types are known as Taft Amendment
4274 Types. When another package uses such a type, an incomplete DIE
4275 may be generated by the compiler. */
4276 if (die_is_declaration (die
, cu
))
4277 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4279 return set_die_type (die
, type
, cu
);
4282 /* Determine the name of the type represented by DIE, which should be
4283 a named C++ or Java compound type. Return the name in question; the caller
4284 is responsible for xfree()'ing it. */
4287 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4289 struct cleanup
*back_to
= NULL
;
4290 struct die_info
*spec_die
= die_specification (die
, cu
);
4291 char *new_prefix
= NULL
;
4293 /* If this is the definition of a class that is declared by another
4294 die, then processing_current_prefix may not be accurate; see
4295 read_func_scope for a similar example. */
4296 if (spec_die
!= NULL
)
4298 char *specification_prefix
= determine_prefix (spec_die
, cu
);
4299 processing_current_prefix
= specification_prefix
;
4300 back_to
= make_cleanup (xfree
, specification_prefix
);
4303 /* If we don't have namespace debug info, guess the name by trying
4304 to demangle the names of members, just like we did in
4305 guess_structure_name. */
4306 if (!processing_has_namespace_info
)
4308 struct die_info
*child
;
4310 for (child
= die
->child
;
4311 child
!= NULL
&& child
->tag
!= 0;
4312 child
= sibling_die (child
))
4314 if (child
->tag
== DW_TAG_subprogram
)
4317 = language_class_name_from_physname (cu
->language_defn
,
4321 if (new_prefix
!= NULL
)
4327 if (new_prefix
== NULL
)
4329 const char *name
= dwarf2_name (die
, cu
);
4330 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
4331 name
? name
: "<<anonymous>>",
4335 if (back_to
!= NULL
)
4336 do_cleanups (back_to
);
4341 /* Given a pointer to a die which begins an enumeration, process all
4342 the dies that define the members of the enumeration, and create the
4343 symbol for the enumeration type.
4345 NOTE: We reverse the order of the element list. */
4348 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4350 struct objfile
*objfile
= cu
->objfile
;
4351 struct die_info
*child_die
;
4352 struct field
*fields
;
4355 int unsigned_enum
= 1;
4357 struct type
*this_type
;
4361 this_type
= get_die_type (die
, cu
);
4362 if (this_type
== NULL
)
4363 this_type
= read_enumeration_type (die
, cu
);
4364 if (die
->child
!= NULL
)
4366 child_die
= die
->child
;
4367 while (child_die
&& child_die
->tag
)
4369 if (child_die
->tag
!= DW_TAG_enumerator
)
4371 process_die (child_die
, cu
);
4375 name
= dwarf2_name (child_die
, cu
);
4378 sym
= new_symbol (child_die
, this_type
, cu
);
4379 if (SYMBOL_VALUE (sym
) < 0)
4382 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4384 fields
= (struct field
*)
4386 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4387 * sizeof (struct field
));
4390 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
4391 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4392 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4393 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4394 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4400 child_die
= sibling_die (child_die
);
4405 TYPE_NFIELDS (this_type
) = num_fields
;
4406 TYPE_FIELDS (this_type
) = (struct field
*)
4407 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4408 memcpy (TYPE_FIELDS (this_type
), fields
,
4409 sizeof (struct field
) * num_fields
);
4413 TYPE_FLAGS (this_type
) |= TYPE_FLAG_UNSIGNED
;
4416 new_symbol (die
, this_type
, cu
);
4419 /* Extract all information from a DW_TAG_array_type DIE and put it in
4420 the DIE's type field. For now, this only handles one dimensional
4423 static struct type
*
4424 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4426 struct objfile
*objfile
= cu
->objfile
;
4427 struct die_info
*child_die
;
4428 struct type
*type
= NULL
;
4429 struct type
*element_type
, *range_type
, *index_type
;
4430 struct type
**range_types
= NULL
;
4431 struct attribute
*attr
;
4433 struct cleanup
*back_to
;
4436 element_type
= die_type (die
, cu
);
4438 /* Irix 6.2 native cc creates array types without children for
4439 arrays with unspecified length. */
4440 if (die
->child
== NULL
)
4442 index_type
= builtin_type_int32
;
4443 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4444 type
= create_array_type (NULL
, element_type
, range_type
);
4445 return set_die_type (die
, type
, cu
);
4448 back_to
= make_cleanup (null_cleanup
, NULL
);
4449 child_die
= die
->child
;
4450 while (child_die
&& child_die
->tag
)
4452 if (child_die
->tag
== DW_TAG_subrange_type
)
4454 struct type
*child_type
= read_type_die (child_die
, cu
);
4455 if (child_type
!= NULL
)
4457 /* The range type was succesfully read. Save it for
4458 the array type creation. */
4459 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4461 range_types
= (struct type
**)
4462 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4463 * sizeof (struct type
*));
4465 make_cleanup (free_current_contents
, &range_types
);
4467 range_types
[ndim
++] = child_type
;
4470 child_die
= sibling_die (child_die
);
4473 /* Dwarf2 dimensions are output from left to right, create the
4474 necessary array types in backwards order. */
4476 type
= element_type
;
4478 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4482 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4487 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4490 /* Understand Dwarf2 support for vector types (like they occur on
4491 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4492 array type. This is not part of the Dwarf2/3 standard yet, but a
4493 custom vendor extension. The main difference between a regular
4494 array and the vector variant is that vectors are passed by value
4496 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4498 make_vector_type (type
);
4500 name
= dwarf2_name (die
, cu
);
4502 TYPE_NAME (type
) = name
;
4504 do_cleanups (back_to
);
4506 /* Install the type in the die. */
4507 return set_die_type (die
, type
, cu
);
4510 static enum dwarf_array_dim_ordering
4511 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4513 struct attribute
*attr
;
4515 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4517 if (attr
) return DW_SND (attr
);
4520 GNU F77 is a special case, as at 08/2004 array type info is the
4521 opposite order to the dwarf2 specification, but data is still
4522 laid out as per normal fortran.
4524 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4528 if (cu
->language
== language_fortran
&&
4529 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4531 return DW_ORD_row_major
;
4534 switch (cu
->language_defn
->la_array_ordering
)
4536 case array_column_major
:
4537 return DW_ORD_col_major
;
4538 case array_row_major
:
4540 return DW_ORD_row_major
;
4544 /* Extract all information from a DW_TAG_set_type DIE and put it in
4545 the DIE's type field. */
4547 static struct type
*
4548 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4550 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4552 return set_die_type (die
, set_type
, cu
);
4555 /* First cut: install each common block member as a global variable. */
4558 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4560 struct die_info
*child_die
;
4561 struct attribute
*attr
;
4563 CORE_ADDR base
= (CORE_ADDR
) 0;
4565 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4568 /* Support the .debug_loc offsets */
4569 if (attr_form_is_block (attr
))
4571 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4573 else if (attr_form_is_section_offset (attr
))
4575 dwarf2_complex_location_expr_complaint ();
4579 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4580 "common block member");
4583 if (die
->child
!= NULL
)
4585 child_die
= die
->child
;
4586 while (child_die
&& child_die
->tag
)
4588 sym
= new_symbol (child_die
, NULL
, cu
);
4589 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4592 SYMBOL_VALUE_ADDRESS (sym
) =
4593 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4594 add_symbol_to_list (sym
, &global_symbols
);
4596 child_die
= sibling_die (child_die
);
4601 /* Read a C++ namespace. */
4604 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4606 struct objfile
*objfile
= cu
->objfile
;
4607 const char *previous_prefix
= processing_current_prefix
;
4610 struct die_info
*current_die
;
4611 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4613 name
= namespace_name (die
, &is_anonymous
, cu
);
4615 /* Now build the name of the current namespace. */
4617 if (previous_prefix
[0] == '\0')
4619 processing_current_prefix
= name
;
4623 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4624 make_cleanup (xfree
, temp_name
);
4625 processing_current_prefix
= temp_name
;
4628 /* Add a symbol associated to this if we haven't seen the namespace
4629 before. Also, add a using directive if it's an anonymous
4632 if (dwarf2_extension (die
, cu
) == NULL
)
4636 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4637 this cast will hopefully become unnecessary. */
4638 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4639 (char *) processing_current_prefix
,
4641 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4643 new_symbol (die
, type
, cu
);
4644 set_die_type (die
, type
, cu
);
4647 cp_add_using_directive (processing_current_prefix
,
4648 strlen (previous_prefix
),
4649 strlen (processing_current_prefix
));
4652 if (die
->child
!= NULL
)
4654 struct die_info
*child_die
= die
->child
;
4656 while (child_die
&& child_die
->tag
)
4658 process_die (child_die
, cu
);
4659 child_die
= sibling_die (child_die
);
4663 processing_current_prefix
= previous_prefix
;
4664 do_cleanups (back_to
);
4667 /* Return the name of the namespace represented by DIE. Set
4668 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4672 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4674 struct die_info
*current_die
;
4675 const char *name
= NULL
;
4677 /* Loop through the extensions until we find a name. */
4679 for (current_die
= die
;
4680 current_die
!= NULL
;
4681 current_die
= dwarf2_extension (die
, cu
))
4683 name
= dwarf2_name (current_die
, cu
);
4688 /* Is it an anonymous namespace? */
4690 *is_anonymous
= (name
== NULL
);
4692 name
= "(anonymous namespace)";
4697 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4698 the user defined type vector. */
4700 static struct type
*
4701 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4703 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4704 struct comp_unit_head
*cu_header
= &cu
->header
;
4706 struct attribute
*attr_byte_size
;
4707 struct attribute
*attr_address_class
;
4708 int byte_size
, addr_class
;
4710 type
= lookup_pointer_type (die_type (die
, cu
));
4712 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4714 byte_size
= DW_UNSND (attr_byte_size
);
4716 byte_size
= cu_header
->addr_size
;
4718 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4719 if (attr_address_class
)
4720 addr_class
= DW_UNSND (attr_address_class
);
4722 addr_class
= DW_ADDR_none
;
4724 /* If the pointer size or address class is different than the
4725 default, create a type variant marked as such and set the
4726 length accordingly. */
4727 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4729 if (gdbarch_address_class_type_flags_p (gdbarch
))
4733 type_flags
= gdbarch_address_class_type_flags
4734 (gdbarch
, byte_size
, addr_class
);
4735 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4736 type
= make_type_with_address_space (type
, type_flags
);
4738 else if (TYPE_LENGTH (type
) != byte_size
)
4740 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4743 /* Should we also complain about unhandled address classes? */
4747 TYPE_LENGTH (type
) = byte_size
;
4748 return set_die_type (die
, type
, cu
);
4751 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4752 the user defined type vector. */
4754 static struct type
*
4755 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4757 struct objfile
*objfile
= cu
->objfile
;
4759 struct type
*to_type
;
4760 struct type
*domain
;
4762 to_type
= die_type (die
, cu
);
4763 domain
= die_containing_type (die
, cu
);
4765 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4766 type
= lookup_methodptr_type (to_type
);
4768 type
= lookup_memberptr_type (to_type
, domain
);
4770 return set_die_type (die
, type
, cu
);
4773 /* Extract all information from a DW_TAG_reference_type DIE and add to
4774 the user defined type vector. */
4776 static struct type
*
4777 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4779 struct comp_unit_head
*cu_header
= &cu
->header
;
4781 struct attribute
*attr
;
4783 type
= lookup_reference_type (die_type (die
, cu
));
4784 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4787 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4791 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4793 return set_die_type (die
, type
, cu
);
4796 static struct type
*
4797 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4799 struct type
*base_type
, *cv_type
;
4801 base_type
= die_type (die
, cu
);
4802 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4803 return set_die_type (die
, cv_type
, cu
);
4806 static struct type
*
4807 read_tag_volatile_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 (TYPE_CONST (base_type
), 1, base_type
, 0);
4813 return set_die_type (die
, cv_type
, cu
);
4816 /* Extract all information from a DW_TAG_string_type DIE and add to
4817 the user defined type vector. It isn't really a user defined type,
4818 but it behaves like one, with other DIE's using an AT_user_def_type
4819 attribute to reference it. */
4821 static struct type
*
4822 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4824 struct objfile
*objfile
= cu
->objfile
;
4825 struct type
*type
, *range_type
, *index_type
, *char_type
;
4826 struct attribute
*attr
;
4827 unsigned int length
;
4829 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4832 length
= DW_UNSND (attr
);
4836 /* check for the DW_AT_byte_size attribute */
4837 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4840 length
= DW_UNSND (attr
);
4848 index_type
= builtin_type_int32
;
4849 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4850 type
= create_string_type (NULL
, range_type
);
4852 return set_die_type (die
, type
, cu
);
4855 /* Handle DIES due to C code like:
4859 int (*funcp)(int a, long l);
4863 ('funcp' generates a DW_TAG_subroutine_type DIE)
4866 static struct type
*
4867 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4869 struct type
*type
; /* Type that this function returns */
4870 struct type
*ftype
; /* Function that returns above type */
4871 struct attribute
*attr
;
4873 type
= die_type (die
, cu
);
4874 ftype
= make_function_type (type
, (struct type
**) 0);
4876 /* All functions in C++, Pascal and Java have prototypes. */
4877 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4878 if ((attr
&& (DW_UNSND (attr
) != 0))
4879 || cu
->language
== language_cplus
4880 || cu
->language
== language_java
4881 || cu
->language
== language_pascal
)
4882 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4884 /* Store the calling convention in the type if it's available in
4885 the subroutine die. Otherwise set the calling convention to
4886 the default value DW_CC_normal. */
4887 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4888 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4890 if (die
->child
!= NULL
)
4892 struct die_info
*child_die
;
4896 /* Count the number of parameters.
4897 FIXME: GDB currently ignores vararg functions, but knows about
4898 vararg member functions. */
4899 child_die
= die
->child
;
4900 while (child_die
&& child_die
->tag
)
4902 if (child_die
->tag
== DW_TAG_formal_parameter
)
4904 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4905 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4906 child_die
= sibling_die (child_die
);
4909 /* Allocate storage for parameters and fill them in. */
4910 TYPE_NFIELDS (ftype
) = nparams
;
4911 TYPE_FIELDS (ftype
) = (struct field
*)
4912 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4914 child_die
= die
->child
;
4915 while (child_die
&& child_die
->tag
)
4917 if (child_die
->tag
== DW_TAG_formal_parameter
)
4919 /* Dwarf2 has no clean way to discern C++ static and non-static
4920 member functions. G++ helps GDB by marking the first
4921 parameter for non-static member functions (which is the
4922 this pointer) as artificial. We pass this information
4923 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4924 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4926 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4928 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4929 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4932 child_die
= sibling_die (child_die
);
4936 return set_die_type (die
, ftype
, cu
);
4939 static struct type
*
4940 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4942 struct objfile
*objfile
= cu
->objfile
;
4943 struct attribute
*attr
;
4945 struct type
*this_type
;
4947 name
= dwarf2_name (die
, cu
);
4948 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4949 TYPE_FLAG_TARGET_STUB
, name
, objfile
);
4950 set_die_type (die
, this_type
, cu
);
4951 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4955 /* Find a representation of a given base type and install
4956 it in the TYPE field of the die. */
4958 static struct type
*
4959 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4961 struct objfile
*objfile
= cu
->objfile
;
4963 struct attribute
*attr
;
4964 int encoding
= 0, size
= 0;
4966 enum type_code code
= TYPE_CODE_INT
;
4968 struct type
*target_type
= NULL
;
4970 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4973 encoding
= DW_UNSND (attr
);
4975 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4978 size
= DW_UNSND (attr
);
4980 name
= dwarf2_name (die
, cu
);
4983 complaint (&symfile_complaints
,
4984 _("DW_AT_name missing from DW_TAG_base_type"));
4989 case DW_ATE_address
:
4990 /* Turn DW_ATE_address into a void * pointer. */
4991 code
= TYPE_CODE_PTR
;
4992 type_flags
|= TYPE_FLAG_UNSIGNED
;
4993 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4995 case DW_ATE_boolean
:
4996 code
= TYPE_CODE_BOOL
;
4997 type_flags
|= TYPE_FLAG_UNSIGNED
;
4999 case DW_ATE_complex_float
:
5000 code
= TYPE_CODE_COMPLEX
;
5001 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5003 case DW_ATE_decimal_float
:
5004 code
= TYPE_CODE_DECFLOAT
;
5007 code
= TYPE_CODE_FLT
;
5011 case DW_ATE_unsigned
:
5012 type_flags
|= TYPE_FLAG_UNSIGNED
;
5014 case DW_ATE_signed_char
:
5015 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5016 code
= TYPE_CODE_CHAR
;
5018 case DW_ATE_unsigned_char
:
5019 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5020 code
= TYPE_CODE_CHAR
;
5021 type_flags
|= TYPE_FLAG_UNSIGNED
;
5024 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5025 dwarf_type_encoding_name (encoding
));
5029 type
= init_type (code
, size
, type_flags
, name
, objfile
);
5030 TYPE_TARGET_TYPE (type
) = target_type
;
5032 return set_die_type (die
, type
, cu
);
5035 /* Read the given DW_AT_subrange DIE. */
5037 static struct type
*
5038 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5040 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5041 struct type
*base_type
;
5042 struct type
*range_type
;
5043 struct attribute
*attr
;
5048 base_type
= die_type (die
, cu
);
5049 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5051 complaint (&symfile_complaints
,
5052 _("DW_AT_type missing from DW_TAG_subrange_type"));
5054 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5055 0, NULL
, cu
->objfile
);
5058 if (cu
->language
== language_fortran
)
5060 /* FORTRAN implies a lower bound of 1, if not given. */
5064 /* FIXME: For variable sized arrays either of these could be
5065 a variable rather than a constant value. We'll allow it,
5066 but we don't know how to handle it. */
5067 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5069 low
= dwarf2_get_attr_constant_value (attr
, 0);
5071 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5074 if (attr
->form
== DW_FORM_block1
)
5076 /* GCC encodes arrays with unspecified or dynamic length
5077 with a DW_FORM_block1 attribute.
5078 FIXME: GDB does not yet know how to handle dynamic
5079 arrays properly, treat them as arrays with unspecified
5082 FIXME: jimb/2003-09-22: GDB does not really know
5083 how to handle arrays of unspecified length
5084 either; we just represent them as zero-length
5085 arrays. Choose an appropriate upper bound given
5086 the lower bound we've computed above. */
5090 high
= dwarf2_get_attr_constant_value (attr
, 1);
5093 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5095 name
= dwarf2_name (die
, cu
);
5097 TYPE_NAME (range_type
) = name
;
5099 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5101 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5103 return set_die_type (die
, range_type
, cu
);
5106 static struct type
*
5107 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5111 /* For now, we only support the C meaning of an unspecified type: void. */
5113 type
= init_type (TYPE_CODE_VOID
, 0, 0, dwarf2_name (die
, cu
),
5116 return set_die_type (die
, type
, cu
);
5119 /* Read a whole compilation unit into a linked list of dies. */
5121 static struct die_info
*
5122 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5124 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5127 /* Read a single die and all its descendents. Set the die's sibling
5128 field to NULL; set other fields in the die correctly, and set all
5129 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5130 location of the info_ptr after reading all of those dies. PARENT
5131 is the parent of the die in question. */
5133 static struct die_info
*
5134 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5135 struct dwarf2_cu
*cu
,
5136 gdb_byte
**new_info_ptr
,
5137 struct die_info
*parent
)
5139 struct die_info
*die
;
5143 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5144 store_in_ref_table (die
->offset
, die
, cu
);
5148 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5154 *new_info_ptr
= cur_ptr
;
5157 die
->sibling
= NULL
;
5158 die
->parent
= parent
;
5162 /* Read a die, all of its descendents, and all of its siblings; set
5163 all of the fields of all of the dies correctly. Arguments are as
5164 in read_die_and_children. */
5166 static struct die_info
*
5167 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5168 struct dwarf2_cu
*cu
,
5169 gdb_byte
**new_info_ptr
,
5170 struct die_info
*parent
)
5172 struct die_info
*first_die
, *last_sibling
;
5176 first_die
= last_sibling
= NULL
;
5180 struct die_info
*die
5181 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5189 last_sibling
->sibling
= die
;
5194 *new_info_ptr
= cur_ptr
;
5204 /* Free a linked list of dies. */
5207 free_die_list (struct die_info
*dies
)
5209 struct die_info
*die
, *next
;
5214 if (die
->child
!= NULL
)
5215 free_die_list (die
->child
);
5216 next
= die
->sibling
;
5223 /* Decompress a section that was compressed using zlib. Store the
5224 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5227 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5228 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5230 bfd
*abfd
= objfile
->obfd
;
5232 error (_("Support for zlib-compressed DWARF data (from '%s') "
5233 "is disabled in this copy of GDB"),
5234 bfd_get_filename (abfd
));
5236 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5237 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5238 bfd_size_type uncompressed_size
;
5239 gdb_byte
*uncompressed_buffer
;
5242 int header_size
= 12;
5244 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5245 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5246 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5247 bfd_get_filename (abfd
));
5249 /* Read the zlib header. In this case, it should be "ZLIB" followed
5250 by the uncompressed section size, 8 bytes in big-endian order. */
5251 if (compressed_size
< header_size
5252 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5253 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5254 bfd_get_filename (abfd
));
5255 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5256 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5257 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5258 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5259 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5260 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5261 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5262 uncompressed_size
+= compressed_buffer
[11];
5264 /* It is possible the section consists of several compressed
5265 buffers concatenated together, so we uncompress in a loop. */
5269 strm
.avail_in
= compressed_size
- header_size
;
5270 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5271 strm
.avail_out
= uncompressed_size
;
5272 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5274 rc
= inflateInit (&strm
);
5275 while (strm
.avail_in
> 0)
5278 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5279 bfd_get_filename (abfd
), rc
);
5280 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5281 + (uncompressed_size
- strm
.avail_out
));
5282 rc
= inflate (&strm
, Z_FINISH
);
5283 if (rc
!= Z_STREAM_END
)
5284 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5285 bfd_get_filename (abfd
), rc
);
5286 rc
= inflateReset (&strm
);
5288 rc
= inflateEnd (&strm
);
5290 || strm
.avail_out
!= 0)
5291 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5292 bfd_get_filename (abfd
), rc
);
5294 xfree (compressed_buffer
);
5295 *outbuf
= uncompressed_buffer
;
5296 *outsize
= uncompressed_size
;
5301 /* Read the contents of the section at OFFSET and of size SIZE from the
5302 object file specified by OBJFILE into the objfile_obstack and return it.
5303 If the section is compressed, uncompress it before returning. */
5306 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5308 bfd
*abfd
= objfile
->obfd
;
5309 gdb_byte
*buf
, *retbuf
;
5310 bfd_size_type size
= bfd_get_section_size (sectp
);
5311 unsigned char header
[4];
5316 /* Check if the file has a 4-byte header indicating compression. */
5317 if (size
> sizeof (header
)
5318 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5319 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5321 /* Upon decompression, update the buffer and its size. */
5322 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5324 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5325 dwarf2_resize_section (sectp
, size
);
5330 /* If we get here, we are a normal, not-compressed section. */
5331 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5332 /* When debugging .o files, we may need to apply relocations; see
5333 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5334 We never compress sections in .o files, so we only need to
5335 try this when the section is not compressed. */
5336 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5340 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5341 || bfd_bread (buf
, size
, abfd
) != size
)
5342 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5343 bfd_get_filename (abfd
));
5348 /* In DWARF version 2, the description of the debugging information is
5349 stored in a separate .debug_abbrev section. Before we read any
5350 dies from a section we read in all abbreviations and install them
5351 in a hash table. This function also sets flags in CU describing
5352 the data found in the abbrev table. */
5355 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5357 struct comp_unit_head
*cu_header
= &cu
->header
;
5358 gdb_byte
*abbrev_ptr
;
5359 struct abbrev_info
*cur_abbrev
;
5360 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5361 unsigned int abbrev_form
, hash_number
;
5362 struct attr_abbrev
*cur_attrs
;
5363 unsigned int allocated_attrs
;
5365 /* Initialize dwarf2 abbrevs */
5366 obstack_init (&cu
->abbrev_obstack
);
5367 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5369 * sizeof (struct abbrev_info
*)));
5370 memset (cu
->dwarf2_abbrevs
, 0,
5371 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5373 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5374 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5375 abbrev_ptr
+= bytes_read
;
5377 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5378 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5380 /* loop until we reach an abbrev number of 0 */
5381 while (abbrev_number
)
5383 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5385 /* read in abbrev header */
5386 cur_abbrev
->number
= abbrev_number
;
5387 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5388 abbrev_ptr
+= bytes_read
;
5389 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5392 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5393 cu
->has_namespace_info
= 1;
5395 /* now read in declarations */
5396 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5397 abbrev_ptr
+= bytes_read
;
5398 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5399 abbrev_ptr
+= bytes_read
;
5402 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5404 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5406 = xrealloc (cur_attrs
, (allocated_attrs
5407 * sizeof (struct attr_abbrev
)));
5410 /* Record whether this compilation unit might have
5411 inter-compilation-unit references. If we don't know what form
5412 this attribute will have, then it might potentially be a
5413 DW_FORM_ref_addr, so we conservatively expect inter-CU
5416 if (abbrev_form
== DW_FORM_ref_addr
5417 || abbrev_form
== DW_FORM_indirect
)
5418 cu
->has_form_ref_addr
= 1;
5420 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5421 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5422 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5423 abbrev_ptr
+= bytes_read
;
5424 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5425 abbrev_ptr
+= bytes_read
;
5428 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5429 (cur_abbrev
->num_attrs
5430 * sizeof (struct attr_abbrev
)));
5431 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5432 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5434 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5435 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5436 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5438 /* Get next abbreviation.
5439 Under Irix6 the abbreviations for a compilation unit are not
5440 always properly terminated with an abbrev number of 0.
5441 Exit loop if we encounter an abbreviation which we have
5442 already read (which means we are about to read the abbreviations
5443 for the next compile unit) or if the end of the abbreviation
5444 table is reached. */
5445 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5446 >= dwarf2_per_objfile
->abbrev_size
)
5448 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5449 abbrev_ptr
+= bytes_read
;
5450 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5457 /* Release the memory used by the abbrev table for a compilation unit. */
5460 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5462 struct dwarf2_cu
*cu
= ptr_to_cu
;
5464 obstack_free (&cu
->abbrev_obstack
, NULL
);
5465 cu
->dwarf2_abbrevs
= NULL
;
5468 /* Lookup an abbrev_info structure in the abbrev hash table. */
5470 static struct abbrev_info
*
5471 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5473 unsigned int hash_number
;
5474 struct abbrev_info
*abbrev
;
5476 hash_number
= number
% ABBREV_HASH_SIZE
;
5477 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5481 if (abbrev
->number
== number
)
5484 abbrev
= abbrev
->next
;
5489 /* Returns nonzero if TAG represents a type that we might generate a partial
5493 is_type_tag_for_partial (int tag
)
5498 /* Some types that would be reasonable to generate partial symbols for,
5499 that we don't at present. */
5500 case DW_TAG_array_type
:
5501 case DW_TAG_file_type
:
5502 case DW_TAG_ptr_to_member_type
:
5503 case DW_TAG_set_type
:
5504 case DW_TAG_string_type
:
5505 case DW_TAG_subroutine_type
:
5507 case DW_TAG_base_type
:
5508 case DW_TAG_class_type
:
5509 case DW_TAG_interface_type
:
5510 case DW_TAG_enumeration_type
:
5511 case DW_TAG_structure_type
:
5512 case DW_TAG_subrange_type
:
5513 case DW_TAG_typedef
:
5514 case DW_TAG_union_type
:
5521 /* Load all DIEs that are interesting for partial symbols into memory. */
5523 static struct partial_die_info
*
5524 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5525 struct dwarf2_cu
*cu
)
5527 struct partial_die_info
*part_die
;
5528 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5529 struct abbrev_info
*abbrev
;
5530 unsigned int bytes_read
;
5531 unsigned int load_all
= 0;
5533 int nesting_level
= 1;
5538 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5542 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5546 &cu
->comp_unit_obstack
,
5547 hashtab_obstack_allocate
,
5548 dummy_obstack_deallocate
);
5550 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5551 sizeof (struct partial_die_info
));
5555 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5557 /* A NULL abbrev means the end of a series of children. */
5560 if (--nesting_level
== 0)
5562 /* PART_DIE was probably the last thing allocated on the
5563 comp_unit_obstack, so we could call obstack_free
5564 here. We don't do that because the waste is small,
5565 and will be cleaned up when we're done with this
5566 compilation unit. This way, we're also more robust
5567 against other users of the comp_unit_obstack. */
5570 info_ptr
+= bytes_read
;
5571 last_die
= parent_die
;
5572 parent_die
= parent_die
->die_parent
;
5576 /* Check whether this DIE is interesting enough to save. Normally
5577 we would not be interested in members here, but there may be
5578 later variables referencing them via DW_AT_specification (for
5581 && !is_type_tag_for_partial (abbrev
->tag
)
5582 && abbrev
->tag
!= DW_TAG_enumerator
5583 && abbrev
->tag
!= DW_TAG_subprogram
5584 && abbrev
->tag
!= DW_TAG_variable
5585 && abbrev
->tag
!= DW_TAG_namespace
5586 && abbrev
->tag
!= DW_TAG_member
)
5588 /* Otherwise we skip to the next sibling, if any. */
5589 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5593 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5594 abfd
, info_ptr
, cu
);
5596 /* This two-pass algorithm for processing partial symbols has a
5597 high cost in cache pressure. Thus, handle some simple cases
5598 here which cover the majority of C partial symbols. DIEs
5599 which neither have specification tags in them, nor could have
5600 specification tags elsewhere pointing at them, can simply be
5601 processed and discarded.
5603 This segment is also optional; scan_partial_symbols and
5604 add_partial_symbol will handle these DIEs if we chain
5605 them in normally. When compilers which do not emit large
5606 quantities of duplicate debug information are more common,
5607 this code can probably be removed. */
5609 /* Any complete simple types at the top level (pretty much all
5610 of them, for a language without namespaces), can be processed
5612 if (parent_die
== NULL
5613 && part_die
->has_specification
== 0
5614 && part_die
->is_declaration
== 0
5615 && (part_die
->tag
== DW_TAG_typedef
5616 || part_die
->tag
== DW_TAG_base_type
5617 || part_die
->tag
== DW_TAG_subrange_type
))
5619 if (building_psymtab
&& part_die
->name
!= NULL
)
5620 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5621 VAR_DOMAIN
, LOC_TYPEDEF
,
5622 &cu
->objfile
->static_psymbols
,
5623 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5624 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5628 /* If we're at the second level, and we're an enumerator, and
5629 our parent has no specification (meaning possibly lives in a
5630 namespace elsewhere), then we can add the partial symbol now
5631 instead of queueing it. */
5632 if (part_die
->tag
== DW_TAG_enumerator
5633 && parent_die
!= NULL
5634 && parent_die
->die_parent
== NULL
5635 && parent_die
->tag
== DW_TAG_enumeration_type
5636 && parent_die
->has_specification
== 0)
5638 if (part_die
->name
== NULL
)
5639 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5640 else if (building_psymtab
)
5641 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5642 VAR_DOMAIN
, LOC_CONST
,
5643 (cu
->language
== language_cplus
5644 || cu
->language
== language_java
)
5645 ? &cu
->objfile
->global_psymbols
5646 : &cu
->objfile
->static_psymbols
,
5647 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5649 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5653 /* We'll save this DIE so link it in. */
5654 part_die
->die_parent
= parent_die
;
5655 part_die
->die_sibling
= NULL
;
5656 part_die
->die_child
= NULL
;
5658 if (last_die
&& last_die
== parent_die
)
5659 last_die
->die_child
= part_die
;
5661 last_die
->die_sibling
= part_die
;
5663 last_die
= part_die
;
5665 if (first_die
== NULL
)
5666 first_die
= part_die
;
5668 /* Maybe add the DIE to the hash table. Not all DIEs that we
5669 find interesting need to be in the hash table, because we
5670 also have the parent/sibling/child chains; only those that we
5671 might refer to by offset later during partial symbol reading.
5673 For now this means things that might have be the target of a
5674 DW_AT_specification, DW_AT_abstract_origin, or
5675 DW_AT_extension. DW_AT_extension will refer only to
5676 namespaces; DW_AT_abstract_origin refers to functions (and
5677 many things under the function DIE, but we do not recurse
5678 into function DIEs during partial symbol reading) and
5679 possibly variables as well; DW_AT_specification refers to
5680 declarations. Declarations ought to have the DW_AT_declaration
5681 flag. It happens that GCC forgets to put it in sometimes, but
5682 only for functions, not for types.
5684 Adding more things than necessary to the hash table is harmless
5685 except for the performance cost. Adding too few will result in
5686 wasted time in find_partial_die, when we reread the compilation
5687 unit with load_all_dies set. */
5690 || abbrev
->tag
== DW_TAG_subprogram
5691 || abbrev
->tag
== DW_TAG_variable
5692 || abbrev
->tag
== DW_TAG_namespace
5693 || part_die
->is_declaration
)
5697 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5698 part_die
->offset
, INSERT
);
5702 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5703 sizeof (struct partial_die_info
));
5705 /* For some DIEs we want to follow their children (if any). For C
5706 we have no reason to follow the children of structures; for other
5707 languages we have to, both so that we can get at method physnames
5708 to infer fully qualified class names, and for DW_AT_specification. */
5709 if (last_die
->has_children
5711 || last_die
->tag
== DW_TAG_namespace
5712 || last_die
->tag
== DW_TAG_enumeration_type
5713 || (cu
->language
!= language_c
5714 && (last_die
->tag
== DW_TAG_class_type
5715 || last_die
->tag
== DW_TAG_interface_type
5716 || last_die
->tag
== DW_TAG_structure_type
5717 || last_die
->tag
== DW_TAG_union_type
))))
5720 parent_die
= last_die
;
5724 /* Otherwise we skip to the next sibling, if any. */
5725 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5727 /* Back to the top, do it again. */
5731 /* Read a minimal amount of information into the minimal die structure. */
5734 read_partial_die (struct partial_die_info
*part_die
,
5735 struct abbrev_info
*abbrev
,
5736 unsigned int abbrev_len
, bfd
*abfd
,
5737 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5739 unsigned int bytes_read
, i
;
5740 struct attribute attr
;
5741 int has_low_pc_attr
= 0;
5742 int has_high_pc_attr
= 0;
5743 CORE_ADDR base_address
= 0;
5747 base_address_low_pc
,
5748 /* Overrides BASE_ADDRESS_LOW_PC. */
5749 base_address_entry_pc
5751 base_address_type
= base_address_none
;
5753 memset (part_die
, 0, sizeof (struct partial_die_info
));
5755 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5757 info_ptr
+= abbrev_len
;
5762 part_die
->tag
= abbrev
->tag
;
5763 part_die
->has_children
= abbrev
->has_children
;
5765 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5767 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5769 /* Store the data if it is of an attribute we want to keep in a
5770 partial symbol table. */
5775 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5776 if (part_die
->name
== NULL
)
5777 part_die
->name
= DW_STRING (&attr
);
5779 case DW_AT_comp_dir
:
5780 if (part_die
->dirname
== NULL
)
5781 part_die
->dirname
= DW_STRING (&attr
);
5783 case DW_AT_MIPS_linkage_name
:
5784 part_die
->name
= DW_STRING (&attr
);
5787 has_low_pc_attr
= 1;
5788 part_die
->lowpc
= DW_ADDR (&attr
);
5789 if (part_die
->tag
== DW_TAG_compile_unit
5790 && base_address_type
< base_address_low_pc
)
5792 base_address
= DW_ADDR (&attr
);
5793 base_address_type
= base_address_low_pc
;
5797 has_high_pc_attr
= 1;
5798 part_die
->highpc
= DW_ADDR (&attr
);
5800 case DW_AT_entry_pc
:
5801 if (part_die
->tag
== DW_TAG_compile_unit
5802 && base_address_type
< base_address_entry_pc
)
5804 base_address
= DW_ADDR (&attr
);
5805 base_address_type
= base_address_entry_pc
;
5809 if (part_die
->tag
== DW_TAG_compile_unit
)
5811 cu
->ranges_offset
= DW_UNSND (&attr
);
5812 cu
->has_ranges_offset
= 1;
5815 case DW_AT_location
:
5816 /* Support the .debug_loc offsets */
5817 if (attr_form_is_block (&attr
))
5819 part_die
->locdesc
= DW_BLOCK (&attr
);
5821 else if (attr_form_is_section_offset (&attr
))
5823 dwarf2_complex_location_expr_complaint ();
5827 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5828 "partial symbol information");
5831 case DW_AT_language
:
5832 part_die
->language
= DW_UNSND (&attr
);
5834 case DW_AT_external
:
5835 part_die
->is_external
= DW_UNSND (&attr
);
5837 case DW_AT_declaration
:
5838 part_die
->is_declaration
= DW_UNSND (&attr
);
5841 part_die
->has_type
= 1;
5843 case DW_AT_abstract_origin
:
5844 case DW_AT_specification
:
5845 case DW_AT_extension
:
5846 part_die
->has_specification
= 1;
5847 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5850 /* Ignore absolute siblings, they might point outside of
5851 the current compile unit. */
5852 if (attr
.form
== DW_FORM_ref_addr
)
5853 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5855 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5856 + dwarf2_get_ref_die_offset (&attr
, cu
);
5858 case DW_AT_stmt_list
:
5859 part_die
->has_stmt_list
= 1;
5860 part_die
->line_offset
= DW_UNSND (&attr
);
5862 case DW_AT_byte_size
:
5863 part_die
->has_byte_size
= 1;
5865 case DW_AT_calling_convention
:
5866 /* DWARF doesn't provide a way to identify a program's source-level
5867 entry point. DW_AT_calling_convention attributes are only meant
5868 to describe functions' calling conventions.
5870 However, because it's a necessary piece of information in
5871 Fortran, and because DW_CC_program is the only piece of debugging
5872 information whose definition refers to a 'main program' at all,
5873 several compilers have begun marking Fortran main programs with
5874 DW_CC_program --- even when those functions use the standard
5875 calling conventions.
5877 So until DWARF specifies a way to provide this information and
5878 compilers pick up the new representation, we'll support this
5880 if (DW_UNSND (&attr
) == DW_CC_program
5881 && cu
->language
== language_fortran
)
5882 set_main_name (part_die
->name
);
5889 /* When using the GNU linker, .gnu.linkonce. sections are used to
5890 eliminate duplicate copies of functions and vtables and such.
5891 The linker will arbitrarily choose one and discard the others.
5892 The AT_*_pc values for such functions refer to local labels in
5893 these sections. If the section from that file was discarded, the
5894 labels are not in the output, so the relocs get a value of 0.
5895 If this is a discarded function, mark the pc bounds as invalid,
5896 so that GDB will ignore it. */
5897 if (has_low_pc_attr
&& has_high_pc_attr
5898 && part_die
->lowpc
< part_die
->highpc
5899 && (part_die
->lowpc
!= 0
5900 || dwarf2_per_objfile
->has_section_at_zero
))
5901 part_die
->has_pc_info
= 1;
5903 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
5905 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5906 cu
->header
.base_known
= 1;
5907 cu
->header
.base_address
= base_address
;
5913 /* Find a cached partial DIE at OFFSET in CU. */
5915 static struct partial_die_info
*
5916 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5918 struct partial_die_info
*lookup_die
= NULL
;
5919 struct partial_die_info part_die
;
5921 part_die
.offset
= offset
;
5922 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5927 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5929 static struct partial_die_info
*
5930 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5932 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5933 struct partial_die_info
*pd
= NULL
;
5935 if (offset
>= cu
->header
.offset
5936 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5938 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5943 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5945 if (per_cu
->cu
== NULL
)
5947 load_comp_unit (per_cu
, cu
->objfile
);
5948 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5949 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5952 per_cu
->cu
->last_used
= 0;
5953 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5955 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5957 struct cleanup
*back_to
;
5958 struct partial_die_info comp_unit_die
;
5959 struct abbrev_info
*abbrev
;
5960 unsigned int bytes_read
;
5963 per_cu
->load_all_dies
= 1;
5965 /* Re-read the DIEs. */
5966 back_to
= make_cleanup (null_cleanup
, 0);
5967 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5969 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5970 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5972 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
5973 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5974 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5975 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5977 if (comp_unit_die
.has_children
)
5978 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5979 do_cleanups (back_to
);
5981 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5985 internal_error (__FILE__
, __LINE__
,
5986 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
5987 offset
, bfd_get_filename (cu
->objfile
->obfd
));
5991 /* Adjust PART_DIE before generating a symbol for it. This function
5992 may set the is_external flag or change the DIE's name. */
5995 fixup_partial_die (struct partial_die_info
*part_die
,
5996 struct dwarf2_cu
*cu
)
5998 /* If we found a reference attribute and the DIE has no name, try
5999 to find a name in the referred to DIE. */
6001 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6003 struct partial_die_info
*spec_die
;
6005 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6007 fixup_partial_die (spec_die
, cu
);
6011 part_die
->name
= spec_die
->name
;
6013 /* Copy DW_AT_external attribute if it is set. */
6014 if (spec_die
->is_external
)
6015 part_die
->is_external
= spec_die
->is_external
;
6019 /* Set default names for some unnamed DIEs. */
6020 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6021 || part_die
->tag
== DW_TAG_class_type
))
6022 part_die
->name
= "(anonymous class)";
6024 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6025 part_die
->name
= "(anonymous namespace)";
6027 if (part_die
->tag
== DW_TAG_structure_type
6028 || part_die
->tag
== DW_TAG_class_type
6029 || part_die
->tag
== DW_TAG_union_type
)
6030 guess_structure_name (part_die
, cu
);
6033 /* Read the die from the .debug_info section buffer. Set DIEP to
6034 point to a newly allocated die with its information, except for its
6035 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6036 whether the die has children or not. */
6039 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6040 struct dwarf2_cu
*cu
, int *has_children
)
6042 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6043 struct abbrev_info
*abbrev
;
6044 struct die_info
*die
;
6046 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6047 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6048 info_ptr
+= bytes_read
;
6051 die
= dwarf_alloc_die ();
6053 die
->abbrev
= abbrev_number
;
6059 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6062 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6064 bfd_get_filename (abfd
));
6066 die
= dwarf_alloc_die ();
6067 die
->offset
= offset
;
6068 die
->tag
= abbrev
->tag
;
6069 die
->abbrev
= abbrev_number
;
6071 die
->num_attrs
= abbrev
->num_attrs
;
6072 die
->attrs
= (struct attribute
*)
6073 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
6075 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6077 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6078 abfd
, info_ptr
, cu
);
6080 /* If this attribute is an absolute reference to a different
6081 compilation unit, make sure that compilation unit is loaded
6083 if (die
->attrs
[i
].form
== DW_FORM_ref_addr
6084 && (DW_ADDR (&die
->attrs
[i
]) < cu
->header
.offset
6085 || (DW_ADDR (&die
->attrs
[i
])
6086 >= cu
->header
.offset
+ cu
->header
.length
)))
6088 struct dwarf2_per_cu_data
*per_cu
;
6089 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (&die
->attrs
[i
]),
6092 /* Mark the dependence relation so that we don't flush PER_CU
6094 dwarf2_add_dependence (cu
, per_cu
);
6096 /* If it's already on the queue, we have nothing to do. */
6100 /* If the compilation unit is already loaded, just mark it as
6102 if (per_cu
->cu
!= NULL
)
6104 per_cu
->cu
->last_used
= 0;
6108 /* Add it to the queue. */
6109 queue_comp_unit (per_cu
);
6114 *has_children
= abbrev
->has_children
;
6118 /* Read an attribute value described by an attribute form. */
6121 read_attribute_value (struct attribute
*attr
, unsigned form
,
6122 bfd
*abfd
, gdb_byte
*info_ptr
,
6123 struct dwarf2_cu
*cu
)
6125 struct comp_unit_head
*cu_header
= &cu
->header
;
6126 unsigned int bytes_read
;
6127 struct dwarf_block
*blk
;
6133 case DW_FORM_ref_addr
:
6134 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6135 info_ptr
+= bytes_read
;
6137 case DW_FORM_block2
:
6138 blk
= dwarf_alloc_block (cu
);
6139 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6141 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6142 info_ptr
+= blk
->size
;
6143 DW_BLOCK (attr
) = blk
;
6145 case DW_FORM_block4
:
6146 blk
= dwarf_alloc_block (cu
);
6147 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6149 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6150 info_ptr
+= blk
->size
;
6151 DW_BLOCK (attr
) = blk
;
6154 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6158 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6162 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6165 case DW_FORM_string
:
6166 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6167 info_ptr
+= bytes_read
;
6170 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6172 info_ptr
+= bytes_read
;
6175 blk
= dwarf_alloc_block (cu
);
6176 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6177 info_ptr
+= bytes_read
;
6178 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6179 info_ptr
+= blk
->size
;
6180 DW_BLOCK (attr
) = blk
;
6182 case DW_FORM_block1
:
6183 blk
= dwarf_alloc_block (cu
);
6184 blk
->size
= read_1_byte (abfd
, info_ptr
);
6186 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6187 info_ptr
+= blk
->size
;
6188 DW_BLOCK (attr
) = blk
;
6191 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6195 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6199 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6200 info_ptr
+= bytes_read
;
6203 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6204 info_ptr
+= bytes_read
;
6207 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6211 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6215 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6219 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6222 case DW_FORM_ref_udata
:
6223 DW_ADDR (attr
) = (cu
->header
.offset
6224 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6225 info_ptr
+= bytes_read
;
6227 case DW_FORM_indirect
:
6228 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6229 info_ptr
+= bytes_read
;
6230 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6233 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6234 dwarf_form_name (form
),
6235 bfd_get_filename (abfd
));
6238 /* We have seen instances where the compiler tried to emit a byte
6239 size attribute of -1 which ended up being encoded as an unsigned
6240 0xffffffff. Although 0xffffffff is technically a valid size value,
6241 an object of this size seems pretty unlikely so we can relatively
6242 safely treat these cases as if the size attribute was invalid and
6243 treat them as zero by default. */
6244 if (attr
->name
== DW_AT_byte_size
6245 && form
== DW_FORM_data4
6246 && DW_UNSND (attr
) >= 0xffffffff)
6249 (&symfile_complaints
,
6250 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6252 DW_UNSND (attr
) = 0;
6258 /* Read an attribute described by an abbreviated attribute. */
6261 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6262 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6264 attr
->name
= abbrev
->name
;
6265 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6268 /* read dwarf information from a buffer */
6271 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6273 return bfd_get_8 (abfd
, buf
);
6277 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6279 return bfd_get_signed_8 (abfd
, buf
);
6283 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6285 return bfd_get_16 (abfd
, buf
);
6289 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6291 return bfd_get_signed_16 (abfd
, buf
);
6295 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6297 return bfd_get_32 (abfd
, buf
);
6301 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6303 return bfd_get_signed_32 (abfd
, buf
);
6306 static unsigned long
6307 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6309 return bfd_get_64 (abfd
, buf
);
6313 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6314 unsigned int *bytes_read
)
6316 struct comp_unit_head
*cu_header
= &cu
->header
;
6317 CORE_ADDR retval
= 0;
6319 if (cu_header
->signed_addr_p
)
6321 switch (cu_header
->addr_size
)
6324 retval
= bfd_get_signed_16 (abfd
, buf
);
6327 retval
= bfd_get_signed_32 (abfd
, buf
);
6330 retval
= bfd_get_signed_64 (abfd
, buf
);
6333 internal_error (__FILE__
, __LINE__
,
6334 _("read_address: bad switch, signed [in module %s]"),
6335 bfd_get_filename (abfd
));
6340 switch (cu_header
->addr_size
)
6343 retval
= bfd_get_16 (abfd
, buf
);
6346 retval
= bfd_get_32 (abfd
, buf
);
6349 retval
= bfd_get_64 (abfd
, buf
);
6352 internal_error (__FILE__
, __LINE__
,
6353 _("read_address: bad switch, unsigned [in module %s]"),
6354 bfd_get_filename (abfd
));
6358 *bytes_read
= cu_header
->addr_size
;
6362 /* Read the initial length from a section. The (draft) DWARF 3
6363 specification allows the initial length to take up either 4 bytes
6364 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6365 bytes describe the length and all offsets will be 8 bytes in length
6368 An older, non-standard 64-bit format is also handled by this
6369 function. The older format in question stores the initial length
6370 as an 8-byte quantity without an escape value. Lengths greater
6371 than 2^32 aren't very common which means that the initial 4 bytes
6372 is almost always zero. Since a length value of zero doesn't make
6373 sense for the 32-bit format, this initial zero can be considered to
6374 be an escape value which indicates the presence of the older 64-bit
6375 format. As written, the code can't detect (old format) lengths
6376 greater than 4GB. If it becomes necessary to handle lengths
6377 somewhat larger than 4GB, we could allow other small values (such
6378 as the non-sensical values of 1, 2, and 3) to also be used as
6379 escape values indicating the presence of the old format.
6381 The value returned via bytes_read should be used to increment the
6382 relevant pointer after calling read_initial_length().
6384 As a side effect, this function sets the fields initial_length_size
6385 and offset_size in cu_header to the values appropriate for the
6386 length field. (The format of the initial length field determines
6387 the width of file offsets to be fetched later with read_offset().)
6389 [ Note: read_initial_length() and read_offset() are based on the
6390 document entitled "DWARF Debugging Information Format", revision
6391 3, draft 8, dated November 19, 2001. This document was obtained
6394 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6396 This document is only a draft and is subject to change. (So beware.)
6398 Details regarding the older, non-standard 64-bit format were
6399 determined empirically by examining 64-bit ELF files produced by
6400 the SGI toolchain on an IRIX 6.5 machine.
6402 - Kevin, July 16, 2002
6406 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6407 unsigned int *bytes_read
)
6409 LONGEST length
= bfd_get_32 (abfd
, buf
);
6411 if (length
== 0xffffffff)
6413 length
= bfd_get_64 (abfd
, buf
+ 4);
6416 else if (length
== 0)
6418 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6419 length
= bfd_get_64 (abfd
, buf
);
6429 gdb_assert (cu_header
->initial_length_size
== 0
6430 || cu_header
->initial_length_size
== 4
6431 || cu_header
->initial_length_size
== 8
6432 || cu_header
->initial_length_size
== 12);
6434 if (cu_header
->initial_length_size
!= 0
6435 && cu_header
->initial_length_size
!= *bytes_read
)
6436 complaint (&symfile_complaints
,
6437 _("intermixed 32-bit and 64-bit DWARF sections"));
6439 cu_header
->initial_length_size
= *bytes_read
;
6440 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6446 /* Read an offset from the data stream. The size of the offset is
6447 given by cu_header->offset_size. */
6450 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6451 unsigned int *bytes_read
)
6455 switch (cu_header
->offset_size
)
6458 retval
= bfd_get_32 (abfd
, buf
);
6462 retval
= bfd_get_64 (abfd
, buf
);
6466 internal_error (__FILE__
, __LINE__
,
6467 _("read_offset: bad switch [in module %s]"),
6468 bfd_get_filename (abfd
));
6475 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6477 /* If the size of a host char is 8 bits, we can return a pointer
6478 to the buffer, otherwise we have to copy the data to a buffer
6479 allocated on the temporary obstack. */
6480 gdb_assert (HOST_CHAR_BIT
== 8);
6485 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6487 /* If the size of a host char is 8 bits, we can return a pointer
6488 to the string, otherwise we have to copy the string to a buffer
6489 allocated on the temporary obstack. */
6490 gdb_assert (HOST_CHAR_BIT
== 8);
6493 *bytes_read_ptr
= 1;
6496 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6497 return (char *) buf
;
6501 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6502 const struct comp_unit_head
*cu_header
,
6503 unsigned int *bytes_read_ptr
)
6505 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6508 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6510 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6511 bfd_get_filename (abfd
));
6514 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6516 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6517 bfd_get_filename (abfd
));
6520 gdb_assert (HOST_CHAR_BIT
== 8);
6521 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6523 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6526 static unsigned long
6527 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6529 unsigned long result
;
6530 unsigned int num_read
;
6540 byte
= bfd_get_8 (abfd
, buf
);
6543 result
|= ((unsigned long)(byte
& 127) << shift
);
6544 if ((byte
& 128) == 0)
6550 *bytes_read_ptr
= num_read
;
6555 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6558 int i
, shift
, num_read
;
6567 byte
= bfd_get_8 (abfd
, buf
);
6570 result
|= ((long)(byte
& 127) << shift
);
6572 if ((byte
& 128) == 0)
6577 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6578 result
|= -(((long)1) << shift
);
6579 *bytes_read_ptr
= num_read
;
6583 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6586 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6592 byte
= bfd_get_8 (abfd
, buf
);
6594 if ((byte
& 128) == 0)
6600 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6606 cu
->language
= language_c
;
6608 case DW_LANG_C_plus_plus
:
6609 cu
->language
= language_cplus
;
6611 case DW_LANG_Fortran77
:
6612 case DW_LANG_Fortran90
:
6613 case DW_LANG_Fortran95
:
6614 cu
->language
= language_fortran
;
6616 case DW_LANG_Mips_Assembler
:
6617 cu
->language
= language_asm
;
6620 cu
->language
= language_java
;
6624 cu
->language
= language_ada
;
6626 case DW_LANG_Modula2
:
6627 cu
->language
= language_m2
;
6629 case DW_LANG_Pascal83
:
6630 cu
->language
= language_pascal
;
6633 cu
->language
= language_objc
;
6635 case DW_LANG_Cobol74
:
6636 case DW_LANG_Cobol85
:
6638 cu
->language
= language_minimal
;
6641 cu
->language_defn
= language_def (cu
->language
);
6644 /* Return the named attribute or NULL if not there. */
6646 static struct attribute
*
6647 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6650 struct attribute
*spec
= NULL
;
6652 for (i
= 0; i
< die
->num_attrs
; ++i
)
6654 if (die
->attrs
[i
].name
== name
)
6655 return &die
->attrs
[i
];
6656 if (die
->attrs
[i
].name
== DW_AT_specification
6657 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6658 spec
= &die
->attrs
[i
];
6662 return dwarf2_attr (follow_die_ref (die
, spec
, cu
), name
, cu
);
6667 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6668 and holds a non-zero value. This function should only be used for
6669 DW_FORM_flag attributes. */
6672 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6674 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6676 return (attr
&& DW_UNSND (attr
));
6680 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6682 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6683 which value is non-zero. However, we have to be careful with
6684 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6685 (via dwarf2_flag_true_p) follows this attribute. So we may
6686 end up accidently finding a declaration attribute that belongs
6687 to a different DIE referenced by the specification attribute,
6688 even though the given DIE does not have a declaration attribute. */
6689 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6690 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6693 /* Return the die giving the specification for DIE, if there is
6696 static struct die_info
*
6697 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6699 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6701 if (spec_attr
== NULL
)
6704 return follow_die_ref (die
, spec_attr
, cu
);
6707 /* Free the line_header structure *LH, and any arrays and strings it
6710 free_line_header (struct line_header
*lh
)
6712 if (lh
->standard_opcode_lengths
)
6713 xfree (lh
->standard_opcode_lengths
);
6715 /* Remember that all the lh->file_names[i].name pointers are
6716 pointers into debug_line_buffer, and don't need to be freed. */
6718 xfree (lh
->file_names
);
6720 /* Similarly for the include directory names. */
6721 if (lh
->include_dirs
)
6722 xfree (lh
->include_dirs
);
6728 /* Add an entry to LH's include directory table. */
6730 add_include_dir (struct line_header
*lh
, char *include_dir
)
6732 /* Grow the array if necessary. */
6733 if (lh
->include_dirs_size
== 0)
6735 lh
->include_dirs_size
= 1; /* for testing */
6736 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6737 * sizeof (*lh
->include_dirs
));
6739 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6741 lh
->include_dirs_size
*= 2;
6742 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6743 (lh
->include_dirs_size
6744 * sizeof (*lh
->include_dirs
)));
6747 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6751 /* Add an entry to LH's file name table. */
6753 add_file_name (struct line_header
*lh
,
6755 unsigned int dir_index
,
6756 unsigned int mod_time
,
6757 unsigned int length
)
6759 struct file_entry
*fe
;
6761 /* Grow the array if necessary. */
6762 if (lh
->file_names_size
== 0)
6764 lh
->file_names_size
= 1; /* for testing */
6765 lh
->file_names
= xmalloc (lh
->file_names_size
6766 * sizeof (*lh
->file_names
));
6768 else if (lh
->num_file_names
>= lh
->file_names_size
)
6770 lh
->file_names_size
*= 2;
6771 lh
->file_names
= xrealloc (lh
->file_names
,
6772 (lh
->file_names_size
6773 * sizeof (*lh
->file_names
)));
6776 fe
= &lh
->file_names
[lh
->num_file_names
++];
6778 fe
->dir_index
= dir_index
;
6779 fe
->mod_time
= mod_time
;
6780 fe
->length
= length
;
6786 /* Read the statement program header starting at OFFSET in
6787 .debug_line, according to the endianness of ABFD. Return a pointer
6788 to a struct line_header, allocated using xmalloc.
6790 NOTE: the strings in the include directory and file name tables of
6791 the returned object point into debug_line_buffer, and must not be
6793 static struct line_header
*
6794 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6795 struct dwarf2_cu
*cu
)
6797 struct cleanup
*back_to
;
6798 struct line_header
*lh
;
6800 unsigned int bytes_read
;
6802 char *cur_dir
, *cur_file
;
6804 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6806 complaint (&symfile_complaints
, _("missing .debug_line section"));
6810 /* Make sure that at least there's room for the total_length field.
6811 That could be 12 bytes long, but we're just going to fudge that. */
6812 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6814 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6818 lh
= xmalloc (sizeof (*lh
));
6819 memset (lh
, 0, sizeof (*lh
));
6820 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6823 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6825 /* Read in the header. */
6827 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6828 line_ptr
+= bytes_read
;
6829 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6830 + dwarf2_per_objfile
->line_size
))
6832 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6835 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6836 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6838 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6839 line_ptr
+= bytes_read
;
6840 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6842 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6844 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6846 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6848 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6850 lh
->standard_opcode_lengths
6851 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6853 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6854 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6856 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6860 /* Read directory table. */
6861 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6863 line_ptr
+= bytes_read
;
6864 add_include_dir (lh
, cur_dir
);
6866 line_ptr
+= bytes_read
;
6868 /* Read file name table. */
6869 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6871 unsigned int dir_index
, mod_time
, length
;
6873 line_ptr
+= bytes_read
;
6874 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6875 line_ptr
+= bytes_read
;
6876 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6877 line_ptr
+= bytes_read
;
6878 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6879 line_ptr
+= bytes_read
;
6881 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6883 line_ptr
+= bytes_read
;
6884 lh
->statement_program_start
= line_ptr
;
6886 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6887 + dwarf2_per_objfile
->line_size
))
6888 complaint (&symfile_complaints
,
6889 _("line number info header doesn't fit in `.debug_line' section"));
6891 discard_cleanups (back_to
);
6895 /* This function exists to work around a bug in certain compilers
6896 (particularly GCC 2.95), in which the first line number marker of a
6897 function does not show up until after the prologue, right before
6898 the second line number marker. This function shifts ADDRESS down
6899 to the beginning of the function if necessary, and is called on
6900 addresses passed to record_line. */
6903 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6905 struct function_range
*fn
;
6907 /* Find the function_range containing address. */
6912 cu
->cached_fn
= cu
->first_fn
;
6916 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6922 while (fn
&& fn
!= cu
->cached_fn
)
6923 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6933 if (address
!= fn
->lowpc
)
6934 complaint (&symfile_complaints
,
6935 _("misplaced first line number at 0x%lx for '%s'"),
6936 (unsigned long) address
, fn
->name
);
6941 /* Decode the Line Number Program (LNP) for the given line_header
6942 structure and CU. The actual information extracted and the type
6943 of structures created from the LNP depends on the value of PST.
6945 1. If PST is NULL, then this procedure uses the data from the program
6946 to create all necessary symbol tables, and their linetables.
6947 The compilation directory of the file is passed in COMP_DIR,
6948 and must not be NULL.
6950 2. If PST is not NULL, this procedure reads the program to determine
6951 the list of files included by the unit represented by PST, and
6952 builds all the associated partial symbol tables. In this case,
6953 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6954 is not used to compute the full name of the symtab, and therefore
6955 omitting it when building the partial symtab does not introduce
6956 the potential for inconsistency - a partial symtab and its associated
6957 symbtab having a different fullname -). */
6960 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6961 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6963 gdb_byte
*line_ptr
, *extended_end
;
6965 unsigned int bytes_read
, extended_len
;
6966 unsigned char op_code
, extended_op
, adj_opcode
;
6968 struct objfile
*objfile
= cu
->objfile
;
6969 const int decode_for_pst_p
= (pst
!= NULL
);
6970 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6972 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6974 line_ptr
= lh
->statement_program_start
;
6975 line_end
= lh
->statement_program_end
;
6977 /* Read the statement sequences until there's nothing left. */
6978 while (line_ptr
< line_end
)
6980 /* state machine registers */
6981 CORE_ADDR address
= 0;
6982 unsigned int file
= 1;
6983 unsigned int line
= 1;
6984 unsigned int column
= 0;
6985 int is_stmt
= lh
->default_is_stmt
;
6986 int basic_block
= 0;
6987 int end_sequence
= 0;
6989 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6991 /* Start a subfile for the current file of the state machine. */
6992 /* lh->include_dirs and lh->file_names are 0-based, but the
6993 directory and file name numbers in the statement program
6995 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6999 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7001 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7004 /* Decode the table. */
7005 while (!end_sequence
)
7007 op_code
= read_1_byte (abfd
, line_ptr
);
7010 if (op_code
>= lh
->opcode_base
)
7012 /* Special operand. */
7013 adj_opcode
= op_code
- lh
->opcode_base
;
7014 address
+= (adj_opcode
/ lh
->line_range
)
7015 * lh
->minimum_instruction_length
;
7016 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7017 if (lh
->num_file_names
< file
)
7018 dwarf2_debug_line_missing_file_complaint ();
7021 lh
->file_names
[file
- 1].included_p
= 1;
7022 if (!decode_for_pst_p
)
7024 if (last_subfile
!= current_subfile
)
7027 record_line (last_subfile
, 0, address
);
7028 last_subfile
= current_subfile
;
7030 /* Append row to matrix using current values. */
7031 record_line (current_subfile
, line
,
7032 check_cu_functions (address
, cu
));
7037 else switch (op_code
)
7039 case DW_LNS_extended_op
:
7040 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7041 line_ptr
+= bytes_read
;
7042 extended_end
= line_ptr
+ extended_len
;
7043 extended_op
= read_1_byte (abfd
, line_ptr
);
7045 switch (extended_op
)
7047 case DW_LNE_end_sequence
:
7050 if (lh
->num_file_names
< file
)
7051 dwarf2_debug_line_missing_file_complaint ();
7054 lh
->file_names
[file
- 1].included_p
= 1;
7055 if (!decode_for_pst_p
)
7056 record_line (current_subfile
, 0, address
);
7059 case DW_LNE_set_address
:
7060 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7061 line_ptr
+= bytes_read
;
7062 address
+= baseaddr
;
7064 case DW_LNE_define_file
:
7067 unsigned int dir_index
, mod_time
, length
;
7069 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7070 line_ptr
+= bytes_read
;
7072 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7073 line_ptr
+= bytes_read
;
7075 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7076 line_ptr
+= bytes_read
;
7078 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7079 line_ptr
+= bytes_read
;
7080 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7084 complaint (&symfile_complaints
,
7085 _("mangled .debug_line section"));
7088 /* Make sure that we parsed the extended op correctly. If e.g.
7089 we expected a different address size than the producer used,
7090 we may have read the wrong number of bytes. */
7091 if (line_ptr
!= extended_end
)
7093 complaint (&symfile_complaints
,
7094 _("mangled .debug_line section"));
7099 if (lh
->num_file_names
< file
)
7100 dwarf2_debug_line_missing_file_complaint ();
7103 lh
->file_names
[file
- 1].included_p
= 1;
7104 if (!decode_for_pst_p
)
7106 if (last_subfile
!= current_subfile
)
7109 record_line (last_subfile
, 0, address
);
7110 last_subfile
= current_subfile
;
7112 record_line (current_subfile
, line
,
7113 check_cu_functions (address
, cu
));
7118 case DW_LNS_advance_pc
:
7119 address
+= lh
->minimum_instruction_length
7120 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7121 line_ptr
+= bytes_read
;
7123 case DW_LNS_advance_line
:
7124 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7125 line_ptr
+= bytes_read
;
7127 case DW_LNS_set_file
:
7129 /* The arrays lh->include_dirs and lh->file_names are
7130 0-based, but the directory and file name numbers in
7131 the statement program are 1-based. */
7132 struct file_entry
*fe
;
7135 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7136 line_ptr
+= bytes_read
;
7137 if (lh
->num_file_names
< file
)
7138 dwarf2_debug_line_missing_file_complaint ();
7141 fe
= &lh
->file_names
[file
- 1];
7143 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7144 if (!decode_for_pst_p
)
7146 last_subfile
= current_subfile
;
7147 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7152 case DW_LNS_set_column
:
7153 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7154 line_ptr
+= bytes_read
;
7156 case DW_LNS_negate_stmt
:
7157 is_stmt
= (!is_stmt
);
7159 case DW_LNS_set_basic_block
:
7162 /* Add to the address register of the state machine the
7163 address increment value corresponding to special opcode
7164 255. I.e., this value is scaled by the minimum
7165 instruction length since special opcode 255 would have
7166 scaled the the increment. */
7167 case DW_LNS_const_add_pc
:
7168 address
+= (lh
->minimum_instruction_length
7169 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7171 case DW_LNS_fixed_advance_pc
:
7172 address
+= read_2_bytes (abfd
, line_ptr
);
7177 /* Unknown standard opcode, ignore it. */
7180 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7182 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7183 line_ptr
+= bytes_read
;
7190 if (decode_for_pst_p
)
7194 /* Now that we're done scanning the Line Header Program, we can
7195 create the psymtab of each included file. */
7196 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7197 if (lh
->file_names
[file_index
].included_p
== 1)
7199 const struct file_entry fe
= lh
->file_names
[file_index
];
7200 char *include_name
= fe
.name
;
7201 char *dir_name
= NULL
;
7202 char *pst_filename
= pst
->filename
;
7205 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7207 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7209 include_name
= concat (dir_name
, SLASH_STRING
,
7210 include_name
, (char *)NULL
);
7211 make_cleanup (xfree
, include_name
);
7214 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7216 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7217 pst_filename
, (char *)NULL
);
7218 make_cleanup (xfree
, pst_filename
);
7221 if (strcmp (include_name
, pst_filename
) != 0)
7222 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7227 /* Make sure a symtab is created for every file, even files
7228 which contain only variables (i.e. no code with associated
7232 struct file_entry
*fe
;
7234 for (i
= 0; i
< lh
->num_file_names
; i
++)
7237 fe
= &lh
->file_names
[i
];
7239 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7240 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7242 /* Skip the main file; we don't need it, and it must be
7243 allocated last, so that it will show up before the
7244 non-primary symtabs in the objfile's symtab list. */
7245 if (current_subfile
== first_subfile
)
7248 if (current_subfile
->symtab
== NULL
)
7249 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7251 fe
->symtab
= current_subfile
->symtab
;
7256 /* Start a subfile for DWARF. FILENAME is the name of the file and
7257 DIRNAME the name of the source directory which contains FILENAME
7258 or NULL if not known. COMP_DIR is the compilation directory for the
7259 linetable's compilation unit or NULL if not known.
7260 This routine tries to keep line numbers from identical absolute and
7261 relative file names in a common subfile.
7263 Using the `list' example from the GDB testsuite, which resides in
7264 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7265 of /srcdir/list0.c yields the following debugging information for list0.c:
7267 DW_AT_name: /srcdir/list0.c
7268 DW_AT_comp_dir: /compdir
7269 files.files[0].name: list0.h
7270 files.files[0].dir: /srcdir
7271 files.files[1].name: list0.c
7272 files.files[1].dir: /srcdir
7274 The line number information for list0.c has to end up in a single
7275 subfile, so that `break /srcdir/list0.c:1' works as expected.
7276 start_subfile will ensure that this happens provided that we pass the
7277 concatenation of files.files[1].dir and files.files[1].name as the
7281 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7285 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7286 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7287 second argument to start_subfile. To be consistent, we do the
7288 same here. In order not to lose the line information directory,
7289 we concatenate it to the filename when it makes sense.
7290 Note that the Dwarf3 standard says (speaking of filenames in line
7291 information): ``The directory index is ignored for file names
7292 that represent full path names''. Thus ignoring dirname in the
7293 `else' branch below isn't an issue. */
7295 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7296 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7298 fullname
= filename
;
7300 start_subfile (fullname
, comp_dir
);
7302 if (fullname
!= filename
)
7307 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7308 struct dwarf2_cu
*cu
)
7310 struct objfile
*objfile
= cu
->objfile
;
7311 struct comp_unit_head
*cu_header
= &cu
->header
;
7313 /* NOTE drow/2003-01-30: There used to be a comment and some special
7314 code here to turn a symbol with DW_AT_external and a
7315 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7316 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7317 with some versions of binutils) where shared libraries could have
7318 relocations against symbols in their debug information - the
7319 minimal symbol would have the right address, but the debug info
7320 would not. It's no longer necessary, because we will explicitly
7321 apply relocations when we read in the debug information now. */
7323 /* A DW_AT_location attribute with no contents indicates that a
7324 variable has been optimized away. */
7325 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7327 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7331 /* Handle one degenerate form of location expression specially, to
7332 preserve GDB's previous behavior when section offsets are
7333 specified. If this is just a DW_OP_addr then mark this symbol
7336 if (attr_form_is_block (attr
)
7337 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7338 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7342 SYMBOL_VALUE_ADDRESS (sym
) =
7343 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7344 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7345 fixup_symbol_section (sym
, objfile
);
7346 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7347 SYMBOL_SECTION (sym
));
7351 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7352 expression evaluator, and use LOC_COMPUTED only when necessary
7353 (i.e. when the value of a register or memory location is
7354 referenced, or a thread-local block, etc.). Then again, it might
7355 not be worthwhile. I'm assuming that it isn't unless performance
7356 or memory numbers show me otherwise. */
7358 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7359 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7362 /* Given a pointer to a DWARF information entry, figure out if we need
7363 to make a symbol table entry for it, and if so, create a new entry
7364 and return a pointer to it.
7365 If TYPE is NULL, determine symbol type from the die, otherwise
7366 used the passed type. */
7368 static struct symbol
*
7369 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7371 struct objfile
*objfile
= cu
->objfile
;
7372 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7373 struct symbol
*sym
= NULL
;
7375 struct attribute
*attr
= NULL
;
7376 struct attribute
*attr2
= NULL
;
7379 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7381 if (die
->tag
!= DW_TAG_namespace
)
7382 name
= dwarf2_linkage_name (die
, cu
);
7384 name
= TYPE_NAME (type
);
7388 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7389 sizeof (struct symbol
));
7390 OBJSTAT (objfile
, n_syms
++);
7391 memset (sym
, 0, sizeof (struct symbol
));
7393 /* Cache this symbol's name and the name's demangled form (if any). */
7394 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7395 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7397 /* Default assumptions.
7398 Use the passed type or decode it from the die. */
7399 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7400 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7402 SYMBOL_TYPE (sym
) = type
;
7404 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7405 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7408 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7411 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7414 int file_index
= DW_UNSND (attr
);
7415 if (cu
->line_header
== NULL
7416 || file_index
> cu
->line_header
->num_file_names
)
7417 complaint (&symfile_complaints
,
7418 _("file index out of range"));
7419 else if (file_index
> 0)
7421 struct file_entry
*fe
;
7422 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7423 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7430 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7433 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7435 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7437 case DW_TAG_subprogram
:
7438 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7440 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7441 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7442 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7443 || cu
->language
== language_ada
)
7445 /* Subprograms marked external are stored as a global symbol.
7446 Ada subprograms, whether marked external or not, are always
7447 stored as a global symbol, because we want to be able to
7448 access them globally. For instance, we want to be able
7449 to break on a nested subprogram without having to
7450 specify the context. */
7451 add_symbol_to_list (sym
, &global_symbols
);
7455 add_symbol_to_list (sym
, cu
->list_in_scope
);
7458 case DW_TAG_variable
:
7459 /* Compilation with minimal debug info may result in variables
7460 with missing type entries. Change the misleading `void' type
7461 to something sensible. */
7462 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7464 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7466 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7469 dwarf2_const_value (attr
, sym
, cu
);
7470 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7471 if (attr2
&& (DW_UNSND (attr2
) != 0))
7472 add_symbol_to_list (sym
, &global_symbols
);
7474 add_symbol_to_list (sym
, cu
->list_in_scope
);
7477 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7480 var_decode_location (attr
, sym
, cu
);
7481 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7482 if (attr2
&& (DW_UNSND (attr2
) != 0))
7483 add_symbol_to_list (sym
, &global_symbols
);
7485 add_symbol_to_list (sym
, cu
->list_in_scope
);
7489 /* We do not know the address of this symbol.
7490 If it is an external symbol and we have type information
7491 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7492 The address of the variable will then be determined from
7493 the minimal symbol table whenever the variable is
7495 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7496 if (attr2
&& (DW_UNSND (attr2
) != 0)
7497 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7499 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7500 add_symbol_to_list (sym
, &global_symbols
);
7504 case DW_TAG_formal_parameter
:
7505 SYMBOL_IS_ARGUMENT (sym
) = 1;
7506 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7509 var_decode_location (attr
, sym
, cu
);
7511 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7514 dwarf2_const_value (attr
, sym
, cu
);
7516 add_symbol_to_list (sym
, cu
->list_in_scope
);
7518 case DW_TAG_unspecified_parameters
:
7519 /* From varargs functions; gdb doesn't seem to have any
7520 interest in this information, so just ignore it for now.
7523 case DW_TAG_class_type
:
7524 case DW_TAG_interface_type
:
7525 case DW_TAG_structure_type
:
7526 case DW_TAG_union_type
:
7527 case DW_TAG_set_type
:
7528 case DW_TAG_enumeration_type
:
7529 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7530 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7532 /* Make sure that the symbol includes appropriate enclosing
7533 classes/namespaces in its name. These are calculated in
7534 read_structure_type, and the correct name is saved in
7537 if (cu
->language
== language_cplus
7538 || cu
->language
== language_java
)
7540 struct type
*type
= SYMBOL_TYPE (sym
);
7542 if (TYPE_TAG_NAME (type
) != NULL
)
7544 /* FIXME: carlton/2003-11-10: Should this use
7545 SYMBOL_SET_NAMES instead? (The same problem also
7546 arises further down in this function.) */
7547 /* The type's name is already allocated along with
7548 this objfile, so we don't need to duplicate it
7550 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7555 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7556 really ever be static objects: otherwise, if you try
7557 to, say, break of a class's method and you're in a file
7558 which doesn't mention that class, it won't work unless
7559 the check for all static symbols in lookup_symbol_aux
7560 saves you. See the OtherFileClass tests in
7561 gdb.c++/namespace.exp. */
7563 struct pending
**list_to_add
;
7565 list_to_add
= (cu
->list_in_scope
== &file_symbols
7566 && (cu
->language
== language_cplus
7567 || cu
->language
== language_java
)
7568 ? &global_symbols
: cu
->list_in_scope
);
7570 add_symbol_to_list (sym
, list_to_add
);
7572 /* The semantics of C++ state that "struct foo { ... }" also
7573 defines a typedef for "foo". A Java class declaration also
7574 defines a typedef for the class. */
7575 if (cu
->language
== language_cplus
7576 || cu
->language
== language_java
7577 || cu
->language
== language_ada
)
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
);
7587 case DW_TAG_typedef
:
7588 if (processing_has_namespace_info
7589 && processing_current_prefix
[0] != '\0')
7591 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7592 processing_current_prefix
,
7595 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7596 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7597 add_symbol_to_list (sym
, cu
->list_in_scope
);
7599 case DW_TAG_base_type
:
7600 case DW_TAG_subrange_type
:
7601 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7602 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7603 add_symbol_to_list (sym
, cu
->list_in_scope
);
7605 case DW_TAG_enumerator
:
7606 if (processing_has_namespace_info
7607 && processing_current_prefix
[0] != '\0')
7609 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7610 processing_current_prefix
,
7613 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7616 dwarf2_const_value (attr
, sym
, cu
);
7619 /* NOTE: carlton/2003-11-10: See comment above in the
7620 DW_TAG_class_type, etc. block. */
7622 struct pending
**list_to_add
;
7624 list_to_add
= (cu
->list_in_scope
== &file_symbols
7625 && (cu
->language
== language_cplus
7626 || cu
->language
== language_java
)
7627 ? &global_symbols
: cu
->list_in_scope
);
7629 add_symbol_to_list (sym
, list_to_add
);
7632 case DW_TAG_namespace
:
7633 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7634 add_symbol_to_list (sym
, &global_symbols
);
7637 /* Not a tag we recognize. Hopefully we aren't processing
7638 trash data, but since we must specifically ignore things
7639 we don't recognize, there is nothing else we should do at
7641 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7642 dwarf_tag_name (die
->tag
));
7649 /* Copy constant value from an attribute to a symbol. */
7652 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7653 struct dwarf2_cu
*cu
)
7655 struct objfile
*objfile
= cu
->objfile
;
7656 struct comp_unit_head
*cu_header
= &cu
->header
;
7657 struct dwarf_block
*blk
;
7662 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7663 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7664 cu_header
->addr_size
,
7665 TYPE_LENGTH (SYMBOL_TYPE
7667 SYMBOL_VALUE_BYTES (sym
) =
7668 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7669 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7670 it's body - store_unsigned_integer. */
7671 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7673 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7676 /* DW_STRING is already allocated on the obstack, point directly
7678 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7679 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7681 case DW_FORM_block1
:
7682 case DW_FORM_block2
:
7683 case DW_FORM_block4
:
7685 blk
= DW_BLOCK (attr
);
7686 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7687 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7689 TYPE_LENGTH (SYMBOL_TYPE
7691 SYMBOL_VALUE_BYTES (sym
) =
7692 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7693 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7694 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7697 /* The DW_AT_const_value attributes are supposed to carry the
7698 symbol's value "represented as it would be on the target
7699 architecture." By the time we get here, it's already been
7700 converted to host endianness, so we just need to sign- or
7701 zero-extend it as appropriate. */
7703 dwarf2_const_value_data (attr
, sym
, 8);
7706 dwarf2_const_value_data (attr
, sym
, 16);
7709 dwarf2_const_value_data (attr
, sym
, 32);
7712 dwarf2_const_value_data (attr
, sym
, 64);
7716 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7717 SYMBOL_CLASS (sym
) = LOC_CONST
;
7721 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7722 SYMBOL_CLASS (sym
) = LOC_CONST
;
7726 complaint (&symfile_complaints
,
7727 _("unsupported const value attribute form: '%s'"),
7728 dwarf_form_name (attr
->form
));
7729 SYMBOL_VALUE (sym
) = 0;
7730 SYMBOL_CLASS (sym
) = LOC_CONST
;
7736 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7737 or zero-extend it as appropriate for the symbol's type. */
7739 dwarf2_const_value_data (struct attribute
*attr
,
7743 LONGEST l
= DW_UNSND (attr
);
7745 if (bits
< sizeof (l
) * 8)
7747 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7748 l
&= ((LONGEST
) 1 << bits
) - 1;
7750 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7753 SYMBOL_VALUE (sym
) = l
;
7754 SYMBOL_CLASS (sym
) = LOC_CONST
;
7758 /* Return the type of the die in question using its DW_AT_type attribute. */
7760 static struct type
*
7761 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7763 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7765 struct attribute
*type_attr
;
7766 struct die_info
*type_die
;
7768 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7771 /* A missing DW_AT_type represents a void type. */
7772 return builtin_type (gdbarch
)->builtin_void
;
7775 type_die
= follow_die_ref (die
, type_attr
, cu
);
7777 type
= tag_type_to_type (type_die
, cu
);
7780 dump_die (type_die
);
7781 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7787 /* Return the containing type of the die in question using its
7788 DW_AT_containing_type attribute. */
7790 static struct type
*
7791 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7793 struct type
*type
= NULL
;
7794 struct attribute
*type_attr
;
7795 struct die_info
*type_die
= NULL
;
7797 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7800 type_die
= follow_die_ref (die
, type_attr
, cu
);
7801 type
= tag_type_to_type (type_die
, cu
);
7806 dump_die (type_die
);
7807 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7813 static struct type
*
7814 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7816 struct type
*this_type
;
7818 this_type
= read_type_die (die
, cu
);
7822 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7828 static struct type
*
7829 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7832 const char *old_prefix
;
7833 struct cleanup
*back_to
;
7834 struct type
*this_type
;
7836 this_type
= get_die_type (die
, cu
);
7840 prefix
= determine_prefix (die
, cu
);
7841 old_prefix
= processing_current_prefix
;
7842 back_to
= make_cleanup (xfree
, prefix
);
7843 processing_current_prefix
= prefix
;
7847 case DW_TAG_class_type
:
7848 case DW_TAG_interface_type
:
7849 case DW_TAG_structure_type
:
7850 case DW_TAG_union_type
:
7851 this_type
= read_structure_type (die
, cu
);
7853 case DW_TAG_enumeration_type
:
7854 this_type
= read_enumeration_type (die
, cu
);
7856 case DW_TAG_subprogram
:
7857 case DW_TAG_subroutine_type
:
7858 this_type
= read_subroutine_type (die
, cu
);
7860 case DW_TAG_array_type
:
7861 this_type
= read_array_type (die
, cu
);
7863 case DW_TAG_set_type
:
7864 this_type
= read_set_type (die
, cu
);
7866 case DW_TAG_pointer_type
:
7867 this_type
= read_tag_pointer_type (die
, cu
);
7869 case DW_TAG_ptr_to_member_type
:
7870 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7872 case DW_TAG_reference_type
:
7873 this_type
= read_tag_reference_type (die
, cu
);
7875 case DW_TAG_const_type
:
7876 this_type
= read_tag_const_type (die
, cu
);
7878 case DW_TAG_volatile_type
:
7879 this_type
= read_tag_volatile_type (die
, cu
);
7881 case DW_TAG_string_type
:
7882 this_type
= read_tag_string_type (die
, cu
);
7884 case DW_TAG_typedef
:
7885 this_type
= read_typedef (die
, cu
);
7887 case DW_TAG_subrange_type
:
7888 this_type
= read_subrange_type (die
, cu
);
7890 case DW_TAG_base_type
:
7891 this_type
= read_base_type (die
, cu
);
7893 case DW_TAG_unspecified_type
:
7894 this_type
= read_unspecified_type (die
, cu
);
7897 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7898 dwarf_tag_name (die
->tag
));
7902 processing_current_prefix
= old_prefix
;
7903 do_cleanups (back_to
);
7907 /* Return the name of the namespace/class that DIE is defined within,
7908 or "" if we can't tell. The caller should xfree the result. */
7910 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7911 therein) for an example of how to use this function to deal with
7912 DW_AT_specification. */
7915 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7917 struct die_info
*parent
;
7919 if (cu
->language
!= language_cplus
7920 && cu
->language
!= language_java
)
7923 parent
= die
->parent
;
7927 return xstrdup ("");
7931 switch (parent
->tag
) {
7932 case DW_TAG_namespace
:
7934 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7935 before doing this check? */
7936 struct type
*parent_type
= get_die_type (parent
, cu
);
7937 if (parent_type
!= NULL
&& TYPE_TAG_NAME (parent_type
) != NULL
)
7939 return xstrdup (TYPE_TAG_NAME (parent_type
));
7944 char *parent_prefix
= determine_prefix (parent
, cu
);
7945 char *retval
= typename_concat (NULL
, parent_prefix
,
7946 namespace_name (parent
, &dummy
,
7949 xfree (parent_prefix
);
7954 case DW_TAG_class_type
:
7955 case DW_TAG_interface_type
:
7956 case DW_TAG_structure_type
:
7958 struct type
*parent_type
= get_die_type (parent
, cu
);
7959 if (parent_type
!= NULL
&& TYPE_TAG_NAME (parent_type
) != NULL
)
7961 return xstrdup (TYPE_TAG_NAME (parent_type
));
7965 const char *old_prefix
= processing_current_prefix
;
7966 char *new_prefix
= determine_prefix (parent
, cu
);
7969 processing_current_prefix
= new_prefix
;
7970 retval
= determine_class_name (parent
, cu
);
7971 processing_current_prefix
= old_prefix
;
7978 return determine_prefix (parent
, cu
);
7983 /* Return a newly-allocated string formed by concatenating PREFIX and
7984 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7985 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7986 perform an obconcat, otherwise allocate storage for the result. The CU argument
7987 is used to determine the language and hence, the appropriate separator. */
7989 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7992 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7993 struct dwarf2_cu
*cu
)
7997 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7999 else if (cu
->language
== language_java
)
8006 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8011 strcpy (retval
, prefix
);
8012 strcat (retval
, sep
);
8015 strcat (retval
, suffix
);
8021 /* We have an obstack. */
8022 return obconcat (obs
, prefix
, sep
, suffix
);
8028 copy_die (struct die_info
*old_die
)
8030 struct die_info
*new_die
;
8033 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8034 memset (new_die
, 0, sizeof (struct die_info
));
8036 new_die
->tag
= old_die
->tag
;
8037 new_die
->has_children
= old_die
->has_children
;
8038 new_die
->abbrev
= old_die
->abbrev
;
8039 new_die
->offset
= old_die
->offset
;
8041 num_attrs
= old_die
->num_attrs
;
8042 new_die
->num_attrs
= num_attrs
;
8043 new_die
->attrs
= (struct attribute
*)
8044 xmalloc (num_attrs
* sizeof (struct attribute
));
8046 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
8048 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
8049 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
8050 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
8053 new_die
->next
= NULL
;
8058 /* Return sibling of die, NULL if no sibling. */
8060 static struct die_info
*
8061 sibling_die (struct die_info
*die
)
8063 return die
->sibling
;
8066 /* Get linkage name of a die, return NULL if not found. */
8069 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8071 struct attribute
*attr
;
8073 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8074 if (attr
&& DW_STRING (attr
))
8075 return DW_STRING (attr
);
8076 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8077 if (attr
&& DW_STRING (attr
))
8078 return DW_STRING (attr
);
8082 /* Get name of a die, return NULL if not found. */
8085 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8087 struct attribute
*attr
;
8089 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8090 if (attr
&& DW_STRING (attr
))
8091 return DW_STRING (attr
);
8095 /* Return the die that this die in an extension of, or NULL if there
8098 static struct die_info
*
8099 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
8101 struct attribute
*attr
;
8103 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
8107 return follow_die_ref (die
, attr
, cu
);
8110 /* Convert a DIE tag into its string name. */
8113 dwarf_tag_name (unsigned tag
)
8117 case DW_TAG_padding
:
8118 return "DW_TAG_padding";
8119 case DW_TAG_array_type
:
8120 return "DW_TAG_array_type";
8121 case DW_TAG_class_type
:
8122 return "DW_TAG_class_type";
8123 case DW_TAG_entry_point
:
8124 return "DW_TAG_entry_point";
8125 case DW_TAG_enumeration_type
:
8126 return "DW_TAG_enumeration_type";
8127 case DW_TAG_formal_parameter
:
8128 return "DW_TAG_formal_parameter";
8129 case DW_TAG_imported_declaration
:
8130 return "DW_TAG_imported_declaration";
8132 return "DW_TAG_label";
8133 case DW_TAG_lexical_block
:
8134 return "DW_TAG_lexical_block";
8136 return "DW_TAG_member";
8137 case DW_TAG_pointer_type
:
8138 return "DW_TAG_pointer_type";
8139 case DW_TAG_reference_type
:
8140 return "DW_TAG_reference_type";
8141 case DW_TAG_compile_unit
:
8142 return "DW_TAG_compile_unit";
8143 case DW_TAG_string_type
:
8144 return "DW_TAG_string_type";
8145 case DW_TAG_structure_type
:
8146 return "DW_TAG_structure_type";
8147 case DW_TAG_subroutine_type
:
8148 return "DW_TAG_subroutine_type";
8149 case DW_TAG_typedef
:
8150 return "DW_TAG_typedef";
8151 case DW_TAG_union_type
:
8152 return "DW_TAG_union_type";
8153 case DW_TAG_unspecified_parameters
:
8154 return "DW_TAG_unspecified_parameters";
8155 case DW_TAG_variant
:
8156 return "DW_TAG_variant";
8157 case DW_TAG_common_block
:
8158 return "DW_TAG_common_block";
8159 case DW_TAG_common_inclusion
:
8160 return "DW_TAG_common_inclusion";
8161 case DW_TAG_inheritance
:
8162 return "DW_TAG_inheritance";
8163 case DW_TAG_inlined_subroutine
:
8164 return "DW_TAG_inlined_subroutine";
8166 return "DW_TAG_module";
8167 case DW_TAG_ptr_to_member_type
:
8168 return "DW_TAG_ptr_to_member_type";
8169 case DW_TAG_set_type
:
8170 return "DW_TAG_set_type";
8171 case DW_TAG_subrange_type
:
8172 return "DW_TAG_subrange_type";
8173 case DW_TAG_with_stmt
:
8174 return "DW_TAG_with_stmt";
8175 case DW_TAG_access_declaration
:
8176 return "DW_TAG_access_declaration";
8177 case DW_TAG_base_type
:
8178 return "DW_TAG_base_type";
8179 case DW_TAG_catch_block
:
8180 return "DW_TAG_catch_block";
8181 case DW_TAG_const_type
:
8182 return "DW_TAG_const_type";
8183 case DW_TAG_constant
:
8184 return "DW_TAG_constant";
8185 case DW_TAG_enumerator
:
8186 return "DW_TAG_enumerator";
8187 case DW_TAG_file_type
:
8188 return "DW_TAG_file_type";
8190 return "DW_TAG_friend";
8191 case DW_TAG_namelist
:
8192 return "DW_TAG_namelist";
8193 case DW_TAG_namelist_item
:
8194 return "DW_TAG_namelist_item";
8195 case DW_TAG_packed_type
:
8196 return "DW_TAG_packed_type";
8197 case DW_TAG_subprogram
:
8198 return "DW_TAG_subprogram";
8199 case DW_TAG_template_type_param
:
8200 return "DW_TAG_template_type_param";
8201 case DW_TAG_template_value_param
:
8202 return "DW_TAG_template_value_param";
8203 case DW_TAG_thrown_type
:
8204 return "DW_TAG_thrown_type";
8205 case DW_TAG_try_block
:
8206 return "DW_TAG_try_block";
8207 case DW_TAG_variant_part
:
8208 return "DW_TAG_variant_part";
8209 case DW_TAG_variable
:
8210 return "DW_TAG_variable";
8211 case DW_TAG_volatile_type
:
8212 return "DW_TAG_volatile_type";
8213 case DW_TAG_dwarf_procedure
:
8214 return "DW_TAG_dwarf_procedure";
8215 case DW_TAG_restrict_type
:
8216 return "DW_TAG_restrict_type";
8217 case DW_TAG_interface_type
:
8218 return "DW_TAG_interface_type";
8219 case DW_TAG_namespace
:
8220 return "DW_TAG_namespace";
8221 case DW_TAG_imported_module
:
8222 return "DW_TAG_imported_module";
8223 case DW_TAG_unspecified_type
:
8224 return "DW_TAG_unspecified_type";
8225 case DW_TAG_partial_unit
:
8226 return "DW_TAG_partial_unit";
8227 case DW_TAG_imported_unit
:
8228 return "DW_TAG_imported_unit";
8229 case DW_TAG_condition
:
8230 return "DW_TAG_condition";
8231 case DW_TAG_shared_type
:
8232 return "DW_TAG_shared_type";
8233 case DW_TAG_MIPS_loop
:
8234 return "DW_TAG_MIPS_loop";
8235 case DW_TAG_HP_array_descriptor
:
8236 return "DW_TAG_HP_array_descriptor";
8237 case DW_TAG_format_label
:
8238 return "DW_TAG_format_label";
8239 case DW_TAG_function_template
:
8240 return "DW_TAG_function_template";
8241 case DW_TAG_class_template
:
8242 return "DW_TAG_class_template";
8243 case DW_TAG_GNU_BINCL
:
8244 return "DW_TAG_GNU_BINCL";
8245 case DW_TAG_GNU_EINCL
:
8246 return "DW_TAG_GNU_EINCL";
8247 case DW_TAG_upc_shared_type
:
8248 return "DW_TAG_upc_shared_type";
8249 case DW_TAG_upc_strict_type
:
8250 return "DW_TAG_upc_strict_type";
8251 case DW_TAG_upc_relaxed_type
:
8252 return "DW_TAG_upc_relaxed_type";
8253 case DW_TAG_PGI_kanji_type
:
8254 return "DW_TAG_PGI_kanji_type";
8255 case DW_TAG_PGI_interface_block
:
8256 return "DW_TAG_PGI_interface_block";
8258 return "DW_TAG_<unknown>";
8262 /* Convert a DWARF attribute code into its string name. */
8265 dwarf_attr_name (unsigned attr
)
8270 return "DW_AT_sibling";
8271 case DW_AT_location
:
8272 return "DW_AT_location";
8274 return "DW_AT_name";
8275 case DW_AT_ordering
:
8276 return "DW_AT_ordering";
8277 case DW_AT_subscr_data
:
8278 return "DW_AT_subscr_data";
8279 case DW_AT_byte_size
:
8280 return "DW_AT_byte_size";
8281 case DW_AT_bit_offset
:
8282 return "DW_AT_bit_offset";
8283 case DW_AT_bit_size
:
8284 return "DW_AT_bit_size";
8285 case DW_AT_element_list
:
8286 return "DW_AT_element_list";
8287 case DW_AT_stmt_list
:
8288 return "DW_AT_stmt_list";
8290 return "DW_AT_low_pc";
8292 return "DW_AT_high_pc";
8293 case DW_AT_language
:
8294 return "DW_AT_language";
8296 return "DW_AT_member";
8298 return "DW_AT_discr";
8299 case DW_AT_discr_value
:
8300 return "DW_AT_discr_value";
8301 case DW_AT_visibility
:
8302 return "DW_AT_visibility";
8304 return "DW_AT_import";
8305 case DW_AT_string_length
:
8306 return "DW_AT_string_length";
8307 case DW_AT_common_reference
:
8308 return "DW_AT_common_reference";
8309 case DW_AT_comp_dir
:
8310 return "DW_AT_comp_dir";
8311 case DW_AT_const_value
:
8312 return "DW_AT_const_value";
8313 case DW_AT_containing_type
:
8314 return "DW_AT_containing_type";
8315 case DW_AT_default_value
:
8316 return "DW_AT_default_value";
8318 return "DW_AT_inline";
8319 case DW_AT_is_optional
:
8320 return "DW_AT_is_optional";
8321 case DW_AT_lower_bound
:
8322 return "DW_AT_lower_bound";
8323 case DW_AT_producer
:
8324 return "DW_AT_producer";
8325 case DW_AT_prototyped
:
8326 return "DW_AT_prototyped";
8327 case DW_AT_return_addr
:
8328 return "DW_AT_return_addr";
8329 case DW_AT_start_scope
:
8330 return "DW_AT_start_scope";
8331 case DW_AT_bit_stride
:
8332 return "DW_AT_bit_stride";
8333 case DW_AT_upper_bound
:
8334 return "DW_AT_upper_bound";
8335 case DW_AT_abstract_origin
:
8336 return "DW_AT_abstract_origin";
8337 case DW_AT_accessibility
:
8338 return "DW_AT_accessibility";
8339 case DW_AT_address_class
:
8340 return "DW_AT_address_class";
8341 case DW_AT_artificial
:
8342 return "DW_AT_artificial";
8343 case DW_AT_base_types
:
8344 return "DW_AT_base_types";
8345 case DW_AT_calling_convention
:
8346 return "DW_AT_calling_convention";
8348 return "DW_AT_count";
8349 case DW_AT_data_member_location
:
8350 return "DW_AT_data_member_location";
8351 case DW_AT_decl_column
:
8352 return "DW_AT_decl_column";
8353 case DW_AT_decl_file
:
8354 return "DW_AT_decl_file";
8355 case DW_AT_decl_line
:
8356 return "DW_AT_decl_line";
8357 case DW_AT_declaration
:
8358 return "DW_AT_declaration";
8359 case DW_AT_discr_list
:
8360 return "DW_AT_discr_list";
8361 case DW_AT_encoding
:
8362 return "DW_AT_encoding";
8363 case DW_AT_external
:
8364 return "DW_AT_external";
8365 case DW_AT_frame_base
:
8366 return "DW_AT_frame_base";
8368 return "DW_AT_friend";
8369 case DW_AT_identifier_case
:
8370 return "DW_AT_identifier_case";
8371 case DW_AT_macro_info
:
8372 return "DW_AT_macro_info";
8373 case DW_AT_namelist_items
:
8374 return "DW_AT_namelist_items";
8375 case DW_AT_priority
:
8376 return "DW_AT_priority";
8378 return "DW_AT_segment";
8379 case DW_AT_specification
:
8380 return "DW_AT_specification";
8381 case DW_AT_static_link
:
8382 return "DW_AT_static_link";
8384 return "DW_AT_type";
8385 case DW_AT_use_location
:
8386 return "DW_AT_use_location";
8387 case DW_AT_variable_parameter
:
8388 return "DW_AT_variable_parameter";
8389 case DW_AT_virtuality
:
8390 return "DW_AT_virtuality";
8391 case DW_AT_vtable_elem_location
:
8392 return "DW_AT_vtable_elem_location";
8393 /* DWARF 3 values. */
8394 case DW_AT_allocated
:
8395 return "DW_AT_allocated";
8396 case DW_AT_associated
:
8397 return "DW_AT_associated";
8398 case DW_AT_data_location
:
8399 return "DW_AT_data_location";
8400 case DW_AT_byte_stride
:
8401 return "DW_AT_byte_stride";
8402 case DW_AT_entry_pc
:
8403 return "DW_AT_entry_pc";
8404 case DW_AT_use_UTF8
:
8405 return "DW_AT_use_UTF8";
8406 case DW_AT_extension
:
8407 return "DW_AT_extension";
8409 return "DW_AT_ranges";
8410 case DW_AT_trampoline
:
8411 return "DW_AT_trampoline";
8412 case DW_AT_call_column
:
8413 return "DW_AT_call_column";
8414 case DW_AT_call_file
:
8415 return "DW_AT_call_file";
8416 case DW_AT_call_line
:
8417 return "DW_AT_call_line";
8418 case DW_AT_description
:
8419 return "DW_AT_description";
8420 case DW_AT_binary_scale
:
8421 return "DW_AT_binary_scale";
8422 case DW_AT_decimal_scale
:
8423 return "DW_AT_decimal_scale";
8425 return "DW_AT_small";
8426 case DW_AT_decimal_sign
:
8427 return "DW_AT_decimal_sign";
8428 case DW_AT_digit_count
:
8429 return "DW_AT_digit_count";
8430 case DW_AT_picture_string
:
8431 return "DW_AT_picture_string";
8433 return "DW_AT_mutable";
8434 case DW_AT_threads_scaled
:
8435 return "DW_AT_threads_scaled";
8436 case DW_AT_explicit
:
8437 return "DW_AT_explicit";
8438 case DW_AT_object_pointer
:
8439 return "DW_AT_object_pointer";
8440 case DW_AT_endianity
:
8441 return "DW_AT_endianity";
8442 case DW_AT_elemental
:
8443 return "DW_AT_elemental";
8445 return "DW_AT_pure";
8446 case DW_AT_recursive
:
8447 return "DW_AT_recursive";
8449 /* SGI/MIPS extensions. */
8450 case DW_AT_MIPS_fde
:
8451 return "DW_AT_MIPS_fde";
8452 case DW_AT_MIPS_loop_begin
:
8453 return "DW_AT_MIPS_loop_begin";
8454 case DW_AT_MIPS_tail_loop_begin
:
8455 return "DW_AT_MIPS_tail_loop_begin";
8456 case DW_AT_MIPS_epilog_begin
:
8457 return "DW_AT_MIPS_epilog_begin";
8458 case DW_AT_MIPS_loop_unroll_factor
:
8459 return "DW_AT_MIPS_loop_unroll_factor";
8460 case DW_AT_MIPS_software_pipeline_depth
:
8461 return "DW_AT_MIPS_software_pipeline_depth";
8462 case DW_AT_MIPS_linkage_name
:
8463 return "DW_AT_MIPS_linkage_name";
8464 case DW_AT_MIPS_stride
:
8465 return "DW_AT_MIPS_stride";
8466 case DW_AT_MIPS_abstract_name
:
8467 return "DW_AT_MIPS_abstract_name";
8468 case DW_AT_MIPS_clone_origin
:
8469 return "DW_AT_MIPS_clone_origin";
8470 case DW_AT_MIPS_has_inlines
:
8471 return "DW_AT_MIPS_has_inlines";
8473 /* HP extensions. */
8474 case DW_AT_HP_block_index
:
8475 return "DW_AT_HP_block_index";
8476 case DW_AT_HP_unmodifiable
:
8477 return "DW_AT_HP_unmodifiable";
8478 case DW_AT_HP_actuals_stmt_list
:
8479 return "DW_AT_HP_actuals_stmt_list";
8480 case DW_AT_HP_proc_per_section
:
8481 return "DW_AT_HP_proc_per_section";
8482 case DW_AT_HP_raw_data_ptr
:
8483 return "DW_AT_HP_raw_data_ptr";
8484 case DW_AT_HP_pass_by_reference
:
8485 return "DW_AT_HP_pass_by_reference";
8486 case DW_AT_HP_opt_level
:
8487 return "DW_AT_HP_opt_level";
8488 case DW_AT_HP_prof_version_id
:
8489 return "DW_AT_HP_prof_version_id";
8490 case DW_AT_HP_opt_flags
:
8491 return "DW_AT_HP_opt_flags";
8492 case DW_AT_HP_cold_region_low_pc
:
8493 return "DW_AT_HP_cold_region_low_pc";
8494 case DW_AT_HP_cold_region_high_pc
:
8495 return "DW_AT_HP_cold_region_high_pc";
8496 case DW_AT_HP_all_variables_modifiable
:
8497 return "DW_AT_HP_all_variables_modifiable";
8498 case DW_AT_HP_linkage_name
:
8499 return "DW_AT_HP_linkage_name";
8500 case DW_AT_HP_prof_flags
:
8501 return "DW_AT_HP_prof_flags";
8502 /* GNU extensions. */
8503 case DW_AT_sf_names
:
8504 return "DW_AT_sf_names";
8505 case DW_AT_src_info
:
8506 return "DW_AT_src_info";
8507 case DW_AT_mac_info
:
8508 return "DW_AT_mac_info";
8509 case DW_AT_src_coords
:
8510 return "DW_AT_src_coords";
8511 case DW_AT_body_begin
:
8512 return "DW_AT_body_begin";
8513 case DW_AT_body_end
:
8514 return "DW_AT_body_end";
8515 case DW_AT_GNU_vector
:
8516 return "DW_AT_GNU_vector";
8517 /* VMS extensions. */
8518 case DW_AT_VMS_rtnbeg_pd_address
:
8519 return "DW_AT_VMS_rtnbeg_pd_address";
8520 /* UPC extension. */
8521 case DW_AT_upc_threads_scaled
:
8522 return "DW_AT_upc_threads_scaled";
8523 /* PGI (STMicroelectronics) extensions. */
8524 case DW_AT_PGI_lbase
:
8525 return "DW_AT_PGI_lbase";
8526 case DW_AT_PGI_soffset
:
8527 return "DW_AT_PGI_soffset";
8528 case DW_AT_PGI_lstride
:
8529 return "DW_AT_PGI_lstride";
8531 return "DW_AT_<unknown>";
8535 /* Convert a DWARF value form code into its string name. */
8538 dwarf_form_name (unsigned form
)
8543 return "DW_FORM_addr";
8544 case DW_FORM_block2
:
8545 return "DW_FORM_block2";
8546 case DW_FORM_block4
:
8547 return "DW_FORM_block4";
8549 return "DW_FORM_data2";
8551 return "DW_FORM_data4";
8553 return "DW_FORM_data8";
8554 case DW_FORM_string
:
8555 return "DW_FORM_string";
8557 return "DW_FORM_block";
8558 case DW_FORM_block1
:
8559 return "DW_FORM_block1";
8561 return "DW_FORM_data1";
8563 return "DW_FORM_flag";
8565 return "DW_FORM_sdata";
8567 return "DW_FORM_strp";
8569 return "DW_FORM_udata";
8570 case DW_FORM_ref_addr
:
8571 return "DW_FORM_ref_addr";
8573 return "DW_FORM_ref1";
8575 return "DW_FORM_ref2";
8577 return "DW_FORM_ref4";
8579 return "DW_FORM_ref8";
8580 case DW_FORM_ref_udata
:
8581 return "DW_FORM_ref_udata";
8582 case DW_FORM_indirect
:
8583 return "DW_FORM_indirect";
8585 return "DW_FORM_<unknown>";
8589 /* Convert a DWARF stack opcode into its string name. */
8592 dwarf_stack_op_name (unsigned op
)
8597 return "DW_OP_addr";
8599 return "DW_OP_deref";
8601 return "DW_OP_const1u";
8603 return "DW_OP_const1s";
8605 return "DW_OP_const2u";
8607 return "DW_OP_const2s";
8609 return "DW_OP_const4u";
8611 return "DW_OP_const4s";
8613 return "DW_OP_const8u";
8615 return "DW_OP_const8s";
8617 return "DW_OP_constu";
8619 return "DW_OP_consts";
8623 return "DW_OP_drop";
8625 return "DW_OP_over";
8627 return "DW_OP_pick";
8629 return "DW_OP_swap";
8633 return "DW_OP_xderef";
8641 return "DW_OP_minus";
8653 return "DW_OP_plus";
8654 case DW_OP_plus_uconst
:
8655 return "DW_OP_plus_uconst";
8661 return "DW_OP_shra";
8679 return "DW_OP_skip";
8681 return "DW_OP_lit0";
8683 return "DW_OP_lit1";
8685 return "DW_OP_lit2";
8687 return "DW_OP_lit3";
8689 return "DW_OP_lit4";
8691 return "DW_OP_lit5";
8693 return "DW_OP_lit6";
8695 return "DW_OP_lit7";
8697 return "DW_OP_lit8";
8699 return "DW_OP_lit9";
8701 return "DW_OP_lit10";
8703 return "DW_OP_lit11";
8705 return "DW_OP_lit12";
8707 return "DW_OP_lit13";
8709 return "DW_OP_lit14";
8711 return "DW_OP_lit15";
8713 return "DW_OP_lit16";
8715 return "DW_OP_lit17";
8717 return "DW_OP_lit18";
8719 return "DW_OP_lit19";
8721 return "DW_OP_lit20";
8723 return "DW_OP_lit21";
8725 return "DW_OP_lit22";
8727 return "DW_OP_lit23";
8729 return "DW_OP_lit24";
8731 return "DW_OP_lit25";
8733 return "DW_OP_lit26";
8735 return "DW_OP_lit27";
8737 return "DW_OP_lit28";
8739 return "DW_OP_lit29";
8741 return "DW_OP_lit30";
8743 return "DW_OP_lit31";
8745 return "DW_OP_reg0";
8747 return "DW_OP_reg1";
8749 return "DW_OP_reg2";
8751 return "DW_OP_reg3";
8753 return "DW_OP_reg4";
8755 return "DW_OP_reg5";
8757 return "DW_OP_reg6";
8759 return "DW_OP_reg7";
8761 return "DW_OP_reg8";
8763 return "DW_OP_reg9";
8765 return "DW_OP_reg10";
8767 return "DW_OP_reg11";
8769 return "DW_OP_reg12";
8771 return "DW_OP_reg13";
8773 return "DW_OP_reg14";
8775 return "DW_OP_reg15";
8777 return "DW_OP_reg16";
8779 return "DW_OP_reg17";
8781 return "DW_OP_reg18";
8783 return "DW_OP_reg19";
8785 return "DW_OP_reg20";
8787 return "DW_OP_reg21";
8789 return "DW_OP_reg22";
8791 return "DW_OP_reg23";
8793 return "DW_OP_reg24";
8795 return "DW_OP_reg25";
8797 return "DW_OP_reg26";
8799 return "DW_OP_reg27";
8801 return "DW_OP_reg28";
8803 return "DW_OP_reg29";
8805 return "DW_OP_reg30";
8807 return "DW_OP_reg31";
8809 return "DW_OP_breg0";
8811 return "DW_OP_breg1";
8813 return "DW_OP_breg2";
8815 return "DW_OP_breg3";
8817 return "DW_OP_breg4";
8819 return "DW_OP_breg5";
8821 return "DW_OP_breg6";
8823 return "DW_OP_breg7";
8825 return "DW_OP_breg8";
8827 return "DW_OP_breg9";
8829 return "DW_OP_breg10";
8831 return "DW_OP_breg11";
8833 return "DW_OP_breg12";
8835 return "DW_OP_breg13";
8837 return "DW_OP_breg14";
8839 return "DW_OP_breg15";
8841 return "DW_OP_breg16";
8843 return "DW_OP_breg17";
8845 return "DW_OP_breg18";
8847 return "DW_OP_breg19";
8849 return "DW_OP_breg20";
8851 return "DW_OP_breg21";
8853 return "DW_OP_breg22";
8855 return "DW_OP_breg23";
8857 return "DW_OP_breg24";
8859 return "DW_OP_breg25";
8861 return "DW_OP_breg26";
8863 return "DW_OP_breg27";
8865 return "DW_OP_breg28";
8867 return "DW_OP_breg29";
8869 return "DW_OP_breg30";
8871 return "DW_OP_breg31";
8873 return "DW_OP_regx";
8875 return "DW_OP_fbreg";
8877 return "DW_OP_bregx";
8879 return "DW_OP_piece";
8880 case DW_OP_deref_size
:
8881 return "DW_OP_deref_size";
8882 case DW_OP_xderef_size
:
8883 return "DW_OP_xderef_size";
8886 /* DWARF 3 extensions. */
8887 case DW_OP_push_object_address
:
8888 return "DW_OP_push_object_address";
8890 return "DW_OP_call2";
8892 return "DW_OP_call4";
8893 case DW_OP_call_ref
:
8894 return "DW_OP_call_ref";
8895 /* GNU extensions. */
8896 case DW_OP_form_tls_address
:
8897 return "DW_OP_form_tls_address";
8898 case DW_OP_call_frame_cfa
:
8899 return "DW_OP_call_frame_cfa";
8900 case DW_OP_bit_piece
:
8901 return "DW_OP_bit_piece";
8902 case DW_OP_GNU_push_tls_address
:
8903 return "DW_OP_GNU_push_tls_address";
8904 case DW_OP_GNU_uninit
:
8905 return "DW_OP_GNU_uninit";
8906 /* HP extensions. */
8907 case DW_OP_HP_is_value
:
8908 return "DW_OP_HP_is_value";
8909 case DW_OP_HP_fltconst4
:
8910 return "DW_OP_HP_fltconst4";
8911 case DW_OP_HP_fltconst8
:
8912 return "DW_OP_HP_fltconst8";
8913 case DW_OP_HP_mod_range
:
8914 return "DW_OP_HP_mod_range";
8915 case DW_OP_HP_unmod_range
:
8916 return "DW_OP_HP_unmod_range";
8918 return "DW_OP_HP_tls";
8920 return "OP_<unknown>";
8925 dwarf_bool_name (unsigned mybool
)
8933 /* Convert a DWARF type code into its string name. */
8936 dwarf_type_encoding_name (unsigned enc
)
8941 return "DW_ATE_void";
8942 case DW_ATE_address
:
8943 return "DW_ATE_address";
8944 case DW_ATE_boolean
:
8945 return "DW_ATE_boolean";
8946 case DW_ATE_complex_float
:
8947 return "DW_ATE_complex_float";
8949 return "DW_ATE_float";
8951 return "DW_ATE_signed";
8952 case DW_ATE_signed_char
:
8953 return "DW_ATE_signed_char";
8954 case DW_ATE_unsigned
:
8955 return "DW_ATE_unsigned";
8956 case DW_ATE_unsigned_char
:
8957 return "DW_ATE_unsigned_char";
8959 case DW_ATE_imaginary_float
:
8960 return "DW_ATE_imaginary_float";
8961 case DW_ATE_packed_decimal
:
8962 return "DW_ATE_packed_decimal";
8963 case DW_ATE_numeric_string
:
8964 return "DW_ATE_numeric_string";
8966 return "DW_ATE_edited";
8967 case DW_ATE_signed_fixed
:
8968 return "DW_ATE_signed_fixed";
8969 case DW_ATE_unsigned_fixed
:
8970 return "DW_ATE_unsigned_fixed";
8971 case DW_ATE_decimal_float
:
8972 return "DW_ATE_decimal_float";
8973 /* HP extensions. */
8974 case DW_ATE_HP_float80
:
8975 return "DW_ATE_HP_float80";
8976 case DW_ATE_HP_complex_float80
:
8977 return "DW_ATE_HP_complex_float80";
8978 case DW_ATE_HP_float128
:
8979 return "DW_ATE_HP_float128";
8980 case DW_ATE_HP_complex_float128
:
8981 return "DW_ATE_HP_complex_float128";
8982 case DW_ATE_HP_floathpintel
:
8983 return "DW_ATE_HP_floathpintel";
8984 case DW_ATE_HP_imaginary_float80
:
8985 return "DW_ATE_HP_imaginary_float80";
8986 case DW_ATE_HP_imaginary_float128
:
8987 return "DW_ATE_HP_imaginary_float128";
8989 return "DW_ATE_<unknown>";
8993 /* Convert a DWARF call frame info operation to its string name. */
8997 dwarf_cfi_name (unsigned cfi_opc
)
9001 case DW_CFA_advance_loc
:
9002 return "DW_CFA_advance_loc";
9004 return "DW_CFA_offset";
9005 case DW_CFA_restore
:
9006 return "DW_CFA_restore";
9008 return "DW_CFA_nop";
9009 case DW_CFA_set_loc
:
9010 return "DW_CFA_set_loc";
9011 case DW_CFA_advance_loc1
:
9012 return "DW_CFA_advance_loc1";
9013 case DW_CFA_advance_loc2
:
9014 return "DW_CFA_advance_loc2";
9015 case DW_CFA_advance_loc4
:
9016 return "DW_CFA_advance_loc4";
9017 case DW_CFA_offset_extended
:
9018 return "DW_CFA_offset_extended";
9019 case DW_CFA_restore_extended
:
9020 return "DW_CFA_restore_extended";
9021 case DW_CFA_undefined
:
9022 return "DW_CFA_undefined";
9023 case DW_CFA_same_value
:
9024 return "DW_CFA_same_value";
9025 case DW_CFA_register
:
9026 return "DW_CFA_register";
9027 case DW_CFA_remember_state
:
9028 return "DW_CFA_remember_state";
9029 case DW_CFA_restore_state
:
9030 return "DW_CFA_restore_state";
9031 case DW_CFA_def_cfa
:
9032 return "DW_CFA_def_cfa";
9033 case DW_CFA_def_cfa_register
:
9034 return "DW_CFA_def_cfa_register";
9035 case DW_CFA_def_cfa_offset
:
9036 return "DW_CFA_def_cfa_offset";
9038 case DW_CFA_def_cfa_expression
:
9039 return "DW_CFA_def_cfa_expression";
9040 case DW_CFA_expression
:
9041 return "DW_CFA_expression";
9042 case DW_CFA_offset_extended_sf
:
9043 return "DW_CFA_offset_extended_sf";
9044 case DW_CFA_def_cfa_sf
:
9045 return "DW_CFA_def_cfa_sf";
9046 case DW_CFA_def_cfa_offset_sf
:
9047 return "DW_CFA_def_cfa_offset_sf";
9048 case DW_CFA_val_offset
:
9049 return "DW_CFA_val_offset";
9050 case DW_CFA_val_offset_sf
:
9051 return "DW_CFA_val_offset_sf";
9052 case DW_CFA_val_expression
:
9053 return "DW_CFA_val_expression";
9054 /* SGI/MIPS specific. */
9055 case DW_CFA_MIPS_advance_loc8
:
9056 return "DW_CFA_MIPS_advance_loc8";
9057 /* GNU extensions. */
9058 case DW_CFA_GNU_window_save
:
9059 return "DW_CFA_GNU_window_save";
9060 case DW_CFA_GNU_args_size
:
9061 return "DW_CFA_GNU_args_size";
9062 case DW_CFA_GNU_negative_offset_extended
:
9063 return "DW_CFA_GNU_negative_offset_extended";
9065 return "DW_CFA_<unknown>";
9071 dump_die (struct die_info
*die
)
9075 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9076 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9077 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9078 dwarf_bool_name (die
->child
!= NULL
));
9080 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9081 for (i
= 0; i
< die
->num_attrs
; ++i
)
9083 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9084 dwarf_attr_name (die
->attrs
[i
].name
),
9085 dwarf_form_name (die
->attrs
[i
].form
));
9086 switch (die
->attrs
[i
].form
)
9088 case DW_FORM_ref_addr
:
9090 fprintf_unfiltered (gdb_stderr
, "address: ");
9091 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9093 case DW_FORM_block2
:
9094 case DW_FORM_block4
:
9096 case DW_FORM_block1
:
9097 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9102 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9103 (long) (DW_ADDR (&die
->attrs
[i
])));
9111 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9113 case DW_FORM_string
:
9115 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9116 DW_STRING (&die
->attrs
[i
])
9117 ? DW_STRING (&die
->attrs
[i
]) : "");
9120 if (DW_UNSND (&die
->attrs
[i
]))
9121 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9123 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9125 case DW_FORM_indirect
:
9126 /* the reader will have reduced the indirect form to
9127 the "base form" so this form should not occur */
9128 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9131 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9132 die
->attrs
[i
].form
);
9134 fprintf_unfiltered (gdb_stderr
, "\n");
9139 dump_die_list (struct die_info
*die
)
9144 if (die
->child
!= NULL
)
9145 dump_die_list (die
->child
);
9146 if (die
->sibling
!= NULL
)
9147 dump_die_list (die
->sibling
);
9152 store_in_ref_table (unsigned int offset
, struct die_info
*die
,
9153 struct dwarf2_cu
*cu
)
9156 struct die_info
*old
;
9158 h
= (offset
% REF_HASH_SIZE
);
9159 old
= cu
->die_ref_table
[h
];
9160 die
->next_ref
= old
;
9161 cu
->die_ref_table
[h
] = die
;
9165 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9167 unsigned int result
= 0;
9171 case DW_FORM_ref_addr
:
9176 case DW_FORM_ref_udata
:
9177 result
= DW_ADDR (attr
);
9180 complaint (&symfile_complaints
,
9181 _("unsupported die ref attribute form: '%s'"),
9182 dwarf_form_name (attr
->form
));
9187 /* Return the constant value held by the given attribute. Return -1
9188 if the value held by the attribute is not constant. */
9191 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9193 if (attr
->form
== DW_FORM_sdata
)
9194 return DW_SND (attr
);
9195 else if (attr
->form
== DW_FORM_udata
9196 || attr
->form
== DW_FORM_data1
9197 || attr
->form
== DW_FORM_data2
9198 || attr
->form
== DW_FORM_data4
9199 || attr
->form
== DW_FORM_data8
)
9200 return DW_UNSND (attr
);
9203 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9204 dwarf_form_name (attr
->form
));
9205 return default_value
;
9209 static struct die_info
*
9210 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9211 struct dwarf2_cu
*cu
)
9213 struct die_info
*die
;
9214 unsigned int offset
;
9216 struct die_info temp_die
;
9217 struct dwarf2_cu
*target_cu
;
9219 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9221 if (DW_ADDR (attr
) < cu
->header
.offset
9222 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9224 struct dwarf2_per_cu_data
*per_cu
;
9225 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9227 target_cu
= per_cu
->cu
;
9232 h
= (offset
% REF_HASH_SIZE
);
9233 die
= target_cu
->die_ref_table
[h
];
9236 if (die
->offset
== offset
)
9238 die
= die
->next_ref
;
9241 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9242 "at 0x%lx [in module %s]"),
9243 (long) src_die
->offset
, (long) offset
, cu
->objfile
->name
);
9248 /* Decode simple location descriptions.
9249 Given a pointer to a dwarf block that defines a location, compute
9250 the location and return the value.
9252 NOTE drow/2003-11-18: This function is called in two situations
9253 now: for the address of static or global variables (partial symbols
9254 only) and for offsets into structures which are expected to be
9255 (more or less) constant. The partial symbol case should go away,
9256 and only the constant case should remain. That will let this
9257 function complain more accurately. A few special modes are allowed
9258 without complaint for global variables (for instance, global
9259 register values and thread-local values).
9261 A location description containing no operations indicates that the
9262 object is optimized out. The return value is 0 for that case.
9263 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9264 callers will only want a very basic result and this can become a
9267 Note that stack[0] is unused except as a default error return.
9268 Note that stack overflow is not yet handled. */
9271 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9273 struct objfile
*objfile
= cu
->objfile
;
9274 struct comp_unit_head
*cu_header
= &cu
->header
;
9276 int size
= blk
->size
;
9277 gdb_byte
*data
= blk
->data
;
9278 CORE_ADDR stack
[64];
9280 unsigned int bytes_read
, unsnd
;
9324 stack
[++stacki
] = op
- DW_OP_lit0
;
9359 stack
[++stacki
] = op
- DW_OP_reg0
;
9361 dwarf2_complex_location_expr_complaint ();
9365 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9367 stack
[++stacki
] = unsnd
;
9369 dwarf2_complex_location_expr_complaint ();
9373 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9379 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9384 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9389 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9394 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9399 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9404 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9409 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9415 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9420 stack
[stacki
+ 1] = stack
[stacki
];
9425 stack
[stacki
- 1] += stack
[stacki
];
9429 case DW_OP_plus_uconst
:
9430 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9435 stack
[stacki
- 1] -= stack
[stacki
];
9440 /* If we're not the last op, then we definitely can't encode
9441 this using GDB's address_class enum. This is valid for partial
9442 global symbols, although the variable's address will be bogus
9445 dwarf2_complex_location_expr_complaint ();
9448 case DW_OP_GNU_push_tls_address
:
9449 /* The top of the stack has the offset from the beginning
9450 of the thread control block at which the variable is located. */
9451 /* Nothing should follow this operator, so the top of stack would
9453 /* This is valid for partial global symbols, but the variable's
9454 address will be bogus in the psymtab. */
9456 dwarf2_complex_location_expr_complaint ();
9459 case DW_OP_GNU_uninit
:
9463 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9464 dwarf_stack_op_name (op
));
9465 return (stack
[stacki
]);
9468 return (stack
[stacki
]);
9471 /* memory allocation interface */
9473 static struct dwarf_block
*
9474 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9476 struct dwarf_block
*blk
;
9478 blk
= (struct dwarf_block
*)
9479 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9483 static struct abbrev_info
*
9484 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9486 struct abbrev_info
*abbrev
;
9488 abbrev
= (struct abbrev_info
*)
9489 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9490 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9494 static struct die_info
*
9495 dwarf_alloc_die (void)
9497 struct die_info
*die
;
9499 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
9500 memset (die
, 0, sizeof (struct die_info
));
9505 /* Macro support. */
9508 /* Return the full name of file number I in *LH's file name table.
9509 Use COMP_DIR as the name of the current directory of the
9510 compilation. The result is allocated using xmalloc; the caller is
9511 responsible for freeing it. */
9513 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9515 /* Is the file number a valid index into the line header's file name
9516 table? Remember that file numbers start with one, not zero. */
9517 if (1 <= file
&& file
<= lh
->num_file_names
)
9519 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9521 if (IS_ABSOLUTE_PATH (fe
->name
))
9522 return xstrdup (fe
->name
);
9530 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9536 dir_len
= strlen (dir
);
9537 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9538 strcpy (full_name
, dir
);
9539 full_name
[dir_len
] = '/';
9540 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9544 return xstrdup (fe
->name
);
9549 /* The compiler produced a bogus file number. We can at least
9550 record the macro definitions made in the file, even if we
9551 won't be able to find the file by name. */
9553 sprintf (fake_name
, "<bad macro file number %d>", file
);
9555 complaint (&symfile_complaints
,
9556 _("bad file number in macro information (%d)"),
9559 return xstrdup (fake_name
);
9564 static struct macro_source_file
*
9565 macro_start_file (int file
, int line
,
9566 struct macro_source_file
*current_file
,
9567 const char *comp_dir
,
9568 struct line_header
*lh
, struct objfile
*objfile
)
9570 /* The full name of this source file. */
9571 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9573 /* We don't create a macro table for this compilation unit
9574 at all until we actually get a filename. */
9575 if (! pending_macros
)
9576 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9577 objfile
->macro_cache
);
9580 /* If we have no current file, then this must be the start_file
9581 directive for the compilation unit's main source file. */
9582 current_file
= macro_set_main (pending_macros
, full_name
);
9584 current_file
= macro_include (current_file
, line
, full_name
);
9588 return current_file
;
9592 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9593 followed by a null byte. */
9595 copy_string (const char *buf
, int len
)
9597 char *s
= xmalloc (len
+ 1);
9598 memcpy (s
, buf
, len
);
9606 consume_improper_spaces (const char *p
, const char *body
)
9610 complaint (&symfile_complaints
,
9611 _("macro definition contains spaces in formal argument list:\n`%s'"),
9623 parse_macro_definition (struct macro_source_file
*file
, int line
,
9628 /* The body string takes one of two forms. For object-like macro
9629 definitions, it should be:
9631 <macro name> " " <definition>
9633 For function-like macro definitions, it should be:
9635 <macro name> "() " <definition>
9637 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9639 Spaces may appear only where explicitly indicated, and in the
9642 The Dwarf 2 spec says that an object-like macro's name is always
9643 followed by a space, but versions of GCC around March 2002 omit
9644 the space when the macro's definition is the empty string.
9646 The Dwarf 2 spec says that there should be no spaces between the
9647 formal arguments in a function-like macro's formal argument list,
9648 but versions of GCC around March 2002 include spaces after the
9652 /* Find the extent of the macro name. The macro name is terminated
9653 by either a space or null character (for an object-like macro) or
9654 an opening paren (for a function-like macro). */
9655 for (p
= body
; *p
; p
++)
9656 if (*p
== ' ' || *p
== '(')
9659 if (*p
== ' ' || *p
== '\0')
9661 /* It's an object-like macro. */
9662 int name_len
= p
- body
;
9663 char *name
= copy_string (body
, name_len
);
9664 const char *replacement
;
9667 replacement
= body
+ name_len
+ 1;
9670 dwarf2_macro_malformed_definition_complaint (body
);
9671 replacement
= body
+ name_len
;
9674 macro_define_object (file
, line
, name
, replacement
);
9680 /* It's a function-like macro. */
9681 char *name
= copy_string (body
, p
- body
);
9684 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9688 p
= consume_improper_spaces (p
, body
);
9690 /* Parse the formal argument list. */
9691 while (*p
&& *p
!= ')')
9693 /* Find the extent of the current argument name. */
9694 const char *arg_start
= p
;
9696 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9699 if (! *p
|| p
== arg_start
)
9700 dwarf2_macro_malformed_definition_complaint (body
);
9703 /* Make sure argv has room for the new argument. */
9704 if (argc
>= argv_size
)
9707 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9710 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9713 p
= consume_improper_spaces (p
, body
);
9715 /* Consume the comma, if present. */
9720 p
= consume_improper_spaces (p
, body
);
9729 /* Perfectly formed definition, no complaints. */
9730 macro_define_function (file
, line
, name
,
9731 argc
, (const char **) argv
,
9733 else if (*p
== '\0')
9735 /* Complain, but do define it. */
9736 dwarf2_macro_malformed_definition_complaint (body
);
9737 macro_define_function (file
, line
, name
,
9738 argc
, (const char **) argv
,
9742 /* Just complain. */
9743 dwarf2_macro_malformed_definition_complaint (body
);
9746 /* Just complain. */
9747 dwarf2_macro_malformed_definition_complaint (body
);
9753 for (i
= 0; i
< argc
; i
++)
9759 dwarf2_macro_malformed_definition_complaint (body
);
9764 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9765 char *comp_dir
, bfd
*abfd
,
9766 struct dwarf2_cu
*cu
)
9768 gdb_byte
*mac_ptr
, *mac_end
;
9769 struct macro_source_file
*current_file
= 0;
9771 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9773 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9777 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9778 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9779 + dwarf2_per_objfile
->macinfo_size
;
9783 enum dwarf_macinfo_record_type macinfo_type
;
9785 /* Do we at least have room for a macinfo type byte? */
9786 if (mac_ptr
>= mac_end
)
9788 dwarf2_macros_too_long_complaint ();
9792 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9795 switch (macinfo_type
)
9797 /* A zero macinfo type indicates the end of the macro
9802 case DW_MACINFO_define
:
9803 case DW_MACINFO_undef
:
9805 unsigned int bytes_read
;
9809 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9810 mac_ptr
+= bytes_read
;
9811 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9812 mac_ptr
+= bytes_read
;
9815 complaint (&symfile_complaints
,
9816 _("debug info gives macro %s outside of any file: %s"),
9818 DW_MACINFO_define
? "definition" : macinfo_type
==
9819 DW_MACINFO_undef
? "undefinition" :
9820 "something-or-other", body
);
9823 if (macinfo_type
== DW_MACINFO_define
)
9824 parse_macro_definition (current_file
, line
, body
);
9825 else if (macinfo_type
== DW_MACINFO_undef
)
9826 macro_undef (current_file
, line
, body
);
9831 case DW_MACINFO_start_file
:
9833 unsigned int bytes_read
;
9836 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9837 mac_ptr
+= bytes_read
;
9838 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9839 mac_ptr
+= bytes_read
;
9841 current_file
= macro_start_file (file
, line
,
9842 current_file
, comp_dir
,
9847 case DW_MACINFO_end_file
:
9849 complaint (&symfile_complaints
,
9850 _("macro debug info has an unmatched `close_file' directive"));
9853 current_file
= current_file
->included_by
;
9856 enum dwarf_macinfo_record_type next_type
;
9858 /* GCC circa March 2002 doesn't produce the zero
9859 type byte marking the end of the compilation
9860 unit. Complain if it's not there, but exit no
9863 /* Do we at least have room for a macinfo type byte? */
9864 if (mac_ptr
>= mac_end
)
9866 dwarf2_macros_too_long_complaint ();
9870 /* We don't increment mac_ptr here, so this is just
9872 next_type
= read_1_byte (abfd
, mac_ptr
);
9874 complaint (&symfile_complaints
,
9875 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9882 case DW_MACINFO_vendor_ext
:
9884 unsigned int bytes_read
;
9888 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9889 mac_ptr
+= bytes_read
;
9890 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9891 mac_ptr
+= bytes_read
;
9893 /* We don't recognize any vendor extensions. */
9900 /* Check if the attribute's form is a DW_FORM_block*
9901 if so return true else false. */
9903 attr_form_is_block (struct attribute
*attr
)
9905 return (attr
== NULL
? 0 :
9906 attr
->form
== DW_FORM_block1
9907 || attr
->form
== DW_FORM_block2
9908 || attr
->form
== DW_FORM_block4
9909 || attr
->form
== DW_FORM_block
);
9912 /* Return non-zero if ATTR's value is a section offset --- classes
9913 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9914 You may use DW_UNSND (attr) to retrieve such offsets.
9916 Section 7.5.4, "Attribute Encodings", explains that no attribute
9917 may have a value that belongs to more than one of these classes; it
9918 would be ambiguous if we did, because we use the same forms for all
9921 attr_form_is_section_offset (struct attribute
*attr
)
9923 return (attr
->form
== DW_FORM_data4
9924 || attr
->form
== DW_FORM_data8
);
9928 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9929 zero otherwise. When this function returns true, you can apply
9930 dwarf2_get_attr_constant_value to it.
9932 However, note that for some attributes you must check
9933 attr_form_is_section_offset before using this test. DW_FORM_data4
9934 and DW_FORM_data8 are members of both the constant class, and of
9935 the classes that contain offsets into other debug sections
9936 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9937 that, if an attribute's can be either a constant or one of the
9938 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9939 taken as section offsets, not constants. */
9941 attr_form_is_constant (struct attribute
*attr
)
9958 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9959 struct dwarf2_cu
*cu
)
9961 if (attr_form_is_section_offset (attr
)
9962 /* ".debug_loc" may not exist at all, or the offset may be outside
9963 the section. If so, fall through to the complaint in the
9965 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9967 struct dwarf2_loclist_baton
*baton
;
9969 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9970 sizeof (struct dwarf2_loclist_baton
));
9971 baton
->per_cu
= cu
->per_cu
;
9972 gdb_assert (baton
->per_cu
);
9974 /* We don't know how long the location list is, but make sure we
9975 don't run off the edge of the section. */
9976 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9977 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9978 baton
->base_address
= cu
->header
.base_address
;
9979 if (cu
->header
.base_known
== 0)
9980 complaint (&symfile_complaints
,
9981 _("Location list used without specifying the CU base address."));
9983 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9984 SYMBOL_LOCATION_BATON (sym
) = baton
;
9988 struct dwarf2_locexpr_baton
*baton
;
9990 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9991 sizeof (struct dwarf2_locexpr_baton
));
9992 baton
->per_cu
= cu
->per_cu
;
9993 gdb_assert (baton
->per_cu
);
9995 if (attr_form_is_block (attr
))
9997 /* Note that we're just copying the block's data pointer
9998 here, not the actual data. We're still pointing into the
9999 info_buffer for SYM's objfile; right now we never release
10000 that buffer, but when we do clean up properly this may
10002 baton
->size
= DW_BLOCK (attr
)->size
;
10003 baton
->data
= DW_BLOCK (attr
)->data
;
10007 dwarf2_invalid_attrib_class_complaint ("location description",
10008 SYMBOL_NATURAL_NAME (sym
));
10010 baton
->data
= NULL
;
10013 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10014 SYMBOL_LOCATION_BATON (sym
) = baton
;
10018 /* Return the OBJFILE associated with the compilation unit CU. */
10021 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10023 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10025 /* Return the master objfile, so that we can report and look up the
10026 correct file containing this variable. */
10027 if (objfile
->separate_debug_objfile_backlink
)
10028 objfile
= objfile
->separate_debug_objfile_backlink
;
10033 /* Return the address size given in the compilation unit header for CU. */
10036 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10039 return per_cu
->cu
->header
.addr_size
;
10042 /* If the CU is not currently read in, we re-read its header. */
10043 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10044 struct dwarf2_per_objfile
*per_objfile
10045 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10046 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10048 struct comp_unit_head cu_header
;
10049 memset (&cu_header
, 0, sizeof cu_header
);
10050 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10051 return cu_header
.addr_size
;
10055 /* Locate the compilation unit from CU's objfile which contains the
10056 DIE at OFFSET. Raises an error on failure. */
10058 static struct dwarf2_per_cu_data
*
10059 dwarf2_find_containing_comp_unit (unsigned long offset
,
10060 struct objfile
*objfile
)
10062 struct dwarf2_per_cu_data
*this_cu
;
10066 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10069 int mid
= low
+ (high
- low
) / 2;
10070 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10075 gdb_assert (low
== high
);
10076 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10079 error (_("Dwarf Error: could not find partial DIE containing "
10080 "offset 0x%lx [in module %s]"),
10081 (long) offset
, bfd_get_filename (objfile
->obfd
));
10083 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10084 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10088 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10089 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10090 && offset
>= this_cu
->offset
+ this_cu
->length
)
10091 error (_("invalid dwarf2 offset %ld"), offset
);
10092 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10097 /* Locate the compilation unit from OBJFILE which is located at exactly
10098 OFFSET. Raises an error on failure. */
10100 static struct dwarf2_per_cu_data
*
10101 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10103 struct dwarf2_per_cu_data
*this_cu
;
10104 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10105 if (this_cu
->offset
!= offset
)
10106 error (_("no compilation unit with offset %ld."), offset
);
10110 /* Release one cached compilation unit, CU. We unlink it from the tree
10111 of compilation units, but we don't remove it from the read_in_chain;
10112 the caller is responsible for that. */
10115 free_one_comp_unit (void *data
)
10117 struct dwarf2_cu
*cu
= data
;
10119 if (cu
->per_cu
!= NULL
)
10120 cu
->per_cu
->cu
= NULL
;
10123 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10125 free_die_list (cu
->dies
);
10130 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10131 when we're finished with it. We can't free the pointer itself, but be
10132 sure to unlink it from the cache. Also release any associated storage
10133 and perform cache maintenance.
10135 Only used during partial symbol parsing. */
10138 free_stack_comp_unit (void *data
)
10140 struct dwarf2_cu
*cu
= data
;
10142 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10143 cu
->partial_dies
= NULL
;
10145 if (cu
->per_cu
!= NULL
)
10147 /* This compilation unit is on the stack in our caller, so we
10148 should not xfree it. Just unlink it. */
10149 cu
->per_cu
->cu
= NULL
;
10152 /* If we had a per-cu pointer, then we may have other compilation
10153 units loaded, so age them now. */
10154 age_cached_comp_units ();
10158 /* Free all cached compilation units. */
10161 free_cached_comp_units (void *data
)
10163 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10165 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10166 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10167 while (per_cu
!= NULL
)
10169 struct dwarf2_per_cu_data
*next_cu
;
10171 next_cu
= per_cu
->cu
->read_in_chain
;
10173 free_one_comp_unit (per_cu
->cu
);
10174 *last_chain
= next_cu
;
10180 /* Increase the age counter on each cached compilation unit, and free
10181 any that are too old. */
10184 age_cached_comp_units (void)
10186 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10188 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10189 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10190 while (per_cu
!= NULL
)
10192 per_cu
->cu
->last_used
++;
10193 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10194 dwarf2_mark (per_cu
->cu
);
10195 per_cu
= per_cu
->cu
->read_in_chain
;
10198 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10199 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10200 while (per_cu
!= NULL
)
10202 struct dwarf2_per_cu_data
*next_cu
;
10204 next_cu
= per_cu
->cu
->read_in_chain
;
10206 if (!per_cu
->cu
->mark
)
10208 free_one_comp_unit (per_cu
->cu
);
10209 *last_chain
= next_cu
;
10212 last_chain
= &per_cu
->cu
->read_in_chain
;
10218 /* Remove a single compilation unit from the cache. */
10221 free_one_cached_comp_unit (void *target_cu
)
10223 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10225 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10226 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10227 while (per_cu
!= NULL
)
10229 struct dwarf2_per_cu_data
*next_cu
;
10231 next_cu
= per_cu
->cu
->read_in_chain
;
10233 if (per_cu
->cu
== target_cu
)
10235 free_one_comp_unit (per_cu
->cu
);
10236 *last_chain
= next_cu
;
10240 last_chain
= &per_cu
->cu
->read_in_chain
;
10246 /* Release all extra memory associated with OBJFILE. */
10249 dwarf2_free_objfile (struct objfile
*objfile
)
10251 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10253 if (dwarf2_per_objfile
== NULL
)
10256 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10257 free_cached_comp_units (NULL
);
10259 /* Everything else should be on the objfile obstack. */
10262 /* A pair of DIE offset and GDB type pointer. We store these
10263 in a hash table separate from the DIEs, and preserve them
10264 when the DIEs are flushed out of cache. */
10266 struct dwarf2_offset_and_type
10268 unsigned int offset
;
10272 /* Hash function for a dwarf2_offset_and_type. */
10275 offset_and_type_hash (const void *item
)
10277 const struct dwarf2_offset_and_type
*ofs
= item
;
10278 return ofs
->offset
;
10281 /* Equality function for a dwarf2_offset_and_type. */
10284 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10286 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10287 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10288 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10291 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10292 table if necessary. For convenience, return TYPE. */
10294 static struct type
*
10295 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10297 struct dwarf2_offset_and_type
**slot
, ofs
;
10299 if (cu
->type_hash
== NULL
)
10301 gdb_assert (cu
->per_cu
!= NULL
);
10302 cu
->per_cu
->type_hash
10303 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10304 offset_and_type_hash
,
10305 offset_and_type_eq
,
10307 &cu
->objfile
->objfile_obstack
,
10308 hashtab_obstack_allocate
,
10309 dummy_obstack_deallocate
);
10310 cu
->type_hash
= cu
->per_cu
->type_hash
;
10313 ofs
.offset
= die
->offset
;
10315 slot
= (struct dwarf2_offset_and_type
**)
10316 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10317 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10322 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10323 not have a saved type. */
10325 static struct type
*
10326 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10328 struct dwarf2_offset_and_type
*slot
, ofs
;
10329 htab_t type_hash
= cu
->type_hash
;
10331 if (type_hash
== NULL
)
10334 ofs
.offset
= die
->offset
;
10335 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10342 /* Set the mark field in CU and in every other compilation unit in the
10343 cache that we must keep because we are keeping CU. */
10345 /* Add a dependence relationship from CU to REF_PER_CU. */
10348 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10349 struct dwarf2_per_cu_data
*ref_per_cu
)
10353 if (cu
->dependencies
== NULL
)
10355 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10356 NULL
, &cu
->comp_unit_obstack
,
10357 hashtab_obstack_allocate
,
10358 dummy_obstack_deallocate
);
10360 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10362 *slot
= ref_per_cu
;
10365 /* Set the mark field in CU and in every other compilation unit in the
10366 cache that we must keep because we are keeping CU. */
10369 dwarf2_mark_helper (void **slot
, void *data
)
10371 struct dwarf2_per_cu_data
*per_cu
;
10373 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10374 if (per_cu
->cu
->mark
)
10376 per_cu
->cu
->mark
= 1;
10378 if (per_cu
->cu
->dependencies
!= NULL
)
10379 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10385 dwarf2_mark (struct dwarf2_cu
*cu
)
10390 if (cu
->dependencies
!= NULL
)
10391 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10395 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10399 per_cu
->cu
->mark
= 0;
10400 per_cu
= per_cu
->cu
->read_in_chain
;
10404 /* Trivial hash function for partial_die_info: the hash value of a DIE
10405 is its offset in .debug_info for this objfile. */
10408 partial_die_hash (const void *item
)
10410 const struct partial_die_info
*part_die
= item
;
10411 return part_die
->offset
;
10414 /* Trivial comparison function for partial_die_info structures: two DIEs
10415 are equal if they have the same offset. */
10418 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10420 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10421 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10422 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10425 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10426 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10429 set_dwarf2_cmd (char *args
, int from_tty
)
10431 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10435 show_dwarf2_cmd (char *args
, int from_tty
)
10437 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10440 void _initialize_dwarf2_read (void);
10443 _initialize_dwarf2_read (void)
10445 dwarf2_objfile_data_key
= register_objfile_data ();
10447 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10448 Set DWARF 2 specific variables.\n\
10449 Configure DWARF 2 variables such as the cache size"),
10450 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10451 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10453 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10454 Show DWARF 2 specific variables\n\
10455 Show DWARF 2 variables such as the cache size"),
10456 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10457 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10459 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10460 &dwarf2_max_cache_age
, _("\
10461 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10462 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10463 A higher limit means that cached compilation units will be stored\n\
10464 in memory longer, and more total memory will be used. Zero disables\n\
10465 caching, which can slow down startup."),
10467 show_dwarf2_max_cache_age
,
10468 &set_dwarf2_cmdlist
,
10469 &show_dwarf2_cmdlist
);