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 set, the file that we're processing is known to have debugging
145 info for C++ namespaces. GCC 3.3.x did not produce this information,
146 but later versions do. */
148 static int processing_has_namespace_info
;
150 static const struct objfile_data
*dwarf2_objfile_data_key
;
152 struct dwarf2_per_objfile
154 /* Sizes of debugging sections. */
155 unsigned int info_size
;
156 unsigned int abbrev_size
;
157 unsigned int line_size
;
158 unsigned int pubnames_size
;
159 unsigned int aranges_size
;
160 unsigned int loc_size
;
161 unsigned int macinfo_size
;
162 unsigned int str_size
;
163 unsigned int ranges_size
;
164 unsigned int frame_size
;
165 unsigned int eh_frame_size
;
167 /* Loaded data from the sections. */
168 gdb_byte
*info_buffer
;
169 gdb_byte
*abbrev_buffer
;
170 gdb_byte
*line_buffer
;
171 gdb_byte
*str_buffer
;
172 gdb_byte
*macinfo_buffer
;
173 gdb_byte
*ranges_buffer
;
174 gdb_byte
*loc_buffer
;
176 /* A list of all the compilation units. This is used to locate
177 the target compilation unit of a particular reference. */
178 struct dwarf2_per_cu_data
**all_comp_units
;
180 /* The number of compilation units in ALL_COMP_UNITS. */
183 /* A chain of compilation units that are currently read in, so that
184 they can be freed later. */
185 struct dwarf2_per_cu_data
*read_in_chain
;
187 /* A flag indicating wether this objfile has a section loaded at a
189 int has_section_at_zero
;
192 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
194 static asection
*dwarf_info_section
;
195 static asection
*dwarf_abbrev_section
;
196 static asection
*dwarf_line_section
;
197 static asection
*dwarf_pubnames_section
;
198 static asection
*dwarf_aranges_section
;
199 static asection
*dwarf_loc_section
;
200 static asection
*dwarf_macinfo_section
;
201 static asection
*dwarf_str_section
;
202 static asection
*dwarf_ranges_section
;
203 asection
*dwarf_frame_section
;
204 asection
*dwarf_eh_frame_section
;
206 /* names of the debugging sections */
208 /* Note that if the debugging section has been compressed, it might
209 have a name like .zdebug_info. */
211 #define INFO_SECTION "debug_info"
212 #define ABBREV_SECTION "debug_abbrev"
213 #define LINE_SECTION "debug_line"
214 #define PUBNAMES_SECTION "debug_pubnames"
215 #define ARANGES_SECTION "debug_aranges"
216 #define LOC_SECTION "debug_loc"
217 #define MACINFO_SECTION "debug_macinfo"
218 #define STR_SECTION "debug_str"
219 #define RANGES_SECTION "debug_ranges"
220 #define FRAME_SECTION "debug_frame"
221 #define EH_FRAME_SECTION "eh_frame"
223 /* local data types */
225 /* We hold several abbreviation tables in memory at the same time. */
226 #ifndef ABBREV_HASH_SIZE
227 #define ABBREV_HASH_SIZE 121
230 /* The data in a compilation unit header, after target2host
231 translation, looks like this. */
232 struct comp_unit_head
234 unsigned long length
;
236 unsigned int abbrev_offset
;
237 unsigned char addr_size
;
238 unsigned char signed_addr_p
;
240 /* Size of file offsets; either 4 or 8. */
241 unsigned int offset_size
;
243 /* Size of the length field; either 4 or 12. */
244 unsigned int initial_length_size
;
246 /* Offset to the first byte of this compilation unit header in the
247 .debug_info section, for resolving relative reference dies. */
250 /* Offset to first die in this cu from the start of the cu.
251 This will be the first byte following the compilation unit header. */
252 unsigned int first_die_offset
;
255 /* Internal state when decoding a particular compilation unit. */
258 /* The objfile containing this compilation unit. */
259 struct objfile
*objfile
;
261 /* The header of the compilation unit. */
262 struct comp_unit_head header
;
264 /* Base address of this compilation unit. */
265 CORE_ADDR base_address
;
267 /* Non-zero if base_address has been set. */
270 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
272 /* The language we are debugging. */
273 enum language language
;
274 const struct language_defn
*language_defn
;
276 const char *producer
;
278 /* The generic symbol table building routines have separate lists for
279 file scope symbols and all all other scopes (local scopes). So
280 we need to select the right one to pass to add_symbol_to_list().
281 We do it by keeping a pointer to the correct list in list_in_scope.
283 FIXME: The original dwarf code just treated the file scope as the
284 first local scope, and all other local scopes as nested local
285 scopes, and worked fine. Check to see if we really need to
286 distinguish these in buildsym.c. */
287 struct pending
**list_in_scope
;
289 /* DWARF abbreviation table associated with this compilation unit. */
290 struct abbrev_info
**dwarf2_abbrevs
;
292 /* Storage for the abbrev table. */
293 struct obstack abbrev_obstack
;
295 /* Hash table holding all the loaded partial DIEs. */
298 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
299 unsigned long ranges_offset
;
301 /* Storage for things with the same lifetime as this read-in compilation
302 unit, including partial DIEs. */
303 struct obstack comp_unit_obstack
;
305 /* When multiple dwarf2_cu structures are living in memory, this field
306 chains them all together, so that they can be released efficiently.
307 We will probably also want a generation counter so that most-recently-used
308 compilation units are cached... */
309 struct dwarf2_per_cu_data
*read_in_chain
;
311 /* Backchain to our per_cu entry if the tree has been built. */
312 struct dwarf2_per_cu_data
*per_cu
;
314 /* Pointer to the die -> type map. Although it is stored
315 permanently in per_cu, we copy it here to avoid double
319 /* How many compilation units ago was this CU last referenced? */
322 /* A hash table of die offsets for following references. */
325 /* Full DIEs if read in. */
326 struct die_info
*dies
;
328 /* A set of pointers to dwarf2_per_cu_data objects for compilation
329 units referenced by this one. Only set during full symbol processing;
330 partial symbol tables do not have dependencies. */
333 /* Header data from the line table, during full symbol processing. */
334 struct line_header
*line_header
;
336 /* Mark used when releasing cached dies. */
337 unsigned int mark
: 1;
339 /* This flag will be set if this compilation unit might include
340 inter-compilation-unit references. */
341 unsigned int has_form_ref_addr
: 1;
343 /* This flag will be set if this compilation unit includes any
344 DW_TAG_namespace DIEs. If we know that there are explicit
345 DIEs for namespaces, we don't need to try to infer them
346 from mangled names. */
347 unsigned int has_namespace_info
: 1;
349 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
350 unsigned int has_ranges_offset
: 1;
353 /* Persistent data held for a compilation unit, even when not
354 processing it. We put a pointer to this structure in the
355 read_symtab_private field of the psymtab. If we encounter
356 inter-compilation-unit references, we also maintain a sorted
357 list of all compilation units. */
359 struct dwarf2_per_cu_data
361 /* The start offset and length of this compilation unit. 2**30-1
362 bytes should suffice to store the length of any compilation unit
363 - if it doesn't, GDB will fall over anyway. */
364 unsigned long offset
;
365 unsigned long length
: 30;
367 /* Flag indicating this compilation unit will be read in before
368 any of the current compilation units are processed. */
369 unsigned long queued
: 1;
371 /* This flag will be set if we need to load absolutely all DIEs
372 for this compilation unit, instead of just the ones we think
373 are interesting. It gets set if we look for a DIE in the
374 hash table and don't find it. */
375 unsigned int load_all_dies
: 1;
377 /* Set iff currently read in. */
378 struct dwarf2_cu
*cu
;
380 /* If full symbols for this CU have been read in, then this field
381 holds a map of DIE offsets to types. It isn't always possible
382 to reconstruct this information later, so we have to preserve
386 /* The partial symbol table associated with this compilation unit,
387 or NULL for partial units (which do not have an associated
389 struct partial_symtab
*psymtab
;
392 /* The line number information for a compilation unit (found in the
393 .debug_line section) begins with a "statement program header",
394 which contains the following information. */
397 unsigned int total_length
;
398 unsigned short version
;
399 unsigned int header_length
;
400 unsigned char minimum_instruction_length
;
401 unsigned char default_is_stmt
;
403 unsigned char line_range
;
404 unsigned char opcode_base
;
406 /* standard_opcode_lengths[i] is the number of operands for the
407 standard opcode whose value is i. This means that
408 standard_opcode_lengths[0] is unused, and the last meaningful
409 element is standard_opcode_lengths[opcode_base - 1]. */
410 unsigned char *standard_opcode_lengths
;
412 /* The include_directories table. NOTE! These strings are not
413 allocated with xmalloc; instead, they are pointers into
414 debug_line_buffer. If you try to free them, `free' will get
416 unsigned int num_include_dirs
, include_dirs_size
;
419 /* The file_names table. NOTE! These strings are not allocated
420 with xmalloc; instead, they are pointers into debug_line_buffer.
421 Don't try to free them directly. */
422 unsigned int num_file_names
, file_names_size
;
426 unsigned int dir_index
;
427 unsigned int mod_time
;
429 int included_p
; /* Non-zero if referenced by the Line Number Program. */
430 struct symtab
*symtab
; /* The associated symbol table, if any. */
433 /* The start and end of the statement program following this
434 header. These point into dwarf2_per_objfile->line_buffer. */
435 gdb_byte
*statement_program_start
, *statement_program_end
;
438 /* When we construct a partial symbol table entry we only
439 need this much information. */
440 struct partial_die_info
442 /* Offset of this DIE. */
445 /* DWARF-2 tag for this DIE. */
446 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
448 /* Language code associated with this DIE. This is only used
449 for the compilation unit DIE. */
450 unsigned int language
: 8;
452 /* Assorted flags describing the data found in this DIE. */
453 unsigned int has_children
: 1;
454 unsigned int is_external
: 1;
455 unsigned int is_declaration
: 1;
456 unsigned int has_type
: 1;
457 unsigned int has_specification
: 1;
458 unsigned int has_stmt_list
: 1;
459 unsigned int has_pc_info
: 1;
461 /* Flag set if the SCOPE field of this structure has been
463 unsigned int scope_set
: 1;
465 /* Flag set if the DIE has a byte_size attribute. */
466 unsigned int has_byte_size
: 1;
468 /* The name of this DIE. Normally the value of DW_AT_name, but
469 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
474 /* The scope to prepend to our children. This is generally
475 allocated on the comp_unit_obstack, so will disappear
476 when this compilation unit leaves the cache. */
479 /* The location description associated with this DIE, if any. */
480 struct dwarf_block
*locdesc
;
482 /* If HAS_PC_INFO, the PC range associated with this DIE. */
486 /* Pointer into the info_buffer pointing at the target of
487 DW_AT_sibling, if any. */
490 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
491 DW_AT_specification (or DW_AT_abstract_origin or
493 unsigned int spec_offset
;
495 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
496 unsigned int line_offset
;
498 /* Pointers to this DIE's parent, first child, and next sibling,
500 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
503 /* This data structure holds the information of an abbrev. */
506 unsigned int number
; /* number identifying abbrev */
507 enum dwarf_tag tag
; /* dwarf tag */
508 unsigned short has_children
; /* boolean */
509 unsigned short num_attrs
; /* number of attributes */
510 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
511 struct abbrev_info
*next
; /* next in chain */
516 enum dwarf_attribute name
;
517 enum dwarf_form form
;
520 /* Attributes have a name and a value */
523 enum dwarf_attribute name
;
524 enum dwarf_form form
;
528 struct dwarf_block
*blk
;
536 /* This data structure holds a complete die structure. */
539 enum dwarf_tag tag
; /* Tag indicating type of die */
540 unsigned int abbrev
; /* Abbrev number */
541 unsigned int offset
; /* Offset in .debug_info section */
542 unsigned int num_attrs
; /* Number of attributes */
544 /* The dies in a compilation unit form an n-ary tree. PARENT
545 points to this die's parent; CHILD points to the first child of
546 this node; and all the children of a given node are chained
547 together via their SIBLING fields, terminated by a die whose
549 struct die_info
*child
; /* Its first child, if any. */
550 struct die_info
*sibling
; /* Its next sibling, if any. */
551 struct die_info
*parent
; /* Its parent, if any. */
553 /* An array of attributes, with NUM_ATTRS elements. There may be
554 zero, but it's not common and zero-sized arrays are not
555 sufficiently portable C. */
556 struct attribute attrs
[1];
559 struct function_range
562 CORE_ADDR lowpc
, highpc
;
564 struct function_range
*next
;
567 /* Get at parts of an attribute structure */
569 #define DW_STRING(attr) ((attr)->u.str)
570 #define DW_UNSND(attr) ((attr)->u.unsnd)
571 #define DW_BLOCK(attr) ((attr)->u.blk)
572 #define DW_SND(attr) ((attr)->u.snd)
573 #define DW_ADDR(attr) ((attr)->u.addr)
575 /* Blocks are a bunch of untyped bytes. */
582 #ifndef ATTR_ALLOC_CHUNK
583 #define ATTR_ALLOC_CHUNK 4
586 /* Allocate fields for structs, unions and enums in this size. */
587 #ifndef DW_FIELD_ALLOC_CHUNK
588 #define DW_FIELD_ALLOC_CHUNK 4
591 /* A zeroed version of a partial die for initialization purposes. */
592 static struct partial_die_info zeroed_partial_die
;
594 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
595 but this would require a corresponding change in unpack_field_as_long
597 static int bits_per_byte
= 8;
599 /* The routines that read and process dies for a C struct or C++ class
600 pass lists of data member fields and lists of member function fields
601 in an instance of a field_info structure, as defined below. */
604 /* List of data member and baseclasses fields. */
607 struct nextfield
*next
;
614 /* Number of fields. */
617 /* Number of baseclasses. */
620 /* Set if the accesibility of one of the fields is not public. */
621 int non_public_fields
;
623 /* Member function fields array, entries are allocated in the order they
624 are encountered in the object file. */
627 struct nextfnfield
*next
;
628 struct fn_field fnfield
;
632 /* Member function fieldlist array, contains name of possibly overloaded
633 member function, number of overloaded member functions and a pointer
634 to the head of the member function field chain. */
639 struct nextfnfield
*head
;
643 /* Number of entries in the fnfieldlists array. */
647 /* One item on the queue of compilation units to read in full symbols
649 struct dwarf2_queue_item
651 struct dwarf2_per_cu_data
*per_cu
;
652 struct dwarf2_queue_item
*next
;
655 /* The current queue. */
656 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
658 /* Loaded secondary compilation units are kept in memory until they
659 have not been referenced for the processing of this many
660 compilation units. Set this to zero to disable caching. Cache
661 sizes of up to at least twenty will improve startup time for
662 typical inter-CU-reference binaries, at an obvious memory cost. */
663 static int dwarf2_max_cache_age
= 5;
665 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
666 struct cmd_list_element
*c
, const char *value
)
668 fprintf_filtered (file
, _("\
669 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
674 /* Various complaints about symbol reading that don't abort the process */
677 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
679 complaint (&symfile_complaints
,
680 _("statement list doesn't fit in .debug_line section"));
684 dwarf2_debug_line_missing_file_complaint (void)
686 complaint (&symfile_complaints
,
687 _(".debug_line section has line data without a file"));
691 dwarf2_complex_location_expr_complaint (void)
693 complaint (&symfile_complaints
, _("location expression too complex"));
697 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
700 complaint (&symfile_complaints
,
701 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
706 dwarf2_macros_too_long_complaint (void)
708 complaint (&symfile_complaints
,
709 _("macro info runs off end of `.debug_macinfo' section"));
713 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
715 complaint (&symfile_complaints
,
716 _("macro debug info contains a malformed macro definition:\n`%s'"),
721 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
723 complaint (&symfile_complaints
,
724 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
727 /* local function prototypes */
729 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
732 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
735 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
738 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
739 struct partial_die_info
*,
740 struct partial_symtab
*);
742 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
744 static void scan_partial_symbols (struct partial_die_info
*,
745 CORE_ADDR
*, CORE_ADDR
*,
748 static void add_partial_symbol (struct partial_die_info
*,
751 static int pdi_needs_namespace (enum dwarf_tag tag
);
753 static void add_partial_namespace (struct partial_die_info
*pdi
,
754 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
755 struct dwarf2_cu
*cu
);
757 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
758 struct dwarf2_cu
*cu
);
760 static void add_partial_subprogram (struct partial_die_info
*pdi
,
761 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
762 struct dwarf2_cu
*cu
);
764 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
767 struct dwarf2_cu
*cu
);
769 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
771 static void psymtab_to_symtab_1 (struct partial_symtab
*);
773 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
775 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
777 static void dwarf2_free_abbrev_table (void *);
779 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
782 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
785 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
788 static gdb_byte
*read_partial_die (struct partial_die_info
*,
789 struct abbrev_info
*abbrev
, unsigned int,
790 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
792 static struct partial_die_info
*find_partial_die (unsigned long,
795 static void fixup_partial_die (struct partial_die_info
*,
798 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
799 struct dwarf2_cu
*, int *);
801 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
802 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
804 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
805 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
807 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
809 static int read_1_signed_byte (bfd
*, gdb_byte
*);
811 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
813 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
815 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
817 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
820 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
821 struct comp_unit_head
*, unsigned int *);
823 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
826 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
828 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
830 static char *read_indirect_string (bfd
*, gdb_byte
*,
831 const struct comp_unit_head
*,
834 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
836 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
838 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
840 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
842 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
845 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
846 struct dwarf2_cu
*cu
);
848 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
850 static struct die_info
*die_specification (struct die_info
*die
,
851 struct dwarf2_cu
**);
853 static void free_line_header (struct line_header
*lh
);
855 static void add_file_name (struct line_header
*, char *, unsigned int,
856 unsigned int, unsigned int);
858 static struct line_header
*(dwarf_decode_line_header
859 (unsigned int offset
,
860 bfd
*abfd
, struct dwarf2_cu
*cu
));
862 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
863 struct dwarf2_cu
*, struct partial_symtab
*);
865 static void dwarf2_start_subfile (char *, char *, char *);
867 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
870 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
873 static void dwarf2_const_value_data (struct attribute
*attr
,
877 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
879 static struct type
*die_containing_type (struct die_info
*,
882 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
884 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
886 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
888 static char *typename_concat (struct obstack
*,
893 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
895 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
897 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
899 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
900 struct dwarf2_cu
*, struct partial_symtab
*);
902 static int dwarf2_get_pc_bounds (struct die_info
*,
903 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
905 static void get_scope_pc_bounds (struct die_info
*,
906 CORE_ADDR
*, CORE_ADDR
*,
909 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
910 CORE_ADDR
, struct dwarf2_cu
*);
912 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
915 static void dwarf2_attach_fields_to_type (struct field_info
*,
916 struct type
*, struct dwarf2_cu
*);
918 static void dwarf2_add_member_fn (struct field_info
*,
919 struct die_info
*, struct type
*,
922 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
923 struct type
*, struct dwarf2_cu
*);
925 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
927 static const char *determine_class_name (struct die_info
*die
,
928 struct dwarf2_cu
*cu
);
930 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
932 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
934 static const char *namespace_name (struct die_info
*die
,
935 int *is_anonymous
, struct dwarf2_cu
*);
937 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
939 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
941 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
944 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
946 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
948 gdb_byte
**new_info_ptr
,
949 struct die_info
*parent
);
951 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
953 gdb_byte
**new_info_ptr
,
954 struct die_info
*parent
);
956 static void process_die (struct die_info
*, struct dwarf2_cu
*);
958 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
960 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
962 static struct die_info
*dwarf2_extension (struct die_info
*die
,
963 struct dwarf2_cu
**);
965 static char *dwarf_tag_name (unsigned int);
967 static char *dwarf_attr_name (unsigned int);
969 static char *dwarf_form_name (unsigned int);
971 static char *dwarf_stack_op_name (unsigned int);
973 static char *dwarf_bool_name (unsigned int);
975 static char *dwarf_type_encoding_name (unsigned int);
978 static char *dwarf_cfi_name (unsigned int);
981 static struct die_info
*sibling_die (struct die_info
*);
983 static void dump_die (struct die_info
*);
985 static void dump_die_list (struct die_info
*);
987 static void store_in_ref_table (struct die_info
*,
990 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
993 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
995 static struct die_info
*follow_die_ref (struct die_info
*,
997 struct dwarf2_cu
**);
999 /* memory allocation interface */
1001 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1003 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1005 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1007 static void initialize_cu_func_list (struct dwarf2_cu
*);
1009 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1010 struct dwarf2_cu
*);
1012 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1013 char *, bfd
*, struct dwarf2_cu
*);
1015 static int attr_form_is_block (struct attribute
*);
1017 static int attr_form_is_section_offset (struct attribute
*);
1019 static int attr_form_is_constant (struct attribute
*);
1021 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1023 struct dwarf2_cu
*cu
);
1025 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1026 struct dwarf2_cu
*cu
);
1028 static void free_stack_comp_unit (void *);
1030 static hashval_t
partial_die_hash (const void *item
);
1032 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1034 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1035 (unsigned long offset
, struct objfile
*objfile
);
1037 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1038 (unsigned long offset
, struct objfile
*objfile
);
1040 static void free_one_comp_unit (void *);
1042 static void free_cached_comp_units (void *);
1044 static void age_cached_comp_units (void);
1046 static void free_one_cached_comp_unit (void *);
1048 static struct type
*set_die_type (struct die_info
*, struct type
*,
1049 struct dwarf2_cu
*);
1051 static void create_all_comp_units (struct objfile
*);
1053 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1056 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1058 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1059 struct dwarf2_per_cu_data
*);
1061 static void dwarf2_mark (struct dwarf2_cu
*);
1063 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1065 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1067 /* Try to locate the sections we need for DWARF 2 debugging
1068 information and return true if we have enough to do something. */
1071 dwarf2_has_info (struct objfile
*objfile
)
1073 struct dwarf2_per_objfile
*data
;
1075 /* Initialize per-objfile state. */
1076 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1077 memset (data
, 0, sizeof (*data
));
1078 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1079 dwarf2_per_objfile
= data
;
1081 dwarf_info_section
= 0;
1082 dwarf_abbrev_section
= 0;
1083 dwarf_line_section
= 0;
1084 dwarf_str_section
= 0;
1085 dwarf_macinfo_section
= 0;
1086 dwarf_frame_section
= 0;
1087 dwarf_eh_frame_section
= 0;
1088 dwarf_ranges_section
= 0;
1089 dwarf_loc_section
= 0;
1091 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1092 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1095 /* When loading sections, we can either look for ".<name>", or for
1096 * ".z<name>", which indicates a compressed section. */
1099 section_is_p (asection
*sectp
, const char *name
)
1101 return ((sectp
->name
[0] == '.'
1102 && strcmp (sectp
->name
+ 1, name
) == 0)
1103 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1104 && strcmp (sectp
->name
+ 2, name
) == 0));
1107 /* This function is mapped across the sections and remembers the
1108 offset and size of each of the debugging sections we are interested
1112 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1114 if (section_is_p (sectp
, INFO_SECTION
))
1116 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1117 dwarf_info_section
= sectp
;
1119 else if (section_is_p (sectp
, ABBREV_SECTION
))
1121 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1122 dwarf_abbrev_section
= sectp
;
1124 else if (section_is_p (sectp
, LINE_SECTION
))
1126 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1127 dwarf_line_section
= sectp
;
1129 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1131 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1132 dwarf_pubnames_section
= sectp
;
1134 else if (section_is_p (sectp
, ARANGES_SECTION
))
1136 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1137 dwarf_aranges_section
= sectp
;
1139 else if (section_is_p (sectp
, LOC_SECTION
))
1141 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1142 dwarf_loc_section
= sectp
;
1144 else if (section_is_p (sectp
, MACINFO_SECTION
))
1146 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1147 dwarf_macinfo_section
= sectp
;
1149 else if (section_is_p (sectp
, STR_SECTION
))
1151 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1152 dwarf_str_section
= sectp
;
1154 else if (section_is_p (sectp
, FRAME_SECTION
))
1156 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1157 dwarf_frame_section
= sectp
;
1159 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1161 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1162 if (aflag
& SEC_HAS_CONTENTS
)
1164 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1165 dwarf_eh_frame_section
= sectp
;
1168 else if (section_is_p (sectp
, RANGES_SECTION
))
1170 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1171 dwarf_ranges_section
= sectp
;
1174 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1175 && bfd_section_vma (abfd
, sectp
) == 0)
1176 dwarf2_per_objfile
->has_section_at_zero
= 1;
1179 /* This function is called after decompressing a section, so
1180 dwarf2_per_objfile can record its new, uncompressed size. */
1183 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1185 if (section_is_p (sectp
, INFO_SECTION
))
1186 dwarf2_per_objfile
->info_size
= new_size
;
1187 else if (section_is_p (sectp
, ABBREV_SECTION
))
1188 dwarf2_per_objfile
->abbrev_size
= new_size
;
1189 else if (section_is_p (sectp
, LINE_SECTION
))
1190 dwarf2_per_objfile
->line_size
= new_size
;
1191 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1192 dwarf2_per_objfile
->pubnames_size
= new_size
;
1193 else if (section_is_p (sectp
, ARANGES_SECTION
))
1194 dwarf2_per_objfile
->aranges_size
= new_size
;
1195 else if (section_is_p (sectp
, LOC_SECTION
))
1196 dwarf2_per_objfile
->loc_size
= new_size
;
1197 else if (section_is_p (sectp
, MACINFO_SECTION
))
1198 dwarf2_per_objfile
->macinfo_size
= new_size
;
1199 else if (section_is_p (sectp
, STR_SECTION
))
1200 dwarf2_per_objfile
->str_size
= new_size
;
1201 else if (section_is_p (sectp
, FRAME_SECTION
))
1202 dwarf2_per_objfile
->frame_size
= new_size
;
1203 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1204 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1205 else if (section_is_p (sectp
, RANGES_SECTION
))
1206 dwarf2_per_objfile
->ranges_size
= new_size
;
1208 internal_error (__FILE__
, __LINE__
,
1209 _("dwarf2_resize_section: missing section_is_p check: %s"),
1213 /* Build a partial symbol table. */
1216 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1218 /* We definitely need the .debug_info and .debug_abbrev sections */
1220 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1221 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1223 if (dwarf_line_section
)
1224 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1226 dwarf2_per_objfile
->line_buffer
= NULL
;
1228 if (dwarf_str_section
)
1229 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1231 dwarf2_per_objfile
->str_buffer
= NULL
;
1233 if (dwarf_macinfo_section
)
1234 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1235 dwarf_macinfo_section
);
1237 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1239 if (dwarf_ranges_section
)
1240 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1242 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1244 if (dwarf_loc_section
)
1245 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1247 dwarf2_per_objfile
->loc_buffer
= NULL
;
1250 || (objfile
->global_psymbols
.size
== 0
1251 && objfile
->static_psymbols
.size
== 0))
1253 init_psymbol_list (objfile
, 1024);
1257 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1259 /* Things are significantly easier if we have .debug_aranges and
1260 .debug_pubnames sections */
1262 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1266 /* only test this case for now */
1268 /* In this case we have to work a bit harder */
1269 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1274 /* Build the partial symbol table from the information in the
1275 .debug_pubnames and .debug_aranges sections. */
1278 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1280 bfd
*abfd
= objfile
->obfd
;
1281 char *aranges_buffer
, *pubnames_buffer
;
1282 char *aranges_ptr
, *pubnames_ptr
;
1283 unsigned int entry_length
, version
, info_offset
, info_size
;
1285 pubnames_buffer
= dwarf2_read_section (objfile
,
1286 dwarf_pubnames_section
);
1287 pubnames_ptr
= pubnames_buffer
;
1288 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1290 struct comp_unit_head cu_header
;
1291 unsigned int bytes_read
;
1293 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1295 pubnames_ptr
+= bytes_read
;
1296 version
= read_1_byte (abfd
, pubnames_ptr
);
1298 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1300 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1304 aranges_buffer
= dwarf2_read_section (objfile
,
1305 dwarf_aranges_section
);
1310 /* Read in the comp unit header information from the debug_info at
1314 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1315 gdb_byte
*info_ptr
, bfd
*abfd
)
1318 unsigned int bytes_read
;
1319 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1321 info_ptr
+= bytes_read
;
1322 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1324 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1326 info_ptr
+= bytes_read
;
1327 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1329 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1330 if (signed_addr
< 0)
1331 internal_error (__FILE__
, __LINE__
,
1332 _("read_comp_unit_head: dwarf from non elf file"));
1333 cu_header
->signed_addr_p
= signed_addr
;
1338 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1341 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1343 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1345 if (header
->version
!= 2 && header
->version
!= 3)
1346 error (_("Dwarf Error: wrong version in compilation unit header "
1347 "(is %d, should be %d) [in module %s]"), header
->version
,
1348 2, bfd_get_filename (abfd
));
1350 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1351 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1352 "(offset 0x%lx + 6) [in module %s]"),
1353 (long) header
->abbrev_offset
,
1354 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1355 bfd_get_filename (abfd
));
1357 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1358 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1359 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1360 "(offset 0x%lx + 0) [in module %s]"),
1361 (long) header
->length
,
1362 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1363 bfd_get_filename (abfd
));
1368 /* Allocate a new partial symtab for file named NAME and mark this new
1369 partial symtab as being an include of PST. */
1372 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1373 struct objfile
*objfile
)
1375 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1377 subpst
->section_offsets
= pst
->section_offsets
;
1378 subpst
->textlow
= 0;
1379 subpst
->texthigh
= 0;
1381 subpst
->dependencies
= (struct partial_symtab
**)
1382 obstack_alloc (&objfile
->objfile_obstack
,
1383 sizeof (struct partial_symtab
*));
1384 subpst
->dependencies
[0] = pst
;
1385 subpst
->number_of_dependencies
= 1;
1387 subpst
->globals_offset
= 0;
1388 subpst
->n_global_syms
= 0;
1389 subpst
->statics_offset
= 0;
1390 subpst
->n_static_syms
= 0;
1391 subpst
->symtab
= NULL
;
1392 subpst
->read_symtab
= pst
->read_symtab
;
1395 /* No private part is necessary for include psymtabs. This property
1396 can be used to differentiate between such include psymtabs and
1397 the regular ones. */
1398 subpst
->read_symtab_private
= NULL
;
1401 /* Read the Line Number Program data and extract the list of files
1402 included by the source file represented by PST. Build an include
1403 partial symtab for each of these included files.
1405 This procedure assumes that there *is* a Line Number Program in
1406 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1407 before calling this procedure. */
1410 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1411 struct partial_die_info
*pdi
,
1412 struct partial_symtab
*pst
)
1414 struct objfile
*objfile
= cu
->objfile
;
1415 bfd
*abfd
= objfile
->obfd
;
1416 struct line_header
*lh
;
1418 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1420 return; /* No linetable, so no includes. */
1422 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1424 free_line_header (lh
);
1428 /* Build the partial symbol table by doing a quick pass through the
1429 .debug_info and .debug_abbrev sections. */
1432 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1434 /* Instead of reading this into a big buffer, we should probably use
1435 mmap() on architectures that support it. (FIXME) */
1436 bfd
*abfd
= objfile
->obfd
;
1438 gdb_byte
*beg_of_comp_unit
;
1439 struct partial_die_info comp_unit_die
;
1440 struct partial_symtab
*pst
;
1441 struct cleanup
*back_to
;
1442 CORE_ADDR lowpc
, highpc
, baseaddr
;
1444 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1446 /* Any cached compilation units will be linked by the per-objfile
1447 read_in_chain. Make sure to free them when we're done. */
1448 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1450 create_all_comp_units (objfile
);
1452 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1453 (&objfile
->objfile_obstack
);
1455 /* Since the objects we're extracting from .debug_info vary in
1456 length, only the individual functions to extract them (like
1457 read_comp_unit_head and load_partial_die) can really know whether
1458 the buffer is large enough to hold another complete object.
1460 At the moment, they don't actually check that. If .debug_info
1461 holds just one extra byte after the last compilation unit's dies,
1462 then read_comp_unit_head will happily read off the end of the
1463 buffer. read_partial_die is similarly casual. Those functions
1466 For this loop condition, simply checking whether there's any data
1467 left at all should be sufficient. */
1468 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1469 + dwarf2_per_objfile
->info_size
))
1471 struct cleanup
*back_to_inner
;
1472 struct dwarf2_cu cu
;
1473 struct abbrev_info
*abbrev
;
1474 unsigned int bytes_read
;
1475 struct dwarf2_per_cu_data
*this_cu
;
1477 beg_of_comp_unit
= info_ptr
;
1479 memset (&cu
, 0, sizeof (cu
));
1481 obstack_init (&cu
.comp_unit_obstack
);
1483 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1485 cu
.objfile
= objfile
;
1486 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1488 /* Complete the cu_header */
1489 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1490 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1492 cu
.list_in_scope
= &file_symbols
;
1494 /* Read the abbrevs for this compilation unit into a table */
1495 dwarf2_read_abbrevs (abfd
, &cu
);
1496 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1498 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1500 /* Read the compilation unit die */
1501 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1502 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1503 abfd
, info_ptr
, &cu
);
1505 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1507 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1508 + cu
.header
.initial_length_size
);
1509 do_cleanups (back_to_inner
);
1513 /* Set the language we're debugging */
1514 set_cu_language (comp_unit_die
.language
, &cu
);
1516 /* Allocate a new partial symbol table structure */
1517 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1518 comp_unit_die
.name
? comp_unit_die
.name
: "",
1519 /* TEXTLOW and TEXTHIGH are set below. */
1521 objfile
->global_psymbols
.next
,
1522 objfile
->static_psymbols
.next
);
1524 if (comp_unit_die
.dirname
)
1525 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1526 strlen (comp_unit_die
.dirname
),
1527 &objfile
->objfile_obstack
);
1529 pst
->read_symtab_private
= (char *) this_cu
;
1531 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1533 /* Store the function that reads in the rest of the symbol table */
1534 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1536 /* If this compilation unit was already read in, free the
1537 cached copy in order to read it in again. This is
1538 necessary because we skipped some symbols when we first
1539 read in the compilation unit (see load_partial_dies).
1540 This problem could be avoided, but the benefit is
1542 if (this_cu
->cu
!= NULL
)
1543 free_one_cached_comp_unit (this_cu
->cu
);
1545 cu
.per_cu
= this_cu
;
1547 /* Note that this is a pointer to our stack frame, being
1548 added to a global data structure. It will be cleaned up
1549 in free_stack_comp_unit when we finish with this
1550 compilation unit. */
1553 this_cu
->psymtab
= pst
;
1555 /* Possibly set the default values of LOWPC and HIGHPC from
1557 if (cu
.has_ranges_offset
)
1559 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1560 &comp_unit_die
.highpc
, &cu
, pst
))
1561 comp_unit_die
.has_pc_info
= 1;
1564 /* Check if comp unit has_children.
1565 If so, read the rest of the partial symbols from this comp unit.
1566 If not, there's no more debug_info for this comp unit. */
1567 if (comp_unit_die
.has_children
)
1569 struct partial_die_info
*first_die
;
1571 lowpc
= ((CORE_ADDR
) -1);
1572 highpc
= ((CORE_ADDR
) 0);
1574 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1576 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1578 /* If we didn't find a lowpc, set it to highpc to avoid
1579 complaints from `maint check'. */
1580 if (lowpc
== ((CORE_ADDR
) -1))
1583 /* If the compilation unit didn't have an explicit address range,
1584 then use the information extracted from its child dies. */
1585 if (! comp_unit_die
.has_pc_info
)
1587 comp_unit_die
.lowpc
= lowpc
;
1588 comp_unit_die
.highpc
= highpc
;
1591 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1592 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1594 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1595 range can be also empty for CUs with no code. */
1596 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1597 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1598 pst
->texthigh
- 1, pst
);
1600 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1601 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1602 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1603 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1604 sort_pst_symbols (pst
);
1606 /* If there is already a psymtab or symtab for a file of this
1607 name, remove it. (If there is a symtab, more drastic things
1608 also happen.) This happens in VxWorks. */
1609 free_named_symtabs (pst
->filename
);
1611 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1612 + cu
.header
.initial_length_size
;
1614 if (comp_unit_die
.has_stmt_list
)
1616 /* Get the list of files included in the current compilation unit,
1617 and build a psymtab for each of them. */
1618 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1621 do_cleanups (back_to_inner
);
1624 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1625 &objfile
->objfile_obstack
);
1627 do_cleanups (back_to
);
1630 /* Load the DIEs for a secondary CU into memory. */
1633 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1635 bfd
*abfd
= objfile
->obfd
;
1636 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1637 struct partial_die_info comp_unit_die
;
1638 struct dwarf2_cu
*cu
;
1639 struct abbrev_info
*abbrev
;
1640 unsigned int bytes_read
;
1641 struct cleanup
*back_to
;
1643 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1644 beg_of_comp_unit
= info_ptr
;
1646 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1647 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1649 obstack_init (&cu
->comp_unit_obstack
);
1651 cu
->objfile
= objfile
;
1652 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1654 /* Complete the cu_header. */
1655 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1656 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1658 /* Read the abbrevs for this compilation unit into a table. */
1659 dwarf2_read_abbrevs (abfd
, cu
);
1660 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1662 /* Read the compilation unit die. */
1663 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1664 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1665 abfd
, info_ptr
, cu
);
1667 /* Set the language we're debugging. */
1668 set_cu_language (comp_unit_die
.language
, cu
);
1670 /* Link this compilation unit into the compilation unit tree. */
1672 cu
->per_cu
= this_cu
;
1673 cu
->type_hash
= cu
->per_cu
->type_hash
;
1675 /* Check if comp unit has_children.
1676 If so, read the rest of the partial symbols from this comp unit.
1677 If not, there's no more debug_info for this comp unit. */
1678 if (comp_unit_die
.has_children
)
1679 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1681 do_cleanups (back_to
);
1684 /* Create a list of all compilation units in OBJFILE. We do this only
1685 if an inter-comp-unit reference is found; presumably if there is one,
1686 there will be many, and one will occur early in the .debug_info section.
1687 So there's no point in building this list incrementally. */
1690 create_all_comp_units (struct objfile
*objfile
)
1694 struct dwarf2_per_cu_data
**all_comp_units
;
1695 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1699 all_comp_units
= xmalloc (n_allocated
1700 * sizeof (struct dwarf2_per_cu_data
*));
1702 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1704 struct comp_unit_head cu_header
;
1705 gdb_byte
*beg_of_comp_unit
;
1706 struct dwarf2_per_cu_data
*this_cu
;
1707 unsigned long offset
;
1708 unsigned int bytes_read
;
1710 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1712 /* Read just enough information to find out where the next
1713 compilation unit is. */
1714 cu_header
.initial_length_size
= 0;
1715 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1716 &cu_header
, &bytes_read
);
1718 /* Save the compilation unit for later lookup. */
1719 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1720 sizeof (struct dwarf2_per_cu_data
));
1721 memset (this_cu
, 0, sizeof (*this_cu
));
1722 this_cu
->offset
= offset
;
1723 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1725 if (n_comp_units
== n_allocated
)
1728 all_comp_units
= xrealloc (all_comp_units
,
1730 * sizeof (struct dwarf2_per_cu_data
*));
1732 all_comp_units
[n_comp_units
++] = this_cu
;
1734 info_ptr
= info_ptr
+ this_cu
->length
;
1737 dwarf2_per_objfile
->all_comp_units
1738 = obstack_alloc (&objfile
->objfile_obstack
,
1739 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1740 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1741 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1742 xfree (all_comp_units
);
1743 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1746 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1747 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1751 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1752 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1754 struct objfile
*objfile
= cu
->objfile
;
1755 bfd
*abfd
= objfile
->obfd
;
1756 struct partial_die_info
*pdi
;
1758 /* Now, march along the PDI's, descending into ones which have
1759 interesting children but skipping the children of the other ones,
1760 until we reach the end of the compilation unit. */
1766 fixup_partial_die (pdi
, cu
);
1768 /* Anonymous namespaces have no name but have interesting
1769 children, so we need to look at them. Ditto for anonymous
1772 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1773 || pdi
->tag
== DW_TAG_enumeration_type
)
1777 case DW_TAG_subprogram
:
1778 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
1780 case DW_TAG_variable
:
1781 case DW_TAG_typedef
:
1782 case DW_TAG_union_type
:
1783 if (!pdi
->is_declaration
)
1785 add_partial_symbol (pdi
, cu
);
1788 case DW_TAG_class_type
:
1789 case DW_TAG_interface_type
:
1790 case DW_TAG_structure_type
:
1791 if (!pdi
->is_declaration
)
1793 add_partial_symbol (pdi
, cu
);
1796 case DW_TAG_enumeration_type
:
1797 if (!pdi
->is_declaration
)
1798 add_partial_enumeration (pdi
, cu
);
1800 case DW_TAG_base_type
:
1801 case DW_TAG_subrange_type
:
1802 /* File scope base type definitions are added to the partial
1804 add_partial_symbol (pdi
, cu
);
1806 case DW_TAG_namespace
:
1807 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1814 /* If the die has a sibling, skip to the sibling. */
1816 pdi
= pdi
->die_sibling
;
1820 /* Functions used to compute the fully scoped name of a partial DIE.
1822 Normally, this is simple. For C++, the parent DIE's fully scoped
1823 name is concatenated with "::" and the partial DIE's name. For
1824 Java, the same thing occurs except that "." is used instead of "::".
1825 Enumerators are an exception; they use the scope of their parent
1826 enumeration type, i.e. the name of the enumeration type is not
1827 prepended to the enumerator.
1829 There are two complexities. One is DW_AT_specification; in this
1830 case "parent" means the parent of the target of the specification,
1831 instead of the direct parent of the DIE. The other is compilers
1832 which do not emit DW_TAG_namespace; in this case we try to guess
1833 the fully qualified name of structure types from their members'
1834 linkage names. This must be done using the DIE's children rather
1835 than the children of any DW_AT_specification target. We only need
1836 to do this for structures at the top level, i.e. if the target of
1837 any DW_AT_specification (if any; otherwise the DIE itself) does not
1840 /* Compute the scope prefix associated with PDI's parent, in
1841 compilation unit CU. The result will be allocated on CU's
1842 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1843 field. NULL is returned if no prefix is necessary. */
1845 partial_die_parent_scope (struct partial_die_info
*pdi
,
1846 struct dwarf2_cu
*cu
)
1848 char *grandparent_scope
;
1849 struct partial_die_info
*parent
, *real_pdi
;
1851 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1852 then this means the parent of the specification DIE. */
1855 while (real_pdi
->has_specification
)
1856 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1858 parent
= real_pdi
->die_parent
;
1862 if (parent
->scope_set
)
1863 return parent
->scope
;
1865 fixup_partial_die (parent
, cu
);
1867 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1869 if (parent
->tag
== DW_TAG_namespace
1870 || parent
->tag
== DW_TAG_structure_type
1871 || parent
->tag
== DW_TAG_class_type
1872 || parent
->tag
== DW_TAG_interface_type
1873 || parent
->tag
== DW_TAG_union_type
)
1875 if (grandparent_scope
== NULL
)
1876 parent
->scope
= parent
->name
;
1878 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1881 else if (parent
->tag
== DW_TAG_enumeration_type
)
1882 /* Enumerators should not get the name of the enumeration as a prefix. */
1883 parent
->scope
= grandparent_scope
;
1886 /* FIXME drow/2004-04-01: What should we be doing with
1887 function-local names? For partial symbols, we should probably be
1889 complaint (&symfile_complaints
,
1890 _("unhandled containing DIE tag %d for DIE at %d"),
1891 parent
->tag
, pdi
->offset
);
1892 parent
->scope
= grandparent_scope
;
1895 parent
->scope_set
= 1;
1896 return parent
->scope
;
1899 /* Return the fully scoped name associated with PDI, from compilation unit
1900 CU. The result will be allocated with malloc. */
1902 partial_die_full_name (struct partial_die_info
*pdi
,
1903 struct dwarf2_cu
*cu
)
1907 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1908 if (parent_scope
== NULL
)
1911 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1915 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1917 struct objfile
*objfile
= cu
->objfile
;
1919 char *actual_name
= NULL
;
1920 const char *my_prefix
;
1921 const struct partial_symbol
*psym
= NULL
;
1923 int built_actual_name
= 0;
1925 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1927 if (pdi_needs_namespace (pdi
->tag
))
1929 actual_name
= partial_die_full_name (pdi
, cu
);
1931 built_actual_name
= 1;
1934 if (actual_name
== NULL
)
1935 actual_name
= pdi
->name
;
1939 case DW_TAG_subprogram
:
1940 if (pdi
->is_external
|| cu
->language
== language_ada
)
1942 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1943 of the global scope. But in Ada, we want to be able to access
1944 nested procedures globally. So all Ada subprograms are stored
1945 in the global scope. */
1946 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1947 mst_text, objfile); */
1948 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1949 VAR_DOMAIN
, LOC_BLOCK
,
1950 &objfile
->global_psymbols
,
1951 0, pdi
->lowpc
+ baseaddr
,
1952 cu
->language
, objfile
);
1956 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1957 mst_file_text, objfile); */
1958 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1959 VAR_DOMAIN
, LOC_BLOCK
,
1960 &objfile
->static_psymbols
,
1961 0, pdi
->lowpc
+ baseaddr
,
1962 cu
->language
, objfile
);
1965 case DW_TAG_variable
:
1966 if (pdi
->is_external
)
1969 Don't enter into the minimal symbol tables as there is
1970 a minimal symbol table entry from the ELF symbols already.
1971 Enter into partial symbol table if it has a location
1972 descriptor or a type.
1973 If the location descriptor is missing, new_symbol will create
1974 a LOC_UNRESOLVED symbol, the address of the variable will then
1975 be determined from the minimal symbol table whenever the variable
1977 The address for the partial symbol table entry is not
1978 used by GDB, but it comes in handy for debugging partial symbol
1982 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1983 if (pdi
->locdesc
|| pdi
->has_type
)
1984 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1985 VAR_DOMAIN
, LOC_STATIC
,
1986 &objfile
->global_psymbols
,
1988 cu
->language
, objfile
);
1992 /* Static Variable. Skip symbols without location descriptors. */
1993 if (pdi
->locdesc
== NULL
)
1995 if (built_actual_name
)
1996 xfree (actual_name
);
1999 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2000 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2001 mst_file_data, objfile); */
2002 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2003 VAR_DOMAIN
, LOC_STATIC
,
2004 &objfile
->static_psymbols
,
2006 cu
->language
, objfile
);
2009 case DW_TAG_typedef
:
2010 case DW_TAG_base_type
:
2011 case DW_TAG_subrange_type
:
2012 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2013 VAR_DOMAIN
, LOC_TYPEDEF
,
2014 &objfile
->static_psymbols
,
2015 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2017 case DW_TAG_namespace
:
2018 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2019 VAR_DOMAIN
, LOC_TYPEDEF
,
2020 &objfile
->global_psymbols
,
2021 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2023 case DW_TAG_class_type
:
2024 case DW_TAG_interface_type
:
2025 case DW_TAG_structure_type
:
2026 case DW_TAG_union_type
:
2027 case DW_TAG_enumeration_type
:
2028 /* Skip external references. The DWARF standard says in the section
2029 about "Structure, Union, and Class Type Entries": "An incomplete
2030 structure, union or class type is represented by a structure,
2031 union or class entry that does not have a byte size attribute
2032 and that has a DW_AT_declaration attribute." */
2033 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2035 if (built_actual_name
)
2036 xfree (actual_name
);
2040 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2041 static vs. global. */
2042 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2043 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2044 (cu
->language
== language_cplus
2045 || cu
->language
== language_java
)
2046 ? &objfile
->global_psymbols
2047 : &objfile
->static_psymbols
,
2048 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2051 case DW_TAG_enumerator
:
2052 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2053 VAR_DOMAIN
, LOC_CONST
,
2054 (cu
->language
== language_cplus
2055 || cu
->language
== language_java
)
2056 ? &objfile
->global_psymbols
2057 : &objfile
->static_psymbols
,
2058 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2064 /* Check to see if we should scan the name for possible namespace
2065 info. Only do this if this is C++, if we don't have namespace
2066 debugging info in the file, if the psym is of an appropriate type
2067 (otherwise we'll have psym == NULL), and if we actually had a
2068 mangled name to begin with. */
2070 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2071 cases which do not set PSYM above? */
2073 if (cu
->language
== language_cplus
2074 && cu
->has_namespace_info
== 0
2076 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2077 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2080 if (built_actual_name
)
2081 xfree (actual_name
);
2084 /* Determine whether a die of type TAG living in a C++ class or
2085 namespace needs to have the name of the scope prepended to the
2086 name listed in the die. */
2089 pdi_needs_namespace (enum dwarf_tag tag
)
2093 case DW_TAG_namespace
:
2094 case DW_TAG_typedef
:
2095 case DW_TAG_class_type
:
2096 case DW_TAG_interface_type
:
2097 case DW_TAG_structure_type
:
2098 case DW_TAG_union_type
:
2099 case DW_TAG_enumeration_type
:
2100 case DW_TAG_enumerator
:
2107 /* Read a partial die corresponding to a namespace; also, add a symbol
2108 corresponding to that namespace to the symbol table. NAMESPACE is
2109 the name of the enclosing namespace. */
2112 add_partial_namespace (struct partial_die_info
*pdi
,
2113 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2114 struct dwarf2_cu
*cu
)
2116 struct objfile
*objfile
= cu
->objfile
;
2118 /* Add a symbol for the namespace. */
2120 add_partial_symbol (pdi
, cu
);
2122 /* Now scan partial symbols in that namespace. */
2124 if (pdi
->has_children
)
2125 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2128 /* Read a partial die corresponding to a subprogram and create a partial
2129 symbol for that subprogram. When the CU language allows it, this
2130 routine also defines a partial symbol for each nested subprogram
2131 that this subprogram contains.
2133 DIE my also be a lexical block, in which case we simply search
2134 recursively for suprograms defined inside that lexical block.
2135 Again, this is only performed when the CU language allows this
2136 type of definitions. */
2139 add_partial_subprogram (struct partial_die_info
*pdi
,
2140 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2141 struct dwarf2_cu
*cu
)
2143 if (pdi
->tag
== DW_TAG_subprogram
)
2145 if (pdi
->has_pc_info
)
2147 if (pdi
->lowpc
< *lowpc
)
2148 *lowpc
= pdi
->lowpc
;
2149 if (pdi
->highpc
> *highpc
)
2150 *highpc
= pdi
->highpc
;
2151 if (!pdi
->is_declaration
)
2152 add_partial_symbol (pdi
, cu
);
2156 if (! pdi
->has_children
)
2159 if (cu
->language
== language_ada
)
2161 pdi
= pdi
->die_child
;
2164 fixup_partial_die (pdi
, cu
);
2165 if (pdi
->tag
== DW_TAG_subprogram
2166 || pdi
->tag
== DW_TAG_lexical_block
)
2167 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
2168 pdi
= pdi
->die_sibling
;
2173 /* See if we can figure out if the class lives in a namespace. We do
2174 this by looking for a member function; its demangled name will
2175 contain namespace info, if there is any. */
2178 guess_structure_name (struct partial_die_info
*struct_pdi
,
2179 struct dwarf2_cu
*cu
)
2181 if ((cu
->language
== language_cplus
2182 || cu
->language
== language_java
)
2183 && cu
->has_namespace_info
== 0
2184 && struct_pdi
->has_children
)
2186 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2187 what template types look like, because the demangler
2188 frequently doesn't give the same name as the debug info. We
2189 could fix this by only using the demangled name to get the
2190 prefix (but see comment in read_structure_type). */
2192 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2193 struct partial_die_info
*real_pdi
;
2195 /* If this DIE (this DIE's specification, if any) has a parent, then
2196 we should not do this. We'll prepend the parent's fully qualified
2197 name when we create the partial symbol. */
2199 real_pdi
= struct_pdi
;
2200 while (real_pdi
->has_specification
)
2201 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2203 if (real_pdi
->die_parent
!= NULL
)
2206 while (child_pdi
!= NULL
)
2208 if (child_pdi
->tag
== DW_TAG_subprogram
)
2210 char *actual_class_name
2211 = language_class_name_from_physname (cu
->language_defn
,
2213 if (actual_class_name
!= NULL
)
2216 = obsavestring (actual_class_name
,
2217 strlen (actual_class_name
),
2218 &cu
->comp_unit_obstack
);
2219 xfree (actual_class_name
);
2224 child_pdi
= child_pdi
->die_sibling
;
2229 /* Read a partial die corresponding to an enumeration type. */
2232 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2233 struct dwarf2_cu
*cu
)
2235 struct objfile
*objfile
= cu
->objfile
;
2236 bfd
*abfd
= objfile
->obfd
;
2237 struct partial_die_info
*pdi
;
2239 if (enum_pdi
->name
!= NULL
)
2240 add_partial_symbol (enum_pdi
, cu
);
2242 pdi
= enum_pdi
->die_child
;
2245 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2246 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2248 add_partial_symbol (pdi
, cu
);
2249 pdi
= pdi
->die_sibling
;
2253 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2254 Return the corresponding abbrev, or NULL if the number is zero (indicating
2255 an empty DIE). In either case *BYTES_READ will be set to the length of
2256 the initial number. */
2258 static struct abbrev_info
*
2259 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2260 struct dwarf2_cu
*cu
)
2262 bfd
*abfd
= cu
->objfile
->obfd
;
2263 unsigned int abbrev_number
;
2264 struct abbrev_info
*abbrev
;
2266 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2268 if (abbrev_number
== 0)
2271 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2274 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2275 bfd_get_filename (abfd
));
2281 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2282 pointer to the end of a series of DIEs, terminated by an empty
2283 DIE. Any children of the skipped DIEs will also be skipped. */
2286 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2288 struct abbrev_info
*abbrev
;
2289 unsigned int bytes_read
;
2293 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2295 return info_ptr
+ bytes_read
;
2297 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2301 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2302 should point just after the initial uleb128 of a DIE, and the
2303 abbrev corresponding to that skipped uleb128 should be passed in
2304 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2308 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2309 struct dwarf2_cu
*cu
)
2311 unsigned int bytes_read
;
2312 struct attribute attr
;
2313 bfd
*abfd
= cu
->objfile
->obfd
;
2314 unsigned int form
, i
;
2316 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2318 /* The only abbrev we care about is DW_AT_sibling. */
2319 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2321 read_attribute (&attr
, &abbrev
->attrs
[i
],
2322 abfd
, info_ptr
, cu
);
2323 if (attr
.form
== DW_FORM_ref_addr
)
2324 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2326 return dwarf2_per_objfile
->info_buffer
2327 + dwarf2_get_ref_die_offset (&attr
, cu
);
2330 /* If it isn't DW_AT_sibling, skip this attribute. */
2331 form
= abbrev
->attrs
[i
].form
;
2336 case DW_FORM_ref_addr
:
2337 info_ptr
+= cu
->header
.addr_size
;
2356 case DW_FORM_string
:
2357 read_string (abfd
, info_ptr
, &bytes_read
);
2358 info_ptr
+= bytes_read
;
2361 info_ptr
+= cu
->header
.offset_size
;
2364 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2365 info_ptr
+= bytes_read
;
2367 case DW_FORM_block1
:
2368 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2370 case DW_FORM_block2
:
2371 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2373 case DW_FORM_block4
:
2374 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2378 case DW_FORM_ref_udata
:
2379 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2381 case DW_FORM_indirect
:
2382 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2383 info_ptr
+= bytes_read
;
2384 /* We need to continue parsing from here, so just go back to
2386 goto skip_attribute
;
2389 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2390 dwarf_form_name (form
),
2391 bfd_get_filename (abfd
));
2395 if (abbrev
->has_children
)
2396 return skip_children (info_ptr
, cu
);
2401 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2402 the next DIE after ORIG_PDI. */
2405 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2406 bfd
*abfd
, struct dwarf2_cu
*cu
)
2408 /* Do we know the sibling already? */
2410 if (orig_pdi
->sibling
)
2411 return orig_pdi
->sibling
;
2413 /* Are there any children to deal with? */
2415 if (!orig_pdi
->has_children
)
2418 /* Skip the children the long way. */
2420 return skip_children (info_ptr
, cu
);
2423 /* Expand this partial symbol table into a full symbol table. */
2426 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2428 /* FIXME: This is barely more than a stub. */
2433 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2439 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2440 gdb_flush (gdb_stdout
);
2443 /* Restore our global data. */
2444 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2445 dwarf2_objfile_data_key
);
2447 psymtab_to_symtab_1 (pst
);
2449 /* Finish up the debug error message. */
2451 printf_filtered (_("done.\n"));
2456 /* Add PER_CU to the queue. */
2459 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2461 struct dwarf2_queue_item
*item
;
2464 item
= xmalloc (sizeof (*item
));
2465 item
->per_cu
= per_cu
;
2468 if (dwarf2_queue
== NULL
)
2469 dwarf2_queue
= item
;
2471 dwarf2_queue_tail
->next
= item
;
2473 dwarf2_queue_tail
= item
;
2475 /* Either PER_CU is the CU we want to process, or we're following a reference
2476 pointing into PER_CU. Either way, we need its DIEs now. */
2477 load_full_comp_unit (item
->per_cu
, objfile
);
2478 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2479 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2482 /* Process the queue. */
2485 process_queue (struct objfile
*objfile
)
2487 struct dwarf2_queue_item
*item
, *next_item
;
2489 /* The queue starts out with one item, but following a DIE reference
2490 may load a new CU, adding it to the end of the queue. */
2491 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2493 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2494 process_full_comp_unit (item
->per_cu
);
2496 item
->per_cu
->queued
= 0;
2497 next_item
= item
->next
;
2501 dwarf2_queue_tail
= NULL
;
2504 /* Free all allocated queue entries. This function only releases anything if
2505 an error was thrown; if the queue was processed then it would have been
2506 freed as we went along. */
2509 dwarf2_release_queue (void *dummy
)
2511 struct dwarf2_queue_item
*item
, *last
;
2513 item
= dwarf2_queue
;
2516 /* Anything still marked queued is likely to be in an
2517 inconsistent state, so discard it. */
2518 if (item
->per_cu
->queued
)
2520 if (item
->per_cu
->cu
!= NULL
)
2521 free_one_cached_comp_unit (item
->per_cu
->cu
);
2522 item
->per_cu
->queued
= 0;
2530 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2533 /* Read in full symbols for PST, and anything it depends on. */
2536 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2538 struct dwarf2_per_cu_data
*per_cu
;
2539 struct cleanup
*back_to
;
2542 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2543 if (!pst
->dependencies
[i
]->readin
)
2545 /* Inform about additional files that need to be read in. */
2548 /* FIXME: i18n: Need to make this a single string. */
2549 fputs_filtered (" ", gdb_stdout
);
2551 fputs_filtered ("and ", gdb_stdout
);
2553 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2554 wrap_here (""); /* Flush output */
2555 gdb_flush (gdb_stdout
);
2557 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2560 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2564 /* It's an include file, no symbols to read for it.
2565 Everything is in the parent symtab. */
2570 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2572 queue_comp_unit (per_cu
, pst
->objfile
);
2574 process_queue (pst
->objfile
);
2576 /* Age the cache, releasing compilation units that have not
2577 been used recently. */
2578 age_cached_comp_units ();
2580 do_cleanups (back_to
);
2583 /* Load the DIEs associated with PST and PER_CU into memory. */
2585 static struct dwarf2_cu
*
2586 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2588 bfd
*abfd
= objfile
->obfd
;
2589 struct dwarf2_cu
*cu
;
2590 unsigned long offset
;
2592 struct cleanup
*back_to
, *free_cu_cleanup
;
2593 struct attribute
*attr
;
2596 /* Set local variables from the partial symbol table info. */
2597 offset
= per_cu
->offset
;
2599 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2601 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2602 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2604 /* If an error occurs while loading, release our storage. */
2605 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2607 cu
->objfile
= objfile
;
2609 /* read in the comp_unit header */
2610 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2612 /* Read the abbrevs for this compilation unit */
2613 dwarf2_read_abbrevs (abfd
, cu
);
2614 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2616 cu
->header
.offset
= offset
;
2618 cu
->per_cu
= per_cu
;
2620 cu
->type_hash
= per_cu
->type_hash
;
2622 /* We use this obstack for block values in dwarf_alloc_block. */
2623 obstack_init (&cu
->comp_unit_obstack
);
2625 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2627 /* We try not to read any attributes in this function, because not
2628 all objfiles needed for references have been loaded yet, and symbol
2629 table processing isn't initialized. But we have to set the CU language,
2630 or we won't be able to build types correctly. */
2631 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2633 set_cu_language (DW_UNSND (attr
), cu
);
2635 set_cu_language (language_minimal
, cu
);
2637 do_cleanups (back_to
);
2639 /* We've successfully allocated this compilation unit. Let our caller
2640 clean it up when finished with it. */
2641 discard_cleanups (free_cu_cleanup
);
2646 /* Generate full symbol information for PST and CU, whose DIEs have
2647 already been loaded into memory. */
2650 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2652 struct partial_symtab
*pst
= per_cu
->psymtab
;
2653 struct dwarf2_cu
*cu
= per_cu
->cu
;
2654 struct objfile
*objfile
= pst
->objfile
;
2655 bfd
*abfd
= objfile
->obfd
;
2656 CORE_ADDR lowpc
, highpc
;
2657 struct symtab
*symtab
;
2658 struct cleanup
*back_to
;
2659 struct attribute
*attr
;
2662 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2665 back_to
= make_cleanup (really_free_pendings
, NULL
);
2667 cu
->list_in_scope
= &file_symbols
;
2669 /* Find the base address of the compilation unit for range lists and
2670 location lists. It will normally be specified by DW_AT_low_pc.
2671 In DWARF-3 draft 4, the base address could be overridden by
2672 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2673 compilation units with discontinuous ranges. */
2676 cu
->base_address
= 0;
2678 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2681 cu
->base_address
= DW_ADDR (attr
);
2686 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2689 cu
->base_address
= DW_ADDR (attr
);
2694 /* Do line number decoding in read_file_scope () */
2695 process_die (cu
->dies
, cu
);
2697 /* Some compilers don't define a DW_AT_high_pc attribute for the
2698 compilation unit. If the DW_AT_high_pc is missing, synthesize
2699 it, by scanning the DIE's below the compilation unit. */
2700 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2702 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2704 /* Set symtab language to language from DW_AT_language.
2705 If the compilation is from a C file generated by language preprocessors,
2706 do not set the language if it was already deduced by start_subfile. */
2708 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2710 symtab
->language
= cu
->language
;
2712 pst
->symtab
= symtab
;
2715 do_cleanups (back_to
);
2718 /* Process a die and its children. */
2721 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2725 case DW_TAG_padding
:
2727 case DW_TAG_compile_unit
:
2728 read_file_scope (die
, cu
);
2730 case DW_TAG_subprogram
:
2731 read_func_scope (die
, cu
);
2733 case DW_TAG_inlined_subroutine
:
2734 /* FIXME: These are ignored for now.
2735 They could be used to set breakpoints on all inlined instances
2736 of a function and make GDB `next' properly over inlined functions. */
2738 case DW_TAG_lexical_block
:
2739 case DW_TAG_try_block
:
2740 case DW_TAG_catch_block
:
2741 read_lexical_block_scope (die
, cu
);
2743 case DW_TAG_class_type
:
2744 case DW_TAG_interface_type
:
2745 case DW_TAG_structure_type
:
2746 case DW_TAG_union_type
:
2747 process_structure_scope (die
, cu
);
2749 case DW_TAG_enumeration_type
:
2750 process_enumeration_scope (die
, cu
);
2753 /* These dies have a type, but processing them does not create
2754 a symbol or recurse to process the children. Therefore we can
2755 read them on-demand through read_type_die. */
2756 case DW_TAG_subroutine_type
:
2757 case DW_TAG_set_type
:
2758 case DW_TAG_array_type
:
2759 case DW_TAG_pointer_type
:
2760 case DW_TAG_ptr_to_member_type
:
2761 case DW_TAG_reference_type
:
2762 case DW_TAG_string_type
:
2765 case DW_TAG_base_type
:
2766 case DW_TAG_subrange_type
:
2767 /* Add a typedef symbol for the type definition, if it has a
2769 new_symbol (die
, read_type_die (die
, cu
), cu
);
2771 case DW_TAG_common_block
:
2772 read_common_block (die
, cu
);
2774 case DW_TAG_common_inclusion
:
2776 case DW_TAG_namespace
:
2777 processing_has_namespace_info
= 1;
2778 read_namespace (die
, cu
);
2780 case DW_TAG_imported_declaration
:
2781 case DW_TAG_imported_module
:
2782 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2783 information contained in these. DW_TAG_imported_declaration
2784 dies shouldn't have children; DW_TAG_imported_module dies
2785 shouldn't in the C++ case, but conceivably could in the
2787 processing_has_namespace_info
= 1;
2788 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2789 dwarf_tag_name (die
->tag
));
2792 new_symbol (die
, NULL
, cu
);
2797 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2798 If scope qualifiers are appropriate they will be added. The result
2799 will be allocated on the objfile_obstack, or NULL if the DIE does
2803 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2805 struct attribute
*attr
;
2806 char *prefix
, *name
;
2807 struct ui_file
*buf
= NULL
;
2809 name
= dwarf2_name (die
, cu
);
2813 /* These are the only languages we know how to qualify names in. */
2814 if (cu
->language
!= language_cplus
2815 && cu
->language
!= language_java
)
2818 /* If no prefix is necessary for this type of DIE, return the
2819 unqualified name. The other three tags listed could be handled
2820 in pdi_needs_namespace, but that requires broader changes. */
2821 if (!pdi_needs_namespace (die
->tag
)
2822 && die
->tag
!= DW_TAG_subprogram
2823 && die
->tag
!= DW_TAG_variable
2824 && die
->tag
!= DW_TAG_member
)
2827 prefix
= determine_prefix (die
, cu
);
2828 if (*prefix
!= '\0')
2829 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2836 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2838 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2842 free_cu_line_header (void *arg
)
2844 struct dwarf2_cu
*cu
= arg
;
2846 free_line_header (cu
->line_header
);
2847 cu
->line_header
= NULL
;
2851 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2853 struct objfile
*objfile
= cu
->objfile
;
2854 struct comp_unit_head
*cu_header
= &cu
->header
;
2855 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2856 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2857 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2858 struct attribute
*attr
;
2860 char *comp_dir
= NULL
;
2861 struct die_info
*child_die
;
2862 bfd
*abfd
= objfile
->obfd
;
2863 struct line_header
*line_header
= 0;
2866 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2868 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2870 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2871 from finish_block. */
2872 if (lowpc
== ((CORE_ADDR
) -1))
2877 /* Find the filename. Do not use dwarf2_name here, since the filename
2878 is not a source language identifier. */
2879 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2882 name
= DW_STRING (attr
);
2885 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2887 comp_dir
= DW_STRING (attr
);
2888 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2890 comp_dir
= ldirname (name
);
2891 if (comp_dir
!= NULL
)
2892 make_cleanup (xfree
, comp_dir
);
2894 if (comp_dir
!= NULL
)
2896 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2897 directory, get rid of it. */
2898 char *cp
= strchr (comp_dir
, ':');
2900 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2907 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2910 set_cu_language (DW_UNSND (attr
), cu
);
2913 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2915 cu
->producer
= DW_STRING (attr
);
2917 /* We assume that we're processing GCC output. */
2918 processing_gcc_compilation
= 2;
2920 processing_has_namespace_info
= 0;
2922 start_symtab (name
, comp_dir
, lowpc
);
2923 record_debugformat ("DWARF 2");
2924 record_producer (cu
->producer
);
2926 initialize_cu_func_list (cu
);
2928 /* Decode line number information if present. We do this before
2929 processing child DIEs, so that the line header table is available
2930 for DW_AT_decl_file. */
2931 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2934 unsigned int line_offset
= DW_UNSND (attr
);
2935 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2938 cu
->line_header
= line_header
;
2939 make_cleanup (free_cu_line_header
, cu
);
2940 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2944 /* Process all dies in compilation unit. */
2945 if (die
->child
!= NULL
)
2947 child_die
= die
->child
;
2948 while (child_die
&& child_die
->tag
)
2950 process_die (child_die
, cu
);
2951 child_die
= sibling_die (child_die
);
2955 /* Decode macro information, if present. Dwarf 2 macro information
2956 refers to information in the line number info statement program
2957 header, so we can only read it if we've read the header
2959 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2960 if (attr
&& line_header
)
2962 unsigned int macro_offset
= DW_UNSND (attr
);
2963 dwarf_decode_macros (line_header
, macro_offset
,
2964 comp_dir
, abfd
, cu
);
2966 do_cleanups (back_to
);
2970 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2971 struct dwarf2_cu
*cu
)
2973 struct function_range
*thisfn
;
2975 thisfn
= (struct function_range
*)
2976 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2977 thisfn
->name
= name
;
2978 thisfn
->lowpc
= lowpc
;
2979 thisfn
->highpc
= highpc
;
2980 thisfn
->seen_line
= 0;
2981 thisfn
->next
= NULL
;
2983 if (cu
->last_fn
== NULL
)
2984 cu
->first_fn
= thisfn
;
2986 cu
->last_fn
->next
= thisfn
;
2988 cu
->last_fn
= thisfn
;
2992 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2994 struct objfile
*objfile
= cu
->objfile
;
2995 struct context_stack
*new;
2998 struct die_info
*child_die
;
2999 struct attribute
*attr
;
3002 struct block
*block
;
3004 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3006 name
= dwarf2_linkage_name (die
, cu
);
3008 /* Ignore functions with missing or empty names and functions with
3009 missing or invalid low and high pc attributes. */
3010 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3016 /* Record the function range for dwarf_decode_lines. */
3017 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3019 new = push_context (0, lowpc
);
3020 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3022 /* If there is a location expression for DW_AT_frame_base, record
3024 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3026 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3027 expression is being recorded directly in the function's symbol
3028 and not in a separate frame-base object. I guess this hack is
3029 to avoid adding some sort of frame-base adjunct/annex to the
3030 function's symbol :-(. The problem with doing this is that it
3031 results in a function symbol with a location expression that
3032 has nothing to do with the location of the function, ouch! The
3033 relationship should be: a function's symbol has-a frame base; a
3034 frame-base has-a location expression. */
3035 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3037 cu
->list_in_scope
= &local_symbols
;
3039 if (die
->child
!= NULL
)
3041 child_die
= die
->child
;
3042 while (child_die
&& child_die
->tag
)
3044 process_die (child_die
, cu
);
3045 child_die
= sibling_die (child_die
);
3049 new = pop_context ();
3050 /* Make a block for the local symbols within. */
3051 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3052 lowpc
, highpc
, objfile
);
3054 /* For C++, set the block's scope. */
3055 if (cu
->language
== language_cplus
)
3056 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3057 determine_prefix (die
, cu
),
3058 processing_has_namespace_info
);
3060 /* If we have address ranges, record them. */
3061 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3063 /* In C++, we can have functions nested inside functions (e.g., when
3064 a function declares a class that has methods). This means that
3065 when we finish processing a function scope, we may need to go
3066 back to building a containing block's symbol lists. */
3067 local_symbols
= new->locals
;
3068 param_symbols
= new->params
;
3070 /* If we've finished processing a top-level function, subsequent
3071 symbols go in the file symbol list. */
3072 if (outermost_context_p ())
3073 cu
->list_in_scope
= &file_symbols
;
3076 /* Process all the DIES contained within a lexical block scope. Start
3077 a new scope, process the dies, and then close the scope. */
3080 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3082 struct objfile
*objfile
= cu
->objfile
;
3083 struct context_stack
*new;
3084 CORE_ADDR lowpc
, highpc
;
3085 struct die_info
*child_die
;
3088 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3090 /* Ignore blocks with missing or invalid low and high pc attributes. */
3091 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3092 as multiple lexical blocks? Handling children in a sane way would
3093 be nasty. Might be easier to properly extend generic blocks to
3095 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3100 push_context (0, lowpc
);
3101 if (die
->child
!= NULL
)
3103 child_die
= die
->child
;
3104 while (child_die
&& child_die
->tag
)
3106 process_die (child_die
, cu
);
3107 child_die
= sibling_die (child_die
);
3110 new = pop_context ();
3112 if (local_symbols
!= NULL
)
3115 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3118 /* Note that recording ranges after traversing children, as we
3119 do here, means that recording a parent's ranges entails
3120 walking across all its children's ranges as they appear in
3121 the address map, which is quadratic behavior.
3123 It would be nicer to record the parent's ranges before
3124 traversing its children, simply overriding whatever you find
3125 there. But since we don't even decide whether to create a
3126 block until after we've traversed its children, that's hard
3128 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3130 local_symbols
= new->locals
;
3133 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3134 Return 1 if the attributes are present and valid, otherwise, return 0.
3135 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3138 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3139 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3140 struct partial_symtab
*ranges_pst
)
3142 struct objfile
*objfile
= cu
->objfile
;
3143 struct comp_unit_head
*cu_header
= &cu
->header
;
3144 bfd
*obfd
= objfile
->obfd
;
3145 unsigned int addr_size
= cu_header
->addr_size
;
3146 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3147 /* Base address selection entry. */
3158 found_base
= cu
->base_known
;
3159 base
= cu
->base_address
;
3161 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3163 complaint (&symfile_complaints
,
3164 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3168 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3170 /* Read in the largest possible address. */
3171 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3172 if ((marker
& mask
) == mask
)
3174 /* If we found the largest possible address, then
3175 read the base address. */
3176 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3177 buffer
+= 2 * addr_size
;
3178 offset
+= 2 * addr_size
;
3184 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3188 CORE_ADDR range_beginning
, range_end
;
3190 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3191 buffer
+= addr_size
;
3192 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3193 buffer
+= addr_size
;
3194 offset
+= 2 * addr_size
;
3196 /* An end of list marker is a pair of zero addresses. */
3197 if (range_beginning
== 0 && range_end
== 0)
3198 /* Found the end of list entry. */
3201 /* Each base address selection entry is a pair of 2 values.
3202 The first is the largest possible address, the second is
3203 the base address. Check for a base address here. */
3204 if ((range_beginning
& mask
) == mask
)
3206 /* If we found the largest possible address, then
3207 read the base address. */
3208 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3215 /* We have no valid base address for the ranges
3217 complaint (&symfile_complaints
,
3218 _("Invalid .debug_ranges data (no base address)"));
3222 range_beginning
+= base
;
3225 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3226 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3227 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3230 /* FIXME: This is recording everything as a low-high
3231 segment of consecutive addresses. We should have a
3232 data structure for discontiguous block ranges
3236 low
= range_beginning
;
3242 if (range_beginning
< low
)
3243 low
= range_beginning
;
3244 if (range_end
> high
)
3250 /* If the first entry is an end-of-list marker, the range
3251 describes an empty scope, i.e. no instructions. */
3257 *high_return
= high
;
3261 /* Get low and high pc attributes from a die. Return 1 if the attributes
3262 are present and valid, otherwise, return 0. Return -1 if the range is
3263 discontinuous, i.e. derived from DW_AT_ranges information. */
3265 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3266 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3268 struct attribute
*attr
;
3273 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3276 high
= DW_ADDR (attr
);
3277 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3279 low
= DW_ADDR (attr
);
3281 /* Found high w/o low attribute. */
3284 /* Found consecutive range of addresses. */
3289 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3292 /* Value of the DW_AT_ranges attribute is the offset in the
3293 .debug_ranges section. */
3294 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3296 /* Found discontinuous range of addresses. */
3304 /* When using the GNU linker, .gnu.linkonce. sections are used to
3305 eliminate duplicate copies of functions and vtables and such.
3306 The linker will arbitrarily choose one and discard the others.
3307 The AT_*_pc values for such functions refer to local labels in
3308 these sections. If the section from that file was discarded, the
3309 labels are not in the output, so the relocs get a value of 0.
3310 If this is a discarded function, mark the pc bounds as invalid,
3311 so that GDB will ignore it. */
3312 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3320 /* Get the low and high pc's represented by the scope DIE, and store
3321 them in *LOWPC and *HIGHPC. If the correct values can't be
3322 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3325 get_scope_pc_bounds (struct die_info
*die
,
3326 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3327 struct dwarf2_cu
*cu
)
3329 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3330 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3331 CORE_ADDR current_low
, current_high
;
3333 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3335 best_low
= current_low
;
3336 best_high
= current_high
;
3340 struct die_info
*child
= die
->child
;
3342 while (child
&& child
->tag
)
3344 switch (child
->tag
) {
3345 case DW_TAG_subprogram
:
3346 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3348 best_low
= min (best_low
, current_low
);
3349 best_high
= max (best_high
, current_high
);
3352 case DW_TAG_namespace
:
3353 /* FIXME: carlton/2004-01-16: Should we do this for
3354 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3355 that current GCC's always emit the DIEs corresponding
3356 to definitions of methods of classes as children of a
3357 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3358 the DIEs giving the declarations, which could be
3359 anywhere). But I don't see any reason why the
3360 standards says that they have to be there. */
3361 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3363 if (current_low
!= ((CORE_ADDR
) -1))
3365 best_low
= min (best_low
, current_low
);
3366 best_high
= max (best_high
, current_high
);
3374 child
= sibling_die (child
);
3379 *highpc
= best_high
;
3382 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3385 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3386 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3388 struct attribute
*attr
;
3390 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3393 CORE_ADDR high
= DW_ADDR (attr
);
3394 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3397 CORE_ADDR low
= DW_ADDR (attr
);
3398 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3402 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3405 bfd
*obfd
= cu
->objfile
->obfd
;
3407 /* The value of the DW_AT_ranges attribute is the offset of the
3408 address range list in the .debug_ranges section. */
3409 unsigned long offset
= DW_UNSND (attr
);
3410 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3412 /* For some target architectures, but not others, the
3413 read_address function sign-extends the addresses it returns.
3414 To recognize base address selection entries, we need a
3416 unsigned int addr_size
= cu
->header
.addr_size
;
3417 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3419 /* The base address, to which the next pair is relative. Note
3420 that this 'base' is a DWARF concept: most entries in a range
3421 list are relative, to reduce the number of relocs against the
3422 debugging information. This is separate from this function's
3423 'baseaddr' argument, which GDB uses to relocate debugging
3424 information from a shared library based on the address at
3425 which the library was loaded. */
3426 CORE_ADDR base
= cu
->base_address
;
3427 int base_known
= cu
->base_known
;
3429 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3431 complaint (&symfile_complaints
,
3432 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3439 unsigned int bytes_read
;
3440 CORE_ADDR start
, end
;
3442 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3443 buffer
+= bytes_read
;
3444 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3445 buffer
+= bytes_read
;
3447 /* Did we find the end of the range list? */
3448 if (start
== 0 && end
== 0)
3451 /* Did we find a base address selection entry? */
3452 else if ((start
& base_select_mask
) == base_select_mask
)
3458 /* We found an ordinary address range. */
3463 complaint (&symfile_complaints
,
3464 _("Invalid .debug_ranges data (no base address)"));
3468 record_block_range (block
,
3469 baseaddr
+ base
+ start
,
3470 baseaddr
+ base
+ end
- 1);
3476 /* Add an aggregate field to the field list. */
3479 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3480 struct dwarf2_cu
*cu
)
3482 struct objfile
*objfile
= cu
->objfile
;
3483 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3484 struct nextfield
*new_field
;
3485 struct attribute
*attr
;
3487 char *fieldname
= "";
3489 /* Allocate a new field list entry and link it in. */
3490 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3491 make_cleanup (xfree
, new_field
);
3492 memset (new_field
, 0, sizeof (struct nextfield
));
3493 new_field
->next
= fip
->fields
;
3494 fip
->fields
= new_field
;
3497 /* Handle accessibility and virtuality of field.
3498 The default accessibility for members is public, the default
3499 accessibility for inheritance is private. */
3500 if (die
->tag
!= DW_TAG_inheritance
)
3501 new_field
->accessibility
= DW_ACCESS_public
;
3503 new_field
->accessibility
= DW_ACCESS_private
;
3504 new_field
->virtuality
= DW_VIRTUALITY_none
;
3506 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3508 new_field
->accessibility
= DW_UNSND (attr
);
3509 if (new_field
->accessibility
!= DW_ACCESS_public
)
3510 fip
->non_public_fields
= 1;
3511 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3513 new_field
->virtuality
= DW_UNSND (attr
);
3515 fp
= &new_field
->field
;
3517 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3519 /* Data member other than a C++ static data member. */
3521 /* Get type of field. */
3522 fp
->type
= die_type (die
, cu
);
3524 FIELD_STATIC_KIND (*fp
) = 0;
3526 /* Get bit size of field (zero if none). */
3527 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3530 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3534 FIELD_BITSIZE (*fp
) = 0;
3537 /* Get bit offset of field. */
3538 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3543 if (attr_form_is_section_offset (attr
))
3545 dwarf2_complex_location_expr_complaint ();
3548 else if (attr_form_is_constant (attr
))
3549 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3551 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3553 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3556 FIELD_BITPOS (*fp
) = 0;
3557 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3560 if (gdbarch_bits_big_endian (gdbarch
))
3562 /* For big endian bits, the DW_AT_bit_offset gives the
3563 additional bit offset from the MSB of the containing
3564 anonymous object to the MSB of the field. We don't
3565 have to do anything special since we don't need to
3566 know the size of the anonymous object. */
3567 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3571 /* For little endian bits, compute the bit offset to the
3572 MSB of the anonymous object, subtract off the number of
3573 bits from the MSB of the field to the MSB of the
3574 object, and then subtract off the number of bits of
3575 the field itself. The result is the bit offset of
3576 the LSB of the field. */
3578 int bit_offset
= DW_UNSND (attr
);
3580 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3583 /* The size of the anonymous object containing
3584 the bit field is explicit, so use the
3585 indicated size (in bytes). */
3586 anonymous_size
= DW_UNSND (attr
);
3590 /* The size of the anonymous object containing
3591 the bit field must be inferred from the type
3592 attribute of the data member containing the
3594 anonymous_size
= TYPE_LENGTH (fp
->type
);
3596 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3597 - bit_offset
- FIELD_BITSIZE (*fp
);
3601 /* Get name of field. */
3602 fieldname
= dwarf2_name (die
, cu
);
3603 if (fieldname
== NULL
)
3606 /* The name is already allocated along with this objfile, so we don't
3607 need to duplicate it for the type. */
3608 fp
->name
= fieldname
;
3610 /* Change accessibility for artificial fields (e.g. virtual table
3611 pointer or virtual base class pointer) to private. */
3612 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3614 new_field
->accessibility
= DW_ACCESS_private
;
3615 fip
->non_public_fields
= 1;
3618 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3620 /* C++ static member. */
3622 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3623 is a declaration, but all versions of G++ as of this writing
3624 (so through at least 3.2.1) incorrectly generate
3625 DW_TAG_variable tags. */
3629 /* Get name of field. */
3630 fieldname
= dwarf2_name (die
, cu
);
3631 if (fieldname
== NULL
)
3634 /* Get physical name. */
3635 physname
= dwarf2_linkage_name (die
, cu
);
3637 /* The name is already allocated along with this objfile, so we don't
3638 need to duplicate it for the type. */
3639 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3640 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3641 FIELD_NAME (*fp
) = fieldname
;
3643 else if (die
->tag
== DW_TAG_inheritance
)
3645 /* C++ base class field. */
3646 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3648 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3650 FIELD_BITSIZE (*fp
) = 0;
3651 FIELD_STATIC_KIND (*fp
) = 0;
3652 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3653 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3654 fip
->nbaseclasses
++;
3658 /* Create the vector of fields, and attach it to the type. */
3661 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3662 struct dwarf2_cu
*cu
)
3664 int nfields
= fip
->nfields
;
3666 /* Record the field count, allocate space for the array of fields,
3667 and create blank accessibility bitfields if necessary. */
3668 TYPE_NFIELDS (type
) = nfields
;
3669 TYPE_FIELDS (type
) = (struct field
*)
3670 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3671 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3673 if (fip
->non_public_fields
)
3675 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3677 TYPE_FIELD_PRIVATE_BITS (type
) =
3678 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3679 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3681 TYPE_FIELD_PROTECTED_BITS (type
) =
3682 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3683 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3685 TYPE_FIELD_IGNORE_BITS (type
) =
3686 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3687 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3690 /* If the type has baseclasses, allocate and clear a bit vector for
3691 TYPE_FIELD_VIRTUAL_BITS. */
3692 if (fip
->nbaseclasses
)
3694 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3695 unsigned char *pointer
;
3697 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3698 pointer
= TYPE_ALLOC (type
, num_bytes
);
3699 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3700 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3701 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3704 /* Copy the saved-up fields into the field vector. Start from the head
3705 of the list, adding to the tail of the field array, so that they end
3706 up in the same order in the array in which they were added to the list. */
3707 while (nfields
-- > 0)
3709 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3710 switch (fip
->fields
->accessibility
)
3712 case DW_ACCESS_private
:
3713 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3716 case DW_ACCESS_protected
:
3717 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3720 case DW_ACCESS_public
:
3724 /* Unknown accessibility. Complain and treat it as public. */
3726 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3727 fip
->fields
->accessibility
);
3731 if (nfields
< fip
->nbaseclasses
)
3733 switch (fip
->fields
->virtuality
)
3735 case DW_VIRTUALITY_virtual
:
3736 case DW_VIRTUALITY_pure_virtual
:
3737 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3741 fip
->fields
= fip
->fields
->next
;
3745 /* Add a member function to the proper fieldlist. */
3748 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3749 struct type
*type
, struct dwarf2_cu
*cu
)
3751 struct objfile
*objfile
= cu
->objfile
;
3752 struct attribute
*attr
;
3753 struct fnfieldlist
*flp
;
3755 struct fn_field
*fnp
;
3758 struct nextfnfield
*new_fnfield
;
3759 struct type
*this_type
;
3761 /* Get name of member function. */
3762 fieldname
= dwarf2_name (die
, cu
);
3763 if (fieldname
== NULL
)
3766 /* Get the mangled name. */
3767 physname
= dwarf2_linkage_name (die
, cu
);
3769 /* Look up member function name in fieldlist. */
3770 for (i
= 0; i
< fip
->nfnfields
; i
++)
3772 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3776 /* Create new list element if necessary. */
3777 if (i
< fip
->nfnfields
)
3778 flp
= &fip
->fnfieldlists
[i
];
3781 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3783 fip
->fnfieldlists
= (struct fnfieldlist
*)
3784 xrealloc (fip
->fnfieldlists
,
3785 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3786 * sizeof (struct fnfieldlist
));
3787 if (fip
->nfnfields
== 0)
3788 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3790 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3791 flp
->name
= fieldname
;
3797 /* Create a new member function field and chain it to the field list
3799 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3800 make_cleanup (xfree
, new_fnfield
);
3801 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3802 new_fnfield
->next
= flp
->head
;
3803 flp
->head
= new_fnfield
;
3806 /* Fill in the member function field info. */
3807 fnp
= &new_fnfield
->fnfield
;
3808 /* The name is already allocated along with this objfile, so we don't
3809 need to duplicate it for the type. */
3810 fnp
->physname
= physname
? physname
: "";
3811 fnp
->type
= alloc_type (objfile
);
3812 this_type
= read_type_die (die
, cu
);
3813 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3815 int nparams
= TYPE_NFIELDS (this_type
);
3817 /* TYPE is the domain of this method, and THIS_TYPE is the type
3818 of the method itself (TYPE_CODE_METHOD). */
3819 smash_to_method_type (fnp
->type
, type
,
3820 TYPE_TARGET_TYPE (this_type
),
3821 TYPE_FIELDS (this_type
),
3822 TYPE_NFIELDS (this_type
),
3823 TYPE_VARARGS (this_type
));
3825 /* Handle static member functions.
3826 Dwarf2 has no clean way to discern C++ static and non-static
3827 member functions. G++ helps GDB by marking the first
3828 parameter for non-static member functions (which is the
3829 this pointer) as artificial. We obtain this information
3830 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3831 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3832 fnp
->voffset
= VOFFSET_STATIC
;
3835 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3838 /* Get fcontext from DW_AT_containing_type if present. */
3839 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3840 fnp
->fcontext
= die_containing_type (die
, cu
);
3842 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3843 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3845 /* Get accessibility. */
3846 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3849 switch (DW_UNSND (attr
))
3851 case DW_ACCESS_private
:
3852 fnp
->is_private
= 1;
3854 case DW_ACCESS_protected
:
3855 fnp
->is_protected
= 1;
3860 /* Check for artificial methods. */
3861 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3862 if (attr
&& DW_UNSND (attr
) != 0)
3863 fnp
->is_artificial
= 1;
3865 /* Get index in virtual function table if it is a virtual member function. */
3866 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3869 /* Support the .debug_loc offsets */
3870 if (attr_form_is_block (attr
))
3872 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3874 else if (attr_form_is_section_offset (attr
))
3876 dwarf2_complex_location_expr_complaint ();
3880 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3886 /* Create the vector of member function fields, and attach it to the type. */
3889 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3890 struct dwarf2_cu
*cu
)
3892 struct fnfieldlist
*flp
;
3893 int total_length
= 0;
3896 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3897 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3898 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3900 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3902 struct nextfnfield
*nfp
= flp
->head
;
3903 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3906 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3907 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3908 fn_flp
->fn_fields
= (struct fn_field
*)
3909 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3910 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3911 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3913 total_length
+= flp
->length
;
3916 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3917 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3920 /* Returns non-zero if NAME is the name of a vtable member in CU's
3921 language, zero otherwise. */
3923 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3925 static const char vptr
[] = "_vptr";
3926 static const char vtable
[] = "vtable";
3928 /* Look for the C++ and Java forms of the vtable. */
3929 if ((cu
->language
== language_java
3930 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3931 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3932 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3938 /* GCC outputs unnamed structures that are really pointers to member
3939 functions, with the ABI-specified layout. If DIE (from CU) describes
3940 such a structure, set its type, and return nonzero. Otherwise return
3943 GCC shouldn't do this; it should just output pointer to member DIEs.
3944 This is GCC PR debug/28767. */
3946 static struct type
*
3947 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3949 struct objfile
*objfile
= cu
->objfile
;
3951 struct die_info
*pfn_die
, *delta_die
;
3952 struct attribute
*pfn_name
, *delta_name
;
3953 struct type
*pfn_type
, *domain_type
;
3955 /* Check for a structure with no name and two children. */
3956 if (die
->tag
!= DW_TAG_structure_type
3957 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3958 || die
->child
== NULL
3959 || die
->child
->sibling
== NULL
3960 || (die
->child
->sibling
->sibling
!= NULL
3961 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3964 /* Check for __pfn and __delta members. */
3965 pfn_die
= die
->child
;
3966 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3967 if (pfn_die
->tag
!= DW_TAG_member
3969 || DW_STRING (pfn_name
) == NULL
3970 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3973 delta_die
= pfn_die
->sibling
;
3974 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3975 if (delta_die
->tag
!= DW_TAG_member
3976 || delta_name
== NULL
3977 || DW_STRING (delta_name
) == NULL
3978 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3981 /* Find the type of the method. */
3982 pfn_type
= die_type (pfn_die
, cu
);
3983 if (pfn_type
== NULL
3984 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3985 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3988 /* Look for the "this" argument. */
3989 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3990 if (TYPE_NFIELDS (pfn_type
) == 0
3991 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3994 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3995 type
= alloc_type (objfile
);
3996 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3997 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3998 TYPE_VARARGS (pfn_type
));
3999 type
= lookup_methodptr_type (type
);
4000 return set_die_type (die
, type
, cu
);
4003 /* Called when we find the DIE that starts a structure or union scope
4004 (definition) to process all dies that define the members of the
4007 NOTE: we need to call struct_type regardless of whether or not the
4008 DIE has an at_name attribute, since it might be an anonymous
4009 structure or union. This gets the type entered into our set of
4012 However, if the structure is incomplete (an opaque struct/union)
4013 then suppress creating a symbol table entry for it since gdb only
4014 wants to find the one with the complete definition. Note that if
4015 it is complete, we just call new_symbol, which does it's own
4016 checking about whether the struct/union is anonymous or not (and
4017 suppresses creating a symbol table entry itself). */
4019 static struct type
*
4020 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4022 struct objfile
*objfile
= cu
->objfile
;
4024 struct attribute
*attr
;
4026 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4028 type
= quirk_gcc_member_function_pointer (die
, cu
);
4032 type
= alloc_type (objfile
);
4033 INIT_CPLUS_SPECIFIC (type
);
4034 name
= dwarf2_name (die
, cu
);
4037 if (cu
->language
== language_cplus
4038 || cu
->language
== language_java
)
4040 const char *new_prefix
= determine_class_name (die
, cu
);
4041 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4045 /* The name is already allocated along with this objfile, so
4046 we don't need to duplicate it for the type. */
4047 TYPE_TAG_NAME (type
) = name
;
4051 if (die
->tag
== DW_TAG_structure_type
)
4053 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4055 else if (die
->tag
== DW_TAG_union_type
)
4057 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4061 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4063 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4066 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4069 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4073 TYPE_LENGTH (type
) = 0;
4076 TYPE_STUB_SUPPORTED (type
) = 1;
4077 if (die_is_declaration (die
, cu
))
4078 TYPE_STUB (type
) = 1;
4080 /* We need to add the type field to the die immediately so we don't
4081 infinitely recurse when dealing with pointers to the structure
4082 type within the structure itself. */
4083 set_die_type (die
, type
, cu
);
4085 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4087 struct field_info fi
;
4088 struct die_info
*child_die
;
4090 memset (&fi
, 0, sizeof (struct field_info
));
4092 child_die
= die
->child
;
4094 while (child_die
&& child_die
->tag
)
4096 if (child_die
->tag
== DW_TAG_member
4097 || child_die
->tag
== DW_TAG_variable
)
4099 /* NOTE: carlton/2002-11-05: A C++ static data member
4100 should be a DW_TAG_member that is a declaration, but
4101 all versions of G++ as of this writing (so through at
4102 least 3.2.1) incorrectly generate DW_TAG_variable
4103 tags for them instead. */
4104 dwarf2_add_field (&fi
, child_die
, cu
);
4106 else if (child_die
->tag
== DW_TAG_subprogram
)
4108 /* C++ member function. */
4109 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4111 else if (child_die
->tag
== DW_TAG_inheritance
)
4113 /* C++ base class field. */
4114 dwarf2_add_field (&fi
, child_die
, cu
);
4116 child_die
= sibling_die (child_die
);
4119 /* Attach fields and member functions to the type. */
4121 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4124 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4126 /* Get the type which refers to the base class (possibly this
4127 class itself) which contains the vtable pointer for the current
4128 class from the DW_AT_containing_type attribute. */
4130 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4132 struct type
*t
= die_containing_type (die
, cu
);
4134 TYPE_VPTR_BASETYPE (type
) = t
;
4139 /* Our own class provides vtbl ptr. */
4140 for (i
= TYPE_NFIELDS (t
) - 1;
4141 i
>= TYPE_N_BASECLASSES (t
);
4144 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4146 if (is_vtable_name (fieldname
, cu
))
4148 TYPE_VPTR_FIELDNO (type
) = i
;
4153 /* Complain if virtual function table field not found. */
4154 if (i
< TYPE_N_BASECLASSES (t
))
4155 complaint (&symfile_complaints
,
4156 _("virtual function table pointer not found when defining class '%s'"),
4157 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4162 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4165 else if (cu
->producer
4166 && strncmp (cu
->producer
,
4167 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4169 /* The IBM XLC compiler does not provide direct indication
4170 of the containing type, but the vtable pointer is
4171 always named __vfp. */
4175 for (i
= TYPE_NFIELDS (type
) - 1;
4176 i
>= TYPE_N_BASECLASSES (type
);
4179 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4181 TYPE_VPTR_FIELDNO (type
) = i
;
4182 TYPE_VPTR_BASETYPE (type
) = type
;
4190 do_cleanups (back_to
);
4195 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4197 struct objfile
*objfile
= cu
->objfile
;
4198 struct die_info
*child_die
= die
->child
;
4199 struct type
*this_type
;
4201 this_type
= get_die_type (die
, cu
);
4202 if (this_type
== NULL
)
4203 this_type
= read_structure_type (die
, cu
);
4205 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4206 snapshots) has been known to create a die giving a declaration
4207 for a class that has, as a child, a die giving a definition for a
4208 nested class. So we have to process our children even if the
4209 current die is a declaration. Normally, of course, a declaration
4210 won't have any children at all. */
4212 while (child_die
!= NULL
&& child_die
->tag
)
4214 if (child_die
->tag
== DW_TAG_member
4215 || child_die
->tag
== DW_TAG_variable
4216 || child_die
->tag
== DW_TAG_inheritance
)
4221 process_die (child_die
, cu
);
4223 child_die
= sibling_die (child_die
);
4226 /* Do not consider external references. According to the DWARF standard,
4227 these DIEs are identified by the fact that they have no byte_size
4228 attribute, and a declaration attribute. */
4229 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4230 || !die_is_declaration (die
, cu
))
4231 new_symbol (die
, this_type
, cu
);
4234 /* Given a DW_AT_enumeration_type die, set its type. We do not
4235 complete the type's fields yet, or create any symbols. */
4237 static struct type
*
4238 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4240 struct objfile
*objfile
= cu
->objfile
;
4242 struct attribute
*attr
;
4245 type
= alloc_type (objfile
);
4247 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4248 name
= dwarf2_full_name (die
, cu
);
4250 TYPE_TAG_NAME (type
) = (char *) name
;
4252 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4255 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4259 TYPE_LENGTH (type
) = 0;
4262 /* The enumeration DIE can be incomplete. In Ada, any type can be
4263 declared as private in the package spec, and then defined only
4264 inside the package body. Such types are known as Taft Amendment
4265 Types. When another package uses such a type, an incomplete DIE
4266 may be generated by the compiler. */
4267 if (die_is_declaration (die
, cu
))
4268 TYPE_STUB (type
) = 1;
4270 return set_die_type (die
, type
, cu
);
4273 /* Determine the name of the type represented by DIE, which should be
4274 a named C++ or Java compound type. Return the name in question,
4275 allocated on the objfile obstack. */
4278 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4280 const char *new_prefix
= NULL
;
4282 /* If we don't have namespace debug info, guess the name by trying
4283 to demangle the names of members, just like we did in
4284 guess_structure_name. */
4285 if (!processing_has_namespace_info
)
4287 struct die_info
*child
;
4289 for (child
= die
->child
;
4290 child
!= NULL
&& child
->tag
!= 0;
4291 child
= sibling_die (child
))
4293 if (child
->tag
== DW_TAG_subprogram
)
4296 = language_class_name_from_physname (cu
->language_defn
,
4300 if (phys_prefix
!= NULL
)
4303 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4304 &cu
->objfile
->objfile_obstack
);
4305 xfree (phys_prefix
);
4312 if (new_prefix
== NULL
)
4313 new_prefix
= dwarf2_full_name (die
, cu
);
4318 /* Given a pointer to a die which begins an enumeration, process all
4319 the dies that define the members of the enumeration, and create the
4320 symbol for the enumeration type.
4322 NOTE: We reverse the order of the element list. */
4325 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4327 struct objfile
*objfile
= cu
->objfile
;
4328 struct die_info
*child_die
;
4329 struct field
*fields
;
4332 int unsigned_enum
= 1;
4334 struct type
*this_type
;
4338 this_type
= get_die_type (die
, cu
);
4339 if (this_type
== NULL
)
4340 this_type
= read_enumeration_type (die
, cu
);
4341 if (die
->child
!= NULL
)
4343 child_die
= die
->child
;
4344 while (child_die
&& child_die
->tag
)
4346 if (child_die
->tag
!= DW_TAG_enumerator
)
4348 process_die (child_die
, cu
);
4352 name
= dwarf2_name (child_die
, cu
);
4355 sym
= new_symbol (child_die
, this_type
, cu
);
4356 if (SYMBOL_VALUE (sym
) < 0)
4359 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4361 fields
= (struct field
*)
4363 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4364 * sizeof (struct field
));
4367 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4368 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4369 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4370 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4371 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4377 child_die
= sibling_die (child_die
);
4382 TYPE_NFIELDS (this_type
) = num_fields
;
4383 TYPE_FIELDS (this_type
) = (struct field
*)
4384 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4385 memcpy (TYPE_FIELDS (this_type
), fields
,
4386 sizeof (struct field
) * num_fields
);
4390 TYPE_UNSIGNED (this_type
) = 1;
4393 new_symbol (die
, this_type
, cu
);
4396 /* Extract all information from a DW_TAG_array_type DIE and put it in
4397 the DIE's type field. For now, this only handles one dimensional
4400 static struct type
*
4401 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4403 struct objfile
*objfile
= cu
->objfile
;
4404 struct die_info
*child_die
;
4405 struct type
*type
= NULL
;
4406 struct type
*element_type
, *range_type
, *index_type
;
4407 struct type
**range_types
= NULL
;
4408 struct attribute
*attr
;
4410 struct cleanup
*back_to
;
4413 element_type
= die_type (die
, cu
);
4415 /* Irix 6.2 native cc creates array types without children for
4416 arrays with unspecified length. */
4417 if (die
->child
== NULL
)
4419 index_type
= builtin_type_int32
;
4420 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4421 type
= create_array_type (NULL
, element_type
, range_type
);
4422 return set_die_type (die
, type
, cu
);
4425 back_to
= make_cleanup (null_cleanup
, NULL
);
4426 child_die
= die
->child
;
4427 while (child_die
&& child_die
->tag
)
4429 if (child_die
->tag
== DW_TAG_subrange_type
)
4431 struct type
*child_type
= read_type_die (child_die
, cu
);
4432 if (child_type
!= NULL
)
4434 /* The range type was succesfully read. Save it for
4435 the array type creation. */
4436 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4438 range_types
= (struct type
**)
4439 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4440 * sizeof (struct type
*));
4442 make_cleanup (free_current_contents
, &range_types
);
4444 range_types
[ndim
++] = child_type
;
4447 child_die
= sibling_die (child_die
);
4450 /* Dwarf2 dimensions are output from left to right, create the
4451 necessary array types in backwards order. */
4453 type
= element_type
;
4455 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4459 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4464 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4467 /* Understand Dwarf2 support for vector types (like they occur on
4468 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4469 array type. This is not part of the Dwarf2/3 standard yet, but a
4470 custom vendor extension. The main difference between a regular
4471 array and the vector variant is that vectors are passed by value
4473 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4475 make_vector_type (type
);
4477 name
= dwarf2_name (die
, cu
);
4479 TYPE_NAME (type
) = name
;
4481 do_cleanups (back_to
);
4483 /* Install the type in the die. */
4484 return set_die_type (die
, type
, cu
);
4487 static enum dwarf_array_dim_ordering
4488 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4490 struct attribute
*attr
;
4492 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4494 if (attr
) return DW_SND (attr
);
4497 GNU F77 is a special case, as at 08/2004 array type info is the
4498 opposite order to the dwarf2 specification, but data is still
4499 laid out as per normal fortran.
4501 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4505 if (cu
->language
== language_fortran
&&
4506 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4508 return DW_ORD_row_major
;
4511 switch (cu
->language_defn
->la_array_ordering
)
4513 case array_column_major
:
4514 return DW_ORD_col_major
;
4515 case array_row_major
:
4517 return DW_ORD_row_major
;
4521 /* Extract all information from a DW_TAG_set_type DIE and put it in
4522 the DIE's type field. */
4524 static struct type
*
4525 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4527 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4529 return set_die_type (die
, set_type
, cu
);
4532 /* First cut: install each common block member as a global variable. */
4535 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4537 struct die_info
*child_die
;
4538 struct attribute
*attr
;
4540 CORE_ADDR base
= (CORE_ADDR
) 0;
4542 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4545 /* Support the .debug_loc offsets */
4546 if (attr_form_is_block (attr
))
4548 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4550 else if (attr_form_is_section_offset (attr
))
4552 dwarf2_complex_location_expr_complaint ();
4556 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4557 "common block member");
4560 if (die
->child
!= NULL
)
4562 child_die
= die
->child
;
4563 while (child_die
&& child_die
->tag
)
4565 sym
= new_symbol (child_die
, NULL
, cu
);
4566 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4569 SYMBOL_VALUE_ADDRESS (sym
) =
4570 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4571 add_symbol_to_list (sym
, &global_symbols
);
4573 child_die
= sibling_die (child_die
);
4578 /* Create a type for a C++ namespace. */
4580 static struct type
*
4581 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4583 struct objfile
*objfile
= cu
->objfile
;
4584 const char *previous_prefix
, *name
;
4588 /* For extensions, reuse the type of the original namespace. */
4589 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4591 struct die_info
*ext_die
;
4592 struct dwarf2_cu
*ext_cu
= cu
;
4593 ext_die
= dwarf2_extension (die
, &ext_cu
);
4594 type
= read_type_die (ext_die
, ext_cu
);
4595 return set_die_type (die
, type
, cu
);
4598 name
= namespace_name (die
, &is_anonymous
, cu
);
4600 /* Now build the name of the current namespace. */
4602 previous_prefix
= determine_prefix (die
, cu
);
4603 if (previous_prefix
[0] != '\0')
4604 name
= typename_concat (&objfile
->objfile_obstack
,
4605 previous_prefix
, name
, cu
);
4607 /* Create the type. */
4608 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4610 TYPE_NAME (type
) = (char *) name
;
4611 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4613 set_die_type (die
, type
, cu
);
4618 /* Read a C++ namespace. */
4621 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4623 struct objfile
*objfile
= cu
->objfile
;
4627 /* Add a symbol associated to this if we haven't seen the namespace
4628 before. Also, add a using directive if it's an anonymous
4631 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4635 type
= read_type_die (die
, cu
);
4636 new_symbol (die
, type
, cu
);
4638 name
= namespace_name (die
, &is_anonymous
, cu
);
4641 const char *previous_prefix
= determine_prefix (die
, cu
);
4642 cp_add_using_directive (TYPE_NAME (type
),
4643 strlen (previous_prefix
),
4644 strlen (TYPE_NAME (type
)));
4648 if (die
->child
!= NULL
)
4650 struct die_info
*child_die
= die
->child
;
4652 while (child_die
&& child_die
->tag
)
4654 process_die (child_die
, cu
);
4655 child_die
= sibling_die (child_die
);
4660 /* Return the name of the namespace represented by DIE. Set
4661 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4665 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4667 struct die_info
*current_die
;
4668 const char *name
= NULL
;
4670 /* Loop through the extensions until we find a name. */
4672 for (current_die
= die
;
4673 current_die
!= NULL
;
4674 current_die
= dwarf2_extension (die
, &cu
))
4676 name
= dwarf2_name (current_die
, cu
);
4681 /* Is it an anonymous namespace? */
4683 *is_anonymous
= (name
== NULL
);
4685 name
= "(anonymous namespace)";
4690 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4691 the user defined type vector. */
4693 static struct type
*
4694 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4696 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4697 struct comp_unit_head
*cu_header
= &cu
->header
;
4699 struct attribute
*attr_byte_size
;
4700 struct attribute
*attr_address_class
;
4701 int byte_size
, addr_class
;
4703 type
= lookup_pointer_type (die_type (die
, cu
));
4705 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4707 byte_size
= DW_UNSND (attr_byte_size
);
4709 byte_size
= cu_header
->addr_size
;
4711 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4712 if (attr_address_class
)
4713 addr_class
= DW_UNSND (attr_address_class
);
4715 addr_class
= DW_ADDR_none
;
4717 /* If the pointer size or address class is different than the
4718 default, create a type variant marked as such and set the
4719 length accordingly. */
4720 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4722 if (gdbarch_address_class_type_flags_p (gdbarch
))
4726 type_flags
= gdbarch_address_class_type_flags
4727 (gdbarch
, byte_size
, addr_class
);
4728 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4730 type
= make_type_with_address_space (type
, type_flags
);
4732 else if (TYPE_LENGTH (type
) != byte_size
)
4734 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4737 /* Should we also complain about unhandled address classes? */
4741 TYPE_LENGTH (type
) = byte_size
;
4742 return set_die_type (die
, type
, cu
);
4745 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4746 the user defined type vector. */
4748 static struct type
*
4749 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4751 struct objfile
*objfile
= cu
->objfile
;
4753 struct type
*to_type
;
4754 struct type
*domain
;
4756 to_type
= die_type (die
, cu
);
4757 domain
= die_containing_type (die
, cu
);
4759 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4760 type
= lookup_methodptr_type (to_type
);
4762 type
= lookup_memberptr_type (to_type
, domain
);
4764 return set_die_type (die
, type
, cu
);
4767 /* Extract all information from a DW_TAG_reference_type DIE and add to
4768 the user defined type vector. */
4770 static struct type
*
4771 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4773 struct comp_unit_head
*cu_header
= &cu
->header
;
4775 struct attribute
*attr
;
4777 type
= lookup_reference_type (die_type (die
, cu
));
4778 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4781 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4785 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4787 return set_die_type (die
, type
, cu
);
4790 static struct type
*
4791 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4793 struct type
*base_type
, *cv_type
;
4795 base_type
= die_type (die
, cu
);
4796 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4797 return set_die_type (die
, cv_type
, cu
);
4800 static struct type
*
4801 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4803 struct type
*base_type
, *cv_type
;
4805 base_type
= die_type (die
, cu
);
4806 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4807 return set_die_type (die
, cv_type
, cu
);
4810 /* Extract all information from a DW_TAG_string_type DIE and add to
4811 the user defined type vector. It isn't really a user defined type,
4812 but it behaves like one, with other DIE's using an AT_user_def_type
4813 attribute to reference it. */
4815 static struct type
*
4816 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4818 struct objfile
*objfile
= cu
->objfile
;
4819 struct type
*type
, *range_type
, *index_type
, *char_type
;
4820 struct attribute
*attr
;
4821 unsigned int length
;
4823 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4826 length
= DW_UNSND (attr
);
4830 /* check for the DW_AT_byte_size attribute */
4831 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4834 length
= DW_UNSND (attr
);
4842 index_type
= builtin_type_int32
;
4843 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4844 type
= create_string_type (NULL
, range_type
);
4846 return set_die_type (die
, type
, cu
);
4849 /* Handle DIES due to C code like:
4853 int (*funcp)(int a, long l);
4857 ('funcp' generates a DW_TAG_subroutine_type DIE)
4860 static struct type
*
4861 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4863 struct type
*type
; /* Type that this function returns */
4864 struct type
*ftype
; /* Function that returns above type */
4865 struct attribute
*attr
;
4867 type
= die_type (die
, cu
);
4868 ftype
= make_function_type (type
, (struct type
**) 0);
4870 /* All functions in C++, Pascal and Java have prototypes. */
4871 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4872 if ((attr
&& (DW_UNSND (attr
) != 0))
4873 || cu
->language
== language_cplus
4874 || cu
->language
== language_java
4875 || cu
->language
== language_pascal
)
4876 TYPE_PROTOTYPED (ftype
) = 1;
4878 /* Store the calling convention in the type if it's available in
4879 the subroutine die. Otherwise set the calling convention to
4880 the default value DW_CC_normal. */
4881 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4882 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4884 if (die
->child
!= NULL
)
4886 struct die_info
*child_die
;
4890 /* Count the number of parameters.
4891 FIXME: GDB currently ignores vararg functions, but knows about
4892 vararg member functions. */
4893 child_die
= die
->child
;
4894 while (child_die
&& child_die
->tag
)
4896 if (child_die
->tag
== DW_TAG_formal_parameter
)
4898 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4899 TYPE_VARARGS (ftype
) = 1;
4900 child_die
= sibling_die (child_die
);
4903 /* Allocate storage for parameters and fill them in. */
4904 TYPE_NFIELDS (ftype
) = nparams
;
4905 TYPE_FIELDS (ftype
) = (struct field
*)
4906 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4908 child_die
= die
->child
;
4909 while (child_die
&& child_die
->tag
)
4911 if (child_die
->tag
== DW_TAG_formal_parameter
)
4913 /* Dwarf2 has no clean way to discern C++ static and non-static
4914 member functions. G++ helps GDB by marking the first
4915 parameter for non-static member functions (which is the
4916 this pointer) as artificial. We pass this information
4917 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4918 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4920 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4922 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4923 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4926 child_die
= sibling_die (child_die
);
4930 return set_die_type (die
, ftype
, cu
);
4933 static struct type
*
4934 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4936 struct objfile
*objfile
= cu
->objfile
;
4937 struct attribute
*attr
;
4938 const char *name
= NULL
;
4939 struct type
*this_type
;
4941 name
= dwarf2_full_name (die
, cu
);
4942 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4943 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
4944 TYPE_NAME (this_type
) = (char *) name
;
4945 set_die_type (die
, this_type
, cu
);
4946 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
4950 /* Find a representation of a given base type and install
4951 it in the TYPE field of the die. */
4953 static struct type
*
4954 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4956 struct objfile
*objfile
= cu
->objfile
;
4958 struct attribute
*attr
;
4959 int encoding
= 0, size
= 0;
4961 enum type_code code
= TYPE_CODE_INT
;
4963 struct type
*target_type
= NULL
;
4965 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4968 encoding
= DW_UNSND (attr
);
4970 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4973 size
= DW_UNSND (attr
);
4975 name
= dwarf2_name (die
, cu
);
4978 complaint (&symfile_complaints
,
4979 _("DW_AT_name missing from DW_TAG_base_type"));
4984 case DW_ATE_address
:
4985 /* Turn DW_ATE_address into a void * pointer. */
4986 code
= TYPE_CODE_PTR
;
4987 type_flags
|= TYPE_FLAG_UNSIGNED
;
4988 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4990 case DW_ATE_boolean
:
4991 code
= TYPE_CODE_BOOL
;
4992 type_flags
|= TYPE_FLAG_UNSIGNED
;
4994 case DW_ATE_complex_float
:
4995 code
= TYPE_CODE_COMPLEX
;
4996 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
4998 case DW_ATE_decimal_float
:
4999 code
= TYPE_CODE_DECFLOAT
;
5002 code
= TYPE_CODE_FLT
;
5006 case DW_ATE_unsigned
:
5007 type_flags
|= TYPE_FLAG_UNSIGNED
;
5009 case DW_ATE_signed_char
:
5010 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5011 code
= TYPE_CODE_CHAR
;
5013 case DW_ATE_unsigned_char
:
5014 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5015 code
= TYPE_CODE_CHAR
;
5016 type_flags
|= TYPE_FLAG_UNSIGNED
;
5019 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5020 dwarf_type_encoding_name (encoding
));
5024 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5025 TYPE_NAME (type
) = name
;
5026 TYPE_TARGET_TYPE (type
) = target_type
;
5028 if (name
&& strcmp (name
, "char") == 0)
5029 TYPE_NOSIGN (type
) = 1;
5031 return set_die_type (die
, type
, cu
);
5034 /* Read the given DW_AT_subrange DIE. */
5036 static struct type
*
5037 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5039 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5040 struct type
*base_type
;
5041 struct type
*range_type
;
5042 struct attribute
*attr
;
5047 base_type
= die_type (die
, cu
);
5048 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5050 complaint (&symfile_complaints
,
5051 _("DW_AT_type missing from DW_TAG_subrange_type"));
5053 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5054 0, NULL
, cu
->objfile
);
5057 if (cu
->language
== language_fortran
)
5059 /* FORTRAN implies a lower bound of 1, if not given. */
5063 /* FIXME: For variable sized arrays either of these could be
5064 a variable rather than a constant value. We'll allow it,
5065 but we don't know how to handle it. */
5066 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5068 low
= dwarf2_get_attr_constant_value (attr
, 0);
5070 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5073 if (attr
->form
== DW_FORM_block1
)
5075 /* GCC encodes arrays with unspecified or dynamic length
5076 with a DW_FORM_block1 attribute.
5077 FIXME: GDB does not yet know how to handle dynamic
5078 arrays properly, treat them as arrays with unspecified
5081 FIXME: jimb/2003-09-22: GDB does not really know
5082 how to handle arrays of unspecified length
5083 either; we just represent them as zero-length
5084 arrays. Choose an appropriate upper bound given
5085 the lower bound we've computed above. */
5089 high
= dwarf2_get_attr_constant_value (attr
, 1);
5092 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5094 name
= dwarf2_name (die
, cu
);
5096 TYPE_NAME (range_type
) = name
;
5098 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5100 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5102 return set_die_type (die
, range_type
, cu
);
5105 static struct type
*
5106 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5110 /* For now, we only support the C meaning of an unspecified type: void. */
5112 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5113 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5115 return set_die_type (die
, type
, cu
);
5118 /* Trivial hash function for die_info: the hash value of a DIE
5119 is its offset in .debug_info for this objfile. */
5122 die_hash (const void *item
)
5124 const struct die_info
*die
= item
;
5128 /* Trivial comparison function for die_info structures: two DIEs
5129 are equal if they have the same offset. */
5132 die_eq (const void *item_lhs
, const void *item_rhs
)
5134 const struct die_info
*die_lhs
= item_lhs
;
5135 const struct die_info
*die_rhs
= item_rhs
;
5136 return die_lhs
->offset
== die_rhs
->offset
;
5139 /* Read a whole compilation unit into a linked list of dies. */
5141 static struct die_info
*
5142 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5145 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5149 &cu
->comp_unit_obstack
,
5150 hashtab_obstack_allocate
,
5151 dummy_obstack_deallocate
);
5153 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5156 /* Read a single die and all its descendents. Set the die's sibling
5157 field to NULL; set other fields in the die correctly, and set all
5158 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5159 location of the info_ptr after reading all of those dies. PARENT
5160 is the parent of the die in question. */
5162 static struct die_info
*
5163 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5164 struct dwarf2_cu
*cu
,
5165 gdb_byte
**new_info_ptr
,
5166 struct die_info
*parent
)
5168 struct die_info
*die
;
5172 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5175 *new_info_ptr
= cur_ptr
;
5178 store_in_ref_table (die
, cu
);
5182 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5188 *new_info_ptr
= cur_ptr
;
5191 die
->sibling
= NULL
;
5192 die
->parent
= parent
;
5196 /* Read a die, all of its descendents, and all of its siblings; set
5197 all of the fields of all of the dies correctly. Arguments are as
5198 in read_die_and_children. */
5200 static struct die_info
*
5201 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5202 struct dwarf2_cu
*cu
,
5203 gdb_byte
**new_info_ptr
,
5204 struct die_info
*parent
)
5206 struct die_info
*first_die
, *last_sibling
;
5210 first_die
= last_sibling
= NULL
;
5214 struct die_info
*die
5215 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5219 *new_info_ptr
= cur_ptr
;
5226 last_sibling
->sibling
= die
;
5232 /* Decompress a section that was compressed using zlib. Store the
5233 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5236 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5237 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5239 bfd
*abfd
= objfile
->obfd
;
5241 error (_("Support for zlib-compressed DWARF data (from '%s') "
5242 "is disabled in this copy of GDB"),
5243 bfd_get_filename (abfd
));
5245 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5246 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5247 bfd_size_type uncompressed_size
;
5248 gdb_byte
*uncompressed_buffer
;
5251 int header_size
= 12;
5253 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5254 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5255 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5256 bfd_get_filename (abfd
));
5258 /* Read the zlib header. In this case, it should be "ZLIB" followed
5259 by the uncompressed section size, 8 bytes in big-endian order. */
5260 if (compressed_size
< header_size
5261 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5262 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5263 bfd_get_filename (abfd
));
5264 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5265 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5266 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5267 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5268 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5269 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5270 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5271 uncompressed_size
+= compressed_buffer
[11];
5273 /* It is possible the section consists of several compressed
5274 buffers concatenated together, so we uncompress in a loop. */
5278 strm
.avail_in
= compressed_size
- header_size
;
5279 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5280 strm
.avail_out
= uncompressed_size
;
5281 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5283 rc
= inflateInit (&strm
);
5284 while (strm
.avail_in
> 0)
5287 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5288 bfd_get_filename (abfd
), rc
);
5289 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5290 + (uncompressed_size
- strm
.avail_out
));
5291 rc
= inflate (&strm
, Z_FINISH
);
5292 if (rc
!= Z_STREAM_END
)
5293 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5294 bfd_get_filename (abfd
), rc
);
5295 rc
= inflateReset (&strm
);
5297 rc
= inflateEnd (&strm
);
5299 || strm
.avail_out
!= 0)
5300 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5301 bfd_get_filename (abfd
), rc
);
5303 xfree (compressed_buffer
);
5304 *outbuf
= uncompressed_buffer
;
5305 *outsize
= uncompressed_size
;
5310 /* Read the contents of the section at OFFSET and of size SIZE from the
5311 object file specified by OBJFILE into the objfile_obstack and return it.
5312 If the section is compressed, uncompress it before returning. */
5315 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5317 bfd
*abfd
= objfile
->obfd
;
5318 gdb_byte
*buf
, *retbuf
;
5319 bfd_size_type size
= bfd_get_section_size (sectp
);
5320 unsigned char header
[4];
5325 /* Check if the file has a 4-byte header indicating compression. */
5326 if (size
> sizeof (header
)
5327 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5328 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5330 /* Upon decompression, update the buffer and its size. */
5331 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5333 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5334 dwarf2_resize_section (sectp
, size
);
5339 /* If we get here, we are a normal, not-compressed section. */
5340 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5341 /* When debugging .o files, we may need to apply relocations; see
5342 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5343 We never compress sections in .o files, so we only need to
5344 try this when the section is not compressed. */
5345 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5349 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5350 || bfd_bread (buf
, size
, abfd
) != size
)
5351 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5352 bfd_get_filename (abfd
));
5357 /* In DWARF version 2, the description of the debugging information is
5358 stored in a separate .debug_abbrev section. Before we read any
5359 dies from a section we read in all abbreviations and install them
5360 in a hash table. This function also sets flags in CU describing
5361 the data found in the abbrev table. */
5364 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5366 struct comp_unit_head
*cu_header
= &cu
->header
;
5367 gdb_byte
*abbrev_ptr
;
5368 struct abbrev_info
*cur_abbrev
;
5369 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5370 unsigned int abbrev_form
, hash_number
;
5371 struct attr_abbrev
*cur_attrs
;
5372 unsigned int allocated_attrs
;
5374 /* Initialize dwarf2 abbrevs */
5375 obstack_init (&cu
->abbrev_obstack
);
5376 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5378 * sizeof (struct abbrev_info
*)));
5379 memset (cu
->dwarf2_abbrevs
, 0,
5380 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5382 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5383 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5384 abbrev_ptr
+= bytes_read
;
5386 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5387 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5389 /* loop until we reach an abbrev number of 0 */
5390 while (abbrev_number
)
5392 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5394 /* read in abbrev header */
5395 cur_abbrev
->number
= abbrev_number
;
5396 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5397 abbrev_ptr
+= bytes_read
;
5398 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5401 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5402 cu
->has_namespace_info
= 1;
5404 /* now read in declarations */
5405 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5406 abbrev_ptr
+= bytes_read
;
5407 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5408 abbrev_ptr
+= bytes_read
;
5411 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5413 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5415 = xrealloc (cur_attrs
, (allocated_attrs
5416 * sizeof (struct attr_abbrev
)));
5419 /* Record whether this compilation unit might have
5420 inter-compilation-unit references. If we don't know what form
5421 this attribute will have, then it might potentially be a
5422 DW_FORM_ref_addr, so we conservatively expect inter-CU
5425 if (abbrev_form
== DW_FORM_ref_addr
5426 || abbrev_form
== DW_FORM_indirect
)
5427 cu
->has_form_ref_addr
= 1;
5429 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5430 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5431 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5432 abbrev_ptr
+= bytes_read
;
5433 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5434 abbrev_ptr
+= bytes_read
;
5437 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5438 (cur_abbrev
->num_attrs
5439 * sizeof (struct attr_abbrev
)));
5440 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5441 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5443 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5444 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5445 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5447 /* Get next abbreviation.
5448 Under Irix6 the abbreviations for a compilation unit are not
5449 always properly terminated with an abbrev number of 0.
5450 Exit loop if we encounter an abbreviation which we have
5451 already read (which means we are about to read the abbreviations
5452 for the next compile unit) or if the end of the abbreviation
5453 table is reached. */
5454 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5455 >= dwarf2_per_objfile
->abbrev_size
)
5457 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5458 abbrev_ptr
+= bytes_read
;
5459 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5466 /* Release the memory used by the abbrev table for a compilation unit. */
5469 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5471 struct dwarf2_cu
*cu
= ptr_to_cu
;
5473 obstack_free (&cu
->abbrev_obstack
, NULL
);
5474 cu
->dwarf2_abbrevs
= NULL
;
5477 /* Lookup an abbrev_info structure in the abbrev hash table. */
5479 static struct abbrev_info
*
5480 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5482 unsigned int hash_number
;
5483 struct abbrev_info
*abbrev
;
5485 hash_number
= number
% ABBREV_HASH_SIZE
;
5486 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5490 if (abbrev
->number
== number
)
5493 abbrev
= abbrev
->next
;
5498 /* Returns nonzero if TAG represents a type that we might generate a partial
5502 is_type_tag_for_partial (int tag
)
5507 /* Some types that would be reasonable to generate partial symbols for,
5508 that we don't at present. */
5509 case DW_TAG_array_type
:
5510 case DW_TAG_file_type
:
5511 case DW_TAG_ptr_to_member_type
:
5512 case DW_TAG_set_type
:
5513 case DW_TAG_string_type
:
5514 case DW_TAG_subroutine_type
:
5516 case DW_TAG_base_type
:
5517 case DW_TAG_class_type
:
5518 case DW_TAG_interface_type
:
5519 case DW_TAG_enumeration_type
:
5520 case DW_TAG_structure_type
:
5521 case DW_TAG_subrange_type
:
5522 case DW_TAG_typedef
:
5523 case DW_TAG_union_type
:
5530 /* Load all DIEs that are interesting for partial symbols into memory. */
5532 static struct partial_die_info
*
5533 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5534 struct dwarf2_cu
*cu
)
5536 struct partial_die_info
*part_die
;
5537 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5538 struct abbrev_info
*abbrev
;
5539 unsigned int bytes_read
;
5540 unsigned int load_all
= 0;
5542 int nesting_level
= 1;
5547 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5551 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5555 &cu
->comp_unit_obstack
,
5556 hashtab_obstack_allocate
,
5557 dummy_obstack_deallocate
);
5559 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5560 sizeof (struct partial_die_info
));
5564 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5566 /* A NULL abbrev means the end of a series of children. */
5569 if (--nesting_level
== 0)
5571 /* PART_DIE was probably the last thing allocated on the
5572 comp_unit_obstack, so we could call obstack_free
5573 here. We don't do that because the waste is small,
5574 and will be cleaned up when we're done with this
5575 compilation unit. This way, we're also more robust
5576 against other users of the comp_unit_obstack. */
5579 info_ptr
+= bytes_read
;
5580 last_die
= parent_die
;
5581 parent_die
= parent_die
->die_parent
;
5585 /* Check whether this DIE is interesting enough to save. Normally
5586 we would not be interested in members here, but there may be
5587 later variables referencing them via DW_AT_specification (for
5590 && !is_type_tag_for_partial (abbrev
->tag
)
5591 && abbrev
->tag
!= DW_TAG_enumerator
5592 && abbrev
->tag
!= DW_TAG_subprogram
5593 && abbrev
->tag
!= DW_TAG_lexical_block
5594 && abbrev
->tag
!= DW_TAG_variable
5595 && abbrev
->tag
!= DW_TAG_namespace
5596 && abbrev
->tag
!= DW_TAG_member
)
5598 /* Otherwise we skip to the next sibling, if any. */
5599 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5603 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5604 abfd
, info_ptr
, cu
);
5606 /* This two-pass algorithm for processing partial symbols has a
5607 high cost in cache pressure. Thus, handle some simple cases
5608 here which cover the majority of C partial symbols. DIEs
5609 which neither have specification tags in them, nor could have
5610 specification tags elsewhere pointing at them, can simply be
5611 processed and discarded.
5613 This segment is also optional; scan_partial_symbols and
5614 add_partial_symbol will handle these DIEs if we chain
5615 them in normally. When compilers which do not emit large
5616 quantities of duplicate debug information are more common,
5617 this code can probably be removed. */
5619 /* Any complete simple types at the top level (pretty much all
5620 of them, for a language without namespaces), can be processed
5622 if (parent_die
== NULL
5623 && part_die
->has_specification
== 0
5624 && part_die
->is_declaration
== 0
5625 && (part_die
->tag
== DW_TAG_typedef
5626 || part_die
->tag
== DW_TAG_base_type
5627 || part_die
->tag
== DW_TAG_subrange_type
))
5629 if (building_psymtab
&& part_die
->name
!= NULL
)
5630 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5631 VAR_DOMAIN
, LOC_TYPEDEF
,
5632 &cu
->objfile
->static_psymbols
,
5633 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5634 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5638 /* If we're at the second level, and we're an enumerator, and
5639 our parent has no specification (meaning possibly lives in a
5640 namespace elsewhere), then we can add the partial symbol now
5641 instead of queueing it. */
5642 if (part_die
->tag
== DW_TAG_enumerator
5643 && parent_die
!= NULL
5644 && parent_die
->die_parent
== NULL
5645 && parent_die
->tag
== DW_TAG_enumeration_type
5646 && parent_die
->has_specification
== 0)
5648 if (part_die
->name
== NULL
)
5649 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5650 else if (building_psymtab
)
5651 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5652 VAR_DOMAIN
, LOC_CONST
,
5653 (cu
->language
== language_cplus
5654 || cu
->language
== language_java
)
5655 ? &cu
->objfile
->global_psymbols
5656 : &cu
->objfile
->static_psymbols
,
5657 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5659 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5663 /* We'll save this DIE so link it in. */
5664 part_die
->die_parent
= parent_die
;
5665 part_die
->die_sibling
= NULL
;
5666 part_die
->die_child
= NULL
;
5668 if (last_die
&& last_die
== parent_die
)
5669 last_die
->die_child
= part_die
;
5671 last_die
->die_sibling
= part_die
;
5673 last_die
= part_die
;
5675 if (first_die
== NULL
)
5676 first_die
= part_die
;
5678 /* Maybe add the DIE to the hash table. Not all DIEs that we
5679 find interesting need to be in the hash table, because we
5680 also have the parent/sibling/child chains; only those that we
5681 might refer to by offset later during partial symbol reading.
5683 For now this means things that might have be the target of a
5684 DW_AT_specification, DW_AT_abstract_origin, or
5685 DW_AT_extension. DW_AT_extension will refer only to
5686 namespaces; DW_AT_abstract_origin refers to functions (and
5687 many things under the function DIE, but we do not recurse
5688 into function DIEs during partial symbol reading) and
5689 possibly variables as well; DW_AT_specification refers to
5690 declarations. Declarations ought to have the DW_AT_declaration
5691 flag. It happens that GCC forgets to put it in sometimes, but
5692 only for functions, not for types.
5694 Adding more things than necessary to the hash table is harmless
5695 except for the performance cost. Adding too few will result in
5696 wasted time in find_partial_die, when we reread the compilation
5697 unit with load_all_dies set. */
5700 || abbrev
->tag
== DW_TAG_subprogram
5701 || abbrev
->tag
== DW_TAG_variable
5702 || abbrev
->tag
== DW_TAG_namespace
5703 || part_die
->is_declaration
)
5707 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5708 part_die
->offset
, INSERT
);
5712 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5713 sizeof (struct partial_die_info
));
5715 /* For some DIEs we want to follow their children (if any). For C
5716 we have no reason to follow the children of structures; for other
5717 languages we have to, both so that we can get at method physnames
5718 to infer fully qualified class names, and for DW_AT_specification.
5720 For Ada, we need to scan the children of subprograms and lexical
5721 blocks as well because Ada allows the definition of nested
5722 entities that could be interesting for the debugger, such as
5723 nested subprograms for instance. */
5724 if (last_die
->has_children
5726 || last_die
->tag
== DW_TAG_namespace
5727 || last_die
->tag
== DW_TAG_enumeration_type
5728 || (cu
->language
!= language_c
5729 && (last_die
->tag
== DW_TAG_class_type
5730 || last_die
->tag
== DW_TAG_interface_type
5731 || last_die
->tag
== DW_TAG_structure_type
5732 || last_die
->tag
== DW_TAG_union_type
))
5733 || (cu
->language
== language_ada
5734 && (last_die
->tag
== DW_TAG_subprogram
5735 || last_die
->tag
== DW_TAG_lexical_block
))))
5738 parent_die
= last_die
;
5742 /* Otherwise we skip to the next sibling, if any. */
5743 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5745 /* Back to the top, do it again. */
5749 /* Read a minimal amount of information into the minimal die structure. */
5752 read_partial_die (struct partial_die_info
*part_die
,
5753 struct abbrev_info
*abbrev
,
5754 unsigned int abbrev_len
, bfd
*abfd
,
5755 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5757 unsigned int bytes_read
, i
;
5758 struct attribute attr
;
5759 int has_low_pc_attr
= 0;
5760 int has_high_pc_attr
= 0;
5761 CORE_ADDR base_address
= 0;
5765 base_address_low_pc
,
5766 /* Overrides BASE_ADDRESS_LOW_PC. */
5767 base_address_entry_pc
5769 base_address_type
= base_address_none
;
5771 memset (part_die
, 0, sizeof (struct partial_die_info
));
5773 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5775 info_ptr
+= abbrev_len
;
5780 part_die
->tag
= abbrev
->tag
;
5781 part_die
->has_children
= abbrev
->has_children
;
5783 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5785 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5787 /* Store the data if it is of an attribute we want to keep in a
5788 partial symbol table. */
5793 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5794 if (part_die
->name
== NULL
)
5795 part_die
->name
= DW_STRING (&attr
);
5797 case DW_AT_comp_dir
:
5798 if (part_die
->dirname
== NULL
)
5799 part_die
->dirname
= DW_STRING (&attr
);
5801 case DW_AT_MIPS_linkage_name
:
5802 part_die
->name
= DW_STRING (&attr
);
5805 has_low_pc_attr
= 1;
5806 part_die
->lowpc
= DW_ADDR (&attr
);
5807 if (part_die
->tag
== DW_TAG_compile_unit
5808 && base_address_type
< base_address_low_pc
)
5810 base_address
= DW_ADDR (&attr
);
5811 base_address_type
= base_address_low_pc
;
5815 has_high_pc_attr
= 1;
5816 part_die
->highpc
= DW_ADDR (&attr
);
5818 case DW_AT_entry_pc
:
5819 if (part_die
->tag
== DW_TAG_compile_unit
5820 && base_address_type
< base_address_entry_pc
)
5822 base_address
= DW_ADDR (&attr
);
5823 base_address_type
= base_address_entry_pc
;
5827 if (part_die
->tag
== DW_TAG_compile_unit
)
5829 cu
->ranges_offset
= DW_UNSND (&attr
);
5830 cu
->has_ranges_offset
= 1;
5833 case DW_AT_location
:
5834 /* Support the .debug_loc offsets */
5835 if (attr_form_is_block (&attr
))
5837 part_die
->locdesc
= DW_BLOCK (&attr
);
5839 else if (attr_form_is_section_offset (&attr
))
5841 dwarf2_complex_location_expr_complaint ();
5845 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5846 "partial symbol information");
5849 case DW_AT_language
:
5850 part_die
->language
= DW_UNSND (&attr
);
5852 case DW_AT_external
:
5853 part_die
->is_external
= DW_UNSND (&attr
);
5855 case DW_AT_declaration
:
5856 part_die
->is_declaration
= DW_UNSND (&attr
);
5859 part_die
->has_type
= 1;
5861 case DW_AT_abstract_origin
:
5862 case DW_AT_specification
:
5863 case DW_AT_extension
:
5864 part_die
->has_specification
= 1;
5865 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5868 /* Ignore absolute siblings, they might point outside of
5869 the current compile unit. */
5870 if (attr
.form
== DW_FORM_ref_addr
)
5871 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5873 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5874 + dwarf2_get_ref_die_offset (&attr
, cu
);
5876 case DW_AT_stmt_list
:
5877 part_die
->has_stmt_list
= 1;
5878 part_die
->line_offset
= DW_UNSND (&attr
);
5880 case DW_AT_byte_size
:
5881 part_die
->has_byte_size
= 1;
5883 case DW_AT_calling_convention
:
5884 /* DWARF doesn't provide a way to identify a program's source-level
5885 entry point. DW_AT_calling_convention attributes are only meant
5886 to describe functions' calling conventions.
5888 However, because it's a necessary piece of information in
5889 Fortran, and because DW_CC_program is the only piece of debugging
5890 information whose definition refers to a 'main program' at all,
5891 several compilers have begun marking Fortran main programs with
5892 DW_CC_program --- even when those functions use the standard
5893 calling conventions.
5895 So until DWARF specifies a way to provide this information and
5896 compilers pick up the new representation, we'll support this
5898 if (DW_UNSND (&attr
) == DW_CC_program
5899 && cu
->language
== language_fortran
)
5900 set_main_name (part_die
->name
);
5907 /* When using the GNU linker, .gnu.linkonce. sections are used to
5908 eliminate duplicate copies of functions and vtables and such.
5909 The linker will arbitrarily choose one and discard the others.
5910 The AT_*_pc values for such functions refer to local labels in
5911 these sections. If the section from that file was discarded, the
5912 labels are not in the output, so the relocs get a value of 0.
5913 If this is a discarded function, mark the pc bounds as invalid,
5914 so that GDB will ignore it. */
5915 if (has_low_pc_attr
&& has_high_pc_attr
5916 && part_die
->lowpc
< part_die
->highpc
5917 && (part_die
->lowpc
!= 0
5918 || dwarf2_per_objfile
->has_section_at_zero
))
5919 part_die
->has_pc_info
= 1;
5921 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
5923 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5925 cu
->base_address
= base_address
;
5931 /* Find a cached partial DIE at OFFSET in CU. */
5933 static struct partial_die_info
*
5934 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5936 struct partial_die_info
*lookup_die
= NULL
;
5937 struct partial_die_info part_die
;
5939 part_die
.offset
= offset
;
5940 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5945 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5947 static struct partial_die_info
*
5948 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5950 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5951 struct partial_die_info
*pd
= NULL
;
5953 if (offset
>= cu
->header
.offset
5954 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5956 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5961 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5963 if (per_cu
->cu
== NULL
)
5965 load_comp_unit (per_cu
, cu
->objfile
);
5966 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5967 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5970 per_cu
->cu
->last_used
= 0;
5971 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5973 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5975 struct cleanup
*back_to
;
5976 struct partial_die_info comp_unit_die
;
5977 struct abbrev_info
*abbrev
;
5978 unsigned int bytes_read
;
5981 per_cu
->load_all_dies
= 1;
5983 /* Re-read the DIEs. */
5984 back_to
= make_cleanup (null_cleanup
, 0);
5985 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5987 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5988 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5990 info_ptr
= (dwarf2_per_objfile
->info_buffer
5991 + per_cu
->cu
->header
.offset
5992 + per_cu
->cu
->header
.first_die_offset
);
5993 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5994 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5995 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5997 if (comp_unit_die
.has_children
)
5998 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5999 do_cleanups (back_to
);
6001 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6005 internal_error (__FILE__
, __LINE__
,
6006 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
6007 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6011 /* Adjust PART_DIE before generating a symbol for it. This function
6012 may set the is_external flag or change the DIE's name. */
6015 fixup_partial_die (struct partial_die_info
*part_die
,
6016 struct dwarf2_cu
*cu
)
6018 /* If we found a reference attribute and the DIE has no name, try
6019 to find a name in the referred to DIE. */
6021 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6023 struct partial_die_info
*spec_die
;
6025 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6027 fixup_partial_die (spec_die
, cu
);
6031 part_die
->name
= spec_die
->name
;
6033 /* Copy DW_AT_external attribute if it is set. */
6034 if (spec_die
->is_external
)
6035 part_die
->is_external
= spec_die
->is_external
;
6039 /* Set default names for some unnamed DIEs. */
6040 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6041 || part_die
->tag
== DW_TAG_class_type
))
6042 part_die
->name
= "(anonymous class)";
6044 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6045 part_die
->name
= "(anonymous namespace)";
6047 if (part_die
->tag
== DW_TAG_structure_type
6048 || part_die
->tag
== DW_TAG_class_type
6049 || part_die
->tag
== DW_TAG_union_type
)
6050 guess_structure_name (part_die
, cu
);
6053 /* Read the die from the .debug_info section buffer. Set DIEP to
6054 point to a newly allocated die with its information, except for its
6055 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6056 whether the die has children or not. */
6059 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6060 struct dwarf2_cu
*cu
, int *has_children
)
6062 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6063 struct abbrev_info
*abbrev
;
6064 struct die_info
*die
;
6066 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6067 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6068 info_ptr
+= bytes_read
;
6076 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6079 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6081 bfd_get_filename (abfd
));
6083 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6084 die
->offset
= offset
;
6085 die
->tag
= abbrev
->tag
;
6086 die
->abbrev
= abbrev_number
;
6088 die
->num_attrs
= abbrev
->num_attrs
;
6090 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6091 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6092 abfd
, info_ptr
, cu
);
6095 *has_children
= abbrev
->has_children
;
6099 /* Read an attribute value described by an attribute form. */
6102 read_attribute_value (struct attribute
*attr
, unsigned form
,
6103 bfd
*abfd
, gdb_byte
*info_ptr
,
6104 struct dwarf2_cu
*cu
)
6106 struct comp_unit_head
*cu_header
= &cu
->header
;
6107 unsigned int bytes_read
;
6108 struct dwarf_block
*blk
;
6114 case DW_FORM_ref_addr
:
6115 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6116 info_ptr
+= bytes_read
;
6118 case DW_FORM_block2
:
6119 blk
= dwarf_alloc_block (cu
);
6120 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6122 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6123 info_ptr
+= blk
->size
;
6124 DW_BLOCK (attr
) = blk
;
6126 case DW_FORM_block4
:
6127 blk
= dwarf_alloc_block (cu
);
6128 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6130 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6131 info_ptr
+= blk
->size
;
6132 DW_BLOCK (attr
) = blk
;
6135 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6139 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6143 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6146 case DW_FORM_string
:
6147 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6148 info_ptr
+= bytes_read
;
6151 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6153 info_ptr
+= bytes_read
;
6156 blk
= dwarf_alloc_block (cu
);
6157 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6158 info_ptr
+= bytes_read
;
6159 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6160 info_ptr
+= blk
->size
;
6161 DW_BLOCK (attr
) = blk
;
6163 case DW_FORM_block1
:
6164 blk
= dwarf_alloc_block (cu
);
6165 blk
->size
= read_1_byte (abfd
, info_ptr
);
6167 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6168 info_ptr
+= blk
->size
;
6169 DW_BLOCK (attr
) = blk
;
6172 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6176 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6180 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6181 info_ptr
+= bytes_read
;
6184 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6185 info_ptr
+= bytes_read
;
6188 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6192 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6196 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6200 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6203 case DW_FORM_ref_udata
:
6204 DW_ADDR (attr
) = (cu
->header
.offset
6205 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6206 info_ptr
+= bytes_read
;
6208 case DW_FORM_indirect
:
6209 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6210 info_ptr
+= bytes_read
;
6211 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6214 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6215 dwarf_form_name (form
),
6216 bfd_get_filename (abfd
));
6219 /* We have seen instances where the compiler tried to emit a byte
6220 size attribute of -1 which ended up being encoded as an unsigned
6221 0xffffffff. Although 0xffffffff is technically a valid size value,
6222 an object of this size seems pretty unlikely so we can relatively
6223 safely treat these cases as if the size attribute was invalid and
6224 treat them as zero by default. */
6225 if (attr
->name
== DW_AT_byte_size
6226 && form
== DW_FORM_data4
6227 && DW_UNSND (attr
) >= 0xffffffff)
6230 (&symfile_complaints
,
6231 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6233 DW_UNSND (attr
) = 0;
6239 /* Read an attribute described by an abbreviated attribute. */
6242 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6243 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6245 attr
->name
= abbrev
->name
;
6246 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6249 /* read dwarf information from a buffer */
6252 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6254 return bfd_get_8 (abfd
, buf
);
6258 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6260 return bfd_get_signed_8 (abfd
, buf
);
6264 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6266 return bfd_get_16 (abfd
, buf
);
6270 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6272 return bfd_get_signed_16 (abfd
, buf
);
6276 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6278 return bfd_get_32 (abfd
, buf
);
6282 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6284 return bfd_get_signed_32 (abfd
, buf
);
6287 static unsigned long
6288 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6290 return bfd_get_64 (abfd
, buf
);
6294 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6295 unsigned int *bytes_read
)
6297 struct comp_unit_head
*cu_header
= &cu
->header
;
6298 CORE_ADDR retval
= 0;
6300 if (cu_header
->signed_addr_p
)
6302 switch (cu_header
->addr_size
)
6305 retval
= bfd_get_signed_16 (abfd
, buf
);
6308 retval
= bfd_get_signed_32 (abfd
, buf
);
6311 retval
= bfd_get_signed_64 (abfd
, buf
);
6314 internal_error (__FILE__
, __LINE__
,
6315 _("read_address: bad switch, signed [in module %s]"),
6316 bfd_get_filename (abfd
));
6321 switch (cu_header
->addr_size
)
6324 retval
= bfd_get_16 (abfd
, buf
);
6327 retval
= bfd_get_32 (abfd
, buf
);
6330 retval
= bfd_get_64 (abfd
, buf
);
6333 internal_error (__FILE__
, __LINE__
,
6334 _("read_address: bad switch, unsigned [in module %s]"),
6335 bfd_get_filename (abfd
));
6339 *bytes_read
= cu_header
->addr_size
;
6343 /* Read the initial length from a section. The (draft) DWARF 3
6344 specification allows the initial length to take up either 4 bytes
6345 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6346 bytes describe the length and all offsets will be 8 bytes in length
6349 An older, non-standard 64-bit format is also handled by this
6350 function. The older format in question stores the initial length
6351 as an 8-byte quantity without an escape value. Lengths greater
6352 than 2^32 aren't very common which means that the initial 4 bytes
6353 is almost always zero. Since a length value of zero doesn't make
6354 sense for the 32-bit format, this initial zero can be considered to
6355 be an escape value which indicates the presence of the older 64-bit
6356 format. As written, the code can't detect (old format) lengths
6357 greater than 4GB. If it becomes necessary to handle lengths
6358 somewhat larger than 4GB, we could allow other small values (such
6359 as the non-sensical values of 1, 2, and 3) to also be used as
6360 escape values indicating the presence of the old format.
6362 The value returned via bytes_read should be used to increment the
6363 relevant pointer after calling read_initial_length().
6365 As a side effect, this function sets the fields initial_length_size
6366 and offset_size in cu_header to the values appropriate for the
6367 length field. (The format of the initial length field determines
6368 the width of file offsets to be fetched later with read_offset().)
6370 [ Note: read_initial_length() and read_offset() are based on the
6371 document entitled "DWARF Debugging Information Format", revision
6372 3, draft 8, dated November 19, 2001. This document was obtained
6375 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6377 This document is only a draft and is subject to change. (So beware.)
6379 Details regarding the older, non-standard 64-bit format were
6380 determined empirically by examining 64-bit ELF files produced by
6381 the SGI toolchain on an IRIX 6.5 machine.
6383 - Kevin, July 16, 2002
6387 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6388 unsigned int *bytes_read
)
6390 LONGEST length
= bfd_get_32 (abfd
, buf
);
6392 if (length
== 0xffffffff)
6394 length
= bfd_get_64 (abfd
, buf
+ 4);
6397 else if (length
== 0)
6399 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6400 length
= bfd_get_64 (abfd
, buf
);
6410 gdb_assert (cu_header
->initial_length_size
== 0
6411 || cu_header
->initial_length_size
== 4
6412 || cu_header
->initial_length_size
== 8
6413 || cu_header
->initial_length_size
== 12);
6415 if (cu_header
->initial_length_size
!= 0
6416 && cu_header
->initial_length_size
!= *bytes_read
)
6417 complaint (&symfile_complaints
,
6418 _("intermixed 32-bit and 64-bit DWARF sections"));
6420 cu_header
->initial_length_size
= *bytes_read
;
6421 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6427 /* Read an offset from the data stream. The size of the offset is
6428 given by cu_header->offset_size. */
6431 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6432 unsigned int *bytes_read
)
6436 switch (cu_header
->offset_size
)
6439 retval
= bfd_get_32 (abfd
, buf
);
6443 retval
= bfd_get_64 (abfd
, buf
);
6447 internal_error (__FILE__
, __LINE__
,
6448 _("read_offset: bad switch [in module %s]"),
6449 bfd_get_filename (abfd
));
6456 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6458 /* If the size of a host char is 8 bits, we can return a pointer
6459 to the buffer, otherwise we have to copy the data to a buffer
6460 allocated on the temporary obstack. */
6461 gdb_assert (HOST_CHAR_BIT
== 8);
6466 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6468 /* If the size of a host char is 8 bits, we can return a pointer
6469 to the string, otherwise we have to copy the string to a buffer
6470 allocated on the temporary obstack. */
6471 gdb_assert (HOST_CHAR_BIT
== 8);
6474 *bytes_read_ptr
= 1;
6477 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6478 return (char *) buf
;
6482 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6483 const struct comp_unit_head
*cu_header
,
6484 unsigned int *bytes_read_ptr
)
6486 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6489 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6491 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6492 bfd_get_filename (abfd
));
6495 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6497 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6498 bfd_get_filename (abfd
));
6501 gdb_assert (HOST_CHAR_BIT
== 8);
6502 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6504 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6507 static unsigned long
6508 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6510 unsigned long result
;
6511 unsigned int num_read
;
6521 byte
= bfd_get_8 (abfd
, buf
);
6524 result
|= ((unsigned long)(byte
& 127) << shift
);
6525 if ((byte
& 128) == 0)
6531 *bytes_read_ptr
= num_read
;
6536 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6539 int i
, shift
, num_read
;
6548 byte
= bfd_get_8 (abfd
, buf
);
6551 result
|= ((long)(byte
& 127) << shift
);
6553 if ((byte
& 128) == 0)
6558 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6559 result
|= -(((long)1) << shift
);
6560 *bytes_read_ptr
= num_read
;
6564 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6567 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6573 byte
= bfd_get_8 (abfd
, buf
);
6575 if ((byte
& 128) == 0)
6581 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6587 cu
->language
= language_c
;
6589 case DW_LANG_C_plus_plus
:
6590 cu
->language
= language_cplus
;
6592 case DW_LANG_Fortran77
:
6593 case DW_LANG_Fortran90
:
6594 case DW_LANG_Fortran95
:
6595 cu
->language
= language_fortran
;
6597 case DW_LANG_Mips_Assembler
:
6598 cu
->language
= language_asm
;
6601 cu
->language
= language_java
;
6605 cu
->language
= language_ada
;
6607 case DW_LANG_Modula2
:
6608 cu
->language
= language_m2
;
6610 case DW_LANG_Pascal83
:
6611 cu
->language
= language_pascal
;
6614 cu
->language
= language_objc
;
6616 case DW_LANG_Cobol74
:
6617 case DW_LANG_Cobol85
:
6619 cu
->language
= language_minimal
;
6622 cu
->language_defn
= language_def (cu
->language
);
6625 /* Return the named attribute or NULL if not there. */
6627 static struct attribute
*
6628 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6631 struct attribute
*spec
= NULL
;
6633 for (i
= 0; i
< die
->num_attrs
; ++i
)
6635 if (die
->attrs
[i
].name
== name
)
6636 return &die
->attrs
[i
];
6637 if (die
->attrs
[i
].name
== DW_AT_specification
6638 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6639 spec
= &die
->attrs
[i
];
6644 die
= follow_die_ref (die
, spec
, &cu
);
6645 return dwarf2_attr (die
, name
, cu
);
6651 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6652 and holds a non-zero value. This function should only be used for
6653 DW_FORM_flag attributes. */
6656 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6658 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6660 return (attr
&& DW_UNSND (attr
));
6664 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6666 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6667 which value is non-zero. However, we have to be careful with
6668 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6669 (via dwarf2_flag_true_p) follows this attribute. So we may
6670 end up accidently finding a declaration attribute that belongs
6671 to a different DIE referenced by the specification attribute,
6672 even though the given DIE does not have a declaration attribute. */
6673 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6674 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6677 /* Return the die giving the specification for DIE, if there is
6678 one. *SPEC_CU is the CU containing DIE on input, and the CU
6679 containing the return value on output. */
6681 static struct die_info
*
6682 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6684 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6687 if (spec_attr
== NULL
)
6690 return follow_die_ref (die
, spec_attr
, spec_cu
);
6693 /* Free the line_header structure *LH, and any arrays and strings it
6696 free_line_header (struct line_header
*lh
)
6698 if (lh
->standard_opcode_lengths
)
6699 xfree (lh
->standard_opcode_lengths
);
6701 /* Remember that all the lh->file_names[i].name pointers are
6702 pointers into debug_line_buffer, and don't need to be freed. */
6704 xfree (lh
->file_names
);
6706 /* Similarly for the include directory names. */
6707 if (lh
->include_dirs
)
6708 xfree (lh
->include_dirs
);
6714 /* Add an entry to LH's include directory table. */
6716 add_include_dir (struct line_header
*lh
, char *include_dir
)
6718 /* Grow the array if necessary. */
6719 if (lh
->include_dirs_size
== 0)
6721 lh
->include_dirs_size
= 1; /* for testing */
6722 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6723 * sizeof (*lh
->include_dirs
));
6725 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6727 lh
->include_dirs_size
*= 2;
6728 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6729 (lh
->include_dirs_size
6730 * sizeof (*lh
->include_dirs
)));
6733 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6737 /* Add an entry to LH's file name table. */
6739 add_file_name (struct line_header
*lh
,
6741 unsigned int dir_index
,
6742 unsigned int mod_time
,
6743 unsigned int length
)
6745 struct file_entry
*fe
;
6747 /* Grow the array if necessary. */
6748 if (lh
->file_names_size
== 0)
6750 lh
->file_names_size
= 1; /* for testing */
6751 lh
->file_names
= xmalloc (lh
->file_names_size
6752 * sizeof (*lh
->file_names
));
6754 else if (lh
->num_file_names
>= lh
->file_names_size
)
6756 lh
->file_names_size
*= 2;
6757 lh
->file_names
= xrealloc (lh
->file_names
,
6758 (lh
->file_names_size
6759 * sizeof (*lh
->file_names
)));
6762 fe
= &lh
->file_names
[lh
->num_file_names
++];
6764 fe
->dir_index
= dir_index
;
6765 fe
->mod_time
= mod_time
;
6766 fe
->length
= length
;
6772 /* Read the statement program header starting at OFFSET in
6773 .debug_line, according to the endianness of ABFD. Return a pointer
6774 to a struct line_header, allocated using xmalloc.
6776 NOTE: the strings in the include directory and file name tables of
6777 the returned object point into debug_line_buffer, and must not be
6779 static struct line_header
*
6780 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6781 struct dwarf2_cu
*cu
)
6783 struct cleanup
*back_to
;
6784 struct line_header
*lh
;
6786 unsigned int bytes_read
;
6788 char *cur_dir
, *cur_file
;
6790 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6792 complaint (&symfile_complaints
, _("missing .debug_line section"));
6796 /* Make sure that at least there's room for the total_length field.
6797 That could be 12 bytes long, but we're just going to fudge that. */
6798 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6800 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6804 lh
= xmalloc (sizeof (*lh
));
6805 memset (lh
, 0, sizeof (*lh
));
6806 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6809 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6811 /* Read in the header. */
6813 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6814 line_ptr
+= bytes_read
;
6815 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6816 + dwarf2_per_objfile
->line_size
))
6818 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6821 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6822 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6824 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6825 line_ptr
+= bytes_read
;
6826 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6828 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6830 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6832 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6834 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6836 lh
->standard_opcode_lengths
6837 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6839 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6840 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6842 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6846 /* Read directory table. */
6847 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6849 line_ptr
+= bytes_read
;
6850 add_include_dir (lh
, cur_dir
);
6852 line_ptr
+= bytes_read
;
6854 /* Read file name table. */
6855 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6857 unsigned int dir_index
, mod_time
, length
;
6859 line_ptr
+= bytes_read
;
6860 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6861 line_ptr
+= bytes_read
;
6862 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6863 line_ptr
+= bytes_read
;
6864 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6865 line_ptr
+= bytes_read
;
6867 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6869 line_ptr
+= bytes_read
;
6870 lh
->statement_program_start
= line_ptr
;
6872 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6873 + dwarf2_per_objfile
->line_size
))
6874 complaint (&symfile_complaints
,
6875 _("line number info header doesn't fit in `.debug_line' section"));
6877 discard_cleanups (back_to
);
6881 /* This function exists to work around a bug in certain compilers
6882 (particularly GCC 2.95), in which the first line number marker of a
6883 function does not show up until after the prologue, right before
6884 the second line number marker. This function shifts ADDRESS down
6885 to the beginning of the function if necessary, and is called on
6886 addresses passed to record_line. */
6889 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6891 struct function_range
*fn
;
6893 /* Find the function_range containing address. */
6898 cu
->cached_fn
= cu
->first_fn
;
6902 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6908 while (fn
&& fn
!= cu
->cached_fn
)
6909 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6919 if (address
!= fn
->lowpc
)
6920 complaint (&symfile_complaints
,
6921 _("misplaced first line number at 0x%lx for '%s'"),
6922 (unsigned long) address
, fn
->name
);
6927 /* Decode the Line Number Program (LNP) for the given line_header
6928 structure and CU. The actual information extracted and the type
6929 of structures created from the LNP depends on the value of PST.
6931 1. If PST is NULL, then this procedure uses the data from the program
6932 to create all necessary symbol tables, and their linetables.
6933 The compilation directory of the file is passed in COMP_DIR,
6934 and must not be NULL.
6936 2. If PST is not NULL, this procedure reads the program to determine
6937 the list of files included by the unit represented by PST, and
6938 builds all the associated partial symbol tables. In this case,
6939 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6940 is not used to compute the full name of the symtab, and therefore
6941 omitting it when building the partial symtab does not introduce
6942 the potential for inconsistency - a partial symtab and its associated
6943 symbtab having a different fullname -). */
6946 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6947 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6949 gdb_byte
*line_ptr
, *extended_end
;
6951 unsigned int bytes_read
, extended_len
;
6952 unsigned char op_code
, extended_op
, adj_opcode
;
6954 struct objfile
*objfile
= cu
->objfile
;
6955 const int decode_for_pst_p
= (pst
!= NULL
);
6956 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
6958 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6960 line_ptr
= lh
->statement_program_start
;
6961 line_end
= lh
->statement_program_end
;
6963 /* Read the statement sequences until there's nothing left. */
6964 while (line_ptr
< line_end
)
6966 /* state machine registers */
6967 CORE_ADDR address
= 0;
6968 unsigned int file
= 1;
6969 unsigned int line
= 1;
6970 unsigned int column
= 0;
6971 int is_stmt
= lh
->default_is_stmt
;
6972 int basic_block
= 0;
6973 int end_sequence
= 0;
6975 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6977 /* Start a subfile for the current file of the state machine. */
6978 /* lh->include_dirs and lh->file_names are 0-based, but the
6979 directory and file name numbers in the statement program
6981 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6985 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6987 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6990 /* Decode the table. */
6991 while (!end_sequence
)
6993 op_code
= read_1_byte (abfd
, line_ptr
);
6996 if (op_code
>= lh
->opcode_base
)
6998 /* Special operand. */
6999 adj_opcode
= op_code
- lh
->opcode_base
;
7000 address
+= (adj_opcode
/ lh
->line_range
)
7001 * lh
->minimum_instruction_length
;
7002 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7003 if (lh
->num_file_names
< file
)
7004 dwarf2_debug_line_missing_file_complaint ();
7007 lh
->file_names
[file
- 1].included_p
= 1;
7008 if (!decode_for_pst_p
)
7010 if (last_subfile
!= current_subfile
)
7013 record_line (last_subfile
, 0, address
);
7014 last_subfile
= current_subfile
;
7016 /* Append row to matrix using current values. */
7017 record_line (current_subfile
, line
,
7018 check_cu_functions (address
, cu
));
7023 else switch (op_code
)
7025 case DW_LNS_extended_op
:
7026 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7027 line_ptr
+= bytes_read
;
7028 extended_end
= line_ptr
+ extended_len
;
7029 extended_op
= read_1_byte (abfd
, line_ptr
);
7031 switch (extended_op
)
7033 case DW_LNE_end_sequence
:
7036 if (lh
->num_file_names
< file
)
7037 dwarf2_debug_line_missing_file_complaint ();
7040 lh
->file_names
[file
- 1].included_p
= 1;
7041 if (!decode_for_pst_p
)
7042 record_line (current_subfile
, 0, address
);
7045 case DW_LNE_set_address
:
7046 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7047 line_ptr
+= bytes_read
;
7048 address
+= baseaddr
;
7050 case DW_LNE_define_file
:
7053 unsigned int dir_index
, mod_time
, length
;
7055 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7056 line_ptr
+= bytes_read
;
7058 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7059 line_ptr
+= bytes_read
;
7061 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7062 line_ptr
+= bytes_read
;
7064 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7065 line_ptr
+= bytes_read
;
7066 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7070 complaint (&symfile_complaints
,
7071 _("mangled .debug_line section"));
7074 /* Make sure that we parsed the extended op correctly. If e.g.
7075 we expected a different address size than the producer used,
7076 we may have read the wrong number of bytes. */
7077 if (line_ptr
!= extended_end
)
7079 complaint (&symfile_complaints
,
7080 _("mangled .debug_line section"));
7085 if (lh
->num_file_names
< file
)
7086 dwarf2_debug_line_missing_file_complaint ();
7089 lh
->file_names
[file
- 1].included_p
= 1;
7090 if (!decode_for_pst_p
)
7092 if (last_subfile
!= current_subfile
)
7095 record_line (last_subfile
, 0, address
);
7096 last_subfile
= current_subfile
;
7098 record_line (current_subfile
, line
,
7099 check_cu_functions (address
, cu
));
7104 case DW_LNS_advance_pc
:
7105 address
+= lh
->minimum_instruction_length
7106 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7107 line_ptr
+= bytes_read
;
7109 case DW_LNS_advance_line
:
7110 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7111 line_ptr
+= bytes_read
;
7113 case DW_LNS_set_file
:
7115 /* The arrays lh->include_dirs and lh->file_names are
7116 0-based, but the directory and file name numbers in
7117 the statement program are 1-based. */
7118 struct file_entry
*fe
;
7121 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7122 line_ptr
+= bytes_read
;
7123 if (lh
->num_file_names
< file
)
7124 dwarf2_debug_line_missing_file_complaint ();
7127 fe
= &lh
->file_names
[file
- 1];
7129 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7130 if (!decode_for_pst_p
)
7132 last_subfile
= current_subfile
;
7133 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7138 case DW_LNS_set_column
:
7139 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7140 line_ptr
+= bytes_read
;
7142 case DW_LNS_negate_stmt
:
7143 is_stmt
= (!is_stmt
);
7145 case DW_LNS_set_basic_block
:
7148 /* Add to the address register of the state machine the
7149 address increment value corresponding to special opcode
7150 255. I.e., this value is scaled by the minimum
7151 instruction length since special opcode 255 would have
7152 scaled the the increment. */
7153 case DW_LNS_const_add_pc
:
7154 address
+= (lh
->minimum_instruction_length
7155 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7157 case DW_LNS_fixed_advance_pc
:
7158 address
+= read_2_bytes (abfd
, line_ptr
);
7163 /* Unknown standard opcode, ignore it. */
7166 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7168 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7169 line_ptr
+= bytes_read
;
7176 if (decode_for_pst_p
)
7180 /* Now that we're done scanning the Line Header Program, we can
7181 create the psymtab of each included file. */
7182 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7183 if (lh
->file_names
[file_index
].included_p
== 1)
7185 const struct file_entry fe
= lh
->file_names
[file_index
];
7186 char *include_name
= fe
.name
;
7187 char *dir_name
= NULL
;
7188 char *pst_filename
= pst
->filename
;
7191 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7193 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7195 include_name
= concat (dir_name
, SLASH_STRING
,
7196 include_name
, (char *)NULL
);
7197 make_cleanup (xfree
, include_name
);
7200 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7202 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7203 pst_filename
, (char *)NULL
);
7204 make_cleanup (xfree
, pst_filename
);
7207 if (strcmp (include_name
, pst_filename
) != 0)
7208 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7213 /* Make sure a symtab is created for every file, even files
7214 which contain only variables (i.e. no code with associated
7218 struct file_entry
*fe
;
7220 for (i
= 0; i
< lh
->num_file_names
; i
++)
7223 fe
= &lh
->file_names
[i
];
7225 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7226 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7228 /* Skip the main file; we don't need it, and it must be
7229 allocated last, so that it will show up before the
7230 non-primary symtabs in the objfile's symtab list. */
7231 if (current_subfile
== first_subfile
)
7234 if (current_subfile
->symtab
== NULL
)
7235 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7237 fe
->symtab
= current_subfile
->symtab
;
7242 /* Start a subfile for DWARF. FILENAME is the name of the file and
7243 DIRNAME the name of the source directory which contains FILENAME
7244 or NULL if not known. COMP_DIR is the compilation directory for the
7245 linetable's compilation unit or NULL if not known.
7246 This routine tries to keep line numbers from identical absolute and
7247 relative file names in a common subfile.
7249 Using the `list' example from the GDB testsuite, which resides in
7250 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7251 of /srcdir/list0.c yields the following debugging information for list0.c:
7253 DW_AT_name: /srcdir/list0.c
7254 DW_AT_comp_dir: /compdir
7255 files.files[0].name: list0.h
7256 files.files[0].dir: /srcdir
7257 files.files[1].name: list0.c
7258 files.files[1].dir: /srcdir
7260 The line number information for list0.c has to end up in a single
7261 subfile, so that `break /srcdir/list0.c:1' works as expected.
7262 start_subfile will ensure that this happens provided that we pass the
7263 concatenation of files.files[1].dir and files.files[1].name as the
7267 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7271 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7272 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7273 second argument to start_subfile. To be consistent, we do the
7274 same here. In order not to lose the line information directory,
7275 we concatenate it to the filename when it makes sense.
7276 Note that the Dwarf3 standard says (speaking of filenames in line
7277 information): ``The directory index is ignored for file names
7278 that represent full path names''. Thus ignoring dirname in the
7279 `else' branch below isn't an issue. */
7281 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7282 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7284 fullname
= filename
;
7286 start_subfile (fullname
, comp_dir
);
7288 if (fullname
!= filename
)
7293 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7294 struct dwarf2_cu
*cu
)
7296 struct objfile
*objfile
= cu
->objfile
;
7297 struct comp_unit_head
*cu_header
= &cu
->header
;
7299 /* NOTE drow/2003-01-30: There used to be a comment and some special
7300 code here to turn a symbol with DW_AT_external and a
7301 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7302 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7303 with some versions of binutils) where shared libraries could have
7304 relocations against symbols in their debug information - the
7305 minimal symbol would have the right address, but the debug info
7306 would not. It's no longer necessary, because we will explicitly
7307 apply relocations when we read in the debug information now. */
7309 /* A DW_AT_location attribute with no contents indicates that a
7310 variable has been optimized away. */
7311 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7313 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7317 /* Handle one degenerate form of location expression specially, to
7318 preserve GDB's previous behavior when section offsets are
7319 specified. If this is just a DW_OP_addr then mark this symbol
7322 if (attr_form_is_block (attr
)
7323 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7324 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7328 SYMBOL_VALUE_ADDRESS (sym
) =
7329 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7330 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7331 fixup_symbol_section (sym
, objfile
);
7332 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7333 SYMBOL_SECTION (sym
));
7337 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7338 expression evaluator, and use LOC_COMPUTED only when necessary
7339 (i.e. when the value of a register or memory location is
7340 referenced, or a thread-local block, etc.). Then again, it might
7341 not be worthwhile. I'm assuming that it isn't unless performance
7342 or memory numbers show me otherwise. */
7344 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7345 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7348 /* Given a pointer to a DWARF information entry, figure out if we need
7349 to make a symbol table entry for it, and if so, create a new entry
7350 and return a pointer to it.
7351 If TYPE is NULL, determine symbol type from the die, otherwise
7352 used the passed type. */
7354 static struct symbol
*
7355 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7357 struct objfile
*objfile
= cu
->objfile
;
7358 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7359 struct symbol
*sym
= NULL
;
7361 struct attribute
*attr
= NULL
;
7362 struct attribute
*attr2
= NULL
;
7365 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7367 if (die
->tag
!= DW_TAG_namespace
)
7368 name
= dwarf2_linkage_name (die
, cu
);
7370 name
= TYPE_NAME (type
);
7374 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7375 sizeof (struct symbol
));
7376 OBJSTAT (objfile
, n_syms
++);
7377 memset (sym
, 0, sizeof (struct symbol
));
7379 /* Cache this symbol's name and the name's demangled form (if any). */
7380 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7381 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7383 /* Default assumptions.
7384 Use the passed type or decode it from the die. */
7385 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7386 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7388 SYMBOL_TYPE (sym
) = type
;
7390 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7391 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7394 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7397 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7400 int file_index
= DW_UNSND (attr
);
7401 if (cu
->line_header
== NULL
7402 || file_index
> cu
->line_header
->num_file_names
)
7403 complaint (&symfile_complaints
,
7404 _("file index out of range"));
7405 else if (file_index
> 0)
7407 struct file_entry
*fe
;
7408 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7409 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7416 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7419 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7421 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7423 case DW_TAG_subprogram
:
7424 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7426 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7427 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7428 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7429 || cu
->language
== language_ada
)
7431 /* Subprograms marked external are stored as a global symbol.
7432 Ada subprograms, whether marked external or not, are always
7433 stored as a global symbol, because we want to be able to
7434 access them globally. For instance, we want to be able
7435 to break on a nested subprogram without having to
7436 specify the context. */
7437 add_symbol_to_list (sym
, &global_symbols
);
7441 add_symbol_to_list (sym
, cu
->list_in_scope
);
7444 case DW_TAG_variable
:
7445 /* Compilation with minimal debug info may result in variables
7446 with missing type entries. Change the misleading `void' type
7447 to something sensible. */
7448 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7450 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7452 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7455 dwarf2_const_value (attr
, sym
, cu
);
7456 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7457 if (attr2
&& (DW_UNSND (attr2
) != 0))
7458 add_symbol_to_list (sym
, &global_symbols
);
7460 add_symbol_to_list (sym
, cu
->list_in_scope
);
7463 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7466 var_decode_location (attr
, sym
, cu
);
7467 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7468 if (attr2
&& (DW_UNSND (attr2
) != 0))
7469 add_symbol_to_list (sym
, &global_symbols
);
7471 add_symbol_to_list (sym
, cu
->list_in_scope
);
7475 /* We do not know the address of this symbol.
7476 If it is an external symbol and we have type information
7477 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7478 The address of the variable will then be determined from
7479 the minimal symbol table whenever the variable is
7481 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7482 if (attr2
&& (DW_UNSND (attr2
) != 0)
7483 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7485 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7486 add_symbol_to_list (sym
, &global_symbols
);
7490 case DW_TAG_formal_parameter
:
7491 SYMBOL_IS_ARGUMENT (sym
) = 1;
7492 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7495 var_decode_location (attr
, sym
, cu
);
7497 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7500 dwarf2_const_value (attr
, sym
, cu
);
7502 add_symbol_to_list (sym
, cu
->list_in_scope
);
7504 case DW_TAG_unspecified_parameters
:
7505 /* From varargs functions; gdb doesn't seem to have any
7506 interest in this information, so just ignore it for now.
7509 case DW_TAG_class_type
:
7510 case DW_TAG_interface_type
:
7511 case DW_TAG_structure_type
:
7512 case DW_TAG_union_type
:
7513 case DW_TAG_set_type
:
7514 case DW_TAG_enumeration_type
:
7515 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7516 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7518 /* Make sure that the symbol includes appropriate enclosing
7519 classes/namespaces in its name. These are calculated in
7520 read_structure_type, and the correct name is saved in
7523 if (cu
->language
== language_cplus
7524 || cu
->language
== language_java
)
7526 struct type
*type
= SYMBOL_TYPE (sym
);
7528 if (TYPE_TAG_NAME (type
) != NULL
)
7530 /* FIXME: carlton/2003-11-10: Should this use
7531 SYMBOL_SET_NAMES instead? (The same problem also
7532 arises further down in this function.) */
7533 /* The type's name is already allocated along with
7534 this objfile, so we don't need to duplicate it
7536 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7541 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7542 really ever be static objects: otherwise, if you try
7543 to, say, break of a class's method and you're in a file
7544 which doesn't mention that class, it won't work unless
7545 the check for all static symbols in lookup_symbol_aux
7546 saves you. See the OtherFileClass tests in
7547 gdb.c++/namespace.exp. */
7549 struct pending
**list_to_add
;
7551 list_to_add
= (cu
->list_in_scope
== &file_symbols
7552 && (cu
->language
== language_cplus
7553 || cu
->language
== language_java
)
7554 ? &global_symbols
: cu
->list_in_scope
);
7556 add_symbol_to_list (sym
, list_to_add
);
7558 /* The semantics of C++ state that "struct foo { ... }" also
7559 defines a typedef for "foo". A Java class declaration also
7560 defines a typedef for the class. */
7561 if (cu
->language
== language_cplus
7562 || cu
->language
== language_java
7563 || cu
->language
== language_ada
)
7565 /* The symbol's name is already allocated along with
7566 this objfile, so we don't need to duplicate it for
7568 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7569 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7573 case DW_TAG_typedef
:
7574 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7575 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7576 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7577 add_symbol_to_list (sym
, cu
->list_in_scope
);
7579 case DW_TAG_base_type
:
7580 case DW_TAG_subrange_type
:
7581 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7582 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7583 add_symbol_to_list (sym
, cu
->list_in_scope
);
7585 case DW_TAG_enumerator
:
7586 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7587 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7590 dwarf2_const_value (attr
, sym
, cu
);
7593 /* NOTE: carlton/2003-11-10: See comment above in the
7594 DW_TAG_class_type, etc. block. */
7596 struct pending
**list_to_add
;
7598 list_to_add
= (cu
->list_in_scope
== &file_symbols
7599 && (cu
->language
== language_cplus
7600 || cu
->language
== language_java
)
7601 ? &global_symbols
: cu
->list_in_scope
);
7603 add_symbol_to_list (sym
, list_to_add
);
7606 case DW_TAG_namespace
:
7607 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7608 add_symbol_to_list (sym
, &global_symbols
);
7611 /* Not a tag we recognize. Hopefully we aren't processing
7612 trash data, but since we must specifically ignore things
7613 we don't recognize, there is nothing else we should do at
7615 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7616 dwarf_tag_name (die
->tag
));
7620 /* For the benefit of old versions of GCC, check for anonymous
7621 namespaces based on the demangled name. */
7622 if (!processing_has_namespace_info
7623 && cu
->language
== language_cplus
7624 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7625 cp_scan_for_anonymous_namespaces (sym
);
7630 /* Copy constant value from an attribute to a symbol. */
7633 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7634 struct dwarf2_cu
*cu
)
7636 struct objfile
*objfile
= cu
->objfile
;
7637 struct comp_unit_head
*cu_header
= &cu
->header
;
7638 struct dwarf_block
*blk
;
7643 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7644 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7645 cu_header
->addr_size
,
7646 TYPE_LENGTH (SYMBOL_TYPE
7648 SYMBOL_VALUE_BYTES (sym
) =
7649 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7650 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7651 it's body - store_unsigned_integer. */
7652 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7654 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7657 /* DW_STRING is already allocated on the obstack, point directly
7659 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7660 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7662 case DW_FORM_block1
:
7663 case DW_FORM_block2
:
7664 case DW_FORM_block4
:
7666 blk
= DW_BLOCK (attr
);
7667 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7668 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7670 TYPE_LENGTH (SYMBOL_TYPE
7672 SYMBOL_VALUE_BYTES (sym
) =
7673 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7674 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7675 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7678 /* The DW_AT_const_value attributes are supposed to carry the
7679 symbol's value "represented as it would be on the target
7680 architecture." By the time we get here, it's already been
7681 converted to host endianness, so we just need to sign- or
7682 zero-extend it as appropriate. */
7684 dwarf2_const_value_data (attr
, sym
, 8);
7687 dwarf2_const_value_data (attr
, sym
, 16);
7690 dwarf2_const_value_data (attr
, sym
, 32);
7693 dwarf2_const_value_data (attr
, sym
, 64);
7697 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7698 SYMBOL_CLASS (sym
) = LOC_CONST
;
7702 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7703 SYMBOL_CLASS (sym
) = LOC_CONST
;
7707 complaint (&symfile_complaints
,
7708 _("unsupported const value attribute form: '%s'"),
7709 dwarf_form_name (attr
->form
));
7710 SYMBOL_VALUE (sym
) = 0;
7711 SYMBOL_CLASS (sym
) = LOC_CONST
;
7717 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7718 or zero-extend it as appropriate for the symbol's type. */
7720 dwarf2_const_value_data (struct attribute
*attr
,
7724 LONGEST l
= DW_UNSND (attr
);
7726 if (bits
< sizeof (l
) * 8)
7728 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7729 l
&= ((LONGEST
) 1 << bits
) - 1;
7731 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7734 SYMBOL_VALUE (sym
) = l
;
7735 SYMBOL_CLASS (sym
) = LOC_CONST
;
7739 /* Return the type of the die in question using its DW_AT_type attribute. */
7741 static struct type
*
7742 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7744 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7746 struct attribute
*type_attr
;
7747 struct die_info
*type_die
;
7749 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7752 /* A missing DW_AT_type represents a void type. */
7753 return builtin_type (gdbarch
)->builtin_void
;
7756 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7758 type
= tag_type_to_type (type_die
, cu
);
7761 dump_die (type_die
);
7762 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7768 /* Return the containing type of the die in question using its
7769 DW_AT_containing_type attribute. */
7771 static struct type
*
7772 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7774 struct type
*type
= NULL
;
7775 struct attribute
*type_attr
;
7776 struct die_info
*type_die
= NULL
;
7778 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7781 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7782 type
= tag_type_to_type (type_die
, cu
);
7787 dump_die (type_die
);
7788 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7794 static struct type
*
7795 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7797 struct type
*this_type
;
7799 this_type
= read_type_die (die
, cu
);
7803 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7809 static struct type
*
7810 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7812 struct type
*this_type
;
7814 this_type
= get_die_type (die
, cu
);
7820 case DW_TAG_class_type
:
7821 case DW_TAG_interface_type
:
7822 case DW_TAG_structure_type
:
7823 case DW_TAG_union_type
:
7824 this_type
= read_structure_type (die
, cu
);
7826 case DW_TAG_enumeration_type
:
7827 this_type
= read_enumeration_type (die
, cu
);
7829 case DW_TAG_subprogram
:
7830 case DW_TAG_subroutine_type
:
7831 this_type
= read_subroutine_type (die
, cu
);
7833 case DW_TAG_array_type
:
7834 this_type
= read_array_type (die
, cu
);
7836 case DW_TAG_set_type
:
7837 this_type
= read_set_type (die
, cu
);
7839 case DW_TAG_pointer_type
:
7840 this_type
= read_tag_pointer_type (die
, cu
);
7842 case DW_TAG_ptr_to_member_type
:
7843 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7845 case DW_TAG_reference_type
:
7846 this_type
= read_tag_reference_type (die
, cu
);
7848 case DW_TAG_const_type
:
7849 this_type
= read_tag_const_type (die
, cu
);
7851 case DW_TAG_volatile_type
:
7852 this_type
= read_tag_volatile_type (die
, cu
);
7854 case DW_TAG_string_type
:
7855 this_type
= read_tag_string_type (die
, cu
);
7857 case DW_TAG_typedef
:
7858 this_type
= read_typedef (die
, cu
);
7860 case DW_TAG_subrange_type
:
7861 this_type
= read_subrange_type (die
, cu
);
7863 case DW_TAG_base_type
:
7864 this_type
= read_base_type (die
, cu
);
7866 case DW_TAG_unspecified_type
:
7867 this_type
= read_unspecified_type (die
, cu
);
7869 case DW_TAG_namespace
:
7870 this_type
= read_namespace_type (die
, cu
);
7873 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7874 dwarf_tag_name (die
->tag
));
7881 /* Return the name of the namespace/class that DIE is defined within,
7882 or "" if we can't tell. The caller should not xfree the result.
7884 For example, if we're within the method foo() in the following
7894 then determine_prefix on foo's die will return "N::C". */
7897 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7899 struct die_info
*parent
, *spec_die
;
7900 struct dwarf2_cu
*spec_cu
;
7901 struct type
*parent_type
;
7903 if (cu
->language
!= language_cplus
7904 && cu
->language
!= language_java
)
7907 /* We have to be careful in the presence of DW_AT_specification.
7908 For example, with GCC 3.4, given the code
7912 // Definition of N::foo.
7916 then we'll have a tree of DIEs like this:
7918 1: DW_TAG_compile_unit
7919 2: DW_TAG_namespace // N
7920 3: DW_TAG_subprogram // declaration of N::foo
7921 4: DW_TAG_subprogram // definition of N::foo
7922 DW_AT_specification // refers to die #3
7924 Thus, when processing die #4, we have to pretend that we're in
7925 the context of its DW_AT_specification, namely the contex of die
7928 spec_die
= die_specification (die
, &spec_cu
);
7929 if (spec_die
== NULL
)
7930 parent
= die
->parent
;
7933 parent
= spec_die
->parent
;
7940 switch (parent
->tag
)
7942 case DW_TAG_namespace
:
7943 parent_type
= read_type_die (parent
, cu
);
7944 /* We give a name to even anonymous namespaces. */
7945 return TYPE_TAG_NAME (parent_type
);
7946 case DW_TAG_class_type
:
7947 case DW_TAG_interface_type
:
7948 case DW_TAG_structure_type
:
7949 case DW_TAG_union_type
:
7950 parent_type
= read_type_die (parent
, cu
);
7951 if (TYPE_TAG_NAME (parent_type
) != NULL
)
7952 return TYPE_TAG_NAME (parent_type
);
7954 /* An anonymous structure is only allowed non-static data
7955 members; no typedefs, no member functions, et cetera.
7956 So it does not need a prefix. */
7959 return determine_prefix (parent
, cu
);
7963 /* Return a newly-allocated string formed by concatenating PREFIX and
7964 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7965 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7966 perform an obconcat, otherwise allocate storage for the result. The CU argument
7967 is used to determine the language and hence, the appropriate separator. */
7969 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7972 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7973 struct dwarf2_cu
*cu
)
7977 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7979 else if (cu
->language
== language_java
)
7986 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7991 strcpy (retval
, prefix
);
7992 strcat (retval
, sep
);
7995 strcat (retval
, suffix
);
8001 /* We have an obstack. */
8002 return obconcat (obs
, prefix
, sep
, suffix
);
8006 /* Return sibling of die, NULL if no sibling. */
8008 static struct die_info
*
8009 sibling_die (struct die_info
*die
)
8011 return die
->sibling
;
8014 /* Get linkage name of a die, return NULL if not found. */
8017 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8019 struct attribute
*attr
;
8021 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8022 if (attr
&& DW_STRING (attr
))
8023 return DW_STRING (attr
);
8024 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8025 if (attr
&& DW_STRING (attr
))
8026 return DW_STRING (attr
);
8030 /* Get name of a die, return NULL if not found. */
8033 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8035 struct attribute
*attr
;
8037 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8038 if (attr
&& DW_STRING (attr
))
8039 return DW_STRING (attr
);
8043 /* Return the die that this die in an extension of, or NULL if there
8044 is none. *EXT_CU is the CU containing DIE on input, and the CU
8045 containing the return value on output. */
8047 static struct die_info
*
8048 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8050 struct attribute
*attr
;
8052 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8056 return follow_die_ref (die
, attr
, ext_cu
);
8059 /* Convert a DIE tag into its string name. */
8062 dwarf_tag_name (unsigned tag
)
8066 case DW_TAG_padding
:
8067 return "DW_TAG_padding";
8068 case DW_TAG_array_type
:
8069 return "DW_TAG_array_type";
8070 case DW_TAG_class_type
:
8071 return "DW_TAG_class_type";
8072 case DW_TAG_entry_point
:
8073 return "DW_TAG_entry_point";
8074 case DW_TAG_enumeration_type
:
8075 return "DW_TAG_enumeration_type";
8076 case DW_TAG_formal_parameter
:
8077 return "DW_TAG_formal_parameter";
8078 case DW_TAG_imported_declaration
:
8079 return "DW_TAG_imported_declaration";
8081 return "DW_TAG_label";
8082 case DW_TAG_lexical_block
:
8083 return "DW_TAG_lexical_block";
8085 return "DW_TAG_member";
8086 case DW_TAG_pointer_type
:
8087 return "DW_TAG_pointer_type";
8088 case DW_TAG_reference_type
:
8089 return "DW_TAG_reference_type";
8090 case DW_TAG_compile_unit
:
8091 return "DW_TAG_compile_unit";
8092 case DW_TAG_string_type
:
8093 return "DW_TAG_string_type";
8094 case DW_TAG_structure_type
:
8095 return "DW_TAG_structure_type";
8096 case DW_TAG_subroutine_type
:
8097 return "DW_TAG_subroutine_type";
8098 case DW_TAG_typedef
:
8099 return "DW_TAG_typedef";
8100 case DW_TAG_union_type
:
8101 return "DW_TAG_union_type";
8102 case DW_TAG_unspecified_parameters
:
8103 return "DW_TAG_unspecified_parameters";
8104 case DW_TAG_variant
:
8105 return "DW_TAG_variant";
8106 case DW_TAG_common_block
:
8107 return "DW_TAG_common_block";
8108 case DW_TAG_common_inclusion
:
8109 return "DW_TAG_common_inclusion";
8110 case DW_TAG_inheritance
:
8111 return "DW_TAG_inheritance";
8112 case DW_TAG_inlined_subroutine
:
8113 return "DW_TAG_inlined_subroutine";
8115 return "DW_TAG_module";
8116 case DW_TAG_ptr_to_member_type
:
8117 return "DW_TAG_ptr_to_member_type";
8118 case DW_TAG_set_type
:
8119 return "DW_TAG_set_type";
8120 case DW_TAG_subrange_type
:
8121 return "DW_TAG_subrange_type";
8122 case DW_TAG_with_stmt
:
8123 return "DW_TAG_with_stmt";
8124 case DW_TAG_access_declaration
:
8125 return "DW_TAG_access_declaration";
8126 case DW_TAG_base_type
:
8127 return "DW_TAG_base_type";
8128 case DW_TAG_catch_block
:
8129 return "DW_TAG_catch_block";
8130 case DW_TAG_const_type
:
8131 return "DW_TAG_const_type";
8132 case DW_TAG_constant
:
8133 return "DW_TAG_constant";
8134 case DW_TAG_enumerator
:
8135 return "DW_TAG_enumerator";
8136 case DW_TAG_file_type
:
8137 return "DW_TAG_file_type";
8139 return "DW_TAG_friend";
8140 case DW_TAG_namelist
:
8141 return "DW_TAG_namelist";
8142 case DW_TAG_namelist_item
:
8143 return "DW_TAG_namelist_item";
8144 case DW_TAG_packed_type
:
8145 return "DW_TAG_packed_type";
8146 case DW_TAG_subprogram
:
8147 return "DW_TAG_subprogram";
8148 case DW_TAG_template_type_param
:
8149 return "DW_TAG_template_type_param";
8150 case DW_TAG_template_value_param
:
8151 return "DW_TAG_template_value_param";
8152 case DW_TAG_thrown_type
:
8153 return "DW_TAG_thrown_type";
8154 case DW_TAG_try_block
:
8155 return "DW_TAG_try_block";
8156 case DW_TAG_variant_part
:
8157 return "DW_TAG_variant_part";
8158 case DW_TAG_variable
:
8159 return "DW_TAG_variable";
8160 case DW_TAG_volatile_type
:
8161 return "DW_TAG_volatile_type";
8162 case DW_TAG_dwarf_procedure
:
8163 return "DW_TAG_dwarf_procedure";
8164 case DW_TAG_restrict_type
:
8165 return "DW_TAG_restrict_type";
8166 case DW_TAG_interface_type
:
8167 return "DW_TAG_interface_type";
8168 case DW_TAG_namespace
:
8169 return "DW_TAG_namespace";
8170 case DW_TAG_imported_module
:
8171 return "DW_TAG_imported_module";
8172 case DW_TAG_unspecified_type
:
8173 return "DW_TAG_unspecified_type";
8174 case DW_TAG_partial_unit
:
8175 return "DW_TAG_partial_unit";
8176 case DW_TAG_imported_unit
:
8177 return "DW_TAG_imported_unit";
8178 case DW_TAG_condition
:
8179 return "DW_TAG_condition";
8180 case DW_TAG_shared_type
:
8181 return "DW_TAG_shared_type";
8182 case DW_TAG_MIPS_loop
:
8183 return "DW_TAG_MIPS_loop";
8184 case DW_TAG_HP_array_descriptor
:
8185 return "DW_TAG_HP_array_descriptor";
8186 case DW_TAG_format_label
:
8187 return "DW_TAG_format_label";
8188 case DW_TAG_function_template
:
8189 return "DW_TAG_function_template";
8190 case DW_TAG_class_template
:
8191 return "DW_TAG_class_template";
8192 case DW_TAG_GNU_BINCL
:
8193 return "DW_TAG_GNU_BINCL";
8194 case DW_TAG_GNU_EINCL
:
8195 return "DW_TAG_GNU_EINCL";
8196 case DW_TAG_upc_shared_type
:
8197 return "DW_TAG_upc_shared_type";
8198 case DW_TAG_upc_strict_type
:
8199 return "DW_TAG_upc_strict_type";
8200 case DW_TAG_upc_relaxed_type
:
8201 return "DW_TAG_upc_relaxed_type";
8202 case DW_TAG_PGI_kanji_type
:
8203 return "DW_TAG_PGI_kanji_type";
8204 case DW_TAG_PGI_interface_block
:
8205 return "DW_TAG_PGI_interface_block";
8207 return "DW_TAG_<unknown>";
8211 /* Convert a DWARF attribute code into its string name. */
8214 dwarf_attr_name (unsigned attr
)
8219 return "DW_AT_sibling";
8220 case DW_AT_location
:
8221 return "DW_AT_location";
8223 return "DW_AT_name";
8224 case DW_AT_ordering
:
8225 return "DW_AT_ordering";
8226 case DW_AT_subscr_data
:
8227 return "DW_AT_subscr_data";
8228 case DW_AT_byte_size
:
8229 return "DW_AT_byte_size";
8230 case DW_AT_bit_offset
:
8231 return "DW_AT_bit_offset";
8232 case DW_AT_bit_size
:
8233 return "DW_AT_bit_size";
8234 case DW_AT_element_list
:
8235 return "DW_AT_element_list";
8236 case DW_AT_stmt_list
:
8237 return "DW_AT_stmt_list";
8239 return "DW_AT_low_pc";
8241 return "DW_AT_high_pc";
8242 case DW_AT_language
:
8243 return "DW_AT_language";
8245 return "DW_AT_member";
8247 return "DW_AT_discr";
8248 case DW_AT_discr_value
:
8249 return "DW_AT_discr_value";
8250 case DW_AT_visibility
:
8251 return "DW_AT_visibility";
8253 return "DW_AT_import";
8254 case DW_AT_string_length
:
8255 return "DW_AT_string_length";
8256 case DW_AT_common_reference
:
8257 return "DW_AT_common_reference";
8258 case DW_AT_comp_dir
:
8259 return "DW_AT_comp_dir";
8260 case DW_AT_const_value
:
8261 return "DW_AT_const_value";
8262 case DW_AT_containing_type
:
8263 return "DW_AT_containing_type";
8264 case DW_AT_default_value
:
8265 return "DW_AT_default_value";
8267 return "DW_AT_inline";
8268 case DW_AT_is_optional
:
8269 return "DW_AT_is_optional";
8270 case DW_AT_lower_bound
:
8271 return "DW_AT_lower_bound";
8272 case DW_AT_producer
:
8273 return "DW_AT_producer";
8274 case DW_AT_prototyped
:
8275 return "DW_AT_prototyped";
8276 case DW_AT_return_addr
:
8277 return "DW_AT_return_addr";
8278 case DW_AT_start_scope
:
8279 return "DW_AT_start_scope";
8280 case DW_AT_bit_stride
:
8281 return "DW_AT_bit_stride";
8282 case DW_AT_upper_bound
:
8283 return "DW_AT_upper_bound";
8284 case DW_AT_abstract_origin
:
8285 return "DW_AT_abstract_origin";
8286 case DW_AT_accessibility
:
8287 return "DW_AT_accessibility";
8288 case DW_AT_address_class
:
8289 return "DW_AT_address_class";
8290 case DW_AT_artificial
:
8291 return "DW_AT_artificial";
8292 case DW_AT_base_types
:
8293 return "DW_AT_base_types";
8294 case DW_AT_calling_convention
:
8295 return "DW_AT_calling_convention";
8297 return "DW_AT_count";
8298 case DW_AT_data_member_location
:
8299 return "DW_AT_data_member_location";
8300 case DW_AT_decl_column
:
8301 return "DW_AT_decl_column";
8302 case DW_AT_decl_file
:
8303 return "DW_AT_decl_file";
8304 case DW_AT_decl_line
:
8305 return "DW_AT_decl_line";
8306 case DW_AT_declaration
:
8307 return "DW_AT_declaration";
8308 case DW_AT_discr_list
:
8309 return "DW_AT_discr_list";
8310 case DW_AT_encoding
:
8311 return "DW_AT_encoding";
8312 case DW_AT_external
:
8313 return "DW_AT_external";
8314 case DW_AT_frame_base
:
8315 return "DW_AT_frame_base";
8317 return "DW_AT_friend";
8318 case DW_AT_identifier_case
:
8319 return "DW_AT_identifier_case";
8320 case DW_AT_macro_info
:
8321 return "DW_AT_macro_info";
8322 case DW_AT_namelist_items
:
8323 return "DW_AT_namelist_items";
8324 case DW_AT_priority
:
8325 return "DW_AT_priority";
8327 return "DW_AT_segment";
8328 case DW_AT_specification
:
8329 return "DW_AT_specification";
8330 case DW_AT_static_link
:
8331 return "DW_AT_static_link";
8333 return "DW_AT_type";
8334 case DW_AT_use_location
:
8335 return "DW_AT_use_location";
8336 case DW_AT_variable_parameter
:
8337 return "DW_AT_variable_parameter";
8338 case DW_AT_virtuality
:
8339 return "DW_AT_virtuality";
8340 case DW_AT_vtable_elem_location
:
8341 return "DW_AT_vtable_elem_location";
8342 /* DWARF 3 values. */
8343 case DW_AT_allocated
:
8344 return "DW_AT_allocated";
8345 case DW_AT_associated
:
8346 return "DW_AT_associated";
8347 case DW_AT_data_location
:
8348 return "DW_AT_data_location";
8349 case DW_AT_byte_stride
:
8350 return "DW_AT_byte_stride";
8351 case DW_AT_entry_pc
:
8352 return "DW_AT_entry_pc";
8353 case DW_AT_use_UTF8
:
8354 return "DW_AT_use_UTF8";
8355 case DW_AT_extension
:
8356 return "DW_AT_extension";
8358 return "DW_AT_ranges";
8359 case DW_AT_trampoline
:
8360 return "DW_AT_trampoline";
8361 case DW_AT_call_column
:
8362 return "DW_AT_call_column";
8363 case DW_AT_call_file
:
8364 return "DW_AT_call_file";
8365 case DW_AT_call_line
:
8366 return "DW_AT_call_line";
8367 case DW_AT_description
:
8368 return "DW_AT_description";
8369 case DW_AT_binary_scale
:
8370 return "DW_AT_binary_scale";
8371 case DW_AT_decimal_scale
:
8372 return "DW_AT_decimal_scale";
8374 return "DW_AT_small";
8375 case DW_AT_decimal_sign
:
8376 return "DW_AT_decimal_sign";
8377 case DW_AT_digit_count
:
8378 return "DW_AT_digit_count";
8379 case DW_AT_picture_string
:
8380 return "DW_AT_picture_string";
8382 return "DW_AT_mutable";
8383 case DW_AT_threads_scaled
:
8384 return "DW_AT_threads_scaled";
8385 case DW_AT_explicit
:
8386 return "DW_AT_explicit";
8387 case DW_AT_object_pointer
:
8388 return "DW_AT_object_pointer";
8389 case DW_AT_endianity
:
8390 return "DW_AT_endianity";
8391 case DW_AT_elemental
:
8392 return "DW_AT_elemental";
8394 return "DW_AT_pure";
8395 case DW_AT_recursive
:
8396 return "DW_AT_recursive";
8398 /* SGI/MIPS extensions. */
8399 case DW_AT_MIPS_fde
:
8400 return "DW_AT_MIPS_fde";
8401 case DW_AT_MIPS_loop_begin
:
8402 return "DW_AT_MIPS_loop_begin";
8403 case DW_AT_MIPS_tail_loop_begin
:
8404 return "DW_AT_MIPS_tail_loop_begin";
8405 case DW_AT_MIPS_epilog_begin
:
8406 return "DW_AT_MIPS_epilog_begin";
8407 case DW_AT_MIPS_loop_unroll_factor
:
8408 return "DW_AT_MIPS_loop_unroll_factor";
8409 case DW_AT_MIPS_software_pipeline_depth
:
8410 return "DW_AT_MIPS_software_pipeline_depth";
8411 case DW_AT_MIPS_linkage_name
:
8412 return "DW_AT_MIPS_linkage_name";
8413 case DW_AT_MIPS_stride
:
8414 return "DW_AT_MIPS_stride";
8415 case DW_AT_MIPS_abstract_name
:
8416 return "DW_AT_MIPS_abstract_name";
8417 case DW_AT_MIPS_clone_origin
:
8418 return "DW_AT_MIPS_clone_origin";
8419 case DW_AT_MIPS_has_inlines
:
8420 return "DW_AT_MIPS_has_inlines";
8422 /* HP extensions. */
8423 case DW_AT_HP_block_index
:
8424 return "DW_AT_HP_block_index";
8425 case DW_AT_HP_unmodifiable
:
8426 return "DW_AT_HP_unmodifiable";
8427 case DW_AT_HP_actuals_stmt_list
:
8428 return "DW_AT_HP_actuals_stmt_list";
8429 case DW_AT_HP_proc_per_section
:
8430 return "DW_AT_HP_proc_per_section";
8431 case DW_AT_HP_raw_data_ptr
:
8432 return "DW_AT_HP_raw_data_ptr";
8433 case DW_AT_HP_pass_by_reference
:
8434 return "DW_AT_HP_pass_by_reference";
8435 case DW_AT_HP_opt_level
:
8436 return "DW_AT_HP_opt_level";
8437 case DW_AT_HP_prof_version_id
:
8438 return "DW_AT_HP_prof_version_id";
8439 case DW_AT_HP_opt_flags
:
8440 return "DW_AT_HP_opt_flags";
8441 case DW_AT_HP_cold_region_low_pc
:
8442 return "DW_AT_HP_cold_region_low_pc";
8443 case DW_AT_HP_cold_region_high_pc
:
8444 return "DW_AT_HP_cold_region_high_pc";
8445 case DW_AT_HP_all_variables_modifiable
:
8446 return "DW_AT_HP_all_variables_modifiable";
8447 case DW_AT_HP_linkage_name
:
8448 return "DW_AT_HP_linkage_name";
8449 case DW_AT_HP_prof_flags
:
8450 return "DW_AT_HP_prof_flags";
8451 /* GNU extensions. */
8452 case DW_AT_sf_names
:
8453 return "DW_AT_sf_names";
8454 case DW_AT_src_info
:
8455 return "DW_AT_src_info";
8456 case DW_AT_mac_info
:
8457 return "DW_AT_mac_info";
8458 case DW_AT_src_coords
:
8459 return "DW_AT_src_coords";
8460 case DW_AT_body_begin
:
8461 return "DW_AT_body_begin";
8462 case DW_AT_body_end
:
8463 return "DW_AT_body_end";
8464 case DW_AT_GNU_vector
:
8465 return "DW_AT_GNU_vector";
8466 /* VMS extensions. */
8467 case DW_AT_VMS_rtnbeg_pd_address
:
8468 return "DW_AT_VMS_rtnbeg_pd_address";
8469 /* UPC extension. */
8470 case DW_AT_upc_threads_scaled
:
8471 return "DW_AT_upc_threads_scaled";
8472 /* PGI (STMicroelectronics) extensions. */
8473 case DW_AT_PGI_lbase
:
8474 return "DW_AT_PGI_lbase";
8475 case DW_AT_PGI_soffset
:
8476 return "DW_AT_PGI_soffset";
8477 case DW_AT_PGI_lstride
:
8478 return "DW_AT_PGI_lstride";
8480 return "DW_AT_<unknown>";
8484 /* Convert a DWARF value form code into its string name. */
8487 dwarf_form_name (unsigned form
)
8492 return "DW_FORM_addr";
8493 case DW_FORM_block2
:
8494 return "DW_FORM_block2";
8495 case DW_FORM_block4
:
8496 return "DW_FORM_block4";
8498 return "DW_FORM_data2";
8500 return "DW_FORM_data4";
8502 return "DW_FORM_data8";
8503 case DW_FORM_string
:
8504 return "DW_FORM_string";
8506 return "DW_FORM_block";
8507 case DW_FORM_block1
:
8508 return "DW_FORM_block1";
8510 return "DW_FORM_data1";
8512 return "DW_FORM_flag";
8514 return "DW_FORM_sdata";
8516 return "DW_FORM_strp";
8518 return "DW_FORM_udata";
8519 case DW_FORM_ref_addr
:
8520 return "DW_FORM_ref_addr";
8522 return "DW_FORM_ref1";
8524 return "DW_FORM_ref2";
8526 return "DW_FORM_ref4";
8528 return "DW_FORM_ref8";
8529 case DW_FORM_ref_udata
:
8530 return "DW_FORM_ref_udata";
8531 case DW_FORM_indirect
:
8532 return "DW_FORM_indirect";
8534 return "DW_FORM_<unknown>";
8538 /* Convert a DWARF stack opcode into its string name. */
8541 dwarf_stack_op_name (unsigned op
)
8546 return "DW_OP_addr";
8548 return "DW_OP_deref";
8550 return "DW_OP_const1u";
8552 return "DW_OP_const1s";
8554 return "DW_OP_const2u";
8556 return "DW_OP_const2s";
8558 return "DW_OP_const4u";
8560 return "DW_OP_const4s";
8562 return "DW_OP_const8u";
8564 return "DW_OP_const8s";
8566 return "DW_OP_constu";
8568 return "DW_OP_consts";
8572 return "DW_OP_drop";
8574 return "DW_OP_over";
8576 return "DW_OP_pick";
8578 return "DW_OP_swap";
8582 return "DW_OP_xderef";
8590 return "DW_OP_minus";
8602 return "DW_OP_plus";
8603 case DW_OP_plus_uconst
:
8604 return "DW_OP_plus_uconst";
8610 return "DW_OP_shra";
8628 return "DW_OP_skip";
8630 return "DW_OP_lit0";
8632 return "DW_OP_lit1";
8634 return "DW_OP_lit2";
8636 return "DW_OP_lit3";
8638 return "DW_OP_lit4";
8640 return "DW_OP_lit5";
8642 return "DW_OP_lit6";
8644 return "DW_OP_lit7";
8646 return "DW_OP_lit8";
8648 return "DW_OP_lit9";
8650 return "DW_OP_lit10";
8652 return "DW_OP_lit11";
8654 return "DW_OP_lit12";
8656 return "DW_OP_lit13";
8658 return "DW_OP_lit14";
8660 return "DW_OP_lit15";
8662 return "DW_OP_lit16";
8664 return "DW_OP_lit17";
8666 return "DW_OP_lit18";
8668 return "DW_OP_lit19";
8670 return "DW_OP_lit20";
8672 return "DW_OP_lit21";
8674 return "DW_OP_lit22";
8676 return "DW_OP_lit23";
8678 return "DW_OP_lit24";
8680 return "DW_OP_lit25";
8682 return "DW_OP_lit26";
8684 return "DW_OP_lit27";
8686 return "DW_OP_lit28";
8688 return "DW_OP_lit29";
8690 return "DW_OP_lit30";
8692 return "DW_OP_lit31";
8694 return "DW_OP_reg0";
8696 return "DW_OP_reg1";
8698 return "DW_OP_reg2";
8700 return "DW_OP_reg3";
8702 return "DW_OP_reg4";
8704 return "DW_OP_reg5";
8706 return "DW_OP_reg6";
8708 return "DW_OP_reg7";
8710 return "DW_OP_reg8";
8712 return "DW_OP_reg9";
8714 return "DW_OP_reg10";
8716 return "DW_OP_reg11";
8718 return "DW_OP_reg12";
8720 return "DW_OP_reg13";
8722 return "DW_OP_reg14";
8724 return "DW_OP_reg15";
8726 return "DW_OP_reg16";
8728 return "DW_OP_reg17";
8730 return "DW_OP_reg18";
8732 return "DW_OP_reg19";
8734 return "DW_OP_reg20";
8736 return "DW_OP_reg21";
8738 return "DW_OP_reg22";
8740 return "DW_OP_reg23";
8742 return "DW_OP_reg24";
8744 return "DW_OP_reg25";
8746 return "DW_OP_reg26";
8748 return "DW_OP_reg27";
8750 return "DW_OP_reg28";
8752 return "DW_OP_reg29";
8754 return "DW_OP_reg30";
8756 return "DW_OP_reg31";
8758 return "DW_OP_breg0";
8760 return "DW_OP_breg1";
8762 return "DW_OP_breg2";
8764 return "DW_OP_breg3";
8766 return "DW_OP_breg4";
8768 return "DW_OP_breg5";
8770 return "DW_OP_breg6";
8772 return "DW_OP_breg7";
8774 return "DW_OP_breg8";
8776 return "DW_OP_breg9";
8778 return "DW_OP_breg10";
8780 return "DW_OP_breg11";
8782 return "DW_OP_breg12";
8784 return "DW_OP_breg13";
8786 return "DW_OP_breg14";
8788 return "DW_OP_breg15";
8790 return "DW_OP_breg16";
8792 return "DW_OP_breg17";
8794 return "DW_OP_breg18";
8796 return "DW_OP_breg19";
8798 return "DW_OP_breg20";
8800 return "DW_OP_breg21";
8802 return "DW_OP_breg22";
8804 return "DW_OP_breg23";
8806 return "DW_OP_breg24";
8808 return "DW_OP_breg25";
8810 return "DW_OP_breg26";
8812 return "DW_OP_breg27";
8814 return "DW_OP_breg28";
8816 return "DW_OP_breg29";
8818 return "DW_OP_breg30";
8820 return "DW_OP_breg31";
8822 return "DW_OP_regx";
8824 return "DW_OP_fbreg";
8826 return "DW_OP_bregx";
8828 return "DW_OP_piece";
8829 case DW_OP_deref_size
:
8830 return "DW_OP_deref_size";
8831 case DW_OP_xderef_size
:
8832 return "DW_OP_xderef_size";
8835 /* DWARF 3 extensions. */
8836 case DW_OP_push_object_address
:
8837 return "DW_OP_push_object_address";
8839 return "DW_OP_call2";
8841 return "DW_OP_call4";
8842 case DW_OP_call_ref
:
8843 return "DW_OP_call_ref";
8844 /* GNU extensions. */
8845 case DW_OP_form_tls_address
:
8846 return "DW_OP_form_tls_address";
8847 case DW_OP_call_frame_cfa
:
8848 return "DW_OP_call_frame_cfa";
8849 case DW_OP_bit_piece
:
8850 return "DW_OP_bit_piece";
8851 case DW_OP_GNU_push_tls_address
:
8852 return "DW_OP_GNU_push_tls_address";
8853 case DW_OP_GNU_uninit
:
8854 return "DW_OP_GNU_uninit";
8855 /* HP extensions. */
8856 case DW_OP_HP_is_value
:
8857 return "DW_OP_HP_is_value";
8858 case DW_OP_HP_fltconst4
:
8859 return "DW_OP_HP_fltconst4";
8860 case DW_OP_HP_fltconst8
:
8861 return "DW_OP_HP_fltconst8";
8862 case DW_OP_HP_mod_range
:
8863 return "DW_OP_HP_mod_range";
8864 case DW_OP_HP_unmod_range
:
8865 return "DW_OP_HP_unmod_range";
8867 return "DW_OP_HP_tls";
8869 return "OP_<unknown>";
8874 dwarf_bool_name (unsigned mybool
)
8882 /* Convert a DWARF type code into its string name. */
8885 dwarf_type_encoding_name (unsigned enc
)
8890 return "DW_ATE_void";
8891 case DW_ATE_address
:
8892 return "DW_ATE_address";
8893 case DW_ATE_boolean
:
8894 return "DW_ATE_boolean";
8895 case DW_ATE_complex_float
:
8896 return "DW_ATE_complex_float";
8898 return "DW_ATE_float";
8900 return "DW_ATE_signed";
8901 case DW_ATE_signed_char
:
8902 return "DW_ATE_signed_char";
8903 case DW_ATE_unsigned
:
8904 return "DW_ATE_unsigned";
8905 case DW_ATE_unsigned_char
:
8906 return "DW_ATE_unsigned_char";
8908 case DW_ATE_imaginary_float
:
8909 return "DW_ATE_imaginary_float";
8910 case DW_ATE_packed_decimal
:
8911 return "DW_ATE_packed_decimal";
8912 case DW_ATE_numeric_string
:
8913 return "DW_ATE_numeric_string";
8915 return "DW_ATE_edited";
8916 case DW_ATE_signed_fixed
:
8917 return "DW_ATE_signed_fixed";
8918 case DW_ATE_unsigned_fixed
:
8919 return "DW_ATE_unsigned_fixed";
8920 case DW_ATE_decimal_float
:
8921 return "DW_ATE_decimal_float";
8922 /* HP extensions. */
8923 case DW_ATE_HP_float80
:
8924 return "DW_ATE_HP_float80";
8925 case DW_ATE_HP_complex_float80
:
8926 return "DW_ATE_HP_complex_float80";
8927 case DW_ATE_HP_float128
:
8928 return "DW_ATE_HP_float128";
8929 case DW_ATE_HP_complex_float128
:
8930 return "DW_ATE_HP_complex_float128";
8931 case DW_ATE_HP_floathpintel
:
8932 return "DW_ATE_HP_floathpintel";
8933 case DW_ATE_HP_imaginary_float80
:
8934 return "DW_ATE_HP_imaginary_float80";
8935 case DW_ATE_HP_imaginary_float128
:
8936 return "DW_ATE_HP_imaginary_float128";
8938 return "DW_ATE_<unknown>";
8942 /* Convert a DWARF call frame info operation to its string name. */
8946 dwarf_cfi_name (unsigned cfi_opc
)
8950 case DW_CFA_advance_loc
:
8951 return "DW_CFA_advance_loc";
8953 return "DW_CFA_offset";
8954 case DW_CFA_restore
:
8955 return "DW_CFA_restore";
8957 return "DW_CFA_nop";
8958 case DW_CFA_set_loc
:
8959 return "DW_CFA_set_loc";
8960 case DW_CFA_advance_loc1
:
8961 return "DW_CFA_advance_loc1";
8962 case DW_CFA_advance_loc2
:
8963 return "DW_CFA_advance_loc2";
8964 case DW_CFA_advance_loc4
:
8965 return "DW_CFA_advance_loc4";
8966 case DW_CFA_offset_extended
:
8967 return "DW_CFA_offset_extended";
8968 case DW_CFA_restore_extended
:
8969 return "DW_CFA_restore_extended";
8970 case DW_CFA_undefined
:
8971 return "DW_CFA_undefined";
8972 case DW_CFA_same_value
:
8973 return "DW_CFA_same_value";
8974 case DW_CFA_register
:
8975 return "DW_CFA_register";
8976 case DW_CFA_remember_state
:
8977 return "DW_CFA_remember_state";
8978 case DW_CFA_restore_state
:
8979 return "DW_CFA_restore_state";
8980 case DW_CFA_def_cfa
:
8981 return "DW_CFA_def_cfa";
8982 case DW_CFA_def_cfa_register
:
8983 return "DW_CFA_def_cfa_register";
8984 case DW_CFA_def_cfa_offset
:
8985 return "DW_CFA_def_cfa_offset";
8987 case DW_CFA_def_cfa_expression
:
8988 return "DW_CFA_def_cfa_expression";
8989 case DW_CFA_expression
:
8990 return "DW_CFA_expression";
8991 case DW_CFA_offset_extended_sf
:
8992 return "DW_CFA_offset_extended_sf";
8993 case DW_CFA_def_cfa_sf
:
8994 return "DW_CFA_def_cfa_sf";
8995 case DW_CFA_def_cfa_offset_sf
:
8996 return "DW_CFA_def_cfa_offset_sf";
8997 case DW_CFA_val_offset
:
8998 return "DW_CFA_val_offset";
8999 case DW_CFA_val_offset_sf
:
9000 return "DW_CFA_val_offset_sf";
9001 case DW_CFA_val_expression
:
9002 return "DW_CFA_val_expression";
9003 /* SGI/MIPS specific. */
9004 case DW_CFA_MIPS_advance_loc8
:
9005 return "DW_CFA_MIPS_advance_loc8";
9006 /* GNU extensions. */
9007 case DW_CFA_GNU_window_save
:
9008 return "DW_CFA_GNU_window_save";
9009 case DW_CFA_GNU_args_size
:
9010 return "DW_CFA_GNU_args_size";
9011 case DW_CFA_GNU_negative_offset_extended
:
9012 return "DW_CFA_GNU_negative_offset_extended";
9014 return "DW_CFA_<unknown>";
9020 dump_die (struct die_info
*die
)
9024 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9025 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9026 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9027 dwarf_bool_name (die
->child
!= NULL
));
9029 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9030 for (i
= 0; i
< die
->num_attrs
; ++i
)
9032 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9033 dwarf_attr_name (die
->attrs
[i
].name
),
9034 dwarf_form_name (die
->attrs
[i
].form
));
9035 switch (die
->attrs
[i
].form
)
9037 case DW_FORM_ref_addr
:
9039 fprintf_unfiltered (gdb_stderr
, "address: ");
9040 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9042 case DW_FORM_block2
:
9043 case DW_FORM_block4
:
9045 case DW_FORM_block1
:
9046 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9051 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9052 (long) (DW_ADDR (&die
->attrs
[i
])));
9060 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9062 case DW_FORM_string
:
9064 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9065 DW_STRING (&die
->attrs
[i
])
9066 ? DW_STRING (&die
->attrs
[i
]) : "");
9069 if (DW_UNSND (&die
->attrs
[i
]))
9070 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9072 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9074 case DW_FORM_indirect
:
9075 /* the reader will have reduced the indirect form to
9076 the "base form" so this form should not occur */
9077 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9080 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9081 die
->attrs
[i
].form
);
9083 fprintf_unfiltered (gdb_stderr
, "\n");
9088 dump_die_list (struct die_info
*die
)
9093 if (die
->child
!= NULL
)
9094 dump_die_list (die
->child
);
9095 if (die
->sibling
!= NULL
)
9096 dump_die_list (die
->sibling
);
9101 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9105 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9111 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9113 unsigned int result
= 0;
9117 case DW_FORM_ref_addr
:
9122 case DW_FORM_ref_udata
:
9123 result
= DW_ADDR (attr
);
9126 complaint (&symfile_complaints
,
9127 _("unsupported die ref attribute form: '%s'"),
9128 dwarf_form_name (attr
->form
));
9133 /* Return the constant value held by the given attribute. Return -1
9134 if the value held by the attribute is not constant. */
9137 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9139 if (attr
->form
== DW_FORM_sdata
)
9140 return DW_SND (attr
);
9141 else if (attr
->form
== DW_FORM_udata
9142 || attr
->form
== DW_FORM_data1
9143 || attr
->form
== DW_FORM_data2
9144 || attr
->form
== DW_FORM_data4
9145 || attr
->form
== DW_FORM_data8
)
9146 return DW_UNSND (attr
);
9149 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9150 dwarf_form_name (attr
->form
));
9151 return default_value
;
9155 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9156 unit and add it to our queue. */
9159 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9160 struct dwarf2_per_cu_data
*per_cu
)
9162 /* Mark the dependence relation so that we don't flush PER_CU
9164 dwarf2_add_dependence (this_cu
, per_cu
);
9166 /* If it's already on the queue, we have nothing to do. */
9170 /* If the compilation unit is already loaded, just mark it as
9172 if (per_cu
->cu
!= NULL
)
9174 per_cu
->cu
->last_used
= 0;
9178 /* Add it to the queue. */
9179 queue_comp_unit (per_cu
, this_cu
->objfile
);
9182 static struct die_info
*
9183 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9184 struct dwarf2_cu
**ref_cu
)
9186 struct die_info
*die
;
9187 unsigned int offset
;
9188 struct die_info temp_die
;
9189 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9191 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9193 if (DW_ADDR (attr
) < cu
->header
.offset
9194 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9196 struct dwarf2_per_cu_data
*per_cu
;
9197 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9200 /* If necessary, add it to the queue and load its DIEs. */
9201 maybe_queue_comp_unit (cu
, per_cu
);
9203 target_cu
= per_cu
->cu
;
9208 *ref_cu
= target_cu
;
9209 temp_die
.offset
= offset
;
9210 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9214 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9215 "at 0x%lx [in module %s]"),
9216 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9219 /* Decode simple location descriptions.
9220 Given a pointer to a dwarf block that defines a location, compute
9221 the location and return the value.
9223 NOTE drow/2003-11-18: This function is called in two situations
9224 now: for the address of static or global variables (partial symbols
9225 only) and for offsets into structures which are expected to be
9226 (more or less) constant. The partial symbol case should go away,
9227 and only the constant case should remain. That will let this
9228 function complain more accurately. A few special modes are allowed
9229 without complaint for global variables (for instance, global
9230 register values and thread-local values).
9232 A location description containing no operations indicates that the
9233 object is optimized out. The return value is 0 for that case.
9234 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9235 callers will only want a very basic result and this can become a
9238 Note that stack[0] is unused except as a default error return.
9239 Note that stack overflow is not yet handled. */
9242 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9244 struct objfile
*objfile
= cu
->objfile
;
9245 struct comp_unit_head
*cu_header
= &cu
->header
;
9247 int size
= blk
->size
;
9248 gdb_byte
*data
= blk
->data
;
9249 CORE_ADDR stack
[64];
9251 unsigned int bytes_read
, unsnd
;
9295 stack
[++stacki
] = op
- DW_OP_lit0
;
9330 stack
[++stacki
] = op
- DW_OP_reg0
;
9332 dwarf2_complex_location_expr_complaint ();
9336 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9338 stack
[++stacki
] = unsnd
;
9340 dwarf2_complex_location_expr_complaint ();
9344 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9350 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9355 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9360 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9365 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9370 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9375 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9380 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9386 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9391 stack
[stacki
+ 1] = stack
[stacki
];
9396 stack
[stacki
- 1] += stack
[stacki
];
9400 case DW_OP_plus_uconst
:
9401 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9406 stack
[stacki
- 1] -= stack
[stacki
];
9411 /* If we're not the last op, then we definitely can't encode
9412 this using GDB's address_class enum. This is valid for partial
9413 global symbols, although the variable's address will be bogus
9416 dwarf2_complex_location_expr_complaint ();
9419 case DW_OP_GNU_push_tls_address
:
9420 /* The top of the stack has the offset from the beginning
9421 of the thread control block at which the variable is located. */
9422 /* Nothing should follow this operator, so the top of stack would
9424 /* This is valid for partial global symbols, but the variable's
9425 address will be bogus in the psymtab. */
9427 dwarf2_complex_location_expr_complaint ();
9430 case DW_OP_GNU_uninit
:
9434 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9435 dwarf_stack_op_name (op
));
9436 return (stack
[stacki
]);
9439 return (stack
[stacki
]);
9442 /* memory allocation interface */
9444 static struct dwarf_block
*
9445 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9447 struct dwarf_block
*blk
;
9449 blk
= (struct dwarf_block
*)
9450 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9454 static struct abbrev_info
*
9455 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9457 struct abbrev_info
*abbrev
;
9459 abbrev
= (struct abbrev_info
*)
9460 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9461 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9465 static struct die_info
*
9466 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9468 struct die_info
*die
;
9469 size_t size
= sizeof (struct die_info
);
9472 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9474 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9475 memset (die
, 0, sizeof (struct die_info
));
9480 /* Macro support. */
9483 /* Return the full name of file number I in *LH's file name table.
9484 Use COMP_DIR as the name of the current directory of the
9485 compilation. The result is allocated using xmalloc; the caller is
9486 responsible for freeing it. */
9488 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9490 /* Is the file number a valid index into the line header's file name
9491 table? Remember that file numbers start with one, not zero. */
9492 if (1 <= file
&& file
<= lh
->num_file_names
)
9494 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9496 if (IS_ABSOLUTE_PATH (fe
->name
))
9497 return xstrdup (fe
->name
);
9505 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9511 dir_len
= strlen (dir
);
9512 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9513 strcpy (full_name
, dir
);
9514 full_name
[dir_len
] = '/';
9515 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9519 return xstrdup (fe
->name
);
9524 /* The compiler produced a bogus file number. We can at least
9525 record the macro definitions made in the file, even if we
9526 won't be able to find the file by name. */
9528 sprintf (fake_name
, "<bad macro file number %d>", file
);
9530 complaint (&symfile_complaints
,
9531 _("bad file number in macro information (%d)"),
9534 return xstrdup (fake_name
);
9539 static struct macro_source_file
*
9540 macro_start_file (int file
, int line
,
9541 struct macro_source_file
*current_file
,
9542 const char *comp_dir
,
9543 struct line_header
*lh
, struct objfile
*objfile
)
9545 /* The full name of this source file. */
9546 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9548 /* We don't create a macro table for this compilation unit
9549 at all until we actually get a filename. */
9550 if (! pending_macros
)
9551 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9552 objfile
->macro_cache
);
9555 /* If we have no current file, then this must be the start_file
9556 directive for the compilation unit's main source file. */
9557 current_file
= macro_set_main (pending_macros
, full_name
);
9559 current_file
= macro_include (current_file
, line
, full_name
);
9563 return current_file
;
9567 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9568 followed by a null byte. */
9570 copy_string (const char *buf
, int len
)
9572 char *s
= xmalloc (len
+ 1);
9573 memcpy (s
, buf
, len
);
9581 consume_improper_spaces (const char *p
, const char *body
)
9585 complaint (&symfile_complaints
,
9586 _("macro definition contains spaces in formal argument list:\n`%s'"),
9598 parse_macro_definition (struct macro_source_file
*file
, int line
,
9603 /* The body string takes one of two forms. For object-like macro
9604 definitions, it should be:
9606 <macro name> " " <definition>
9608 For function-like macro definitions, it should be:
9610 <macro name> "() " <definition>
9612 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9614 Spaces may appear only where explicitly indicated, and in the
9617 The Dwarf 2 spec says that an object-like macro's name is always
9618 followed by a space, but versions of GCC around March 2002 omit
9619 the space when the macro's definition is the empty string.
9621 The Dwarf 2 spec says that there should be no spaces between the
9622 formal arguments in a function-like macro's formal argument list,
9623 but versions of GCC around March 2002 include spaces after the
9627 /* Find the extent of the macro name. The macro name is terminated
9628 by either a space or null character (for an object-like macro) or
9629 an opening paren (for a function-like macro). */
9630 for (p
= body
; *p
; p
++)
9631 if (*p
== ' ' || *p
== '(')
9634 if (*p
== ' ' || *p
== '\0')
9636 /* It's an object-like macro. */
9637 int name_len
= p
- body
;
9638 char *name
= copy_string (body
, name_len
);
9639 const char *replacement
;
9642 replacement
= body
+ name_len
+ 1;
9645 dwarf2_macro_malformed_definition_complaint (body
);
9646 replacement
= body
+ name_len
;
9649 macro_define_object (file
, line
, name
, replacement
);
9655 /* It's a function-like macro. */
9656 char *name
= copy_string (body
, p
- body
);
9659 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9663 p
= consume_improper_spaces (p
, body
);
9665 /* Parse the formal argument list. */
9666 while (*p
&& *p
!= ')')
9668 /* Find the extent of the current argument name. */
9669 const char *arg_start
= p
;
9671 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9674 if (! *p
|| p
== arg_start
)
9675 dwarf2_macro_malformed_definition_complaint (body
);
9678 /* Make sure argv has room for the new argument. */
9679 if (argc
>= argv_size
)
9682 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9685 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9688 p
= consume_improper_spaces (p
, body
);
9690 /* Consume the comma, if present. */
9695 p
= consume_improper_spaces (p
, body
);
9704 /* Perfectly formed definition, no complaints. */
9705 macro_define_function (file
, line
, name
,
9706 argc
, (const char **) argv
,
9708 else if (*p
== '\0')
9710 /* Complain, but do define it. */
9711 dwarf2_macro_malformed_definition_complaint (body
);
9712 macro_define_function (file
, line
, name
,
9713 argc
, (const char **) argv
,
9717 /* Just complain. */
9718 dwarf2_macro_malformed_definition_complaint (body
);
9721 /* Just complain. */
9722 dwarf2_macro_malformed_definition_complaint (body
);
9728 for (i
= 0; i
< argc
; i
++)
9734 dwarf2_macro_malformed_definition_complaint (body
);
9739 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9740 char *comp_dir
, bfd
*abfd
,
9741 struct dwarf2_cu
*cu
)
9743 gdb_byte
*mac_ptr
, *mac_end
;
9744 struct macro_source_file
*current_file
= 0;
9746 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9748 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9752 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9753 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9754 + dwarf2_per_objfile
->macinfo_size
;
9758 enum dwarf_macinfo_record_type macinfo_type
;
9760 /* Do we at least have room for a macinfo type byte? */
9761 if (mac_ptr
>= mac_end
)
9763 dwarf2_macros_too_long_complaint ();
9767 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9770 switch (macinfo_type
)
9772 /* A zero macinfo type indicates the end of the macro
9777 case DW_MACINFO_define
:
9778 case DW_MACINFO_undef
:
9780 unsigned int bytes_read
;
9784 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9785 mac_ptr
+= bytes_read
;
9786 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9787 mac_ptr
+= bytes_read
;
9790 complaint (&symfile_complaints
,
9791 _("debug info gives macro %s outside of any file: %s"),
9793 DW_MACINFO_define
? "definition" : macinfo_type
==
9794 DW_MACINFO_undef
? "undefinition" :
9795 "something-or-other", body
);
9798 if (macinfo_type
== DW_MACINFO_define
)
9799 parse_macro_definition (current_file
, line
, body
);
9800 else if (macinfo_type
== DW_MACINFO_undef
)
9801 macro_undef (current_file
, line
, body
);
9806 case DW_MACINFO_start_file
:
9808 unsigned int bytes_read
;
9811 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9812 mac_ptr
+= bytes_read
;
9813 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9814 mac_ptr
+= bytes_read
;
9816 current_file
= macro_start_file (file
, line
,
9817 current_file
, comp_dir
,
9822 case DW_MACINFO_end_file
:
9824 complaint (&symfile_complaints
,
9825 _("macro debug info has an unmatched `close_file' directive"));
9828 current_file
= current_file
->included_by
;
9831 enum dwarf_macinfo_record_type next_type
;
9833 /* GCC circa March 2002 doesn't produce the zero
9834 type byte marking the end of the compilation
9835 unit. Complain if it's not there, but exit no
9838 /* Do we at least have room for a macinfo type byte? */
9839 if (mac_ptr
>= mac_end
)
9841 dwarf2_macros_too_long_complaint ();
9845 /* We don't increment mac_ptr here, so this is just
9847 next_type
= read_1_byte (abfd
, mac_ptr
);
9849 complaint (&symfile_complaints
,
9850 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9857 case DW_MACINFO_vendor_ext
:
9859 unsigned int bytes_read
;
9863 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9864 mac_ptr
+= bytes_read
;
9865 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9866 mac_ptr
+= bytes_read
;
9868 /* We don't recognize any vendor extensions. */
9875 /* Check if the attribute's form is a DW_FORM_block*
9876 if so return true else false. */
9878 attr_form_is_block (struct attribute
*attr
)
9880 return (attr
== NULL
? 0 :
9881 attr
->form
== DW_FORM_block1
9882 || attr
->form
== DW_FORM_block2
9883 || attr
->form
== DW_FORM_block4
9884 || attr
->form
== DW_FORM_block
);
9887 /* Return non-zero if ATTR's value is a section offset --- classes
9888 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9889 You may use DW_UNSND (attr) to retrieve such offsets.
9891 Section 7.5.4, "Attribute Encodings", explains that no attribute
9892 may have a value that belongs to more than one of these classes; it
9893 would be ambiguous if we did, because we use the same forms for all
9896 attr_form_is_section_offset (struct attribute
*attr
)
9898 return (attr
->form
== DW_FORM_data4
9899 || attr
->form
== DW_FORM_data8
);
9903 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9904 zero otherwise. When this function returns true, you can apply
9905 dwarf2_get_attr_constant_value to it.
9907 However, note that for some attributes you must check
9908 attr_form_is_section_offset before using this test. DW_FORM_data4
9909 and DW_FORM_data8 are members of both the constant class, and of
9910 the classes that contain offsets into other debug sections
9911 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9912 that, if an attribute's can be either a constant or one of the
9913 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9914 taken as section offsets, not constants. */
9916 attr_form_is_constant (struct attribute
*attr
)
9933 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9934 struct dwarf2_cu
*cu
)
9936 if (attr_form_is_section_offset (attr
)
9937 /* ".debug_loc" may not exist at all, or the offset may be outside
9938 the section. If so, fall through to the complaint in the
9940 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9942 struct dwarf2_loclist_baton
*baton
;
9944 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9945 sizeof (struct dwarf2_loclist_baton
));
9946 baton
->per_cu
= cu
->per_cu
;
9947 gdb_assert (baton
->per_cu
);
9949 /* We don't know how long the location list is, but make sure we
9950 don't run off the edge of the section. */
9951 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9952 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9953 baton
->base_address
= cu
->base_address
;
9954 if (cu
->base_known
== 0)
9955 complaint (&symfile_complaints
,
9956 _("Location list used without specifying the CU base address."));
9958 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9959 SYMBOL_LOCATION_BATON (sym
) = baton
;
9963 struct dwarf2_locexpr_baton
*baton
;
9965 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9966 sizeof (struct dwarf2_locexpr_baton
));
9967 baton
->per_cu
= cu
->per_cu
;
9968 gdb_assert (baton
->per_cu
);
9970 if (attr_form_is_block (attr
))
9972 /* Note that we're just copying the block's data pointer
9973 here, not the actual data. We're still pointing into the
9974 info_buffer for SYM's objfile; right now we never release
9975 that buffer, but when we do clean up properly this may
9977 baton
->size
= DW_BLOCK (attr
)->size
;
9978 baton
->data
= DW_BLOCK (attr
)->data
;
9982 dwarf2_invalid_attrib_class_complaint ("location description",
9983 SYMBOL_NATURAL_NAME (sym
));
9988 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9989 SYMBOL_LOCATION_BATON (sym
) = baton
;
9993 /* Return the OBJFILE associated with the compilation unit CU. */
9996 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
9998 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10000 /* Return the master objfile, so that we can report and look up the
10001 correct file containing this variable. */
10002 if (objfile
->separate_debug_objfile_backlink
)
10003 objfile
= objfile
->separate_debug_objfile_backlink
;
10008 /* Return the address size given in the compilation unit header for CU. */
10011 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10014 return per_cu
->cu
->header
.addr_size
;
10017 /* If the CU is not currently read in, we re-read its header. */
10018 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10019 struct dwarf2_per_objfile
*per_objfile
10020 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10021 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10023 struct comp_unit_head cu_header
;
10024 memset (&cu_header
, 0, sizeof cu_header
);
10025 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10026 return cu_header
.addr_size
;
10030 /* Locate the compilation unit from CU's objfile which contains the
10031 DIE at OFFSET. Raises an error on failure. */
10033 static struct dwarf2_per_cu_data
*
10034 dwarf2_find_containing_comp_unit (unsigned long offset
,
10035 struct objfile
*objfile
)
10037 struct dwarf2_per_cu_data
*this_cu
;
10041 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10044 int mid
= low
+ (high
- low
) / 2;
10045 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10050 gdb_assert (low
== high
);
10051 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10054 error (_("Dwarf Error: could not find partial DIE containing "
10055 "offset 0x%lx [in module %s]"),
10056 (long) offset
, bfd_get_filename (objfile
->obfd
));
10058 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10059 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10063 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10064 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10065 && offset
>= this_cu
->offset
+ this_cu
->length
)
10066 error (_("invalid dwarf2 offset %ld"), offset
);
10067 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10072 /* Locate the compilation unit from OBJFILE which is located at exactly
10073 OFFSET. Raises an error on failure. */
10075 static struct dwarf2_per_cu_data
*
10076 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10078 struct dwarf2_per_cu_data
*this_cu
;
10079 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10080 if (this_cu
->offset
!= offset
)
10081 error (_("no compilation unit with offset %ld."), offset
);
10085 /* Release one cached compilation unit, CU. We unlink it from the tree
10086 of compilation units, but we don't remove it from the read_in_chain;
10087 the caller is responsible for that. */
10090 free_one_comp_unit (void *data
)
10092 struct dwarf2_cu
*cu
= data
;
10094 if (cu
->per_cu
!= NULL
)
10095 cu
->per_cu
->cu
= NULL
;
10098 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10103 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10104 when we're finished with it. We can't free the pointer itself, but be
10105 sure to unlink it from the cache. Also release any associated storage
10106 and perform cache maintenance.
10108 Only used during partial symbol parsing. */
10111 free_stack_comp_unit (void *data
)
10113 struct dwarf2_cu
*cu
= data
;
10115 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10116 cu
->partial_dies
= NULL
;
10118 if (cu
->per_cu
!= NULL
)
10120 /* This compilation unit is on the stack in our caller, so we
10121 should not xfree it. Just unlink it. */
10122 cu
->per_cu
->cu
= NULL
;
10125 /* If we had a per-cu pointer, then we may have other compilation
10126 units loaded, so age them now. */
10127 age_cached_comp_units ();
10131 /* Free all cached compilation units. */
10134 free_cached_comp_units (void *data
)
10136 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10138 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10139 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10140 while (per_cu
!= NULL
)
10142 struct dwarf2_per_cu_data
*next_cu
;
10144 next_cu
= per_cu
->cu
->read_in_chain
;
10146 free_one_comp_unit (per_cu
->cu
);
10147 *last_chain
= next_cu
;
10153 /* Increase the age counter on each cached compilation unit, and free
10154 any that are too old. */
10157 age_cached_comp_units (void)
10159 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10161 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10162 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10163 while (per_cu
!= NULL
)
10165 per_cu
->cu
->last_used
++;
10166 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10167 dwarf2_mark (per_cu
->cu
);
10168 per_cu
= per_cu
->cu
->read_in_chain
;
10171 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10172 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10173 while (per_cu
!= NULL
)
10175 struct dwarf2_per_cu_data
*next_cu
;
10177 next_cu
= per_cu
->cu
->read_in_chain
;
10179 if (!per_cu
->cu
->mark
)
10181 free_one_comp_unit (per_cu
->cu
);
10182 *last_chain
= next_cu
;
10185 last_chain
= &per_cu
->cu
->read_in_chain
;
10191 /* Remove a single compilation unit from the cache. */
10194 free_one_cached_comp_unit (void *target_cu
)
10196 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10198 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10199 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10200 while (per_cu
!= NULL
)
10202 struct dwarf2_per_cu_data
*next_cu
;
10204 next_cu
= per_cu
->cu
->read_in_chain
;
10206 if (per_cu
->cu
== target_cu
)
10208 free_one_comp_unit (per_cu
->cu
);
10209 *last_chain
= next_cu
;
10213 last_chain
= &per_cu
->cu
->read_in_chain
;
10219 /* Release all extra memory associated with OBJFILE. */
10222 dwarf2_free_objfile (struct objfile
*objfile
)
10224 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10226 if (dwarf2_per_objfile
== NULL
)
10229 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10230 free_cached_comp_units (NULL
);
10232 /* Everything else should be on the objfile obstack. */
10235 /* A pair of DIE offset and GDB type pointer. We store these
10236 in a hash table separate from the DIEs, and preserve them
10237 when the DIEs are flushed out of cache. */
10239 struct dwarf2_offset_and_type
10241 unsigned int offset
;
10245 /* Hash function for a dwarf2_offset_and_type. */
10248 offset_and_type_hash (const void *item
)
10250 const struct dwarf2_offset_and_type
*ofs
= item
;
10251 return ofs
->offset
;
10254 /* Equality function for a dwarf2_offset_and_type. */
10257 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10259 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10260 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10261 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10264 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10265 table if necessary. For convenience, return TYPE. */
10267 static struct type
*
10268 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10270 struct dwarf2_offset_and_type
**slot
, ofs
;
10272 if (cu
->type_hash
== NULL
)
10274 gdb_assert (cu
->per_cu
!= NULL
);
10275 cu
->per_cu
->type_hash
10276 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10277 offset_and_type_hash
,
10278 offset_and_type_eq
,
10280 &cu
->objfile
->objfile_obstack
,
10281 hashtab_obstack_allocate
,
10282 dummy_obstack_deallocate
);
10283 cu
->type_hash
= cu
->per_cu
->type_hash
;
10286 ofs
.offset
= die
->offset
;
10288 slot
= (struct dwarf2_offset_and_type
**)
10289 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10290 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10295 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10296 not have a saved type. */
10298 static struct type
*
10299 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10301 struct dwarf2_offset_and_type
*slot
, ofs
;
10302 htab_t type_hash
= cu
->type_hash
;
10304 if (type_hash
== NULL
)
10307 ofs
.offset
= die
->offset
;
10308 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10315 /* Set the mark field in CU and in every other compilation unit in the
10316 cache that we must keep because we are keeping CU. */
10318 /* Add a dependence relationship from CU to REF_PER_CU. */
10321 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10322 struct dwarf2_per_cu_data
*ref_per_cu
)
10326 if (cu
->dependencies
== NULL
)
10328 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10329 NULL
, &cu
->comp_unit_obstack
,
10330 hashtab_obstack_allocate
,
10331 dummy_obstack_deallocate
);
10333 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10335 *slot
= ref_per_cu
;
10338 /* Set the mark field in CU and in every other compilation unit in the
10339 cache that we must keep because we are keeping CU. */
10342 dwarf2_mark_helper (void **slot
, void *data
)
10344 struct dwarf2_per_cu_data
*per_cu
;
10346 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10347 if (per_cu
->cu
->mark
)
10349 per_cu
->cu
->mark
= 1;
10351 if (per_cu
->cu
->dependencies
!= NULL
)
10352 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10358 dwarf2_mark (struct dwarf2_cu
*cu
)
10363 if (cu
->dependencies
!= NULL
)
10364 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10368 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10372 per_cu
->cu
->mark
= 0;
10373 per_cu
= per_cu
->cu
->read_in_chain
;
10377 /* Trivial hash function for partial_die_info: the hash value of a DIE
10378 is its offset in .debug_info for this objfile. */
10381 partial_die_hash (const void *item
)
10383 const struct partial_die_info
*part_die
= item
;
10384 return part_die
->offset
;
10387 /* Trivial comparison function for partial_die_info structures: two DIEs
10388 are equal if they have the same offset. */
10391 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10393 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10394 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10395 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10398 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10399 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10402 set_dwarf2_cmd (char *args
, int from_tty
)
10404 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10408 show_dwarf2_cmd (char *args
, int from_tty
)
10410 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10413 void _initialize_dwarf2_read (void);
10416 _initialize_dwarf2_read (void)
10418 dwarf2_objfile_data_key
= register_objfile_data ();
10420 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10421 Set DWARF 2 specific variables.\n\
10422 Configure DWARF 2 variables such as the cache size"),
10423 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10424 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10426 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10427 Show DWARF 2 specific variables\n\
10428 Show DWARF 2 variables such as the cache size"),
10429 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10430 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10432 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10433 &dwarf2_max_cache_age
, _("\
10434 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10435 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10436 A higher limit means that cached compilation units will be stored\n\
10437 in memory longer, and more total memory will be used. Zero disables\n\
10438 caching, which can slow down startup."),
10440 show_dwarf2_max_cache_age
,
10441 &set_dwarf2_cmdlist
,
10442 &show_dwarf2_cmdlist
);