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 /* When non-zero, dump DIEs after they are read in. */
145 static int dwarf2_die_debug
= 0;
147 /* When set, the file that we're processing is known to have debugging
148 info for C++ namespaces. GCC 3.3.x did not produce this information,
149 but later versions do. */
151 static int processing_has_namespace_info
;
153 static const struct objfile_data
*dwarf2_objfile_data_key
;
155 struct dwarf2_per_objfile
157 /* Sizes of debugging sections. */
158 unsigned int info_size
;
159 unsigned int abbrev_size
;
160 unsigned int line_size
;
161 unsigned int pubnames_size
;
162 unsigned int aranges_size
;
163 unsigned int loc_size
;
164 unsigned int macinfo_size
;
165 unsigned int str_size
;
166 unsigned int ranges_size
;
167 unsigned int frame_size
;
168 unsigned int eh_frame_size
;
170 /* Loaded data from the sections. */
171 gdb_byte
*info_buffer
;
172 gdb_byte
*abbrev_buffer
;
173 gdb_byte
*line_buffer
;
174 gdb_byte
*str_buffer
;
175 gdb_byte
*macinfo_buffer
;
176 gdb_byte
*ranges_buffer
;
177 gdb_byte
*loc_buffer
;
179 /* A list of all the compilation units. This is used to locate
180 the target compilation unit of a particular reference. */
181 struct dwarf2_per_cu_data
**all_comp_units
;
183 /* The number of compilation units in ALL_COMP_UNITS. */
186 /* A chain of compilation units that are currently read in, so that
187 they can be freed later. */
188 struct dwarf2_per_cu_data
*read_in_chain
;
190 /* A flag indicating wether this objfile has a section loaded at a
192 int has_section_at_zero
;
195 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
197 static asection
*dwarf_info_section
;
198 static asection
*dwarf_abbrev_section
;
199 static asection
*dwarf_line_section
;
200 static asection
*dwarf_pubnames_section
;
201 static asection
*dwarf_aranges_section
;
202 static asection
*dwarf_loc_section
;
203 static asection
*dwarf_macinfo_section
;
204 static asection
*dwarf_str_section
;
205 static asection
*dwarf_ranges_section
;
206 asection
*dwarf_frame_section
;
207 asection
*dwarf_eh_frame_section
;
209 /* names of the debugging sections */
211 /* Note that if the debugging section has been compressed, it might
212 have a name like .zdebug_info. */
214 #define INFO_SECTION "debug_info"
215 #define ABBREV_SECTION "debug_abbrev"
216 #define LINE_SECTION "debug_line"
217 #define PUBNAMES_SECTION "debug_pubnames"
218 #define ARANGES_SECTION "debug_aranges"
219 #define LOC_SECTION "debug_loc"
220 #define MACINFO_SECTION "debug_macinfo"
221 #define STR_SECTION "debug_str"
222 #define RANGES_SECTION "debug_ranges"
223 #define FRAME_SECTION "debug_frame"
224 #define EH_FRAME_SECTION "eh_frame"
226 /* local data types */
228 /* We hold several abbreviation tables in memory at the same time. */
229 #ifndef ABBREV_HASH_SIZE
230 #define ABBREV_HASH_SIZE 121
233 /* The data in a compilation unit header, after target2host
234 translation, looks like this. */
235 struct comp_unit_head
239 unsigned char addr_size
;
240 unsigned char signed_addr_p
;
241 unsigned int abbrev_offset
;
243 /* Size of file offsets; either 4 or 8. */
244 unsigned int offset_size
;
246 /* Size of the length field; either 4 or 12. */
247 unsigned int initial_length_size
;
249 /* Offset to the first byte of this compilation unit header in the
250 .debug_info section, for resolving relative reference dies. */
253 /* Offset to first die in this cu from the start of the cu.
254 This will be the first byte following the compilation unit header. */
255 unsigned int first_die_offset
;
258 /* Internal state when decoding a particular compilation unit. */
261 /* The objfile containing this compilation unit. */
262 struct objfile
*objfile
;
264 /* The header of the compilation unit. */
265 struct comp_unit_head header
;
267 /* Base address of this compilation unit. */
268 CORE_ADDR base_address
;
270 /* Non-zero if base_address has been set. */
273 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
275 /* The language we are debugging. */
276 enum language language
;
277 const struct language_defn
*language_defn
;
279 const char *producer
;
281 /* The generic symbol table building routines have separate lists for
282 file scope symbols and all all other scopes (local scopes). So
283 we need to select the right one to pass to add_symbol_to_list().
284 We do it by keeping a pointer to the correct list in list_in_scope.
286 FIXME: The original dwarf code just treated the file scope as the
287 first local scope, and all other local scopes as nested local
288 scopes, and worked fine. Check to see if we really need to
289 distinguish these in buildsym.c. */
290 struct pending
**list_in_scope
;
292 /* DWARF abbreviation table associated with this compilation unit. */
293 struct abbrev_info
**dwarf2_abbrevs
;
295 /* Storage for the abbrev table. */
296 struct obstack abbrev_obstack
;
298 /* Hash table holding all the loaded partial DIEs. */
301 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
302 unsigned int ranges_offset
;
304 /* Storage for things with the same lifetime as this read-in compilation
305 unit, including partial DIEs. */
306 struct obstack comp_unit_obstack
;
308 /* When multiple dwarf2_cu structures are living in memory, this field
309 chains them all together, so that they can be released efficiently.
310 We will probably also want a generation counter so that most-recently-used
311 compilation units are cached... */
312 struct dwarf2_per_cu_data
*read_in_chain
;
314 /* Backchain to our per_cu entry if the tree has been built. */
315 struct dwarf2_per_cu_data
*per_cu
;
317 /* Pointer to the die -> type map. Although it is stored
318 permanently in per_cu, we copy it here to avoid double
322 /* How many compilation units ago was this CU last referenced? */
325 /* A hash table of die offsets for following references. */
328 /* Full DIEs if read in. */
329 struct die_info
*dies
;
331 /* A set of pointers to dwarf2_per_cu_data objects for compilation
332 units referenced by this one. Only set during full symbol processing;
333 partial symbol tables do not have dependencies. */
336 /* Header data from the line table, during full symbol processing. */
337 struct line_header
*line_header
;
339 /* Mark used when releasing cached dies. */
340 unsigned int mark
: 1;
342 /* This flag will be set if this compilation unit might include
343 inter-compilation-unit references. */
344 unsigned int has_form_ref_addr
: 1;
346 /* This flag will be set if this compilation unit includes any
347 DW_TAG_namespace DIEs. If we know that there are explicit
348 DIEs for namespaces, we don't need to try to infer them
349 from mangled names. */
350 unsigned int has_namespace_info
: 1;
352 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
353 unsigned int has_ranges_offset
: 1;
356 /* Persistent data held for a compilation unit, even when not
357 processing it. We put a pointer to this structure in the
358 read_symtab_private field of the psymtab. If we encounter
359 inter-compilation-unit references, we also maintain a sorted
360 list of all compilation units. */
362 struct dwarf2_per_cu_data
364 /* The start offset and length of this compilation unit. 2**30-1
365 bytes should suffice to store the length of any compilation unit
366 - if it doesn't, GDB will fall over anyway.
367 NOTE: Unlike comp_unit_head.length, this length includes
368 initial_length_size. */
370 unsigned int length
: 30;
372 /* Flag indicating this compilation unit will be read in before
373 any of the current compilation units are processed. */
374 unsigned int queued
: 1;
376 /* This flag will be set if we need to load absolutely all DIEs
377 for this compilation unit, instead of just the ones we think
378 are interesting. It gets set if we look for a DIE in the
379 hash table and don't find it. */
380 unsigned int load_all_dies
: 1;
382 /* Set iff currently read in. */
383 struct dwarf2_cu
*cu
;
385 /* If full symbols for this CU have been read in, then this field
386 holds a map of DIE offsets to types. It isn't always possible
387 to reconstruct this information later, so we have to preserve
391 /* The partial symbol table associated with this compilation unit,
392 or NULL for partial units (which do not have an associated
394 struct partial_symtab
*psymtab
;
397 /* The line number information for a compilation unit (found in the
398 .debug_line section) begins with a "statement program header",
399 which contains the following information. */
402 unsigned int total_length
;
403 unsigned short version
;
404 unsigned int header_length
;
405 unsigned char minimum_instruction_length
;
406 unsigned char default_is_stmt
;
408 unsigned char line_range
;
409 unsigned char opcode_base
;
411 /* standard_opcode_lengths[i] is the number of operands for the
412 standard opcode whose value is i. This means that
413 standard_opcode_lengths[0] is unused, and the last meaningful
414 element is standard_opcode_lengths[opcode_base - 1]. */
415 unsigned char *standard_opcode_lengths
;
417 /* The include_directories table. NOTE! These strings are not
418 allocated with xmalloc; instead, they are pointers into
419 debug_line_buffer. If you try to free them, `free' will get
421 unsigned int num_include_dirs
, include_dirs_size
;
424 /* The file_names table. NOTE! These strings are not allocated
425 with xmalloc; instead, they are pointers into debug_line_buffer.
426 Don't try to free them directly. */
427 unsigned int num_file_names
, file_names_size
;
431 unsigned int dir_index
;
432 unsigned int mod_time
;
434 int included_p
; /* Non-zero if referenced by the Line Number Program. */
435 struct symtab
*symtab
; /* The associated symbol table, if any. */
438 /* The start and end of the statement program following this
439 header. These point into dwarf2_per_objfile->line_buffer. */
440 gdb_byte
*statement_program_start
, *statement_program_end
;
443 /* When we construct a partial symbol table entry we only
444 need this much information. */
445 struct partial_die_info
447 /* Offset of this DIE. */
450 /* DWARF-2 tag for this DIE. */
451 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
453 /* Language code associated with this DIE. This is only used
454 for the compilation unit DIE. */
455 unsigned int language
: 8;
457 /* Assorted flags describing the data found in this DIE. */
458 unsigned int has_children
: 1;
459 unsigned int is_external
: 1;
460 unsigned int is_declaration
: 1;
461 unsigned int has_type
: 1;
462 unsigned int has_specification
: 1;
463 unsigned int has_stmt_list
: 1;
464 unsigned int has_pc_info
: 1;
466 /* Flag set if the SCOPE field of this structure has been
468 unsigned int scope_set
: 1;
470 /* Flag set if the DIE has a byte_size attribute. */
471 unsigned int has_byte_size
: 1;
473 /* The name of this DIE. Normally the value of DW_AT_name, but
474 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
479 /* The scope to prepend to our children. This is generally
480 allocated on the comp_unit_obstack, so will disappear
481 when this compilation unit leaves the cache. */
484 /* The location description associated with this DIE, if any. */
485 struct dwarf_block
*locdesc
;
487 /* If HAS_PC_INFO, the PC range associated with this DIE. */
491 /* Pointer into the info_buffer pointing at the target of
492 DW_AT_sibling, if any. */
495 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
496 DW_AT_specification (or DW_AT_abstract_origin or
498 unsigned int spec_offset
;
500 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
501 unsigned int line_offset
;
503 /* Pointers to this DIE's parent, first child, and next sibling,
505 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
508 /* This data structure holds the information of an abbrev. */
511 unsigned int number
; /* number identifying abbrev */
512 enum dwarf_tag tag
; /* dwarf tag */
513 unsigned short has_children
; /* boolean */
514 unsigned short num_attrs
; /* number of attributes */
515 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
516 struct abbrev_info
*next
; /* next in chain */
521 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
522 ENUM_BITFIELD(dwarf_form
) form
: 16;
525 /* Attributes have a name and a value */
528 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
529 ENUM_BITFIELD(dwarf_form
) form
: 16;
533 struct dwarf_block
*blk
;
541 /* This data structure holds a complete die structure. */
544 /* DWARF-2 tag for this DIE. */
545 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
547 /* Number of attributes */
548 unsigned short num_attrs
;
553 /* Offset in .debug_info section */
556 /* The dies in a compilation unit form an n-ary tree. PARENT
557 points to this die's parent; CHILD points to the first child of
558 this node; and all the children of a given node are chained
559 together via their SIBLING fields, terminated by a die whose
561 struct die_info
*child
; /* Its first child, if any. */
562 struct die_info
*sibling
; /* Its next sibling, if any. */
563 struct die_info
*parent
; /* Its parent, if any. */
565 /* An array of attributes, with NUM_ATTRS elements. There may be
566 zero, but it's not common and zero-sized arrays are not
567 sufficiently portable C. */
568 struct attribute attrs
[1];
571 struct function_range
574 CORE_ADDR lowpc
, highpc
;
576 struct function_range
*next
;
579 /* Get at parts of an attribute structure */
581 #define DW_STRING(attr) ((attr)->u.str)
582 #define DW_UNSND(attr) ((attr)->u.unsnd)
583 #define DW_BLOCK(attr) ((attr)->u.blk)
584 #define DW_SND(attr) ((attr)->u.snd)
585 #define DW_ADDR(attr) ((attr)->u.addr)
587 /* Blocks are a bunch of untyped bytes. */
594 #ifndef ATTR_ALLOC_CHUNK
595 #define ATTR_ALLOC_CHUNK 4
598 /* Allocate fields for structs, unions and enums in this size. */
599 #ifndef DW_FIELD_ALLOC_CHUNK
600 #define DW_FIELD_ALLOC_CHUNK 4
603 /* A zeroed version of a partial die for initialization purposes. */
604 static struct partial_die_info zeroed_partial_die
;
606 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
607 but this would require a corresponding change in unpack_field_as_long
609 static int bits_per_byte
= 8;
611 /* The routines that read and process dies for a C struct or C++ class
612 pass lists of data member fields and lists of member function fields
613 in an instance of a field_info structure, as defined below. */
616 /* List of data member and baseclasses fields. */
619 struct nextfield
*next
;
626 /* Number of fields. */
629 /* Number of baseclasses. */
632 /* Set if the accesibility of one of the fields is not public. */
633 int non_public_fields
;
635 /* Member function fields array, entries are allocated in the order they
636 are encountered in the object file. */
639 struct nextfnfield
*next
;
640 struct fn_field fnfield
;
644 /* Member function fieldlist array, contains name of possibly overloaded
645 member function, number of overloaded member functions and a pointer
646 to the head of the member function field chain. */
651 struct nextfnfield
*head
;
655 /* Number of entries in the fnfieldlists array. */
659 /* One item on the queue of compilation units to read in full symbols
661 struct dwarf2_queue_item
663 struct dwarf2_per_cu_data
*per_cu
;
664 struct dwarf2_queue_item
*next
;
667 /* The current queue. */
668 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
670 /* Loaded secondary compilation units are kept in memory until they
671 have not been referenced for the processing of this many
672 compilation units. Set this to zero to disable caching. Cache
673 sizes of up to at least twenty will improve startup time for
674 typical inter-CU-reference binaries, at an obvious memory cost. */
675 static int dwarf2_max_cache_age
= 5;
677 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
678 struct cmd_list_element
*c
, const char *value
)
680 fprintf_filtered (file
, _("\
681 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
686 /* Various complaints about symbol reading that don't abort the process */
689 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
691 complaint (&symfile_complaints
,
692 _("statement list doesn't fit in .debug_line section"));
696 dwarf2_debug_line_missing_file_complaint (void)
698 complaint (&symfile_complaints
,
699 _(".debug_line section has line data without a file"));
703 dwarf2_debug_line_missing_end_sequence_complaint (void)
705 complaint (&symfile_complaints
,
706 _(".debug_line section has line program sequence without an end"));
710 dwarf2_complex_location_expr_complaint (void)
712 complaint (&symfile_complaints
, _("location expression too complex"));
716 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
719 complaint (&symfile_complaints
,
720 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
725 dwarf2_macros_too_long_complaint (void)
727 complaint (&symfile_complaints
,
728 _("macro info runs off end of `.debug_macinfo' section"));
732 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
734 complaint (&symfile_complaints
,
735 _("macro debug info contains a malformed macro definition:\n`%s'"),
740 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
742 complaint (&symfile_complaints
,
743 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
746 /* local function prototypes */
748 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
751 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
754 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
757 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
758 struct partial_die_info
*,
759 struct partial_symtab
*);
761 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
763 static void scan_partial_symbols (struct partial_die_info
*,
764 CORE_ADDR
*, CORE_ADDR
*,
767 static void add_partial_symbol (struct partial_die_info
*,
770 static int pdi_needs_namespace (enum dwarf_tag tag
);
772 static void add_partial_namespace (struct partial_die_info
*pdi
,
773 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
774 struct dwarf2_cu
*cu
);
776 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
777 struct dwarf2_cu
*cu
);
779 static void add_partial_subprogram (struct partial_die_info
*pdi
,
780 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
781 struct dwarf2_cu
*cu
);
783 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
786 struct dwarf2_cu
*cu
);
788 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
790 static void psymtab_to_symtab_1 (struct partial_symtab
*);
792 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
794 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
796 static void dwarf2_free_abbrev_table (void *);
798 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
801 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
804 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
807 static gdb_byte
*read_partial_die (struct partial_die_info
*,
808 struct abbrev_info
*abbrev
, unsigned int,
809 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
811 static struct partial_die_info
*find_partial_die (unsigned int,
814 static void fixup_partial_die (struct partial_die_info
*,
817 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
818 struct dwarf2_cu
*, int *);
820 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
821 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
823 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
824 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
826 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
828 static int read_1_signed_byte (bfd
*, gdb_byte
*);
830 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
832 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
834 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
836 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
839 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
841 static LONGEST read_checked_initial_length_and_offset
842 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
843 unsigned int *, unsigned int *);
845 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
848 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
850 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
852 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
854 static char *read_indirect_string (bfd
*, gdb_byte
*,
855 const struct comp_unit_head
*,
858 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
860 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
862 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
864 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
866 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
869 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
870 struct dwarf2_cu
*cu
);
872 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
874 static struct die_info
*die_specification (struct die_info
*die
,
875 struct dwarf2_cu
**);
877 static void free_line_header (struct line_header
*lh
);
879 static void add_file_name (struct line_header
*, char *, unsigned int,
880 unsigned int, unsigned int);
882 static struct line_header
*(dwarf_decode_line_header
883 (unsigned int offset
,
884 bfd
*abfd
, struct dwarf2_cu
*cu
));
886 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
887 struct dwarf2_cu
*, struct partial_symtab
*);
889 static void dwarf2_start_subfile (char *, char *, char *);
891 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
894 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
897 static void dwarf2_const_value_data (struct attribute
*attr
,
901 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
903 static struct type
*die_containing_type (struct die_info
*,
906 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
908 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
910 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
912 static char *typename_concat (struct obstack
*,
917 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
919 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
921 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
923 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
924 struct dwarf2_cu
*, struct partial_symtab
*);
926 static int dwarf2_get_pc_bounds (struct die_info
*,
927 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
929 static void get_scope_pc_bounds (struct die_info
*,
930 CORE_ADDR
*, CORE_ADDR
*,
933 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
934 CORE_ADDR
, struct dwarf2_cu
*);
936 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
939 static void dwarf2_attach_fields_to_type (struct field_info
*,
940 struct type
*, struct dwarf2_cu
*);
942 static void dwarf2_add_member_fn (struct field_info
*,
943 struct die_info
*, struct type
*,
946 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
947 struct type
*, struct dwarf2_cu
*);
949 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
951 static const char *determine_class_name (struct die_info
*die
,
952 struct dwarf2_cu
*cu
);
954 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
956 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
958 static const char *namespace_name (struct die_info
*die
,
959 int *is_anonymous
, struct dwarf2_cu
*);
961 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
963 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
965 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
968 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
970 static struct die_info
*read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
972 gdb_byte
**new_info_ptr
,
973 struct die_info
*parent
);
975 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
977 gdb_byte
**new_info_ptr
,
978 struct die_info
*parent
);
980 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
982 gdb_byte
**new_info_ptr
,
983 struct die_info
*parent
);
985 static void process_die (struct die_info
*, struct dwarf2_cu
*);
987 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
989 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
991 static struct die_info
*dwarf2_extension (struct die_info
*die
,
992 struct dwarf2_cu
**);
994 static char *dwarf_tag_name (unsigned int);
996 static char *dwarf_attr_name (unsigned int);
998 static char *dwarf_form_name (unsigned int);
1000 static char *dwarf_stack_op_name (unsigned int);
1002 static char *dwarf_bool_name (unsigned int);
1004 static char *dwarf_type_encoding_name (unsigned int);
1007 static char *dwarf_cfi_name (unsigned int);
1010 static struct die_info
*sibling_die (struct die_info
*);
1012 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1014 static void dump_die_for_error (struct die_info
*);
1016 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1019 /*static*/ void dump_die (struct die_info
*, int max_level
);
1021 static void store_in_ref_table (struct die_info
*,
1022 struct dwarf2_cu
*);
1024 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1026 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1028 static struct die_info
*follow_die_ref (struct die_info
*,
1030 struct dwarf2_cu
**);
1032 /* memory allocation interface */
1034 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1036 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1038 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1040 static void initialize_cu_func_list (struct dwarf2_cu
*);
1042 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1043 struct dwarf2_cu
*);
1045 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1046 char *, bfd
*, struct dwarf2_cu
*);
1048 static int attr_form_is_block (struct attribute
*);
1050 static int attr_form_is_section_offset (struct attribute
*);
1052 static int attr_form_is_constant (struct attribute
*);
1054 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1056 struct dwarf2_cu
*cu
);
1058 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1059 struct dwarf2_cu
*cu
);
1061 static void free_stack_comp_unit (void *);
1063 static hashval_t
partial_die_hash (const void *item
);
1065 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1067 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1068 (unsigned int offset
, struct objfile
*objfile
);
1070 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1071 (unsigned int offset
, struct objfile
*objfile
);
1073 static void free_one_comp_unit (void *);
1075 static void free_cached_comp_units (void *);
1077 static void age_cached_comp_units (void);
1079 static void free_one_cached_comp_unit (void *);
1081 static struct type
*set_die_type (struct die_info
*, struct type
*,
1082 struct dwarf2_cu
*);
1084 static void create_all_comp_units (struct objfile
*);
1086 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1089 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1091 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1092 struct dwarf2_per_cu_data
*);
1094 static void dwarf2_mark (struct dwarf2_cu
*);
1096 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1098 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1100 /* Try to locate the sections we need for DWARF 2 debugging
1101 information and return true if we have enough to do something. */
1104 dwarf2_has_info (struct objfile
*objfile
)
1106 struct dwarf2_per_objfile
*data
;
1108 /* Initialize per-objfile state. */
1109 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1110 memset (data
, 0, sizeof (*data
));
1111 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1112 dwarf2_per_objfile
= data
;
1114 dwarf_info_section
= 0;
1115 dwarf_abbrev_section
= 0;
1116 dwarf_line_section
= 0;
1117 dwarf_str_section
= 0;
1118 dwarf_macinfo_section
= 0;
1119 dwarf_frame_section
= 0;
1120 dwarf_eh_frame_section
= 0;
1121 dwarf_ranges_section
= 0;
1122 dwarf_loc_section
= 0;
1124 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1125 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1128 /* When loading sections, we can either look for ".<name>", or for
1129 * ".z<name>", which indicates a compressed section. */
1132 section_is_p (asection
*sectp
, const char *name
)
1134 return ((sectp
->name
[0] == '.'
1135 && strcmp (sectp
->name
+ 1, name
) == 0)
1136 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1137 && strcmp (sectp
->name
+ 2, name
) == 0));
1140 /* This function is mapped across the sections and remembers the
1141 offset and size of each of the debugging sections we are interested
1145 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1147 if (section_is_p (sectp
, INFO_SECTION
))
1149 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1150 dwarf_info_section
= sectp
;
1152 else if (section_is_p (sectp
, ABBREV_SECTION
))
1154 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1155 dwarf_abbrev_section
= sectp
;
1157 else if (section_is_p (sectp
, LINE_SECTION
))
1159 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1160 dwarf_line_section
= sectp
;
1162 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1164 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1165 dwarf_pubnames_section
= sectp
;
1167 else if (section_is_p (sectp
, ARANGES_SECTION
))
1169 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1170 dwarf_aranges_section
= sectp
;
1172 else if (section_is_p (sectp
, LOC_SECTION
))
1174 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1175 dwarf_loc_section
= sectp
;
1177 else if (section_is_p (sectp
, MACINFO_SECTION
))
1179 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1180 dwarf_macinfo_section
= sectp
;
1182 else if (section_is_p (sectp
, STR_SECTION
))
1184 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1185 dwarf_str_section
= sectp
;
1187 else if (section_is_p (sectp
, FRAME_SECTION
))
1189 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1190 dwarf_frame_section
= sectp
;
1192 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1194 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1195 if (aflag
& SEC_HAS_CONTENTS
)
1197 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1198 dwarf_eh_frame_section
= sectp
;
1201 else if (section_is_p (sectp
, RANGES_SECTION
))
1203 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1204 dwarf_ranges_section
= sectp
;
1207 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1208 && bfd_section_vma (abfd
, sectp
) == 0)
1209 dwarf2_per_objfile
->has_section_at_zero
= 1;
1212 /* This function is called after decompressing a section, so
1213 dwarf2_per_objfile can record its new, uncompressed size. */
1216 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1218 if (section_is_p (sectp
, INFO_SECTION
))
1219 dwarf2_per_objfile
->info_size
= new_size
;
1220 else if (section_is_p (sectp
, ABBREV_SECTION
))
1221 dwarf2_per_objfile
->abbrev_size
= new_size
;
1222 else if (section_is_p (sectp
, LINE_SECTION
))
1223 dwarf2_per_objfile
->line_size
= new_size
;
1224 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1225 dwarf2_per_objfile
->pubnames_size
= new_size
;
1226 else if (section_is_p (sectp
, ARANGES_SECTION
))
1227 dwarf2_per_objfile
->aranges_size
= new_size
;
1228 else if (section_is_p (sectp
, LOC_SECTION
))
1229 dwarf2_per_objfile
->loc_size
= new_size
;
1230 else if (section_is_p (sectp
, MACINFO_SECTION
))
1231 dwarf2_per_objfile
->macinfo_size
= new_size
;
1232 else if (section_is_p (sectp
, STR_SECTION
))
1233 dwarf2_per_objfile
->str_size
= new_size
;
1234 else if (section_is_p (sectp
, FRAME_SECTION
))
1235 dwarf2_per_objfile
->frame_size
= new_size
;
1236 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1237 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1238 else if (section_is_p (sectp
, RANGES_SECTION
))
1239 dwarf2_per_objfile
->ranges_size
= new_size
;
1241 internal_error (__FILE__
, __LINE__
,
1242 _("dwarf2_resize_section: missing section_is_p check: %s"),
1246 /* Build a partial symbol table. */
1249 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1251 /* We definitely need the .debug_info and .debug_abbrev sections */
1253 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1254 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1256 if (dwarf_line_section
)
1257 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1259 dwarf2_per_objfile
->line_buffer
= NULL
;
1261 if (dwarf_str_section
)
1262 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1264 dwarf2_per_objfile
->str_buffer
= NULL
;
1266 if (dwarf_macinfo_section
)
1267 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1268 dwarf_macinfo_section
);
1270 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1272 if (dwarf_ranges_section
)
1273 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1275 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1277 if (dwarf_loc_section
)
1278 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1280 dwarf2_per_objfile
->loc_buffer
= NULL
;
1283 || (objfile
->global_psymbols
.size
== 0
1284 && objfile
->static_psymbols
.size
== 0))
1286 init_psymbol_list (objfile
, 1024);
1290 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1292 /* Things are significantly easier if we have .debug_aranges and
1293 .debug_pubnames sections */
1295 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1299 /* only test this case for now */
1301 /* In this case we have to work a bit harder */
1302 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1307 /* Build the partial symbol table from the information in the
1308 .debug_pubnames and .debug_aranges sections. */
1311 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1313 bfd
*abfd
= objfile
->obfd
;
1314 char *aranges_buffer
, *pubnames_buffer
;
1315 char *aranges_ptr
, *pubnames_ptr
;
1316 unsigned int entry_length
, version
, info_offset
, info_size
;
1318 pubnames_buffer
= dwarf2_read_section (objfile
,
1319 dwarf_pubnames_section
);
1320 pubnames_ptr
= pubnames_buffer
;
1321 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1323 unsigned int bytes_read
;
1325 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1326 pubnames_ptr
+= bytes_read
;
1327 version
= read_1_byte (abfd
, pubnames_ptr
);
1329 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1331 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1335 aranges_buffer
= dwarf2_read_section (objfile
,
1336 dwarf_aranges_section
);
1341 /* Return TRUE if OFFSET is within CU_HEADER. */
1344 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1346 unsigned int bottom
= cu_header
->offset
;
1347 unsigned int top
= (cu_header
->offset
1349 + cu_header
->initial_length_size
);
1350 return (offset
>= bottom
&& offset
< top
);
1353 /* Read in the comp unit header information from the debug_info at
1357 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1358 gdb_byte
*info_ptr
, bfd
*abfd
)
1361 unsigned int bytes_read
;
1363 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1364 cu_header
->initial_length_size
= bytes_read
;
1365 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1366 info_ptr
+= bytes_read
;
1367 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1369 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1371 info_ptr
+= bytes_read
;
1372 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1374 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1375 if (signed_addr
< 0)
1376 internal_error (__FILE__
, __LINE__
,
1377 _("read_comp_unit_head: dwarf from non elf file"));
1378 cu_header
->signed_addr_p
= signed_addr
;
1384 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1387 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1389 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1391 if (header
->version
!= 2 && header
->version
!= 3)
1392 error (_("Dwarf Error: wrong version in compilation unit header "
1393 "(is %d, should be %d) [in module %s]"), header
->version
,
1394 2, bfd_get_filename (abfd
));
1396 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1397 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1398 "(offset 0x%lx + 6) [in module %s]"),
1399 (long) header
->abbrev_offset
,
1400 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1401 bfd_get_filename (abfd
));
1403 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1404 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1405 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1406 "(offset 0x%lx + 0) [in module %s]"),
1407 (long) header
->length
,
1408 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1409 bfd_get_filename (abfd
));
1414 /* Allocate a new partial symtab for file named NAME and mark this new
1415 partial symtab as being an include of PST. */
1418 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1419 struct objfile
*objfile
)
1421 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1423 subpst
->section_offsets
= pst
->section_offsets
;
1424 subpst
->textlow
= 0;
1425 subpst
->texthigh
= 0;
1427 subpst
->dependencies
= (struct partial_symtab
**)
1428 obstack_alloc (&objfile
->objfile_obstack
,
1429 sizeof (struct partial_symtab
*));
1430 subpst
->dependencies
[0] = pst
;
1431 subpst
->number_of_dependencies
= 1;
1433 subpst
->globals_offset
= 0;
1434 subpst
->n_global_syms
= 0;
1435 subpst
->statics_offset
= 0;
1436 subpst
->n_static_syms
= 0;
1437 subpst
->symtab
= NULL
;
1438 subpst
->read_symtab
= pst
->read_symtab
;
1441 /* No private part is necessary for include psymtabs. This property
1442 can be used to differentiate between such include psymtabs and
1443 the regular ones. */
1444 subpst
->read_symtab_private
= NULL
;
1447 /* Read the Line Number Program data and extract the list of files
1448 included by the source file represented by PST. Build an include
1449 partial symtab for each of these included files.
1451 This procedure assumes that there *is* a Line Number Program in
1452 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1453 before calling this procedure. */
1456 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1457 struct partial_die_info
*pdi
,
1458 struct partial_symtab
*pst
)
1460 struct objfile
*objfile
= cu
->objfile
;
1461 bfd
*abfd
= objfile
->obfd
;
1462 struct line_header
*lh
;
1464 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1466 return; /* No linetable, so no includes. */
1468 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1470 free_line_header (lh
);
1474 /* Build the partial symbol table by doing a quick pass through the
1475 .debug_info and .debug_abbrev sections. */
1478 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1480 /* Instead of reading this into a big buffer, we should probably use
1481 mmap() on architectures that support it. (FIXME) */
1482 bfd
*abfd
= objfile
->obfd
;
1484 gdb_byte
*beg_of_comp_unit
;
1485 struct partial_die_info comp_unit_die
;
1486 struct partial_symtab
*pst
;
1487 struct cleanup
*back_to
;
1488 CORE_ADDR lowpc
, highpc
, baseaddr
;
1490 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1492 /* Any cached compilation units will be linked by the per-objfile
1493 read_in_chain. Make sure to free them when we're done. */
1494 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1496 create_all_comp_units (objfile
);
1498 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1499 (&objfile
->objfile_obstack
);
1501 /* Since the objects we're extracting from .debug_info vary in
1502 length, only the individual functions to extract them (like
1503 read_comp_unit_head and load_partial_die) can really know whether
1504 the buffer is large enough to hold another complete object.
1506 At the moment, they don't actually check that. If .debug_info
1507 holds just one extra byte after the last compilation unit's dies,
1508 then read_comp_unit_head will happily read off the end of the
1509 buffer. read_partial_die is similarly casual. Those functions
1512 For this loop condition, simply checking whether there's any data
1513 left at all should be sufficient. */
1514 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1515 + dwarf2_per_objfile
->info_size
))
1517 struct cleanup
*back_to_inner
;
1518 struct dwarf2_cu cu
;
1519 struct abbrev_info
*abbrev
;
1520 unsigned int bytes_read
;
1521 struct dwarf2_per_cu_data
*this_cu
;
1523 beg_of_comp_unit
= info_ptr
;
1525 memset (&cu
, 0, sizeof (cu
));
1527 obstack_init (&cu
.comp_unit_obstack
);
1529 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1531 cu
.objfile
= objfile
;
1532 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1534 /* Complete the cu_header */
1535 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1536 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1538 cu
.list_in_scope
= &file_symbols
;
1540 /* Read the abbrevs for this compilation unit into a table */
1541 dwarf2_read_abbrevs (abfd
, &cu
);
1542 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1544 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1546 /* Read the compilation unit die */
1547 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1548 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1549 abfd
, info_ptr
, &cu
);
1551 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1553 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1554 + cu
.header
.initial_length_size
);
1555 do_cleanups (back_to_inner
);
1559 /* Set the language we're debugging */
1560 set_cu_language (comp_unit_die
.language
, &cu
);
1562 /* Allocate a new partial symbol table structure */
1563 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1564 comp_unit_die
.name
? comp_unit_die
.name
: "",
1565 /* TEXTLOW and TEXTHIGH are set below. */
1567 objfile
->global_psymbols
.next
,
1568 objfile
->static_psymbols
.next
);
1570 if (comp_unit_die
.dirname
)
1571 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1572 strlen (comp_unit_die
.dirname
),
1573 &objfile
->objfile_obstack
);
1575 pst
->read_symtab_private
= (char *) this_cu
;
1577 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1579 /* Store the function that reads in the rest of the symbol table */
1580 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1582 /* If this compilation unit was already read in, free the
1583 cached copy in order to read it in again. This is
1584 necessary because we skipped some symbols when we first
1585 read in the compilation unit (see load_partial_dies).
1586 This problem could be avoided, but the benefit is
1588 if (this_cu
->cu
!= NULL
)
1589 free_one_cached_comp_unit (this_cu
->cu
);
1591 cu
.per_cu
= this_cu
;
1593 /* Note that this is a pointer to our stack frame, being
1594 added to a global data structure. It will be cleaned up
1595 in free_stack_comp_unit when we finish with this
1596 compilation unit. */
1599 this_cu
->psymtab
= pst
;
1601 /* Possibly set the default values of LOWPC and HIGHPC from
1603 if (cu
.has_ranges_offset
)
1605 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1606 &comp_unit_die
.highpc
, &cu
, pst
))
1607 comp_unit_die
.has_pc_info
= 1;
1610 /* Check if comp unit has_children.
1611 If so, read the rest of the partial symbols from this comp unit.
1612 If not, there's no more debug_info for this comp unit. */
1613 if (comp_unit_die
.has_children
)
1615 struct partial_die_info
*first_die
;
1617 lowpc
= ((CORE_ADDR
) -1);
1618 highpc
= ((CORE_ADDR
) 0);
1620 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1622 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1624 /* If we didn't find a lowpc, set it to highpc to avoid
1625 complaints from `maint check'. */
1626 if (lowpc
== ((CORE_ADDR
) -1))
1629 /* If the compilation unit didn't have an explicit address range,
1630 then use the information extracted from its child dies. */
1631 if (! comp_unit_die
.has_pc_info
)
1633 comp_unit_die
.lowpc
= lowpc
;
1634 comp_unit_die
.highpc
= highpc
;
1637 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1638 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1640 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1641 range can be also empty for CUs with no code. */
1642 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1643 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1644 pst
->texthigh
- 1, pst
);
1646 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1647 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1648 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1649 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1650 sort_pst_symbols (pst
);
1652 /* If there is already a psymtab or symtab for a file of this
1653 name, remove it. (If there is a symtab, more drastic things
1654 also happen.) This happens in VxWorks. */
1655 free_named_symtabs (pst
->filename
);
1657 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1658 + cu
.header
.initial_length_size
;
1660 if (comp_unit_die
.has_stmt_list
)
1662 /* Get the list of files included in the current compilation unit,
1663 and build a psymtab for each of them. */
1664 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1667 do_cleanups (back_to_inner
);
1670 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1671 &objfile
->objfile_obstack
);
1673 do_cleanups (back_to
);
1676 /* Load the DIEs for a secondary CU into memory. */
1679 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1681 bfd
*abfd
= objfile
->obfd
;
1682 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1683 struct partial_die_info comp_unit_die
;
1684 struct dwarf2_cu
*cu
;
1685 struct abbrev_info
*abbrev
;
1686 unsigned int bytes_read
;
1687 struct cleanup
*back_to
;
1689 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1690 beg_of_comp_unit
= info_ptr
;
1692 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1693 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1695 obstack_init (&cu
->comp_unit_obstack
);
1697 cu
->objfile
= objfile
;
1698 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1700 /* Complete the cu_header. */
1701 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1702 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1704 /* Read the abbrevs for this compilation unit into a table. */
1705 dwarf2_read_abbrevs (abfd
, cu
);
1706 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1708 /* Read the compilation unit die. */
1709 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1710 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1711 abfd
, info_ptr
, cu
);
1713 /* Set the language we're debugging. */
1714 set_cu_language (comp_unit_die
.language
, cu
);
1716 /* Link this compilation unit into the compilation unit tree. */
1718 cu
->per_cu
= this_cu
;
1719 cu
->type_hash
= cu
->per_cu
->type_hash
;
1721 /* Check if comp unit has_children.
1722 If so, read the rest of the partial symbols from this comp unit.
1723 If not, there's no more debug_info for this comp unit. */
1724 if (comp_unit_die
.has_children
)
1725 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1727 do_cleanups (back_to
);
1730 /* Create a list of all compilation units in OBJFILE. We do this only
1731 if an inter-comp-unit reference is found; presumably if there is one,
1732 there will be many, and one will occur early in the .debug_info section.
1733 So there's no point in building this list incrementally. */
1736 create_all_comp_units (struct objfile
*objfile
)
1740 struct dwarf2_per_cu_data
**all_comp_units
;
1741 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1745 all_comp_units
= xmalloc (n_allocated
1746 * sizeof (struct dwarf2_per_cu_data
*));
1748 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1750 unsigned int length
, initial_length_size
;
1751 gdb_byte
*beg_of_comp_unit
;
1752 struct dwarf2_per_cu_data
*this_cu
;
1753 unsigned int offset
;
1755 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1757 /* Read just enough information to find out where the next
1758 compilation unit is. */
1759 length
= read_initial_length (objfile
->obfd
, info_ptr
,
1760 &initial_length_size
);
1762 /* Save the compilation unit for later lookup. */
1763 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1764 sizeof (struct dwarf2_per_cu_data
));
1765 memset (this_cu
, 0, sizeof (*this_cu
));
1766 this_cu
->offset
= offset
;
1767 this_cu
->length
= length
+ initial_length_size
;
1769 if (n_comp_units
== n_allocated
)
1772 all_comp_units
= xrealloc (all_comp_units
,
1774 * sizeof (struct dwarf2_per_cu_data
*));
1776 all_comp_units
[n_comp_units
++] = this_cu
;
1778 info_ptr
= info_ptr
+ this_cu
->length
;
1781 dwarf2_per_objfile
->all_comp_units
1782 = obstack_alloc (&objfile
->objfile_obstack
,
1783 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1784 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1785 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1786 xfree (all_comp_units
);
1787 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1790 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1791 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1795 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1796 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1798 struct objfile
*objfile
= cu
->objfile
;
1799 bfd
*abfd
= objfile
->obfd
;
1800 struct partial_die_info
*pdi
;
1802 /* Now, march along the PDI's, descending into ones which have
1803 interesting children but skipping the children of the other ones,
1804 until we reach the end of the compilation unit. */
1810 fixup_partial_die (pdi
, cu
);
1812 /* Anonymous namespaces have no name but have interesting
1813 children, so we need to look at them. Ditto for anonymous
1816 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1817 || pdi
->tag
== DW_TAG_enumeration_type
)
1821 case DW_TAG_subprogram
:
1822 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
1824 case DW_TAG_variable
:
1825 case DW_TAG_typedef
:
1826 case DW_TAG_union_type
:
1827 if (!pdi
->is_declaration
)
1829 add_partial_symbol (pdi
, cu
);
1832 case DW_TAG_class_type
:
1833 case DW_TAG_interface_type
:
1834 case DW_TAG_structure_type
:
1835 if (!pdi
->is_declaration
)
1837 add_partial_symbol (pdi
, cu
);
1840 case DW_TAG_enumeration_type
:
1841 if (!pdi
->is_declaration
)
1842 add_partial_enumeration (pdi
, cu
);
1844 case DW_TAG_base_type
:
1845 case DW_TAG_subrange_type
:
1846 /* File scope base type definitions are added to the partial
1848 add_partial_symbol (pdi
, cu
);
1850 case DW_TAG_namespace
:
1851 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1858 /* If the die has a sibling, skip to the sibling. */
1860 pdi
= pdi
->die_sibling
;
1864 /* Functions used to compute the fully scoped name of a partial DIE.
1866 Normally, this is simple. For C++, the parent DIE's fully scoped
1867 name is concatenated with "::" and the partial DIE's name. For
1868 Java, the same thing occurs except that "." is used instead of "::".
1869 Enumerators are an exception; they use the scope of their parent
1870 enumeration type, i.e. the name of the enumeration type is not
1871 prepended to the enumerator.
1873 There are two complexities. One is DW_AT_specification; in this
1874 case "parent" means the parent of the target of the specification,
1875 instead of the direct parent of the DIE. The other is compilers
1876 which do not emit DW_TAG_namespace; in this case we try to guess
1877 the fully qualified name of structure types from their members'
1878 linkage names. This must be done using the DIE's children rather
1879 than the children of any DW_AT_specification target. We only need
1880 to do this for structures at the top level, i.e. if the target of
1881 any DW_AT_specification (if any; otherwise the DIE itself) does not
1884 /* Compute the scope prefix associated with PDI's parent, in
1885 compilation unit CU. The result will be allocated on CU's
1886 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1887 field. NULL is returned if no prefix is necessary. */
1889 partial_die_parent_scope (struct partial_die_info
*pdi
,
1890 struct dwarf2_cu
*cu
)
1892 char *grandparent_scope
;
1893 struct partial_die_info
*parent
, *real_pdi
;
1895 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1896 then this means the parent of the specification DIE. */
1899 while (real_pdi
->has_specification
)
1900 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1902 parent
= real_pdi
->die_parent
;
1906 if (parent
->scope_set
)
1907 return parent
->scope
;
1909 fixup_partial_die (parent
, cu
);
1911 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1913 if (parent
->tag
== DW_TAG_namespace
1914 || parent
->tag
== DW_TAG_structure_type
1915 || parent
->tag
== DW_TAG_class_type
1916 || parent
->tag
== DW_TAG_interface_type
1917 || parent
->tag
== DW_TAG_union_type
)
1919 if (grandparent_scope
== NULL
)
1920 parent
->scope
= parent
->name
;
1922 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1925 else if (parent
->tag
== DW_TAG_enumeration_type
)
1926 /* Enumerators should not get the name of the enumeration as a prefix. */
1927 parent
->scope
= grandparent_scope
;
1930 /* FIXME drow/2004-04-01: What should we be doing with
1931 function-local names? For partial symbols, we should probably be
1933 complaint (&symfile_complaints
,
1934 _("unhandled containing DIE tag %d for DIE at %d"),
1935 parent
->tag
, pdi
->offset
);
1936 parent
->scope
= grandparent_scope
;
1939 parent
->scope_set
= 1;
1940 return parent
->scope
;
1943 /* Return the fully scoped name associated with PDI, from compilation unit
1944 CU. The result will be allocated with malloc. */
1946 partial_die_full_name (struct partial_die_info
*pdi
,
1947 struct dwarf2_cu
*cu
)
1951 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1952 if (parent_scope
== NULL
)
1955 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1959 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1961 struct objfile
*objfile
= cu
->objfile
;
1963 char *actual_name
= NULL
;
1964 const char *my_prefix
;
1965 const struct partial_symbol
*psym
= NULL
;
1967 int built_actual_name
= 0;
1969 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1971 if (pdi_needs_namespace (pdi
->tag
))
1973 actual_name
= partial_die_full_name (pdi
, cu
);
1975 built_actual_name
= 1;
1978 if (actual_name
== NULL
)
1979 actual_name
= pdi
->name
;
1983 case DW_TAG_subprogram
:
1984 if (pdi
->is_external
|| cu
->language
== language_ada
)
1986 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1987 of the global scope. But in Ada, we want to be able to access
1988 nested procedures globally. So all Ada subprograms are stored
1989 in the global scope. */
1990 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1991 mst_text, objfile); */
1992 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1993 VAR_DOMAIN
, LOC_BLOCK
,
1994 &objfile
->global_psymbols
,
1995 0, pdi
->lowpc
+ baseaddr
,
1996 cu
->language
, objfile
);
2000 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2001 mst_file_text, objfile); */
2002 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2003 VAR_DOMAIN
, LOC_BLOCK
,
2004 &objfile
->static_psymbols
,
2005 0, pdi
->lowpc
+ baseaddr
,
2006 cu
->language
, objfile
);
2009 case DW_TAG_variable
:
2010 if (pdi
->is_external
)
2013 Don't enter into the minimal symbol tables as there is
2014 a minimal symbol table entry from the ELF symbols already.
2015 Enter into partial symbol table if it has a location
2016 descriptor or a type.
2017 If the location descriptor is missing, new_symbol will create
2018 a LOC_UNRESOLVED symbol, the address of the variable will then
2019 be determined from the minimal symbol table whenever the variable
2021 The address for the partial symbol table entry is not
2022 used by GDB, but it comes in handy for debugging partial symbol
2026 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2027 if (pdi
->locdesc
|| pdi
->has_type
)
2028 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2029 VAR_DOMAIN
, LOC_STATIC
,
2030 &objfile
->global_psymbols
,
2032 cu
->language
, objfile
);
2036 /* Static Variable. Skip symbols without location descriptors. */
2037 if (pdi
->locdesc
== NULL
)
2039 if (built_actual_name
)
2040 xfree (actual_name
);
2043 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2044 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2045 mst_file_data, objfile); */
2046 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2047 VAR_DOMAIN
, LOC_STATIC
,
2048 &objfile
->static_psymbols
,
2050 cu
->language
, objfile
);
2053 case DW_TAG_typedef
:
2054 case DW_TAG_base_type
:
2055 case DW_TAG_subrange_type
:
2056 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2057 VAR_DOMAIN
, LOC_TYPEDEF
,
2058 &objfile
->static_psymbols
,
2059 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2061 case DW_TAG_namespace
:
2062 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2063 VAR_DOMAIN
, LOC_TYPEDEF
,
2064 &objfile
->global_psymbols
,
2065 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2067 case DW_TAG_class_type
:
2068 case DW_TAG_interface_type
:
2069 case DW_TAG_structure_type
:
2070 case DW_TAG_union_type
:
2071 case DW_TAG_enumeration_type
:
2072 /* Skip external references. The DWARF standard says in the section
2073 about "Structure, Union, and Class Type Entries": "An incomplete
2074 structure, union or class type is represented by a structure,
2075 union or class entry that does not have a byte size attribute
2076 and that has a DW_AT_declaration attribute." */
2077 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2079 if (built_actual_name
)
2080 xfree (actual_name
);
2084 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2085 static vs. global. */
2086 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2087 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2088 (cu
->language
== language_cplus
2089 || cu
->language
== language_java
)
2090 ? &objfile
->global_psymbols
2091 : &objfile
->static_psymbols
,
2092 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2095 case DW_TAG_enumerator
:
2096 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2097 VAR_DOMAIN
, LOC_CONST
,
2098 (cu
->language
== language_cplus
2099 || cu
->language
== language_java
)
2100 ? &objfile
->global_psymbols
2101 : &objfile
->static_psymbols
,
2102 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2108 /* Check to see if we should scan the name for possible namespace
2109 info. Only do this if this is C++, if we don't have namespace
2110 debugging info in the file, if the psym is of an appropriate type
2111 (otherwise we'll have psym == NULL), and if we actually had a
2112 mangled name to begin with. */
2114 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2115 cases which do not set PSYM above? */
2117 if (cu
->language
== language_cplus
2118 && cu
->has_namespace_info
== 0
2120 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2121 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2124 if (built_actual_name
)
2125 xfree (actual_name
);
2128 /* Determine whether a die of type TAG living in a C++ class or
2129 namespace needs to have the name of the scope prepended to the
2130 name listed in the die. */
2133 pdi_needs_namespace (enum dwarf_tag tag
)
2137 case DW_TAG_namespace
:
2138 case DW_TAG_typedef
:
2139 case DW_TAG_class_type
:
2140 case DW_TAG_interface_type
:
2141 case DW_TAG_structure_type
:
2142 case DW_TAG_union_type
:
2143 case DW_TAG_enumeration_type
:
2144 case DW_TAG_enumerator
:
2151 /* Read a partial die corresponding to a namespace; also, add a symbol
2152 corresponding to that namespace to the symbol table. NAMESPACE is
2153 the name of the enclosing namespace. */
2156 add_partial_namespace (struct partial_die_info
*pdi
,
2157 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2158 struct dwarf2_cu
*cu
)
2160 struct objfile
*objfile
= cu
->objfile
;
2162 /* Add a symbol for the namespace. */
2164 add_partial_symbol (pdi
, cu
);
2166 /* Now scan partial symbols in that namespace. */
2168 if (pdi
->has_children
)
2169 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2172 /* Read a partial die corresponding to a subprogram and create a partial
2173 symbol for that subprogram. When the CU language allows it, this
2174 routine also defines a partial symbol for each nested subprogram
2175 that this subprogram contains.
2177 DIE my also be a lexical block, in which case we simply search
2178 recursively for suprograms defined inside that lexical block.
2179 Again, this is only performed when the CU language allows this
2180 type of definitions. */
2183 add_partial_subprogram (struct partial_die_info
*pdi
,
2184 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2185 struct dwarf2_cu
*cu
)
2187 if (pdi
->tag
== DW_TAG_subprogram
)
2189 if (pdi
->has_pc_info
)
2191 if (pdi
->lowpc
< *lowpc
)
2192 *lowpc
= pdi
->lowpc
;
2193 if (pdi
->highpc
> *highpc
)
2194 *highpc
= pdi
->highpc
;
2195 if (!pdi
->is_declaration
)
2196 add_partial_symbol (pdi
, cu
);
2200 if (! pdi
->has_children
)
2203 if (cu
->language
== language_ada
)
2205 pdi
= pdi
->die_child
;
2208 fixup_partial_die (pdi
, cu
);
2209 if (pdi
->tag
== DW_TAG_subprogram
2210 || pdi
->tag
== DW_TAG_lexical_block
)
2211 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
2212 pdi
= pdi
->die_sibling
;
2217 /* See if we can figure out if the class lives in a namespace. We do
2218 this by looking for a member function; its demangled name will
2219 contain namespace info, if there is any. */
2222 guess_structure_name (struct partial_die_info
*struct_pdi
,
2223 struct dwarf2_cu
*cu
)
2225 if ((cu
->language
== language_cplus
2226 || cu
->language
== language_java
)
2227 && cu
->has_namespace_info
== 0
2228 && struct_pdi
->has_children
)
2230 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2231 what template types look like, because the demangler
2232 frequently doesn't give the same name as the debug info. We
2233 could fix this by only using the demangled name to get the
2234 prefix (but see comment in read_structure_type). */
2236 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2237 struct partial_die_info
*real_pdi
;
2239 /* If this DIE (this DIE's specification, if any) has a parent, then
2240 we should not do this. We'll prepend the parent's fully qualified
2241 name when we create the partial symbol. */
2243 real_pdi
= struct_pdi
;
2244 while (real_pdi
->has_specification
)
2245 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2247 if (real_pdi
->die_parent
!= NULL
)
2250 while (child_pdi
!= NULL
)
2252 if (child_pdi
->tag
== DW_TAG_subprogram
)
2254 char *actual_class_name
2255 = language_class_name_from_physname (cu
->language_defn
,
2257 if (actual_class_name
!= NULL
)
2260 = obsavestring (actual_class_name
,
2261 strlen (actual_class_name
),
2262 &cu
->comp_unit_obstack
);
2263 xfree (actual_class_name
);
2268 child_pdi
= child_pdi
->die_sibling
;
2273 /* Read a partial die corresponding to an enumeration type. */
2276 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2277 struct dwarf2_cu
*cu
)
2279 struct objfile
*objfile
= cu
->objfile
;
2280 bfd
*abfd
= objfile
->obfd
;
2281 struct partial_die_info
*pdi
;
2283 if (enum_pdi
->name
!= NULL
)
2284 add_partial_symbol (enum_pdi
, cu
);
2286 pdi
= enum_pdi
->die_child
;
2289 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2290 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2292 add_partial_symbol (pdi
, cu
);
2293 pdi
= pdi
->die_sibling
;
2297 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2298 Return the corresponding abbrev, or NULL if the number is zero (indicating
2299 an empty DIE). In either case *BYTES_READ will be set to the length of
2300 the initial number. */
2302 static struct abbrev_info
*
2303 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2304 struct dwarf2_cu
*cu
)
2306 bfd
*abfd
= cu
->objfile
->obfd
;
2307 unsigned int abbrev_number
;
2308 struct abbrev_info
*abbrev
;
2310 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2312 if (abbrev_number
== 0)
2315 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2318 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2319 bfd_get_filename (abfd
));
2325 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2326 pointer to the end of a series of DIEs, terminated by an empty
2327 DIE. Any children of the skipped DIEs will also be skipped. */
2330 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2332 struct abbrev_info
*abbrev
;
2333 unsigned int bytes_read
;
2337 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2339 return info_ptr
+ bytes_read
;
2341 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2345 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2346 should point just after the initial uleb128 of a DIE, and the
2347 abbrev corresponding to that skipped uleb128 should be passed in
2348 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2352 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2353 struct dwarf2_cu
*cu
)
2355 unsigned int bytes_read
;
2356 struct attribute attr
;
2357 bfd
*abfd
= cu
->objfile
->obfd
;
2358 unsigned int form
, i
;
2360 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2362 /* The only abbrev we care about is DW_AT_sibling. */
2363 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2365 read_attribute (&attr
, &abbrev
->attrs
[i
],
2366 abfd
, info_ptr
, cu
);
2367 if (attr
.form
== DW_FORM_ref_addr
)
2368 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2370 return dwarf2_per_objfile
->info_buffer
2371 + dwarf2_get_ref_die_offset (&attr
);
2374 /* If it isn't DW_AT_sibling, skip this attribute. */
2375 form
= abbrev
->attrs
[i
].form
;
2380 case DW_FORM_ref_addr
:
2381 info_ptr
+= cu
->header
.addr_size
;
2400 case DW_FORM_string
:
2401 read_string (abfd
, info_ptr
, &bytes_read
);
2402 info_ptr
+= bytes_read
;
2405 info_ptr
+= cu
->header
.offset_size
;
2408 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2409 info_ptr
+= bytes_read
;
2411 case DW_FORM_block1
:
2412 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2414 case DW_FORM_block2
:
2415 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2417 case DW_FORM_block4
:
2418 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2422 case DW_FORM_ref_udata
:
2423 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2425 case DW_FORM_indirect
:
2426 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2427 info_ptr
+= bytes_read
;
2428 /* We need to continue parsing from here, so just go back to
2430 goto skip_attribute
;
2433 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2434 dwarf_form_name (form
),
2435 bfd_get_filename (abfd
));
2439 if (abbrev
->has_children
)
2440 return skip_children (info_ptr
, cu
);
2445 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2446 the next DIE after ORIG_PDI. */
2449 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2450 bfd
*abfd
, struct dwarf2_cu
*cu
)
2452 /* Do we know the sibling already? */
2454 if (orig_pdi
->sibling
)
2455 return orig_pdi
->sibling
;
2457 /* Are there any children to deal with? */
2459 if (!orig_pdi
->has_children
)
2462 /* Skip the children the long way. */
2464 return skip_children (info_ptr
, cu
);
2467 /* Expand this partial symbol table into a full symbol table. */
2470 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2472 /* FIXME: This is barely more than a stub. */
2477 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2483 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2484 gdb_flush (gdb_stdout
);
2487 /* Restore our global data. */
2488 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2489 dwarf2_objfile_data_key
);
2491 psymtab_to_symtab_1 (pst
);
2493 /* Finish up the debug error message. */
2495 printf_filtered (_("done.\n"));
2500 /* Add PER_CU to the queue. */
2503 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2505 struct dwarf2_queue_item
*item
;
2508 item
= xmalloc (sizeof (*item
));
2509 item
->per_cu
= per_cu
;
2512 if (dwarf2_queue
== NULL
)
2513 dwarf2_queue
= item
;
2515 dwarf2_queue_tail
->next
= item
;
2517 dwarf2_queue_tail
= item
;
2519 /* Either PER_CU is the CU we want to process, or we're following a reference
2520 pointing into PER_CU. Either way, we need its DIEs now. */
2521 load_full_comp_unit (item
->per_cu
, objfile
);
2522 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2523 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2526 /* Process the queue. */
2529 process_queue (struct objfile
*objfile
)
2531 struct dwarf2_queue_item
*item
, *next_item
;
2533 /* The queue starts out with one item, but following a DIE reference
2534 may load a new CU, adding it to the end of the queue. */
2535 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2537 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2538 process_full_comp_unit (item
->per_cu
);
2540 item
->per_cu
->queued
= 0;
2541 next_item
= item
->next
;
2545 dwarf2_queue_tail
= NULL
;
2548 /* Free all allocated queue entries. This function only releases anything if
2549 an error was thrown; if the queue was processed then it would have been
2550 freed as we went along. */
2553 dwarf2_release_queue (void *dummy
)
2555 struct dwarf2_queue_item
*item
, *last
;
2557 item
= dwarf2_queue
;
2560 /* Anything still marked queued is likely to be in an
2561 inconsistent state, so discard it. */
2562 if (item
->per_cu
->queued
)
2564 if (item
->per_cu
->cu
!= NULL
)
2565 free_one_cached_comp_unit (item
->per_cu
->cu
);
2566 item
->per_cu
->queued
= 0;
2574 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2577 /* Read in full symbols for PST, and anything it depends on. */
2580 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2582 struct dwarf2_per_cu_data
*per_cu
;
2583 struct cleanup
*back_to
;
2586 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2587 if (!pst
->dependencies
[i
]->readin
)
2589 /* Inform about additional files that need to be read in. */
2592 /* FIXME: i18n: Need to make this a single string. */
2593 fputs_filtered (" ", gdb_stdout
);
2595 fputs_filtered ("and ", gdb_stdout
);
2597 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2598 wrap_here (""); /* Flush output */
2599 gdb_flush (gdb_stdout
);
2601 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2604 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2608 /* It's an include file, no symbols to read for it.
2609 Everything is in the parent symtab. */
2614 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2616 queue_comp_unit (per_cu
, pst
->objfile
);
2618 process_queue (pst
->objfile
);
2620 /* Age the cache, releasing compilation units that have not
2621 been used recently. */
2622 age_cached_comp_units ();
2624 do_cleanups (back_to
);
2627 /* Load the DIEs associated with PST and PER_CU into memory. */
2629 static struct dwarf2_cu
*
2630 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2632 bfd
*abfd
= objfile
->obfd
;
2633 struct dwarf2_cu
*cu
;
2634 unsigned int offset
;
2636 struct cleanup
*back_to
, *free_cu_cleanup
;
2637 struct attribute
*attr
;
2640 /* Set local variables from the partial symbol table info. */
2641 offset
= per_cu
->offset
;
2643 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2645 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2646 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2648 /* If an error occurs while loading, release our storage. */
2649 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2651 cu
->objfile
= objfile
;
2653 /* read in the comp_unit header */
2654 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2656 /* Read the abbrevs for this compilation unit */
2657 dwarf2_read_abbrevs (abfd
, cu
);
2658 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2660 cu
->header
.offset
= offset
;
2662 cu
->per_cu
= per_cu
;
2664 cu
->type_hash
= per_cu
->type_hash
;
2666 /* We use this obstack for block values in dwarf_alloc_block. */
2667 obstack_init (&cu
->comp_unit_obstack
);
2669 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2671 /* We try not to read any attributes in this function, because not
2672 all objfiles needed for references have been loaded yet, and symbol
2673 table processing isn't initialized. But we have to set the CU language,
2674 or we won't be able to build types correctly. */
2675 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2677 set_cu_language (DW_UNSND (attr
), cu
);
2679 set_cu_language (language_minimal
, cu
);
2681 do_cleanups (back_to
);
2683 /* We've successfully allocated this compilation unit. Let our caller
2684 clean it up when finished with it. */
2685 discard_cleanups (free_cu_cleanup
);
2690 /* Generate full symbol information for PST and CU, whose DIEs have
2691 already been loaded into memory. */
2694 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2696 struct partial_symtab
*pst
= per_cu
->psymtab
;
2697 struct dwarf2_cu
*cu
= per_cu
->cu
;
2698 struct objfile
*objfile
= pst
->objfile
;
2699 bfd
*abfd
= objfile
->obfd
;
2700 CORE_ADDR lowpc
, highpc
;
2701 struct symtab
*symtab
;
2702 struct cleanup
*back_to
;
2703 struct attribute
*attr
;
2706 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2709 back_to
= make_cleanup (really_free_pendings
, NULL
);
2711 cu
->list_in_scope
= &file_symbols
;
2713 /* Find the base address of the compilation unit for range lists and
2714 location lists. It will normally be specified by DW_AT_low_pc.
2715 In DWARF-3 draft 4, the base address could be overridden by
2716 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2717 compilation units with discontinuous ranges. */
2720 cu
->base_address
= 0;
2722 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2725 cu
->base_address
= DW_ADDR (attr
);
2730 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2733 cu
->base_address
= DW_ADDR (attr
);
2738 /* Do line number decoding in read_file_scope () */
2739 process_die (cu
->dies
, cu
);
2741 /* Some compilers don't define a DW_AT_high_pc attribute for the
2742 compilation unit. If the DW_AT_high_pc is missing, synthesize
2743 it, by scanning the DIE's below the compilation unit. */
2744 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2746 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2748 /* Set symtab language to language from DW_AT_language.
2749 If the compilation is from a C file generated by language preprocessors,
2750 do not set the language if it was already deduced by start_subfile. */
2752 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2754 symtab
->language
= cu
->language
;
2756 pst
->symtab
= symtab
;
2759 do_cleanups (back_to
);
2762 /* Process a die and its children. */
2765 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2769 case DW_TAG_padding
:
2771 case DW_TAG_compile_unit
:
2772 read_file_scope (die
, cu
);
2774 case DW_TAG_subprogram
:
2775 read_func_scope (die
, cu
);
2777 case DW_TAG_inlined_subroutine
:
2778 /* FIXME: These are ignored for now.
2779 They could be used to set breakpoints on all inlined instances
2780 of a function and make GDB `next' properly over inlined functions. */
2782 case DW_TAG_lexical_block
:
2783 case DW_TAG_try_block
:
2784 case DW_TAG_catch_block
:
2785 read_lexical_block_scope (die
, cu
);
2787 case DW_TAG_class_type
:
2788 case DW_TAG_interface_type
:
2789 case DW_TAG_structure_type
:
2790 case DW_TAG_union_type
:
2791 process_structure_scope (die
, cu
);
2793 case DW_TAG_enumeration_type
:
2794 process_enumeration_scope (die
, cu
);
2797 /* These dies have a type, but processing them does not create
2798 a symbol or recurse to process the children. Therefore we can
2799 read them on-demand through read_type_die. */
2800 case DW_TAG_subroutine_type
:
2801 case DW_TAG_set_type
:
2802 case DW_TAG_array_type
:
2803 case DW_TAG_pointer_type
:
2804 case DW_TAG_ptr_to_member_type
:
2805 case DW_TAG_reference_type
:
2806 case DW_TAG_string_type
:
2809 case DW_TAG_base_type
:
2810 case DW_TAG_subrange_type
:
2811 /* Add a typedef symbol for the type definition, if it has a
2813 new_symbol (die
, read_type_die (die
, cu
), cu
);
2815 case DW_TAG_common_block
:
2816 read_common_block (die
, cu
);
2818 case DW_TAG_common_inclusion
:
2820 case DW_TAG_namespace
:
2821 processing_has_namespace_info
= 1;
2822 read_namespace (die
, cu
);
2824 case DW_TAG_imported_declaration
:
2825 case DW_TAG_imported_module
:
2826 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2827 information contained in these. DW_TAG_imported_declaration
2828 dies shouldn't have children; DW_TAG_imported_module dies
2829 shouldn't in the C++ case, but conceivably could in the
2831 processing_has_namespace_info
= 1;
2832 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2833 dwarf_tag_name (die
->tag
));
2836 new_symbol (die
, NULL
, cu
);
2841 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2842 If scope qualifiers are appropriate they will be added. The result
2843 will be allocated on the objfile_obstack, or NULL if the DIE does
2847 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2849 struct attribute
*attr
;
2850 char *prefix
, *name
;
2851 struct ui_file
*buf
= NULL
;
2853 name
= dwarf2_name (die
, cu
);
2857 /* These are the only languages we know how to qualify names in. */
2858 if (cu
->language
!= language_cplus
2859 && cu
->language
!= language_java
)
2862 /* If no prefix is necessary for this type of DIE, return the
2863 unqualified name. The other three tags listed could be handled
2864 in pdi_needs_namespace, but that requires broader changes. */
2865 if (!pdi_needs_namespace (die
->tag
)
2866 && die
->tag
!= DW_TAG_subprogram
2867 && die
->tag
!= DW_TAG_variable
2868 && die
->tag
!= DW_TAG_member
)
2871 prefix
= determine_prefix (die
, cu
);
2872 if (*prefix
!= '\0')
2873 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2880 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2882 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2886 free_cu_line_header (void *arg
)
2888 struct dwarf2_cu
*cu
= arg
;
2890 free_line_header (cu
->line_header
);
2891 cu
->line_header
= NULL
;
2895 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2897 struct objfile
*objfile
= cu
->objfile
;
2898 struct comp_unit_head
*cu_header
= &cu
->header
;
2899 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2900 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2901 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2902 struct attribute
*attr
;
2904 char *comp_dir
= NULL
;
2905 struct die_info
*child_die
;
2906 bfd
*abfd
= objfile
->obfd
;
2907 struct line_header
*line_header
= 0;
2910 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2912 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2914 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2915 from finish_block. */
2916 if (lowpc
== ((CORE_ADDR
) -1))
2921 /* Find the filename. Do not use dwarf2_name here, since the filename
2922 is not a source language identifier. */
2923 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2926 name
= DW_STRING (attr
);
2929 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2931 comp_dir
= DW_STRING (attr
);
2932 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2934 comp_dir
= ldirname (name
);
2935 if (comp_dir
!= NULL
)
2936 make_cleanup (xfree
, comp_dir
);
2938 if (comp_dir
!= NULL
)
2940 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2941 directory, get rid of it. */
2942 char *cp
= strchr (comp_dir
, ':');
2944 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2951 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2954 set_cu_language (DW_UNSND (attr
), cu
);
2957 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2959 cu
->producer
= DW_STRING (attr
);
2961 /* We assume that we're processing GCC output. */
2962 processing_gcc_compilation
= 2;
2964 processing_has_namespace_info
= 0;
2966 start_symtab (name
, comp_dir
, lowpc
);
2967 record_debugformat ("DWARF 2");
2968 record_producer (cu
->producer
);
2970 initialize_cu_func_list (cu
);
2972 /* Decode line number information if present. We do this before
2973 processing child DIEs, so that the line header table is available
2974 for DW_AT_decl_file. */
2975 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2978 unsigned int line_offset
= DW_UNSND (attr
);
2979 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2982 cu
->line_header
= line_header
;
2983 make_cleanup (free_cu_line_header
, cu
);
2984 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2988 /* Process all dies in compilation unit. */
2989 if (die
->child
!= NULL
)
2991 child_die
= die
->child
;
2992 while (child_die
&& child_die
->tag
)
2994 process_die (child_die
, cu
);
2995 child_die
= sibling_die (child_die
);
2999 /* Decode macro information, if present. Dwarf 2 macro information
3000 refers to information in the line number info statement program
3001 header, so we can only read it if we've read the header
3003 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3004 if (attr
&& line_header
)
3006 unsigned int macro_offset
= DW_UNSND (attr
);
3007 dwarf_decode_macros (line_header
, macro_offset
,
3008 comp_dir
, abfd
, cu
);
3010 do_cleanups (back_to
);
3014 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3015 struct dwarf2_cu
*cu
)
3017 struct function_range
*thisfn
;
3019 thisfn
= (struct function_range
*)
3020 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3021 thisfn
->name
= name
;
3022 thisfn
->lowpc
= lowpc
;
3023 thisfn
->highpc
= highpc
;
3024 thisfn
->seen_line
= 0;
3025 thisfn
->next
= NULL
;
3027 if (cu
->last_fn
== NULL
)
3028 cu
->first_fn
= thisfn
;
3030 cu
->last_fn
->next
= thisfn
;
3032 cu
->last_fn
= thisfn
;
3036 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3038 struct objfile
*objfile
= cu
->objfile
;
3039 struct context_stack
*new;
3042 struct die_info
*child_die
;
3043 struct attribute
*attr
;
3046 struct block
*block
;
3048 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3050 name
= dwarf2_linkage_name (die
, cu
);
3052 /* Ignore functions with missing or empty names and functions with
3053 missing or invalid low and high pc attributes. */
3054 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3060 /* Record the function range for dwarf_decode_lines. */
3061 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3063 new = push_context (0, lowpc
);
3064 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3066 /* If there is a location expression for DW_AT_frame_base, record
3068 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3070 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3071 expression is being recorded directly in the function's symbol
3072 and not in a separate frame-base object. I guess this hack is
3073 to avoid adding some sort of frame-base adjunct/annex to the
3074 function's symbol :-(. The problem with doing this is that it
3075 results in a function symbol with a location expression that
3076 has nothing to do with the location of the function, ouch! The
3077 relationship should be: a function's symbol has-a frame base; a
3078 frame-base has-a location expression. */
3079 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3081 cu
->list_in_scope
= &local_symbols
;
3083 if (die
->child
!= NULL
)
3085 child_die
= die
->child
;
3086 while (child_die
&& child_die
->tag
)
3088 process_die (child_die
, cu
);
3089 child_die
= sibling_die (child_die
);
3093 new = pop_context ();
3094 /* Make a block for the local symbols within. */
3095 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3096 lowpc
, highpc
, objfile
);
3098 /* For C++, set the block's scope. */
3099 if (cu
->language
== language_cplus
)
3100 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3101 determine_prefix (die
, cu
),
3102 processing_has_namespace_info
);
3104 /* If we have address ranges, record them. */
3105 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3107 /* In C++, we can have functions nested inside functions (e.g., when
3108 a function declares a class that has methods). This means that
3109 when we finish processing a function scope, we may need to go
3110 back to building a containing block's symbol lists. */
3111 local_symbols
= new->locals
;
3112 param_symbols
= new->params
;
3114 /* If we've finished processing a top-level function, subsequent
3115 symbols go in the file symbol list. */
3116 if (outermost_context_p ())
3117 cu
->list_in_scope
= &file_symbols
;
3120 /* Process all the DIES contained within a lexical block scope. Start
3121 a new scope, process the dies, and then close the scope. */
3124 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3126 struct objfile
*objfile
= cu
->objfile
;
3127 struct context_stack
*new;
3128 CORE_ADDR lowpc
, highpc
;
3129 struct die_info
*child_die
;
3132 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3134 /* Ignore blocks with missing or invalid low and high pc attributes. */
3135 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3136 as multiple lexical blocks? Handling children in a sane way would
3137 be nasty. Might be easier to properly extend generic blocks to
3139 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3144 push_context (0, lowpc
);
3145 if (die
->child
!= NULL
)
3147 child_die
= die
->child
;
3148 while (child_die
&& child_die
->tag
)
3150 process_die (child_die
, cu
);
3151 child_die
= sibling_die (child_die
);
3154 new = pop_context ();
3156 if (local_symbols
!= NULL
)
3159 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3162 /* Note that recording ranges after traversing children, as we
3163 do here, means that recording a parent's ranges entails
3164 walking across all its children's ranges as they appear in
3165 the address map, which is quadratic behavior.
3167 It would be nicer to record the parent's ranges before
3168 traversing its children, simply overriding whatever you find
3169 there. But since we don't even decide whether to create a
3170 block until after we've traversed its children, that's hard
3172 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3174 local_symbols
= new->locals
;
3177 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3178 Return 1 if the attributes are present and valid, otherwise, return 0.
3179 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3182 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3183 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3184 struct partial_symtab
*ranges_pst
)
3186 struct objfile
*objfile
= cu
->objfile
;
3187 struct comp_unit_head
*cu_header
= &cu
->header
;
3188 bfd
*obfd
= objfile
->obfd
;
3189 unsigned int addr_size
= cu_header
->addr_size
;
3190 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3191 /* Base address selection entry. */
3202 found_base
= cu
->base_known
;
3203 base
= cu
->base_address
;
3205 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3207 complaint (&symfile_complaints
,
3208 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3212 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3214 /* Read in the largest possible address. */
3215 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3216 if ((marker
& mask
) == mask
)
3218 /* If we found the largest possible address, then
3219 read the base address. */
3220 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3221 buffer
+= 2 * addr_size
;
3222 offset
+= 2 * addr_size
;
3228 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3232 CORE_ADDR range_beginning
, range_end
;
3234 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3235 buffer
+= addr_size
;
3236 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3237 buffer
+= addr_size
;
3238 offset
+= 2 * addr_size
;
3240 /* An end of list marker is a pair of zero addresses. */
3241 if (range_beginning
== 0 && range_end
== 0)
3242 /* Found the end of list entry. */
3245 /* Each base address selection entry is a pair of 2 values.
3246 The first is the largest possible address, the second is
3247 the base address. Check for a base address here. */
3248 if ((range_beginning
& mask
) == mask
)
3250 /* If we found the largest possible address, then
3251 read the base address. */
3252 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3259 /* We have no valid base address for the ranges
3261 complaint (&symfile_complaints
,
3262 _("Invalid .debug_ranges data (no base address)"));
3266 range_beginning
+= base
;
3269 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3270 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3271 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3274 /* FIXME: This is recording everything as a low-high
3275 segment of consecutive addresses. We should have a
3276 data structure for discontiguous block ranges
3280 low
= range_beginning
;
3286 if (range_beginning
< low
)
3287 low
= range_beginning
;
3288 if (range_end
> high
)
3294 /* If the first entry is an end-of-list marker, the range
3295 describes an empty scope, i.e. no instructions. */
3301 *high_return
= high
;
3305 /* Get low and high pc attributes from a die. Return 1 if the attributes
3306 are present and valid, otherwise, return 0. Return -1 if the range is
3307 discontinuous, i.e. derived from DW_AT_ranges information. */
3309 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3310 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3312 struct attribute
*attr
;
3317 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3320 high
= DW_ADDR (attr
);
3321 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3323 low
= DW_ADDR (attr
);
3325 /* Found high w/o low attribute. */
3328 /* Found consecutive range of addresses. */
3333 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3336 /* Value of the DW_AT_ranges attribute is the offset in the
3337 .debug_ranges section. */
3338 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3340 /* Found discontinuous range of addresses. */
3348 /* When using the GNU linker, .gnu.linkonce. sections are used to
3349 eliminate duplicate copies of functions and vtables and such.
3350 The linker will arbitrarily choose one and discard the others.
3351 The AT_*_pc values for such functions refer to local labels in
3352 these sections. If the section from that file was discarded, the
3353 labels are not in the output, so the relocs get a value of 0.
3354 If this is a discarded function, mark the pc bounds as invalid,
3355 so that GDB will ignore it. */
3356 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3364 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3365 its low and high PC addresses. Do nothing if these addresses could not
3366 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3367 and HIGHPC to the high address if greater than HIGHPC. */
3370 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3371 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3372 struct dwarf2_cu
*cu
)
3374 CORE_ADDR low
, high
;
3375 struct die_info
*child
= die
->child
;
3377 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3379 *lowpc
= min (*lowpc
, low
);
3380 *highpc
= max (*highpc
, high
);
3383 /* If the language does not allow nested subprograms (either inside
3384 subprograms or lexical blocks), we're done. */
3385 if (cu
->language
!= language_ada
)
3388 /* Check all the children of the given DIE. If it contains nested
3389 subprograms, then check their pc bounds. Likewise, we need to
3390 check lexical blocks as well, as they may also contain subprogram
3392 while (child
&& child
->tag
)
3394 if (child
->tag
== DW_TAG_subprogram
3395 || child
->tag
== DW_TAG_lexical_block
)
3396 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3397 child
= sibling_die (child
);
3401 /* Get the low and high pc's represented by the scope DIE, and store
3402 them in *LOWPC and *HIGHPC. If the correct values can't be
3403 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3406 get_scope_pc_bounds (struct die_info
*die
,
3407 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3408 struct dwarf2_cu
*cu
)
3410 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3411 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3412 CORE_ADDR current_low
, current_high
;
3414 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3416 best_low
= current_low
;
3417 best_high
= current_high
;
3421 struct die_info
*child
= die
->child
;
3423 while (child
&& child
->tag
)
3425 switch (child
->tag
) {
3426 case DW_TAG_subprogram
:
3427 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3429 case DW_TAG_namespace
:
3430 /* FIXME: carlton/2004-01-16: Should we do this for
3431 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3432 that current GCC's always emit the DIEs corresponding
3433 to definitions of methods of classes as children of a
3434 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3435 the DIEs giving the declarations, which could be
3436 anywhere). But I don't see any reason why the
3437 standards says that they have to be there. */
3438 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3440 if (current_low
!= ((CORE_ADDR
) -1))
3442 best_low
= min (best_low
, current_low
);
3443 best_high
= max (best_high
, current_high
);
3451 child
= sibling_die (child
);
3456 *highpc
= best_high
;
3459 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3462 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3463 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3465 struct attribute
*attr
;
3467 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3470 CORE_ADDR high
= DW_ADDR (attr
);
3471 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3474 CORE_ADDR low
= DW_ADDR (attr
);
3475 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3479 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3482 bfd
*obfd
= cu
->objfile
->obfd
;
3484 /* The value of the DW_AT_ranges attribute is the offset of the
3485 address range list in the .debug_ranges section. */
3486 unsigned long offset
= DW_UNSND (attr
);
3487 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3489 /* For some target architectures, but not others, the
3490 read_address function sign-extends the addresses it returns.
3491 To recognize base address selection entries, we need a
3493 unsigned int addr_size
= cu
->header
.addr_size
;
3494 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3496 /* The base address, to which the next pair is relative. Note
3497 that this 'base' is a DWARF concept: most entries in a range
3498 list are relative, to reduce the number of relocs against the
3499 debugging information. This is separate from this function's
3500 'baseaddr' argument, which GDB uses to relocate debugging
3501 information from a shared library based on the address at
3502 which the library was loaded. */
3503 CORE_ADDR base
= cu
->base_address
;
3504 int base_known
= cu
->base_known
;
3506 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3508 complaint (&symfile_complaints
,
3509 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3516 unsigned int bytes_read
;
3517 CORE_ADDR start
, end
;
3519 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3520 buffer
+= bytes_read
;
3521 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3522 buffer
+= bytes_read
;
3524 /* Did we find the end of the range list? */
3525 if (start
== 0 && end
== 0)
3528 /* Did we find a base address selection entry? */
3529 else if ((start
& base_select_mask
) == base_select_mask
)
3535 /* We found an ordinary address range. */
3540 complaint (&symfile_complaints
,
3541 _("Invalid .debug_ranges data (no base address)"));
3545 record_block_range (block
,
3546 baseaddr
+ base
+ start
,
3547 baseaddr
+ base
+ end
- 1);
3553 /* Add an aggregate field to the field list. */
3556 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3557 struct dwarf2_cu
*cu
)
3559 struct objfile
*objfile
= cu
->objfile
;
3560 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3561 struct nextfield
*new_field
;
3562 struct attribute
*attr
;
3564 char *fieldname
= "";
3566 /* Allocate a new field list entry and link it in. */
3567 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3568 make_cleanup (xfree
, new_field
);
3569 memset (new_field
, 0, sizeof (struct nextfield
));
3570 new_field
->next
= fip
->fields
;
3571 fip
->fields
= new_field
;
3574 /* Handle accessibility and virtuality of field.
3575 The default accessibility for members is public, the default
3576 accessibility for inheritance is private. */
3577 if (die
->tag
!= DW_TAG_inheritance
)
3578 new_field
->accessibility
= DW_ACCESS_public
;
3580 new_field
->accessibility
= DW_ACCESS_private
;
3581 new_field
->virtuality
= DW_VIRTUALITY_none
;
3583 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3585 new_field
->accessibility
= DW_UNSND (attr
);
3586 if (new_field
->accessibility
!= DW_ACCESS_public
)
3587 fip
->non_public_fields
= 1;
3588 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3590 new_field
->virtuality
= DW_UNSND (attr
);
3592 fp
= &new_field
->field
;
3594 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3596 /* Data member other than a C++ static data member. */
3598 /* Get type of field. */
3599 fp
->type
= die_type (die
, cu
);
3601 SET_FIELD_BITPOS (*fp
, 0);
3603 /* Get bit size of field (zero if none). */
3604 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3607 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3611 FIELD_BITSIZE (*fp
) = 0;
3614 /* Get bit offset of field. */
3615 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3620 if (attr_form_is_section_offset (attr
))
3622 dwarf2_complex_location_expr_complaint ();
3625 else if (attr_form_is_constant (attr
))
3626 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3628 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3630 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3632 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3635 if (gdbarch_bits_big_endian (gdbarch
))
3637 /* For big endian bits, the DW_AT_bit_offset gives the
3638 additional bit offset from the MSB of the containing
3639 anonymous object to the MSB of the field. We don't
3640 have to do anything special since we don't need to
3641 know the size of the anonymous object. */
3642 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3646 /* For little endian bits, compute the bit offset to the
3647 MSB of the anonymous object, subtract off the number of
3648 bits from the MSB of the field to the MSB of the
3649 object, and then subtract off the number of bits of
3650 the field itself. The result is the bit offset of
3651 the LSB of the field. */
3653 int bit_offset
= DW_UNSND (attr
);
3655 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3658 /* The size of the anonymous object containing
3659 the bit field is explicit, so use the
3660 indicated size (in bytes). */
3661 anonymous_size
= DW_UNSND (attr
);
3665 /* The size of the anonymous object containing
3666 the bit field must be inferred from the type
3667 attribute of the data member containing the
3669 anonymous_size
= TYPE_LENGTH (fp
->type
);
3671 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3672 - bit_offset
- FIELD_BITSIZE (*fp
);
3676 /* Get name of field. */
3677 fieldname
= dwarf2_name (die
, cu
);
3678 if (fieldname
== NULL
)
3681 /* The name is already allocated along with this objfile, so we don't
3682 need to duplicate it for the type. */
3683 fp
->name
= fieldname
;
3685 /* Change accessibility for artificial fields (e.g. virtual table
3686 pointer or virtual base class pointer) to private. */
3687 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3689 new_field
->accessibility
= DW_ACCESS_private
;
3690 fip
->non_public_fields
= 1;
3693 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3695 /* C++ static member. */
3697 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3698 is a declaration, but all versions of G++ as of this writing
3699 (so through at least 3.2.1) incorrectly generate
3700 DW_TAG_variable tags. */
3704 /* Get name of field. */
3705 fieldname
= dwarf2_name (die
, cu
);
3706 if (fieldname
== NULL
)
3709 /* Get physical name. */
3710 physname
= dwarf2_linkage_name (die
, cu
);
3712 /* The name is already allocated along with this objfile, so we don't
3713 need to duplicate it for the type. */
3714 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3715 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3716 FIELD_NAME (*fp
) = fieldname
;
3718 else if (die
->tag
== DW_TAG_inheritance
)
3720 /* C++ base class field. */
3721 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3723 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
3725 FIELD_BITSIZE (*fp
) = 0;
3726 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3727 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3728 fip
->nbaseclasses
++;
3732 /* Create the vector of fields, and attach it to the type. */
3735 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3736 struct dwarf2_cu
*cu
)
3738 int nfields
= fip
->nfields
;
3740 /* Record the field count, allocate space for the array of fields,
3741 and create blank accessibility bitfields if necessary. */
3742 TYPE_NFIELDS (type
) = nfields
;
3743 TYPE_FIELDS (type
) = (struct field
*)
3744 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3745 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3747 if (fip
->non_public_fields
)
3749 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3751 TYPE_FIELD_PRIVATE_BITS (type
) =
3752 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3753 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3755 TYPE_FIELD_PROTECTED_BITS (type
) =
3756 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3757 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3759 TYPE_FIELD_IGNORE_BITS (type
) =
3760 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3761 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3764 /* If the type has baseclasses, allocate and clear a bit vector for
3765 TYPE_FIELD_VIRTUAL_BITS. */
3766 if (fip
->nbaseclasses
)
3768 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3769 unsigned char *pointer
;
3771 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3772 pointer
= TYPE_ALLOC (type
, num_bytes
);
3773 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3774 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3775 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3778 /* Copy the saved-up fields into the field vector. Start from the head
3779 of the list, adding to the tail of the field array, so that they end
3780 up in the same order in the array in which they were added to the list. */
3781 while (nfields
-- > 0)
3783 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3784 switch (fip
->fields
->accessibility
)
3786 case DW_ACCESS_private
:
3787 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3790 case DW_ACCESS_protected
:
3791 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3794 case DW_ACCESS_public
:
3798 /* Unknown accessibility. Complain and treat it as public. */
3800 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3801 fip
->fields
->accessibility
);
3805 if (nfields
< fip
->nbaseclasses
)
3807 switch (fip
->fields
->virtuality
)
3809 case DW_VIRTUALITY_virtual
:
3810 case DW_VIRTUALITY_pure_virtual
:
3811 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3815 fip
->fields
= fip
->fields
->next
;
3819 /* Add a member function to the proper fieldlist. */
3822 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3823 struct type
*type
, struct dwarf2_cu
*cu
)
3825 struct objfile
*objfile
= cu
->objfile
;
3826 struct attribute
*attr
;
3827 struct fnfieldlist
*flp
;
3829 struct fn_field
*fnp
;
3832 struct nextfnfield
*new_fnfield
;
3833 struct type
*this_type
;
3835 /* Get name of member function. */
3836 fieldname
= dwarf2_name (die
, cu
);
3837 if (fieldname
== NULL
)
3840 /* Get the mangled name. */
3841 physname
= dwarf2_linkage_name (die
, cu
);
3843 /* Look up member function name in fieldlist. */
3844 for (i
= 0; i
< fip
->nfnfields
; i
++)
3846 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3850 /* Create new list element if necessary. */
3851 if (i
< fip
->nfnfields
)
3852 flp
= &fip
->fnfieldlists
[i
];
3855 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3857 fip
->fnfieldlists
= (struct fnfieldlist
*)
3858 xrealloc (fip
->fnfieldlists
,
3859 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3860 * sizeof (struct fnfieldlist
));
3861 if (fip
->nfnfields
== 0)
3862 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3864 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3865 flp
->name
= fieldname
;
3871 /* Create a new member function field and chain it to the field list
3873 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3874 make_cleanup (xfree
, new_fnfield
);
3875 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3876 new_fnfield
->next
= flp
->head
;
3877 flp
->head
= new_fnfield
;
3880 /* Fill in the member function field info. */
3881 fnp
= &new_fnfield
->fnfield
;
3882 /* The name is already allocated along with this objfile, so we don't
3883 need to duplicate it for the type. */
3884 fnp
->physname
= physname
? physname
: "";
3885 fnp
->type
= alloc_type (objfile
);
3886 this_type
= read_type_die (die
, cu
);
3887 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3889 int nparams
= TYPE_NFIELDS (this_type
);
3891 /* TYPE is the domain of this method, and THIS_TYPE is the type
3892 of the method itself (TYPE_CODE_METHOD). */
3893 smash_to_method_type (fnp
->type
, type
,
3894 TYPE_TARGET_TYPE (this_type
),
3895 TYPE_FIELDS (this_type
),
3896 TYPE_NFIELDS (this_type
),
3897 TYPE_VARARGS (this_type
));
3899 /* Handle static member functions.
3900 Dwarf2 has no clean way to discern C++ static and non-static
3901 member functions. G++ helps GDB by marking the first
3902 parameter for non-static member functions (which is the
3903 this pointer) as artificial. We obtain this information
3904 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3905 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3906 fnp
->voffset
= VOFFSET_STATIC
;
3909 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3912 /* Get fcontext from DW_AT_containing_type if present. */
3913 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3914 fnp
->fcontext
= die_containing_type (die
, cu
);
3916 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3917 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3919 /* Get accessibility. */
3920 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3923 switch (DW_UNSND (attr
))
3925 case DW_ACCESS_private
:
3926 fnp
->is_private
= 1;
3928 case DW_ACCESS_protected
:
3929 fnp
->is_protected
= 1;
3934 /* Check for artificial methods. */
3935 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3936 if (attr
&& DW_UNSND (attr
) != 0)
3937 fnp
->is_artificial
= 1;
3939 /* Get index in virtual function table if it is a virtual member function. */
3940 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3943 /* Support the .debug_loc offsets */
3944 if (attr_form_is_block (attr
))
3946 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3948 else if (attr_form_is_section_offset (attr
))
3950 dwarf2_complex_location_expr_complaint ();
3954 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3960 /* Create the vector of member function fields, and attach it to the type. */
3963 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3964 struct dwarf2_cu
*cu
)
3966 struct fnfieldlist
*flp
;
3967 int total_length
= 0;
3970 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3971 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3972 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3974 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3976 struct nextfnfield
*nfp
= flp
->head
;
3977 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3980 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3981 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3982 fn_flp
->fn_fields
= (struct fn_field
*)
3983 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3984 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3985 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3987 total_length
+= flp
->length
;
3990 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3991 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3994 /* Returns non-zero if NAME is the name of a vtable member in CU's
3995 language, zero otherwise. */
3997 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3999 static const char vptr
[] = "_vptr";
4000 static const char vtable
[] = "vtable";
4002 /* Look for the C++ and Java forms of the vtable. */
4003 if ((cu
->language
== language_java
4004 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4005 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4006 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4012 /* GCC outputs unnamed structures that are really pointers to member
4013 functions, with the ABI-specified layout. If DIE (from CU) describes
4014 such a structure, set its type, and return nonzero. Otherwise return
4017 GCC shouldn't do this; it should just output pointer to member DIEs.
4018 This is GCC PR debug/28767. */
4020 static struct type
*
4021 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4023 struct objfile
*objfile
= cu
->objfile
;
4025 struct die_info
*pfn_die
, *delta_die
;
4026 struct attribute
*pfn_name
, *delta_name
;
4027 struct type
*pfn_type
, *domain_type
;
4029 /* Check for a structure with no name and two children. */
4030 if (die
->tag
!= DW_TAG_structure_type
4031 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4032 || die
->child
== NULL
4033 || die
->child
->sibling
== NULL
4034 || (die
->child
->sibling
->sibling
!= NULL
4035 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4038 /* Check for __pfn and __delta members. */
4039 pfn_die
= die
->child
;
4040 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4041 if (pfn_die
->tag
!= DW_TAG_member
4043 || DW_STRING (pfn_name
) == NULL
4044 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4047 delta_die
= pfn_die
->sibling
;
4048 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4049 if (delta_die
->tag
!= DW_TAG_member
4050 || delta_name
== NULL
4051 || DW_STRING (delta_name
) == NULL
4052 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4055 /* Find the type of the method. */
4056 pfn_type
= die_type (pfn_die
, cu
);
4057 if (pfn_type
== NULL
4058 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4059 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4062 /* Look for the "this" argument. */
4063 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4064 if (TYPE_NFIELDS (pfn_type
) == 0
4065 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4068 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4069 type
= alloc_type (objfile
);
4070 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4071 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4072 TYPE_VARARGS (pfn_type
));
4073 type
= lookup_methodptr_type (type
);
4074 return set_die_type (die
, type
, cu
);
4077 /* Called when we find the DIE that starts a structure or union scope
4078 (definition) to process all dies that define the members of the
4081 NOTE: we need to call struct_type regardless of whether or not the
4082 DIE has an at_name attribute, since it might be an anonymous
4083 structure or union. This gets the type entered into our set of
4086 However, if the structure is incomplete (an opaque struct/union)
4087 then suppress creating a symbol table entry for it since gdb only
4088 wants to find the one with the complete definition. Note that if
4089 it is complete, we just call new_symbol, which does it's own
4090 checking about whether the struct/union is anonymous or not (and
4091 suppresses creating a symbol table entry itself). */
4093 static struct type
*
4094 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4096 struct objfile
*objfile
= cu
->objfile
;
4098 struct attribute
*attr
;
4100 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4102 type
= quirk_gcc_member_function_pointer (die
, cu
);
4106 type
= alloc_type (objfile
);
4107 INIT_CPLUS_SPECIFIC (type
);
4108 name
= dwarf2_name (die
, cu
);
4111 if (cu
->language
== language_cplus
4112 || cu
->language
== language_java
)
4114 const char *new_prefix
= determine_class_name (die
, cu
);
4115 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4119 /* The name is already allocated along with this objfile, so
4120 we don't need to duplicate it for the type. */
4121 TYPE_TAG_NAME (type
) = name
;
4125 if (die
->tag
== DW_TAG_structure_type
)
4127 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4129 else if (die
->tag
== DW_TAG_union_type
)
4131 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4135 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4137 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4140 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4143 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4147 TYPE_LENGTH (type
) = 0;
4150 TYPE_STUB_SUPPORTED (type
) = 1;
4151 if (die_is_declaration (die
, cu
))
4152 TYPE_STUB (type
) = 1;
4154 /* We need to add the type field to the die immediately so we don't
4155 infinitely recurse when dealing with pointers to the structure
4156 type within the structure itself. */
4157 set_die_type (die
, type
, cu
);
4159 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4161 struct field_info fi
;
4162 struct die_info
*child_die
;
4164 memset (&fi
, 0, sizeof (struct field_info
));
4166 child_die
= die
->child
;
4168 while (child_die
&& child_die
->tag
)
4170 if (child_die
->tag
== DW_TAG_member
4171 || child_die
->tag
== DW_TAG_variable
)
4173 /* NOTE: carlton/2002-11-05: A C++ static data member
4174 should be a DW_TAG_member that is a declaration, but
4175 all versions of G++ as of this writing (so through at
4176 least 3.2.1) incorrectly generate DW_TAG_variable
4177 tags for them instead. */
4178 dwarf2_add_field (&fi
, child_die
, cu
);
4180 else if (child_die
->tag
== DW_TAG_subprogram
)
4182 /* C++ member function. */
4183 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4185 else if (child_die
->tag
== DW_TAG_inheritance
)
4187 /* C++ base class field. */
4188 dwarf2_add_field (&fi
, child_die
, cu
);
4190 child_die
= sibling_die (child_die
);
4193 /* Attach fields and member functions to the type. */
4195 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4198 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4200 /* Get the type which refers to the base class (possibly this
4201 class itself) which contains the vtable pointer for the current
4202 class from the DW_AT_containing_type attribute. */
4204 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4206 struct type
*t
= die_containing_type (die
, cu
);
4208 TYPE_VPTR_BASETYPE (type
) = t
;
4213 /* Our own class provides vtbl ptr. */
4214 for (i
= TYPE_NFIELDS (t
) - 1;
4215 i
>= TYPE_N_BASECLASSES (t
);
4218 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4220 if (is_vtable_name (fieldname
, cu
))
4222 TYPE_VPTR_FIELDNO (type
) = i
;
4227 /* Complain if virtual function table field not found. */
4228 if (i
< TYPE_N_BASECLASSES (t
))
4229 complaint (&symfile_complaints
,
4230 _("virtual function table pointer not found when defining class '%s'"),
4231 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4236 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4239 else if (cu
->producer
4240 && strncmp (cu
->producer
,
4241 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4243 /* The IBM XLC compiler does not provide direct indication
4244 of the containing type, but the vtable pointer is
4245 always named __vfp. */
4249 for (i
= TYPE_NFIELDS (type
) - 1;
4250 i
>= TYPE_N_BASECLASSES (type
);
4253 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4255 TYPE_VPTR_FIELDNO (type
) = i
;
4256 TYPE_VPTR_BASETYPE (type
) = type
;
4264 do_cleanups (back_to
);
4269 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4271 struct objfile
*objfile
= cu
->objfile
;
4272 struct die_info
*child_die
= die
->child
;
4273 struct type
*this_type
;
4275 this_type
= get_die_type (die
, cu
);
4276 if (this_type
== NULL
)
4277 this_type
= read_structure_type (die
, cu
);
4279 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4280 snapshots) has been known to create a die giving a declaration
4281 for a class that has, as a child, a die giving a definition for a
4282 nested class. So we have to process our children even if the
4283 current die is a declaration. Normally, of course, a declaration
4284 won't have any children at all. */
4286 while (child_die
!= NULL
&& child_die
->tag
)
4288 if (child_die
->tag
== DW_TAG_member
4289 || child_die
->tag
== DW_TAG_variable
4290 || child_die
->tag
== DW_TAG_inheritance
)
4295 process_die (child_die
, cu
);
4297 child_die
= sibling_die (child_die
);
4300 /* Do not consider external references. According to the DWARF standard,
4301 these DIEs are identified by the fact that they have no byte_size
4302 attribute, and a declaration attribute. */
4303 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4304 || !die_is_declaration (die
, cu
))
4305 new_symbol (die
, this_type
, cu
);
4308 /* Given a DW_AT_enumeration_type die, set its type. We do not
4309 complete the type's fields yet, or create any symbols. */
4311 static struct type
*
4312 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4314 struct objfile
*objfile
= cu
->objfile
;
4316 struct attribute
*attr
;
4319 type
= alloc_type (objfile
);
4321 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4322 name
= dwarf2_full_name (die
, cu
);
4324 TYPE_TAG_NAME (type
) = (char *) name
;
4326 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4329 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4333 TYPE_LENGTH (type
) = 0;
4336 /* The enumeration DIE can be incomplete. In Ada, any type can be
4337 declared as private in the package spec, and then defined only
4338 inside the package body. Such types are known as Taft Amendment
4339 Types. When another package uses such a type, an incomplete DIE
4340 may be generated by the compiler. */
4341 if (die_is_declaration (die
, cu
))
4342 TYPE_STUB (type
) = 1;
4344 return set_die_type (die
, type
, cu
);
4347 /* Determine the name of the type represented by DIE, which should be
4348 a named C++ or Java compound type. Return the name in question,
4349 allocated on the objfile obstack. */
4352 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4354 const char *new_prefix
= NULL
;
4356 /* If we don't have namespace debug info, guess the name by trying
4357 to demangle the names of members, just like we did in
4358 guess_structure_name. */
4359 if (!processing_has_namespace_info
)
4361 struct die_info
*child
;
4363 for (child
= die
->child
;
4364 child
!= NULL
&& child
->tag
!= 0;
4365 child
= sibling_die (child
))
4367 if (child
->tag
== DW_TAG_subprogram
)
4370 = language_class_name_from_physname (cu
->language_defn
,
4374 if (phys_prefix
!= NULL
)
4377 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4378 &cu
->objfile
->objfile_obstack
);
4379 xfree (phys_prefix
);
4386 if (new_prefix
== NULL
)
4387 new_prefix
= dwarf2_full_name (die
, cu
);
4392 /* Given a pointer to a die which begins an enumeration, process all
4393 the dies that define the members of the enumeration, and create the
4394 symbol for the enumeration type.
4396 NOTE: We reverse the order of the element list. */
4399 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4401 struct objfile
*objfile
= cu
->objfile
;
4402 struct die_info
*child_die
;
4403 struct field
*fields
;
4406 int unsigned_enum
= 1;
4408 struct type
*this_type
;
4412 this_type
= get_die_type (die
, cu
);
4413 if (this_type
== NULL
)
4414 this_type
= read_enumeration_type (die
, cu
);
4415 if (die
->child
!= NULL
)
4417 child_die
= die
->child
;
4418 while (child_die
&& child_die
->tag
)
4420 if (child_die
->tag
!= DW_TAG_enumerator
)
4422 process_die (child_die
, cu
);
4426 name
= dwarf2_name (child_die
, cu
);
4429 sym
= new_symbol (child_die
, this_type
, cu
);
4430 if (SYMBOL_VALUE (sym
) < 0)
4433 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4435 fields
= (struct field
*)
4437 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4438 * sizeof (struct field
));
4441 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4442 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4443 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4444 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4450 child_die
= sibling_die (child_die
);
4455 TYPE_NFIELDS (this_type
) = num_fields
;
4456 TYPE_FIELDS (this_type
) = (struct field
*)
4457 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4458 memcpy (TYPE_FIELDS (this_type
), fields
,
4459 sizeof (struct field
) * num_fields
);
4463 TYPE_UNSIGNED (this_type
) = 1;
4466 new_symbol (die
, this_type
, cu
);
4469 /* Extract all information from a DW_TAG_array_type DIE and put it in
4470 the DIE's type field. For now, this only handles one dimensional
4473 static struct type
*
4474 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4476 struct objfile
*objfile
= cu
->objfile
;
4477 struct die_info
*child_die
;
4478 struct type
*type
= NULL
;
4479 struct type
*element_type
, *range_type
, *index_type
;
4480 struct type
**range_types
= NULL
;
4481 struct attribute
*attr
;
4483 struct cleanup
*back_to
;
4486 element_type
= die_type (die
, cu
);
4488 /* Irix 6.2 native cc creates array types without children for
4489 arrays with unspecified length. */
4490 if (die
->child
== NULL
)
4492 index_type
= builtin_type_int32
;
4493 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4494 type
= create_array_type (NULL
, element_type
, range_type
);
4495 return set_die_type (die
, type
, cu
);
4498 back_to
= make_cleanup (null_cleanup
, NULL
);
4499 child_die
= die
->child
;
4500 while (child_die
&& child_die
->tag
)
4502 if (child_die
->tag
== DW_TAG_subrange_type
)
4504 struct type
*child_type
= read_type_die (child_die
, cu
);
4505 if (child_type
!= NULL
)
4507 /* The range type was succesfully read. Save it for
4508 the array type creation. */
4509 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4511 range_types
= (struct type
**)
4512 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4513 * sizeof (struct type
*));
4515 make_cleanup (free_current_contents
, &range_types
);
4517 range_types
[ndim
++] = child_type
;
4520 child_die
= sibling_die (child_die
);
4523 /* Dwarf2 dimensions are output from left to right, create the
4524 necessary array types in backwards order. */
4526 type
= element_type
;
4528 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4532 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4537 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4540 /* Understand Dwarf2 support for vector types (like they occur on
4541 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4542 array type. This is not part of the Dwarf2/3 standard yet, but a
4543 custom vendor extension. The main difference between a regular
4544 array and the vector variant is that vectors are passed by value
4546 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4548 make_vector_type (type
);
4550 name
= dwarf2_name (die
, cu
);
4552 TYPE_NAME (type
) = name
;
4554 do_cleanups (back_to
);
4556 /* Install the type in the die. */
4557 return set_die_type (die
, type
, cu
);
4560 static enum dwarf_array_dim_ordering
4561 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4563 struct attribute
*attr
;
4565 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4567 if (attr
) return DW_SND (attr
);
4570 GNU F77 is a special case, as at 08/2004 array type info is the
4571 opposite order to the dwarf2 specification, but data is still
4572 laid out as per normal fortran.
4574 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4578 if (cu
->language
== language_fortran
&&
4579 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4581 return DW_ORD_row_major
;
4584 switch (cu
->language_defn
->la_array_ordering
)
4586 case array_column_major
:
4587 return DW_ORD_col_major
;
4588 case array_row_major
:
4590 return DW_ORD_row_major
;
4594 /* Extract all information from a DW_TAG_set_type DIE and put it in
4595 the DIE's type field. */
4597 static struct type
*
4598 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4600 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4602 return set_die_type (die
, set_type
, cu
);
4605 /* First cut: install each common block member as a global variable. */
4608 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4610 struct die_info
*child_die
;
4611 struct attribute
*attr
;
4613 CORE_ADDR base
= (CORE_ADDR
) 0;
4615 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4618 /* Support the .debug_loc offsets */
4619 if (attr_form_is_block (attr
))
4621 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4623 else if (attr_form_is_section_offset (attr
))
4625 dwarf2_complex_location_expr_complaint ();
4629 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4630 "common block member");
4633 if (die
->child
!= NULL
)
4635 child_die
= die
->child
;
4636 while (child_die
&& child_die
->tag
)
4638 sym
= new_symbol (child_die
, NULL
, cu
);
4639 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4642 SYMBOL_VALUE_ADDRESS (sym
) =
4643 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4644 add_symbol_to_list (sym
, &global_symbols
);
4646 child_die
= sibling_die (child_die
);
4651 /* Create a type for a C++ namespace. */
4653 static struct type
*
4654 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4656 struct objfile
*objfile
= cu
->objfile
;
4657 const char *previous_prefix
, *name
;
4661 /* For extensions, reuse the type of the original namespace. */
4662 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4664 struct die_info
*ext_die
;
4665 struct dwarf2_cu
*ext_cu
= cu
;
4666 ext_die
= dwarf2_extension (die
, &ext_cu
);
4667 type
= read_type_die (ext_die
, ext_cu
);
4668 return set_die_type (die
, type
, cu
);
4671 name
= namespace_name (die
, &is_anonymous
, cu
);
4673 /* Now build the name of the current namespace. */
4675 previous_prefix
= determine_prefix (die
, cu
);
4676 if (previous_prefix
[0] != '\0')
4677 name
= typename_concat (&objfile
->objfile_obstack
,
4678 previous_prefix
, name
, cu
);
4680 /* Create the type. */
4681 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4683 TYPE_NAME (type
) = (char *) name
;
4684 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4686 set_die_type (die
, type
, cu
);
4691 /* Read a C++ namespace. */
4694 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4696 struct objfile
*objfile
= cu
->objfile
;
4700 /* Add a symbol associated to this if we haven't seen the namespace
4701 before. Also, add a using directive if it's an anonymous
4704 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4708 type
= read_type_die (die
, cu
);
4709 new_symbol (die
, type
, cu
);
4711 name
= namespace_name (die
, &is_anonymous
, cu
);
4714 const char *previous_prefix
= determine_prefix (die
, cu
);
4715 cp_add_using_directive (TYPE_NAME (type
),
4716 strlen (previous_prefix
),
4717 strlen (TYPE_NAME (type
)));
4721 if (die
->child
!= NULL
)
4723 struct die_info
*child_die
= die
->child
;
4725 while (child_die
&& child_die
->tag
)
4727 process_die (child_die
, cu
);
4728 child_die
= sibling_die (child_die
);
4733 /* Return the name of the namespace represented by DIE. Set
4734 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4738 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4740 struct die_info
*current_die
;
4741 const char *name
= NULL
;
4743 /* Loop through the extensions until we find a name. */
4745 for (current_die
= die
;
4746 current_die
!= NULL
;
4747 current_die
= dwarf2_extension (die
, &cu
))
4749 name
= dwarf2_name (current_die
, cu
);
4754 /* Is it an anonymous namespace? */
4756 *is_anonymous
= (name
== NULL
);
4758 name
= "(anonymous namespace)";
4763 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4764 the user defined type vector. */
4766 static struct type
*
4767 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4769 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4770 struct comp_unit_head
*cu_header
= &cu
->header
;
4772 struct attribute
*attr_byte_size
;
4773 struct attribute
*attr_address_class
;
4774 int byte_size
, addr_class
;
4776 type
= lookup_pointer_type (die_type (die
, cu
));
4778 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4780 byte_size
= DW_UNSND (attr_byte_size
);
4782 byte_size
= cu_header
->addr_size
;
4784 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4785 if (attr_address_class
)
4786 addr_class
= DW_UNSND (attr_address_class
);
4788 addr_class
= DW_ADDR_none
;
4790 /* If the pointer size or address class is different than the
4791 default, create a type variant marked as such and set the
4792 length accordingly. */
4793 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4795 if (gdbarch_address_class_type_flags_p (gdbarch
))
4799 type_flags
= gdbarch_address_class_type_flags
4800 (gdbarch
, byte_size
, addr_class
);
4801 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4803 type
= make_type_with_address_space (type
, type_flags
);
4805 else if (TYPE_LENGTH (type
) != byte_size
)
4807 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4810 /* Should we also complain about unhandled address classes? */
4814 TYPE_LENGTH (type
) = byte_size
;
4815 return set_die_type (die
, type
, cu
);
4818 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4819 the user defined type vector. */
4821 static struct type
*
4822 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4824 struct objfile
*objfile
= cu
->objfile
;
4826 struct type
*to_type
;
4827 struct type
*domain
;
4829 to_type
= die_type (die
, cu
);
4830 domain
= die_containing_type (die
, cu
);
4832 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4833 type
= lookup_methodptr_type (to_type
);
4835 type
= lookup_memberptr_type (to_type
, domain
);
4837 return set_die_type (die
, type
, cu
);
4840 /* Extract all information from a DW_TAG_reference_type DIE and add to
4841 the user defined type vector. */
4843 static struct type
*
4844 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4846 struct comp_unit_head
*cu_header
= &cu
->header
;
4848 struct attribute
*attr
;
4850 type
= lookup_reference_type (die_type (die
, cu
));
4851 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4854 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4858 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4860 return set_die_type (die
, type
, cu
);
4863 static struct type
*
4864 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4866 struct type
*base_type
, *cv_type
;
4868 base_type
= die_type (die
, cu
);
4869 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4870 return set_die_type (die
, cv_type
, cu
);
4873 static struct type
*
4874 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4876 struct type
*base_type
, *cv_type
;
4878 base_type
= die_type (die
, cu
);
4879 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4880 return set_die_type (die
, cv_type
, cu
);
4883 /* Extract all information from a DW_TAG_string_type DIE and add to
4884 the user defined type vector. It isn't really a user defined type,
4885 but it behaves like one, with other DIE's using an AT_user_def_type
4886 attribute to reference it. */
4888 static struct type
*
4889 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4891 struct objfile
*objfile
= cu
->objfile
;
4892 struct type
*type
, *range_type
, *index_type
, *char_type
;
4893 struct attribute
*attr
;
4894 unsigned int length
;
4896 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4899 length
= DW_UNSND (attr
);
4903 /* check for the DW_AT_byte_size attribute */
4904 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4907 length
= DW_UNSND (attr
);
4915 index_type
= builtin_type_int32
;
4916 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4917 type
= create_string_type (NULL
, range_type
);
4919 return set_die_type (die
, type
, cu
);
4922 /* Handle DIES due to C code like:
4926 int (*funcp)(int a, long l);
4930 ('funcp' generates a DW_TAG_subroutine_type DIE)
4933 static struct type
*
4934 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4936 struct type
*type
; /* Type that this function returns */
4937 struct type
*ftype
; /* Function that returns above type */
4938 struct attribute
*attr
;
4940 type
= die_type (die
, cu
);
4941 ftype
= make_function_type (type
, (struct type
**) 0);
4943 /* All functions in C++, Pascal and Java have prototypes. */
4944 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4945 if ((attr
&& (DW_UNSND (attr
) != 0))
4946 || cu
->language
== language_cplus
4947 || cu
->language
== language_java
4948 || cu
->language
== language_pascal
)
4949 TYPE_PROTOTYPED (ftype
) = 1;
4951 /* Store the calling convention in the type if it's available in
4952 the subroutine die. Otherwise set the calling convention to
4953 the default value DW_CC_normal. */
4954 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4955 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4957 if (die
->child
!= NULL
)
4959 struct die_info
*child_die
;
4963 /* Count the number of parameters.
4964 FIXME: GDB currently ignores vararg functions, but knows about
4965 vararg member functions. */
4966 child_die
= die
->child
;
4967 while (child_die
&& child_die
->tag
)
4969 if (child_die
->tag
== DW_TAG_formal_parameter
)
4971 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4972 TYPE_VARARGS (ftype
) = 1;
4973 child_die
= sibling_die (child_die
);
4976 /* Allocate storage for parameters and fill them in. */
4977 TYPE_NFIELDS (ftype
) = nparams
;
4978 TYPE_FIELDS (ftype
) = (struct field
*)
4979 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4981 child_die
= die
->child
;
4982 while (child_die
&& child_die
->tag
)
4984 if (child_die
->tag
== DW_TAG_formal_parameter
)
4986 /* Dwarf2 has no clean way to discern C++ static and non-static
4987 member functions. G++ helps GDB by marking the first
4988 parameter for non-static member functions (which is the
4989 this pointer) as artificial. We pass this information
4990 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4991 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4993 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4995 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4996 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4999 child_die
= sibling_die (child_die
);
5003 return set_die_type (die
, ftype
, cu
);
5006 static struct type
*
5007 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5009 struct objfile
*objfile
= cu
->objfile
;
5010 struct attribute
*attr
;
5011 const char *name
= NULL
;
5012 struct type
*this_type
;
5014 name
= dwarf2_full_name (die
, cu
);
5015 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5016 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5017 TYPE_NAME (this_type
) = (char *) name
;
5018 set_die_type (die
, this_type
, cu
);
5019 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5023 /* Find a representation of a given base type and install
5024 it in the TYPE field of the die. */
5026 static struct type
*
5027 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5029 struct objfile
*objfile
= cu
->objfile
;
5031 struct attribute
*attr
;
5032 int encoding
= 0, size
= 0;
5034 enum type_code code
= TYPE_CODE_INT
;
5036 struct type
*target_type
= NULL
;
5038 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5041 encoding
= DW_UNSND (attr
);
5043 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5046 size
= DW_UNSND (attr
);
5048 name
= dwarf2_name (die
, cu
);
5051 complaint (&symfile_complaints
,
5052 _("DW_AT_name missing from DW_TAG_base_type"));
5057 case DW_ATE_address
:
5058 /* Turn DW_ATE_address into a void * pointer. */
5059 code
= TYPE_CODE_PTR
;
5060 type_flags
|= TYPE_FLAG_UNSIGNED
;
5061 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5063 case DW_ATE_boolean
:
5064 code
= TYPE_CODE_BOOL
;
5065 type_flags
|= TYPE_FLAG_UNSIGNED
;
5067 case DW_ATE_complex_float
:
5068 code
= TYPE_CODE_COMPLEX
;
5069 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5071 case DW_ATE_decimal_float
:
5072 code
= TYPE_CODE_DECFLOAT
;
5075 code
= TYPE_CODE_FLT
;
5079 case DW_ATE_unsigned
:
5080 type_flags
|= TYPE_FLAG_UNSIGNED
;
5082 case DW_ATE_signed_char
:
5083 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5084 code
= TYPE_CODE_CHAR
;
5086 case DW_ATE_unsigned_char
:
5087 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5088 code
= TYPE_CODE_CHAR
;
5089 type_flags
|= TYPE_FLAG_UNSIGNED
;
5092 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5093 dwarf_type_encoding_name (encoding
));
5097 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5098 TYPE_NAME (type
) = name
;
5099 TYPE_TARGET_TYPE (type
) = target_type
;
5101 if (name
&& strcmp (name
, "char") == 0)
5102 TYPE_NOSIGN (type
) = 1;
5104 return set_die_type (die
, type
, cu
);
5107 /* Read the given DW_AT_subrange DIE. */
5109 static struct type
*
5110 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5112 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5113 struct type
*base_type
;
5114 struct type
*range_type
;
5115 struct attribute
*attr
;
5120 base_type
= die_type (die
, cu
);
5121 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5123 complaint (&symfile_complaints
,
5124 _("DW_AT_type missing from DW_TAG_subrange_type"));
5126 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5127 0, NULL
, cu
->objfile
);
5130 if (cu
->language
== language_fortran
)
5132 /* FORTRAN implies a lower bound of 1, if not given. */
5136 /* FIXME: For variable sized arrays either of these could be
5137 a variable rather than a constant value. We'll allow it,
5138 but we don't know how to handle it. */
5139 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5141 low
= dwarf2_get_attr_constant_value (attr
, 0);
5143 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5146 if (attr
->form
== DW_FORM_block1
)
5148 /* GCC encodes arrays with unspecified or dynamic length
5149 with a DW_FORM_block1 attribute.
5150 FIXME: GDB does not yet know how to handle dynamic
5151 arrays properly, treat them as arrays with unspecified
5154 FIXME: jimb/2003-09-22: GDB does not really know
5155 how to handle arrays of unspecified length
5156 either; we just represent them as zero-length
5157 arrays. Choose an appropriate upper bound given
5158 the lower bound we've computed above. */
5162 high
= dwarf2_get_attr_constant_value (attr
, 1);
5165 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5167 name
= dwarf2_name (die
, cu
);
5169 TYPE_NAME (range_type
) = name
;
5171 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5173 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5175 return set_die_type (die
, range_type
, cu
);
5178 static struct type
*
5179 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5183 /* For now, we only support the C meaning of an unspecified type: void. */
5185 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5186 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5188 return set_die_type (die
, type
, cu
);
5191 /* Trivial hash function for die_info: the hash value of a DIE
5192 is its offset in .debug_info for this objfile. */
5195 die_hash (const void *item
)
5197 const struct die_info
*die
= item
;
5201 /* Trivial comparison function for die_info structures: two DIEs
5202 are equal if they have the same offset. */
5205 die_eq (const void *item_lhs
, const void *item_rhs
)
5207 const struct die_info
*die_lhs
= item_lhs
;
5208 const struct die_info
*die_rhs
= item_rhs
;
5209 return die_lhs
->offset
== die_rhs
->offset
;
5212 /* Read a whole compilation unit into a linked list of dies. */
5214 static struct die_info
*
5215 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5218 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5222 &cu
->comp_unit_obstack
,
5223 hashtab_obstack_allocate
,
5224 dummy_obstack_deallocate
);
5226 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5229 /* Main entry point for reading a DIE and all children.
5230 Read the DIE and dump it if requested. */
5232 static struct die_info
*
5233 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5234 struct dwarf2_cu
*cu
,
5235 gdb_byte
**new_info_ptr
,
5236 struct die_info
*parent
)
5238 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5239 new_info_ptr
, parent
);
5241 if (dwarf2_die_debug
)
5243 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5244 dump_die (result
, dwarf2_die_debug
);
5250 /* Read a single die and all its descendents. Set the die's sibling
5251 field to NULL; set other fields in the die correctly, and set all
5252 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5253 location of the info_ptr after reading all of those dies. PARENT
5254 is the parent of the die in question. */
5256 static struct die_info
*
5257 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5258 struct dwarf2_cu
*cu
,
5259 gdb_byte
**new_info_ptr
,
5260 struct die_info
*parent
)
5262 struct die_info
*die
;
5266 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5269 *new_info_ptr
= cur_ptr
;
5272 store_in_ref_table (die
, cu
);
5276 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5282 *new_info_ptr
= cur_ptr
;
5285 die
->sibling
= NULL
;
5286 die
->parent
= parent
;
5290 /* Read a die, all of its descendents, and all of its siblings; set
5291 all of the fields of all of the dies correctly. Arguments are as
5292 in read_die_and_children. */
5294 static struct die_info
*
5295 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5296 struct dwarf2_cu
*cu
,
5297 gdb_byte
**new_info_ptr
,
5298 struct die_info
*parent
)
5300 struct die_info
*first_die
, *last_sibling
;
5304 first_die
= last_sibling
= NULL
;
5308 struct die_info
*die
5309 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5313 *new_info_ptr
= cur_ptr
;
5320 last_sibling
->sibling
= die
;
5326 /* Decompress a section that was compressed using zlib. Store the
5327 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5330 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5331 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5333 bfd
*abfd
= objfile
->obfd
;
5335 error (_("Support for zlib-compressed DWARF data (from '%s') "
5336 "is disabled in this copy of GDB"),
5337 bfd_get_filename (abfd
));
5339 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5340 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5341 bfd_size_type uncompressed_size
;
5342 gdb_byte
*uncompressed_buffer
;
5345 int header_size
= 12;
5347 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5348 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5349 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5350 bfd_get_filename (abfd
));
5352 /* Read the zlib header. In this case, it should be "ZLIB" followed
5353 by the uncompressed section size, 8 bytes in big-endian order. */
5354 if (compressed_size
< header_size
5355 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5356 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5357 bfd_get_filename (abfd
));
5358 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5359 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5360 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5361 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5362 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5363 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5364 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5365 uncompressed_size
+= compressed_buffer
[11];
5367 /* It is possible the section consists of several compressed
5368 buffers concatenated together, so we uncompress in a loop. */
5372 strm
.avail_in
= compressed_size
- header_size
;
5373 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5374 strm
.avail_out
= uncompressed_size
;
5375 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5377 rc
= inflateInit (&strm
);
5378 while (strm
.avail_in
> 0)
5381 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5382 bfd_get_filename (abfd
), rc
);
5383 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5384 + (uncompressed_size
- strm
.avail_out
));
5385 rc
= inflate (&strm
, Z_FINISH
);
5386 if (rc
!= Z_STREAM_END
)
5387 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5388 bfd_get_filename (abfd
), rc
);
5389 rc
= inflateReset (&strm
);
5391 rc
= inflateEnd (&strm
);
5393 || strm
.avail_out
!= 0)
5394 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5395 bfd_get_filename (abfd
), rc
);
5397 xfree (compressed_buffer
);
5398 *outbuf
= uncompressed_buffer
;
5399 *outsize
= uncompressed_size
;
5404 /* Read the contents of the section at OFFSET and of size SIZE from the
5405 object file specified by OBJFILE into the objfile_obstack and return it.
5406 If the section is compressed, uncompress it before returning. */
5409 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5411 bfd
*abfd
= objfile
->obfd
;
5412 gdb_byte
*buf
, *retbuf
;
5413 bfd_size_type size
= bfd_get_section_size (sectp
);
5414 unsigned char header
[4];
5419 /* Check if the file has a 4-byte header indicating compression. */
5420 if (size
> sizeof (header
)
5421 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5422 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5424 /* Upon decompression, update the buffer and its size. */
5425 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5427 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5428 dwarf2_resize_section (sectp
, size
);
5433 /* If we get here, we are a normal, not-compressed section. */
5434 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5435 /* When debugging .o files, we may need to apply relocations; see
5436 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5437 We never compress sections in .o files, so we only need to
5438 try this when the section is not compressed. */
5439 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5443 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5444 || bfd_bread (buf
, size
, abfd
) != size
)
5445 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5446 bfd_get_filename (abfd
));
5451 /* In DWARF version 2, the description of the debugging information is
5452 stored in a separate .debug_abbrev section. Before we read any
5453 dies from a section we read in all abbreviations and install them
5454 in a hash table. This function also sets flags in CU describing
5455 the data found in the abbrev table. */
5458 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5460 struct comp_unit_head
*cu_header
= &cu
->header
;
5461 gdb_byte
*abbrev_ptr
;
5462 struct abbrev_info
*cur_abbrev
;
5463 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5464 unsigned int abbrev_form
, hash_number
;
5465 struct attr_abbrev
*cur_attrs
;
5466 unsigned int allocated_attrs
;
5468 /* Initialize dwarf2 abbrevs */
5469 obstack_init (&cu
->abbrev_obstack
);
5470 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5472 * sizeof (struct abbrev_info
*)));
5473 memset (cu
->dwarf2_abbrevs
, 0,
5474 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5476 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5477 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5478 abbrev_ptr
+= bytes_read
;
5480 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5481 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5483 /* loop until we reach an abbrev number of 0 */
5484 while (abbrev_number
)
5486 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5488 /* read in abbrev header */
5489 cur_abbrev
->number
= abbrev_number
;
5490 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5491 abbrev_ptr
+= bytes_read
;
5492 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5495 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5496 cu
->has_namespace_info
= 1;
5498 /* now read in declarations */
5499 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5500 abbrev_ptr
+= bytes_read
;
5501 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5502 abbrev_ptr
+= bytes_read
;
5505 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5507 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5509 = xrealloc (cur_attrs
, (allocated_attrs
5510 * sizeof (struct attr_abbrev
)));
5513 /* Record whether this compilation unit might have
5514 inter-compilation-unit references. If we don't know what form
5515 this attribute will have, then it might potentially be a
5516 DW_FORM_ref_addr, so we conservatively expect inter-CU
5519 if (abbrev_form
== DW_FORM_ref_addr
5520 || abbrev_form
== DW_FORM_indirect
)
5521 cu
->has_form_ref_addr
= 1;
5523 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5524 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5525 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5526 abbrev_ptr
+= bytes_read
;
5527 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5528 abbrev_ptr
+= bytes_read
;
5531 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5532 (cur_abbrev
->num_attrs
5533 * sizeof (struct attr_abbrev
)));
5534 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5535 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5537 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5538 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5539 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5541 /* Get next abbreviation.
5542 Under Irix6 the abbreviations for a compilation unit are not
5543 always properly terminated with an abbrev number of 0.
5544 Exit loop if we encounter an abbreviation which we have
5545 already read (which means we are about to read the abbreviations
5546 for the next compile unit) or if the end of the abbreviation
5547 table is reached. */
5548 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5549 >= dwarf2_per_objfile
->abbrev_size
)
5551 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5552 abbrev_ptr
+= bytes_read
;
5553 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5560 /* Release the memory used by the abbrev table for a compilation unit. */
5563 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5565 struct dwarf2_cu
*cu
= ptr_to_cu
;
5567 obstack_free (&cu
->abbrev_obstack
, NULL
);
5568 cu
->dwarf2_abbrevs
= NULL
;
5571 /* Lookup an abbrev_info structure in the abbrev hash table. */
5573 static struct abbrev_info
*
5574 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5576 unsigned int hash_number
;
5577 struct abbrev_info
*abbrev
;
5579 hash_number
= number
% ABBREV_HASH_SIZE
;
5580 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5584 if (abbrev
->number
== number
)
5587 abbrev
= abbrev
->next
;
5592 /* Returns nonzero if TAG represents a type that we might generate a partial
5596 is_type_tag_for_partial (int tag
)
5601 /* Some types that would be reasonable to generate partial symbols for,
5602 that we don't at present. */
5603 case DW_TAG_array_type
:
5604 case DW_TAG_file_type
:
5605 case DW_TAG_ptr_to_member_type
:
5606 case DW_TAG_set_type
:
5607 case DW_TAG_string_type
:
5608 case DW_TAG_subroutine_type
:
5610 case DW_TAG_base_type
:
5611 case DW_TAG_class_type
:
5612 case DW_TAG_interface_type
:
5613 case DW_TAG_enumeration_type
:
5614 case DW_TAG_structure_type
:
5615 case DW_TAG_subrange_type
:
5616 case DW_TAG_typedef
:
5617 case DW_TAG_union_type
:
5624 /* Load all DIEs that are interesting for partial symbols into memory. */
5626 static struct partial_die_info
*
5627 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5628 struct dwarf2_cu
*cu
)
5630 struct partial_die_info
*part_die
;
5631 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5632 struct abbrev_info
*abbrev
;
5633 unsigned int bytes_read
;
5634 unsigned int load_all
= 0;
5636 int nesting_level
= 1;
5641 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5645 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5649 &cu
->comp_unit_obstack
,
5650 hashtab_obstack_allocate
,
5651 dummy_obstack_deallocate
);
5653 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5654 sizeof (struct partial_die_info
));
5658 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5660 /* A NULL abbrev means the end of a series of children. */
5663 if (--nesting_level
== 0)
5665 /* PART_DIE was probably the last thing allocated on the
5666 comp_unit_obstack, so we could call obstack_free
5667 here. We don't do that because the waste is small,
5668 and will be cleaned up when we're done with this
5669 compilation unit. This way, we're also more robust
5670 against other users of the comp_unit_obstack. */
5673 info_ptr
+= bytes_read
;
5674 last_die
= parent_die
;
5675 parent_die
= parent_die
->die_parent
;
5679 /* Check whether this DIE is interesting enough to save. Normally
5680 we would not be interested in members here, but there may be
5681 later variables referencing them via DW_AT_specification (for
5684 && !is_type_tag_for_partial (abbrev
->tag
)
5685 && abbrev
->tag
!= DW_TAG_enumerator
5686 && abbrev
->tag
!= DW_TAG_subprogram
5687 && abbrev
->tag
!= DW_TAG_lexical_block
5688 && abbrev
->tag
!= DW_TAG_variable
5689 && abbrev
->tag
!= DW_TAG_namespace
5690 && abbrev
->tag
!= DW_TAG_member
)
5692 /* Otherwise we skip to the next sibling, if any. */
5693 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5697 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5698 abfd
, info_ptr
, cu
);
5700 /* This two-pass algorithm for processing partial symbols has a
5701 high cost in cache pressure. Thus, handle some simple cases
5702 here which cover the majority of C partial symbols. DIEs
5703 which neither have specification tags in them, nor could have
5704 specification tags elsewhere pointing at them, can simply be
5705 processed and discarded.
5707 This segment is also optional; scan_partial_symbols and
5708 add_partial_symbol will handle these DIEs if we chain
5709 them in normally. When compilers which do not emit large
5710 quantities of duplicate debug information are more common,
5711 this code can probably be removed. */
5713 /* Any complete simple types at the top level (pretty much all
5714 of them, for a language without namespaces), can be processed
5716 if (parent_die
== NULL
5717 && part_die
->has_specification
== 0
5718 && part_die
->is_declaration
== 0
5719 && (part_die
->tag
== DW_TAG_typedef
5720 || part_die
->tag
== DW_TAG_base_type
5721 || part_die
->tag
== DW_TAG_subrange_type
))
5723 if (building_psymtab
&& part_die
->name
!= NULL
)
5724 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5725 VAR_DOMAIN
, LOC_TYPEDEF
,
5726 &cu
->objfile
->static_psymbols
,
5727 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5728 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5732 /* If we're at the second level, and we're an enumerator, and
5733 our parent has no specification (meaning possibly lives in a
5734 namespace elsewhere), then we can add the partial symbol now
5735 instead of queueing it. */
5736 if (part_die
->tag
== DW_TAG_enumerator
5737 && parent_die
!= NULL
5738 && parent_die
->die_parent
== NULL
5739 && parent_die
->tag
== DW_TAG_enumeration_type
5740 && parent_die
->has_specification
== 0)
5742 if (part_die
->name
== NULL
)
5743 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5744 else if (building_psymtab
)
5745 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5746 VAR_DOMAIN
, LOC_CONST
,
5747 (cu
->language
== language_cplus
5748 || cu
->language
== language_java
)
5749 ? &cu
->objfile
->global_psymbols
5750 : &cu
->objfile
->static_psymbols
,
5751 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5753 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5757 /* We'll save this DIE so link it in. */
5758 part_die
->die_parent
= parent_die
;
5759 part_die
->die_sibling
= NULL
;
5760 part_die
->die_child
= NULL
;
5762 if (last_die
&& last_die
== parent_die
)
5763 last_die
->die_child
= part_die
;
5765 last_die
->die_sibling
= part_die
;
5767 last_die
= part_die
;
5769 if (first_die
== NULL
)
5770 first_die
= part_die
;
5772 /* Maybe add the DIE to the hash table. Not all DIEs that we
5773 find interesting need to be in the hash table, because we
5774 also have the parent/sibling/child chains; only those that we
5775 might refer to by offset later during partial symbol reading.
5777 For now this means things that might have be the target of a
5778 DW_AT_specification, DW_AT_abstract_origin, or
5779 DW_AT_extension. DW_AT_extension will refer only to
5780 namespaces; DW_AT_abstract_origin refers to functions (and
5781 many things under the function DIE, but we do not recurse
5782 into function DIEs during partial symbol reading) and
5783 possibly variables as well; DW_AT_specification refers to
5784 declarations. Declarations ought to have the DW_AT_declaration
5785 flag. It happens that GCC forgets to put it in sometimes, but
5786 only for functions, not for types.
5788 Adding more things than necessary to the hash table is harmless
5789 except for the performance cost. Adding too few will result in
5790 wasted time in find_partial_die, when we reread the compilation
5791 unit with load_all_dies set. */
5794 || abbrev
->tag
== DW_TAG_subprogram
5795 || abbrev
->tag
== DW_TAG_variable
5796 || abbrev
->tag
== DW_TAG_namespace
5797 || part_die
->is_declaration
)
5801 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5802 part_die
->offset
, INSERT
);
5806 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5807 sizeof (struct partial_die_info
));
5809 /* For some DIEs we want to follow their children (if any). For C
5810 we have no reason to follow the children of structures; for other
5811 languages we have to, both so that we can get at method physnames
5812 to infer fully qualified class names, and for DW_AT_specification.
5814 For Ada, we need to scan the children of subprograms and lexical
5815 blocks as well because Ada allows the definition of nested
5816 entities that could be interesting for the debugger, such as
5817 nested subprograms for instance. */
5818 if (last_die
->has_children
5820 || last_die
->tag
== DW_TAG_namespace
5821 || last_die
->tag
== DW_TAG_enumeration_type
5822 || (cu
->language
!= language_c
5823 && (last_die
->tag
== DW_TAG_class_type
5824 || last_die
->tag
== DW_TAG_interface_type
5825 || last_die
->tag
== DW_TAG_structure_type
5826 || last_die
->tag
== DW_TAG_union_type
))
5827 || (cu
->language
== language_ada
5828 && (last_die
->tag
== DW_TAG_subprogram
5829 || last_die
->tag
== DW_TAG_lexical_block
))))
5832 parent_die
= last_die
;
5836 /* Otherwise we skip to the next sibling, if any. */
5837 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5839 /* Back to the top, do it again. */
5843 /* Read a minimal amount of information into the minimal die structure. */
5846 read_partial_die (struct partial_die_info
*part_die
,
5847 struct abbrev_info
*abbrev
,
5848 unsigned int abbrev_len
, bfd
*abfd
,
5849 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5851 unsigned int bytes_read
, i
;
5852 struct attribute attr
;
5853 int has_low_pc_attr
= 0;
5854 int has_high_pc_attr
= 0;
5855 CORE_ADDR base_address
= 0;
5859 base_address_low_pc
,
5860 /* Overrides BASE_ADDRESS_LOW_PC. */
5861 base_address_entry_pc
5863 base_address_type
= base_address_none
;
5865 memset (part_die
, 0, sizeof (struct partial_die_info
));
5867 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5869 info_ptr
+= abbrev_len
;
5874 part_die
->tag
= abbrev
->tag
;
5875 part_die
->has_children
= abbrev
->has_children
;
5877 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5879 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5881 /* Store the data if it is of an attribute we want to keep in a
5882 partial symbol table. */
5887 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5888 if (part_die
->name
== NULL
)
5889 part_die
->name
= DW_STRING (&attr
);
5891 case DW_AT_comp_dir
:
5892 if (part_die
->dirname
== NULL
)
5893 part_die
->dirname
= DW_STRING (&attr
);
5895 case DW_AT_MIPS_linkage_name
:
5896 part_die
->name
= DW_STRING (&attr
);
5899 has_low_pc_attr
= 1;
5900 part_die
->lowpc
= DW_ADDR (&attr
);
5901 if (part_die
->tag
== DW_TAG_compile_unit
5902 && base_address_type
< base_address_low_pc
)
5904 base_address
= DW_ADDR (&attr
);
5905 base_address_type
= base_address_low_pc
;
5909 has_high_pc_attr
= 1;
5910 part_die
->highpc
= DW_ADDR (&attr
);
5912 case DW_AT_entry_pc
:
5913 if (part_die
->tag
== DW_TAG_compile_unit
5914 && base_address_type
< base_address_entry_pc
)
5916 base_address
= DW_ADDR (&attr
);
5917 base_address_type
= base_address_entry_pc
;
5921 if (part_die
->tag
== DW_TAG_compile_unit
)
5923 cu
->ranges_offset
= DW_UNSND (&attr
);
5924 cu
->has_ranges_offset
= 1;
5927 case DW_AT_location
:
5928 /* Support the .debug_loc offsets */
5929 if (attr_form_is_block (&attr
))
5931 part_die
->locdesc
= DW_BLOCK (&attr
);
5933 else if (attr_form_is_section_offset (&attr
))
5935 dwarf2_complex_location_expr_complaint ();
5939 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5940 "partial symbol information");
5943 case DW_AT_language
:
5944 part_die
->language
= DW_UNSND (&attr
);
5946 case DW_AT_external
:
5947 part_die
->is_external
= DW_UNSND (&attr
);
5949 case DW_AT_declaration
:
5950 part_die
->is_declaration
= DW_UNSND (&attr
);
5953 part_die
->has_type
= 1;
5955 case DW_AT_abstract_origin
:
5956 case DW_AT_specification
:
5957 case DW_AT_extension
:
5958 part_die
->has_specification
= 1;
5959 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
5962 /* Ignore absolute siblings, they might point outside of
5963 the current compile unit. */
5964 if (attr
.form
== DW_FORM_ref_addr
)
5965 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5967 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5968 + dwarf2_get_ref_die_offset (&attr
);
5970 case DW_AT_stmt_list
:
5971 part_die
->has_stmt_list
= 1;
5972 part_die
->line_offset
= DW_UNSND (&attr
);
5974 case DW_AT_byte_size
:
5975 part_die
->has_byte_size
= 1;
5977 case DW_AT_calling_convention
:
5978 /* DWARF doesn't provide a way to identify a program's source-level
5979 entry point. DW_AT_calling_convention attributes are only meant
5980 to describe functions' calling conventions.
5982 However, because it's a necessary piece of information in
5983 Fortran, and because DW_CC_program is the only piece of debugging
5984 information whose definition refers to a 'main program' at all,
5985 several compilers have begun marking Fortran main programs with
5986 DW_CC_program --- even when those functions use the standard
5987 calling conventions.
5989 So until DWARF specifies a way to provide this information and
5990 compilers pick up the new representation, we'll support this
5992 if (DW_UNSND (&attr
) == DW_CC_program
5993 && cu
->language
== language_fortran
)
5994 set_main_name (part_die
->name
);
6001 /* When using the GNU linker, .gnu.linkonce. sections are used to
6002 eliminate duplicate copies of functions and vtables and such.
6003 The linker will arbitrarily choose one and discard the others.
6004 The AT_*_pc values for such functions refer to local labels in
6005 these sections. If the section from that file was discarded, the
6006 labels are not in the output, so the relocs get a value of 0.
6007 If this is a discarded function, mark the pc bounds as invalid,
6008 so that GDB will ignore it. */
6009 if (has_low_pc_attr
&& has_high_pc_attr
6010 && part_die
->lowpc
< part_die
->highpc
6011 && (part_die
->lowpc
!= 0
6012 || dwarf2_per_objfile
->has_section_at_zero
))
6013 part_die
->has_pc_info
= 1;
6015 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6017 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6019 cu
->base_address
= base_address
;
6025 /* Find a cached partial DIE at OFFSET in CU. */
6027 static struct partial_die_info
*
6028 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6030 struct partial_die_info
*lookup_die
= NULL
;
6031 struct partial_die_info part_die
;
6033 part_die
.offset
= offset
;
6034 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6039 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6041 static struct partial_die_info
*
6042 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6044 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6045 struct partial_die_info
*pd
= NULL
;
6047 if (offset_in_cu_p (&cu
->header
, offset
))
6049 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6054 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6056 if (per_cu
->cu
== NULL
)
6058 load_comp_unit (per_cu
, cu
->objfile
);
6059 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6060 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6063 per_cu
->cu
->last_used
= 0;
6064 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6066 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6068 struct cleanup
*back_to
;
6069 struct partial_die_info comp_unit_die
;
6070 struct abbrev_info
*abbrev
;
6071 unsigned int bytes_read
;
6074 per_cu
->load_all_dies
= 1;
6076 /* Re-read the DIEs. */
6077 back_to
= make_cleanup (null_cleanup
, 0);
6078 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6080 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6081 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6083 info_ptr
= (dwarf2_per_objfile
->info_buffer
6084 + per_cu
->cu
->header
.offset
6085 + per_cu
->cu
->header
.first_die_offset
);
6086 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6087 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6088 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6090 if (comp_unit_die
.has_children
)
6091 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6092 do_cleanups (back_to
);
6094 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6098 internal_error (__FILE__
, __LINE__
,
6099 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6100 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6104 /* Adjust PART_DIE before generating a symbol for it. This function
6105 may set the is_external flag or change the DIE's name. */
6108 fixup_partial_die (struct partial_die_info
*part_die
,
6109 struct dwarf2_cu
*cu
)
6111 /* If we found a reference attribute and the DIE has no name, try
6112 to find a name in the referred to DIE. */
6114 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6116 struct partial_die_info
*spec_die
;
6118 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6120 fixup_partial_die (spec_die
, cu
);
6124 part_die
->name
= spec_die
->name
;
6126 /* Copy DW_AT_external attribute if it is set. */
6127 if (spec_die
->is_external
)
6128 part_die
->is_external
= spec_die
->is_external
;
6132 /* Set default names for some unnamed DIEs. */
6133 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6134 || part_die
->tag
== DW_TAG_class_type
))
6135 part_die
->name
= "(anonymous class)";
6137 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6138 part_die
->name
= "(anonymous namespace)";
6140 if (part_die
->tag
== DW_TAG_structure_type
6141 || part_die
->tag
== DW_TAG_class_type
6142 || part_die
->tag
== DW_TAG_union_type
)
6143 guess_structure_name (part_die
, cu
);
6146 /* Read the die from the .debug_info section buffer. Set DIEP to
6147 point to a newly allocated die with its information, except for its
6148 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6149 whether the die has children or not. */
6152 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6153 struct dwarf2_cu
*cu
, int *has_children
)
6155 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6156 struct abbrev_info
*abbrev
;
6157 struct die_info
*die
;
6159 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6160 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6161 info_ptr
+= bytes_read
;
6169 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6172 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6174 bfd_get_filename (abfd
));
6176 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6177 die
->offset
= offset
;
6178 die
->tag
= abbrev
->tag
;
6179 die
->abbrev
= abbrev_number
;
6181 die
->num_attrs
= abbrev
->num_attrs
;
6183 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6184 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6185 abfd
, info_ptr
, cu
);
6188 *has_children
= abbrev
->has_children
;
6192 /* Read an attribute value described by an attribute form. */
6195 read_attribute_value (struct attribute
*attr
, unsigned form
,
6196 bfd
*abfd
, gdb_byte
*info_ptr
,
6197 struct dwarf2_cu
*cu
)
6199 struct comp_unit_head
*cu_header
= &cu
->header
;
6200 unsigned int bytes_read
;
6201 struct dwarf_block
*blk
;
6207 case DW_FORM_ref_addr
:
6208 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6209 info_ptr
+= bytes_read
;
6211 case DW_FORM_block2
:
6212 blk
= dwarf_alloc_block (cu
);
6213 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6215 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6216 info_ptr
+= blk
->size
;
6217 DW_BLOCK (attr
) = blk
;
6219 case DW_FORM_block4
:
6220 blk
= dwarf_alloc_block (cu
);
6221 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6223 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6224 info_ptr
+= blk
->size
;
6225 DW_BLOCK (attr
) = blk
;
6228 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6232 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6236 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6239 case DW_FORM_string
:
6240 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6241 info_ptr
+= bytes_read
;
6244 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6246 info_ptr
+= bytes_read
;
6249 blk
= dwarf_alloc_block (cu
);
6250 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6251 info_ptr
+= bytes_read
;
6252 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6253 info_ptr
+= blk
->size
;
6254 DW_BLOCK (attr
) = blk
;
6256 case DW_FORM_block1
:
6257 blk
= dwarf_alloc_block (cu
);
6258 blk
->size
= read_1_byte (abfd
, info_ptr
);
6260 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6261 info_ptr
+= blk
->size
;
6262 DW_BLOCK (attr
) = blk
;
6265 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6269 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6273 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6274 info_ptr
+= bytes_read
;
6277 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6278 info_ptr
+= bytes_read
;
6281 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6285 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6289 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6293 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6296 case DW_FORM_ref_udata
:
6297 DW_ADDR (attr
) = (cu
->header
.offset
6298 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6299 info_ptr
+= bytes_read
;
6301 case DW_FORM_indirect
:
6302 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6303 info_ptr
+= bytes_read
;
6304 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6307 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6308 dwarf_form_name (form
),
6309 bfd_get_filename (abfd
));
6312 /* We have seen instances where the compiler tried to emit a byte
6313 size attribute of -1 which ended up being encoded as an unsigned
6314 0xffffffff. Although 0xffffffff is technically a valid size value,
6315 an object of this size seems pretty unlikely so we can relatively
6316 safely treat these cases as if the size attribute was invalid and
6317 treat them as zero by default. */
6318 if (attr
->name
== DW_AT_byte_size
6319 && form
== DW_FORM_data4
6320 && DW_UNSND (attr
) >= 0xffffffff)
6323 (&symfile_complaints
,
6324 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6326 DW_UNSND (attr
) = 0;
6332 /* Read an attribute described by an abbreviated attribute. */
6335 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6336 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6338 attr
->name
= abbrev
->name
;
6339 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6342 /* read dwarf information from a buffer */
6345 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6347 return bfd_get_8 (abfd
, buf
);
6351 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6353 return bfd_get_signed_8 (abfd
, buf
);
6357 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6359 return bfd_get_16 (abfd
, buf
);
6363 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6365 return bfd_get_signed_16 (abfd
, buf
);
6369 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6371 return bfd_get_32 (abfd
, buf
);
6375 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6377 return bfd_get_signed_32 (abfd
, buf
);
6380 static unsigned long
6381 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6383 return bfd_get_64 (abfd
, buf
);
6387 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6388 unsigned int *bytes_read
)
6390 struct comp_unit_head
*cu_header
= &cu
->header
;
6391 CORE_ADDR retval
= 0;
6393 if (cu_header
->signed_addr_p
)
6395 switch (cu_header
->addr_size
)
6398 retval
= bfd_get_signed_16 (abfd
, buf
);
6401 retval
= bfd_get_signed_32 (abfd
, buf
);
6404 retval
= bfd_get_signed_64 (abfd
, buf
);
6407 internal_error (__FILE__
, __LINE__
,
6408 _("read_address: bad switch, signed [in module %s]"),
6409 bfd_get_filename (abfd
));
6414 switch (cu_header
->addr_size
)
6417 retval
= bfd_get_16 (abfd
, buf
);
6420 retval
= bfd_get_32 (abfd
, buf
);
6423 retval
= bfd_get_64 (abfd
, buf
);
6426 internal_error (__FILE__
, __LINE__
,
6427 _("read_address: bad switch, unsigned [in module %s]"),
6428 bfd_get_filename (abfd
));
6432 *bytes_read
= cu_header
->addr_size
;
6436 /* Read the initial length from a section. The (draft) DWARF 3
6437 specification allows the initial length to take up either 4 bytes
6438 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6439 bytes describe the length and all offsets will be 8 bytes in length
6442 An older, non-standard 64-bit format is also handled by this
6443 function. The older format in question stores the initial length
6444 as an 8-byte quantity without an escape value. Lengths greater
6445 than 2^32 aren't very common which means that the initial 4 bytes
6446 is almost always zero. Since a length value of zero doesn't make
6447 sense for the 32-bit format, this initial zero can be considered to
6448 be an escape value which indicates the presence of the older 64-bit
6449 format. As written, the code can't detect (old format) lengths
6450 greater than 4GB. If it becomes necessary to handle lengths
6451 somewhat larger than 4GB, we could allow other small values (such
6452 as the non-sensical values of 1, 2, and 3) to also be used as
6453 escape values indicating the presence of the old format.
6455 The value returned via bytes_read should be used to increment the
6456 relevant pointer after calling read_initial_length().
6458 [ Note: read_initial_length() and read_offset() are based on the
6459 document entitled "DWARF Debugging Information Format", revision
6460 3, draft 8, dated November 19, 2001. This document was obtained
6463 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6465 This document is only a draft and is subject to change. (So beware.)
6467 Details regarding the older, non-standard 64-bit format were
6468 determined empirically by examining 64-bit ELF files produced by
6469 the SGI toolchain on an IRIX 6.5 machine.
6471 - Kevin, July 16, 2002
6475 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6477 LONGEST length
= bfd_get_32 (abfd
, buf
);
6479 if (length
== 0xffffffff)
6481 length
= bfd_get_64 (abfd
, buf
+ 4);
6484 else if (length
== 0)
6486 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6487 length
= bfd_get_64 (abfd
, buf
);
6498 /* Cover function for read_initial_length.
6499 Returns the length of the object at BUF, and stores the size of the
6500 initial length in *BYTES_READ and stores the size that offsets will be in
6502 If the initial length size is not equivalent to that specified in
6503 CU_HEADER then issue a complaint.
6504 This is useful when reading non-comp-unit headers. */
6507 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6508 const struct comp_unit_head
*cu_header
,
6509 unsigned int *bytes_read
,
6510 unsigned int *offset_size
)
6512 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6514 gdb_assert (cu_header
->initial_length_size
== 4
6515 || cu_header
->initial_length_size
== 8
6516 || cu_header
->initial_length_size
== 12);
6518 if (cu_header
->initial_length_size
!= *bytes_read
)
6519 complaint (&symfile_complaints
,
6520 _("intermixed 32-bit and 64-bit DWARF sections"));
6522 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6526 /* Read an offset from the data stream. The size of the offset is
6527 given by cu_header->offset_size. */
6530 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6531 unsigned int *bytes_read
)
6533 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6534 *bytes_read
= cu_header
->offset_size
;
6538 /* Read an offset from the data stream. */
6541 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6545 switch (offset_size
)
6548 retval
= bfd_get_32 (abfd
, buf
);
6551 retval
= bfd_get_64 (abfd
, buf
);
6554 internal_error (__FILE__
, __LINE__
,
6555 _("read_offset_1: bad switch [in module %s]"),
6556 bfd_get_filename (abfd
));
6563 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6565 /* If the size of a host char is 8 bits, we can return a pointer
6566 to the buffer, otherwise we have to copy the data to a buffer
6567 allocated on the temporary obstack. */
6568 gdb_assert (HOST_CHAR_BIT
== 8);
6573 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6575 /* If the size of a host char is 8 bits, we can return a pointer
6576 to the string, otherwise we have to copy the string to a buffer
6577 allocated on the temporary obstack. */
6578 gdb_assert (HOST_CHAR_BIT
== 8);
6581 *bytes_read_ptr
= 1;
6584 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6585 return (char *) buf
;
6589 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6590 const struct comp_unit_head
*cu_header
,
6591 unsigned int *bytes_read_ptr
)
6593 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6595 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6597 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6598 bfd_get_filename (abfd
));
6601 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6603 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6604 bfd_get_filename (abfd
));
6607 gdb_assert (HOST_CHAR_BIT
== 8);
6608 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6610 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6613 static unsigned long
6614 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6616 unsigned long result
;
6617 unsigned int num_read
;
6627 byte
= bfd_get_8 (abfd
, buf
);
6630 result
|= ((unsigned long)(byte
& 127) << shift
);
6631 if ((byte
& 128) == 0)
6637 *bytes_read_ptr
= num_read
;
6642 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6645 int i
, shift
, num_read
;
6654 byte
= bfd_get_8 (abfd
, buf
);
6657 result
|= ((long)(byte
& 127) << shift
);
6659 if ((byte
& 128) == 0)
6664 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6665 result
|= -(((long)1) << shift
);
6666 *bytes_read_ptr
= num_read
;
6670 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6673 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6679 byte
= bfd_get_8 (abfd
, buf
);
6681 if ((byte
& 128) == 0)
6687 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6693 cu
->language
= language_c
;
6695 case DW_LANG_C_plus_plus
:
6696 cu
->language
= language_cplus
;
6698 case DW_LANG_Fortran77
:
6699 case DW_LANG_Fortran90
:
6700 case DW_LANG_Fortran95
:
6701 cu
->language
= language_fortran
;
6703 case DW_LANG_Mips_Assembler
:
6704 cu
->language
= language_asm
;
6707 cu
->language
= language_java
;
6711 cu
->language
= language_ada
;
6713 case DW_LANG_Modula2
:
6714 cu
->language
= language_m2
;
6716 case DW_LANG_Pascal83
:
6717 cu
->language
= language_pascal
;
6720 cu
->language
= language_objc
;
6722 case DW_LANG_Cobol74
:
6723 case DW_LANG_Cobol85
:
6725 cu
->language
= language_minimal
;
6728 cu
->language_defn
= language_def (cu
->language
);
6731 /* Return the named attribute or NULL if not there. */
6733 static struct attribute
*
6734 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6737 struct attribute
*spec
= NULL
;
6739 for (i
= 0; i
< die
->num_attrs
; ++i
)
6741 if (die
->attrs
[i
].name
== name
)
6742 return &die
->attrs
[i
];
6743 if (die
->attrs
[i
].name
== DW_AT_specification
6744 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6745 spec
= &die
->attrs
[i
];
6750 die
= follow_die_ref (die
, spec
, &cu
);
6751 return dwarf2_attr (die
, name
, cu
);
6757 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6758 and holds a non-zero value. This function should only be used for
6759 DW_FORM_flag attributes. */
6762 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6764 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6766 return (attr
&& DW_UNSND (attr
));
6770 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6772 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6773 which value is non-zero. However, we have to be careful with
6774 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6775 (via dwarf2_flag_true_p) follows this attribute. So we may
6776 end up accidently finding a declaration attribute that belongs
6777 to a different DIE referenced by the specification attribute,
6778 even though the given DIE does not have a declaration attribute. */
6779 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6780 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6783 /* Return the die giving the specification for DIE, if there is
6784 one. *SPEC_CU is the CU containing DIE on input, and the CU
6785 containing the return value on output. */
6787 static struct die_info
*
6788 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6790 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6793 if (spec_attr
== NULL
)
6796 return follow_die_ref (die
, spec_attr
, spec_cu
);
6799 /* Free the line_header structure *LH, and any arrays and strings it
6802 free_line_header (struct line_header
*lh
)
6804 if (lh
->standard_opcode_lengths
)
6805 xfree (lh
->standard_opcode_lengths
);
6807 /* Remember that all the lh->file_names[i].name pointers are
6808 pointers into debug_line_buffer, and don't need to be freed. */
6810 xfree (lh
->file_names
);
6812 /* Similarly for the include directory names. */
6813 if (lh
->include_dirs
)
6814 xfree (lh
->include_dirs
);
6820 /* Add an entry to LH's include directory table. */
6822 add_include_dir (struct line_header
*lh
, char *include_dir
)
6824 /* Grow the array if necessary. */
6825 if (lh
->include_dirs_size
== 0)
6827 lh
->include_dirs_size
= 1; /* for testing */
6828 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6829 * sizeof (*lh
->include_dirs
));
6831 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6833 lh
->include_dirs_size
*= 2;
6834 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6835 (lh
->include_dirs_size
6836 * sizeof (*lh
->include_dirs
)));
6839 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6843 /* Add an entry to LH's file name table. */
6845 add_file_name (struct line_header
*lh
,
6847 unsigned int dir_index
,
6848 unsigned int mod_time
,
6849 unsigned int length
)
6851 struct file_entry
*fe
;
6853 /* Grow the array if necessary. */
6854 if (lh
->file_names_size
== 0)
6856 lh
->file_names_size
= 1; /* for testing */
6857 lh
->file_names
= xmalloc (lh
->file_names_size
6858 * sizeof (*lh
->file_names
));
6860 else if (lh
->num_file_names
>= lh
->file_names_size
)
6862 lh
->file_names_size
*= 2;
6863 lh
->file_names
= xrealloc (lh
->file_names
,
6864 (lh
->file_names_size
6865 * sizeof (*lh
->file_names
)));
6868 fe
= &lh
->file_names
[lh
->num_file_names
++];
6870 fe
->dir_index
= dir_index
;
6871 fe
->mod_time
= mod_time
;
6872 fe
->length
= length
;
6878 /* Read the statement program header starting at OFFSET in
6879 .debug_line, according to the endianness of ABFD. Return a pointer
6880 to a struct line_header, allocated using xmalloc.
6882 NOTE: the strings in the include directory and file name tables of
6883 the returned object point into debug_line_buffer, and must not be
6885 static struct line_header
*
6886 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6887 struct dwarf2_cu
*cu
)
6889 struct cleanup
*back_to
;
6890 struct line_header
*lh
;
6892 unsigned int bytes_read
, offset_size
;
6894 char *cur_dir
, *cur_file
;
6896 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6898 complaint (&symfile_complaints
, _("missing .debug_line section"));
6902 /* Make sure that at least there's room for the total_length field.
6903 That could be 12 bytes long, but we're just going to fudge that. */
6904 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6906 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6910 lh
= xmalloc (sizeof (*lh
));
6911 memset (lh
, 0, sizeof (*lh
));
6912 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6915 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6917 /* Read in the header. */
6919 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
6920 &bytes_read
, &offset_size
);
6921 line_ptr
+= bytes_read
;
6922 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6923 + dwarf2_per_objfile
->line_size
))
6925 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6928 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6929 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6931 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
6932 line_ptr
+= offset_size
;
6933 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6935 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6937 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6939 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6941 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6943 lh
->standard_opcode_lengths
6944 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6946 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6947 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6949 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6953 /* Read directory table. */
6954 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6956 line_ptr
+= bytes_read
;
6957 add_include_dir (lh
, cur_dir
);
6959 line_ptr
+= bytes_read
;
6961 /* Read file name table. */
6962 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6964 unsigned int dir_index
, mod_time
, length
;
6966 line_ptr
+= bytes_read
;
6967 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6968 line_ptr
+= bytes_read
;
6969 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6970 line_ptr
+= bytes_read
;
6971 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6972 line_ptr
+= bytes_read
;
6974 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6976 line_ptr
+= bytes_read
;
6977 lh
->statement_program_start
= line_ptr
;
6979 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6980 + dwarf2_per_objfile
->line_size
))
6981 complaint (&symfile_complaints
,
6982 _("line number info header doesn't fit in `.debug_line' section"));
6984 discard_cleanups (back_to
);
6988 /* This function exists to work around a bug in certain compilers
6989 (particularly GCC 2.95), in which the first line number marker of a
6990 function does not show up until after the prologue, right before
6991 the second line number marker. This function shifts ADDRESS down
6992 to the beginning of the function if necessary, and is called on
6993 addresses passed to record_line. */
6996 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6998 struct function_range
*fn
;
7000 /* Find the function_range containing address. */
7005 cu
->cached_fn
= cu
->first_fn
;
7009 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7015 while (fn
&& fn
!= cu
->cached_fn
)
7016 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7026 if (address
!= fn
->lowpc
)
7027 complaint (&symfile_complaints
,
7028 _("misplaced first line number at 0x%lx for '%s'"),
7029 (unsigned long) address
, fn
->name
);
7034 /* Decode the Line Number Program (LNP) for the given line_header
7035 structure and CU. The actual information extracted and the type
7036 of structures created from the LNP depends on the value of PST.
7038 1. If PST is NULL, then this procedure uses the data from the program
7039 to create all necessary symbol tables, and their linetables.
7040 The compilation directory of the file is passed in COMP_DIR,
7041 and must not be NULL.
7043 2. If PST is not NULL, this procedure reads the program to determine
7044 the list of files included by the unit represented by PST, and
7045 builds all the associated partial symbol tables. In this case,
7046 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7047 is not used to compute the full name of the symtab, and therefore
7048 omitting it when building the partial symtab does not introduce
7049 the potential for inconsistency - a partial symtab and its associated
7050 symbtab having a different fullname -). */
7053 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7054 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7056 gdb_byte
*line_ptr
, *extended_end
;
7058 unsigned int bytes_read
, extended_len
;
7059 unsigned char op_code
, extended_op
, adj_opcode
;
7061 struct objfile
*objfile
= cu
->objfile
;
7062 const int decode_for_pst_p
= (pst
!= NULL
);
7063 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7065 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7067 line_ptr
= lh
->statement_program_start
;
7068 line_end
= lh
->statement_program_end
;
7070 /* Read the statement sequences until there's nothing left. */
7071 while (line_ptr
< line_end
)
7073 /* state machine registers */
7074 CORE_ADDR address
= 0;
7075 unsigned int file
= 1;
7076 unsigned int line
= 1;
7077 unsigned int column
= 0;
7078 int is_stmt
= lh
->default_is_stmt
;
7079 int basic_block
= 0;
7080 int end_sequence
= 0;
7082 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7084 /* Start a subfile for the current file of the state machine. */
7085 /* lh->include_dirs and lh->file_names are 0-based, but the
7086 directory and file name numbers in the statement program
7088 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7092 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7094 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7097 /* Decode the table. */
7098 while (!end_sequence
)
7100 op_code
= read_1_byte (abfd
, line_ptr
);
7102 if (line_ptr
> line_end
)
7104 dwarf2_debug_line_missing_end_sequence_complaint ();
7108 if (op_code
>= lh
->opcode_base
)
7110 /* Special operand. */
7111 adj_opcode
= op_code
- lh
->opcode_base
;
7112 address
+= (adj_opcode
/ lh
->line_range
)
7113 * lh
->minimum_instruction_length
;
7114 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7115 if (lh
->num_file_names
< file
|| file
== 0)
7116 dwarf2_debug_line_missing_file_complaint ();
7119 lh
->file_names
[file
- 1].included_p
= 1;
7120 if (!decode_for_pst_p
)
7122 if (last_subfile
!= current_subfile
)
7125 record_line (last_subfile
, 0, address
);
7126 last_subfile
= current_subfile
;
7128 /* Append row to matrix using current values. */
7129 record_line (current_subfile
, line
,
7130 check_cu_functions (address
, cu
));
7135 else switch (op_code
)
7137 case DW_LNS_extended_op
:
7138 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7139 line_ptr
+= bytes_read
;
7140 extended_end
= line_ptr
+ extended_len
;
7141 extended_op
= read_1_byte (abfd
, line_ptr
);
7143 switch (extended_op
)
7145 case DW_LNE_end_sequence
:
7148 case DW_LNE_set_address
:
7149 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7150 line_ptr
+= bytes_read
;
7151 address
+= baseaddr
;
7153 case DW_LNE_define_file
:
7156 unsigned int dir_index
, mod_time
, length
;
7158 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7159 line_ptr
+= bytes_read
;
7161 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7162 line_ptr
+= bytes_read
;
7164 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7165 line_ptr
+= bytes_read
;
7167 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7168 line_ptr
+= bytes_read
;
7169 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7173 complaint (&symfile_complaints
,
7174 _("mangled .debug_line section"));
7177 /* Make sure that we parsed the extended op correctly. If e.g.
7178 we expected a different address size than the producer used,
7179 we may have read the wrong number of bytes. */
7180 if (line_ptr
!= extended_end
)
7182 complaint (&symfile_complaints
,
7183 _("mangled .debug_line section"));
7188 if (lh
->num_file_names
< file
|| file
== 0)
7189 dwarf2_debug_line_missing_file_complaint ();
7192 lh
->file_names
[file
- 1].included_p
= 1;
7193 if (!decode_for_pst_p
)
7195 if (last_subfile
!= current_subfile
)
7198 record_line (last_subfile
, 0, address
);
7199 last_subfile
= current_subfile
;
7201 record_line (current_subfile
, line
,
7202 check_cu_functions (address
, cu
));
7207 case DW_LNS_advance_pc
:
7208 address
+= lh
->minimum_instruction_length
7209 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7210 line_ptr
+= bytes_read
;
7212 case DW_LNS_advance_line
:
7213 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7214 line_ptr
+= bytes_read
;
7216 case DW_LNS_set_file
:
7218 /* The arrays lh->include_dirs and lh->file_names are
7219 0-based, but the directory and file name numbers in
7220 the statement program are 1-based. */
7221 struct file_entry
*fe
;
7224 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7225 line_ptr
+= bytes_read
;
7226 if (lh
->num_file_names
< file
|| file
== 0)
7227 dwarf2_debug_line_missing_file_complaint ();
7230 fe
= &lh
->file_names
[file
- 1];
7232 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7233 if (!decode_for_pst_p
)
7235 last_subfile
= current_subfile
;
7236 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7241 case DW_LNS_set_column
:
7242 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7243 line_ptr
+= bytes_read
;
7245 case DW_LNS_negate_stmt
:
7246 is_stmt
= (!is_stmt
);
7248 case DW_LNS_set_basic_block
:
7251 /* Add to the address register of the state machine the
7252 address increment value corresponding to special opcode
7253 255. I.e., this value is scaled by the minimum
7254 instruction length since special opcode 255 would have
7255 scaled the the increment. */
7256 case DW_LNS_const_add_pc
:
7257 address
+= (lh
->minimum_instruction_length
7258 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7260 case DW_LNS_fixed_advance_pc
:
7261 address
+= read_2_bytes (abfd
, line_ptr
);
7266 /* Unknown standard opcode, ignore it. */
7269 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7271 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7272 line_ptr
+= bytes_read
;
7277 if (lh
->num_file_names
< file
|| file
== 0)
7278 dwarf2_debug_line_missing_file_complaint ();
7281 lh
->file_names
[file
- 1].included_p
= 1;
7282 if (!decode_for_pst_p
)
7283 record_line (current_subfile
, 0, address
);
7287 if (decode_for_pst_p
)
7291 /* Now that we're done scanning the Line Header Program, we can
7292 create the psymtab of each included file. */
7293 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7294 if (lh
->file_names
[file_index
].included_p
== 1)
7296 const struct file_entry fe
= lh
->file_names
[file_index
];
7297 char *include_name
= fe
.name
;
7298 char *dir_name
= NULL
;
7299 char *pst_filename
= pst
->filename
;
7302 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7304 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7306 include_name
= concat (dir_name
, SLASH_STRING
,
7307 include_name
, (char *)NULL
);
7308 make_cleanup (xfree
, include_name
);
7311 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7313 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7314 pst_filename
, (char *)NULL
);
7315 make_cleanup (xfree
, pst_filename
);
7318 if (strcmp (include_name
, pst_filename
) != 0)
7319 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7324 /* Make sure a symtab is created for every file, even files
7325 which contain only variables (i.e. no code with associated
7329 struct file_entry
*fe
;
7331 for (i
= 0; i
< lh
->num_file_names
; i
++)
7334 fe
= &lh
->file_names
[i
];
7336 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7337 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7339 /* Skip the main file; we don't need it, and it must be
7340 allocated last, so that it will show up before the
7341 non-primary symtabs in the objfile's symtab list. */
7342 if (current_subfile
== first_subfile
)
7345 if (current_subfile
->symtab
== NULL
)
7346 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7348 fe
->symtab
= current_subfile
->symtab
;
7353 /* Start a subfile for DWARF. FILENAME is the name of the file and
7354 DIRNAME the name of the source directory which contains FILENAME
7355 or NULL if not known. COMP_DIR is the compilation directory for the
7356 linetable's compilation unit or NULL if not known.
7357 This routine tries to keep line numbers from identical absolute and
7358 relative file names in a common subfile.
7360 Using the `list' example from the GDB testsuite, which resides in
7361 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7362 of /srcdir/list0.c yields the following debugging information for list0.c:
7364 DW_AT_name: /srcdir/list0.c
7365 DW_AT_comp_dir: /compdir
7366 files.files[0].name: list0.h
7367 files.files[0].dir: /srcdir
7368 files.files[1].name: list0.c
7369 files.files[1].dir: /srcdir
7371 The line number information for list0.c has to end up in a single
7372 subfile, so that `break /srcdir/list0.c:1' works as expected.
7373 start_subfile will ensure that this happens provided that we pass the
7374 concatenation of files.files[1].dir and files.files[1].name as the
7378 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7382 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7383 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7384 second argument to start_subfile. To be consistent, we do the
7385 same here. In order not to lose the line information directory,
7386 we concatenate it to the filename when it makes sense.
7387 Note that the Dwarf3 standard says (speaking of filenames in line
7388 information): ``The directory index is ignored for file names
7389 that represent full path names''. Thus ignoring dirname in the
7390 `else' branch below isn't an issue. */
7392 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7393 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7395 fullname
= filename
;
7397 start_subfile (fullname
, comp_dir
);
7399 if (fullname
!= filename
)
7404 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7405 struct dwarf2_cu
*cu
)
7407 struct objfile
*objfile
= cu
->objfile
;
7408 struct comp_unit_head
*cu_header
= &cu
->header
;
7410 /* NOTE drow/2003-01-30: There used to be a comment and some special
7411 code here to turn a symbol with DW_AT_external and a
7412 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7413 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7414 with some versions of binutils) where shared libraries could have
7415 relocations against symbols in their debug information - the
7416 minimal symbol would have the right address, but the debug info
7417 would not. It's no longer necessary, because we will explicitly
7418 apply relocations when we read in the debug information now. */
7420 /* A DW_AT_location attribute with no contents indicates that a
7421 variable has been optimized away. */
7422 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7424 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7428 /* Handle one degenerate form of location expression specially, to
7429 preserve GDB's previous behavior when section offsets are
7430 specified. If this is just a DW_OP_addr then mark this symbol
7433 if (attr_form_is_block (attr
)
7434 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7435 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7439 SYMBOL_VALUE_ADDRESS (sym
) =
7440 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7441 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7442 fixup_symbol_section (sym
, objfile
);
7443 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7444 SYMBOL_SECTION (sym
));
7448 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7449 expression evaluator, and use LOC_COMPUTED only when necessary
7450 (i.e. when the value of a register or memory location is
7451 referenced, or a thread-local block, etc.). Then again, it might
7452 not be worthwhile. I'm assuming that it isn't unless performance
7453 or memory numbers show me otherwise. */
7455 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7456 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7459 /* Given a pointer to a DWARF information entry, figure out if we need
7460 to make a symbol table entry for it, and if so, create a new entry
7461 and return a pointer to it.
7462 If TYPE is NULL, determine symbol type from the die, otherwise
7463 used the passed type. */
7465 static struct symbol
*
7466 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7468 struct objfile
*objfile
= cu
->objfile
;
7469 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7470 struct symbol
*sym
= NULL
;
7472 struct attribute
*attr
= NULL
;
7473 struct attribute
*attr2
= NULL
;
7476 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7478 if (die
->tag
!= DW_TAG_namespace
)
7479 name
= dwarf2_linkage_name (die
, cu
);
7481 name
= TYPE_NAME (type
);
7485 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7486 sizeof (struct symbol
));
7487 OBJSTAT (objfile
, n_syms
++);
7488 memset (sym
, 0, sizeof (struct symbol
));
7490 /* Cache this symbol's name and the name's demangled form (if any). */
7491 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7492 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7494 /* Default assumptions.
7495 Use the passed type or decode it from the die. */
7496 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7497 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7499 SYMBOL_TYPE (sym
) = type
;
7501 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7502 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7505 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7508 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7511 int file_index
= DW_UNSND (attr
);
7512 if (cu
->line_header
== NULL
7513 || file_index
> cu
->line_header
->num_file_names
)
7514 complaint (&symfile_complaints
,
7515 _("file index out of range"));
7516 else if (file_index
> 0)
7518 struct file_entry
*fe
;
7519 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7520 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7527 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7530 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7532 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7534 case DW_TAG_subprogram
:
7535 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7537 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7538 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7539 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7540 || cu
->language
== language_ada
)
7542 /* Subprograms marked external are stored as a global symbol.
7543 Ada subprograms, whether marked external or not, are always
7544 stored as a global symbol, because we want to be able to
7545 access them globally. For instance, we want to be able
7546 to break on a nested subprogram without having to
7547 specify the context. */
7548 add_symbol_to_list (sym
, &global_symbols
);
7552 add_symbol_to_list (sym
, cu
->list_in_scope
);
7555 case DW_TAG_variable
:
7556 /* Compilation with minimal debug info may result in variables
7557 with missing type entries. Change the misleading `void' type
7558 to something sensible. */
7559 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7561 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7563 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7566 dwarf2_const_value (attr
, sym
, cu
);
7567 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7568 if (attr2
&& (DW_UNSND (attr2
) != 0))
7569 add_symbol_to_list (sym
, &global_symbols
);
7571 add_symbol_to_list (sym
, cu
->list_in_scope
);
7574 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7577 var_decode_location (attr
, sym
, cu
);
7578 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7579 if (attr2
&& (DW_UNSND (attr2
) != 0))
7580 add_symbol_to_list (sym
, &global_symbols
);
7582 add_symbol_to_list (sym
, cu
->list_in_scope
);
7586 /* We do not know the address of this symbol.
7587 If it is an external symbol and we have type information
7588 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7589 The address of the variable will then be determined from
7590 the minimal symbol table whenever the variable is
7592 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7593 if (attr2
&& (DW_UNSND (attr2
) != 0)
7594 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7596 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7597 add_symbol_to_list (sym
, &global_symbols
);
7601 case DW_TAG_formal_parameter
:
7602 SYMBOL_IS_ARGUMENT (sym
) = 1;
7603 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7606 var_decode_location (attr
, sym
, cu
);
7608 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7611 dwarf2_const_value (attr
, sym
, cu
);
7613 add_symbol_to_list (sym
, cu
->list_in_scope
);
7615 case DW_TAG_unspecified_parameters
:
7616 /* From varargs functions; gdb doesn't seem to have any
7617 interest in this information, so just ignore it for now.
7620 case DW_TAG_class_type
:
7621 case DW_TAG_interface_type
:
7622 case DW_TAG_structure_type
:
7623 case DW_TAG_union_type
:
7624 case DW_TAG_set_type
:
7625 case DW_TAG_enumeration_type
:
7626 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7627 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7629 /* Make sure that the symbol includes appropriate enclosing
7630 classes/namespaces in its name. These are calculated in
7631 read_structure_type, and the correct name is saved in
7634 if (cu
->language
== language_cplus
7635 || cu
->language
== language_java
)
7637 struct type
*type
= SYMBOL_TYPE (sym
);
7639 if (TYPE_TAG_NAME (type
) != NULL
)
7641 /* FIXME: carlton/2003-11-10: Should this use
7642 SYMBOL_SET_NAMES instead? (The same problem also
7643 arises further down in this function.) */
7644 /* The type's name is already allocated along with
7645 this objfile, so we don't need to duplicate it
7647 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7652 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7653 really ever be static objects: otherwise, if you try
7654 to, say, break of a class's method and you're in a file
7655 which doesn't mention that class, it won't work unless
7656 the check for all static symbols in lookup_symbol_aux
7657 saves you. See the OtherFileClass tests in
7658 gdb.c++/namespace.exp. */
7660 struct pending
**list_to_add
;
7662 list_to_add
= (cu
->list_in_scope
== &file_symbols
7663 && (cu
->language
== language_cplus
7664 || cu
->language
== language_java
)
7665 ? &global_symbols
: cu
->list_in_scope
);
7667 add_symbol_to_list (sym
, list_to_add
);
7669 /* The semantics of C++ state that "struct foo { ... }" also
7670 defines a typedef for "foo". A Java class declaration also
7671 defines a typedef for the class. */
7672 if (cu
->language
== language_cplus
7673 || cu
->language
== language_java
7674 || cu
->language
== language_ada
)
7676 /* The symbol's name is already allocated along with
7677 this objfile, so we don't need to duplicate it for
7679 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7680 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7684 case DW_TAG_typedef
:
7685 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7686 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7687 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7688 add_symbol_to_list (sym
, cu
->list_in_scope
);
7690 case DW_TAG_base_type
:
7691 case DW_TAG_subrange_type
:
7692 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7693 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7694 add_symbol_to_list (sym
, cu
->list_in_scope
);
7696 case DW_TAG_enumerator
:
7697 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7698 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7701 dwarf2_const_value (attr
, sym
, cu
);
7704 /* NOTE: carlton/2003-11-10: See comment above in the
7705 DW_TAG_class_type, etc. block. */
7707 struct pending
**list_to_add
;
7709 list_to_add
= (cu
->list_in_scope
== &file_symbols
7710 && (cu
->language
== language_cplus
7711 || cu
->language
== language_java
)
7712 ? &global_symbols
: cu
->list_in_scope
);
7714 add_symbol_to_list (sym
, list_to_add
);
7717 case DW_TAG_namespace
:
7718 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7719 add_symbol_to_list (sym
, &global_symbols
);
7722 /* Not a tag we recognize. Hopefully we aren't processing
7723 trash data, but since we must specifically ignore things
7724 we don't recognize, there is nothing else we should do at
7726 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7727 dwarf_tag_name (die
->tag
));
7731 /* For the benefit of old versions of GCC, check for anonymous
7732 namespaces based on the demangled name. */
7733 if (!processing_has_namespace_info
7734 && cu
->language
== language_cplus
7735 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7736 cp_scan_for_anonymous_namespaces (sym
);
7741 /* Copy constant value from an attribute to a symbol. */
7744 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7745 struct dwarf2_cu
*cu
)
7747 struct objfile
*objfile
= cu
->objfile
;
7748 struct comp_unit_head
*cu_header
= &cu
->header
;
7749 struct dwarf_block
*blk
;
7754 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7755 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7756 cu_header
->addr_size
,
7757 TYPE_LENGTH (SYMBOL_TYPE
7759 SYMBOL_VALUE_BYTES (sym
) =
7760 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7761 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7762 it's body - store_unsigned_integer. */
7763 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7765 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7768 /* DW_STRING is already allocated on the obstack, point directly
7770 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7771 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7773 case DW_FORM_block1
:
7774 case DW_FORM_block2
:
7775 case DW_FORM_block4
:
7777 blk
= DW_BLOCK (attr
);
7778 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7779 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7781 TYPE_LENGTH (SYMBOL_TYPE
7783 SYMBOL_VALUE_BYTES (sym
) =
7784 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7785 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7786 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7789 /* The DW_AT_const_value attributes are supposed to carry the
7790 symbol's value "represented as it would be on the target
7791 architecture." By the time we get here, it's already been
7792 converted to host endianness, so we just need to sign- or
7793 zero-extend it as appropriate. */
7795 dwarf2_const_value_data (attr
, sym
, 8);
7798 dwarf2_const_value_data (attr
, sym
, 16);
7801 dwarf2_const_value_data (attr
, sym
, 32);
7804 dwarf2_const_value_data (attr
, sym
, 64);
7808 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7809 SYMBOL_CLASS (sym
) = LOC_CONST
;
7813 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7814 SYMBOL_CLASS (sym
) = LOC_CONST
;
7818 complaint (&symfile_complaints
,
7819 _("unsupported const value attribute form: '%s'"),
7820 dwarf_form_name (attr
->form
));
7821 SYMBOL_VALUE (sym
) = 0;
7822 SYMBOL_CLASS (sym
) = LOC_CONST
;
7828 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7829 or zero-extend it as appropriate for the symbol's type. */
7831 dwarf2_const_value_data (struct attribute
*attr
,
7835 LONGEST l
= DW_UNSND (attr
);
7837 if (bits
< sizeof (l
) * 8)
7839 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7840 l
&= ((LONGEST
) 1 << bits
) - 1;
7842 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7845 SYMBOL_VALUE (sym
) = l
;
7846 SYMBOL_CLASS (sym
) = LOC_CONST
;
7850 /* Return the type of the die in question using its DW_AT_type attribute. */
7852 static struct type
*
7853 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7855 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7857 struct attribute
*type_attr
;
7858 struct die_info
*type_die
;
7860 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7863 /* A missing DW_AT_type represents a void type. */
7864 return builtin_type (gdbarch
)->builtin_void
;
7867 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7869 type
= tag_type_to_type (type_die
, cu
);
7872 dump_die_for_error (type_die
);
7873 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7879 /* Return the containing type of the die in question using its
7880 DW_AT_containing_type attribute. */
7882 static struct type
*
7883 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7885 struct type
*type
= NULL
;
7886 struct attribute
*type_attr
;
7887 struct die_info
*type_die
= NULL
;
7889 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7892 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7893 type
= tag_type_to_type (type_die
, cu
);
7898 dump_die_for_error (type_die
);
7899 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7905 static struct type
*
7906 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7908 struct type
*this_type
;
7910 this_type
= read_type_die (die
, cu
);
7913 dump_die_for_error (die
);
7914 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7920 static struct type
*
7921 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7923 struct type
*this_type
;
7925 this_type
= get_die_type (die
, cu
);
7931 case DW_TAG_class_type
:
7932 case DW_TAG_interface_type
:
7933 case DW_TAG_structure_type
:
7934 case DW_TAG_union_type
:
7935 this_type
= read_structure_type (die
, cu
);
7937 case DW_TAG_enumeration_type
:
7938 this_type
= read_enumeration_type (die
, cu
);
7940 case DW_TAG_subprogram
:
7941 case DW_TAG_subroutine_type
:
7942 this_type
= read_subroutine_type (die
, cu
);
7944 case DW_TAG_array_type
:
7945 this_type
= read_array_type (die
, cu
);
7947 case DW_TAG_set_type
:
7948 this_type
= read_set_type (die
, cu
);
7950 case DW_TAG_pointer_type
:
7951 this_type
= read_tag_pointer_type (die
, cu
);
7953 case DW_TAG_ptr_to_member_type
:
7954 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7956 case DW_TAG_reference_type
:
7957 this_type
= read_tag_reference_type (die
, cu
);
7959 case DW_TAG_const_type
:
7960 this_type
= read_tag_const_type (die
, cu
);
7962 case DW_TAG_volatile_type
:
7963 this_type
= read_tag_volatile_type (die
, cu
);
7965 case DW_TAG_string_type
:
7966 this_type
= read_tag_string_type (die
, cu
);
7968 case DW_TAG_typedef
:
7969 this_type
= read_typedef (die
, cu
);
7971 case DW_TAG_subrange_type
:
7972 this_type
= read_subrange_type (die
, cu
);
7974 case DW_TAG_base_type
:
7975 this_type
= read_base_type (die
, cu
);
7977 case DW_TAG_unspecified_type
:
7978 this_type
= read_unspecified_type (die
, cu
);
7980 case DW_TAG_namespace
:
7981 this_type
= read_namespace_type (die
, cu
);
7984 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7985 dwarf_tag_name (die
->tag
));
7992 /* Return the name of the namespace/class that DIE is defined within,
7993 or "" if we can't tell. The caller should not xfree the result.
7995 For example, if we're within the method foo() in the following
8005 then determine_prefix on foo's die will return "N::C". */
8008 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8010 struct die_info
*parent
, *spec_die
;
8011 struct dwarf2_cu
*spec_cu
;
8012 struct type
*parent_type
;
8014 if (cu
->language
!= language_cplus
8015 && cu
->language
!= language_java
)
8018 /* We have to be careful in the presence of DW_AT_specification.
8019 For example, with GCC 3.4, given the code
8023 // Definition of N::foo.
8027 then we'll have a tree of DIEs like this:
8029 1: DW_TAG_compile_unit
8030 2: DW_TAG_namespace // N
8031 3: DW_TAG_subprogram // declaration of N::foo
8032 4: DW_TAG_subprogram // definition of N::foo
8033 DW_AT_specification // refers to die #3
8035 Thus, when processing die #4, we have to pretend that we're in
8036 the context of its DW_AT_specification, namely the contex of die
8039 spec_die
= die_specification (die
, &spec_cu
);
8040 if (spec_die
== NULL
)
8041 parent
= die
->parent
;
8044 parent
= spec_die
->parent
;
8051 switch (parent
->tag
)
8053 case DW_TAG_namespace
:
8054 parent_type
= read_type_die (parent
, cu
);
8055 /* We give a name to even anonymous namespaces. */
8056 return TYPE_TAG_NAME (parent_type
);
8057 case DW_TAG_class_type
:
8058 case DW_TAG_interface_type
:
8059 case DW_TAG_structure_type
:
8060 case DW_TAG_union_type
:
8061 parent_type
= read_type_die (parent
, cu
);
8062 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8063 return TYPE_TAG_NAME (parent_type
);
8065 /* An anonymous structure is only allowed non-static data
8066 members; no typedefs, no member functions, et cetera.
8067 So it does not need a prefix. */
8070 return determine_prefix (parent
, cu
);
8074 /* Return a newly-allocated string formed by concatenating PREFIX and
8075 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8076 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8077 perform an obconcat, otherwise allocate storage for the result. The CU argument
8078 is used to determine the language and hence, the appropriate separator. */
8080 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8083 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8084 struct dwarf2_cu
*cu
)
8088 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8090 else if (cu
->language
== language_java
)
8102 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8103 strcpy (retval
, prefix
);
8104 strcat (retval
, sep
);
8105 strcat (retval
, suffix
);
8110 /* We have an obstack. */
8111 return obconcat (obs
, prefix
, sep
, suffix
);
8115 /* Return sibling of die, NULL if no sibling. */
8117 static struct die_info
*
8118 sibling_die (struct die_info
*die
)
8120 return die
->sibling
;
8123 /* Get linkage name of a die, return NULL if not found. */
8126 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8128 struct attribute
*attr
;
8130 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8131 if (attr
&& DW_STRING (attr
))
8132 return DW_STRING (attr
);
8133 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8134 if (attr
&& DW_STRING (attr
))
8135 return DW_STRING (attr
);
8139 /* Get name of a die, return NULL if not found. */
8142 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8144 struct attribute
*attr
;
8146 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8147 if (attr
&& DW_STRING (attr
))
8148 return DW_STRING (attr
);
8152 /* Return the die that this die in an extension of, or NULL if there
8153 is none. *EXT_CU is the CU containing DIE on input, and the CU
8154 containing the return value on output. */
8156 static struct die_info
*
8157 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8159 struct attribute
*attr
;
8161 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8165 return follow_die_ref (die
, attr
, ext_cu
);
8168 /* Convert a DIE tag into its string name. */
8171 dwarf_tag_name (unsigned tag
)
8175 case DW_TAG_padding
:
8176 return "DW_TAG_padding";
8177 case DW_TAG_array_type
:
8178 return "DW_TAG_array_type";
8179 case DW_TAG_class_type
:
8180 return "DW_TAG_class_type";
8181 case DW_TAG_entry_point
:
8182 return "DW_TAG_entry_point";
8183 case DW_TAG_enumeration_type
:
8184 return "DW_TAG_enumeration_type";
8185 case DW_TAG_formal_parameter
:
8186 return "DW_TAG_formal_parameter";
8187 case DW_TAG_imported_declaration
:
8188 return "DW_TAG_imported_declaration";
8190 return "DW_TAG_label";
8191 case DW_TAG_lexical_block
:
8192 return "DW_TAG_lexical_block";
8194 return "DW_TAG_member";
8195 case DW_TAG_pointer_type
:
8196 return "DW_TAG_pointer_type";
8197 case DW_TAG_reference_type
:
8198 return "DW_TAG_reference_type";
8199 case DW_TAG_compile_unit
:
8200 return "DW_TAG_compile_unit";
8201 case DW_TAG_string_type
:
8202 return "DW_TAG_string_type";
8203 case DW_TAG_structure_type
:
8204 return "DW_TAG_structure_type";
8205 case DW_TAG_subroutine_type
:
8206 return "DW_TAG_subroutine_type";
8207 case DW_TAG_typedef
:
8208 return "DW_TAG_typedef";
8209 case DW_TAG_union_type
:
8210 return "DW_TAG_union_type";
8211 case DW_TAG_unspecified_parameters
:
8212 return "DW_TAG_unspecified_parameters";
8213 case DW_TAG_variant
:
8214 return "DW_TAG_variant";
8215 case DW_TAG_common_block
:
8216 return "DW_TAG_common_block";
8217 case DW_TAG_common_inclusion
:
8218 return "DW_TAG_common_inclusion";
8219 case DW_TAG_inheritance
:
8220 return "DW_TAG_inheritance";
8221 case DW_TAG_inlined_subroutine
:
8222 return "DW_TAG_inlined_subroutine";
8224 return "DW_TAG_module";
8225 case DW_TAG_ptr_to_member_type
:
8226 return "DW_TAG_ptr_to_member_type";
8227 case DW_TAG_set_type
:
8228 return "DW_TAG_set_type";
8229 case DW_TAG_subrange_type
:
8230 return "DW_TAG_subrange_type";
8231 case DW_TAG_with_stmt
:
8232 return "DW_TAG_with_stmt";
8233 case DW_TAG_access_declaration
:
8234 return "DW_TAG_access_declaration";
8235 case DW_TAG_base_type
:
8236 return "DW_TAG_base_type";
8237 case DW_TAG_catch_block
:
8238 return "DW_TAG_catch_block";
8239 case DW_TAG_const_type
:
8240 return "DW_TAG_const_type";
8241 case DW_TAG_constant
:
8242 return "DW_TAG_constant";
8243 case DW_TAG_enumerator
:
8244 return "DW_TAG_enumerator";
8245 case DW_TAG_file_type
:
8246 return "DW_TAG_file_type";
8248 return "DW_TAG_friend";
8249 case DW_TAG_namelist
:
8250 return "DW_TAG_namelist";
8251 case DW_TAG_namelist_item
:
8252 return "DW_TAG_namelist_item";
8253 case DW_TAG_packed_type
:
8254 return "DW_TAG_packed_type";
8255 case DW_TAG_subprogram
:
8256 return "DW_TAG_subprogram";
8257 case DW_TAG_template_type_param
:
8258 return "DW_TAG_template_type_param";
8259 case DW_TAG_template_value_param
:
8260 return "DW_TAG_template_value_param";
8261 case DW_TAG_thrown_type
:
8262 return "DW_TAG_thrown_type";
8263 case DW_TAG_try_block
:
8264 return "DW_TAG_try_block";
8265 case DW_TAG_variant_part
:
8266 return "DW_TAG_variant_part";
8267 case DW_TAG_variable
:
8268 return "DW_TAG_variable";
8269 case DW_TAG_volatile_type
:
8270 return "DW_TAG_volatile_type";
8271 case DW_TAG_dwarf_procedure
:
8272 return "DW_TAG_dwarf_procedure";
8273 case DW_TAG_restrict_type
:
8274 return "DW_TAG_restrict_type";
8275 case DW_TAG_interface_type
:
8276 return "DW_TAG_interface_type";
8277 case DW_TAG_namespace
:
8278 return "DW_TAG_namespace";
8279 case DW_TAG_imported_module
:
8280 return "DW_TAG_imported_module";
8281 case DW_TAG_unspecified_type
:
8282 return "DW_TAG_unspecified_type";
8283 case DW_TAG_partial_unit
:
8284 return "DW_TAG_partial_unit";
8285 case DW_TAG_imported_unit
:
8286 return "DW_TAG_imported_unit";
8287 case DW_TAG_condition
:
8288 return "DW_TAG_condition";
8289 case DW_TAG_shared_type
:
8290 return "DW_TAG_shared_type";
8291 case DW_TAG_MIPS_loop
:
8292 return "DW_TAG_MIPS_loop";
8293 case DW_TAG_HP_array_descriptor
:
8294 return "DW_TAG_HP_array_descriptor";
8295 case DW_TAG_format_label
:
8296 return "DW_TAG_format_label";
8297 case DW_TAG_function_template
:
8298 return "DW_TAG_function_template";
8299 case DW_TAG_class_template
:
8300 return "DW_TAG_class_template";
8301 case DW_TAG_GNU_BINCL
:
8302 return "DW_TAG_GNU_BINCL";
8303 case DW_TAG_GNU_EINCL
:
8304 return "DW_TAG_GNU_EINCL";
8305 case DW_TAG_upc_shared_type
:
8306 return "DW_TAG_upc_shared_type";
8307 case DW_TAG_upc_strict_type
:
8308 return "DW_TAG_upc_strict_type";
8309 case DW_TAG_upc_relaxed_type
:
8310 return "DW_TAG_upc_relaxed_type";
8311 case DW_TAG_PGI_kanji_type
:
8312 return "DW_TAG_PGI_kanji_type";
8313 case DW_TAG_PGI_interface_block
:
8314 return "DW_TAG_PGI_interface_block";
8316 return "DW_TAG_<unknown>";
8320 /* Convert a DWARF attribute code into its string name. */
8323 dwarf_attr_name (unsigned attr
)
8328 return "DW_AT_sibling";
8329 case DW_AT_location
:
8330 return "DW_AT_location";
8332 return "DW_AT_name";
8333 case DW_AT_ordering
:
8334 return "DW_AT_ordering";
8335 case DW_AT_subscr_data
:
8336 return "DW_AT_subscr_data";
8337 case DW_AT_byte_size
:
8338 return "DW_AT_byte_size";
8339 case DW_AT_bit_offset
:
8340 return "DW_AT_bit_offset";
8341 case DW_AT_bit_size
:
8342 return "DW_AT_bit_size";
8343 case DW_AT_element_list
:
8344 return "DW_AT_element_list";
8345 case DW_AT_stmt_list
:
8346 return "DW_AT_stmt_list";
8348 return "DW_AT_low_pc";
8350 return "DW_AT_high_pc";
8351 case DW_AT_language
:
8352 return "DW_AT_language";
8354 return "DW_AT_member";
8356 return "DW_AT_discr";
8357 case DW_AT_discr_value
:
8358 return "DW_AT_discr_value";
8359 case DW_AT_visibility
:
8360 return "DW_AT_visibility";
8362 return "DW_AT_import";
8363 case DW_AT_string_length
:
8364 return "DW_AT_string_length";
8365 case DW_AT_common_reference
:
8366 return "DW_AT_common_reference";
8367 case DW_AT_comp_dir
:
8368 return "DW_AT_comp_dir";
8369 case DW_AT_const_value
:
8370 return "DW_AT_const_value";
8371 case DW_AT_containing_type
:
8372 return "DW_AT_containing_type";
8373 case DW_AT_default_value
:
8374 return "DW_AT_default_value";
8376 return "DW_AT_inline";
8377 case DW_AT_is_optional
:
8378 return "DW_AT_is_optional";
8379 case DW_AT_lower_bound
:
8380 return "DW_AT_lower_bound";
8381 case DW_AT_producer
:
8382 return "DW_AT_producer";
8383 case DW_AT_prototyped
:
8384 return "DW_AT_prototyped";
8385 case DW_AT_return_addr
:
8386 return "DW_AT_return_addr";
8387 case DW_AT_start_scope
:
8388 return "DW_AT_start_scope";
8389 case DW_AT_bit_stride
:
8390 return "DW_AT_bit_stride";
8391 case DW_AT_upper_bound
:
8392 return "DW_AT_upper_bound";
8393 case DW_AT_abstract_origin
:
8394 return "DW_AT_abstract_origin";
8395 case DW_AT_accessibility
:
8396 return "DW_AT_accessibility";
8397 case DW_AT_address_class
:
8398 return "DW_AT_address_class";
8399 case DW_AT_artificial
:
8400 return "DW_AT_artificial";
8401 case DW_AT_base_types
:
8402 return "DW_AT_base_types";
8403 case DW_AT_calling_convention
:
8404 return "DW_AT_calling_convention";
8406 return "DW_AT_count";
8407 case DW_AT_data_member_location
:
8408 return "DW_AT_data_member_location";
8409 case DW_AT_decl_column
:
8410 return "DW_AT_decl_column";
8411 case DW_AT_decl_file
:
8412 return "DW_AT_decl_file";
8413 case DW_AT_decl_line
:
8414 return "DW_AT_decl_line";
8415 case DW_AT_declaration
:
8416 return "DW_AT_declaration";
8417 case DW_AT_discr_list
:
8418 return "DW_AT_discr_list";
8419 case DW_AT_encoding
:
8420 return "DW_AT_encoding";
8421 case DW_AT_external
:
8422 return "DW_AT_external";
8423 case DW_AT_frame_base
:
8424 return "DW_AT_frame_base";
8426 return "DW_AT_friend";
8427 case DW_AT_identifier_case
:
8428 return "DW_AT_identifier_case";
8429 case DW_AT_macro_info
:
8430 return "DW_AT_macro_info";
8431 case DW_AT_namelist_items
:
8432 return "DW_AT_namelist_items";
8433 case DW_AT_priority
:
8434 return "DW_AT_priority";
8436 return "DW_AT_segment";
8437 case DW_AT_specification
:
8438 return "DW_AT_specification";
8439 case DW_AT_static_link
:
8440 return "DW_AT_static_link";
8442 return "DW_AT_type";
8443 case DW_AT_use_location
:
8444 return "DW_AT_use_location";
8445 case DW_AT_variable_parameter
:
8446 return "DW_AT_variable_parameter";
8447 case DW_AT_virtuality
:
8448 return "DW_AT_virtuality";
8449 case DW_AT_vtable_elem_location
:
8450 return "DW_AT_vtable_elem_location";
8451 /* DWARF 3 values. */
8452 case DW_AT_allocated
:
8453 return "DW_AT_allocated";
8454 case DW_AT_associated
:
8455 return "DW_AT_associated";
8456 case DW_AT_data_location
:
8457 return "DW_AT_data_location";
8458 case DW_AT_byte_stride
:
8459 return "DW_AT_byte_stride";
8460 case DW_AT_entry_pc
:
8461 return "DW_AT_entry_pc";
8462 case DW_AT_use_UTF8
:
8463 return "DW_AT_use_UTF8";
8464 case DW_AT_extension
:
8465 return "DW_AT_extension";
8467 return "DW_AT_ranges";
8468 case DW_AT_trampoline
:
8469 return "DW_AT_trampoline";
8470 case DW_AT_call_column
:
8471 return "DW_AT_call_column";
8472 case DW_AT_call_file
:
8473 return "DW_AT_call_file";
8474 case DW_AT_call_line
:
8475 return "DW_AT_call_line";
8476 case DW_AT_description
:
8477 return "DW_AT_description";
8478 case DW_AT_binary_scale
:
8479 return "DW_AT_binary_scale";
8480 case DW_AT_decimal_scale
:
8481 return "DW_AT_decimal_scale";
8483 return "DW_AT_small";
8484 case DW_AT_decimal_sign
:
8485 return "DW_AT_decimal_sign";
8486 case DW_AT_digit_count
:
8487 return "DW_AT_digit_count";
8488 case DW_AT_picture_string
:
8489 return "DW_AT_picture_string";
8491 return "DW_AT_mutable";
8492 case DW_AT_threads_scaled
:
8493 return "DW_AT_threads_scaled";
8494 case DW_AT_explicit
:
8495 return "DW_AT_explicit";
8496 case DW_AT_object_pointer
:
8497 return "DW_AT_object_pointer";
8498 case DW_AT_endianity
:
8499 return "DW_AT_endianity";
8500 case DW_AT_elemental
:
8501 return "DW_AT_elemental";
8503 return "DW_AT_pure";
8504 case DW_AT_recursive
:
8505 return "DW_AT_recursive";
8506 /* SGI/MIPS extensions. */
8507 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8508 case DW_AT_MIPS_fde
:
8509 return "DW_AT_MIPS_fde";
8511 case DW_AT_MIPS_loop_begin
:
8512 return "DW_AT_MIPS_loop_begin";
8513 case DW_AT_MIPS_tail_loop_begin
:
8514 return "DW_AT_MIPS_tail_loop_begin";
8515 case DW_AT_MIPS_epilog_begin
:
8516 return "DW_AT_MIPS_epilog_begin";
8517 case DW_AT_MIPS_loop_unroll_factor
:
8518 return "DW_AT_MIPS_loop_unroll_factor";
8519 case DW_AT_MIPS_software_pipeline_depth
:
8520 return "DW_AT_MIPS_software_pipeline_depth";
8521 case DW_AT_MIPS_linkage_name
:
8522 return "DW_AT_MIPS_linkage_name";
8523 case DW_AT_MIPS_stride
:
8524 return "DW_AT_MIPS_stride";
8525 case DW_AT_MIPS_abstract_name
:
8526 return "DW_AT_MIPS_abstract_name";
8527 case DW_AT_MIPS_clone_origin
:
8528 return "DW_AT_MIPS_clone_origin";
8529 case DW_AT_MIPS_has_inlines
:
8530 return "DW_AT_MIPS_has_inlines";
8531 /* HP extensions. */
8532 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8533 case DW_AT_HP_block_index
:
8534 return "DW_AT_HP_block_index";
8536 case DW_AT_HP_unmodifiable
:
8537 return "DW_AT_HP_unmodifiable";
8538 case DW_AT_HP_actuals_stmt_list
:
8539 return "DW_AT_HP_actuals_stmt_list";
8540 case DW_AT_HP_proc_per_section
:
8541 return "DW_AT_HP_proc_per_section";
8542 case DW_AT_HP_raw_data_ptr
:
8543 return "DW_AT_HP_raw_data_ptr";
8544 case DW_AT_HP_pass_by_reference
:
8545 return "DW_AT_HP_pass_by_reference";
8546 case DW_AT_HP_opt_level
:
8547 return "DW_AT_HP_opt_level";
8548 case DW_AT_HP_prof_version_id
:
8549 return "DW_AT_HP_prof_version_id";
8550 case DW_AT_HP_opt_flags
:
8551 return "DW_AT_HP_opt_flags";
8552 case DW_AT_HP_cold_region_low_pc
:
8553 return "DW_AT_HP_cold_region_low_pc";
8554 case DW_AT_HP_cold_region_high_pc
:
8555 return "DW_AT_HP_cold_region_high_pc";
8556 case DW_AT_HP_all_variables_modifiable
:
8557 return "DW_AT_HP_all_variables_modifiable";
8558 case DW_AT_HP_linkage_name
:
8559 return "DW_AT_HP_linkage_name";
8560 case DW_AT_HP_prof_flags
:
8561 return "DW_AT_HP_prof_flags";
8562 /* GNU extensions. */
8563 case DW_AT_sf_names
:
8564 return "DW_AT_sf_names";
8565 case DW_AT_src_info
:
8566 return "DW_AT_src_info";
8567 case DW_AT_mac_info
:
8568 return "DW_AT_mac_info";
8569 case DW_AT_src_coords
:
8570 return "DW_AT_src_coords";
8571 case DW_AT_body_begin
:
8572 return "DW_AT_body_begin";
8573 case DW_AT_body_end
:
8574 return "DW_AT_body_end";
8575 case DW_AT_GNU_vector
:
8576 return "DW_AT_GNU_vector";
8577 /* VMS extensions. */
8578 case DW_AT_VMS_rtnbeg_pd_address
:
8579 return "DW_AT_VMS_rtnbeg_pd_address";
8580 /* UPC extension. */
8581 case DW_AT_upc_threads_scaled
:
8582 return "DW_AT_upc_threads_scaled";
8583 /* PGI (STMicroelectronics) extensions. */
8584 case DW_AT_PGI_lbase
:
8585 return "DW_AT_PGI_lbase";
8586 case DW_AT_PGI_soffset
:
8587 return "DW_AT_PGI_soffset";
8588 case DW_AT_PGI_lstride
:
8589 return "DW_AT_PGI_lstride";
8591 return "DW_AT_<unknown>";
8595 /* Convert a DWARF value form code into its string name. */
8598 dwarf_form_name (unsigned form
)
8603 return "DW_FORM_addr";
8604 case DW_FORM_block2
:
8605 return "DW_FORM_block2";
8606 case DW_FORM_block4
:
8607 return "DW_FORM_block4";
8609 return "DW_FORM_data2";
8611 return "DW_FORM_data4";
8613 return "DW_FORM_data8";
8614 case DW_FORM_string
:
8615 return "DW_FORM_string";
8617 return "DW_FORM_block";
8618 case DW_FORM_block1
:
8619 return "DW_FORM_block1";
8621 return "DW_FORM_data1";
8623 return "DW_FORM_flag";
8625 return "DW_FORM_sdata";
8627 return "DW_FORM_strp";
8629 return "DW_FORM_udata";
8630 case DW_FORM_ref_addr
:
8631 return "DW_FORM_ref_addr";
8633 return "DW_FORM_ref1";
8635 return "DW_FORM_ref2";
8637 return "DW_FORM_ref4";
8639 return "DW_FORM_ref8";
8640 case DW_FORM_ref_udata
:
8641 return "DW_FORM_ref_udata";
8642 case DW_FORM_indirect
:
8643 return "DW_FORM_indirect";
8645 return "DW_FORM_<unknown>";
8649 /* Convert a DWARF stack opcode into its string name. */
8652 dwarf_stack_op_name (unsigned op
)
8657 return "DW_OP_addr";
8659 return "DW_OP_deref";
8661 return "DW_OP_const1u";
8663 return "DW_OP_const1s";
8665 return "DW_OP_const2u";
8667 return "DW_OP_const2s";
8669 return "DW_OP_const4u";
8671 return "DW_OP_const4s";
8673 return "DW_OP_const8u";
8675 return "DW_OP_const8s";
8677 return "DW_OP_constu";
8679 return "DW_OP_consts";
8683 return "DW_OP_drop";
8685 return "DW_OP_over";
8687 return "DW_OP_pick";
8689 return "DW_OP_swap";
8693 return "DW_OP_xderef";
8701 return "DW_OP_minus";
8713 return "DW_OP_plus";
8714 case DW_OP_plus_uconst
:
8715 return "DW_OP_plus_uconst";
8721 return "DW_OP_shra";
8739 return "DW_OP_skip";
8741 return "DW_OP_lit0";
8743 return "DW_OP_lit1";
8745 return "DW_OP_lit2";
8747 return "DW_OP_lit3";
8749 return "DW_OP_lit4";
8751 return "DW_OP_lit5";
8753 return "DW_OP_lit6";
8755 return "DW_OP_lit7";
8757 return "DW_OP_lit8";
8759 return "DW_OP_lit9";
8761 return "DW_OP_lit10";
8763 return "DW_OP_lit11";
8765 return "DW_OP_lit12";
8767 return "DW_OP_lit13";
8769 return "DW_OP_lit14";
8771 return "DW_OP_lit15";
8773 return "DW_OP_lit16";
8775 return "DW_OP_lit17";
8777 return "DW_OP_lit18";
8779 return "DW_OP_lit19";
8781 return "DW_OP_lit20";
8783 return "DW_OP_lit21";
8785 return "DW_OP_lit22";
8787 return "DW_OP_lit23";
8789 return "DW_OP_lit24";
8791 return "DW_OP_lit25";
8793 return "DW_OP_lit26";
8795 return "DW_OP_lit27";
8797 return "DW_OP_lit28";
8799 return "DW_OP_lit29";
8801 return "DW_OP_lit30";
8803 return "DW_OP_lit31";
8805 return "DW_OP_reg0";
8807 return "DW_OP_reg1";
8809 return "DW_OP_reg2";
8811 return "DW_OP_reg3";
8813 return "DW_OP_reg4";
8815 return "DW_OP_reg5";
8817 return "DW_OP_reg6";
8819 return "DW_OP_reg7";
8821 return "DW_OP_reg8";
8823 return "DW_OP_reg9";
8825 return "DW_OP_reg10";
8827 return "DW_OP_reg11";
8829 return "DW_OP_reg12";
8831 return "DW_OP_reg13";
8833 return "DW_OP_reg14";
8835 return "DW_OP_reg15";
8837 return "DW_OP_reg16";
8839 return "DW_OP_reg17";
8841 return "DW_OP_reg18";
8843 return "DW_OP_reg19";
8845 return "DW_OP_reg20";
8847 return "DW_OP_reg21";
8849 return "DW_OP_reg22";
8851 return "DW_OP_reg23";
8853 return "DW_OP_reg24";
8855 return "DW_OP_reg25";
8857 return "DW_OP_reg26";
8859 return "DW_OP_reg27";
8861 return "DW_OP_reg28";
8863 return "DW_OP_reg29";
8865 return "DW_OP_reg30";
8867 return "DW_OP_reg31";
8869 return "DW_OP_breg0";
8871 return "DW_OP_breg1";
8873 return "DW_OP_breg2";
8875 return "DW_OP_breg3";
8877 return "DW_OP_breg4";
8879 return "DW_OP_breg5";
8881 return "DW_OP_breg6";
8883 return "DW_OP_breg7";
8885 return "DW_OP_breg8";
8887 return "DW_OP_breg9";
8889 return "DW_OP_breg10";
8891 return "DW_OP_breg11";
8893 return "DW_OP_breg12";
8895 return "DW_OP_breg13";
8897 return "DW_OP_breg14";
8899 return "DW_OP_breg15";
8901 return "DW_OP_breg16";
8903 return "DW_OP_breg17";
8905 return "DW_OP_breg18";
8907 return "DW_OP_breg19";
8909 return "DW_OP_breg20";
8911 return "DW_OP_breg21";
8913 return "DW_OP_breg22";
8915 return "DW_OP_breg23";
8917 return "DW_OP_breg24";
8919 return "DW_OP_breg25";
8921 return "DW_OP_breg26";
8923 return "DW_OP_breg27";
8925 return "DW_OP_breg28";
8927 return "DW_OP_breg29";
8929 return "DW_OP_breg30";
8931 return "DW_OP_breg31";
8933 return "DW_OP_regx";
8935 return "DW_OP_fbreg";
8937 return "DW_OP_bregx";
8939 return "DW_OP_piece";
8940 case DW_OP_deref_size
:
8941 return "DW_OP_deref_size";
8942 case DW_OP_xderef_size
:
8943 return "DW_OP_xderef_size";
8946 /* DWARF 3 extensions. */
8947 case DW_OP_push_object_address
:
8948 return "DW_OP_push_object_address";
8950 return "DW_OP_call2";
8952 return "DW_OP_call4";
8953 case DW_OP_call_ref
:
8954 return "DW_OP_call_ref";
8955 /* GNU extensions. */
8956 case DW_OP_form_tls_address
:
8957 return "DW_OP_form_tls_address";
8958 case DW_OP_call_frame_cfa
:
8959 return "DW_OP_call_frame_cfa";
8960 case DW_OP_bit_piece
:
8961 return "DW_OP_bit_piece";
8962 case DW_OP_GNU_push_tls_address
:
8963 return "DW_OP_GNU_push_tls_address";
8964 case DW_OP_GNU_uninit
:
8965 return "DW_OP_GNU_uninit";
8966 /* HP extensions. */
8967 case DW_OP_HP_is_value
:
8968 return "DW_OP_HP_is_value";
8969 case DW_OP_HP_fltconst4
:
8970 return "DW_OP_HP_fltconst4";
8971 case DW_OP_HP_fltconst8
:
8972 return "DW_OP_HP_fltconst8";
8973 case DW_OP_HP_mod_range
:
8974 return "DW_OP_HP_mod_range";
8975 case DW_OP_HP_unmod_range
:
8976 return "DW_OP_HP_unmod_range";
8978 return "DW_OP_HP_tls";
8980 return "OP_<unknown>";
8985 dwarf_bool_name (unsigned mybool
)
8993 /* Convert a DWARF type code into its string name. */
8996 dwarf_type_encoding_name (unsigned enc
)
9001 return "DW_ATE_void";
9002 case DW_ATE_address
:
9003 return "DW_ATE_address";
9004 case DW_ATE_boolean
:
9005 return "DW_ATE_boolean";
9006 case DW_ATE_complex_float
:
9007 return "DW_ATE_complex_float";
9009 return "DW_ATE_float";
9011 return "DW_ATE_signed";
9012 case DW_ATE_signed_char
:
9013 return "DW_ATE_signed_char";
9014 case DW_ATE_unsigned
:
9015 return "DW_ATE_unsigned";
9016 case DW_ATE_unsigned_char
:
9017 return "DW_ATE_unsigned_char";
9019 case DW_ATE_imaginary_float
:
9020 return "DW_ATE_imaginary_float";
9021 case DW_ATE_packed_decimal
:
9022 return "DW_ATE_packed_decimal";
9023 case DW_ATE_numeric_string
:
9024 return "DW_ATE_numeric_string";
9026 return "DW_ATE_edited";
9027 case DW_ATE_signed_fixed
:
9028 return "DW_ATE_signed_fixed";
9029 case DW_ATE_unsigned_fixed
:
9030 return "DW_ATE_unsigned_fixed";
9031 case DW_ATE_decimal_float
:
9032 return "DW_ATE_decimal_float";
9033 /* HP extensions. */
9034 case DW_ATE_HP_float80
:
9035 return "DW_ATE_HP_float80";
9036 case DW_ATE_HP_complex_float80
:
9037 return "DW_ATE_HP_complex_float80";
9038 case DW_ATE_HP_float128
:
9039 return "DW_ATE_HP_float128";
9040 case DW_ATE_HP_complex_float128
:
9041 return "DW_ATE_HP_complex_float128";
9042 case DW_ATE_HP_floathpintel
:
9043 return "DW_ATE_HP_floathpintel";
9044 case DW_ATE_HP_imaginary_float80
:
9045 return "DW_ATE_HP_imaginary_float80";
9046 case DW_ATE_HP_imaginary_float128
:
9047 return "DW_ATE_HP_imaginary_float128";
9049 return "DW_ATE_<unknown>";
9053 /* Convert a DWARF call frame info operation to its string name. */
9057 dwarf_cfi_name (unsigned cfi_opc
)
9061 case DW_CFA_advance_loc
:
9062 return "DW_CFA_advance_loc";
9064 return "DW_CFA_offset";
9065 case DW_CFA_restore
:
9066 return "DW_CFA_restore";
9068 return "DW_CFA_nop";
9069 case DW_CFA_set_loc
:
9070 return "DW_CFA_set_loc";
9071 case DW_CFA_advance_loc1
:
9072 return "DW_CFA_advance_loc1";
9073 case DW_CFA_advance_loc2
:
9074 return "DW_CFA_advance_loc2";
9075 case DW_CFA_advance_loc4
:
9076 return "DW_CFA_advance_loc4";
9077 case DW_CFA_offset_extended
:
9078 return "DW_CFA_offset_extended";
9079 case DW_CFA_restore_extended
:
9080 return "DW_CFA_restore_extended";
9081 case DW_CFA_undefined
:
9082 return "DW_CFA_undefined";
9083 case DW_CFA_same_value
:
9084 return "DW_CFA_same_value";
9085 case DW_CFA_register
:
9086 return "DW_CFA_register";
9087 case DW_CFA_remember_state
:
9088 return "DW_CFA_remember_state";
9089 case DW_CFA_restore_state
:
9090 return "DW_CFA_restore_state";
9091 case DW_CFA_def_cfa
:
9092 return "DW_CFA_def_cfa";
9093 case DW_CFA_def_cfa_register
:
9094 return "DW_CFA_def_cfa_register";
9095 case DW_CFA_def_cfa_offset
:
9096 return "DW_CFA_def_cfa_offset";
9098 case DW_CFA_def_cfa_expression
:
9099 return "DW_CFA_def_cfa_expression";
9100 case DW_CFA_expression
:
9101 return "DW_CFA_expression";
9102 case DW_CFA_offset_extended_sf
:
9103 return "DW_CFA_offset_extended_sf";
9104 case DW_CFA_def_cfa_sf
:
9105 return "DW_CFA_def_cfa_sf";
9106 case DW_CFA_def_cfa_offset_sf
:
9107 return "DW_CFA_def_cfa_offset_sf";
9108 case DW_CFA_val_offset
:
9109 return "DW_CFA_val_offset";
9110 case DW_CFA_val_offset_sf
:
9111 return "DW_CFA_val_offset_sf";
9112 case DW_CFA_val_expression
:
9113 return "DW_CFA_val_expression";
9114 /* SGI/MIPS specific. */
9115 case DW_CFA_MIPS_advance_loc8
:
9116 return "DW_CFA_MIPS_advance_loc8";
9117 /* GNU extensions. */
9118 case DW_CFA_GNU_window_save
:
9119 return "DW_CFA_GNU_window_save";
9120 case DW_CFA_GNU_args_size
:
9121 return "DW_CFA_GNU_args_size";
9122 case DW_CFA_GNU_negative_offset_extended
:
9123 return "DW_CFA_GNU_negative_offset_extended";
9125 return "DW_CFA_<unknown>";
9131 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9135 print_spaces (indent
, f
);
9136 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9137 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9139 if (die
->parent
!= NULL
)
9141 print_spaces (indent
, f
);
9142 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9143 die
->parent
->offset
);
9146 print_spaces (indent
, f
);
9147 fprintf_unfiltered (f
, " has children: %s\n",
9148 dwarf_bool_name (die
->child
!= NULL
));
9150 print_spaces (indent
, f
);
9151 fprintf_unfiltered (f
, " attributes:\n");
9153 for (i
= 0; i
< die
->num_attrs
; ++i
)
9155 print_spaces (indent
, f
);
9156 fprintf_unfiltered (f
, " %s (%s) ",
9157 dwarf_attr_name (die
->attrs
[i
].name
),
9158 dwarf_form_name (die
->attrs
[i
].form
));
9160 switch (die
->attrs
[i
].form
)
9162 case DW_FORM_ref_addr
:
9164 fprintf_unfiltered (f
, "address: ");
9165 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9167 case DW_FORM_block2
:
9168 case DW_FORM_block4
:
9170 case DW_FORM_block1
:
9171 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9176 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9177 (long) (DW_ADDR (&die
->attrs
[i
])));
9185 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9187 case DW_FORM_string
:
9189 fprintf_unfiltered (f
, "string: \"%s\"",
9190 DW_STRING (&die
->attrs
[i
])
9191 ? DW_STRING (&die
->attrs
[i
]) : "");
9194 if (DW_UNSND (&die
->attrs
[i
]))
9195 fprintf_unfiltered (f
, "flag: TRUE");
9197 fprintf_unfiltered (f
, "flag: FALSE");
9199 case DW_FORM_indirect
:
9200 /* the reader will have reduced the indirect form to
9201 the "base form" so this form should not occur */
9202 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9205 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9206 die
->attrs
[i
].form
);
9209 fprintf_unfiltered (f
, "\n");
9214 dump_die_for_error (struct die_info
*die
)
9216 dump_die_shallow (gdb_stderr
, 0, die
);
9220 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9222 int indent
= level
* 4;
9224 gdb_assert (die
!= NULL
);
9226 if (level
>= max_level
)
9229 dump_die_shallow (f
, indent
, die
);
9231 if (die
->child
!= NULL
)
9233 print_spaces (indent
, f
);
9234 fprintf_unfiltered (f
, " Children:");
9235 if (level
+ 1 < max_level
)
9237 fprintf_unfiltered (f
, "\n");
9238 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9242 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9246 if (die
->sibling
!= NULL
&& level
> 0)
9248 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9252 /* This is called from the pdie macro in gdbinit.in.
9253 It's not static so gcc will keep a copy callable from gdb. */
9256 dump_die (struct die_info
*die
, int max_level
)
9258 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9262 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9266 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9272 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9274 unsigned int result
= 0;
9278 case DW_FORM_ref_addr
:
9283 case DW_FORM_ref_udata
:
9284 result
= DW_ADDR (attr
);
9287 complaint (&symfile_complaints
,
9288 _("unsupported die ref attribute form: '%s'"),
9289 dwarf_form_name (attr
->form
));
9294 /* Return the constant value held by the given attribute. Return -1
9295 if the value held by the attribute is not constant. */
9298 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9300 if (attr
->form
== DW_FORM_sdata
)
9301 return DW_SND (attr
);
9302 else if (attr
->form
== DW_FORM_udata
9303 || attr
->form
== DW_FORM_data1
9304 || attr
->form
== DW_FORM_data2
9305 || attr
->form
== DW_FORM_data4
9306 || attr
->form
== DW_FORM_data8
)
9307 return DW_UNSND (attr
);
9310 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9311 dwarf_form_name (attr
->form
));
9312 return default_value
;
9316 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9317 unit and add it to our queue. */
9320 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9321 struct dwarf2_per_cu_data
*per_cu
)
9323 /* Mark the dependence relation so that we don't flush PER_CU
9325 dwarf2_add_dependence (this_cu
, per_cu
);
9327 /* If it's already on the queue, we have nothing to do. */
9331 /* If the compilation unit is already loaded, just mark it as
9333 if (per_cu
->cu
!= NULL
)
9335 per_cu
->cu
->last_used
= 0;
9339 /* Add it to the queue. */
9340 queue_comp_unit (per_cu
, this_cu
->objfile
);
9343 static struct die_info
*
9344 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9345 struct dwarf2_cu
**ref_cu
)
9347 struct die_info
*die
;
9348 unsigned int offset
;
9349 struct die_info temp_die
;
9350 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9352 offset
= dwarf2_get_ref_die_offset (attr
);
9354 if (! offset_in_cu_p (&cu
->header
, offset
))
9356 struct dwarf2_per_cu_data
*per_cu
;
9357 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9359 /* If necessary, add it to the queue and load its DIEs. */
9360 maybe_queue_comp_unit (cu
, per_cu
);
9362 target_cu
= per_cu
->cu
;
9367 *ref_cu
= target_cu
;
9368 temp_die
.offset
= offset
;
9369 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9373 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9374 "at 0x%lx [in module %s]"),
9375 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9378 /* Decode simple location descriptions.
9379 Given a pointer to a dwarf block that defines a location, compute
9380 the location and return the value.
9382 NOTE drow/2003-11-18: This function is called in two situations
9383 now: for the address of static or global variables (partial symbols
9384 only) and for offsets into structures which are expected to be
9385 (more or less) constant. The partial symbol case should go away,
9386 and only the constant case should remain. That will let this
9387 function complain more accurately. A few special modes are allowed
9388 without complaint for global variables (for instance, global
9389 register values and thread-local values).
9391 A location description containing no operations indicates that the
9392 object is optimized out. The return value is 0 for that case.
9393 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9394 callers will only want a very basic result and this can become a
9397 Note that stack[0] is unused except as a default error return.
9398 Note that stack overflow is not yet handled. */
9401 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9403 struct objfile
*objfile
= cu
->objfile
;
9404 struct comp_unit_head
*cu_header
= &cu
->header
;
9406 int size
= blk
->size
;
9407 gdb_byte
*data
= blk
->data
;
9408 CORE_ADDR stack
[64];
9410 unsigned int bytes_read
, unsnd
;
9454 stack
[++stacki
] = op
- DW_OP_lit0
;
9489 stack
[++stacki
] = op
- DW_OP_reg0
;
9491 dwarf2_complex_location_expr_complaint ();
9495 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9497 stack
[++stacki
] = unsnd
;
9499 dwarf2_complex_location_expr_complaint ();
9503 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9509 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9514 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9519 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9524 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9529 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9534 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9539 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9545 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9550 stack
[stacki
+ 1] = stack
[stacki
];
9555 stack
[stacki
- 1] += stack
[stacki
];
9559 case DW_OP_plus_uconst
:
9560 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9565 stack
[stacki
- 1] -= stack
[stacki
];
9570 /* If we're not the last op, then we definitely can't encode
9571 this using GDB's address_class enum. This is valid for partial
9572 global symbols, although the variable's address will be bogus
9575 dwarf2_complex_location_expr_complaint ();
9578 case DW_OP_GNU_push_tls_address
:
9579 /* The top of the stack has the offset from the beginning
9580 of the thread control block at which the variable is located. */
9581 /* Nothing should follow this operator, so the top of stack would
9583 /* This is valid for partial global symbols, but the variable's
9584 address will be bogus in the psymtab. */
9586 dwarf2_complex_location_expr_complaint ();
9589 case DW_OP_GNU_uninit
:
9593 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9594 dwarf_stack_op_name (op
));
9595 return (stack
[stacki
]);
9598 return (stack
[stacki
]);
9601 /* memory allocation interface */
9603 static struct dwarf_block
*
9604 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9606 struct dwarf_block
*blk
;
9608 blk
= (struct dwarf_block
*)
9609 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9613 static struct abbrev_info
*
9614 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9616 struct abbrev_info
*abbrev
;
9618 abbrev
= (struct abbrev_info
*)
9619 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9620 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9624 static struct die_info
*
9625 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9627 struct die_info
*die
;
9628 size_t size
= sizeof (struct die_info
);
9631 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9633 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9634 memset (die
, 0, sizeof (struct die_info
));
9639 /* Macro support. */
9642 /* Return the full name of file number I in *LH's file name table.
9643 Use COMP_DIR as the name of the current directory of the
9644 compilation. The result is allocated using xmalloc; the caller is
9645 responsible for freeing it. */
9647 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9649 /* Is the file number a valid index into the line header's file name
9650 table? Remember that file numbers start with one, not zero. */
9651 if (1 <= file
&& file
<= lh
->num_file_names
)
9653 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9655 if (IS_ABSOLUTE_PATH (fe
->name
))
9656 return xstrdup (fe
->name
);
9664 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9670 dir_len
= strlen (dir
);
9671 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9672 strcpy (full_name
, dir
);
9673 full_name
[dir_len
] = '/';
9674 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9678 return xstrdup (fe
->name
);
9683 /* The compiler produced a bogus file number. We can at least
9684 record the macro definitions made in the file, even if we
9685 won't be able to find the file by name. */
9687 sprintf (fake_name
, "<bad macro file number %d>", file
);
9689 complaint (&symfile_complaints
,
9690 _("bad file number in macro information (%d)"),
9693 return xstrdup (fake_name
);
9698 static struct macro_source_file
*
9699 macro_start_file (int file
, int line
,
9700 struct macro_source_file
*current_file
,
9701 const char *comp_dir
,
9702 struct line_header
*lh
, struct objfile
*objfile
)
9704 /* The full name of this source file. */
9705 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9707 /* We don't create a macro table for this compilation unit
9708 at all until we actually get a filename. */
9709 if (! pending_macros
)
9710 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9711 objfile
->macro_cache
);
9714 /* If we have no current file, then this must be the start_file
9715 directive for the compilation unit's main source file. */
9716 current_file
= macro_set_main (pending_macros
, full_name
);
9718 current_file
= macro_include (current_file
, line
, full_name
);
9722 return current_file
;
9726 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9727 followed by a null byte. */
9729 copy_string (const char *buf
, int len
)
9731 char *s
= xmalloc (len
+ 1);
9732 memcpy (s
, buf
, len
);
9740 consume_improper_spaces (const char *p
, const char *body
)
9744 complaint (&symfile_complaints
,
9745 _("macro definition contains spaces in formal argument list:\n`%s'"),
9757 parse_macro_definition (struct macro_source_file
*file
, int line
,
9762 /* The body string takes one of two forms. For object-like macro
9763 definitions, it should be:
9765 <macro name> " " <definition>
9767 For function-like macro definitions, it should be:
9769 <macro name> "() " <definition>
9771 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9773 Spaces may appear only where explicitly indicated, and in the
9776 The Dwarf 2 spec says that an object-like macro's name is always
9777 followed by a space, but versions of GCC around March 2002 omit
9778 the space when the macro's definition is the empty string.
9780 The Dwarf 2 spec says that there should be no spaces between the
9781 formal arguments in a function-like macro's formal argument list,
9782 but versions of GCC around March 2002 include spaces after the
9786 /* Find the extent of the macro name. The macro name is terminated
9787 by either a space or null character (for an object-like macro) or
9788 an opening paren (for a function-like macro). */
9789 for (p
= body
; *p
; p
++)
9790 if (*p
== ' ' || *p
== '(')
9793 if (*p
== ' ' || *p
== '\0')
9795 /* It's an object-like macro. */
9796 int name_len
= p
- body
;
9797 char *name
= copy_string (body
, name_len
);
9798 const char *replacement
;
9801 replacement
= body
+ name_len
+ 1;
9804 dwarf2_macro_malformed_definition_complaint (body
);
9805 replacement
= body
+ name_len
;
9808 macro_define_object (file
, line
, name
, replacement
);
9814 /* It's a function-like macro. */
9815 char *name
= copy_string (body
, p
- body
);
9818 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9822 p
= consume_improper_spaces (p
, body
);
9824 /* Parse the formal argument list. */
9825 while (*p
&& *p
!= ')')
9827 /* Find the extent of the current argument name. */
9828 const char *arg_start
= p
;
9830 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9833 if (! *p
|| p
== arg_start
)
9834 dwarf2_macro_malformed_definition_complaint (body
);
9837 /* Make sure argv has room for the new argument. */
9838 if (argc
>= argv_size
)
9841 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9844 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9847 p
= consume_improper_spaces (p
, body
);
9849 /* Consume the comma, if present. */
9854 p
= consume_improper_spaces (p
, body
);
9863 /* Perfectly formed definition, no complaints. */
9864 macro_define_function (file
, line
, name
,
9865 argc
, (const char **) argv
,
9867 else if (*p
== '\0')
9869 /* Complain, but do define it. */
9870 dwarf2_macro_malformed_definition_complaint (body
);
9871 macro_define_function (file
, line
, name
,
9872 argc
, (const char **) argv
,
9876 /* Just complain. */
9877 dwarf2_macro_malformed_definition_complaint (body
);
9880 /* Just complain. */
9881 dwarf2_macro_malformed_definition_complaint (body
);
9887 for (i
= 0; i
< argc
; i
++)
9893 dwarf2_macro_malformed_definition_complaint (body
);
9898 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9899 char *comp_dir
, bfd
*abfd
,
9900 struct dwarf2_cu
*cu
)
9902 gdb_byte
*mac_ptr
, *mac_end
;
9903 struct macro_source_file
*current_file
= 0;
9905 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9907 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9911 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9912 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9913 + dwarf2_per_objfile
->macinfo_size
;
9917 enum dwarf_macinfo_record_type macinfo_type
;
9919 /* Do we at least have room for a macinfo type byte? */
9920 if (mac_ptr
>= mac_end
)
9922 dwarf2_macros_too_long_complaint ();
9926 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9929 switch (macinfo_type
)
9931 /* A zero macinfo type indicates the end of the macro
9936 case DW_MACINFO_define
:
9937 case DW_MACINFO_undef
:
9939 unsigned int bytes_read
;
9943 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9944 mac_ptr
+= bytes_read
;
9945 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9946 mac_ptr
+= bytes_read
;
9949 complaint (&symfile_complaints
,
9950 _("debug info gives macro %s outside of any file: %s"),
9952 DW_MACINFO_define
? "definition" : macinfo_type
==
9953 DW_MACINFO_undef
? "undefinition" :
9954 "something-or-other", body
);
9957 if (macinfo_type
== DW_MACINFO_define
)
9958 parse_macro_definition (current_file
, line
, body
);
9959 else if (macinfo_type
== DW_MACINFO_undef
)
9960 macro_undef (current_file
, line
, body
);
9965 case DW_MACINFO_start_file
:
9967 unsigned int bytes_read
;
9970 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9971 mac_ptr
+= bytes_read
;
9972 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9973 mac_ptr
+= bytes_read
;
9975 current_file
= macro_start_file (file
, line
,
9976 current_file
, comp_dir
,
9981 case DW_MACINFO_end_file
:
9983 complaint (&symfile_complaints
,
9984 _("macro debug info has an unmatched `close_file' directive"));
9987 current_file
= current_file
->included_by
;
9990 enum dwarf_macinfo_record_type next_type
;
9992 /* GCC circa March 2002 doesn't produce the zero
9993 type byte marking the end of the compilation
9994 unit. Complain if it's not there, but exit no
9997 /* Do we at least have room for a macinfo type byte? */
9998 if (mac_ptr
>= mac_end
)
10000 dwarf2_macros_too_long_complaint ();
10004 /* We don't increment mac_ptr here, so this is just
10006 next_type
= read_1_byte (abfd
, mac_ptr
);
10007 if (next_type
!= 0)
10008 complaint (&symfile_complaints
,
10009 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10016 case DW_MACINFO_vendor_ext
:
10018 unsigned int bytes_read
;
10022 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10023 mac_ptr
+= bytes_read
;
10024 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10025 mac_ptr
+= bytes_read
;
10027 /* We don't recognize any vendor extensions. */
10034 /* Check if the attribute's form is a DW_FORM_block*
10035 if so return true else false. */
10037 attr_form_is_block (struct attribute
*attr
)
10039 return (attr
== NULL
? 0 :
10040 attr
->form
== DW_FORM_block1
10041 || attr
->form
== DW_FORM_block2
10042 || attr
->form
== DW_FORM_block4
10043 || attr
->form
== DW_FORM_block
);
10046 /* Return non-zero if ATTR's value is a section offset --- classes
10047 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10048 You may use DW_UNSND (attr) to retrieve such offsets.
10050 Section 7.5.4, "Attribute Encodings", explains that no attribute
10051 may have a value that belongs to more than one of these classes; it
10052 would be ambiguous if we did, because we use the same forms for all
10055 attr_form_is_section_offset (struct attribute
*attr
)
10057 return (attr
->form
== DW_FORM_data4
10058 || attr
->form
== DW_FORM_data8
);
10062 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10063 zero otherwise. When this function returns true, you can apply
10064 dwarf2_get_attr_constant_value to it.
10066 However, note that for some attributes you must check
10067 attr_form_is_section_offset before using this test. DW_FORM_data4
10068 and DW_FORM_data8 are members of both the constant class, and of
10069 the classes that contain offsets into other debug sections
10070 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10071 that, if an attribute's can be either a constant or one of the
10072 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10073 taken as section offsets, not constants. */
10075 attr_form_is_constant (struct attribute
*attr
)
10077 switch (attr
->form
)
10079 case DW_FORM_sdata
:
10080 case DW_FORM_udata
:
10081 case DW_FORM_data1
:
10082 case DW_FORM_data2
:
10083 case DW_FORM_data4
:
10084 case DW_FORM_data8
:
10092 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10093 struct dwarf2_cu
*cu
)
10095 if (attr_form_is_section_offset (attr
)
10096 /* ".debug_loc" may not exist at all, or the offset may be outside
10097 the section. If so, fall through to the complaint in the
10099 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10101 struct dwarf2_loclist_baton
*baton
;
10103 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10104 sizeof (struct dwarf2_loclist_baton
));
10105 baton
->per_cu
= cu
->per_cu
;
10106 gdb_assert (baton
->per_cu
);
10108 /* We don't know how long the location list is, but make sure we
10109 don't run off the edge of the section. */
10110 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10111 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10112 baton
->base_address
= cu
->base_address
;
10113 if (cu
->base_known
== 0)
10114 complaint (&symfile_complaints
,
10115 _("Location list used without specifying the CU base address."));
10117 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10118 SYMBOL_LOCATION_BATON (sym
) = baton
;
10122 struct dwarf2_locexpr_baton
*baton
;
10124 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10125 sizeof (struct dwarf2_locexpr_baton
));
10126 baton
->per_cu
= cu
->per_cu
;
10127 gdb_assert (baton
->per_cu
);
10129 if (attr_form_is_block (attr
))
10131 /* Note that we're just copying the block's data pointer
10132 here, not the actual data. We're still pointing into the
10133 info_buffer for SYM's objfile; right now we never release
10134 that buffer, but when we do clean up properly this may
10136 baton
->size
= DW_BLOCK (attr
)->size
;
10137 baton
->data
= DW_BLOCK (attr
)->data
;
10141 dwarf2_invalid_attrib_class_complaint ("location description",
10142 SYMBOL_NATURAL_NAME (sym
));
10144 baton
->data
= NULL
;
10147 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10148 SYMBOL_LOCATION_BATON (sym
) = baton
;
10152 /* Return the OBJFILE associated with the compilation unit CU. */
10155 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10157 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10159 /* Return the master objfile, so that we can report and look up the
10160 correct file containing this variable. */
10161 if (objfile
->separate_debug_objfile_backlink
)
10162 objfile
= objfile
->separate_debug_objfile_backlink
;
10167 /* Return the address size given in the compilation unit header for CU. */
10170 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10173 return per_cu
->cu
->header
.addr_size
;
10176 /* If the CU is not currently read in, we re-read its header. */
10177 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10178 struct dwarf2_per_objfile
*per_objfile
10179 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10180 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10182 struct comp_unit_head cu_header
;
10183 memset (&cu_header
, 0, sizeof cu_header
);
10184 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10185 return cu_header
.addr_size
;
10189 /* Locate the compilation unit from CU's objfile which contains the
10190 DIE at OFFSET. Raises an error on failure. */
10192 static struct dwarf2_per_cu_data
*
10193 dwarf2_find_containing_comp_unit (unsigned int offset
,
10194 struct objfile
*objfile
)
10196 struct dwarf2_per_cu_data
*this_cu
;
10200 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10203 int mid
= low
+ (high
- low
) / 2;
10204 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10209 gdb_assert (low
== high
);
10210 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10213 error (_("Dwarf Error: could not find partial DIE containing "
10214 "offset 0x%lx [in module %s]"),
10215 (long) offset
, bfd_get_filename (objfile
->obfd
));
10217 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10218 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10222 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10223 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10224 && offset
>= this_cu
->offset
+ this_cu
->length
)
10225 error (_("invalid dwarf2 offset %u"), offset
);
10226 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10231 /* Locate the compilation unit from OBJFILE which is located at exactly
10232 OFFSET. Raises an error on failure. */
10234 static struct dwarf2_per_cu_data
*
10235 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10237 struct dwarf2_per_cu_data
*this_cu
;
10238 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10239 if (this_cu
->offset
!= offset
)
10240 error (_("no compilation unit with offset %u."), offset
);
10244 /* Release one cached compilation unit, CU. We unlink it from the tree
10245 of compilation units, but we don't remove it from the read_in_chain;
10246 the caller is responsible for that. */
10249 free_one_comp_unit (void *data
)
10251 struct dwarf2_cu
*cu
= data
;
10253 if (cu
->per_cu
!= NULL
)
10254 cu
->per_cu
->cu
= NULL
;
10257 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10262 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10263 when we're finished with it. We can't free the pointer itself, but be
10264 sure to unlink it from the cache. Also release any associated storage
10265 and perform cache maintenance.
10267 Only used during partial symbol parsing. */
10270 free_stack_comp_unit (void *data
)
10272 struct dwarf2_cu
*cu
= data
;
10274 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10275 cu
->partial_dies
= NULL
;
10277 if (cu
->per_cu
!= NULL
)
10279 /* This compilation unit is on the stack in our caller, so we
10280 should not xfree it. Just unlink it. */
10281 cu
->per_cu
->cu
= NULL
;
10284 /* If we had a per-cu pointer, then we may have other compilation
10285 units loaded, so age them now. */
10286 age_cached_comp_units ();
10290 /* Free all cached compilation units. */
10293 free_cached_comp_units (void *data
)
10295 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10297 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10298 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10299 while (per_cu
!= NULL
)
10301 struct dwarf2_per_cu_data
*next_cu
;
10303 next_cu
= per_cu
->cu
->read_in_chain
;
10305 free_one_comp_unit (per_cu
->cu
);
10306 *last_chain
= next_cu
;
10312 /* Increase the age counter on each cached compilation unit, and free
10313 any that are too old. */
10316 age_cached_comp_units (void)
10318 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10320 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10321 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10322 while (per_cu
!= NULL
)
10324 per_cu
->cu
->last_used
++;
10325 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10326 dwarf2_mark (per_cu
->cu
);
10327 per_cu
= per_cu
->cu
->read_in_chain
;
10330 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10331 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10332 while (per_cu
!= NULL
)
10334 struct dwarf2_per_cu_data
*next_cu
;
10336 next_cu
= per_cu
->cu
->read_in_chain
;
10338 if (!per_cu
->cu
->mark
)
10340 free_one_comp_unit (per_cu
->cu
);
10341 *last_chain
= next_cu
;
10344 last_chain
= &per_cu
->cu
->read_in_chain
;
10350 /* Remove a single compilation unit from the cache. */
10353 free_one_cached_comp_unit (void *target_cu
)
10355 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10357 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10358 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10359 while (per_cu
!= NULL
)
10361 struct dwarf2_per_cu_data
*next_cu
;
10363 next_cu
= per_cu
->cu
->read_in_chain
;
10365 if (per_cu
->cu
== target_cu
)
10367 free_one_comp_unit (per_cu
->cu
);
10368 *last_chain
= next_cu
;
10372 last_chain
= &per_cu
->cu
->read_in_chain
;
10378 /* Release all extra memory associated with OBJFILE. */
10381 dwarf2_free_objfile (struct objfile
*objfile
)
10383 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10385 if (dwarf2_per_objfile
== NULL
)
10388 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10389 free_cached_comp_units (NULL
);
10391 /* Everything else should be on the objfile obstack. */
10394 /* A pair of DIE offset and GDB type pointer. We store these
10395 in a hash table separate from the DIEs, and preserve them
10396 when the DIEs are flushed out of cache. */
10398 struct dwarf2_offset_and_type
10400 unsigned int offset
;
10404 /* Hash function for a dwarf2_offset_and_type. */
10407 offset_and_type_hash (const void *item
)
10409 const struct dwarf2_offset_and_type
*ofs
= item
;
10410 return ofs
->offset
;
10413 /* Equality function for a dwarf2_offset_and_type. */
10416 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10418 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10419 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10420 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10423 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10424 table if necessary. For convenience, return TYPE. */
10426 static struct type
*
10427 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10429 struct dwarf2_offset_and_type
**slot
, ofs
;
10431 if (cu
->type_hash
== NULL
)
10433 gdb_assert (cu
->per_cu
!= NULL
);
10434 cu
->per_cu
->type_hash
10435 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10436 offset_and_type_hash
,
10437 offset_and_type_eq
,
10439 &cu
->objfile
->objfile_obstack
,
10440 hashtab_obstack_allocate
,
10441 dummy_obstack_deallocate
);
10442 cu
->type_hash
= cu
->per_cu
->type_hash
;
10445 ofs
.offset
= die
->offset
;
10447 slot
= (struct dwarf2_offset_and_type
**)
10448 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10449 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10454 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10455 not have a saved type. */
10457 static struct type
*
10458 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10460 struct dwarf2_offset_and_type
*slot
, ofs
;
10461 htab_t type_hash
= cu
->type_hash
;
10463 if (type_hash
== NULL
)
10466 ofs
.offset
= die
->offset
;
10467 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10474 /* Set the mark field in CU and in every other compilation unit in the
10475 cache that we must keep because we are keeping CU. */
10477 /* Add a dependence relationship from CU to REF_PER_CU. */
10480 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10481 struct dwarf2_per_cu_data
*ref_per_cu
)
10485 if (cu
->dependencies
== NULL
)
10487 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10488 NULL
, &cu
->comp_unit_obstack
,
10489 hashtab_obstack_allocate
,
10490 dummy_obstack_deallocate
);
10492 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10494 *slot
= ref_per_cu
;
10497 /* Set the mark field in CU and in every other compilation unit in the
10498 cache that we must keep because we are keeping CU. */
10501 dwarf2_mark_helper (void **slot
, void *data
)
10503 struct dwarf2_per_cu_data
*per_cu
;
10505 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10506 if (per_cu
->cu
->mark
)
10508 per_cu
->cu
->mark
= 1;
10510 if (per_cu
->cu
->dependencies
!= NULL
)
10511 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10517 dwarf2_mark (struct dwarf2_cu
*cu
)
10522 if (cu
->dependencies
!= NULL
)
10523 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10527 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10531 per_cu
->cu
->mark
= 0;
10532 per_cu
= per_cu
->cu
->read_in_chain
;
10536 /* Trivial hash function for partial_die_info: the hash value of a DIE
10537 is its offset in .debug_info for this objfile. */
10540 partial_die_hash (const void *item
)
10542 const struct partial_die_info
*part_die
= item
;
10543 return part_die
->offset
;
10546 /* Trivial comparison function for partial_die_info structures: two DIEs
10547 are equal if they have the same offset. */
10550 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10552 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10553 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10554 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10557 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10558 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10561 set_dwarf2_cmd (char *args
, int from_tty
)
10563 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10567 show_dwarf2_cmd (char *args
, int from_tty
)
10569 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10572 void _initialize_dwarf2_read (void);
10575 _initialize_dwarf2_read (void)
10577 dwarf2_objfile_data_key
= register_objfile_data ();
10579 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10580 Set DWARF 2 specific variables.\n\
10581 Configure DWARF 2 variables such as the cache size"),
10582 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10583 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10585 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10586 Show DWARF 2 specific variables\n\
10587 Show DWARF 2 variables such as the cache size"),
10588 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10589 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10591 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10592 &dwarf2_max_cache_age
, _("\
10593 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10594 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10595 A higher limit means that cached compilation units will be stored\n\
10596 in memory longer, and more total memory will be used. Zero disables\n\
10597 caching, which can slow down startup."),
10599 show_dwarf2_max_cache_age
,
10600 &set_dwarf2_cmdlist
,
10601 &show_dwarf2_cmdlist
);
10603 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
10604 Set debugging of the dwarf2 DIE reader."), _("\
10605 Show debugging of the dwarf2 DIE reader."), _("\
10606 When enabled (non-zero), DIEs are dumped after they are read in.\n\
10607 The value is the maximum depth to print."),
10610 &setdebuglist
, &showdebuglist
);