1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
51 #include "gdb_string.h"
52 #include "gdb_assert.h"
53 #include <sys/types.h>
58 /* A note on memory usage for this file.
60 At the present time, this code reads the debug info sections into
61 the objfile's objfile_obstack. A definite improvement for startup
62 time, on platforms which do not emit relocations for debug
63 sections, would be to use mmap instead. The object's complete
64 debug information is loaded into memory, partly to simplify
65 absolute DIE references.
67 Whether using obstacks or mmap, the sections should remain loaded
68 until the objfile is released, and pointers into the section data
69 can be used for any other data associated to the objfile (symbol
70 names, type names, location expressions to name a few). */
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 /* When non-zero, dump DIEs after they are read in. */
145 static int dwarf2_die_debug
= 0;
147 /* When set, the file that we're processing is known to have debugging
148 info for C++ namespaces. GCC 3.3.x did not produce this information,
149 but later versions do. */
151 static int processing_has_namespace_info
;
153 static const struct objfile_data
*dwarf2_objfile_data_key
;
155 struct dwarf2_per_objfile
157 /* Sizes of debugging sections. */
158 unsigned int info_size
;
159 unsigned int abbrev_size
;
160 unsigned int line_size
;
161 unsigned int pubnames_size
;
162 unsigned int aranges_size
;
163 unsigned int loc_size
;
164 unsigned int macinfo_size
;
165 unsigned int str_size
;
166 unsigned int ranges_size
;
167 unsigned int frame_size
;
168 unsigned int eh_frame_size
;
170 /* Loaded data from the sections. */
171 gdb_byte
*info_buffer
;
172 gdb_byte
*abbrev_buffer
;
173 gdb_byte
*line_buffer
;
174 gdb_byte
*str_buffer
;
175 gdb_byte
*macinfo_buffer
;
176 gdb_byte
*ranges_buffer
;
177 gdb_byte
*loc_buffer
;
179 /* A list of all the compilation units. This is used to locate
180 the target compilation unit of a particular reference. */
181 struct dwarf2_per_cu_data
**all_comp_units
;
183 /* The number of compilation units in ALL_COMP_UNITS. */
186 /* A chain of compilation units that are currently read in, so that
187 they can be freed later. */
188 struct dwarf2_per_cu_data
*read_in_chain
;
190 /* A flag indicating wether this objfile has a section loaded at a
192 int has_section_at_zero
;
195 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
197 static asection
*dwarf_info_section
;
198 static asection
*dwarf_abbrev_section
;
199 static asection
*dwarf_line_section
;
200 static asection
*dwarf_pubnames_section
;
201 static asection
*dwarf_aranges_section
;
202 static asection
*dwarf_loc_section
;
203 static asection
*dwarf_macinfo_section
;
204 static asection
*dwarf_str_section
;
205 static asection
*dwarf_ranges_section
;
206 asection
*dwarf_frame_section
;
207 asection
*dwarf_eh_frame_section
;
209 /* names of the debugging sections */
211 /* Note that if the debugging section has been compressed, it might
212 have a name like .zdebug_info. */
214 #define INFO_SECTION "debug_info"
215 #define ABBREV_SECTION "debug_abbrev"
216 #define LINE_SECTION "debug_line"
217 #define PUBNAMES_SECTION "debug_pubnames"
218 #define ARANGES_SECTION "debug_aranges"
219 #define LOC_SECTION "debug_loc"
220 #define MACINFO_SECTION "debug_macinfo"
221 #define STR_SECTION "debug_str"
222 #define RANGES_SECTION "debug_ranges"
223 #define FRAME_SECTION "debug_frame"
224 #define EH_FRAME_SECTION "eh_frame"
226 /* local data types */
228 /* We hold several abbreviation tables in memory at the same time. */
229 #ifndef ABBREV_HASH_SIZE
230 #define ABBREV_HASH_SIZE 121
233 /* The data in a compilation unit header, after target2host
234 translation, looks like this. */
235 struct comp_unit_head
239 unsigned char addr_size
;
240 unsigned char signed_addr_p
;
241 unsigned int abbrev_offset
;
243 /* Size of file offsets; either 4 or 8. */
244 unsigned int offset_size
;
246 /* Size of the length field; either 4 or 12. */
247 unsigned int initial_length_size
;
249 /* Offset to the first byte of this compilation unit header in the
250 .debug_info section, for resolving relative reference dies. */
253 /* Offset to first die in this cu from the start of the cu.
254 This will be the first byte following the compilation unit header. */
255 unsigned int first_die_offset
;
258 /* Internal state when decoding a particular compilation unit. */
261 /* The objfile containing this compilation unit. */
262 struct objfile
*objfile
;
264 /* The header of the compilation unit. */
265 struct comp_unit_head header
;
267 /* Base address of this compilation unit. */
268 CORE_ADDR base_address
;
270 /* Non-zero if base_address has been set. */
273 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
275 /* The language we are debugging. */
276 enum language language
;
277 const struct language_defn
*language_defn
;
279 const char *producer
;
281 /* The generic symbol table building routines have separate lists for
282 file scope symbols and all all other scopes (local scopes). So
283 we need to select the right one to pass to add_symbol_to_list().
284 We do it by keeping a pointer to the correct list in list_in_scope.
286 FIXME: The original dwarf code just treated the file scope as the
287 first local scope, and all other local scopes as nested local
288 scopes, and worked fine. Check to see if we really need to
289 distinguish these in buildsym.c. */
290 struct pending
**list_in_scope
;
292 /* DWARF abbreviation table associated with this compilation unit. */
293 struct abbrev_info
**dwarf2_abbrevs
;
295 /* Storage for the abbrev table. */
296 struct obstack abbrev_obstack
;
298 /* Hash table holding all the loaded partial DIEs. */
301 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
302 unsigned int ranges_offset
;
304 /* Storage for things with the same lifetime as this read-in compilation
305 unit, including partial DIEs. */
306 struct obstack comp_unit_obstack
;
308 /* When multiple dwarf2_cu structures are living in memory, this field
309 chains them all together, so that they can be released efficiently.
310 We will probably also want a generation counter so that most-recently-used
311 compilation units are cached... */
312 struct dwarf2_per_cu_data
*read_in_chain
;
314 /* Backchain to our per_cu entry if the tree has been built. */
315 struct dwarf2_per_cu_data
*per_cu
;
317 /* Pointer to the die -> type map. Although it is stored
318 permanently in per_cu, we copy it here to avoid double
322 /* How many compilation units ago was this CU last referenced? */
325 /* A hash table of die offsets for following references. */
328 /* Full DIEs if read in. */
329 struct die_info
*dies
;
331 /* A set of pointers to dwarf2_per_cu_data objects for compilation
332 units referenced by this one. Only set during full symbol processing;
333 partial symbol tables do not have dependencies. */
336 /* Header data from the line table, during full symbol processing. */
337 struct line_header
*line_header
;
339 /* Mark used when releasing cached dies. */
340 unsigned int mark
: 1;
342 /* This flag will be set if this compilation unit might include
343 inter-compilation-unit references. */
344 unsigned int has_form_ref_addr
: 1;
346 /* This flag will be set if this compilation unit includes any
347 DW_TAG_namespace DIEs. If we know that there are explicit
348 DIEs for namespaces, we don't need to try to infer them
349 from mangled names. */
350 unsigned int has_namespace_info
: 1;
352 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
353 unsigned int has_ranges_offset
: 1;
356 /* Persistent data held for a compilation unit, even when not
357 processing it. We put a pointer to this structure in the
358 read_symtab_private field of the psymtab. If we encounter
359 inter-compilation-unit references, we also maintain a sorted
360 list of all compilation units. */
362 struct dwarf2_per_cu_data
364 /* The start offset and length of this compilation unit. 2**30-1
365 bytes should suffice to store the length of any compilation unit
366 - if it doesn't, GDB will fall over anyway.
367 NOTE: Unlike comp_unit_head.length, this length includes
368 initial_length_size. */
370 unsigned int length
: 30;
372 /* Flag indicating this compilation unit will be read in before
373 any of the current compilation units are processed. */
374 unsigned int queued
: 1;
376 /* This flag will be set if we need to load absolutely all DIEs
377 for this compilation unit, instead of just the ones we think
378 are interesting. It gets set if we look for a DIE in the
379 hash table and don't find it. */
380 unsigned int load_all_dies
: 1;
382 /* Set iff currently read in. */
383 struct dwarf2_cu
*cu
;
385 /* If full symbols for this CU have been read in, then this field
386 holds a map of DIE offsets to types. It isn't always possible
387 to reconstruct this information later, so we have to preserve
391 /* The partial symbol table associated with this compilation unit,
392 or NULL for partial units (which do not have an associated
394 struct partial_symtab
*psymtab
;
397 /* The line number information for a compilation unit (found in the
398 .debug_line section) begins with a "statement program header",
399 which contains the following information. */
402 unsigned int total_length
;
403 unsigned short version
;
404 unsigned int header_length
;
405 unsigned char minimum_instruction_length
;
406 unsigned char default_is_stmt
;
408 unsigned char line_range
;
409 unsigned char opcode_base
;
411 /* standard_opcode_lengths[i] is the number of operands for the
412 standard opcode whose value is i. This means that
413 standard_opcode_lengths[0] is unused, and the last meaningful
414 element is standard_opcode_lengths[opcode_base - 1]. */
415 unsigned char *standard_opcode_lengths
;
417 /* The include_directories table. NOTE! These strings are not
418 allocated with xmalloc; instead, they are pointers into
419 debug_line_buffer. If you try to free them, `free' will get
421 unsigned int num_include_dirs
, include_dirs_size
;
424 /* The file_names table. NOTE! These strings are not allocated
425 with xmalloc; instead, they are pointers into debug_line_buffer.
426 Don't try to free them directly. */
427 unsigned int num_file_names
, file_names_size
;
431 unsigned int dir_index
;
432 unsigned int mod_time
;
434 int included_p
; /* Non-zero if referenced by the Line Number Program. */
435 struct symtab
*symtab
; /* The associated symbol table, if any. */
438 /* The start and end of the statement program following this
439 header. These point into dwarf2_per_objfile->line_buffer. */
440 gdb_byte
*statement_program_start
, *statement_program_end
;
443 /* When we construct a partial symbol table entry we only
444 need this much information. */
445 struct partial_die_info
447 /* Offset of this DIE. */
450 /* DWARF-2 tag for this DIE. */
451 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
453 /* Language code associated with this DIE. This is only used
454 for the compilation unit DIE. */
455 unsigned int language
: 8;
457 /* Assorted flags describing the data found in this DIE. */
458 unsigned int has_children
: 1;
459 unsigned int is_external
: 1;
460 unsigned int is_declaration
: 1;
461 unsigned int has_type
: 1;
462 unsigned int has_specification
: 1;
463 unsigned int has_stmt_list
: 1;
464 unsigned int has_pc_info
: 1;
466 /* Flag set if the SCOPE field of this structure has been
468 unsigned int scope_set
: 1;
470 /* Flag set if the DIE has a byte_size attribute. */
471 unsigned int has_byte_size
: 1;
473 /* The name of this DIE. Normally the value of DW_AT_name, but
474 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
479 /* The scope to prepend to our children. This is generally
480 allocated on the comp_unit_obstack, so will disappear
481 when this compilation unit leaves the cache. */
484 /* The location description associated with this DIE, if any. */
485 struct dwarf_block
*locdesc
;
487 /* If HAS_PC_INFO, the PC range associated with this DIE. */
491 /* Pointer into the info_buffer pointing at the target of
492 DW_AT_sibling, if any. */
495 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
496 DW_AT_specification (or DW_AT_abstract_origin or
498 unsigned int spec_offset
;
500 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
501 unsigned int line_offset
;
503 /* Pointers to this DIE's parent, first child, and next sibling,
505 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
508 /* This data structure holds the information of an abbrev. */
511 unsigned int number
; /* number identifying abbrev */
512 enum dwarf_tag tag
; /* dwarf tag */
513 unsigned short has_children
; /* boolean */
514 unsigned short num_attrs
; /* number of attributes */
515 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
516 struct abbrev_info
*next
; /* next in chain */
521 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
522 ENUM_BITFIELD(dwarf_form
) form
: 16;
525 /* Attributes have a name and a value */
528 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
529 ENUM_BITFIELD(dwarf_form
) form
: 16;
533 struct dwarf_block
*blk
;
541 /* This data structure holds a complete die structure. */
544 /* DWARF-2 tag for this DIE. */
545 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
547 /* Number of attributes */
548 unsigned short num_attrs
;
553 /* Offset in .debug_info section */
556 /* The dies in a compilation unit form an n-ary tree. PARENT
557 points to this die's parent; CHILD points to the first child of
558 this node; and all the children of a given node are chained
559 together via their SIBLING fields, terminated by a die whose
561 struct die_info
*child
; /* Its first child, if any. */
562 struct die_info
*sibling
; /* Its next sibling, if any. */
563 struct die_info
*parent
; /* Its parent, if any. */
565 /* An array of attributes, with NUM_ATTRS elements. There may be
566 zero, but it's not common and zero-sized arrays are not
567 sufficiently portable C. */
568 struct attribute attrs
[1];
571 struct function_range
574 CORE_ADDR lowpc
, highpc
;
576 struct function_range
*next
;
579 /* Get at parts of an attribute structure */
581 #define DW_STRING(attr) ((attr)->u.str)
582 #define DW_UNSND(attr) ((attr)->u.unsnd)
583 #define DW_BLOCK(attr) ((attr)->u.blk)
584 #define DW_SND(attr) ((attr)->u.snd)
585 #define DW_ADDR(attr) ((attr)->u.addr)
587 /* Blocks are a bunch of untyped bytes. */
594 #ifndef ATTR_ALLOC_CHUNK
595 #define ATTR_ALLOC_CHUNK 4
598 /* Allocate fields for structs, unions and enums in this size. */
599 #ifndef DW_FIELD_ALLOC_CHUNK
600 #define DW_FIELD_ALLOC_CHUNK 4
603 /* A zeroed version of a partial die for initialization purposes. */
604 static struct partial_die_info zeroed_partial_die
;
606 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
607 but this would require a corresponding change in unpack_field_as_long
609 static int bits_per_byte
= 8;
611 /* The routines that read and process dies for a C struct or C++ class
612 pass lists of data member fields and lists of member function fields
613 in an instance of a field_info structure, as defined below. */
616 /* List of data member and baseclasses fields. */
619 struct nextfield
*next
;
626 /* Number of fields. */
629 /* Number of baseclasses. */
632 /* Set if the accesibility of one of the fields is not public. */
633 int non_public_fields
;
635 /* Member function fields array, entries are allocated in the order they
636 are encountered in the object file. */
639 struct nextfnfield
*next
;
640 struct fn_field fnfield
;
644 /* Member function fieldlist array, contains name of possibly overloaded
645 member function, number of overloaded member functions and a pointer
646 to the head of the member function field chain. */
651 struct nextfnfield
*head
;
655 /* Number of entries in the fnfieldlists array. */
659 /* One item on the queue of compilation units to read in full symbols
661 struct dwarf2_queue_item
663 struct dwarf2_per_cu_data
*per_cu
;
664 struct dwarf2_queue_item
*next
;
667 /* The current queue. */
668 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
670 /* Loaded secondary compilation units are kept in memory until they
671 have not been referenced for the processing of this many
672 compilation units. Set this to zero to disable caching. Cache
673 sizes of up to at least twenty will improve startup time for
674 typical inter-CU-reference binaries, at an obvious memory cost. */
675 static int dwarf2_max_cache_age
= 5;
677 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
678 struct cmd_list_element
*c
, const char *value
)
680 fprintf_filtered (file
, _("\
681 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
686 /* Various complaints about symbol reading that don't abort the process */
689 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
691 complaint (&symfile_complaints
,
692 _("statement list doesn't fit in .debug_line section"));
696 dwarf2_debug_line_missing_file_complaint (void)
698 complaint (&symfile_complaints
,
699 _(".debug_line section has line data without a file"));
703 dwarf2_complex_location_expr_complaint (void)
705 complaint (&symfile_complaints
, _("location expression too complex"));
709 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
712 complaint (&symfile_complaints
,
713 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
718 dwarf2_macros_too_long_complaint (void)
720 complaint (&symfile_complaints
,
721 _("macro info runs off end of `.debug_macinfo' section"));
725 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
727 complaint (&symfile_complaints
,
728 _("macro debug info contains a malformed macro definition:\n`%s'"),
733 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
735 complaint (&symfile_complaints
,
736 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
739 /* local function prototypes */
741 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
744 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
747 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
750 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
751 struct partial_die_info
*,
752 struct partial_symtab
*);
754 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
756 static void scan_partial_symbols (struct partial_die_info
*,
757 CORE_ADDR
*, CORE_ADDR
*,
760 static void add_partial_symbol (struct partial_die_info
*,
763 static int pdi_needs_namespace (enum dwarf_tag tag
);
765 static void add_partial_namespace (struct partial_die_info
*pdi
,
766 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
767 struct dwarf2_cu
*cu
);
769 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
770 struct dwarf2_cu
*cu
);
772 static void add_partial_subprogram (struct partial_die_info
*pdi
,
773 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
774 struct dwarf2_cu
*cu
);
776 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
779 struct dwarf2_cu
*cu
);
781 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
783 static void psymtab_to_symtab_1 (struct partial_symtab
*);
785 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
787 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
789 static void dwarf2_free_abbrev_table (void *);
791 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
794 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
797 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
800 static gdb_byte
*read_partial_die (struct partial_die_info
*,
801 struct abbrev_info
*abbrev
, unsigned int,
802 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
804 static struct partial_die_info
*find_partial_die (unsigned int,
807 static void fixup_partial_die (struct partial_die_info
*,
810 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
811 struct dwarf2_cu
*, int *);
813 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
814 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
816 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
817 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
819 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
821 static int read_1_signed_byte (bfd
*, gdb_byte
*);
823 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
825 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
827 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
829 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
832 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
834 static LONGEST read_checked_initial_length_and_offset
835 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
836 unsigned int *, unsigned int *);
838 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
841 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
843 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
845 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
847 static char *read_indirect_string (bfd
*, gdb_byte
*,
848 const struct comp_unit_head
*,
851 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
853 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
855 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
857 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
859 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
862 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
863 struct dwarf2_cu
*cu
);
865 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
867 static struct die_info
*die_specification (struct die_info
*die
,
868 struct dwarf2_cu
**);
870 static void free_line_header (struct line_header
*lh
);
872 static void add_file_name (struct line_header
*, char *, unsigned int,
873 unsigned int, unsigned int);
875 static struct line_header
*(dwarf_decode_line_header
876 (unsigned int offset
,
877 bfd
*abfd
, struct dwarf2_cu
*cu
));
879 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
880 struct dwarf2_cu
*, struct partial_symtab
*);
882 static void dwarf2_start_subfile (char *, char *, char *);
884 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
887 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
890 static void dwarf2_const_value_data (struct attribute
*attr
,
894 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
896 static struct type
*die_containing_type (struct die_info
*,
899 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
901 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
903 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
905 static char *typename_concat (struct obstack
*,
910 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
912 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
914 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
916 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
917 struct dwarf2_cu
*, struct partial_symtab
*);
919 static int dwarf2_get_pc_bounds (struct die_info
*,
920 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
922 static void get_scope_pc_bounds (struct die_info
*,
923 CORE_ADDR
*, CORE_ADDR
*,
926 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
927 CORE_ADDR
, struct dwarf2_cu
*);
929 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
932 static void dwarf2_attach_fields_to_type (struct field_info
*,
933 struct type
*, struct dwarf2_cu
*);
935 static void dwarf2_add_member_fn (struct field_info
*,
936 struct die_info
*, struct type
*,
939 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
940 struct type
*, struct dwarf2_cu
*);
942 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
944 static const char *determine_class_name (struct die_info
*die
,
945 struct dwarf2_cu
*cu
);
947 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
949 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
951 static const char *namespace_name (struct die_info
*die
,
952 int *is_anonymous
, struct dwarf2_cu
*);
954 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
956 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
958 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
961 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
963 static struct die_info
*read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
965 gdb_byte
**new_info_ptr
,
966 struct die_info
*parent
);
968 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
970 gdb_byte
**new_info_ptr
,
971 struct die_info
*parent
);
973 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
975 gdb_byte
**new_info_ptr
,
976 struct die_info
*parent
);
978 static void process_die (struct die_info
*, struct dwarf2_cu
*);
980 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
982 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
984 static struct die_info
*dwarf2_extension (struct die_info
*die
,
985 struct dwarf2_cu
**);
987 static char *dwarf_tag_name (unsigned int);
989 static char *dwarf_attr_name (unsigned int);
991 static char *dwarf_form_name (unsigned int);
993 static char *dwarf_stack_op_name (unsigned int);
995 static char *dwarf_bool_name (unsigned int);
997 static char *dwarf_type_encoding_name (unsigned int);
1000 static char *dwarf_cfi_name (unsigned int);
1003 static struct die_info
*sibling_die (struct die_info
*);
1005 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1007 static void dump_die_for_error (struct die_info
*);
1009 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1012 /*static*/ void dump_die (struct die_info
*, int max_level
);
1014 static void store_in_ref_table (struct die_info
*,
1015 struct dwarf2_cu
*);
1017 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1019 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1021 static struct die_info
*follow_die_ref (struct die_info
*,
1023 struct dwarf2_cu
**);
1025 /* memory allocation interface */
1027 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1029 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1031 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1033 static void initialize_cu_func_list (struct dwarf2_cu
*);
1035 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1036 struct dwarf2_cu
*);
1038 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1039 char *, bfd
*, struct dwarf2_cu
*);
1041 static int attr_form_is_block (struct attribute
*);
1043 static int attr_form_is_section_offset (struct attribute
*);
1045 static int attr_form_is_constant (struct attribute
*);
1047 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1049 struct dwarf2_cu
*cu
);
1051 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1052 struct dwarf2_cu
*cu
);
1054 static void free_stack_comp_unit (void *);
1056 static hashval_t
partial_die_hash (const void *item
);
1058 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1060 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1061 (unsigned int offset
, struct objfile
*objfile
);
1063 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1064 (unsigned int offset
, struct objfile
*objfile
);
1066 static void free_one_comp_unit (void *);
1068 static void free_cached_comp_units (void *);
1070 static void age_cached_comp_units (void);
1072 static void free_one_cached_comp_unit (void *);
1074 static struct type
*set_die_type (struct die_info
*, struct type
*,
1075 struct dwarf2_cu
*);
1077 static void create_all_comp_units (struct objfile
*);
1079 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1082 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1084 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1085 struct dwarf2_per_cu_data
*);
1087 static void dwarf2_mark (struct dwarf2_cu
*);
1089 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1091 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1093 /* Try to locate the sections we need for DWARF 2 debugging
1094 information and return true if we have enough to do something. */
1097 dwarf2_has_info (struct objfile
*objfile
)
1099 struct dwarf2_per_objfile
*data
;
1101 /* Initialize per-objfile state. */
1102 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1103 memset (data
, 0, sizeof (*data
));
1104 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1105 dwarf2_per_objfile
= data
;
1107 dwarf_info_section
= 0;
1108 dwarf_abbrev_section
= 0;
1109 dwarf_line_section
= 0;
1110 dwarf_str_section
= 0;
1111 dwarf_macinfo_section
= 0;
1112 dwarf_frame_section
= 0;
1113 dwarf_eh_frame_section
= 0;
1114 dwarf_ranges_section
= 0;
1115 dwarf_loc_section
= 0;
1117 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1118 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1121 /* When loading sections, we can either look for ".<name>", or for
1122 * ".z<name>", which indicates a compressed section. */
1125 section_is_p (asection
*sectp
, const char *name
)
1127 return ((sectp
->name
[0] == '.'
1128 && strcmp (sectp
->name
+ 1, name
) == 0)
1129 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1130 && strcmp (sectp
->name
+ 2, name
) == 0));
1133 /* This function is mapped across the sections and remembers the
1134 offset and size of each of the debugging sections we are interested
1138 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1140 if (section_is_p (sectp
, INFO_SECTION
))
1142 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1143 dwarf_info_section
= sectp
;
1145 else if (section_is_p (sectp
, ABBREV_SECTION
))
1147 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1148 dwarf_abbrev_section
= sectp
;
1150 else if (section_is_p (sectp
, LINE_SECTION
))
1152 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1153 dwarf_line_section
= sectp
;
1155 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1157 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1158 dwarf_pubnames_section
= sectp
;
1160 else if (section_is_p (sectp
, ARANGES_SECTION
))
1162 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1163 dwarf_aranges_section
= sectp
;
1165 else if (section_is_p (sectp
, LOC_SECTION
))
1167 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1168 dwarf_loc_section
= sectp
;
1170 else if (section_is_p (sectp
, MACINFO_SECTION
))
1172 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1173 dwarf_macinfo_section
= sectp
;
1175 else if (section_is_p (sectp
, STR_SECTION
))
1177 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1178 dwarf_str_section
= sectp
;
1180 else if (section_is_p (sectp
, FRAME_SECTION
))
1182 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1183 dwarf_frame_section
= sectp
;
1185 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1187 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1188 if (aflag
& SEC_HAS_CONTENTS
)
1190 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1191 dwarf_eh_frame_section
= sectp
;
1194 else if (section_is_p (sectp
, RANGES_SECTION
))
1196 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1197 dwarf_ranges_section
= sectp
;
1200 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1201 && bfd_section_vma (abfd
, sectp
) == 0)
1202 dwarf2_per_objfile
->has_section_at_zero
= 1;
1205 /* This function is called after decompressing a section, so
1206 dwarf2_per_objfile can record its new, uncompressed size. */
1209 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1211 if (section_is_p (sectp
, INFO_SECTION
))
1212 dwarf2_per_objfile
->info_size
= new_size
;
1213 else if (section_is_p (sectp
, ABBREV_SECTION
))
1214 dwarf2_per_objfile
->abbrev_size
= new_size
;
1215 else if (section_is_p (sectp
, LINE_SECTION
))
1216 dwarf2_per_objfile
->line_size
= new_size
;
1217 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1218 dwarf2_per_objfile
->pubnames_size
= new_size
;
1219 else if (section_is_p (sectp
, ARANGES_SECTION
))
1220 dwarf2_per_objfile
->aranges_size
= new_size
;
1221 else if (section_is_p (sectp
, LOC_SECTION
))
1222 dwarf2_per_objfile
->loc_size
= new_size
;
1223 else if (section_is_p (sectp
, MACINFO_SECTION
))
1224 dwarf2_per_objfile
->macinfo_size
= new_size
;
1225 else if (section_is_p (sectp
, STR_SECTION
))
1226 dwarf2_per_objfile
->str_size
= new_size
;
1227 else if (section_is_p (sectp
, FRAME_SECTION
))
1228 dwarf2_per_objfile
->frame_size
= new_size
;
1229 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1230 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1231 else if (section_is_p (sectp
, RANGES_SECTION
))
1232 dwarf2_per_objfile
->ranges_size
= new_size
;
1234 internal_error (__FILE__
, __LINE__
,
1235 _("dwarf2_resize_section: missing section_is_p check: %s"),
1239 /* Build a partial symbol table. */
1242 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1244 /* We definitely need the .debug_info and .debug_abbrev sections */
1246 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1247 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1249 if (dwarf_line_section
)
1250 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1252 dwarf2_per_objfile
->line_buffer
= NULL
;
1254 if (dwarf_str_section
)
1255 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1257 dwarf2_per_objfile
->str_buffer
= NULL
;
1259 if (dwarf_macinfo_section
)
1260 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1261 dwarf_macinfo_section
);
1263 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1265 if (dwarf_ranges_section
)
1266 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1268 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1270 if (dwarf_loc_section
)
1271 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1273 dwarf2_per_objfile
->loc_buffer
= NULL
;
1276 || (objfile
->global_psymbols
.size
== 0
1277 && objfile
->static_psymbols
.size
== 0))
1279 init_psymbol_list (objfile
, 1024);
1283 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1285 /* Things are significantly easier if we have .debug_aranges and
1286 .debug_pubnames sections */
1288 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1292 /* only test this case for now */
1294 /* In this case we have to work a bit harder */
1295 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1300 /* Build the partial symbol table from the information in the
1301 .debug_pubnames and .debug_aranges sections. */
1304 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1306 bfd
*abfd
= objfile
->obfd
;
1307 char *aranges_buffer
, *pubnames_buffer
;
1308 char *aranges_ptr
, *pubnames_ptr
;
1309 unsigned int entry_length
, version
, info_offset
, info_size
;
1311 pubnames_buffer
= dwarf2_read_section (objfile
,
1312 dwarf_pubnames_section
);
1313 pubnames_ptr
= pubnames_buffer
;
1314 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1316 unsigned int bytes_read
;
1318 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1319 pubnames_ptr
+= bytes_read
;
1320 version
= read_1_byte (abfd
, pubnames_ptr
);
1322 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1324 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1328 aranges_buffer
= dwarf2_read_section (objfile
,
1329 dwarf_aranges_section
);
1334 /* Return TRUE if OFFSET is within CU_HEADER. */
1337 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1339 unsigned int bottom
= cu_header
->offset
;
1340 unsigned int top
= (cu_header
->offset
1342 + cu_header
->initial_length_size
);
1343 return (offset
>= bottom
&& offset
< top
);
1346 /* Read in the comp unit header information from the debug_info at
1350 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1351 gdb_byte
*info_ptr
, bfd
*abfd
)
1354 unsigned int bytes_read
;
1356 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1357 cu_header
->initial_length_size
= bytes_read
;
1358 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1359 info_ptr
+= bytes_read
;
1360 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1362 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1364 info_ptr
+= bytes_read
;
1365 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1367 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1368 if (signed_addr
< 0)
1369 internal_error (__FILE__
, __LINE__
,
1370 _("read_comp_unit_head: dwarf from non elf file"));
1371 cu_header
->signed_addr_p
= signed_addr
;
1377 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1380 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1382 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1384 if (header
->version
!= 2 && header
->version
!= 3)
1385 error (_("Dwarf Error: wrong version in compilation unit header "
1386 "(is %d, should be %d) [in module %s]"), header
->version
,
1387 2, bfd_get_filename (abfd
));
1389 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1390 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1391 "(offset 0x%lx + 6) [in module %s]"),
1392 (long) header
->abbrev_offset
,
1393 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1394 bfd_get_filename (abfd
));
1396 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1397 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1398 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1399 "(offset 0x%lx + 0) [in module %s]"),
1400 (long) header
->length
,
1401 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1402 bfd_get_filename (abfd
));
1407 /* Allocate a new partial symtab for file named NAME and mark this new
1408 partial symtab as being an include of PST. */
1411 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1412 struct objfile
*objfile
)
1414 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1416 subpst
->section_offsets
= pst
->section_offsets
;
1417 subpst
->textlow
= 0;
1418 subpst
->texthigh
= 0;
1420 subpst
->dependencies
= (struct partial_symtab
**)
1421 obstack_alloc (&objfile
->objfile_obstack
,
1422 sizeof (struct partial_symtab
*));
1423 subpst
->dependencies
[0] = pst
;
1424 subpst
->number_of_dependencies
= 1;
1426 subpst
->globals_offset
= 0;
1427 subpst
->n_global_syms
= 0;
1428 subpst
->statics_offset
= 0;
1429 subpst
->n_static_syms
= 0;
1430 subpst
->symtab
= NULL
;
1431 subpst
->read_symtab
= pst
->read_symtab
;
1434 /* No private part is necessary for include psymtabs. This property
1435 can be used to differentiate between such include psymtabs and
1436 the regular ones. */
1437 subpst
->read_symtab_private
= NULL
;
1440 /* Read the Line Number Program data and extract the list of files
1441 included by the source file represented by PST. Build an include
1442 partial symtab for each of these included files.
1444 This procedure assumes that there *is* a Line Number Program in
1445 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1446 before calling this procedure. */
1449 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1450 struct partial_die_info
*pdi
,
1451 struct partial_symtab
*pst
)
1453 struct objfile
*objfile
= cu
->objfile
;
1454 bfd
*abfd
= objfile
->obfd
;
1455 struct line_header
*lh
;
1457 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1459 return; /* No linetable, so no includes. */
1461 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1463 free_line_header (lh
);
1467 /* Build the partial symbol table by doing a quick pass through the
1468 .debug_info and .debug_abbrev sections. */
1471 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1473 /* Instead of reading this into a big buffer, we should probably use
1474 mmap() on architectures that support it. (FIXME) */
1475 bfd
*abfd
= objfile
->obfd
;
1477 gdb_byte
*beg_of_comp_unit
;
1478 struct partial_die_info comp_unit_die
;
1479 struct partial_symtab
*pst
;
1480 struct cleanup
*back_to
;
1481 CORE_ADDR lowpc
, highpc
, baseaddr
;
1483 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1485 /* Any cached compilation units will be linked by the per-objfile
1486 read_in_chain. Make sure to free them when we're done. */
1487 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1489 create_all_comp_units (objfile
);
1491 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1492 (&objfile
->objfile_obstack
);
1494 /* Since the objects we're extracting from .debug_info vary in
1495 length, only the individual functions to extract them (like
1496 read_comp_unit_head and load_partial_die) can really know whether
1497 the buffer is large enough to hold another complete object.
1499 At the moment, they don't actually check that. If .debug_info
1500 holds just one extra byte after the last compilation unit's dies,
1501 then read_comp_unit_head will happily read off the end of the
1502 buffer. read_partial_die is similarly casual. Those functions
1505 For this loop condition, simply checking whether there's any data
1506 left at all should be sufficient. */
1507 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1508 + dwarf2_per_objfile
->info_size
))
1510 struct cleanup
*back_to_inner
;
1511 struct dwarf2_cu cu
;
1512 struct abbrev_info
*abbrev
;
1513 unsigned int bytes_read
;
1514 struct dwarf2_per_cu_data
*this_cu
;
1516 beg_of_comp_unit
= info_ptr
;
1518 memset (&cu
, 0, sizeof (cu
));
1520 obstack_init (&cu
.comp_unit_obstack
);
1522 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1524 cu
.objfile
= objfile
;
1525 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1527 /* Complete the cu_header */
1528 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1529 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1531 cu
.list_in_scope
= &file_symbols
;
1533 /* Read the abbrevs for this compilation unit into a table */
1534 dwarf2_read_abbrevs (abfd
, &cu
);
1535 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1537 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1539 /* Read the compilation unit die */
1540 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1541 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1542 abfd
, info_ptr
, &cu
);
1544 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1546 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1547 + cu
.header
.initial_length_size
);
1548 do_cleanups (back_to_inner
);
1552 /* Set the language we're debugging */
1553 set_cu_language (comp_unit_die
.language
, &cu
);
1555 /* Allocate a new partial symbol table structure */
1556 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1557 comp_unit_die
.name
? comp_unit_die
.name
: "",
1558 /* TEXTLOW and TEXTHIGH are set below. */
1560 objfile
->global_psymbols
.next
,
1561 objfile
->static_psymbols
.next
);
1563 if (comp_unit_die
.dirname
)
1564 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1565 strlen (comp_unit_die
.dirname
),
1566 &objfile
->objfile_obstack
);
1568 pst
->read_symtab_private
= (char *) this_cu
;
1570 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1572 /* Store the function that reads in the rest of the symbol table */
1573 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1575 /* If this compilation unit was already read in, free the
1576 cached copy in order to read it in again. This is
1577 necessary because we skipped some symbols when we first
1578 read in the compilation unit (see load_partial_dies).
1579 This problem could be avoided, but the benefit is
1581 if (this_cu
->cu
!= NULL
)
1582 free_one_cached_comp_unit (this_cu
->cu
);
1584 cu
.per_cu
= this_cu
;
1586 /* Note that this is a pointer to our stack frame, being
1587 added to a global data structure. It will be cleaned up
1588 in free_stack_comp_unit when we finish with this
1589 compilation unit. */
1592 this_cu
->psymtab
= pst
;
1594 /* Possibly set the default values of LOWPC and HIGHPC from
1596 if (cu
.has_ranges_offset
)
1598 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1599 &comp_unit_die
.highpc
, &cu
, pst
))
1600 comp_unit_die
.has_pc_info
= 1;
1603 /* Check if comp unit has_children.
1604 If so, read the rest of the partial symbols from this comp unit.
1605 If not, there's no more debug_info for this comp unit. */
1606 if (comp_unit_die
.has_children
)
1608 struct partial_die_info
*first_die
;
1610 lowpc
= ((CORE_ADDR
) -1);
1611 highpc
= ((CORE_ADDR
) 0);
1613 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1615 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1617 /* If we didn't find a lowpc, set it to highpc to avoid
1618 complaints from `maint check'. */
1619 if (lowpc
== ((CORE_ADDR
) -1))
1622 /* If the compilation unit didn't have an explicit address range,
1623 then use the information extracted from its child dies. */
1624 if (! comp_unit_die
.has_pc_info
)
1626 comp_unit_die
.lowpc
= lowpc
;
1627 comp_unit_die
.highpc
= highpc
;
1630 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1631 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1633 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1634 range can be also empty for CUs with no code. */
1635 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1636 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1637 pst
->texthigh
- 1, pst
);
1639 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1640 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1641 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1642 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1643 sort_pst_symbols (pst
);
1645 /* If there is already a psymtab or symtab for a file of this
1646 name, remove it. (If there is a symtab, more drastic things
1647 also happen.) This happens in VxWorks. */
1648 free_named_symtabs (pst
->filename
);
1650 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1651 + cu
.header
.initial_length_size
;
1653 if (comp_unit_die
.has_stmt_list
)
1655 /* Get the list of files included in the current compilation unit,
1656 and build a psymtab for each of them. */
1657 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1660 do_cleanups (back_to_inner
);
1663 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1664 &objfile
->objfile_obstack
);
1666 do_cleanups (back_to
);
1669 /* Load the DIEs for a secondary CU into memory. */
1672 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1674 bfd
*abfd
= objfile
->obfd
;
1675 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1676 struct partial_die_info comp_unit_die
;
1677 struct dwarf2_cu
*cu
;
1678 struct abbrev_info
*abbrev
;
1679 unsigned int bytes_read
;
1680 struct cleanup
*back_to
;
1682 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1683 beg_of_comp_unit
= info_ptr
;
1685 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1686 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1688 obstack_init (&cu
->comp_unit_obstack
);
1690 cu
->objfile
= objfile
;
1691 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1693 /* Complete the cu_header. */
1694 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1695 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1697 /* Read the abbrevs for this compilation unit into a table. */
1698 dwarf2_read_abbrevs (abfd
, cu
);
1699 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1701 /* Read the compilation unit die. */
1702 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1703 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1704 abfd
, info_ptr
, cu
);
1706 /* Set the language we're debugging. */
1707 set_cu_language (comp_unit_die
.language
, cu
);
1709 /* Link this compilation unit into the compilation unit tree. */
1711 cu
->per_cu
= this_cu
;
1712 cu
->type_hash
= cu
->per_cu
->type_hash
;
1714 /* Check if comp unit has_children.
1715 If so, read the rest of the partial symbols from this comp unit.
1716 If not, there's no more debug_info for this comp unit. */
1717 if (comp_unit_die
.has_children
)
1718 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1720 do_cleanups (back_to
);
1723 /* Create a list of all compilation units in OBJFILE. We do this only
1724 if an inter-comp-unit reference is found; presumably if there is one,
1725 there will be many, and one will occur early in the .debug_info section.
1726 So there's no point in building this list incrementally. */
1729 create_all_comp_units (struct objfile
*objfile
)
1733 struct dwarf2_per_cu_data
**all_comp_units
;
1734 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1738 all_comp_units
= xmalloc (n_allocated
1739 * sizeof (struct dwarf2_per_cu_data
*));
1741 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1743 unsigned int length
, initial_length_size
;
1744 gdb_byte
*beg_of_comp_unit
;
1745 struct dwarf2_per_cu_data
*this_cu
;
1746 unsigned int offset
;
1748 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1750 /* Read just enough information to find out where the next
1751 compilation unit is. */
1752 length
= read_initial_length (objfile
->obfd
, info_ptr
,
1753 &initial_length_size
);
1755 /* Save the compilation unit for later lookup. */
1756 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1757 sizeof (struct dwarf2_per_cu_data
));
1758 memset (this_cu
, 0, sizeof (*this_cu
));
1759 this_cu
->offset
= offset
;
1760 this_cu
->length
= length
+ initial_length_size
;
1762 if (n_comp_units
== n_allocated
)
1765 all_comp_units
= xrealloc (all_comp_units
,
1767 * sizeof (struct dwarf2_per_cu_data
*));
1769 all_comp_units
[n_comp_units
++] = this_cu
;
1771 info_ptr
= info_ptr
+ this_cu
->length
;
1774 dwarf2_per_objfile
->all_comp_units
1775 = obstack_alloc (&objfile
->objfile_obstack
,
1776 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1777 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1778 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1779 xfree (all_comp_units
);
1780 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1783 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1784 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1788 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1789 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1791 struct objfile
*objfile
= cu
->objfile
;
1792 bfd
*abfd
= objfile
->obfd
;
1793 struct partial_die_info
*pdi
;
1795 /* Now, march along the PDI's, descending into ones which have
1796 interesting children but skipping the children of the other ones,
1797 until we reach the end of the compilation unit. */
1803 fixup_partial_die (pdi
, cu
);
1805 /* Anonymous namespaces have no name but have interesting
1806 children, so we need to look at them. Ditto for anonymous
1809 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1810 || pdi
->tag
== DW_TAG_enumeration_type
)
1814 case DW_TAG_subprogram
:
1815 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
1817 case DW_TAG_variable
:
1818 case DW_TAG_typedef
:
1819 case DW_TAG_union_type
:
1820 if (!pdi
->is_declaration
)
1822 add_partial_symbol (pdi
, cu
);
1825 case DW_TAG_class_type
:
1826 case DW_TAG_interface_type
:
1827 case DW_TAG_structure_type
:
1828 if (!pdi
->is_declaration
)
1830 add_partial_symbol (pdi
, cu
);
1833 case DW_TAG_enumeration_type
:
1834 if (!pdi
->is_declaration
)
1835 add_partial_enumeration (pdi
, cu
);
1837 case DW_TAG_base_type
:
1838 case DW_TAG_subrange_type
:
1839 /* File scope base type definitions are added to the partial
1841 add_partial_symbol (pdi
, cu
);
1843 case DW_TAG_namespace
:
1844 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1851 /* If the die has a sibling, skip to the sibling. */
1853 pdi
= pdi
->die_sibling
;
1857 /* Functions used to compute the fully scoped name of a partial DIE.
1859 Normally, this is simple. For C++, the parent DIE's fully scoped
1860 name is concatenated with "::" and the partial DIE's name. For
1861 Java, the same thing occurs except that "." is used instead of "::".
1862 Enumerators are an exception; they use the scope of their parent
1863 enumeration type, i.e. the name of the enumeration type is not
1864 prepended to the enumerator.
1866 There are two complexities. One is DW_AT_specification; in this
1867 case "parent" means the parent of the target of the specification,
1868 instead of the direct parent of the DIE. The other is compilers
1869 which do not emit DW_TAG_namespace; in this case we try to guess
1870 the fully qualified name of structure types from their members'
1871 linkage names. This must be done using the DIE's children rather
1872 than the children of any DW_AT_specification target. We only need
1873 to do this for structures at the top level, i.e. if the target of
1874 any DW_AT_specification (if any; otherwise the DIE itself) does not
1877 /* Compute the scope prefix associated with PDI's parent, in
1878 compilation unit CU. The result will be allocated on CU's
1879 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1880 field. NULL is returned if no prefix is necessary. */
1882 partial_die_parent_scope (struct partial_die_info
*pdi
,
1883 struct dwarf2_cu
*cu
)
1885 char *grandparent_scope
;
1886 struct partial_die_info
*parent
, *real_pdi
;
1888 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1889 then this means the parent of the specification DIE. */
1892 while (real_pdi
->has_specification
)
1893 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1895 parent
= real_pdi
->die_parent
;
1899 if (parent
->scope_set
)
1900 return parent
->scope
;
1902 fixup_partial_die (parent
, cu
);
1904 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1906 if (parent
->tag
== DW_TAG_namespace
1907 || parent
->tag
== DW_TAG_structure_type
1908 || parent
->tag
== DW_TAG_class_type
1909 || parent
->tag
== DW_TAG_interface_type
1910 || parent
->tag
== DW_TAG_union_type
)
1912 if (grandparent_scope
== NULL
)
1913 parent
->scope
= parent
->name
;
1915 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1918 else if (parent
->tag
== DW_TAG_enumeration_type
)
1919 /* Enumerators should not get the name of the enumeration as a prefix. */
1920 parent
->scope
= grandparent_scope
;
1923 /* FIXME drow/2004-04-01: What should we be doing with
1924 function-local names? For partial symbols, we should probably be
1926 complaint (&symfile_complaints
,
1927 _("unhandled containing DIE tag %d for DIE at %d"),
1928 parent
->tag
, pdi
->offset
);
1929 parent
->scope
= grandparent_scope
;
1932 parent
->scope_set
= 1;
1933 return parent
->scope
;
1936 /* Return the fully scoped name associated with PDI, from compilation unit
1937 CU. The result will be allocated with malloc. */
1939 partial_die_full_name (struct partial_die_info
*pdi
,
1940 struct dwarf2_cu
*cu
)
1944 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1945 if (parent_scope
== NULL
)
1948 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1952 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1954 struct objfile
*objfile
= cu
->objfile
;
1956 char *actual_name
= NULL
;
1957 const char *my_prefix
;
1958 const struct partial_symbol
*psym
= NULL
;
1960 int built_actual_name
= 0;
1962 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1964 if (pdi_needs_namespace (pdi
->tag
))
1966 actual_name
= partial_die_full_name (pdi
, cu
);
1968 built_actual_name
= 1;
1971 if (actual_name
== NULL
)
1972 actual_name
= pdi
->name
;
1976 case DW_TAG_subprogram
:
1977 if (pdi
->is_external
|| cu
->language
== language_ada
)
1979 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1980 of the global scope. But in Ada, we want to be able to access
1981 nested procedures globally. So all Ada subprograms are stored
1982 in the global scope. */
1983 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1984 mst_text, objfile); */
1985 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1986 VAR_DOMAIN
, LOC_BLOCK
,
1987 &objfile
->global_psymbols
,
1988 0, pdi
->lowpc
+ baseaddr
,
1989 cu
->language
, objfile
);
1993 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1994 mst_file_text, objfile); */
1995 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1996 VAR_DOMAIN
, LOC_BLOCK
,
1997 &objfile
->static_psymbols
,
1998 0, pdi
->lowpc
+ baseaddr
,
1999 cu
->language
, objfile
);
2002 case DW_TAG_variable
:
2003 if (pdi
->is_external
)
2006 Don't enter into the minimal symbol tables as there is
2007 a minimal symbol table entry from the ELF symbols already.
2008 Enter into partial symbol table if it has a location
2009 descriptor or a type.
2010 If the location descriptor is missing, new_symbol will create
2011 a LOC_UNRESOLVED symbol, the address of the variable will then
2012 be determined from the minimal symbol table whenever the variable
2014 The address for the partial symbol table entry is not
2015 used by GDB, but it comes in handy for debugging partial symbol
2019 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2020 if (pdi
->locdesc
|| pdi
->has_type
)
2021 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2022 VAR_DOMAIN
, LOC_STATIC
,
2023 &objfile
->global_psymbols
,
2025 cu
->language
, objfile
);
2029 /* Static Variable. Skip symbols without location descriptors. */
2030 if (pdi
->locdesc
== NULL
)
2032 if (built_actual_name
)
2033 xfree (actual_name
);
2036 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2037 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2038 mst_file_data, objfile); */
2039 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2040 VAR_DOMAIN
, LOC_STATIC
,
2041 &objfile
->static_psymbols
,
2043 cu
->language
, objfile
);
2046 case DW_TAG_typedef
:
2047 case DW_TAG_base_type
:
2048 case DW_TAG_subrange_type
:
2049 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2050 VAR_DOMAIN
, LOC_TYPEDEF
,
2051 &objfile
->static_psymbols
,
2052 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2054 case DW_TAG_namespace
:
2055 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2056 VAR_DOMAIN
, LOC_TYPEDEF
,
2057 &objfile
->global_psymbols
,
2058 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2060 case DW_TAG_class_type
:
2061 case DW_TAG_interface_type
:
2062 case DW_TAG_structure_type
:
2063 case DW_TAG_union_type
:
2064 case DW_TAG_enumeration_type
:
2065 /* Skip external references. The DWARF standard says in the section
2066 about "Structure, Union, and Class Type Entries": "An incomplete
2067 structure, union or class type is represented by a structure,
2068 union or class entry that does not have a byte size attribute
2069 and that has a DW_AT_declaration attribute." */
2070 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2072 if (built_actual_name
)
2073 xfree (actual_name
);
2077 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2078 static vs. global. */
2079 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2080 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2081 (cu
->language
== language_cplus
2082 || cu
->language
== language_java
)
2083 ? &objfile
->global_psymbols
2084 : &objfile
->static_psymbols
,
2085 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2088 case DW_TAG_enumerator
:
2089 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2090 VAR_DOMAIN
, LOC_CONST
,
2091 (cu
->language
== language_cplus
2092 || cu
->language
== language_java
)
2093 ? &objfile
->global_psymbols
2094 : &objfile
->static_psymbols
,
2095 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2101 /* Check to see if we should scan the name for possible namespace
2102 info. Only do this if this is C++, if we don't have namespace
2103 debugging info in the file, if the psym is of an appropriate type
2104 (otherwise we'll have psym == NULL), and if we actually had a
2105 mangled name to begin with. */
2107 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2108 cases which do not set PSYM above? */
2110 if (cu
->language
== language_cplus
2111 && cu
->has_namespace_info
== 0
2113 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2114 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2117 if (built_actual_name
)
2118 xfree (actual_name
);
2121 /* Determine whether a die of type TAG living in a C++ class or
2122 namespace needs to have the name of the scope prepended to the
2123 name listed in the die. */
2126 pdi_needs_namespace (enum dwarf_tag tag
)
2130 case DW_TAG_namespace
:
2131 case DW_TAG_typedef
:
2132 case DW_TAG_class_type
:
2133 case DW_TAG_interface_type
:
2134 case DW_TAG_structure_type
:
2135 case DW_TAG_union_type
:
2136 case DW_TAG_enumeration_type
:
2137 case DW_TAG_enumerator
:
2144 /* Read a partial die corresponding to a namespace; also, add a symbol
2145 corresponding to that namespace to the symbol table. NAMESPACE is
2146 the name of the enclosing namespace. */
2149 add_partial_namespace (struct partial_die_info
*pdi
,
2150 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2151 struct dwarf2_cu
*cu
)
2153 struct objfile
*objfile
= cu
->objfile
;
2155 /* Add a symbol for the namespace. */
2157 add_partial_symbol (pdi
, cu
);
2159 /* Now scan partial symbols in that namespace. */
2161 if (pdi
->has_children
)
2162 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2165 /* Read a partial die corresponding to a subprogram and create a partial
2166 symbol for that subprogram. When the CU language allows it, this
2167 routine also defines a partial symbol for each nested subprogram
2168 that this subprogram contains.
2170 DIE my also be a lexical block, in which case we simply search
2171 recursively for suprograms defined inside that lexical block.
2172 Again, this is only performed when the CU language allows this
2173 type of definitions. */
2176 add_partial_subprogram (struct partial_die_info
*pdi
,
2177 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2178 struct dwarf2_cu
*cu
)
2180 if (pdi
->tag
== DW_TAG_subprogram
)
2182 if (pdi
->has_pc_info
)
2184 if (pdi
->lowpc
< *lowpc
)
2185 *lowpc
= pdi
->lowpc
;
2186 if (pdi
->highpc
> *highpc
)
2187 *highpc
= pdi
->highpc
;
2188 if (!pdi
->is_declaration
)
2189 add_partial_symbol (pdi
, cu
);
2193 if (! pdi
->has_children
)
2196 if (cu
->language
== language_ada
)
2198 pdi
= pdi
->die_child
;
2201 fixup_partial_die (pdi
, cu
);
2202 if (pdi
->tag
== DW_TAG_subprogram
2203 || pdi
->tag
== DW_TAG_lexical_block
)
2204 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
2205 pdi
= pdi
->die_sibling
;
2210 /* See if we can figure out if the class lives in a namespace. We do
2211 this by looking for a member function; its demangled name will
2212 contain namespace info, if there is any. */
2215 guess_structure_name (struct partial_die_info
*struct_pdi
,
2216 struct dwarf2_cu
*cu
)
2218 if ((cu
->language
== language_cplus
2219 || cu
->language
== language_java
)
2220 && cu
->has_namespace_info
== 0
2221 && struct_pdi
->has_children
)
2223 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2224 what template types look like, because the demangler
2225 frequently doesn't give the same name as the debug info. We
2226 could fix this by only using the demangled name to get the
2227 prefix (but see comment in read_structure_type). */
2229 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2230 struct partial_die_info
*real_pdi
;
2232 /* If this DIE (this DIE's specification, if any) has a parent, then
2233 we should not do this. We'll prepend the parent's fully qualified
2234 name when we create the partial symbol. */
2236 real_pdi
= struct_pdi
;
2237 while (real_pdi
->has_specification
)
2238 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2240 if (real_pdi
->die_parent
!= NULL
)
2243 while (child_pdi
!= NULL
)
2245 if (child_pdi
->tag
== DW_TAG_subprogram
)
2247 char *actual_class_name
2248 = language_class_name_from_physname (cu
->language_defn
,
2250 if (actual_class_name
!= NULL
)
2253 = obsavestring (actual_class_name
,
2254 strlen (actual_class_name
),
2255 &cu
->comp_unit_obstack
);
2256 xfree (actual_class_name
);
2261 child_pdi
= child_pdi
->die_sibling
;
2266 /* Read a partial die corresponding to an enumeration type. */
2269 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2270 struct dwarf2_cu
*cu
)
2272 struct objfile
*objfile
= cu
->objfile
;
2273 bfd
*abfd
= objfile
->obfd
;
2274 struct partial_die_info
*pdi
;
2276 if (enum_pdi
->name
!= NULL
)
2277 add_partial_symbol (enum_pdi
, cu
);
2279 pdi
= enum_pdi
->die_child
;
2282 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2283 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2285 add_partial_symbol (pdi
, cu
);
2286 pdi
= pdi
->die_sibling
;
2290 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2291 Return the corresponding abbrev, or NULL if the number is zero (indicating
2292 an empty DIE). In either case *BYTES_READ will be set to the length of
2293 the initial number. */
2295 static struct abbrev_info
*
2296 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2297 struct dwarf2_cu
*cu
)
2299 bfd
*abfd
= cu
->objfile
->obfd
;
2300 unsigned int abbrev_number
;
2301 struct abbrev_info
*abbrev
;
2303 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2305 if (abbrev_number
== 0)
2308 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2311 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2312 bfd_get_filename (abfd
));
2318 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2319 pointer to the end of a series of DIEs, terminated by an empty
2320 DIE. Any children of the skipped DIEs will also be skipped. */
2323 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2325 struct abbrev_info
*abbrev
;
2326 unsigned int bytes_read
;
2330 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2332 return info_ptr
+ bytes_read
;
2334 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2338 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2339 should point just after the initial uleb128 of a DIE, and the
2340 abbrev corresponding to that skipped uleb128 should be passed in
2341 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2345 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2346 struct dwarf2_cu
*cu
)
2348 unsigned int bytes_read
;
2349 struct attribute attr
;
2350 bfd
*abfd
= cu
->objfile
->obfd
;
2351 unsigned int form
, i
;
2353 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2355 /* The only abbrev we care about is DW_AT_sibling. */
2356 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2358 read_attribute (&attr
, &abbrev
->attrs
[i
],
2359 abfd
, info_ptr
, cu
);
2360 if (attr
.form
== DW_FORM_ref_addr
)
2361 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2363 return dwarf2_per_objfile
->info_buffer
2364 + dwarf2_get_ref_die_offset (&attr
);
2367 /* If it isn't DW_AT_sibling, skip this attribute. */
2368 form
= abbrev
->attrs
[i
].form
;
2373 case DW_FORM_ref_addr
:
2374 info_ptr
+= cu
->header
.addr_size
;
2393 case DW_FORM_string
:
2394 read_string (abfd
, info_ptr
, &bytes_read
);
2395 info_ptr
+= bytes_read
;
2398 info_ptr
+= cu
->header
.offset_size
;
2401 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2402 info_ptr
+= bytes_read
;
2404 case DW_FORM_block1
:
2405 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2407 case DW_FORM_block2
:
2408 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2410 case DW_FORM_block4
:
2411 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2415 case DW_FORM_ref_udata
:
2416 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2418 case DW_FORM_indirect
:
2419 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2420 info_ptr
+= bytes_read
;
2421 /* We need to continue parsing from here, so just go back to
2423 goto skip_attribute
;
2426 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2427 dwarf_form_name (form
),
2428 bfd_get_filename (abfd
));
2432 if (abbrev
->has_children
)
2433 return skip_children (info_ptr
, cu
);
2438 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2439 the next DIE after ORIG_PDI. */
2442 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2443 bfd
*abfd
, struct dwarf2_cu
*cu
)
2445 /* Do we know the sibling already? */
2447 if (orig_pdi
->sibling
)
2448 return orig_pdi
->sibling
;
2450 /* Are there any children to deal with? */
2452 if (!orig_pdi
->has_children
)
2455 /* Skip the children the long way. */
2457 return skip_children (info_ptr
, cu
);
2460 /* Expand this partial symbol table into a full symbol table. */
2463 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2465 /* FIXME: This is barely more than a stub. */
2470 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2476 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2477 gdb_flush (gdb_stdout
);
2480 /* Restore our global data. */
2481 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2482 dwarf2_objfile_data_key
);
2484 psymtab_to_symtab_1 (pst
);
2486 /* Finish up the debug error message. */
2488 printf_filtered (_("done.\n"));
2493 /* Add PER_CU to the queue. */
2496 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2498 struct dwarf2_queue_item
*item
;
2501 item
= xmalloc (sizeof (*item
));
2502 item
->per_cu
= per_cu
;
2505 if (dwarf2_queue
== NULL
)
2506 dwarf2_queue
= item
;
2508 dwarf2_queue_tail
->next
= item
;
2510 dwarf2_queue_tail
= item
;
2512 /* Either PER_CU is the CU we want to process, or we're following a reference
2513 pointing into PER_CU. Either way, we need its DIEs now. */
2514 load_full_comp_unit (item
->per_cu
, objfile
);
2515 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2516 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2519 /* Process the queue. */
2522 process_queue (struct objfile
*objfile
)
2524 struct dwarf2_queue_item
*item
, *next_item
;
2526 /* The queue starts out with one item, but following a DIE reference
2527 may load a new CU, adding it to the end of the queue. */
2528 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2530 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2531 process_full_comp_unit (item
->per_cu
);
2533 item
->per_cu
->queued
= 0;
2534 next_item
= item
->next
;
2538 dwarf2_queue_tail
= NULL
;
2541 /* Free all allocated queue entries. This function only releases anything if
2542 an error was thrown; if the queue was processed then it would have been
2543 freed as we went along. */
2546 dwarf2_release_queue (void *dummy
)
2548 struct dwarf2_queue_item
*item
, *last
;
2550 item
= dwarf2_queue
;
2553 /* Anything still marked queued is likely to be in an
2554 inconsistent state, so discard it. */
2555 if (item
->per_cu
->queued
)
2557 if (item
->per_cu
->cu
!= NULL
)
2558 free_one_cached_comp_unit (item
->per_cu
->cu
);
2559 item
->per_cu
->queued
= 0;
2567 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2570 /* Read in full symbols for PST, and anything it depends on. */
2573 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2575 struct dwarf2_per_cu_data
*per_cu
;
2576 struct cleanup
*back_to
;
2579 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2580 if (!pst
->dependencies
[i
]->readin
)
2582 /* Inform about additional files that need to be read in. */
2585 /* FIXME: i18n: Need to make this a single string. */
2586 fputs_filtered (" ", gdb_stdout
);
2588 fputs_filtered ("and ", gdb_stdout
);
2590 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2591 wrap_here (""); /* Flush output */
2592 gdb_flush (gdb_stdout
);
2594 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2597 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2601 /* It's an include file, no symbols to read for it.
2602 Everything is in the parent symtab. */
2607 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2609 queue_comp_unit (per_cu
, pst
->objfile
);
2611 process_queue (pst
->objfile
);
2613 /* Age the cache, releasing compilation units that have not
2614 been used recently. */
2615 age_cached_comp_units ();
2617 do_cleanups (back_to
);
2620 /* Load the DIEs associated with PST and PER_CU into memory. */
2622 static struct dwarf2_cu
*
2623 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2625 bfd
*abfd
= objfile
->obfd
;
2626 struct dwarf2_cu
*cu
;
2627 unsigned int offset
;
2629 struct cleanup
*back_to
, *free_cu_cleanup
;
2630 struct attribute
*attr
;
2633 /* Set local variables from the partial symbol table info. */
2634 offset
= per_cu
->offset
;
2636 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2638 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2639 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2641 /* If an error occurs while loading, release our storage. */
2642 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2644 cu
->objfile
= objfile
;
2646 /* read in the comp_unit header */
2647 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2649 /* Read the abbrevs for this compilation unit */
2650 dwarf2_read_abbrevs (abfd
, cu
);
2651 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2653 cu
->header
.offset
= offset
;
2655 cu
->per_cu
= per_cu
;
2657 cu
->type_hash
= per_cu
->type_hash
;
2659 /* We use this obstack for block values in dwarf_alloc_block. */
2660 obstack_init (&cu
->comp_unit_obstack
);
2662 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2664 /* We try not to read any attributes in this function, because not
2665 all objfiles needed for references have been loaded yet, and symbol
2666 table processing isn't initialized. But we have to set the CU language,
2667 or we won't be able to build types correctly. */
2668 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2670 set_cu_language (DW_UNSND (attr
), cu
);
2672 set_cu_language (language_minimal
, cu
);
2674 do_cleanups (back_to
);
2676 /* We've successfully allocated this compilation unit. Let our caller
2677 clean it up when finished with it. */
2678 discard_cleanups (free_cu_cleanup
);
2683 /* Generate full symbol information for PST and CU, whose DIEs have
2684 already been loaded into memory. */
2687 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2689 struct partial_symtab
*pst
= per_cu
->psymtab
;
2690 struct dwarf2_cu
*cu
= per_cu
->cu
;
2691 struct objfile
*objfile
= pst
->objfile
;
2692 bfd
*abfd
= objfile
->obfd
;
2693 CORE_ADDR lowpc
, highpc
;
2694 struct symtab
*symtab
;
2695 struct cleanup
*back_to
;
2696 struct attribute
*attr
;
2699 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2702 back_to
= make_cleanup (really_free_pendings
, NULL
);
2704 cu
->list_in_scope
= &file_symbols
;
2706 /* Find the base address of the compilation unit for range lists and
2707 location lists. It will normally be specified by DW_AT_low_pc.
2708 In DWARF-3 draft 4, the base address could be overridden by
2709 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2710 compilation units with discontinuous ranges. */
2713 cu
->base_address
= 0;
2715 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2718 cu
->base_address
= DW_ADDR (attr
);
2723 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2726 cu
->base_address
= DW_ADDR (attr
);
2731 /* Do line number decoding in read_file_scope () */
2732 process_die (cu
->dies
, cu
);
2734 /* Some compilers don't define a DW_AT_high_pc attribute for the
2735 compilation unit. If the DW_AT_high_pc is missing, synthesize
2736 it, by scanning the DIE's below the compilation unit. */
2737 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2739 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2741 /* Set symtab language to language from DW_AT_language.
2742 If the compilation is from a C file generated by language preprocessors,
2743 do not set the language if it was already deduced by start_subfile. */
2745 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2747 symtab
->language
= cu
->language
;
2749 pst
->symtab
= symtab
;
2752 do_cleanups (back_to
);
2755 /* Process a die and its children. */
2758 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2762 case DW_TAG_padding
:
2764 case DW_TAG_compile_unit
:
2765 read_file_scope (die
, cu
);
2767 case DW_TAG_subprogram
:
2768 read_func_scope (die
, cu
);
2770 case DW_TAG_inlined_subroutine
:
2771 /* FIXME: These are ignored for now.
2772 They could be used to set breakpoints on all inlined instances
2773 of a function and make GDB `next' properly over inlined functions. */
2775 case DW_TAG_lexical_block
:
2776 case DW_TAG_try_block
:
2777 case DW_TAG_catch_block
:
2778 read_lexical_block_scope (die
, cu
);
2780 case DW_TAG_class_type
:
2781 case DW_TAG_interface_type
:
2782 case DW_TAG_structure_type
:
2783 case DW_TAG_union_type
:
2784 process_structure_scope (die
, cu
);
2786 case DW_TAG_enumeration_type
:
2787 process_enumeration_scope (die
, cu
);
2790 /* These dies have a type, but processing them does not create
2791 a symbol or recurse to process the children. Therefore we can
2792 read them on-demand through read_type_die. */
2793 case DW_TAG_subroutine_type
:
2794 case DW_TAG_set_type
:
2795 case DW_TAG_array_type
:
2796 case DW_TAG_pointer_type
:
2797 case DW_TAG_ptr_to_member_type
:
2798 case DW_TAG_reference_type
:
2799 case DW_TAG_string_type
:
2802 case DW_TAG_base_type
:
2803 case DW_TAG_subrange_type
:
2804 /* Add a typedef symbol for the type definition, if it has a
2806 new_symbol (die
, read_type_die (die
, cu
), cu
);
2808 case DW_TAG_common_block
:
2809 read_common_block (die
, cu
);
2811 case DW_TAG_common_inclusion
:
2813 case DW_TAG_namespace
:
2814 processing_has_namespace_info
= 1;
2815 read_namespace (die
, cu
);
2817 case DW_TAG_imported_declaration
:
2818 case DW_TAG_imported_module
:
2819 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2820 information contained in these. DW_TAG_imported_declaration
2821 dies shouldn't have children; DW_TAG_imported_module dies
2822 shouldn't in the C++ case, but conceivably could in the
2824 processing_has_namespace_info
= 1;
2825 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2826 dwarf_tag_name (die
->tag
));
2829 new_symbol (die
, NULL
, cu
);
2834 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2835 If scope qualifiers are appropriate they will be added. The result
2836 will be allocated on the objfile_obstack, or NULL if the DIE does
2840 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2842 struct attribute
*attr
;
2843 char *prefix
, *name
;
2844 struct ui_file
*buf
= NULL
;
2846 name
= dwarf2_name (die
, cu
);
2850 /* These are the only languages we know how to qualify names in. */
2851 if (cu
->language
!= language_cplus
2852 && cu
->language
!= language_java
)
2855 /* If no prefix is necessary for this type of DIE, return the
2856 unqualified name. The other three tags listed could be handled
2857 in pdi_needs_namespace, but that requires broader changes. */
2858 if (!pdi_needs_namespace (die
->tag
)
2859 && die
->tag
!= DW_TAG_subprogram
2860 && die
->tag
!= DW_TAG_variable
2861 && die
->tag
!= DW_TAG_member
)
2864 prefix
= determine_prefix (die
, cu
);
2865 if (*prefix
!= '\0')
2866 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2873 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2875 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2879 free_cu_line_header (void *arg
)
2881 struct dwarf2_cu
*cu
= arg
;
2883 free_line_header (cu
->line_header
);
2884 cu
->line_header
= NULL
;
2888 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2890 struct objfile
*objfile
= cu
->objfile
;
2891 struct comp_unit_head
*cu_header
= &cu
->header
;
2892 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2893 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2894 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2895 struct attribute
*attr
;
2897 char *comp_dir
= NULL
;
2898 struct die_info
*child_die
;
2899 bfd
*abfd
= objfile
->obfd
;
2900 struct line_header
*line_header
= 0;
2903 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2905 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2907 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2908 from finish_block. */
2909 if (lowpc
== ((CORE_ADDR
) -1))
2914 /* Find the filename. Do not use dwarf2_name here, since the filename
2915 is not a source language identifier. */
2916 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2919 name
= DW_STRING (attr
);
2922 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2924 comp_dir
= DW_STRING (attr
);
2925 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2927 comp_dir
= ldirname (name
);
2928 if (comp_dir
!= NULL
)
2929 make_cleanup (xfree
, comp_dir
);
2931 if (comp_dir
!= NULL
)
2933 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2934 directory, get rid of it. */
2935 char *cp
= strchr (comp_dir
, ':');
2937 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2944 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2947 set_cu_language (DW_UNSND (attr
), cu
);
2950 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2952 cu
->producer
= DW_STRING (attr
);
2954 /* We assume that we're processing GCC output. */
2955 processing_gcc_compilation
= 2;
2957 processing_has_namespace_info
= 0;
2959 start_symtab (name
, comp_dir
, lowpc
);
2960 record_debugformat ("DWARF 2");
2961 record_producer (cu
->producer
);
2963 initialize_cu_func_list (cu
);
2965 /* Decode line number information if present. We do this before
2966 processing child DIEs, so that the line header table is available
2967 for DW_AT_decl_file. */
2968 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2971 unsigned int line_offset
= DW_UNSND (attr
);
2972 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2975 cu
->line_header
= line_header
;
2976 make_cleanup (free_cu_line_header
, cu
);
2977 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2981 /* Process all dies in compilation unit. */
2982 if (die
->child
!= NULL
)
2984 child_die
= die
->child
;
2985 while (child_die
&& child_die
->tag
)
2987 process_die (child_die
, cu
);
2988 child_die
= sibling_die (child_die
);
2992 /* Decode macro information, if present. Dwarf 2 macro information
2993 refers to information in the line number info statement program
2994 header, so we can only read it if we've read the header
2996 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2997 if (attr
&& line_header
)
2999 unsigned int macro_offset
= DW_UNSND (attr
);
3000 dwarf_decode_macros (line_header
, macro_offset
,
3001 comp_dir
, abfd
, cu
);
3003 do_cleanups (back_to
);
3007 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3008 struct dwarf2_cu
*cu
)
3010 struct function_range
*thisfn
;
3012 thisfn
= (struct function_range
*)
3013 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3014 thisfn
->name
= name
;
3015 thisfn
->lowpc
= lowpc
;
3016 thisfn
->highpc
= highpc
;
3017 thisfn
->seen_line
= 0;
3018 thisfn
->next
= NULL
;
3020 if (cu
->last_fn
== NULL
)
3021 cu
->first_fn
= thisfn
;
3023 cu
->last_fn
->next
= thisfn
;
3025 cu
->last_fn
= thisfn
;
3029 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3031 struct objfile
*objfile
= cu
->objfile
;
3032 struct context_stack
*new;
3035 struct die_info
*child_die
;
3036 struct attribute
*attr
;
3039 struct block
*block
;
3041 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3043 name
= dwarf2_linkage_name (die
, cu
);
3045 /* Ignore functions with missing or empty names and functions with
3046 missing or invalid low and high pc attributes. */
3047 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3053 /* Record the function range for dwarf_decode_lines. */
3054 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3056 new = push_context (0, lowpc
);
3057 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3059 /* If there is a location expression for DW_AT_frame_base, record
3061 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3063 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3064 expression is being recorded directly in the function's symbol
3065 and not in a separate frame-base object. I guess this hack is
3066 to avoid adding some sort of frame-base adjunct/annex to the
3067 function's symbol :-(. The problem with doing this is that it
3068 results in a function symbol with a location expression that
3069 has nothing to do with the location of the function, ouch! The
3070 relationship should be: a function's symbol has-a frame base; a
3071 frame-base has-a location expression. */
3072 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3074 cu
->list_in_scope
= &local_symbols
;
3076 if (die
->child
!= NULL
)
3078 child_die
= die
->child
;
3079 while (child_die
&& child_die
->tag
)
3081 process_die (child_die
, cu
);
3082 child_die
= sibling_die (child_die
);
3086 new = pop_context ();
3087 /* Make a block for the local symbols within. */
3088 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3089 lowpc
, highpc
, objfile
);
3091 /* For C++, set the block's scope. */
3092 if (cu
->language
== language_cplus
)
3093 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3094 determine_prefix (die
, cu
),
3095 processing_has_namespace_info
);
3097 /* If we have address ranges, record them. */
3098 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3100 /* In C++, we can have functions nested inside functions (e.g., when
3101 a function declares a class that has methods). This means that
3102 when we finish processing a function scope, we may need to go
3103 back to building a containing block's symbol lists. */
3104 local_symbols
= new->locals
;
3105 param_symbols
= new->params
;
3107 /* If we've finished processing a top-level function, subsequent
3108 symbols go in the file symbol list. */
3109 if (outermost_context_p ())
3110 cu
->list_in_scope
= &file_symbols
;
3113 /* Process all the DIES contained within a lexical block scope. Start
3114 a new scope, process the dies, and then close the scope. */
3117 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3119 struct objfile
*objfile
= cu
->objfile
;
3120 struct context_stack
*new;
3121 CORE_ADDR lowpc
, highpc
;
3122 struct die_info
*child_die
;
3125 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3127 /* Ignore blocks with missing or invalid low and high pc attributes. */
3128 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3129 as multiple lexical blocks? Handling children in a sane way would
3130 be nasty. Might be easier to properly extend generic blocks to
3132 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3137 push_context (0, lowpc
);
3138 if (die
->child
!= NULL
)
3140 child_die
= die
->child
;
3141 while (child_die
&& child_die
->tag
)
3143 process_die (child_die
, cu
);
3144 child_die
= sibling_die (child_die
);
3147 new = pop_context ();
3149 if (local_symbols
!= NULL
)
3152 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3155 /* Note that recording ranges after traversing children, as we
3156 do here, means that recording a parent's ranges entails
3157 walking across all its children's ranges as they appear in
3158 the address map, which is quadratic behavior.
3160 It would be nicer to record the parent's ranges before
3161 traversing its children, simply overriding whatever you find
3162 there. But since we don't even decide whether to create a
3163 block until after we've traversed its children, that's hard
3165 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3167 local_symbols
= new->locals
;
3170 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3171 Return 1 if the attributes are present and valid, otherwise, return 0.
3172 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3175 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3176 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3177 struct partial_symtab
*ranges_pst
)
3179 struct objfile
*objfile
= cu
->objfile
;
3180 struct comp_unit_head
*cu_header
= &cu
->header
;
3181 bfd
*obfd
= objfile
->obfd
;
3182 unsigned int addr_size
= cu_header
->addr_size
;
3183 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3184 /* Base address selection entry. */
3195 found_base
= cu
->base_known
;
3196 base
= cu
->base_address
;
3198 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3200 complaint (&symfile_complaints
,
3201 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3205 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3207 /* Read in the largest possible address. */
3208 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3209 if ((marker
& mask
) == mask
)
3211 /* If we found the largest possible address, then
3212 read the base address. */
3213 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3214 buffer
+= 2 * addr_size
;
3215 offset
+= 2 * addr_size
;
3221 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3225 CORE_ADDR range_beginning
, range_end
;
3227 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3228 buffer
+= addr_size
;
3229 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3230 buffer
+= addr_size
;
3231 offset
+= 2 * addr_size
;
3233 /* An end of list marker is a pair of zero addresses. */
3234 if (range_beginning
== 0 && range_end
== 0)
3235 /* Found the end of list entry. */
3238 /* Each base address selection entry is a pair of 2 values.
3239 The first is the largest possible address, the second is
3240 the base address. Check for a base address here. */
3241 if ((range_beginning
& mask
) == mask
)
3243 /* If we found the largest possible address, then
3244 read the base address. */
3245 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3252 /* We have no valid base address for the ranges
3254 complaint (&symfile_complaints
,
3255 _("Invalid .debug_ranges data (no base address)"));
3259 range_beginning
+= base
;
3262 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3263 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3264 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3267 /* FIXME: This is recording everything as a low-high
3268 segment of consecutive addresses. We should have a
3269 data structure for discontiguous block ranges
3273 low
= range_beginning
;
3279 if (range_beginning
< low
)
3280 low
= range_beginning
;
3281 if (range_end
> high
)
3287 /* If the first entry is an end-of-list marker, the range
3288 describes an empty scope, i.e. no instructions. */
3294 *high_return
= high
;
3298 /* Get low and high pc attributes from a die. Return 1 if the attributes
3299 are present and valid, otherwise, return 0. Return -1 if the range is
3300 discontinuous, i.e. derived from DW_AT_ranges information. */
3302 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3303 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3305 struct attribute
*attr
;
3310 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3313 high
= DW_ADDR (attr
);
3314 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3316 low
= DW_ADDR (attr
);
3318 /* Found high w/o low attribute. */
3321 /* Found consecutive range of addresses. */
3326 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3329 /* Value of the DW_AT_ranges attribute is the offset in the
3330 .debug_ranges section. */
3331 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3333 /* Found discontinuous range of addresses. */
3341 /* When using the GNU linker, .gnu.linkonce. sections are used to
3342 eliminate duplicate copies of functions and vtables and such.
3343 The linker will arbitrarily choose one and discard the others.
3344 The AT_*_pc values for such functions refer to local labels in
3345 these sections. If the section from that file was discarded, the
3346 labels are not in the output, so the relocs get a value of 0.
3347 If this is a discarded function, mark the pc bounds as invalid,
3348 so that GDB will ignore it. */
3349 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3357 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3358 its low and high PC addresses. Do nothing if these addresses could not
3359 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3360 and HIGHPC to the high address if greater than HIGHPC. */
3363 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3364 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3365 struct dwarf2_cu
*cu
)
3367 CORE_ADDR low
, high
;
3368 struct die_info
*child
= die
->child
;
3370 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3372 *lowpc
= min (*lowpc
, low
);
3373 *highpc
= max (*highpc
, high
);
3376 /* If the language does not allow nested subprograms (either inside
3377 subprograms or lexical blocks), we're done. */
3378 if (cu
->language
!= language_ada
)
3381 /* Check all the children of the given DIE. If it contains nested
3382 subprograms, then check their pc bounds. Likewise, we need to
3383 check lexical blocks as well, as they may also contain subprogram
3385 while (child
&& child
->tag
)
3387 if (child
->tag
== DW_TAG_subprogram
3388 || child
->tag
== DW_TAG_lexical_block
)
3389 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3390 child
= sibling_die (child
);
3394 /* Get the low and high pc's represented by the scope DIE, and store
3395 them in *LOWPC and *HIGHPC. If the correct values can't be
3396 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3399 get_scope_pc_bounds (struct die_info
*die
,
3400 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3401 struct dwarf2_cu
*cu
)
3403 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3404 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3405 CORE_ADDR current_low
, current_high
;
3407 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3409 best_low
= current_low
;
3410 best_high
= current_high
;
3414 struct die_info
*child
= die
->child
;
3416 while (child
&& child
->tag
)
3418 switch (child
->tag
) {
3419 case DW_TAG_subprogram
:
3420 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3422 case DW_TAG_namespace
:
3423 /* FIXME: carlton/2004-01-16: Should we do this for
3424 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3425 that current GCC's always emit the DIEs corresponding
3426 to definitions of methods of classes as children of a
3427 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3428 the DIEs giving the declarations, which could be
3429 anywhere). But I don't see any reason why the
3430 standards says that they have to be there. */
3431 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3433 if (current_low
!= ((CORE_ADDR
) -1))
3435 best_low
= min (best_low
, current_low
);
3436 best_high
= max (best_high
, current_high
);
3444 child
= sibling_die (child
);
3449 *highpc
= best_high
;
3452 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3455 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3456 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3458 struct attribute
*attr
;
3460 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3463 CORE_ADDR high
= DW_ADDR (attr
);
3464 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3467 CORE_ADDR low
= DW_ADDR (attr
);
3468 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3472 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3475 bfd
*obfd
= cu
->objfile
->obfd
;
3477 /* The value of the DW_AT_ranges attribute is the offset of the
3478 address range list in the .debug_ranges section. */
3479 unsigned long offset
= DW_UNSND (attr
);
3480 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3482 /* For some target architectures, but not others, the
3483 read_address function sign-extends the addresses it returns.
3484 To recognize base address selection entries, we need a
3486 unsigned int addr_size
= cu
->header
.addr_size
;
3487 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3489 /* The base address, to which the next pair is relative. Note
3490 that this 'base' is a DWARF concept: most entries in a range
3491 list are relative, to reduce the number of relocs against the
3492 debugging information. This is separate from this function's
3493 'baseaddr' argument, which GDB uses to relocate debugging
3494 information from a shared library based on the address at
3495 which the library was loaded. */
3496 CORE_ADDR base
= cu
->base_address
;
3497 int base_known
= cu
->base_known
;
3499 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3501 complaint (&symfile_complaints
,
3502 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3509 unsigned int bytes_read
;
3510 CORE_ADDR start
, end
;
3512 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3513 buffer
+= bytes_read
;
3514 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3515 buffer
+= bytes_read
;
3517 /* Did we find the end of the range list? */
3518 if (start
== 0 && end
== 0)
3521 /* Did we find a base address selection entry? */
3522 else if ((start
& base_select_mask
) == base_select_mask
)
3528 /* We found an ordinary address range. */
3533 complaint (&symfile_complaints
,
3534 _("Invalid .debug_ranges data (no base address)"));
3538 record_block_range (block
,
3539 baseaddr
+ base
+ start
,
3540 baseaddr
+ base
+ end
- 1);
3546 /* Add an aggregate field to the field list. */
3549 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3550 struct dwarf2_cu
*cu
)
3552 struct objfile
*objfile
= cu
->objfile
;
3553 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3554 struct nextfield
*new_field
;
3555 struct attribute
*attr
;
3557 char *fieldname
= "";
3559 /* Allocate a new field list entry and link it in. */
3560 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3561 make_cleanup (xfree
, new_field
);
3562 memset (new_field
, 0, sizeof (struct nextfield
));
3563 new_field
->next
= fip
->fields
;
3564 fip
->fields
= new_field
;
3567 /* Handle accessibility and virtuality of field.
3568 The default accessibility for members is public, the default
3569 accessibility for inheritance is private. */
3570 if (die
->tag
!= DW_TAG_inheritance
)
3571 new_field
->accessibility
= DW_ACCESS_public
;
3573 new_field
->accessibility
= DW_ACCESS_private
;
3574 new_field
->virtuality
= DW_VIRTUALITY_none
;
3576 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3578 new_field
->accessibility
= DW_UNSND (attr
);
3579 if (new_field
->accessibility
!= DW_ACCESS_public
)
3580 fip
->non_public_fields
= 1;
3581 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3583 new_field
->virtuality
= DW_UNSND (attr
);
3585 fp
= &new_field
->field
;
3587 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3589 /* Data member other than a C++ static data member. */
3591 /* Get type of field. */
3592 fp
->type
= die_type (die
, cu
);
3594 SET_FIELD_BITPOS (*fp
, 0);
3596 /* Get bit size of field (zero if none). */
3597 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3600 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3604 FIELD_BITSIZE (*fp
) = 0;
3607 /* Get bit offset of field. */
3608 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3613 if (attr_form_is_section_offset (attr
))
3615 dwarf2_complex_location_expr_complaint ();
3618 else if (attr_form_is_constant (attr
))
3619 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3621 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3623 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3625 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3628 if (gdbarch_bits_big_endian (gdbarch
))
3630 /* For big endian bits, the DW_AT_bit_offset gives the
3631 additional bit offset from the MSB of the containing
3632 anonymous object to the MSB of the field. We don't
3633 have to do anything special since we don't need to
3634 know the size of the anonymous object. */
3635 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3639 /* For little endian bits, compute the bit offset to the
3640 MSB of the anonymous object, subtract off the number of
3641 bits from the MSB of the field to the MSB of the
3642 object, and then subtract off the number of bits of
3643 the field itself. The result is the bit offset of
3644 the LSB of the field. */
3646 int bit_offset
= DW_UNSND (attr
);
3648 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3651 /* The size of the anonymous object containing
3652 the bit field is explicit, so use the
3653 indicated size (in bytes). */
3654 anonymous_size
= DW_UNSND (attr
);
3658 /* The size of the anonymous object containing
3659 the bit field must be inferred from the type
3660 attribute of the data member containing the
3662 anonymous_size
= TYPE_LENGTH (fp
->type
);
3664 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3665 - bit_offset
- FIELD_BITSIZE (*fp
);
3669 /* Get name of field. */
3670 fieldname
= dwarf2_name (die
, cu
);
3671 if (fieldname
== NULL
)
3674 /* The name is already allocated along with this objfile, so we don't
3675 need to duplicate it for the type. */
3676 fp
->name
= fieldname
;
3678 /* Change accessibility for artificial fields (e.g. virtual table
3679 pointer or virtual base class pointer) to private. */
3680 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3682 new_field
->accessibility
= DW_ACCESS_private
;
3683 fip
->non_public_fields
= 1;
3686 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3688 /* C++ static member. */
3690 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3691 is a declaration, but all versions of G++ as of this writing
3692 (so through at least 3.2.1) incorrectly generate
3693 DW_TAG_variable tags. */
3697 /* Get name of field. */
3698 fieldname
= dwarf2_name (die
, cu
);
3699 if (fieldname
== NULL
)
3702 /* Get physical name. */
3703 physname
= dwarf2_linkage_name (die
, cu
);
3705 /* The name is already allocated along with this objfile, so we don't
3706 need to duplicate it for the type. */
3707 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3708 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3709 FIELD_NAME (*fp
) = fieldname
;
3711 else if (die
->tag
== DW_TAG_inheritance
)
3713 /* C++ base class field. */
3714 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3716 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
3718 FIELD_BITSIZE (*fp
) = 0;
3719 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3720 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3721 fip
->nbaseclasses
++;
3725 /* Create the vector of fields, and attach it to the type. */
3728 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3729 struct dwarf2_cu
*cu
)
3731 int nfields
= fip
->nfields
;
3733 /* Record the field count, allocate space for the array of fields,
3734 and create blank accessibility bitfields if necessary. */
3735 TYPE_NFIELDS (type
) = nfields
;
3736 TYPE_FIELDS (type
) = (struct field
*)
3737 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3738 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3740 if (fip
->non_public_fields
)
3742 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3744 TYPE_FIELD_PRIVATE_BITS (type
) =
3745 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3746 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3748 TYPE_FIELD_PROTECTED_BITS (type
) =
3749 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3750 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3752 TYPE_FIELD_IGNORE_BITS (type
) =
3753 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3754 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3757 /* If the type has baseclasses, allocate and clear a bit vector for
3758 TYPE_FIELD_VIRTUAL_BITS. */
3759 if (fip
->nbaseclasses
)
3761 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3762 unsigned char *pointer
;
3764 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3765 pointer
= TYPE_ALLOC (type
, num_bytes
);
3766 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3767 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3768 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3771 /* Copy the saved-up fields into the field vector. Start from the head
3772 of the list, adding to the tail of the field array, so that they end
3773 up in the same order in the array in which they were added to the list. */
3774 while (nfields
-- > 0)
3776 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3777 switch (fip
->fields
->accessibility
)
3779 case DW_ACCESS_private
:
3780 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3783 case DW_ACCESS_protected
:
3784 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3787 case DW_ACCESS_public
:
3791 /* Unknown accessibility. Complain and treat it as public. */
3793 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3794 fip
->fields
->accessibility
);
3798 if (nfields
< fip
->nbaseclasses
)
3800 switch (fip
->fields
->virtuality
)
3802 case DW_VIRTUALITY_virtual
:
3803 case DW_VIRTUALITY_pure_virtual
:
3804 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3808 fip
->fields
= fip
->fields
->next
;
3812 /* Add a member function to the proper fieldlist. */
3815 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3816 struct type
*type
, struct dwarf2_cu
*cu
)
3818 struct objfile
*objfile
= cu
->objfile
;
3819 struct attribute
*attr
;
3820 struct fnfieldlist
*flp
;
3822 struct fn_field
*fnp
;
3825 struct nextfnfield
*new_fnfield
;
3826 struct type
*this_type
;
3828 /* Get name of member function. */
3829 fieldname
= dwarf2_name (die
, cu
);
3830 if (fieldname
== NULL
)
3833 /* Get the mangled name. */
3834 physname
= dwarf2_linkage_name (die
, cu
);
3836 /* Look up member function name in fieldlist. */
3837 for (i
= 0; i
< fip
->nfnfields
; i
++)
3839 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3843 /* Create new list element if necessary. */
3844 if (i
< fip
->nfnfields
)
3845 flp
= &fip
->fnfieldlists
[i
];
3848 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3850 fip
->fnfieldlists
= (struct fnfieldlist
*)
3851 xrealloc (fip
->fnfieldlists
,
3852 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3853 * sizeof (struct fnfieldlist
));
3854 if (fip
->nfnfields
== 0)
3855 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3857 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3858 flp
->name
= fieldname
;
3864 /* Create a new member function field and chain it to the field list
3866 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3867 make_cleanup (xfree
, new_fnfield
);
3868 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3869 new_fnfield
->next
= flp
->head
;
3870 flp
->head
= new_fnfield
;
3873 /* Fill in the member function field info. */
3874 fnp
= &new_fnfield
->fnfield
;
3875 /* The name is already allocated along with this objfile, so we don't
3876 need to duplicate it for the type. */
3877 fnp
->physname
= physname
? physname
: "";
3878 fnp
->type
= alloc_type (objfile
);
3879 this_type
= read_type_die (die
, cu
);
3880 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3882 int nparams
= TYPE_NFIELDS (this_type
);
3884 /* TYPE is the domain of this method, and THIS_TYPE is the type
3885 of the method itself (TYPE_CODE_METHOD). */
3886 smash_to_method_type (fnp
->type
, type
,
3887 TYPE_TARGET_TYPE (this_type
),
3888 TYPE_FIELDS (this_type
),
3889 TYPE_NFIELDS (this_type
),
3890 TYPE_VARARGS (this_type
));
3892 /* Handle static member functions.
3893 Dwarf2 has no clean way to discern C++ static and non-static
3894 member functions. G++ helps GDB by marking the first
3895 parameter for non-static member functions (which is the
3896 this pointer) as artificial. We obtain this information
3897 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3898 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3899 fnp
->voffset
= VOFFSET_STATIC
;
3902 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3905 /* Get fcontext from DW_AT_containing_type if present. */
3906 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3907 fnp
->fcontext
= die_containing_type (die
, cu
);
3909 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3910 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3912 /* Get accessibility. */
3913 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3916 switch (DW_UNSND (attr
))
3918 case DW_ACCESS_private
:
3919 fnp
->is_private
= 1;
3921 case DW_ACCESS_protected
:
3922 fnp
->is_protected
= 1;
3927 /* Check for artificial methods. */
3928 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3929 if (attr
&& DW_UNSND (attr
) != 0)
3930 fnp
->is_artificial
= 1;
3932 /* Get index in virtual function table if it is a virtual member function. */
3933 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3936 /* Support the .debug_loc offsets */
3937 if (attr_form_is_block (attr
))
3939 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3941 else if (attr_form_is_section_offset (attr
))
3943 dwarf2_complex_location_expr_complaint ();
3947 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3953 /* Create the vector of member function fields, and attach it to the type. */
3956 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3957 struct dwarf2_cu
*cu
)
3959 struct fnfieldlist
*flp
;
3960 int total_length
= 0;
3963 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3964 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3965 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3967 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3969 struct nextfnfield
*nfp
= flp
->head
;
3970 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3973 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3974 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3975 fn_flp
->fn_fields
= (struct fn_field
*)
3976 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3977 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3978 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3980 total_length
+= flp
->length
;
3983 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3984 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3987 /* Returns non-zero if NAME is the name of a vtable member in CU's
3988 language, zero otherwise. */
3990 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3992 static const char vptr
[] = "_vptr";
3993 static const char vtable
[] = "vtable";
3995 /* Look for the C++ and Java forms of the vtable. */
3996 if ((cu
->language
== language_java
3997 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3998 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3999 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4005 /* GCC outputs unnamed structures that are really pointers to member
4006 functions, with the ABI-specified layout. If DIE (from CU) describes
4007 such a structure, set its type, and return nonzero. Otherwise return
4010 GCC shouldn't do this; it should just output pointer to member DIEs.
4011 This is GCC PR debug/28767. */
4013 static struct type
*
4014 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4016 struct objfile
*objfile
= cu
->objfile
;
4018 struct die_info
*pfn_die
, *delta_die
;
4019 struct attribute
*pfn_name
, *delta_name
;
4020 struct type
*pfn_type
, *domain_type
;
4022 /* Check for a structure with no name and two children. */
4023 if (die
->tag
!= DW_TAG_structure_type
4024 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4025 || die
->child
== NULL
4026 || die
->child
->sibling
== NULL
4027 || (die
->child
->sibling
->sibling
!= NULL
4028 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4031 /* Check for __pfn and __delta members. */
4032 pfn_die
= die
->child
;
4033 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4034 if (pfn_die
->tag
!= DW_TAG_member
4036 || DW_STRING (pfn_name
) == NULL
4037 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4040 delta_die
= pfn_die
->sibling
;
4041 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4042 if (delta_die
->tag
!= DW_TAG_member
4043 || delta_name
== NULL
4044 || DW_STRING (delta_name
) == NULL
4045 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4048 /* Find the type of the method. */
4049 pfn_type
= die_type (pfn_die
, cu
);
4050 if (pfn_type
== NULL
4051 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4052 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4055 /* Look for the "this" argument. */
4056 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4057 if (TYPE_NFIELDS (pfn_type
) == 0
4058 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4061 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4062 type
= alloc_type (objfile
);
4063 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4064 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4065 TYPE_VARARGS (pfn_type
));
4066 type
= lookup_methodptr_type (type
);
4067 return set_die_type (die
, type
, cu
);
4070 /* Called when we find the DIE that starts a structure or union scope
4071 (definition) to process all dies that define the members of the
4074 NOTE: we need to call struct_type regardless of whether or not the
4075 DIE has an at_name attribute, since it might be an anonymous
4076 structure or union. This gets the type entered into our set of
4079 However, if the structure is incomplete (an opaque struct/union)
4080 then suppress creating a symbol table entry for it since gdb only
4081 wants to find the one with the complete definition. Note that if
4082 it is complete, we just call new_symbol, which does it's own
4083 checking about whether the struct/union is anonymous or not (and
4084 suppresses creating a symbol table entry itself). */
4086 static struct type
*
4087 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4089 struct objfile
*objfile
= cu
->objfile
;
4091 struct attribute
*attr
;
4093 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4095 type
= quirk_gcc_member_function_pointer (die
, cu
);
4099 type
= alloc_type (objfile
);
4100 INIT_CPLUS_SPECIFIC (type
);
4101 name
= dwarf2_name (die
, cu
);
4104 if (cu
->language
== language_cplus
4105 || cu
->language
== language_java
)
4107 const char *new_prefix
= determine_class_name (die
, cu
);
4108 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4112 /* The name is already allocated along with this objfile, so
4113 we don't need to duplicate it for the type. */
4114 TYPE_TAG_NAME (type
) = name
;
4118 if (die
->tag
== DW_TAG_structure_type
)
4120 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4122 else if (die
->tag
== DW_TAG_union_type
)
4124 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4128 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4130 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4133 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4136 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4140 TYPE_LENGTH (type
) = 0;
4143 TYPE_STUB_SUPPORTED (type
) = 1;
4144 if (die_is_declaration (die
, cu
))
4145 TYPE_STUB (type
) = 1;
4147 /* We need to add the type field to the die immediately so we don't
4148 infinitely recurse when dealing with pointers to the structure
4149 type within the structure itself. */
4150 set_die_type (die
, type
, cu
);
4152 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4154 struct field_info fi
;
4155 struct die_info
*child_die
;
4157 memset (&fi
, 0, sizeof (struct field_info
));
4159 child_die
= die
->child
;
4161 while (child_die
&& child_die
->tag
)
4163 if (child_die
->tag
== DW_TAG_member
4164 || child_die
->tag
== DW_TAG_variable
)
4166 /* NOTE: carlton/2002-11-05: A C++ static data member
4167 should be a DW_TAG_member that is a declaration, but
4168 all versions of G++ as of this writing (so through at
4169 least 3.2.1) incorrectly generate DW_TAG_variable
4170 tags for them instead. */
4171 dwarf2_add_field (&fi
, child_die
, cu
);
4173 else if (child_die
->tag
== DW_TAG_subprogram
)
4175 /* C++ member function. */
4176 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4178 else if (child_die
->tag
== DW_TAG_inheritance
)
4180 /* C++ base class field. */
4181 dwarf2_add_field (&fi
, child_die
, cu
);
4183 child_die
= sibling_die (child_die
);
4186 /* Attach fields and member functions to the type. */
4188 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4191 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4193 /* Get the type which refers to the base class (possibly this
4194 class itself) which contains the vtable pointer for the current
4195 class from the DW_AT_containing_type attribute. */
4197 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4199 struct type
*t
= die_containing_type (die
, cu
);
4201 TYPE_VPTR_BASETYPE (type
) = t
;
4206 /* Our own class provides vtbl ptr. */
4207 for (i
= TYPE_NFIELDS (t
) - 1;
4208 i
>= TYPE_N_BASECLASSES (t
);
4211 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4213 if (is_vtable_name (fieldname
, cu
))
4215 TYPE_VPTR_FIELDNO (type
) = i
;
4220 /* Complain if virtual function table field not found. */
4221 if (i
< TYPE_N_BASECLASSES (t
))
4222 complaint (&symfile_complaints
,
4223 _("virtual function table pointer not found when defining class '%s'"),
4224 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4229 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4232 else if (cu
->producer
4233 && strncmp (cu
->producer
,
4234 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4236 /* The IBM XLC compiler does not provide direct indication
4237 of the containing type, but the vtable pointer is
4238 always named __vfp. */
4242 for (i
= TYPE_NFIELDS (type
) - 1;
4243 i
>= TYPE_N_BASECLASSES (type
);
4246 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4248 TYPE_VPTR_FIELDNO (type
) = i
;
4249 TYPE_VPTR_BASETYPE (type
) = type
;
4257 do_cleanups (back_to
);
4262 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4264 struct objfile
*objfile
= cu
->objfile
;
4265 struct die_info
*child_die
= die
->child
;
4266 struct type
*this_type
;
4268 this_type
= get_die_type (die
, cu
);
4269 if (this_type
== NULL
)
4270 this_type
= read_structure_type (die
, cu
);
4272 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4273 snapshots) has been known to create a die giving a declaration
4274 for a class that has, as a child, a die giving a definition for a
4275 nested class. So we have to process our children even if the
4276 current die is a declaration. Normally, of course, a declaration
4277 won't have any children at all. */
4279 while (child_die
!= NULL
&& child_die
->tag
)
4281 if (child_die
->tag
== DW_TAG_member
4282 || child_die
->tag
== DW_TAG_variable
4283 || child_die
->tag
== DW_TAG_inheritance
)
4288 process_die (child_die
, cu
);
4290 child_die
= sibling_die (child_die
);
4293 /* Do not consider external references. According to the DWARF standard,
4294 these DIEs are identified by the fact that they have no byte_size
4295 attribute, and a declaration attribute. */
4296 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4297 || !die_is_declaration (die
, cu
))
4298 new_symbol (die
, this_type
, cu
);
4301 /* Given a DW_AT_enumeration_type die, set its type. We do not
4302 complete the type's fields yet, or create any symbols. */
4304 static struct type
*
4305 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4307 struct objfile
*objfile
= cu
->objfile
;
4309 struct attribute
*attr
;
4312 type
= alloc_type (objfile
);
4314 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4315 name
= dwarf2_full_name (die
, cu
);
4317 TYPE_TAG_NAME (type
) = (char *) name
;
4319 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4322 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4326 TYPE_LENGTH (type
) = 0;
4329 /* The enumeration DIE can be incomplete. In Ada, any type can be
4330 declared as private in the package spec, and then defined only
4331 inside the package body. Such types are known as Taft Amendment
4332 Types. When another package uses such a type, an incomplete DIE
4333 may be generated by the compiler. */
4334 if (die_is_declaration (die
, cu
))
4335 TYPE_STUB (type
) = 1;
4337 return set_die_type (die
, type
, cu
);
4340 /* Determine the name of the type represented by DIE, which should be
4341 a named C++ or Java compound type. Return the name in question,
4342 allocated on the objfile obstack. */
4345 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4347 const char *new_prefix
= NULL
;
4349 /* If we don't have namespace debug info, guess the name by trying
4350 to demangle the names of members, just like we did in
4351 guess_structure_name. */
4352 if (!processing_has_namespace_info
)
4354 struct die_info
*child
;
4356 for (child
= die
->child
;
4357 child
!= NULL
&& child
->tag
!= 0;
4358 child
= sibling_die (child
))
4360 if (child
->tag
== DW_TAG_subprogram
)
4363 = language_class_name_from_physname (cu
->language_defn
,
4367 if (phys_prefix
!= NULL
)
4370 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4371 &cu
->objfile
->objfile_obstack
);
4372 xfree (phys_prefix
);
4379 if (new_prefix
== NULL
)
4380 new_prefix
= dwarf2_full_name (die
, cu
);
4385 /* Given a pointer to a die which begins an enumeration, process all
4386 the dies that define the members of the enumeration, and create the
4387 symbol for the enumeration type.
4389 NOTE: We reverse the order of the element list. */
4392 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4394 struct objfile
*objfile
= cu
->objfile
;
4395 struct die_info
*child_die
;
4396 struct field
*fields
;
4399 int unsigned_enum
= 1;
4401 struct type
*this_type
;
4405 this_type
= get_die_type (die
, cu
);
4406 if (this_type
== NULL
)
4407 this_type
= read_enumeration_type (die
, cu
);
4408 if (die
->child
!= NULL
)
4410 child_die
= die
->child
;
4411 while (child_die
&& child_die
->tag
)
4413 if (child_die
->tag
!= DW_TAG_enumerator
)
4415 process_die (child_die
, cu
);
4419 name
= dwarf2_name (child_die
, cu
);
4422 sym
= new_symbol (child_die
, this_type
, cu
);
4423 if (SYMBOL_VALUE (sym
) < 0)
4426 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4428 fields
= (struct field
*)
4430 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4431 * sizeof (struct field
));
4434 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4435 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4436 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4437 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4443 child_die
= sibling_die (child_die
);
4448 TYPE_NFIELDS (this_type
) = num_fields
;
4449 TYPE_FIELDS (this_type
) = (struct field
*)
4450 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4451 memcpy (TYPE_FIELDS (this_type
), fields
,
4452 sizeof (struct field
) * num_fields
);
4456 TYPE_UNSIGNED (this_type
) = 1;
4459 new_symbol (die
, this_type
, cu
);
4462 /* Extract all information from a DW_TAG_array_type DIE and put it in
4463 the DIE's type field. For now, this only handles one dimensional
4466 static struct type
*
4467 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4469 struct objfile
*objfile
= cu
->objfile
;
4470 struct die_info
*child_die
;
4471 struct type
*type
= NULL
;
4472 struct type
*element_type
, *range_type
, *index_type
;
4473 struct type
**range_types
= NULL
;
4474 struct attribute
*attr
;
4476 struct cleanup
*back_to
;
4479 element_type
= die_type (die
, cu
);
4481 /* Irix 6.2 native cc creates array types without children for
4482 arrays with unspecified length. */
4483 if (die
->child
== NULL
)
4485 index_type
= builtin_type_int32
;
4486 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4487 type
= create_array_type (NULL
, element_type
, range_type
);
4488 return set_die_type (die
, type
, cu
);
4491 back_to
= make_cleanup (null_cleanup
, NULL
);
4492 child_die
= die
->child
;
4493 while (child_die
&& child_die
->tag
)
4495 if (child_die
->tag
== DW_TAG_subrange_type
)
4497 struct type
*child_type
= read_type_die (child_die
, cu
);
4498 if (child_type
!= NULL
)
4500 /* The range type was succesfully read. Save it for
4501 the array type creation. */
4502 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4504 range_types
= (struct type
**)
4505 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4506 * sizeof (struct type
*));
4508 make_cleanup (free_current_contents
, &range_types
);
4510 range_types
[ndim
++] = child_type
;
4513 child_die
= sibling_die (child_die
);
4516 /* Dwarf2 dimensions are output from left to right, create the
4517 necessary array types in backwards order. */
4519 type
= element_type
;
4521 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4525 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4530 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4533 /* Understand Dwarf2 support for vector types (like they occur on
4534 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4535 array type. This is not part of the Dwarf2/3 standard yet, but a
4536 custom vendor extension. The main difference between a regular
4537 array and the vector variant is that vectors are passed by value
4539 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4541 make_vector_type (type
);
4543 name
= dwarf2_name (die
, cu
);
4545 TYPE_NAME (type
) = name
;
4547 do_cleanups (back_to
);
4549 /* Install the type in the die. */
4550 return set_die_type (die
, type
, cu
);
4553 static enum dwarf_array_dim_ordering
4554 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4556 struct attribute
*attr
;
4558 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4560 if (attr
) return DW_SND (attr
);
4563 GNU F77 is a special case, as at 08/2004 array type info is the
4564 opposite order to the dwarf2 specification, but data is still
4565 laid out as per normal fortran.
4567 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4571 if (cu
->language
== language_fortran
&&
4572 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4574 return DW_ORD_row_major
;
4577 switch (cu
->language_defn
->la_array_ordering
)
4579 case array_column_major
:
4580 return DW_ORD_col_major
;
4581 case array_row_major
:
4583 return DW_ORD_row_major
;
4587 /* Extract all information from a DW_TAG_set_type DIE and put it in
4588 the DIE's type field. */
4590 static struct type
*
4591 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4593 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4595 return set_die_type (die
, set_type
, cu
);
4598 /* First cut: install each common block member as a global variable. */
4601 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4603 struct die_info
*child_die
;
4604 struct attribute
*attr
;
4606 CORE_ADDR base
= (CORE_ADDR
) 0;
4608 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4611 /* Support the .debug_loc offsets */
4612 if (attr_form_is_block (attr
))
4614 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4616 else if (attr_form_is_section_offset (attr
))
4618 dwarf2_complex_location_expr_complaint ();
4622 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4623 "common block member");
4626 if (die
->child
!= NULL
)
4628 child_die
= die
->child
;
4629 while (child_die
&& child_die
->tag
)
4631 sym
= new_symbol (child_die
, NULL
, cu
);
4632 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4635 SYMBOL_VALUE_ADDRESS (sym
) =
4636 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4637 add_symbol_to_list (sym
, &global_symbols
);
4639 child_die
= sibling_die (child_die
);
4644 /* Create a type for a C++ namespace. */
4646 static struct type
*
4647 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4649 struct objfile
*objfile
= cu
->objfile
;
4650 const char *previous_prefix
, *name
;
4654 /* For extensions, reuse the type of the original namespace. */
4655 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4657 struct die_info
*ext_die
;
4658 struct dwarf2_cu
*ext_cu
= cu
;
4659 ext_die
= dwarf2_extension (die
, &ext_cu
);
4660 type
= read_type_die (ext_die
, ext_cu
);
4661 return set_die_type (die
, type
, cu
);
4664 name
= namespace_name (die
, &is_anonymous
, cu
);
4666 /* Now build the name of the current namespace. */
4668 previous_prefix
= determine_prefix (die
, cu
);
4669 if (previous_prefix
[0] != '\0')
4670 name
= typename_concat (&objfile
->objfile_obstack
,
4671 previous_prefix
, name
, cu
);
4673 /* Create the type. */
4674 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4676 TYPE_NAME (type
) = (char *) name
;
4677 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4679 set_die_type (die
, type
, cu
);
4684 /* Read a C++ namespace. */
4687 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4689 struct objfile
*objfile
= cu
->objfile
;
4693 /* Add a symbol associated to this if we haven't seen the namespace
4694 before. Also, add a using directive if it's an anonymous
4697 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4701 type
= read_type_die (die
, cu
);
4702 new_symbol (die
, type
, cu
);
4704 name
= namespace_name (die
, &is_anonymous
, cu
);
4707 const char *previous_prefix
= determine_prefix (die
, cu
);
4708 cp_add_using_directive (TYPE_NAME (type
),
4709 strlen (previous_prefix
),
4710 strlen (TYPE_NAME (type
)));
4714 if (die
->child
!= NULL
)
4716 struct die_info
*child_die
= die
->child
;
4718 while (child_die
&& child_die
->tag
)
4720 process_die (child_die
, cu
);
4721 child_die
= sibling_die (child_die
);
4726 /* Return the name of the namespace represented by DIE. Set
4727 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4731 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4733 struct die_info
*current_die
;
4734 const char *name
= NULL
;
4736 /* Loop through the extensions until we find a name. */
4738 for (current_die
= die
;
4739 current_die
!= NULL
;
4740 current_die
= dwarf2_extension (die
, &cu
))
4742 name
= dwarf2_name (current_die
, cu
);
4747 /* Is it an anonymous namespace? */
4749 *is_anonymous
= (name
== NULL
);
4751 name
= "(anonymous namespace)";
4756 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4757 the user defined type vector. */
4759 static struct type
*
4760 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4762 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4763 struct comp_unit_head
*cu_header
= &cu
->header
;
4765 struct attribute
*attr_byte_size
;
4766 struct attribute
*attr_address_class
;
4767 int byte_size
, addr_class
;
4769 type
= lookup_pointer_type (die_type (die
, cu
));
4771 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4773 byte_size
= DW_UNSND (attr_byte_size
);
4775 byte_size
= cu_header
->addr_size
;
4777 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4778 if (attr_address_class
)
4779 addr_class
= DW_UNSND (attr_address_class
);
4781 addr_class
= DW_ADDR_none
;
4783 /* If the pointer size or address class is different than the
4784 default, create a type variant marked as such and set the
4785 length accordingly. */
4786 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4788 if (gdbarch_address_class_type_flags_p (gdbarch
))
4792 type_flags
= gdbarch_address_class_type_flags
4793 (gdbarch
, byte_size
, addr_class
);
4794 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4796 type
= make_type_with_address_space (type
, type_flags
);
4798 else if (TYPE_LENGTH (type
) != byte_size
)
4800 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4803 /* Should we also complain about unhandled address classes? */
4807 TYPE_LENGTH (type
) = byte_size
;
4808 return set_die_type (die
, type
, cu
);
4811 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4812 the user defined type vector. */
4814 static struct type
*
4815 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4817 struct objfile
*objfile
= cu
->objfile
;
4819 struct type
*to_type
;
4820 struct type
*domain
;
4822 to_type
= die_type (die
, cu
);
4823 domain
= die_containing_type (die
, cu
);
4825 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4826 type
= lookup_methodptr_type (to_type
);
4828 type
= lookup_memberptr_type (to_type
, domain
);
4830 return set_die_type (die
, type
, cu
);
4833 /* Extract all information from a DW_TAG_reference_type DIE and add to
4834 the user defined type vector. */
4836 static struct type
*
4837 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4839 struct comp_unit_head
*cu_header
= &cu
->header
;
4841 struct attribute
*attr
;
4843 type
= lookup_reference_type (die_type (die
, cu
));
4844 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4847 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4851 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4853 return set_die_type (die
, type
, cu
);
4856 static struct type
*
4857 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4859 struct type
*base_type
, *cv_type
;
4861 base_type
= die_type (die
, cu
);
4862 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4863 return set_die_type (die
, cv_type
, cu
);
4866 static struct type
*
4867 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4869 struct type
*base_type
, *cv_type
;
4871 base_type
= die_type (die
, cu
);
4872 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4873 return set_die_type (die
, cv_type
, cu
);
4876 /* Extract all information from a DW_TAG_string_type DIE and add to
4877 the user defined type vector. It isn't really a user defined type,
4878 but it behaves like one, with other DIE's using an AT_user_def_type
4879 attribute to reference it. */
4881 static struct type
*
4882 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4884 struct objfile
*objfile
= cu
->objfile
;
4885 struct type
*type
, *range_type
, *index_type
, *char_type
;
4886 struct attribute
*attr
;
4887 unsigned int length
;
4889 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4892 length
= DW_UNSND (attr
);
4896 /* check for the DW_AT_byte_size attribute */
4897 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4900 length
= DW_UNSND (attr
);
4908 index_type
= builtin_type_int32
;
4909 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4910 type
= create_string_type (NULL
, range_type
);
4912 return set_die_type (die
, type
, cu
);
4915 /* Handle DIES due to C code like:
4919 int (*funcp)(int a, long l);
4923 ('funcp' generates a DW_TAG_subroutine_type DIE)
4926 static struct type
*
4927 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4929 struct type
*type
; /* Type that this function returns */
4930 struct type
*ftype
; /* Function that returns above type */
4931 struct attribute
*attr
;
4933 type
= die_type (die
, cu
);
4934 ftype
= make_function_type (type
, (struct type
**) 0);
4936 /* All functions in C++, Pascal and Java have prototypes. */
4937 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4938 if ((attr
&& (DW_UNSND (attr
) != 0))
4939 || cu
->language
== language_cplus
4940 || cu
->language
== language_java
4941 || cu
->language
== language_pascal
)
4942 TYPE_PROTOTYPED (ftype
) = 1;
4944 /* Store the calling convention in the type if it's available in
4945 the subroutine die. Otherwise set the calling convention to
4946 the default value DW_CC_normal. */
4947 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4948 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4950 if (die
->child
!= NULL
)
4952 struct die_info
*child_die
;
4956 /* Count the number of parameters.
4957 FIXME: GDB currently ignores vararg functions, but knows about
4958 vararg member functions. */
4959 child_die
= die
->child
;
4960 while (child_die
&& child_die
->tag
)
4962 if (child_die
->tag
== DW_TAG_formal_parameter
)
4964 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4965 TYPE_VARARGS (ftype
) = 1;
4966 child_die
= sibling_die (child_die
);
4969 /* Allocate storage for parameters and fill them in. */
4970 TYPE_NFIELDS (ftype
) = nparams
;
4971 TYPE_FIELDS (ftype
) = (struct field
*)
4972 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4974 child_die
= die
->child
;
4975 while (child_die
&& child_die
->tag
)
4977 if (child_die
->tag
== DW_TAG_formal_parameter
)
4979 /* Dwarf2 has no clean way to discern C++ static and non-static
4980 member functions. G++ helps GDB by marking the first
4981 parameter for non-static member functions (which is the
4982 this pointer) as artificial. We pass this information
4983 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4984 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4986 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4988 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4989 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4992 child_die
= sibling_die (child_die
);
4996 return set_die_type (die
, ftype
, cu
);
4999 static struct type
*
5000 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5002 struct objfile
*objfile
= cu
->objfile
;
5003 struct attribute
*attr
;
5004 const char *name
= NULL
;
5005 struct type
*this_type
;
5007 name
= dwarf2_full_name (die
, cu
);
5008 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5009 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5010 TYPE_NAME (this_type
) = (char *) name
;
5011 set_die_type (die
, this_type
, cu
);
5012 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5016 /* Find a representation of a given base type and install
5017 it in the TYPE field of the die. */
5019 static struct type
*
5020 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5022 struct objfile
*objfile
= cu
->objfile
;
5024 struct attribute
*attr
;
5025 int encoding
= 0, size
= 0;
5027 enum type_code code
= TYPE_CODE_INT
;
5029 struct type
*target_type
= NULL
;
5031 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5034 encoding
= DW_UNSND (attr
);
5036 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5039 size
= DW_UNSND (attr
);
5041 name
= dwarf2_name (die
, cu
);
5044 complaint (&symfile_complaints
,
5045 _("DW_AT_name missing from DW_TAG_base_type"));
5050 case DW_ATE_address
:
5051 /* Turn DW_ATE_address into a void * pointer. */
5052 code
= TYPE_CODE_PTR
;
5053 type_flags
|= TYPE_FLAG_UNSIGNED
;
5054 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5056 case DW_ATE_boolean
:
5057 code
= TYPE_CODE_BOOL
;
5058 type_flags
|= TYPE_FLAG_UNSIGNED
;
5060 case DW_ATE_complex_float
:
5061 code
= TYPE_CODE_COMPLEX
;
5062 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5064 case DW_ATE_decimal_float
:
5065 code
= TYPE_CODE_DECFLOAT
;
5068 code
= TYPE_CODE_FLT
;
5072 case DW_ATE_unsigned
:
5073 type_flags
|= TYPE_FLAG_UNSIGNED
;
5075 case DW_ATE_signed_char
:
5076 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5077 code
= TYPE_CODE_CHAR
;
5079 case DW_ATE_unsigned_char
:
5080 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5081 code
= TYPE_CODE_CHAR
;
5082 type_flags
|= TYPE_FLAG_UNSIGNED
;
5085 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5086 dwarf_type_encoding_name (encoding
));
5090 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5091 TYPE_NAME (type
) = name
;
5092 TYPE_TARGET_TYPE (type
) = target_type
;
5094 if (name
&& strcmp (name
, "char") == 0)
5095 TYPE_NOSIGN (type
) = 1;
5097 return set_die_type (die
, type
, cu
);
5100 /* Read the given DW_AT_subrange DIE. */
5102 static struct type
*
5103 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5105 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5106 struct type
*base_type
;
5107 struct type
*range_type
;
5108 struct attribute
*attr
;
5113 base_type
= die_type (die
, cu
);
5114 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5116 complaint (&symfile_complaints
,
5117 _("DW_AT_type missing from DW_TAG_subrange_type"));
5119 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5120 0, NULL
, cu
->objfile
);
5123 if (cu
->language
== language_fortran
)
5125 /* FORTRAN implies a lower bound of 1, if not given. */
5129 /* FIXME: For variable sized arrays either of these could be
5130 a variable rather than a constant value. We'll allow it,
5131 but we don't know how to handle it. */
5132 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5134 low
= dwarf2_get_attr_constant_value (attr
, 0);
5136 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5139 if (attr
->form
== DW_FORM_block1
)
5141 /* GCC encodes arrays with unspecified or dynamic length
5142 with a DW_FORM_block1 attribute.
5143 FIXME: GDB does not yet know how to handle dynamic
5144 arrays properly, treat them as arrays with unspecified
5147 FIXME: jimb/2003-09-22: GDB does not really know
5148 how to handle arrays of unspecified length
5149 either; we just represent them as zero-length
5150 arrays. Choose an appropriate upper bound given
5151 the lower bound we've computed above. */
5155 high
= dwarf2_get_attr_constant_value (attr
, 1);
5158 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5160 name
= dwarf2_name (die
, cu
);
5162 TYPE_NAME (range_type
) = name
;
5164 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5166 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5168 return set_die_type (die
, range_type
, cu
);
5171 static struct type
*
5172 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5176 /* For now, we only support the C meaning of an unspecified type: void. */
5178 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5179 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5181 return set_die_type (die
, type
, cu
);
5184 /* Trivial hash function for die_info: the hash value of a DIE
5185 is its offset in .debug_info for this objfile. */
5188 die_hash (const void *item
)
5190 const struct die_info
*die
= item
;
5194 /* Trivial comparison function for die_info structures: two DIEs
5195 are equal if they have the same offset. */
5198 die_eq (const void *item_lhs
, const void *item_rhs
)
5200 const struct die_info
*die_lhs
= item_lhs
;
5201 const struct die_info
*die_rhs
= item_rhs
;
5202 return die_lhs
->offset
== die_rhs
->offset
;
5205 /* Read a whole compilation unit into a linked list of dies. */
5207 static struct die_info
*
5208 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5211 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5215 &cu
->comp_unit_obstack
,
5216 hashtab_obstack_allocate
,
5217 dummy_obstack_deallocate
);
5219 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5222 /* Main entry point for reading a DIE and all children.
5223 Read the DIE and dump it if requested. */
5225 static struct die_info
*
5226 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5227 struct dwarf2_cu
*cu
,
5228 gdb_byte
**new_info_ptr
,
5229 struct die_info
*parent
)
5231 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5232 new_info_ptr
, parent
);
5234 if (dwarf2_die_debug
)
5236 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5237 dump_die (result
, dwarf2_die_debug
);
5243 /* Read a single die and all its descendents. Set the die's sibling
5244 field to NULL; set other fields in the die correctly, and set all
5245 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5246 location of the info_ptr after reading all of those dies. PARENT
5247 is the parent of the die in question. */
5249 static struct die_info
*
5250 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5251 struct dwarf2_cu
*cu
,
5252 gdb_byte
**new_info_ptr
,
5253 struct die_info
*parent
)
5255 struct die_info
*die
;
5259 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5262 *new_info_ptr
= cur_ptr
;
5265 store_in_ref_table (die
, cu
);
5269 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5275 *new_info_ptr
= cur_ptr
;
5278 die
->sibling
= NULL
;
5279 die
->parent
= parent
;
5283 /* Read a die, all of its descendents, and all of its siblings; set
5284 all of the fields of all of the dies correctly. Arguments are as
5285 in read_die_and_children. */
5287 static struct die_info
*
5288 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5289 struct dwarf2_cu
*cu
,
5290 gdb_byte
**new_info_ptr
,
5291 struct die_info
*parent
)
5293 struct die_info
*first_die
, *last_sibling
;
5297 first_die
= last_sibling
= NULL
;
5301 struct die_info
*die
5302 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5306 *new_info_ptr
= cur_ptr
;
5313 last_sibling
->sibling
= die
;
5319 /* Decompress a section that was compressed using zlib. Store the
5320 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5323 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5324 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5326 bfd
*abfd
= objfile
->obfd
;
5328 error (_("Support for zlib-compressed DWARF data (from '%s') "
5329 "is disabled in this copy of GDB"),
5330 bfd_get_filename (abfd
));
5332 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5333 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5334 bfd_size_type uncompressed_size
;
5335 gdb_byte
*uncompressed_buffer
;
5338 int header_size
= 12;
5340 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5341 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5342 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5343 bfd_get_filename (abfd
));
5345 /* Read the zlib header. In this case, it should be "ZLIB" followed
5346 by the uncompressed section size, 8 bytes in big-endian order. */
5347 if (compressed_size
< header_size
5348 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5349 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5350 bfd_get_filename (abfd
));
5351 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5352 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5353 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5354 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5355 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5356 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5357 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5358 uncompressed_size
+= compressed_buffer
[11];
5360 /* It is possible the section consists of several compressed
5361 buffers concatenated together, so we uncompress in a loop. */
5365 strm
.avail_in
= compressed_size
- header_size
;
5366 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5367 strm
.avail_out
= uncompressed_size
;
5368 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5370 rc
= inflateInit (&strm
);
5371 while (strm
.avail_in
> 0)
5374 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5375 bfd_get_filename (abfd
), rc
);
5376 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5377 + (uncompressed_size
- strm
.avail_out
));
5378 rc
= inflate (&strm
, Z_FINISH
);
5379 if (rc
!= Z_STREAM_END
)
5380 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5381 bfd_get_filename (abfd
), rc
);
5382 rc
= inflateReset (&strm
);
5384 rc
= inflateEnd (&strm
);
5386 || strm
.avail_out
!= 0)
5387 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5388 bfd_get_filename (abfd
), rc
);
5390 xfree (compressed_buffer
);
5391 *outbuf
= uncompressed_buffer
;
5392 *outsize
= uncompressed_size
;
5397 /* Read the contents of the section at OFFSET and of size SIZE from the
5398 object file specified by OBJFILE into the objfile_obstack and return it.
5399 If the section is compressed, uncompress it before returning. */
5402 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5404 bfd
*abfd
= objfile
->obfd
;
5405 gdb_byte
*buf
, *retbuf
;
5406 bfd_size_type size
= bfd_get_section_size (sectp
);
5407 unsigned char header
[4];
5412 /* Check if the file has a 4-byte header indicating compression. */
5413 if (size
> sizeof (header
)
5414 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5415 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5417 /* Upon decompression, update the buffer and its size. */
5418 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5420 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5421 dwarf2_resize_section (sectp
, size
);
5426 /* If we get here, we are a normal, not-compressed section. */
5427 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5428 /* When debugging .o files, we may need to apply relocations; see
5429 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5430 We never compress sections in .o files, so we only need to
5431 try this when the section is not compressed. */
5432 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5436 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5437 || bfd_bread (buf
, size
, abfd
) != size
)
5438 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5439 bfd_get_filename (abfd
));
5444 /* In DWARF version 2, the description of the debugging information is
5445 stored in a separate .debug_abbrev section. Before we read any
5446 dies from a section we read in all abbreviations and install them
5447 in a hash table. This function also sets flags in CU describing
5448 the data found in the abbrev table. */
5451 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5453 struct comp_unit_head
*cu_header
= &cu
->header
;
5454 gdb_byte
*abbrev_ptr
;
5455 struct abbrev_info
*cur_abbrev
;
5456 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5457 unsigned int abbrev_form
, hash_number
;
5458 struct attr_abbrev
*cur_attrs
;
5459 unsigned int allocated_attrs
;
5461 /* Initialize dwarf2 abbrevs */
5462 obstack_init (&cu
->abbrev_obstack
);
5463 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5465 * sizeof (struct abbrev_info
*)));
5466 memset (cu
->dwarf2_abbrevs
, 0,
5467 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5469 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5470 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5471 abbrev_ptr
+= bytes_read
;
5473 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5474 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5476 /* loop until we reach an abbrev number of 0 */
5477 while (abbrev_number
)
5479 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5481 /* read in abbrev header */
5482 cur_abbrev
->number
= abbrev_number
;
5483 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5484 abbrev_ptr
+= bytes_read
;
5485 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5488 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5489 cu
->has_namespace_info
= 1;
5491 /* now read in declarations */
5492 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5493 abbrev_ptr
+= bytes_read
;
5494 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5495 abbrev_ptr
+= bytes_read
;
5498 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5500 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5502 = xrealloc (cur_attrs
, (allocated_attrs
5503 * sizeof (struct attr_abbrev
)));
5506 /* Record whether this compilation unit might have
5507 inter-compilation-unit references. If we don't know what form
5508 this attribute will have, then it might potentially be a
5509 DW_FORM_ref_addr, so we conservatively expect inter-CU
5512 if (abbrev_form
== DW_FORM_ref_addr
5513 || abbrev_form
== DW_FORM_indirect
)
5514 cu
->has_form_ref_addr
= 1;
5516 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5517 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5518 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5519 abbrev_ptr
+= bytes_read
;
5520 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5521 abbrev_ptr
+= bytes_read
;
5524 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5525 (cur_abbrev
->num_attrs
5526 * sizeof (struct attr_abbrev
)));
5527 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5528 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5530 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5531 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5532 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5534 /* Get next abbreviation.
5535 Under Irix6 the abbreviations for a compilation unit are not
5536 always properly terminated with an abbrev number of 0.
5537 Exit loop if we encounter an abbreviation which we have
5538 already read (which means we are about to read the abbreviations
5539 for the next compile unit) or if the end of the abbreviation
5540 table is reached. */
5541 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5542 >= dwarf2_per_objfile
->abbrev_size
)
5544 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5545 abbrev_ptr
+= bytes_read
;
5546 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5553 /* Release the memory used by the abbrev table for a compilation unit. */
5556 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5558 struct dwarf2_cu
*cu
= ptr_to_cu
;
5560 obstack_free (&cu
->abbrev_obstack
, NULL
);
5561 cu
->dwarf2_abbrevs
= NULL
;
5564 /* Lookup an abbrev_info structure in the abbrev hash table. */
5566 static struct abbrev_info
*
5567 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5569 unsigned int hash_number
;
5570 struct abbrev_info
*abbrev
;
5572 hash_number
= number
% ABBREV_HASH_SIZE
;
5573 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5577 if (abbrev
->number
== number
)
5580 abbrev
= abbrev
->next
;
5585 /* Returns nonzero if TAG represents a type that we might generate a partial
5589 is_type_tag_for_partial (int tag
)
5594 /* Some types that would be reasonable to generate partial symbols for,
5595 that we don't at present. */
5596 case DW_TAG_array_type
:
5597 case DW_TAG_file_type
:
5598 case DW_TAG_ptr_to_member_type
:
5599 case DW_TAG_set_type
:
5600 case DW_TAG_string_type
:
5601 case DW_TAG_subroutine_type
:
5603 case DW_TAG_base_type
:
5604 case DW_TAG_class_type
:
5605 case DW_TAG_interface_type
:
5606 case DW_TAG_enumeration_type
:
5607 case DW_TAG_structure_type
:
5608 case DW_TAG_subrange_type
:
5609 case DW_TAG_typedef
:
5610 case DW_TAG_union_type
:
5617 /* Load all DIEs that are interesting for partial symbols into memory. */
5619 static struct partial_die_info
*
5620 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5621 struct dwarf2_cu
*cu
)
5623 struct partial_die_info
*part_die
;
5624 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5625 struct abbrev_info
*abbrev
;
5626 unsigned int bytes_read
;
5627 unsigned int load_all
= 0;
5629 int nesting_level
= 1;
5634 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5638 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5642 &cu
->comp_unit_obstack
,
5643 hashtab_obstack_allocate
,
5644 dummy_obstack_deallocate
);
5646 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5647 sizeof (struct partial_die_info
));
5651 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5653 /* A NULL abbrev means the end of a series of children. */
5656 if (--nesting_level
== 0)
5658 /* PART_DIE was probably the last thing allocated on the
5659 comp_unit_obstack, so we could call obstack_free
5660 here. We don't do that because the waste is small,
5661 and will be cleaned up when we're done with this
5662 compilation unit. This way, we're also more robust
5663 against other users of the comp_unit_obstack. */
5666 info_ptr
+= bytes_read
;
5667 last_die
= parent_die
;
5668 parent_die
= parent_die
->die_parent
;
5672 /* Check whether this DIE is interesting enough to save. Normally
5673 we would not be interested in members here, but there may be
5674 later variables referencing them via DW_AT_specification (for
5677 && !is_type_tag_for_partial (abbrev
->tag
)
5678 && abbrev
->tag
!= DW_TAG_enumerator
5679 && abbrev
->tag
!= DW_TAG_subprogram
5680 && abbrev
->tag
!= DW_TAG_lexical_block
5681 && abbrev
->tag
!= DW_TAG_variable
5682 && abbrev
->tag
!= DW_TAG_namespace
5683 && abbrev
->tag
!= DW_TAG_member
)
5685 /* Otherwise we skip to the next sibling, if any. */
5686 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5690 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5691 abfd
, info_ptr
, cu
);
5693 /* This two-pass algorithm for processing partial symbols has a
5694 high cost in cache pressure. Thus, handle some simple cases
5695 here which cover the majority of C partial symbols. DIEs
5696 which neither have specification tags in them, nor could have
5697 specification tags elsewhere pointing at them, can simply be
5698 processed and discarded.
5700 This segment is also optional; scan_partial_symbols and
5701 add_partial_symbol will handle these DIEs if we chain
5702 them in normally. When compilers which do not emit large
5703 quantities of duplicate debug information are more common,
5704 this code can probably be removed. */
5706 /* Any complete simple types at the top level (pretty much all
5707 of them, for a language without namespaces), can be processed
5709 if (parent_die
== NULL
5710 && part_die
->has_specification
== 0
5711 && part_die
->is_declaration
== 0
5712 && (part_die
->tag
== DW_TAG_typedef
5713 || part_die
->tag
== DW_TAG_base_type
5714 || part_die
->tag
== DW_TAG_subrange_type
))
5716 if (building_psymtab
&& part_die
->name
!= NULL
)
5717 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5718 VAR_DOMAIN
, LOC_TYPEDEF
,
5719 &cu
->objfile
->static_psymbols
,
5720 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5721 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5725 /* If we're at the second level, and we're an enumerator, and
5726 our parent has no specification (meaning possibly lives in a
5727 namespace elsewhere), then we can add the partial symbol now
5728 instead of queueing it. */
5729 if (part_die
->tag
== DW_TAG_enumerator
5730 && parent_die
!= NULL
5731 && parent_die
->die_parent
== NULL
5732 && parent_die
->tag
== DW_TAG_enumeration_type
5733 && parent_die
->has_specification
== 0)
5735 if (part_die
->name
== NULL
)
5736 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5737 else if (building_psymtab
)
5738 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5739 VAR_DOMAIN
, LOC_CONST
,
5740 (cu
->language
== language_cplus
5741 || cu
->language
== language_java
)
5742 ? &cu
->objfile
->global_psymbols
5743 : &cu
->objfile
->static_psymbols
,
5744 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5746 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5750 /* We'll save this DIE so link it in. */
5751 part_die
->die_parent
= parent_die
;
5752 part_die
->die_sibling
= NULL
;
5753 part_die
->die_child
= NULL
;
5755 if (last_die
&& last_die
== parent_die
)
5756 last_die
->die_child
= part_die
;
5758 last_die
->die_sibling
= part_die
;
5760 last_die
= part_die
;
5762 if (first_die
== NULL
)
5763 first_die
= part_die
;
5765 /* Maybe add the DIE to the hash table. Not all DIEs that we
5766 find interesting need to be in the hash table, because we
5767 also have the parent/sibling/child chains; only those that we
5768 might refer to by offset later during partial symbol reading.
5770 For now this means things that might have be the target of a
5771 DW_AT_specification, DW_AT_abstract_origin, or
5772 DW_AT_extension. DW_AT_extension will refer only to
5773 namespaces; DW_AT_abstract_origin refers to functions (and
5774 many things under the function DIE, but we do not recurse
5775 into function DIEs during partial symbol reading) and
5776 possibly variables as well; DW_AT_specification refers to
5777 declarations. Declarations ought to have the DW_AT_declaration
5778 flag. It happens that GCC forgets to put it in sometimes, but
5779 only for functions, not for types.
5781 Adding more things than necessary to the hash table is harmless
5782 except for the performance cost. Adding too few will result in
5783 wasted time in find_partial_die, when we reread the compilation
5784 unit with load_all_dies set. */
5787 || abbrev
->tag
== DW_TAG_subprogram
5788 || abbrev
->tag
== DW_TAG_variable
5789 || abbrev
->tag
== DW_TAG_namespace
5790 || part_die
->is_declaration
)
5794 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5795 part_die
->offset
, INSERT
);
5799 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5800 sizeof (struct partial_die_info
));
5802 /* For some DIEs we want to follow their children (if any). For C
5803 we have no reason to follow the children of structures; for other
5804 languages we have to, both so that we can get at method physnames
5805 to infer fully qualified class names, and for DW_AT_specification.
5807 For Ada, we need to scan the children of subprograms and lexical
5808 blocks as well because Ada allows the definition of nested
5809 entities that could be interesting for the debugger, such as
5810 nested subprograms for instance. */
5811 if (last_die
->has_children
5813 || last_die
->tag
== DW_TAG_namespace
5814 || last_die
->tag
== DW_TAG_enumeration_type
5815 || (cu
->language
!= language_c
5816 && (last_die
->tag
== DW_TAG_class_type
5817 || last_die
->tag
== DW_TAG_interface_type
5818 || last_die
->tag
== DW_TAG_structure_type
5819 || last_die
->tag
== DW_TAG_union_type
))
5820 || (cu
->language
== language_ada
5821 && (last_die
->tag
== DW_TAG_subprogram
5822 || last_die
->tag
== DW_TAG_lexical_block
))))
5825 parent_die
= last_die
;
5829 /* Otherwise we skip to the next sibling, if any. */
5830 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5832 /* Back to the top, do it again. */
5836 /* Read a minimal amount of information into the minimal die structure. */
5839 read_partial_die (struct partial_die_info
*part_die
,
5840 struct abbrev_info
*abbrev
,
5841 unsigned int abbrev_len
, bfd
*abfd
,
5842 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5844 unsigned int bytes_read
, i
;
5845 struct attribute attr
;
5846 int has_low_pc_attr
= 0;
5847 int has_high_pc_attr
= 0;
5848 CORE_ADDR base_address
= 0;
5852 base_address_low_pc
,
5853 /* Overrides BASE_ADDRESS_LOW_PC. */
5854 base_address_entry_pc
5856 base_address_type
= base_address_none
;
5858 memset (part_die
, 0, sizeof (struct partial_die_info
));
5860 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5862 info_ptr
+= abbrev_len
;
5867 part_die
->tag
= abbrev
->tag
;
5868 part_die
->has_children
= abbrev
->has_children
;
5870 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5872 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5874 /* Store the data if it is of an attribute we want to keep in a
5875 partial symbol table. */
5880 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5881 if (part_die
->name
== NULL
)
5882 part_die
->name
= DW_STRING (&attr
);
5884 case DW_AT_comp_dir
:
5885 if (part_die
->dirname
== NULL
)
5886 part_die
->dirname
= DW_STRING (&attr
);
5888 case DW_AT_MIPS_linkage_name
:
5889 part_die
->name
= DW_STRING (&attr
);
5892 has_low_pc_attr
= 1;
5893 part_die
->lowpc
= DW_ADDR (&attr
);
5894 if (part_die
->tag
== DW_TAG_compile_unit
5895 && base_address_type
< base_address_low_pc
)
5897 base_address
= DW_ADDR (&attr
);
5898 base_address_type
= base_address_low_pc
;
5902 has_high_pc_attr
= 1;
5903 part_die
->highpc
= DW_ADDR (&attr
);
5905 case DW_AT_entry_pc
:
5906 if (part_die
->tag
== DW_TAG_compile_unit
5907 && base_address_type
< base_address_entry_pc
)
5909 base_address
= DW_ADDR (&attr
);
5910 base_address_type
= base_address_entry_pc
;
5914 if (part_die
->tag
== DW_TAG_compile_unit
)
5916 cu
->ranges_offset
= DW_UNSND (&attr
);
5917 cu
->has_ranges_offset
= 1;
5920 case DW_AT_location
:
5921 /* Support the .debug_loc offsets */
5922 if (attr_form_is_block (&attr
))
5924 part_die
->locdesc
= DW_BLOCK (&attr
);
5926 else if (attr_form_is_section_offset (&attr
))
5928 dwarf2_complex_location_expr_complaint ();
5932 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5933 "partial symbol information");
5936 case DW_AT_language
:
5937 part_die
->language
= DW_UNSND (&attr
);
5939 case DW_AT_external
:
5940 part_die
->is_external
= DW_UNSND (&attr
);
5942 case DW_AT_declaration
:
5943 part_die
->is_declaration
= DW_UNSND (&attr
);
5946 part_die
->has_type
= 1;
5948 case DW_AT_abstract_origin
:
5949 case DW_AT_specification
:
5950 case DW_AT_extension
:
5951 part_die
->has_specification
= 1;
5952 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
5955 /* Ignore absolute siblings, they might point outside of
5956 the current compile unit. */
5957 if (attr
.form
== DW_FORM_ref_addr
)
5958 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5960 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5961 + dwarf2_get_ref_die_offset (&attr
);
5963 case DW_AT_stmt_list
:
5964 part_die
->has_stmt_list
= 1;
5965 part_die
->line_offset
= DW_UNSND (&attr
);
5967 case DW_AT_byte_size
:
5968 part_die
->has_byte_size
= 1;
5970 case DW_AT_calling_convention
:
5971 /* DWARF doesn't provide a way to identify a program's source-level
5972 entry point. DW_AT_calling_convention attributes are only meant
5973 to describe functions' calling conventions.
5975 However, because it's a necessary piece of information in
5976 Fortran, and because DW_CC_program is the only piece of debugging
5977 information whose definition refers to a 'main program' at all,
5978 several compilers have begun marking Fortran main programs with
5979 DW_CC_program --- even when those functions use the standard
5980 calling conventions.
5982 So until DWARF specifies a way to provide this information and
5983 compilers pick up the new representation, we'll support this
5985 if (DW_UNSND (&attr
) == DW_CC_program
5986 && cu
->language
== language_fortran
)
5987 set_main_name (part_die
->name
);
5994 /* When using the GNU linker, .gnu.linkonce. sections are used to
5995 eliminate duplicate copies of functions and vtables and such.
5996 The linker will arbitrarily choose one and discard the others.
5997 The AT_*_pc values for such functions refer to local labels in
5998 these sections. If the section from that file was discarded, the
5999 labels are not in the output, so the relocs get a value of 0.
6000 If this is a discarded function, mark the pc bounds as invalid,
6001 so that GDB will ignore it. */
6002 if (has_low_pc_attr
&& has_high_pc_attr
6003 && part_die
->lowpc
< part_die
->highpc
6004 && (part_die
->lowpc
!= 0
6005 || dwarf2_per_objfile
->has_section_at_zero
))
6006 part_die
->has_pc_info
= 1;
6008 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6010 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6012 cu
->base_address
= base_address
;
6018 /* Find a cached partial DIE at OFFSET in CU. */
6020 static struct partial_die_info
*
6021 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6023 struct partial_die_info
*lookup_die
= NULL
;
6024 struct partial_die_info part_die
;
6026 part_die
.offset
= offset
;
6027 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6032 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6034 static struct partial_die_info
*
6035 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6037 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6038 struct partial_die_info
*pd
= NULL
;
6040 if (offset_in_cu_p (&cu
->header
, offset
))
6042 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6047 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6049 if (per_cu
->cu
== NULL
)
6051 load_comp_unit (per_cu
, cu
->objfile
);
6052 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6053 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6056 per_cu
->cu
->last_used
= 0;
6057 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6059 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6061 struct cleanup
*back_to
;
6062 struct partial_die_info comp_unit_die
;
6063 struct abbrev_info
*abbrev
;
6064 unsigned int bytes_read
;
6067 per_cu
->load_all_dies
= 1;
6069 /* Re-read the DIEs. */
6070 back_to
= make_cleanup (null_cleanup
, 0);
6071 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6073 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6074 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6076 info_ptr
= (dwarf2_per_objfile
->info_buffer
6077 + per_cu
->cu
->header
.offset
6078 + per_cu
->cu
->header
.first_die_offset
);
6079 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6080 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6081 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6083 if (comp_unit_die
.has_children
)
6084 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6085 do_cleanups (back_to
);
6087 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6091 internal_error (__FILE__
, __LINE__
,
6092 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6093 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6097 /* Adjust PART_DIE before generating a symbol for it. This function
6098 may set the is_external flag or change the DIE's name. */
6101 fixup_partial_die (struct partial_die_info
*part_die
,
6102 struct dwarf2_cu
*cu
)
6104 /* If we found a reference attribute and the DIE has no name, try
6105 to find a name in the referred to DIE. */
6107 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6109 struct partial_die_info
*spec_die
;
6111 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6113 fixup_partial_die (spec_die
, cu
);
6117 part_die
->name
= spec_die
->name
;
6119 /* Copy DW_AT_external attribute if it is set. */
6120 if (spec_die
->is_external
)
6121 part_die
->is_external
= spec_die
->is_external
;
6125 /* Set default names for some unnamed DIEs. */
6126 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6127 || part_die
->tag
== DW_TAG_class_type
))
6128 part_die
->name
= "(anonymous class)";
6130 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6131 part_die
->name
= "(anonymous namespace)";
6133 if (part_die
->tag
== DW_TAG_structure_type
6134 || part_die
->tag
== DW_TAG_class_type
6135 || part_die
->tag
== DW_TAG_union_type
)
6136 guess_structure_name (part_die
, cu
);
6139 /* Read the die from the .debug_info section buffer. Set DIEP to
6140 point to a newly allocated die with its information, except for its
6141 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6142 whether the die has children or not. */
6145 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6146 struct dwarf2_cu
*cu
, int *has_children
)
6148 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6149 struct abbrev_info
*abbrev
;
6150 struct die_info
*die
;
6152 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6153 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6154 info_ptr
+= bytes_read
;
6162 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6165 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6167 bfd_get_filename (abfd
));
6169 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6170 die
->offset
= offset
;
6171 die
->tag
= abbrev
->tag
;
6172 die
->abbrev
= abbrev_number
;
6174 die
->num_attrs
= abbrev
->num_attrs
;
6176 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6177 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6178 abfd
, info_ptr
, cu
);
6181 *has_children
= abbrev
->has_children
;
6185 /* Read an attribute value described by an attribute form. */
6188 read_attribute_value (struct attribute
*attr
, unsigned form
,
6189 bfd
*abfd
, gdb_byte
*info_ptr
,
6190 struct dwarf2_cu
*cu
)
6192 struct comp_unit_head
*cu_header
= &cu
->header
;
6193 unsigned int bytes_read
;
6194 struct dwarf_block
*blk
;
6200 case DW_FORM_ref_addr
:
6201 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6202 info_ptr
+= bytes_read
;
6204 case DW_FORM_block2
:
6205 blk
= dwarf_alloc_block (cu
);
6206 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6208 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6209 info_ptr
+= blk
->size
;
6210 DW_BLOCK (attr
) = blk
;
6212 case DW_FORM_block4
:
6213 blk
= dwarf_alloc_block (cu
);
6214 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6216 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6217 info_ptr
+= blk
->size
;
6218 DW_BLOCK (attr
) = blk
;
6221 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6225 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6229 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6232 case DW_FORM_string
:
6233 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6234 info_ptr
+= bytes_read
;
6237 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6239 info_ptr
+= bytes_read
;
6242 blk
= dwarf_alloc_block (cu
);
6243 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6244 info_ptr
+= bytes_read
;
6245 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6246 info_ptr
+= blk
->size
;
6247 DW_BLOCK (attr
) = blk
;
6249 case DW_FORM_block1
:
6250 blk
= dwarf_alloc_block (cu
);
6251 blk
->size
= read_1_byte (abfd
, info_ptr
);
6253 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6254 info_ptr
+= blk
->size
;
6255 DW_BLOCK (attr
) = blk
;
6258 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6262 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6266 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6267 info_ptr
+= bytes_read
;
6270 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6271 info_ptr
+= bytes_read
;
6274 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6278 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6282 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6286 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6289 case DW_FORM_ref_udata
:
6290 DW_ADDR (attr
) = (cu
->header
.offset
6291 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6292 info_ptr
+= bytes_read
;
6294 case DW_FORM_indirect
:
6295 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6296 info_ptr
+= bytes_read
;
6297 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6300 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6301 dwarf_form_name (form
),
6302 bfd_get_filename (abfd
));
6305 /* We have seen instances where the compiler tried to emit a byte
6306 size attribute of -1 which ended up being encoded as an unsigned
6307 0xffffffff. Although 0xffffffff is technically a valid size value,
6308 an object of this size seems pretty unlikely so we can relatively
6309 safely treat these cases as if the size attribute was invalid and
6310 treat them as zero by default. */
6311 if (attr
->name
== DW_AT_byte_size
6312 && form
== DW_FORM_data4
6313 && DW_UNSND (attr
) >= 0xffffffff)
6316 (&symfile_complaints
,
6317 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6319 DW_UNSND (attr
) = 0;
6325 /* Read an attribute described by an abbreviated attribute. */
6328 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6329 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6331 attr
->name
= abbrev
->name
;
6332 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6335 /* read dwarf information from a buffer */
6338 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6340 return bfd_get_8 (abfd
, buf
);
6344 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6346 return bfd_get_signed_8 (abfd
, buf
);
6350 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6352 return bfd_get_16 (abfd
, buf
);
6356 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6358 return bfd_get_signed_16 (abfd
, buf
);
6362 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6364 return bfd_get_32 (abfd
, buf
);
6368 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6370 return bfd_get_signed_32 (abfd
, buf
);
6373 static unsigned long
6374 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6376 return bfd_get_64 (abfd
, buf
);
6380 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6381 unsigned int *bytes_read
)
6383 struct comp_unit_head
*cu_header
= &cu
->header
;
6384 CORE_ADDR retval
= 0;
6386 if (cu_header
->signed_addr_p
)
6388 switch (cu_header
->addr_size
)
6391 retval
= bfd_get_signed_16 (abfd
, buf
);
6394 retval
= bfd_get_signed_32 (abfd
, buf
);
6397 retval
= bfd_get_signed_64 (abfd
, buf
);
6400 internal_error (__FILE__
, __LINE__
,
6401 _("read_address: bad switch, signed [in module %s]"),
6402 bfd_get_filename (abfd
));
6407 switch (cu_header
->addr_size
)
6410 retval
= bfd_get_16 (abfd
, buf
);
6413 retval
= bfd_get_32 (abfd
, buf
);
6416 retval
= bfd_get_64 (abfd
, buf
);
6419 internal_error (__FILE__
, __LINE__
,
6420 _("read_address: bad switch, unsigned [in module %s]"),
6421 bfd_get_filename (abfd
));
6425 *bytes_read
= cu_header
->addr_size
;
6429 /* Read the initial length from a section. The (draft) DWARF 3
6430 specification allows the initial length to take up either 4 bytes
6431 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6432 bytes describe the length and all offsets will be 8 bytes in length
6435 An older, non-standard 64-bit format is also handled by this
6436 function. The older format in question stores the initial length
6437 as an 8-byte quantity without an escape value. Lengths greater
6438 than 2^32 aren't very common which means that the initial 4 bytes
6439 is almost always zero. Since a length value of zero doesn't make
6440 sense for the 32-bit format, this initial zero can be considered to
6441 be an escape value which indicates the presence of the older 64-bit
6442 format. As written, the code can't detect (old format) lengths
6443 greater than 4GB. If it becomes necessary to handle lengths
6444 somewhat larger than 4GB, we could allow other small values (such
6445 as the non-sensical values of 1, 2, and 3) to also be used as
6446 escape values indicating the presence of the old format.
6448 The value returned via bytes_read should be used to increment the
6449 relevant pointer after calling read_initial_length().
6451 [ Note: read_initial_length() and read_offset() are based on the
6452 document entitled "DWARF Debugging Information Format", revision
6453 3, draft 8, dated November 19, 2001. This document was obtained
6456 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6458 This document is only a draft and is subject to change. (So beware.)
6460 Details regarding the older, non-standard 64-bit format were
6461 determined empirically by examining 64-bit ELF files produced by
6462 the SGI toolchain on an IRIX 6.5 machine.
6464 - Kevin, July 16, 2002
6468 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6470 LONGEST length
= bfd_get_32 (abfd
, buf
);
6472 if (length
== 0xffffffff)
6474 length
= bfd_get_64 (abfd
, buf
+ 4);
6477 else if (length
== 0)
6479 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6480 length
= bfd_get_64 (abfd
, buf
);
6491 /* Cover function for read_initial_length.
6492 Returns the length of the object at BUF, and stores the size of the
6493 initial length in *BYTES_READ and stores the size that offsets will be in
6495 If the initial length size is not equivalent to that specified in
6496 CU_HEADER then issue a complaint.
6497 This is useful when reading non-comp-unit headers. */
6500 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6501 const struct comp_unit_head
*cu_header
,
6502 unsigned int *bytes_read
,
6503 unsigned int *offset_size
)
6505 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6507 gdb_assert (cu_header
->initial_length_size
== 4
6508 || cu_header
->initial_length_size
== 8
6509 || cu_header
->initial_length_size
== 12);
6511 if (cu_header
->initial_length_size
!= *bytes_read
)
6512 complaint (&symfile_complaints
,
6513 _("intermixed 32-bit and 64-bit DWARF sections"));
6515 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6519 /* Read an offset from the data stream. The size of the offset is
6520 given by cu_header->offset_size. */
6523 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6524 unsigned int *bytes_read
)
6526 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6527 *bytes_read
= cu_header
->offset_size
;
6531 /* Read an offset from the data stream. */
6534 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6538 switch (offset_size
)
6541 retval
= bfd_get_32 (abfd
, buf
);
6544 retval
= bfd_get_64 (abfd
, buf
);
6547 internal_error (__FILE__
, __LINE__
,
6548 _("read_offset_1: bad switch [in module %s]"),
6549 bfd_get_filename (abfd
));
6556 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6558 /* If the size of a host char is 8 bits, we can return a pointer
6559 to the buffer, otherwise we have to copy the data to a buffer
6560 allocated on the temporary obstack. */
6561 gdb_assert (HOST_CHAR_BIT
== 8);
6566 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6568 /* If the size of a host char is 8 bits, we can return a pointer
6569 to the string, otherwise we have to copy the string to a buffer
6570 allocated on the temporary obstack. */
6571 gdb_assert (HOST_CHAR_BIT
== 8);
6574 *bytes_read_ptr
= 1;
6577 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6578 return (char *) buf
;
6582 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6583 const struct comp_unit_head
*cu_header
,
6584 unsigned int *bytes_read_ptr
)
6586 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6588 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6590 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6591 bfd_get_filename (abfd
));
6594 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6596 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6597 bfd_get_filename (abfd
));
6600 gdb_assert (HOST_CHAR_BIT
== 8);
6601 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6603 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6606 static unsigned long
6607 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6609 unsigned long result
;
6610 unsigned int num_read
;
6620 byte
= bfd_get_8 (abfd
, buf
);
6623 result
|= ((unsigned long)(byte
& 127) << shift
);
6624 if ((byte
& 128) == 0)
6630 *bytes_read_ptr
= num_read
;
6635 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6638 int i
, shift
, num_read
;
6647 byte
= bfd_get_8 (abfd
, buf
);
6650 result
|= ((long)(byte
& 127) << shift
);
6652 if ((byte
& 128) == 0)
6657 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6658 result
|= -(((long)1) << shift
);
6659 *bytes_read_ptr
= num_read
;
6663 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6666 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6672 byte
= bfd_get_8 (abfd
, buf
);
6674 if ((byte
& 128) == 0)
6680 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6686 cu
->language
= language_c
;
6688 case DW_LANG_C_plus_plus
:
6689 cu
->language
= language_cplus
;
6691 case DW_LANG_Fortran77
:
6692 case DW_LANG_Fortran90
:
6693 case DW_LANG_Fortran95
:
6694 cu
->language
= language_fortran
;
6696 case DW_LANG_Mips_Assembler
:
6697 cu
->language
= language_asm
;
6700 cu
->language
= language_java
;
6704 cu
->language
= language_ada
;
6706 case DW_LANG_Modula2
:
6707 cu
->language
= language_m2
;
6709 case DW_LANG_Pascal83
:
6710 cu
->language
= language_pascal
;
6713 cu
->language
= language_objc
;
6715 case DW_LANG_Cobol74
:
6716 case DW_LANG_Cobol85
:
6718 cu
->language
= language_minimal
;
6721 cu
->language_defn
= language_def (cu
->language
);
6724 /* Return the named attribute or NULL if not there. */
6726 static struct attribute
*
6727 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6730 struct attribute
*spec
= NULL
;
6732 for (i
= 0; i
< die
->num_attrs
; ++i
)
6734 if (die
->attrs
[i
].name
== name
)
6735 return &die
->attrs
[i
];
6736 if (die
->attrs
[i
].name
== DW_AT_specification
6737 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6738 spec
= &die
->attrs
[i
];
6743 die
= follow_die_ref (die
, spec
, &cu
);
6744 return dwarf2_attr (die
, name
, cu
);
6750 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6751 and holds a non-zero value. This function should only be used for
6752 DW_FORM_flag attributes. */
6755 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6757 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6759 return (attr
&& DW_UNSND (attr
));
6763 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6765 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6766 which value is non-zero. However, we have to be careful with
6767 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6768 (via dwarf2_flag_true_p) follows this attribute. So we may
6769 end up accidently finding a declaration attribute that belongs
6770 to a different DIE referenced by the specification attribute,
6771 even though the given DIE does not have a declaration attribute. */
6772 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6773 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6776 /* Return the die giving the specification for DIE, if there is
6777 one. *SPEC_CU is the CU containing DIE on input, and the CU
6778 containing the return value on output. */
6780 static struct die_info
*
6781 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6783 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6786 if (spec_attr
== NULL
)
6789 return follow_die_ref (die
, spec_attr
, spec_cu
);
6792 /* Free the line_header structure *LH, and any arrays and strings it
6795 free_line_header (struct line_header
*lh
)
6797 if (lh
->standard_opcode_lengths
)
6798 xfree (lh
->standard_opcode_lengths
);
6800 /* Remember that all the lh->file_names[i].name pointers are
6801 pointers into debug_line_buffer, and don't need to be freed. */
6803 xfree (lh
->file_names
);
6805 /* Similarly for the include directory names. */
6806 if (lh
->include_dirs
)
6807 xfree (lh
->include_dirs
);
6813 /* Add an entry to LH's include directory table. */
6815 add_include_dir (struct line_header
*lh
, char *include_dir
)
6817 /* Grow the array if necessary. */
6818 if (lh
->include_dirs_size
== 0)
6820 lh
->include_dirs_size
= 1; /* for testing */
6821 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6822 * sizeof (*lh
->include_dirs
));
6824 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6826 lh
->include_dirs_size
*= 2;
6827 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6828 (lh
->include_dirs_size
6829 * sizeof (*lh
->include_dirs
)));
6832 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6836 /* Add an entry to LH's file name table. */
6838 add_file_name (struct line_header
*lh
,
6840 unsigned int dir_index
,
6841 unsigned int mod_time
,
6842 unsigned int length
)
6844 struct file_entry
*fe
;
6846 /* Grow the array if necessary. */
6847 if (lh
->file_names_size
== 0)
6849 lh
->file_names_size
= 1; /* for testing */
6850 lh
->file_names
= xmalloc (lh
->file_names_size
6851 * sizeof (*lh
->file_names
));
6853 else if (lh
->num_file_names
>= lh
->file_names_size
)
6855 lh
->file_names_size
*= 2;
6856 lh
->file_names
= xrealloc (lh
->file_names
,
6857 (lh
->file_names_size
6858 * sizeof (*lh
->file_names
)));
6861 fe
= &lh
->file_names
[lh
->num_file_names
++];
6863 fe
->dir_index
= dir_index
;
6864 fe
->mod_time
= mod_time
;
6865 fe
->length
= length
;
6871 /* Read the statement program header starting at OFFSET in
6872 .debug_line, according to the endianness of ABFD. Return a pointer
6873 to a struct line_header, allocated using xmalloc.
6875 NOTE: the strings in the include directory and file name tables of
6876 the returned object point into debug_line_buffer, and must not be
6878 static struct line_header
*
6879 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6880 struct dwarf2_cu
*cu
)
6882 struct cleanup
*back_to
;
6883 struct line_header
*lh
;
6885 unsigned int bytes_read
, offset_size
;
6887 char *cur_dir
, *cur_file
;
6889 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6891 complaint (&symfile_complaints
, _("missing .debug_line section"));
6895 /* Make sure that at least there's room for the total_length field.
6896 That could be 12 bytes long, but we're just going to fudge that. */
6897 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6899 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6903 lh
= xmalloc (sizeof (*lh
));
6904 memset (lh
, 0, sizeof (*lh
));
6905 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6908 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6910 /* Read in the header. */
6912 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
6913 &bytes_read
, &offset_size
);
6914 line_ptr
+= bytes_read
;
6915 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6916 + dwarf2_per_objfile
->line_size
))
6918 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6921 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6922 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6924 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
6925 line_ptr
+= offset_size
;
6926 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6928 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6930 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6932 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6934 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6936 lh
->standard_opcode_lengths
6937 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6939 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6940 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6942 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6946 /* Read directory table. */
6947 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6949 line_ptr
+= bytes_read
;
6950 add_include_dir (lh
, cur_dir
);
6952 line_ptr
+= bytes_read
;
6954 /* Read file name table. */
6955 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6957 unsigned int dir_index
, mod_time
, length
;
6959 line_ptr
+= bytes_read
;
6960 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6961 line_ptr
+= bytes_read
;
6962 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6963 line_ptr
+= bytes_read
;
6964 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6965 line_ptr
+= bytes_read
;
6967 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6969 line_ptr
+= bytes_read
;
6970 lh
->statement_program_start
= line_ptr
;
6972 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6973 + dwarf2_per_objfile
->line_size
))
6974 complaint (&symfile_complaints
,
6975 _("line number info header doesn't fit in `.debug_line' section"));
6977 discard_cleanups (back_to
);
6981 /* This function exists to work around a bug in certain compilers
6982 (particularly GCC 2.95), in which the first line number marker of a
6983 function does not show up until after the prologue, right before
6984 the second line number marker. This function shifts ADDRESS down
6985 to the beginning of the function if necessary, and is called on
6986 addresses passed to record_line. */
6989 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6991 struct function_range
*fn
;
6993 /* Find the function_range containing address. */
6998 cu
->cached_fn
= cu
->first_fn
;
7002 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7008 while (fn
&& fn
!= cu
->cached_fn
)
7009 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7019 if (address
!= fn
->lowpc
)
7020 complaint (&symfile_complaints
,
7021 _("misplaced first line number at 0x%lx for '%s'"),
7022 (unsigned long) address
, fn
->name
);
7027 /* Decode the Line Number Program (LNP) for the given line_header
7028 structure and CU. The actual information extracted and the type
7029 of structures created from the LNP depends on the value of PST.
7031 1. If PST is NULL, then this procedure uses the data from the program
7032 to create all necessary symbol tables, and their linetables.
7033 The compilation directory of the file is passed in COMP_DIR,
7034 and must not be NULL.
7036 2. If PST is not NULL, this procedure reads the program to determine
7037 the list of files included by the unit represented by PST, and
7038 builds all the associated partial symbol tables. In this case,
7039 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7040 is not used to compute the full name of the symtab, and therefore
7041 omitting it when building the partial symtab does not introduce
7042 the potential for inconsistency - a partial symtab and its associated
7043 symbtab having a different fullname -). */
7046 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7047 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7049 gdb_byte
*line_ptr
, *extended_end
;
7051 unsigned int bytes_read
, extended_len
;
7052 unsigned char op_code
, extended_op
, adj_opcode
;
7054 struct objfile
*objfile
= cu
->objfile
;
7055 const int decode_for_pst_p
= (pst
!= NULL
);
7056 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7058 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7060 line_ptr
= lh
->statement_program_start
;
7061 line_end
= lh
->statement_program_end
;
7063 /* Read the statement sequences until there's nothing left. */
7064 while (line_ptr
< line_end
)
7066 /* state machine registers */
7067 CORE_ADDR address
= 0;
7068 unsigned int file
= 1;
7069 unsigned int line
= 1;
7070 unsigned int column
= 0;
7071 int is_stmt
= lh
->default_is_stmt
;
7072 int basic_block
= 0;
7073 int end_sequence
= 0;
7075 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7077 /* Start a subfile for the current file of the state machine. */
7078 /* lh->include_dirs and lh->file_names are 0-based, but the
7079 directory and file name numbers in the statement program
7081 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7085 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7087 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7090 /* Decode the table. */
7091 while (!end_sequence
)
7093 op_code
= read_1_byte (abfd
, line_ptr
);
7096 if (op_code
>= lh
->opcode_base
)
7098 /* Special operand. */
7099 adj_opcode
= op_code
- lh
->opcode_base
;
7100 address
+= (adj_opcode
/ lh
->line_range
)
7101 * lh
->minimum_instruction_length
;
7102 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7103 if (lh
->num_file_names
< file
)
7104 dwarf2_debug_line_missing_file_complaint ();
7107 lh
->file_names
[file
- 1].included_p
= 1;
7108 if (!decode_for_pst_p
)
7110 if (last_subfile
!= current_subfile
)
7113 record_line (last_subfile
, 0, address
);
7114 last_subfile
= current_subfile
;
7116 /* Append row to matrix using current values. */
7117 record_line (current_subfile
, line
,
7118 check_cu_functions (address
, cu
));
7123 else switch (op_code
)
7125 case DW_LNS_extended_op
:
7126 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7127 line_ptr
+= bytes_read
;
7128 extended_end
= line_ptr
+ extended_len
;
7129 extended_op
= read_1_byte (abfd
, line_ptr
);
7131 switch (extended_op
)
7133 case DW_LNE_end_sequence
:
7136 if (lh
->num_file_names
< file
)
7137 dwarf2_debug_line_missing_file_complaint ();
7140 lh
->file_names
[file
- 1].included_p
= 1;
7141 if (!decode_for_pst_p
)
7142 record_line (current_subfile
, 0, address
);
7145 case DW_LNE_set_address
:
7146 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7147 line_ptr
+= bytes_read
;
7148 address
+= baseaddr
;
7150 case DW_LNE_define_file
:
7153 unsigned int dir_index
, mod_time
, length
;
7155 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7156 line_ptr
+= bytes_read
;
7158 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7159 line_ptr
+= bytes_read
;
7161 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7162 line_ptr
+= bytes_read
;
7164 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7165 line_ptr
+= bytes_read
;
7166 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7170 complaint (&symfile_complaints
,
7171 _("mangled .debug_line section"));
7174 /* Make sure that we parsed the extended op correctly. If e.g.
7175 we expected a different address size than the producer used,
7176 we may have read the wrong number of bytes. */
7177 if (line_ptr
!= extended_end
)
7179 complaint (&symfile_complaints
,
7180 _("mangled .debug_line section"));
7185 if (lh
->num_file_names
< file
)
7186 dwarf2_debug_line_missing_file_complaint ();
7189 lh
->file_names
[file
- 1].included_p
= 1;
7190 if (!decode_for_pst_p
)
7192 if (last_subfile
!= current_subfile
)
7195 record_line (last_subfile
, 0, address
);
7196 last_subfile
= current_subfile
;
7198 record_line (current_subfile
, line
,
7199 check_cu_functions (address
, cu
));
7204 case DW_LNS_advance_pc
:
7205 address
+= lh
->minimum_instruction_length
7206 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7207 line_ptr
+= bytes_read
;
7209 case DW_LNS_advance_line
:
7210 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7211 line_ptr
+= bytes_read
;
7213 case DW_LNS_set_file
:
7215 /* The arrays lh->include_dirs and lh->file_names are
7216 0-based, but the directory and file name numbers in
7217 the statement program are 1-based. */
7218 struct file_entry
*fe
;
7221 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7222 line_ptr
+= bytes_read
;
7223 if (lh
->num_file_names
< file
)
7224 dwarf2_debug_line_missing_file_complaint ();
7227 fe
= &lh
->file_names
[file
- 1];
7229 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7230 if (!decode_for_pst_p
)
7232 last_subfile
= current_subfile
;
7233 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7238 case DW_LNS_set_column
:
7239 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7240 line_ptr
+= bytes_read
;
7242 case DW_LNS_negate_stmt
:
7243 is_stmt
= (!is_stmt
);
7245 case DW_LNS_set_basic_block
:
7248 /* Add to the address register of the state machine the
7249 address increment value corresponding to special opcode
7250 255. I.e., this value is scaled by the minimum
7251 instruction length since special opcode 255 would have
7252 scaled the the increment. */
7253 case DW_LNS_const_add_pc
:
7254 address
+= (lh
->minimum_instruction_length
7255 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7257 case DW_LNS_fixed_advance_pc
:
7258 address
+= read_2_bytes (abfd
, line_ptr
);
7263 /* Unknown standard opcode, ignore it. */
7266 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7268 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7269 line_ptr
+= bytes_read
;
7276 if (decode_for_pst_p
)
7280 /* Now that we're done scanning the Line Header Program, we can
7281 create the psymtab of each included file. */
7282 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7283 if (lh
->file_names
[file_index
].included_p
== 1)
7285 const struct file_entry fe
= lh
->file_names
[file_index
];
7286 char *include_name
= fe
.name
;
7287 char *dir_name
= NULL
;
7288 char *pst_filename
= pst
->filename
;
7291 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7293 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7295 include_name
= concat (dir_name
, SLASH_STRING
,
7296 include_name
, (char *)NULL
);
7297 make_cleanup (xfree
, include_name
);
7300 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7302 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7303 pst_filename
, (char *)NULL
);
7304 make_cleanup (xfree
, pst_filename
);
7307 if (strcmp (include_name
, pst_filename
) != 0)
7308 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7313 /* Make sure a symtab is created for every file, even files
7314 which contain only variables (i.e. no code with associated
7318 struct file_entry
*fe
;
7320 for (i
= 0; i
< lh
->num_file_names
; i
++)
7323 fe
= &lh
->file_names
[i
];
7325 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7326 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7328 /* Skip the main file; we don't need it, and it must be
7329 allocated last, so that it will show up before the
7330 non-primary symtabs in the objfile's symtab list. */
7331 if (current_subfile
== first_subfile
)
7334 if (current_subfile
->symtab
== NULL
)
7335 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7337 fe
->symtab
= current_subfile
->symtab
;
7342 /* Start a subfile for DWARF. FILENAME is the name of the file and
7343 DIRNAME the name of the source directory which contains FILENAME
7344 or NULL if not known. COMP_DIR is the compilation directory for the
7345 linetable's compilation unit or NULL if not known.
7346 This routine tries to keep line numbers from identical absolute and
7347 relative file names in a common subfile.
7349 Using the `list' example from the GDB testsuite, which resides in
7350 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7351 of /srcdir/list0.c yields the following debugging information for list0.c:
7353 DW_AT_name: /srcdir/list0.c
7354 DW_AT_comp_dir: /compdir
7355 files.files[0].name: list0.h
7356 files.files[0].dir: /srcdir
7357 files.files[1].name: list0.c
7358 files.files[1].dir: /srcdir
7360 The line number information for list0.c has to end up in a single
7361 subfile, so that `break /srcdir/list0.c:1' works as expected.
7362 start_subfile will ensure that this happens provided that we pass the
7363 concatenation of files.files[1].dir and files.files[1].name as the
7367 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7371 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7372 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7373 second argument to start_subfile. To be consistent, we do the
7374 same here. In order not to lose the line information directory,
7375 we concatenate it to the filename when it makes sense.
7376 Note that the Dwarf3 standard says (speaking of filenames in line
7377 information): ``The directory index is ignored for file names
7378 that represent full path names''. Thus ignoring dirname in the
7379 `else' branch below isn't an issue. */
7381 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7382 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7384 fullname
= filename
;
7386 start_subfile (fullname
, comp_dir
);
7388 if (fullname
!= filename
)
7393 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7394 struct dwarf2_cu
*cu
)
7396 struct objfile
*objfile
= cu
->objfile
;
7397 struct comp_unit_head
*cu_header
= &cu
->header
;
7399 /* NOTE drow/2003-01-30: There used to be a comment and some special
7400 code here to turn a symbol with DW_AT_external and a
7401 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7402 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7403 with some versions of binutils) where shared libraries could have
7404 relocations against symbols in their debug information - the
7405 minimal symbol would have the right address, but the debug info
7406 would not. It's no longer necessary, because we will explicitly
7407 apply relocations when we read in the debug information now. */
7409 /* A DW_AT_location attribute with no contents indicates that a
7410 variable has been optimized away. */
7411 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7413 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7417 /* Handle one degenerate form of location expression specially, to
7418 preserve GDB's previous behavior when section offsets are
7419 specified. If this is just a DW_OP_addr then mark this symbol
7422 if (attr_form_is_block (attr
)
7423 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7424 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7428 SYMBOL_VALUE_ADDRESS (sym
) =
7429 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7430 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7431 fixup_symbol_section (sym
, objfile
);
7432 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7433 SYMBOL_SECTION (sym
));
7437 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7438 expression evaluator, and use LOC_COMPUTED only when necessary
7439 (i.e. when the value of a register or memory location is
7440 referenced, or a thread-local block, etc.). Then again, it might
7441 not be worthwhile. I'm assuming that it isn't unless performance
7442 or memory numbers show me otherwise. */
7444 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7445 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7448 /* Given a pointer to a DWARF information entry, figure out if we need
7449 to make a symbol table entry for it, and if so, create a new entry
7450 and return a pointer to it.
7451 If TYPE is NULL, determine symbol type from the die, otherwise
7452 used the passed type. */
7454 static struct symbol
*
7455 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7457 struct objfile
*objfile
= cu
->objfile
;
7458 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7459 struct symbol
*sym
= NULL
;
7461 struct attribute
*attr
= NULL
;
7462 struct attribute
*attr2
= NULL
;
7465 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7467 if (die
->tag
!= DW_TAG_namespace
)
7468 name
= dwarf2_linkage_name (die
, cu
);
7470 name
= TYPE_NAME (type
);
7474 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7475 sizeof (struct symbol
));
7476 OBJSTAT (objfile
, n_syms
++);
7477 memset (sym
, 0, sizeof (struct symbol
));
7479 /* Cache this symbol's name and the name's demangled form (if any). */
7480 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7481 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7483 /* Default assumptions.
7484 Use the passed type or decode it from the die. */
7485 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7486 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7488 SYMBOL_TYPE (sym
) = type
;
7490 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7491 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7494 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7497 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7500 int file_index
= DW_UNSND (attr
);
7501 if (cu
->line_header
== NULL
7502 || file_index
> cu
->line_header
->num_file_names
)
7503 complaint (&symfile_complaints
,
7504 _("file index out of range"));
7505 else if (file_index
> 0)
7507 struct file_entry
*fe
;
7508 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7509 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7516 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7519 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7521 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7523 case DW_TAG_subprogram
:
7524 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7526 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7527 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7528 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7529 || cu
->language
== language_ada
)
7531 /* Subprograms marked external are stored as a global symbol.
7532 Ada subprograms, whether marked external or not, are always
7533 stored as a global symbol, because we want to be able to
7534 access them globally. For instance, we want to be able
7535 to break on a nested subprogram without having to
7536 specify the context. */
7537 add_symbol_to_list (sym
, &global_symbols
);
7541 add_symbol_to_list (sym
, cu
->list_in_scope
);
7544 case DW_TAG_variable
:
7545 /* Compilation with minimal debug info may result in variables
7546 with missing type entries. Change the misleading `void' type
7547 to something sensible. */
7548 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7550 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7552 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7555 dwarf2_const_value (attr
, sym
, cu
);
7556 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7557 if (attr2
&& (DW_UNSND (attr2
) != 0))
7558 add_symbol_to_list (sym
, &global_symbols
);
7560 add_symbol_to_list (sym
, cu
->list_in_scope
);
7563 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7566 var_decode_location (attr
, sym
, cu
);
7567 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7568 if (attr2
&& (DW_UNSND (attr2
) != 0))
7569 add_symbol_to_list (sym
, &global_symbols
);
7571 add_symbol_to_list (sym
, cu
->list_in_scope
);
7575 /* We do not know the address of this symbol.
7576 If it is an external symbol and we have type information
7577 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7578 The address of the variable will then be determined from
7579 the minimal symbol table whenever the variable is
7581 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7582 if (attr2
&& (DW_UNSND (attr2
) != 0)
7583 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7585 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7586 add_symbol_to_list (sym
, &global_symbols
);
7590 case DW_TAG_formal_parameter
:
7591 SYMBOL_IS_ARGUMENT (sym
) = 1;
7592 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7595 var_decode_location (attr
, sym
, cu
);
7597 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7600 dwarf2_const_value (attr
, sym
, cu
);
7602 add_symbol_to_list (sym
, cu
->list_in_scope
);
7604 case DW_TAG_unspecified_parameters
:
7605 /* From varargs functions; gdb doesn't seem to have any
7606 interest in this information, so just ignore it for now.
7609 case DW_TAG_class_type
:
7610 case DW_TAG_interface_type
:
7611 case DW_TAG_structure_type
:
7612 case DW_TAG_union_type
:
7613 case DW_TAG_set_type
:
7614 case DW_TAG_enumeration_type
:
7615 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7616 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7618 /* Make sure that the symbol includes appropriate enclosing
7619 classes/namespaces in its name. These are calculated in
7620 read_structure_type, and the correct name is saved in
7623 if (cu
->language
== language_cplus
7624 || cu
->language
== language_java
)
7626 struct type
*type
= SYMBOL_TYPE (sym
);
7628 if (TYPE_TAG_NAME (type
) != NULL
)
7630 /* FIXME: carlton/2003-11-10: Should this use
7631 SYMBOL_SET_NAMES instead? (The same problem also
7632 arises further down in this function.) */
7633 /* The type's name is already allocated along with
7634 this objfile, so we don't need to duplicate it
7636 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7641 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7642 really ever be static objects: otherwise, if you try
7643 to, say, break of a class's method and you're in a file
7644 which doesn't mention that class, it won't work unless
7645 the check for all static symbols in lookup_symbol_aux
7646 saves you. See the OtherFileClass tests in
7647 gdb.c++/namespace.exp. */
7649 struct pending
**list_to_add
;
7651 list_to_add
= (cu
->list_in_scope
== &file_symbols
7652 && (cu
->language
== language_cplus
7653 || cu
->language
== language_java
)
7654 ? &global_symbols
: cu
->list_in_scope
);
7656 add_symbol_to_list (sym
, list_to_add
);
7658 /* The semantics of C++ state that "struct foo { ... }" also
7659 defines a typedef for "foo". A Java class declaration also
7660 defines a typedef for the class. */
7661 if (cu
->language
== language_cplus
7662 || cu
->language
== language_java
7663 || cu
->language
== language_ada
)
7665 /* The symbol's name is already allocated along with
7666 this objfile, so we don't need to duplicate it for
7668 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7669 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7673 case DW_TAG_typedef
:
7674 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7675 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7676 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7677 add_symbol_to_list (sym
, cu
->list_in_scope
);
7679 case DW_TAG_base_type
:
7680 case DW_TAG_subrange_type
:
7681 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7682 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7683 add_symbol_to_list (sym
, cu
->list_in_scope
);
7685 case DW_TAG_enumerator
:
7686 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7687 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7690 dwarf2_const_value (attr
, sym
, cu
);
7693 /* NOTE: carlton/2003-11-10: See comment above in the
7694 DW_TAG_class_type, etc. block. */
7696 struct pending
**list_to_add
;
7698 list_to_add
= (cu
->list_in_scope
== &file_symbols
7699 && (cu
->language
== language_cplus
7700 || cu
->language
== language_java
)
7701 ? &global_symbols
: cu
->list_in_scope
);
7703 add_symbol_to_list (sym
, list_to_add
);
7706 case DW_TAG_namespace
:
7707 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7708 add_symbol_to_list (sym
, &global_symbols
);
7711 /* Not a tag we recognize. Hopefully we aren't processing
7712 trash data, but since we must specifically ignore things
7713 we don't recognize, there is nothing else we should do at
7715 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7716 dwarf_tag_name (die
->tag
));
7720 /* For the benefit of old versions of GCC, check for anonymous
7721 namespaces based on the demangled name. */
7722 if (!processing_has_namespace_info
7723 && cu
->language
== language_cplus
7724 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7725 cp_scan_for_anonymous_namespaces (sym
);
7730 /* Copy constant value from an attribute to a symbol. */
7733 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7734 struct dwarf2_cu
*cu
)
7736 struct objfile
*objfile
= cu
->objfile
;
7737 struct comp_unit_head
*cu_header
= &cu
->header
;
7738 struct dwarf_block
*blk
;
7743 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7744 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7745 cu_header
->addr_size
,
7746 TYPE_LENGTH (SYMBOL_TYPE
7748 SYMBOL_VALUE_BYTES (sym
) =
7749 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7750 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7751 it's body - store_unsigned_integer. */
7752 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7754 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7757 /* DW_STRING is already allocated on the obstack, point directly
7759 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7760 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7762 case DW_FORM_block1
:
7763 case DW_FORM_block2
:
7764 case DW_FORM_block4
:
7766 blk
= DW_BLOCK (attr
);
7767 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7768 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7770 TYPE_LENGTH (SYMBOL_TYPE
7772 SYMBOL_VALUE_BYTES (sym
) =
7773 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7774 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7775 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7778 /* The DW_AT_const_value attributes are supposed to carry the
7779 symbol's value "represented as it would be on the target
7780 architecture." By the time we get here, it's already been
7781 converted to host endianness, so we just need to sign- or
7782 zero-extend it as appropriate. */
7784 dwarf2_const_value_data (attr
, sym
, 8);
7787 dwarf2_const_value_data (attr
, sym
, 16);
7790 dwarf2_const_value_data (attr
, sym
, 32);
7793 dwarf2_const_value_data (attr
, sym
, 64);
7797 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7798 SYMBOL_CLASS (sym
) = LOC_CONST
;
7802 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7803 SYMBOL_CLASS (sym
) = LOC_CONST
;
7807 complaint (&symfile_complaints
,
7808 _("unsupported const value attribute form: '%s'"),
7809 dwarf_form_name (attr
->form
));
7810 SYMBOL_VALUE (sym
) = 0;
7811 SYMBOL_CLASS (sym
) = LOC_CONST
;
7817 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7818 or zero-extend it as appropriate for the symbol's type. */
7820 dwarf2_const_value_data (struct attribute
*attr
,
7824 LONGEST l
= DW_UNSND (attr
);
7826 if (bits
< sizeof (l
) * 8)
7828 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7829 l
&= ((LONGEST
) 1 << bits
) - 1;
7831 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7834 SYMBOL_VALUE (sym
) = l
;
7835 SYMBOL_CLASS (sym
) = LOC_CONST
;
7839 /* Return the type of the die in question using its DW_AT_type attribute. */
7841 static struct type
*
7842 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7844 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7846 struct attribute
*type_attr
;
7847 struct die_info
*type_die
;
7849 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7852 /* A missing DW_AT_type represents a void type. */
7853 return builtin_type (gdbarch
)->builtin_void
;
7856 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7858 type
= tag_type_to_type (type_die
, cu
);
7861 dump_die_for_error (type_die
);
7862 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7868 /* Return the containing type of the die in question using its
7869 DW_AT_containing_type attribute. */
7871 static struct type
*
7872 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7874 struct type
*type
= NULL
;
7875 struct attribute
*type_attr
;
7876 struct die_info
*type_die
= NULL
;
7878 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7881 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7882 type
= tag_type_to_type (type_die
, cu
);
7887 dump_die_for_error (type_die
);
7888 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7894 static struct type
*
7895 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7897 struct type
*this_type
;
7899 this_type
= read_type_die (die
, cu
);
7902 dump_die_for_error (die
);
7903 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7909 static struct type
*
7910 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7912 struct type
*this_type
;
7914 this_type
= get_die_type (die
, cu
);
7920 case DW_TAG_class_type
:
7921 case DW_TAG_interface_type
:
7922 case DW_TAG_structure_type
:
7923 case DW_TAG_union_type
:
7924 this_type
= read_structure_type (die
, cu
);
7926 case DW_TAG_enumeration_type
:
7927 this_type
= read_enumeration_type (die
, cu
);
7929 case DW_TAG_subprogram
:
7930 case DW_TAG_subroutine_type
:
7931 this_type
= read_subroutine_type (die
, cu
);
7933 case DW_TAG_array_type
:
7934 this_type
= read_array_type (die
, cu
);
7936 case DW_TAG_set_type
:
7937 this_type
= read_set_type (die
, cu
);
7939 case DW_TAG_pointer_type
:
7940 this_type
= read_tag_pointer_type (die
, cu
);
7942 case DW_TAG_ptr_to_member_type
:
7943 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7945 case DW_TAG_reference_type
:
7946 this_type
= read_tag_reference_type (die
, cu
);
7948 case DW_TAG_const_type
:
7949 this_type
= read_tag_const_type (die
, cu
);
7951 case DW_TAG_volatile_type
:
7952 this_type
= read_tag_volatile_type (die
, cu
);
7954 case DW_TAG_string_type
:
7955 this_type
= read_tag_string_type (die
, cu
);
7957 case DW_TAG_typedef
:
7958 this_type
= read_typedef (die
, cu
);
7960 case DW_TAG_subrange_type
:
7961 this_type
= read_subrange_type (die
, cu
);
7963 case DW_TAG_base_type
:
7964 this_type
= read_base_type (die
, cu
);
7966 case DW_TAG_unspecified_type
:
7967 this_type
= read_unspecified_type (die
, cu
);
7969 case DW_TAG_namespace
:
7970 this_type
= read_namespace_type (die
, cu
);
7973 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7974 dwarf_tag_name (die
->tag
));
7981 /* Return the name of the namespace/class that DIE is defined within,
7982 or "" if we can't tell. The caller should not xfree the result.
7984 For example, if we're within the method foo() in the following
7994 then determine_prefix on foo's die will return "N::C". */
7997 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7999 struct die_info
*parent
, *spec_die
;
8000 struct dwarf2_cu
*spec_cu
;
8001 struct type
*parent_type
;
8003 if (cu
->language
!= language_cplus
8004 && cu
->language
!= language_java
)
8007 /* We have to be careful in the presence of DW_AT_specification.
8008 For example, with GCC 3.4, given the code
8012 // Definition of N::foo.
8016 then we'll have a tree of DIEs like this:
8018 1: DW_TAG_compile_unit
8019 2: DW_TAG_namespace // N
8020 3: DW_TAG_subprogram // declaration of N::foo
8021 4: DW_TAG_subprogram // definition of N::foo
8022 DW_AT_specification // refers to die #3
8024 Thus, when processing die #4, we have to pretend that we're in
8025 the context of its DW_AT_specification, namely the contex of die
8028 spec_die
= die_specification (die
, &spec_cu
);
8029 if (spec_die
== NULL
)
8030 parent
= die
->parent
;
8033 parent
= spec_die
->parent
;
8040 switch (parent
->tag
)
8042 case DW_TAG_namespace
:
8043 parent_type
= read_type_die (parent
, cu
);
8044 /* We give a name to even anonymous namespaces. */
8045 return TYPE_TAG_NAME (parent_type
);
8046 case DW_TAG_class_type
:
8047 case DW_TAG_interface_type
:
8048 case DW_TAG_structure_type
:
8049 case DW_TAG_union_type
:
8050 parent_type
= read_type_die (parent
, cu
);
8051 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8052 return TYPE_TAG_NAME (parent_type
);
8054 /* An anonymous structure is only allowed non-static data
8055 members; no typedefs, no member functions, et cetera.
8056 So it does not need a prefix. */
8059 return determine_prefix (parent
, cu
);
8063 /* Return a newly-allocated string formed by concatenating PREFIX and
8064 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8065 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8066 perform an obconcat, otherwise allocate storage for the result. The CU argument
8067 is used to determine the language and hence, the appropriate separator. */
8069 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8072 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8073 struct dwarf2_cu
*cu
)
8077 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8079 else if (cu
->language
== language_java
)
8091 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8092 strcpy (retval
, prefix
);
8093 strcat (retval
, sep
);
8094 strcat (retval
, suffix
);
8099 /* We have an obstack. */
8100 return obconcat (obs
, prefix
, sep
, suffix
);
8104 /* Return sibling of die, NULL if no sibling. */
8106 static struct die_info
*
8107 sibling_die (struct die_info
*die
)
8109 return die
->sibling
;
8112 /* Get linkage name of a die, return NULL if not found. */
8115 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8117 struct attribute
*attr
;
8119 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8120 if (attr
&& DW_STRING (attr
))
8121 return DW_STRING (attr
);
8122 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8123 if (attr
&& DW_STRING (attr
))
8124 return DW_STRING (attr
);
8128 /* Get name of a die, return NULL if not found. */
8131 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8133 struct attribute
*attr
;
8135 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8136 if (attr
&& DW_STRING (attr
))
8137 return DW_STRING (attr
);
8141 /* Return the die that this die in an extension of, or NULL if there
8142 is none. *EXT_CU is the CU containing DIE on input, and the CU
8143 containing the return value on output. */
8145 static struct die_info
*
8146 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8148 struct attribute
*attr
;
8150 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8154 return follow_die_ref (die
, attr
, ext_cu
);
8157 /* Convert a DIE tag into its string name. */
8160 dwarf_tag_name (unsigned tag
)
8164 case DW_TAG_padding
:
8165 return "DW_TAG_padding";
8166 case DW_TAG_array_type
:
8167 return "DW_TAG_array_type";
8168 case DW_TAG_class_type
:
8169 return "DW_TAG_class_type";
8170 case DW_TAG_entry_point
:
8171 return "DW_TAG_entry_point";
8172 case DW_TAG_enumeration_type
:
8173 return "DW_TAG_enumeration_type";
8174 case DW_TAG_formal_parameter
:
8175 return "DW_TAG_formal_parameter";
8176 case DW_TAG_imported_declaration
:
8177 return "DW_TAG_imported_declaration";
8179 return "DW_TAG_label";
8180 case DW_TAG_lexical_block
:
8181 return "DW_TAG_lexical_block";
8183 return "DW_TAG_member";
8184 case DW_TAG_pointer_type
:
8185 return "DW_TAG_pointer_type";
8186 case DW_TAG_reference_type
:
8187 return "DW_TAG_reference_type";
8188 case DW_TAG_compile_unit
:
8189 return "DW_TAG_compile_unit";
8190 case DW_TAG_string_type
:
8191 return "DW_TAG_string_type";
8192 case DW_TAG_structure_type
:
8193 return "DW_TAG_structure_type";
8194 case DW_TAG_subroutine_type
:
8195 return "DW_TAG_subroutine_type";
8196 case DW_TAG_typedef
:
8197 return "DW_TAG_typedef";
8198 case DW_TAG_union_type
:
8199 return "DW_TAG_union_type";
8200 case DW_TAG_unspecified_parameters
:
8201 return "DW_TAG_unspecified_parameters";
8202 case DW_TAG_variant
:
8203 return "DW_TAG_variant";
8204 case DW_TAG_common_block
:
8205 return "DW_TAG_common_block";
8206 case DW_TAG_common_inclusion
:
8207 return "DW_TAG_common_inclusion";
8208 case DW_TAG_inheritance
:
8209 return "DW_TAG_inheritance";
8210 case DW_TAG_inlined_subroutine
:
8211 return "DW_TAG_inlined_subroutine";
8213 return "DW_TAG_module";
8214 case DW_TAG_ptr_to_member_type
:
8215 return "DW_TAG_ptr_to_member_type";
8216 case DW_TAG_set_type
:
8217 return "DW_TAG_set_type";
8218 case DW_TAG_subrange_type
:
8219 return "DW_TAG_subrange_type";
8220 case DW_TAG_with_stmt
:
8221 return "DW_TAG_with_stmt";
8222 case DW_TAG_access_declaration
:
8223 return "DW_TAG_access_declaration";
8224 case DW_TAG_base_type
:
8225 return "DW_TAG_base_type";
8226 case DW_TAG_catch_block
:
8227 return "DW_TAG_catch_block";
8228 case DW_TAG_const_type
:
8229 return "DW_TAG_const_type";
8230 case DW_TAG_constant
:
8231 return "DW_TAG_constant";
8232 case DW_TAG_enumerator
:
8233 return "DW_TAG_enumerator";
8234 case DW_TAG_file_type
:
8235 return "DW_TAG_file_type";
8237 return "DW_TAG_friend";
8238 case DW_TAG_namelist
:
8239 return "DW_TAG_namelist";
8240 case DW_TAG_namelist_item
:
8241 return "DW_TAG_namelist_item";
8242 case DW_TAG_packed_type
:
8243 return "DW_TAG_packed_type";
8244 case DW_TAG_subprogram
:
8245 return "DW_TAG_subprogram";
8246 case DW_TAG_template_type_param
:
8247 return "DW_TAG_template_type_param";
8248 case DW_TAG_template_value_param
:
8249 return "DW_TAG_template_value_param";
8250 case DW_TAG_thrown_type
:
8251 return "DW_TAG_thrown_type";
8252 case DW_TAG_try_block
:
8253 return "DW_TAG_try_block";
8254 case DW_TAG_variant_part
:
8255 return "DW_TAG_variant_part";
8256 case DW_TAG_variable
:
8257 return "DW_TAG_variable";
8258 case DW_TAG_volatile_type
:
8259 return "DW_TAG_volatile_type";
8260 case DW_TAG_dwarf_procedure
:
8261 return "DW_TAG_dwarf_procedure";
8262 case DW_TAG_restrict_type
:
8263 return "DW_TAG_restrict_type";
8264 case DW_TAG_interface_type
:
8265 return "DW_TAG_interface_type";
8266 case DW_TAG_namespace
:
8267 return "DW_TAG_namespace";
8268 case DW_TAG_imported_module
:
8269 return "DW_TAG_imported_module";
8270 case DW_TAG_unspecified_type
:
8271 return "DW_TAG_unspecified_type";
8272 case DW_TAG_partial_unit
:
8273 return "DW_TAG_partial_unit";
8274 case DW_TAG_imported_unit
:
8275 return "DW_TAG_imported_unit";
8276 case DW_TAG_condition
:
8277 return "DW_TAG_condition";
8278 case DW_TAG_shared_type
:
8279 return "DW_TAG_shared_type";
8280 case DW_TAG_MIPS_loop
:
8281 return "DW_TAG_MIPS_loop";
8282 case DW_TAG_HP_array_descriptor
:
8283 return "DW_TAG_HP_array_descriptor";
8284 case DW_TAG_format_label
:
8285 return "DW_TAG_format_label";
8286 case DW_TAG_function_template
:
8287 return "DW_TAG_function_template";
8288 case DW_TAG_class_template
:
8289 return "DW_TAG_class_template";
8290 case DW_TAG_GNU_BINCL
:
8291 return "DW_TAG_GNU_BINCL";
8292 case DW_TAG_GNU_EINCL
:
8293 return "DW_TAG_GNU_EINCL";
8294 case DW_TAG_upc_shared_type
:
8295 return "DW_TAG_upc_shared_type";
8296 case DW_TAG_upc_strict_type
:
8297 return "DW_TAG_upc_strict_type";
8298 case DW_TAG_upc_relaxed_type
:
8299 return "DW_TAG_upc_relaxed_type";
8300 case DW_TAG_PGI_kanji_type
:
8301 return "DW_TAG_PGI_kanji_type";
8302 case DW_TAG_PGI_interface_block
:
8303 return "DW_TAG_PGI_interface_block";
8305 return "DW_TAG_<unknown>";
8309 /* Convert a DWARF attribute code into its string name. */
8312 dwarf_attr_name (unsigned attr
)
8317 return "DW_AT_sibling";
8318 case DW_AT_location
:
8319 return "DW_AT_location";
8321 return "DW_AT_name";
8322 case DW_AT_ordering
:
8323 return "DW_AT_ordering";
8324 case DW_AT_subscr_data
:
8325 return "DW_AT_subscr_data";
8326 case DW_AT_byte_size
:
8327 return "DW_AT_byte_size";
8328 case DW_AT_bit_offset
:
8329 return "DW_AT_bit_offset";
8330 case DW_AT_bit_size
:
8331 return "DW_AT_bit_size";
8332 case DW_AT_element_list
:
8333 return "DW_AT_element_list";
8334 case DW_AT_stmt_list
:
8335 return "DW_AT_stmt_list";
8337 return "DW_AT_low_pc";
8339 return "DW_AT_high_pc";
8340 case DW_AT_language
:
8341 return "DW_AT_language";
8343 return "DW_AT_member";
8345 return "DW_AT_discr";
8346 case DW_AT_discr_value
:
8347 return "DW_AT_discr_value";
8348 case DW_AT_visibility
:
8349 return "DW_AT_visibility";
8351 return "DW_AT_import";
8352 case DW_AT_string_length
:
8353 return "DW_AT_string_length";
8354 case DW_AT_common_reference
:
8355 return "DW_AT_common_reference";
8356 case DW_AT_comp_dir
:
8357 return "DW_AT_comp_dir";
8358 case DW_AT_const_value
:
8359 return "DW_AT_const_value";
8360 case DW_AT_containing_type
:
8361 return "DW_AT_containing_type";
8362 case DW_AT_default_value
:
8363 return "DW_AT_default_value";
8365 return "DW_AT_inline";
8366 case DW_AT_is_optional
:
8367 return "DW_AT_is_optional";
8368 case DW_AT_lower_bound
:
8369 return "DW_AT_lower_bound";
8370 case DW_AT_producer
:
8371 return "DW_AT_producer";
8372 case DW_AT_prototyped
:
8373 return "DW_AT_prototyped";
8374 case DW_AT_return_addr
:
8375 return "DW_AT_return_addr";
8376 case DW_AT_start_scope
:
8377 return "DW_AT_start_scope";
8378 case DW_AT_bit_stride
:
8379 return "DW_AT_bit_stride";
8380 case DW_AT_upper_bound
:
8381 return "DW_AT_upper_bound";
8382 case DW_AT_abstract_origin
:
8383 return "DW_AT_abstract_origin";
8384 case DW_AT_accessibility
:
8385 return "DW_AT_accessibility";
8386 case DW_AT_address_class
:
8387 return "DW_AT_address_class";
8388 case DW_AT_artificial
:
8389 return "DW_AT_artificial";
8390 case DW_AT_base_types
:
8391 return "DW_AT_base_types";
8392 case DW_AT_calling_convention
:
8393 return "DW_AT_calling_convention";
8395 return "DW_AT_count";
8396 case DW_AT_data_member_location
:
8397 return "DW_AT_data_member_location";
8398 case DW_AT_decl_column
:
8399 return "DW_AT_decl_column";
8400 case DW_AT_decl_file
:
8401 return "DW_AT_decl_file";
8402 case DW_AT_decl_line
:
8403 return "DW_AT_decl_line";
8404 case DW_AT_declaration
:
8405 return "DW_AT_declaration";
8406 case DW_AT_discr_list
:
8407 return "DW_AT_discr_list";
8408 case DW_AT_encoding
:
8409 return "DW_AT_encoding";
8410 case DW_AT_external
:
8411 return "DW_AT_external";
8412 case DW_AT_frame_base
:
8413 return "DW_AT_frame_base";
8415 return "DW_AT_friend";
8416 case DW_AT_identifier_case
:
8417 return "DW_AT_identifier_case";
8418 case DW_AT_macro_info
:
8419 return "DW_AT_macro_info";
8420 case DW_AT_namelist_items
:
8421 return "DW_AT_namelist_items";
8422 case DW_AT_priority
:
8423 return "DW_AT_priority";
8425 return "DW_AT_segment";
8426 case DW_AT_specification
:
8427 return "DW_AT_specification";
8428 case DW_AT_static_link
:
8429 return "DW_AT_static_link";
8431 return "DW_AT_type";
8432 case DW_AT_use_location
:
8433 return "DW_AT_use_location";
8434 case DW_AT_variable_parameter
:
8435 return "DW_AT_variable_parameter";
8436 case DW_AT_virtuality
:
8437 return "DW_AT_virtuality";
8438 case DW_AT_vtable_elem_location
:
8439 return "DW_AT_vtable_elem_location";
8440 /* DWARF 3 values. */
8441 case DW_AT_allocated
:
8442 return "DW_AT_allocated";
8443 case DW_AT_associated
:
8444 return "DW_AT_associated";
8445 case DW_AT_data_location
:
8446 return "DW_AT_data_location";
8447 case DW_AT_byte_stride
:
8448 return "DW_AT_byte_stride";
8449 case DW_AT_entry_pc
:
8450 return "DW_AT_entry_pc";
8451 case DW_AT_use_UTF8
:
8452 return "DW_AT_use_UTF8";
8453 case DW_AT_extension
:
8454 return "DW_AT_extension";
8456 return "DW_AT_ranges";
8457 case DW_AT_trampoline
:
8458 return "DW_AT_trampoline";
8459 case DW_AT_call_column
:
8460 return "DW_AT_call_column";
8461 case DW_AT_call_file
:
8462 return "DW_AT_call_file";
8463 case DW_AT_call_line
:
8464 return "DW_AT_call_line";
8465 case DW_AT_description
:
8466 return "DW_AT_description";
8467 case DW_AT_binary_scale
:
8468 return "DW_AT_binary_scale";
8469 case DW_AT_decimal_scale
:
8470 return "DW_AT_decimal_scale";
8472 return "DW_AT_small";
8473 case DW_AT_decimal_sign
:
8474 return "DW_AT_decimal_sign";
8475 case DW_AT_digit_count
:
8476 return "DW_AT_digit_count";
8477 case DW_AT_picture_string
:
8478 return "DW_AT_picture_string";
8480 return "DW_AT_mutable";
8481 case DW_AT_threads_scaled
:
8482 return "DW_AT_threads_scaled";
8483 case DW_AT_explicit
:
8484 return "DW_AT_explicit";
8485 case DW_AT_object_pointer
:
8486 return "DW_AT_object_pointer";
8487 case DW_AT_endianity
:
8488 return "DW_AT_endianity";
8489 case DW_AT_elemental
:
8490 return "DW_AT_elemental";
8492 return "DW_AT_pure";
8493 case DW_AT_recursive
:
8494 return "DW_AT_recursive";
8495 /* SGI/MIPS extensions. */
8496 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8497 case DW_AT_MIPS_fde
:
8498 return "DW_AT_MIPS_fde";
8500 case DW_AT_MIPS_loop_begin
:
8501 return "DW_AT_MIPS_loop_begin";
8502 case DW_AT_MIPS_tail_loop_begin
:
8503 return "DW_AT_MIPS_tail_loop_begin";
8504 case DW_AT_MIPS_epilog_begin
:
8505 return "DW_AT_MIPS_epilog_begin";
8506 case DW_AT_MIPS_loop_unroll_factor
:
8507 return "DW_AT_MIPS_loop_unroll_factor";
8508 case DW_AT_MIPS_software_pipeline_depth
:
8509 return "DW_AT_MIPS_software_pipeline_depth";
8510 case DW_AT_MIPS_linkage_name
:
8511 return "DW_AT_MIPS_linkage_name";
8512 case DW_AT_MIPS_stride
:
8513 return "DW_AT_MIPS_stride";
8514 case DW_AT_MIPS_abstract_name
:
8515 return "DW_AT_MIPS_abstract_name";
8516 case DW_AT_MIPS_clone_origin
:
8517 return "DW_AT_MIPS_clone_origin";
8518 case DW_AT_MIPS_has_inlines
:
8519 return "DW_AT_MIPS_has_inlines";
8520 /* HP extensions. */
8521 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8522 case DW_AT_HP_block_index
:
8523 return "DW_AT_HP_block_index";
8525 case DW_AT_HP_unmodifiable
:
8526 return "DW_AT_HP_unmodifiable";
8527 case DW_AT_HP_actuals_stmt_list
:
8528 return "DW_AT_HP_actuals_stmt_list";
8529 case DW_AT_HP_proc_per_section
:
8530 return "DW_AT_HP_proc_per_section";
8531 case DW_AT_HP_raw_data_ptr
:
8532 return "DW_AT_HP_raw_data_ptr";
8533 case DW_AT_HP_pass_by_reference
:
8534 return "DW_AT_HP_pass_by_reference";
8535 case DW_AT_HP_opt_level
:
8536 return "DW_AT_HP_opt_level";
8537 case DW_AT_HP_prof_version_id
:
8538 return "DW_AT_HP_prof_version_id";
8539 case DW_AT_HP_opt_flags
:
8540 return "DW_AT_HP_opt_flags";
8541 case DW_AT_HP_cold_region_low_pc
:
8542 return "DW_AT_HP_cold_region_low_pc";
8543 case DW_AT_HP_cold_region_high_pc
:
8544 return "DW_AT_HP_cold_region_high_pc";
8545 case DW_AT_HP_all_variables_modifiable
:
8546 return "DW_AT_HP_all_variables_modifiable";
8547 case DW_AT_HP_linkage_name
:
8548 return "DW_AT_HP_linkage_name";
8549 case DW_AT_HP_prof_flags
:
8550 return "DW_AT_HP_prof_flags";
8551 /* GNU extensions. */
8552 case DW_AT_sf_names
:
8553 return "DW_AT_sf_names";
8554 case DW_AT_src_info
:
8555 return "DW_AT_src_info";
8556 case DW_AT_mac_info
:
8557 return "DW_AT_mac_info";
8558 case DW_AT_src_coords
:
8559 return "DW_AT_src_coords";
8560 case DW_AT_body_begin
:
8561 return "DW_AT_body_begin";
8562 case DW_AT_body_end
:
8563 return "DW_AT_body_end";
8564 case DW_AT_GNU_vector
:
8565 return "DW_AT_GNU_vector";
8566 /* VMS extensions. */
8567 case DW_AT_VMS_rtnbeg_pd_address
:
8568 return "DW_AT_VMS_rtnbeg_pd_address";
8569 /* UPC extension. */
8570 case DW_AT_upc_threads_scaled
:
8571 return "DW_AT_upc_threads_scaled";
8572 /* PGI (STMicroelectronics) extensions. */
8573 case DW_AT_PGI_lbase
:
8574 return "DW_AT_PGI_lbase";
8575 case DW_AT_PGI_soffset
:
8576 return "DW_AT_PGI_soffset";
8577 case DW_AT_PGI_lstride
:
8578 return "DW_AT_PGI_lstride";
8580 return "DW_AT_<unknown>";
8584 /* Convert a DWARF value form code into its string name. */
8587 dwarf_form_name (unsigned form
)
8592 return "DW_FORM_addr";
8593 case DW_FORM_block2
:
8594 return "DW_FORM_block2";
8595 case DW_FORM_block4
:
8596 return "DW_FORM_block4";
8598 return "DW_FORM_data2";
8600 return "DW_FORM_data4";
8602 return "DW_FORM_data8";
8603 case DW_FORM_string
:
8604 return "DW_FORM_string";
8606 return "DW_FORM_block";
8607 case DW_FORM_block1
:
8608 return "DW_FORM_block1";
8610 return "DW_FORM_data1";
8612 return "DW_FORM_flag";
8614 return "DW_FORM_sdata";
8616 return "DW_FORM_strp";
8618 return "DW_FORM_udata";
8619 case DW_FORM_ref_addr
:
8620 return "DW_FORM_ref_addr";
8622 return "DW_FORM_ref1";
8624 return "DW_FORM_ref2";
8626 return "DW_FORM_ref4";
8628 return "DW_FORM_ref8";
8629 case DW_FORM_ref_udata
:
8630 return "DW_FORM_ref_udata";
8631 case DW_FORM_indirect
:
8632 return "DW_FORM_indirect";
8634 return "DW_FORM_<unknown>";
8638 /* Convert a DWARF stack opcode into its string name. */
8641 dwarf_stack_op_name (unsigned op
)
8646 return "DW_OP_addr";
8648 return "DW_OP_deref";
8650 return "DW_OP_const1u";
8652 return "DW_OP_const1s";
8654 return "DW_OP_const2u";
8656 return "DW_OP_const2s";
8658 return "DW_OP_const4u";
8660 return "DW_OP_const4s";
8662 return "DW_OP_const8u";
8664 return "DW_OP_const8s";
8666 return "DW_OP_constu";
8668 return "DW_OP_consts";
8672 return "DW_OP_drop";
8674 return "DW_OP_over";
8676 return "DW_OP_pick";
8678 return "DW_OP_swap";
8682 return "DW_OP_xderef";
8690 return "DW_OP_minus";
8702 return "DW_OP_plus";
8703 case DW_OP_plus_uconst
:
8704 return "DW_OP_plus_uconst";
8710 return "DW_OP_shra";
8728 return "DW_OP_skip";
8730 return "DW_OP_lit0";
8732 return "DW_OP_lit1";
8734 return "DW_OP_lit2";
8736 return "DW_OP_lit3";
8738 return "DW_OP_lit4";
8740 return "DW_OP_lit5";
8742 return "DW_OP_lit6";
8744 return "DW_OP_lit7";
8746 return "DW_OP_lit8";
8748 return "DW_OP_lit9";
8750 return "DW_OP_lit10";
8752 return "DW_OP_lit11";
8754 return "DW_OP_lit12";
8756 return "DW_OP_lit13";
8758 return "DW_OP_lit14";
8760 return "DW_OP_lit15";
8762 return "DW_OP_lit16";
8764 return "DW_OP_lit17";
8766 return "DW_OP_lit18";
8768 return "DW_OP_lit19";
8770 return "DW_OP_lit20";
8772 return "DW_OP_lit21";
8774 return "DW_OP_lit22";
8776 return "DW_OP_lit23";
8778 return "DW_OP_lit24";
8780 return "DW_OP_lit25";
8782 return "DW_OP_lit26";
8784 return "DW_OP_lit27";
8786 return "DW_OP_lit28";
8788 return "DW_OP_lit29";
8790 return "DW_OP_lit30";
8792 return "DW_OP_lit31";
8794 return "DW_OP_reg0";
8796 return "DW_OP_reg1";
8798 return "DW_OP_reg2";
8800 return "DW_OP_reg3";
8802 return "DW_OP_reg4";
8804 return "DW_OP_reg5";
8806 return "DW_OP_reg6";
8808 return "DW_OP_reg7";
8810 return "DW_OP_reg8";
8812 return "DW_OP_reg9";
8814 return "DW_OP_reg10";
8816 return "DW_OP_reg11";
8818 return "DW_OP_reg12";
8820 return "DW_OP_reg13";
8822 return "DW_OP_reg14";
8824 return "DW_OP_reg15";
8826 return "DW_OP_reg16";
8828 return "DW_OP_reg17";
8830 return "DW_OP_reg18";
8832 return "DW_OP_reg19";
8834 return "DW_OP_reg20";
8836 return "DW_OP_reg21";
8838 return "DW_OP_reg22";
8840 return "DW_OP_reg23";
8842 return "DW_OP_reg24";
8844 return "DW_OP_reg25";
8846 return "DW_OP_reg26";
8848 return "DW_OP_reg27";
8850 return "DW_OP_reg28";
8852 return "DW_OP_reg29";
8854 return "DW_OP_reg30";
8856 return "DW_OP_reg31";
8858 return "DW_OP_breg0";
8860 return "DW_OP_breg1";
8862 return "DW_OP_breg2";
8864 return "DW_OP_breg3";
8866 return "DW_OP_breg4";
8868 return "DW_OP_breg5";
8870 return "DW_OP_breg6";
8872 return "DW_OP_breg7";
8874 return "DW_OP_breg8";
8876 return "DW_OP_breg9";
8878 return "DW_OP_breg10";
8880 return "DW_OP_breg11";
8882 return "DW_OP_breg12";
8884 return "DW_OP_breg13";
8886 return "DW_OP_breg14";
8888 return "DW_OP_breg15";
8890 return "DW_OP_breg16";
8892 return "DW_OP_breg17";
8894 return "DW_OP_breg18";
8896 return "DW_OP_breg19";
8898 return "DW_OP_breg20";
8900 return "DW_OP_breg21";
8902 return "DW_OP_breg22";
8904 return "DW_OP_breg23";
8906 return "DW_OP_breg24";
8908 return "DW_OP_breg25";
8910 return "DW_OP_breg26";
8912 return "DW_OP_breg27";
8914 return "DW_OP_breg28";
8916 return "DW_OP_breg29";
8918 return "DW_OP_breg30";
8920 return "DW_OP_breg31";
8922 return "DW_OP_regx";
8924 return "DW_OP_fbreg";
8926 return "DW_OP_bregx";
8928 return "DW_OP_piece";
8929 case DW_OP_deref_size
:
8930 return "DW_OP_deref_size";
8931 case DW_OP_xderef_size
:
8932 return "DW_OP_xderef_size";
8935 /* DWARF 3 extensions. */
8936 case DW_OP_push_object_address
:
8937 return "DW_OP_push_object_address";
8939 return "DW_OP_call2";
8941 return "DW_OP_call4";
8942 case DW_OP_call_ref
:
8943 return "DW_OP_call_ref";
8944 /* GNU extensions. */
8945 case DW_OP_form_tls_address
:
8946 return "DW_OP_form_tls_address";
8947 case DW_OP_call_frame_cfa
:
8948 return "DW_OP_call_frame_cfa";
8949 case DW_OP_bit_piece
:
8950 return "DW_OP_bit_piece";
8951 case DW_OP_GNU_push_tls_address
:
8952 return "DW_OP_GNU_push_tls_address";
8953 case DW_OP_GNU_uninit
:
8954 return "DW_OP_GNU_uninit";
8955 /* HP extensions. */
8956 case DW_OP_HP_is_value
:
8957 return "DW_OP_HP_is_value";
8958 case DW_OP_HP_fltconst4
:
8959 return "DW_OP_HP_fltconst4";
8960 case DW_OP_HP_fltconst8
:
8961 return "DW_OP_HP_fltconst8";
8962 case DW_OP_HP_mod_range
:
8963 return "DW_OP_HP_mod_range";
8964 case DW_OP_HP_unmod_range
:
8965 return "DW_OP_HP_unmod_range";
8967 return "DW_OP_HP_tls";
8969 return "OP_<unknown>";
8974 dwarf_bool_name (unsigned mybool
)
8982 /* Convert a DWARF type code into its string name. */
8985 dwarf_type_encoding_name (unsigned enc
)
8990 return "DW_ATE_void";
8991 case DW_ATE_address
:
8992 return "DW_ATE_address";
8993 case DW_ATE_boolean
:
8994 return "DW_ATE_boolean";
8995 case DW_ATE_complex_float
:
8996 return "DW_ATE_complex_float";
8998 return "DW_ATE_float";
9000 return "DW_ATE_signed";
9001 case DW_ATE_signed_char
:
9002 return "DW_ATE_signed_char";
9003 case DW_ATE_unsigned
:
9004 return "DW_ATE_unsigned";
9005 case DW_ATE_unsigned_char
:
9006 return "DW_ATE_unsigned_char";
9008 case DW_ATE_imaginary_float
:
9009 return "DW_ATE_imaginary_float";
9010 case DW_ATE_packed_decimal
:
9011 return "DW_ATE_packed_decimal";
9012 case DW_ATE_numeric_string
:
9013 return "DW_ATE_numeric_string";
9015 return "DW_ATE_edited";
9016 case DW_ATE_signed_fixed
:
9017 return "DW_ATE_signed_fixed";
9018 case DW_ATE_unsigned_fixed
:
9019 return "DW_ATE_unsigned_fixed";
9020 case DW_ATE_decimal_float
:
9021 return "DW_ATE_decimal_float";
9022 /* HP extensions. */
9023 case DW_ATE_HP_float80
:
9024 return "DW_ATE_HP_float80";
9025 case DW_ATE_HP_complex_float80
:
9026 return "DW_ATE_HP_complex_float80";
9027 case DW_ATE_HP_float128
:
9028 return "DW_ATE_HP_float128";
9029 case DW_ATE_HP_complex_float128
:
9030 return "DW_ATE_HP_complex_float128";
9031 case DW_ATE_HP_floathpintel
:
9032 return "DW_ATE_HP_floathpintel";
9033 case DW_ATE_HP_imaginary_float80
:
9034 return "DW_ATE_HP_imaginary_float80";
9035 case DW_ATE_HP_imaginary_float128
:
9036 return "DW_ATE_HP_imaginary_float128";
9038 return "DW_ATE_<unknown>";
9042 /* Convert a DWARF call frame info operation to its string name. */
9046 dwarf_cfi_name (unsigned cfi_opc
)
9050 case DW_CFA_advance_loc
:
9051 return "DW_CFA_advance_loc";
9053 return "DW_CFA_offset";
9054 case DW_CFA_restore
:
9055 return "DW_CFA_restore";
9057 return "DW_CFA_nop";
9058 case DW_CFA_set_loc
:
9059 return "DW_CFA_set_loc";
9060 case DW_CFA_advance_loc1
:
9061 return "DW_CFA_advance_loc1";
9062 case DW_CFA_advance_loc2
:
9063 return "DW_CFA_advance_loc2";
9064 case DW_CFA_advance_loc4
:
9065 return "DW_CFA_advance_loc4";
9066 case DW_CFA_offset_extended
:
9067 return "DW_CFA_offset_extended";
9068 case DW_CFA_restore_extended
:
9069 return "DW_CFA_restore_extended";
9070 case DW_CFA_undefined
:
9071 return "DW_CFA_undefined";
9072 case DW_CFA_same_value
:
9073 return "DW_CFA_same_value";
9074 case DW_CFA_register
:
9075 return "DW_CFA_register";
9076 case DW_CFA_remember_state
:
9077 return "DW_CFA_remember_state";
9078 case DW_CFA_restore_state
:
9079 return "DW_CFA_restore_state";
9080 case DW_CFA_def_cfa
:
9081 return "DW_CFA_def_cfa";
9082 case DW_CFA_def_cfa_register
:
9083 return "DW_CFA_def_cfa_register";
9084 case DW_CFA_def_cfa_offset
:
9085 return "DW_CFA_def_cfa_offset";
9087 case DW_CFA_def_cfa_expression
:
9088 return "DW_CFA_def_cfa_expression";
9089 case DW_CFA_expression
:
9090 return "DW_CFA_expression";
9091 case DW_CFA_offset_extended_sf
:
9092 return "DW_CFA_offset_extended_sf";
9093 case DW_CFA_def_cfa_sf
:
9094 return "DW_CFA_def_cfa_sf";
9095 case DW_CFA_def_cfa_offset_sf
:
9096 return "DW_CFA_def_cfa_offset_sf";
9097 case DW_CFA_val_offset
:
9098 return "DW_CFA_val_offset";
9099 case DW_CFA_val_offset_sf
:
9100 return "DW_CFA_val_offset_sf";
9101 case DW_CFA_val_expression
:
9102 return "DW_CFA_val_expression";
9103 /* SGI/MIPS specific. */
9104 case DW_CFA_MIPS_advance_loc8
:
9105 return "DW_CFA_MIPS_advance_loc8";
9106 /* GNU extensions. */
9107 case DW_CFA_GNU_window_save
:
9108 return "DW_CFA_GNU_window_save";
9109 case DW_CFA_GNU_args_size
:
9110 return "DW_CFA_GNU_args_size";
9111 case DW_CFA_GNU_negative_offset_extended
:
9112 return "DW_CFA_GNU_negative_offset_extended";
9114 return "DW_CFA_<unknown>";
9120 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9124 print_spaces (indent
, f
);
9125 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9126 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9128 if (die
->parent
!= NULL
)
9130 print_spaces (indent
, f
);
9131 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9132 die
->parent
->offset
);
9135 print_spaces (indent
, f
);
9136 fprintf_unfiltered (f
, " has children: %s\n",
9137 dwarf_bool_name (die
->child
!= NULL
));
9139 print_spaces (indent
, f
);
9140 fprintf_unfiltered (f
, " attributes:\n");
9142 for (i
= 0; i
< die
->num_attrs
; ++i
)
9144 print_spaces (indent
, f
);
9145 fprintf_unfiltered (f
, " %s (%s) ",
9146 dwarf_attr_name (die
->attrs
[i
].name
),
9147 dwarf_form_name (die
->attrs
[i
].form
));
9149 switch (die
->attrs
[i
].form
)
9151 case DW_FORM_ref_addr
:
9153 fprintf_unfiltered (f
, "address: ");
9154 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9156 case DW_FORM_block2
:
9157 case DW_FORM_block4
:
9159 case DW_FORM_block1
:
9160 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9165 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9166 (long) (DW_ADDR (&die
->attrs
[i
])));
9174 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9176 case DW_FORM_string
:
9178 fprintf_unfiltered (f
, "string: \"%s\"",
9179 DW_STRING (&die
->attrs
[i
])
9180 ? DW_STRING (&die
->attrs
[i
]) : "");
9183 if (DW_UNSND (&die
->attrs
[i
]))
9184 fprintf_unfiltered (f
, "flag: TRUE");
9186 fprintf_unfiltered (f
, "flag: FALSE");
9188 case DW_FORM_indirect
:
9189 /* the reader will have reduced the indirect form to
9190 the "base form" so this form should not occur */
9191 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9194 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9195 die
->attrs
[i
].form
);
9198 fprintf_unfiltered (f
, "\n");
9203 dump_die_for_error (struct die_info
*die
)
9205 dump_die_shallow (gdb_stderr
, 0, die
);
9209 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9211 int indent
= level
* 4;
9213 gdb_assert (die
!= NULL
);
9215 if (level
>= max_level
)
9218 dump_die_shallow (f
, indent
, die
);
9220 if (die
->child
!= NULL
)
9222 print_spaces (indent
, f
);
9223 fprintf_unfiltered (f
, " Children:");
9224 if (level
+ 1 < max_level
)
9226 fprintf_unfiltered (f
, "\n");
9227 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9231 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9235 if (die
->sibling
!= NULL
&& level
> 0)
9237 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9241 /* This is called from the pdie macro in gdbinit.in.
9242 It's not static so gcc will keep a copy callable from gdb. */
9245 dump_die (struct die_info
*die
, int max_level
)
9247 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9251 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9255 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9261 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9263 unsigned int result
= 0;
9267 case DW_FORM_ref_addr
:
9272 case DW_FORM_ref_udata
:
9273 result
= DW_ADDR (attr
);
9276 complaint (&symfile_complaints
,
9277 _("unsupported die ref attribute form: '%s'"),
9278 dwarf_form_name (attr
->form
));
9283 /* Return the constant value held by the given attribute. Return -1
9284 if the value held by the attribute is not constant. */
9287 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9289 if (attr
->form
== DW_FORM_sdata
)
9290 return DW_SND (attr
);
9291 else if (attr
->form
== DW_FORM_udata
9292 || attr
->form
== DW_FORM_data1
9293 || attr
->form
== DW_FORM_data2
9294 || attr
->form
== DW_FORM_data4
9295 || attr
->form
== DW_FORM_data8
)
9296 return DW_UNSND (attr
);
9299 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9300 dwarf_form_name (attr
->form
));
9301 return default_value
;
9305 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9306 unit and add it to our queue. */
9309 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9310 struct dwarf2_per_cu_data
*per_cu
)
9312 /* Mark the dependence relation so that we don't flush PER_CU
9314 dwarf2_add_dependence (this_cu
, per_cu
);
9316 /* If it's already on the queue, we have nothing to do. */
9320 /* If the compilation unit is already loaded, just mark it as
9322 if (per_cu
->cu
!= NULL
)
9324 per_cu
->cu
->last_used
= 0;
9328 /* Add it to the queue. */
9329 queue_comp_unit (per_cu
, this_cu
->objfile
);
9332 static struct die_info
*
9333 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9334 struct dwarf2_cu
**ref_cu
)
9336 struct die_info
*die
;
9337 unsigned int offset
;
9338 struct die_info temp_die
;
9339 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9341 offset
= dwarf2_get_ref_die_offset (attr
);
9343 if (! offset_in_cu_p (&cu
->header
, offset
))
9345 struct dwarf2_per_cu_data
*per_cu
;
9346 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9348 /* If necessary, add it to the queue and load its DIEs. */
9349 maybe_queue_comp_unit (cu
, per_cu
);
9351 target_cu
= per_cu
->cu
;
9356 *ref_cu
= target_cu
;
9357 temp_die
.offset
= offset
;
9358 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9362 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9363 "at 0x%lx [in module %s]"),
9364 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9367 /* Decode simple location descriptions.
9368 Given a pointer to a dwarf block that defines a location, compute
9369 the location and return the value.
9371 NOTE drow/2003-11-18: This function is called in two situations
9372 now: for the address of static or global variables (partial symbols
9373 only) and for offsets into structures which are expected to be
9374 (more or less) constant. The partial symbol case should go away,
9375 and only the constant case should remain. That will let this
9376 function complain more accurately. A few special modes are allowed
9377 without complaint for global variables (for instance, global
9378 register values and thread-local values).
9380 A location description containing no operations indicates that the
9381 object is optimized out. The return value is 0 for that case.
9382 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9383 callers will only want a very basic result and this can become a
9386 Note that stack[0] is unused except as a default error return.
9387 Note that stack overflow is not yet handled. */
9390 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9392 struct objfile
*objfile
= cu
->objfile
;
9393 struct comp_unit_head
*cu_header
= &cu
->header
;
9395 int size
= blk
->size
;
9396 gdb_byte
*data
= blk
->data
;
9397 CORE_ADDR stack
[64];
9399 unsigned int bytes_read
, unsnd
;
9443 stack
[++stacki
] = op
- DW_OP_lit0
;
9478 stack
[++stacki
] = op
- DW_OP_reg0
;
9480 dwarf2_complex_location_expr_complaint ();
9484 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9486 stack
[++stacki
] = unsnd
;
9488 dwarf2_complex_location_expr_complaint ();
9492 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9498 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9503 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9508 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9513 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9518 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9523 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9528 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9534 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9539 stack
[stacki
+ 1] = stack
[stacki
];
9544 stack
[stacki
- 1] += stack
[stacki
];
9548 case DW_OP_plus_uconst
:
9549 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9554 stack
[stacki
- 1] -= stack
[stacki
];
9559 /* If we're not the last op, then we definitely can't encode
9560 this using GDB's address_class enum. This is valid for partial
9561 global symbols, although the variable's address will be bogus
9564 dwarf2_complex_location_expr_complaint ();
9567 case DW_OP_GNU_push_tls_address
:
9568 /* The top of the stack has the offset from the beginning
9569 of the thread control block at which the variable is located. */
9570 /* Nothing should follow this operator, so the top of stack would
9572 /* This is valid for partial global symbols, but the variable's
9573 address will be bogus in the psymtab. */
9575 dwarf2_complex_location_expr_complaint ();
9578 case DW_OP_GNU_uninit
:
9582 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9583 dwarf_stack_op_name (op
));
9584 return (stack
[stacki
]);
9587 return (stack
[stacki
]);
9590 /* memory allocation interface */
9592 static struct dwarf_block
*
9593 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9595 struct dwarf_block
*blk
;
9597 blk
= (struct dwarf_block
*)
9598 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9602 static struct abbrev_info
*
9603 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9605 struct abbrev_info
*abbrev
;
9607 abbrev
= (struct abbrev_info
*)
9608 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9609 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9613 static struct die_info
*
9614 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9616 struct die_info
*die
;
9617 size_t size
= sizeof (struct die_info
);
9620 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9622 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9623 memset (die
, 0, sizeof (struct die_info
));
9628 /* Macro support. */
9631 /* Return the full name of file number I in *LH's file name table.
9632 Use COMP_DIR as the name of the current directory of the
9633 compilation. The result is allocated using xmalloc; the caller is
9634 responsible for freeing it. */
9636 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9638 /* Is the file number a valid index into the line header's file name
9639 table? Remember that file numbers start with one, not zero. */
9640 if (1 <= file
&& file
<= lh
->num_file_names
)
9642 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9644 if (IS_ABSOLUTE_PATH (fe
->name
))
9645 return xstrdup (fe
->name
);
9653 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9659 dir_len
= strlen (dir
);
9660 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9661 strcpy (full_name
, dir
);
9662 full_name
[dir_len
] = '/';
9663 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9667 return xstrdup (fe
->name
);
9672 /* The compiler produced a bogus file number. We can at least
9673 record the macro definitions made in the file, even if we
9674 won't be able to find the file by name. */
9676 sprintf (fake_name
, "<bad macro file number %d>", file
);
9678 complaint (&symfile_complaints
,
9679 _("bad file number in macro information (%d)"),
9682 return xstrdup (fake_name
);
9687 static struct macro_source_file
*
9688 macro_start_file (int file
, int line
,
9689 struct macro_source_file
*current_file
,
9690 const char *comp_dir
,
9691 struct line_header
*lh
, struct objfile
*objfile
)
9693 /* The full name of this source file. */
9694 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9696 /* We don't create a macro table for this compilation unit
9697 at all until we actually get a filename. */
9698 if (! pending_macros
)
9699 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9700 objfile
->macro_cache
);
9703 /* If we have no current file, then this must be the start_file
9704 directive for the compilation unit's main source file. */
9705 current_file
= macro_set_main (pending_macros
, full_name
);
9707 current_file
= macro_include (current_file
, line
, full_name
);
9711 return current_file
;
9715 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9716 followed by a null byte. */
9718 copy_string (const char *buf
, int len
)
9720 char *s
= xmalloc (len
+ 1);
9721 memcpy (s
, buf
, len
);
9729 consume_improper_spaces (const char *p
, const char *body
)
9733 complaint (&symfile_complaints
,
9734 _("macro definition contains spaces in formal argument list:\n`%s'"),
9746 parse_macro_definition (struct macro_source_file
*file
, int line
,
9751 /* The body string takes one of two forms. For object-like macro
9752 definitions, it should be:
9754 <macro name> " " <definition>
9756 For function-like macro definitions, it should be:
9758 <macro name> "() " <definition>
9760 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9762 Spaces may appear only where explicitly indicated, and in the
9765 The Dwarf 2 spec says that an object-like macro's name is always
9766 followed by a space, but versions of GCC around March 2002 omit
9767 the space when the macro's definition is the empty string.
9769 The Dwarf 2 spec says that there should be no spaces between the
9770 formal arguments in a function-like macro's formal argument list,
9771 but versions of GCC around March 2002 include spaces after the
9775 /* Find the extent of the macro name. The macro name is terminated
9776 by either a space or null character (for an object-like macro) or
9777 an opening paren (for a function-like macro). */
9778 for (p
= body
; *p
; p
++)
9779 if (*p
== ' ' || *p
== '(')
9782 if (*p
== ' ' || *p
== '\0')
9784 /* It's an object-like macro. */
9785 int name_len
= p
- body
;
9786 char *name
= copy_string (body
, name_len
);
9787 const char *replacement
;
9790 replacement
= body
+ name_len
+ 1;
9793 dwarf2_macro_malformed_definition_complaint (body
);
9794 replacement
= body
+ name_len
;
9797 macro_define_object (file
, line
, name
, replacement
);
9803 /* It's a function-like macro. */
9804 char *name
= copy_string (body
, p
- body
);
9807 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9811 p
= consume_improper_spaces (p
, body
);
9813 /* Parse the formal argument list. */
9814 while (*p
&& *p
!= ')')
9816 /* Find the extent of the current argument name. */
9817 const char *arg_start
= p
;
9819 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9822 if (! *p
|| p
== arg_start
)
9823 dwarf2_macro_malformed_definition_complaint (body
);
9826 /* Make sure argv has room for the new argument. */
9827 if (argc
>= argv_size
)
9830 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9833 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9836 p
= consume_improper_spaces (p
, body
);
9838 /* Consume the comma, if present. */
9843 p
= consume_improper_spaces (p
, body
);
9852 /* Perfectly formed definition, no complaints. */
9853 macro_define_function (file
, line
, name
,
9854 argc
, (const char **) argv
,
9856 else if (*p
== '\0')
9858 /* Complain, but do define it. */
9859 dwarf2_macro_malformed_definition_complaint (body
);
9860 macro_define_function (file
, line
, name
,
9861 argc
, (const char **) argv
,
9865 /* Just complain. */
9866 dwarf2_macro_malformed_definition_complaint (body
);
9869 /* Just complain. */
9870 dwarf2_macro_malformed_definition_complaint (body
);
9876 for (i
= 0; i
< argc
; i
++)
9882 dwarf2_macro_malformed_definition_complaint (body
);
9887 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9888 char *comp_dir
, bfd
*abfd
,
9889 struct dwarf2_cu
*cu
)
9891 gdb_byte
*mac_ptr
, *mac_end
;
9892 struct macro_source_file
*current_file
= 0;
9894 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9896 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9900 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9901 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9902 + dwarf2_per_objfile
->macinfo_size
;
9906 enum dwarf_macinfo_record_type macinfo_type
;
9908 /* Do we at least have room for a macinfo type byte? */
9909 if (mac_ptr
>= mac_end
)
9911 dwarf2_macros_too_long_complaint ();
9915 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9918 switch (macinfo_type
)
9920 /* A zero macinfo type indicates the end of the macro
9925 case DW_MACINFO_define
:
9926 case DW_MACINFO_undef
:
9928 unsigned int bytes_read
;
9932 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9933 mac_ptr
+= bytes_read
;
9934 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9935 mac_ptr
+= bytes_read
;
9938 complaint (&symfile_complaints
,
9939 _("debug info gives macro %s outside of any file: %s"),
9941 DW_MACINFO_define
? "definition" : macinfo_type
==
9942 DW_MACINFO_undef
? "undefinition" :
9943 "something-or-other", body
);
9946 if (macinfo_type
== DW_MACINFO_define
)
9947 parse_macro_definition (current_file
, line
, body
);
9948 else if (macinfo_type
== DW_MACINFO_undef
)
9949 macro_undef (current_file
, line
, body
);
9954 case DW_MACINFO_start_file
:
9956 unsigned int bytes_read
;
9959 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9960 mac_ptr
+= bytes_read
;
9961 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9962 mac_ptr
+= bytes_read
;
9964 current_file
= macro_start_file (file
, line
,
9965 current_file
, comp_dir
,
9970 case DW_MACINFO_end_file
:
9972 complaint (&symfile_complaints
,
9973 _("macro debug info has an unmatched `close_file' directive"));
9976 current_file
= current_file
->included_by
;
9979 enum dwarf_macinfo_record_type next_type
;
9981 /* GCC circa March 2002 doesn't produce the zero
9982 type byte marking the end of the compilation
9983 unit. Complain if it's not there, but exit no
9986 /* Do we at least have room for a macinfo type byte? */
9987 if (mac_ptr
>= mac_end
)
9989 dwarf2_macros_too_long_complaint ();
9993 /* We don't increment mac_ptr here, so this is just
9995 next_type
= read_1_byte (abfd
, mac_ptr
);
9997 complaint (&symfile_complaints
,
9998 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10005 case DW_MACINFO_vendor_ext
:
10007 unsigned int bytes_read
;
10011 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10012 mac_ptr
+= bytes_read
;
10013 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10014 mac_ptr
+= bytes_read
;
10016 /* We don't recognize any vendor extensions. */
10023 /* Check if the attribute's form is a DW_FORM_block*
10024 if so return true else false. */
10026 attr_form_is_block (struct attribute
*attr
)
10028 return (attr
== NULL
? 0 :
10029 attr
->form
== DW_FORM_block1
10030 || attr
->form
== DW_FORM_block2
10031 || attr
->form
== DW_FORM_block4
10032 || attr
->form
== DW_FORM_block
);
10035 /* Return non-zero if ATTR's value is a section offset --- classes
10036 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10037 You may use DW_UNSND (attr) to retrieve such offsets.
10039 Section 7.5.4, "Attribute Encodings", explains that no attribute
10040 may have a value that belongs to more than one of these classes; it
10041 would be ambiguous if we did, because we use the same forms for all
10044 attr_form_is_section_offset (struct attribute
*attr
)
10046 return (attr
->form
== DW_FORM_data4
10047 || attr
->form
== DW_FORM_data8
);
10051 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10052 zero otherwise. When this function returns true, you can apply
10053 dwarf2_get_attr_constant_value to it.
10055 However, note that for some attributes you must check
10056 attr_form_is_section_offset before using this test. DW_FORM_data4
10057 and DW_FORM_data8 are members of both the constant class, and of
10058 the classes that contain offsets into other debug sections
10059 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10060 that, if an attribute's can be either a constant or one of the
10061 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10062 taken as section offsets, not constants. */
10064 attr_form_is_constant (struct attribute
*attr
)
10066 switch (attr
->form
)
10068 case DW_FORM_sdata
:
10069 case DW_FORM_udata
:
10070 case DW_FORM_data1
:
10071 case DW_FORM_data2
:
10072 case DW_FORM_data4
:
10073 case DW_FORM_data8
:
10081 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10082 struct dwarf2_cu
*cu
)
10084 if (attr_form_is_section_offset (attr
)
10085 /* ".debug_loc" may not exist at all, or the offset may be outside
10086 the section. If so, fall through to the complaint in the
10088 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10090 struct dwarf2_loclist_baton
*baton
;
10092 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10093 sizeof (struct dwarf2_loclist_baton
));
10094 baton
->per_cu
= cu
->per_cu
;
10095 gdb_assert (baton
->per_cu
);
10097 /* We don't know how long the location list is, but make sure we
10098 don't run off the edge of the section. */
10099 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10100 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10101 baton
->base_address
= cu
->base_address
;
10102 if (cu
->base_known
== 0)
10103 complaint (&symfile_complaints
,
10104 _("Location list used without specifying the CU base address."));
10106 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10107 SYMBOL_LOCATION_BATON (sym
) = baton
;
10111 struct dwarf2_locexpr_baton
*baton
;
10113 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10114 sizeof (struct dwarf2_locexpr_baton
));
10115 baton
->per_cu
= cu
->per_cu
;
10116 gdb_assert (baton
->per_cu
);
10118 if (attr_form_is_block (attr
))
10120 /* Note that we're just copying the block's data pointer
10121 here, not the actual data. We're still pointing into the
10122 info_buffer for SYM's objfile; right now we never release
10123 that buffer, but when we do clean up properly this may
10125 baton
->size
= DW_BLOCK (attr
)->size
;
10126 baton
->data
= DW_BLOCK (attr
)->data
;
10130 dwarf2_invalid_attrib_class_complaint ("location description",
10131 SYMBOL_NATURAL_NAME (sym
));
10133 baton
->data
= NULL
;
10136 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10137 SYMBOL_LOCATION_BATON (sym
) = baton
;
10141 /* Return the OBJFILE associated with the compilation unit CU. */
10144 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10146 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10148 /* Return the master objfile, so that we can report and look up the
10149 correct file containing this variable. */
10150 if (objfile
->separate_debug_objfile_backlink
)
10151 objfile
= objfile
->separate_debug_objfile_backlink
;
10156 /* Return the address size given in the compilation unit header for CU. */
10159 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10162 return per_cu
->cu
->header
.addr_size
;
10165 /* If the CU is not currently read in, we re-read its header. */
10166 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10167 struct dwarf2_per_objfile
*per_objfile
10168 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10169 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10171 struct comp_unit_head cu_header
;
10172 memset (&cu_header
, 0, sizeof cu_header
);
10173 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10174 return cu_header
.addr_size
;
10178 /* Locate the compilation unit from CU's objfile which contains the
10179 DIE at OFFSET. Raises an error on failure. */
10181 static struct dwarf2_per_cu_data
*
10182 dwarf2_find_containing_comp_unit (unsigned int offset
,
10183 struct objfile
*objfile
)
10185 struct dwarf2_per_cu_data
*this_cu
;
10189 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10192 int mid
= low
+ (high
- low
) / 2;
10193 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10198 gdb_assert (low
== high
);
10199 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10202 error (_("Dwarf Error: could not find partial DIE containing "
10203 "offset 0x%lx [in module %s]"),
10204 (long) offset
, bfd_get_filename (objfile
->obfd
));
10206 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10207 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10211 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10212 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10213 && offset
>= this_cu
->offset
+ this_cu
->length
)
10214 error (_("invalid dwarf2 offset %u"), offset
);
10215 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10220 /* Locate the compilation unit from OBJFILE which is located at exactly
10221 OFFSET. Raises an error on failure. */
10223 static struct dwarf2_per_cu_data
*
10224 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10226 struct dwarf2_per_cu_data
*this_cu
;
10227 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10228 if (this_cu
->offset
!= offset
)
10229 error (_("no compilation unit with offset %u."), offset
);
10233 /* Release one cached compilation unit, CU. We unlink it from the tree
10234 of compilation units, but we don't remove it from the read_in_chain;
10235 the caller is responsible for that. */
10238 free_one_comp_unit (void *data
)
10240 struct dwarf2_cu
*cu
= data
;
10242 if (cu
->per_cu
!= NULL
)
10243 cu
->per_cu
->cu
= NULL
;
10246 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10251 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10252 when we're finished with it. We can't free the pointer itself, but be
10253 sure to unlink it from the cache. Also release any associated storage
10254 and perform cache maintenance.
10256 Only used during partial symbol parsing. */
10259 free_stack_comp_unit (void *data
)
10261 struct dwarf2_cu
*cu
= data
;
10263 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10264 cu
->partial_dies
= NULL
;
10266 if (cu
->per_cu
!= NULL
)
10268 /* This compilation unit is on the stack in our caller, so we
10269 should not xfree it. Just unlink it. */
10270 cu
->per_cu
->cu
= NULL
;
10273 /* If we had a per-cu pointer, then we may have other compilation
10274 units loaded, so age them now. */
10275 age_cached_comp_units ();
10279 /* Free all cached compilation units. */
10282 free_cached_comp_units (void *data
)
10284 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10286 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10287 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10288 while (per_cu
!= NULL
)
10290 struct dwarf2_per_cu_data
*next_cu
;
10292 next_cu
= per_cu
->cu
->read_in_chain
;
10294 free_one_comp_unit (per_cu
->cu
);
10295 *last_chain
= next_cu
;
10301 /* Increase the age counter on each cached compilation unit, and free
10302 any that are too old. */
10305 age_cached_comp_units (void)
10307 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10309 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10310 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10311 while (per_cu
!= NULL
)
10313 per_cu
->cu
->last_used
++;
10314 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10315 dwarf2_mark (per_cu
->cu
);
10316 per_cu
= per_cu
->cu
->read_in_chain
;
10319 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10320 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10321 while (per_cu
!= NULL
)
10323 struct dwarf2_per_cu_data
*next_cu
;
10325 next_cu
= per_cu
->cu
->read_in_chain
;
10327 if (!per_cu
->cu
->mark
)
10329 free_one_comp_unit (per_cu
->cu
);
10330 *last_chain
= next_cu
;
10333 last_chain
= &per_cu
->cu
->read_in_chain
;
10339 /* Remove a single compilation unit from the cache. */
10342 free_one_cached_comp_unit (void *target_cu
)
10344 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10346 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10347 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10348 while (per_cu
!= NULL
)
10350 struct dwarf2_per_cu_data
*next_cu
;
10352 next_cu
= per_cu
->cu
->read_in_chain
;
10354 if (per_cu
->cu
== target_cu
)
10356 free_one_comp_unit (per_cu
->cu
);
10357 *last_chain
= next_cu
;
10361 last_chain
= &per_cu
->cu
->read_in_chain
;
10367 /* Release all extra memory associated with OBJFILE. */
10370 dwarf2_free_objfile (struct objfile
*objfile
)
10372 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10374 if (dwarf2_per_objfile
== NULL
)
10377 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10378 free_cached_comp_units (NULL
);
10380 /* Everything else should be on the objfile obstack. */
10383 /* A pair of DIE offset and GDB type pointer. We store these
10384 in a hash table separate from the DIEs, and preserve them
10385 when the DIEs are flushed out of cache. */
10387 struct dwarf2_offset_and_type
10389 unsigned int offset
;
10393 /* Hash function for a dwarf2_offset_and_type. */
10396 offset_and_type_hash (const void *item
)
10398 const struct dwarf2_offset_and_type
*ofs
= item
;
10399 return ofs
->offset
;
10402 /* Equality function for a dwarf2_offset_and_type. */
10405 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10407 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10408 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10409 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10412 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10413 table if necessary. For convenience, return TYPE. */
10415 static struct type
*
10416 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10418 struct dwarf2_offset_and_type
**slot
, ofs
;
10420 if (cu
->type_hash
== NULL
)
10422 gdb_assert (cu
->per_cu
!= NULL
);
10423 cu
->per_cu
->type_hash
10424 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10425 offset_and_type_hash
,
10426 offset_and_type_eq
,
10428 &cu
->objfile
->objfile_obstack
,
10429 hashtab_obstack_allocate
,
10430 dummy_obstack_deallocate
);
10431 cu
->type_hash
= cu
->per_cu
->type_hash
;
10434 ofs
.offset
= die
->offset
;
10436 slot
= (struct dwarf2_offset_and_type
**)
10437 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10438 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10443 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10444 not have a saved type. */
10446 static struct type
*
10447 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10449 struct dwarf2_offset_and_type
*slot
, ofs
;
10450 htab_t type_hash
= cu
->type_hash
;
10452 if (type_hash
== NULL
)
10455 ofs
.offset
= die
->offset
;
10456 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10463 /* Set the mark field in CU and in every other compilation unit in the
10464 cache that we must keep because we are keeping CU. */
10466 /* Add a dependence relationship from CU to REF_PER_CU. */
10469 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10470 struct dwarf2_per_cu_data
*ref_per_cu
)
10474 if (cu
->dependencies
== NULL
)
10476 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10477 NULL
, &cu
->comp_unit_obstack
,
10478 hashtab_obstack_allocate
,
10479 dummy_obstack_deallocate
);
10481 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10483 *slot
= ref_per_cu
;
10486 /* Set the mark field in CU and in every other compilation unit in the
10487 cache that we must keep because we are keeping CU. */
10490 dwarf2_mark_helper (void **slot
, void *data
)
10492 struct dwarf2_per_cu_data
*per_cu
;
10494 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10495 if (per_cu
->cu
->mark
)
10497 per_cu
->cu
->mark
= 1;
10499 if (per_cu
->cu
->dependencies
!= NULL
)
10500 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10506 dwarf2_mark (struct dwarf2_cu
*cu
)
10511 if (cu
->dependencies
!= NULL
)
10512 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10516 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10520 per_cu
->cu
->mark
= 0;
10521 per_cu
= per_cu
->cu
->read_in_chain
;
10525 /* Trivial hash function for partial_die_info: the hash value of a DIE
10526 is its offset in .debug_info for this objfile. */
10529 partial_die_hash (const void *item
)
10531 const struct partial_die_info
*part_die
= item
;
10532 return part_die
->offset
;
10535 /* Trivial comparison function for partial_die_info structures: two DIEs
10536 are equal if they have the same offset. */
10539 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10541 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10542 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10543 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10546 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10547 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10550 set_dwarf2_cmd (char *args
, int from_tty
)
10552 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10556 show_dwarf2_cmd (char *args
, int from_tty
)
10558 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10561 void _initialize_dwarf2_read (void);
10564 _initialize_dwarf2_read (void)
10566 dwarf2_objfile_data_key
= register_objfile_data ();
10568 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10569 Set DWARF 2 specific variables.\n\
10570 Configure DWARF 2 variables such as the cache size"),
10571 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10572 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10574 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10575 Show DWARF 2 specific variables\n\
10576 Show DWARF 2 variables such as the cache size"),
10577 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10578 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10580 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10581 &dwarf2_max_cache_age
, _("\
10582 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10583 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10584 A higher limit means that cached compilation units will be stored\n\
10585 in memory longer, and more total memory will be used. Zero disables\n\
10586 caching, which can slow down startup."),
10588 show_dwarf2_max_cache_age
,
10589 &set_dwarf2_cmdlist
,
10590 &show_dwarf2_cmdlist
);
10592 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
10593 Set debugging of the dwarf2 DIE reader."), _("\
10594 Show debugging of the dwarf2 DIE reader."), _("\
10595 When enabled (non-zero), DIEs are dumped after they are read in.\n\
10596 The value is the maximum depth to print."),
10599 &setdebuglist
, &showdebuglist
);