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
*,
766 int, struct dwarf2_cu
*);
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 int need_pc
, 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 int need_pc
, 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
;
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;
1610 else if (comp_unit_die
.has_pc_info
1611 && comp_unit_die
.lowpc
< comp_unit_die
.highpc
)
1612 /* Store the contiguous range if it is not empty; it can be empty for
1613 CUs with no code. */
1614 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1615 comp_unit_die
.lowpc
+ baseaddr
,
1616 comp_unit_die
.highpc
+ baseaddr
- 1, pst
);
1618 /* Check if comp unit has_children.
1619 If so, read the rest of the partial symbols from this comp unit.
1620 If not, there's no more debug_info for this comp unit. */
1621 if (comp_unit_die
.has_children
)
1623 struct partial_die_info
*first_die
;
1624 CORE_ADDR lowpc
, highpc
;
1626 lowpc
= ((CORE_ADDR
) -1);
1627 highpc
= ((CORE_ADDR
) 0);
1629 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1631 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1632 ! comp_unit_die
.has_pc_info
, &cu
);
1634 /* If we didn't find a lowpc, set it to highpc to avoid
1635 complaints from `maint check'. */
1636 if (lowpc
== ((CORE_ADDR
) -1))
1639 /* If the compilation unit didn't have an explicit address range,
1640 then use the information extracted from its child dies. */
1641 if (! comp_unit_die
.has_pc_info
)
1643 comp_unit_die
.lowpc
= lowpc
;
1644 comp_unit_die
.highpc
= highpc
;
1647 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1648 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1650 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1651 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1652 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1653 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1654 sort_pst_symbols (pst
);
1656 /* If there is already a psymtab or symtab for a file of this
1657 name, remove it. (If there is a symtab, more drastic things
1658 also happen.) This happens in VxWorks. */
1659 free_named_symtabs (pst
->filename
);
1661 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1662 + cu
.header
.initial_length_size
;
1664 if (comp_unit_die
.has_stmt_list
)
1666 /* Get the list of files included in the current compilation unit,
1667 and build a psymtab for each of them. */
1668 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1671 do_cleanups (back_to_inner
);
1674 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1675 &objfile
->objfile_obstack
);
1677 do_cleanups (back_to
);
1680 /* Load the DIEs for a secondary CU into memory. */
1683 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1685 bfd
*abfd
= objfile
->obfd
;
1686 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1687 struct partial_die_info comp_unit_die
;
1688 struct dwarf2_cu
*cu
;
1689 struct abbrev_info
*abbrev
;
1690 unsigned int bytes_read
;
1691 struct cleanup
*back_to
;
1693 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1694 beg_of_comp_unit
= info_ptr
;
1696 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1697 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1699 obstack_init (&cu
->comp_unit_obstack
);
1701 cu
->objfile
= objfile
;
1702 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1704 /* Complete the cu_header. */
1705 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1706 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1708 /* Read the abbrevs for this compilation unit into a table. */
1709 dwarf2_read_abbrevs (abfd
, cu
);
1710 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1712 /* Read the compilation unit die. */
1713 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1714 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1715 abfd
, info_ptr
, cu
);
1717 /* Set the language we're debugging. */
1718 set_cu_language (comp_unit_die
.language
, cu
);
1720 /* Link this compilation unit into the compilation unit tree. */
1722 cu
->per_cu
= this_cu
;
1723 cu
->type_hash
= cu
->per_cu
->type_hash
;
1725 /* Check if comp unit has_children.
1726 If so, read the rest of the partial symbols from this comp unit.
1727 If not, there's no more debug_info for this comp unit. */
1728 if (comp_unit_die
.has_children
)
1729 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1731 do_cleanups (back_to
);
1734 /* Create a list of all compilation units in OBJFILE. We do this only
1735 if an inter-comp-unit reference is found; presumably if there is one,
1736 there will be many, and one will occur early in the .debug_info section.
1737 So there's no point in building this list incrementally. */
1740 create_all_comp_units (struct objfile
*objfile
)
1744 struct dwarf2_per_cu_data
**all_comp_units
;
1745 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1749 all_comp_units
= xmalloc (n_allocated
1750 * sizeof (struct dwarf2_per_cu_data
*));
1752 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1754 unsigned int length
, initial_length_size
;
1755 gdb_byte
*beg_of_comp_unit
;
1756 struct dwarf2_per_cu_data
*this_cu
;
1757 unsigned int offset
;
1759 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1761 /* Read just enough information to find out where the next
1762 compilation unit is. */
1763 length
= read_initial_length (objfile
->obfd
, info_ptr
,
1764 &initial_length_size
);
1766 /* Save the compilation unit for later lookup. */
1767 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1768 sizeof (struct dwarf2_per_cu_data
));
1769 memset (this_cu
, 0, sizeof (*this_cu
));
1770 this_cu
->offset
= offset
;
1771 this_cu
->length
= length
+ initial_length_size
;
1773 if (n_comp_units
== n_allocated
)
1776 all_comp_units
= xrealloc (all_comp_units
,
1778 * sizeof (struct dwarf2_per_cu_data
*));
1780 all_comp_units
[n_comp_units
++] = this_cu
;
1782 info_ptr
= info_ptr
+ this_cu
->length
;
1785 dwarf2_per_objfile
->all_comp_units
1786 = obstack_alloc (&objfile
->objfile_obstack
,
1787 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1788 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1789 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1790 xfree (all_comp_units
);
1791 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1794 /* Process all loaded DIEs for compilation unit CU, starting at
1795 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
1796 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
1797 DW_AT_ranges). If NEED_PC is set, then this function will set
1798 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
1799 and record the covered ranges in the addrmap. */
1802 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1803 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
1805 struct objfile
*objfile
= cu
->objfile
;
1806 bfd
*abfd
= objfile
->obfd
;
1807 struct partial_die_info
*pdi
;
1809 /* Now, march along the PDI's, descending into ones which have
1810 interesting children but skipping the children of the other ones,
1811 until we reach the end of the compilation unit. */
1817 fixup_partial_die (pdi
, cu
);
1819 /* Anonymous namespaces have no name but have interesting
1820 children, so we need to look at them. Ditto for anonymous
1823 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1824 || pdi
->tag
== DW_TAG_enumeration_type
)
1828 case DW_TAG_subprogram
:
1829 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
1831 case DW_TAG_variable
:
1832 case DW_TAG_typedef
:
1833 case DW_TAG_union_type
:
1834 if (!pdi
->is_declaration
)
1836 add_partial_symbol (pdi
, cu
);
1839 case DW_TAG_class_type
:
1840 case DW_TAG_interface_type
:
1841 case DW_TAG_structure_type
:
1842 if (!pdi
->is_declaration
)
1844 add_partial_symbol (pdi
, cu
);
1847 case DW_TAG_enumeration_type
:
1848 if (!pdi
->is_declaration
)
1849 add_partial_enumeration (pdi
, cu
);
1851 case DW_TAG_base_type
:
1852 case DW_TAG_subrange_type
:
1853 /* File scope base type definitions are added to the partial
1855 add_partial_symbol (pdi
, cu
);
1857 case DW_TAG_namespace
:
1858 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
1865 /* If the die has a sibling, skip to the sibling. */
1867 pdi
= pdi
->die_sibling
;
1871 /* Functions used to compute the fully scoped name of a partial DIE.
1873 Normally, this is simple. For C++, the parent DIE's fully scoped
1874 name is concatenated with "::" and the partial DIE's name. For
1875 Java, the same thing occurs except that "." is used instead of "::".
1876 Enumerators are an exception; they use the scope of their parent
1877 enumeration type, i.e. the name of the enumeration type is not
1878 prepended to the enumerator.
1880 There are two complexities. One is DW_AT_specification; in this
1881 case "parent" means the parent of the target of the specification,
1882 instead of the direct parent of the DIE. The other is compilers
1883 which do not emit DW_TAG_namespace; in this case we try to guess
1884 the fully qualified name of structure types from their members'
1885 linkage names. This must be done using the DIE's children rather
1886 than the children of any DW_AT_specification target. We only need
1887 to do this for structures at the top level, i.e. if the target of
1888 any DW_AT_specification (if any; otherwise the DIE itself) does not
1891 /* Compute the scope prefix associated with PDI's parent, in
1892 compilation unit CU. The result will be allocated on CU's
1893 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1894 field. NULL is returned if no prefix is necessary. */
1896 partial_die_parent_scope (struct partial_die_info
*pdi
,
1897 struct dwarf2_cu
*cu
)
1899 char *grandparent_scope
;
1900 struct partial_die_info
*parent
, *real_pdi
;
1902 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1903 then this means the parent of the specification DIE. */
1906 while (real_pdi
->has_specification
)
1907 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1909 parent
= real_pdi
->die_parent
;
1913 if (parent
->scope_set
)
1914 return parent
->scope
;
1916 fixup_partial_die (parent
, cu
);
1918 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1920 if (parent
->tag
== DW_TAG_namespace
1921 || parent
->tag
== DW_TAG_structure_type
1922 || parent
->tag
== DW_TAG_class_type
1923 || parent
->tag
== DW_TAG_interface_type
1924 || parent
->tag
== DW_TAG_union_type
)
1926 if (grandparent_scope
== NULL
)
1927 parent
->scope
= parent
->name
;
1929 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1932 else if (parent
->tag
== DW_TAG_enumeration_type
)
1933 /* Enumerators should not get the name of the enumeration as a prefix. */
1934 parent
->scope
= grandparent_scope
;
1937 /* FIXME drow/2004-04-01: What should we be doing with
1938 function-local names? For partial symbols, we should probably be
1940 complaint (&symfile_complaints
,
1941 _("unhandled containing DIE tag %d for DIE at %d"),
1942 parent
->tag
, pdi
->offset
);
1943 parent
->scope
= grandparent_scope
;
1946 parent
->scope_set
= 1;
1947 return parent
->scope
;
1950 /* Return the fully scoped name associated with PDI, from compilation unit
1951 CU. The result will be allocated with malloc. */
1953 partial_die_full_name (struct partial_die_info
*pdi
,
1954 struct dwarf2_cu
*cu
)
1958 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1959 if (parent_scope
== NULL
)
1962 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1966 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1968 struct objfile
*objfile
= cu
->objfile
;
1970 char *actual_name
= NULL
;
1971 const char *my_prefix
;
1972 const struct partial_symbol
*psym
= NULL
;
1974 int built_actual_name
= 0;
1976 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1978 if (pdi_needs_namespace (pdi
->tag
))
1980 actual_name
= partial_die_full_name (pdi
, cu
);
1982 built_actual_name
= 1;
1985 if (actual_name
== NULL
)
1986 actual_name
= pdi
->name
;
1990 case DW_TAG_subprogram
:
1991 if (pdi
->is_external
|| cu
->language
== language_ada
)
1993 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1994 of the global scope. But in Ada, we want to be able to access
1995 nested procedures globally. So all Ada subprograms are stored
1996 in the global scope. */
1997 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1998 mst_text, objfile); */
1999 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2000 VAR_DOMAIN
, LOC_BLOCK
,
2001 &objfile
->global_psymbols
,
2002 0, pdi
->lowpc
+ baseaddr
,
2003 cu
->language
, objfile
);
2007 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2008 mst_file_text, objfile); */
2009 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2010 VAR_DOMAIN
, LOC_BLOCK
,
2011 &objfile
->static_psymbols
,
2012 0, pdi
->lowpc
+ baseaddr
,
2013 cu
->language
, objfile
);
2016 case DW_TAG_variable
:
2017 if (pdi
->is_external
)
2020 Don't enter into the minimal symbol tables as there is
2021 a minimal symbol table entry from the ELF symbols already.
2022 Enter into partial symbol table if it has a location
2023 descriptor or a type.
2024 If the location descriptor is missing, new_symbol will create
2025 a LOC_UNRESOLVED symbol, the address of the variable will then
2026 be determined from the minimal symbol table whenever the variable
2028 The address for the partial symbol table entry is not
2029 used by GDB, but it comes in handy for debugging partial symbol
2033 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2034 if (pdi
->locdesc
|| pdi
->has_type
)
2035 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2036 VAR_DOMAIN
, LOC_STATIC
,
2037 &objfile
->global_psymbols
,
2039 cu
->language
, objfile
);
2043 /* Static Variable. Skip symbols without location descriptors. */
2044 if (pdi
->locdesc
== NULL
)
2046 if (built_actual_name
)
2047 xfree (actual_name
);
2050 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2051 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2052 mst_file_data, objfile); */
2053 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2054 VAR_DOMAIN
, LOC_STATIC
,
2055 &objfile
->static_psymbols
,
2057 cu
->language
, objfile
);
2060 case DW_TAG_typedef
:
2061 case DW_TAG_base_type
:
2062 case DW_TAG_subrange_type
:
2063 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2064 VAR_DOMAIN
, LOC_TYPEDEF
,
2065 &objfile
->static_psymbols
,
2066 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2068 case DW_TAG_namespace
:
2069 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2070 VAR_DOMAIN
, LOC_TYPEDEF
,
2071 &objfile
->global_psymbols
,
2072 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2074 case DW_TAG_class_type
:
2075 case DW_TAG_interface_type
:
2076 case DW_TAG_structure_type
:
2077 case DW_TAG_union_type
:
2078 case DW_TAG_enumeration_type
:
2079 /* Skip external references. The DWARF standard says in the section
2080 about "Structure, Union, and Class Type Entries": "An incomplete
2081 structure, union or class type is represented by a structure,
2082 union or class entry that does not have a byte size attribute
2083 and that has a DW_AT_declaration attribute." */
2084 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2086 if (built_actual_name
)
2087 xfree (actual_name
);
2091 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2092 static vs. global. */
2093 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2094 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2095 (cu
->language
== language_cplus
2096 || cu
->language
== language_java
)
2097 ? &objfile
->global_psymbols
2098 : &objfile
->static_psymbols
,
2099 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2102 case DW_TAG_enumerator
:
2103 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2104 VAR_DOMAIN
, LOC_CONST
,
2105 (cu
->language
== language_cplus
2106 || cu
->language
== language_java
)
2107 ? &objfile
->global_psymbols
2108 : &objfile
->static_psymbols
,
2109 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2115 /* Check to see if we should scan the name for possible namespace
2116 info. Only do this if this is C++, if we don't have namespace
2117 debugging info in the file, if the psym is of an appropriate type
2118 (otherwise we'll have psym == NULL), and if we actually had a
2119 mangled name to begin with. */
2121 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2122 cases which do not set PSYM above? */
2124 if (cu
->language
== language_cplus
2125 && cu
->has_namespace_info
== 0
2127 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2128 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2131 if (built_actual_name
)
2132 xfree (actual_name
);
2135 /* Determine whether a die of type TAG living in a C++ class or
2136 namespace needs to have the name of the scope prepended to the
2137 name listed in the die. */
2140 pdi_needs_namespace (enum dwarf_tag tag
)
2144 case DW_TAG_namespace
:
2145 case DW_TAG_typedef
:
2146 case DW_TAG_class_type
:
2147 case DW_TAG_interface_type
:
2148 case DW_TAG_structure_type
:
2149 case DW_TAG_union_type
:
2150 case DW_TAG_enumeration_type
:
2151 case DW_TAG_enumerator
:
2158 /* Read a partial die corresponding to a namespace; also, add a symbol
2159 corresponding to that namespace to the symbol table. NAMESPACE is
2160 the name of the enclosing namespace. */
2163 add_partial_namespace (struct partial_die_info
*pdi
,
2164 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2165 int need_pc
, struct dwarf2_cu
*cu
)
2167 struct objfile
*objfile
= cu
->objfile
;
2169 /* Add a symbol for the namespace. */
2171 add_partial_symbol (pdi
, cu
);
2173 /* Now scan partial symbols in that namespace. */
2175 if (pdi
->has_children
)
2176 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2179 /* Read a partial die corresponding to a subprogram and create a partial
2180 symbol for that subprogram. When the CU language allows it, this
2181 routine also defines a partial symbol for each nested subprogram
2182 that this subprogram contains.
2184 DIE my also be a lexical block, in which case we simply search
2185 recursively for suprograms defined inside that lexical block.
2186 Again, this is only performed when the CU language allows this
2187 type of definitions. */
2190 add_partial_subprogram (struct partial_die_info
*pdi
,
2191 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2192 int need_pc
, struct dwarf2_cu
*cu
)
2194 if (pdi
->tag
== DW_TAG_subprogram
)
2196 if (pdi
->has_pc_info
)
2198 if (pdi
->lowpc
< *lowpc
)
2199 *lowpc
= pdi
->lowpc
;
2200 if (pdi
->highpc
> *highpc
)
2201 *highpc
= pdi
->highpc
;
2205 struct objfile
*objfile
= cu
->objfile
;
2207 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2208 SECT_OFF_TEXT (objfile
));
2209 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2210 pdi
->lowpc
, pdi
->highpc
- 1,
2211 cu
->per_cu
->psymtab
);
2213 if (!pdi
->is_declaration
)
2214 add_partial_symbol (pdi
, cu
);
2218 if (! pdi
->has_children
)
2221 if (cu
->language
== language_ada
)
2223 pdi
= pdi
->die_child
;
2226 fixup_partial_die (pdi
, cu
);
2227 if (pdi
->tag
== DW_TAG_subprogram
2228 || pdi
->tag
== DW_TAG_lexical_block
)
2229 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2230 pdi
= pdi
->die_sibling
;
2235 /* See if we can figure out if the class lives in a namespace. We do
2236 this by looking for a member function; its demangled name will
2237 contain namespace info, if there is any. */
2240 guess_structure_name (struct partial_die_info
*struct_pdi
,
2241 struct dwarf2_cu
*cu
)
2243 if ((cu
->language
== language_cplus
2244 || cu
->language
== language_java
)
2245 && cu
->has_namespace_info
== 0
2246 && struct_pdi
->has_children
)
2248 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2249 what template types look like, because the demangler
2250 frequently doesn't give the same name as the debug info. We
2251 could fix this by only using the demangled name to get the
2252 prefix (but see comment in read_structure_type). */
2254 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2255 struct partial_die_info
*real_pdi
;
2257 /* If this DIE (this DIE's specification, if any) has a parent, then
2258 we should not do this. We'll prepend the parent's fully qualified
2259 name when we create the partial symbol. */
2261 real_pdi
= struct_pdi
;
2262 while (real_pdi
->has_specification
)
2263 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2265 if (real_pdi
->die_parent
!= NULL
)
2268 while (child_pdi
!= NULL
)
2270 if (child_pdi
->tag
== DW_TAG_subprogram
)
2272 char *actual_class_name
2273 = language_class_name_from_physname (cu
->language_defn
,
2275 if (actual_class_name
!= NULL
)
2278 = obsavestring (actual_class_name
,
2279 strlen (actual_class_name
),
2280 &cu
->comp_unit_obstack
);
2281 xfree (actual_class_name
);
2286 child_pdi
= child_pdi
->die_sibling
;
2291 /* Read a partial die corresponding to an enumeration type. */
2294 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2295 struct dwarf2_cu
*cu
)
2297 struct objfile
*objfile
= cu
->objfile
;
2298 bfd
*abfd
= objfile
->obfd
;
2299 struct partial_die_info
*pdi
;
2301 if (enum_pdi
->name
!= NULL
)
2302 add_partial_symbol (enum_pdi
, cu
);
2304 pdi
= enum_pdi
->die_child
;
2307 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2308 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2310 add_partial_symbol (pdi
, cu
);
2311 pdi
= pdi
->die_sibling
;
2315 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2316 Return the corresponding abbrev, or NULL if the number is zero (indicating
2317 an empty DIE). In either case *BYTES_READ will be set to the length of
2318 the initial number. */
2320 static struct abbrev_info
*
2321 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2322 struct dwarf2_cu
*cu
)
2324 bfd
*abfd
= cu
->objfile
->obfd
;
2325 unsigned int abbrev_number
;
2326 struct abbrev_info
*abbrev
;
2328 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2330 if (abbrev_number
== 0)
2333 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2336 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2337 bfd_get_filename (abfd
));
2343 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2344 pointer to the end of a series of DIEs, terminated by an empty
2345 DIE. Any children of the skipped DIEs will also be skipped. */
2348 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2350 struct abbrev_info
*abbrev
;
2351 unsigned int bytes_read
;
2355 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2357 return info_ptr
+ bytes_read
;
2359 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2363 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2364 should point just after the initial uleb128 of a DIE, and the
2365 abbrev corresponding to that skipped uleb128 should be passed in
2366 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2370 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2371 struct dwarf2_cu
*cu
)
2373 unsigned int bytes_read
;
2374 struct attribute attr
;
2375 bfd
*abfd
= cu
->objfile
->obfd
;
2376 unsigned int form
, i
;
2378 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2380 /* The only abbrev we care about is DW_AT_sibling. */
2381 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2383 read_attribute (&attr
, &abbrev
->attrs
[i
],
2384 abfd
, info_ptr
, cu
);
2385 if (attr
.form
== DW_FORM_ref_addr
)
2386 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2388 return dwarf2_per_objfile
->info_buffer
2389 + dwarf2_get_ref_die_offset (&attr
);
2392 /* If it isn't DW_AT_sibling, skip this attribute. */
2393 form
= abbrev
->attrs
[i
].form
;
2398 case DW_FORM_ref_addr
:
2399 info_ptr
+= cu
->header
.addr_size
;
2418 case DW_FORM_string
:
2419 read_string (abfd
, info_ptr
, &bytes_read
);
2420 info_ptr
+= bytes_read
;
2423 info_ptr
+= cu
->header
.offset_size
;
2426 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2427 info_ptr
+= bytes_read
;
2429 case DW_FORM_block1
:
2430 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2432 case DW_FORM_block2
:
2433 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2435 case DW_FORM_block4
:
2436 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2440 case DW_FORM_ref_udata
:
2441 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2443 case DW_FORM_indirect
:
2444 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2445 info_ptr
+= bytes_read
;
2446 /* We need to continue parsing from here, so just go back to
2448 goto skip_attribute
;
2451 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2452 dwarf_form_name (form
),
2453 bfd_get_filename (abfd
));
2457 if (abbrev
->has_children
)
2458 return skip_children (info_ptr
, cu
);
2463 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2464 the next DIE after ORIG_PDI. */
2467 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2468 bfd
*abfd
, struct dwarf2_cu
*cu
)
2470 /* Do we know the sibling already? */
2472 if (orig_pdi
->sibling
)
2473 return orig_pdi
->sibling
;
2475 /* Are there any children to deal with? */
2477 if (!orig_pdi
->has_children
)
2480 /* Skip the children the long way. */
2482 return skip_children (info_ptr
, cu
);
2485 /* Expand this partial symbol table into a full symbol table. */
2488 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2490 /* FIXME: This is barely more than a stub. */
2495 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2501 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2502 gdb_flush (gdb_stdout
);
2505 /* Restore our global data. */
2506 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2507 dwarf2_objfile_data_key
);
2509 psymtab_to_symtab_1 (pst
);
2511 /* Finish up the debug error message. */
2513 printf_filtered (_("done.\n"));
2518 /* Add PER_CU to the queue. */
2521 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2523 struct dwarf2_queue_item
*item
;
2526 item
= xmalloc (sizeof (*item
));
2527 item
->per_cu
= per_cu
;
2530 if (dwarf2_queue
== NULL
)
2531 dwarf2_queue
= item
;
2533 dwarf2_queue_tail
->next
= item
;
2535 dwarf2_queue_tail
= item
;
2537 /* Either PER_CU is the CU we want to process, or we're following a reference
2538 pointing into PER_CU. Either way, we need its DIEs now. */
2539 load_full_comp_unit (item
->per_cu
, objfile
);
2540 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2541 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2544 /* Process the queue. */
2547 process_queue (struct objfile
*objfile
)
2549 struct dwarf2_queue_item
*item
, *next_item
;
2551 /* The queue starts out with one item, but following a DIE reference
2552 may load a new CU, adding it to the end of the queue. */
2553 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2555 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2556 process_full_comp_unit (item
->per_cu
);
2558 item
->per_cu
->queued
= 0;
2559 next_item
= item
->next
;
2563 dwarf2_queue_tail
= NULL
;
2566 /* Free all allocated queue entries. This function only releases anything if
2567 an error was thrown; if the queue was processed then it would have been
2568 freed as we went along. */
2571 dwarf2_release_queue (void *dummy
)
2573 struct dwarf2_queue_item
*item
, *last
;
2575 item
= dwarf2_queue
;
2578 /* Anything still marked queued is likely to be in an
2579 inconsistent state, so discard it. */
2580 if (item
->per_cu
->queued
)
2582 if (item
->per_cu
->cu
!= NULL
)
2583 free_one_cached_comp_unit (item
->per_cu
->cu
);
2584 item
->per_cu
->queued
= 0;
2592 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2595 /* Read in full symbols for PST, and anything it depends on. */
2598 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2600 struct dwarf2_per_cu_data
*per_cu
;
2601 struct cleanup
*back_to
;
2604 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2605 if (!pst
->dependencies
[i
]->readin
)
2607 /* Inform about additional files that need to be read in. */
2610 /* FIXME: i18n: Need to make this a single string. */
2611 fputs_filtered (" ", gdb_stdout
);
2613 fputs_filtered ("and ", gdb_stdout
);
2615 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2616 wrap_here (""); /* Flush output */
2617 gdb_flush (gdb_stdout
);
2619 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2622 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2626 /* It's an include file, no symbols to read for it.
2627 Everything is in the parent symtab. */
2632 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2634 queue_comp_unit (per_cu
, pst
->objfile
);
2636 process_queue (pst
->objfile
);
2638 /* Age the cache, releasing compilation units that have not
2639 been used recently. */
2640 age_cached_comp_units ();
2642 do_cleanups (back_to
);
2645 /* Load the DIEs associated with PST and PER_CU into memory. */
2647 static struct dwarf2_cu
*
2648 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2650 bfd
*abfd
= objfile
->obfd
;
2651 struct dwarf2_cu
*cu
;
2652 unsigned int offset
;
2654 struct cleanup
*back_to
, *free_cu_cleanup
;
2655 struct attribute
*attr
;
2658 /* Set local variables from the partial symbol table info. */
2659 offset
= per_cu
->offset
;
2661 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2663 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2664 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2666 /* If an error occurs while loading, release our storage. */
2667 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2669 cu
->objfile
= objfile
;
2671 /* read in the comp_unit header */
2672 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2674 /* Read the abbrevs for this compilation unit */
2675 dwarf2_read_abbrevs (abfd
, cu
);
2676 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2678 cu
->header
.offset
= offset
;
2680 cu
->per_cu
= per_cu
;
2682 cu
->type_hash
= per_cu
->type_hash
;
2684 /* We use this obstack for block values in dwarf_alloc_block. */
2685 obstack_init (&cu
->comp_unit_obstack
);
2687 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2689 /* We try not to read any attributes in this function, because not
2690 all objfiles needed for references have been loaded yet, and symbol
2691 table processing isn't initialized. But we have to set the CU language,
2692 or we won't be able to build types correctly. */
2693 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2695 set_cu_language (DW_UNSND (attr
), cu
);
2697 set_cu_language (language_minimal
, cu
);
2699 do_cleanups (back_to
);
2701 /* We've successfully allocated this compilation unit. Let our caller
2702 clean it up when finished with it. */
2703 discard_cleanups (free_cu_cleanup
);
2708 /* Generate full symbol information for PST and CU, whose DIEs have
2709 already been loaded into memory. */
2712 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2714 struct partial_symtab
*pst
= per_cu
->psymtab
;
2715 struct dwarf2_cu
*cu
= per_cu
->cu
;
2716 struct objfile
*objfile
= pst
->objfile
;
2717 bfd
*abfd
= objfile
->obfd
;
2718 CORE_ADDR lowpc
, highpc
;
2719 struct symtab
*symtab
;
2720 struct cleanup
*back_to
;
2721 struct attribute
*attr
;
2724 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2727 back_to
= make_cleanup (really_free_pendings
, NULL
);
2729 cu
->list_in_scope
= &file_symbols
;
2731 /* Find the base address of the compilation unit for range lists and
2732 location lists. It will normally be specified by DW_AT_low_pc.
2733 In DWARF-3 draft 4, the base address could be overridden by
2734 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2735 compilation units with discontinuous ranges. */
2738 cu
->base_address
= 0;
2740 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2743 cu
->base_address
= DW_ADDR (attr
);
2748 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2751 cu
->base_address
= DW_ADDR (attr
);
2756 /* Do line number decoding in read_file_scope () */
2757 process_die (cu
->dies
, cu
);
2759 /* Some compilers don't define a DW_AT_high_pc attribute for the
2760 compilation unit. If the DW_AT_high_pc is missing, synthesize
2761 it, by scanning the DIE's below the compilation unit. */
2762 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2764 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2766 /* Set symtab language to language from DW_AT_language.
2767 If the compilation is from a C file generated by language preprocessors,
2768 do not set the language if it was already deduced by start_subfile. */
2770 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2772 symtab
->language
= cu
->language
;
2774 pst
->symtab
= symtab
;
2777 do_cleanups (back_to
);
2780 /* Process a die and its children. */
2783 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2787 case DW_TAG_padding
:
2789 case DW_TAG_compile_unit
:
2790 read_file_scope (die
, cu
);
2792 case DW_TAG_subprogram
:
2793 read_func_scope (die
, cu
);
2795 case DW_TAG_inlined_subroutine
:
2796 /* FIXME: These are ignored for now.
2797 They could be used to set breakpoints on all inlined instances
2798 of a function and make GDB `next' properly over inlined functions. */
2800 case DW_TAG_lexical_block
:
2801 case DW_TAG_try_block
:
2802 case DW_TAG_catch_block
:
2803 read_lexical_block_scope (die
, cu
);
2805 case DW_TAG_class_type
:
2806 case DW_TAG_interface_type
:
2807 case DW_TAG_structure_type
:
2808 case DW_TAG_union_type
:
2809 process_structure_scope (die
, cu
);
2811 case DW_TAG_enumeration_type
:
2812 process_enumeration_scope (die
, cu
);
2815 /* These dies have a type, but processing them does not create
2816 a symbol or recurse to process the children. Therefore we can
2817 read them on-demand through read_type_die. */
2818 case DW_TAG_subroutine_type
:
2819 case DW_TAG_set_type
:
2820 case DW_TAG_array_type
:
2821 case DW_TAG_pointer_type
:
2822 case DW_TAG_ptr_to_member_type
:
2823 case DW_TAG_reference_type
:
2824 case DW_TAG_string_type
:
2827 case DW_TAG_base_type
:
2828 case DW_TAG_subrange_type
:
2829 /* Add a typedef symbol for the type definition, if it has a
2831 new_symbol (die
, read_type_die (die
, cu
), cu
);
2833 case DW_TAG_common_block
:
2834 read_common_block (die
, cu
);
2836 case DW_TAG_common_inclusion
:
2838 case DW_TAG_namespace
:
2839 processing_has_namespace_info
= 1;
2840 read_namespace (die
, cu
);
2842 case DW_TAG_imported_declaration
:
2843 case DW_TAG_imported_module
:
2844 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2845 information contained in these. DW_TAG_imported_declaration
2846 dies shouldn't have children; DW_TAG_imported_module dies
2847 shouldn't in the C++ case, but conceivably could in the
2849 processing_has_namespace_info
= 1;
2850 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2851 dwarf_tag_name (die
->tag
));
2854 new_symbol (die
, NULL
, cu
);
2859 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2860 If scope qualifiers are appropriate they will be added. The result
2861 will be allocated on the objfile_obstack, or NULL if the DIE does
2865 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2867 struct attribute
*attr
;
2868 char *prefix
, *name
;
2869 struct ui_file
*buf
= NULL
;
2871 name
= dwarf2_name (die
, cu
);
2875 /* These are the only languages we know how to qualify names in. */
2876 if (cu
->language
!= language_cplus
2877 && cu
->language
!= language_java
)
2880 /* If no prefix is necessary for this type of DIE, return the
2881 unqualified name. The other three tags listed could be handled
2882 in pdi_needs_namespace, but that requires broader changes. */
2883 if (!pdi_needs_namespace (die
->tag
)
2884 && die
->tag
!= DW_TAG_subprogram
2885 && die
->tag
!= DW_TAG_variable
2886 && die
->tag
!= DW_TAG_member
)
2889 prefix
= determine_prefix (die
, cu
);
2890 if (*prefix
!= '\0')
2891 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2898 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2900 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2904 free_cu_line_header (void *arg
)
2906 struct dwarf2_cu
*cu
= arg
;
2908 free_line_header (cu
->line_header
);
2909 cu
->line_header
= NULL
;
2913 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2915 struct objfile
*objfile
= cu
->objfile
;
2916 struct comp_unit_head
*cu_header
= &cu
->header
;
2917 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2918 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2919 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2920 struct attribute
*attr
;
2922 char *comp_dir
= NULL
;
2923 struct die_info
*child_die
;
2924 bfd
*abfd
= objfile
->obfd
;
2925 struct line_header
*line_header
= 0;
2928 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2930 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2932 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2933 from finish_block. */
2934 if (lowpc
== ((CORE_ADDR
) -1))
2939 /* Find the filename. Do not use dwarf2_name here, since the filename
2940 is not a source language identifier. */
2941 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2944 name
= DW_STRING (attr
);
2947 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2949 comp_dir
= DW_STRING (attr
);
2950 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2952 comp_dir
= ldirname (name
);
2953 if (comp_dir
!= NULL
)
2954 make_cleanup (xfree
, comp_dir
);
2956 if (comp_dir
!= NULL
)
2958 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2959 directory, get rid of it. */
2960 char *cp
= strchr (comp_dir
, ':');
2962 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2969 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2972 set_cu_language (DW_UNSND (attr
), cu
);
2975 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2977 cu
->producer
= DW_STRING (attr
);
2979 /* We assume that we're processing GCC output. */
2980 processing_gcc_compilation
= 2;
2982 processing_has_namespace_info
= 0;
2984 start_symtab (name
, comp_dir
, lowpc
);
2985 record_debugformat ("DWARF 2");
2986 record_producer (cu
->producer
);
2988 initialize_cu_func_list (cu
);
2990 /* Decode line number information if present. We do this before
2991 processing child DIEs, so that the line header table is available
2992 for DW_AT_decl_file. */
2993 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2996 unsigned int line_offset
= DW_UNSND (attr
);
2997 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3000 cu
->line_header
= line_header
;
3001 make_cleanup (free_cu_line_header
, cu
);
3002 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3006 /* Process all dies in compilation unit. */
3007 if (die
->child
!= NULL
)
3009 child_die
= die
->child
;
3010 while (child_die
&& child_die
->tag
)
3012 process_die (child_die
, cu
);
3013 child_die
= sibling_die (child_die
);
3017 /* Decode macro information, if present. Dwarf 2 macro information
3018 refers to information in the line number info statement program
3019 header, so we can only read it if we've read the header
3021 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3022 if (attr
&& line_header
)
3024 unsigned int macro_offset
= DW_UNSND (attr
);
3025 dwarf_decode_macros (line_header
, macro_offset
,
3026 comp_dir
, abfd
, cu
);
3028 do_cleanups (back_to
);
3032 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3033 struct dwarf2_cu
*cu
)
3035 struct function_range
*thisfn
;
3037 thisfn
= (struct function_range
*)
3038 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3039 thisfn
->name
= name
;
3040 thisfn
->lowpc
= lowpc
;
3041 thisfn
->highpc
= highpc
;
3042 thisfn
->seen_line
= 0;
3043 thisfn
->next
= NULL
;
3045 if (cu
->last_fn
== NULL
)
3046 cu
->first_fn
= thisfn
;
3048 cu
->last_fn
->next
= thisfn
;
3050 cu
->last_fn
= thisfn
;
3054 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3056 struct objfile
*objfile
= cu
->objfile
;
3057 struct context_stack
*new;
3060 struct die_info
*child_die
;
3061 struct attribute
*attr
;
3064 struct block
*block
;
3066 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3068 name
= dwarf2_linkage_name (die
, cu
);
3070 /* Ignore functions with missing or empty names and functions with
3071 missing or invalid low and high pc attributes. */
3072 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3078 /* Record the function range for dwarf_decode_lines. */
3079 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3081 new = push_context (0, lowpc
);
3082 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3084 /* If there is a location expression for DW_AT_frame_base, record
3086 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3088 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3089 expression is being recorded directly in the function's symbol
3090 and not in a separate frame-base object. I guess this hack is
3091 to avoid adding some sort of frame-base adjunct/annex to the
3092 function's symbol :-(. The problem with doing this is that it
3093 results in a function symbol with a location expression that
3094 has nothing to do with the location of the function, ouch! The
3095 relationship should be: a function's symbol has-a frame base; a
3096 frame-base has-a location expression. */
3097 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3099 cu
->list_in_scope
= &local_symbols
;
3101 if (die
->child
!= NULL
)
3103 child_die
= die
->child
;
3104 while (child_die
&& child_die
->tag
)
3106 process_die (child_die
, cu
);
3107 child_die
= sibling_die (child_die
);
3111 new = pop_context ();
3112 /* Make a block for the local symbols within. */
3113 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3114 lowpc
, highpc
, objfile
);
3116 /* For C++, set the block's scope. */
3117 if (cu
->language
== language_cplus
)
3118 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3119 determine_prefix (die
, cu
),
3120 processing_has_namespace_info
);
3122 /* If we have address ranges, record them. */
3123 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3125 /* In C++, we can have functions nested inside functions (e.g., when
3126 a function declares a class that has methods). This means that
3127 when we finish processing a function scope, we may need to go
3128 back to building a containing block's symbol lists. */
3129 local_symbols
= new->locals
;
3130 param_symbols
= new->params
;
3132 /* If we've finished processing a top-level function, subsequent
3133 symbols go in the file symbol list. */
3134 if (outermost_context_p ())
3135 cu
->list_in_scope
= &file_symbols
;
3138 /* Process all the DIES contained within a lexical block scope. Start
3139 a new scope, process the dies, and then close the scope. */
3142 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3144 struct objfile
*objfile
= cu
->objfile
;
3145 struct context_stack
*new;
3146 CORE_ADDR lowpc
, highpc
;
3147 struct die_info
*child_die
;
3150 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3152 /* Ignore blocks with missing or invalid low and high pc attributes. */
3153 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3154 as multiple lexical blocks? Handling children in a sane way would
3155 be nasty. Might be easier to properly extend generic blocks to
3157 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3162 push_context (0, lowpc
);
3163 if (die
->child
!= NULL
)
3165 child_die
= die
->child
;
3166 while (child_die
&& child_die
->tag
)
3168 process_die (child_die
, cu
);
3169 child_die
= sibling_die (child_die
);
3172 new = pop_context ();
3174 if (local_symbols
!= NULL
)
3177 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3180 /* Note that recording ranges after traversing children, as we
3181 do here, means that recording a parent's ranges entails
3182 walking across all its children's ranges as they appear in
3183 the address map, which is quadratic behavior.
3185 It would be nicer to record the parent's ranges before
3186 traversing its children, simply overriding whatever you find
3187 there. But since we don't even decide whether to create a
3188 block until after we've traversed its children, that's hard
3190 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3192 local_symbols
= new->locals
;
3195 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3196 Return 1 if the attributes are present and valid, otherwise, return 0.
3197 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3200 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3201 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3202 struct partial_symtab
*ranges_pst
)
3204 struct objfile
*objfile
= cu
->objfile
;
3205 struct comp_unit_head
*cu_header
= &cu
->header
;
3206 bfd
*obfd
= objfile
->obfd
;
3207 unsigned int addr_size
= cu_header
->addr_size
;
3208 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3209 /* Base address selection entry. */
3220 found_base
= cu
->base_known
;
3221 base
= cu
->base_address
;
3223 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3225 complaint (&symfile_complaints
,
3226 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3230 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3232 /* Read in the largest possible address. */
3233 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3234 if ((marker
& mask
) == mask
)
3236 /* If we found the largest possible address, then
3237 read the base address. */
3238 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3239 buffer
+= 2 * addr_size
;
3240 offset
+= 2 * addr_size
;
3246 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3250 CORE_ADDR range_beginning
, range_end
;
3252 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3253 buffer
+= addr_size
;
3254 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3255 buffer
+= addr_size
;
3256 offset
+= 2 * addr_size
;
3258 /* An end of list marker is a pair of zero addresses. */
3259 if (range_beginning
== 0 && range_end
== 0)
3260 /* Found the end of list entry. */
3263 /* Each base address selection entry is a pair of 2 values.
3264 The first is the largest possible address, the second is
3265 the base address. Check for a base address here. */
3266 if ((range_beginning
& mask
) == mask
)
3268 /* If we found the largest possible address, then
3269 read the base address. */
3270 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3277 /* We have no valid base address for the ranges
3279 complaint (&symfile_complaints
,
3280 _("Invalid .debug_ranges data (no base address)"));
3284 range_beginning
+= base
;
3287 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3288 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3289 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3292 /* FIXME: This is recording everything as a low-high
3293 segment of consecutive addresses. We should have a
3294 data structure for discontiguous block ranges
3298 low
= range_beginning
;
3304 if (range_beginning
< low
)
3305 low
= range_beginning
;
3306 if (range_end
> high
)
3312 /* If the first entry is an end-of-list marker, the range
3313 describes an empty scope, i.e. no instructions. */
3319 *high_return
= high
;
3323 /* Get low and high pc attributes from a die. Return 1 if the attributes
3324 are present and valid, otherwise, return 0. Return -1 if the range is
3325 discontinuous, i.e. derived from DW_AT_ranges information. */
3327 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3328 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3330 struct attribute
*attr
;
3335 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3338 high
= DW_ADDR (attr
);
3339 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3341 low
= DW_ADDR (attr
);
3343 /* Found high w/o low attribute. */
3346 /* Found consecutive range of addresses. */
3351 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3354 /* Value of the DW_AT_ranges attribute is the offset in the
3355 .debug_ranges section. */
3356 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3358 /* Found discontinuous range of addresses. */
3366 /* When using the GNU linker, .gnu.linkonce. sections are used to
3367 eliminate duplicate copies of functions and vtables and such.
3368 The linker will arbitrarily choose one and discard the others.
3369 The AT_*_pc values for such functions refer to local labels in
3370 these sections. If the section from that file was discarded, the
3371 labels are not in the output, so the relocs get a value of 0.
3372 If this is a discarded function, mark the pc bounds as invalid,
3373 so that GDB will ignore it. */
3374 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3382 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3383 its low and high PC addresses. Do nothing if these addresses could not
3384 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3385 and HIGHPC to the high address if greater than HIGHPC. */
3388 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3389 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3390 struct dwarf2_cu
*cu
)
3392 CORE_ADDR low
, high
;
3393 struct die_info
*child
= die
->child
;
3395 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3397 *lowpc
= min (*lowpc
, low
);
3398 *highpc
= max (*highpc
, high
);
3401 /* If the language does not allow nested subprograms (either inside
3402 subprograms or lexical blocks), we're done. */
3403 if (cu
->language
!= language_ada
)
3406 /* Check all the children of the given DIE. If it contains nested
3407 subprograms, then check their pc bounds. Likewise, we need to
3408 check lexical blocks as well, as they may also contain subprogram
3410 while (child
&& child
->tag
)
3412 if (child
->tag
== DW_TAG_subprogram
3413 || child
->tag
== DW_TAG_lexical_block
)
3414 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3415 child
= sibling_die (child
);
3419 /* Get the low and high pc's represented by the scope DIE, and store
3420 them in *LOWPC and *HIGHPC. If the correct values can't be
3421 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3424 get_scope_pc_bounds (struct die_info
*die
,
3425 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3426 struct dwarf2_cu
*cu
)
3428 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3429 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3430 CORE_ADDR current_low
, current_high
;
3432 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3434 best_low
= current_low
;
3435 best_high
= current_high
;
3439 struct die_info
*child
= die
->child
;
3441 while (child
&& child
->tag
)
3443 switch (child
->tag
) {
3444 case DW_TAG_subprogram
:
3445 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3447 case DW_TAG_namespace
:
3448 /* FIXME: carlton/2004-01-16: Should we do this for
3449 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3450 that current GCC's always emit the DIEs corresponding
3451 to definitions of methods of classes as children of a
3452 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3453 the DIEs giving the declarations, which could be
3454 anywhere). But I don't see any reason why the
3455 standards says that they have to be there. */
3456 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3458 if (current_low
!= ((CORE_ADDR
) -1))
3460 best_low
= min (best_low
, current_low
);
3461 best_high
= max (best_high
, current_high
);
3469 child
= sibling_die (child
);
3474 *highpc
= best_high
;
3477 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3480 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3481 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3483 struct attribute
*attr
;
3485 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3488 CORE_ADDR high
= DW_ADDR (attr
);
3489 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3492 CORE_ADDR low
= DW_ADDR (attr
);
3493 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3497 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3500 bfd
*obfd
= cu
->objfile
->obfd
;
3502 /* The value of the DW_AT_ranges attribute is the offset of the
3503 address range list in the .debug_ranges section. */
3504 unsigned long offset
= DW_UNSND (attr
);
3505 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3507 /* For some target architectures, but not others, the
3508 read_address function sign-extends the addresses it returns.
3509 To recognize base address selection entries, we need a
3511 unsigned int addr_size
= cu
->header
.addr_size
;
3512 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3514 /* The base address, to which the next pair is relative. Note
3515 that this 'base' is a DWARF concept: most entries in a range
3516 list are relative, to reduce the number of relocs against the
3517 debugging information. This is separate from this function's
3518 'baseaddr' argument, which GDB uses to relocate debugging
3519 information from a shared library based on the address at
3520 which the library was loaded. */
3521 CORE_ADDR base
= cu
->base_address
;
3522 int base_known
= cu
->base_known
;
3524 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3526 complaint (&symfile_complaints
,
3527 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3534 unsigned int bytes_read
;
3535 CORE_ADDR start
, end
;
3537 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3538 buffer
+= bytes_read
;
3539 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3540 buffer
+= bytes_read
;
3542 /* Did we find the end of the range list? */
3543 if (start
== 0 && end
== 0)
3546 /* Did we find a base address selection entry? */
3547 else if ((start
& base_select_mask
) == base_select_mask
)
3553 /* We found an ordinary address range. */
3558 complaint (&symfile_complaints
,
3559 _("Invalid .debug_ranges data (no base address)"));
3563 record_block_range (block
,
3564 baseaddr
+ base
+ start
,
3565 baseaddr
+ base
+ end
- 1);
3571 /* Add an aggregate field to the field list. */
3574 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3575 struct dwarf2_cu
*cu
)
3577 struct objfile
*objfile
= cu
->objfile
;
3578 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3579 struct nextfield
*new_field
;
3580 struct attribute
*attr
;
3582 char *fieldname
= "";
3584 /* Allocate a new field list entry and link it in. */
3585 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3586 make_cleanup (xfree
, new_field
);
3587 memset (new_field
, 0, sizeof (struct nextfield
));
3588 new_field
->next
= fip
->fields
;
3589 fip
->fields
= new_field
;
3592 /* Handle accessibility and virtuality of field.
3593 The default accessibility for members is public, the default
3594 accessibility for inheritance is private. */
3595 if (die
->tag
!= DW_TAG_inheritance
)
3596 new_field
->accessibility
= DW_ACCESS_public
;
3598 new_field
->accessibility
= DW_ACCESS_private
;
3599 new_field
->virtuality
= DW_VIRTUALITY_none
;
3601 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3603 new_field
->accessibility
= DW_UNSND (attr
);
3604 if (new_field
->accessibility
!= DW_ACCESS_public
)
3605 fip
->non_public_fields
= 1;
3606 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3608 new_field
->virtuality
= DW_UNSND (attr
);
3610 fp
= &new_field
->field
;
3612 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3614 /* Data member other than a C++ static data member. */
3616 /* Get type of field. */
3617 fp
->type
= die_type (die
, cu
);
3619 SET_FIELD_BITPOS (*fp
, 0);
3621 /* Get bit size of field (zero if none). */
3622 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3625 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3629 FIELD_BITSIZE (*fp
) = 0;
3632 /* Get bit offset of field. */
3633 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3638 if (attr_form_is_section_offset (attr
))
3640 dwarf2_complex_location_expr_complaint ();
3643 else if (attr_form_is_constant (attr
))
3644 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3646 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3648 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3650 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3653 if (gdbarch_bits_big_endian (gdbarch
))
3655 /* For big endian bits, the DW_AT_bit_offset gives the
3656 additional bit offset from the MSB of the containing
3657 anonymous object to the MSB of the field. We don't
3658 have to do anything special since we don't need to
3659 know the size of the anonymous object. */
3660 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3664 /* For little endian bits, compute the bit offset to the
3665 MSB of the anonymous object, subtract off the number of
3666 bits from the MSB of the field to the MSB of the
3667 object, and then subtract off the number of bits of
3668 the field itself. The result is the bit offset of
3669 the LSB of the field. */
3671 int bit_offset
= DW_UNSND (attr
);
3673 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3676 /* The size of the anonymous object containing
3677 the bit field is explicit, so use the
3678 indicated size (in bytes). */
3679 anonymous_size
= DW_UNSND (attr
);
3683 /* The size of the anonymous object containing
3684 the bit field must be inferred from the type
3685 attribute of the data member containing the
3687 anonymous_size
= TYPE_LENGTH (fp
->type
);
3689 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3690 - bit_offset
- FIELD_BITSIZE (*fp
);
3694 /* Get name of field. */
3695 fieldname
= dwarf2_name (die
, cu
);
3696 if (fieldname
== NULL
)
3699 /* The name is already allocated along with this objfile, so we don't
3700 need to duplicate it for the type. */
3701 fp
->name
= fieldname
;
3703 /* Change accessibility for artificial fields (e.g. virtual table
3704 pointer or virtual base class pointer) to private. */
3705 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3707 new_field
->accessibility
= DW_ACCESS_private
;
3708 fip
->non_public_fields
= 1;
3711 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3713 /* C++ static member. */
3715 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3716 is a declaration, but all versions of G++ as of this writing
3717 (so through at least 3.2.1) incorrectly generate
3718 DW_TAG_variable tags. */
3722 /* Get name of field. */
3723 fieldname
= dwarf2_name (die
, cu
);
3724 if (fieldname
== NULL
)
3727 /* Get physical name. */
3728 physname
= dwarf2_linkage_name (die
, cu
);
3730 /* The name is already allocated along with this objfile, so we don't
3731 need to duplicate it for the type. */
3732 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3733 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3734 FIELD_NAME (*fp
) = fieldname
;
3736 else if (die
->tag
== DW_TAG_inheritance
)
3738 /* C++ base class field. */
3739 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3741 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
3743 FIELD_BITSIZE (*fp
) = 0;
3744 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3745 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3746 fip
->nbaseclasses
++;
3750 /* Create the vector of fields, and attach it to the type. */
3753 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3754 struct dwarf2_cu
*cu
)
3756 int nfields
= fip
->nfields
;
3758 /* Record the field count, allocate space for the array of fields,
3759 and create blank accessibility bitfields if necessary. */
3760 TYPE_NFIELDS (type
) = nfields
;
3761 TYPE_FIELDS (type
) = (struct field
*)
3762 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3763 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3765 if (fip
->non_public_fields
)
3767 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3769 TYPE_FIELD_PRIVATE_BITS (type
) =
3770 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3771 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3773 TYPE_FIELD_PROTECTED_BITS (type
) =
3774 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3775 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3777 TYPE_FIELD_IGNORE_BITS (type
) =
3778 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3779 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3782 /* If the type has baseclasses, allocate and clear a bit vector for
3783 TYPE_FIELD_VIRTUAL_BITS. */
3784 if (fip
->nbaseclasses
)
3786 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3787 unsigned char *pointer
;
3789 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3790 pointer
= TYPE_ALLOC (type
, num_bytes
);
3791 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3792 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3793 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3796 /* Copy the saved-up fields into the field vector. Start from the head
3797 of the list, adding to the tail of the field array, so that they end
3798 up in the same order in the array in which they were added to the list. */
3799 while (nfields
-- > 0)
3801 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3802 switch (fip
->fields
->accessibility
)
3804 case DW_ACCESS_private
:
3805 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3808 case DW_ACCESS_protected
:
3809 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3812 case DW_ACCESS_public
:
3816 /* Unknown accessibility. Complain and treat it as public. */
3818 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3819 fip
->fields
->accessibility
);
3823 if (nfields
< fip
->nbaseclasses
)
3825 switch (fip
->fields
->virtuality
)
3827 case DW_VIRTUALITY_virtual
:
3828 case DW_VIRTUALITY_pure_virtual
:
3829 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3833 fip
->fields
= fip
->fields
->next
;
3837 /* Add a member function to the proper fieldlist. */
3840 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3841 struct type
*type
, struct dwarf2_cu
*cu
)
3843 struct objfile
*objfile
= cu
->objfile
;
3844 struct attribute
*attr
;
3845 struct fnfieldlist
*flp
;
3847 struct fn_field
*fnp
;
3850 struct nextfnfield
*new_fnfield
;
3851 struct type
*this_type
;
3853 /* Get name of member function. */
3854 fieldname
= dwarf2_name (die
, cu
);
3855 if (fieldname
== NULL
)
3858 /* Get the mangled name. */
3859 physname
= dwarf2_linkage_name (die
, cu
);
3861 /* Look up member function name in fieldlist. */
3862 for (i
= 0; i
< fip
->nfnfields
; i
++)
3864 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3868 /* Create new list element if necessary. */
3869 if (i
< fip
->nfnfields
)
3870 flp
= &fip
->fnfieldlists
[i
];
3873 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3875 fip
->fnfieldlists
= (struct fnfieldlist
*)
3876 xrealloc (fip
->fnfieldlists
,
3877 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3878 * sizeof (struct fnfieldlist
));
3879 if (fip
->nfnfields
== 0)
3880 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3882 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3883 flp
->name
= fieldname
;
3889 /* Create a new member function field and chain it to the field list
3891 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3892 make_cleanup (xfree
, new_fnfield
);
3893 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3894 new_fnfield
->next
= flp
->head
;
3895 flp
->head
= new_fnfield
;
3898 /* Fill in the member function field info. */
3899 fnp
= &new_fnfield
->fnfield
;
3900 /* The name is already allocated along with this objfile, so we don't
3901 need to duplicate it for the type. */
3902 fnp
->physname
= physname
? physname
: "";
3903 fnp
->type
= alloc_type (objfile
);
3904 this_type
= read_type_die (die
, cu
);
3905 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3907 int nparams
= TYPE_NFIELDS (this_type
);
3909 /* TYPE is the domain of this method, and THIS_TYPE is the type
3910 of the method itself (TYPE_CODE_METHOD). */
3911 smash_to_method_type (fnp
->type
, type
,
3912 TYPE_TARGET_TYPE (this_type
),
3913 TYPE_FIELDS (this_type
),
3914 TYPE_NFIELDS (this_type
),
3915 TYPE_VARARGS (this_type
));
3917 /* Handle static member functions.
3918 Dwarf2 has no clean way to discern C++ static and non-static
3919 member functions. G++ helps GDB by marking the first
3920 parameter for non-static member functions (which is the
3921 this pointer) as artificial. We obtain this information
3922 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3923 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3924 fnp
->voffset
= VOFFSET_STATIC
;
3927 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3930 /* Get fcontext from DW_AT_containing_type if present. */
3931 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3932 fnp
->fcontext
= die_containing_type (die
, cu
);
3934 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3935 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3937 /* Get accessibility. */
3938 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3941 switch (DW_UNSND (attr
))
3943 case DW_ACCESS_private
:
3944 fnp
->is_private
= 1;
3946 case DW_ACCESS_protected
:
3947 fnp
->is_protected
= 1;
3952 /* Check for artificial methods. */
3953 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3954 if (attr
&& DW_UNSND (attr
) != 0)
3955 fnp
->is_artificial
= 1;
3957 /* Get index in virtual function table if it is a virtual member function. */
3958 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3961 /* Support the .debug_loc offsets */
3962 if (attr_form_is_block (attr
))
3964 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3966 else if (attr_form_is_section_offset (attr
))
3968 dwarf2_complex_location_expr_complaint ();
3972 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3978 /* Create the vector of member function fields, and attach it to the type. */
3981 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3982 struct dwarf2_cu
*cu
)
3984 struct fnfieldlist
*flp
;
3985 int total_length
= 0;
3988 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3989 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3990 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3992 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3994 struct nextfnfield
*nfp
= flp
->head
;
3995 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3998 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3999 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4000 fn_flp
->fn_fields
= (struct fn_field
*)
4001 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4002 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4003 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4005 total_length
+= flp
->length
;
4008 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4009 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4012 /* Returns non-zero if NAME is the name of a vtable member in CU's
4013 language, zero otherwise. */
4015 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4017 static const char vptr
[] = "_vptr";
4018 static const char vtable
[] = "vtable";
4020 /* Look for the C++ and Java forms of the vtable. */
4021 if ((cu
->language
== language_java
4022 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4023 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4024 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4030 /* GCC outputs unnamed structures that are really pointers to member
4031 functions, with the ABI-specified layout. If DIE (from CU) describes
4032 such a structure, set its type, and return nonzero. Otherwise return
4035 GCC shouldn't do this; it should just output pointer to member DIEs.
4036 This is GCC PR debug/28767. */
4038 static struct type
*
4039 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4041 struct objfile
*objfile
= cu
->objfile
;
4043 struct die_info
*pfn_die
, *delta_die
;
4044 struct attribute
*pfn_name
, *delta_name
;
4045 struct type
*pfn_type
, *domain_type
;
4047 /* Check for a structure with no name and two children. */
4048 if (die
->tag
!= DW_TAG_structure_type
4049 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4050 || die
->child
== NULL
4051 || die
->child
->sibling
== NULL
4052 || (die
->child
->sibling
->sibling
!= NULL
4053 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4056 /* Check for __pfn and __delta members. */
4057 pfn_die
= die
->child
;
4058 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4059 if (pfn_die
->tag
!= DW_TAG_member
4061 || DW_STRING (pfn_name
) == NULL
4062 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4065 delta_die
= pfn_die
->sibling
;
4066 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4067 if (delta_die
->tag
!= DW_TAG_member
4068 || delta_name
== NULL
4069 || DW_STRING (delta_name
) == NULL
4070 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4073 /* Find the type of the method. */
4074 pfn_type
= die_type (pfn_die
, cu
);
4075 if (pfn_type
== NULL
4076 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4077 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4080 /* Look for the "this" argument. */
4081 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4082 if (TYPE_NFIELDS (pfn_type
) == 0
4083 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4086 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4087 type
= alloc_type (objfile
);
4088 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4089 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4090 TYPE_VARARGS (pfn_type
));
4091 type
= lookup_methodptr_type (type
);
4092 return set_die_type (die
, type
, cu
);
4095 /* Called when we find the DIE that starts a structure or union scope
4096 (definition) to process all dies that define the members of the
4099 NOTE: we need to call struct_type regardless of whether or not the
4100 DIE has an at_name attribute, since it might be an anonymous
4101 structure or union. This gets the type entered into our set of
4104 However, if the structure is incomplete (an opaque struct/union)
4105 then suppress creating a symbol table entry for it since gdb only
4106 wants to find the one with the complete definition. Note that if
4107 it is complete, we just call new_symbol, which does it's own
4108 checking about whether the struct/union is anonymous or not (and
4109 suppresses creating a symbol table entry itself). */
4111 static struct type
*
4112 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4114 struct objfile
*objfile
= cu
->objfile
;
4116 struct attribute
*attr
;
4118 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4120 type
= quirk_gcc_member_function_pointer (die
, cu
);
4124 type
= alloc_type (objfile
);
4125 INIT_CPLUS_SPECIFIC (type
);
4126 name
= dwarf2_name (die
, cu
);
4129 if (cu
->language
== language_cplus
4130 || cu
->language
== language_java
)
4132 const char *new_prefix
= determine_class_name (die
, cu
);
4133 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4137 /* The name is already allocated along with this objfile, so
4138 we don't need to duplicate it for the type. */
4139 TYPE_TAG_NAME (type
) = name
;
4143 if (die
->tag
== DW_TAG_structure_type
)
4145 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4147 else if (die
->tag
== DW_TAG_union_type
)
4149 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4153 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4155 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4158 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4161 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4165 TYPE_LENGTH (type
) = 0;
4168 TYPE_STUB_SUPPORTED (type
) = 1;
4169 if (die_is_declaration (die
, cu
))
4170 TYPE_STUB (type
) = 1;
4172 /* We need to add the type field to the die immediately so we don't
4173 infinitely recurse when dealing with pointers to the structure
4174 type within the structure itself. */
4175 set_die_type (die
, type
, cu
);
4177 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4179 struct field_info fi
;
4180 struct die_info
*child_die
;
4182 memset (&fi
, 0, sizeof (struct field_info
));
4184 child_die
= die
->child
;
4186 while (child_die
&& child_die
->tag
)
4188 if (child_die
->tag
== DW_TAG_member
4189 || child_die
->tag
== DW_TAG_variable
)
4191 /* NOTE: carlton/2002-11-05: A C++ static data member
4192 should be a DW_TAG_member that is a declaration, but
4193 all versions of G++ as of this writing (so through at
4194 least 3.2.1) incorrectly generate DW_TAG_variable
4195 tags for them instead. */
4196 dwarf2_add_field (&fi
, child_die
, cu
);
4198 else if (child_die
->tag
== DW_TAG_subprogram
)
4200 /* C++ member function. */
4201 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4203 else if (child_die
->tag
== DW_TAG_inheritance
)
4205 /* C++ base class field. */
4206 dwarf2_add_field (&fi
, child_die
, cu
);
4208 child_die
= sibling_die (child_die
);
4211 /* Attach fields and member functions to the type. */
4213 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4216 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4218 /* Get the type which refers to the base class (possibly this
4219 class itself) which contains the vtable pointer for the current
4220 class from the DW_AT_containing_type attribute. */
4222 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4224 struct type
*t
= die_containing_type (die
, cu
);
4226 TYPE_VPTR_BASETYPE (type
) = t
;
4231 /* Our own class provides vtbl ptr. */
4232 for (i
= TYPE_NFIELDS (t
) - 1;
4233 i
>= TYPE_N_BASECLASSES (t
);
4236 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4238 if (is_vtable_name (fieldname
, cu
))
4240 TYPE_VPTR_FIELDNO (type
) = i
;
4245 /* Complain if virtual function table field not found. */
4246 if (i
< TYPE_N_BASECLASSES (t
))
4247 complaint (&symfile_complaints
,
4248 _("virtual function table pointer not found when defining class '%s'"),
4249 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4254 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4257 else if (cu
->producer
4258 && strncmp (cu
->producer
,
4259 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4261 /* The IBM XLC compiler does not provide direct indication
4262 of the containing type, but the vtable pointer is
4263 always named __vfp. */
4267 for (i
= TYPE_NFIELDS (type
) - 1;
4268 i
>= TYPE_N_BASECLASSES (type
);
4271 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4273 TYPE_VPTR_FIELDNO (type
) = i
;
4274 TYPE_VPTR_BASETYPE (type
) = type
;
4282 do_cleanups (back_to
);
4287 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4289 struct objfile
*objfile
= cu
->objfile
;
4290 struct die_info
*child_die
= die
->child
;
4291 struct type
*this_type
;
4293 this_type
= get_die_type (die
, cu
);
4294 if (this_type
== NULL
)
4295 this_type
= read_structure_type (die
, cu
);
4297 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4298 snapshots) has been known to create a die giving a declaration
4299 for a class that has, as a child, a die giving a definition for a
4300 nested class. So we have to process our children even if the
4301 current die is a declaration. Normally, of course, a declaration
4302 won't have any children at all. */
4304 while (child_die
!= NULL
&& child_die
->tag
)
4306 if (child_die
->tag
== DW_TAG_member
4307 || child_die
->tag
== DW_TAG_variable
4308 || child_die
->tag
== DW_TAG_inheritance
)
4313 process_die (child_die
, cu
);
4315 child_die
= sibling_die (child_die
);
4318 /* Do not consider external references. According to the DWARF standard,
4319 these DIEs are identified by the fact that they have no byte_size
4320 attribute, and a declaration attribute. */
4321 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4322 || !die_is_declaration (die
, cu
))
4323 new_symbol (die
, this_type
, cu
);
4326 /* Given a DW_AT_enumeration_type die, set its type. We do not
4327 complete the type's fields yet, or create any symbols. */
4329 static struct type
*
4330 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4332 struct objfile
*objfile
= cu
->objfile
;
4334 struct attribute
*attr
;
4337 type
= alloc_type (objfile
);
4339 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4340 name
= dwarf2_full_name (die
, cu
);
4342 TYPE_TAG_NAME (type
) = (char *) name
;
4344 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4347 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4351 TYPE_LENGTH (type
) = 0;
4354 /* The enumeration DIE can be incomplete. In Ada, any type can be
4355 declared as private in the package spec, and then defined only
4356 inside the package body. Such types are known as Taft Amendment
4357 Types. When another package uses such a type, an incomplete DIE
4358 may be generated by the compiler. */
4359 if (die_is_declaration (die
, cu
))
4360 TYPE_STUB (type
) = 1;
4362 return set_die_type (die
, type
, cu
);
4365 /* Determine the name of the type represented by DIE, which should be
4366 a named C++ or Java compound type. Return the name in question,
4367 allocated on the objfile obstack. */
4370 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4372 const char *new_prefix
= NULL
;
4374 /* If we don't have namespace debug info, guess the name by trying
4375 to demangle the names of members, just like we did in
4376 guess_structure_name. */
4377 if (!processing_has_namespace_info
)
4379 struct die_info
*child
;
4381 for (child
= die
->child
;
4382 child
!= NULL
&& child
->tag
!= 0;
4383 child
= sibling_die (child
))
4385 if (child
->tag
== DW_TAG_subprogram
)
4388 = language_class_name_from_physname (cu
->language_defn
,
4392 if (phys_prefix
!= NULL
)
4395 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4396 &cu
->objfile
->objfile_obstack
);
4397 xfree (phys_prefix
);
4404 if (new_prefix
== NULL
)
4405 new_prefix
= dwarf2_full_name (die
, cu
);
4410 /* Given a pointer to a die which begins an enumeration, process all
4411 the dies that define the members of the enumeration, and create the
4412 symbol for the enumeration type.
4414 NOTE: We reverse the order of the element list. */
4417 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4419 struct objfile
*objfile
= cu
->objfile
;
4420 struct die_info
*child_die
;
4421 struct field
*fields
;
4424 int unsigned_enum
= 1;
4426 struct type
*this_type
;
4430 this_type
= get_die_type (die
, cu
);
4431 if (this_type
== NULL
)
4432 this_type
= read_enumeration_type (die
, cu
);
4433 if (die
->child
!= NULL
)
4435 child_die
= die
->child
;
4436 while (child_die
&& child_die
->tag
)
4438 if (child_die
->tag
!= DW_TAG_enumerator
)
4440 process_die (child_die
, cu
);
4444 name
= dwarf2_name (child_die
, cu
);
4447 sym
= new_symbol (child_die
, this_type
, cu
);
4448 if (SYMBOL_VALUE (sym
) < 0)
4451 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4453 fields
= (struct field
*)
4455 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4456 * sizeof (struct field
));
4459 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4460 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4461 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4462 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4468 child_die
= sibling_die (child_die
);
4473 TYPE_NFIELDS (this_type
) = num_fields
;
4474 TYPE_FIELDS (this_type
) = (struct field
*)
4475 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4476 memcpy (TYPE_FIELDS (this_type
), fields
,
4477 sizeof (struct field
) * num_fields
);
4481 TYPE_UNSIGNED (this_type
) = 1;
4484 new_symbol (die
, this_type
, cu
);
4487 /* Extract all information from a DW_TAG_array_type DIE and put it in
4488 the DIE's type field. For now, this only handles one dimensional
4491 static struct type
*
4492 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4494 struct objfile
*objfile
= cu
->objfile
;
4495 struct die_info
*child_die
;
4496 struct type
*type
= NULL
;
4497 struct type
*element_type
, *range_type
, *index_type
;
4498 struct type
**range_types
= NULL
;
4499 struct attribute
*attr
;
4501 struct cleanup
*back_to
;
4504 element_type
= die_type (die
, cu
);
4506 /* Irix 6.2 native cc creates array types without children for
4507 arrays with unspecified length. */
4508 if (die
->child
== NULL
)
4510 index_type
= builtin_type_int32
;
4511 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4512 type
= create_array_type (NULL
, element_type
, range_type
);
4513 return set_die_type (die
, type
, cu
);
4516 back_to
= make_cleanup (null_cleanup
, NULL
);
4517 child_die
= die
->child
;
4518 while (child_die
&& child_die
->tag
)
4520 if (child_die
->tag
== DW_TAG_subrange_type
)
4522 struct type
*child_type
= read_type_die (child_die
, cu
);
4523 if (child_type
!= NULL
)
4525 /* The range type was succesfully read. Save it for
4526 the array type creation. */
4527 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4529 range_types
= (struct type
**)
4530 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4531 * sizeof (struct type
*));
4533 make_cleanup (free_current_contents
, &range_types
);
4535 range_types
[ndim
++] = child_type
;
4538 child_die
= sibling_die (child_die
);
4541 /* Dwarf2 dimensions are output from left to right, create the
4542 necessary array types in backwards order. */
4544 type
= element_type
;
4546 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4550 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4555 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4558 /* Understand Dwarf2 support for vector types (like they occur on
4559 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4560 array type. This is not part of the Dwarf2/3 standard yet, but a
4561 custom vendor extension. The main difference between a regular
4562 array and the vector variant is that vectors are passed by value
4564 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4566 make_vector_type (type
);
4568 name
= dwarf2_name (die
, cu
);
4570 TYPE_NAME (type
) = name
;
4572 do_cleanups (back_to
);
4574 /* Install the type in the die. */
4575 return set_die_type (die
, type
, cu
);
4578 static enum dwarf_array_dim_ordering
4579 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4581 struct attribute
*attr
;
4583 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4585 if (attr
) return DW_SND (attr
);
4588 GNU F77 is a special case, as at 08/2004 array type info is the
4589 opposite order to the dwarf2 specification, but data is still
4590 laid out as per normal fortran.
4592 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4596 if (cu
->language
== language_fortran
&&
4597 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4599 return DW_ORD_row_major
;
4602 switch (cu
->language_defn
->la_array_ordering
)
4604 case array_column_major
:
4605 return DW_ORD_col_major
;
4606 case array_row_major
:
4608 return DW_ORD_row_major
;
4612 /* Extract all information from a DW_TAG_set_type DIE and put it in
4613 the DIE's type field. */
4615 static struct type
*
4616 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4618 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4620 return set_die_type (die
, set_type
, cu
);
4623 /* First cut: install each common block member as a global variable. */
4626 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4628 struct die_info
*child_die
;
4629 struct attribute
*attr
;
4631 CORE_ADDR base
= (CORE_ADDR
) 0;
4633 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4636 /* Support the .debug_loc offsets */
4637 if (attr_form_is_block (attr
))
4639 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4641 else if (attr_form_is_section_offset (attr
))
4643 dwarf2_complex_location_expr_complaint ();
4647 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4648 "common block member");
4651 if (die
->child
!= NULL
)
4653 child_die
= die
->child
;
4654 while (child_die
&& child_die
->tag
)
4656 sym
= new_symbol (child_die
, NULL
, cu
);
4657 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4660 SYMBOL_VALUE_ADDRESS (sym
) =
4661 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4662 add_symbol_to_list (sym
, &global_symbols
);
4664 child_die
= sibling_die (child_die
);
4669 /* Create a type for a C++ namespace. */
4671 static struct type
*
4672 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4674 struct objfile
*objfile
= cu
->objfile
;
4675 const char *previous_prefix
, *name
;
4679 /* For extensions, reuse the type of the original namespace. */
4680 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4682 struct die_info
*ext_die
;
4683 struct dwarf2_cu
*ext_cu
= cu
;
4684 ext_die
= dwarf2_extension (die
, &ext_cu
);
4685 type
= read_type_die (ext_die
, ext_cu
);
4686 return set_die_type (die
, type
, cu
);
4689 name
= namespace_name (die
, &is_anonymous
, cu
);
4691 /* Now build the name of the current namespace. */
4693 previous_prefix
= determine_prefix (die
, cu
);
4694 if (previous_prefix
[0] != '\0')
4695 name
= typename_concat (&objfile
->objfile_obstack
,
4696 previous_prefix
, name
, cu
);
4698 /* Create the type. */
4699 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4701 TYPE_NAME (type
) = (char *) name
;
4702 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4704 set_die_type (die
, type
, cu
);
4709 /* Read a C++ namespace. */
4712 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4714 struct objfile
*objfile
= cu
->objfile
;
4718 /* Add a symbol associated to this if we haven't seen the namespace
4719 before. Also, add a using directive if it's an anonymous
4722 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4726 type
= read_type_die (die
, cu
);
4727 new_symbol (die
, type
, cu
);
4729 name
= namespace_name (die
, &is_anonymous
, cu
);
4732 const char *previous_prefix
= determine_prefix (die
, cu
);
4733 cp_add_using_directive (TYPE_NAME (type
),
4734 strlen (previous_prefix
),
4735 strlen (TYPE_NAME (type
)));
4739 if (die
->child
!= NULL
)
4741 struct die_info
*child_die
= die
->child
;
4743 while (child_die
&& child_die
->tag
)
4745 process_die (child_die
, cu
);
4746 child_die
= sibling_die (child_die
);
4751 /* Return the name of the namespace represented by DIE. Set
4752 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4756 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4758 struct die_info
*current_die
;
4759 const char *name
= NULL
;
4761 /* Loop through the extensions until we find a name. */
4763 for (current_die
= die
;
4764 current_die
!= NULL
;
4765 current_die
= dwarf2_extension (die
, &cu
))
4767 name
= dwarf2_name (current_die
, cu
);
4772 /* Is it an anonymous namespace? */
4774 *is_anonymous
= (name
== NULL
);
4776 name
= "(anonymous namespace)";
4781 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4782 the user defined type vector. */
4784 static struct type
*
4785 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4787 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4788 struct comp_unit_head
*cu_header
= &cu
->header
;
4790 struct attribute
*attr_byte_size
;
4791 struct attribute
*attr_address_class
;
4792 int byte_size
, addr_class
;
4794 type
= lookup_pointer_type (die_type (die
, cu
));
4796 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4798 byte_size
= DW_UNSND (attr_byte_size
);
4800 byte_size
= cu_header
->addr_size
;
4802 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4803 if (attr_address_class
)
4804 addr_class
= DW_UNSND (attr_address_class
);
4806 addr_class
= DW_ADDR_none
;
4808 /* If the pointer size or address class is different than the
4809 default, create a type variant marked as such and set the
4810 length accordingly. */
4811 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4813 if (gdbarch_address_class_type_flags_p (gdbarch
))
4817 type_flags
= gdbarch_address_class_type_flags
4818 (gdbarch
, byte_size
, addr_class
);
4819 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4821 type
= make_type_with_address_space (type
, type_flags
);
4823 else if (TYPE_LENGTH (type
) != byte_size
)
4825 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4828 /* Should we also complain about unhandled address classes? */
4832 TYPE_LENGTH (type
) = byte_size
;
4833 return set_die_type (die
, type
, cu
);
4836 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4837 the user defined type vector. */
4839 static struct type
*
4840 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4842 struct objfile
*objfile
= cu
->objfile
;
4844 struct type
*to_type
;
4845 struct type
*domain
;
4847 to_type
= die_type (die
, cu
);
4848 domain
= die_containing_type (die
, cu
);
4850 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4851 type
= lookup_methodptr_type (to_type
);
4853 type
= lookup_memberptr_type (to_type
, domain
);
4855 return set_die_type (die
, type
, cu
);
4858 /* Extract all information from a DW_TAG_reference_type DIE and add to
4859 the user defined type vector. */
4861 static struct type
*
4862 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4864 struct comp_unit_head
*cu_header
= &cu
->header
;
4866 struct attribute
*attr
;
4868 type
= lookup_reference_type (die_type (die
, cu
));
4869 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4872 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4876 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4878 return set_die_type (die
, type
, cu
);
4881 static struct type
*
4882 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4884 struct type
*base_type
, *cv_type
;
4886 base_type
= die_type (die
, cu
);
4887 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4888 return set_die_type (die
, cv_type
, cu
);
4891 static struct type
*
4892 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4894 struct type
*base_type
, *cv_type
;
4896 base_type
= die_type (die
, cu
);
4897 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4898 return set_die_type (die
, cv_type
, cu
);
4901 /* Extract all information from a DW_TAG_string_type DIE and add to
4902 the user defined type vector. It isn't really a user defined type,
4903 but it behaves like one, with other DIE's using an AT_user_def_type
4904 attribute to reference it. */
4906 static struct type
*
4907 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4909 struct objfile
*objfile
= cu
->objfile
;
4910 struct type
*type
, *range_type
, *index_type
, *char_type
;
4911 struct attribute
*attr
;
4912 unsigned int length
;
4914 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4917 length
= DW_UNSND (attr
);
4921 /* check for the DW_AT_byte_size attribute */
4922 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4925 length
= DW_UNSND (attr
);
4933 index_type
= builtin_type_int32
;
4934 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4935 type
= create_string_type (NULL
, range_type
);
4937 return set_die_type (die
, type
, cu
);
4940 /* Handle DIES due to C code like:
4944 int (*funcp)(int a, long l);
4948 ('funcp' generates a DW_TAG_subroutine_type DIE)
4951 static struct type
*
4952 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4954 struct type
*type
; /* Type that this function returns */
4955 struct type
*ftype
; /* Function that returns above type */
4956 struct attribute
*attr
;
4958 type
= die_type (die
, cu
);
4959 ftype
= make_function_type (type
, (struct type
**) 0);
4961 /* All functions in C++, Pascal and Java have prototypes. */
4962 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4963 if ((attr
&& (DW_UNSND (attr
) != 0))
4964 || cu
->language
== language_cplus
4965 || cu
->language
== language_java
4966 || cu
->language
== language_pascal
)
4967 TYPE_PROTOTYPED (ftype
) = 1;
4969 /* Store the calling convention in the type if it's available in
4970 the subroutine die. Otherwise set the calling convention to
4971 the default value DW_CC_normal. */
4972 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4973 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4975 if (die
->child
!= NULL
)
4977 struct die_info
*child_die
;
4981 /* Count the number of parameters.
4982 FIXME: GDB currently ignores vararg functions, but knows about
4983 vararg member functions. */
4984 child_die
= die
->child
;
4985 while (child_die
&& child_die
->tag
)
4987 if (child_die
->tag
== DW_TAG_formal_parameter
)
4989 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4990 TYPE_VARARGS (ftype
) = 1;
4991 child_die
= sibling_die (child_die
);
4994 /* Allocate storage for parameters and fill them in. */
4995 TYPE_NFIELDS (ftype
) = nparams
;
4996 TYPE_FIELDS (ftype
) = (struct field
*)
4997 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4999 child_die
= die
->child
;
5000 while (child_die
&& child_die
->tag
)
5002 if (child_die
->tag
== DW_TAG_formal_parameter
)
5004 /* Dwarf2 has no clean way to discern C++ static and non-static
5005 member functions. G++ helps GDB by marking the first
5006 parameter for non-static member functions (which is the
5007 this pointer) as artificial. We pass this information
5008 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5009 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5011 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5013 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5014 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5017 child_die
= sibling_die (child_die
);
5021 return set_die_type (die
, ftype
, cu
);
5024 static struct type
*
5025 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5027 struct objfile
*objfile
= cu
->objfile
;
5028 struct attribute
*attr
;
5029 const char *name
= NULL
;
5030 struct type
*this_type
;
5032 name
= dwarf2_full_name (die
, cu
);
5033 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5034 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5035 TYPE_NAME (this_type
) = (char *) name
;
5036 set_die_type (die
, this_type
, cu
);
5037 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5041 /* Find a representation of a given base type and install
5042 it in the TYPE field of the die. */
5044 static struct type
*
5045 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5047 struct objfile
*objfile
= cu
->objfile
;
5049 struct attribute
*attr
;
5050 int encoding
= 0, size
= 0;
5052 enum type_code code
= TYPE_CODE_INT
;
5054 struct type
*target_type
= NULL
;
5056 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5059 encoding
= DW_UNSND (attr
);
5061 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5064 size
= DW_UNSND (attr
);
5066 name
= dwarf2_name (die
, cu
);
5069 complaint (&symfile_complaints
,
5070 _("DW_AT_name missing from DW_TAG_base_type"));
5075 case DW_ATE_address
:
5076 /* Turn DW_ATE_address into a void * pointer. */
5077 code
= TYPE_CODE_PTR
;
5078 type_flags
|= TYPE_FLAG_UNSIGNED
;
5079 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5081 case DW_ATE_boolean
:
5082 code
= TYPE_CODE_BOOL
;
5083 type_flags
|= TYPE_FLAG_UNSIGNED
;
5085 case DW_ATE_complex_float
:
5086 code
= TYPE_CODE_COMPLEX
;
5087 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5089 case DW_ATE_decimal_float
:
5090 code
= TYPE_CODE_DECFLOAT
;
5093 code
= TYPE_CODE_FLT
;
5097 case DW_ATE_unsigned
:
5098 type_flags
|= TYPE_FLAG_UNSIGNED
;
5100 case DW_ATE_signed_char
:
5101 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5102 code
= TYPE_CODE_CHAR
;
5104 case DW_ATE_unsigned_char
:
5105 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5106 code
= TYPE_CODE_CHAR
;
5107 type_flags
|= TYPE_FLAG_UNSIGNED
;
5110 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5111 dwarf_type_encoding_name (encoding
));
5115 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5116 TYPE_NAME (type
) = name
;
5117 TYPE_TARGET_TYPE (type
) = target_type
;
5119 if (name
&& strcmp (name
, "char") == 0)
5120 TYPE_NOSIGN (type
) = 1;
5122 return set_die_type (die
, type
, cu
);
5125 /* Read the given DW_AT_subrange DIE. */
5127 static struct type
*
5128 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5130 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5131 struct type
*base_type
;
5132 struct type
*range_type
;
5133 struct attribute
*attr
;
5138 base_type
= die_type (die
, cu
);
5139 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5141 complaint (&symfile_complaints
,
5142 _("DW_AT_type missing from DW_TAG_subrange_type"));
5144 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5145 0, NULL
, cu
->objfile
);
5148 if (cu
->language
== language_fortran
)
5150 /* FORTRAN implies a lower bound of 1, if not given. */
5154 /* FIXME: For variable sized arrays either of these could be
5155 a variable rather than a constant value. We'll allow it,
5156 but we don't know how to handle it. */
5157 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5159 low
= dwarf2_get_attr_constant_value (attr
, 0);
5161 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5164 if (attr
->form
== DW_FORM_block1
)
5166 /* GCC encodes arrays with unspecified or dynamic length
5167 with a DW_FORM_block1 attribute.
5168 FIXME: GDB does not yet know how to handle dynamic
5169 arrays properly, treat them as arrays with unspecified
5172 FIXME: jimb/2003-09-22: GDB does not really know
5173 how to handle arrays of unspecified length
5174 either; we just represent them as zero-length
5175 arrays. Choose an appropriate upper bound given
5176 the lower bound we've computed above. */
5180 high
= dwarf2_get_attr_constant_value (attr
, 1);
5183 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5185 name
= dwarf2_name (die
, cu
);
5187 TYPE_NAME (range_type
) = name
;
5189 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5191 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5193 return set_die_type (die
, range_type
, cu
);
5196 static struct type
*
5197 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5201 /* For now, we only support the C meaning of an unspecified type: void. */
5203 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5204 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5206 return set_die_type (die
, type
, cu
);
5209 /* Trivial hash function for die_info: the hash value of a DIE
5210 is its offset in .debug_info for this objfile. */
5213 die_hash (const void *item
)
5215 const struct die_info
*die
= item
;
5219 /* Trivial comparison function for die_info structures: two DIEs
5220 are equal if they have the same offset. */
5223 die_eq (const void *item_lhs
, const void *item_rhs
)
5225 const struct die_info
*die_lhs
= item_lhs
;
5226 const struct die_info
*die_rhs
= item_rhs
;
5227 return die_lhs
->offset
== die_rhs
->offset
;
5230 /* Read a whole compilation unit into a linked list of dies. */
5232 static struct die_info
*
5233 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5236 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5240 &cu
->comp_unit_obstack
,
5241 hashtab_obstack_allocate
,
5242 dummy_obstack_deallocate
);
5244 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5247 /* Main entry point for reading a DIE and all children.
5248 Read the DIE and dump it if requested. */
5250 static struct die_info
*
5251 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5252 struct dwarf2_cu
*cu
,
5253 gdb_byte
**new_info_ptr
,
5254 struct die_info
*parent
)
5256 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5257 new_info_ptr
, parent
);
5259 if (dwarf2_die_debug
)
5261 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5262 dump_die (result
, dwarf2_die_debug
);
5268 /* Read a single die and all its descendents. Set the die's sibling
5269 field to NULL; set other fields in the die correctly, and set all
5270 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5271 location of the info_ptr after reading all of those dies. PARENT
5272 is the parent of the die in question. */
5274 static struct die_info
*
5275 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5276 struct dwarf2_cu
*cu
,
5277 gdb_byte
**new_info_ptr
,
5278 struct die_info
*parent
)
5280 struct die_info
*die
;
5284 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5287 *new_info_ptr
= cur_ptr
;
5290 store_in_ref_table (die
, cu
);
5294 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5300 *new_info_ptr
= cur_ptr
;
5303 die
->sibling
= NULL
;
5304 die
->parent
= parent
;
5308 /* Read a die, all of its descendents, and all of its siblings; set
5309 all of the fields of all of the dies correctly. Arguments are as
5310 in read_die_and_children. */
5312 static struct die_info
*
5313 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5314 struct dwarf2_cu
*cu
,
5315 gdb_byte
**new_info_ptr
,
5316 struct die_info
*parent
)
5318 struct die_info
*first_die
, *last_sibling
;
5322 first_die
= last_sibling
= NULL
;
5326 struct die_info
*die
5327 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5331 *new_info_ptr
= cur_ptr
;
5338 last_sibling
->sibling
= die
;
5344 /* Decompress a section that was compressed using zlib. Store the
5345 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5348 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5349 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5351 bfd
*abfd
= objfile
->obfd
;
5353 error (_("Support for zlib-compressed DWARF data (from '%s') "
5354 "is disabled in this copy of GDB"),
5355 bfd_get_filename (abfd
));
5357 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5358 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5359 bfd_size_type uncompressed_size
;
5360 gdb_byte
*uncompressed_buffer
;
5363 int header_size
= 12;
5365 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5366 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5367 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5368 bfd_get_filename (abfd
));
5370 /* Read the zlib header. In this case, it should be "ZLIB" followed
5371 by the uncompressed section size, 8 bytes in big-endian order. */
5372 if (compressed_size
< header_size
5373 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5374 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5375 bfd_get_filename (abfd
));
5376 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5377 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5378 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5379 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5380 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5381 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5382 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5383 uncompressed_size
+= compressed_buffer
[11];
5385 /* It is possible the section consists of several compressed
5386 buffers concatenated together, so we uncompress in a loop. */
5390 strm
.avail_in
= compressed_size
- header_size
;
5391 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5392 strm
.avail_out
= uncompressed_size
;
5393 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5395 rc
= inflateInit (&strm
);
5396 while (strm
.avail_in
> 0)
5399 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5400 bfd_get_filename (abfd
), rc
);
5401 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5402 + (uncompressed_size
- strm
.avail_out
));
5403 rc
= inflate (&strm
, Z_FINISH
);
5404 if (rc
!= Z_STREAM_END
)
5405 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5406 bfd_get_filename (abfd
), rc
);
5407 rc
= inflateReset (&strm
);
5409 rc
= inflateEnd (&strm
);
5411 || strm
.avail_out
!= 0)
5412 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5413 bfd_get_filename (abfd
), rc
);
5415 xfree (compressed_buffer
);
5416 *outbuf
= uncompressed_buffer
;
5417 *outsize
= uncompressed_size
;
5422 /* Read the contents of the section at OFFSET and of size SIZE from the
5423 object file specified by OBJFILE into the objfile_obstack and return it.
5424 If the section is compressed, uncompress it before returning. */
5427 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5429 bfd
*abfd
= objfile
->obfd
;
5430 gdb_byte
*buf
, *retbuf
;
5431 bfd_size_type size
= bfd_get_section_size (sectp
);
5432 unsigned char header
[4];
5437 /* Check if the file has a 4-byte header indicating compression. */
5438 if (size
> sizeof (header
)
5439 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5440 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5442 /* Upon decompression, update the buffer and its size. */
5443 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5445 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5446 dwarf2_resize_section (sectp
, size
);
5451 /* If we get here, we are a normal, not-compressed section. */
5452 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5453 /* When debugging .o files, we may need to apply relocations; see
5454 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5455 We never compress sections in .o files, so we only need to
5456 try this when the section is not compressed. */
5457 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5461 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5462 || bfd_bread (buf
, size
, abfd
) != size
)
5463 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5464 bfd_get_filename (abfd
));
5469 /* In DWARF version 2, the description of the debugging information is
5470 stored in a separate .debug_abbrev section. Before we read any
5471 dies from a section we read in all abbreviations and install them
5472 in a hash table. This function also sets flags in CU describing
5473 the data found in the abbrev table. */
5476 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5478 struct comp_unit_head
*cu_header
= &cu
->header
;
5479 gdb_byte
*abbrev_ptr
;
5480 struct abbrev_info
*cur_abbrev
;
5481 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5482 unsigned int abbrev_form
, hash_number
;
5483 struct attr_abbrev
*cur_attrs
;
5484 unsigned int allocated_attrs
;
5486 /* Initialize dwarf2 abbrevs */
5487 obstack_init (&cu
->abbrev_obstack
);
5488 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5490 * sizeof (struct abbrev_info
*)));
5491 memset (cu
->dwarf2_abbrevs
, 0,
5492 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5494 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5495 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5496 abbrev_ptr
+= bytes_read
;
5498 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5499 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5501 /* loop until we reach an abbrev number of 0 */
5502 while (abbrev_number
)
5504 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5506 /* read in abbrev header */
5507 cur_abbrev
->number
= abbrev_number
;
5508 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5509 abbrev_ptr
+= bytes_read
;
5510 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5513 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5514 cu
->has_namespace_info
= 1;
5516 /* now read in declarations */
5517 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5518 abbrev_ptr
+= bytes_read
;
5519 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5520 abbrev_ptr
+= bytes_read
;
5523 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5525 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5527 = xrealloc (cur_attrs
, (allocated_attrs
5528 * sizeof (struct attr_abbrev
)));
5531 /* Record whether this compilation unit might have
5532 inter-compilation-unit references. If we don't know what form
5533 this attribute will have, then it might potentially be a
5534 DW_FORM_ref_addr, so we conservatively expect inter-CU
5537 if (abbrev_form
== DW_FORM_ref_addr
5538 || abbrev_form
== DW_FORM_indirect
)
5539 cu
->has_form_ref_addr
= 1;
5541 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5542 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5543 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5544 abbrev_ptr
+= bytes_read
;
5545 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5546 abbrev_ptr
+= bytes_read
;
5549 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5550 (cur_abbrev
->num_attrs
5551 * sizeof (struct attr_abbrev
)));
5552 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5553 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5555 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5556 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5557 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5559 /* Get next abbreviation.
5560 Under Irix6 the abbreviations for a compilation unit are not
5561 always properly terminated with an abbrev number of 0.
5562 Exit loop if we encounter an abbreviation which we have
5563 already read (which means we are about to read the abbreviations
5564 for the next compile unit) or if the end of the abbreviation
5565 table is reached. */
5566 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5567 >= dwarf2_per_objfile
->abbrev_size
)
5569 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5570 abbrev_ptr
+= bytes_read
;
5571 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5578 /* Release the memory used by the abbrev table for a compilation unit. */
5581 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5583 struct dwarf2_cu
*cu
= ptr_to_cu
;
5585 obstack_free (&cu
->abbrev_obstack
, NULL
);
5586 cu
->dwarf2_abbrevs
= NULL
;
5589 /* Lookup an abbrev_info structure in the abbrev hash table. */
5591 static struct abbrev_info
*
5592 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5594 unsigned int hash_number
;
5595 struct abbrev_info
*abbrev
;
5597 hash_number
= number
% ABBREV_HASH_SIZE
;
5598 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5602 if (abbrev
->number
== number
)
5605 abbrev
= abbrev
->next
;
5610 /* Returns nonzero if TAG represents a type that we might generate a partial
5614 is_type_tag_for_partial (int tag
)
5619 /* Some types that would be reasonable to generate partial symbols for,
5620 that we don't at present. */
5621 case DW_TAG_array_type
:
5622 case DW_TAG_file_type
:
5623 case DW_TAG_ptr_to_member_type
:
5624 case DW_TAG_set_type
:
5625 case DW_TAG_string_type
:
5626 case DW_TAG_subroutine_type
:
5628 case DW_TAG_base_type
:
5629 case DW_TAG_class_type
:
5630 case DW_TAG_interface_type
:
5631 case DW_TAG_enumeration_type
:
5632 case DW_TAG_structure_type
:
5633 case DW_TAG_subrange_type
:
5634 case DW_TAG_typedef
:
5635 case DW_TAG_union_type
:
5642 /* Load all DIEs that are interesting for partial symbols into memory. */
5644 static struct partial_die_info
*
5645 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5646 struct dwarf2_cu
*cu
)
5648 struct partial_die_info
*part_die
;
5649 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5650 struct abbrev_info
*abbrev
;
5651 unsigned int bytes_read
;
5652 unsigned int load_all
= 0;
5654 int nesting_level
= 1;
5659 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5663 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5667 &cu
->comp_unit_obstack
,
5668 hashtab_obstack_allocate
,
5669 dummy_obstack_deallocate
);
5671 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5672 sizeof (struct partial_die_info
));
5676 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5678 /* A NULL abbrev means the end of a series of children. */
5681 if (--nesting_level
== 0)
5683 /* PART_DIE was probably the last thing allocated on the
5684 comp_unit_obstack, so we could call obstack_free
5685 here. We don't do that because the waste is small,
5686 and will be cleaned up when we're done with this
5687 compilation unit. This way, we're also more robust
5688 against other users of the comp_unit_obstack. */
5691 info_ptr
+= bytes_read
;
5692 last_die
= parent_die
;
5693 parent_die
= parent_die
->die_parent
;
5697 /* Check whether this DIE is interesting enough to save. Normally
5698 we would not be interested in members here, but there may be
5699 later variables referencing them via DW_AT_specification (for
5702 && !is_type_tag_for_partial (abbrev
->tag
)
5703 && abbrev
->tag
!= DW_TAG_enumerator
5704 && abbrev
->tag
!= DW_TAG_subprogram
5705 && abbrev
->tag
!= DW_TAG_lexical_block
5706 && abbrev
->tag
!= DW_TAG_variable
5707 && abbrev
->tag
!= DW_TAG_namespace
5708 && abbrev
->tag
!= DW_TAG_member
)
5710 /* Otherwise we skip to the next sibling, if any. */
5711 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5715 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5716 abfd
, info_ptr
, cu
);
5718 /* This two-pass algorithm for processing partial symbols has a
5719 high cost in cache pressure. Thus, handle some simple cases
5720 here which cover the majority of C partial symbols. DIEs
5721 which neither have specification tags in them, nor could have
5722 specification tags elsewhere pointing at them, can simply be
5723 processed and discarded.
5725 This segment is also optional; scan_partial_symbols and
5726 add_partial_symbol will handle these DIEs if we chain
5727 them in normally. When compilers which do not emit large
5728 quantities of duplicate debug information are more common,
5729 this code can probably be removed. */
5731 /* Any complete simple types at the top level (pretty much all
5732 of them, for a language without namespaces), can be processed
5734 if (parent_die
== NULL
5735 && part_die
->has_specification
== 0
5736 && part_die
->is_declaration
== 0
5737 && (part_die
->tag
== DW_TAG_typedef
5738 || part_die
->tag
== DW_TAG_base_type
5739 || part_die
->tag
== DW_TAG_subrange_type
))
5741 if (building_psymtab
&& part_die
->name
!= NULL
)
5742 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5743 VAR_DOMAIN
, LOC_TYPEDEF
,
5744 &cu
->objfile
->static_psymbols
,
5745 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5746 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5750 /* If we're at the second level, and we're an enumerator, and
5751 our parent has no specification (meaning possibly lives in a
5752 namespace elsewhere), then we can add the partial symbol now
5753 instead of queueing it. */
5754 if (part_die
->tag
== DW_TAG_enumerator
5755 && parent_die
!= NULL
5756 && parent_die
->die_parent
== NULL
5757 && parent_die
->tag
== DW_TAG_enumeration_type
5758 && parent_die
->has_specification
== 0)
5760 if (part_die
->name
== NULL
)
5761 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5762 else if (building_psymtab
)
5763 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5764 VAR_DOMAIN
, LOC_CONST
,
5765 (cu
->language
== language_cplus
5766 || cu
->language
== language_java
)
5767 ? &cu
->objfile
->global_psymbols
5768 : &cu
->objfile
->static_psymbols
,
5769 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5771 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5775 /* We'll save this DIE so link it in. */
5776 part_die
->die_parent
= parent_die
;
5777 part_die
->die_sibling
= NULL
;
5778 part_die
->die_child
= NULL
;
5780 if (last_die
&& last_die
== parent_die
)
5781 last_die
->die_child
= part_die
;
5783 last_die
->die_sibling
= part_die
;
5785 last_die
= part_die
;
5787 if (first_die
== NULL
)
5788 first_die
= part_die
;
5790 /* Maybe add the DIE to the hash table. Not all DIEs that we
5791 find interesting need to be in the hash table, because we
5792 also have the parent/sibling/child chains; only those that we
5793 might refer to by offset later during partial symbol reading.
5795 For now this means things that might have be the target of a
5796 DW_AT_specification, DW_AT_abstract_origin, or
5797 DW_AT_extension. DW_AT_extension will refer only to
5798 namespaces; DW_AT_abstract_origin refers to functions (and
5799 many things under the function DIE, but we do not recurse
5800 into function DIEs during partial symbol reading) and
5801 possibly variables as well; DW_AT_specification refers to
5802 declarations. Declarations ought to have the DW_AT_declaration
5803 flag. It happens that GCC forgets to put it in sometimes, but
5804 only for functions, not for types.
5806 Adding more things than necessary to the hash table is harmless
5807 except for the performance cost. Adding too few will result in
5808 wasted time in find_partial_die, when we reread the compilation
5809 unit with load_all_dies set. */
5812 || abbrev
->tag
== DW_TAG_subprogram
5813 || abbrev
->tag
== DW_TAG_variable
5814 || abbrev
->tag
== DW_TAG_namespace
5815 || part_die
->is_declaration
)
5819 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5820 part_die
->offset
, INSERT
);
5824 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5825 sizeof (struct partial_die_info
));
5827 /* For some DIEs we want to follow their children (if any). For C
5828 we have no reason to follow the children of structures; for other
5829 languages we have to, both so that we can get at method physnames
5830 to infer fully qualified class names, and for DW_AT_specification.
5832 For Ada, we need to scan the children of subprograms and lexical
5833 blocks as well because Ada allows the definition of nested
5834 entities that could be interesting for the debugger, such as
5835 nested subprograms for instance. */
5836 if (last_die
->has_children
5838 || last_die
->tag
== DW_TAG_namespace
5839 || last_die
->tag
== DW_TAG_enumeration_type
5840 || (cu
->language
!= language_c
5841 && (last_die
->tag
== DW_TAG_class_type
5842 || last_die
->tag
== DW_TAG_interface_type
5843 || last_die
->tag
== DW_TAG_structure_type
5844 || last_die
->tag
== DW_TAG_union_type
))
5845 || (cu
->language
== language_ada
5846 && (last_die
->tag
== DW_TAG_subprogram
5847 || last_die
->tag
== DW_TAG_lexical_block
))))
5850 parent_die
= last_die
;
5854 /* Otherwise we skip to the next sibling, if any. */
5855 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5857 /* Back to the top, do it again. */
5861 /* Read a minimal amount of information into the minimal die structure. */
5864 read_partial_die (struct partial_die_info
*part_die
,
5865 struct abbrev_info
*abbrev
,
5866 unsigned int abbrev_len
, bfd
*abfd
,
5867 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5869 unsigned int bytes_read
, i
;
5870 struct attribute attr
;
5871 int has_low_pc_attr
= 0;
5872 int has_high_pc_attr
= 0;
5873 CORE_ADDR base_address
= 0;
5877 base_address_low_pc
,
5878 /* Overrides BASE_ADDRESS_LOW_PC. */
5879 base_address_entry_pc
5881 base_address_type
= base_address_none
;
5883 memset (part_die
, 0, sizeof (struct partial_die_info
));
5885 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5887 info_ptr
+= abbrev_len
;
5892 part_die
->tag
= abbrev
->tag
;
5893 part_die
->has_children
= abbrev
->has_children
;
5895 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5897 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5899 /* Store the data if it is of an attribute we want to keep in a
5900 partial symbol table. */
5905 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5906 if (part_die
->name
== NULL
)
5907 part_die
->name
= DW_STRING (&attr
);
5909 case DW_AT_comp_dir
:
5910 if (part_die
->dirname
== NULL
)
5911 part_die
->dirname
= DW_STRING (&attr
);
5913 case DW_AT_MIPS_linkage_name
:
5914 part_die
->name
= DW_STRING (&attr
);
5917 has_low_pc_attr
= 1;
5918 part_die
->lowpc
= DW_ADDR (&attr
);
5919 if (part_die
->tag
== DW_TAG_compile_unit
5920 && base_address_type
< base_address_low_pc
)
5922 base_address
= DW_ADDR (&attr
);
5923 base_address_type
= base_address_low_pc
;
5927 has_high_pc_attr
= 1;
5928 part_die
->highpc
= DW_ADDR (&attr
);
5930 case DW_AT_entry_pc
:
5931 if (part_die
->tag
== DW_TAG_compile_unit
5932 && base_address_type
< base_address_entry_pc
)
5934 base_address
= DW_ADDR (&attr
);
5935 base_address_type
= base_address_entry_pc
;
5939 if (part_die
->tag
== DW_TAG_compile_unit
)
5941 cu
->ranges_offset
= DW_UNSND (&attr
);
5942 cu
->has_ranges_offset
= 1;
5945 case DW_AT_location
:
5946 /* Support the .debug_loc offsets */
5947 if (attr_form_is_block (&attr
))
5949 part_die
->locdesc
= DW_BLOCK (&attr
);
5951 else if (attr_form_is_section_offset (&attr
))
5953 dwarf2_complex_location_expr_complaint ();
5957 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5958 "partial symbol information");
5961 case DW_AT_language
:
5962 part_die
->language
= DW_UNSND (&attr
);
5964 case DW_AT_external
:
5965 part_die
->is_external
= DW_UNSND (&attr
);
5967 case DW_AT_declaration
:
5968 part_die
->is_declaration
= DW_UNSND (&attr
);
5971 part_die
->has_type
= 1;
5973 case DW_AT_abstract_origin
:
5974 case DW_AT_specification
:
5975 case DW_AT_extension
:
5976 part_die
->has_specification
= 1;
5977 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
5980 /* Ignore absolute siblings, they might point outside of
5981 the current compile unit. */
5982 if (attr
.form
== DW_FORM_ref_addr
)
5983 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5985 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5986 + dwarf2_get_ref_die_offset (&attr
);
5988 case DW_AT_stmt_list
:
5989 part_die
->has_stmt_list
= 1;
5990 part_die
->line_offset
= DW_UNSND (&attr
);
5992 case DW_AT_byte_size
:
5993 part_die
->has_byte_size
= 1;
5995 case DW_AT_calling_convention
:
5996 /* DWARF doesn't provide a way to identify a program's source-level
5997 entry point. DW_AT_calling_convention attributes are only meant
5998 to describe functions' calling conventions.
6000 However, because it's a necessary piece of information in
6001 Fortran, and because DW_CC_program is the only piece of debugging
6002 information whose definition refers to a 'main program' at all,
6003 several compilers have begun marking Fortran main programs with
6004 DW_CC_program --- even when those functions use the standard
6005 calling conventions.
6007 So until DWARF specifies a way to provide this information and
6008 compilers pick up the new representation, we'll support this
6010 if (DW_UNSND (&attr
) == DW_CC_program
6011 && cu
->language
== language_fortran
)
6012 set_main_name (part_die
->name
);
6019 /* When using the GNU linker, .gnu.linkonce. sections are used to
6020 eliminate duplicate copies of functions and vtables and such.
6021 The linker will arbitrarily choose one and discard the others.
6022 The AT_*_pc values for such functions refer to local labels in
6023 these sections. If the section from that file was discarded, the
6024 labels are not in the output, so the relocs get a value of 0.
6025 If this is a discarded function, mark the pc bounds as invalid,
6026 so that GDB will ignore it. */
6027 if (has_low_pc_attr
&& has_high_pc_attr
6028 && part_die
->lowpc
< part_die
->highpc
6029 && (part_die
->lowpc
!= 0
6030 || dwarf2_per_objfile
->has_section_at_zero
))
6031 part_die
->has_pc_info
= 1;
6033 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6035 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6037 cu
->base_address
= base_address
;
6043 /* Find a cached partial DIE at OFFSET in CU. */
6045 static struct partial_die_info
*
6046 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6048 struct partial_die_info
*lookup_die
= NULL
;
6049 struct partial_die_info part_die
;
6051 part_die
.offset
= offset
;
6052 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6057 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6059 static struct partial_die_info
*
6060 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6062 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6063 struct partial_die_info
*pd
= NULL
;
6065 if (offset_in_cu_p (&cu
->header
, offset
))
6067 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6072 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6074 if (per_cu
->cu
== NULL
)
6076 load_comp_unit (per_cu
, cu
->objfile
);
6077 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6078 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6081 per_cu
->cu
->last_used
= 0;
6082 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6084 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6086 struct cleanup
*back_to
;
6087 struct partial_die_info comp_unit_die
;
6088 struct abbrev_info
*abbrev
;
6089 unsigned int bytes_read
;
6092 per_cu
->load_all_dies
= 1;
6094 /* Re-read the DIEs. */
6095 back_to
= make_cleanup (null_cleanup
, 0);
6096 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6098 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6099 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6101 info_ptr
= (dwarf2_per_objfile
->info_buffer
6102 + per_cu
->cu
->header
.offset
6103 + per_cu
->cu
->header
.first_die_offset
);
6104 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6105 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6106 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6108 if (comp_unit_die
.has_children
)
6109 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6110 do_cleanups (back_to
);
6112 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6116 internal_error (__FILE__
, __LINE__
,
6117 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6118 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6122 /* Adjust PART_DIE before generating a symbol for it. This function
6123 may set the is_external flag or change the DIE's name. */
6126 fixup_partial_die (struct partial_die_info
*part_die
,
6127 struct dwarf2_cu
*cu
)
6129 /* If we found a reference attribute and the DIE has no name, try
6130 to find a name in the referred to DIE. */
6132 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6134 struct partial_die_info
*spec_die
;
6136 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6138 fixup_partial_die (spec_die
, cu
);
6142 part_die
->name
= spec_die
->name
;
6144 /* Copy DW_AT_external attribute if it is set. */
6145 if (spec_die
->is_external
)
6146 part_die
->is_external
= spec_die
->is_external
;
6150 /* Set default names for some unnamed DIEs. */
6151 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6152 || part_die
->tag
== DW_TAG_class_type
))
6153 part_die
->name
= "(anonymous class)";
6155 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6156 part_die
->name
= "(anonymous namespace)";
6158 if (part_die
->tag
== DW_TAG_structure_type
6159 || part_die
->tag
== DW_TAG_class_type
6160 || part_die
->tag
== DW_TAG_union_type
)
6161 guess_structure_name (part_die
, cu
);
6164 /* Read the die from the .debug_info section buffer. Set DIEP to
6165 point to a newly allocated die with its information, except for its
6166 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6167 whether the die has children or not. */
6170 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6171 struct dwarf2_cu
*cu
, int *has_children
)
6173 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6174 struct abbrev_info
*abbrev
;
6175 struct die_info
*die
;
6177 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6178 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6179 info_ptr
+= bytes_read
;
6187 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6190 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6192 bfd_get_filename (abfd
));
6194 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6195 die
->offset
= offset
;
6196 die
->tag
= abbrev
->tag
;
6197 die
->abbrev
= abbrev_number
;
6199 die
->num_attrs
= abbrev
->num_attrs
;
6201 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6202 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6203 abfd
, info_ptr
, cu
);
6206 *has_children
= abbrev
->has_children
;
6210 /* Read an attribute value described by an attribute form. */
6213 read_attribute_value (struct attribute
*attr
, unsigned form
,
6214 bfd
*abfd
, gdb_byte
*info_ptr
,
6215 struct dwarf2_cu
*cu
)
6217 struct comp_unit_head
*cu_header
= &cu
->header
;
6218 unsigned int bytes_read
;
6219 struct dwarf_block
*blk
;
6225 case DW_FORM_ref_addr
:
6226 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6227 info_ptr
+= bytes_read
;
6229 case DW_FORM_block2
:
6230 blk
= dwarf_alloc_block (cu
);
6231 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6233 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6234 info_ptr
+= blk
->size
;
6235 DW_BLOCK (attr
) = blk
;
6237 case DW_FORM_block4
:
6238 blk
= dwarf_alloc_block (cu
);
6239 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6241 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6242 info_ptr
+= blk
->size
;
6243 DW_BLOCK (attr
) = blk
;
6246 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6250 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6254 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6257 case DW_FORM_string
:
6258 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6259 info_ptr
+= bytes_read
;
6262 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6264 info_ptr
+= bytes_read
;
6267 blk
= dwarf_alloc_block (cu
);
6268 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6269 info_ptr
+= bytes_read
;
6270 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6271 info_ptr
+= blk
->size
;
6272 DW_BLOCK (attr
) = blk
;
6274 case DW_FORM_block1
:
6275 blk
= dwarf_alloc_block (cu
);
6276 blk
->size
= read_1_byte (abfd
, info_ptr
);
6278 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6279 info_ptr
+= blk
->size
;
6280 DW_BLOCK (attr
) = blk
;
6283 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6287 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6291 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6292 info_ptr
+= bytes_read
;
6295 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6296 info_ptr
+= bytes_read
;
6299 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6303 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6307 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6311 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6314 case DW_FORM_ref_udata
:
6315 DW_ADDR (attr
) = (cu
->header
.offset
6316 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6317 info_ptr
+= bytes_read
;
6319 case DW_FORM_indirect
:
6320 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6321 info_ptr
+= bytes_read
;
6322 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6325 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6326 dwarf_form_name (form
),
6327 bfd_get_filename (abfd
));
6330 /* We have seen instances where the compiler tried to emit a byte
6331 size attribute of -1 which ended up being encoded as an unsigned
6332 0xffffffff. Although 0xffffffff is technically a valid size value,
6333 an object of this size seems pretty unlikely so we can relatively
6334 safely treat these cases as if the size attribute was invalid and
6335 treat them as zero by default. */
6336 if (attr
->name
== DW_AT_byte_size
6337 && form
== DW_FORM_data4
6338 && DW_UNSND (attr
) >= 0xffffffff)
6341 (&symfile_complaints
,
6342 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6344 DW_UNSND (attr
) = 0;
6350 /* Read an attribute described by an abbreviated attribute. */
6353 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6354 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6356 attr
->name
= abbrev
->name
;
6357 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6360 /* read dwarf information from a buffer */
6363 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6365 return bfd_get_8 (abfd
, buf
);
6369 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6371 return bfd_get_signed_8 (abfd
, buf
);
6375 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6377 return bfd_get_16 (abfd
, buf
);
6381 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6383 return bfd_get_signed_16 (abfd
, buf
);
6387 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6389 return bfd_get_32 (abfd
, buf
);
6393 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6395 return bfd_get_signed_32 (abfd
, buf
);
6398 static unsigned long
6399 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6401 return bfd_get_64 (abfd
, buf
);
6405 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6406 unsigned int *bytes_read
)
6408 struct comp_unit_head
*cu_header
= &cu
->header
;
6409 CORE_ADDR retval
= 0;
6411 if (cu_header
->signed_addr_p
)
6413 switch (cu_header
->addr_size
)
6416 retval
= bfd_get_signed_16 (abfd
, buf
);
6419 retval
= bfd_get_signed_32 (abfd
, buf
);
6422 retval
= bfd_get_signed_64 (abfd
, buf
);
6425 internal_error (__FILE__
, __LINE__
,
6426 _("read_address: bad switch, signed [in module %s]"),
6427 bfd_get_filename (abfd
));
6432 switch (cu_header
->addr_size
)
6435 retval
= bfd_get_16 (abfd
, buf
);
6438 retval
= bfd_get_32 (abfd
, buf
);
6441 retval
= bfd_get_64 (abfd
, buf
);
6444 internal_error (__FILE__
, __LINE__
,
6445 _("read_address: bad switch, unsigned [in module %s]"),
6446 bfd_get_filename (abfd
));
6450 *bytes_read
= cu_header
->addr_size
;
6454 /* Read the initial length from a section. The (draft) DWARF 3
6455 specification allows the initial length to take up either 4 bytes
6456 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6457 bytes describe the length and all offsets will be 8 bytes in length
6460 An older, non-standard 64-bit format is also handled by this
6461 function. The older format in question stores the initial length
6462 as an 8-byte quantity without an escape value. Lengths greater
6463 than 2^32 aren't very common which means that the initial 4 bytes
6464 is almost always zero. Since a length value of zero doesn't make
6465 sense for the 32-bit format, this initial zero can be considered to
6466 be an escape value which indicates the presence of the older 64-bit
6467 format. As written, the code can't detect (old format) lengths
6468 greater than 4GB. If it becomes necessary to handle lengths
6469 somewhat larger than 4GB, we could allow other small values (such
6470 as the non-sensical values of 1, 2, and 3) to also be used as
6471 escape values indicating the presence of the old format.
6473 The value returned via bytes_read should be used to increment the
6474 relevant pointer after calling read_initial_length().
6476 [ Note: read_initial_length() and read_offset() are based on the
6477 document entitled "DWARF Debugging Information Format", revision
6478 3, draft 8, dated November 19, 2001. This document was obtained
6481 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6483 This document is only a draft and is subject to change. (So beware.)
6485 Details regarding the older, non-standard 64-bit format were
6486 determined empirically by examining 64-bit ELF files produced by
6487 the SGI toolchain on an IRIX 6.5 machine.
6489 - Kevin, July 16, 2002
6493 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6495 LONGEST length
= bfd_get_32 (abfd
, buf
);
6497 if (length
== 0xffffffff)
6499 length
= bfd_get_64 (abfd
, buf
+ 4);
6502 else if (length
== 0)
6504 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6505 length
= bfd_get_64 (abfd
, buf
);
6516 /* Cover function for read_initial_length.
6517 Returns the length of the object at BUF, and stores the size of the
6518 initial length in *BYTES_READ and stores the size that offsets will be in
6520 If the initial length size is not equivalent to that specified in
6521 CU_HEADER then issue a complaint.
6522 This is useful when reading non-comp-unit headers. */
6525 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6526 const struct comp_unit_head
*cu_header
,
6527 unsigned int *bytes_read
,
6528 unsigned int *offset_size
)
6530 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6532 gdb_assert (cu_header
->initial_length_size
== 4
6533 || cu_header
->initial_length_size
== 8
6534 || cu_header
->initial_length_size
== 12);
6536 if (cu_header
->initial_length_size
!= *bytes_read
)
6537 complaint (&symfile_complaints
,
6538 _("intermixed 32-bit and 64-bit DWARF sections"));
6540 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6544 /* Read an offset from the data stream. The size of the offset is
6545 given by cu_header->offset_size. */
6548 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6549 unsigned int *bytes_read
)
6551 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6552 *bytes_read
= cu_header
->offset_size
;
6556 /* Read an offset from the data stream. */
6559 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6563 switch (offset_size
)
6566 retval
= bfd_get_32 (abfd
, buf
);
6569 retval
= bfd_get_64 (abfd
, buf
);
6572 internal_error (__FILE__
, __LINE__
,
6573 _("read_offset_1: bad switch [in module %s]"),
6574 bfd_get_filename (abfd
));
6581 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6583 /* If the size of a host char is 8 bits, we can return a pointer
6584 to the buffer, otherwise we have to copy the data to a buffer
6585 allocated on the temporary obstack. */
6586 gdb_assert (HOST_CHAR_BIT
== 8);
6591 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6593 /* If the size of a host char is 8 bits, we can return a pointer
6594 to the string, otherwise we have to copy the string to a buffer
6595 allocated on the temporary obstack. */
6596 gdb_assert (HOST_CHAR_BIT
== 8);
6599 *bytes_read_ptr
= 1;
6602 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6603 return (char *) buf
;
6607 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6608 const struct comp_unit_head
*cu_header
,
6609 unsigned int *bytes_read_ptr
)
6611 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6613 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6615 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6616 bfd_get_filename (abfd
));
6619 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6621 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6622 bfd_get_filename (abfd
));
6625 gdb_assert (HOST_CHAR_BIT
== 8);
6626 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6628 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6631 static unsigned long
6632 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6634 unsigned long result
;
6635 unsigned int num_read
;
6645 byte
= bfd_get_8 (abfd
, buf
);
6648 result
|= ((unsigned long)(byte
& 127) << shift
);
6649 if ((byte
& 128) == 0)
6655 *bytes_read_ptr
= num_read
;
6660 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6663 int i
, shift
, num_read
;
6672 byte
= bfd_get_8 (abfd
, buf
);
6675 result
|= ((long)(byte
& 127) << shift
);
6677 if ((byte
& 128) == 0)
6682 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6683 result
|= -(((long)1) << shift
);
6684 *bytes_read_ptr
= num_read
;
6688 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6691 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6697 byte
= bfd_get_8 (abfd
, buf
);
6699 if ((byte
& 128) == 0)
6705 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6711 cu
->language
= language_c
;
6713 case DW_LANG_C_plus_plus
:
6714 cu
->language
= language_cplus
;
6716 case DW_LANG_Fortran77
:
6717 case DW_LANG_Fortran90
:
6718 case DW_LANG_Fortran95
:
6719 cu
->language
= language_fortran
;
6721 case DW_LANG_Mips_Assembler
:
6722 cu
->language
= language_asm
;
6725 cu
->language
= language_java
;
6729 cu
->language
= language_ada
;
6731 case DW_LANG_Modula2
:
6732 cu
->language
= language_m2
;
6734 case DW_LANG_Pascal83
:
6735 cu
->language
= language_pascal
;
6738 cu
->language
= language_objc
;
6740 case DW_LANG_Cobol74
:
6741 case DW_LANG_Cobol85
:
6743 cu
->language
= language_minimal
;
6746 cu
->language_defn
= language_def (cu
->language
);
6749 /* Return the named attribute or NULL if not there. */
6751 static struct attribute
*
6752 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6755 struct attribute
*spec
= NULL
;
6757 for (i
= 0; i
< die
->num_attrs
; ++i
)
6759 if (die
->attrs
[i
].name
== name
)
6760 return &die
->attrs
[i
];
6761 if (die
->attrs
[i
].name
== DW_AT_specification
6762 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6763 spec
= &die
->attrs
[i
];
6768 die
= follow_die_ref (die
, spec
, &cu
);
6769 return dwarf2_attr (die
, name
, cu
);
6775 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6776 and holds a non-zero value. This function should only be used for
6777 DW_FORM_flag attributes. */
6780 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6782 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6784 return (attr
&& DW_UNSND (attr
));
6788 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6790 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6791 which value is non-zero. However, we have to be careful with
6792 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6793 (via dwarf2_flag_true_p) follows this attribute. So we may
6794 end up accidently finding a declaration attribute that belongs
6795 to a different DIE referenced by the specification attribute,
6796 even though the given DIE does not have a declaration attribute. */
6797 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6798 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6801 /* Return the die giving the specification for DIE, if there is
6802 one. *SPEC_CU is the CU containing DIE on input, and the CU
6803 containing the return value on output. */
6805 static struct die_info
*
6806 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6808 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6811 if (spec_attr
== NULL
)
6814 return follow_die_ref (die
, spec_attr
, spec_cu
);
6817 /* Free the line_header structure *LH, and any arrays and strings it
6820 free_line_header (struct line_header
*lh
)
6822 if (lh
->standard_opcode_lengths
)
6823 xfree (lh
->standard_opcode_lengths
);
6825 /* Remember that all the lh->file_names[i].name pointers are
6826 pointers into debug_line_buffer, and don't need to be freed. */
6828 xfree (lh
->file_names
);
6830 /* Similarly for the include directory names. */
6831 if (lh
->include_dirs
)
6832 xfree (lh
->include_dirs
);
6838 /* Add an entry to LH's include directory table. */
6840 add_include_dir (struct line_header
*lh
, char *include_dir
)
6842 /* Grow the array if necessary. */
6843 if (lh
->include_dirs_size
== 0)
6845 lh
->include_dirs_size
= 1; /* for testing */
6846 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6847 * sizeof (*lh
->include_dirs
));
6849 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6851 lh
->include_dirs_size
*= 2;
6852 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6853 (lh
->include_dirs_size
6854 * sizeof (*lh
->include_dirs
)));
6857 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6861 /* Add an entry to LH's file name table. */
6863 add_file_name (struct line_header
*lh
,
6865 unsigned int dir_index
,
6866 unsigned int mod_time
,
6867 unsigned int length
)
6869 struct file_entry
*fe
;
6871 /* Grow the array if necessary. */
6872 if (lh
->file_names_size
== 0)
6874 lh
->file_names_size
= 1; /* for testing */
6875 lh
->file_names
= xmalloc (lh
->file_names_size
6876 * sizeof (*lh
->file_names
));
6878 else if (lh
->num_file_names
>= lh
->file_names_size
)
6880 lh
->file_names_size
*= 2;
6881 lh
->file_names
= xrealloc (lh
->file_names
,
6882 (lh
->file_names_size
6883 * sizeof (*lh
->file_names
)));
6886 fe
= &lh
->file_names
[lh
->num_file_names
++];
6888 fe
->dir_index
= dir_index
;
6889 fe
->mod_time
= mod_time
;
6890 fe
->length
= length
;
6896 /* Read the statement program header starting at OFFSET in
6897 .debug_line, according to the endianness of ABFD. Return a pointer
6898 to a struct line_header, allocated using xmalloc.
6900 NOTE: the strings in the include directory and file name tables of
6901 the returned object point into debug_line_buffer, and must not be
6903 static struct line_header
*
6904 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6905 struct dwarf2_cu
*cu
)
6907 struct cleanup
*back_to
;
6908 struct line_header
*lh
;
6910 unsigned int bytes_read
, offset_size
;
6912 char *cur_dir
, *cur_file
;
6914 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6916 complaint (&symfile_complaints
, _("missing .debug_line section"));
6920 /* Make sure that at least there's room for the total_length field.
6921 That could be 12 bytes long, but we're just going to fudge that. */
6922 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6924 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6928 lh
= xmalloc (sizeof (*lh
));
6929 memset (lh
, 0, sizeof (*lh
));
6930 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6933 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6935 /* Read in the header. */
6937 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
6938 &bytes_read
, &offset_size
);
6939 line_ptr
+= bytes_read
;
6940 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6941 + dwarf2_per_objfile
->line_size
))
6943 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6946 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6947 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6949 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
6950 line_ptr
+= offset_size
;
6951 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6953 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6955 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6957 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6959 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6961 lh
->standard_opcode_lengths
6962 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6964 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6965 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6967 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6971 /* Read directory table. */
6972 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6974 line_ptr
+= bytes_read
;
6975 add_include_dir (lh
, cur_dir
);
6977 line_ptr
+= bytes_read
;
6979 /* Read file name table. */
6980 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6982 unsigned int dir_index
, mod_time
, length
;
6984 line_ptr
+= bytes_read
;
6985 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6986 line_ptr
+= bytes_read
;
6987 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6988 line_ptr
+= bytes_read
;
6989 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6990 line_ptr
+= bytes_read
;
6992 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6994 line_ptr
+= bytes_read
;
6995 lh
->statement_program_start
= line_ptr
;
6997 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6998 + dwarf2_per_objfile
->line_size
))
6999 complaint (&symfile_complaints
,
7000 _("line number info header doesn't fit in `.debug_line' section"));
7002 discard_cleanups (back_to
);
7006 /* This function exists to work around a bug in certain compilers
7007 (particularly GCC 2.95), in which the first line number marker of a
7008 function does not show up until after the prologue, right before
7009 the second line number marker. This function shifts ADDRESS down
7010 to the beginning of the function if necessary, and is called on
7011 addresses passed to record_line. */
7014 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7016 struct function_range
*fn
;
7018 /* Find the function_range containing address. */
7023 cu
->cached_fn
= cu
->first_fn
;
7027 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7033 while (fn
&& fn
!= cu
->cached_fn
)
7034 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7044 if (address
!= fn
->lowpc
)
7045 complaint (&symfile_complaints
,
7046 _("misplaced first line number at 0x%lx for '%s'"),
7047 (unsigned long) address
, fn
->name
);
7052 /* Decode the Line Number Program (LNP) for the given line_header
7053 structure and CU. The actual information extracted and the type
7054 of structures created from the LNP depends on the value of PST.
7056 1. If PST is NULL, then this procedure uses the data from the program
7057 to create all necessary symbol tables, and their linetables.
7058 The compilation directory of the file is passed in COMP_DIR,
7059 and must not be NULL.
7061 2. If PST is not NULL, this procedure reads the program to determine
7062 the list of files included by the unit represented by PST, and
7063 builds all the associated partial symbol tables. In this case,
7064 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7065 is not used to compute the full name of the symtab, and therefore
7066 omitting it when building the partial symtab does not introduce
7067 the potential for inconsistency - a partial symtab and its associated
7068 symbtab having a different fullname -). */
7071 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7072 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7074 gdb_byte
*line_ptr
, *extended_end
;
7076 unsigned int bytes_read
, extended_len
;
7077 unsigned char op_code
, extended_op
, adj_opcode
;
7079 struct objfile
*objfile
= cu
->objfile
;
7080 const int decode_for_pst_p
= (pst
!= NULL
);
7081 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7083 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7085 line_ptr
= lh
->statement_program_start
;
7086 line_end
= lh
->statement_program_end
;
7088 /* Read the statement sequences until there's nothing left. */
7089 while (line_ptr
< line_end
)
7091 /* state machine registers */
7092 CORE_ADDR address
= 0;
7093 unsigned int file
= 1;
7094 unsigned int line
= 1;
7095 unsigned int column
= 0;
7096 int is_stmt
= lh
->default_is_stmt
;
7097 int basic_block
= 0;
7098 int end_sequence
= 0;
7100 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7102 /* Start a subfile for the current file of the state machine. */
7103 /* lh->include_dirs and lh->file_names are 0-based, but the
7104 directory and file name numbers in the statement program
7106 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7110 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7112 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7115 /* Decode the table. */
7116 while (!end_sequence
)
7118 op_code
= read_1_byte (abfd
, line_ptr
);
7120 if (line_ptr
> line_end
)
7122 dwarf2_debug_line_missing_end_sequence_complaint ();
7126 if (op_code
>= lh
->opcode_base
)
7128 /* Special operand. */
7129 adj_opcode
= op_code
- lh
->opcode_base
;
7130 address
+= (adj_opcode
/ lh
->line_range
)
7131 * lh
->minimum_instruction_length
;
7132 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7133 if (lh
->num_file_names
< file
|| file
== 0)
7134 dwarf2_debug_line_missing_file_complaint ();
7137 lh
->file_names
[file
- 1].included_p
= 1;
7138 if (!decode_for_pst_p
)
7140 if (last_subfile
!= current_subfile
)
7143 record_line (last_subfile
, 0, address
);
7144 last_subfile
= current_subfile
;
7146 /* Append row to matrix using current values. */
7147 record_line (current_subfile
, line
,
7148 check_cu_functions (address
, cu
));
7153 else switch (op_code
)
7155 case DW_LNS_extended_op
:
7156 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7157 line_ptr
+= bytes_read
;
7158 extended_end
= line_ptr
+ extended_len
;
7159 extended_op
= read_1_byte (abfd
, line_ptr
);
7161 switch (extended_op
)
7163 case DW_LNE_end_sequence
:
7166 case DW_LNE_set_address
:
7167 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7168 line_ptr
+= bytes_read
;
7169 address
+= baseaddr
;
7171 case DW_LNE_define_file
:
7174 unsigned int dir_index
, mod_time
, length
;
7176 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7177 line_ptr
+= bytes_read
;
7179 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7180 line_ptr
+= bytes_read
;
7182 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7183 line_ptr
+= bytes_read
;
7185 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7186 line_ptr
+= bytes_read
;
7187 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7191 complaint (&symfile_complaints
,
7192 _("mangled .debug_line section"));
7195 /* Make sure that we parsed the extended op correctly. If e.g.
7196 we expected a different address size than the producer used,
7197 we may have read the wrong number of bytes. */
7198 if (line_ptr
!= extended_end
)
7200 complaint (&symfile_complaints
,
7201 _("mangled .debug_line section"));
7206 if (lh
->num_file_names
< file
|| file
== 0)
7207 dwarf2_debug_line_missing_file_complaint ();
7210 lh
->file_names
[file
- 1].included_p
= 1;
7211 if (!decode_for_pst_p
)
7213 if (last_subfile
!= current_subfile
)
7216 record_line (last_subfile
, 0, address
);
7217 last_subfile
= current_subfile
;
7219 record_line (current_subfile
, line
,
7220 check_cu_functions (address
, cu
));
7225 case DW_LNS_advance_pc
:
7226 address
+= lh
->minimum_instruction_length
7227 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7228 line_ptr
+= bytes_read
;
7230 case DW_LNS_advance_line
:
7231 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7232 line_ptr
+= bytes_read
;
7234 case DW_LNS_set_file
:
7236 /* The arrays lh->include_dirs and lh->file_names are
7237 0-based, but the directory and file name numbers in
7238 the statement program are 1-based. */
7239 struct file_entry
*fe
;
7242 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7243 line_ptr
+= bytes_read
;
7244 if (lh
->num_file_names
< file
|| file
== 0)
7245 dwarf2_debug_line_missing_file_complaint ();
7248 fe
= &lh
->file_names
[file
- 1];
7250 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7251 if (!decode_for_pst_p
)
7253 last_subfile
= current_subfile
;
7254 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7259 case DW_LNS_set_column
:
7260 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7261 line_ptr
+= bytes_read
;
7263 case DW_LNS_negate_stmt
:
7264 is_stmt
= (!is_stmt
);
7266 case DW_LNS_set_basic_block
:
7269 /* Add to the address register of the state machine the
7270 address increment value corresponding to special opcode
7271 255. I.e., this value is scaled by the minimum
7272 instruction length since special opcode 255 would have
7273 scaled the the increment. */
7274 case DW_LNS_const_add_pc
:
7275 address
+= (lh
->minimum_instruction_length
7276 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7278 case DW_LNS_fixed_advance_pc
:
7279 address
+= read_2_bytes (abfd
, line_ptr
);
7284 /* Unknown standard opcode, ignore it. */
7287 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7289 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7290 line_ptr
+= bytes_read
;
7295 if (lh
->num_file_names
< file
|| file
== 0)
7296 dwarf2_debug_line_missing_file_complaint ();
7299 lh
->file_names
[file
- 1].included_p
= 1;
7300 if (!decode_for_pst_p
)
7301 record_line (current_subfile
, 0, address
);
7305 if (decode_for_pst_p
)
7309 /* Now that we're done scanning the Line Header Program, we can
7310 create the psymtab of each included file. */
7311 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7312 if (lh
->file_names
[file_index
].included_p
== 1)
7314 const struct file_entry fe
= lh
->file_names
[file_index
];
7315 char *include_name
= fe
.name
;
7316 char *dir_name
= NULL
;
7317 char *pst_filename
= pst
->filename
;
7320 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7322 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7324 include_name
= concat (dir_name
, SLASH_STRING
,
7325 include_name
, (char *)NULL
);
7326 make_cleanup (xfree
, include_name
);
7329 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7331 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7332 pst_filename
, (char *)NULL
);
7333 make_cleanup (xfree
, pst_filename
);
7336 if (strcmp (include_name
, pst_filename
) != 0)
7337 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7342 /* Make sure a symtab is created for every file, even files
7343 which contain only variables (i.e. no code with associated
7347 struct file_entry
*fe
;
7349 for (i
= 0; i
< lh
->num_file_names
; i
++)
7352 fe
= &lh
->file_names
[i
];
7354 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7355 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7357 /* Skip the main file; we don't need it, and it must be
7358 allocated last, so that it will show up before the
7359 non-primary symtabs in the objfile's symtab list. */
7360 if (current_subfile
== first_subfile
)
7363 if (current_subfile
->symtab
== NULL
)
7364 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7366 fe
->symtab
= current_subfile
->symtab
;
7371 /* Start a subfile for DWARF. FILENAME is the name of the file and
7372 DIRNAME the name of the source directory which contains FILENAME
7373 or NULL if not known. COMP_DIR is the compilation directory for the
7374 linetable's compilation unit or NULL if not known.
7375 This routine tries to keep line numbers from identical absolute and
7376 relative file names in a common subfile.
7378 Using the `list' example from the GDB testsuite, which resides in
7379 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7380 of /srcdir/list0.c yields the following debugging information for list0.c:
7382 DW_AT_name: /srcdir/list0.c
7383 DW_AT_comp_dir: /compdir
7384 files.files[0].name: list0.h
7385 files.files[0].dir: /srcdir
7386 files.files[1].name: list0.c
7387 files.files[1].dir: /srcdir
7389 The line number information for list0.c has to end up in a single
7390 subfile, so that `break /srcdir/list0.c:1' works as expected.
7391 start_subfile will ensure that this happens provided that we pass the
7392 concatenation of files.files[1].dir and files.files[1].name as the
7396 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7400 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7401 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7402 second argument to start_subfile. To be consistent, we do the
7403 same here. In order not to lose the line information directory,
7404 we concatenate it to the filename when it makes sense.
7405 Note that the Dwarf3 standard says (speaking of filenames in line
7406 information): ``The directory index is ignored for file names
7407 that represent full path names''. Thus ignoring dirname in the
7408 `else' branch below isn't an issue. */
7410 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7411 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7413 fullname
= filename
;
7415 start_subfile (fullname
, comp_dir
);
7417 if (fullname
!= filename
)
7422 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7423 struct dwarf2_cu
*cu
)
7425 struct objfile
*objfile
= cu
->objfile
;
7426 struct comp_unit_head
*cu_header
= &cu
->header
;
7428 /* NOTE drow/2003-01-30: There used to be a comment and some special
7429 code here to turn a symbol with DW_AT_external and a
7430 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7431 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7432 with some versions of binutils) where shared libraries could have
7433 relocations against symbols in their debug information - the
7434 minimal symbol would have the right address, but the debug info
7435 would not. It's no longer necessary, because we will explicitly
7436 apply relocations when we read in the debug information now. */
7438 /* A DW_AT_location attribute with no contents indicates that a
7439 variable has been optimized away. */
7440 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7442 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7446 /* Handle one degenerate form of location expression specially, to
7447 preserve GDB's previous behavior when section offsets are
7448 specified. If this is just a DW_OP_addr then mark this symbol
7451 if (attr_form_is_block (attr
)
7452 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7453 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7457 SYMBOL_VALUE_ADDRESS (sym
) =
7458 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7459 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7460 fixup_symbol_section (sym
, objfile
);
7461 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7462 SYMBOL_SECTION (sym
));
7466 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7467 expression evaluator, and use LOC_COMPUTED only when necessary
7468 (i.e. when the value of a register or memory location is
7469 referenced, or a thread-local block, etc.). Then again, it might
7470 not be worthwhile. I'm assuming that it isn't unless performance
7471 or memory numbers show me otherwise. */
7473 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7474 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7477 /* Given a pointer to a DWARF information entry, figure out if we need
7478 to make a symbol table entry for it, and if so, create a new entry
7479 and return a pointer to it.
7480 If TYPE is NULL, determine symbol type from the die, otherwise
7481 used the passed type. */
7483 static struct symbol
*
7484 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7486 struct objfile
*objfile
= cu
->objfile
;
7487 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7488 struct symbol
*sym
= NULL
;
7490 struct attribute
*attr
= NULL
;
7491 struct attribute
*attr2
= NULL
;
7494 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7496 if (die
->tag
!= DW_TAG_namespace
)
7497 name
= dwarf2_linkage_name (die
, cu
);
7499 name
= TYPE_NAME (type
);
7503 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7504 sizeof (struct symbol
));
7505 OBJSTAT (objfile
, n_syms
++);
7506 memset (sym
, 0, sizeof (struct symbol
));
7508 /* Cache this symbol's name and the name's demangled form (if any). */
7509 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7510 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7512 /* Default assumptions.
7513 Use the passed type or decode it from the die. */
7514 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7515 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7517 SYMBOL_TYPE (sym
) = type
;
7519 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7520 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7523 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7526 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7529 int file_index
= DW_UNSND (attr
);
7530 if (cu
->line_header
== NULL
7531 || file_index
> cu
->line_header
->num_file_names
)
7532 complaint (&symfile_complaints
,
7533 _("file index out of range"));
7534 else if (file_index
> 0)
7536 struct file_entry
*fe
;
7537 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7538 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7545 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7548 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7550 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7552 case DW_TAG_subprogram
:
7553 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7555 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7556 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7557 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7558 || cu
->language
== language_ada
)
7560 /* Subprograms marked external are stored as a global symbol.
7561 Ada subprograms, whether marked external or not, are always
7562 stored as a global symbol, because we want to be able to
7563 access them globally. For instance, we want to be able
7564 to break on a nested subprogram without having to
7565 specify the context. */
7566 add_symbol_to_list (sym
, &global_symbols
);
7570 add_symbol_to_list (sym
, cu
->list_in_scope
);
7573 case DW_TAG_variable
:
7574 /* Compilation with minimal debug info may result in variables
7575 with missing type entries. Change the misleading `void' type
7576 to something sensible. */
7577 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7579 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7581 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7584 dwarf2_const_value (attr
, sym
, cu
);
7585 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7586 if (attr2
&& (DW_UNSND (attr2
) != 0))
7587 add_symbol_to_list (sym
, &global_symbols
);
7589 add_symbol_to_list (sym
, cu
->list_in_scope
);
7592 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7595 var_decode_location (attr
, sym
, cu
);
7596 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7597 if (attr2
&& (DW_UNSND (attr2
) != 0))
7598 add_symbol_to_list (sym
, &global_symbols
);
7600 add_symbol_to_list (sym
, cu
->list_in_scope
);
7604 /* We do not know the address of this symbol.
7605 If it is an external symbol and we have type information
7606 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7607 The address of the variable will then be determined from
7608 the minimal symbol table whenever the variable is
7610 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7611 if (attr2
&& (DW_UNSND (attr2
) != 0)
7612 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7614 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7615 add_symbol_to_list (sym
, &global_symbols
);
7619 case DW_TAG_formal_parameter
:
7620 SYMBOL_IS_ARGUMENT (sym
) = 1;
7621 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7624 var_decode_location (attr
, sym
, cu
);
7626 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7629 dwarf2_const_value (attr
, sym
, cu
);
7631 add_symbol_to_list (sym
, cu
->list_in_scope
);
7633 case DW_TAG_unspecified_parameters
:
7634 /* From varargs functions; gdb doesn't seem to have any
7635 interest in this information, so just ignore it for now.
7638 case DW_TAG_class_type
:
7639 case DW_TAG_interface_type
:
7640 case DW_TAG_structure_type
:
7641 case DW_TAG_union_type
:
7642 case DW_TAG_set_type
:
7643 case DW_TAG_enumeration_type
:
7644 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7645 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7647 /* Make sure that the symbol includes appropriate enclosing
7648 classes/namespaces in its name. These are calculated in
7649 read_structure_type, and the correct name is saved in
7652 if (cu
->language
== language_cplus
7653 || cu
->language
== language_java
)
7655 struct type
*type
= SYMBOL_TYPE (sym
);
7657 if (TYPE_TAG_NAME (type
) != NULL
)
7659 /* FIXME: carlton/2003-11-10: Should this use
7660 SYMBOL_SET_NAMES instead? (The same problem also
7661 arises further down in this function.) */
7662 /* The type's name is already allocated along with
7663 this objfile, so we don't need to duplicate it
7665 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7670 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7671 really ever be static objects: otherwise, if you try
7672 to, say, break of a class's method and you're in a file
7673 which doesn't mention that class, it won't work unless
7674 the check for all static symbols in lookup_symbol_aux
7675 saves you. See the OtherFileClass tests in
7676 gdb.c++/namespace.exp. */
7678 struct pending
**list_to_add
;
7680 list_to_add
= (cu
->list_in_scope
== &file_symbols
7681 && (cu
->language
== language_cplus
7682 || cu
->language
== language_java
)
7683 ? &global_symbols
: cu
->list_in_scope
);
7685 add_symbol_to_list (sym
, list_to_add
);
7687 /* The semantics of C++ state that "struct foo { ... }" also
7688 defines a typedef for "foo". A Java class declaration also
7689 defines a typedef for the class. */
7690 if (cu
->language
== language_cplus
7691 || cu
->language
== language_java
7692 || cu
->language
== language_ada
)
7694 /* The symbol's name is already allocated along with
7695 this objfile, so we don't need to duplicate it for
7697 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7698 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7702 case DW_TAG_typedef
:
7703 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7704 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7705 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7706 add_symbol_to_list (sym
, cu
->list_in_scope
);
7708 case DW_TAG_base_type
:
7709 case DW_TAG_subrange_type
:
7710 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7711 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7712 add_symbol_to_list (sym
, cu
->list_in_scope
);
7714 case DW_TAG_enumerator
:
7715 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7716 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7719 dwarf2_const_value (attr
, sym
, cu
);
7722 /* NOTE: carlton/2003-11-10: See comment above in the
7723 DW_TAG_class_type, etc. block. */
7725 struct pending
**list_to_add
;
7727 list_to_add
= (cu
->list_in_scope
== &file_symbols
7728 && (cu
->language
== language_cplus
7729 || cu
->language
== language_java
)
7730 ? &global_symbols
: cu
->list_in_scope
);
7732 add_symbol_to_list (sym
, list_to_add
);
7735 case DW_TAG_namespace
:
7736 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7737 add_symbol_to_list (sym
, &global_symbols
);
7740 /* Not a tag we recognize. Hopefully we aren't processing
7741 trash data, but since we must specifically ignore things
7742 we don't recognize, there is nothing else we should do at
7744 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7745 dwarf_tag_name (die
->tag
));
7749 /* For the benefit of old versions of GCC, check for anonymous
7750 namespaces based on the demangled name. */
7751 if (!processing_has_namespace_info
7752 && cu
->language
== language_cplus
7753 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7754 cp_scan_for_anonymous_namespaces (sym
);
7759 /* Copy constant value from an attribute to a symbol. */
7762 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7763 struct dwarf2_cu
*cu
)
7765 struct objfile
*objfile
= cu
->objfile
;
7766 struct comp_unit_head
*cu_header
= &cu
->header
;
7767 struct dwarf_block
*blk
;
7772 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7773 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7774 cu_header
->addr_size
,
7775 TYPE_LENGTH (SYMBOL_TYPE
7777 SYMBOL_VALUE_BYTES (sym
) =
7778 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7779 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7780 it's body - store_unsigned_integer. */
7781 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7783 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7786 /* DW_STRING is already allocated on the obstack, point directly
7788 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7789 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7791 case DW_FORM_block1
:
7792 case DW_FORM_block2
:
7793 case DW_FORM_block4
:
7795 blk
= DW_BLOCK (attr
);
7796 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7797 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7799 TYPE_LENGTH (SYMBOL_TYPE
7801 SYMBOL_VALUE_BYTES (sym
) =
7802 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7803 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7804 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7807 /* The DW_AT_const_value attributes are supposed to carry the
7808 symbol's value "represented as it would be on the target
7809 architecture." By the time we get here, it's already been
7810 converted to host endianness, so we just need to sign- or
7811 zero-extend it as appropriate. */
7813 dwarf2_const_value_data (attr
, sym
, 8);
7816 dwarf2_const_value_data (attr
, sym
, 16);
7819 dwarf2_const_value_data (attr
, sym
, 32);
7822 dwarf2_const_value_data (attr
, sym
, 64);
7826 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7827 SYMBOL_CLASS (sym
) = LOC_CONST
;
7831 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7832 SYMBOL_CLASS (sym
) = LOC_CONST
;
7836 complaint (&symfile_complaints
,
7837 _("unsupported const value attribute form: '%s'"),
7838 dwarf_form_name (attr
->form
));
7839 SYMBOL_VALUE (sym
) = 0;
7840 SYMBOL_CLASS (sym
) = LOC_CONST
;
7846 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7847 or zero-extend it as appropriate for the symbol's type. */
7849 dwarf2_const_value_data (struct attribute
*attr
,
7853 LONGEST l
= DW_UNSND (attr
);
7855 if (bits
< sizeof (l
) * 8)
7857 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7858 l
&= ((LONGEST
) 1 << bits
) - 1;
7860 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7863 SYMBOL_VALUE (sym
) = l
;
7864 SYMBOL_CLASS (sym
) = LOC_CONST
;
7868 /* Return the type of the die in question using its DW_AT_type attribute. */
7870 static struct type
*
7871 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7873 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7875 struct attribute
*type_attr
;
7876 struct die_info
*type_die
;
7878 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7881 /* A missing DW_AT_type represents a void type. */
7882 return builtin_type (gdbarch
)->builtin_void
;
7885 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7887 type
= tag_type_to_type (type_die
, cu
);
7890 dump_die_for_error (type_die
);
7891 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7897 /* Return the containing type of the die in question using its
7898 DW_AT_containing_type attribute. */
7900 static struct type
*
7901 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7903 struct type
*type
= NULL
;
7904 struct attribute
*type_attr
;
7905 struct die_info
*type_die
= NULL
;
7907 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7910 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7911 type
= tag_type_to_type (type_die
, cu
);
7916 dump_die_for_error (type_die
);
7917 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7923 static struct type
*
7924 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7926 struct type
*this_type
;
7928 this_type
= read_type_die (die
, cu
);
7931 dump_die_for_error (die
);
7932 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7938 static struct type
*
7939 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7941 struct type
*this_type
;
7943 this_type
= get_die_type (die
, cu
);
7949 case DW_TAG_class_type
:
7950 case DW_TAG_interface_type
:
7951 case DW_TAG_structure_type
:
7952 case DW_TAG_union_type
:
7953 this_type
= read_structure_type (die
, cu
);
7955 case DW_TAG_enumeration_type
:
7956 this_type
= read_enumeration_type (die
, cu
);
7958 case DW_TAG_subprogram
:
7959 case DW_TAG_subroutine_type
:
7960 this_type
= read_subroutine_type (die
, cu
);
7962 case DW_TAG_array_type
:
7963 this_type
= read_array_type (die
, cu
);
7965 case DW_TAG_set_type
:
7966 this_type
= read_set_type (die
, cu
);
7968 case DW_TAG_pointer_type
:
7969 this_type
= read_tag_pointer_type (die
, cu
);
7971 case DW_TAG_ptr_to_member_type
:
7972 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7974 case DW_TAG_reference_type
:
7975 this_type
= read_tag_reference_type (die
, cu
);
7977 case DW_TAG_const_type
:
7978 this_type
= read_tag_const_type (die
, cu
);
7980 case DW_TAG_volatile_type
:
7981 this_type
= read_tag_volatile_type (die
, cu
);
7983 case DW_TAG_string_type
:
7984 this_type
= read_tag_string_type (die
, cu
);
7986 case DW_TAG_typedef
:
7987 this_type
= read_typedef (die
, cu
);
7989 case DW_TAG_subrange_type
:
7990 this_type
= read_subrange_type (die
, cu
);
7992 case DW_TAG_base_type
:
7993 this_type
= read_base_type (die
, cu
);
7995 case DW_TAG_unspecified_type
:
7996 this_type
= read_unspecified_type (die
, cu
);
7998 case DW_TAG_namespace
:
7999 this_type
= read_namespace_type (die
, cu
);
8002 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8003 dwarf_tag_name (die
->tag
));
8010 /* Return the name of the namespace/class that DIE is defined within,
8011 or "" if we can't tell. The caller should not xfree the result.
8013 For example, if we're within the method foo() in the following
8023 then determine_prefix on foo's die will return "N::C". */
8026 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8028 struct die_info
*parent
, *spec_die
;
8029 struct dwarf2_cu
*spec_cu
;
8030 struct type
*parent_type
;
8032 if (cu
->language
!= language_cplus
8033 && cu
->language
!= language_java
)
8036 /* We have to be careful in the presence of DW_AT_specification.
8037 For example, with GCC 3.4, given the code
8041 // Definition of N::foo.
8045 then we'll have a tree of DIEs like this:
8047 1: DW_TAG_compile_unit
8048 2: DW_TAG_namespace // N
8049 3: DW_TAG_subprogram // declaration of N::foo
8050 4: DW_TAG_subprogram // definition of N::foo
8051 DW_AT_specification // refers to die #3
8053 Thus, when processing die #4, we have to pretend that we're in
8054 the context of its DW_AT_specification, namely the contex of die
8057 spec_die
= die_specification (die
, &spec_cu
);
8058 if (spec_die
== NULL
)
8059 parent
= die
->parent
;
8062 parent
= spec_die
->parent
;
8069 switch (parent
->tag
)
8071 case DW_TAG_namespace
:
8072 parent_type
= read_type_die (parent
, cu
);
8073 /* We give a name to even anonymous namespaces. */
8074 return TYPE_TAG_NAME (parent_type
);
8075 case DW_TAG_class_type
:
8076 case DW_TAG_interface_type
:
8077 case DW_TAG_structure_type
:
8078 case DW_TAG_union_type
:
8079 parent_type
= read_type_die (parent
, cu
);
8080 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8081 return TYPE_TAG_NAME (parent_type
);
8083 /* An anonymous structure is only allowed non-static data
8084 members; no typedefs, no member functions, et cetera.
8085 So it does not need a prefix. */
8088 return determine_prefix (parent
, cu
);
8092 /* Return a newly-allocated string formed by concatenating PREFIX and
8093 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8094 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8095 perform an obconcat, otherwise allocate storage for the result. The CU argument
8096 is used to determine the language and hence, the appropriate separator. */
8098 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8101 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8102 struct dwarf2_cu
*cu
)
8106 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8108 else if (cu
->language
== language_java
)
8120 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8121 strcpy (retval
, prefix
);
8122 strcat (retval
, sep
);
8123 strcat (retval
, suffix
);
8128 /* We have an obstack. */
8129 return obconcat (obs
, prefix
, sep
, suffix
);
8133 /* Return sibling of die, NULL if no sibling. */
8135 static struct die_info
*
8136 sibling_die (struct die_info
*die
)
8138 return die
->sibling
;
8141 /* Get linkage name of a die, return NULL if not found. */
8144 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8146 struct attribute
*attr
;
8148 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8149 if (attr
&& DW_STRING (attr
))
8150 return DW_STRING (attr
);
8151 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8152 if (attr
&& DW_STRING (attr
))
8153 return DW_STRING (attr
);
8157 /* Get name of a die, return NULL if not found. */
8160 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8162 struct attribute
*attr
;
8164 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8165 if (attr
&& DW_STRING (attr
))
8166 return DW_STRING (attr
);
8170 /* Return the die that this die in an extension of, or NULL if there
8171 is none. *EXT_CU is the CU containing DIE on input, and the CU
8172 containing the return value on output. */
8174 static struct die_info
*
8175 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8177 struct attribute
*attr
;
8179 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8183 return follow_die_ref (die
, attr
, ext_cu
);
8186 /* Convert a DIE tag into its string name. */
8189 dwarf_tag_name (unsigned tag
)
8193 case DW_TAG_padding
:
8194 return "DW_TAG_padding";
8195 case DW_TAG_array_type
:
8196 return "DW_TAG_array_type";
8197 case DW_TAG_class_type
:
8198 return "DW_TAG_class_type";
8199 case DW_TAG_entry_point
:
8200 return "DW_TAG_entry_point";
8201 case DW_TAG_enumeration_type
:
8202 return "DW_TAG_enumeration_type";
8203 case DW_TAG_formal_parameter
:
8204 return "DW_TAG_formal_parameter";
8205 case DW_TAG_imported_declaration
:
8206 return "DW_TAG_imported_declaration";
8208 return "DW_TAG_label";
8209 case DW_TAG_lexical_block
:
8210 return "DW_TAG_lexical_block";
8212 return "DW_TAG_member";
8213 case DW_TAG_pointer_type
:
8214 return "DW_TAG_pointer_type";
8215 case DW_TAG_reference_type
:
8216 return "DW_TAG_reference_type";
8217 case DW_TAG_compile_unit
:
8218 return "DW_TAG_compile_unit";
8219 case DW_TAG_string_type
:
8220 return "DW_TAG_string_type";
8221 case DW_TAG_structure_type
:
8222 return "DW_TAG_structure_type";
8223 case DW_TAG_subroutine_type
:
8224 return "DW_TAG_subroutine_type";
8225 case DW_TAG_typedef
:
8226 return "DW_TAG_typedef";
8227 case DW_TAG_union_type
:
8228 return "DW_TAG_union_type";
8229 case DW_TAG_unspecified_parameters
:
8230 return "DW_TAG_unspecified_parameters";
8231 case DW_TAG_variant
:
8232 return "DW_TAG_variant";
8233 case DW_TAG_common_block
:
8234 return "DW_TAG_common_block";
8235 case DW_TAG_common_inclusion
:
8236 return "DW_TAG_common_inclusion";
8237 case DW_TAG_inheritance
:
8238 return "DW_TAG_inheritance";
8239 case DW_TAG_inlined_subroutine
:
8240 return "DW_TAG_inlined_subroutine";
8242 return "DW_TAG_module";
8243 case DW_TAG_ptr_to_member_type
:
8244 return "DW_TAG_ptr_to_member_type";
8245 case DW_TAG_set_type
:
8246 return "DW_TAG_set_type";
8247 case DW_TAG_subrange_type
:
8248 return "DW_TAG_subrange_type";
8249 case DW_TAG_with_stmt
:
8250 return "DW_TAG_with_stmt";
8251 case DW_TAG_access_declaration
:
8252 return "DW_TAG_access_declaration";
8253 case DW_TAG_base_type
:
8254 return "DW_TAG_base_type";
8255 case DW_TAG_catch_block
:
8256 return "DW_TAG_catch_block";
8257 case DW_TAG_const_type
:
8258 return "DW_TAG_const_type";
8259 case DW_TAG_constant
:
8260 return "DW_TAG_constant";
8261 case DW_TAG_enumerator
:
8262 return "DW_TAG_enumerator";
8263 case DW_TAG_file_type
:
8264 return "DW_TAG_file_type";
8266 return "DW_TAG_friend";
8267 case DW_TAG_namelist
:
8268 return "DW_TAG_namelist";
8269 case DW_TAG_namelist_item
:
8270 return "DW_TAG_namelist_item";
8271 case DW_TAG_packed_type
:
8272 return "DW_TAG_packed_type";
8273 case DW_TAG_subprogram
:
8274 return "DW_TAG_subprogram";
8275 case DW_TAG_template_type_param
:
8276 return "DW_TAG_template_type_param";
8277 case DW_TAG_template_value_param
:
8278 return "DW_TAG_template_value_param";
8279 case DW_TAG_thrown_type
:
8280 return "DW_TAG_thrown_type";
8281 case DW_TAG_try_block
:
8282 return "DW_TAG_try_block";
8283 case DW_TAG_variant_part
:
8284 return "DW_TAG_variant_part";
8285 case DW_TAG_variable
:
8286 return "DW_TAG_variable";
8287 case DW_TAG_volatile_type
:
8288 return "DW_TAG_volatile_type";
8289 case DW_TAG_dwarf_procedure
:
8290 return "DW_TAG_dwarf_procedure";
8291 case DW_TAG_restrict_type
:
8292 return "DW_TAG_restrict_type";
8293 case DW_TAG_interface_type
:
8294 return "DW_TAG_interface_type";
8295 case DW_TAG_namespace
:
8296 return "DW_TAG_namespace";
8297 case DW_TAG_imported_module
:
8298 return "DW_TAG_imported_module";
8299 case DW_TAG_unspecified_type
:
8300 return "DW_TAG_unspecified_type";
8301 case DW_TAG_partial_unit
:
8302 return "DW_TAG_partial_unit";
8303 case DW_TAG_imported_unit
:
8304 return "DW_TAG_imported_unit";
8305 case DW_TAG_condition
:
8306 return "DW_TAG_condition";
8307 case DW_TAG_shared_type
:
8308 return "DW_TAG_shared_type";
8309 case DW_TAG_MIPS_loop
:
8310 return "DW_TAG_MIPS_loop";
8311 case DW_TAG_HP_array_descriptor
:
8312 return "DW_TAG_HP_array_descriptor";
8313 case DW_TAG_format_label
:
8314 return "DW_TAG_format_label";
8315 case DW_TAG_function_template
:
8316 return "DW_TAG_function_template";
8317 case DW_TAG_class_template
:
8318 return "DW_TAG_class_template";
8319 case DW_TAG_GNU_BINCL
:
8320 return "DW_TAG_GNU_BINCL";
8321 case DW_TAG_GNU_EINCL
:
8322 return "DW_TAG_GNU_EINCL";
8323 case DW_TAG_upc_shared_type
:
8324 return "DW_TAG_upc_shared_type";
8325 case DW_TAG_upc_strict_type
:
8326 return "DW_TAG_upc_strict_type";
8327 case DW_TAG_upc_relaxed_type
:
8328 return "DW_TAG_upc_relaxed_type";
8329 case DW_TAG_PGI_kanji_type
:
8330 return "DW_TAG_PGI_kanji_type";
8331 case DW_TAG_PGI_interface_block
:
8332 return "DW_TAG_PGI_interface_block";
8334 return "DW_TAG_<unknown>";
8338 /* Convert a DWARF attribute code into its string name. */
8341 dwarf_attr_name (unsigned attr
)
8346 return "DW_AT_sibling";
8347 case DW_AT_location
:
8348 return "DW_AT_location";
8350 return "DW_AT_name";
8351 case DW_AT_ordering
:
8352 return "DW_AT_ordering";
8353 case DW_AT_subscr_data
:
8354 return "DW_AT_subscr_data";
8355 case DW_AT_byte_size
:
8356 return "DW_AT_byte_size";
8357 case DW_AT_bit_offset
:
8358 return "DW_AT_bit_offset";
8359 case DW_AT_bit_size
:
8360 return "DW_AT_bit_size";
8361 case DW_AT_element_list
:
8362 return "DW_AT_element_list";
8363 case DW_AT_stmt_list
:
8364 return "DW_AT_stmt_list";
8366 return "DW_AT_low_pc";
8368 return "DW_AT_high_pc";
8369 case DW_AT_language
:
8370 return "DW_AT_language";
8372 return "DW_AT_member";
8374 return "DW_AT_discr";
8375 case DW_AT_discr_value
:
8376 return "DW_AT_discr_value";
8377 case DW_AT_visibility
:
8378 return "DW_AT_visibility";
8380 return "DW_AT_import";
8381 case DW_AT_string_length
:
8382 return "DW_AT_string_length";
8383 case DW_AT_common_reference
:
8384 return "DW_AT_common_reference";
8385 case DW_AT_comp_dir
:
8386 return "DW_AT_comp_dir";
8387 case DW_AT_const_value
:
8388 return "DW_AT_const_value";
8389 case DW_AT_containing_type
:
8390 return "DW_AT_containing_type";
8391 case DW_AT_default_value
:
8392 return "DW_AT_default_value";
8394 return "DW_AT_inline";
8395 case DW_AT_is_optional
:
8396 return "DW_AT_is_optional";
8397 case DW_AT_lower_bound
:
8398 return "DW_AT_lower_bound";
8399 case DW_AT_producer
:
8400 return "DW_AT_producer";
8401 case DW_AT_prototyped
:
8402 return "DW_AT_prototyped";
8403 case DW_AT_return_addr
:
8404 return "DW_AT_return_addr";
8405 case DW_AT_start_scope
:
8406 return "DW_AT_start_scope";
8407 case DW_AT_bit_stride
:
8408 return "DW_AT_bit_stride";
8409 case DW_AT_upper_bound
:
8410 return "DW_AT_upper_bound";
8411 case DW_AT_abstract_origin
:
8412 return "DW_AT_abstract_origin";
8413 case DW_AT_accessibility
:
8414 return "DW_AT_accessibility";
8415 case DW_AT_address_class
:
8416 return "DW_AT_address_class";
8417 case DW_AT_artificial
:
8418 return "DW_AT_artificial";
8419 case DW_AT_base_types
:
8420 return "DW_AT_base_types";
8421 case DW_AT_calling_convention
:
8422 return "DW_AT_calling_convention";
8424 return "DW_AT_count";
8425 case DW_AT_data_member_location
:
8426 return "DW_AT_data_member_location";
8427 case DW_AT_decl_column
:
8428 return "DW_AT_decl_column";
8429 case DW_AT_decl_file
:
8430 return "DW_AT_decl_file";
8431 case DW_AT_decl_line
:
8432 return "DW_AT_decl_line";
8433 case DW_AT_declaration
:
8434 return "DW_AT_declaration";
8435 case DW_AT_discr_list
:
8436 return "DW_AT_discr_list";
8437 case DW_AT_encoding
:
8438 return "DW_AT_encoding";
8439 case DW_AT_external
:
8440 return "DW_AT_external";
8441 case DW_AT_frame_base
:
8442 return "DW_AT_frame_base";
8444 return "DW_AT_friend";
8445 case DW_AT_identifier_case
:
8446 return "DW_AT_identifier_case";
8447 case DW_AT_macro_info
:
8448 return "DW_AT_macro_info";
8449 case DW_AT_namelist_items
:
8450 return "DW_AT_namelist_items";
8451 case DW_AT_priority
:
8452 return "DW_AT_priority";
8454 return "DW_AT_segment";
8455 case DW_AT_specification
:
8456 return "DW_AT_specification";
8457 case DW_AT_static_link
:
8458 return "DW_AT_static_link";
8460 return "DW_AT_type";
8461 case DW_AT_use_location
:
8462 return "DW_AT_use_location";
8463 case DW_AT_variable_parameter
:
8464 return "DW_AT_variable_parameter";
8465 case DW_AT_virtuality
:
8466 return "DW_AT_virtuality";
8467 case DW_AT_vtable_elem_location
:
8468 return "DW_AT_vtable_elem_location";
8469 /* DWARF 3 values. */
8470 case DW_AT_allocated
:
8471 return "DW_AT_allocated";
8472 case DW_AT_associated
:
8473 return "DW_AT_associated";
8474 case DW_AT_data_location
:
8475 return "DW_AT_data_location";
8476 case DW_AT_byte_stride
:
8477 return "DW_AT_byte_stride";
8478 case DW_AT_entry_pc
:
8479 return "DW_AT_entry_pc";
8480 case DW_AT_use_UTF8
:
8481 return "DW_AT_use_UTF8";
8482 case DW_AT_extension
:
8483 return "DW_AT_extension";
8485 return "DW_AT_ranges";
8486 case DW_AT_trampoline
:
8487 return "DW_AT_trampoline";
8488 case DW_AT_call_column
:
8489 return "DW_AT_call_column";
8490 case DW_AT_call_file
:
8491 return "DW_AT_call_file";
8492 case DW_AT_call_line
:
8493 return "DW_AT_call_line";
8494 case DW_AT_description
:
8495 return "DW_AT_description";
8496 case DW_AT_binary_scale
:
8497 return "DW_AT_binary_scale";
8498 case DW_AT_decimal_scale
:
8499 return "DW_AT_decimal_scale";
8501 return "DW_AT_small";
8502 case DW_AT_decimal_sign
:
8503 return "DW_AT_decimal_sign";
8504 case DW_AT_digit_count
:
8505 return "DW_AT_digit_count";
8506 case DW_AT_picture_string
:
8507 return "DW_AT_picture_string";
8509 return "DW_AT_mutable";
8510 case DW_AT_threads_scaled
:
8511 return "DW_AT_threads_scaled";
8512 case DW_AT_explicit
:
8513 return "DW_AT_explicit";
8514 case DW_AT_object_pointer
:
8515 return "DW_AT_object_pointer";
8516 case DW_AT_endianity
:
8517 return "DW_AT_endianity";
8518 case DW_AT_elemental
:
8519 return "DW_AT_elemental";
8521 return "DW_AT_pure";
8522 case DW_AT_recursive
:
8523 return "DW_AT_recursive";
8524 /* SGI/MIPS extensions. */
8525 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8526 case DW_AT_MIPS_fde
:
8527 return "DW_AT_MIPS_fde";
8529 case DW_AT_MIPS_loop_begin
:
8530 return "DW_AT_MIPS_loop_begin";
8531 case DW_AT_MIPS_tail_loop_begin
:
8532 return "DW_AT_MIPS_tail_loop_begin";
8533 case DW_AT_MIPS_epilog_begin
:
8534 return "DW_AT_MIPS_epilog_begin";
8535 case DW_AT_MIPS_loop_unroll_factor
:
8536 return "DW_AT_MIPS_loop_unroll_factor";
8537 case DW_AT_MIPS_software_pipeline_depth
:
8538 return "DW_AT_MIPS_software_pipeline_depth";
8539 case DW_AT_MIPS_linkage_name
:
8540 return "DW_AT_MIPS_linkage_name";
8541 case DW_AT_MIPS_stride
:
8542 return "DW_AT_MIPS_stride";
8543 case DW_AT_MIPS_abstract_name
:
8544 return "DW_AT_MIPS_abstract_name";
8545 case DW_AT_MIPS_clone_origin
:
8546 return "DW_AT_MIPS_clone_origin";
8547 case DW_AT_MIPS_has_inlines
:
8548 return "DW_AT_MIPS_has_inlines";
8549 /* HP extensions. */
8550 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8551 case DW_AT_HP_block_index
:
8552 return "DW_AT_HP_block_index";
8554 case DW_AT_HP_unmodifiable
:
8555 return "DW_AT_HP_unmodifiable";
8556 case DW_AT_HP_actuals_stmt_list
:
8557 return "DW_AT_HP_actuals_stmt_list";
8558 case DW_AT_HP_proc_per_section
:
8559 return "DW_AT_HP_proc_per_section";
8560 case DW_AT_HP_raw_data_ptr
:
8561 return "DW_AT_HP_raw_data_ptr";
8562 case DW_AT_HP_pass_by_reference
:
8563 return "DW_AT_HP_pass_by_reference";
8564 case DW_AT_HP_opt_level
:
8565 return "DW_AT_HP_opt_level";
8566 case DW_AT_HP_prof_version_id
:
8567 return "DW_AT_HP_prof_version_id";
8568 case DW_AT_HP_opt_flags
:
8569 return "DW_AT_HP_opt_flags";
8570 case DW_AT_HP_cold_region_low_pc
:
8571 return "DW_AT_HP_cold_region_low_pc";
8572 case DW_AT_HP_cold_region_high_pc
:
8573 return "DW_AT_HP_cold_region_high_pc";
8574 case DW_AT_HP_all_variables_modifiable
:
8575 return "DW_AT_HP_all_variables_modifiable";
8576 case DW_AT_HP_linkage_name
:
8577 return "DW_AT_HP_linkage_name";
8578 case DW_AT_HP_prof_flags
:
8579 return "DW_AT_HP_prof_flags";
8580 /* GNU extensions. */
8581 case DW_AT_sf_names
:
8582 return "DW_AT_sf_names";
8583 case DW_AT_src_info
:
8584 return "DW_AT_src_info";
8585 case DW_AT_mac_info
:
8586 return "DW_AT_mac_info";
8587 case DW_AT_src_coords
:
8588 return "DW_AT_src_coords";
8589 case DW_AT_body_begin
:
8590 return "DW_AT_body_begin";
8591 case DW_AT_body_end
:
8592 return "DW_AT_body_end";
8593 case DW_AT_GNU_vector
:
8594 return "DW_AT_GNU_vector";
8595 /* VMS extensions. */
8596 case DW_AT_VMS_rtnbeg_pd_address
:
8597 return "DW_AT_VMS_rtnbeg_pd_address";
8598 /* UPC extension. */
8599 case DW_AT_upc_threads_scaled
:
8600 return "DW_AT_upc_threads_scaled";
8601 /* PGI (STMicroelectronics) extensions. */
8602 case DW_AT_PGI_lbase
:
8603 return "DW_AT_PGI_lbase";
8604 case DW_AT_PGI_soffset
:
8605 return "DW_AT_PGI_soffset";
8606 case DW_AT_PGI_lstride
:
8607 return "DW_AT_PGI_lstride";
8609 return "DW_AT_<unknown>";
8613 /* Convert a DWARF value form code into its string name. */
8616 dwarf_form_name (unsigned form
)
8621 return "DW_FORM_addr";
8622 case DW_FORM_block2
:
8623 return "DW_FORM_block2";
8624 case DW_FORM_block4
:
8625 return "DW_FORM_block4";
8627 return "DW_FORM_data2";
8629 return "DW_FORM_data4";
8631 return "DW_FORM_data8";
8632 case DW_FORM_string
:
8633 return "DW_FORM_string";
8635 return "DW_FORM_block";
8636 case DW_FORM_block1
:
8637 return "DW_FORM_block1";
8639 return "DW_FORM_data1";
8641 return "DW_FORM_flag";
8643 return "DW_FORM_sdata";
8645 return "DW_FORM_strp";
8647 return "DW_FORM_udata";
8648 case DW_FORM_ref_addr
:
8649 return "DW_FORM_ref_addr";
8651 return "DW_FORM_ref1";
8653 return "DW_FORM_ref2";
8655 return "DW_FORM_ref4";
8657 return "DW_FORM_ref8";
8658 case DW_FORM_ref_udata
:
8659 return "DW_FORM_ref_udata";
8660 case DW_FORM_indirect
:
8661 return "DW_FORM_indirect";
8663 return "DW_FORM_<unknown>";
8667 /* Convert a DWARF stack opcode into its string name. */
8670 dwarf_stack_op_name (unsigned op
)
8675 return "DW_OP_addr";
8677 return "DW_OP_deref";
8679 return "DW_OP_const1u";
8681 return "DW_OP_const1s";
8683 return "DW_OP_const2u";
8685 return "DW_OP_const2s";
8687 return "DW_OP_const4u";
8689 return "DW_OP_const4s";
8691 return "DW_OP_const8u";
8693 return "DW_OP_const8s";
8695 return "DW_OP_constu";
8697 return "DW_OP_consts";
8701 return "DW_OP_drop";
8703 return "DW_OP_over";
8705 return "DW_OP_pick";
8707 return "DW_OP_swap";
8711 return "DW_OP_xderef";
8719 return "DW_OP_minus";
8731 return "DW_OP_plus";
8732 case DW_OP_plus_uconst
:
8733 return "DW_OP_plus_uconst";
8739 return "DW_OP_shra";
8757 return "DW_OP_skip";
8759 return "DW_OP_lit0";
8761 return "DW_OP_lit1";
8763 return "DW_OP_lit2";
8765 return "DW_OP_lit3";
8767 return "DW_OP_lit4";
8769 return "DW_OP_lit5";
8771 return "DW_OP_lit6";
8773 return "DW_OP_lit7";
8775 return "DW_OP_lit8";
8777 return "DW_OP_lit9";
8779 return "DW_OP_lit10";
8781 return "DW_OP_lit11";
8783 return "DW_OP_lit12";
8785 return "DW_OP_lit13";
8787 return "DW_OP_lit14";
8789 return "DW_OP_lit15";
8791 return "DW_OP_lit16";
8793 return "DW_OP_lit17";
8795 return "DW_OP_lit18";
8797 return "DW_OP_lit19";
8799 return "DW_OP_lit20";
8801 return "DW_OP_lit21";
8803 return "DW_OP_lit22";
8805 return "DW_OP_lit23";
8807 return "DW_OP_lit24";
8809 return "DW_OP_lit25";
8811 return "DW_OP_lit26";
8813 return "DW_OP_lit27";
8815 return "DW_OP_lit28";
8817 return "DW_OP_lit29";
8819 return "DW_OP_lit30";
8821 return "DW_OP_lit31";
8823 return "DW_OP_reg0";
8825 return "DW_OP_reg1";
8827 return "DW_OP_reg2";
8829 return "DW_OP_reg3";
8831 return "DW_OP_reg4";
8833 return "DW_OP_reg5";
8835 return "DW_OP_reg6";
8837 return "DW_OP_reg7";
8839 return "DW_OP_reg8";
8841 return "DW_OP_reg9";
8843 return "DW_OP_reg10";
8845 return "DW_OP_reg11";
8847 return "DW_OP_reg12";
8849 return "DW_OP_reg13";
8851 return "DW_OP_reg14";
8853 return "DW_OP_reg15";
8855 return "DW_OP_reg16";
8857 return "DW_OP_reg17";
8859 return "DW_OP_reg18";
8861 return "DW_OP_reg19";
8863 return "DW_OP_reg20";
8865 return "DW_OP_reg21";
8867 return "DW_OP_reg22";
8869 return "DW_OP_reg23";
8871 return "DW_OP_reg24";
8873 return "DW_OP_reg25";
8875 return "DW_OP_reg26";
8877 return "DW_OP_reg27";
8879 return "DW_OP_reg28";
8881 return "DW_OP_reg29";
8883 return "DW_OP_reg30";
8885 return "DW_OP_reg31";
8887 return "DW_OP_breg0";
8889 return "DW_OP_breg1";
8891 return "DW_OP_breg2";
8893 return "DW_OP_breg3";
8895 return "DW_OP_breg4";
8897 return "DW_OP_breg5";
8899 return "DW_OP_breg6";
8901 return "DW_OP_breg7";
8903 return "DW_OP_breg8";
8905 return "DW_OP_breg9";
8907 return "DW_OP_breg10";
8909 return "DW_OP_breg11";
8911 return "DW_OP_breg12";
8913 return "DW_OP_breg13";
8915 return "DW_OP_breg14";
8917 return "DW_OP_breg15";
8919 return "DW_OP_breg16";
8921 return "DW_OP_breg17";
8923 return "DW_OP_breg18";
8925 return "DW_OP_breg19";
8927 return "DW_OP_breg20";
8929 return "DW_OP_breg21";
8931 return "DW_OP_breg22";
8933 return "DW_OP_breg23";
8935 return "DW_OP_breg24";
8937 return "DW_OP_breg25";
8939 return "DW_OP_breg26";
8941 return "DW_OP_breg27";
8943 return "DW_OP_breg28";
8945 return "DW_OP_breg29";
8947 return "DW_OP_breg30";
8949 return "DW_OP_breg31";
8951 return "DW_OP_regx";
8953 return "DW_OP_fbreg";
8955 return "DW_OP_bregx";
8957 return "DW_OP_piece";
8958 case DW_OP_deref_size
:
8959 return "DW_OP_deref_size";
8960 case DW_OP_xderef_size
:
8961 return "DW_OP_xderef_size";
8964 /* DWARF 3 extensions. */
8965 case DW_OP_push_object_address
:
8966 return "DW_OP_push_object_address";
8968 return "DW_OP_call2";
8970 return "DW_OP_call4";
8971 case DW_OP_call_ref
:
8972 return "DW_OP_call_ref";
8973 /* GNU extensions. */
8974 case DW_OP_form_tls_address
:
8975 return "DW_OP_form_tls_address";
8976 case DW_OP_call_frame_cfa
:
8977 return "DW_OP_call_frame_cfa";
8978 case DW_OP_bit_piece
:
8979 return "DW_OP_bit_piece";
8980 case DW_OP_GNU_push_tls_address
:
8981 return "DW_OP_GNU_push_tls_address";
8982 case DW_OP_GNU_uninit
:
8983 return "DW_OP_GNU_uninit";
8984 /* HP extensions. */
8985 case DW_OP_HP_is_value
:
8986 return "DW_OP_HP_is_value";
8987 case DW_OP_HP_fltconst4
:
8988 return "DW_OP_HP_fltconst4";
8989 case DW_OP_HP_fltconst8
:
8990 return "DW_OP_HP_fltconst8";
8991 case DW_OP_HP_mod_range
:
8992 return "DW_OP_HP_mod_range";
8993 case DW_OP_HP_unmod_range
:
8994 return "DW_OP_HP_unmod_range";
8996 return "DW_OP_HP_tls";
8998 return "OP_<unknown>";
9003 dwarf_bool_name (unsigned mybool
)
9011 /* Convert a DWARF type code into its string name. */
9014 dwarf_type_encoding_name (unsigned enc
)
9019 return "DW_ATE_void";
9020 case DW_ATE_address
:
9021 return "DW_ATE_address";
9022 case DW_ATE_boolean
:
9023 return "DW_ATE_boolean";
9024 case DW_ATE_complex_float
:
9025 return "DW_ATE_complex_float";
9027 return "DW_ATE_float";
9029 return "DW_ATE_signed";
9030 case DW_ATE_signed_char
:
9031 return "DW_ATE_signed_char";
9032 case DW_ATE_unsigned
:
9033 return "DW_ATE_unsigned";
9034 case DW_ATE_unsigned_char
:
9035 return "DW_ATE_unsigned_char";
9037 case DW_ATE_imaginary_float
:
9038 return "DW_ATE_imaginary_float";
9039 case DW_ATE_packed_decimal
:
9040 return "DW_ATE_packed_decimal";
9041 case DW_ATE_numeric_string
:
9042 return "DW_ATE_numeric_string";
9044 return "DW_ATE_edited";
9045 case DW_ATE_signed_fixed
:
9046 return "DW_ATE_signed_fixed";
9047 case DW_ATE_unsigned_fixed
:
9048 return "DW_ATE_unsigned_fixed";
9049 case DW_ATE_decimal_float
:
9050 return "DW_ATE_decimal_float";
9051 /* HP extensions. */
9052 case DW_ATE_HP_float80
:
9053 return "DW_ATE_HP_float80";
9054 case DW_ATE_HP_complex_float80
:
9055 return "DW_ATE_HP_complex_float80";
9056 case DW_ATE_HP_float128
:
9057 return "DW_ATE_HP_float128";
9058 case DW_ATE_HP_complex_float128
:
9059 return "DW_ATE_HP_complex_float128";
9060 case DW_ATE_HP_floathpintel
:
9061 return "DW_ATE_HP_floathpintel";
9062 case DW_ATE_HP_imaginary_float80
:
9063 return "DW_ATE_HP_imaginary_float80";
9064 case DW_ATE_HP_imaginary_float128
:
9065 return "DW_ATE_HP_imaginary_float128";
9067 return "DW_ATE_<unknown>";
9071 /* Convert a DWARF call frame info operation to its string name. */
9075 dwarf_cfi_name (unsigned cfi_opc
)
9079 case DW_CFA_advance_loc
:
9080 return "DW_CFA_advance_loc";
9082 return "DW_CFA_offset";
9083 case DW_CFA_restore
:
9084 return "DW_CFA_restore";
9086 return "DW_CFA_nop";
9087 case DW_CFA_set_loc
:
9088 return "DW_CFA_set_loc";
9089 case DW_CFA_advance_loc1
:
9090 return "DW_CFA_advance_loc1";
9091 case DW_CFA_advance_loc2
:
9092 return "DW_CFA_advance_loc2";
9093 case DW_CFA_advance_loc4
:
9094 return "DW_CFA_advance_loc4";
9095 case DW_CFA_offset_extended
:
9096 return "DW_CFA_offset_extended";
9097 case DW_CFA_restore_extended
:
9098 return "DW_CFA_restore_extended";
9099 case DW_CFA_undefined
:
9100 return "DW_CFA_undefined";
9101 case DW_CFA_same_value
:
9102 return "DW_CFA_same_value";
9103 case DW_CFA_register
:
9104 return "DW_CFA_register";
9105 case DW_CFA_remember_state
:
9106 return "DW_CFA_remember_state";
9107 case DW_CFA_restore_state
:
9108 return "DW_CFA_restore_state";
9109 case DW_CFA_def_cfa
:
9110 return "DW_CFA_def_cfa";
9111 case DW_CFA_def_cfa_register
:
9112 return "DW_CFA_def_cfa_register";
9113 case DW_CFA_def_cfa_offset
:
9114 return "DW_CFA_def_cfa_offset";
9116 case DW_CFA_def_cfa_expression
:
9117 return "DW_CFA_def_cfa_expression";
9118 case DW_CFA_expression
:
9119 return "DW_CFA_expression";
9120 case DW_CFA_offset_extended_sf
:
9121 return "DW_CFA_offset_extended_sf";
9122 case DW_CFA_def_cfa_sf
:
9123 return "DW_CFA_def_cfa_sf";
9124 case DW_CFA_def_cfa_offset_sf
:
9125 return "DW_CFA_def_cfa_offset_sf";
9126 case DW_CFA_val_offset
:
9127 return "DW_CFA_val_offset";
9128 case DW_CFA_val_offset_sf
:
9129 return "DW_CFA_val_offset_sf";
9130 case DW_CFA_val_expression
:
9131 return "DW_CFA_val_expression";
9132 /* SGI/MIPS specific. */
9133 case DW_CFA_MIPS_advance_loc8
:
9134 return "DW_CFA_MIPS_advance_loc8";
9135 /* GNU extensions. */
9136 case DW_CFA_GNU_window_save
:
9137 return "DW_CFA_GNU_window_save";
9138 case DW_CFA_GNU_args_size
:
9139 return "DW_CFA_GNU_args_size";
9140 case DW_CFA_GNU_negative_offset_extended
:
9141 return "DW_CFA_GNU_negative_offset_extended";
9143 return "DW_CFA_<unknown>";
9149 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9153 print_spaces (indent
, f
);
9154 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9155 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9157 if (die
->parent
!= NULL
)
9159 print_spaces (indent
, f
);
9160 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9161 die
->parent
->offset
);
9164 print_spaces (indent
, f
);
9165 fprintf_unfiltered (f
, " has children: %s\n",
9166 dwarf_bool_name (die
->child
!= NULL
));
9168 print_spaces (indent
, f
);
9169 fprintf_unfiltered (f
, " attributes:\n");
9171 for (i
= 0; i
< die
->num_attrs
; ++i
)
9173 print_spaces (indent
, f
);
9174 fprintf_unfiltered (f
, " %s (%s) ",
9175 dwarf_attr_name (die
->attrs
[i
].name
),
9176 dwarf_form_name (die
->attrs
[i
].form
));
9178 switch (die
->attrs
[i
].form
)
9180 case DW_FORM_ref_addr
:
9182 fprintf_unfiltered (f
, "address: ");
9183 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9185 case DW_FORM_block2
:
9186 case DW_FORM_block4
:
9188 case DW_FORM_block1
:
9189 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9194 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9195 (long) (DW_ADDR (&die
->attrs
[i
])));
9203 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9205 case DW_FORM_string
:
9207 fprintf_unfiltered (f
, "string: \"%s\"",
9208 DW_STRING (&die
->attrs
[i
])
9209 ? DW_STRING (&die
->attrs
[i
]) : "");
9212 if (DW_UNSND (&die
->attrs
[i
]))
9213 fprintf_unfiltered (f
, "flag: TRUE");
9215 fprintf_unfiltered (f
, "flag: FALSE");
9217 case DW_FORM_indirect
:
9218 /* the reader will have reduced the indirect form to
9219 the "base form" so this form should not occur */
9220 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9223 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9224 die
->attrs
[i
].form
);
9227 fprintf_unfiltered (f
, "\n");
9232 dump_die_for_error (struct die_info
*die
)
9234 dump_die_shallow (gdb_stderr
, 0, die
);
9238 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9240 int indent
= level
* 4;
9242 gdb_assert (die
!= NULL
);
9244 if (level
>= max_level
)
9247 dump_die_shallow (f
, indent
, die
);
9249 if (die
->child
!= NULL
)
9251 print_spaces (indent
, f
);
9252 fprintf_unfiltered (f
, " Children:");
9253 if (level
+ 1 < max_level
)
9255 fprintf_unfiltered (f
, "\n");
9256 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9260 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9264 if (die
->sibling
!= NULL
&& level
> 0)
9266 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9270 /* This is called from the pdie macro in gdbinit.in.
9271 It's not static so gcc will keep a copy callable from gdb. */
9274 dump_die (struct die_info
*die
, int max_level
)
9276 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9280 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9284 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9290 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9292 unsigned int result
= 0;
9296 case DW_FORM_ref_addr
:
9301 case DW_FORM_ref_udata
:
9302 result
= DW_ADDR (attr
);
9305 complaint (&symfile_complaints
,
9306 _("unsupported die ref attribute form: '%s'"),
9307 dwarf_form_name (attr
->form
));
9312 /* Return the constant value held by the given attribute. Return -1
9313 if the value held by the attribute is not constant. */
9316 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9318 if (attr
->form
== DW_FORM_sdata
)
9319 return DW_SND (attr
);
9320 else if (attr
->form
== DW_FORM_udata
9321 || attr
->form
== DW_FORM_data1
9322 || attr
->form
== DW_FORM_data2
9323 || attr
->form
== DW_FORM_data4
9324 || attr
->form
== DW_FORM_data8
)
9325 return DW_UNSND (attr
);
9328 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9329 dwarf_form_name (attr
->form
));
9330 return default_value
;
9334 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9335 unit and add it to our queue. */
9338 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9339 struct dwarf2_per_cu_data
*per_cu
)
9341 /* Mark the dependence relation so that we don't flush PER_CU
9343 dwarf2_add_dependence (this_cu
, per_cu
);
9345 /* If it's already on the queue, we have nothing to do. */
9349 /* If the compilation unit is already loaded, just mark it as
9351 if (per_cu
->cu
!= NULL
)
9353 per_cu
->cu
->last_used
= 0;
9357 /* Add it to the queue. */
9358 queue_comp_unit (per_cu
, this_cu
->objfile
);
9361 static struct die_info
*
9362 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9363 struct dwarf2_cu
**ref_cu
)
9365 struct die_info
*die
;
9366 unsigned int offset
;
9367 struct die_info temp_die
;
9368 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9370 offset
= dwarf2_get_ref_die_offset (attr
);
9372 if (! offset_in_cu_p (&cu
->header
, offset
))
9374 struct dwarf2_per_cu_data
*per_cu
;
9375 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9377 /* If necessary, add it to the queue and load its DIEs. */
9378 maybe_queue_comp_unit (cu
, per_cu
);
9380 target_cu
= per_cu
->cu
;
9385 *ref_cu
= target_cu
;
9386 temp_die
.offset
= offset
;
9387 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9391 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9392 "at 0x%lx [in module %s]"),
9393 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9396 /* Decode simple location descriptions.
9397 Given a pointer to a dwarf block that defines a location, compute
9398 the location and return the value.
9400 NOTE drow/2003-11-18: This function is called in two situations
9401 now: for the address of static or global variables (partial symbols
9402 only) and for offsets into structures which are expected to be
9403 (more or less) constant. The partial symbol case should go away,
9404 and only the constant case should remain. That will let this
9405 function complain more accurately. A few special modes are allowed
9406 without complaint for global variables (for instance, global
9407 register values and thread-local values).
9409 A location description containing no operations indicates that the
9410 object is optimized out. The return value is 0 for that case.
9411 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9412 callers will only want a very basic result and this can become a
9415 Note that stack[0] is unused except as a default error return.
9416 Note that stack overflow is not yet handled. */
9419 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9421 struct objfile
*objfile
= cu
->objfile
;
9422 struct comp_unit_head
*cu_header
= &cu
->header
;
9424 int size
= blk
->size
;
9425 gdb_byte
*data
= blk
->data
;
9426 CORE_ADDR stack
[64];
9428 unsigned int bytes_read
, unsnd
;
9472 stack
[++stacki
] = op
- DW_OP_lit0
;
9507 stack
[++stacki
] = op
- DW_OP_reg0
;
9509 dwarf2_complex_location_expr_complaint ();
9513 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9515 stack
[++stacki
] = unsnd
;
9517 dwarf2_complex_location_expr_complaint ();
9521 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9527 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9532 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9537 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9542 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9547 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9552 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9557 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9563 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9568 stack
[stacki
+ 1] = stack
[stacki
];
9573 stack
[stacki
- 1] += stack
[stacki
];
9577 case DW_OP_plus_uconst
:
9578 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9583 stack
[stacki
- 1] -= stack
[stacki
];
9588 /* If we're not the last op, then we definitely can't encode
9589 this using GDB's address_class enum. This is valid for partial
9590 global symbols, although the variable's address will be bogus
9593 dwarf2_complex_location_expr_complaint ();
9596 case DW_OP_GNU_push_tls_address
:
9597 /* The top of the stack has the offset from the beginning
9598 of the thread control block at which the variable is located. */
9599 /* Nothing should follow this operator, so the top of stack would
9601 /* This is valid for partial global symbols, but the variable's
9602 address will be bogus in the psymtab. */
9604 dwarf2_complex_location_expr_complaint ();
9607 case DW_OP_GNU_uninit
:
9611 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9612 dwarf_stack_op_name (op
));
9613 return (stack
[stacki
]);
9616 return (stack
[stacki
]);
9619 /* memory allocation interface */
9621 static struct dwarf_block
*
9622 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9624 struct dwarf_block
*blk
;
9626 blk
= (struct dwarf_block
*)
9627 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9631 static struct abbrev_info
*
9632 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9634 struct abbrev_info
*abbrev
;
9636 abbrev
= (struct abbrev_info
*)
9637 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9638 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9642 static struct die_info
*
9643 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9645 struct die_info
*die
;
9646 size_t size
= sizeof (struct die_info
);
9649 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9651 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9652 memset (die
, 0, sizeof (struct die_info
));
9657 /* Macro support. */
9660 /* Return the full name of file number I in *LH's file name table.
9661 Use COMP_DIR as the name of the current directory of the
9662 compilation. The result is allocated using xmalloc; the caller is
9663 responsible for freeing it. */
9665 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9667 /* Is the file number a valid index into the line header's file name
9668 table? Remember that file numbers start with one, not zero. */
9669 if (1 <= file
&& file
<= lh
->num_file_names
)
9671 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9673 if (IS_ABSOLUTE_PATH (fe
->name
))
9674 return xstrdup (fe
->name
);
9682 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9688 dir_len
= strlen (dir
);
9689 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9690 strcpy (full_name
, dir
);
9691 full_name
[dir_len
] = '/';
9692 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9696 return xstrdup (fe
->name
);
9701 /* The compiler produced a bogus file number. We can at least
9702 record the macro definitions made in the file, even if we
9703 won't be able to find the file by name. */
9705 sprintf (fake_name
, "<bad macro file number %d>", file
);
9707 complaint (&symfile_complaints
,
9708 _("bad file number in macro information (%d)"),
9711 return xstrdup (fake_name
);
9716 static struct macro_source_file
*
9717 macro_start_file (int file
, int line
,
9718 struct macro_source_file
*current_file
,
9719 const char *comp_dir
,
9720 struct line_header
*lh
, struct objfile
*objfile
)
9722 /* The full name of this source file. */
9723 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9725 /* We don't create a macro table for this compilation unit
9726 at all until we actually get a filename. */
9727 if (! pending_macros
)
9728 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9729 objfile
->macro_cache
);
9732 /* If we have no current file, then this must be the start_file
9733 directive for the compilation unit's main source file. */
9734 current_file
= macro_set_main (pending_macros
, full_name
);
9736 current_file
= macro_include (current_file
, line
, full_name
);
9740 return current_file
;
9744 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9745 followed by a null byte. */
9747 copy_string (const char *buf
, int len
)
9749 char *s
= xmalloc (len
+ 1);
9750 memcpy (s
, buf
, len
);
9758 consume_improper_spaces (const char *p
, const char *body
)
9762 complaint (&symfile_complaints
,
9763 _("macro definition contains spaces in formal argument list:\n`%s'"),
9775 parse_macro_definition (struct macro_source_file
*file
, int line
,
9780 /* The body string takes one of two forms. For object-like macro
9781 definitions, it should be:
9783 <macro name> " " <definition>
9785 For function-like macro definitions, it should be:
9787 <macro name> "() " <definition>
9789 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9791 Spaces may appear only where explicitly indicated, and in the
9794 The Dwarf 2 spec says that an object-like macro's name is always
9795 followed by a space, but versions of GCC around March 2002 omit
9796 the space when the macro's definition is the empty string.
9798 The Dwarf 2 spec says that there should be no spaces between the
9799 formal arguments in a function-like macro's formal argument list,
9800 but versions of GCC around March 2002 include spaces after the
9804 /* Find the extent of the macro name. The macro name is terminated
9805 by either a space or null character (for an object-like macro) or
9806 an opening paren (for a function-like macro). */
9807 for (p
= body
; *p
; p
++)
9808 if (*p
== ' ' || *p
== '(')
9811 if (*p
== ' ' || *p
== '\0')
9813 /* It's an object-like macro. */
9814 int name_len
= p
- body
;
9815 char *name
= copy_string (body
, name_len
);
9816 const char *replacement
;
9819 replacement
= body
+ name_len
+ 1;
9822 dwarf2_macro_malformed_definition_complaint (body
);
9823 replacement
= body
+ name_len
;
9826 macro_define_object (file
, line
, name
, replacement
);
9832 /* It's a function-like macro. */
9833 char *name
= copy_string (body
, p
- body
);
9836 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9840 p
= consume_improper_spaces (p
, body
);
9842 /* Parse the formal argument list. */
9843 while (*p
&& *p
!= ')')
9845 /* Find the extent of the current argument name. */
9846 const char *arg_start
= p
;
9848 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9851 if (! *p
|| p
== arg_start
)
9852 dwarf2_macro_malformed_definition_complaint (body
);
9855 /* Make sure argv has room for the new argument. */
9856 if (argc
>= argv_size
)
9859 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9862 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9865 p
= consume_improper_spaces (p
, body
);
9867 /* Consume the comma, if present. */
9872 p
= consume_improper_spaces (p
, body
);
9881 /* Perfectly formed definition, no complaints. */
9882 macro_define_function (file
, line
, name
,
9883 argc
, (const char **) argv
,
9885 else if (*p
== '\0')
9887 /* Complain, but do define it. */
9888 dwarf2_macro_malformed_definition_complaint (body
);
9889 macro_define_function (file
, line
, name
,
9890 argc
, (const char **) argv
,
9894 /* Just complain. */
9895 dwarf2_macro_malformed_definition_complaint (body
);
9898 /* Just complain. */
9899 dwarf2_macro_malformed_definition_complaint (body
);
9905 for (i
= 0; i
< argc
; i
++)
9911 dwarf2_macro_malformed_definition_complaint (body
);
9916 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9917 char *comp_dir
, bfd
*abfd
,
9918 struct dwarf2_cu
*cu
)
9920 gdb_byte
*mac_ptr
, *mac_end
;
9921 struct macro_source_file
*current_file
= 0;
9923 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9925 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9929 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9930 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9931 + dwarf2_per_objfile
->macinfo_size
;
9935 enum dwarf_macinfo_record_type macinfo_type
;
9937 /* Do we at least have room for a macinfo type byte? */
9938 if (mac_ptr
>= mac_end
)
9940 dwarf2_macros_too_long_complaint ();
9944 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9947 switch (macinfo_type
)
9949 /* A zero macinfo type indicates the end of the macro
9954 case DW_MACINFO_define
:
9955 case DW_MACINFO_undef
:
9957 unsigned int bytes_read
;
9961 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9962 mac_ptr
+= bytes_read
;
9963 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9964 mac_ptr
+= bytes_read
;
9967 complaint (&symfile_complaints
,
9968 _("debug info gives macro %s outside of any file: %s"),
9970 DW_MACINFO_define
? "definition" : macinfo_type
==
9971 DW_MACINFO_undef
? "undefinition" :
9972 "something-or-other", body
);
9975 if (macinfo_type
== DW_MACINFO_define
)
9976 parse_macro_definition (current_file
, line
, body
);
9977 else if (macinfo_type
== DW_MACINFO_undef
)
9978 macro_undef (current_file
, line
, body
);
9983 case DW_MACINFO_start_file
:
9985 unsigned int bytes_read
;
9988 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9989 mac_ptr
+= bytes_read
;
9990 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9991 mac_ptr
+= bytes_read
;
9993 current_file
= macro_start_file (file
, line
,
9994 current_file
, comp_dir
,
9999 case DW_MACINFO_end_file
:
10000 if (! current_file
)
10001 complaint (&symfile_complaints
,
10002 _("macro debug info has an unmatched `close_file' directive"));
10005 current_file
= current_file
->included_by
;
10006 if (! current_file
)
10008 enum dwarf_macinfo_record_type next_type
;
10010 /* GCC circa March 2002 doesn't produce the zero
10011 type byte marking the end of the compilation
10012 unit. Complain if it's not there, but exit no
10015 /* Do we at least have room for a macinfo type byte? */
10016 if (mac_ptr
>= mac_end
)
10018 dwarf2_macros_too_long_complaint ();
10022 /* We don't increment mac_ptr here, so this is just
10024 next_type
= read_1_byte (abfd
, mac_ptr
);
10025 if (next_type
!= 0)
10026 complaint (&symfile_complaints
,
10027 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10034 case DW_MACINFO_vendor_ext
:
10036 unsigned int bytes_read
;
10040 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10041 mac_ptr
+= bytes_read
;
10042 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10043 mac_ptr
+= bytes_read
;
10045 /* We don't recognize any vendor extensions. */
10052 /* Check if the attribute's form is a DW_FORM_block*
10053 if so return true else false. */
10055 attr_form_is_block (struct attribute
*attr
)
10057 return (attr
== NULL
? 0 :
10058 attr
->form
== DW_FORM_block1
10059 || attr
->form
== DW_FORM_block2
10060 || attr
->form
== DW_FORM_block4
10061 || attr
->form
== DW_FORM_block
);
10064 /* Return non-zero if ATTR's value is a section offset --- classes
10065 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10066 You may use DW_UNSND (attr) to retrieve such offsets.
10068 Section 7.5.4, "Attribute Encodings", explains that no attribute
10069 may have a value that belongs to more than one of these classes; it
10070 would be ambiguous if we did, because we use the same forms for all
10073 attr_form_is_section_offset (struct attribute
*attr
)
10075 return (attr
->form
== DW_FORM_data4
10076 || attr
->form
== DW_FORM_data8
);
10080 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10081 zero otherwise. When this function returns true, you can apply
10082 dwarf2_get_attr_constant_value to it.
10084 However, note that for some attributes you must check
10085 attr_form_is_section_offset before using this test. DW_FORM_data4
10086 and DW_FORM_data8 are members of both the constant class, and of
10087 the classes that contain offsets into other debug sections
10088 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10089 that, if an attribute's can be either a constant or one of the
10090 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10091 taken as section offsets, not constants. */
10093 attr_form_is_constant (struct attribute
*attr
)
10095 switch (attr
->form
)
10097 case DW_FORM_sdata
:
10098 case DW_FORM_udata
:
10099 case DW_FORM_data1
:
10100 case DW_FORM_data2
:
10101 case DW_FORM_data4
:
10102 case DW_FORM_data8
:
10110 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10111 struct dwarf2_cu
*cu
)
10113 if (attr_form_is_section_offset (attr
)
10114 /* ".debug_loc" may not exist at all, or the offset may be outside
10115 the section. If so, fall through to the complaint in the
10117 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10119 struct dwarf2_loclist_baton
*baton
;
10121 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10122 sizeof (struct dwarf2_loclist_baton
));
10123 baton
->per_cu
= cu
->per_cu
;
10124 gdb_assert (baton
->per_cu
);
10126 /* We don't know how long the location list is, but make sure we
10127 don't run off the edge of the section. */
10128 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10129 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10130 baton
->base_address
= cu
->base_address
;
10131 if (cu
->base_known
== 0)
10132 complaint (&symfile_complaints
,
10133 _("Location list used without specifying the CU base address."));
10135 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10136 SYMBOL_LOCATION_BATON (sym
) = baton
;
10140 struct dwarf2_locexpr_baton
*baton
;
10142 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10143 sizeof (struct dwarf2_locexpr_baton
));
10144 baton
->per_cu
= cu
->per_cu
;
10145 gdb_assert (baton
->per_cu
);
10147 if (attr_form_is_block (attr
))
10149 /* Note that we're just copying the block's data pointer
10150 here, not the actual data. We're still pointing into the
10151 info_buffer for SYM's objfile; right now we never release
10152 that buffer, but when we do clean up properly this may
10154 baton
->size
= DW_BLOCK (attr
)->size
;
10155 baton
->data
= DW_BLOCK (attr
)->data
;
10159 dwarf2_invalid_attrib_class_complaint ("location description",
10160 SYMBOL_NATURAL_NAME (sym
));
10162 baton
->data
= NULL
;
10165 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10166 SYMBOL_LOCATION_BATON (sym
) = baton
;
10170 /* Return the OBJFILE associated with the compilation unit CU. */
10173 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10175 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10177 /* Return the master objfile, so that we can report and look up the
10178 correct file containing this variable. */
10179 if (objfile
->separate_debug_objfile_backlink
)
10180 objfile
= objfile
->separate_debug_objfile_backlink
;
10185 /* Return the address size given in the compilation unit header for CU. */
10188 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10191 return per_cu
->cu
->header
.addr_size
;
10194 /* If the CU is not currently read in, we re-read its header. */
10195 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10196 struct dwarf2_per_objfile
*per_objfile
10197 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10198 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10200 struct comp_unit_head cu_header
;
10201 memset (&cu_header
, 0, sizeof cu_header
);
10202 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10203 return cu_header
.addr_size
;
10207 /* Locate the compilation unit from CU's objfile which contains the
10208 DIE at OFFSET. Raises an error on failure. */
10210 static struct dwarf2_per_cu_data
*
10211 dwarf2_find_containing_comp_unit (unsigned int offset
,
10212 struct objfile
*objfile
)
10214 struct dwarf2_per_cu_data
*this_cu
;
10218 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10221 int mid
= low
+ (high
- low
) / 2;
10222 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10227 gdb_assert (low
== high
);
10228 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10231 error (_("Dwarf Error: could not find partial DIE containing "
10232 "offset 0x%lx [in module %s]"),
10233 (long) offset
, bfd_get_filename (objfile
->obfd
));
10235 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10236 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10240 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10241 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10242 && offset
>= this_cu
->offset
+ this_cu
->length
)
10243 error (_("invalid dwarf2 offset %u"), offset
);
10244 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10249 /* Locate the compilation unit from OBJFILE which is located at exactly
10250 OFFSET. Raises an error on failure. */
10252 static struct dwarf2_per_cu_data
*
10253 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10255 struct dwarf2_per_cu_data
*this_cu
;
10256 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10257 if (this_cu
->offset
!= offset
)
10258 error (_("no compilation unit with offset %u."), offset
);
10262 /* Release one cached compilation unit, CU. We unlink it from the tree
10263 of compilation units, but we don't remove it from the read_in_chain;
10264 the caller is responsible for that. */
10267 free_one_comp_unit (void *data
)
10269 struct dwarf2_cu
*cu
= data
;
10271 if (cu
->per_cu
!= NULL
)
10272 cu
->per_cu
->cu
= NULL
;
10275 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10280 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10281 when we're finished with it. We can't free the pointer itself, but be
10282 sure to unlink it from the cache. Also release any associated storage
10283 and perform cache maintenance.
10285 Only used during partial symbol parsing. */
10288 free_stack_comp_unit (void *data
)
10290 struct dwarf2_cu
*cu
= data
;
10292 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10293 cu
->partial_dies
= NULL
;
10295 if (cu
->per_cu
!= NULL
)
10297 /* This compilation unit is on the stack in our caller, so we
10298 should not xfree it. Just unlink it. */
10299 cu
->per_cu
->cu
= NULL
;
10302 /* If we had a per-cu pointer, then we may have other compilation
10303 units loaded, so age them now. */
10304 age_cached_comp_units ();
10308 /* Free all cached compilation units. */
10311 free_cached_comp_units (void *data
)
10313 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10315 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10316 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10317 while (per_cu
!= NULL
)
10319 struct dwarf2_per_cu_data
*next_cu
;
10321 next_cu
= per_cu
->cu
->read_in_chain
;
10323 free_one_comp_unit (per_cu
->cu
);
10324 *last_chain
= next_cu
;
10330 /* Increase the age counter on each cached compilation unit, and free
10331 any that are too old. */
10334 age_cached_comp_units (void)
10336 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10338 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10339 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10340 while (per_cu
!= NULL
)
10342 per_cu
->cu
->last_used
++;
10343 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10344 dwarf2_mark (per_cu
->cu
);
10345 per_cu
= per_cu
->cu
->read_in_chain
;
10348 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10349 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10350 while (per_cu
!= NULL
)
10352 struct dwarf2_per_cu_data
*next_cu
;
10354 next_cu
= per_cu
->cu
->read_in_chain
;
10356 if (!per_cu
->cu
->mark
)
10358 free_one_comp_unit (per_cu
->cu
);
10359 *last_chain
= next_cu
;
10362 last_chain
= &per_cu
->cu
->read_in_chain
;
10368 /* Remove a single compilation unit from the cache. */
10371 free_one_cached_comp_unit (void *target_cu
)
10373 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10375 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10376 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10377 while (per_cu
!= NULL
)
10379 struct dwarf2_per_cu_data
*next_cu
;
10381 next_cu
= per_cu
->cu
->read_in_chain
;
10383 if (per_cu
->cu
== target_cu
)
10385 free_one_comp_unit (per_cu
->cu
);
10386 *last_chain
= next_cu
;
10390 last_chain
= &per_cu
->cu
->read_in_chain
;
10396 /* Release all extra memory associated with OBJFILE. */
10399 dwarf2_free_objfile (struct objfile
*objfile
)
10401 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10403 if (dwarf2_per_objfile
== NULL
)
10406 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10407 free_cached_comp_units (NULL
);
10409 /* Everything else should be on the objfile obstack. */
10412 /* A pair of DIE offset and GDB type pointer. We store these
10413 in a hash table separate from the DIEs, and preserve them
10414 when the DIEs are flushed out of cache. */
10416 struct dwarf2_offset_and_type
10418 unsigned int offset
;
10422 /* Hash function for a dwarf2_offset_and_type. */
10425 offset_and_type_hash (const void *item
)
10427 const struct dwarf2_offset_and_type
*ofs
= item
;
10428 return ofs
->offset
;
10431 /* Equality function for a dwarf2_offset_and_type. */
10434 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10436 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10437 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10438 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10441 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10442 table if necessary. For convenience, return TYPE. */
10444 static struct type
*
10445 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10447 struct dwarf2_offset_and_type
**slot
, ofs
;
10449 if (cu
->type_hash
== NULL
)
10451 gdb_assert (cu
->per_cu
!= NULL
);
10452 cu
->per_cu
->type_hash
10453 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10454 offset_and_type_hash
,
10455 offset_and_type_eq
,
10457 &cu
->objfile
->objfile_obstack
,
10458 hashtab_obstack_allocate
,
10459 dummy_obstack_deallocate
);
10460 cu
->type_hash
= cu
->per_cu
->type_hash
;
10463 ofs
.offset
= die
->offset
;
10465 slot
= (struct dwarf2_offset_and_type
**)
10466 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10467 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10472 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10473 not have a saved type. */
10475 static struct type
*
10476 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10478 struct dwarf2_offset_and_type
*slot
, ofs
;
10479 htab_t type_hash
= cu
->type_hash
;
10481 if (type_hash
== NULL
)
10484 ofs
.offset
= die
->offset
;
10485 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10492 /* Set the mark field in CU and in every other compilation unit in the
10493 cache that we must keep because we are keeping CU. */
10495 /* Add a dependence relationship from CU to REF_PER_CU. */
10498 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10499 struct dwarf2_per_cu_data
*ref_per_cu
)
10503 if (cu
->dependencies
== NULL
)
10505 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10506 NULL
, &cu
->comp_unit_obstack
,
10507 hashtab_obstack_allocate
,
10508 dummy_obstack_deallocate
);
10510 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10512 *slot
= ref_per_cu
;
10515 /* Set the mark field in CU and in every other compilation unit in the
10516 cache that we must keep because we are keeping CU. */
10519 dwarf2_mark_helper (void **slot
, void *data
)
10521 struct dwarf2_per_cu_data
*per_cu
;
10523 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10524 if (per_cu
->cu
->mark
)
10526 per_cu
->cu
->mark
= 1;
10528 if (per_cu
->cu
->dependencies
!= NULL
)
10529 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10535 dwarf2_mark (struct dwarf2_cu
*cu
)
10540 if (cu
->dependencies
!= NULL
)
10541 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10545 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10549 per_cu
->cu
->mark
= 0;
10550 per_cu
= per_cu
->cu
->read_in_chain
;
10554 /* Trivial hash function for partial_die_info: the hash value of a DIE
10555 is its offset in .debug_info for this objfile. */
10558 partial_die_hash (const void *item
)
10560 const struct partial_die_info
*part_die
= item
;
10561 return part_die
->offset
;
10564 /* Trivial comparison function for partial_die_info structures: two DIEs
10565 are equal if they have the same offset. */
10568 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10570 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10571 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10572 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10575 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10576 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10579 set_dwarf2_cmd (char *args
, int from_tty
)
10581 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10585 show_dwarf2_cmd (char *args
, int from_tty
)
10587 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10590 void _initialize_dwarf2_read (void);
10593 _initialize_dwarf2_read (void)
10595 dwarf2_objfile_data_key
= register_objfile_data ();
10597 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10598 Set DWARF 2 specific variables.\n\
10599 Configure DWARF 2 variables such as the cache size"),
10600 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10601 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10603 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10604 Show DWARF 2 specific variables\n\
10605 Show DWARF 2 variables such as the cache size"),
10606 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10607 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10609 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10610 &dwarf2_max_cache_age
, _("\
10611 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10612 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10613 A higher limit means that cached compilation units will be stored\n\
10614 in memory longer, and more total memory will be used. Zero disables\n\
10615 caching, which can slow down startup."),
10617 show_dwarf2_max_cache_age
,
10618 &set_dwarf2_cmdlist
,
10619 &show_dwarf2_cmdlist
);
10621 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
10622 Set debugging of the dwarf2 DIE reader."), _("\
10623 Show debugging of the dwarf2 DIE reader."), _("\
10624 When enabled (non-zero), DIEs are dumped after they are read in.\n\
10625 The value is the maximum depth to print."),
10628 &setdebuglist
, &showdebuglist
);