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, 2009
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
59 /* A note on memory usage for this file.
61 At the present time, this code reads the debug info sections into
62 the objfile's objfile_obstack. A definite improvement for startup
63 time, on platforms which do not emit relocations for debug
64 sections, would be to use mmap instead. The object's complete
65 debug information is loaded into memory, partly to simplify
66 absolute DIE references.
68 Whether using obstacks or mmap, the sections should remain loaded
69 until the objfile is released, and pointers into the section data
70 can be used for any other data associated to the objfile (symbol
71 names, type names, location expressions to name a few). */
74 /* .debug_info header for a compilation unit
75 Because of alignment constraints, this structure has padding and cannot
76 be mapped directly onto the beginning of the .debug_info section. */
77 typedef struct comp_unit_header
79 unsigned int length
; /* length of the .debug_info
81 unsigned short version
; /* version number -- 2 for DWARF
83 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
84 unsigned char addr_size
; /* byte size of an address -- 4 */
87 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
90 /* .debug_pubnames header
91 Because of alignment constraints, this structure has padding and cannot
92 be mapped directly onto the beginning of the .debug_info section. */
93 typedef struct pubnames_header
95 unsigned int length
; /* length of the .debug_pubnames
97 unsigned char version
; /* version number -- 2 for DWARF
99 unsigned int info_offset
; /* offset into .debug_info section */
100 unsigned int info_size
; /* byte size of .debug_info section
104 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
106 /* .debug_pubnames header
107 Because of alignment constraints, this structure has padding and cannot
108 be mapped directly onto the beginning of the .debug_info section. */
109 typedef struct aranges_header
111 unsigned int length
; /* byte len of the .debug_aranges
113 unsigned short version
; /* version number -- 2 for DWARF
115 unsigned int info_offset
; /* offset into .debug_info section */
116 unsigned char addr_size
; /* byte size of an address */
117 unsigned char seg_size
; /* byte size of segment descriptor */
120 #define _ACTUAL_ARANGES_HEADER_SIZE 12
122 /* .debug_line statement program prologue
123 Because of alignment constraints, this structure has padding and cannot
124 be mapped directly onto the beginning of the .debug_info section. */
125 typedef struct statement_prologue
127 unsigned int total_length
; /* byte length of the statement
129 unsigned short version
; /* version number -- 2 for DWARF
131 unsigned int prologue_length
; /* # bytes between prologue &
133 unsigned char minimum_instruction_length
; /* byte size of
135 unsigned char default_is_stmt
; /* initial value of is_stmt
138 unsigned char line_range
;
139 unsigned char opcode_base
; /* number assigned to first special
141 unsigned char *standard_opcode_lengths
;
145 /* When non-zero, dump DIEs after they are read in. */
146 static int dwarf2_die_debug
= 0;
148 /* When set, the file that we're processing is known to have debugging
149 info for C++ namespaces. GCC 3.3.x did not produce this information,
150 but later versions do. */
152 static int processing_has_namespace_info
;
154 static const struct objfile_data
*dwarf2_objfile_data_key
;
156 struct dwarf2_per_objfile
158 /* Sizes of debugging sections. */
159 unsigned int info_size
;
160 unsigned int abbrev_size
;
161 unsigned int line_size
;
162 unsigned int pubnames_size
;
163 unsigned int aranges_size
;
164 unsigned int loc_size
;
165 unsigned int macinfo_size
;
166 unsigned int str_size
;
167 unsigned int ranges_size
;
168 unsigned int frame_size
;
169 unsigned int eh_frame_size
;
171 /* Loaded data from the sections. */
172 gdb_byte
*info_buffer
;
173 gdb_byte
*abbrev_buffer
;
174 gdb_byte
*line_buffer
;
175 gdb_byte
*str_buffer
;
176 gdb_byte
*macinfo_buffer
;
177 gdb_byte
*ranges_buffer
;
178 gdb_byte
*loc_buffer
;
180 /* A list of all the compilation units. This is used to locate
181 the target compilation unit of a particular reference. */
182 struct dwarf2_per_cu_data
**all_comp_units
;
184 /* The number of compilation units in ALL_COMP_UNITS. */
187 /* A chain of compilation units that are currently read in, so that
188 they can be freed later. */
189 struct dwarf2_per_cu_data
*read_in_chain
;
191 /* A flag indicating wether this objfile has a section loaded at a
193 int has_section_at_zero
;
196 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
198 static asection
*dwarf_info_section
;
199 static asection
*dwarf_abbrev_section
;
200 static asection
*dwarf_line_section
;
201 static asection
*dwarf_pubnames_section
;
202 static asection
*dwarf_aranges_section
;
203 static asection
*dwarf_loc_section
;
204 static asection
*dwarf_macinfo_section
;
205 static asection
*dwarf_str_section
;
206 static asection
*dwarf_ranges_section
;
207 asection
*dwarf_frame_section
;
208 asection
*dwarf_eh_frame_section
;
210 /* names of the debugging sections */
212 /* Note that if the debugging section has been compressed, it might
213 have a name like .zdebug_info. */
215 #define INFO_SECTION "debug_info"
216 #define ABBREV_SECTION "debug_abbrev"
217 #define LINE_SECTION "debug_line"
218 #define PUBNAMES_SECTION "debug_pubnames"
219 #define ARANGES_SECTION "debug_aranges"
220 #define LOC_SECTION "debug_loc"
221 #define MACINFO_SECTION "debug_macinfo"
222 #define STR_SECTION "debug_str"
223 #define RANGES_SECTION "debug_ranges"
224 #define FRAME_SECTION "debug_frame"
225 #define EH_FRAME_SECTION "eh_frame"
227 /* local data types */
229 /* We hold several abbreviation tables in memory at the same time. */
230 #ifndef ABBREV_HASH_SIZE
231 #define ABBREV_HASH_SIZE 121
234 /* The data in a compilation unit header, after target2host
235 translation, looks like this. */
236 struct comp_unit_head
240 unsigned char addr_size
;
241 unsigned char signed_addr_p
;
242 unsigned int abbrev_offset
;
244 /* Size of file offsets; either 4 or 8. */
245 unsigned int offset_size
;
247 /* Size of the length field; either 4 or 12. */
248 unsigned int initial_length_size
;
250 /* Offset to the first byte of this compilation unit header in the
251 .debug_info section, for resolving relative reference dies. */
254 /* Offset to first die in this cu from the start of the cu.
255 This will be the first byte following the compilation unit header. */
256 unsigned int first_die_offset
;
259 /* Internal state when decoding a particular compilation unit. */
262 /* The objfile containing this compilation unit. */
263 struct objfile
*objfile
;
265 /* The header of the compilation unit. */
266 struct comp_unit_head header
;
268 /* Base address of this compilation unit. */
269 CORE_ADDR base_address
;
271 /* Non-zero if base_address has been set. */
274 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
276 /* The language we are debugging. */
277 enum language language
;
278 const struct language_defn
*language_defn
;
280 const char *producer
;
282 /* The generic symbol table building routines have separate lists for
283 file scope symbols and all all other scopes (local scopes). So
284 we need to select the right one to pass to add_symbol_to_list().
285 We do it by keeping a pointer to the correct list in list_in_scope.
287 FIXME: The original dwarf code just treated the file scope as the
288 first local scope, and all other local scopes as nested local
289 scopes, and worked fine. Check to see if we really need to
290 distinguish these in buildsym.c. */
291 struct pending
**list_in_scope
;
293 /* DWARF abbreviation table associated with this compilation unit. */
294 struct abbrev_info
**dwarf2_abbrevs
;
296 /* Storage for the abbrev table. */
297 struct obstack abbrev_obstack
;
299 /* Hash table holding all the loaded partial DIEs. */
302 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
303 unsigned int ranges_offset
;
305 /* Storage for things with the same lifetime as this read-in compilation
306 unit, including partial DIEs. */
307 struct obstack comp_unit_obstack
;
309 /* When multiple dwarf2_cu structures are living in memory, this field
310 chains them all together, so that they can be released efficiently.
311 We will probably also want a generation counter so that most-recently-used
312 compilation units are cached... */
313 struct dwarf2_per_cu_data
*read_in_chain
;
315 /* Backchain to our per_cu entry if the tree has been built. */
316 struct dwarf2_per_cu_data
*per_cu
;
318 /* Pointer to the die -> type map. Although it is stored
319 permanently in per_cu, we copy it here to avoid double
323 /* How many compilation units ago was this CU last referenced? */
326 /* A hash table of die offsets for following references. */
329 /* Full DIEs if read in. */
330 struct die_info
*dies
;
332 /* A set of pointers to dwarf2_per_cu_data objects for compilation
333 units referenced by this one. Only set during full symbol processing;
334 partial symbol tables do not have dependencies. */
337 /* Header data from the line table, during full symbol processing. */
338 struct line_header
*line_header
;
340 /* Mark used when releasing cached dies. */
341 unsigned int mark
: 1;
343 /* This flag will be set if this compilation unit might include
344 inter-compilation-unit references. */
345 unsigned int has_form_ref_addr
: 1;
347 /* This flag will be set if this compilation unit includes any
348 DW_TAG_namespace DIEs. If we know that there are explicit
349 DIEs for namespaces, we don't need to try to infer them
350 from mangled names. */
351 unsigned int has_namespace_info
: 1;
353 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
354 unsigned int has_ranges_offset
: 1;
357 /* Persistent data held for a compilation unit, even when not
358 processing it. We put a pointer to this structure in the
359 read_symtab_private field of the psymtab. If we encounter
360 inter-compilation-unit references, we also maintain a sorted
361 list of all compilation units. */
363 struct dwarf2_per_cu_data
365 /* The start offset and length of this compilation unit. 2**30-1
366 bytes should suffice to store the length of any compilation unit
367 - if it doesn't, GDB will fall over anyway.
368 NOTE: Unlike comp_unit_head.length, this length includes
369 initial_length_size. */
371 unsigned int length
: 30;
373 /* Flag indicating this compilation unit will be read in before
374 any of the current compilation units are processed. */
375 unsigned int queued
: 1;
377 /* This flag will be set if we need to load absolutely all DIEs
378 for this compilation unit, instead of just the ones we think
379 are interesting. It gets set if we look for a DIE in the
380 hash table and don't find it. */
381 unsigned int load_all_dies
: 1;
383 /* Set iff currently read in. */
384 struct dwarf2_cu
*cu
;
386 /* If full symbols for this CU have been read in, then this field
387 holds a map of DIE offsets to types. It isn't always possible
388 to reconstruct this information later, so we have to preserve
392 /* The partial symbol table associated with this compilation unit,
393 or NULL for partial units (which do not have an associated
395 struct partial_symtab
*psymtab
;
398 /* The line number information for a compilation unit (found in the
399 .debug_line section) begins with a "statement program header",
400 which contains the following information. */
403 unsigned int total_length
;
404 unsigned short version
;
405 unsigned int header_length
;
406 unsigned char minimum_instruction_length
;
407 unsigned char default_is_stmt
;
409 unsigned char line_range
;
410 unsigned char opcode_base
;
412 /* standard_opcode_lengths[i] is the number of operands for the
413 standard opcode whose value is i. This means that
414 standard_opcode_lengths[0] is unused, and the last meaningful
415 element is standard_opcode_lengths[opcode_base - 1]. */
416 unsigned char *standard_opcode_lengths
;
418 /* The include_directories table. NOTE! These strings are not
419 allocated with xmalloc; instead, they are pointers into
420 debug_line_buffer. If you try to free them, `free' will get
422 unsigned int num_include_dirs
, include_dirs_size
;
425 /* The file_names table. NOTE! These strings are not allocated
426 with xmalloc; instead, they are pointers into debug_line_buffer.
427 Don't try to free them directly. */
428 unsigned int num_file_names
, file_names_size
;
432 unsigned int dir_index
;
433 unsigned int mod_time
;
435 int included_p
; /* Non-zero if referenced by the Line Number Program. */
436 struct symtab
*symtab
; /* The associated symbol table, if any. */
439 /* The start and end of the statement program following this
440 header. These point into dwarf2_per_objfile->line_buffer. */
441 gdb_byte
*statement_program_start
, *statement_program_end
;
444 /* When we construct a partial symbol table entry we only
445 need this much information. */
446 struct partial_die_info
448 /* Offset of this DIE. */
451 /* DWARF-2 tag for this DIE. */
452 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
454 /* Language code associated with this DIE. This is only used
455 for the compilation unit DIE. */
456 unsigned int language
: 8;
458 /* Assorted flags describing the data found in this DIE. */
459 unsigned int has_children
: 1;
460 unsigned int is_external
: 1;
461 unsigned int is_declaration
: 1;
462 unsigned int has_type
: 1;
463 unsigned int has_specification
: 1;
464 unsigned int has_stmt_list
: 1;
465 unsigned int has_pc_info
: 1;
467 /* Flag set if the SCOPE field of this structure has been
469 unsigned int scope_set
: 1;
471 /* Flag set if the DIE has a byte_size attribute. */
472 unsigned int has_byte_size
: 1;
474 /* The name of this DIE. Normally the value of DW_AT_name, but
475 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
480 /* The scope to prepend to our children. This is generally
481 allocated on the comp_unit_obstack, so will disappear
482 when this compilation unit leaves the cache. */
485 /* The location description associated with this DIE, if any. */
486 struct dwarf_block
*locdesc
;
488 /* If HAS_PC_INFO, the PC range associated with this DIE. */
492 /* Pointer into the info_buffer pointing at the target of
493 DW_AT_sibling, if any. */
496 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
497 DW_AT_specification (or DW_AT_abstract_origin or
499 unsigned int spec_offset
;
501 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
502 unsigned int line_offset
;
504 /* Pointers to this DIE's parent, first child, and next sibling,
506 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
509 /* This data structure holds the information of an abbrev. */
512 unsigned int number
; /* number identifying abbrev */
513 enum dwarf_tag tag
; /* dwarf tag */
514 unsigned short has_children
; /* boolean */
515 unsigned short num_attrs
; /* number of attributes */
516 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
517 struct abbrev_info
*next
; /* next in chain */
522 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
523 ENUM_BITFIELD(dwarf_form
) form
: 16;
526 /* Attributes have a name and a value */
529 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
530 ENUM_BITFIELD(dwarf_form
) form
: 16;
534 struct dwarf_block
*blk
;
542 /* This data structure holds a complete die structure. */
545 /* DWARF-2 tag for this DIE. */
546 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
548 /* Number of attributes */
549 unsigned short num_attrs
;
554 /* Offset in .debug_info section */
557 /* The dies in a compilation unit form an n-ary tree. PARENT
558 points to this die's parent; CHILD points to the first child of
559 this node; and all the children of a given node are chained
560 together via their SIBLING fields, terminated by a die whose
562 struct die_info
*child
; /* Its first child, if any. */
563 struct die_info
*sibling
; /* Its next sibling, if any. */
564 struct die_info
*parent
; /* Its parent, if any. */
566 /* An array of attributes, with NUM_ATTRS elements. There may be
567 zero, but it's not common and zero-sized arrays are not
568 sufficiently portable C. */
569 struct attribute attrs
[1];
572 struct function_range
575 CORE_ADDR lowpc
, highpc
;
577 struct function_range
*next
;
580 /* Get at parts of an attribute structure */
582 #define DW_STRING(attr) ((attr)->u.str)
583 #define DW_UNSND(attr) ((attr)->u.unsnd)
584 #define DW_BLOCK(attr) ((attr)->u.blk)
585 #define DW_SND(attr) ((attr)->u.snd)
586 #define DW_ADDR(attr) ((attr)->u.addr)
588 /* Blocks are a bunch of untyped bytes. */
595 #ifndef ATTR_ALLOC_CHUNK
596 #define ATTR_ALLOC_CHUNK 4
599 /* Allocate fields for structs, unions and enums in this size. */
600 #ifndef DW_FIELD_ALLOC_CHUNK
601 #define DW_FIELD_ALLOC_CHUNK 4
604 /* A zeroed version of a partial die for initialization purposes. */
605 static struct partial_die_info zeroed_partial_die
;
607 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
608 but this would require a corresponding change in unpack_field_as_long
610 static int bits_per_byte
= 8;
612 /* The routines that read and process dies for a C struct or C++ class
613 pass lists of data member fields and lists of member function fields
614 in an instance of a field_info structure, as defined below. */
617 /* List of data member and baseclasses fields. */
620 struct nextfield
*next
;
627 /* Number of fields. */
630 /* Number of baseclasses. */
633 /* Set if the accesibility of one of the fields is not public. */
634 int non_public_fields
;
636 /* Member function fields array, entries are allocated in the order they
637 are encountered in the object file. */
640 struct nextfnfield
*next
;
641 struct fn_field fnfield
;
645 /* Member function fieldlist array, contains name of possibly overloaded
646 member function, number of overloaded member functions and a pointer
647 to the head of the member function field chain. */
652 struct nextfnfield
*head
;
656 /* Number of entries in the fnfieldlists array. */
660 /* One item on the queue of compilation units to read in full symbols
662 struct dwarf2_queue_item
664 struct dwarf2_per_cu_data
*per_cu
;
665 struct dwarf2_queue_item
*next
;
668 /* The current queue. */
669 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
671 /* Loaded secondary compilation units are kept in memory until they
672 have not been referenced for the processing of this many
673 compilation units. Set this to zero to disable caching. Cache
674 sizes of up to at least twenty will improve startup time for
675 typical inter-CU-reference binaries, at an obvious memory cost. */
676 static int dwarf2_max_cache_age
= 5;
678 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
679 struct cmd_list_element
*c
, const char *value
)
681 fprintf_filtered (file
, _("\
682 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
687 /* Various complaints about symbol reading that don't abort the process */
690 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
692 complaint (&symfile_complaints
,
693 _("statement list doesn't fit in .debug_line section"));
697 dwarf2_debug_line_missing_file_complaint (void)
699 complaint (&symfile_complaints
,
700 _(".debug_line section has line data without a file"));
704 dwarf2_debug_line_missing_end_sequence_complaint (void)
706 complaint (&symfile_complaints
,
707 _(".debug_line section has line program sequence without an end"));
711 dwarf2_complex_location_expr_complaint (void)
713 complaint (&symfile_complaints
, _("location expression too complex"));
717 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
720 complaint (&symfile_complaints
,
721 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
726 dwarf2_macros_too_long_complaint (void)
728 complaint (&symfile_complaints
,
729 _("macro info runs off end of `.debug_macinfo' section"));
733 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
735 complaint (&symfile_complaints
,
736 _("macro debug info contains a malformed macro definition:\n`%s'"),
741 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
743 complaint (&symfile_complaints
,
744 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
747 /* local function prototypes */
749 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
752 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
755 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
758 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
759 struct partial_die_info
*,
760 struct partial_symtab
*);
762 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
764 static void scan_partial_symbols (struct partial_die_info
*,
765 CORE_ADDR
*, CORE_ADDR
*,
768 static void add_partial_symbol (struct partial_die_info
*,
771 static int pdi_needs_namespace (enum dwarf_tag tag
);
773 static void add_partial_namespace (struct partial_die_info
*pdi
,
774 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
775 struct dwarf2_cu
*cu
);
777 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
778 struct dwarf2_cu
*cu
);
780 static void add_partial_subprogram (struct partial_die_info
*pdi
,
781 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
782 struct dwarf2_cu
*cu
);
784 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
787 struct dwarf2_cu
*cu
);
789 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
791 static void psymtab_to_symtab_1 (struct partial_symtab
*);
793 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
795 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
797 static void dwarf2_free_abbrev_table (void *);
799 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
802 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
805 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
808 static gdb_byte
*read_partial_die (struct partial_die_info
*,
809 struct abbrev_info
*abbrev
, unsigned int,
810 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
812 static struct partial_die_info
*find_partial_die (unsigned int,
815 static void fixup_partial_die (struct partial_die_info
*,
818 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
819 struct dwarf2_cu
*, int *);
821 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
822 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
824 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
825 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
827 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
829 static int read_1_signed_byte (bfd
*, gdb_byte
*);
831 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
833 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
835 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
837 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
840 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
842 static LONGEST read_checked_initial_length_and_offset
843 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
844 unsigned int *, unsigned int *);
846 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
849 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
851 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
853 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
855 static char *read_indirect_string (bfd
*, gdb_byte
*,
856 const struct comp_unit_head
*,
859 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
861 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
863 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
865 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
867 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
870 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
871 struct dwarf2_cu
*cu
);
873 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
875 static struct die_info
*die_specification (struct die_info
*die
,
876 struct dwarf2_cu
**);
878 static void free_line_header (struct line_header
*lh
);
880 static void add_file_name (struct line_header
*, char *, unsigned int,
881 unsigned int, unsigned int);
883 static struct line_header
*(dwarf_decode_line_header
884 (unsigned int offset
,
885 bfd
*abfd
, struct dwarf2_cu
*cu
));
887 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
888 struct dwarf2_cu
*, struct partial_symtab
*);
890 static void dwarf2_start_subfile (char *, char *, char *);
892 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
895 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
898 static void dwarf2_const_value_data (struct attribute
*attr
,
902 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
904 static struct type
*die_containing_type (struct die_info
*,
907 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
909 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
911 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
913 static char *typename_concat (struct obstack
*,
918 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
920 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
922 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
924 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
925 struct dwarf2_cu
*, struct partial_symtab
*);
927 static int dwarf2_get_pc_bounds (struct die_info
*,
928 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
930 static void get_scope_pc_bounds (struct die_info
*,
931 CORE_ADDR
*, CORE_ADDR
*,
934 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
935 CORE_ADDR
, struct dwarf2_cu
*);
937 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
940 static void dwarf2_attach_fields_to_type (struct field_info
*,
941 struct type
*, struct dwarf2_cu
*);
943 static void dwarf2_add_member_fn (struct field_info
*,
944 struct die_info
*, struct type
*,
947 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
948 struct type
*, struct dwarf2_cu
*);
950 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
952 static const char *determine_class_name (struct die_info
*die
,
953 struct dwarf2_cu
*cu
);
955 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
957 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
959 static const char *namespace_name (struct die_info
*die
,
960 int *is_anonymous
, struct dwarf2_cu
*);
962 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
964 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
966 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
969 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
971 static struct die_info
*read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
973 gdb_byte
**new_info_ptr
,
974 struct die_info
*parent
);
976 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
978 gdb_byte
**new_info_ptr
,
979 struct die_info
*parent
);
981 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
983 gdb_byte
**new_info_ptr
,
984 struct die_info
*parent
);
986 static void process_die (struct die_info
*, struct dwarf2_cu
*);
988 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
990 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
992 static struct die_info
*dwarf2_extension (struct die_info
*die
,
993 struct dwarf2_cu
**);
995 static char *dwarf_tag_name (unsigned int);
997 static char *dwarf_attr_name (unsigned int);
999 static char *dwarf_form_name (unsigned int);
1001 static char *dwarf_stack_op_name (unsigned int);
1003 static char *dwarf_bool_name (unsigned int);
1005 static char *dwarf_type_encoding_name (unsigned int);
1008 static char *dwarf_cfi_name (unsigned int);
1011 static struct die_info
*sibling_die (struct die_info
*);
1013 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1015 static void dump_die_for_error (struct die_info
*);
1017 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1020 /*static*/ void dump_die (struct die_info
*, int max_level
);
1022 static void store_in_ref_table (struct die_info
*,
1023 struct dwarf2_cu
*);
1025 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1027 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1029 static struct die_info
*follow_die_ref (struct die_info
*,
1031 struct dwarf2_cu
**);
1033 /* memory allocation interface */
1035 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1037 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1039 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1041 static void initialize_cu_func_list (struct dwarf2_cu
*);
1043 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1044 struct dwarf2_cu
*);
1046 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1047 char *, bfd
*, struct dwarf2_cu
*);
1049 static int attr_form_is_block (struct attribute
*);
1051 static int attr_form_is_section_offset (struct attribute
*);
1053 static int attr_form_is_constant (struct attribute
*);
1055 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1057 struct dwarf2_cu
*cu
);
1059 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1060 struct dwarf2_cu
*cu
);
1062 static void free_stack_comp_unit (void *);
1064 static hashval_t
partial_die_hash (const void *item
);
1066 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1068 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1069 (unsigned int offset
, struct objfile
*objfile
);
1071 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1072 (unsigned int offset
, struct objfile
*objfile
);
1074 static void free_one_comp_unit (void *);
1076 static void free_cached_comp_units (void *);
1078 static void age_cached_comp_units (void);
1080 static void free_one_cached_comp_unit (void *);
1082 static struct type
*set_die_type (struct die_info
*, struct type
*,
1083 struct dwarf2_cu
*);
1085 static void create_all_comp_units (struct objfile
*);
1087 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1090 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1092 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1093 struct dwarf2_per_cu_data
*);
1095 static void dwarf2_mark (struct dwarf2_cu
*);
1097 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1099 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1101 /* Try to locate the sections we need for DWARF 2 debugging
1102 information and return true if we have enough to do something. */
1105 dwarf2_has_info (struct objfile
*objfile
)
1107 struct dwarf2_per_objfile
*data
;
1109 /* Initialize per-objfile state. */
1110 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1111 memset (data
, 0, sizeof (*data
));
1112 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1113 dwarf2_per_objfile
= data
;
1115 dwarf_info_section
= 0;
1116 dwarf_abbrev_section
= 0;
1117 dwarf_line_section
= 0;
1118 dwarf_str_section
= 0;
1119 dwarf_macinfo_section
= 0;
1120 dwarf_frame_section
= 0;
1121 dwarf_eh_frame_section
= 0;
1122 dwarf_ranges_section
= 0;
1123 dwarf_loc_section
= 0;
1125 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1126 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1129 /* When loading sections, we can either look for ".<name>", or for
1130 * ".z<name>", which indicates a compressed section. */
1133 section_is_p (asection
*sectp
, const char *name
)
1135 return ((sectp
->name
[0] == '.'
1136 && strcmp (sectp
->name
+ 1, name
) == 0)
1137 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1138 && strcmp (sectp
->name
+ 2, name
) == 0));
1141 /* This function is mapped across the sections and remembers the
1142 offset and size of each of the debugging sections we are interested
1146 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1148 if (section_is_p (sectp
, INFO_SECTION
))
1150 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1151 dwarf_info_section
= sectp
;
1153 else if (section_is_p (sectp
, ABBREV_SECTION
))
1155 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1156 dwarf_abbrev_section
= sectp
;
1158 else if (section_is_p (sectp
, LINE_SECTION
))
1160 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1161 dwarf_line_section
= sectp
;
1163 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1165 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1166 dwarf_pubnames_section
= sectp
;
1168 else if (section_is_p (sectp
, ARANGES_SECTION
))
1170 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1171 dwarf_aranges_section
= sectp
;
1173 else if (section_is_p (sectp
, LOC_SECTION
))
1175 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1176 dwarf_loc_section
= sectp
;
1178 else if (section_is_p (sectp
, MACINFO_SECTION
))
1180 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1181 dwarf_macinfo_section
= sectp
;
1183 else if (section_is_p (sectp
, STR_SECTION
))
1185 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1186 dwarf_str_section
= sectp
;
1188 else if (section_is_p (sectp
, FRAME_SECTION
))
1190 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1191 dwarf_frame_section
= sectp
;
1193 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1195 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1196 if (aflag
& SEC_HAS_CONTENTS
)
1198 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1199 dwarf_eh_frame_section
= sectp
;
1202 else if (section_is_p (sectp
, RANGES_SECTION
))
1204 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1205 dwarf_ranges_section
= sectp
;
1208 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1209 && bfd_section_vma (abfd
, sectp
) == 0)
1210 dwarf2_per_objfile
->has_section_at_zero
= 1;
1213 /* This function is called after decompressing a section, so
1214 dwarf2_per_objfile can record its new, uncompressed size. */
1217 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1219 if (section_is_p (sectp
, INFO_SECTION
))
1220 dwarf2_per_objfile
->info_size
= new_size
;
1221 else if (section_is_p (sectp
, ABBREV_SECTION
))
1222 dwarf2_per_objfile
->abbrev_size
= new_size
;
1223 else if (section_is_p (sectp
, LINE_SECTION
))
1224 dwarf2_per_objfile
->line_size
= new_size
;
1225 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1226 dwarf2_per_objfile
->pubnames_size
= new_size
;
1227 else if (section_is_p (sectp
, ARANGES_SECTION
))
1228 dwarf2_per_objfile
->aranges_size
= new_size
;
1229 else if (section_is_p (sectp
, LOC_SECTION
))
1230 dwarf2_per_objfile
->loc_size
= new_size
;
1231 else if (section_is_p (sectp
, MACINFO_SECTION
))
1232 dwarf2_per_objfile
->macinfo_size
= new_size
;
1233 else if (section_is_p (sectp
, STR_SECTION
))
1234 dwarf2_per_objfile
->str_size
= new_size
;
1235 else if (section_is_p (sectp
, FRAME_SECTION
))
1236 dwarf2_per_objfile
->frame_size
= new_size
;
1237 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1238 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1239 else if (section_is_p (sectp
, RANGES_SECTION
))
1240 dwarf2_per_objfile
->ranges_size
= new_size
;
1242 internal_error (__FILE__
, __LINE__
,
1243 _("dwarf2_resize_section: missing section_is_p check: %s"),
1247 /* Build a partial symbol table. */
1250 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1252 /* We definitely need the .debug_info and .debug_abbrev sections */
1254 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1255 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1257 if (dwarf_line_section
)
1258 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1260 dwarf2_per_objfile
->line_buffer
= NULL
;
1262 if (dwarf_str_section
)
1263 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1265 dwarf2_per_objfile
->str_buffer
= NULL
;
1267 if (dwarf_macinfo_section
)
1268 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1269 dwarf_macinfo_section
);
1271 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1273 if (dwarf_ranges_section
)
1274 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1276 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1278 if (dwarf_loc_section
)
1279 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1281 dwarf2_per_objfile
->loc_buffer
= NULL
;
1284 || (objfile
->global_psymbols
.size
== 0
1285 && objfile
->static_psymbols
.size
== 0))
1287 init_psymbol_list (objfile
, 1024);
1291 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1293 /* Things are significantly easier if we have .debug_aranges and
1294 .debug_pubnames sections */
1296 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1300 /* only test this case for now */
1302 /* In this case we have to work a bit harder */
1303 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1308 /* Build the partial symbol table from the information in the
1309 .debug_pubnames and .debug_aranges sections. */
1312 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1314 bfd
*abfd
= objfile
->obfd
;
1315 char *aranges_buffer
, *pubnames_buffer
;
1316 char *aranges_ptr
, *pubnames_ptr
;
1317 unsigned int entry_length
, version
, info_offset
, info_size
;
1319 pubnames_buffer
= dwarf2_read_section (objfile
,
1320 dwarf_pubnames_section
);
1321 pubnames_ptr
= pubnames_buffer
;
1322 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1324 unsigned int bytes_read
;
1326 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1327 pubnames_ptr
+= bytes_read
;
1328 version
= read_1_byte (abfd
, pubnames_ptr
);
1330 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1332 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1336 aranges_buffer
= dwarf2_read_section (objfile
,
1337 dwarf_aranges_section
);
1342 /* Return TRUE if OFFSET is within CU_HEADER. */
1345 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1347 unsigned int bottom
= cu_header
->offset
;
1348 unsigned int top
= (cu_header
->offset
1350 + cu_header
->initial_length_size
);
1351 return (offset
>= bottom
&& offset
< top
);
1354 /* Read in the comp unit header information from the debug_info at
1358 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1359 gdb_byte
*info_ptr
, bfd
*abfd
)
1362 unsigned int bytes_read
;
1364 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1365 cu_header
->initial_length_size
= bytes_read
;
1366 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1367 info_ptr
+= bytes_read
;
1368 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1370 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1372 info_ptr
+= bytes_read
;
1373 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1375 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1376 if (signed_addr
< 0)
1377 internal_error (__FILE__
, __LINE__
,
1378 _("read_comp_unit_head: dwarf from non elf file"));
1379 cu_header
->signed_addr_p
= signed_addr
;
1385 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1388 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1390 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1392 if (header
->version
!= 2 && header
->version
!= 3)
1393 error (_("Dwarf Error: wrong version in compilation unit header "
1394 "(is %d, should be %d) [in module %s]"), header
->version
,
1395 2, bfd_get_filename (abfd
));
1397 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1398 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1399 "(offset 0x%lx + 6) [in module %s]"),
1400 (long) header
->abbrev_offset
,
1401 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1402 bfd_get_filename (abfd
));
1404 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1405 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1406 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1407 "(offset 0x%lx + 0) [in module %s]"),
1408 (long) header
->length
,
1409 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1410 bfd_get_filename (abfd
));
1415 /* Allocate a new partial symtab for file named NAME and mark this new
1416 partial symtab as being an include of PST. */
1419 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1420 struct objfile
*objfile
)
1422 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1424 subpst
->section_offsets
= pst
->section_offsets
;
1425 subpst
->textlow
= 0;
1426 subpst
->texthigh
= 0;
1428 subpst
->dependencies
= (struct partial_symtab
**)
1429 obstack_alloc (&objfile
->objfile_obstack
,
1430 sizeof (struct partial_symtab
*));
1431 subpst
->dependencies
[0] = pst
;
1432 subpst
->number_of_dependencies
= 1;
1434 subpst
->globals_offset
= 0;
1435 subpst
->n_global_syms
= 0;
1436 subpst
->statics_offset
= 0;
1437 subpst
->n_static_syms
= 0;
1438 subpst
->symtab
= NULL
;
1439 subpst
->read_symtab
= pst
->read_symtab
;
1442 /* No private part is necessary for include psymtabs. This property
1443 can be used to differentiate between such include psymtabs and
1444 the regular ones. */
1445 subpst
->read_symtab_private
= NULL
;
1448 /* Read the Line Number Program data and extract the list of files
1449 included by the source file represented by PST. Build an include
1450 partial symtab for each of these included files.
1452 This procedure assumes that there *is* a Line Number Program in
1453 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1454 before calling this procedure. */
1457 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1458 struct partial_die_info
*pdi
,
1459 struct partial_symtab
*pst
)
1461 struct objfile
*objfile
= cu
->objfile
;
1462 bfd
*abfd
= objfile
->obfd
;
1463 struct line_header
*lh
;
1465 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1467 return; /* No linetable, so no includes. */
1469 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1471 free_line_header (lh
);
1475 /* Build the partial symbol table by doing a quick pass through the
1476 .debug_info and .debug_abbrev sections. */
1479 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1481 /* Instead of reading this into a big buffer, we should probably use
1482 mmap() on architectures that support it. (FIXME) */
1483 bfd
*abfd
= objfile
->obfd
;
1485 gdb_byte
*beg_of_comp_unit
;
1486 struct partial_die_info comp_unit_die
;
1487 struct partial_symtab
*pst
;
1488 struct cleanup
*back_to
;
1489 CORE_ADDR lowpc
, highpc
, baseaddr
;
1491 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1493 /* Any cached compilation units will be linked by the per-objfile
1494 read_in_chain. Make sure to free them when we're done. */
1495 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1497 create_all_comp_units (objfile
);
1499 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1500 (&objfile
->objfile_obstack
);
1502 /* Since the objects we're extracting from .debug_info vary in
1503 length, only the individual functions to extract them (like
1504 read_comp_unit_head and load_partial_die) can really know whether
1505 the buffer is large enough to hold another complete object.
1507 At the moment, they don't actually check that. If .debug_info
1508 holds just one extra byte after the last compilation unit's dies,
1509 then read_comp_unit_head will happily read off the end of the
1510 buffer. read_partial_die is similarly casual. Those functions
1513 For this loop condition, simply checking whether there's any data
1514 left at all should be sufficient. */
1515 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1516 + dwarf2_per_objfile
->info_size
))
1518 struct cleanup
*back_to_inner
;
1519 struct dwarf2_cu cu
;
1520 struct abbrev_info
*abbrev
;
1521 unsigned int bytes_read
;
1522 struct dwarf2_per_cu_data
*this_cu
;
1524 beg_of_comp_unit
= info_ptr
;
1526 memset (&cu
, 0, sizeof (cu
));
1528 obstack_init (&cu
.comp_unit_obstack
);
1530 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1532 cu
.objfile
= objfile
;
1533 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1535 /* Complete the cu_header */
1536 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1537 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1539 cu
.list_in_scope
= &file_symbols
;
1541 /* Read the abbrevs for this compilation unit into a table */
1542 dwarf2_read_abbrevs (abfd
, &cu
);
1543 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1545 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1547 /* Read the compilation unit die */
1548 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1549 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1550 abfd
, info_ptr
, &cu
);
1552 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1554 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1555 + cu
.header
.initial_length_size
);
1556 do_cleanups (back_to_inner
);
1560 /* Set the language we're debugging */
1561 set_cu_language (comp_unit_die
.language
, &cu
);
1563 /* Allocate a new partial symbol table structure */
1564 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1565 comp_unit_die
.name
? comp_unit_die
.name
: "",
1566 /* TEXTLOW and TEXTHIGH are set below. */
1568 objfile
->global_psymbols
.next
,
1569 objfile
->static_psymbols
.next
);
1571 if (comp_unit_die
.dirname
)
1572 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1573 strlen (comp_unit_die
.dirname
),
1574 &objfile
->objfile_obstack
);
1576 pst
->read_symtab_private
= (char *) this_cu
;
1578 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1580 /* Store the function that reads in the rest of the symbol table */
1581 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1583 /* If this compilation unit was already read in, free the
1584 cached copy in order to read it in again. This is
1585 necessary because we skipped some symbols when we first
1586 read in the compilation unit (see load_partial_dies).
1587 This problem could be avoided, but the benefit is
1589 if (this_cu
->cu
!= NULL
)
1590 free_one_cached_comp_unit (this_cu
->cu
);
1592 cu
.per_cu
= this_cu
;
1594 /* Note that this is a pointer to our stack frame, being
1595 added to a global data structure. It will be cleaned up
1596 in free_stack_comp_unit when we finish with this
1597 compilation unit. */
1600 this_cu
->psymtab
= pst
;
1602 /* Possibly set the default values of LOWPC and HIGHPC from
1604 if (cu
.has_ranges_offset
)
1606 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1607 &comp_unit_die
.highpc
, &cu
, pst
))
1608 comp_unit_die
.has_pc_info
= 1;
1611 /* Check if comp unit has_children.
1612 If so, read the rest of the partial symbols from this comp unit.
1613 If not, there's no more debug_info for this comp unit. */
1614 if (comp_unit_die
.has_children
)
1616 struct partial_die_info
*first_die
;
1618 lowpc
= ((CORE_ADDR
) -1);
1619 highpc
= ((CORE_ADDR
) 0);
1621 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1623 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1625 /* If we didn't find a lowpc, set it to highpc to avoid
1626 complaints from `maint check'. */
1627 if (lowpc
== ((CORE_ADDR
) -1))
1630 /* If the compilation unit didn't have an explicit address range,
1631 then use the information extracted from its child dies. */
1632 if (! comp_unit_die
.has_pc_info
)
1634 comp_unit_die
.lowpc
= lowpc
;
1635 comp_unit_die
.highpc
= highpc
;
1638 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1639 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1641 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1642 range can be also empty for CUs with no code. */
1643 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1644 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1645 pst
->texthigh
- 1, pst
);
1647 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1648 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1649 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1650 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1651 sort_pst_symbols (pst
);
1653 /* If there is already a psymtab or symtab for a file of this
1654 name, remove it. (If there is a symtab, more drastic things
1655 also happen.) This happens in VxWorks. */
1656 free_named_symtabs (pst
->filename
);
1658 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1659 + cu
.header
.initial_length_size
;
1661 if (comp_unit_die
.has_stmt_list
)
1663 /* Get the list of files included in the current compilation unit,
1664 and build a psymtab for each of them. */
1665 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1668 do_cleanups (back_to_inner
);
1671 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1672 &objfile
->objfile_obstack
);
1674 do_cleanups (back_to
);
1677 /* Load the DIEs for a secondary CU into memory. */
1680 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1682 bfd
*abfd
= objfile
->obfd
;
1683 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1684 struct partial_die_info comp_unit_die
;
1685 struct dwarf2_cu
*cu
;
1686 struct abbrev_info
*abbrev
;
1687 unsigned int bytes_read
;
1688 struct cleanup
*back_to
;
1690 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1691 beg_of_comp_unit
= info_ptr
;
1693 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1694 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1696 obstack_init (&cu
->comp_unit_obstack
);
1698 cu
->objfile
= objfile
;
1699 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1701 /* Complete the cu_header. */
1702 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1703 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1705 /* Read the abbrevs for this compilation unit into a table. */
1706 dwarf2_read_abbrevs (abfd
, cu
);
1707 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1709 /* Read the compilation unit die. */
1710 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1711 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1712 abfd
, info_ptr
, cu
);
1714 /* Set the language we're debugging. */
1715 set_cu_language (comp_unit_die
.language
, cu
);
1717 /* Link this compilation unit into the compilation unit tree. */
1719 cu
->per_cu
= this_cu
;
1720 cu
->type_hash
= cu
->per_cu
->type_hash
;
1722 /* Check if comp unit has_children.
1723 If so, read the rest of the partial symbols from this comp unit.
1724 If not, there's no more debug_info for this comp unit. */
1725 if (comp_unit_die
.has_children
)
1726 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1728 do_cleanups (back_to
);
1731 /* Create a list of all compilation units in OBJFILE. We do this only
1732 if an inter-comp-unit reference is found; presumably if there is one,
1733 there will be many, and one will occur early in the .debug_info section.
1734 So there's no point in building this list incrementally. */
1737 create_all_comp_units (struct objfile
*objfile
)
1741 struct dwarf2_per_cu_data
**all_comp_units
;
1742 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1746 all_comp_units
= xmalloc (n_allocated
1747 * sizeof (struct dwarf2_per_cu_data
*));
1749 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1751 unsigned int length
, initial_length_size
;
1752 gdb_byte
*beg_of_comp_unit
;
1753 struct dwarf2_per_cu_data
*this_cu
;
1754 unsigned int offset
;
1756 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1758 /* Read just enough information to find out where the next
1759 compilation unit is. */
1760 length
= read_initial_length (objfile
->obfd
, info_ptr
,
1761 &initial_length_size
);
1763 /* Save the compilation unit for later lookup. */
1764 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1765 sizeof (struct dwarf2_per_cu_data
));
1766 memset (this_cu
, 0, sizeof (*this_cu
));
1767 this_cu
->offset
= offset
;
1768 this_cu
->length
= length
+ initial_length_size
;
1770 if (n_comp_units
== n_allocated
)
1773 all_comp_units
= xrealloc (all_comp_units
,
1775 * sizeof (struct dwarf2_per_cu_data
*));
1777 all_comp_units
[n_comp_units
++] = this_cu
;
1779 info_ptr
= info_ptr
+ this_cu
->length
;
1782 dwarf2_per_objfile
->all_comp_units
1783 = obstack_alloc (&objfile
->objfile_obstack
,
1784 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1785 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1786 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1787 xfree (all_comp_units
);
1788 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1791 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1792 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1796 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1797 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1799 struct objfile
*objfile
= cu
->objfile
;
1800 bfd
*abfd
= objfile
->obfd
;
1801 struct partial_die_info
*pdi
;
1803 /* Now, march along the PDI's, descending into ones which have
1804 interesting children but skipping the children of the other ones,
1805 until we reach the end of the compilation unit. */
1811 fixup_partial_die (pdi
, cu
);
1813 /* Anonymous namespaces have no name but have interesting
1814 children, so we need to look at them. Ditto for anonymous
1817 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1818 || pdi
->tag
== DW_TAG_enumeration_type
)
1822 case DW_TAG_subprogram
:
1823 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
1825 case DW_TAG_variable
:
1826 case DW_TAG_typedef
:
1827 case DW_TAG_union_type
:
1828 if (!pdi
->is_declaration
)
1830 add_partial_symbol (pdi
, cu
);
1833 case DW_TAG_class_type
:
1834 case DW_TAG_interface_type
:
1835 case DW_TAG_structure_type
:
1836 if (!pdi
->is_declaration
)
1838 add_partial_symbol (pdi
, cu
);
1841 case DW_TAG_enumeration_type
:
1842 if (!pdi
->is_declaration
)
1843 add_partial_enumeration (pdi
, cu
);
1845 case DW_TAG_base_type
:
1846 case DW_TAG_subrange_type
:
1847 /* File scope base type definitions are added to the partial
1849 add_partial_symbol (pdi
, cu
);
1851 case DW_TAG_namespace
:
1852 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1859 /* If the die has a sibling, skip to the sibling. */
1861 pdi
= pdi
->die_sibling
;
1865 /* Functions used to compute the fully scoped name of a partial DIE.
1867 Normally, this is simple. For C++, the parent DIE's fully scoped
1868 name is concatenated with "::" and the partial DIE's name. For
1869 Java, the same thing occurs except that "." is used instead of "::".
1870 Enumerators are an exception; they use the scope of their parent
1871 enumeration type, i.e. the name of the enumeration type is not
1872 prepended to the enumerator.
1874 There are two complexities. One is DW_AT_specification; in this
1875 case "parent" means the parent of the target of the specification,
1876 instead of the direct parent of the DIE. The other is compilers
1877 which do not emit DW_TAG_namespace; in this case we try to guess
1878 the fully qualified name of structure types from their members'
1879 linkage names. This must be done using the DIE's children rather
1880 than the children of any DW_AT_specification target. We only need
1881 to do this for structures at the top level, i.e. if the target of
1882 any DW_AT_specification (if any; otherwise the DIE itself) does not
1885 /* Compute the scope prefix associated with PDI's parent, in
1886 compilation unit CU. The result will be allocated on CU's
1887 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1888 field. NULL is returned if no prefix is necessary. */
1890 partial_die_parent_scope (struct partial_die_info
*pdi
,
1891 struct dwarf2_cu
*cu
)
1893 char *grandparent_scope
;
1894 struct partial_die_info
*parent
, *real_pdi
;
1896 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1897 then this means the parent of the specification DIE. */
1900 while (real_pdi
->has_specification
)
1901 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1903 parent
= real_pdi
->die_parent
;
1907 if (parent
->scope_set
)
1908 return parent
->scope
;
1910 fixup_partial_die (parent
, cu
);
1912 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1914 if (parent
->tag
== DW_TAG_namespace
1915 || parent
->tag
== DW_TAG_structure_type
1916 || parent
->tag
== DW_TAG_class_type
1917 || parent
->tag
== DW_TAG_interface_type
1918 || parent
->tag
== DW_TAG_union_type
)
1920 if (grandparent_scope
== NULL
)
1921 parent
->scope
= parent
->name
;
1923 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1926 else if (parent
->tag
== DW_TAG_enumeration_type
)
1927 /* Enumerators should not get the name of the enumeration as a prefix. */
1928 parent
->scope
= grandparent_scope
;
1931 /* FIXME drow/2004-04-01: What should we be doing with
1932 function-local names? For partial symbols, we should probably be
1934 complaint (&symfile_complaints
,
1935 _("unhandled containing DIE tag %d for DIE at %d"),
1936 parent
->tag
, pdi
->offset
);
1937 parent
->scope
= grandparent_scope
;
1940 parent
->scope_set
= 1;
1941 return parent
->scope
;
1944 /* Return the fully scoped name associated with PDI, from compilation unit
1945 CU. The result will be allocated with malloc. */
1947 partial_die_full_name (struct partial_die_info
*pdi
,
1948 struct dwarf2_cu
*cu
)
1952 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1953 if (parent_scope
== NULL
)
1956 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1960 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1962 struct objfile
*objfile
= cu
->objfile
;
1964 char *actual_name
= NULL
;
1965 const char *my_prefix
;
1966 const struct partial_symbol
*psym
= NULL
;
1968 int built_actual_name
= 0;
1970 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1972 if (pdi_needs_namespace (pdi
->tag
))
1974 actual_name
= partial_die_full_name (pdi
, cu
);
1976 built_actual_name
= 1;
1979 if (actual_name
== NULL
)
1980 actual_name
= pdi
->name
;
1984 case DW_TAG_subprogram
:
1985 if (pdi
->is_external
|| cu
->language
== language_ada
)
1987 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1988 of the global scope. But in Ada, we want to be able to access
1989 nested procedures globally. So all Ada subprograms are stored
1990 in the global scope. */
1991 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1992 mst_text, objfile); */
1993 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1994 VAR_DOMAIN
, LOC_BLOCK
,
1995 &objfile
->global_psymbols
,
1996 0, pdi
->lowpc
+ baseaddr
,
1997 cu
->language
, objfile
);
2001 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2002 mst_file_text, objfile); */
2003 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2004 VAR_DOMAIN
, LOC_BLOCK
,
2005 &objfile
->static_psymbols
,
2006 0, pdi
->lowpc
+ baseaddr
,
2007 cu
->language
, objfile
);
2010 case DW_TAG_variable
:
2011 if (pdi
->is_external
)
2014 Don't enter into the minimal symbol tables as there is
2015 a minimal symbol table entry from the ELF symbols already.
2016 Enter into partial symbol table if it has a location
2017 descriptor or a type.
2018 If the location descriptor is missing, new_symbol will create
2019 a LOC_UNRESOLVED symbol, the address of the variable will then
2020 be determined from the minimal symbol table whenever the variable
2022 The address for the partial symbol table entry is not
2023 used by GDB, but it comes in handy for debugging partial symbol
2027 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2028 if (pdi
->locdesc
|| pdi
->has_type
)
2029 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2030 VAR_DOMAIN
, LOC_STATIC
,
2031 &objfile
->global_psymbols
,
2033 cu
->language
, objfile
);
2037 /* Static Variable. Skip symbols without location descriptors. */
2038 if (pdi
->locdesc
== NULL
)
2040 if (built_actual_name
)
2041 xfree (actual_name
);
2044 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2045 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2046 mst_file_data, objfile); */
2047 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2048 VAR_DOMAIN
, LOC_STATIC
,
2049 &objfile
->static_psymbols
,
2051 cu
->language
, objfile
);
2054 case DW_TAG_typedef
:
2055 case DW_TAG_base_type
:
2056 case DW_TAG_subrange_type
:
2057 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2058 VAR_DOMAIN
, LOC_TYPEDEF
,
2059 &objfile
->static_psymbols
,
2060 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2062 case DW_TAG_namespace
:
2063 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2064 VAR_DOMAIN
, LOC_TYPEDEF
,
2065 &objfile
->global_psymbols
,
2066 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2068 case DW_TAG_class_type
:
2069 case DW_TAG_interface_type
:
2070 case DW_TAG_structure_type
:
2071 case DW_TAG_union_type
:
2072 case DW_TAG_enumeration_type
:
2073 /* Skip external references. The DWARF standard says in the section
2074 about "Structure, Union, and Class Type Entries": "An incomplete
2075 structure, union or class type is represented by a structure,
2076 union or class entry that does not have a byte size attribute
2077 and that has a DW_AT_declaration attribute." */
2078 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2080 if (built_actual_name
)
2081 xfree (actual_name
);
2085 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2086 static vs. global. */
2087 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2088 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2089 (cu
->language
== language_cplus
2090 || cu
->language
== language_java
)
2091 ? &objfile
->global_psymbols
2092 : &objfile
->static_psymbols
,
2093 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2096 case DW_TAG_enumerator
:
2097 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2098 VAR_DOMAIN
, LOC_CONST
,
2099 (cu
->language
== language_cplus
2100 || cu
->language
== language_java
)
2101 ? &objfile
->global_psymbols
2102 : &objfile
->static_psymbols
,
2103 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2109 /* Check to see if we should scan the name for possible namespace
2110 info. Only do this if this is C++, if we don't have namespace
2111 debugging info in the file, if the psym is of an appropriate type
2112 (otherwise we'll have psym == NULL), and if we actually had a
2113 mangled name to begin with. */
2115 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2116 cases which do not set PSYM above? */
2118 if (cu
->language
== language_cplus
2119 && cu
->has_namespace_info
== 0
2121 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2122 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2125 if (built_actual_name
)
2126 xfree (actual_name
);
2129 /* Determine whether a die of type TAG living in a C++ class or
2130 namespace needs to have the name of the scope prepended to the
2131 name listed in the die. */
2134 pdi_needs_namespace (enum dwarf_tag tag
)
2138 case DW_TAG_namespace
:
2139 case DW_TAG_typedef
:
2140 case DW_TAG_class_type
:
2141 case DW_TAG_interface_type
:
2142 case DW_TAG_structure_type
:
2143 case DW_TAG_union_type
:
2144 case DW_TAG_enumeration_type
:
2145 case DW_TAG_enumerator
:
2152 /* Read a partial die corresponding to a namespace; also, add a symbol
2153 corresponding to that namespace to the symbol table. NAMESPACE is
2154 the name of the enclosing namespace. */
2157 add_partial_namespace (struct partial_die_info
*pdi
,
2158 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2159 struct dwarf2_cu
*cu
)
2161 struct objfile
*objfile
= cu
->objfile
;
2163 /* Add a symbol for the namespace. */
2165 add_partial_symbol (pdi
, cu
);
2167 /* Now scan partial symbols in that namespace. */
2169 if (pdi
->has_children
)
2170 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2173 /* Read a partial die corresponding to a subprogram and create a partial
2174 symbol for that subprogram. When the CU language allows it, this
2175 routine also defines a partial symbol for each nested subprogram
2176 that this subprogram contains.
2178 DIE my also be a lexical block, in which case we simply search
2179 recursively for suprograms defined inside that lexical block.
2180 Again, this is only performed when the CU language allows this
2181 type of definitions. */
2184 add_partial_subprogram (struct partial_die_info
*pdi
,
2185 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2186 struct dwarf2_cu
*cu
)
2188 if (pdi
->tag
== DW_TAG_subprogram
)
2190 if (pdi
->has_pc_info
)
2192 if (pdi
->lowpc
< *lowpc
)
2193 *lowpc
= pdi
->lowpc
;
2194 if (pdi
->highpc
> *highpc
)
2195 *highpc
= pdi
->highpc
;
2196 if (!pdi
->is_declaration
)
2197 add_partial_symbol (pdi
, cu
);
2201 if (! pdi
->has_children
)
2204 if (cu
->language
== language_ada
)
2206 pdi
= pdi
->die_child
;
2209 fixup_partial_die (pdi
, cu
);
2210 if (pdi
->tag
== DW_TAG_subprogram
2211 || pdi
->tag
== DW_TAG_lexical_block
)
2212 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
2213 pdi
= pdi
->die_sibling
;
2218 /* See if we can figure out if the class lives in a namespace. We do
2219 this by looking for a member function; its demangled name will
2220 contain namespace info, if there is any. */
2223 guess_structure_name (struct partial_die_info
*struct_pdi
,
2224 struct dwarf2_cu
*cu
)
2226 if ((cu
->language
== language_cplus
2227 || cu
->language
== language_java
)
2228 && cu
->has_namespace_info
== 0
2229 && struct_pdi
->has_children
)
2231 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2232 what template types look like, because the demangler
2233 frequently doesn't give the same name as the debug info. We
2234 could fix this by only using the demangled name to get the
2235 prefix (but see comment in read_structure_type). */
2237 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2238 struct partial_die_info
*real_pdi
;
2240 /* If this DIE (this DIE's specification, if any) has a parent, then
2241 we should not do this. We'll prepend the parent's fully qualified
2242 name when we create the partial symbol. */
2244 real_pdi
= struct_pdi
;
2245 while (real_pdi
->has_specification
)
2246 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2248 if (real_pdi
->die_parent
!= NULL
)
2251 while (child_pdi
!= NULL
)
2253 if (child_pdi
->tag
== DW_TAG_subprogram
)
2255 char *actual_class_name
2256 = language_class_name_from_physname (cu
->language_defn
,
2258 if (actual_class_name
!= NULL
)
2261 = obsavestring (actual_class_name
,
2262 strlen (actual_class_name
),
2263 &cu
->comp_unit_obstack
);
2264 xfree (actual_class_name
);
2269 child_pdi
= child_pdi
->die_sibling
;
2274 /* Read a partial die corresponding to an enumeration type. */
2277 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2278 struct dwarf2_cu
*cu
)
2280 struct objfile
*objfile
= cu
->objfile
;
2281 bfd
*abfd
= objfile
->obfd
;
2282 struct partial_die_info
*pdi
;
2284 if (enum_pdi
->name
!= NULL
)
2285 add_partial_symbol (enum_pdi
, cu
);
2287 pdi
= enum_pdi
->die_child
;
2290 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2291 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2293 add_partial_symbol (pdi
, cu
);
2294 pdi
= pdi
->die_sibling
;
2298 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2299 Return the corresponding abbrev, or NULL if the number is zero (indicating
2300 an empty DIE). In either case *BYTES_READ will be set to the length of
2301 the initial number. */
2303 static struct abbrev_info
*
2304 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2305 struct dwarf2_cu
*cu
)
2307 bfd
*abfd
= cu
->objfile
->obfd
;
2308 unsigned int abbrev_number
;
2309 struct abbrev_info
*abbrev
;
2311 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2313 if (abbrev_number
== 0)
2316 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2319 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2320 bfd_get_filename (abfd
));
2326 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2327 pointer to the end of a series of DIEs, terminated by an empty
2328 DIE. Any children of the skipped DIEs will also be skipped. */
2331 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2333 struct abbrev_info
*abbrev
;
2334 unsigned int bytes_read
;
2338 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2340 return info_ptr
+ bytes_read
;
2342 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2346 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2347 should point just after the initial uleb128 of a DIE, and the
2348 abbrev corresponding to that skipped uleb128 should be passed in
2349 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2353 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2354 struct dwarf2_cu
*cu
)
2356 unsigned int bytes_read
;
2357 struct attribute attr
;
2358 bfd
*abfd
= cu
->objfile
->obfd
;
2359 unsigned int form
, i
;
2361 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2363 /* The only abbrev we care about is DW_AT_sibling. */
2364 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2366 read_attribute (&attr
, &abbrev
->attrs
[i
],
2367 abfd
, info_ptr
, cu
);
2368 if (attr
.form
== DW_FORM_ref_addr
)
2369 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2371 return dwarf2_per_objfile
->info_buffer
2372 + dwarf2_get_ref_die_offset (&attr
);
2375 /* If it isn't DW_AT_sibling, skip this attribute. */
2376 form
= abbrev
->attrs
[i
].form
;
2381 case DW_FORM_ref_addr
:
2382 info_ptr
+= cu
->header
.addr_size
;
2401 case DW_FORM_string
:
2402 read_string (abfd
, info_ptr
, &bytes_read
);
2403 info_ptr
+= bytes_read
;
2406 info_ptr
+= cu
->header
.offset_size
;
2409 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2410 info_ptr
+= bytes_read
;
2412 case DW_FORM_block1
:
2413 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2415 case DW_FORM_block2
:
2416 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2418 case DW_FORM_block4
:
2419 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2423 case DW_FORM_ref_udata
:
2424 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2426 case DW_FORM_indirect
:
2427 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2428 info_ptr
+= bytes_read
;
2429 /* We need to continue parsing from here, so just go back to
2431 goto skip_attribute
;
2434 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2435 dwarf_form_name (form
),
2436 bfd_get_filename (abfd
));
2440 if (abbrev
->has_children
)
2441 return skip_children (info_ptr
, cu
);
2446 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2447 the next DIE after ORIG_PDI. */
2450 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2451 bfd
*abfd
, struct dwarf2_cu
*cu
)
2453 /* Do we know the sibling already? */
2455 if (orig_pdi
->sibling
)
2456 return orig_pdi
->sibling
;
2458 /* Are there any children to deal with? */
2460 if (!orig_pdi
->has_children
)
2463 /* Skip the children the long way. */
2465 return skip_children (info_ptr
, cu
);
2468 /* Expand this partial symbol table into a full symbol table. */
2471 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2473 /* FIXME: This is barely more than a stub. */
2478 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2484 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2485 gdb_flush (gdb_stdout
);
2488 /* Restore our global data. */
2489 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2490 dwarf2_objfile_data_key
);
2492 psymtab_to_symtab_1 (pst
);
2494 /* Finish up the debug error message. */
2496 printf_filtered (_("done.\n"));
2501 /* Add PER_CU to the queue. */
2504 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2506 struct dwarf2_queue_item
*item
;
2509 item
= xmalloc (sizeof (*item
));
2510 item
->per_cu
= per_cu
;
2513 if (dwarf2_queue
== NULL
)
2514 dwarf2_queue
= item
;
2516 dwarf2_queue_tail
->next
= item
;
2518 dwarf2_queue_tail
= item
;
2520 /* Either PER_CU is the CU we want to process, or we're following a reference
2521 pointing into PER_CU. Either way, we need its DIEs now. */
2522 load_full_comp_unit (item
->per_cu
, objfile
);
2523 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2524 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2527 /* Process the queue. */
2530 process_queue (struct objfile
*objfile
)
2532 struct dwarf2_queue_item
*item
, *next_item
;
2534 /* The queue starts out with one item, but following a DIE reference
2535 may load a new CU, adding it to the end of the queue. */
2536 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2538 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2539 process_full_comp_unit (item
->per_cu
);
2541 item
->per_cu
->queued
= 0;
2542 next_item
= item
->next
;
2546 dwarf2_queue_tail
= NULL
;
2549 /* Free all allocated queue entries. This function only releases anything if
2550 an error was thrown; if the queue was processed then it would have been
2551 freed as we went along. */
2554 dwarf2_release_queue (void *dummy
)
2556 struct dwarf2_queue_item
*item
, *last
;
2558 item
= dwarf2_queue
;
2561 /* Anything still marked queued is likely to be in an
2562 inconsistent state, so discard it. */
2563 if (item
->per_cu
->queued
)
2565 if (item
->per_cu
->cu
!= NULL
)
2566 free_one_cached_comp_unit (item
->per_cu
->cu
);
2567 item
->per_cu
->queued
= 0;
2575 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2578 /* Read in full symbols for PST, and anything it depends on. */
2581 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2583 struct dwarf2_per_cu_data
*per_cu
;
2584 struct cleanup
*back_to
;
2587 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2588 if (!pst
->dependencies
[i
]->readin
)
2590 /* Inform about additional files that need to be read in. */
2593 /* FIXME: i18n: Need to make this a single string. */
2594 fputs_filtered (" ", gdb_stdout
);
2596 fputs_filtered ("and ", gdb_stdout
);
2598 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2599 wrap_here (""); /* Flush output */
2600 gdb_flush (gdb_stdout
);
2602 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2605 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2609 /* It's an include file, no symbols to read for it.
2610 Everything is in the parent symtab. */
2615 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2617 queue_comp_unit (per_cu
, pst
->objfile
);
2619 process_queue (pst
->objfile
);
2621 /* Age the cache, releasing compilation units that have not
2622 been used recently. */
2623 age_cached_comp_units ();
2625 do_cleanups (back_to
);
2628 /* Load the DIEs associated with PST and PER_CU into memory. */
2630 static struct dwarf2_cu
*
2631 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2633 bfd
*abfd
= objfile
->obfd
;
2634 struct dwarf2_cu
*cu
;
2635 unsigned int offset
;
2637 struct cleanup
*back_to
, *free_cu_cleanup
;
2638 struct attribute
*attr
;
2641 /* Set local variables from the partial symbol table info. */
2642 offset
= per_cu
->offset
;
2644 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2646 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2647 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2649 /* If an error occurs while loading, release our storage. */
2650 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2652 cu
->objfile
= objfile
;
2654 /* read in the comp_unit header */
2655 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2657 /* Read the abbrevs for this compilation unit */
2658 dwarf2_read_abbrevs (abfd
, cu
);
2659 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2661 cu
->header
.offset
= offset
;
2663 cu
->per_cu
= per_cu
;
2665 cu
->type_hash
= per_cu
->type_hash
;
2667 /* We use this obstack for block values in dwarf_alloc_block. */
2668 obstack_init (&cu
->comp_unit_obstack
);
2670 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2672 /* We try not to read any attributes in this function, because not
2673 all objfiles needed for references have been loaded yet, and symbol
2674 table processing isn't initialized. But we have to set the CU language,
2675 or we won't be able to build types correctly. */
2676 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2678 set_cu_language (DW_UNSND (attr
), cu
);
2680 set_cu_language (language_minimal
, cu
);
2682 do_cleanups (back_to
);
2684 /* We've successfully allocated this compilation unit. Let our caller
2685 clean it up when finished with it. */
2686 discard_cleanups (free_cu_cleanup
);
2691 /* Generate full symbol information for PST and CU, whose DIEs have
2692 already been loaded into memory. */
2695 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2697 struct partial_symtab
*pst
= per_cu
->psymtab
;
2698 struct dwarf2_cu
*cu
= per_cu
->cu
;
2699 struct objfile
*objfile
= pst
->objfile
;
2700 bfd
*abfd
= objfile
->obfd
;
2701 CORE_ADDR lowpc
, highpc
;
2702 struct symtab
*symtab
;
2703 struct cleanup
*back_to
;
2704 struct attribute
*attr
;
2707 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2710 back_to
= make_cleanup (really_free_pendings
, NULL
);
2712 cu
->list_in_scope
= &file_symbols
;
2714 /* Find the base address of the compilation unit for range lists and
2715 location lists. It will normally be specified by DW_AT_low_pc.
2716 In DWARF-3 draft 4, the base address could be overridden by
2717 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2718 compilation units with discontinuous ranges. */
2721 cu
->base_address
= 0;
2723 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2726 cu
->base_address
= DW_ADDR (attr
);
2731 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2734 cu
->base_address
= DW_ADDR (attr
);
2739 /* Do line number decoding in read_file_scope () */
2740 process_die (cu
->dies
, cu
);
2742 /* Some compilers don't define a DW_AT_high_pc attribute for the
2743 compilation unit. If the DW_AT_high_pc is missing, synthesize
2744 it, by scanning the DIE's below the compilation unit. */
2745 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2747 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2749 /* Set symtab language to language from DW_AT_language.
2750 If the compilation is from a C file generated by language preprocessors,
2751 do not set the language if it was already deduced by start_subfile. */
2753 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2755 symtab
->language
= cu
->language
;
2757 pst
->symtab
= symtab
;
2760 do_cleanups (back_to
);
2763 /* Process a die and its children. */
2766 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2770 case DW_TAG_padding
:
2772 case DW_TAG_compile_unit
:
2773 read_file_scope (die
, cu
);
2775 case DW_TAG_subprogram
:
2776 read_func_scope (die
, cu
);
2778 case DW_TAG_inlined_subroutine
:
2779 /* FIXME: These are ignored for now.
2780 They could be used to set breakpoints on all inlined instances
2781 of a function and make GDB `next' properly over inlined functions. */
2783 case DW_TAG_lexical_block
:
2784 case DW_TAG_try_block
:
2785 case DW_TAG_catch_block
:
2786 read_lexical_block_scope (die
, cu
);
2788 case DW_TAG_class_type
:
2789 case DW_TAG_interface_type
:
2790 case DW_TAG_structure_type
:
2791 case DW_TAG_union_type
:
2792 process_structure_scope (die
, cu
);
2794 case DW_TAG_enumeration_type
:
2795 process_enumeration_scope (die
, cu
);
2798 /* These dies have a type, but processing them does not create
2799 a symbol or recurse to process the children. Therefore we can
2800 read them on-demand through read_type_die. */
2801 case DW_TAG_subroutine_type
:
2802 case DW_TAG_set_type
:
2803 case DW_TAG_array_type
:
2804 case DW_TAG_pointer_type
:
2805 case DW_TAG_ptr_to_member_type
:
2806 case DW_TAG_reference_type
:
2807 case DW_TAG_string_type
:
2810 case DW_TAG_base_type
:
2811 case DW_TAG_subrange_type
:
2812 /* Add a typedef symbol for the type definition, if it has a
2814 new_symbol (die
, read_type_die (die
, cu
), cu
);
2816 case DW_TAG_common_block
:
2817 read_common_block (die
, cu
);
2819 case DW_TAG_common_inclusion
:
2821 case DW_TAG_namespace
:
2822 processing_has_namespace_info
= 1;
2823 read_namespace (die
, cu
);
2825 case DW_TAG_imported_declaration
:
2826 case DW_TAG_imported_module
:
2827 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2828 information contained in these. DW_TAG_imported_declaration
2829 dies shouldn't have children; DW_TAG_imported_module dies
2830 shouldn't in the C++ case, but conceivably could in the
2832 processing_has_namespace_info
= 1;
2833 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2834 dwarf_tag_name (die
->tag
));
2837 new_symbol (die
, NULL
, cu
);
2842 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2843 If scope qualifiers are appropriate they will be added. The result
2844 will be allocated on the objfile_obstack, or NULL if the DIE does
2848 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2850 struct attribute
*attr
;
2851 char *prefix
, *name
;
2852 struct ui_file
*buf
= NULL
;
2854 name
= dwarf2_name (die
, cu
);
2858 /* These are the only languages we know how to qualify names in. */
2859 if (cu
->language
!= language_cplus
2860 && cu
->language
!= language_java
)
2863 /* If no prefix is necessary for this type of DIE, return the
2864 unqualified name. The other three tags listed could be handled
2865 in pdi_needs_namespace, but that requires broader changes. */
2866 if (!pdi_needs_namespace (die
->tag
)
2867 && die
->tag
!= DW_TAG_subprogram
2868 && die
->tag
!= DW_TAG_variable
2869 && die
->tag
!= DW_TAG_member
)
2872 prefix
= determine_prefix (die
, cu
);
2873 if (*prefix
!= '\0')
2874 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2881 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2883 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2887 free_cu_line_header (void *arg
)
2889 struct dwarf2_cu
*cu
= arg
;
2891 free_line_header (cu
->line_header
);
2892 cu
->line_header
= NULL
;
2896 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2898 struct objfile
*objfile
= cu
->objfile
;
2899 struct comp_unit_head
*cu_header
= &cu
->header
;
2900 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2901 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2902 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2903 struct attribute
*attr
;
2905 char *comp_dir
= NULL
;
2906 struct die_info
*child_die
;
2907 bfd
*abfd
= objfile
->obfd
;
2908 struct line_header
*line_header
= 0;
2911 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2913 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2915 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2916 from finish_block. */
2917 if (lowpc
== ((CORE_ADDR
) -1))
2922 /* Find the filename. Do not use dwarf2_name here, since the filename
2923 is not a source language identifier. */
2924 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2927 name
= DW_STRING (attr
);
2930 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2932 comp_dir
= DW_STRING (attr
);
2933 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2935 comp_dir
= ldirname (name
);
2936 if (comp_dir
!= NULL
)
2937 make_cleanup (xfree
, comp_dir
);
2939 if (comp_dir
!= NULL
)
2941 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2942 directory, get rid of it. */
2943 char *cp
= strchr (comp_dir
, ':');
2945 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2952 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2955 set_cu_language (DW_UNSND (attr
), cu
);
2958 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2960 cu
->producer
= DW_STRING (attr
);
2962 /* We assume that we're processing GCC output. */
2963 processing_gcc_compilation
= 2;
2965 processing_has_namespace_info
= 0;
2967 start_symtab (name
, comp_dir
, lowpc
);
2968 record_debugformat ("DWARF 2");
2969 record_producer (cu
->producer
);
2971 initialize_cu_func_list (cu
);
2973 /* Decode line number information if present. We do this before
2974 processing child DIEs, so that the line header table is available
2975 for DW_AT_decl_file. */
2976 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2979 unsigned int line_offset
= DW_UNSND (attr
);
2980 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2983 cu
->line_header
= line_header
;
2984 make_cleanup (free_cu_line_header
, cu
);
2985 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2989 /* Process all dies in compilation unit. */
2990 if (die
->child
!= NULL
)
2992 child_die
= die
->child
;
2993 while (child_die
&& child_die
->tag
)
2995 process_die (child_die
, cu
);
2996 child_die
= sibling_die (child_die
);
3000 /* Decode macro information, if present. Dwarf 2 macro information
3001 refers to information in the line number info statement program
3002 header, so we can only read it if we've read the header
3004 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3005 if (attr
&& line_header
)
3007 unsigned int macro_offset
= DW_UNSND (attr
);
3008 dwarf_decode_macros (line_header
, macro_offset
,
3009 comp_dir
, abfd
, cu
);
3011 do_cleanups (back_to
);
3015 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3016 struct dwarf2_cu
*cu
)
3018 struct function_range
*thisfn
;
3020 thisfn
= (struct function_range
*)
3021 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3022 thisfn
->name
= name
;
3023 thisfn
->lowpc
= lowpc
;
3024 thisfn
->highpc
= highpc
;
3025 thisfn
->seen_line
= 0;
3026 thisfn
->next
= NULL
;
3028 if (cu
->last_fn
== NULL
)
3029 cu
->first_fn
= thisfn
;
3031 cu
->last_fn
->next
= thisfn
;
3033 cu
->last_fn
= thisfn
;
3037 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3039 struct objfile
*objfile
= cu
->objfile
;
3040 struct context_stack
*new;
3043 struct die_info
*child_die
;
3044 struct attribute
*attr
;
3047 struct block
*block
;
3049 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3051 name
= dwarf2_linkage_name (die
, cu
);
3053 /* Ignore functions with missing or empty names and functions with
3054 missing or invalid low and high pc attributes. */
3055 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3061 /* Record the function range for dwarf_decode_lines. */
3062 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3064 new = push_context (0, lowpc
);
3065 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3067 /* If there is a location expression for DW_AT_frame_base, record
3069 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3071 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3072 expression is being recorded directly in the function's symbol
3073 and not in a separate frame-base object. I guess this hack is
3074 to avoid adding some sort of frame-base adjunct/annex to the
3075 function's symbol :-(. The problem with doing this is that it
3076 results in a function symbol with a location expression that
3077 has nothing to do with the location of the function, ouch! The
3078 relationship should be: a function's symbol has-a frame base; a
3079 frame-base has-a location expression. */
3080 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3082 cu
->list_in_scope
= &local_symbols
;
3084 if (die
->child
!= NULL
)
3086 child_die
= die
->child
;
3087 while (child_die
&& child_die
->tag
)
3089 process_die (child_die
, cu
);
3090 child_die
= sibling_die (child_die
);
3094 new = pop_context ();
3095 /* Make a block for the local symbols within. */
3096 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3097 lowpc
, highpc
, objfile
);
3099 /* For C++, set the block's scope. */
3100 if (cu
->language
== language_cplus
)
3101 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3102 determine_prefix (die
, cu
),
3103 processing_has_namespace_info
);
3105 /* If we have address ranges, record them. */
3106 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3108 /* In C++, we can have functions nested inside functions (e.g., when
3109 a function declares a class that has methods). This means that
3110 when we finish processing a function scope, we may need to go
3111 back to building a containing block's symbol lists. */
3112 local_symbols
= new->locals
;
3113 param_symbols
= new->params
;
3115 /* If we've finished processing a top-level function, subsequent
3116 symbols go in the file symbol list. */
3117 if (outermost_context_p ())
3118 cu
->list_in_scope
= &file_symbols
;
3121 /* Process all the DIES contained within a lexical block scope. Start
3122 a new scope, process the dies, and then close the scope. */
3125 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3127 struct objfile
*objfile
= cu
->objfile
;
3128 struct context_stack
*new;
3129 CORE_ADDR lowpc
, highpc
;
3130 struct die_info
*child_die
;
3133 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3135 /* Ignore blocks with missing or invalid low and high pc attributes. */
3136 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3137 as multiple lexical blocks? Handling children in a sane way would
3138 be nasty. Might be easier to properly extend generic blocks to
3140 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3145 push_context (0, lowpc
);
3146 if (die
->child
!= NULL
)
3148 child_die
= die
->child
;
3149 while (child_die
&& child_die
->tag
)
3151 process_die (child_die
, cu
);
3152 child_die
= sibling_die (child_die
);
3155 new = pop_context ();
3157 if (local_symbols
!= NULL
)
3160 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3163 /* Note that recording ranges after traversing children, as we
3164 do here, means that recording a parent's ranges entails
3165 walking across all its children's ranges as they appear in
3166 the address map, which is quadratic behavior.
3168 It would be nicer to record the parent's ranges before
3169 traversing its children, simply overriding whatever you find
3170 there. But since we don't even decide whether to create a
3171 block until after we've traversed its children, that's hard
3173 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3175 local_symbols
= new->locals
;
3178 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3179 Return 1 if the attributes are present and valid, otherwise, return 0.
3180 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3183 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3184 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3185 struct partial_symtab
*ranges_pst
)
3187 struct objfile
*objfile
= cu
->objfile
;
3188 struct comp_unit_head
*cu_header
= &cu
->header
;
3189 bfd
*obfd
= objfile
->obfd
;
3190 unsigned int addr_size
= cu_header
->addr_size
;
3191 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3192 /* Base address selection entry. */
3203 found_base
= cu
->base_known
;
3204 base
= cu
->base_address
;
3206 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3208 complaint (&symfile_complaints
,
3209 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3213 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3215 /* Read in the largest possible address. */
3216 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3217 if ((marker
& mask
) == mask
)
3219 /* If we found the largest possible address, then
3220 read the base address. */
3221 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3222 buffer
+= 2 * addr_size
;
3223 offset
+= 2 * addr_size
;
3229 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3233 CORE_ADDR range_beginning
, range_end
;
3235 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3236 buffer
+= addr_size
;
3237 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3238 buffer
+= addr_size
;
3239 offset
+= 2 * addr_size
;
3241 /* An end of list marker is a pair of zero addresses. */
3242 if (range_beginning
== 0 && range_end
== 0)
3243 /* Found the end of list entry. */
3246 /* Each base address selection entry is a pair of 2 values.
3247 The first is the largest possible address, the second is
3248 the base address. Check for a base address here. */
3249 if ((range_beginning
& mask
) == mask
)
3251 /* If we found the largest possible address, then
3252 read the base address. */
3253 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3260 /* We have no valid base address for the ranges
3262 complaint (&symfile_complaints
,
3263 _("Invalid .debug_ranges data (no base address)"));
3267 range_beginning
+= base
;
3270 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3271 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3272 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3275 /* FIXME: This is recording everything as a low-high
3276 segment of consecutive addresses. We should have a
3277 data structure for discontiguous block ranges
3281 low
= range_beginning
;
3287 if (range_beginning
< low
)
3288 low
= range_beginning
;
3289 if (range_end
> high
)
3295 /* If the first entry is an end-of-list marker, the range
3296 describes an empty scope, i.e. no instructions. */
3302 *high_return
= high
;
3306 /* Get low and high pc attributes from a die. Return 1 if the attributes
3307 are present and valid, otherwise, return 0. Return -1 if the range is
3308 discontinuous, i.e. derived from DW_AT_ranges information. */
3310 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3311 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3313 struct attribute
*attr
;
3318 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3321 high
= DW_ADDR (attr
);
3322 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3324 low
= DW_ADDR (attr
);
3326 /* Found high w/o low attribute. */
3329 /* Found consecutive range of addresses. */
3334 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3337 /* Value of the DW_AT_ranges attribute is the offset in the
3338 .debug_ranges section. */
3339 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3341 /* Found discontinuous range of addresses. */
3349 /* When using the GNU linker, .gnu.linkonce. sections are used to
3350 eliminate duplicate copies of functions and vtables and such.
3351 The linker will arbitrarily choose one and discard the others.
3352 The AT_*_pc values for such functions refer to local labels in
3353 these sections. If the section from that file was discarded, the
3354 labels are not in the output, so the relocs get a value of 0.
3355 If this is a discarded function, mark the pc bounds as invalid,
3356 so that GDB will ignore it. */
3357 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3365 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3366 its low and high PC addresses. Do nothing if these addresses could not
3367 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3368 and HIGHPC to the high address if greater than HIGHPC. */
3371 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3372 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3373 struct dwarf2_cu
*cu
)
3375 CORE_ADDR low
, high
;
3376 struct die_info
*child
= die
->child
;
3378 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3380 *lowpc
= min (*lowpc
, low
);
3381 *highpc
= max (*highpc
, high
);
3384 /* If the language does not allow nested subprograms (either inside
3385 subprograms or lexical blocks), we're done. */
3386 if (cu
->language
!= language_ada
)
3389 /* Check all the children of the given DIE. If it contains nested
3390 subprograms, then check their pc bounds. Likewise, we need to
3391 check lexical blocks as well, as they may also contain subprogram
3393 while (child
&& child
->tag
)
3395 if (child
->tag
== DW_TAG_subprogram
3396 || child
->tag
== DW_TAG_lexical_block
)
3397 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3398 child
= sibling_die (child
);
3402 /* Get the low and high pc's represented by the scope DIE, and store
3403 them in *LOWPC and *HIGHPC. If the correct values can't be
3404 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3407 get_scope_pc_bounds (struct die_info
*die
,
3408 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3409 struct dwarf2_cu
*cu
)
3411 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3412 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3413 CORE_ADDR current_low
, current_high
;
3415 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3417 best_low
= current_low
;
3418 best_high
= current_high
;
3422 struct die_info
*child
= die
->child
;
3424 while (child
&& child
->tag
)
3426 switch (child
->tag
) {
3427 case DW_TAG_subprogram
:
3428 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3430 case DW_TAG_namespace
:
3431 /* FIXME: carlton/2004-01-16: Should we do this for
3432 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3433 that current GCC's always emit the DIEs corresponding
3434 to definitions of methods of classes as children of a
3435 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3436 the DIEs giving the declarations, which could be
3437 anywhere). But I don't see any reason why the
3438 standards says that they have to be there. */
3439 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3441 if (current_low
!= ((CORE_ADDR
) -1))
3443 best_low
= min (best_low
, current_low
);
3444 best_high
= max (best_high
, current_high
);
3452 child
= sibling_die (child
);
3457 *highpc
= best_high
;
3460 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3463 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3464 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3466 struct attribute
*attr
;
3468 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3471 CORE_ADDR high
= DW_ADDR (attr
);
3472 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3475 CORE_ADDR low
= DW_ADDR (attr
);
3476 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3480 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3483 bfd
*obfd
= cu
->objfile
->obfd
;
3485 /* The value of the DW_AT_ranges attribute is the offset of the
3486 address range list in the .debug_ranges section. */
3487 unsigned long offset
= DW_UNSND (attr
);
3488 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3490 /* For some target architectures, but not others, the
3491 read_address function sign-extends the addresses it returns.
3492 To recognize base address selection entries, we need a
3494 unsigned int addr_size
= cu
->header
.addr_size
;
3495 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3497 /* The base address, to which the next pair is relative. Note
3498 that this 'base' is a DWARF concept: most entries in a range
3499 list are relative, to reduce the number of relocs against the
3500 debugging information. This is separate from this function's
3501 'baseaddr' argument, which GDB uses to relocate debugging
3502 information from a shared library based on the address at
3503 which the library was loaded. */
3504 CORE_ADDR base
= cu
->base_address
;
3505 int base_known
= cu
->base_known
;
3507 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3509 complaint (&symfile_complaints
,
3510 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3517 unsigned int bytes_read
;
3518 CORE_ADDR start
, end
;
3520 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3521 buffer
+= bytes_read
;
3522 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3523 buffer
+= bytes_read
;
3525 /* Did we find the end of the range list? */
3526 if (start
== 0 && end
== 0)
3529 /* Did we find a base address selection entry? */
3530 else if ((start
& base_select_mask
) == base_select_mask
)
3536 /* We found an ordinary address range. */
3541 complaint (&symfile_complaints
,
3542 _("Invalid .debug_ranges data (no base address)"));
3546 record_block_range (block
,
3547 baseaddr
+ base
+ start
,
3548 baseaddr
+ base
+ end
- 1);
3554 /* Add an aggregate field to the field list. */
3557 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3558 struct dwarf2_cu
*cu
)
3560 struct objfile
*objfile
= cu
->objfile
;
3561 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3562 struct nextfield
*new_field
;
3563 struct attribute
*attr
;
3565 char *fieldname
= "";
3567 /* Allocate a new field list entry and link it in. */
3568 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3569 make_cleanup (xfree
, new_field
);
3570 memset (new_field
, 0, sizeof (struct nextfield
));
3571 new_field
->next
= fip
->fields
;
3572 fip
->fields
= new_field
;
3575 /* Handle accessibility and virtuality of field.
3576 The default accessibility for members is public, the default
3577 accessibility for inheritance is private. */
3578 if (die
->tag
!= DW_TAG_inheritance
)
3579 new_field
->accessibility
= DW_ACCESS_public
;
3581 new_field
->accessibility
= DW_ACCESS_private
;
3582 new_field
->virtuality
= DW_VIRTUALITY_none
;
3584 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3586 new_field
->accessibility
= DW_UNSND (attr
);
3587 if (new_field
->accessibility
!= DW_ACCESS_public
)
3588 fip
->non_public_fields
= 1;
3589 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3591 new_field
->virtuality
= DW_UNSND (attr
);
3593 fp
= &new_field
->field
;
3595 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3597 /* Data member other than a C++ static data member. */
3599 /* Get type of field. */
3600 fp
->type
= die_type (die
, cu
);
3602 SET_FIELD_BITPOS (*fp
, 0);
3604 /* Get bit size of field (zero if none). */
3605 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3608 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3612 FIELD_BITSIZE (*fp
) = 0;
3615 /* Get bit offset of field. */
3616 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3621 if (attr_form_is_section_offset (attr
))
3623 dwarf2_complex_location_expr_complaint ();
3626 else if (attr_form_is_constant (attr
))
3627 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3629 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3631 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3633 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3636 if (gdbarch_bits_big_endian (gdbarch
))
3638 /* For big endian bits, the DW_AT_bit_offset gives the
3639 additional bit offset from the MSB of the containing
3640 anonymous object to the MSB of the field. We don't
3641 have to do anything special since we don't need to
3642 know the size of the anonymous object. */
3643 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3647 /* For little endian bits, compute the bit offset to the
3648 MSB of the anonymous object, subtract off the number of
3649 bits from the MSB of the field to the MSB of the
3650 object, and then subtract off the number of bits of
3651 the field itself. The result is the bit offset of
3652 the LSB of the field. */
3654 int bit_offset
= DW_UNSND (attr
);
3656 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3659 /* The size of the anonymous object containing
3660 the bit field is explicit, so use the
3661 indicated size (in bytes). */
3662 anonymous_size
= DW_UNSND (attr
);
3666 /* The size of the anonymous object containing
3667 the bit field must be inferred from the type
3668 attribute of the data member containing the
3670 anonymous_size
= TYPE_LENGTH (fp
->type
);
3672 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3673 - bit_offset
- FIELD_BITSIZE (*fp
);
3677 /* Get name of field. */
3678 fieldname
= dwarf2_name (die
, cu
);
3679 if (fieldname
== NULL
)
3682 /* The name is already allocated along with this objfile, so we don't
3683 need to duplicate it for the type. */
3684 fp
->name
= fieldname
;
3686 /* Change accessibility for artificial fields (e.g. virtual table
3687 pointer or virtual base class pointer) to private. */
3688 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3690 new_field
->accessibility
= DW_ACCESS_private
;
3691 fip
->non_public_fields
= 1;
3694 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3696 /* C++ static member. */
3698 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3699 is a declaration, but all versions of G++ as of this writing
3700 (so through at least 3.2.1) incorrectly generate
3701 DW_TAG_variable tags. */
3705 /* Get name of field. */
3706 fieldname
= dwarf2_name (die
, cu
);
3707 if (fieldname
== NULL
)
3710 /* Get physical name. */
3711 physname
= dwarf2_linkage_name (die
, cu
);
3713 /* The name is already allocated along with this objfile, so we don't
3714 need to duplicate it for the type. */
3715 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3716 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3717 FIELD_NAME (*fp
) = fieldname
;
3719 else if (die
->tag
== DW_TAG_inheritance
)
3721 /* C++ base class field. */
3722 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3724 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
3726 FIELD_BITSIZE (*fp
) = 0;
3727 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3728 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3729 fip
->nbaseclasses
++;
3733 /* Create the vector of fields, and attach it to the type. */
3736 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3737 struct dwarf2_cu
*cu
)
3739 int nfields
= fip
->nfields
;
3741 /* Record the field count, allocate space for the array of fields,
3742 and create blank accessibility bitfields if necessary. */
3743 TYPE_NFIELDS (type
) = nfields
;
3744 TYPE_FIELDS (type
) = (struct field
*)
3745 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3746 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3748 if (fip
->non_public_fields
)
3750 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3752 TYPE_FIELD_PRIVATE_BITS (type
) =
3753 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3754 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3756 TYPE_FIELD_PROTECTED_BITS (type
) =
3757 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3758 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3760 TYPE_FIELD_IGNORE_BITS (type
) =
3761 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3762 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3765 /* If the type has baseclasses, allocate and clear a bit vector for
3766 TYPE_FIELD_VIRTUAL_BITS. */
3767 if (fip
->nbaseclasses
)
3769 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3770 unsigned char *pointer
;
3772 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3773 pointer
= TYPE_ALLOC (type
, num_bytes
);
3774 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3775 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3776 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3779 /* Copy the saved-up fields into the field vector. Start from the head
3780 of the list, adding to the tail of the field array, so that they end
3781 up in the same order in the array in which they were added to the list. */
3782 while (nfields
-- > 0)
3784 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3785 switch (fip
->fields
->accessibility
)
3787 case DW_ACCESS_private
:
3788 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3791 case DW_ACCESS_protected
:
3792 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3795 case DW_ACCESS_public
:
3799 /* Unknown accessibility. Complain and treat it as public. */
3801 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3802 fip
->fields
->accessibility
);
3806 if (nfields
< fip
->nbaseclasses
)
3808 switch (fip
->fields
->virtuality
)
3810 case DW_VIRTUALITY_virtual
:
3811 case DW_VIRTUALITY_pure_virtual
:
3812 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3816 fip
->fields
= fip
->fields
->next
;
3820 /* Add a member function to the proper fieldlist. */
3823 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3824 struct type
*type
, struct dwarf2_cu
*cu
)
3826 struct objfile
*objfile
= cu
->objfile
;
3827 struct attribute
*attr
;
3828 struct fnfieldlist
*flp
;
3830 struct fn_field
*fnp
;
3833 struct nextfnfield
*new_fnfield
;
3834 struct type
*this_type
;
3836 /* Get name of member function. */
3837 fieldname
= dwarf2_name (die
, cu
);
3838 if (fieldname
== NULL
)
3841 /* Get the mangled name. */
3842 physname
= dwarf2_linkage_name (die
, cu
);
3844 /* Look up member function name in fieldlist. */
3845 for (i
= 0; i
< fip
->nfnfields
; i
++)
3847 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3851 /* Create new list element if necessary. */
3852 if (i
< fip
->nfnfields
)
3853 flp
= &fip
->fnfieldlists
[i
];
3856 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3858 fip
->fnfieldlists
= (struct fnfieldlist
*)
3859 xrealloc (fip
->fnfieldlists
,
3860 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3861 * sizeof (struct fnfieldlist
));
3862 if (fip
->nfnfields
== 0)
3863 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3865 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3866 flp
->name
= fieldname
;
3872 /* Create a new member function field and chain it to the field list
3874 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3875 make_cleanup (xfree
, new_fnfield
);
3876 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3877 new_fnfield
->next
= flp
->head
;
3878 flp
->head
= new_fnfield
;
3881 /* Fill in the member function field info. */
3882 fnp
= &new_fnfield
->fnfield
;
3883 /* The name is already allocated along with this objfile, so we don't
3884 need to duplicate it for the type. */
3885 fnp
->physname
= physname
? physname
: "";
3886 fnp
->type
= alloc_type (objfile
);
3887 this_type
= read_type_die (die
, cu
);
3888 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3890 int nparams
= TYPE_NFIELDS (this_type
);
3892 /* TYPE is the domain of this method, and THIS_TYPE is the type
3893 of the method itself (TYPE_CODE_METHOD). */
3894 smash_to_method_type (fnp
->type
, type
,
3895 TYPE_TARGET_TYPE (this_type
),
3896 TYPE_FIELDS (this_type
),
3897 TYPE_NFIELDS (this_type
),
3898 TYPE_VARARGS (this_type
));
3900 /* Handle static member functions.
3901 Dwarf2 has no clean way to discern C++ static and non-static
3902 member functions. G++ helps GDB by marking the first
3903 parameter for non-static member functions (which is the
3904 this pointer) as artificial. We obtain this information
3905 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3906 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3907 fnp
->voffset
= VOFFSET_STATIC
;
3910 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3913 /* Get fcontext from DW_AT_containing_type if present. */
3914 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3915 fnp
->fcontext
= die_containing_type (die
, cu
);
3917 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3918 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3920 /* Get accessibility. */
3921 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3924 switch (DW_UNSND (attr
))
3926 case DW_ACCESS_private
:
3927 fnp
->is_private
= 1;
3929 case DW_ACCESS_protected
:
3930 fnp
->is_protected
= 1;
3935 /* Check for artificial methods. */
3936 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3937 if (attr
&& DW_UNSND (attr
) != 0)
3938 fnp
->is_artificial
= 1;
3940 /* Get index in virtual function table if it is a virtual member function. */
3941 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3944 /* Support the .debug_loc offsets */
3945 if (attr_form_is_block (attr
))
3947 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3949 else if (attr_form_is_section_offset (attr
))
3951 dwarf2_complex_location_expr_complaint ();
3955 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3961 /* Create the vector of member function fields, and attach it to the type. */
3964 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3965 struct dwarf2_cu
*cu
)
3967 struct fnfieldlist
*flp
;
3968 int total_length
= 0;
3971 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3972 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3973 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3975 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3977 struct nextfnfield
*nfp
= flp
->head
;
3978 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3981 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3982 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3983 fn_flp
->fn_fields
= (struct fn_field
*)
3984 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3985 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3986 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3988 total_length
+= flp
->length
;
3991 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3992 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3995 /* Returns non-zero if NAME is the name of a vtable member in CU's
3996 language, zero otherwise. */
3998 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4000 static const char vptr
[] = "_vptr";
4001 static const char vtable
[] = "vtable";
4003 /* Look for the C++ and Java forms of the vtable. */
4004 if ((cu
->language
== language_java
4005 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4006 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4007 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4013 /* GCC outputs unnamed structures that are really pointers to member
4014 functions, with the ABI-specified layout. If DIE (from CU) describes
4015 such a structure, set its type, and return nonzero. Otherwise return
4018 GCC shouldn't do this; it should just output pointer to member DIEs.
4019 This is GCC PR debug/28767. */
4021 static struct type
*
4022 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4024 struct objfile
*objfile
= cu
->objfile
;
4026 struct die_info
*pfn_die
, *delta_die
;
4027 struct attribute
*pfn_name
, *delta_name
;
4028 struct type
*pfn_type
, *domain_type
;
4030 /* Check for a structure with no name and two children. */
4031 if (die
->tag
!= DW_TAG_structure_type
4032 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4033 || die
->child
== NULL
4034 || die
->child
->sibling
== NULL
4035 || (die
->child
->sibling
->sibling
!= NULL
4036 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4039 /* Check for __pfn and __delta members. */
4040 pfn_die
= die
->child
;
4041 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4042 if (pfn_die
->tag
!= DW_TAG_member
4044 || DW_STRING (pfn_name
) == NULL
4045 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4048 delta_die
= pfn_die
->sibling
;
4049 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4050 if (delta_die
->tag
!= DW_TAG_member
4051 || delta_name
== NULL
4052 || DW_STRING (delta_name
) == NULL
4053 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4056 /* Find the type of the method. */
4057 pfn_type
= die_type (pfn_die
, cu
);
4058 if (pfn_type
== NULL
4059 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4060 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4063 /* Look for the "this" argument. */
4064 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4065 if (TYPE_NFIELDS (pfn_type
) == 0
4066 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4069 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4070 type
= alloc_type (objfile
);
4071 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4072 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4073 TYPE_VARARGS (pfn_type
));
4074 type
= lookup_methodptr_type (type
);
4075 return set_die_type (die
, type
, cu
);
4078 /* Called when we find the DIE that starts a structure or union scope
4079 (definition) to process all dies that define the members of the
4082 NOTE: we need to call struct_type regardless of whether or not the
4083 DIE has an at_name attribute, since it might be an anonymous
4084 structure or union. This gets the type entered into our set of
4087 However, if the structure is incomplete (an opaque struct/union)
4088 then suppress creating a symbol table entry for it since gdb only
4089 wants to find the one with the complete definition. Note that if
4090 it is complete, we just call new_symbol, which does it's own
4091 checking about whether the struct/union is anonymous or not (and
4092 suppresses creating a symbol table entry itself). */
4094 static struct type
*
4095 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4097 struct objfile
*objfile
= cu
->objfile
;
4099 struct attribute
*attr
;
4101 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4103 type
= quirk_gcc_member_function_pointer (die
, cu
);
4107 type
= alloc_type (objfile
);
4108 INIT_CPLUS_SPECIFIC (type
);
4109 name
= dwarf2_name (die
, cu
);
4112 if (cu
->language
== language_cplus
4113 || cu
->language
== language_java
)
4115 const char *new_prefix
= determine_class_name (die
, cu
);
4116 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4120 /* The name is already allocated along with this objfile, so
4121 we don't need to duplicate it for the type. */
4122 TYPE_TAG_NAME (type
) = name
;
4126 if (die
->tag
== DW_TAG_structure_type
)
4128 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4130 else if (die
->tag
== DW_TAG_union_type
)
4132 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4136 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4138 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4141 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4144 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4148 TYPE_LENGTH (type
) = 0;
4151 TYPE_STUB_SUPPORTED (type
) = 1;
4152 if (die_is_declaration (die
, cu
))
4153 TYPE_STUB (type
) = 1;
4155 /* We need to add the type field to the die immediately so we don't
4156 infinitely recurse when dealing with pointers to the structure
4157 type within the structure itself. */
4158 set_die_type (die
, type
, cu
);
4160 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4162 struct field_info fi
;
4163 struct die_info
*child_die
;
4165 memset (&fi
, 0, sizeof (struct field_info
));
4167 child_die
= die
->child
;
4169 while (child_die
&& child_die
->tag
)
4171 if (child_die
->tag
== DW_TAG_member
4172 || child_die
->tag
== DW_TAG_variable
)
4174 /* NOTE: carlton/2002-11-05: A C++ static data member
4175 should be a DW_TAG_member that is a declaration, but
4176 all versions of G++ as of this writing (so through at
4177 least 3.2.1) incorrectly generate DW_TAG_variable
4178 tags for them instead. */
4179 dwarf2_add_field (&fi
, child_die
, cu
);
4181 else if (child_die
->tag
== DW_TAG_subprogram
)
4183 /* C++ member function. */
4184 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4186 else if (child_die
->tag
== DW_TAG_inheritance
)
4188 /* C++ base class field. */
4189 dwarf2_add_field (&fi
, child_die
, cu
);
4191 child_die
= sibling_die (child_die
);
4194 /* Attach fields and member functions to the type. */
4196 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4199 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4201 /* Get the type which refers to the base class (possibly this
4202 class itself) which contains the vtable pointer for the current
4203 class from the DW_AT_containing_type attribute. */
4205 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4207 struct type
*t
= die_containing_type (die
, cu
);
4209 TYPE_VPTR_BASETYPE (type
) = t
;
4214 /* Our own class provides vtbl ptr. */
4215 for (i
= TYPE_NFIELDS (t
) - 1;
4216 i
>= TYPE_N_BASECLASSES (t
);
4219 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4221 if (is_vtable_name (fieldname
, cu
))
4223 TYPE_VPTR_FIELDNO (type
) = i
;
4228 /* Complain if virtual function table field not found. */
4229 if (i
< TYPE_N_BASECLASSES (t
))
4230 complaint (&symfile_complaints
,
4231 _("virtual function table pointer not found when defining class '%s'"),
4232 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4237 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4240 else if (cu
->producer
4241 && strncmp (cu
->producer
,
4242 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4244 /* The IBM XLC compiler does not provide direct indication
4245 of the containing type, but the vtable pointer is
4246 always named __vfp. */
4250 for (i
= TYPE_NFIELDS (type
) - 1;
4251 i
>= TYPE_N_BASECLASSES (type
);
4254 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4256 TYPE_VPTR_FIELDNO (type
) = i
;
4257 TYPE_VPTR_BASETYPE (type
) = type
;
4265 do_cleanups (back_to
);
4270 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4272 struct objfile
*objfile
= cu
->objfile
;
4273 struct die_info
*child_die
= die
->child
;
4274 struct type
*this_type
;
4276 this_type
= get_die_type (die
, cu
);
4277 if (this_type
== NULL
)
4278 this_type
= read_structure_type (die
, cu
);
4280 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4281 snapshots) has been known to create a die giving a declaration
4282 for a class that has, as a child, a die giving a definition for a
4283 nested class. So we have to process our children even if the
4284 current die is a declaration. Normally, of course, a declaration
4285 won't have any children at all. */
4287 while (child_die
!= NULL
&& child_die
->tag
)
4289 if (child_die
->tag
== DW_TAG_member
4290 || child_die
->tag
== DW_TAG_variable
4291 || child_die
->tag
== DW_TAG_inheritance
)
4296 process_die (child_die
, cu
);
4298 child_die
= sibling_die (child_die
);
4301 /* Do not consider external references. According to the DWARF standard,
4302 these DIEs are identified by the fact that they have no byte_size
4303 attribute, and a declaration attribute. */
4304 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4305 || !die_is_declaration (die
, cu
))
4306 new_symbol (die
, this_type
, cu
);
4309 /* Given a DW_AT_enumeration_type die, set its type. We do not
4310 complete the type's fields yet, or create any symbols. */
4312 static struct type
*
4313 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4315 struct objfile
*objfile
= cu
->objfile
;
4317 struct attribute
*attr
;
4320 type
= alloc_type (objfile
);
4322 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4323 name
= dwarf2_full_name (die
, cu
);
4325 TYPE_TAG_NAME (type
) = (char *) name
;
4327 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4330 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4334 TYPE_LENGTH (type
) = 0;
4337 /* The enumeration DIE can be incomplete. In Ada, any type can be
4338 declared as private in the package spec, and then defined only
4339 inside the package body. Such types are known as Taft Amendment
4340 Types. When another package uses such a type, an incomplete DIE
4341 may be generated by the compiler. */
4342 if (die_is_declaration (die
, cu
))
4343 TYPE_STUB (type
) = 1;
4345 return set_die_type (die
, type
, cu
);
4348 /* Determine the name of the type represented by DIE, which should be
4349 a named C++ or Java compound type. Return the name in question,
4350 allocated on the objfile obstack. */
4353 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4355 const char *new_prefix
= NULL
;
4357 /* If we don't have namespace debug info, guess the name by trying
4358 to demangle the names of members, just like we did in
4359 guess_structure_name. */
4360 if (!processing_has_namespace_info
)
4362 struct die_info
*child
;
4364 for (child
= die
->child
;
4365 child
!= NULL
&& child
->tag
!= 0;
4366 child
= sibling_die (child
))
4368 if (child
->tag
== DW_TAG_subprogram
)
4371 = language_class_name_from_physname (cu
->language_defn
,
4375 if (phys_prefix
!= NULL
)
4378 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4379 &cu
->objfile
->objfile_obstack
);
4380 xfree (phys_prefix
);
4387 if (new_prefix
== NULL
)
4388 new_prefix
= dwarf2_full_name (die
, cu
);
4393 /* Given a pointer to a die which begins an enumeration, process all
4394 the dies that define the members of the enumeration, and create the
4395 symbol for the enumeration type.
4397 NOTE: We reverse the order of the element list. */
4400 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4402 struct objfile
*objfile
= cu
->objfile
;
4403 struct die_info
*child_die
;
4404 struct field
*fields
;
4407 int unsigned_enum
= 1;
4409 struct type
*this_type
;
4413 this_type
= get_die_type (die
, cu
);
4414 if (this_type
== NULL
)
4415 this_type
= read_enumeration_type (die
, cu
);
4416 if (die
->child
!= NULL
)
4418 child_die
= die
->child
;
4419 while (child_die
&& child_die
->tag
)
4421 if (child_die
->tag
!= DW_TAG_enumerator
)
4423 process_die (child_die
, cu
);
4427 name
= dwarf2_name (child_die
, cu
);
4430 sym
= new_symbol (child_die
, this_type
, cu
);
4431 if (SYMBOL_VALUE (sym
) < 0)
4434 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4436 fields
= (struct field
*)
4438 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4439 * sizeof (struct field
));
4442 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4443 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4444 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4445 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4451 child_die
= sibling_die (child_die
);
4456 TYPE_NFIELDS (this_type
) = num_fields
;
4457 TYPE_FIELDS (this_type
) = (struct field
*)
4458 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4459 memcpy (TYPE_FIELDS (this_type
), fields
,
4460 sizeof (struct field
) * num_fields
);
4464 TYPE_UNSIGNED (this_type
) = 1;
4467 new_symbol (die
, this_type
, cu
);
4470 /* Extract all information from a DW_TAG_array_type DIE and put it in
4471 the DIE's type field. For now, this only handles one dimensional
4474 static struct type
*
4475 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4477 struct objfile
*objfile
= cu
->objfile
;
4478 struct die_info
*child_die
;
4479 struct type
*type
= NULL
;
4480 struct type
*element_type
, *range_type
, *index_type
;
4481 struct type
**range_types
= NULL
;
4482 struct attribute
*attr
;
4484 struct cleanup
*back_to
;
4487 element_type
= die_type (die
, cu
);
4489 /* Irix 6.2 native cc creates array types without children for
4490 arrays with unspecified length. */
4491 if (die
->child
== NULL
)
4493 index_type
= builtin_type_int32
;
4494 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4495 type
= create_array_type (NULL
, element_type
, range_type
);
4496 return set_die_type (die
, type
, cu
);
4499 back_to
= make_cleanup (null_cleanup
, NULL
);
4500 child_die
= die
->child
;
4501 while (child_die
&& child_die
->tag
)
4503 if (child_die
->tag
== DW_TAG_subrange_type
)
4505 struct type
*child_type
= read_type_die (child_die
, cu
);
4506 if (child_type
!= NULL
)
4508 /* The range type was succesfully read. Save it for
4509 the array type creation. */
4510 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4512 range_types
= (struct type
**)
4513 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4514 * sizeof (struct type
*));
4516 make_cleanup (free_current_contents
, &range_types
);
4518 range_types
[ndim
++] = child_type
;
4521 child_die
= sibling_die (child_die
);
4524 /* Dwarf2 dimensions are output from left to right, create the
4525 necessary array types in backwards order. */
4527 type
= element_type
;
4529 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4533 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4538 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4541 /* Understand Dwarf2 support for vector types (like they occur on
4542 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4543 array type. This is not part of the Dwarf2/3 standard yet, but a
4544 custom vendor extension. The main difference between a regular
4545 array and the vector variant is that vectors are passed by value
4547 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4549 make_vector_type (type
);
4551 name
= dwarf2_name (die
, cu
);
4553 TYPE_NAME (type
) = name
;
4555 do_cleanups (back_to
);
4557 /* Install the type in the die. */
4558 return set_die_type (die
, type
, cu
);
4561 static enum dwarf_array_dim_ordering
4562 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4564 struct attribute
*attr
;
4566 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4568 if (attr
) return DW_SND (attr
);
4571 GNU F77 is a special case, as at 08/2004 array type info is the
4572 opposite order to the dwarf2 specification, but data is still
4573 laid out as per normal fortran.
4575 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4579 if (cu
->language
== language_fortran
&&
4580 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4582 return DW_ORD_row_major
;
4585 switch (cu
->language_defn
->la_array_ordering
)
4587 case array_column_major
:
4588 return DW_ORD_col_major
;
4589 case array_row_major
:
4591 return DW_ORD_row_major
;
4595 /* Extract all information from a DW_TAG_set_type DIE and put it in
4596 the DIE's type field. */
4598 static struct type
*
4599 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4601 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4603 return set_die_type (die
, set_type
, cu
);
4606 /* First cut: install each common block member as a global variable. */
4609 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4611 struct die_info
*child_die
;
4612 struct attribute
*attr
;
4614 CORE_ADDR base
= (CORE_ADDR
) 0;
4616 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4619 /* Support the .debug_loc offsets */
4620 if (attr_form_is_block (attr
))
4622 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4624 else if (attr_form_is_section_offset (attr
))
4626 dwarf2_complex_location_expr_complaint ();
4630 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4631 "common block member");
4634 if (die
->child
!= NULL
)
4636 child_die
= die
->child
;
4637 while (child_die
&& child_die
->tag
)
4639 sym
= new_symbol (child_die
, NULL
, cu
);
4640 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4643 SYMBOL_VALUE_ADDRESS (sym
) =
4644 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4645 add_symbol_to_list (sym
, &global_symbols
);
4647 child_die
= sibling_die (child_die
);
4652 /* Create a type for a C++ namespace. */
4654 static struct type
*
4655 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4657 struct objfile
*objfile
= cu
->objfile
;
4658 const char *previous_prefix
, *name
;
4662 /* For extensions, reuse the type of the original namespace. */
4663 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4665 struct die_info
*ext_die
;
4666 struct dwarf2_cu
*ext_cu
= cu
;
4667 ext_die
= dwarf2_extension (die
, &ext_cu
);
4668 type
= read_type_die (ext_die
, ext_cu
);
4669 return set_die_type (die
, type
, cu
);
4672 name
= namespace_name (die
, &is_anonymous
, cu
);
4674 /* Now build the name of the current namespace. */
4676 previous_prefix
= determine_prefix (die
, cu
);
4677 if (previous_prefix
[0] != '\0')
4678 name
= typename_concat (&objfile
->objfile_obstack
,
4679 previous_prefix
, name
, cu
);
4681 /* Create the type. */
4682 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4684 TYPE_NAME (type
) = (char *) name
;
4685 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4687 set_die_type (die
, type
, cu
);
4692 /* Read a C++ namespace. */
4695 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4697 struct objfile
*objfile
= cu
->objfile
;
4701 /* Add a symbol associated to this if we haven't seen the namespace
4702 before. Also, add a using directive if it's an anonymous
4705 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4709 type
= read_type_die (die
, cu
);
4710 new_symbol (die
, type
, cu
);
4712 name
= namespace_name (die
, &is_anonymous
, cu
);
4715 const char *previous_prefix
= determine_prefix (die
, cu
);
4716 cp_add_using_directive (TYPE_NAME (type
),
4717 strlen (previous_prefix
),
4718 strlen (TYPE_NAME (type
)));
4722 if (die
->child
!= NULL
)
4724 struct die_info
*child_die
= die
->child
;
4726 while (child_die
&& child_die
->tag
)
4728 process_die (child_die
, cu
);
4729 child_die
= sibling_die (child_die
);
4734 /* Return the name of the namespace represented by DIE. Set
4735 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4739 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4741 struct die_info
*current_die
;
4742 const char *name
= NULL
;
4744 /* Loop through the extensions until we find a name. */
4746 for (current_die
= die
;
4747 current_die
!= NULL
;
4748 current_die
= dwarf2_extension (die
, &cu
))
4750 name
= dwarf2_name (current_die
, cu
);
4755 /* Is it an anonymous namespace? */
4757 *is_anonymous
= (name
== NULL
);
4759 name
= "(anonymous namespace)";
4764 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4765 the user defined type vector. */
4767 static struct type
*
4768 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4770 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4771 struct comp_unit_head
*cu_header
= &cu
->header
;
4773 struct attribute
*attr_byte_size
;
4774 struct attribute
*attr_address_class
;
4775 int byte_size
, addr_class
;
4777 type
= lookup_pointer_type (die_type (die
, cu
));
4779 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4781 byte_size
= DW_UNSND (attr_byte_size
);
4783 byte_size
= cu_header
->addr_size
;
4785 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4786 if (attr_address_class
)
4787 addr_class
= DW_UNSND (attr_address_class
);
4789 addr_class
= DW_ADDR_none
;
4791 /* If the pointer size or address class is different than the
4792 default, create a type variant marked as such and set the
4793 length accordingly. */
4794 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4796 if (gdbarch_address_class_type_flags_p (gdbarch
))
4800 type_flags
= gdbarch_address_class_type_flags
4801 (gdbarch
, byte_size
, addr_class
);
4802 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4804 type
= make_type_with_address_space (type
, type_flags
);
4806 else if (TYPE_LENGTH (type
) != byte_size
)
4808 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4811 /* Should we also complain about unhandled address classes? */
4815 TYPE_LENGTH (type
) = byte_size
;
4816 return set_die_type (die
, type
, cu
);
4819 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4820 the user defined type vector. */
4822 static struct type
*
4823 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4825 struct objfile
*objfile
= cu
->objfile
;
4827 struct type
*to_type
;
4828 struct type
*domain
;
4830 to_type
= die_type (die
, cu
);
4831 domain
= die_containing_type (die
, cu
);
4833 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4834 type
= lookup_methodptr_type (to_type
);
4836 type
= lookup_memberptr_type (to_type
, domain
);
4838 return set_die_type (die
, type
, cu
);
4841 /* Extract all information from a DW_TAG_reference_type DIE and add to
4842 the user defined type vector. */
4844 static struct type
*
4845 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4847 struct comp_unit_head
*cu_header
= &cu
->header
;
4849 struct attribute
*attr
;
4851 type
= lookup_reference_type (die_type (die
, cu
));
4852 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4855 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4859 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4861 return set_die_type (die
, type
, cu
);
4864 static struct type
*
4865 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4867 struct type
*base_type
, *cv_type
;
4869 base_type
= die_type (die
, cu
);
4870 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4871 return set_die_type (die
, cv_type
, cu
);
4874 static struct type
*
4875 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4877 struct type
*base_type
, *cv_type
;
4879 base_type
= die_type (die
, cu
);
4880 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4881 return set_die_type (die
, cv_type
, cu
);
4884 /* Extract all information from a DW_TAG_string_type DIE and add to
4885 the user defined type vector. It isn't really a user defined type,
4886 but it behaves like one, with other DIE's using an AT_user_def_type
4887 attribute to reference it. */
4889 static struct type
*
4890 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4892 struct objfile
*objfile
= cu
->objfile
;
4893 struct type
*type
, *range_type
, *index_type
, *char_type
;
4894 struct attribute
*attr
;
4895 unsigned int length
;
4897 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4900 length
= DW_UNSND (attr
);
4904 /* check for the DW_AT_byte_size attribute */
4905 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4908 length
= DW_UNSND (attr
);
4916 index_type
= builtin_type_int32
;
4917 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4918 type
= create_string_type (NULL
, range_type
);
4920 return set_die_type (die
, type
, cu
);
4923 /* Handle DIES due to C code like:
4927 int (*funcp)(int a, long l);
4931 ('funcp' generates a DW_TAG_subroutine_type DIE)
4934 static struct type
*
4935 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4937 struct type
*type
; /* Type that this function returns */
4938 struct type
*ftype
; /* Function that returns above type */
4939 struct attribute
*attr
;
4941 type
= die_type (die
, cu
);
4942 ftype
= make_function_type (type
, (struct type
**) 0);
4944 /* All functions in C++, Pascal and Java have prototypes. */
4945 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4946 if ((attr
&& (DW_UNSND (attr
) != 0))
4947 || cu
->language
== language_cplus
4948 || cu
->language
== language_java
4949 || cu
->language
== language_pascal
)
4950 TYPE_PROTOTYPED (ftype
) = 1;
4952 /* Store the calling convention in the type if it's available in
4953 the subroutine die. Otherwise set the calling convention to
4954 the default value DW_CC_normal. */
4955 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4956 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4958 if (die
->child
!= NULL
)
4960 struct die_info
*child_die
;
4964 /* Count the number of parameters.
4965 FIXME: GDB currently ignores vararg functions, but knows about
4966 vararg member functions. */
4967 child_die
= die
->child
;
4968 while (child_die
&& child_die
->tag
)
4970 if (child_die
->tag
== DW_TAG_formal_parameter
)
4972 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4973 TYPE_VARARGS (ftype
) = 1;
4974 child_die
= sibling_die (child_die
);
4977 /* Allocate storage for parameters and fill them in. */
4978 TYPE_NFIELDS (ftype
) = nparams
;
4979 TYPE_FIELDS (ftype
) = (struct field
*)
4980 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4982 child_die
= die
->child
;
4983 while (child_die
&& child_die
->tag
)
4985 if (child_die
->tag
== DW_TAG_formal_parameter
)
4987 /* Dwarf2 has no clean way to discern C++ static and non-static
4988 member functions. G++ helps GDB by marking the first
4989 parameter for non-static member functions (which is the
4990 this pointer) as artificial. We pass this information
4991 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4992 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4994 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4996 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4997 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5000 child_die
= sibling_die (child_die
);
5004 return set_die_type (die
, ftype
, cu
);
5007 static struct type
*
5008 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5010 struct objfile
*objfile
= cu
->objfile
;
5011 struct attribute
*attr
;
5012 const char *name
= NULL
;
5013 struct type
*this_type
;
5015 name
= dwarf2_full_name (die
, cu
);
5016 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5017 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5018 TYPE_NAME (this_type
) = (char *) name
;
5019 set_die_type (die
, this_type
, cu
);
5020 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5024 /* Find a representation of a given base type and install
5025 it in the TYPE field of the die. */
5027 static struct type
*
5028 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5030 struct objfile
*objfile
= cu
->objfile
;
5032 struct attribute
*attr
;
5033 int encoding
= 0, size
= 0;
5035 enum type_code code
= TYPE_CODE_INT
;
5037 struct type
*target_type
= NULL
;
5039 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5042 encoding
= DW_UNSND (attr
);
5044 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5047 size
= DW_UNSND (attr
);
5049 name
= dwarf2_name (die
, cu
);
5052 complaint (&symfile_complaints
,
5053 _("DW_AT_name missing from DW_TAG_base_type"));
5058 case DW_ATE_address
:
5059 /* Turn DW_ATE_address into a void * pointer. */
5060 code
= TYPE_CODE_PTR
;
5061 type_flags
|= TYPE_FLAG_UNSIGNED
;
5062 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5064 case DW_ATE_boolean
:
5065 code
= TYPE_CODE_BOOL
;
5066 type_flags
|= TYPE_FLAG_UNSIGNED
;
5068 case DW_ATE_complex_float
:
5069 code
= TYPE_CODE_COMPLEX
;
5070 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5072 case DW_ATE_decimal_float
:
5073 code
= TYPE_CODE_DECFLOAT
;
5076 code
= TYPE_CODE_FLT
;
5080 case DW_ATE_unsigned
:
5081 type_flags
|= TYPE_FLAG_UNSIGNED
;
5083 case DW_ATE_signed_char
:
5084 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5085 code
= TYPE_CODE_CHAR
;
5087 case DW_ATE_unsigned_char
:
5088 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5089 code
= TYPE_CODE_CHAR
;
5090 type_flags
|= TYPE_FLAG_UNSIGNED
;
5093 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5094 dwarf_type_encoding_name (encoding
));
5098 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5099 TYPE_NAME (type
) = name
;
5100 TYPE_TARGET_TYPE (type
) = target_type
;
5102 if (name
&& strcmp (name
, "char") == 0)
5103 TYPE_NOSIGN (type
) = 1;
5105 return set_die_type (die
, type
, cu
);
5108 /* Read the given DW_AT_subrange DIE. */
5110 static struct type
*
5111 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5113 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5114 struct type
*base_type
;
5115 struct type
*range_type
;
5116 struct attribute
*attr
;
5121 base_type
= die_type (die
, cu
);
5122 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5124 complaint (&symfile_complaints
,
5125 _("DW_AT_type missing from DW_TAG_subrange_type"));
5127 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5128 0, NULL
, cu
->objfile
);
5131 if (cu
->language
== language_fortran
)
5133 /* FORTRAN implies a lower bound of 1, if not given. */
5137 /* FIXME: For variable sized arrays either of these could be
5138 a variable rather than a constant value. We'll allow it,
5139 but we don't know how to handle it. */
5140 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5142 low
= dwarf2_get_attr_constant_value (attr
, 0);
5144 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5147 if (attr
->form
== DW_FORM_block1
)
5149 /* GCC encodes arrays with unspecified or dynamic length
5150 with a DW_FORM_block1 attribute.
5151 FIXME: GDB does not yet know how to handle dynamic
5152 arrays properly, treat them as arrays with unspecified
5155 FIXME: jimb/2003-09-22: GDB does not really know
5156 how to handle arrays of unspecified length
5157 either; we just represent them as zero-length
5158 arrays. Choose an appropriate upper bound given
5159 the lower bound we've computed above. */
5163 high
= dwarf2_get_attr_constant_value (attr
, 1);
5166 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5168 name
= dwarf2_name (die
, cu
);
5170 TYPE_NAME (range_type
) = name
;
5172 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5174 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5176 return set_die_type (die
, range_type
, cu
);
5179 static struct type
*
5180 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5184 /* For now, we only support the C meaning of an unspecified type: void. */
5186 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5187 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5189 return set_die_type (die
, type
, cu
);
5192 /* Trivial hash function for die_info: the hash value of a DIE
5193 is its offset in .debug_info for this objfile. */
5196 die_hash (const void *item
)
5198 const struct die_info
*die
= item
;
5202 /* Trivial comparison function for die_info structures: two DIEs
5203 are equal if they have the same offset. */
5206 die_eq (const void *item_lhs
, const void *item_rhs
)
5208 const struct die_info
*die_lhs
= item_lhs
;
5209 const struct die_info
*die_rhs
= item_rhs
;
5210 return die_lhs
->offset
== die_rhs
->offset
;
5213 /* Read a whole compilation unit into a linked list of dies. */
5215 static struct die_info
*
5216 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5219 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5223 &cu
->comp_unit_obstack
,
5224 hashtab_obstack_allocate
,
5225 dummy_obstack_deallocate
);
5227 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5230 /* Main entry point for reading a DIE and all children.
5231 Read the DIE and dump it if requested. */
5233 static struct die_info
*
5234 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5235 struct dwarf2_cu
*cu
,
5236 gdb_byte
**new_info_ptr
,
5237 struct die_info
*parent
)
5239 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5240 new_info_ptr
, parent
);
5242 if (dwarf2_die_debug
)
5244 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5245 dump_die (result
, dwarf2_die_debug
);
5251 /* Read a single die and all its descendents. Set the die's sibling
5252 field to NULL; set other fields in the die correctly, and set all
5253 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5254 location of the info_ptr after reading all of those dies. PARENT
5255 is the parent of the die in question. */
5257 static struct die_info
*
5258 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5259 struct dwarf2_cu
*cu
,
5260 gdb_byte
**new_info_ptr
,
5261 struct die_info
*parent
)
5263 struct die_info
*die
;
5267 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5270 *new_info_ptr
= cur_ptr
;
5273 store_in_ref_table (die
, cu
);
5277 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5283 *new_info_ptr
= cur_ptr
;
5286 die
->sibling
= NULL
;
5287 die
->parent
= parent
;
5291 /* Read a die, all of its descendents, and all of its siblings; set
5292 all of the fields of all of the dies correctly. Arguments are as
5293 in read_die_and_children. */
5295 static struct die_info
*
5296 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5297 struct dwarf2_cu
*cu
,
5298 gdb_byte
**new_info_ptr
,
5299 struct die_info
*parent
)
5301 struct die_info
*first_die
, *last_sibling
;
5305 first_die
= last_sibling
= NULL
;
5309 struct die_info
*die
5310 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5314 *new_info_ptr
= cur_ptr
;
5321 last_sibling
->sibling
= die
;
5327 /* Decompress a section that was compressed using zlib. Store the
5328 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5331 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5332 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5334 bfd
*abfd
= objfile
->obfd
;
5336 error (_("Support for zlib-compressed DWARF data (from '%s') "
5337 "is disabled in this copy of GDB"),
5338 bfd_get_filename (abfd
));
5340 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5341 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5342 bfd_size_type uncompressed_size
;
5343 gdb_byte
*uncompressed_buffer
;
5346 int header_size
= 12;
5348 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5349 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5350 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5351 bfd_get_filename (abfd
));
5353 /* Read the zlib header. In this case, it should be "ZLIB" followed
5354 by the uncompressed section size, 8 bytes in big-endian order. */
5355 if (compressed_size
< header_size
5356 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5357 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5358 bfd_get_filename (abfd
));
5359 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5360 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5361 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5362 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5363 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5364 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5365 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5366 uncompressed_size
+= compressed_buffer
[11];
5368 /* It is possible the section consists of several compressed
5369 buffers concatenated together, so we uncompress in a loop. */
5373 strm
.avail_in
= compressed_size
- header_size
;
5374 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5375 strm
.avail_out
= uncompressed_size
;
5376 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5378 rc
= inflateInit (&strm
);
5379 while (strm
.avail_in
> 0)
5382 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5383 bfd_get_filename (abfd
), rc
);
5384 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5385 + (uncompressed_size
- strm
.avail_out
));
5386 rc
= inflate (&strm
, Z_FINISH
);
5387 if (rc
!= Z_STREAM_END
)
5388 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5389 bfd_get_filename (abfd
), rc
);
5390 rc
= inflateReset (&strm
);
5392 rc
= inflateEnd (&strm
);
5394 || strm
.avail_out
!= 0)
5395 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5396 bfd_get_filename (abfd
), rc
);
5398 xfree (compressed_buffer
);
5399 *outbuf
= uncompressed_buffer
;
5400 *outsize
= uncompressed_size
;
5405 /* Read the contents of the section at OFFSET and of size SIZE from the
5406 object file specified by OBJFILE into the objfile_obstack and return it.
5407 If the section is compressed, uncompress it before returning. */
5410 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5412 bfd
*abfd
= objfile
->obfd
;
5413 gdb_byte
*buf
, *retbuf
;
5414 bfd_size_type size
= bfd_get_section_size (sectp
);
5415 unsigned char header
[4];
5420 /* Check if the file has a 4-byte header indicating compression. */
5421 if (size
> sizeof (header
)
5422 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5423 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5425 /* Upon decompression, update the buffer and its size. */
5426 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5428 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5429 dwarf2_resize_section (sectp
, size
);
5434 /* If we get here, we are a normal, not-compressed section. */
5435 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5436 /* When debugging .o files, we may need to apply relocations; see
5437 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5438 We never compress sections in .o files, so we only need to
5439 try this when the section is not compressed. */
5440 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5444 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5445 || bfd_bread (buf
, size
, abfd
) != size
)
5446 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5447 bfd_get_filename (abfd
));
5452 /* In DWARF version 2, the description of the debugging information is
5453 stored in a separate .debug_abbrev section. Before we read any
5454 dies from a section we read in all abbreviations and install them
5455 in a hash table. This function also sets flags in CU describing
5456 the data found in the abbrev table. */
5459 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5461 struct comp_unit_head
*cu_header
= &cu
->header
;
5462 gdb_byte
*abbrev_ptr
;
5463 struct abbrev_info
*cur_abbrev
;
5464 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5465 unsigned int abbrev_form
, hash_number
;
5466 struct attr_abbrev
*cur_attrs
;
5467 unsigned int allocated_attrs
;
5469 /* Initialize dwarf2 abbrevs */
5470 obstack_init (&cu
->abbrev_obstack
);
5471 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5473 * sizeof (struct abbrev_info
*)));
5474 memset (cu
->dwarf2_abbrevs
, 0,
5475 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5477 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5478 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5479 abbrev_ptr
+= bytes_read
;
5481 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5482 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5484 /* loop until we reach an abbrev number of 0 */
5485 while (abbrev_number
)
5487 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5489 /* read in abbrev header */
5490 cur_abbrev
->number
= abbrev_number
;
5491 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5492 abbrev_ptr
+= bytes_read
;
5493 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5496 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5497 cu
->has_namespace_info
= 1;
5499 /* now read in declarations */
5500 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5501 abbrev_ptr
+= bytes_read
;
5502 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5503 abbrev_ptr
+= bytes_read
;
5506 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5508 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5510 = xrealloc (cur_attrs
, (allocated_attrs
5511 * sizeof (struct attr_abbrev
)));
5514 /* Record whether this compilation unit might have
5515 inter-compilation-unit references. If we don't know what form
5516 this attribute will have, then it might potentially be a
5517 DW_FORM_ref_addr, so we conservatively expect inter-CU
5520 if (abbrev_form
== DW_FORM_ref_addr
5521 || abbrev_form
== DW_FORM_indirect
)
5522 cu
->has_form_ref_addr
= 1;
5524 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5525 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5526 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5527 abbrev_ptr
+= bytes_read
;
5528 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5529 abbrev_ptr
+= bytes_read
;
5532 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5533 (cur_abbrev
->num_attrs
5534 * sizeof (struct attr_abbrev
)));
5535 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5536 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5538 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5539 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5540 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5542 /* Get next abbreviation.
5543 Under Irix6 the abbreviations for a compilation unit are not
5544 always properly terminated with an abbrev number of 0.
5545 Exit loop if we encounter an abbreviation which we have
5546 already read (which means we are about to read the abbreviations
5547 for the next compile unit) or if the end of the abbreviation
5548 table is reached. */
5549 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5550 >= dwarf2_per_objfile
->abbrev_size
)
5552 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5553 abbrev_ptr
+= bytes_read
;
5554 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5561 /* Release the memory used by the abbrev table for a compilation unit. */
5564 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5566 struct dwarf2_cu
*cu
= ptr_to_cu
;
5568 obstack_free (&cu
->abbrev_obstack
, NULL
);
5569 cu
->dwarf2_abbrevs
= NULL
;
5572 /* Lookup an abbrev_info structure in the abbrev hash table. */
5574 static struct abbrev_info
*
5575 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5577 unsigned int hash_number
;
5578 struct abbrev_info
*abbrev
;
5580 hash_number
= number
% ABBREV_HASH_SIZE
;
5581 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5585 if (abbrev
->number
== number
)
5588 abbrev
= abbrev
->next
;
5593 /* Returns nonzero if TAG represents a type that we might generate a partial
5597 is_type_tag_for_partial (int tag
)
5602 /* Some types that would be reasonable to generate partial symbols for,
5603 that we don't at present. */
5604 case DW_TAG_array_type
:
5605 case DW_TAG_file_type
:
5606 case DW_TAG_ptr_to_member_type
:
5607 case DW_TAG_set_type
:
5608 case DW_TAG_string_type
:
5609 case DW_TAG_subroutine_type
:
5611 case DW_TAG_base_type
:
5612 case DW_TAG_class_type
:
5613 case DW_TAG_interface_type
:
5614 case DW_TAG_enumeration_type
:
5615 case DW_TAG_structure_type
:
5616 case DW_TAG_subrange_type
:
5617 case DW_TAG_typedef
:
5618 case DW_TAG_union_type
:
5625 /* Load all DIEs that are interesting for partial symbols into memory. */
5627 static struct partial_die_info
*
5628 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5629 struct dwarf2_cu
*cu
)
5631 struct partial_die_info
*part_die
;
5632 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5633 struct abbrev_info
*abbrev
;
5634 unsigned int bytes_read
;
5635 unsigned int load_all
= 0;
5637 int nesting_level
= 1;
5642 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5646 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5650 &cu
->comp_unit_obstack
,
5651 hashtab_obstack_allocate
,
5652 dummy_obstack_deallocate
);
5654 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5655 sizeof (struct partial_die_info
));
5659 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5661 /* A NULL abbrev means the end of a series of children. */
5664 if (--nesting_level
== 0)
5666 /* PART_DIE was probably the last thing allocated on the
5667 comp_unit_obstack, so we could call obstack_free
5668 here. We don't do that because the waste is small,
5669 and will be cleaned up when we're done with this
5670 compilation unit. This way, we're also more robust
5671 against other users of the comp_unit_obstack. */
5674 info_ptr
+= bytes_read
;
5675 last_die
= parent_die
;
5676 parent_die
= parent_die
->die_parent
;
5680 /* Check whether this DIE is interesting enough to save. Normally
5681 we would not be interested in members here, but there may be
5682 later variables referencing them via DW_AT_specification (for
5685 && !is_type_tag_for_partial (abbrev
->tag
)
5686 && abbrev
->tag
!= DW_TAG_enumerator
5687 && abbrev
->tag
!= DW_TAG_subprogram
5688 && abbrev
->tag
!= DW_TAG_lexical_block
5689 && abbrev
->tag
!= DW_TAG_variable
5690 && abbrev
->tag
!= DW_TAG_namespace
5691 && abbrev
->tag
!= DW_TAG_member
)
5693 /* Otherwise we skip to the next sibling, if any. */
5694 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5698 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5699 abfd
, info_ptr
, cu
);
5701 /* This two-pass algorithm for processing partial symbols has a
5702 high cost in cache pressure. Thus, handle some simple cases
5703 here which cover the majority of C partial symbols. DIEs
5704 which neither have specification tags in them, nor could have
5705 specification tags elsewhere pointing at them, can simply be
5706 processed and discarded.
5708 This segment is also optional; scan_partial_symbols and
5709 add_partial_symbol will handle these DIEs if we chain
5710 them in normally. When compilers which do not emit large
5711 quantities of duplicate debug information are more common,
5712 this code can probably be removed. */
5714 /* Any complete simple types at the top level (pretty much all
5715 of them, for a language without namespaces), can be processed
5717 if (parent_die
== NULL
5718 && part_die
->has_specification
== 0
5719 && part_die
->is_declaration
== 0
5720 && (part_die
->tag
== DW_TAG_typedef
5721 || part_die
->tag
== DW_TAG_base_type
5722 || part_die
->tag
== DW_TAG_subrange_type
))
5724 if (building_psymtab
&& part_die
->name
!= NULL
)
5725 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5726 VAR_DOMAIN
, LOC_TYPEDEF
,
5727 &cu
->objfile
->static_psymbols
,
5728 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5729 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5733 /* If we're at the second level, and we're an enumerator, and
5734 our parent has no specification (meaning possibly lives in a
5735 namespace elsewhere), then we can add the partial symbol now
5736 instead of queueing it. */
5737 if (part_die
->tag
== DW_TAG_enumerator
5738 && parent_die
!= NULL
5739 && parent_die
->die_parent
== NULL
5740 && parent_die
->tag
== DW_TAG_enumeration_type
5741 && parent_die
->has_specification
== 0)
5743 if (part_die
->name
== NULL
)
5744 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5745 else if (building_psymtab
)
5746 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5747 VAR_DOMAIN
, LOC_CONST
,
5748 (cu
->language
== language_cplus
5749 || cu
->language
== language_java
)
5750 ? &cu
->objfile
->global_psymbols
5751 : &cu
->objfile
->static_psymbols
,
5752 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5754 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5758 /* We'll save this DIE so link it in. */
5759 part_die
->die_parent
= parent_die
;
5760 part_die
->die_sibling
= NULL
;
5761 part_die
->die_child
= NULL
;
5763 if (last_die
&& last_die
== parent_die
)
5764 last_die
->die_child
= part_die
;
5766 last_die
->die_sibling
= part_die
;
5768 last_die
= part_die
;
5770 if (first_die
== NULL
)
5771 first_die
= part_die
;
5773 /* Maybe add the DIE to the hash table. Not all DIEs that we
5774 find interesting need to be in the hash table, because we
5775 also have the parent/sibling/child chains; only those that we
5776 might refer to by offset later during partial symbol reading.
5778 For now this means things that might have be the target of a
5779 DW_AT_specification, DW_AT_abstract_origin, or
5780 DW_AT_extension. DW_AT_extension will refer only to
5781 namespaces; DW_AT_abstract_origin refers to functions (and
5782 many things under the function DIE, but we do not recurse
5783 into function DIEs during partial symbol reading) and
5784 possibly variables as well; DW_AT_specification refers to
5785 declarations. Declarations ought to have the DW_AT_declaration
5786 flag. It happens that GCC forgets to put it in sometimes, but
5787 only for functions, not for types.
5789 Adding more things than necessary to the hash table is harmless
5790 except for the performance cost. Adding too few will result in
5791 wasted time in find_partial_die, when we reread the compilation
5792 unit with load_all_dies set. */
5795 || abbrev
->tag
== DW_TAG_subprogram
5796 || abbrev
->tag
== DW_TAG_variable
5797 || abbrev
->tag
== DW_TAG_namespace
5798 || part_die
->is_declaration
)
5802 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5803 part_die
->offset
, INSERT
);
5807 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5808 sizeof (struct partial_die_info
));
5810 /* For some DIEs we want to follow their children (if any). For C
5811 we have no reason to follow the children of structures; for other
5812 languages we have to, both so that we can get at method physnames
5813 to infer fully qualified class names, and for DW_AT_specification.
5815 For Ada, we need to scan the children of subprograms and lexical
5816 blocks as well because Ada allows the definition of nested
5817 entities that could be interesting for the debugger, such as
5818 nested subprograms for instance. */
5819 if (last_die
->has_children
5821 || last_die
->tag
== DW_TAG_namespace
5822 || last_die
->tag
== DW_TAG_enumeration_type
5823 || (cu
->language
!= language_c
5824 && (last_die
->tag
== DW_TAG_class_type
5825 || last_die
->tag
== DW_TAG_interface_type
5826 || last_die
->tag
== DW_TAG_structure_type
5827 || last_die
->tag
== DW_TAG_union_type
))
5828 || (cu
->language
== language_ada
5829 && (last_die
->tag
== DW_TAG_subprogram
5830 || last_die
->tag
== DW_TAG_lexical_block
))))
5833 parent_die
= last_die
;
5837 /* Otherwise we skip to the next sibling, if any. */
5838 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5840 /* Back to the top, do it again. */
5844 /* Read a minimal amount of information into the minimal die structure. */
5847 read_partial_die (struct partial_die_info
*part_die
,
5848 struct abbrev_info
*abbrev
,
5849 unsigned int abbrev_len
, bfd
*abfd
,
5850 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5852 unsigned int bytes_read
, i
;
5853 struct attribute attr
;
5854 int has_low_pc_attr
= 0;
5855 int has_high_pc_attr
= 0;
5856 CORE_ADDR base_address
= 0;
5860 base_address_low_pc
,
5861 /* Overrides BASE_ADDRESS_LOW_PC. */
5862 base_address_entry_pc
5864 base_address_type
= base_address_none
;
5866 memset (part_die
, 0, sizeof (struct partial_die_info
));
5868 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5870 info_ptr
+= abbrev_len
;
5875 part_die
->tag
= abbrev
->tag
;
5876 part_die
->has_children
= abbrev
->has_children
;
5878 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5880 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5882 /* Store the data if it is of an attribute we want to keep in a
5883 partial symbol table. */
5888 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5889 if (part_die
->name
== NULL
)
5890 part_die
->name
= DW_STRING (&attr
);
5892 case DW_AT_comp_dir
:
5893 if (part_die
->dirname
== NULL
)
5894 part_die
->dirname
= DW_STRING (&attr
);
5896 case DW_AT_MIPS_linkage_name
:
5897 part_die
->name
= DW_STRING (&attr
);
5900 has_low_pc_attr
= 1;
5901 part_die
->lowpc
= DW_ADDR (&attr
);
5902 if (part_die
->tag
== DW_TAG_compile_unit
5903 && base_address_type
< base_address_low_pc
)
5905 base_address
= DW_ADDR (&attr
);
5906 base_address_type
= base_address_low_pc
;
5910 has_high_pc_attr
= 1;
5911 part_die
->highpc
= DW_ADDR (&attr
);
5913 case DW_AT_entry_pc
:
5914 if (part_die
->tag
== DW_TAG_compile_unit
5915 && base_address_type
< base_address_entry_pc
)
5917 base_address
= DW_ADDR (&attr
);
5918 base_address_type
= base_address_entry_pc
;
5922 if (part_die
->tag
== DW_TAG_compile_unit
)
5924 cu
->ranges_offset
= DW_UNSND (&attr
);
5925 cu
->has_ranges_offset
= 1;
5928 case DW_AT_location
:
5929 /* Support the .debug_loc offsets */
5930 if (attr_form_is_block (&attr
))
5932 part_die
->locdesc
= DW_BLOCK (&attr
);
5934 else if (attr_form_is_section_offset (&attr
))
5936 dwarf2_complex_location_expr_complaint ();
5940 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5941 "partial symbol information");
5944 case DW_AT_language
:
5945 part_die
->language
= DW_UNSND (&attr
);
5947 case DW_AT_external
:
5948 part_die
->is_external
= DW_UNSND (&attr
);
5950 case DW_AT_declaration
:
5951 part_die
->is_declaration
= DW_UNSND (&attr
);
5954 part_die
->has_type
= 1;
5956 case DW_AT_abstract_origin
:
5957 case DW_AT_specification
:
5958 case DW_AT_extension
:
5959 part_die
->has_specification
= 1;
5960 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
5963 /* Ignore absolute siblings, they might point outside of
5964 the current compile unit. */
5965 if (attr
.form
== DW_FORM_ref_addr
)
5966 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5968 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5969 + dwarf2_get_ref_die_offset (&attr
);
5971 case DW_AT_stmt_list
:
5972 part_die
->has_stmt_list
= 1;
5973 part_die
->line_offset
= DW_UNSND (&attr
);
5975 case DW_AT_byte_size
:
5976 part_die
->has_byte_size
= 1;
5978 case DW_AT_calling_convention
:
5979 /* DWARF doesn't provide a way to identify a program's source-level
5980 entry point. DW_AT_calling_convention attributes are only meant
5981 to describe functions' calling conventions.
5983 However, because it's a necessary piece of information in
5984 Fortran, and because DW_CC_program is the only piece of debugging
5985 information whose definition refers to a 'main program' at all,
5986 several compilers have begun marking Fortran main programs with
5987 DW_CC_program --- even when those functions use the standard
5988 calling conventions.
5990 So until DWARF specifies a way to provide this information and
5991 compilers pick up the new representation, we'll support this
5993 if (DW_UNSND (&attr
) == DW_CC_program
5994 && cu
->language
== language_fortran
)
5995 set_main_name (part_die
->name
);
6002 /* When using the GNU linker, .gnu.linkonce. sections are used to
6003 eliminate duplicate copies of functions and vtables and such.
6004 The linker will arbitrarily choose one and discard the others.
6005 The AT_*_pc values for such functions refer to local labels in
6006 these sections. If the section from that file was discarded, the
6007 labels are not in the output, so the relocs get a value of 0.
6008 If this is a discarded function, mark the pc bounds as invalid,
6009 so that GDB will ignore it. */
6010 if (has_low_pc_attr
&& has_high_pc_attr
6011 && part_die
->lowpc
< part_die
->highpc
6012 && (part_die
->lowpc
!= 0
6013 || dwarf2_per_objfile
->has_section_at_zero
))
6014 part_die
->has_pc_info
= 1;
6016 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6018 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6020 cu
->base_address
= base_address
;
6026 /* Find a cached partial DIE at OFFSET in CU. */
6028 static struct partial_die_info
*
6029 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6031 struct partial_die_info
*lookup_die
= NULL
;
6032 struct partial_die_info part_die
;
6034 part_die
.offset
= offset
;
6035 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6040 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6042 static struct partial_die_info
*
6043 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6045 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6046 struct partial_die_info
*pd
= NULL
;
6048 if (offset_in_cu_p (&cu
->header
, offset
))
6050 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6055 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6057 if (per_cu
->cu
== NULL
)
6059 load_comp_unit (per_cu
, cu
->objfile
);
6060 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6061 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6064 per_cu
->cu
->last_used
= 0;
6065 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6067 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6069 struct cleanup
*back_to
;
6070 struct partial_die_info comp_unit_die
;
6071 struct abbrev_info
*abbrev
;
6072 unsigned int bytes_read
;
6075 per_cu
->load_all_dies
= 1;
6077 /* Re-read the DIEs. */
6078 back_to
= make_cleanup (null_cleanup
, 0);
6079 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6081 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6082 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6084 info_ptr
= (dwarf2_per_objfile
->info_buffer
6085 + per_cu
->cu
->header
.offset
6086 + per_cu
->cu
->header
.first_die_offset
);
6087 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6088 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6089 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6091 if (comp_unit_die
.has_children
)
6092 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6093 do_cleanups (back_to
);
6095 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6099 internal_error (__FILE__
, __LINE__
,
6100 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6101 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6105 /* Adjust PART_DIE before generating a symbol for it. This function
6106 may set the is_external flag or change the DIE's name. */
6109 fixup_partial_die (struct partial_die_info
*part_die
,
6110 struct dwarf2_cu
*cu
)
6112 /* If we found a reference attribute and the DIE has no name, try
6113 to find a name in the referred to DIE. */
6115 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6117 struct partial_die_info
*spec_die
;
6119 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6121 fixup_partial_die (spec_die
, cu
);
6125 part_die
->name
= spec_die
->name
;
6127 /* Copy DW_AT_external attribute if it is set. */
6128 if (spec_die
->is_external
)
6129 part_die
->is_external
= spec_die
->is_external
;
6133 /* Set default names for some unnamed DIEs. */
6134 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6135 || part_die
->tag
== DW_TAG_class_type
))
6136 part_die
->name
= "(anonymous class)";
6138 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6139 part_die
->name
= "(anonymous namespace)";
6141 if (part_die
->tag
== DW_TAG_structure_type
6142 || part_die
->tag
== DW_TAG_class_type
6143 || part_die
->tag
== DW_TAG_union_type
)
6144 guess_structure_name (part_die
, cu
);
6147 /* Read the die from the .debug_info section buffer. Set DIEP to
6148 point to a newly allocated die with its information, except for its
6149 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6150 whether the die has children or not. */
6153 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6154 struct dwarf2_cu
*cu
, int *has_children
)
6156 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6157 struct abbrev_info
*abbrev
;
6158 struct die_info
*die
;
6160 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6161 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6162 info_ptr
+= bytes_read
;
6170 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6173 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6175 bfd_get_filename (abfd
));
6177 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6178 die
->offset
= offset
;
6179 die
->tag
= abbrev
->tag
;
6180 die
->abbrev
= abbrev_number
;
6182 die
->num_attrs
= abbrev
->num_attrs
;
6184 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6185 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6186 abfd
, info_ptr
, cu
);
6189 *has_children
= abbrev
->has_children
;
6193 /* Read an attribute value described by an attribute form. */
6196 read_attribute_value (struct attribute
*attr
, unsigned form
,
6197 bfd
*abfd
, gdb_byte
*info_ptr
,
6198 struct dwarf2_cu
*cu
)
6200 struct comp_unit_head
*cu_header
= &cu
->header
;
6201 unsigned int bytes_read
;
6202 struct dwarf_block
*blk
;
6208 case DW_FORM_ref_addr
:
6209 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6210 info_ptr
+= bytes_read
;
6212 case DW_FORM_block2
:
6213 blk
= dwarf_alloc_block (cu
);
6214 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6216 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6217 info_ptr
+= blk
->size
;
6218 DW_BLOCK (attr
) = blk
;
6220 case DW_FORM_block4
:
6221 blk
= dwarf_alloc_block (cu
);
6222 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6224 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6225 info_ptr
+= blk
->size
;
6226 DW_BLOCK (attr
) = blk
;
6229 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6233 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6237 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6240 case DW_FORM_string
:
6241 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6242 info_ptr
+= bytes_read
;
6245 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6247 info_ptr
+= bytes_read
;
6250 blk
= dwarf_alloc_block (cu
);
6251 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6252 info_ptr
+= bytes_read
;
6253 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6254 info_ptr
+= blk
->size
;
6255 DW_BLOCK (attr
) = blk
;
6257 case DW_FORM_block1
:
6258 blk
= dwarf_alloc_block (cu
);
6259 blk
->size
= read_1_byte (abfd
, info_ptr
);
6261 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6262 info_ptr
+= blk
->size
;
6263 DW_BLOCK (attr
) = blk
;
6266 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6270 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6274 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6275 info_ptr
+= bytes_read
;
6278 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6279 info_ptr
+= bytes_read
;
6282 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6286 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6290 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6294 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6297 case DW_FORM_ref_udata
:
6298 DW_ADDR (attr
) = (cu
->header
.offset
6299 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6300 info_ptr
+= bytes_read
;
6302 case DW_FORM_indirect
:
6303 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6304 info_ptr
+= bytes_read
;
6305 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6308 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6309 dwarf_form_name (form
),
6310 bfd_get_filename (abfd
));
6313 /* We have seen instances where the compiler tried to emit a byte
6314 size attribute of -1 which ended up being encoded as an unsigned
6315 0xffffffff. Although 0xffffffff is technically a valid size value,
6316 an object of this size seems pretty unlikely so we can relatively
6317 safely treat these cases as if the size attribute was invalid and
6318 treat them as zero by default. */
6319 if (attr
->name
== DW_AT_byte_size
6320 && form
== DW_FORM_data4
6321 && DW_UNSND (attr
) >= 0xffffffff)
6324 (&symfile_complaints
,
6325 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6327 DW_UNSND (attr
) = 0;
6333 /* Read an attribute described by an abbreviated attribute. */
6336 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6337 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6339 attr
->name
= abbrev
->name
;
6340 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6343 /* read dwarf information from a buffer */
6346 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6348 return bfd_get_8 (abfd
, buf
);
6352 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6354 return bfd_get_signed_8 (abfd
, buf
);
6358 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6360 return bfd_get_16 (abfd
, buf
);
6364 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6366 return bfd_get_signed_16 (abfd
, buf
);
6370 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6372 return bfd_get_32 (abfd
, buf
);
6376 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6378 return bfd_get_signed_32 (abfd
, buf
);
6381 static unsigned long
6382 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6384 return bfd_get_64 (abfd
, buf
);
6388 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6389 unsigned int *bytes_read
)
6391 struct comp_unit_head
*cu_header
= &cu
->header
;
6392 CORE_ADDR retval
= 0;
6394 if (cu_header
->signed_addr_p
)
6396 switch (cu_header
->addr_size
)
6399 retval
= bfd_get_signed_16 (abfd
, buf
);
6402 retval
= bfd_get_signed_32 (abfd
, buf
);
6405 retval
= bfd_get_signed_64 (abfd
, buf
);
6408 internal_error (__FILE__
, __LINE__
,
6409 _("read_address: bad switch, signed [in module %s]"),
6410 bfd_get_filename (abfd
));
6415 switch (cu_header
->addr_size
)
6418 retval
= bfd_get_16 (abfd
, buf
);
6421 retval
= bfd_get_32 (abfd
, buf
);
6424 retval
= bfd_get_64 (abfd
, buf
);
6427 internal_error (__FILE__
, __LINE__
,
6428 _("read_address: bad switch, unsigned [in module %s]"),
6429 bfd_get_filename (abfd
));
6433 *bytes_read
= cu_header
->addr_size
;
6437 /* Read the initial length from a section. The (draft) DWARF 3
6438 specification allows the initial length to take up either 4 bytes
6439 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6440 bytes describe the length and all offsets will be 8 bytes in length
6443 An older, non-standard 64-bit format is also handled by this
6444 function. The older format in question stores the initial length
6445 as an 8-byte quantity without an escape value. Lengths greater
6446 than 2^32 aren't very common which means that the initial 4 bytes
6447 is almost always zero. Since a length value of zero doesn't make
6448 sense for the 32-bit format, this initial zero can be considered to
6449 be an escape value which indicates the presence of the older 64-bit
6450 format. As written, the code can't detect (old format) lengths
6451 greater than 4GB. If it becomes necessary to handle lengths
6452 somewhat larger than 4GB, we could allow other small values (such
6453 as the non-sensical values of 1, 2, and 3) to also be used as
6454 escape values indicating the presence of the old format.
6456 The value returned via bytes_read should be used to increment the
6457 relevant pointer after calling read_initial_length().
6459 [ Note: read_initial_length() and read_offset() are based on the
6460 document entitled "DWARF Debugging Information Format", revision
6461 3, draft 8, dated November 19, 2001. This document was obtained
6464 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6466 This document is only a draft and is subject to change. (So beware.)
6468 Details regarding the older, non-standard 64-bit format were
6469 determined empirically by examining 64-bit ELF files produced by
6470 the SGI toolchain on an IRIX 6.5 machine.
6472 - Kevin, July 16, 2002
6476 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6478 LONGEST length
= bfd_get_32 (abfd
, buf
);
6480 if (length
== 0xffffffff)
6482 length
= bfd_get_64 (abfd
, buf
+ 4);
6485 else if (length
== 0)
6487 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6488 length
= bfd_get_64 (abfd
, buf
);
6499 /* Cover function for read_initial_length.
6500 Returns the length of the object at BUF, and stores the size of the
6501 initial length in *BYTES_READ and stores the size that offsets will be in
6503 If the initial length size is not equivalent to that specified in
6504 CU_HEADER then issue a complaint.
6505 This is useful when reading non-comp-unit headers. */
6508 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6509 const struct comp_unit_head
*cu_header
,
6510 unsigned int *bytes_read
,
6511 unsigned int *offset_size
)
6513 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6515 gdb_assert (cu_header
->initial_length_size
== 4
6516 || cu_header
->initial_length_size
== 8
6517 || cu_header
->initial_length_size
== 12);
6519 if (cu_header
->initial_length_size
!= *bytes_read
)
6520 complaint (&symfile_complaints
,
6521 _("intermixed 32-bit and 64-bit DWARF sections"));
6523 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6527 /* Read an offset from the data stream. The size of the offset is
6528 given by cu_header->offset_size. */
6531 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6532 unsigned int *bytes_read
)
6534 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6535 *bytes_read
= cu_header
->offset_size
;
6539 /* Read an offset from the data stream. */
6542 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6546 switch (offset_size
)
6549 retval
= bfd_get_32 (abfd
, buf
);
6552 retval
= bfd_get_64 (abfd
, buf
);
6555 internal_error (__FILE__
, __LINE__
,
6556 _("read_offset_1: bad switch [in module %s]"),
6557 bfd_get_filename (abfd
));
6564 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6566 /* If the size of a host char is 8 bits, we can return a pointer
6567 to the buffer, otherwise we have to copy the data to a buffer
6568 allocated on the temporary obstack. */
6569 gdb_assert (HOST_CHAR_BIT
== 8);
6574 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6576 /* If the size of a host char is 8 bits, we can return a pointer
6577 to the string, otherwise we have to copy the string to a buffer
6578 allocated on the temporary obstack. */
6579 gdb_assert (HOST_CHAR_BIT
== 8);
6582 *bytes_read_ptr
= 1;
6585 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6586 return (char *) buf
;
6590 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6591 const struct comp_unit_head
*cu_header
,
6592 unsigned int *bytes_read_ptr
)
6594 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6596 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6598 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6599 bfd_get_filename (abfd
));
6602 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6604 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6605 bfd_get_filename (abfd
));
6608 gdb_assert (HOST_CHAR_BIT
== 8);
6609 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6611 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6614 static unsigned long
6615 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6617 unsigned long result
;
6618 unsigned int num_read
;
6628 byte
= bfd_get_8 (abfd
, buf
);
6631 result
|= ((unsigned long)(byte
& 127) << shift
);
6632 if ((byte
& 128) == 0)
6638 *bytes_read_ptr
= num_read
;
6643 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6646 int i
, shift
, num_read
;
6655 byte
= bfd_get_8 (abfd
, buf
);
6658 result
|= ((long)(byte
& 127) << shift
);
6660 if ((byte
& 128) == 0)
6665 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6666 result
|= -(((long)1) << shift
);
6667 *bytes_read_ptr
= num_read
;
6671 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6674 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6680 byte
= bfd_get_8 (abfd
, buf
);
6682 if ((byte
& 128) == 0)
6688 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6694 cu
->language
= language_c
;
6696 case DW_LANG_C_plus_plus
:
6697 cu
->language
= language_cplus
;
6699 case DW_LANG_Fortran77
:
6700 case DW_LANG_Fortran90
:
6701 case DW_LANG_Fortran95
:
6702 cu
->language
= language_fortran
;
6704 case DW_LANG_Mips_Assembler
:
6705 cu
->language
= language_asm
;
6708 cu
->language
= language_java
;
6712 cu
->language
= language_ada
;
6714 case DW_LANG_Modula2
:
6715 cu
->language
= language_m2
;
6717 case DW_LANG_Pascal83
:
6718 cu
->language
= language_pascal
;
6721 cu
->language
= language_objc
;
6723 case DW_LANG_Cobol74
:
6724 case DW_LANG_Cobol85
:
6726 cu
->language
= language_minimal
;
6729 cu
->language_defn
= language_def (cu
->language
);
6732 /* Return the named attribute or NULL if not there. */
6734 static struct attribute
*
6735 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6738 struct attribute
*spec
= NULL
;
6740 for (i
= 0; i
< die
->num_attrs
; ++i
)
6742 if (die
->attrs
[i
].name
== name
)
6743 return &die
->attrs
[i
];
6744 if (die
->attrs
[i
].name
== DW_AT_specification
6745 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6746 spec
= &die
->attrs
[i
];
6751 die
= follow_die_ref (die
, spec
, &cu
);
6752 return dwarf2_attr (die
, name
, cu
);
6758 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6759 and holds a non-zero value. This function should only be used for
6760 DW_FORM_flag attributes. */
6763 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6765 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6767 return (attr
&& DW_UNSND (attr
));
6771 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6773 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6774 which value is non-zero. However, we have to be careful with
6775 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6776 (via dwarf2_flag_true_p) follows this attribute. So we may
6777 end up accidently finding a declaration attribute that belongs
6778 to a different DIE referenced by the specification attribute,
6779 even though the given DIE does not have a declaration attribute. */
6780 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6781 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6784 /* Return the die giving the specification for DIE, if there is
6785 one. *SPEC_CU is the CU containing DIE on input, and the CU
6786 containing the return value on output. */
6788 static struct die_info
*
6789 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6791 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6794 if (spec_attr
== NULL
)
6797 return follow_die_ref (die
, spec_attr
, spec_cu
);
6800 /* Free the line_header structure *LH, and any arrays and strings it
6803 free_line_header (struct line_header
*lh
)
6805 if (lh
->standard_opcode_lengths
)
6806 xfree (lh
->standard_opcode_lengths
);
6808 /* Remember that all the lh->file_names[i].name pointers are
6809 pointers into debug_line_buffer, and don't need to be freed. */
6811 xfree (lh
->file_names
);
6813 /* Similarly for the include directory names. */
6814 if (lh
->include_dirs
)
6815 xfree (lh
->include_dirs
);
6821 /* Add an entry to LH's include directory table. */
6823 add_include_dir (struct line_header
*lh
, char *include_dir
)
6825 /* Grow the array if necessary. */
6826 if (lh
->include_dirs_size
== 0)
6828 lh
->include_dirs_size
= 1; /* for testing */
6829 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6830 * sizeof (*lh
->include_dirs
));
6832 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6834 lh
->include_dirs_size
*= 2;
6835 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6836 (lh
->include_dirs_size
6837 * sizeof (*lh
->include_dirs
)));
6840 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6844 /* Add an entry to LH's file name table. */
6846 add_file_name (struct line_header
*lh
,
6848 unsigned int dir_index
,
6849 unsigned int mod_time
,
6850 unsigned int length
)
6852 struct file_entry
*fe
;
6854 /* Grow the array if necessary. */
6855 if (lh
->file_names_size
== 0)
6857 lh
->file_names_size
= 1; /* for testing */
6858 lh
->file_names
= xmalloc (lh
->file_names_size
6859 * sizeof (*lh
->file_names
));
6861 else if (lh
->num_file_names
>= lh
->file_names_size
)
6863 lh
->file_names_size
*= 2;
6864 lh
->file_names
= xrealloc (lh
->file_names
,
6865 (lh
->file_names_size
6866 * sizeof (*lh
->file_names
)));
6869 fe
= &lh
->file_names
[lh
->num_file_names
++];
6871 fe
->dir_index
= dir_index
;
6872 fe
->mod_time
= mod_time
;
6873 fe
->length
= length
;
6879 /* Read the statement program header starting at OFFSET in
6880 .debug_line, according to the endianness of ABFD. Return a pointer
6881 to a struct line_header, allocated using xmalloc.
6883 NOTE: the strings in the include directory and file name tables of
6884 the returned object point into debug_line_buffer, and must not be
6886 static struct line_header
*
6887 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6888 struct dwarf2_cu
*cu
)
6890 struct cleanup
*back_to
;
6891 struct line_header
*lh
;
6893 unsigned int bytes_read
, offset_size
;
6895 char *cur_dir
, *cur_file
;
6897 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6899 complaint (&symfile_complaints
, _("missing .debug_line section"));
6903 /* Make sure that at least there's room for the total_length field.
6904 That could be 12 bytes long, but we're just going to fudge that. */
6905 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6907 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6911 lh
= xmalloc (sizeof (*lh
));
6912 memset (lh
, 0, sizeof (*lh
));
6913 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6916 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6918 /* Read in the header. */
6920 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
6921 &bytes_read
, &offset_size
);
6922 line_ptr
+= bytes_read
;
6923 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6924 + dwarf2_per_objfile
->line_size
))
6926 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6929 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6930 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6932 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
6933 line_ptr
+= offset_size
;
6934 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6936 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6938 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6940 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6942 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6944 lh
->standard_opcode_lengths
6945 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6947 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6948 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6950 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6954 /* Read directory table. */
6955 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6957 line_ptr
+= bytes_read
;
6958 add_include_dir (lh
, cur_dir
);
6960 line_ptr
+= bytes_read
;
6962 /* Read file name table. */
6963 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6965 unsigned int dir_index
, mod_time
, length
;
6967 line_ptr
+= bytes_read
;
6968 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6969 line_ptr
+= bytes_read
;
6970 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6971 line_ptr
+= bytes_read
;
6972 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6973 line_ptr
+= bytes_read
;
6975 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6977 line_ptr
+= bytes_read
;
6978 lh
->statement_program_start
= line_ptr
;
6980 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6981 + dwarf2_per_objfile
->line_size
))
6982 complaint (&symfile_complaints
,
6983 _("line number info header doesn't fit in `.debug_line' section"));
6985 discard_cleanups (back_to
);
6989 /* This function exists to work around a bug in certain compilers
6990 (particularly GCC 2.95), in which the first line number marker of a
6991 function does not show up until after the prologue, right before
6992 the second line number marker. This function shifts ADDRESS down
6993 to the beginning of the function if necessary, and is called on
6994 addresses passed to record_line. */
6997 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6999 struct function_range
*fn
;
7001 /* Find the function_range containing address. */
7006 cu
->cached_fn
= cu
->first_fn
;
7010 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7016 while (fn
&& fn
!= cu
->cached_fn
)
7017 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7027 if (address
!= fn
->lowpc
)
7028 complaint (&symfile_complaints
,
7029 _("misplaced first line number at 0x%lx for '%s'"),
7030 (unsigned long) address
, fn
->name
);
7035 /* Decode the Line Number Program (LNP) for the given line_header
7036 structure and CU. The actual information extracted and the type
7037 of structures created from the LNP depends on the value of PST.
7039 1. If PST is NULL, then this procedure uses the data from the program
7040 to create all necessary symbol tables, and their linetables.
7041 The compilation directory of the file is passed in COMP_DIR,
7042 and must not be NULL.
7044 2. If PST is not NULL, this procedure reads the program to determine
7045 the list of files included by the unit represented by PST, and
7046 builds all the associated partial symbol tables. In this case,
7047 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7048 is not used to compute the full name of the symtab, and therefore
7049 omitting it when building the partial symtab does not introduce
7050 the potential for inconsistency - a partial symtab and its associated
7051 symbtab having a different fullname -). */
7054 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7055 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7057 gdb_byte
*line_ptr
, *extended_end
;
7059 unsigned int bytes_read
, extended_len
;
7060 unsigned char op_code
, extended_op
, adj_opcode
;
7062 struct objfile
*objfile
= cu
->objfile
;
7063 const int decode_for_pst_p
= (pst
!= NULL
);
7064 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7066 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7068 line_ptr
= lh
->statement_program_start
;
7069 line_end
= lh
->statement_program_end
;
7071 /* Read the statement sequences until there's nothing left. */
7072 while (line_ptr
< line_end
)
7074 /* state machine registers */
7075 CORE_ADDR address
= 0;
7076 unsigned int file
= 1;
7077 unsigned int line
= 1;
7078 unsigned int column
= 0;
7079 int is_stmt
= lh
->default_is_stmt
;
7080 int basic_block
= 0;
7081 int end_sequence
= 0;
7083 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7085 /* Start a subfile for the current file of the state machine. */
7086 /* lh->include_dirs and lh->file_names are 0-based, but the
7087 directory and file name numbers in the statement program
7089 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7093 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7095 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7098 /* Decode the table. */
7099 while (!end_sequence
)
7101 op_code
= read_1_byte (abfd
, line_ptr
);
7103 if (line_ptr
> line_end
)
7105 dwarf2_debug_line_missing_end_sequence_complaint ();
7109 if (op_code
>= lh
->opcode_base
)
7111 /* Special operand. */
7112 adj_opcode
= op_code
- lh
->opcode_base
;
7113 address
+= (adj_opcode
/ lh
->line_range
)
7114 * lh
->minimum_instruction_length
;
7115 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7116 if (lh
->num_file_names
< file
|| file
== 0)
7117 dwarf2_debug_line_missing_file_complaint ();
7120 lh
->file_names
[file
- 1].included_p
= 1;
7121 if (!decode_for_pst_p
)
7123 if (last_subfile
!= current_subfile
)
7126 record_line (last_subfile
, 0, address
);
7127 last_subfile
= current_subfile
;
7129 /* Append row to matrix using current values. */
7130 record_line (current_subfile
, line
,
7131 check_cu_functions (address
, cu
));
7136 else switch (op_code
)
7138 case DW_LNS_extended_op
:
7139 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7140 line_ptr
+= bytes_read
;
7141 extended_end
= line_ptr
+ extended_len
;
7142 extended_op
= read_1_byte (abfd
, line_ptr
);
7144 switch (extended_op
)
7146 case DW_LNE_end_sequence
:
7149 case DW_LNE_set_address
:
7150 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7151 line_ptr
+= bytes_read
;
7152 address
+= baseaddr
;
7154 case DW_LNE_define_file
:
7157 unsigned int dir_index
, mod_time
, length
;
7159 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7160 line_ptr
+= bytes_read
;
7162 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7163 line_ptr
+= bytes_read
;
7165 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7166 line_ptr
+= bytes_read
;
7168 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7169 line_ptr
+= bytes_read
;
7170 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7174 complaint (&symfile_complaints
,
7175 _("mangled .debug_line section"));
7178 /* Make sure that we parsed the extended op correctly. If e.g.
7179 we expected a different address size than the producer used,
7180 we may have read the wrong number of bytes. */
7181 if (line_ptr
!= extended_end
)
7183 complaint (&symfile_complaints
,
7184 _("mangled .debug_line section"));
7189 if (lh
->num_file_names
< file
|| file
== 0)
7190 dwarf2_debug_line_missing_file_complaint ();
7193 lh
->file_names
[file
- 1].included_p
= 1;
7194 if (!decode_for_pst_p
)
7196 if (last_subfile
!= current_subfile
)
7199 record_line (last_subfile
, 0, address
);
7200 last_subfile
= current_subfile
;
7202 record_line (current_subfile
, line
,
7203 check_cu_functions (address
, cu
));
7208 case DW_LNS_advance_pc
:
7209 address
+= lh
->minimum_instruction_length
7210 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7211 line_ptr
+= bytes_read
;
7213 case DW_LNS_advance_line
:
7214 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7215 line_ptr
+= bytes_read
;
7217 case DW_LNS_set_file
:
7219 /* The arrays lh->include_dirs and lh->file_names are
7220 0-based, but the directory and file name numbers in
7221 the statement program are 1-based. */
7222 struct file_entry
*fe
;
7225 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7226 line_ptr
+= bytes_read
;
7227 if (lh
->num_file_names
< file
|| file
== 0)
7228 dwarf2_debug_line_missing_file_complaint ();
7231 fe
= &lh
->file_names
[file
- 1];
7233 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7234 if (!decode_for_pst_p
)
7236 last_subfile
= current_subfile
;
7237 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7242 case DW_LNS_set_column
:
7243 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7244 line_ptr
+= bytes_read
;
7246 case DW_LNS_negate_stmt
:
7247 is_stmt
= (!is_stmt
);
7249 case DW_LNS_set_basic_block
:
7252 /* Add to the address register of the state machine the
7253 address increment value corresponding to special opcode
7254 255. I.e., this value is scaled by the minimum
7255 instruction length since special opcode 255 would have
7256 scaled the the increment. */
7257 case DW_LNS_const_add_pc
:
7258 address
+= (lh
->minimum_instruction_length
7259 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7261 case DW_LNS_fixed_advance_pc
:
7262 address
+= read_2_bytes (abfd
, line_ptr
);
7267 /* Unknown standard opcode, ignore it. */
7270 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7272 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7273 line_ptr
+= bytes_read
;
7278 if (lh
->num_file_names
< file
|| file
== 0)
7279 dwarf2_debug_line_missing_file_complaint ();
7282 lh
->file_names
[file
- 1].included_p
= 1;
7283 if (!decode_for_pst_p
)
7284 record_line (current_subfile
, 0, address
);
7288 if (decode_for_pst_p
)
7292 /* Now that we're done scanning the Line Header Program, we can
7293 create the psymtab of each included file. */
7294 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7295 if (lh
->file_names
[file_index
].included_p
== 1)
7297 const struct file_entry fe
= lh
->file_names
[file_index
];
7298 char *include_name
= fe
.name
;
7299 char *dir_name
= NULL
;
7300 char *pst_filename
= pst
->filename
;
7303 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7305 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7307 include_name
= concat (dir_name
, SLASH_STRING
,
7308 include_name
, (char *)NULL
);
7309 make_cleanup (xfree
, include_name
);
7312 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7314 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7315 pst_filename
, (char *)NULL
);
7316 make_cleanup (xfree
, pst_filename
);
7319 if (strcmp (include_name
, pst_filename
) != 0)
7320 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7325 /* Make sure a symtab is created for every file, even files
7326 which contain only variables (i.e. no code with associated
7330 struct file_entry
*fe
;
7332 for (i
= 0; i
< lh
->num_file_names
; i
++)
7335 fe
= &lh
->file_names
[i
];
7337 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7338 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7340 /* Skip the main file; we don't need it, and it must be
7341 allocated last, so that it will show up before the
7342 non-primary symtabs in the objfile's symtab list. */
7343 if (current_subfile
== first_subfile
)
7346 if (current_subfile
->symtab
== NULL
)
7347 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7349 fe
->symtab
= current_subfile
->symtab
;
7354 /* Start a subfile for DWARF. FILENAME is the name of the file and
7355 DIRNAME the name of the source directory which contains FILENAME
7356 or NULL if not known. COMP_DIR is the compilation directory for the
7357 linetable's compilation unit or NULL if not known.
7358 This routine tries to keep line numbers from identical absolute and
7359 relative file names in a common subfile.
7361 Using the `list' example from the GDB testsuite, which resides in
7362 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7363 of /srcdir/list0.c yields the following debugging information for list0.c:
7365 DW_AT_name: /srcdir/list0.c
7366 DW_AT_comp_dir: /compdir
7367 files.files[0].name: list0.h
7368 files.files[0].dir: /srcdir
7369 files.files[1].name: list0.c
7370 files.files[1].dir: /srcdir
7372 The line number information for list0.c has to end up in a single
7373 subfile, so that `break /srcdir/list0.c:1' works as expected.
7374 start_subfile will ensure that this happens provided that we pass the
7375 concatenation of files.files[1].dir and files.files[1].name as the
7379 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7383 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7384 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7385 second argument to start_subfile. To be consistent, we do the
7386 same here. In order not to lose the line information directory,
7387 we concatenate it to the filename when it makes sense.
7388 Note that the Dwarf3 standard says (speaking of filenames in line
7389 information): ``The directory index is ignored for file names
7390 that represent full path names''. Thus ignoring dirname in the
7391 `else' branch below isn't an issue. */
7393 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7394 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7396 fullname
= filename
;
7398 start_subfile (fullname
, comp_dir
);
7400 if (fullname
!= filename
)
7405 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7406 struct dwarf2_cu
*cu
)
7408 struct objfile
*objfile
= cu
->objfile
;
7409 struct comp_unit_head
*cu_header
= &cu
->header
;
7411 /* NOTE drow/2003-01-30: There used to be a comment and some special
7412 code here to turn a symbol with DW_AT_external and a
7413 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7414 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7415 with some versions of binutils) where shared libraries could have
7416 relocations against symbols in their debug information - the
7417 minimal symbol would have the right address, but the debug info
7418 would not. It's no longer necessary, because we will explicitly
7419 apply relocations when we read in the debug information now. */
7421 /* A DW_AT_location attribute with no contents indicates that a
7422 variable has been optimized away. */
7423 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7425 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7429 /* Handle one degenerate form of location expression specially, to
7430 preserve GDB's previous behavior when section offsets are
7431 specified. If this is just a DW_OP_addr then mark this symbol
7434 if (attr_form_is_block (attr
)
7435 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7436 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7440 SYMBOL_VALUE_ADDRESS (sym
) =
7441 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7442 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7443 fixup_symbol_section (sym
, objfile
);
7444 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7445 SYMBOL_SECTION (sym
));
7449 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7450 expression evaluator, and use LOC_COMPUTED only when necessary
7451 (i.e. when the value of a register or memory location is
7452 referenced, or a thread-local block, etc.). Then again, it might
7453 not be worthwhile. I'm assuming that it isn't unless performance
7454 or memory numbers show me otherwise. */
7456 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7457 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7460 /* Given a pointer to a DWARF information entry, figure out if we need
7461 to make a symbol table entry for it, and if so, create a new entry
7462 and return a pointer to it.
7463 If TYPE is NULL, determine symbol type from the die, otherwise
7464 used the passed type. */
7466 static struct symbol
*
7467 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7469 struct objfile
*objfile
= cu
->objfile
;
7470 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7471 struct symbol
*sym
= NULL
;
7473 struct attribute
*attr
= NULL
;
7474 struct attribute
*attr2
= NULL
;
7477 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7479 if (die
->tag
!= DW_TAG_namespace
)
7480 name
= dwarf2_linkage_name (die
, cu
);
7482 name
= TYPE_NAME (type
);
7486 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7487 sizeof (struct symbol
));
7488 OBJSTAT (objfile
, n_syms
++);
7489 memset (sym
, 0, sizeof (struct symbol
));
7491 /* Cache this symbol's name and the name's demangled form (if any). */
7492 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7493 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7495 /* Default assumptions.
7496 Use the passed type or decode it from the die. */
7497 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7498 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7500 SYMBOL_TYPE (sym
) = type
;
7502 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7503 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7506 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7509 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7512 int file_index
= DW_UNSND (attr
);
7513 if (cu
->line_header
== NULL
7514 || file_index
> cu
->line_header
->num_file_names
)
7515 complaint (&symfile_complaints
,
7516 _("file index out of range"));
7517 else if (file_index
> 0)
7519 struct file_entry
*fe
;
7520 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7521 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7528 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7531 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7533 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7535 case DW_TAG_subprogram
:
7536 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7538 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7539 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7540 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7541 || cu
->language
== language_ada
)
7543 /* Subprograms marked external are stored as a global symbol.
7544 Ada subprograms, whether marked external or not, are always
7545 stored as a global symbol, because we want to be able to
7546 access them globally. For instance, we want to be able
7547 to break on a nested subprogram without having to
7548 specify the context. */
7549 add_symbol_to_list (sym
, &global_symbols
);
7553 add_symbol_to_list (sym
, cu
->list_in_scope
);
7556 case DW_TAG_variable
:
7557 /* Compilation with minimal debug info may result in variables
7558 with missing type entries. Change the misleading `void' type
7559 to something sensible. */
7560 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7562 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7564 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7567 dwarf2_const_value (attr
, sym
, cu
);
7568 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7569 if (attr2
&& (DW_UNSND (attr2
) != 0))
7570 add_symbol_to_list (sym
, &global_symbols
);
7572 add_symbol_to_list (sym
, cu
->list_in_scope
);
7575 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7578 var_decode_location (attr
, sym
, cu
);
7579 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7580 if (attr2
&& (DW_UNSND (attr2
) != 0))
7581 add_symbol_to_list (sym
, &global_symbols
);
7583 add_symbol_to_list (sym
, cu
->list_in_scope
);
7587 /* We do not know the address of this symbol.
7588 If it is an external symbol and we have type information
7589 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7590 The address of the variable will then be determined from
7591 the minimal symbol table whenever the variable is
7593 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7594 if (attr2
&& (DW_UNSND (attr2
) != 0)
7595 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7597 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7598 add_symbol_to_list (sym
, &global_symbols
);
7602 case DW_TAG_formal_parameter
:
7603 SYMBOL_IS_ARGUMENT (sym
) = 1;
7604 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7607 var_decode_location (attr
, sym
, cu
);
7609 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7612 dwarf2_const_value (attr
, sym
, cu
);
7614 add_symbol_to_list (sym
, cu
->list_in_scope
);
7616 case DW_TAG_unspecified_parameters
:
7617 /* From varargs functions; gdb doesn't seem to have any
7618 interest in this information, so just ignore it for now.
7621 case DW_TAG_class_type
:
7622 case DW_TAG_interface_type
:
7623 case DW_TAG_structure_type
:
7624 case DW_TAG_union_type
:
7625 case DW_TAG_set_type
:
7626 case DW_TAG_enumeration_type
:
7627 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7628 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7630 /* Make sure that the symbol includes appropriate enclosing
7631 classes/namespaces in its name. These are calculated in
7632 read_structure_type, and the correct name is saved in
7635 if (cu
->language
== language_cplus
7636 || cu
->language
== language_java
)
7638 struct type
*type
= SYMBOL_TYPE (sym
);
7640 if (TYPE_TAG_NAME (type
) != NULL
)
7642 /* FIXME: carlton/2003-11-10: Should this use
7643 SYMBOL_SET_NAMES instead? (The same problem also
7644 arises further down in this function.) */
7645 /* The type's name is already allocated along with
7646 this objfile, so we don't need to duplicate it
7648 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7653 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7654 really ever be static objects: otherwise, if you try
7655 to, say, break of a class's method and you're in a file
7656 which doesn't mention that class, it won't work unless
7657 the check for all static symbols in lookup_symbol_aux
7658 saves you. See the OtherFileClass tests in
7659 gdb.c++/namespace.exp. */
7661 struct pending
**list_to_add
;
7663 list_to_add
= (cu
->list_in_scope
== &file_symbols
7664 && (cu
->language
== language_cplus
7665 || cu
->language
== language_java
)
7666 ? &global_symbols
: cu
->list_in_scope
);
7668 add_symbol_to_list (sym
, list_to_add
);
7670 /* The semantics of C++ state that "struct foo { ... }" also
7671 defines a typedef for "foo". A Java class declaration also
7672 defines a typedef for the class. */
7673 if (cu
->language
== language_cplus
7674 || cu
->language
== language_java
7675 || cu
->language
== language_ada
)
7677 /* The symbol's name is already allocated along with
7678 this objfile, so we don't need to duplicate it for
7680 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7681 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7685 case DW_TAG_typedef
:
7686 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7687 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7688 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7689 add_symbol_to_list (sym
, cu
->list_in_scope
);
7691 case DW_TAG_base_type
:
7692 case DW_TAG_subrange_type
:
7693 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7694 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7695 add_symbol_to_list (sym
, cu
->list_in_scope
);
7697 case DW_TAG_enumerator
:
7698 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7699 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7702 dwarf2_const_value (attr
, sym
, cu
);
7705 /* NOTE: carlton/2003-11-10: See comment above in the
7706 DW_TAG_class_type, etc. block. */
7708 struct pending
**list_to_add
;
7710 list_to_add
= (cu
->list_in_scope
== &file_symbols
7711 && (cu
->language
== language_cplus
7712 || cu
->language
== language_java
)
7713 ? &global_symbols
: cu
->list_in_scope
);
7715 add_symbol_to_list (sym
, list_to_add
);
7718 case DW_TAG_namespace
:
7719 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7720 add_symbol_to_list (sym
, &global_symbols
);
7723 /* Not a tag we recognize. Hopefully we aren't processing
7724 trash data, but since we must specifically ignore things
7725 we don't recognize, there is nothing else we should do at
7727 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7728 dwarf_tag_name (die
->tag
));
7732 /* For the benefit of old versions of GCC, check for anonymous
7733 namespaces based on the demangled name. */
7734 if (!processing_has_namespace_info
7735 && cu
->language
== language_cplus
7736 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7737 cp_scan_for_anonymous_namespaces (sym
);
7742 /* Copy constant value from an attribute to a symbol. */
7745 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7746 struct dwarf2_cu
*cu
)
7748 struct objfile
*objfile
= cu
->objfile
;
7749 struct comp_unit_head
*cu_header
= &cu
->header
;
7750 struct dwarf_block
*blk
;
7755 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7756 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7757 cu_header
->addr_size
,
7758 TYPE_LENGTH (SYMBOL_TYPE
7760 SYMBOL_VALUE_BYTES (sym
) =
7761 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7762 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7763 it's body - store_unsigned_integer. */
7764 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7766 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7769 /* DW_STRING is already allocated on the obstack, point directly
7771 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7772 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7774 case DW_FORM_block1
:
7775 case DW_FORM_block2
:
7776 case DW_FORM_block4
:
7778 blk
= DW_BLOCK (attr
);
7779 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7780 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7782 TYPE_LENGTH (SYMBOL_TYPE
7784 SYMBOL_VALUE_BYTES (sym
) =
7785 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7786 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7787 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7790 /* The DW_AT_const_value attributes are supposed to carry the
7791 symbol's value "represented as it would be on the target
7792 architecture." By the time we get here, it's already been
7793 converted to host endianness, so we just need to sign- or
7794 zero-extend it as appropriate. */
7796 dwarf2_const_value_data (attr
, sym
, 8);
7799 dwarf2_const_value_data (attr
, sym
, 16);
7802 dwarf2_const_value_data (attr
, sym
, 32);
7805 dwarf2_const_value_data (attr
, sym
, 64);
7809 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7810 SYMBOL_CLASS (sym
) = LOC_CONST
;
7814 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7815 SYMBOL_CLASS (sym
) = LOC_CONST
;
7819 complaint (&symfile_complaints
,
7820 _("unsupported const value attribute form: '%s'"),
7821 dwarf_form_name (attr
->form
));
7822 SYMBOL_VALUE (sym
) = 0;
7823 SYMBOL_CLASS (sym
) = LOC_CONST
;
7829 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7830 or zero-extend it as appropriate for the symbol's type. */
7832 dwarf2_const_value_data (struct attribute
*attr
,
7836 LONGEST l
= DW_UNSND (attr
);
7838 if (bits
< sizeof (l
) * 8)
7840 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7841 l
&= ((LONGEST
) 1 << bits
) - 1;
7843 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7846 SYMBOL_VALUE (sym
) = l
;
7847 SYMBOL_CLASS (sym
) = LOC_CONST
;
7851 /* Return the type of the die in question using its DW_AT_type attribute. */
7853 static struct type
*
7854 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7856 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7858 struct attribute
*type_attr
;
7859 struct die_info
*type_die
;
7861 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7864 /* A missing DW_AT_type represents a void type. */
7865 return builtin_type (gdbarch
)->builtin_void
;
7868 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7870 type
= tag_type_to_type (type_die
, cu
);
7873 dump_die_for_error (type_die
);
7874 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7880 /* Return the containing type of the die in question using its
7881 DW_AT_containing_type attribute. */
7883 static struct type
*
7884 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7886 struct type
*type
= NULL
;
7887 struct attribute
*type_attr
;
7888 struct die_info
*type_die
= NULL
;
7890 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7893 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7894 type
= tag_type_to_type (type_die
, cu
);
7899 dump_die_for_error (type_die
);
7900 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7906 static struct type
*
7907 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7909 struct type
*this_type
;
7911 this_type
= read_type_die (die
, cu
);
7914 dump_die_for_error (die
);
7915 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7921 static struct type
*
7922 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7924 struct type
*this_type
;
7926 this_type
= get_die_type (die
, cu
);
7932 case DW_TAG_class_type
:
7933 case DW_TAG_interface_type
:
7934 case DW_TAG_structure_type
:
7935 case DW_TAG_union_type
:
7936 this_type
= read_structure_type (die
, cu
);
7938 case DW_TAG_enumeration_type
:
7939 this_type
= read_enumeration_type (die
, cu
);
7941 case DW_TAG_subprogram
:
7942 case DW_TAG_subroutine_type
:
7943 this_type
= read_subroutine_type (die
, cu
);
7945 case DW_TAG_array_type
:
7946 this_type
= read_array_type (die
, cu
);
7948 case DW_TAG_set_type
:
7949 this_type
= read_set_type (die
, cu
);
7951 case DW_TAG_pointer_type
:
7952 this_type
= read_tag_pointer_type (die
, cu
);
7954 case DW_TAG_ptr_to_member_type
:
7955 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7957 case DW_TAG_reference_type
:
7958 this_type
= read_tag_reference_type (die
, cu
);
7960 case DW_TAG_const_type
:
7961 this_type
= read_tag_const_type (die
, cu
);
7963 case DW_TAG_volatile_type
:
7964 this_type
= read_tag_volatile_type (die
, cu
);
7966 case DW_TAG_string_type
:
7967 this_type
= read_tag_string_type (die
, cu
);
7969 case DW_TAG_typedef
:
7970 this_type
= read_typedef (die
, cu
);
7972 case DW_TAG_subrange_type
:
7973 this_type
= read_subrange_type (die
, cu
);
7975 case DW_TAG_base_type
:
7976 this_type
= read_base_type (die
, cu
);
7978 case DW_TAG_unspecified_type
:
7979 this_type
= read_unspecified_type (die
, cu
);
7981 case DW_TAG_namespace
:
7982 this_type
= read_namespace_type (die
, cu
);
7985 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7986 dwarf_tag_name (die
->tag
));
7993 /* Return the name of the namespace/class that DIE is defined within,
7994 or "" if we can't tell. The caller should not xfree the result.
7996 For example, if we're within the method foo() in the following
8006 then determine_prefix on foo's die will return "N::C". */
8009 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8011 struct die_info
*parent
, *spec_die
;
8012 struct dwarf2_cu
*spec_cu
;
8013 struct type
*parent_type
;
8015 if (cu
->language
!= language_cplus
8016 && cu
->language
!= language_java
)
8019 /* We have to be careful in the presence of DW_AT_specification.
8020 For example, with GCC 3.4, given the code
8024 // Definition of N::foo.
8028 then we'll have a tree of DIEs like this:
8030 1: DW_TAG_compile_unit
8031 2: DW_TAG_namespace // N
8032 3: DW_TAG_subprogram // declaration of N::foo
8033 4: DW_TAG_subprogram // definition of N::foo
8034 DW_AT_specification // refers to die #3
8036 Thus, when processing die #4, we have to pretend that we're in
8037 the context of its DW_AT_specification, namely the contex of die
8040 spec_die
= die_specification (die
, &spec_cu
);
8041 if (spec_die
== NULL
)
8042 parent
= die
->parent
;
8045 parent
= spec_die
->parent
;
8052 switch (parent
->tag
)
8054 case DW_TAG_namespace
:
8055 parent_type
= read_type_die (parent
, cu
);
8056 /* We give a name to even anonymous namespaces. */
8057 return TYPE_TAG_NAME (parent_type
);
8058 case DW_TAG_class_type
:
8059 case DW_TAG_interface_type
:
8060 case DW_TAG_structure_type
:
8061 case DW_TAG_union_type
:
8062 parent_type
= read_type_die (parent
, cu
);
8063 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8064 return TYPE_TAG_NAME (parent_type
);
8066 /* An anonymous structure is only allowed non-static data
8067 members; no typedefs, no member functions, et cetera.
8068 So it does not need a prefix. */
8071 return determine_prefix (parent
, cu
);
8075 /* Return a newly-allocated string formed by concatenating PREFIX and
8076 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8077 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8078 perform an obconcat, otherwise allocate storage for the result. The CU argument
8079 is used to determine the language and hence, the appropriate separator. */
8081 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8084 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8085 struct dwarf2_cu
*cu
)
8089 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8091 else if (cu
->language
== language_java
)
8103 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8104 strcpy (retval
, prefix
);
8105 strcat (retval
, sep
);
8106 strcat (retval
, suffix
);
8111 /* We have an obstack. */
8112 return obconcat (obs
, prefix
, sep
, suffix
);
8116 /* Return sibling of die, NULL if no sibling. */
8118 static struct die_info
*
8119 sibling_die (struct die_info
*die
)
8121 return die
->sibling
;
8124 /* Get linkage name of a die, return NULL if not found. */
8127 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8129 struct attribute
*attr
;
8131 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8132 if (attr
&& DW_STRING (attr
))
8133 return DW_STRING (attr
);
8134 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8135 if (attr
&& DW_STRING (attr
))
8136 return DW_STRING (attr
);
8140 /* Get name of a die, return NULL if not found. */
8143 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8145 struct attribute
*attr
;
8147 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8148 if (attr
&& DW_STRING (attr
))
8149 return DW_STRING (attr
);
8153 /* Return the die that this die in an extension of, or NULL if there
8154 is none. *EXT_CU is the CU containing DIE on input, and the CU
8155 containing the return value on output. */
8157 static struct die_info
*
8158 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8160 struct attribute
*attr
;
8162 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8166 return follow_die_ref (die
, attr
, ext_cu
);
8169 /* Convert a DIE tag into its string name. */
8172 dwarf_tag_name (unsigned tag
)
8176 case DW_TAG_padding
:
8177 return "DW_TAG_padding";
8178 case DW_TAG_array_type
:
8179 return "DW_TAG_array_type";
8180 case DW_TAG_class_type
:
8181 return "DW_TAG_class_type";
8182 case DW_TAG_entry_point
:
8183 return "DW_TAG_entry_point";
8184 case DW_TAG_enumeration_type
:
8185 return "DW_TAG_enumeration_type";
8186 case DW_TAG_formal_parameter
:
8187 return "DW_TAG_formal_parameter";
8188 case DW_TAG_imported_declaration
:
8189 return "DW_TAG_imported_declaration";
8191 return "DW_TAG_label";
8192 case DW_TAG_lexical_block
:
8193 return "DW_TAG_lexical_block";
8195 return "DW_TAG_member";
8196 case DW_TAG_pointer_type
:
8197 return "DW_TAG_pointer_type";
8198 case DW_TAG_reference_type
:
8199 return "DW_TAG_reference_type";
8200 case DW_TAG_compile_unit
:
8201 return "DW_TAG_compile_unit";
8202 case DW_TAG_string_type
:
8203 return "DW_TAG_string_type";
8204 case DW_TAG_structure_type
:
8205 return "DW_TAG_structure_type";
8206 case DW_TAG_subroutine_type
:
8207 return "DW_TAG_subroutine_type";
8208 case DW_TAG_typedef
:
8209 return "DW_TAG_typedef";
8210 case DW_TAG_union_type
:
8211 return "DW_TAG_union_type";
8212 case DW_TAG_unspecified_parameters
:
8213 return "DW_TAG_unspecified_parameters";
8214 case DW_TAG_variant
:
8215 return "DW_TAG_variant";
8216 case DW_TAG_common_block
:
8217 return "DW_TAG_common_block";
8218 case DW_TAG_common_inclusion
:
8219 return "DW_TAG_common_inclusion";
8220 case DW_TAG_inheritance
:
8221 return "DW_TAG_inheritance";
8222 case DW_TAG_inlined_subroutine
:
8223 return "DW_TAG_inlined_subroutine";
8225 return "DW_TAG_module";
8226 case DW_TAG_ptr_to_member_type
:
8227 return "DW_TAG_ptr_to_member_type";
8228 case DW_TAG_set_type
:
8229 return "DW_TAG_set_type";
8230 case DW_TAG_subrange_type
:
8231 return "DW_TAG_subrange_type";
8232 case DW_TAG_with_stmt
:
8233 return "DW_TAG_with_stmt";
8234 case DW_TAG_access_declaration
:
8235 return "DW_TAG_access_declaration";
8236 case DW_TAG_base_type
:
8237 return "DW_TAG_base_type";
8238 case DW_TAG_catch_block
:
8239 return "DW_TAG_catch_block";
8240 case DW_TAG_const_type
:
8241 return "DW_TAG_const_type";
8242 case DW_TAG_constant
:
8243 return "DW_TAG_constant";
8244 case DW_TAG_enumerator
:
8245 return "DW_TAG_enumerator";
8246 case DW_TAG_file_type
:
8247 return "DW_TAG_file_type";
8249 return "DW_TAG_friend";
8250 case DW_TAG_namelist
:
8251 return "DW_TAG_namelist";
8252 case DW_TAG_namelist_item
:
8253 return "DW_TAG_namelist_item";
8254 case DW_TAG_packed_type
:
8255 return "DW_TAG_packed_type";
8256 case DW_TAG_subprogram
:
8257 return "DW_TAG_subprogram";
8258 case DW_TAG_template_type_param
:
8259 return "DW_TAG_template_type_param";
8260 case DW_TAG_template_value_param
:
8261 return "DW_TAG_template_value_param";
8262 case DW_TAG_thrown_type
:
8263 return "DW_TAG_thrown_type";
8264 case DW_TAG_try_block
:
8265 return "DW_TAG_try_block";
8266 case DW_TAG_variant_part
:
8267 return "DW_TAG_variant_part";
8268 case DW_TAG_variable
:
8269 return "DW_TAG_variable";
8270 case DW_TAG_volatile_type
:
8271 return "DW_TAG_volatile_type";
8272 case DW_TAG_dwarf_procedure
:
8273 return "DW_TAG_dwarf_procedure";
8274 case DW_TAG_restrict_type
:
8275 return "DW_TAG_restrict_type";
8276 case DW_TAG_interface_type
:
8277 return "DW_TAG_interface_type";
8278 case DW_TAG_namespace
:
8279 return "DW_TAG_namespace";
8280 case DW_TAG_imported_module
:
8281 return "DW_TAG_imported_module";
8282 case DW_TAG_unspecified_type
:
8283 return "DW_TAG_unspecified_type";
8284 case DW_TAG_partial_unit
:
8285 return "DW_TAG_partial_unit";
8286 case DW_TAG_imported_unit
:
8287 return "DW_TAG_imported_unit";
8288 case DW_TAG_condition
:
8289 return "DW_TAG_condition";
8290 case DW_TAG_shared_type
:
8291 return "DW_TAG_shared_type";
8292 case DW_TAG_MIPS_loop
:
8293 return "DW_TAG_MIPS_loop";
8294 case DW_TAG_HP_array_descriptor
:
8295 return "DW_TAG_HP_array_descriptor";
8296 case DW_TAG_format_label
:
8297 return "DW_TAG_format_label";
8298 case DW_TAG_function_template
:
8299 return "DW_TAG_function_template";
8300 case DW_TAG_class_template
:
8301 return "DW_TAG_class_template";
8302 case DW_TAG_GNU_BINCL
:
8303 return "DW_TAG_GNU_BINCL";
8304 case DW_TAG_GNU_EINCL
:
8305 return "DW_TAG_GNU_EINCL";
8306 case DW_TAG_upc_shared_type
:
8307 return "DW_TAG_upc_shared_type";
8308 case DW_TAG_upc_strict_type
:
8309 return "DW_TAG_upc_strict_type";
8310 case DW_TAG_upc_relaxed_type
:
8311 return "DW_TAG_upc_relaxed_type";
8312 case DW_TAG_PGI_kanji_type
:
8313 return "DW_TAG_PGI_kanji_type";
8314 case DW_TAG_PGI_interface_block
:
8315 return "DW_TAG_PGI_interface_block";
8317 return "DW_TAG_<unknown>";
8321 /* Convert a DWARF attribute code into its string name. */
8324 dwarf_attr_name (unsigned attr
)
8329 return "DW_AT_sibling";
8330 case DW_AT_location
:
8331 return "DW_AT_location";
8333 return "DW_AT_name";
8334 case DW_AT_ordering
:
8335 return "DW_AT_ordering";
8336 case DW_AT_subscr_data
:
8337 return "DW_AT_subscr_data";
8338 case DW_AT_byte_size
:
8339 return "DW_AT_byte_size";
8340 case DW_AT_bit_offset
:
8341 return "DW_AT_bit_offset";
8342 case DW_AT_bit_size
:
8343 return "DW_AT_bit_size";
8344 case DW_AT_element_list
:
8345 return "DW_AT_element_list";
8346 case DW_AT_stmt_list
:
8347 return "DW_AT_stmt_list";
8349 return "DW_AT_low_pc";
8351 return "DW_AT_high_pc";
8352 case DW_AT_language
:
8353 return "DW_AT_language";
8355 return "DW_AT_member";
8357 return "DW_AT_discr";
8358 case DW_AT_discr_value
:
8359 return "DW_AT_discr_value";
8360 case DW_AT_visibility
:
8361 return "DW_AT_visibility";
8363 return "DW_AT_import";
8364 case DW_AT_string_length
:
8365 return "DW_AT_string_length";
8366 case DW_AT_common_reference
:
8367 return "DW_AT_common_reference";
8368 case DW_AT_comp_dir
:
8369 return "DW_AT_comp_dir";
8370 case DW_AT_const_value
:
8371 return "DW_AT_const_value";
8372 case DW_AT_containing_type
:
8373 return "DW_AT_containing_type";
8374 case DW_AT_default_value
:
8375 return "DW_AT_default_value";
8377 return "DW_AT_inline";
8378 case DW_AT_is_optional
:
8379 return "DW_AT_is_optional";
8380 case DW_AT_lower_bound
:
8381 return "DW_AT_lower_bound";
8382 case DW_AT_producer
:
8383 return "DW_AT_producer";
8384 case DW_AT_prototyped
:
8385 return "DW_AT_prototyped";
8386 case DW_AT_return_addr
:
8387 return "DW_AT_return_addr";
8388 case DW_AT_start_scope
:
8389 return "DW_AT_start_scope";
8390 case DW_AT_bit_stride
:
8391 return "DW_AT_bit_stride";
8392 case DW_AT_upper_bound
:
8393 return "DW_AT_upper_bound";
8394 case DW_AT_abstract_origin
:
8395 return "DW_AT_abstract_origin";
8396 case DW_AT_accessibility
:
8397 return "DW_AT_accessibility";
8398 case DW_AT_address_class
:
8399 return "DW_AT_address_class";
8400 case DW_AT_artificial
:
8401 return "DW_AT_artificial";
8402 case DW_AT_base_types
:
8403 return "DW_AT_base_types";
8404 case DW_AT_calling_convention
:
8405 return "DW_AT_calling_convention";
8407 return "DW_AT_count";
8408 case DW_AT_data_member_location
:
8409 return "DW_AT_data_member_location";
8410 case DW_AT_decl_column
:
8411 return "DW_AT_decl_column";
8412 case DW_AT_decl_file
:
8413 return "DW_AT_decl_file";
8414 case DW_AT_decl_line
:
8415 return "DW_AT_decl_line";
8416 case DW_AT_declaration
:
8417 return "DW_AT_declaration";
8418 case DW_AT_discr_list
:
8419 return "DW_AT_discr_list";
8420 case DW_AT_encoding
:
8421 return "DW_AT_encoding";
8422 case DW_AT_external
:
8423 return "DW_AT_external";
8424 case DW_AT_frame_base
:
8425 return "DW_AT_frame_base";
8427 return "DW_AT_friend";
8428 case DW_AT_identifier_case
:
8429 return "DW_AT_identifier_case";
8430 case DW_AT_macro_info
:
8431 return "DW_AT_macro_info";
8432 case DW_AT_namelist_items
:
8433 return "DW_AT_namelist_items";
8434 case DW_AT_priority
:
8435 return "DW_AT_priority";
8437 return "DW_AT_segment";
8438 case DW_AT_specification
:
8439 return "DW_AT_specification";
8440 case DW_AT_static_link
:
8441 return "DW_AT_static_link";
8443 return "DW_AT_type";
8444 case DW_AT_use_location
:
8445 return "DW_AT_use_location";
8446 case DW_AT_variable_parameter
:
8447 return "DW_AT_variable_parameter";
8448 case DW_AT_virtuality
:
8449 return "DW_AT_virtuality";
8450 case DW_AT_vtable_elem_location
:
8451 return "DW_AT_vtable_elem_location";
8452 /* DWARF 3 values. */
8453 case DW_AT_allocated
:
8454 return "DW_AT_allocated";
8455 case DW_AT_associated
:
8456 return "DW_AT_associated";
8457 case DW_AT_data_location
:
8458 return "DW_AT_data_location";
8459 case DW_AT_byte_stride
:
8460 return "DW_AT_byte_stride";
8461 case DW_AT_entry_pc
:
8462 return "DW_AT_entry_pc";
8463 case DW_AT_use_UTF8
:
8464 return "DW_AT_use_UTF8";
8465 case DW_AT_extension
:
8466 return "DW_AT_extension";
8468 return "DW_AT_ranges";
8469 case DW_AT_trampoline
:
8470 return "DW_AT_trampoline";
8471 case DW_AT_call_column
:
8472 return "DW_AT_call_column";
8473 case DW_AT_call_file
:
8474 return "DW_AT_call_file";
8475 case DW_AT_call_line
:
8476 return "DW_AT_call_line";
8477 case DW_AT_description
:
8478 return "DW_AT_description";
8479 case DW_AT_binary_scale
:
8480 return "DW_AT_binary_scale";
8481 case DW_AT_decimal_scale
:
8482 return "DW_AT_decimal_scale";
8484 return "DW_AT_small";
8485 case DW_AT_decimal_sign
:
8486 return "DW_AT_decimal_sign";
8487 case DW_AT_digit_count
:
8488 return "DW_AT_digit_count";
8489 case DW_AT_picture_string
:
8490 return "DW_AT_picture_string";
8492 return "DW_AT_mutable";
8493 case DW_AT_threads_scaled
:
8494 return "DW_AT_threads_scaled";
8495 case DW_AT_explicit
:
8496 return "DW_AT_explicit";
8497 case DW_AT_object_pointer
:
8498 return "DW_AT_object_pointer";
8499 case DW_AT_endianity
:
8500 return "DW_AT_endianity";
8501 case DW_AT_elemental
:
8502 return "DW_AT_elemental";
8504 return "DW_AT_pure";
8505 case DW_AT_recursive
:
8506 return "DW_AT_recursive";
8507 /* SGI/MIPS extensions. */
8508 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8509 case DW_AT_MIPS_fde
:
8510 return "DW_AT_MIPS_fde";
8512 case DW_AT_MIPS_loop_begin
:
8513 return "DW_AT_MIPS_loop_begin";
8514 case DW_AT_MIPS_tail_loop_begin
:
8515 return "DW_AT_MIPS_tail_loop_begin";
8516 case DW_AT_MIPS_epilog_begin
:
8517 return "DW_AT_MIPS_epilog_begin";
8518 case DW_AT_MIPS_loop_unroll_factor
:
8519 return "DW_AT_MIPS_loop_unroll_factor";
8520 case DW_AT_MIPS_software_pipeline_depth
:
8521 return "DW_AT_MIPS_software_pipeline_depth";
8522 case DW_AT_MIPS_linkage_name
:
8523 return "DW_AT_MIPS_linkage_name";
8524 case DW_AT_MIPS_stride
:
8525 return "DW_AT_MIPS_stride";
8526 case DW_AT_MIPS_abstract_name
:
8527 return "DW_AT_MIPS_abstract_name";
8528 case DW_AT_MIPS_clone_origin
:
8529 return "DW_AT_MIPS_clone_origin";
8530 case DW_AT_MIPS_has_inlines
:
8531 return "DW_AT_MIPS_has_inlines";
8532 /* HP extensions. */
8533 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8534 case DW_AT_HP_block_index
:
8535 return "DW_AT_HP_block_index";
8537 case DW_AT_HP_unmodifiable
:
8538 return "DW_AT_HP_unmodifiable";
8539 case DW_AT_HP_actuals_stmt_list
:
8540 return "DW_AT_HP_actuals_stmt_list";
8541 case DW_AT_HP_proc_per_section
:
8542 return "DW_AT_HP_proc_per_section";
8543 case DW_AT_HP_raw_data_ptr
:
8544 return "DW_AT_HP_raw_data_ptr";
8545 case DW_AT_HP_pass_by_reference
:
8546 return "DW_AT_HP_pass_by_reference";
8547 case DW_AT_HP_opt_level
:
8548 return "DW_AT_HP_opt_level";
8549 case DW_AT_HP_prof_version_id
:
8550 return "DW_AT_HP_prof_version_id";
8551 case DW_AT_HP_opt_flags
:
8552 return "DW_AT_HP_opt_flags";
8553 case DW_AT_HP_cold_region_low_pc
:
8554 return "DW_AT_HP_cold_region_low_pc";
8555 case DW_AT_HP_cold_region_high_pc
:
8556 return "DW_AT_HP_cold_region_high_pc";
8557 case DW_AT_HP_all_variables_modifiable
:
8558 return "DW_AT_HP_all_variables_modifiable";
8559 case DW_AT_HP_linkage_name
:
8560 return "DW_AT_HP_linkage_name";
8561 case DW_AT_HP_prof_flags
:
8562 return "DW_AT_HP_prof_flags";
8563 /* GNU extensions. */
8564 case DW_AT_sf_names
:
8565 return "DW_AT_sf_names";
8566 case DW_AT_src_info
:
8567 return "DW_AT_src_info";
8568 case DW_AT_mac_info
:
8569 return "DW_AT_mac_info";
8570 case DW_AT_src_coords
:
8571 return "DW_AT_src_coords";
8572 case DW_AT_body_begin
:
8573 return "DW_AT_body_begin";
8574 case DW_AT_body_end
:
8575 return "DW_AT_body_end";
8576 case DW_AT_GNU_vector
:
8577 return "DW_AT_GNU_vector";
8578 /* VMS extensions. */
8579 case DW_AT_VMS_rtnbeg_pd_address
:
8580 return "DW_AT_VMS_rtnbeg_pd_address";
8581 /* UPC extension. */
8582 case DW_AT_upc_threads_scaled
:
8583 return "DW_AT_upc_threads_scaled";
8584 /* PGI (STMicroelectronics) extensions. */
8585 case DW_AT_PGI_lbase
:
8586 return "DW_AT_PGI_lbase";
8587 case DW_AT_PGI_soffset
:
8588 return "DW_AT_PGI_soffset";
8589 case DW_AT_PGI_lstride
:
8590 return "DW_AT_PGI_lstride";
8592 return "DW_AT_<unknown>";
8596 /* Convert a DWARF value form code into its string name. */
8599 dwarf_form_name (unsigned form
)
8604 return "DW_FORM_addr";
8605 case DW_FORM_block2
:
8606 return "DW_FORM_block2";
8607 case DW_FORM_block4
:
8608 return "DW_FORM_block4";
8610 return "DW_FORM_data2";
8612 return "DW_FORM_data4";
8614 return "DW_FORM_data8";
8615 case DW_FORM_string
:
8616 return "DW_FORM_string";
8618 return "DW_FORM_block";
8619 case DW_FORM_block1
:
8620 return "DW_FORM_block1";
8622 return "DW_FORM_data1";
8624 return "DW_FORM_flag";
8626 return "DW_FORM_sdata";
8628 return "DW_FORM_strp";
8630 return "DW_FORM_udata";
8631 case DW_FORM_ref_addr
:
8632 return "DW_FORM_ref_addr";
8634 return "DW_FORM_ref1";
8636 return "DW_FORM_ref2";
8638 return "DW_FORM_ref4";
8640 return "DW_FORM_ref8";
8641 case DW_FORM_ref_udata
:
8642 return "DW_FORM_ref_udata";
8643 case DW_FORM_indirect
:
8644 return "DW_FORM_indirect";
8646 return "DW_FORM_<unknown>";
8650 /* Convert a DWARF stack opcode into its string name. */
8653 dwarf_stack_op_name (unsigned op
)
8658 return "DW_OP_addr";
8660 return "DW_OP_deref";
8662 return "DW_OP_const1u";
8664 return "DW_OP_const1s";
8666 return "DW_OP_const2u";
8668 return "DW_OP_const2s";
8670 return "DW_OP_const4u";
8672 return "DW_OP_const4s";
8674 return "DW_OP_const8u";
8676 return "DW_OP_const8s";
8678 return "DW_OP_constu";
8680 return "DW_OP_consts";
8684 return "DW_OP_drop";
8686 return "DW_OP_over";
8688 return "DW_OP_pick";
8690 return "DW_OP_swap";
8694 return "DW_OP_xderef";
8702 return "DW_OP_minus";
8714 return "DW_OP_plus";
8715 case DW_OP_plus_uconst
:
8716 return "DW_OP_plus_uconst";
8722 return "DW_OP_shra";
8740 return "DW_OP_skip";
8742 return "DW_OP_lit0";
8744 return "DW_OP_lit1";
8746 return "DW_OP_lit2";
8748 return "DW_OP_lit3";
8750 return "DW_OP_lit4";
8752 return "DW_OP_lit5";
8754 return "DW_OP_lit6";
8756 return "DW_OP_lit7";
8758 return "DW_OP_lit8";
8760 return "DW_OP_lit9";
8762 return "DW_OP_lit10";
8764 return "DW_OP_lit11";
8766 return "DW_OP_lit12";
8768 return "DW_OP_lit13";
8770 return "DW_OP_lit14";
8772 return "DW_OP_lit15";
8774 return "DW_OP_lit16";
8776 return "DW_OP_lit17";
8778 return "DW_OP_lit18";
8780 return "DW_OP_lit19";
8782 return "DW_OP_lit20";
8784 return "DW_OP_lit21";
8786 return "DW_OP_lit22";
8788 return "DW_OP_lit23";
8790 return "DW_OP_lit24";
8792 return "DW_OP_lit25";
8794 return "DW_OP_lit26";
8796 return "DW_OP_lit27";
8798 return "DW_OP_lit28";
8800 return "DW_OP_lit29";
8802 return "DW_OP_lit30";
8804 return "DW_OP_lit31";
8806 return "DW_OP_reg0";
8808 return "DW_OP_reg1";
8810 return "DW_OP_reg2";
8812 return "DW_OP_reg3";
8814 return "DW_OP_reg4";
8816 return "DW_OP_reg5";
8818 return "DW_OP_reg6";
8820 return "DW_OP_reg7";
8822 return "DW_OP_reg8";
8824 return "DW_OP_reg9";
8826 return "DW_OP_reg10";
8828 return "DW_OP_reg11";
8830 return "DW_OP_reg12";
8832 return "DW_OP_reg13";
8834 return "DW_OP_reg14";
8836 return "DW_OP_reg15";
8838 return "DW_OP_reg16";
8840 return "DW_OP_reg17";
8842 return "DW_OP_reg18";
8844 return "DW_OP_reg19";
8846 return "DW_OP_reg20";
8848 return "DW_OP_reg21";
8850 return "DW_OP_reg22";
8852 return "DW_OP_reg23";
8854 return "DW_OP_reg24";
8856 return "DW_OP_reg25";
8858 return "DW_OP_reg26";
8860 return "DW_OP_reg27";
8862 return "DW_OP_reg28";
8864 return "DW_OP_reg29";
8866 return "DW_OP_reg30";
8868 return "DW_OP_reg31";
8870 return "DW_OP_breg0";
8872 return "DW_OP_breg1";
8874 return "DW_OP_breg2";
8876 return "DW_OP_breg3";
8878 return "DW_OP_breg4";
8880 return "DW_OP_breg5";
8882 return "DW_OP_breg6";
8884 return "DW_OP_breg7";
8886 return "DW_OP_breg8";
8888 return "DW_OP_breg9";
8890 return "DW_OP_breg10";
8892 return "DW_OP_breg11";
8894 return "DW_OP_breg12";
8896 return "DW_OP_breg13";
8898 return "DW_OP_breg14";
8900 return "DW_OP_breg15";
8902 return "DW_OP_breg16";
8904 return "DW_OP_breg17";
8906 return "DW_OP_breg18";
8908 return "DW_OP_breg19";
8910 return "DW_OP_breg20";
8912 return "DW_OP_breg21";
8914 return "DW_OP_breg22";
8916 return "DW_OP_breg23";
8918 return "DW_OP_breg24";
8920 return "DW_OP_breg25";
8922 return "DW_OP_breg26";
8924 return "DW_OP_breg27";
8926 return "DW_OP_breg28";
8928 return "DW_OP_breg29";
8930 return "DW_OP_breg30";
8932 return "DW_OP_breg31";
8934 return "DW_OP_regx";
8936 return "DW_OP_fbreg";
8938 return "DW_OP_bregx";
8940 return "DW_OP_piece";
8941 case DW_OP_deref_size
:
8942 return "DW_OP_deref_size";
8943 case DW_OP_xderef_size
:
8944 return "DW_OP_xderef_size";
8947 /* DWARF 3 extensions. */
8948 case DW_OP_push_object_address
:
8949 return "DW_OP_push_object_address";
8951 return "DW_OP_call2";
8953 return "DW_OP_call4";
8954 case DW_OP_call_ref
:
8955 return "DW_OP_call_ref";
8956 /* GNU extensions. */
8957 case DW_OP_form_tls_address
:
8958 return "DW_OP_form_tls_address";
8959 case DW_OP_call_frame_cfa
:
8960 return "DW_OP_call_frame_cfa";
8961 case DW_OP_bit_piece
:
8962 return "DW_OP_bit_piece";
8963 case DW_OP_GNU_push_tls_address
:
8964 return "DW_OP_GNU_push_tls_address";
8965 case DW_OP_GNU_uninit
:
8966 return "DW_OP_GNU_uninit";
8967 /* HP extensions. */
8968 case DW_OP_HP_is_value
:
8969 return "DW_OP_HP_is_value";
8970 case DW_OP_HP_fltconst4
:
8971 return "DW_OP_HP_fltconst4";
8972 case DW_OP_HP_fltconst8
:
8973 return "DW_OP_HP_fltconst8";
8974 case DW_OP_HP_mod_range
:
8975 return "DW_OP_HP_mod_range";
8976 case DW_OP_HP_unmod_range
:
8977 return "DW_OP_HP_unmod_range";
8979 return "DW_OP_HP_tls";
8981 return "OP_<unknown>";
8986 dwarf_bool_name (unsigned mybool
)
8994 /* Convert a DWARF type code into its string name. */
8997 dwarf_type_encoding_name (unsigned enc
)
9002 return "DW_ATE_void";
9003 case DW_ATE_address
:
9004 return "DW_ATE_address";
9005 case DW_ATE_boolean
:
9006 return "DW_ATE_boolean";
9007 case DW_ATE_complex_float
:
9008 return "DW_ATE_complex_float";
9010 return "DW_ATE_float";
9012 return "DW_ATE_signed";
9013 case DW_ATE_signed_char
:
9014 return "DW_ATE_signed_char";
9015 case DW_ATE_unsigned
:
9016 return "DW_ATE_unsigned";
9017 case DW_ATE_unsigned_char
:
9018 return "DW_ATE_unsigned_char";
9020 case DW_ATE_imaginary_float
:
9021 return "DW_ATE_imaginary_float";
9022 case DW_ATE_packed_decimal
:
9023 return "DW_ATE_packed_decimal";
9024 case DW_ATE_numeric_string
:
9025 return "DW_ATE_numeric_string";
9027 return "DW_ATE_edited";
9028 case DW_ATE_signed_fixed
:
9029 return "DW_ATE_signed_fixed";
9030 case DW_ATE_unsigned_fixed
:
9031 return "DW_ATE_unsigned_fixed";
9032 case DW_ATE_decimal_float
:
9033 return "DW_ATE_decimal_float";
9034 /* HP extensions. */
9035 case DW_ATE_HP_float80
:
9036 return "DW_ATE_HP_float80";
9037 case DW_ATE_HP_complex_float80
:
9038 return "DW_ATE_HP_complex_float80";
9039 case DW_ATE_HP_float128
:
9040 return "DW_ATE_HP_float128";
9041 case DW_ATE_HP_complex_float128
:
9042 return "DW_ATE_HP_complex_float128";
9043 case DW_ATE_HP_floathpintel
:
9044 return "DW_ATE_HP_floathpintel";
9045 case DW_ATE_HP_imaginary_float80
:
9046 return "DW_ATE_HP_imaginary_float80";
9047 case DW_ATE_HP_imaginary_float128
:
9048 return "DW_ATE_HP_imaginary_float128";
9050 return "DW_ATE_<unknown>";
9054 /* Convert a DWARF call frame info operation to its string name. */
9058 dwarf_cfi_name (unsigned cfi_opc
)
9062 case DW_CFA_advance_loc
:
9063 return "DW_CFA_advance_loc";
9065 return "DW_CFA_offset";
9066 case DW_CFA_restore
:
9067 return "DW_CFA_restore";
9069 return "DW_CFA_nop";
9070 case DW_CFA_set_loc
:
9071 return "DW_CFA_set_loc";
9072 case DW_CFA_advance_loc1
:
9073 return "DW_CFA_advance_loc1";
9074 case DW_CFA_advance_loc2
:
9075 return "DW_CFA_advance_loc2";
9076 case DW_CFA_advance_loc4
:
9077 return "DW_CFA_advance_loc4";
9078 case DW_CFA_offset_extended
:
9079 return "DW_CFA_offset_extended";
9080 case DW_CFA_restore_extended
:
9081 return "DW_CFA_restore_extended";
9082 case DW_CFA_undefined
:
9083 return "DW_CFA_undefined";
9084 case DW_CFA_same_value
:
9085 return "DW_CFA_same_value";
9086 case DW_CFA_register
:
9087 return "DW_CFA_register";
9088 case DW_CFA_remember_state
:
9089 return "DW_CFA_remember_state";
9090 case DW_CFA_restore_state
:
9091 return "DW_CFA_restore_state";
9092 case DW_CFA_def_cfa
:
9093 return "DW_CFA_def_cfa";
9094 case DW_CFA_def_cfa_register
:
9095 return "DW_CFA_def_cfa_register";
9096 case DW_CFA_def_cfa_offset
:
9097 return "DW_CFA_def_cfa_offset";
9099 case DW_CFA_def_cfa_expression
:
9100 return "DW_CFA_def_cfa_expression";
9101 case DW_CFA_expression
:
9102 return "DW_CFA_expression";
9103 case DW_CFA_offset_extended_sf
:
9104 return "DW_CFA_offset_extended_sf";
9105 case DW_CFA_def_cfa_sf
:
9106 return "DW_CFA_def_cfa_sf";
9107 case DW_CFA_def_cfa_offset_sf
:
9108 return "DW_CFA_def_cfa_offset_sf";
9109 case DW_CFA_val_offset
:
9110 return "DW_CFA_val_offset";
9111 case DW_CFA_val_offset_sf
:
9112 return "DW_CFA_val_offset_sf";
9113 case DW_CFA_val_expression
:
9114 return "DW_CFA_val_expression";
9115 /* SGI/MIPS specific. */
9116 case DW_CFA_MIPS_advance_loc8
:
9117 return "DW_CFA_MIPS_advance_loc8";
9118 /* GNU extensions. */
9119 case DW_CFA_GNU_window_save
:
9120 return "DW_CFA_GNU_window_save";
9121 case DW_CFA_GNU_args_size
:
9122 return "DW_CFA_GNU_args_size";
9123 case DW_CFA_GNU_negative_offset_extended
:
9124 return "DW_CFA_GNU_negative_offset_extended";
9126 return "DW_CFA_<unknown>";
9132 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9136 print_spaces (indent
, f
);
9137 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9138 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9140 if (die
->parent
!= NULL
)
9142 print_spaces (indent
, f
);
9143 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9144 die
->parent
->offset
);
9147 print_spaces (indent
, f
);
9148 fprintf_unfiltered (f
, " has children: %s\n",
9149 dwarf_bool_name (die
->child
!= NULL
));
9151 print_spaces (indent
, f
);
9152 fprintf_unfiltered (f
, " attributes:\n");
9154 for (i
= 0; i
< die
->num_attrs
; ++i
)
9156 print_spaces (indent
, f
);
9157 fprintf_unfiltered (f
, " %s (%s) ",
9158 dwarf_attr_name (die
->attrs
[i
].name
),
9159 dwarf_form_name (die
->attrs
[i
].form
));
9161 switch (die
->attrs
[i
].form
)
9163 case DW_FORM_ref_addr
:
9165 fprintf_unfiltered (f
, "address: ");
9166 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9168 case DW_FORM_block2
:
9169 case DW_FORM_block4
:
9171 case DW_FORM_block1
:
9172 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9177 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9178 (long) (DW_ADDR (&die
->attrs
[i
])));
9186 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9188 case DW_FORM_string
:
9190 fprintf_unfiltered (f
, "string: \"%s\"",
9191 DW_STRING (&die
->attrs
[i
])
9192 ? DW_STRING (&die
->attrs
[i
]) : "");
9195 if (DW_UNSND (&die
->attrs
[i
]))
9196 fprintf_unfiltered (f
, "flag: TRUE");
9198 fprintf_unfiltered (f
, "flag: FALSE");
9200 case DW_FORM_indirect
:
9201 /* the reader will have reduced the indirect form to
9202 the "base form" so this form should not occur */
9203 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9206 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9207 die
->attrs
[i
].form
);
9210 fprintf_unfiltered (f
, "\n");
9215 dump_die_for_error (struct die_info
*die
)
9217 dump_die_shallow (gdb_stderr
, 0, die
);
9221 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9223 int indent
= level
* 4;
9225 gdb_assert (die
!= NULL
);
9227 if (level
>= max_level
)
9230 dump_die_shallow (f
, indent
, die
);
9232 if (die
->child
!= NULL
)
9234 print_spaces (indent
, f
);
9235 fprintf_unfiltered (f
, " Children:");
9236 if (level
+ 1 < max_level
)
9238 fprintf_unfiltered (f
, "\n");
9239 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9243 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9247 if (die
->sibling
!= NULL
&& level
> 0)
9249 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9253 /* This is called from the pdie macro in gdbinit.in.
9254 It's not static so gcc will keep a copy callable from gdb. */
9257 dump_die (struct die_info
*die
, int max_level
)
9259 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9263 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9267 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9273 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9275 unsigned int result
= 0;
9279 case DW_FORM_ref_addr
:
9284 case DW_FORM_ref_udata
:
9285 result
= DW_ADDR (attr
);
9288 complaint (&symfile_complaints
,
9289 _("unsupported die ref attribute form: '%s'"),
9290 dwarf_form_name (attr
->form
));
9295 /* Return the constant value held by the given attribute. Return -1
9296 if the value held by the attribute is not constant. */
9299 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9301 if (attr
->form
== DW_FORM_sdata
)
9302 return DW_SND (attr
);
9303 else if (attr
->form
== DW_FORM_udata
9304 || attr
->form
== DW_FORM_data1
9305 || attr
->form
== DW_FORM_data2
9306 || attr
->form
== DW_FORM_data4
9307 || attr
->form
== DW_FORM_data8
)
9308 return DW_UNSND (attr
);
9311 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9312 dwarf_form_name (attr
->form
));
9313 return default_value
;
9317 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9318 unit and add it to our queue. */
9321 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9322 struct dwarf2_per_cu_data
*per_cu
)
9324 /* Mark the dependence relation so that we don't flush PER_CU
9326 dwarf2_add_dependence (this_cu
, per_cu
);
9328 /* If it's already on the queue, we have nothing to do. */
9332 /* If the compilation unit is already loaded, just mark it as
9334 if (per_cu
->cu
!= NULL
)
9336 per_cu
->cu
->last_used
= 0;
9340 /* Add it to the queue. */
9341 queue_comp_unit (per_cu
, this_cu
->objfile
);
9344 static struct die_info
*
9345 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9346 struct dwarf2_cu
**ref_cu
)
9348 struct die_info
*die
;
9349 unsigned int offset
;
9350 struct die_info temp_die
;
9351 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9353 offset
= dwarf2_get_ref_die_offset (attr
);
9355 if (! offset_in_cu_p (&cu
->header
, offset
))
9357 struct dwarf2_per_cu_data
*per_cu
;
9358 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9360 /* If necessary, add it to the queue and load its DIEs. */
9361 maybe_queue_comp_unit (cu
, per_cu
);
9363 target_cu
= per_cu
->cu
;
9368 *ref_cu
= target_cu
;
9369 temp_die
.offset
= offset
;
9370 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9374 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9375 "at 0x%lx [in module %s]"),
9376 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9379 /* Decode simple location descriptions.
9380 Given a pointer to a dwarf block that defines a location, compute
9381 the location and return the value.
9383 NOTE drow/2003-11-18: This function is called in two situations
9384 now: for the address of static or global variables (partial symbols
9385 only) and for offsets into structures which are expected to be
9386 (more or less) constant. The partial symbol case should go away,
9387 and only the constant case should remain. That will let this
9388 function complain more accurately. A few special modes are allowed
9389 without complaint for global variables (for instance, global
9390 register values and thread-local values).
9392 A location description containing no operations indicates that the
9393 object is optimized out. The return value is 0 for that case.
9394 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9395 callers will only want a very basic result and this can become a
9398 Note that stack[0] is unused except as a default error return.
9399 Note that stack overflow is not yet handled. */
9402 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9404 struct objfile
*objfile
= cu
->objfile
;
9405 struct comp_unit_head
*cu_header
= &cu
->header
;
9407 int size
= blk
->size
;
9408 gdb_byte
*data
= blk
->data
;
9409 CORE_ADDR stack
[64];
9411 unsigned int bytes_read
, unsnd
;
9455 stack
[++stacki
] = op
- DW_OP_lit0
;
9490 stack
[++stacki
] = op
- DW_OP_reg0
;
9492 dwarf2_complex_location_expr_complaint ();
9496 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9498 stack
[++stacki
] = unsnd
;
9500 dwarf2_complex_location_expr_complaint ();
9504 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9510 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9515 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9520 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9525 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9530 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9535 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9540 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9546 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9551 stack
[stacki
+ 1] = stack
[stacki
];
9556 stack
[stacki
- 1] += stack
[stacki
];
9560 case DW_OP_plus_uconst
:
9561 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9566 stack
[stacki
- 1] -= stack
[stacki
];
9571 /* If we're not the last op, then we definitely can't encode
9572 this using GDB's address_class enum. This is valid for partial
9573 global symbols, although the variable's address will be bogus
9576 dwarf2_complex_location_expr_complaint ();
9579 case DW_OP_GNU_push_tls_address
:
9580 /* The top of the stack has the offset from the beginning
9581 of the thread control block at which the variable is located. */
9582 /* Nothing should follow this operator, so the top of stack would
9584 /* This is valid for partial global symbols, but the variable's
9585 address will be bogus in the psymtab. */
9587 dwarf2_complex_location_expr_complaint ();
9590 case DW_OP_GNU_uninit
:
9594 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9595 dwarf_stack_op_name (op
));
9596 return (stack
[stacki
]);
9599 return (stack
[stacki
]);
9602 /* memory allocation interface */
9604 static struct dwarf_block
*
9605 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9607 struct dwarf_block
*blk
;
9609 blk
= (struct dwarf_block
*)
9610 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9614 static struct abbrev_info
*
9615 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9617 struct abbrev_info
*abbrev
;
9619 abbrev
= (struct abbrev_info
*)
9620 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9621 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9625 static struct die_info
*
9626 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9628 struct die_info
*die
;
9629 size_t size
= sizeof (struct die_info
);
9632 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9634 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9635 memset (die
, 0, sizeof (struct die_info
));
9640 /* Macro support. */
9643 /* Return the full name of file number I in *LH's file name table.
9644 Use COMP_DIR as the name of the current directory of the
9645 compilation. The result is allocated using xmalloc; the caller is
9646 responsible for freeing it. */
9648 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9650 /* Is the file number a valid index into the line header's file name
9651 table? Remember that file numbers start with one, not zero. */
9652 if (1 <= file
&& file
<= lh
->num_file_names
)
9654 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9656 if (IS_ABSOLUTE_PATH (fe
->name
))
9657 return xstrdup (fe
->name
);
9665 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9671 dir_len
= strlen (dir
);
9672 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9673 strcpy (full_name
, dir
);
9674 full_name
[dir_len
] = '/';
9675 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9679 return xstrdup (fe
->name
);
9684 /* The compiler produced a bogus file number. We can at least
9685 record the macro definitions made in the file, even if we
9686 won't be able to find the file by name. */
9688 sprintf (fake_name
, "<bad macro file number %d>", file
);
9690 complaint (&symfile_complaints
,
9691 _("bad file number in macro information (%d)"),
9694 return xstrdup (fake_name
);
9699 static struct macro_source_file
*
9700 macro_start_file (int file
, int line
,
9701 struct macro_source_file
*current_file
,
9702 const char *comp_dir
,
9703 struct line_header
*lh
, struct objfile
*objfile
)
9705 /* The full name of this source file. */
9706 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9708 /* We don't create a macro table for this compilation unit
9709 at all until we actually get a filename. */
9710 if (! pending_macros
)
9711 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9712 objfile
->macro_cache
);
9715 /* If we have no current file, then this must be the start_file
9716 directive for the compilation unit's main source file. */
9717 current_file
= macro_set_main (pending_macros
, full_name
);
9719 current_file
= macro_include (current_file
, line
, full_name
);
9723 return current_file
;
9727 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9728 followed by a null byte. */
9730 copy_string (const char *buf
, int len
)
9732 char *s
= xmalloc (len
+ 1);
9733 memcpy (s
, buf
, len
);
9741 consume_improper_spaces (const char *p
, const char *body
)
9745 complaint (&symfile_complaints
,
9746 _("macro definition contains spaces in formal argument list:\n`%s'"),
9758 parse_macro_definition (struct macro_source_file
*file
, int line
,
9763 /* The body string takes one of two forms. For object-like macro
9764 definitions, it should be:
9766 <macro name> " " <definition>
9768 For function-like macro definitions, it should be:
9770 <macro name> "() " <definition>
9772 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9774 Spaces may appear only where explicitly indicated, and in the
9777 The Dwarf 2 spec says that an object-like macro's name is always
9778 followed by a space, but versions of GCC around March 2002 omit
9779 the space when the macro's definition is the empty string.
9781 The Dwarf 2 spec says that there should be no spaces between the
9782 formal arguments in a function-like macro's formal argument list,
9783 but versions of GCC around March 2002 include spaces after the
9787 /* Find the extent of the macro name. The macro name is terminated
9788 by either a space or null character (for an object-like macro) or
9789 an opening paren (for a function-like macro). */
9790 for (p
= body
; *p
; p
++)
9791 if (*p
== ' ' || *p
== '(')
9794 if (*p
== ' ' || *p
== '\0')
9796 /* It's an object-like macro. */
9797 int name_len
= p
- body
;
9798 char *name
= copy_string (body
, name_len
);
9799 const char *replacement
;
9802 replacement
= body
+ name_len
+ 1;
9805 dwarf2_macro_malformed_definition_complaint (body
);
9806 replacement
= body
+ name_len
;
9809 macro_define_object (file
, line
, name
, replacement
);
9815 /* It's a function-like macro. */
9816 char *name
= copy_string (body
, p
- body
);
9819 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9823 p
= consume_improper_spaces (p
, body
);
9825 /* Parse the formal argument list. */
9826 while (*p
&& *p
!= ')')
9828 /* Find the extent of the current argument name. */
9829 const char *arg_start
= p
;
9831 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9834 if (! *p
|| p
== arg_start
)
9835 dwarf2_macro_malformed_definition_complaint (body
);
9838 /* Make sure argv has room for the new argument. */
9839 if (argc
>= argv_size
)
9842 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9845 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9848 p
= consume_improper_spaces (p
, body
);
9850 /* Consume the comma, if present. */
9855 p
= consume_improper_spaces (p
, body
);
9864 /* Perfectly formed definition, no complaints. */
9865 macro_define_function (file
, line
, name
,
9866 argc
, (const char **) argv
,
9868 else if (*p
== '\0')
9870 /* Complain, but do define it. */
9871 dwarf2_macro_malformed_definition_complaint (body
);
9872 macro_define_function (file
, line
, name
,
9873 argc
, (const char **) argv
,
9877 /* Just complain. */
9878 dwarf2_macro_malformed_definition_complaint (body
);
9881 /* Just complain. */
9882 dwarf2_macro_malformed_definition_complaint (body
);
9888 for (i
= 0; i
< argc
; i
++)
9894 dwarf2_macro_malformed_definition_complaint (body
);
9899 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9900 char *comp_dir
, bfd
*abfd
,
9901 struct dwarf2_cu
*cu
)
9903 gdb_byte
*mac_ptr
, *mac_end
;
9904 struct macro_source_file
*current_file
= 0;
9906 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9908 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9912 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9913 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9914 + dwarf2_per_objfile
->macinfo_size
;
9918 enum dwarf_macinfo_record_type macinfo_type
;
9920 /* Do we at least have room for a macinfo type byte? */
9921 if (mac_ptr
>= mac_end
)
9923 dwarf2_macros_too_long_complaint ();
9927 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9930 switch (macinfo_type
)
9932 /* A zero macinfo type indicates the end of the macro
9937 case DW_MACINFO_define
:
9938 case DW_MACINFO_undef
:
9940 unsigned int bytes_read
;
9944 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9945 mac_ptr
+= bytes_read
;
9946 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9947 mac_ptr
+= bytes_read
;
9950 complaint (&symfile_complaints
,
9951 _("debug info gives macro %s outside of any file: %s"),
9953 DW_MACINFO_define
? "definition" : macinfo_type
==
9954 DW_MACINFO_undef
? "undefinition" :
9955 "something-or-other", body
);
9958 if (macinfo_type
== DW_MACINFO_define
)
9959 parse_macro_definition (current_file
, line
, body
);
9960 else if (macinfo_type
== DW_MACINFO_undef
)
9961 macro_undef (current_file
, line
, body
);
9966 case DW_MACINFO_start_file
:
9968 unsigned int bytes_read
;
9971 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9972 mac_ptr
+= bytes_read
;
9973 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9974 mac_ptr
+= bytes_read
;
9976 current_file
= macro_start_file (file
, line
,
9977 current_file
, comp_dir
,
9982 case DW_MACINFO_end_file
:
9984 complaint (&symfile_complaints
,
9985 _("macro debug info has an unmatched `close_file' directive"));
9988 current_file
= current_file
->included_by
;
9991 enum dwarf_macinfo_record_type next_type
;
9993 /* GCC circa March 2002 doesn't produce the zero
9994 type byte marking the end of the compilation
9995 unit. Complain if it's not there, but exit no
9998 /* Do we at least have room for a macinfo type byte? */
9999 if (mac_ptr
>= mac_end
)
10001 dwarf2_macros_too_long_complaint ();
10005 /* We don't increment mac_ptr here, so this is just
10007 next_type
= read_1_byte (abfd
, mac_ptr
);
10008 if (next_type
!= 0)
10009 complaint (&symfile_complaints
,
10010 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10017 case DW_MACINFO_vendor_ext
:
10019 unsigned int bytes_read
;
10023 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10024 mac_ptr
+= bytes_read
;
10025 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10026 mac_ptr
+= bytes_read
;
10028 /* We don't recognize any vendor extensions. */
10035 /* Check if the attribute's form is a DW_FORM_block*
10036 if so return true else false. */
10038 attr_form_is_block (struct attribute
*attr
)
10040 return (attr
== NULL
? 0 :
10041 attr
->form
== DW_FORM_block1
10042 || attr
->form
== DW_FORM_block2
10043 || attr
->form
== DW_FORM_block4
10044 || attr
->form
== DW_FORM_block
);
10047 /* Return non-zero if ATTR's value is a section offset --- classes
10048 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10049 You may use DW_UNSND (attr) to retrieve such offsets.
10051 Section 7.5.4, "Attribute Encodings", explains that no attribute
10052 may have a value that belongs to more than one of these classes; it
10053 would be ambiguous if we did, because we use the same forms for all
10056 attr_form_is_section_offset (struct attribute
*attr
)
10058 return (attr
->form
== DW_FORM_data4
10059 || attr
->form
== DW_FORM_data8
);
10063 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10064 zero otherwise. When this function returns true, you can apply
10065 dwarf2_get_attr_constant_value to it.
10067 However, note that for some attributes you must check
10068 attr_form_is_section_offset before using this test. DW_FORM_data4
10069 and DW_FORM_data8 are members of both the constant class, and of
10070 the classes that contain offsets into other debug sections
10071 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10072 that, if an attribute's can be either a constant or one of the
10073 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10074 taken as section offsets, not constants. */
10076 attr_form_is_constant (struct attribute
*attr
)
10078 switch (attr
->form
)
10080 case DW_FORM_sdata
:
10081 case DW_FORM_udata
:
10082 case DW_FORM_data1
:
10083 case DW_FORM_data2
:
10084 case DW_FORM_data4
:
10085 case DW_FORM_data8
:
10093 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10094 struct dwarf2_cu
*cu
)
10096 if (attr_form_is_section_offset (attr
)
10097 /* ".debug_loc" may not exist at all, or the offset may be outside
10098 the section. If so, fall through to the complaint in the
10100 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10102 struct dwarf2_loclist_baton
*baton
;
10104 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10105 sizeof (struct dwarf2_loclist_baton
));
10106 baton
->per_cu
= cu
->per_cu
;
10107 gdb_assert (baton
->per_cu
);
10109 /* We don't know how long the location list is, but make sure we
10110 don't run off the edge of the section. */
10111 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10112 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10113 baton
->base_address
= cu
->base_address
;
10114 if (cu
->base_known
== 0)
10115 complaint (&symfile_complaints
,
10116 _("Location list used without specifying the CU base address."));
10118 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10119 SYMBOL_LOCATION_BATON (sym
) = baton
;
10123 struct dwarf2_locexpr_baton
*baton
;
10125 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10126 sizeof (struct dwarf2_locexpr_baton
));
10127 baton
->per_cu
= cu
->per_cu
;
10128 gdb_assert (baton
->per_cu
);
10130 if (attr_form_is_block (attr
))
10132 /* Note that we're just copying the block's data pointer
10133 here, not the actual data. We're still pointing into the
10134 info_buffer for SYM's objfile; right now we never release
10135 that buffer, but when we do clean up properly this may
10137 baton
->size
= DW_BLOCK (attr
)->size
;
10138 baton
->data
= DW_BLOCK (attr
)->data
;
10142 dwarf2_invalid_attrib_class_complaint ("location description",
10143 SYMBOL_NATURAL_NAME (sym
));
10145 baton
->data
= NULL
;
10148 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10149 SYMBOL_LOCATION_BATON (sym
) = baton
;
10153 /* Return the OBJFILE associated with the compilation unit CU. */
10156 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10158 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10160 /* Return the master objfile, so that we can report and look up the
10161 correct file containing this variable. */
10162 if (objfile
->separate_debug_objfile_backlink
)
10163 objfile
= objfile
->separate_debug_objfile_backlink
;
10168 /* Return the address size given in the compilation unit header for CU. */
10171 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10174 return per_cu
->cu
->header
.addr_size
;
10177 /* If the CU is not currently read in, we re-read its header. */
10178 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10179 struct dwarf2_per_objfile
*per_objfile
10180 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10181 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10183 struct comp_unit_head cu_header
;
10184 memset (&cu_header
, 0, sizeof cu_header
);
10185 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10186 return cu_header
.addr_size
;
10190 /* Locate the compilation unit from CU's objfile which contains the
10191 DIE at OFFSET. Raises an error on failure. */
10193 static struct dwarf2_per_cu_data
*
10194 dwarf2_find_containing_comp_unit (unsigned int offset
,
10195 struct objfile
*objfile
)
10197 struct dwarf2_per_cu_data
*this_cu
;
10201 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10204 int mid
= low
+ (high
- low
) / 2;
10205 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10210 gdb_assert (low
== high
);
10211 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10214 error (_("Dwarf Error: could not find partial DIE containing "
10215 "offset 0x%lx [in module %s]"),
10216 (long) offset
, bfd_get_filename (objfile
->obfd
));
10218 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10219 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10223 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10224 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10225 && offset
>= this_cu
->offset
+ this_cu
->length
)
10226 error (_("invalid dwarf2 offset %u"), offset
);
10227 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10232 /* Locate the compilation unit from OBJFILE which is located at exactly
10233 OFFSET. Raises an error on failure. */
10235 static struct dwarf2_per_cu_data
*
10236 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10238 struct dwarf2_per_cu_data
*this_cu
;
10239 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10240 if (this_cu
->offset
!= offset
)
10241 error (_("no compilation unit with offset %u."), offset
);
10245 /* Release one cached compilation unit, CU. We unlink it from the tree
10246 of compilation units, but we don't remove it from the read_in_chain;
10247 the caller is responsible for that. */
10250 free_one_comp_unit (void *data
)
10252 struct dwarf2_cu
*cu
= data
;
10254 if (cu
->per_cu
!= NULL
)
10255 cu
->per_cu
->cu
= NULL
;
10258 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10263 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10264 when we're finished with it. We can't free the pointer itself, but be
10265 sure to unlink it from the cache. Also release any associated storage
10266 and perform cache maintenance.
10268 Only used during partial symbol parsing. */
10271 free_stack_comp_unit (void *data
)
10273 struct dwarf2_cu
*cu
= data
;
10275 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10276 cu
->partial_dies
= NULL
;
10278 if (cu
->per_cu
!= NULL
)
10280 /* This compilation unit is on the stack in our caller, so we
10281 should not xfree it. Just unlink it. */
10282 cu
->per_cu
->cu
= NULL
;
10285 /* If we had a per-cu pointer, then we may have other compilation
10286 units loaded, so age them now. */
10287 age_cached_comp_units ();
10291 /* Free all cached compilation units. */
10294 free_cached_comp_units (void *data
)
10296 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10298 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10299 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10300 while (per_cu
!= NULL
)
10302 struct dwarf2_per_cu_data
*next_cu
;
10304 next_cu
= per_cu
->cu
->read_in_chain
;
10306 free_one_comp_unit (per_cu
->cu
);
10307 *last_chain
= next_cu
;
10313 /* Increase the age counter on each cached compilation unit, and free
10314 any that are too old. */
10317 age_cached_comp_units (void)
10319 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10321 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10322 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10323 while (per_cu
!= NULL
)
10325 per_cu
->cu
->last_used
++;
10326 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10327 dwarf2_mark (per_cu
->cu
);
10328 per_cu
= per_cu
->cu
->read_in_chain
;
10331 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10332 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10333 while (per_cu
!= NULL
)
10335 struct dwarf2_per_cu_data
*next_cu
;
10337 next_cu
= per_cu
->cu
->read_in_chain
;
10339 if (!per_cu
->cu
->mark
)
10341 free_one_comp_unit (per_cu
->cu
);
10342 *last_chain
= next_cu
;
10345 last_chain
= &per_cu
->cu
->read_in_chain
;
10351 /* Remove a single compilation unit from the cache. */
10354 free_one_cached_comp_unit (void *target_cu
)
10356 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10358 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10359 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10360 while (per_cu
!= NULL
)
10362 struct dwarf2_per_cu_data
*next_cu
;
10364 next_cu
= per_cu
->cu
->read_in_chain
;
10366 if (per_cu
->cu
== target_cu
)
10368 free_one_comp_unit (per_cu
->cu
);
10369 *last_chain
= next_cu
;
10373 last_chain
= &per_cu
->cu
->read_in_chain
;
10379 /* Release all extra memory associated with OBJFILE. */
10382 dwarf2_free_objfile (struct objfile
*objfile
)
10384 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10386 if (dwarf2_per_objfile
== NULL
)
10389 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10390 free_cached_comp_units (NULL
);
10392 /* Everything else should be on the objfile obstack. */
10395 /* A pair of DIE offset and GDB type pointer. We store these
10396 in a hash table separate from the DIEs, and preserve them
10397 when the DIEs are flushed out of cache. */
10399 struct dwarf2_offset_and_type
10401 unsigned int offset
;
10405 /* Hash function for a dwarf2_offset_and_type. */
10408 offset_and_type_hash (const void *item
)
10410 const struct dwarf2_offset_and_type
*ofs
= item
;
10411 return ofs
->offset
;
10414 /* Equality function for a dwarf2_offset_and_type. */
10417 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10419 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10420 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10421 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10424 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10425 table if necessary. For convenience, return TYPE. */
10427 static struct type
*
10428 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10430 struct dwarf2_offset_and_type
**slot
, ofs
;
10432 if (cu
->type_hash
== NULL
)
10434 gdb_assert (cu
->per_cu
!= NULL
);
10435 cu
->per_cu
->type_hash
10436 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10437 offset_and_type_hash
,
10438 offset_and_type_eq
,
10440 &cu
->objfile
->objfile_obstack
,
10441 hashtab_obstack_allocate
,
10442 dummy_obstack_deallocate
);
10443 cu
->type_hash
= cu
->per_cu
->type_hash
;
10446 ofs
.offset
= die
->offset
;
10448 slot
= (struct dwarf2_offset_and_type
**)
10449 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10450 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10455 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10456 not have a saved type. */
10458 static struct type
*
10459 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10461 struct dwarf2_offset_and_type
*slot
, ofs
;
10462 htab_t type_hash
= cu
->type_hash
;
10464 if (type_hash
== NULL
)
10467 ofs
.offset
= die
->offset
;
10468 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10475 /* Set the mark field in CU and in every other compilation unit in the
10476 cache that we must keep because we are keeping CU. */
10478 /* Add a dependence relationship from CU to REF_PER_CU. */
10481 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10482 struct dwarf2_per_cu_data
*ref_per_cu
)
10486 if (cu
->dependencies
== NULL
)
10488 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10489 NULL
, &cu
->comp_unit_obstack
,
10490 hashtab_obstack_allocate
,
10491 dummy_obstack_deallocate
);
10493 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10495 *slot
= ref_per_cu
;
10498 /* Set the mark field in CU and in every other compilation unit in the
10499 cache that we must keep because we are keeping CU. */
10502 dwarf2_mark_helper (void **slot
, void *data
)
10504 struct dwarf2_per_cu_data
*per_cu
;
10506 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10507 if (per_cu
->cu
->mark
)
10509 per_cu
->cu
->mark
= 1;
10511 if (per_cu
->cu
->dependencies
!= NULL
)
10512 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10518 dwarf2_mark (struct dwarf2_cu
*cu
)
10523 if (cu
->dependencies
!= NULL
)
10524 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10528 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10532 per_cu
->cu
->mark
= 0;
10533 per_cu
= per_cu
->cu
->read_in_chain
;
10537 /* Trivial hash function for partial_die_info: the hash value of a DIE
10538 is its offset in .debug_info for this objfile. */
10541 partial_die_hash (const void *item
)
10543 const struct partial_die_info
*part_die
= item
;
10544 return part_die
->offset
;
10547 /* Trivial comparison function for partial_die_info structures: two DIEs
10548 are equal if they have the same offset. */
10551 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10553 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10554 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10555 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10558 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10559 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10562 set_dwarf2_cmd (char *args
, int from_tty
)
10564 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10568 show_dwarf2_cmd (char *args
, int from_tty
)
10570 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10573 void _initialize_dwarf2_read (void);
10576 _initialize_dwarf2_read (void)
10578 dwarf2_objfile_data_key
= register_objfile_data ();
10580 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10581 Set DWARF 2 specific variables.\n\
10582 Configure DWARF 2 variables such as the cache size"),
10583 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10584 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10586 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10587 Show DWARF 2 specific variables\n\
10588 Show DWARF 2 variables such as the cache size"),
10589 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10590 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10592 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10593 &dwarf2_max_cache_age
, _("\
10594 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10595 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10596 A higher limit means that cached compilation units will be stored\n\
10597 in memory longer, and more total memory will be used. Zero disables\n\
10598 caching, which can slow down startup."),
10600 show_dwarf2_max_cache_age
,
10601 &set_dwarf2_cmdlist
,
10602 &show_dwarf2_cmdlist
);
10604 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
10605 Set debugging of the dwarf2 DIE reader."), _("\
10606 Show debugging of the dwarf2 DIE reader."), _("\
10607 When enabled (non-zero), DIEs are dumped after they are read in.\n\
10608 The value is the maximum depth to print."),
10611 &setdebuglist
, &showdebuglist
);