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"
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
57 /* A note on memory usage for this file.
59 At the present time, this code reads the debug info sections into
60 the objfile's objfile_obstack. A definite improvement for startup
61 time, on platforms which do not emit relocations for debug
62 sections, would be to use mmap instead. The object's complete
63 debug information is loaded into memory, partly to simplify
64 absolute DIE references.
66 Whether using obstacks or mmap, the sections should remain loaded
67 until the objfile is released, and pointers into the section data
68 can be used for any other data associated to the objfile (symbol
69 names, type names, location expressions to name a few). */
72 /* .debug_info header for a compilation unit
73 Because of alignment constraints, this structure has padding and cannot
74 be mapped directly onto the beginning of the .debug_info section. */
75 typedef struct comp_unit_header
77 unsigned int length
; /* length of the .debug_info
79 unsigned short version
; /* version number -- 2 for DWARF
81 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
82 unsigned char addr_size
; /* byte size of an address -- 4 */
85 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
88 /* .debug_pubnames header
89 Because of alignment constraints, this structure has padding and cannot
90 be mapped directly onto the beginning of the .debug_info section. */
91 typedef struct pubnames_header
93 unsigned int length
; /* length of the .debug_pubnames
95 unsigned char version
; /* version number -- 2 for DWARF
97 unsigned int info_offset
; /* offset into .debug_info section */
98 unsigned int info_size
; /* byte size of .debug_info section
102 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
104 /* .debug_pubnames header
105 Because of alignment constraints, this structure has padding and cannot
106 be mapped directly onto the beginning of the .debug_info section. */
107 typedef struct aranges_header
109 unsigned int length
; /* byte len of the .debug_aranges
111 unsigned short version
; /* version number -- 2 for DWARF
113 unsigned int info_offset
; /* offset into .debug_info section */
114 unsigned char addr_size
; /* byte size of an address */
115 unsigned char seg_size
; /* byte size of segment descriptor */
118 #define _ACTUAL_ARANGES_HEADER_SIZE 12
120 /* .debug_line statement program prologue
121 Because of alignment constraints, this structure has padding and cannot
122 be mapped directly onto the beginning of the .debug_info section. */
123 typedef struct statement_prologue
125 unsigned int total_length
; /* byte length of the statement
127 unsigned short version
; /* version number -- 2 for DWARF
129 unsigned int prologue_length
; /* # bytes between prologue &
131 unsigned char minimum_instruction_length
; /* byte size of
133 unsigned char default_is_stmt
; /* initial value of is_stmt
136 unsigned char line_range
;
137 unsigned char opcode_base
; /* number assigned to first special
139 unsigned char *standard_opcode_lengths
;
143 static const struct objfile_data
*dwarf2_objfile_data_key
;
145 struct dwarf2_per_objfile
147 /* Sizes of debugging sections. */
148 unsigned int info_size
;
149 unsigned int abbrev_size
;
150 unsigned int line_size
;
151 unsigned int pubnames_size
;
152 unsigned int aranges_size
;
153 unsigned int loc_size
;
154 unsigned int macinfo_size
;
155 unsigned int str_size
;
156 unsigned int ranges_size
;
157 unsigned int frame_size
;
158 unsigned int eh_frame_size
;
160 /* Loaded data from the sections. */
161 gdb_byte
*info_buffer
;
162 gdb_byte
*abbrev_buffer
;
163 gdb_byte
*line_buffer
;
164 gdb_byte
*str_buffer
;
165 gdb_byte
*macinfo_buffer
;
166 gdb_byte
*ranges_buffer
;
167 gdb_byte
*loc_buffer
;
169 /* A list of all the compilation units. This is used to locate
170 the target compilation unit of a particular reference. */
171 struct dwarf2_per_cu_data
**all_comp_units
;
173 /* The number of compilation units in ALL_COMP_UNITS. */
176 /* A chain of compilation units that are currently read in, so that
177 they can be freed later. */
178 struct dwarf2_per_cu_data
*read_in_chain
;
180 /* A flag indicating wether this objfile has a section loaded at a
182 int has_section_at_zero
;
185 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
187 static asection
*dwarf_info_section
;
188 static asection
*dwarf_abbrev_section
;
189 static asection
*dwarf_line_section
;
190 static asection
*dwarf_pubnames_section
;
191 static asection
*dwarf_aranges_section
;
192 static asection
*dwarf_loc_section
;
193 static asection
*dwarf_macinfo_section
;
194 static asection
*dwarf_str_section
;
195 static asection
*dwarf_ranges_section
;
196 asection
*dwarf_frame_section
;
197 asection
*dwarf_eh_frame_section
;
199 /* names of the debugging sections */
201 /* Note that if the debugging section has been compressed, it might
202 have a name like .zdebug_info. */
204 #define INFO_SECTION "debug_info"
205 #define ABBREV_SECTION "debug_abbrev"
206 #define LINE_SECTION "debug_line"
207 #define PUBNAMES_SECTION "debug_pubnames"
208 #define ARANGES_SECTION "debug_aranges"
209 #define LOC_SECTION "debug_loc"
210 #define MACINFO_SECTION "debug_macinfo"
211 #define STR_SECTION "debug_str"
212 #define RANGES_SECTION "debug_ranges"
213 #define FRAME_SECTION "debug_frame"
214 #define EH_FRAME_SECTION "eh_frame"
216 /* local data types */
218 /* We hold several abbreviation tables in memory at the same time. */
219 #ifndef ABBREV_HASH_SIZE
220 #define ABBREV_HASH_SIZE 121
223 /* The data in a compilation unit header, after target2host
224 translation, looks like this. */
225 struct comp_unit_head
227 unsigned long length
;
229 unsigned int abbrev_offset
;
230 unsigned char addr_size
;
231 unsigned char signed_addr_p
;
233 /* Size of file offsets; either 4 or 8. */
234 unsigned int offset_size
;
236 /* Size of the length field; either 4 or 12. */
237 unsigned int initial_length_size
;
239 /* Offset to the first byte of this compilation unit header in the
240 .debug_info section, for resolving relative reference dies. */
243 /* Pointer to this compilation unit header in the .debug_info
245 gdb_byte
*cu_head_ptr
;
247 /* Pointer to the first die of this compilation unit. This will be
248 the first byte following the compilation unit header. */
249 gdb_byte
*first_die_ptr
;
251 /* Pointer to the next compilation unit header in the program. */
252 struct comp_unit_head
*next
;
254 /* Base address of this compilation unit. */
255 CORE_ADDR base_address
;
257 /* Non-zero if base_address has been set. */
261 /* Fixed size for the DIE hash table. */
262 #ifndef REF_HASH_SIZE
263 #define REF_HASH_SIZE 1021
266 /* Internal state when decoding a particular compilation unit. */
269 /* The objfile containing this compilation unit. */
270 struct objfile
*objfile
;
272 /* The header of the compilation unit.
274 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
275 should logically be moved to the dwarf2_cu structure. */
276 struct comp_unit_head header
;
278 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
280 /* The language we are debugging. */
281 enum language language
;
282 const struct language_defn
*language_defn
;
284 const char *producer
;
286 /* The generic symbol table building routines have separate lists for
287 file scope symbols and all all other scopes (local scopes). So
288 we need to select the right one to pass to add_symbol_to_list().
289 We do it by keeping a pointer to the correct list in list_in_scope.
291 FIXME: The original dwarf code just treated the file scope as the
292 first local scope, and all other local scopes as nested local
293 scopes, and worked fine. Check to see if we really need to
294 distinguish these in buildsym.c. */
295 struct pending
**list_in_scope
;
297 /* DWARF abbreviation table associated with this compilation unit. */
298 struct abbrev_info
**dwarf2_abbrevs
;
300 /* Storage for the abbrev table. */
301 struct obstack abbrev_obstack
;
303 /* Hash table holding all the loaded partial DIEs. */
306 /* Storage for things with the same lifetime as this read-in compilation
307 unit, including partial DIEs. */
308 struct obstack comp_unit_obstack
;
310 /* When multiple dwarf2_cu structures are living in memory, this field
311 chains them all together, so that they can be released efficiently.
312 We will probably also want a generation counter so that most-recently-used
313 compilation units are cached... */
314 struct dwarf2_per_cu_data
*read_in_chain
;
316 /* Backchain to our per_cu entry if the tree has been built. */
317 struct dwarf2_per_cu_data
*per_cu
;
319 /* How many compilation units ago was this CU last referenced? */
322 /* A hash table of die offsets for following references. */
323 struct die_info
*die_ref_table
[REF_HASH_SIZE
];
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;
350 /* Persistent data held for a compilation unit, even when not
351 processing it. We put a pointer to this structure in the
352 read_symtab_private field of the psymtab. If we encounter
353 inter-compilation-unit references, we also maintain a sorted
354 list of all compilation units. */
356 struct dwarf2_per_cu_data
358 /* The start offset and length of this compilation unit. 2**30-1
359 bytes should suffice to store the length of any compilation unit
360 - if it doesn't, GDB will fall over anyway. */
361 unsigned long offset
;
362 unsigned long length
: 30;
364 /* Flag indicating this compilation unit will be read in before
365 any of the current compilation units are processed. */
366 unsigned long queued
: 1;
368 /* This flag will be set if we need to load absolutely all DIEs
369 for this compilation unit, instead of just the ones we think
370 are interesting. It gets set if we look for a DIE in the
371 hash table and don't find it. */
372 unsigned int load_all_dies
: 1;
374 /* Set iff currently read in. */
375 struct dwarf2_cu
*cu
;
377 /* If full symbols for this CU have been read in, then this field
378 holds a map of DIE offsets to types. It isn't always possible
379 to reconstruct this information later, so we have to preserve
383 /* The partial symbol table associated with this compilation unit,
384 or NULL for partial units (which do not have an associated
386 struct partial_symtab
*psymtab
;
389 /* The line number information for a compilation unit (found in the
390 .debug_line section) begins with a "statement program header",
391 which contains the following information. */
394 unsigned int total_length
;
395 unsigned short version
;
396 unsigned int header_length
;
397 unsigned char minimum_instruction_length
;
398 unsigned char default_is_stmt
;
400 unsigned char line_range
;
401 unsigned char opcode_base
;
403 /* standard_opcode_lengths[i] is the number of operands for the
404 standard opcode whose value is i. This means that
405 standard_opcode_lengths[0] is unused, and the last meaningful
406 element is standard_opcode_lengths[opcode_base - 1]. */
407 unsigned char *standard_opcode_lengths
;
409 /* The include_directories table. NOTE! These strings are not
410 allocated with xmalloc; instead, they are pointers into
411 debug_line_buffer. If you try to free them, `free' will get
413 unsigned int num_include_dirs
, include_dirs_size
;
416 /* The file_names table. NOTE! These strings are not allocated
417 with xmalloc; instead, they are pointers into debug_line_buffer.
418 Don't try to free them directly. */
419 unsigned int num_file_names
, file_names_size
;
423 unsigned int dir_index
;
424 unsigned int mod_time
;
426 int included_p
; /* Non-zero if referenced by the Line Number Program. */
427 struct symtab
*symtab
; /* The associated symbol table, if any. */
430 /* The start and end of the statement program following this
431 header. These point into dwarf2_per_objfile->line_buffer. */
432 gdb_byte
*statement_program_start
, *statement_program_end
;
435 /* When we construct a partial symbol table entry we only
436 need this much information. */
437 struct partial_die_info
439 /* Offset of this DIE. */
442 /* DWARF-2 tag for this DIE. */
443 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
445 /* Language code associated with this DIE. This is only used
446 for the compilation unit DIE. */
447 unsigned int language
: 8;
449 /* Assorted flags describing the data found in this DIE. */
450 unsigned int has_children
: 1;
451 unsigned int is_external
: 1;
452 unsigned int is_declaration
: 1;
453 unsigned int has_type
: 1;
454 unsigned int has_specification
: 1;
455 unsigned int has_stmt_list
: 1;
456 unsigned int has_pc_info
: 1;
458 /* Flag set if the SCOPE field of this structure has been
460 unsigned int scope_set
: 1;
462 /* Flag set if the DIE has a byte_size attribute. */
463 unsigned int has_byte_size
: 1;
465 /* The name of this DIE. Normally the value of DW_AT_name, but
466 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
471 /* The scope to prepend to our children. This is generally
472 allocated on the comp_unit_obstack, so will disappear
473 when this compilation unit leaves the cache. */
476 /* The location description associated with this DIE, if any. */
477 struct dwarf_block
*locdesc
;
479 /* If HAS_PC_INFO, the PC range associated with this DIE. */
483 /* Pointer into the info_buffer pointing at the target of
484 DW_AT_sibling, if any. */
487 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
488 DW_AT_specification (or DW_AT_abstract_origin or
490 unsigned int spec_offset
;
492 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
493 unsigned int line_offset
;
495 /* Pointers to this DIE's parent, first child, and next sibling,
497 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
500 /* This data structure holds the information of an abbrev. */
503 unsigned int number
; /* number identifying abbrev */
504 enum dwarf_tag tag
; /* dwarf tag */
505 unsigned short has_children
; /* boolean */
506 unsigned short num_attrs
; /* number of attributes */
507 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
508 struct abbrev_info
*next
; /* next in chain */
513 enum dwarf_attribute name
;
514 enum dwarf_form form
;
517 /* This data structure holds a complete die structure. */
520 enum dwarf_tag tag
; /* Tag indicating type of die */
521 unsigned int abbrev
; /* Abbrev number */
522 unsigned int offset
; /* Offset in .debug_info section */
523 unsigned int num_attrs
; /* Number of attributes */
524 struct attribute
*attrs
; /* An array of attributes */
525 struct die_info
*next_ref
; /* Next die in ref hash table */
527 /* The dies in a compilation unit form an n-ary tree. PARENT
528 points to this die's parent; CHILD points to the first child of
529 this node; and all the children of a given node are chained
530 together via their SIBLING fields, terminated by a die whose
532 struct die_info
*child
; /* Its first child, if any. */
533 struct die_info
*sibling
; /* Its next sibling, if any. */
534 struct die_info
*parent
; /* Its parent, if any. */
536 struct type
*type
; /* Cached type information */
539 /* Attributes have a name and a value */
542 enum dwarf_attribute name
;
543 enum dwarf_form form
;
547 struct dwarf_block
*blk
;
555 struct function_range
558 CORE_ADDR lowpc
, highpc
;
560 struct function_range
*next
;
563 /* Get at parts of an attribute structure */
565 #define DW_STRING(attr) ((attr)->u.str)
566 #define DW_UNSND(attr) ((attr)->u.unsnd)
567 #define DW_BLOCK(attr) ((attr)->u.blk)
568 #define DW_SND(attr) ((attr)->u.snd)
569 #define DW_ADDR(attr) ((attr)->u.addr)
571 /* Blocks are a bunch of untyped bytes. */
578 #ifndef ATTR_ALLOC_CHUNK
579 #define ATTR_ALLOC_CHUNK 4
582 /* Allocate fields for structs, unions and enums in this size. */
583 #ifndef DW_FIELD_ALLOC_CHUNK
584 #define DW_FIELD_ALLOC_CHUNK 4
587 /* A zeroed version of a partial die for initialization purposes. */
588 static struct partial_die_info zeroed_partial_die
;
590 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
591 but this would require a corresponding change in unpack_field_as_long
593 static int bits_per_byte
= 8;
595 /* The routines that read and process dies for a C struct or C++ class
596 pass lists of data member fields and lists of member function fields
597 in an instance of a field_info structure, as defined below. */
600 /* List of data member and baseclasses fields. */
603 struct nextfield
*next
;
610 /* Number of fields. */
613 /* Number of baseclasses. */
616 /* Set if the accesibility of one of the fields is not public. */
617 int non_public_fields
;
619 /* Member function fields array, entries are allocated in the order they
620 are encountered in the object file. */
623 struct nextfnfield
*next
;
624 struct fn_field fnfield
;
628 /* Member function fieldlist array, contains name of possibly overloaded
629 member function, number of overloaded member functions and a pointer
630 to the head of the member function field chain. */
635 struct nextfnfield
*head
;
639 /* Number of entries in the fnfieldlists array. */
643 /* One item on the queue of compilation units to read in full symbols
645 struct dwarf2_queue_item
647 struct dwarf2_per_cu_data
*per_cu
;
648 struct dwarf2_queue_item
*next
;
651 /* The current queue. */
652 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
654 /* Loaded secondary compilation units are kept in memory until they
655 have not been referenced for the processing of this many
656 compilation units. Set this to zero to disable caching. Cache
657 sizes of up to at least twenty will improve startup time for
658 typical inter-CU-reference binaries, at an obvious memory cost. */
659 static int dwarf2_max_cache_age
= 5;
661 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
662 struct cmd_list_element
*c
, const char *value
)
664 fprintf_filtered (file
, _("\
665 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
670 /* Various complaints about symbol reading that don't abort the process */
673 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
675 complaint (&symfile_complaints
,
676 _("statement list doesn't fit in .debug_line section"));
680 dwarf2_debug_line_missing_file_complaint (void)
682 complaint (&symfile_complaints
,
683 _(".debug_line section has line data without a file"));
687 dwarf2_complex_location_expr_complaint (void)
689 complaint (&symfile_complaints
, _("location expression too complex"));
693 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
696 complaint (&symfile_complaints
,
697 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
702 dwarf2_macros_too_long_complaint (void)
704 complaint (&symfile_complaints
,
705 _("macro info runs off end of `.debug_macinfo' section"));
709 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
711 complaint (&symfile_complaints
,
712 _("macro debug info contains a malformed macro definition:\n`%s'"),
717 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
719 complaint (&symfile_complaints
,
720 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
723 /* local function prototypes */
725 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
728 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
731 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
734 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
735 struct partial_die_info
*,
736 struct partial_symtab
*);
738 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
740 static void scan_partial_symbols (struct partial_die_info
*,
741 CORE_ADDR
*, CORE_ADDR
*,
744 static void add_partial_symbol (struct partial_die_info
*,
747 static int pdi_needs_namespace (enum dwarf_tag tag
);
749 static void add_partial_namespace (struct partial_die_info
*pdi
,
750 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
751 struct dwarf2_cu
*cu
);
753 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
754 struct dwarf2_cu
*cu
);
756 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
759 struct dwarf2_cu
*cu
);
761 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
763 static void psymtab_to_symtab_1 (struct partial_symtab
*);
765 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
767 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
769 static void dwarf2_free_abbrev_table (void *);
771 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
774 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
777 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
780 static gdb_byte
*read_partial_die (struct partial_die_info
*,
781 struct abbrev_info
*abbrev
, unsigned int,
782 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
784 static struct partial_die_info
*find_partial_die (unsigned long,
787 static void fixup_partial_die (struct partial_die_info
*,
790 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
791 struct dwarf2_cu
*, int *);
793 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
794 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
796 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
797 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
799 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
801 static int read_1_signed_byte (bfd
*, gdb_byte
*);
803 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
805 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
807 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
809 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
812 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
813 struct comp_unit_head
*, unsigned int *);
815 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
818 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
820 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
822 static char *read_indirect_string (bfd
*, gdb_byte
*,
823 const struct comp_unit_head
*,
826 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
828 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
830 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
832 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
834 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
837 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
838 struct dwarf2_cu
*cu
);
840 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
842 static struct die_info
*die_specification (struct die_info
*die
,
845 static void free_line_header (struct line_header
*lh
);
847 static void add_file_name (struct line_header
*, char *, unsigned int,
848 unsigned int, unsigned int);
850 static struct line_header
*(dwarf_decode_line_header
851 (unsigned int offset
,
852 bfd
*abfd
, struct dwarf2_cu
*cu
));
854 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
855 struct dwarf2_cu
*, struct partial_symtab
*);
857 static void dwarf2_start_subfile (char *, char *, char *);
859 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
862 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
865 static void dwarf2_const_value_data (struct attribute
*attr
,
869 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
871 static struct type
*die_containing_type (struct die_info
*,
874 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
876 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
878 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
880 static char *typename_concat (struct obstack
*,
885 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
887 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
889 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
891 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
893 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
895 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
897 static int dwarf2_get_pc_bounds (struct die_info
*,
898 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
900 static void get_scope_pc_bounds (struct die_info
*,
901 CORE_ADDR
*, CORE_ADDR
*,
904 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
905 CORE_ADDR
, struct dwarf2_cu
*);
907 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
910 static void dwarf2_attach_fields_to_type (struct field_info
*,
911 struct type
*, struct dwarf2_cu
*);
913 static void dwarf2_add_member_fn (struct field_info
*,
914 struct die_info
*, struct type
*,
917 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
918 struct type
*, struct dwarf2_cu
*);
920 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
922 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
924 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
926 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
928 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
930 static const char *namespace_name (struct die_info
*die
,
931 int *is_anonymous
, struct dwarf2_cu
*);
933 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
935 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
937 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
939 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
941 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
944 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
946 static void read_tag_ptr_to_member_type (struct die_info
*,
949 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
951 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
953 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
955 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
957 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
959 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
961 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
963 gdb_byte
**new_info_ptr
,
964 struct die_info
*parent
);
966 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
968 gdb_byte
**new_info_ptr
,
969 struct die_info
*parent
);
971 static void free_die_list (struct die_info
*);
973 static void process_die (struct die_info
*, struct dwarf2_cu
*);
975 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
977 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
979 static struct die_info
*dwarf2_extension (struct die_info
*die
,
982 static char *dwarf_tag_name (unsigned int);
984 static char *dwarf_attr_name (unsigned int);
986 static char *dwarf_form_name (unsigned int);
988 static char *dwarf_stack_op_name (unsigned int);
990 static char *dwarf_bool_name (unsigned int);
992 static char *dwarf_type_encoding_name (unsigned int);
995 static char *dwarf_cfi_name (unsigned int);
997 struct die_info
*copy_die (struct die_info
*);
1000 static struct die_info
*sibling_die (struct die_info
*);
1002 static void dump_die (struct die_info
*);
1004 static void dump_die_list (struct die_info
*);
1006 static void store_in_ref_table (unsigned int, struct die_info
*,
1007 struct dwarf2_cu
*);
1009 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
1010 struct dwarf2_cu
*);
1012 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1014 static struct die_info
*follow_die_ref (struct die_info
*,
1016 struct dwarf2_cu
*);
1018 /* memory allocation interface */
1020 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1022 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1024 static struct die_info
*dwarf_alloc_die (void);
1026 static void initialize_cu_func_list (struct dwarf2_cu
*);
1028 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1029 struct dwarf2_cu
*);
1031 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1032 char *, bfd
*, struct dwarf2_cu
*);
1034 static int attr_form_is_block (struct attribute
*);
1036 static int attr_form_is_section_offset (struct attribute
*);
1038 static int attr_form_is_constant (struct attribute
*);
1040 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1042 struct dwarf2_cu
*cu
);
1044 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1045 struct dwarf2_cu
*cu
);
1047 static void free_stack_comp_unit (void *);
1049 static hashval_t
partial_die_hash (const void *item
);
1051 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1053 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1054 (unsigned long offset
, struct objfile
*objfile
);
1056 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1057 (unsigned long offset
, struct objfile
*objfile
);
1059 static void free_one_comp_unit (void *);
1061 static void free_cached_comp_units (void *);
1063 static void age_cached_comp_units (void);
1065 static void free_one_cached_comp_unit (void *);
1067 static void set_die_type (struct die_info
*, struct type
*,
1068 struct dwarf2_cu
*);
1070 static void reset_die_and_siblings_types (struct die_info
*,
1071 struct dwarf2_cu
*);
1073 static void create_all_comp_units (struct objfile
*);
1075 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1078 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1080 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1081 struct dwarf2_per_cu_data
*);
1083 static void dwarf2_mark (struct dwarf2_cu
*);
1085 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1087 static void read_set_type (struct die_info
*, struct dwarf2_cu
*);
1090 /* Try to locate the sections we need for DWARF 2 debugging
1091 information and return true if we have enough to do something. */
1094 dwarf2_has_info (struct objfile
*objfile
)
1096 struct dwarf2_per_objfile
*data
;
1098 /* Initialize per-objfile state. */
1099 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1100 memset (data
, 0, sizeof (*data
));
1101 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1102 dwarf2_per_objfile
= data
;
1104 dwarf_info_section
= 0;
1105 dwarf_abbrev_section
= 0;
1106 dwarf_line_section
= 0;
1107 dwarf_str_section
= 0;
1108 dwarf_macinfo_section
= 0;
1109 dwarf_frame_section
= 0;
1110 dwarf_eh_frame_section
= 0;
1111 dwarf_ranges_section
= 0;
1112 dwarf_loc_section
= 0;
1114 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1115 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1118 /* When loading sections, we can either look for ".<name>", or for
1119 * ".z<name>", which indicates a compressed section. */
1122 section_is_p (asection
*sectp
, const char *name
)
1124 return ((sectp
->name
[0] == '.'
1125 && strcmp (sectp
->name
+ 1, name
) == 0)
1126 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1127 && strcmp (sectp
->name
+ 2, name
) == 0));
1130 /* This function is mapped across the sections and remembers the
1131 offset and size of each of the debugging sections we are interested
1135 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1137 if (section_is_p (sectp
, INFO_SECTION
))
1139 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1140 dwarf_info_section
= sectp
;
1142 else if (section_is_p (sectp
, ABBREV_SECTION
))
1144 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1145 dwarf_abbrev_section
= sectp
;
1147 else if (section_is_p (sectp
, LINE_SECTION
))
1149 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1150 dwarf_line_section
= sectp
;
1152 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1154 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1155 dwarf_pubnames_section
= sectp
;
1157 else if (section_is_p (sectp
, ARANGES_SECTION
))
1159 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1160 dwarf_aranges_section
= sectp
;
1162 else if (section_is_p (sectp
, LOC_SECTION
))
1164 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1165 dwarf_loc_section
= sectp
;
1167 else if (section_is_p (sectp
, MACINFO_SECTION
))
1169 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1170 dwarf_macinfo_section
= sectp
;
1172 else if (section_is_p (sectp
, STR_SECTION
))
1174 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1175 dwarf_str_section
= sectp
;
1177 else if (section_is_p (sectp
, FRAME_SECTION
))
1179 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1180 dwarf_frame_section
= sectp
;
1182 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1184 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1185 if (aflag
& SEC_HAS_CONTENTS
)
1187 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1188 dwarf_eh_frame_section
= sectp
;
1191 else if (section_is_p (sectp
, RANGES_SECTION
))
1193 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1194 dwarf_ranges_section
= sectp
;
1197 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1198 && bfd_section_vma (abfd
, sectp
) == 0)
1199 dwarf2_per_objfile
->has_section_at_zero
= 1;
1202 /* This function is called after decompressing a section, so
1203 dwarf2_per_objfile can record its new, uncompressed size. */
1206 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1208 if (section_is_p (sectp
, INFO_SECTION
))
1209 dwarf2_per_objfile
->info_size
= new_size
;
1210 else if (section_is_p (sectp
, ABBREV_SECTION
))
1211 dwarf2_per_objfile
->abbrev_size
= new_size
;
1212 else if (section_is_p (sectp
, LINE_SECTION
))
1213 dwarf2_per_objfile
->line_size
= new_size
;
1214 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1215 dwarf2_per_objfile
->pubnames_size
= new_size
;
1216 else if (section_is_p (sectp
, ARANGES_SECTION
))
1217 dwarf2_per_objfile
->aranges_size
= new_size
;
1218 else if (section_is_p (sectp
, LOC_SECTION
))
1219 dwarf2_per_objfile
->loc_size
= new_size
;
1220 else if (section_is_p (sectp
, MACINFO_SECTION
))
1221 dwarf2_per_objfile
->macinfo_size
= new_size
;
1222 else if (section_is_p (sectp
, STR_SECTION
))
1223 dwarf2_per_objfile
->str_size
= new_size
;
1224 else if (section_is_p (sectp
, FRAME_SECTION
))
1225 dwarf2_per_objfile
->frame_size
= new_size
;
1226 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1227 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1228 else if (section_is_p (sectp
, RANGES_SECTION
))
1229 dwarf2_per_objfile
->ranges_size
= new_size
;
1231 internal_error (__FILE__
, __LINE__
,
1232 _("dwarf2_resize_section: missing section_is_p check: %s"),
1236 /* Build a partial symbol table. */
1239 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1241 /* We definitely need the .debug_info and .debug_abbrev sections */
1243 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1244 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1246 if (dwarf_line_section
)
1247 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1249 dwarf2_per_objfile
->line_buffer
= NULL
;
1251 if (dwarf_str_section
)
1252 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1254 dwarf2_per_objfile
->str_buffer
= NULL
;
1256 if (dwarf_macinfo_section
)
1257 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1258 dwarf_macinfo_section
);
1260 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1262 if (dwarf_ranges_section
)
1263 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1265 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1267 if (dwarf_loc_section
)
1268 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1270 dwarf2_per_objfile
->loc_buffer
= NULL
;
1273 || (objfile
->global_psymbols
.size
== 0
1274 && objfile
->static_psymbols
.size
== 0))
1276 init_psymbol_list (objfile
, 1024);
1280 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1282 /* Things are significantly easier if we have .debug_aranges and
1283 .debug_pubnames sections */
1285 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1289 /* only test this case for now */
1291 /* In this case we have to work a bit harder */
1292 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1297 /* Build the partial symbol table from the information in the
1298 .debug_pubnames and .debug_aranges sections. */
1301 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1303 bfd
*abfd
= objfile
->obfd
;
1304 char *aranges_buffer
, *pubnames_buffer
;
1305 char *aranges_ptr
, *pubnames_ptr
;
1306 unsigned int entry_length
, version
, info_offset
, info_size
;
1308 pubnames_buffer
= dwarf2_read_section (objfile
,
1309 dwarf_pubnames_section
);
1310 pubnames_ptr
= pubnames_buffer
;
1311 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1313 struct comp_unit_head cu_header
;
1314 unsigned int bytes_read
;
1316 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1318 pubnames_ptr
+= bytes_read
;
1319 version
= read_1_byte (abfd
, pubnames_ptr
);
1321 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1323 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1327 aranges_buffer
= dwarf2_read_section (objfile
,
1328 dwarf_aranges_section
);
1333 /* Read in the comp unit header information from the debug_info at
1337 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1338 gdb_byte
*info_ptr
, bfd
*abfd
)
1341 unsigned int bytes_read
;
1342 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1344 info_ptr
+= bytes_read
;
1345 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1347 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1349 info_ptr
+= bytes_read
;
1350 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1352 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1353 if (signed_addr
< 0)
1354 internal_error (__FILE__
, __LINE__
,
1355 _("read_comp_unit_head: dwarf from non elf file"));
1356 cu_header
->signed_addr_p
= signed_addr
;
1361 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1364 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1366 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1368 if (header
->version
!= 2 && header
->version
!= 3)
1369 error (_("Dwarf Error: wrong version in compilation unit header "
1370 "(is %d, should be %d) [in module %s]"), header
->version
,
1371 2, bfd_get_filename (abfd
));
1373 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1374 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1375 "(offset 0x%lx + 6) [in module %s]"),
1376 (long) header
->abbrev_offset
,
1377 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1378 bfd_get_filename (abfd
));
1380 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1381 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1382 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1383 "(offset 0x%lx + 0) [in module %s]"),
1384 (long) header
->length
,
1385 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1386 bfd_get_filename (abfd
));
1391 /* Allocate a new partial symtab for file named NAME and mark this new
1392 partial symtab as being an include of PST. */
1395 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1396 struct objfile
*objfile
)
1398 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1400 subpst
->section_offsets
= pst
->section_offsets
;
1401 subpst
->textlow
= 0;
1402 subpst
->texthigh
= 0;
1404 subpst
->dependencies
= (struct partial_symtab
**)
1405 obstack_alloc (&objfile
->objfile_obstack
,
1406 sizeof (struct partial_symtab
*));
1407 subpst
->dependencies
[0] = pst
;
1408 subpst
->number_of_dependencies
= 1;
1410 subpst
->globals_offset
= 0;
1411 subpst
->n_global_syms
= 0;
1412 subpst
->statics_offset
= 0;
1413 subpst
->n_static_syms
= 0;
1414 subpst
->symtab
= NULL
;
1415 subpst
->read_symtab
= pst
->read_symtab
;
1418 /* No private part is necessary for include psymtabs. This property
1419 can be used to differentiate between such include psymtabs and
1420 the regular ones. */
1421 subpst
->read_symtab_private
= NULL
;
1424 /* Read the Line Number Program data and extract the list of files
1425 included by the source file represented by PST. Build an include
1426 partial symtab for each of these included files.
1428 This procedure assumes that there *is* a Line Number Program in
1429 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1430 before calling this procedure. */
1433 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1434 struct partial_die_info
*pdi
,
1435 struct partial_symtab
*pst
)
1437 struct objfile
*objfile
= cu
->objfile
;
1438 bfd
*abfd
= objfile
->obfd
;
1439 struct line_header
*lh
;
1441 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1443 return; /* No linetable, so no includes. */
1445 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1447 free_line_header (lh
);
1451 /* Build the partial symbol table by doing a quick pass through the
1452 .debug_info and .debug_abbrev sections. */
1455 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1457 /* Instead of reading this into a big buffer, we should probably use
1458 mmap() on architectures that support it. (FIXME) */
1459 bfd
*abfd
= objfile
->obfd
;
1461 gdb_byte
*beg_of_comp_unit
;
1462 struct partial_die_info comp_unit_die
;
1463 struct partial_symtab
*pst
;
1464 struct cleanup
*back_to
;
1465 CORE_ADDR lowpc
, highpc
, baseaddr
;
1467 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1469 /* Any cached compilation units will be linked by the per-objfile
1470 read_in_chain. Make sure to free them when we're done. */
1471 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1473 create_all_comp_units (objfile
);
1475 /* Since the objects we're extracting from .debug_info vary in
1476 length, only the individual functions to extract them (like
1477 read_comp_unit_head and load_partial_die) can really know whether
1478 the buffer is large enough to hold another complete object.
1480 At the moment, they don't actually check that. If .debug_info
1481 holds just one extra byte after the last compilation unit's dies,
1482 then read_comp_unit_head will happily read off the end of the
1483 buffer. read_partial_die is similarly casual. Those functions
1486 For this loop condition, simply checking whether there's any data
1487 left at all should be sufficient. */
1488 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1489 + dwarf2_per_objfile
->info_size
))
1491 struct cleanup
*back_to_inner
;
1492 struct dwarf2_cu cu
;
1493 struct abbrev_info
*abbrev
;
1494 unsigned int bytes_read
;
1495 struct dwarf2_per_cu_data
*this_cu
;
1497 beg_of_comp_unit
= info_ptr
;
1499 memset (&cu
, 0, sizeof (cu
));
1501 obstack_init (&cu
.comp_unit_obstack
);
1503 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1505 cu
.objfile
= objfile
;
1506 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1508 /* Complete the cu_header */
1509 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1510 cu
.header
.first_die_ptr
= info_ptr
;
1511 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1513 cu
.list_in_scope
= &file_symbols
;
1515 /* Read the abbrevs for this compilation unit into a table */
1516 dwarf2_read_abbrevs (abfd
, &cu
);
1517 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1519 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1521 /* Read the compilation unit die */
1522 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1523 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1524 abfd
, info_ptr
, &cu
);
1526 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1528 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1529 + cu
.header
.initial_length_size
);
1530 do_cleanups (back_to_inner
);
1534 /* Set the language we're debugging */
1535 set_cu_language (comp_unit_die
.language
, &cu
);
1537 /* Allocate a new partial symbol table structure */
1538 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1539 comp_unit_die
.name
? comp_unit_die
.name
: "",
1540 comp_unit_die
.lowpc
,
1541 objfile
->global_psymbols
.next
,
1542 objfile
->static_psymbols
.next
);
1544 if (comp_unit_die
.dirname
)
1545 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1547 pst
->read_symtab_private
= (char *) this_cu
;
1549 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1551 /* Store the function that reads in the rest of the symbol table */
1552 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1554 /* If this compilation unit was already read in, free the
1555 cached copy in order to read it in again. This is
1556 necessary because we skipped some symbols when we first
1557 read in the compilation unit (see load_partial_dies).
1558 This problem could be avoided, but the benefit is
1560 if (this_cu
->cu
!= NULL
)
1561 free_one_cached_comp_unit (this_cu
->cu
);
1563 cu
.per_cu
= this_cu
;
1565 /* Note that this is a pointer to our stack frame, being
1566 added to a global data structure. It will be cleaned up
1567 in free_stack_comp_unit when we finish with this
1568 compilation unit. */
1571 this_cu
->psymtab
= pst
;
1573 /* Check if comp unit has_children.
1574 If so, read the rest of the partial symbols from this comp unit.
1575 If not, there's no more debug_info for this comp unit. */
1576 if (comp_unit_die
.has_children
)
1578 struct partial_die_info
*first_die
;
1580 lowpc
= ((CORE_ADDR
) -1);
1581 highpc
= ((CORE_ADDR
) 0);
1583 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1585 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1587 /* If we didn't find a lowpc, set it to highpc to avoid
1588 complaints from `maint check'. */
1589 if (lowpc
== ((CORE_ADDR
) -1))
1592 /* If the compilation unit didn't have an explicit address range,
1593 then use the information extracted from its child dies. */
1594 if (! comp_unit_die
.has_pc_info
)
1596 comp_unit_die
.lowpc
= lowpc
;
1597 comp_unit_die
.highpc
= highpc
;
1600 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1601 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1603 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1604 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1605 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1606 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1607 sort_pst_symbols (pst
);
1609 /* If there is already a psymtab or symtab for a file of this
1610 name, remove it. (If there is a symtab, more drastic things
1611 also happen.) This happens in VxWorks. */
1612 free_named_symtabs (pst
->filename
);
1614 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1615 + cu
.header
.initial_length_size
;
1617 if (comp_unit_die
.has_stmt_list
)
1619 /* Get the list of files included in the current compilation unit,
1620 and build a psymtab for each of them. */
1621 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1624 do_cleanups (back_to_inner
);
1626 do_cleanups (back_to
);
1629 /* Load the DIEs for a secondary CU into memory. */
1632 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1634 bfd
*abfd
= objfile
->obfd
;
1635 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1636 struct partial_die_info comp_unit_die
;
1637 struct dwarf2_cu
*cu
;
1638 struct abbrev_info
*abbrev
;
1639 unsigned int bytes_read
;
1640 struct cleanup
*back_to
;
1642 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1643 beg_of_comp_unit
= info_ptr
;
1645 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1646 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1648 obstack_init (&cu
->comp_unit_obstack
);
1650 cu
->objfile
= objfile
;
1651 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1653 /* Complete the cu_header. */
1654 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1655 cu
->header
.first_die_ptr
= info_ptr
;
1656 cu
->header
.cu_head_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
;
1674 /* Check if comp unit has_children.
1675 If so, read the rest of the partial symbols from this comp unit.
1676 If not, there's no more debug_info for this comp unit. */
1677 if (comp_unit_die
.has_children
)
1678 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1680 do_cleanups (back_to
);
1683 /* Create a list of all compilation units in OBJFILE. We do this only
1684 if an inter-comp-unit reference is found; presumably if there is one,
1685 there will be many, and one will occur early in the .debug_info section.
1686 So there's no point in building this list incrementally. */
1689 create_all_comp_units (struct objfile
*objfile
)
1693 struct dwarf2_per_cu_data
**all_comp_units
;
1694 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1698 all_comp_units
= xmalloc (n_allocated
1699 * sizeof (struct dwarf2_per_cu_data
*));
1701 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1703 struct comp_unit_head cu_header
;
1704 gdb_byte
*beg_of_comp_unit
;
1705 struct dwarf2_per_cu_data
*this_cu
;
1706 unsigned long offset
;
1707 unsigned int bytes_read
;
1709 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1711 /* Read just enough information to find out where the next
1712 compilation unit is. */
1713 cu_header
.initial_length_size
= 0;
1714 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1715 &cu_header
, &bytes_read
);
1717 /* Save the compilation unit for later lookup. */
1718 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1719 sizeof (struct dwarf2_per_cu_data
));
1720 memset (this_cu
, 0, sizeof (*this_cu
));
1721 this_cu
->offset
= offset
;
1722 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1724 if (n_comp_units
== n_allocated
)
1727 all_comp_units
= xrealloc (all_comp_units
,
1729 * sizeof (struct dwarf2_per_cu_data
*));
1731 all_comp_units
[n_comp_units
++] = this_cu
;
1733 info_ptr
= info_ptr
+ this_cu
->length
;
1736 dwarf2_per_objfile
->all_comp_units
1737 = obstack_alloc (&objfile
->objfile_obstack
,
1738 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1739 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1740 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1741 xfree (all_comp_units
);
1742 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1745 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1746 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1750 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1751 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1753 struct objfile
*objfile
= cu
->objfile
;
1754 bfd
*abfd
= objfile
->obfd
;
1755 struct partial_die_info
*pdi
;
1757 /* Now, march along the PDI's, descending into ones which have
1758 interesting children but skipping the children of the other ones,
1759 until we reach the end of the compilation unit. */
1765 fixup_partial_die (pdi
, cu
);
1767 /* Anonymous namespaces have no name but have interesting
1768 children, so we need to look at them. Ditto for anonymous
1771 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1772 || pdi
->tag
== DW_TAG_enumeration_type
)
1776 case DW_TAG_subprogram
:
1777 if (pdi
->has_pc_info
)
1779 if (pdi
->lowpc
< *lowpc
)
1781 *lowpc
= pdi
->lowpc
;
1783 if (pdi
->highpc
> *highpc
)
1785 *highpc
= pdi
->highpc
;
1787 if (!pdi
->is_declaration
)
1789 add_partial_symbol (pdi
, cu
);
1793 case DW_TAG_variable
:
1794 case DW_TAG_typedef
:
1795 case DW_TAG_union_type
:
1796 if (!pdi
->is_declaration
)
1798 add_partial_symbol (pdi
, cu
);
1801 case DW_TAG_class_type
:
1802 case DW_TAG_interface_type
:
1803 case DW_TAG_structure_type
:
1804 if (!pdi
->is_declaration
)
1806 add_partial_symbol (pdi
, cu
);
1809 case DW_TAG_enumeration_type
:
1810 if (!pdi
->is_declaration
)
1811 add_partial_enumeration (pdi
, cu
);
1813 case DW_TAG_base_type
:
1814 case DW_TAG_subrange_type
:
1815 /* File scope base type definitions are added to the partial
1817 add_partial_symbol (pdi
, cu
);
1819 case DW_TAG_namespace
:
1820 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1827 /* If the die has a sibling, skip to the sibling. */
1829 pdi
= pdi
->die_sibling
;
1833 /* Functions used to compute the fully scoped name of a partial DIE.
1835 Normally, this is simple. For C++, the parent DIE's fully scoped
1836 name is concatenated with "::" and the partial DIE's name. For
1837 Java, the same thing occurs except that "." is used instead of "::".
1838 Enumerators are an exception; they use the scope of their parent
1839 enumeration type, i.e. the name of the enumeration type is not
1840 prepended to the enumerator.
1842 There are two complexities. One is DW_AT_specification; in this
1843 case "parent" means the parent of the target of the specification,
1844 instead of the direct parent of the DIE. The other is compilers
1845 which do not emit DW_TAG_namespace; in this case we try to guess
1846 the fully qualified name of structure types from their members'
1847 linkage names. This must be done using the DIE's children rather
1848 than the children of any DW_AT_specification target. We only need
1849 to do this for structures at the top level, i.e. if the target of
1850 any DW_AT_specification (if any; otherwise the DIE itself) does not
1853 /* Compute the scope prefix associated with PDI's parent, in
1854 compilation unit CU. The result will be allocated on CU's
1855 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1856 field. NULL is returned if no prefix is necessary. */
1858 partial_die_parent_scope (struct partial_die_info
*pdi
,
1859 struct dwarf2_cu
*cu
)
1861 char *grandparent_scope
;
1862 struct partial_die_info
*parent
, *real_pdi
;
1864 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1865 then this means the parent of the specification DIE. */
1868 while (real_pdi
->has_specification
)
1869 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1871 parent
= real_pdi
->die_parent
;
1875 if (parent
->scope_set
)
1876 return parent
->scope
;
1878 fixup_partial_die (parent
, cu
);
1880 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1882 if (parent
->tag
== DW_TAG_namespace
1883 || parent
->tag
== DW_TAG_structure_type
1884 || parent
->tag
== DW_TAG_class_type
1885 || parent
->tag
== DW_TAG_interface_type
1886 || parent
->tag
== DW_TAG_union_type
)
1888 if (grandparent_scope
== NULL
)
1889 parent
->scope
= parent
->name
;
1891 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1894 else if (parent
->tag
== DW_TAG_enumeration_type
)
1895 /* Enumerators should not get the name of the enumeration as a prefix. */
1896 parent
->scope
= grandparent_scope
;
1899 /* FIXME drow/2004-04-01: What should we be doing with
1900 function-local names? For partial symbols, we should probably be
1902 complaint (&symfile_complaints
,
1903 _("unhandled containing DIE tag %d for DIE at %d"),
1904 parent
->tag
, pdi
->offset
);
1905 parent
->scope
= grandparent_scope
;
1908 parent
->scope_set
= 1;
1909 return parent
->scope
;
1912 /* Return the fully scoped name associated with PDI, from compilation unit
1913 CU. The result will be allocated with malloc. */
1915 partial_die_full_name (struct partial_die_info
*pdi
,
1916 struct dwarf2_cu
*cu
)
1920 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1921 if (parent_scope
== NULL
)
1924 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1928 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1930 struct objfile
*objfile
= cu
->objfile
;
1932 char *actual_name
= NULL
;
1933 const char *my_prefix
;
1934 const struct partial_symbol
*psym
= NULL
;
1936 int built_actual_name
= 0;
1938 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1940 if (pdi_needs_namespace (pdi
->tag
))
1942 actual_name
= partial_die_full_name (pdi
, cu
);
1944 built_actual_name
= 1;
1947 if (actual_name
== NULL
)
1948 actual_name
= pdi
->name
;
1952 case DW_TAG_subprogram
:
1953 if (pdi
->is_external
|| cu
->language
== language_ada
)
1955 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1956 of the global scope. But in Ada, we want to be able to access
1957 nested procedures globally. So all Ada subprograms are stored
1958 in the global scope. */
1959 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1960 mst_text, objfile); */
1961 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1962 VAR_DOMAIN
, LOC_BLOCK
,
1963 &objfile
->global_psymbols
,
1964 0, pdi
->lowpc
+ baseaddr
,
1965 cu
->language
, objfile
);
1969 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1970 mst_file_text, objfile); */
1971 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1972 VAR_DOMAIN
, LOC_BLOCK
,
1973 &objfile
->static_psymbols
,
1974 0, pdi
->lowpc
+ baseaddr
,
1975 cu
->language
, objfile
);
1978 case DW_TAG_variable
:
1979 if (pdi
->is_external
)
1982 Don't enter into the minimal symbol tables as there is
1983 a minimal symbol table entry from the ELF symbols already.
1984 Enter into partial symbol table if it has a location
1985 descriptor or a type.
1986 If the location descriptor is missing, new_symbol will create
1987 a LOC_UNRESOLVED symbol, the address of the variable will then
1988 be determined from the minimal symbol table whenever the variable
1990 The address for the partial symbol table entry is not
1991 used by GDB, but it comes in handy for debugging partial symbol
1995 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1996 if (pdi
->locdesc
|| pdi
->has_type
)
1997 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1998 VAR_DOMAIN
, LOC_STATIC
,
1999 &objfile
->global_psymbols
,
2001 cu
->language
, objfile
);
2005 /* Static Variable. Skip symbols without location descriptors. */
2006 if (pdi
->locdesc
== NULL
)
2008 if (built_actual_name
)
2009 xfree (actual_name
);
2012 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2013 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2014 mst_file_data, objfile); */
2015 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2016 VAR_DOMAIN
, LOC_STATIC
,
2017 &objfile
->static_psymbols
,
2019 cu
->language
, objfile
);
2022 case DW_TAG_typedef
:
2023 case DW_TAG_base_type
:
2024 case DW_TAG_subrange_type
:
2025 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2026 VAR_DOMAIN
, LOC_TYPEDEF
,
2027 &objfile
->static_psymbols
,
2028 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2030 case DW_TAG_namespace
:
2031 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2032 VAR_DOMAIN
, LOC_TYPEDEF
,
2033 &objfile
->global_psymbols
,
2034 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2036 case DW_TAG_class_type
:
2037 case DW_TAG_interface_type
:
2038 case DW_TAG_structure_type
:
2039 case DW_TAG_union_type
:
2040 case DW_TAG_enumeration_type
:
2041 /* Skip external references. The DWARF standard says in the section
2042 about "Structure, Union, and Class Type Entries": "An incomplete
2043 structure, union or class type is represented by a structure,
2044 union or class entry that does not have a byte size attribute
2045 and that has a DW_AT_declaration attribute." */
2046 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2048 if (built_actual_name
)
2049 xfree (actual_name
);
2053 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2054 static vs. global. */
2055 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2056 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2057 (cu
->language
== language_cplus
2058 || cu
->language
== language_java
)
2059 ? &objfile
->global_psymbols
2060 : &objfile
->static_psymbols
,
2061 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2063 if (cu
->language
== language_cplus
2064 || cu
->language
== language_java
2065 || cu
->language
== language_ada
)
2067 /* For C++ and Java, these implicitly act as typedefs as well. */
2068 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2069 VAR_DOMAIN
, LOC_TYPEDEF
,
2070 &objfile
->global_psymbols
,
2071 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2074 case DW_TAG_enumerator
:
2075 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2076 VAR_DOMAIN
, LOC_CONST
,
2077 (cu
->language
== language_cplus
2078 || cu
->language
== language_java
)
2079 ? &objfile
->global_psymbols
2080 : &objfile
->static_psymbols
,
2081 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2087 /* Check to see if we should scan the name for possible namespace
2088 info. Only do this if this is C++, if we don't have namespace
2089 debugging info in the file, if the psym is of an appropriate type
2090 (otherwise we'll have psym == NULL), and if we actually had a
2091 mangled name to begin with. */
2093 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2094 cases which do not set PSYM above? */
2096 if (cu
->language
== language_cplus
2097 && cu
->has_namespace_info
== 0
2099 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2100 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2103 if (built_actual_name
)
2104 xfree (actual_name
);
2107 /* Determine whether a die of type TAG living in a C++ class or
2108 namespace needs to have the name of the scope prepended to the
2109 name listed in the die. */
2112 pdi_needs_namespace (enum dwarf_tag tag
)
2116 case DW_TAG_namespace
:
2117 case DW_TAG_typedef
:
2118 case DW_TAG_class_type
:
2119 case DW_TAG_interface_type
:
2120 case DW_TAG_structure_type
:
2121 case DW_TAG_union_type
:
2122 case DW_TAG_enumeration_type
:
2123 case DW_TAG_enumerator
:
2130 /* Read a partial die corresponding to a namespace; also, add a symbol
2131 corresponding to that namespace to the symbol table. NAMESPACE is
2132 the name of the enclosing namespace. */
2135 add_partial_namespace (struct partial_die_info
*pdi
,
2136 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2137 struct dwarf2_cu
*cu
)
2139 struct objfile
*objfile
= cu
->objfile
;
2141 /* Add a symbol for the namespace. */
2143 add_partial_symbol (pdi
, cu
);
2145 /* Now scan partial symbols in that namespace. */
2147 if (pdi
->has_children
)
2148 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2151 /* See if we can figure out if the class lives in a namespace. We do
2152 this by looking for a member function; its demangled name will
2153 contain namespace info, if there is any. */
2156 guess_structure_name (struct partial_die_info
*struct_pdi
,
2157 struct dwarf2_cu
*cu
)
2159 if ((cu
->language
== language_cplus
2160 || cu
->language
== language_java
)
2161 && cu
->has_namespace_info
== 0
2162 && struct_pdi
->has_children
)
2164 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2165 what template types look like, because the demangler
2166 frequently doesn't give the same name as the debug info. We
2167 could fix this by only using the demangled name to get the
2168 prefix (but see comment in read_structure_type). */
2170 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2171 struct partial_die_info
*real_pdi
;
2173 /* If this DIE (this DIE's specification, if any) has a parent, then
2174 we should not do this. We'll prepend the parent's fully qualified
2175 name when we create the partial symbol. */
2177 real_pdi
= struct_pdi
;
2178 while (real_pdi
->has_specification
)
2179 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2181 if (real_pdi
->die_parent
!= NULL
)
2184 while (child_pdi
!= NULL
)
2186 if (child_pdi
->tag
== DW_TAG_subprogram
)
2188 char *actual_class_name
2189 = language_class_name_from_physname (cu
->language_defn
,
2191 if (actual_class_name
!= NULL
)
2194 = obsavestring (actual_class_name
,
2195 strlen (actual_class_name
),
2196 &cu
->comp_unit_obstack
);
2197 xfree (actual_class_name
);
2202 child_pdi
= child_pdi
->die_sibling
;
2207 /* Read a partial die corresponding to an enumeration type. */
2210 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2211 struct dwarf2_cu
*cu
)
2213 struct objfile
*objfile
= cu
->objfile
;
2214 bfd
*abfd
= objfile
->obfd
;
2215 struct partial_die_info
*pdi
;
2217 if (enum_pdi
->name
!= NULL
)
2218 add_partial_symbol (enum_pdi
, cu
);
2220 pdi
= enum_pdi
->die_child
;
2223 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2224 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2226 add_partial_symbol (pdi
, cu
);
2227 pdi
= pdi
->die_sibling
;
2231 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2232 Return the corresponding abbrev, or NULL if the number is zero (indicating
2233 an empty DIE). In either case *BYTES_READ will be set to the length of
2234 the initial number. */
2236 static struct abbrev_info
*
2237 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2238 struct dwarf2_cu
*cu
)
2240 bfd
*abfd
= cu
->objfile
->obfd
;
2241 unsigned int abbrev_number
;
2242 struct abbrev_info
*abbrev
;
2244 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2246 if (abbrev_number
== 0)
2249 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2252 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2253 bfd_get_filename (abfd
));
2259 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2260 pointer to the end of a series of DIEs, terminated by an empty
2261 DIE. Any children of the skipped DIEs will also be skipped. */
2264 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2266 struct abbrev_info
*abbrev
;
2267 unsigned int bytes_read
;
2271 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2273 return info_ptr
+ bytes_read
;
2275 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2279 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2280 should point just after the initial uleb128 of a DIE, and the
2281 abbrev corresponding to that skipped uleb128 should be passed in
2282 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2286 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2287 struct dwarf2_cu
*cu
)
2289 unsigned int bytes_read
;
2290 struct attribute attr
;
2291 bfd
*abfd
= cu
->objfile
->obfd
;
2292 unsigned int form
, i
;
2294 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2296 /* The only abbrev we care about is DW_AT_sibling. */
2297 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2299 read_attribute (&attr
, &abbrev
->attrs
[i
],
2300 abfd
, info_ptr
, cu
);
2301 if (attr
.form
== DW_FORM_ref_addr
)
2302 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2304 return dwarf2_per_objfile
->info_buffer
2305 + dwarf2_get_ref_die_offset (&attr
, cu
);
2308 /* If it isn't DW_AT_sibling, skip this attribute. */
2309 form
= abbrev
->attrs
[i
].form
;
2314 case DW_FORM_ref_addr
:
2315 info_ptr
+= cu
->header
.addr_size
;
2334 case DW_FORM_string
:
2335 read_string (abfd
, info_ptr
, &bytes_read
);
2336 info_ptr
+= bytes_read
;
2339 info_ptr
+= cu
->header
.offset_size
;
2342 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2343 info_ptr
+= bytes_read
;
2345 case DW_FORM_block1
:
2346 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2348 case DW_FORM_block2
:
2349 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2351 case DW_FORM_block4
:
2352 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2356 case DW_FORM_ref_udata
:
2357 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2359 case DW_FORM_indirect
:
2360 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2361 info_ptr
+= bytes_read
;
2362 /* We need to continue parsing from here, so just go back to
2364 goto skip_attribute
;
2367 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2368 dwarf_form_name (form
),
2369 bfd_get_filename (abfd
));
2373 if (abbrev
->has_children
)
2374 return skip_children (info_ptr
, cu
);
2379 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2380 the next DIE after ORIG_PDI. */
2383 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2384 bfd
*abfd
, struct dwarf2_cu
*cu
)
2386 /* Do we know the sibling already? */
2388 if (orig_pdi
->sibling
)
2389 return orig_pdi
->sibling
;
2391 /* Are there any children to deal with? */
2393 if (!orig_pdi
->has_children
)
2396 /* Skip the children the long way. */
2398 return skip_children (info_ptr
, cu
);
2401 /* Expand this partial symbol table into a full symbol table. */
2404 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2406 /* FIXME: This is barely more than a stub. */
2411 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2417 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2418 gdb_flush (gdb_stdout
);
2421 /* Restore our global data. */
2422 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2423 dwarf2_objfile_data_key
);
2425 psymtab_to_symtab_1 (pst
);
2427 /* Finish up the debug error message. */
2429 printf_filtered (_("done.\n"));
2434 /* Add PER_CU to the queue. */
2437 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2439 struct dwarf2_queue_item
*item
;
2442 item
= xmalloc (sizeof (*item
));
2443 item
->per_cu
= per_cu
;
2446 if (dwarf2_queue
== NULL
)
2447 dwarf2_queue
= item
;
2449 dwarf2_queue_tail
->next
= item
;
2451 dwarf2_queue_tail
= item
;
2454 /* Process the queue. */
2457 process_queue (struct objfile
*objfile
)
2459 struct dwarf2_queue_item
*item
, *next_item
;
2461 /* Initially, there is just one item on the queue. Load its DIEs,
2462 and the DIEs of any other compilation units it requires,
2465 for (item
= dwarf2_queue
; item
!= NULL
; item
= item
->next
)
2467 /* Read in this compilation unit. This may add new items to
2468 the end of the queue. */
2469 load_full_comp_unit (item
->per_cu
, objfile
);
2471 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2472 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2474 /* If this compilation unit has already had full symbols created,
2475 reset the TYPE fields in each DIE. */
2476 if (item
->per_cu
->type_hash
)
2477 reset_die_and_siblings_types (item
->per_cu
->cu
->dies
,
2481 /* Now everything left on the queue needs to be read in. Process
2482 them, one at a time, removing from the queue as we finish. */
2483 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2485 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2486 process_full_comp_unit (item
->per_cu
);
2488 item
->per_cu
->queued
= 0;
2489 next_item
= item
->next
;
2493 dwarf2_queue_tail
= NULL
;
2496 /* Free all allocated queue entries. This function only releases anything if
2497 an error was thrown; if the queue was processed then it would have been
2498 freed as we went along. */
2501 dwarf2_release_queue (void *dummy
)
2503 struct dwarf2_queue_item
*item
, *last
;
2505 item
= dwarf2_queue
;
2508 /* Anything still marked queued is likely to be in an
2509 inconsistent state, so discard it. */
2510 if (item
->per_cu
->queued
)
2512 if (item
->per_cu
->cu
!= NULL
)
2513 free_one_cached_comp_unit (item
->per_cu
->cu
);
2514 item
->per_cu
->queued
= 0;
2522 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2525 /* Read in full symbols for PST, and anything it depends on. */
2528 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2530 struct dwarf2_per_cu_data
*per_cu
;
2531 struct cleanup
*back_to
;
2534 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2535 if (!pst
->dependencies
[i
]->readin
)
2537 /* Inform about additional files that need to be read in. */
2540 /* FIXME: i18n: Need to make this a single string. */
2541 fputs_filtered (" ", gdb_stdout
);
2543 fputs_filtered ("and ", gdb_stdout
);
2545 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2546 wrap_here (""); /* Flush output */
2547 gdb_flush (gdb_stdout
);
2549 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2552 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2556 /* It's an include file, no symbols to read for it.
2557 Everything is in the parent symtab. */
2562 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2564 queue_comp_unit (per_cu
);
2566 process_queue (pst
->objfile
);
2568 /* Age the cache, releasing compilation units that have not
2569 been used recently. */
2570 age_cached_comp_units ();
2572 do_cleanups (back_to
);
2575 /* Load the DIEs associated with PST and PER_CU into memory. */
2577 static struct dwarf2_cu
*
2578 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2580 bfd
*abfd
= objfile
->obfd
;
2581 struct dwarf2_cu
*cu
;
2582 unsigned long offset
;
2584 struct cleanup
*back_to
, *free_cu_cleanup
;
2585 struct attribute
*attr
;
2588 /* Set local variables from the partial symbol table info. */
2589 offset
= per_cu
->offset
;
2591 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2593 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2594 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2596 /* If an error occurs while loading, release our storage. */
2597 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2599 cu
->objfile
= objfile
;
2601 /* read in the comp_unit header */
2602 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2604 /* Read the abbrevs for this compilation unit */
2605 dwarf2_read_abbrevs (abfd
, cu
);
2606 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2608 cu
->header
.offset
= offset
;
2610 cu
->per_cu
= per_cu
;
2613 /* We use this obstack for block values in dwarf_alloc_block. */
2614 obstack_init (&cu
->comp_unit_obstack
);
2616 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2618 /* We try not to read any attributes in this function, because not
2619 all objfiles needed for references have been loaded yet, and symbol
2620 table processing isn't initialized. But we have to set the CU language,
2621 or we won't be able to build types correctly. */
2622 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2624 set_cu_language (DW_UNSND (attr
), cu
);
2626 set_cu_language (language_minimal
, cu
);
2628 do_cleanups (back_to
);
2630 /* We've successfully allocated this compilation unit. Let our caller
2631 clean it up when finished with it. */
2632 discard_cleanups (free_cu_cleanup
);
2637 /* Generate full symbol information for PST and CU, whose DIEs have
2638 already been loaded into memory. */
2641 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2643 struct partial_symtab
*pst
= per_cu
->psymtab
;
2644 struct dwarf2_cu
*cu
= per_cu
->cu
;
2645 struct objfile
*objfile
= pst
->objfile
;
2646 bfd
*abfd
= objfile
->obfd
;
2647 CORE_ADDR lowpc
, highpc
;
2648 struct symtab
*symtab
;
2649 struct cleanup
*back_to
;
2650 struct attribute
*attr
;
2653 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2655 /* We're in the global namespace. */
2656 processing_current_prefix
= "";
2659 back_to
= make_cleanup (really_free_pendings
, NULL
);
2661 cu
->list_in_scope
= &file_symbols
;
2663 /* Find the base address of the compilation unit for range lists and
2664 location lists. It will normally be specified by DW_AT_low_pc.
2665 In DWARF-3 draft 4, the base address could be overridden by
2666 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2667 compilation units with discontinuous ranges. */
2669 cu
->header
.base_known
= 0;
2670 cu
->header
.base_address
= 0;
2672 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2675 cu
->header
.base_address
= DW_ADDR (attr
);
2676 cu
->header
.base_known
= 1;
2680 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2683 cu
->header
.base_address
= DW_ADDR (attr
);
2684 cu
->header
.base_known
= 1;
2688 /* Do line number decoding in read_file_scope () */
2689 process_die (cu
->dies
, cu
);
2691 /* Some compilers don't define a DW_AT_high_pc attribute for the
2692 compilation unit. If the DW_AT_high_pc is missing, synthesize
2693 it, by scanning the DIE's below the compilation unit. */
2694 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2696 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2698 /* Set symtab language to language from DW_AT_language.
2699 If the compilation is from a C file generated by language preprocessors,
2700 do not set the language if it was already deduced by start_subfile. */
2702 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2704 symtab
->language
= cu
->language
;
2706 pst
->symtab
= symtab
;
2709 do_cleanups (back_to
);
2712 /* Process a die and its children. */
2715 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2719 case DW_TAG_padding
:
2721 case DW_TAG_compile_unit
:
2722 read_file_scope (die
, cu
);
2724 case DW_TAG_subprogram
:
2725 read_subroutine_type (die
, cu
);
2726 read_func_scope (die
, cu
);
2728 case DW_TAG_inlined_subroutine
:
2729 /* FIXME: These are ignored for now.
2730 They could be used to set breakpoints on all inlined instances
2731 of a function and make GDB `next' properly over inlined functions. */
2733 case DW_TAG_lexical_block
:
2734 case DW_TAG_try_block
:
2735 case DW_TAG_catch_block
:
2736 read_lexical_block_scope (die
, cu
);
2738 case DW_TAG_class_type
:
2739 case DW_TAG_interface_type
:
2740 case DW_TAG_structure_type
:
2741 case DW_TAG_union_type
:
2742 read_structure_type (die
, cu
);
2743 process_structure_scope (die
, cu
);
2745 case DW_TAG_enumeration_type
:
2746 read_enumeration_type (die
, cu
);
2747 process_enumeration_scope (die
, cu
);
2750 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2751 a symbol or process any children. Therefore it doesn't do anything
2752 that won't be done on-demand by read_type_die. */
2753 case DW_TAG_subroutine_type
:
2754 read_subroutine_type (die
, cu
);
2756 case DW_TAG_set_type
:
2757 read_set_type (die
, cu
);
2759 case DW_TAG_array_type
:
2760 read_array_type (die
, cu
);
2762 case DW_TAG_pointer_type
:
2763 read_tag_pointer_type (die
, cu
);
2765 case DW_TAG_ptr_to_member_type
:
2766 read_tag_ptr_to_member_type (die
, cu
);
2768 case DW_TAG_reference_type
:
2769 read_tag_reference_type (die
, cu
);
2771 case DW_TAG_string_type
:
2772 read_tag_string_type (die
, cu
);
2776 case DW_TAG_base_type
:
2777 read_base_type (die
, cu
);
2778 /* Add a typedef symbol for the type definition, if it has a
2780 new_symbol (die
, die
->type
, cu
);
2782 case DW_TAG_subrange_type
:
2783 read_subrange_type (die
, cu
);
2784 /* Add a typedef symbol for the type definition, if it has a
2786 new_symbol (die
, die
->type
, cu
);
2788 case DW_TAG_common_block
:
2789 read_common_block (die
, cu
);
2791 case DW_TAG_common_inclusion
:
2793 case DW_TAG_namespace
:
2794 processing_has_namespace_info
= 1;
2795 read_namespace (die
, cu
);
2797 case DW_TAG_imported_declaration
:
2798 case DW_TAG_imported_module
:
2799 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2800 information contained in these. DW_TAG_imported_declaration
2801 dies shouldn't have children; DW_TAG_imported_module dies
2802 shouldn't in the C++ case, but conceivably could in the
2803 Fortran case, so we'll have to replace this gdb_assert if
2804 Fortran compilers start generating that info. */
2805 processing_has_namespace_info
= 1;
2806 gdb_assert (die
->child
== NULL
);
2809 new_symbol (die
, NULL
, cu
);
2815 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2817 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2821 free_cu_line_header (void *arg
)
2823 struct dwarf2_cu
*cu
= arg
;
2825 free_line_header (cu
->line_header
);
2826 cu
->line_header
= NULL
;
2830 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2832 struct objfile
*objfile
= cu
->objfile
;
2833 struct comp_unit_head
*cu_header
= &cu
->header
;
2834 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2835 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2836 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2837 struct attribute
*attr
;
2839 char *comp_dir
= NULL
;
2840 struct die_info
*child_die
;
2841 bfd
*abfd
= objfile
->obfd
;
2842 struct line_header
*line_header
= 0;
2845 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2847 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2849 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2850 from finish_block. */
2851 if (lowpc
== ((CORE_ADDR
) -1))
2856 /* Find the filename. Do not use dwarf2_name here, since the filename
2857 is not a source language identifier. */
2858 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2861 name
= DW_STRING (attr
);
2864 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2866 comp_dir
= DW_STRING (attr
);
2867 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2869 comp_dir
= ldirname (name
);
2870 if (comp_dir
!= NULL
)
2871 make_cleanup (xfree
, comp_dir
);
2873 if (comp_dir
!= NULL
)
2875 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2876 directory, get rid of it. */
2877 char *cp
= strchr (comp_dir
, ':');
2879 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2886 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2889 set_cu_language (DW_UNSND (attr
), cu
);
2892 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2894 cu
->producer
= DW_STRING (attr
);
2896 /* We assume that we're processing GCC output. */
2897 processing_gcc_compilation
= 2;
2899 start_symtab (name
, comp_dir
, lowpc
);
2900 record_debugformat ("DWARF 2");
2901 record_producer (cu
->producer
);
2903 initialize_cu_func_list (cu
);
2905 /* Decode line number information if present. We do this before
2906 processing child DIEs, so that the line header table is available
2907 for DW_AT_decl_file. */
2908 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2911 unsigned int line_offset
= DW_UNSND (attr
);
2912 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2915 cu
->line_header
= line_header
;
2916 make_cleanup (free_cu_line_header
, cu
);
2917 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2921 /* Process all dies in compilation unit. */
2922 if (die
->child
!= NULL
)
2924 child_die
= die
->child
;
2925 while (child_die
&& child_die
->tag
)
2927 process_die (child_die
, cu
);
2928 child_die
= sibling_die (child_die
);
2932 /* Decode macro information, if present. Dwarf 2 macro information
2933 refers to information in the line number info statement program
2934 header, so we can only read it if we've read the header
2936 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2937 if (attr
&& line_header
)
2939 unsigned int macro_offset
= DW_UNSND (attr
);
2940 dwarf_decode_macros (line_header
, macro_offset
,
2941 comp_dir
, abfd
, cu
);
2943 do_cleanups (back_to
);
2947 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2948 struct dwarf2_cu
*cu
)
2950 struct function_range
*thisfn
;
2952 thisfn
= (struct function_range
*)
2953 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2954 thisfn
->name
= name
;
2955 thisfn
->lowpc
= lowpc
;
2956 thisfn
->highpc
= highpc
;
2957 thisfn
->seen_line
= 0;
2958 thisfn
->next
= NULL
;
2960 if (cu
->last_fn
== NULL
)
2961 cu
->first_fn
= thisfn
;
2963 cu
->last_fn
->next
= thisfn
;
2965 cu
->last_fn
= thisfn
;
2969 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2971 struct objfile
*objfile
= cu
->objfile
;
2972 struct context_stack
*new;
2975 struct die_info
*child_die
;
2976 struct attribute
*attr
;
2978 const char *previous_prefix
= processing_current_prefix
;
2979 struct cleanup
*back_to
= NULL
;
2981 struct block
*block
;
2983 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2985 name
= dwarf2_linkage_name (die
, cu
);
2987 /* Ignore functions with missing or empty names and functions with
2988 missing or invalid low and high pc attributes. */
2989 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2992 if (cu
->language
== language_cplus
2993 || cu
->language
== language_java
)
2995 struct die_info
*spec_die
= die_specification (die
, cu
);
2997 /* NOTE: carlton/2004-01-23: We have to be careful in the
2998 presence of DW_AT_specification. For example, with GCC 3.4,
3003 // Definition of N::foo.
3007 then we'll have a tree of DIEs like this:
3009 1: DW_TAG_compile_unit
3010 2: DW_TAG_namespace // N
3011 3: DW_TAG_subprogram // declaration of N::foo
3012 4: DW_TAG_subprogram // definition of N::foo
3013 DW_AT_specification // refers to die #3
3015 Thus, when processing die #4, we have to pretend that we're
3016 in the context of its DW_AT_specification, namely the contex
3019 if (spec_die
!= NULL
)
3021 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3022 processing_current_prefix
= specification_prefix
;
3023 back_to
= make_cleanup (xfree
, specification_prefix
);
3030 /* Record the function range for dwarf_decode_lines. */
3031 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3033 new = push_context (0, lowpc
);
3034 new->name
= new_symbol (die
, die
->type
, cu
);
3036 /* If there is a location expression for DW_AT_frame_base, record
3038 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3040 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3041 expression is being recorded directly in the function's symbol
3042 and not in a separate frame-base object. I guess this hack is
3043 to avoid adding some sort of frame-base adjunct/annex to the
3044 function's symbol :-(. The problem with doing this is that it
3045 results in a function symbol with a location expression that
3046 has nothing to do with the location of the function, ouch! The
3047 relationship should be: a function's symbol has-a frame base; a
3048 frame-base has-a location expression. */
3049 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3051 cu
->list_in_scope
= &local_symbols
;
3053 if (die
->child
!= NULL
)
3055 child_die
= die
->child
;
3056 while (child_die
&& child_die
->tag
)
3058 process_die (child_die
, cu
);
3059 child_die
= sibling_die (child_die
);
3063 new = pop_context ();
3064 /* Make a block for the local symbols within. */
3065 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3066 lowpc
, highpc
, objfile
);
3068 /* If we have address ranges, record them. */
3069 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3071 /* In C++, we can have functions nested inside functions (e.g., when
3072 a function declares a class that has methods). This means that
3073 when we finish processing a function scope, we may need to go
3074 back to building a containing block's symbol lists. */
3075 local_symbols
= new->locals
;
3076 param_symbols
= new->params
;
3078 /* If we've finished processing a top-level function, subsequent
3079 symbols go in the file symbol list. */
3080 if (outermost_context_p ())
3081 cu
->list_in_scope
= &file_symbols
;
3083 processing_current_prefix
= previous_prefix
;
3084 if (back_to
!= NULL
)
3085 do_cleanups (back_to
);
3088 /* Process all the DIES contained within a lexical block scope. Start
3089 a new scope, process the dies, and then close the scope. */
3092 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3094 struct objfile
*objfile
= cu
->objfile
;
3095 struct context_stack
*new;
3096 CORE_ADDR lowpc
, highpc
;
3097 struct die_info
*child_die
;
3100 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3102 /* Ignore blocks with missing or invalid low and high pc attributes. */
3103 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3104 as multiple lexical blocks? Handling children in a sane way would
3105 be nasty. Might be easier to properly extend generic blocks to
3107 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3112 push_context (0, lowpc
);
3113 if (die
->child
!= NULL
)
3115 child_die
= die
->child
;
3116 while (child_die
&& child_die
->tag
)
3118 process_die (child_die
, cu
);
3119 child_die
= sibling_die (child_die
);
3122 new = pop_context ();
3124 if (local_symbols
!= NULL
)
3127 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3130 /* Note that recording ranges after traversing children, as we
3131 do here, means that recording a parent's ranges entails
3132 walking across all its children's ranges as they appear in
3133 the address map, which is quadratic behavior.
3135 It would be nicer to record the parent's ranges before
3136 traversing its children, simply overriding whatever you find
3137 there. But since we don't even decide whether to create a
3138 block until after we've traversed its children, that's hard
3140 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3142 local_symbols
= new->locals
;
3145 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3146 Return 1 if the attributes are present and valid, otherwise, return 0. */
3149 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3150 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
)
3152 struct objfile
*objfile
= cu
->objfile
;
3153 struct comp_unit_head
*cu_header
= &cu
->header
;
3154 bfd
*obfd
= objfile
->obfd
;
3155 unsigned int addr_size
= cu_header
->addr_size
;
3156 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3157 /* Base address selection entry. */
3167 found_base
= cu_header
->base_known
;
3168 base
= cu_header
->base_address
;
3170 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3172 complaint (&symfile_complaints
,
3173 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3177 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3179 /* Read in the largest possible address. */
3180 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3181 if ((marker
& mask
) == mask
)
3183 /* If we found the largest possible address, then
3184 read the base address. */
3185 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3186 buffer
+= 2 * addr_size
;
3187 offset
+= 2 * addr_size
;
3195 CORE_ADDR range_beginning
, range_end
;
3197 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3198 buffer
+= addr_size
;
3199 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3200 buffer
+= addr_size
;
3201 offset
+= 2 * addr_size
;
3203 /* An end of list marker is a pair of zero addresses. */
3204 if (range_beginning
== 0 && range_end
== 0)
3205 /* Found the end of list entry. */
3208 /* Each base address selection entry is a pair of 2 values.
3209 The first is the largest possible address, the second is
3210 the base address. Check for a base address here. */
3211 if ((range_beginning
& mask
) == mask
)
3213 /* If we found the largest possible address, then
3214 read the base address. */
3215 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3222 /* We have no valid base address for the ranges
3224 complaint (&symfile_complaints
,
3225 _("Invalid .debug_ranges data (no base address)"));
3229 range_beginning
+= base
;
3232 /* FIXME: This is recording everything as a low-high
3233 segment of consecutive addresses. We should have a
3234 data structure for discontiguous block ranges
3238 low
= range_beginning
;
3244 if (range_beginning
< low
)
3245 low
= range_beginning
;
3246 if (range_end
> high
)
3252 /* If the first entry is an end-of-list marker, the range
3253 describes an empty scope, i.e. no instructions. */
3259 *high_return
= high
;
3263 /* Get low and high pc attributes from a die. Return 1 if the attributes
3264 are present and valid, otherwise, return 0. Return -1 if the range is
3265 discontinuous, i.e. derived from DW_AT_ranges information. */
3267 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3268 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3270 struct attribute
*attr
;
3275 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3278 high
= DW_ADDR (attr
);
3279 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3281 low
= DW_ADDR (attr
);
3283 /* Found high w/o low attribute. */
3286 /* Found consecutive range of addresses. */
3291 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3294 /* Value of the DW_AT_ranges attribute is the offset in the
3295 .debug_ranges section. */
3296 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
))
3298 /* Found discontinuous range of addresses. */
3306 /* When using the GNU linker, .gnu.linkonce. sections are used to
3307 eliminate duplicate copies of functions and vtables and such.
3308 The linker will arbitrarily choose one and discard the others.
3309 The AT_*_pc values for such functions refer to local labels in
3310 these sections. If the section from that file was discarded, the
3311 labels are not in the output, so the relocs get a value of 0.
3312 If this is a discarded function, mark the pc bounds as invalid,
3313 so that GDB will ignore it. */
3314 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3322 /* Get the low and high pc's represented by the scope DIE, and store
3323 them in *LOWPC and *HIGHPC. If the correct values can't be
3324 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3327 get_scope_pc_bounds (struct die_info
*die
,
3328 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3329 struct dwarf2_cu
*cu
)
3331 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3332 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3333 CORE_ADDR current_low
, current_high
;
3335 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3337 best_low
= current_low
;
3338 best_high
= current_high
;
3342 struct die_info
*child
= die
->child
;
3344 while (child
&& child
->tag
)
3346 switch (child
->tag
) {
3347 case DW_TAG_subprogram
:
3348 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3350 best_low
= min (best_low
, current_low
);
3351 best_high
= max (best_high
, current_high
);
3354 case DW_TAG_namespace
:
3355 /* FIXME: carlton/2004-01-16: Should we do this for
3356 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3357 that current GCC's always emit the DIEs corresponding
3358 to definitions of methods of classes as children of a
3359 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3360 the DIEs giving the declarations, which could be
3361 anywhere). But I don't see any reason why the
3362 standards says that they have to be there. */
3363 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3365 if (current_low
!= ((CORE_ADDR
) -1))
3367 best_low
= min (best_low
, current_low
);
3368 best_high
= max (best_high
, current_high
);
3376 child
= sibling_die (child
);
3381 *highpc
= best_high
;
3384 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3387 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3388 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3390 struct attribute
*attr
;
3392 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3395 CORE_ADDR high
= DW_ADDR (attr
);
3396 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3399 CORE_ADDR low
= DW_ADDR (attr
);
3400 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3404 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3407 bfd
*obfd
= cu
->objfile
->obfd
;
3409 /* The value of the DW_AT_ranges attribute is the offset of the
3410 address range list in the .debug_ranges section. */
3411 unsigned long offset
= DW_UNSND (attr
);
3412 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3414 /* For some target architectures, but not others, the
3415 read_address function sign-extends the addresses it returns.
3416 To recognize base address selection entries, we need a
3418 unsigned int addr_size
= cu
->header
.addr_size
;
3419 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3421 /* The base address, to which the next pair is relative. Note
3422 that this 'base' is a DWARF concept: most entries in a range
3423 list are relative, to reduce the number of relocs against the
3424 debugging information. This is separate from this function's
3425 'baseaddr' argument, which GDB uses to relocate debugging
3426 information from a shared library based on the address at
3427 which the library was loaded. */
3428 CORE_ADDR base
= cu
->header
.base_address
;
3429 int base_known
= cu
->header
.base_known
;
3431 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3433 complaint (&symfile_complaints
,
3434 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3441 unsigned int bytes_read
;
3442 CORE_ADDR start
, end
;
3444 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3445 buffer
+= bytes_read
;
3446 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3447 buffer
+= bytes_read
;
3449 /* Did we find the end of the range list? */
3450 if (start
== 0 && end
== 0)
3453 /* Did we find a base address selection entry? */
3454 else if ((start
& base_select_mask
) == base_select_mask
)
3460 /* We found an ordinary address range. */
3465 complaint (&symfile_complaints
,
3466 _("Invalid .debug_ranges data (no base address)"));
3470 record_block_range (block
,
3471 baseaddr
+ base
+ start
,
3472 baseaddr
+ base
+ end
- 1);
3478 /* Add an aggregate field to the field list. */
3481 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3482 struct dwarf2_cu
*cu
)
3484 struct objfile
*objfile
= cu
->objfile
;
3485 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3486 struct nextfield
*new_field
;
3487 struct attribute
*attr
;
3489 char *fieldname
= "";
3491 /* Allocate a new field list entry and link it in. */
3492 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3493 make_cleanup (xfree
, new_field
);
3494 memset (new_field
, 0, sizeof (struct nextfield
));
3495 new_field
->next
= fip
->fields
;
3496 fip
->fields
= new_field
;
3499 /* Handle accessibility and virtuality of field.
3500 The default accessibility for members is public, the default
3501 accessibility for inheritance is private. */
3502 if (die
->tag
!= DW_TAG_inheritance
)
3503 new_field
->accessibility
= DW_ACCESS_public
;
3505 new_field
->accessibility
= DW_ACCESS_private
;
3506 new_field
->virtuality
= DW_VIRTUALITY_none
;
3508 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3510 new_field
->accessibility
= DW_UNSND (attr
);
3511 if (new_field
->accessibility
!= DW_ACCESS_public
)
3512 fip
->non_public_fields
= 1;
3513 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3515 new_field
->virtuality
= DW_UNSND (attr
);
3517 fp
= &new_field
->field
;
3519 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3521 /* Data member other than a C++ static data member. */
3523 /* Get type of field. */
3524 fp
->type
= die_type (die
, cu
);
3526 FIELD_STATIC_KIND (*fp
) = 0;
3528 /* Get bit size of field (zero if none). */
3529 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3532 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3536 FIELD_BITSIZE (*fp
) = 0;
3539 /* Get bit offset of field. */
3540 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3545 if (attr_form_is_section_offset (attr
))
3547 dwarf2_complex_location_expr_complaint ();
3550 else if (attr_form_is_constant (attr
))
3551 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3553 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3555 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3558 FIELD_BITPOS (*fp
) = 0;
3559 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3562 if (gdbarch_bits_big_endian (gdbarch
))
3564 /* For big endian bits, the DW_AT_bit_offset gives the
3565 additional bit offset from the MSB of the containing
3566 anonymous object to the MSB of the field. We don't
3567 have to do anything special since we don't need to
3568 know the size of the anonymous object. */
3569 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3573 /* For little endian bits, compute the bit offset to the
3574 MSB of the anonymous object, subtract off the number of
3575 bits from the MSB of the field to the MSB of the
3576 object, and then subtract off the number of bits of
3577 the field itself. The result is the bit offset of
3578 the LSB of the field. */
3580 int bit_offset
= DW_UNSND (attr
);
3582 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3585 /* The size of the anonymous object containing
3586 the bit field is explicit, so use the
3587 indicated size (in bytes). */
3588 anonymous_size
= DW_UNSND (attr
);
3592 /* The size of the anonymous object containing
3593 the bit field must be inferred from the type
3594 attribute of the data member containing the
3596 anonymous_size
= TYPE_LENGTH (fp
->type
);
3598 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3599 - bit_offset
- FIELD_BITSIZE (*fp
);
3603 /* Get name of field. */
3604 fieldname
= dwarf2_name (die
, cu
);
3605 if (fieldname
== NULL
)
3608 /* The name is already allocated along with this objfile, so we don't
3609 need to duplicate it for the type. */
3610 fp
->name
= fieldname
;
3612 /* Change accessibility for artificial fields (e.g. virtual table
3613 pointer or virtual base class pointer) to private. */
3614 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3616 new_field
->accessibility
= DW_ACCESS_private
;
3617 fip
->non_public_fields
= 1;
3620 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3622 /* C++ static member. */
3624 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3625 is a declaration, but all versions of G++ as of this writing
3626 (so through at least 3.2.1) incorrectly generate
3627 DW_TAG_variable tags. */
3631 /* Get name of field. */
3632 fieldname
= dwarf2_name (die
, cu
);
3633 if (fieldname
== NULL
)
3636 /* Get physical name. */
3637 physname
= dwarf2_linkage_name (die
, cu
);
3639 /* The name is already allocated along with this objfile, so we don't
3640 need to duplicate it for the type. */
3641 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3642 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3643 FIELD_NAME (*fp
) = fieldname
;
3645 else if (die
->tag
== DW_TAG_inheritance
)
3647 /* C++ base class field. */
3648 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3650 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3652 FIELD_BITSIZE (*fp
) = 0;
3653 FIELD_STATIC_KIND (*fp
) = 0;
3654 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3655 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3656 fip
->nbaseclasses
++;
3660 /* Create the vector of fields, and attach it to the type. */
3663 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3664 struct dwarf2_cu
*cu
)
3666 int nfields
= fip
->nfields
;
3668 /* Record the field count, allocate space for the array of fields,
3669 and create blank accessibility bitfields if necessary. */
3670 TYPE_NFIELDS (type
) = nfields
;
3671 TYPE_FIELDS (type
) = (struct field
*)
3672 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3673 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3675 if (fip
->non_public_fields
)
3677 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3679 TYPE_FIELD_PRIVATE_BITS (type
) =
3680 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3681 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3683 TYPE_FIELD_PROTECTED_BITS (type
) =
3684 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3685 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3687 TYPE_FIELD_IGNORE_BITS (type
) =
3688 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3689 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3692 /* If the type has baseclasses, allocate and clear a bit vector for
3693 TYPE_FIELD_VIRTUAL_BITS. */
3694 if (fip
->nbaseclasses
)
3696 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3697 unsigned char *pointer
;
3699 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3700 pointer
= TYPE_ALLOC (type
, num_bytes
);
3701 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3702 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3703 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3706 /* Copy the saved-up fields into the field vector. Start from the head
3707 of the list, adding to the tail of the field array, so that they end
3708 up in the same order in the array in which they were added to the list. */
3709 while (nfields
-- > 0)
3711 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3712 switch (fip
->fields
->accessibility
)
3714 case DW_ACCESS_private
:
3715 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3718 case DW_ACCESS_protected
:
3719 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3722 case DW_ACCESS_public
:
3726 /* Unknown accessibility. Complain and treat it as public. */
3728 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3729 fip
->fields
->accessibility
);
3733 if (nfields
< fip
->nbaseclasses
)
3735 switch (fip
->fields
->virtuality
)
3737 case DW_VIRTUALITY_virtual
:
3738 case DW_VIRTUALITY_pure_virtual
:
3739 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3743 fip
->fields
= fip
->fields
->next
;
3747 /* Add a member function to the proper fieldlist. */
3750 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3751 struct type
*type
, struct dwarf2_cu
*cu
)
3753 struct objfile
*objfile
= cu
->objfile
;
3754 struct attribute
*attr
;
3755 struct fnfieldlist
*flp
;
3757 struct fn_field
*fnp
;
3760 struct nextfnfield
*new_fnfield
;
3762 /* Get name of member function. */
3763 fieldname
= dwarf2_name (die
, cu
);
3764 if (fieldname
== NULL
)
3767 /* Get the mangled name. */
3768 physname
= dwarf2_linkage_name (die
, cu
);
3770 /* Look up member function name in fieldlist. */
3771 for (i
= 0; i
< fip
->nfnfields
; i
++)
3773 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3777 /* Create new list element if necessary. */
3778 if (i
< fip
->nfnfields
)
3779 flp
= &fip
->fnfieldlists
[i
];
3782 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3784 fip
->fnfieldlists
= (struct fnfieldlist
*)
3785 xrealloc (fip
->fnfieldlists
,
3786 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3787 * sizeof (struct fnfieldlist
));
3788 if (fip
->nfnfields
== 0)
3789 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3791 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3792 flp
->name
= fieldname
;
3798 /* Create a new member function field and chain it to the field list
3800 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3801 make_cleanup (xfree
, new_fnfield
);
3802 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3803 new_fnfield
->next
= flp
->head
;
3804 flp
->head
= new_fnfield
;
3807 /* Fill in the member function field info. */
3808 fnp
= &new_fnfield
->fnfield
;
3809 /* The name is already allocated along with this objfile, so we don't
3810 need to duplicate it for the type. */
3811 fnp
->physname
= physname
? physname
: "";
3812 fnp
->type
= alloc_type (objfile
);
3813 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3815 int nparams
= TYPE_NFIELDS (die
->type
);
3817 /* TYPE is the domain of this method, and DIE->TYPE is the type
3818 of the method itself (TYPE_CODE_METHOD). */
3819 smash_to_method_type (fnp
->type
, type
,
3820 TYPE_TARGET_TYPE (die
->type
),
3821 TYPE_FIELDS (die
->type
),
3822 TYPE_NFIELDS (die
->type
),
3823 TYPE_VARARGS (die
->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 (die
->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. */
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 set_die_type (die
, type
, cu
);
4005 /* Called when we find the DIE that starts a structure or union scope
4006 (definition) to process all dies that define the members of the
4009 NOTE: we need to call struct_type regardless of whether or not the
4010 DIE has an at_name attribute, since it might be an anonymous
4011 structure or union. This gets the type entered into our set of
4014 However, if the structure is incomplete (an opaque struct/union)
4015 then suppress creating a symbol table entry for it since gdb only
4016 wants to find the one with the complete definition. Note that if
4017 it is complete, we just call new_symbol, which does it's own
4018 checking about whether the struct/union is anonymous or not (and
4019 suppresses creating a symbol table entry itself). */
4022 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4024 struct objfile
*objfile
= cu
->objfile
;
4026 struct attribute
*attr
;
4027 const char *previous_prefix
= processing_current_prefix
;
4028 struct cleanup
*back_to
= NULL
;
4034 if (quirk_gcc_member_function_pointer (die
, cu
))
4037 type
= alloc_type (objfile
);
4038 INIT_CPLUS_SPECIFIC (type
);
4039 name
= dwarf2_name (die
, cu
);
4042 if (cu
->language
== language_cplus
4043 || cu
->language
== language_java
)
4045 char *new_prefix
= determine_class_name (die
, cu
);
4046 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
4047 strlen (new_prefix
),
4048 &objfile
->objfile_obstack
);
4049 back_to
= make_cleanup (xfree
, new_prefix
);
4050 processing_current_prefix
= new_prefix
;
4054 /* The name is already allocated along with this objfile, so
4055 we don't need to duplicate it for the type. */
4056 TYPE_TAG_NAME (type
) = name
;
4060 if (die
->tag
== DW_TAG_structure_type
)
4062 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4064 else if (die
->tag
== DW_TAG_union_type
)
4066 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4070 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4072 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4075 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4078 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4082 TYPE_LENGTH (type
) = 0;
4085 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB_SUPPORTED
;
4086 if (die_is_declaration (die
, cu
))
4087 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4089 /* We need to add the type field to the die immediately so we don't
4090 infinitely recurse when dealing with pointers to the structure
4091 type within the structure itself. */
4092 set_die_type (die
, type
, cu
);
4094 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4096 struct field_info fi
;
4097 struct die_info
*child_die
;
4098 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
4100 memset (&fi
, 0, sizeof (struct field_info
));
4102 child_die
= die
->child
;
4104 while (child_die
&& child_die
->tag
)
4106 if (child_die
->tag
== DW_TAG_member
4107 || child_die
->tag
== DW_TAG_variable
)
4109 /* NOTE: carlton/2002-11-05: A C++ static data member
4110 should be a DW_TAG_member that is a declaration, but
4111 all versions of G++ as of this writing (so through at
4112 least 3.2.1) incorrectly generate DW_TAG_variable
4113 tags for them instead. */
4114 dwarf2_add_field (&fi
, child_die
, cu
);
4116 else if (child_die
->tag
== DW_TAG_subprogram
)
4118 /* C++ member function. */
4119 read_type_die (child_die
, cu
);
4120 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4122 else if (child_die
->tag
== DW_TAG_inheritance
)
4124 /* C++ base class field. */
4125 dwarf2_add_field (&fi
, child_die
, cu
);
4127 child_die
= sibling_die (child_die
);
4130 /* Attach fields and member functions to the type. */
4132 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4135 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4137 /* Get the type which refers to the base class (possibly this
4138 class itself) which contains the vtable pointer for the current
4139 class from the DW_AT_containing_type attribute. */
4141 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4143 struct type
*t
= die_containing_type (die
, cu
);
4145 TYPE_VPTR_BASETYPE (type
) = t
;
4150 /* Our own class provides vtbl ptr. */
4151 for (i
= TYPE_NFIELDS (t
) - 1;
4152 i
>= TYPE_N_BASECLASSES (t
);
4155 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4157 if (is_vtable_name (fieldname
, cu
))
4159 TYPE_VPTR_FIELDNO (type
) = i
;
4164 /* Complain if virtual function table field not found. */
4165 if (i
< TYPE_N_BASECLASSES (t
))
4166 complaint (&symfile_complaints
,
4167 _("virtual function table pointer not found when defining class '%s'"),
4168 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4173 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4176 else if (cu
->producer
4177 && strncmp (cu
->producer
,
4178 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4180 /* The IBM XLC compiler does not provide direct indication
4181 of the containing type, but the vtable pointer is
4182 always named __vfp. */
4186 for (i
= TYPE_NFIELDS (type
) - 1;
4187 i
>= TYPE_N_BASECLASSES (type
);
4190 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4192 TYPE_VPTR_FIELDNO (type
) = i
;
4193 TYPE_VPTR_BASETYPE (type
) = type
;
4200 do_cleanups (back_to
);
4203 processing_current_prefix
= previous_prefix
;
4204 if (back_to
!= NULL
)
4205 do_cleanups (back_to
);
4209 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4211 struct objfile
*objfile
= cu
->objfile
;
4212 const char *previous_prefix
= processing_current_prefix
;
4213 struct die_info
*child_die
= die
->child
;
4215 if (TYPE_TAG_NAME (die
->type
) != NULL
)
4216 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
4218 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4219 snapshots) has been known to create a die giving a declaration
4220 for a class that has, as a child, a die giving a definition for a
4221 nested class. So we have to process our children even if the
4222 current die is a declaration. Normally, of course, a declaration
4223 won't have any children at all. */
4225 while (child_die
!= NULL
&& child_die
->tag
)
4227 if (child_die
->tag
== DW_TAG_member
4228 || child_die
->tag
== DW_TAG_variable
4229 || child_die
->tag
== DW_TAG_inheritance
)
4234 process_die (child_die
, cu
);
4236 child_die
= sibling_die (child_die
);
4239 /* Do not consider external references. According to the DWARF standard,
4240 these DIEs are identified by the fact that they have no byte_size
4241 attribute, and a declaration attribute. */
4242 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4243 || !die_is_declaration (die
, cu
))
4244 new_symbol (die
, die
->type
, cu
);
4246 processing_current_prefix
= previous_prefix
;
4249 /* Given a DW_AT_enumeration_type die, set its type. We do not
4250 complete the type's fields yet, or create any symbols. */
4253 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4255 struct objfile
*objfile
= cu
->objfile
;
4257 struct attribute
*attr
;
4263 type
= alloc_type (objfile
);
4265 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4266 name
= dwarf2_name (die
, cu
);
4269 if (processing_has_namespace_info
)
4271 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
4272 processing_current_prefix
,
4277 /* The name is already allocated along with this objfile, so
4278 we don't need to duplicate it for the type. */
4279 TYPE_TAG_NAME (type
) = name
;
4283 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4286 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4290 TYPE_LENGTH (type
) = 0;
4293 /* The enumeration DIE can be incomplete. In Ada, any type can be
4294 declared as private in the package spec, and then defined only
4295 inside the package body. Such types are known as Taft Amendment
4296 Types. When another package uses such a type, an incomplete DIE
4297 may be generated by the compiler. */
4298 if (die_is_declaration (die
, cu
))
4299 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4301 set_die_type (die
, type
, cu
);
4304 /* Determine the name of the type represented by DIE, which should be
4305 a named C++ or Java compound type. Return the name in question; the caller
4306 is responsible for xfree()'ing it. */
4309 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4311 struct cleanup
*back_to
= NULL
;
4312 struct die_info
*spec_die
= die_specification (die
, cu
);
4313 char *new_prefix
= NULL
;
4315 /* If this is the definition of a class that is declared by another
4316 die, then processing_current_prefix may not be accurate; see
4317 read_func_scope for a similar example. */
4318 if (spec_die
!= NULL
)
4320 char *specification_prefix
= determine_prefix (spec_die
, cu
);
4321 processing_current_prefix
= specification_prefix
;
4322 back_to
= make_cleanup (xfree
, specification_prefix
);
4325 /* If we don't have namespace debug info, guess the name by trying
4326 to demangle the names of members, just like we did in
4327 guess_structure_name. */
4328 if (!processing_has_namespace_info
)
4330 struct die_info
*child
;
4332 for (child
= die
->child
;
4333 child
!= NULL
&& child
->tag
!= 0;
4334 child
= sibling_die (child
))
4336 if (child
->tag
== DW_TAG_subprogram
)
4339 = language_class_name_from_physname (cu
->language_defn
,
4343 if (new_prefix
!= NULL
)
4349 if (new_prefix
== NULL
)
4351 const char *name
= dwarf2_name (die
, cu
);
4352 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
4353 name
? name
: "<<anonymous>>",
4357 if (back_to
!= NULL
)
4358 do_cleanups (back_to
);
4363 /* Given a pointer to a die which begins an enumeration, process all
4364 the dies that define the members of the enumeration, and create the
4365 symbol for the enumeration type.
4367 NOTE: We reverse the order of the element list. */
4370 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4372 struct objfile
*objfile
= cu
->objfile
;
4373 struct die_info
*child_die
;
4374 struct field
*fields
;
4377 int unsigned_enum
= 1;
4382 if (die
->child
!= NULL
)
4384 child_die
= die
->child
;
4385 while (child_die
&& child_die
->tag
)
4387 if (child_die
->tag
!= DW_TAG_enumerator
)
4389 process_die (child_die
, cu
);
4393 name
= dwarf2_name (child_die
, cu
);
4396 sym
= new_symbol (child_die
, die
->type
, cu
);
4397 if (SYMBOL_VALUE (sym
) < 0)
4400 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4402 fields
= (struct field
*)
4404 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4405 * sizeof (struct field
));
4408 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
4409 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4410 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4411 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4412 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4418 child_die
= sibling_die (child_die
);
4423 TYPE_NFIELDS (die
->type
) = num_fields
;
4424 TYPE_FIELDS (die
->type
) = (struct field
*)
4425 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
4426 memcpy (TYPE_FIELDS (die
->type
), fields
,
4427 sizeof (struct field
) * num_fields
);
4431 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
4434 new_symbol (die
, die
->type
, cu
);
4437 /* Extract all information from a DW_TAG_array_type DIE and put it in
4438 the DIE's type field. For now, this only handles one dimensional
4442 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4444 struct objfile
*objfile
= cu
->objfile
;
4445 struct die_info
*child_die
;
4446 struct type
*type
= NULL
;
4447 struct type
*element_type
, *range_type
, *index_type
;
4448 struct type
**range_types
= NULL
;
4449 struct attribute
*attr
;
4451 struct cleanup
*back_to
;
4454 /* Return if we've already decoded this type. */
4460 element_type
= die_type (die
, cu
);
4462 /* Irix 6.2 native cc creates array types without children for
4463 arrays with unspecified length. */
4464 if (die
->child
== NULL
)
4466 index_type
= builtin_type_int32
;
4467 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4468 set_die_type (die
, create_array_type (NULL
, element_type
, range_type
),
4473 back_to
= make_cleanup (null_cleanup
, NULL
);
4474 child_die
= die
->child
;
4475 while (child_die
&& child_die
->tag
)
4477 if (child_die
->tag
== DW_TAG_subrange_type
)
4479 read_subrange_type (child_die
, cu
);
4481 if (child_die
->type
!= NULL
)
4483 /* The range type was succesfully read. Save it for
4484 the array type creation. */
4485 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4487 range_types
= (struct type
**)
4488 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4489 * sizeof (struct type
*));
4491 make_cleanup (free_current_contents
, &range_types
);
4493 range_types
[ndim
++] = child_die
->type
;
4496 child_die
= sibling_die (child_die
);
4499 /* Dwarf2 dimensions are output from left to right, create the
4500 necessary array types in backwards order. */
4502 type
= element_type
;
4504 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4508 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4513 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4516 /* Understand Dwarf2 support for vector types (like they occur on
4517 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4518 array type. This is not part of the Dwarf2/3 standard yet, but a
4519 custom vendor extension. The main difference between a regular
4520 array and the vector variant is that vectors are passed by value
4522 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4524 make_vector_type (type
);
4526 name
= dwarf2_name (die
, cu
);
4528 TYPE_NAME (type
) = name
;
4530 do_cleanups (back_to
);
4532 /* Install the type in the die. */
4533 set_die_type (die
, type
, cu
);
4536 static enum dwarf_array_dim_ordering
4537 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4539 struct attribute
*attr
;
4541 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4543 if (attr
) return DW_SND (attr
);
4546 GNU F77 is a special case, as at 08/2004 array type info is the
4547 opposite order to the dwarf2 specification, but data is still
4548 laid out as per normal fortran.
4550 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4554 if (cu
->language
== language_fortran
&&
4555 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4557 return DW_ORD_row_major
;
4560 switch (cu
->language_defn
->la_array_ordering
)
4562 case array_column_major
:
4563 return DW_ORD_col_major
;
4564 case array_row_major
:
4566 return DW_ORD_row_major
;
4570 /* Extract all information from a DW_TAG_set_type DIE and put it in
4571 the DIE's type field. */
4574 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4576 if (die
->type
== NULL
)
4577 die
->type
= create_set_type ((struct type
*) NULL
, die_type (die
, cu
));
4580 /* First cut: install each common block member as a global variable. */
4583 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4585 struct die_info
*child_die
;
4586 struct attribute
*attr
;
4588 CORE_ADDR base
= (CORE_ADDR
) 0;
4590 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4593 /* Support the .debug_loc offsets */
4594 if (attr_form_is_block (attr
))
4596 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4598 else if (attr_form_is_section_offset (attr
))
4600 dwarf2_complex_location_expr_complaint ();
4604 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4605 "common block member");
4608 if (die
->child
!= NULL
)
4610 child_die
= die
->child
;
4611 while (child_die
&& child_die
->tag
)
4613 sym
= new_symbol (child_die
, NULL
, cu
);
4614 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4617 SYMBOL_VALUE_ADDRESS (sym
) =
4618 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4619 add_symbol_to_list (sym
, &global_symbols
);
4621 child_die
= sibling_die (child_die
);
4626 /* Read a C++ namespace. */
4629 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4631 struct objfile
*objfile
= cu
->objfile
;
4632 const char *previous_prefix
= processing_current_prefix
;
4635 struct die_info
*current_die
;
4636 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4638 name
= namespace_name (die
, &is_anonymous
, cu
);
4640 /* Now build the name of the current namespace. */
4642 if (previous_prefix
[0] == '\0')
4644 processing_current_prefix
= name
;
4648 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4649 make_cleanup (xfree
, temp_name
);
4650 processing_current_prefix
= temp_name
;
4653 /* Add a symbol associated to this if we haven't seen the namespace
4654 before. Also, add a using directive if it's an anonymous
4657 if (dwarf2_extension (die
, cu
) == NULL
)
4661 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4662 this cast will hopefully become unnecessary. */
4663 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4664 (char *) processing_current_prefix
,
4666 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4668 new_symbol (die
, type
, cu
);
4669 set_die_type (die
, type
, cu
);
4672 cp_add_using_directive (processing_current_prefix
,
4673 strlen (previous_prefix
),
4674 strlen (processing_current_prefix
));
4677 if (die
->child
!= NULL
)
4679 struct die_info
*child_die
= die
->child
;
4681 while (child_die
&& child_die
->tag
)
4683 process_die (child_die
, cu
);
4684 child_die
= sibling_die (child_die
);
4688 processing_current_prefix
= previous_prefix
;
4689 do_cleanups (back_to
);
4692 /* Return the name of the namespace represented by DIE. Set
4693 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4697 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4699 struct die_info
*current_die
;
4700 const char *name
= NULL
;
4702 /* Loop through the extensions until we find a name. */
4704 for (current_die
= die
;
4705 current_die
!= NULL
;
4706 current_die
= dwarf2_extension (die
, cu
))
4708 name
= dwarf2_name (current_die
, cu
);
4713 /* Is it an anonymous namespace? */
4715 *is_anonymous
= (name
== NULL
);
4717 name
= "(anonymous namespace)";
4722 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4723 the user defined type vector. */
4726 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4728 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4729 struct comp_unit_head
*cu_header
= &cu
->header
;
4731 struct attribute
*attr_byte_size
;
4732 struct attribute
*attr_address_class
;
4733 int byte_size
, addr_class
;
4740 type
= lookup_pointer_type (die_type (die
, cu
));
4742 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4744 byte_size
= DW_UNSND (attr_byte_size
);
4746 byte_size
= cu_header
->addr_size
;
4748 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4749 if (attr_address_class
)
4750 addr_class
= DW_UNSND (attr_address_class
);
4752 addr_class
= DW_ADDR_none
;
4754 /* If the pointer size or address class is different than the
4755 default, create a type variant marked as such and set the
4756 length accordingly. */
4757 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4759 if (gdbarch_address_class_type_flags_p (gdbarch
))
4763 type_flags
= gdbarch_address_class_type_flags
4764 (gdbarch
, byte_size
, addr_class
);
4765 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4766 type
= make_type_with_address_space (type
, type_flags
);
4768 else if (TYPE_LENGTH (type
) != byte_size
)
4770 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4773 /* Should we also complain about unhandled address classes? */
4777 TYPE_LENGTH (type
) = byte_size
;
4778 set_die_type (die
, type
, cu
);
4781 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4782 the user defined type vector. */
4785 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4787 struct objfile
*objfile
= cu
->objfile
;
4789 struct type
*to_type
;
4790 struct type
*domain
;
4797 to_type
= die_type (die
, cu
);
4798 domain
= die_containing_type (die
, cu
);
4800 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4801 type
= lookup_methodptr_type (to_type
);
4803 type
= lookup_memberptr_type (to_type
, domain
);
4805 set_die_type (die
, type
, cu
);
4808 /* Extract all information from a DW_TAG_reference_type DIE and add to
4809 the user defined type vector. */
4812 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4814 struct comp_unit_head
*cu_header
= &cu
->header
;
4816 struct attribute
*attr
;
4823 type
= lookup_reference_type (die_type (die
, cu
));
4824 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4827 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4831 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4833 set_die_type (die
, type
, cu
);
4837 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4839 struct type
*base_type
;
4846 base_type
= die_type (die
, cu
);
4847 set_die_type (die
, make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0),
4852 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4854 struct type
*base_type
;
4861 base_type
= die_type (die
, cu
);
4862 set_die_type (die
, make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0),
4866 /* Extract all information from a DW_TAG_string_type DIE and add to
4867 the user defined type vector. It isn't really a user defined type,
4868 but it behaves like one, with other DIE's using an AT_user_def_type
4869 attribute to reference it. */
4872 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4874 struct objfile
*objfile
= cu
->objfile
;
4875 struct type
*type
, *range_type
, *index_type
, *char_type
;
4876 struct attribute
*attr
;
4877 unsigned int length
;
4884 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4887 length
= DW_UNSND (attr
);
4891 /* check for the DW_AT_byte_size attribute */
4892 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4895 length
= DW_UNSND (attr
);
4903 index_type
= builtin_type_int32
;
4904 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4905 type
= create_string_type (NULL
, range_type
);
4907 set_die_type (die
, type
, cu
);
4910 /* Handle DIES due to C code like:
4914 int (*funcp)(int a, long l);
4918 ('funcp' generates a DW_TAG_subroutine_type DIE)
4922 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4924 struct type
*type
; /* Type that this function returns */
4925 struct type
*ftype
; /* Function that returns above type */
4926 struct attribute
*attr
;
4928 /* Decode the type that this subroutine returns */
4933 type
= die_type (die
, cu
);
4934 ftype
= make_function_type (type
, (struct type
**) 0);
4936 /* All functions in C++, Pascal and Java have prototypes. */
4937 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4938 if ((attr
&& (DW_UNSND (attr
) != 0))
4939 || cu
->language
== language_cplus
4940 || cu
->language
== language_java
4941 || cu
->language
== language_pascal
)
4942 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4944 /* Store the calling convention in the type if it's available in
4945 the subroutine die. Otherwise set the calling convention to
4946 the default value DW_CC_normal. */
4947 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4948 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4950 if (die
->child
!= NULL
)
4952 struct die_info
*child_die
;
4956 /* Count the number of parameters.
4957 FIXME: GDB currently ignores vararg functions, but knows about
4958 vararg member functions. */
4959 child_die
= die
->child
;
4960 while (child_die
&& child_die
->tag
)
4962 if (child_die
->tag
== DW_TAG_formal_parameter
)
4964 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4965 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4966 child_die
= sibling_die (child_die
);
4969 /* Allocate storage for parameters and fill them in. */
4970 TYPE_NFIELDS (ftype
) = nparams
;
4971 TYPE_FIELDS (ftype
) = (struct field
*)
4972 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4974 child_die
= die
->child
;
4975 while (child_die
&& child_die
->tag
)
4977 if (child_die
->tag
== DW_TAG_formal_parameter
)
4979 /* Dwarf2 has no clean way to discern C++ static and non-static
4980 member functions. G++ helps GDB by marking the first
4981 parameter for non-static member functions (which is the
4982 this pointer) as artificial. We pass this information
4983 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4984 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4986 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4988 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4989 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4992 child_die
= sibling_die (child_die
);
4996 set_die_type (die
, ftype
, cu
);
5000 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5002 struct objfile
*objfile
= cu
->objfile
;
5003 struct attribute
*attr
;
5008 name
= dwarf2_name (die
, cu
);
5009 set_die_type (die
, init_type (TYPE_CODE_TYPEDEF
, 0,
5010 TYPE_FLAG_TARGET_STUB
, name
, objfile
),
5012 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
5016 /* Find a representation of a given base type and install
5017 it in the TYPE field of the die. */
5020 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5022 struct objfile
*objfile
= cu
->objfile
;
5024 struct attribute
*attr
;
5025 int encoding
= 0, size
= 0;
5027 enum type_code code
= TYPE_CODE_INT
;
5029 struct type
*target_type
= NULL
;
5031 /* If we've already decoded this die, this is a no-op. */
5037 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5040 encoding
= DW_UNSND (attr
);
5042 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5045 size
= DW_UNSND (attr
);
5047 name
= dwarf2_name (die
, cu
);
5050 complaint (&symfile_complaints
,
5051 _("DW_AT_name missing from DW_TAG_base_type"));
5056 case DW_ATE_address
:
5057 /* Turn DW_ATE_address into a void * pointer. */
5058 code
= TYPE_CODE_PTR
;
5059 type_flags
|= TYPE_FLAG_UNSIGNED
;
5060 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5062 case DW_ATE_boolean
:
5063 code
= TYPE_CODE_BOOL
;
5064 type_flags
|= TYPE_FLAG_UNSIGNED
;
5066 case DW_ATE_complex_float
:
5067 code
= TYPE_CODE_COMPLEX
;
5068 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5070 case DW_ATE_decimal_float
:
5071 code
= TYPE_CODE_DECFLOAT
;
5074 code
= TYPE_CODE_FLT
;
5078 case DW_ATE_unsigned
:
5079 type_flags
|= TYPE_FLAG_UNSIGNED
;
5081 case DW_ATE_signed_char
:
5082 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5083 code
= TYPE_CODE_CHAR
;
5085 case DW_ATE_unsigned_char
:
5086 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5087 code
= TYPE_CODE_CHAR
;
5088 type_flags
|= TYPE_FLAG_UNSIGNED
;
5091 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5092 dwarf_type_encoding_name (encoding
));
5096 type
= init_type (code
, size
, type_flags
, name
, objfile
);
5097 TYPE_TARGET_TYPE (type
) = target_type
;
5099 set_die_type (die
, type
, cu
);
5102 /* Read the given DW_AT_subrange DIE. */
5105 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5107 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5108 struct type
*base_type
;
5109 struct type
*range_type
;
5110 struct attribute
*attr
;
5115 /* If we have already decoded this die, then nothing more to do. */
5119 base_type
= die_type (die
, cu
);
5120 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5122 complaint (&symfile_complaints
,
5123 _("DW_AT_type missing from DW_TAG_subrange_type"));
5125 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5126 0, NULL
, cu
->objfile
);
5129 if (cu
->language
== language_fortran
)
5131 /* FORTRAN implies a lower bound of 1, if not given. */
5135 /* FIXME: For variable sized arrays either of these could be
5136 a variable rather than a constant value. We'll allow it,
5137 but we don't know how to handle it. */
5138 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5140 low
= dwarf2_get_attr_constant_value (attr
, 0);
5142 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5145 if (attr
->form
== DW_FORM_block1
)
5147 /* GCC encodes arrays with unspecified or dynamic length
5148 with a DW_FORM_block1 attribute.
5149 FIXME: GDB does not yet know how to handle dynamic
5150 arrays properly, treat them as arrays with unspecified
5153 FIXME: jimb/2003-09-22: GDB does not really know
5154 how to handle arrays of unspecified length
5155 either; we just represent them as zero-length
5156 arrays. Choose an appropriate upper bound given
5157 the lower bound we've computed above. */
5161 high
= dwarf2_get_attr_constant_value (attr
, 1);
5164 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5166 name
= dwarf2_name (die
, cu
);
5168 TYPE_NAME (range_type
) = name
;
5170 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5172 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5174 set_die_type (die
, range_type
, cu
);
5178 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5185 /* For now, we only support the C meaning of an unspecified type: void. */
5187 type
= init_type (TYPE_CODE_VOID
, 0, 0, dwarf2_name (die
, cu
),
5190 set_die_type (die
, type
, cu
);
5193 /* Read a whole compilation unit into a linked list of dies. */
5195 static struct die_info
*
5196 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5198 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5201 /* Read a single die and all its descendents. Set the die's sibling
5202 field to NULL; set other fields in the die correctly, and set all
5203 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5204 location of the info_ptr after reading all of those dies. PARENT
5205 is the parent of the die in question. */
5207 static struct die_info
*
5208 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5209 struct dwarf2_cu
*cu
,
5210 gdb_byte
**new_info_ptr
,
5211 struct die_info
*parent
)
5213 struct die_info
*die
;
5217 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5218 store_in_ref_table (die
->offset
, die
, cu
);
5222 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5228 *new_info_ptr
= cur_ptr
;
5231 die
->sibling
= NULL
;
5232 die
->parent
= parent
;
5236 /* Read a die, all of its descendents, and all of its siblings; set
5237 all of the fields of all of the dies correctly. Arguments are as
5238 in read_die_and_children. */
5240 static struct die_info
*
5241 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5242 struct dwarf2_cu
*cu
,
5243 gdb_byte
**new_info_ptr
,
5244 struct die_info
*parent
)
5246 struct die_info
*first_die
, *last_sibling
;
5250 first_die
= last_sibling
= NULL
;
5254 struct die_info
*die
5255 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5263 last_sibling
->sibling
= die
;
5268 *new_info_ptr
= cur_ptr
;
5278 /* Free a linked list of dies. */
5281 free_die_list (struct die_info
*dies
)
5283 struct die_info
*die
, *next
;
5288 if (die
->child
!= NULL
)
5289 free_die_list (die
->child
);
5290 next
= die
->sibling
;
5297 /* Decompress a section that was compressed using zlib. Store the
5298 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5301 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5302 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5304 bfd
*abfd
= objfile
->obfd
;
5306 error (_("Support for zlib-compressed DWARF data (from '%s') "
5307 "is disabled in this copy of GDB"),
5308 bfd_get_filename (abfd
));
5310 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5311 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5312 bfd_size_type uncompressed_size
;
5313 gdb_byte
*uncompressed_buffer
;
5316 int header_size
= 12;
5318 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5319 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5320 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5321 bfd_get_filename (abfd
));
5323 /* Read the zlib header. In this case, it should be "ZLIB" followed
5324 by the uncompressed section size, 8 bytes in big-endian order. */
5325 if (compressed_size
< header_size
5326 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5327 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5328 bfd_get_filename (abfd
));
5329 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5330 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5331 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5332 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5333 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5334 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5335 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5336 uncompressed_size
+= compressed_buffer
[11];
5338 /* It is possible the section consists of several compressed
5339 buffers concatenated together, so we uncompress in a loop. */
5343 strm
.avail_in
= compressed_size
- header_size
;
5344 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5345 strm
.avail_out
= uncompressed_size
;
5346 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5348 rc
= inflateInit (&strm
);
5349 while (strm
.avail_in
> 0)
5352 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5353 bfd_get_filename (abfd
), rc
);
5354 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5355 + (uncompressed_size
- strm
.avail_out
));
5356 rc
= inflate (&strm
, Z_FINISH
);
5357 if (rc
!= Z_STREAM_END
)
5358 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5359 bfd_get_filename (abfd
), rc
);
5360 rc
= inflateReset (&strm
);
5362 rc
= inflateEnd (&strm
);
5364 || strm
.avail_out
!= 0)
5365 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5366 bfd_get_filename (abfd
), rc
);
5368 xfree (compressed_buffer
);
5369 *outbuf
= uncompressed_buffer
;
5370 *outsize
= uncompressed_size
;
5375 /* Read the contents of the section at OFFSET and of size SIZE from the
5376 object file specified by OBJFILE into the objfile_obstack and return it.
5377 If the section is compressed, uncompress it before returning. */
5380 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5382 bfd
*abfd
= objfile
->obfd
;
5383 gdb_byte
*buf
, *retbuf
;
5384 bfd_size_type size
= bfd_get_section_size (sectp
);
5385 unsigned char header
[4];
5390 /* Check if the file has a 4-byte header indicating compression. */
5391 if (size
> sizeof (header
)
5392 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5393 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5395 /* Upon decompression, update the buffer and its size. */
5396 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5398 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5399 dwarf2_resize_section (sectp
, size
);
5404 /* If we get here, we are a normal, not-compressed section. */
5405 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5406 /* When debugging .o files, we may need to apply relocations; see
5407 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5408 We never compress sections in .o files, so we only need to
5409 try this when the section is not compressed. */
5410 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5414 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5415 || bfd_bread (buf
, size
, abfd
) != size
)
5416 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5417 bfd_get_filename (abfd
));
5422 /* In DWARF version 2, the description of the debugging information is
5423 stored in a separate .debug_abbrev section. Before we read any
5424 dies from a section we read in all abbreviations and install them
5425 in a hash table. This function also sets flags in CU describing
5426 the data found in the abbrev table. */
5429 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5431 struct comp_unit_head
*cu_header
= &cu
->header
;
5432 gdb_byte
*abbrev_ptr
;
5433 struct abbrev_info
*cur_abbrev
;
5434 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5435 unsigned int abbrev_form
, hash_number
;
5436 struct attr_abbrev
*cur_attrs
;
5437 unsigned int allocated_attrs
;
5439 /* Initialize dwarf2 abbrevs */
5440 obstack_init (&cu
->abbrev_obstack
);
5441 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5443 * sizeof (struct abbrev_info
*)));
5444 memset (cu
->dwarf2_abbrevs
, 0,
5445 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5447 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5448 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5449 abbrev_ptr
+= bytes_read
;
5451 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5452 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5454 /* loop until we reach an abbrev number of 0 */
5455 while (abbrev_number
)
5457 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5459 /* read in abbrev header */
5460 cur_abbrev
->number
= abbrev_number
;
5461 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5462 abbrev_ptr
+= bytes_read
;
5463 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5466 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5467 cu
->has_namespace_info
= 1;
5469 /* now read in declarations */
5470 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5471 abbrev_ptr
+= bytes_read
;
5472 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5473 abbrev_ptr
+= bytes_read
;
5476 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5478 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5480 = xrealloc (cur_attrs
, (allocated_attrs
5481 * sizeof (struct attr_abbrev
)));
5484 /* Record whether this compilation unit might have
5485 inter-compilation-unit references. If we don't know what form
5486 this attribute will have, then it might potentially be a
5487 DW_FORM_ref_addr, so we conservatively expect inter-CU
5490 if (abbrev_form
== DW_FORM_ref_addr
5491 || abbrev_form
== DW_FORM_indirect
)
5492 cu
->has_form_ref_addr
= 1;
5494 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5495 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5496 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5497 abbrev_ptr
+= bytes_read
;
5498 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5499 abbrev_ptr
+= bytes_read
;
5502 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5503 (cur_abbrev
->num_attrs
5504 * sizeof (struct attr_abbrev
)));
5505 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5506 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5508 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5509 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5510 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5512 /* Get next abbreviation.
5513 Under Irix6 the abbreviations for a compilation unit are not
5514 always properly terminated with an abbrev number of 0.
5515 Exit loop if we encounter an abbreviation which we have
5516 already read (which means we are about to read the abbreviations
5517 for the next compile unit) or if the end of the abbreviation
5518 table is reached. */
5519 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5520 >= dwarf2_per_objfile
->abbrev_size
)
5522 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5523 abbrev_ptr
+= bytes_read
;
5524 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5531 /* Release the memory used by the abbrev table for a compilation unit. */
5534 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5536 struct dwarf2_cu
*cu
= ptr_to_cu
;
5538 obstack_free (&cu
->abbrev_obstack
, NULL
);
5539 cu
->dwarf2_abbrevs
= NULL
;
5542 /* Lookup an abbrev_info structure in the abbrev hash table. */
5544 static struct abbrev_info
*
5545 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5547 unsigned int hash_number
;
5548 struct abbrev_info
*abbrev
;
5550 hash_number
= number
% ABBREV_HASH_SIZE
;
5551 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5555 if (abbrev
->number
== number
)
5558 abbrev
= abbrev
->next
;
5563 /* Returns nonzero if TAG represents a type that we might generate a partial
5567 is_type_tag_for_partial (int tag
)
5572 /* Some types that would be reasonable to generate partial symbols for,
5573 that we don't at present. */
5574 case DW_TAG_array_type
:
5575 case DW_TAG_file_type
:
5576 case DW_TAG_ptr_to_member_type
:
5577 case DW_TAG_set_type
:
5578 case DW_TAG_string_type
:
5579 case DW_TAG_subroutine_type
:
5581 case DW_TAG_base_type
:
5582 case DW_TAG_class_type
:
5583 case DW_TAG_interface_type
:
5584 case DW_TAG_enumeration_type
:
5585 case DW_TAG_structure_type
:
5586 case DW_TAG_subrange_type
:
5587 case DW_TAG_typedef
:
5588 case DW_TAG_union_type
:
5595 /* Load all DIEs that are interesting for partial symbols into memory. */
5597 static struct partial_die_info
*
5598 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5599 struct dwarf2_cu
*cu
)
5601 struct partial_die_info
*part_die
;
5602 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5603 struct abbrev_info
*abbrev
;
5604 unsigned int bytes_read
;
5605 unsigned int load_all
= 0;
5607 int nesting_level
= 1;
5612 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5616 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5620 &cu
->comp_unit_obstack
,
5621 hashtab_obstack_allocate
,
5622 dummy_obstack_deallocate
);
5624 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5625 sizeof (struct partial_die_info
));
5629 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5631 /* A NULL abbrev means the end of a series of children. */
5634 if (--nesting_level
== 0)
5636 /* PART_DIE was probably the last thing allocated on the
5637 comp_unit_obstack, so we could call obstack_free
5638 here. We don't do that because the waste is small,
5639 and will be cleaned up when we're done with this
5640 compilation unit. This way, we're also more robust
5641 against other users of the comp_unit_obstack. */
5644 info_ptr
+= bytes_read
;
5645 last_die
= parent_die
;
5646 parent_die
= parent_die
->die_parent
;
5650 /* Check whether this DIE is interesting enough to save. Normally
5651 we would not be interested in members here, but there may be
5652 later variables referencing them via DW_AT_specification (for
5655 && !is_type_tag_for_partial (abbrev
->tag
)
5656 && abbrev
->tag
!= DW_TAG_enumerator
5657 && abbrev
->tag
!= DW_TAG_subprogram
5658 && abbrev
->tag
!= DW_TAG_variable
5659 && abbrev
->tag
!= DW_TAG_namespace
5660 && abbrev
->tag
!= DW_TAG_member
)
5662 /* Otherwise we skip to the next sibling, if any. */
5663 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5667 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5668 abfd
, info_ptr
, cu
);
5670 /* This two-pass algorithm for processing partial symbols has a
5671 high cost in cache pressure. Thus, handle some simple cases
5672 here which cover the majority of C partial symbols. DIEs
5673 which neither have specification tags in them, nor could have
5674 specification tags elsewhere pointing at them, can simply be
5675 processed and discarded.
5677 This segment is also optional; scan_partial_symbols and
5678 add_partial_symbol will handle these DIEs if we chain
5679 them in normally. When compilers which do not emit large
5680 quantities of duplicate debug information are more common,
5681 this code can probably be removed. */
5683 /* Any complete simple types at the top level (pretty much all
5684 of them, for a language without namespaces), can be processed
5686 if (parent_die
== NULL
5687 && part_die
->has_specification
== 0
5688 && part_die
->is_declaration
== 0
5689 && (part_die
->tag
== DW_TAG_typedef
5690 || part_die
->tag
== DW_TAG_base_type
5691 || part_die
->tag
== DW_TAG_subrange_type
))
5693 if (building_psymtab
&& part_die
->name
!= NULL
)
5694 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5695 VAR_DOMAIN
, LOC_TYPEDEF
,
5696 &cu
->objfile
->static_psymbols
,
5697 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5698 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5702 /* If we're at the second level, and we're an enumerator, and
5703 our parent has no specification (meaning possibly lives in a
5704 namespace elsewhere), then we can add the partial symbol now
5705 instead of queueing it. */
5706 if (part_die
->tag
== DW_TAG_enumerator
5707 && parent_die
!= NULL
5708 && parent_die
->die_parent
== NULL
5709 && parent_die
->tag
== DW_TAG_enumeration_type
5710 && parent_die
->has_specification
== 0)
5712 if (part_die
->name
== NULL
)
5713 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5714 else if (building_psymtab
)
5715 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5716 VAR_DOMAIN
, LOC_CONST
,
5717 (cu
->language
== language_cplus
5718 || cu
->language
== language_java
)
5719 ? &cu
->objfile
->global_psymbols
5720 : &cu
->objfile
->static_psymbols
,
5721 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5723 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5727 /* We'll save this DIE so link it in. */
5728 part_die
->die_parent
= parent_die
;
5729 part_die
->die_sibling
= NULL
;
5730 part_die
->die_child
= NULL
;
5732 if (last_die
&& last_die
== parent_die
)
5733 last_die
->die_child
= part_die
;
5735 last_die
->die_sibling
= part_die
;
5737 last_die
= part_die
;
5739 if (first_die
== NULL
)
5740 first_die
= part_die
;
5742 /* Maybe add the DIE to the hash table. Not all DIEs that we
5743 find interesting need to be in the hash table, because we
5744 also have the parent/sibling/child chains; only those that we
5745 might refer to by offset later during partial symbol reading.
5747 For now this means things that might have be the target of a
5748 DW_AT_specification, DW_AT_abstract_origin, or
5749 DW_AT_extension. DW_AT_extension will refer only to
5750 namespaces; DW_AT_abstract_origin refers to functions (and
5751 many things under the function DIE, but we do not recurse
5752 into function DIEs during partial symbol reading) and
5753 possibly variables as well; DW_AT_specification refers to
5754 declarations. Declarations ought to have the DW_AT_declaration
5755 flag. It happens that GCC forgets to put it in sometimes, but
5756 only for functions, not for types.
5758 Adding more things than necessary to the hash table is harmless
5759 except for the performance cost. Adding too few will result in
5760 wasted time in find_partial_die, when we reread the compilation
5761 unit with load_all_dies set. */
5764 || abbrev
->tag
== DW_TAG_subprogram
5765 || abbrev
->tag
== DW_TAG_variable
5766 || abbrev
->tag
== DW_TAG_namespace
5767 || part_die
->is_declaration
)
5771 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5772 part_die
->offset
, INSERT
);
5776 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5777 sizeof (struct partial_die_info
));
5779 /* For some DIEs we want to follow their children (if any). For C
5780 we have no reason to follow the children of structures; for other
5781 languages we have to, both so that we can get at method physnames
5782 to infer fully qualified class names, and for DW_AT_specification. */
5783 if (last_die
->has_children
5785 || last_die
->tag
== DW_TAG_namespace
5786 || last_die
->tag
== DW_TAG_enumeration_type
5787 || (cu
->language
!= language_c
5788 && (last_die
->tag
== DW_TAG_class_type
5789 || last_die
->tag
== DW_TAG_interface_type
5790 || last_die
->tag
== DW_TAG_structure_type
5791 || last_die
->tag
== DW_TAG_union_type
))))
5794 parent_die
= last_die
;
5798 /* Otherwise we skip to the next sibling, if any. */
5799 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5801 /* Back to the top, do it again. */
5805 /* Read a minimal amount of information into the minimal die structure. */
5808 read_partial_die (struct partial_die_info
*part_die
,
5809 struct abbrev_info
*abbrev
,
5810 unsigned int abbrev_len
, bfd
*abfd
,
5811 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5813 unsigned int bytes_read
, i
;
5814 struct attribute attr
;
5815 int has_low_pc_attr
= 0;
5816 int has_high_pc_attr
= 0;
5817 CORE_ADDR base_address
;
5821 base_address_low_pc
,
5822 /* Overrides BASE_ADDRESS_LOW_PC. */
5823 base_address_entry_pc
5825 base_address_type
= base_address_none
;
5827 memset (part_die
, 0, sizeof (struct partial_die_info
));
5829 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5831 info_ptr
+= abbrev_len
;
5836 part_die
->tag
= abbrev
->tag
;
5837 part_die
->has_children
= abbrev
->has_children
;
5839 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5841 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5843 /* Store the data if it is of an attribute we want to keep in a
5844 partial symbol table. */
5849 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5850 if (part_die
->name
== NULL
)
5851 part_die
->name
= DW_STRING (&attr
);
5853 case DW_AT_comp_dir
:
5854 if (part_die
->dirname
== NULL
)
5855 part_die
->dirname
= DW_STRING (&attr
);
5857 case DW_AT_MIPS_linkage_name
:
5858 part_die
->name
= DW_STRING (&attr
);
5861 has_low_pc_attr
= 1;
5862 part_die
->lowpc
= DW_ADDR (&attr
);
5863 if (part_die
->tag
== DW_TAG_compile_unit
5864 && base_address_type
< base_address_low_pc
)
5866 base_address
= DW_ADDR (&attr
);
5867 base_address_type
= base_address_low_pc
;
5871 has_high_pc_attr
= 1;
5872 part_die
->highpc
= DW_ADDR (&attr
);
5874 case DW_AT_entry_pc
:
5875 if (part_die
->tag
== DW_TAG_compile_unit
5876 && base_address_type
< base_address_entry_pc
)
5878 base_address
= DW_ADDR (&attr
);
5879 base_address_type
= base_address_entry_pc
;
5883 if (dwarf2_ranges_read (DW_UNSND (&attr
), &part_die
->lowpc
,
5884 &part_die
->highpc
, cu
))
5885 has_low_pc_attr
= has_high_pc_attr
= 1;
5887 case DW_AT_location
:
5888 /* Support the .debug_loc offsets */
5889 if (attr_form_is_block (&attr
))
5891 part_die
->locdesc
= DW_BLOCK (&attr
);
5893 else if (attr_form_is_section_offset (&attr
))
5895 dwarf2_complex_location_expr_complaint ();
5899 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5900 "partial symbol information");
5903 case DW_AT_language
:
5904 part_die
->language
= DW_UNSND (&attr
);
5906 case DW_AT_external
:
5907 part_die
->is_external
= DW_UNSND (&attr
);
5909 case DW_AT_declaration
:
5910 part_die
->is_declaration
= DW_UNSND (&attr
);
5913 part_die
->has_type
= 1;
5915 case DW_AT_abstract_origin
:
5916 case DW_AT_specification
:
5917 case DW_AT_extension
:
5918 part_die
->has_specification
= 1;
5919 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5922 /* Ignore absolute siblings, they might point outside of
5923 the current compile unit. */
5924 if (attr
.form
== DW_FORM_ref_addr
)
5925 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5927 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5928 + dwarf2_get_ref_die_offset (&attr
, cu
);
5930 case DW_AT_stmt_list
:
5931 part_die
->has_stmt_list
= 1;
5932 part_die
->line_offset
= DW_UNSND (&attr
);
5934 case DW_AT_byte_size
:
5935 part_die
->has_byte_size
= 1;
5937 case DW_AT_calling_convention
:
5938 /* DWARF doesn't provide a way to identify a program's source-level
5939 entry point. DW_AT_calling_convention attributes are only meant
5940 to describe functions' calling conventions.
5942 However, because it's a necessary piece of information in
5943 Fortran, and because DW_CC_program is the only piece of debugging
5944 information whose definition refers to a 'main program' at all,
5945 several compilers have begun marking Fortran main programs with
5946 DW_CC_program --- even when those functions use the standard
5947 calling conventions.
5949 So until DWARF specifies a way to provide this information and
5950 compilers pick up the new representation, we'll support this
5952 if (DW_UNSND (&attr
) == DW_CC_program
5953 && cu
->language
== language_fortran
)
5954 set_main_name (part_die
->name
);
5961 /* When using the GNU linker, .gnu.linkonce. sections are used to
5962 eliminate duplicate copies of functions and vtables and such.
5963 The linker will arbitrarily choose one and discard the others.
5964 The AT_*_pc values for such functions refer to local labels in
5965 these sections. If the section from that file was discarded, the
5966 labels are not in the output, so the relocs get a value of 0.
5967 If this is a discarded function, mark the pc bounds as invalid,
5968 so that GDB will ignore it. */
5969 if (has_low_pc_attr
&& has_high_pc_attr
5970 && part_die
->lowpc
< part_die
->highpc
5971 && (part_die
->lowpc
!= 0
5972 || dwarf2_per_objfile
->has_section_at_zero
))
5973 part_die
->has_pc_info
= 1;
5975 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
5977 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5978 cu
->header
.base_known
= 1;
5979 cu
->header
.base_address
= base_address
;
5985 /* Find a cached partial DIE at OFFSET in CU. */
5987 static struct partial_die_info
*
5988 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5990 struct partial_die_info
*lookup_die
= NULL
;
5991 struct partial_die_info part_die
;
5993 part_die
.offset
= offset
;
5994 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5999 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6001 static struct partial_die_info
*
6002 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
6004 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6005 struct partial_die_info
*pd
= NULL
;
6007 if (offset
>= cu
->header
.offset
6008 && offset
< cu
->header
.offset
+ cu
->header
.length
)
6010 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6015 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6017 if (per_cu
->cu
== NULL
)
6019 load_comp_unit (per_cu
, cu
->objfile
);
6020 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6021 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6024 per_cu
->cu
->last_used
= 0;
6025 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6027 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6029 struct cleanup
*back_to
;
6030 struct partial_die_info comp_unit_die
;
6031 struct abbrev_info
*abbrev
;
6032 unsigned int bytes_read
;
6035 per_cu
->load_all_dies
= 1;
6037 /* Re-read the DIEs. */
6038 back_to
= make_cleanup (null_cleanup
, 0);
6039 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6041 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6042 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6044 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
6045 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6046 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6047 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6049 if (comp_unit_die
.has_children
)
6050 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6051 do_cleanups (back_to
);
6053 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6057 internal_error (__FILE__
, __LINE__
,
6058 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
6059 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6063 /* Adjust PART_DIE before generating a symbol for it. This function
6064 may set the is_external flag or change the DIE's name. */
6067 fixup_partial_die (struct partial_die_info
*part_die
,
6068 struct dwarf2_cu
*cu
)
6070 /* If we found a reference attribute and the DIE has no name, try
6071 to find a name in the referred to DIE. */
6073 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6075 struct partial_die_info
*spec_die
;
6077 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6079 fixup_partial_die (spec_die
, cu
);
6083 part_die
->name
= spec_die
->name
;
6085 /* Copy DW_AT_external attribute if it is set. */
6086 if (spec_die
->is_external
)
6087 part_die
->is_external
= spec_die
->is_external
;
6091 /* Set default names for some unnamed DIEs. */
6092 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6093 || part_die
->tag
== DW_TAG_class_type
))
6094 part_die
->name
= "(anonymous class)";
6096 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6097 part_die
->name
= "(anonymous namespace)";
6099 if (part_die
->tag
== DW_TAG_structure_type
6100 || part_die
->tag
== DW_TAG_class_type
6101 || part_die
->tag
== DW_TAG_union_type
)
6102 guess_structure_name (part_die
, cu
);
6105 /* Read the die from the .debug_info section buffer. Set DIEP to
6106 point to a newly allocated die with its information, except for its
6107 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6108 whether the die has children or not. */
6111 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6112 struct dwarf2_cu
*cu
, int *has_children
)
6114 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6115 struct abbrev_info
*abbrev
;
6116 struct die_info
*die
;
6118 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6119 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6120 info_ptr
+= bytes_read
;
6123 die
= dwarf_alloc_die ();
6125 die
->abbrev
= abbrev_number
;
6132 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6135 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6137 bfd_get_filename (abfd
));
6139 die
= dwarf_alloc_die ();
6140 die
->offset
= offset
;
6141 die
->tag
= abbrev
->tag
;
6142 die
->abbrev
= abbrev_number
;
6145 die
->num_attrs
= abbrev
->num_attrs
;
6146 die
->attrs
= (struct attribute
*)
6147 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
6149 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6151 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6152 abfd
, info_ptr
, cu
);
6154 /* If this attribute is an absolute reference to a different
6155 compilation unit, make sure that compilation unit is loaded
6157 if (die
->attrs
[i
].form
== DW_FORM_ref_addr
6158 && (DW_ADDR (&die
->attrs
[i
]) < cu
->header
.offset
6159 || (DW_ADDR (&die
->attrs
[i
])
6160 >= cu
->header
.offset
+ cu
->header
.length
)))
6162 struct dwarf2_per_cu_data
*per_cu
;
6163 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (&die
->attrs
[i
]),
6166 /* Mark the dependence relation so that we don't flush PER_CU
6168 dwarf2_add_dependence (cu
, per_cu
);
6170 /* If it's already on the queue, we have nothing to do. */
6174 /* If the compilation unit is already loaded, just mark it as
6176 if (per_cu
->cu
!= NULL
)
6178 per_cu
->cu
->last_used
= 0;
6182 /* Add it to the queue. */
6183 queue_comp_unit (per_cu
);
6188 *has_children
= abbrev
->has_children
;
6192 /* Read an attribute value described by an attribute form. */
6195 read_attribute_value (struct attribute
*attr
, unsigned form
,
6196 bfd
*abfd
, gdb_byte
*info_ptr
,
6197 struct dwarf2_cu
*cu
)
6199 struct comp_unit_head
*cu_header
= &cu
->header
;
6200 unsigned int bytes_read
;
6201 struct dwarf_block
*blk
;
6207 case DW_FORM_ref_addr
:
6208 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6209 info_ptr
+= bytes_read
;
6211 case DW_FORM_block2
:
6212 blk
= dwarf_alloc_block (cu
);
6213 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6215 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6216 info_ptr
+= blk
->size
;
6217 DW_BLOCK (attr
) = blk
;
6219 case DW_FORM_block4
:
6220 blk
= dwarf_alloc_block (cu
);
6221 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6223 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6224 info_ptr
+= blk
->size
;
6225 DW_BLOCK (attr
) = blk
;
6228 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6232 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6236 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6239 case DW_FORM_string
:
6240 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6241 info_ptr
+= bytes_read
;
6244 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6246 info_ptr
+= bytes_read
;
6249 blk
= dwarf_alloc_block (cu
);
6250 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6251 info_ptr
+= bytes_read
;
6252 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6253 info_ptr
+= blk
->size
;
6254 DW_BLOCK (attr
) = blk
;
6256 case DW_FORM_block1
:
6257 blk
= dwarf_alloc_block (cu
);
6258 blk
->size
= read_1_byte (abfd
, info_ptr
);
6260 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6261 info_ptr
+= blk
->size
;
6262 DW_BLOCK (attr
) = blk
;
6265 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6269 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6273 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6274 info_ptr
+= bytes_read
;
6277 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6278 info_ptr
+= bytes_read
;
6281 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6285 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6289 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6293 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6296 case DW_FORM_ref_udata
:
6297 DW_ADDR (attr
) = (cu
->header
.offset
6298 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6299 info_ptr
+= bytes_read
;
6301 case DW_FORM_indirect
:
6302 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6303 info_ptr
+= bytes_read
;
6304 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6307 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6308 dwarf_form_name (form
),
6309 bfd_get_filename (abfd
));
6314 /* Read an attribute described by an abbreviated attribute. */
6317 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6318 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6320 attr
->name
= abbrev
->name
;
6321 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6324 /* read dwarf information from a buffer */
6327 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6329 return bfd_get_8 (abfd
, buf
);
6333 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6335 return bfd_get_signed_8 (abfd
, buf
);
6339 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6341 return bfd_get_16 (abfd
, buf
);
6345 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6347 return bfd_get_signed_16 (abfd
, buf
);
6351 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6353 return bfd_get_32 (abfd
, buf
);
6357 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6359 return bfd_get_signed_32 (abfd
, buf
);
6362 static unsigned long
6363 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6365 return bfd_get_64 (abfd
, buf
);
6369 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6370 unsigned int *bytes_read
)
6372 struct comp_unit_head
*cu_header
= &cu
->header
;
6373 CORE_ADDR retval
= 0;
6375 if (cu_header
->signed_addr_p
)
6377 switch (cu_header
->addr_size
)
6380 retval
= bfd_get_signed_16 (abfd
, buf
);
6383 retval
= bfd_get_signed_32 (abfd
, buf
);
6386 retval
= bfd_get_signed_64 (abfd
, buf
);
6389 internal_error (__FILE__
, __LINE__
,
6390 _("read_address: bad switch, signed [in module %s]"),
6391 bfd_get_filename (abfd
));
6396 switch (cu_header
->addr_size
)
6399 retval
= bfd_get_16 (abfd
, buf
);
6402 retval
= bfd_get_32 (abfd
, buf
);
6405 retval
= bfd_get_64 (abfd
, buf
);
6408 internal_error (__FILE__
, __LINE__
,
6409 _("read_address: bad switch, unsigned [in module %s]"),
6410 bfd_get_filename (abfd
));
6414 *bytes_read
= cu_header
->addr_size
;
6418 /* Read the initial length from a section. The (draft) DWARF 3
6419 specification allows the initial length to take up either 4 bytes
6420 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6421 bytes describe the length and all offsets will be 8 bytes in length
6424 An older, non-standard 64-bit format is also handled by this
6425 function. The older format in question stores the initial length
6426 as an 8-byte quantity without an escape value. Lengths greater
6427 than 2^32 aren't very common which means that the initial 4 bytes
6428 is almost always zero. Since a length value of zero doesn't make
6429 sense for the 32-bit format, this initial zero can be considered to
6430 be an escape value which indicates the presence of the older 64-bit
6431 format. As written, the code can't detect (old format) lengths
6432 greater than 4GB. If it becomes necessary to handle lengths
6433 somewhat larger than 4GB, we could allow other small values (such
6434 as the non-sensical values of 1, 2, and 3) to also be used as
6435 escape values indicating the presence of the old format.
6437 The value returned via bytes_read should be used to increment the
6438 relevant pointer after calling read_initial_length().
6440 As a side effect, this function sets the fields initial_length_size
6441 and offset_size in cu_header to the values appropriate for the
6442 length field. (The format of the initial length field determines
6443 the width of file offsets to be fetched later with read_offset().)
6445 [ Note: read_initial_length() and read_offset() are based on the
6446 document entitled "DWARF Debugging Information Format", revision
6447 3, draft 8, dated November 19, 2001. This document was obtained
6450 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6452 This document is only a draft and is subject to change. (So beware.)
6454 Details regarding the older, non-standard 64-bit format were
6455 determined empirically by examining 64-bit ELF files produced by
6456 the SGI toolchain on an IRIX 6.5 machine.
6458 - Kevin, July 16, 2002
6462 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6463 unsigned int *bytes_read
)
6465 LONGEST length
= bfd_get_32 (abfd
, buf
);
6467 if (length
== 0xffffffff)
6469 length
= bfd_get_64 (abfd
, buf
+ 4);
6472 else if (length
== 0)
6474 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6475 length
= bfd_get_64 (abfd
, buf
);
6485 gdb_assert (cu_header
->initial_length_size
== 0
6486 || cu_header
->initial_length_size
== 4
6487 || cu_header
->initial_length_size
== 8
6488 || cu_header
->initial_length_size
== 12);
6490 if (cu_header
->initial_length_size
!= 0
6491 && cu_header
->initial_length_size
!= *bytes_read
)
6492 complaint (&symfile_complaints
,
6493 _("intermixed 32-bit and 64-bit DWARF sections"));
6495 cu_header
->initial_length_size
= *bytes_read
;
6496 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6502 /* Read an offset from the data stream. The size of the offset is
6503 given by cu_header->offset_size. */
6506 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6507 unsigned int *bytes_read
)
6511 switch (cu_header
->offset_size
)
6514 retval
= bfd_get_32 (abfd
, buf
);
6518 retval
= bfd_get_64 (abfd
, buf
);
6522 internal_error (__FILE__
, __LINE__
,
6523 _("read_offset: bad switch [in module %s]"),
6524 bfd_get_filename (abfd
));
6531 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6533 /* If the size of a host char is 8 bits, we can return a pointer
6534 to the buffer, otherwise we have to copy the data to a buffer
6535 allocated on the temporary obstack. */
6536 gdb_assert (HOST_CHAR_BIT
== 8);
6541 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6543 /* If the size of a host char is 8 bits, we can return a pointer
6544 to the string, otherwise we have to copy the string to a buffer
6545 allocated on the temporary obstack. */
6546 gdb_assert (HOST_CHAR_BIT
== 8);
6549 *bytes_read_ptr
= 1;
6552 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6553 return (char *) buf
;
6557 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6558 const struct comp_unit_head
*cu_header
,
6559 unsigned int *bytes_read_ptr
)
6561 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6564 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6566 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6567 bfd_get_filename (abfd
));
6570 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6572 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6573 bfd_get_filename (abfd
));
6576 gdb_assert (HOST_CHAR_BIT
== 8);
6577 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6579 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6582 static unsigned long
6583 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6585 unsigned long result
;
6586 unsigned int num_read
;
6596 byte
= bfd_get_8 (abfd
, buf
);
6599 result
|= ((unsigned long)(byte
& 127) << shift
);
6600 if ((byte
& 128) == 0)
6606 *bytes_read_ptr
= num_read
;
6611 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6614 int i
, shift
, num_read
;
6623 byte
= bfd_get_8 (abfd
, buf
);
6626 result
|= ((long)(byte
& 127) << shift
);
6628 if ((byte
& 128) == 0)
6633 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6634 result
|= -(((long)1) << shift
);
6635 *bytes_read_ptr
= num_read
;
6639 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6642 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6648 byte
= bfd_get_8 (abfd
, buf
);
6650 if ((byte
& 128) == 0)
6656 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6662 cu
->language
= language_c
;
6664 case DW_LANG_C_plus_plus
:
6665 cu
->language
= language_cplus
;
6667 case DW_LANG_Fortran77
:
6668 case DW_LANG_Fortran90
:
6669 case DW_LANG_Fortran95
:
6670 cu
->language
= language_fortran
;
6672 case DW_LANG_Mips_Assembler
:
6673 cu
->language
= language_asm
;
6676 cu
->language
= language_java
;
6680 cu
->language
= language_ada
;
6682 case DW_LANG_Modula2
:
6683 cu
->language
= language_m2
;
6685 case DW_LANG_Pascal83
:
6686 cu
->language
= language_pascal
;
6689 cu
->language
= language_objc
;
6691 case DW_LANG_Cobol74
:
6692 case DW_LANG_Cobol85
:
6694 cu
->language
= language_minimal
;
6697 cu
->language_defn
= language_def (cu
->language
);
6700 /* Return the named attribute or NULL if not there. */
6702 static struct attribute
*
6703 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6706 struct attribute
*spec
= NULL
;
6708 for (i
= 0; i
< die
->num_attrs
; ++i
)
6710 if (die
->attrs
[i
].name
== name
)
6711 return &die
->attrs
[i
];
6712 if (die
->attrs
[i
].name
== DW_AT_specification
6713 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6714 spec
= &die
->attrs
[i
];
6718 return dwarf2_attr (follow_die_ref (die
, spec
, cu
), name
, cu
);
6723 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6724 and holds a non-zero value. This function should only be used for
6725 DW_FORM_flag attributes. */
6728 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6730 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6732 return (attr
&& DW_UNSND (attr
));
6736 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6738 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6739 which value is non-zero. However, we have to be careful with
6740 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6741 (via dwarf2_flag_true_p) follows this attribute. So we may
6742 end up accidently finding a declaration attribute that belongs
6743 to a different DIE referenced by the specification attribute,
6744 even though the given DIE does not have a declaration attribute. */
6745 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6746 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6749 /* Return the die giving the specification for DIE, if there is
6752 static struct die_info
*
6753 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6755 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6757 if (spec_attr
== NULL
)
6760 return follow_die_ref (die
, spec_attr
, cu
);
6763 /* Free the line_header structure *LH, and any arrays and strings it
6766 free_line_header (struct line_header
*lh
)
6768 if (lh
->standard_opcode_lengths
)
6769 xfree (lh
->standard_opcode_lengths
);
6771 /* Remember that all the lh->file_names[i].name pointers are
6772 pointers into debug_line_buffer, and don't need to be freed. */
6774 xfree (lh
->file_names
);
6776 /* Similarly for the include directory names. */
6777 if (lh
->include_dirs
)
6778 xfree (lh
->include_dirs
);
6784 /* Add an entry to LH's include directory table. */
6786 add_include_dir (struct line_header
*lh
, char *include_dir
)
6788 /* Grow the array if necessary. */
6789 if (lh
->include_dirs_size
== 0)
6791 lh
->include_dirs_size
= 1; /* for testing */
6792 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6793 * sizeof (*lh
->include_dirs
));
6795 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6797 lh
->include_dirs_size
*= 2;
6798 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6799 (lh
->include_dirs_size
6800 * sizeof (*lh
->include_dirs
)));
6803 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6807 /* Add an entry to LH's file name table. */
6809 add_file_name (struct line_header
*lh
,
6811 unsigned int dir_index
,
6812 unsigned int mod_time
,
6813 unsigned int length
)
6815 struct file_entry
*fe
;
6817 /* Grow the array if necessary. */
6818 if (lh
->file_names_size
== 0)
6820 lh
->file_names_size
= 1; /* for testing */
6821 lh
->file_names
= xmalloc (lh
->file_names_size
6822 * sizeof (*lh
->file_names
));
6824 else if (lh
->num_file_names
>= lh
->file_names_size
)
6826 lh
->file_names_size
*= 2;
6827 lh
->file_names
= xrealloc (lh
->file_names
,
6828 (lh
->file_names_size
6829 * sizeof (*lh
->file_names
)));
6832 fe
= &lh
->file_names
[lh
->num_file_names
++];
6834 fe
->dir_index
= dir_index
;
6835 fe
->mod_time
= mod_time
;
6836 fe
->length
= length
;
6842 /* Read the statement program header starting at OFFSET in
6843 .debug_line, according to the endianness of ABFD. Return a pointer
6844 to a struct line_header, allocated using xmalloc.
6846 NOTE: the strings in the include directory and file name tables of
6847 the returned object point into debug_line_buffer, and must not be
6849 static struct line_header
*
6850 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6851 struct dwarf2_cu
*cu
)
6853 struct cleanup
*back_to
;
6854 struct line_header
*lh
;
6856 unsigned int bytes_read
;
6858 char *cur_dir
, *cur_file
;
6860 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6862 complaint (&symfile_complaints
, _("missing .debug_line section"));
6866 /* Make sure that at least there's room for the total_length field.
6867 That could be 12 bytes long, but we're just going to fudge that. */
6868 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6870 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6874 lh
= xmalloc (sizeof (*lh
));
6875 memset (lh
, 0, sizeof (*lh
));
6876 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6879 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6881 /* Read in the header. */
6883 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6884 line_ptr
+= bytes_read
;
6885 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6886 + dwarf2_per_objfile
->line_size
))
6888 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6891 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6892 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6894 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6895 line_ptr
+= bytes_read
;
6896 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6898 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6900 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6902 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6904 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6906 lh
->standard_opcode_lengths
6907 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6909 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6910 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6912 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6916 /* Read directory table. */
6917 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6919 line_ptr
+= bytes_read
;
6920 add_include_dir (lh
, cur_dir
);
6922 line_ptr
+= bytes_read
;
6924 /* Read file name table. */
6925 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6927 unsigned int dir_index
, mod_time
, length
;
6929 line_ptr
+= bytes_read
;
6930 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6931 line_ptr
+= bytes_read
;
6932 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6933 line_ptr
+= bytes_read
;
6934 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6935 line_ptr
+= bytes_read
;
6937 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6939 line_ptr
+= bytes_read
;
6940 lh
->statement_program_start
= line_ptr
;
6942 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6943 + dwarf2_per_objfile
->line_size
))
6944 complaint (&symfile_complaints
,
6945 _("line number info header doesn't fit in `.debug_line' section"));
6947 discard_cleanups (back_to
);
6951 /* This function exists to work around a bug in certain compilers
6952 (particularly GCC 2.95), in which the first line number marker of a
6953 function does not show up until after the prologue, right before
6954 the second line number marker. This function shifts ADDRESS down
6955 to the beginning of the function if necessary, and is called on
6956 addresses passed to record_line. */
6959 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6961 struct function_range
*fn
;
6963 /* Find the function_range containing address. */
6968 cu
->cached_fn
= cu
->first_fn
;
6972 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6978 while (fn
&& fn
!= cu
->cached_fn
)
6979 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6989 if (address
!= fn
->lowpc
)
6990 complaint (&symfile_complaints
,
6991 _("misplaced first line number at 0x%lx for '%s'"),
6992 (unsigned long) address
, fn
->name
);
6997 /* Decode the Line Number Program (LNP) for the given line_header
6998 structure and CU. The actual information extracted and the type
6999 of structures created from the LNP depends on the value of PST.
7001 1. If PST is NULL, then this procedure uses the data from the program
7002 to create all necessary symbol tables, and their linetables.
7003 The compilation directory of the file is passed in COMP_DIR,
7004 and must not be NULL.
7006 2. If PST is not NULL, this procedure reads the program to determine
7007 the list of files included by the unit represented by PST, and
7008 builds all the associated partial symbol tables. In this case,
7009 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7010 is not used to compute the full name of the symtab, and therefore
7011 omitting it when building the partial symtab does not introduce
7012 the potential for inconsistency - a partial symtab and its associated
7013 symbtab having a different fullname -). */
7016 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7017 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7019 gdb_byte
*line_ptr
, *extended_end
;
7021 unsigned int bytes_read
, extended_len
;
7022 unsigned char op_code
, extended_op
, adj_opcode
;
7024 struct objfile
*objfile
= cu
->objfile
;
7025 const int decode_for_pst_p
= (pst
!= NULL
);
7026 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7028 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7030 line_ptr
= lh
->statement_program_start
;
7031 line_end
= lh
->statement_program_end
;
7033 /* Read the statement sequences until there's nothing left. */
7034 while (line_ptr
< line_end
)
7036 /* state machine registers */
7037 CORE_ADDR address
= 0;
7038 unsigned int file
= 1;
7039 unsigned int line
= 1;
7040 unsigned int column
= 0;
7041 int is_stmt
= lh
->default_is_stmt
;
7042 int basic_block
= 0;
7043 int end_sequence
= 0;
7045 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7047 /* Start a subfile for the current file of the state machine. */
7048 /* lh->include_dirs and lh->file_names are 0-based, but the
7049 directory and file name numbers in the statement program
7051 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7055 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7057 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7060 /* Decode the table. */
7061 while (!end_sequence
)
7063 op_code
= read_1_byte (abfd
, line_ptr
);
7066 if (op_code
>= lh
->opcode_base
)
7068 /* Special operand. */
7069 adj_opcode
= op_code
- lh
->opcode_base
;
7070 address
+= (adj_opcode
/ lh
->line_range
)
7071 * lh
->minimum_instruction_length
;
7072 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7073 if (lh
->num_file_names
< file
)
7074 dwarf2_debug_line_missing_file_complaint ();
7077 lh
->file_names
[file
- 1].included_p
= 1;
7078 if (!decode_for_pst_p
)
7080 if (last_subfile
!= current_subfile
)
7083 record_line (last_subfile
, 0, address
);
7084 last_subfile
= current_subfile
;
7086 /* Append row to matrix using current values. */
7087 record_line (current_subfile
, line
,
7088 check_cu_functions (address
, cu
));
7093 else switch (op_code
)
7095 case DW_LNS_extended_op
:
7096 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7097 line_ptr
+= bytes_read
;
7098 extended_end
= line_ptr
+ extended_len
;
7099 extended_op
= read_1_byte (abfd
, line_ptr
);
7101 switch (extended_op
)
7103 case DW_LNE_end_sequence
:
7106 if (lh
->num_file_names
< file
)
7107 dwarf2_debug_line_missing_file_complaint ();
7110 lh
->file_names
[file
- 1].included_p
= 1;
7111 if (!decode_for_pst_p
)
7112 record_line (current_subfile
, 0, address
);
7115 case DW_LNE_set_address
:
7116 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7117 line_ptr
+= bytes_read
;
7118 address
+= baseaddr
;
7120 case DW_LNE_define_file
:
7123 unsigned int dir_index
, mod_time
, length
;
7125 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7126 line_ptr
+= bytes_read
;
7128 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7129 line_ptr
+= bytes_read
;
7131 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7132 line_ptr
+= bytes_read
;
7134 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7135 line_ptr
+= bytes_read
;
7136 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7140 complaint (&symfile_complaints
,
7141 _("mangled .debug_line section"));
7144 /* Make sure that we parsed the extended op correctly. If e.g.
7145 we expected a different address size than the producer used,
7146 we may have read the wrong number of bytes. */
7147 if (line_ptr
!= extended_end
)
7149 complaint (&symfile_complaints
,
7150 _("mangled .debug_line section"));
7155 if (lh
->num_file_names
< file
)
7156 dwarf2_debug_line_missing_file_complaint ();
7159 lh
->file_names
[file
- 1].included_p
= 1;
7160 if (!decode_for_pst_p
)
7162 if (last_subfile
!= current_subfile
)
7165 record_line (last_subfile
, 0, address
);
7166 last_subfile
= current_subfile
;
7168 record_line (current_subfile
, line
,
7169 check_cu_functions (address
, cu
));
7174 case DW_LNS_advance_pc
:
7175 address
+= lh
->minimum_instruction_length
7176 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7177 line_ptr
+= bytes_read
;
7179 case DW_LNS_advance_line
:
7180 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7181 line_ptr
+= bytes_read
;
7183 case DW_LNS_set_file
:
7185 /* The arrays lh->include_dirs and lh->file_names are
7186 0-based, but the directory and file name numbers in
7187 the statement program are 1-based. */
7188 struct file_entry
*fe
;
7191 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7192 line_ptr
+= bytes_read
;
7193 if (lh
->num_file_names
< file
)
7194 dwarf2_debug_line_missing_file_complaint ();
7197 fe
= &lh
->file_names
[file
- 1];
7199 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7200 if (!decode_for_pst_p
)
7202 last_subfile
= current_subfile
;
7203 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7208 case DW_LNS_set_column
:
7209 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7210 line_ptr
+= bytes_read
;
7212 case DW_LNS_negate_stmt
:
7213 is_stmt
= (!is_stmt
);
7215 case DW_LNS_set_basic_block
:
7218 /* Add to the address register of the state machine the
7219 address increment value corresponding to special opcode
7220 255. I.e., this value is scaled by the minimum
7221 instruction length since special opcode 255 would have
7222 scaled the the increment. */
7223 case DW_LNS_const_add_pc
:
7224 address
+= (lh
->minimum_instruction_length
7225 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7227 case DW_LNS_fixed_advance_pc
:
7228 address
+= read_2_bytes (abfd
, line_ptr
);
7233 /* Unknown standard opcode, ignore it. */
7236 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7238 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7239 line_ptr
+= bytes_read
;
7246 if (decode_for_pst_p
)
7250 /* Now that we're done scanning the Line Header Program, we can
7251 create the psymtab of each included file. */
7252 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7253 if (lh
->file_names
[file_index
].included_p
== 1)
7255 const struct file_entry fe
= lh
->file_names
[file_index
];
7256 char *include_name
= fe
.name
;
7257 char *dir_name
= NULL
;
7258 char *pst_filename
= pst
->filename
;
7261 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7263 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7265 include_name
= concat (dir_name
, SLASH_STRING
,
7266 include_name
, (char *)NULL
);
7267 make_cleanup (xfree
, include_name
);
7270 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7272 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7273 pst_filename
, (char *)NULL
);
7274 make_cleanup (xfree
, pst_filename
);
7277 if (strcmp (include_name
, pst_filename
) != 0)
7278 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7283 /* Make sure a symtab is created for every file, even files
7284 which contain only variables (i.e. no code with associated
7288 struct file_entry
*fe
;
7290 for (i
= 0; i
< lh
->num_file_names
; i
++)
7293 fe
= &lh
->file_names
[i
];
7295 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7296 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7298 /* Skip the main file; we don't need it, and it must be
7299 allocated last, so that it will show up before the
7300 non-primary symtabs in the objfile's symtab list. */
7301 if (current_subfile
== first_subfile
)
7304 if (current_subfile
->symtab
== NULL
)
7305 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7307 fe
->symtab
= current_subfile
->symtab
;
7312 /* Start a subfile for DWARF. FILENAME is the name of the file and
7313 DIRNAME the name of the source directory which contains FILENAME
7314 or NULL if not known. COMP_DIR is the compilation directory for the
7315 linetable's compilation unit or NULL if not known.
7316 This routine tries to keep line numbers from identical absolute and
7317 relative file names in a common subfile.
7319 Using the `list' example from the GDB testsuite, which resides in
7320 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7321 of /srcdir/list0.c yields the following debugging information for list0.c:
7323 DW_AT_name: /srcdir/list0.c
7324 DW_AT_comp_dir: /compdir
7325 files.files[0].name: list0.h
7326 files.files[0].dir: /srcdir
7327 files.files[1].name: list0.c
7328 files.files[1].dir: /srcdir
7330 The line number information for list0.c has to end up in a single
7331 subfile, so that `break /srcdir/list0.c:1' works as expected.
7332 start_subfile will ensure that this happens provided that we pass the
7333 concatenation of files.files[1].dir and files.files[1].name as the
7337 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7341 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7342 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7343 second argument to start_subfile. To be consistent, we do the
7344 same here. In order not to lose the line information directory,
7345 we concatenate it to the filename when it makes sense.
7346 Note that the Dwarf3 standard says (speaking of filenames in line
7347 information): ``The directory index is ignored for file names
7348 that represent full path names''. Thus ignoring dirname in the
7349 `else' branch below isn't an issue. */
7351 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7352 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7354 fullname
= filename
;
7356 start_subfile (fullname
, comp_dir
);
7358 if (fullname
!= filename
)
7363 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7364 struct dwarf2_cu
*cu
)
7366 struct objfile
*objfile
= cu
->objfile
;
7367 struct comp_unit_head
*cu_header
= &cu
->header
;
7369 /* NOTE drow/2003-01-30: There used to be a comment and some special
7370 code here to turn a symbol with DW_AT_external and a
7371 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7372 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7373 with some versions of binutils) where shared libraries could have
7374 relocations against symbols in their debug information - the
7375 minimal symbol would have the right address, but the debug info
7376 would not. It's no longer necessary, because we will explicitly
7377 apply relocations when we read in the debug information now. */
7379 /* A DW_AT_location attribute with no contents indicates that a
7380 variable has been optimized away. */
7381 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7383 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7387 /* Handle one degenerate form of location expression specially, to
7388 preserve GDB's previous behavior when section offsets are
7389 specified. If this is just a DW_OP_addr then mark this symbol
7392 if (attr_form_is_block (attr
)
7393 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7394 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7398 SYMBOL_VALUE_ADDRESS (sym
) =
7399 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7400 fixup_symbol_section (sym
, objfile
);
7401 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7402 SYMBOL_SECTION (sym
));
7403 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7407 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7408 expression evaluator, and use LOC_COMPUTED only when necessary
7409 (i.e. when the value of a register or memory location is
7410 referenced, or a thread-local block, etc.). Then again, it might
7411 not be worthwhile. I'm assuming that it isn't unless performance
7412 or memory numbers show me otherwise. */
7414 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7415 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7418 /* Given a pointer to a DWARF information entry, figure out if we need
7419 to make a symbol table entry for it, and if so, create a new entry
7420 and return a pointer to it.
7421 If TYPE is NULL, determine symbol type from the die, otherwise
7422 used the passed type. */
7424 static struct symbol
*
7425 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7427 struct objfile
*objfile
= cu
->objfile
;
7428 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7429 struct symbol
*sym
= NULL
;
7431 struct attribute
*attr
= NULL
;
7432 struct attribute
*attr2
= NULL
;
7435 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7437 if (die
->tag
!= DW_TAG_namespace
)
7438 name
= dwarf2_linkage_name (die
, cu
);
7440 name
= TYPE_NAME (type
);
7444 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7445 sizeof (struct symbol
));
7446 OBJSTAT (objfile
, n_syms
++);
7447 memset (sym
, 0, sizeof (struct symbol
));
7449 /* Cache this symbol's name and the name's demangled form (if any). */
7450 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7451 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7453 /* Default assumptions.
7454 Use the passed type or decode it from the die. */
7455 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7456 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7458 SYMBOL_TYPE (sym
) = type
;
7460 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7461 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7464 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7467 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7470 int file_index
= DW_UNSND (attr
);
7471 if (cu
->line_header
== NULL
7472 || file_index
> cu
->line_header
->num_file_names
)
7473 complaint (&symfile_complaints
,
7474 _("file index out of range"));
7475 else if (file_index
> 0)
7477 struct file_entry
*fe
;
7478 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7479 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7486 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7489 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7491 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7493 case DW_TAG_subprogram
:
7494 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7496 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7497 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7498 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7499 || cu
->language
== language_ada
)
7501 /* Subprograms marked external are stored as a global symbol.
7502 Ada subprograms, whether marked external or not, are always
7503 stored as a global symbol, because we want to be able to
7504 access them globally. For instance, we want to be able
7505 to break on a nested subprogram without having to
7506 specify the context. */
7507 add_symbol_to_list (sym
, &global_symbols
);
7511 add_symbol_to_list (sym
, cu
->list_in_scope
);
7514 case DW_TAG_variable
:
7515 /* Compilation with minimal debug info may result in variables
7516 with missing type entries. Change the misleading `void' type
7517 to something sensible. */
7518 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7520 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7522 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7525 dwarf2_const_value (attr
, sym
, cu
);
7526 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7527 if (attr2
&& (DW_UNSND (attr2
) != 0))
7528 add_symbol_to_list (sym
, &global_symbols
);
7530 add_symbol_to_list (sym
, cu
->list_in_scope
);
7533 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7536 var_decode_location (attr
, sym
, cu
);
7537 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7538 if (attr2
&& (DW_UNSND (attr2
) != 0))
7539 add_symbol_to_list (sym
, &global_symbols
);
7541 add_symbol_to_list (sym
, cu
->list_in_scope
);
7545 /* We do not know the address of this symbol.
7546 If it is an external symbol and we have type information
7547 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7548 The address of the variable will then be determined from
7549 the minimal symbol table whenever the variable is
7551 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7552 if (attr2
&& (DW_UNSND (attr2
) != 0)
7553 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7555 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7556 add_symbol_to_list (sym
, &global_symbols
);
7560 case DW_TAG_formal_parameter
:
7561 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7564 var_decode_location (attr
, sym
, cu
);
7565 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
7566 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
7567 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
7569 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7572 dwarf2_const_value (attr
, sym
, cu
);
7574 add_symbol_to_list (sym
, cu
->list_in_scope
);
7576 case DW_TAG_unspecified_parameters
:
7577 /* From varargs functions; gdb doesn't seem to have any
7578 interest in this information, so just ignore it for now.
7581 case DW_TAG_class_type
:
7582 case DW_TAG_interface_type
:
7583 case DW_TAG_structure_type
:
7584 case DW_TAG_union_type
:
7585 case DW_TAG_set_type
:
7586 case DW_TAG_enumeration_type
:
7587 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7588 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7590 /* Make sure that the symbol includes appropriate enclosing
7591 classes/namespaces in its name. These are calculated in
7592 read_structure_type, and the correct name is saved in
7595 if (cu
->language
== language_cplus
7596 || cu
->language
== language_java
)
7598 struct type
*type
= SYMBOL_TYPE (sym
);
7600 if (TYPE_TAG_NAME (type
) != NULL
)
7602 /* FIXME: carlton/2003-11-10: Should this use
7603 SYMBOL_SET_NAMES instead? (The same problem also
7604 arises further down in this function.) */
7605 /* The type's name is already allocated along with
7606 this objfile, so we don't need to duplicate it
7608 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7613 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7614 really ever be static objects: otherwise, if you try
7615 to, say, break of a class's method and you're in a file
7616 which doesn't mention that class, it won't work unless
7617 the check for all static symbols in lookup_symbol_aux
7618 saves you. See the OtherFileClass tests in
7619 gdb.c++/namespace.exp. */
7621 struct pending
**list_to_add
;
7623 list_to_add
= (cu
->list_in_scope
== &file_symbols
7624 && (cu
->language
== language_cplus
7625 || cu
->language
== language_java
)
7626 ? &global_symbols
: cu
->list_in_scope
);
7628 add_symbol_to_list (sym
, list_to_add
);
7630 /* The semantics of C++ state that "struct foo { ... }" also
7631 defines a typedef for "foo". A Java class declaration also
7632 defines a typedef for the class. Synthesize a typedef symbol
7633 so that "ptype foo" works as expected. */
7634 if (cu
->language
== language_cplus
7635 || cu
->language
== language_java
7636 || cu
->language
== language_ada
)
7638 struct symbol
*typedef_sym
= (struct symbol
*)
7639 obstack_alloc (&objfile
->objfile_obstack
,
7640 sizeof (struct symbol
));
7641 *typedef_sym
= *sym
;
7642 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
7643 /* The symbol's name is already allocated along with
7644 this objfile, so we don't need to duplicate it for
7646 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7647 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7648 add_symbol_to_list (typedef_sym
, list_to_add
);
7652 case DW_TAG_typedef
:
7653 if (processing_has_namespace_info
7654 && processing_current_prefix
[0] != '\0')
7656 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7657 processing_current_prefix
,
7660 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7661 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7662 add_symbol_to_list (sym
, cu
->list_in_scope
);
7664 case DW_TAG_base_type
:
7665 case DW_TAG_subrange_type
:
7666 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7667 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7668 add_symbol_to_list (sym
, cu
->list_in_scope
);
7670 case DW_TAG_enumerator
:
7671 if (processing_has_namespace_info
7672 && processing_current_prefix
[0] != '\0')
7674 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7675 processing_current_prefix
,
7678 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7681 dwarf2_const_value (attr
, sym
, cu
);
7684 /* NOTE: carlton/2003-11-10: See comment above in the
7685 DW_TAG_class_type, etc. block. */
7687 struct pending
**list_to_add
;
7689 list_to_add
= (cu
->list_in_scope
== &file_symbols
7690 && (cu
->language
== language_cplus
7691 || cu
->language
== language_java
)
7692 ? &global_symbols
: cu
->list_in_scope
);
7694 add_symbol_to_list (sym
, list_to_add
);
7697 case DW_TAG_namespace
:
7698 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7699 add_symbol_to_list (sym
, &global_symbols
);
7702 /* Not a tag we recognize. Hopefully we aren't processing
7703 trash data, but since we must specifically ignore things
7704 we don't recognize, there is nothing else we should do at
7706 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7707 dwarf_tag_name (die
->tag
));
7714 /* Copy constant value from an attribute to a symbol. */
7717 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7718 struct dwarf2_cu
*cu
)
7720 struct objfile
*objfile
= cu
->objfile
;
7721 struct comp_unit_head
*cu_header
= &cu
->header
;
7722 struct dwarf_block
*blk
;
7727 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7728 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7729 cu_header
->addr_size
,
7730 TYPE_LENGTH (SYMBOL_TYPE
7732 SYMBOL_VALUE_BYTES (sym
) =
7733 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7734 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7735 it's body - store_unsigned_integer. */
7736 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7738 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7741 /* DW_STRING is already allocated on the obstack, point directly
7743 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7744 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7746 case DW_FORM_block1
:
7747 case DW_FORM_block2
:
7748 case DW_FORM_block4
:
7750 blk
= DW_BLOCK (attr
);
7751 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7752 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7754 TYPE_LENGTH (SYMBOL_TYPE
7756 SYMBOL_VALUE_BYTES (sym
) =
7757 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7758 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7759 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7762 /* The DW_AT_const_value attributes are supposed to carry the
7763 symbol's value "represented as it would be on the target
7764 architecture." By the time we get here, it's already been
7765 converted to host endianness, so we just need to sign- or
7766 zero-extend it as appropriate. */
7768 dwarf2_const_value_data (attr
, sym
, 8);
7771 dwarf2_const_value_data (attr
, sym
, 16);
7774 dwarf2_const_value_data (attr
, sym
, 32);
7777 dwarf2_const_value_data (attr
, sym
, 64);
7781 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7782 SYMBOL_CLASS (sym
) = LOC_CONST
;
7786 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7787 SYMBOL_CLASS (sym
) = LOC_CONST
;
7791 complaint (&symfile_complaints
,
7792 _("unsupported const value attribute form: '%s'"),
7793 dwarf_form_name (attr
->form
));
7794 SYMBOL_VALUE (sym
) = 0;
7795 SYMBOL_CLASS (sym
) = LOC_CONST
;
7801 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7802 or zero-extend it as appropriate for the symbol's type. */
7804 dwarf2_const_value_data (struct attribute
*attr
,
7808 LONGEST l
= DW_UNSND (attr
);
7810 if (bits
< sizeof (l
) * 8)
7812 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7813 l
&= ((LONGEST
) 1 << bits
) - 1;
7815 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7818 SYMBOL_VALUE (sym
) = l
;
7819 SYMBOL_CLASS (sym
) = LOC_CONST
;
7823 /* Return the type of the die in question using its DW_AT_type attribute. */
7825 static struct type
*
7826 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7828 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7830 struct attribute
*type_attr
;
7831 struct die_info
*type_die
;
7833 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7836 /* A missing DW_AT_type represents a void type. */
7837 return builtin_type (gdbarch
)->builtin_void
;
7840 type_die
= follow_die_ref (die
, type_attr
, cu
);
7842 type
= tag_type_to_type (type_die
, cu
);
7845 dump_die (type_die
);
7846 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7852 /* Return the containing type of the die in question using its
7853 DW_AT_containing_type attribute. */
7855 static struct type
*
7856 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7858 struct type
*type
= NULL
;
7859 struct attribute
*type_attr
;
7860 struct die_info
*type_die
= NULL
;
7862 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7865 type_die
= follow_die_ref (die
, type_attr
, cu
);
7866 type
= tag_type_to_type (type_die
, cu
);
7871 dump_die (type_die
);
7872 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7878 static struct type
*
7879 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7887 read_type_die (die
, cu
);
7891 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7899 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7901 char *prefix
= determine_prefix (die
, cu
);
7902 const char *old_prefix
= processing_current_prefix
;
7903 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
7904 processing_current_prefix
= prefix
;
7908 case DW_TAG_class_type
:
7909 case DW_TAG_interface_type
:
7910 case DW_TAG_structure_type
:
7911 case DW_TAG_union_type
:
7912 read_structure_type (die
, cu
);
7914 case DW_TAG_enumeration_type
:
7915 read_enumeration_type (die
, cu
);
7917 case DW_TAG_subprogram
:
7918 case DW_TAG_subroutine_type
:
7919 read_subroutine_type (die
, cu
);
7921 case DW_TAG_array_type
:
7922 read_array_type (die
, cu
);
7924 case DW_TAG_set_type
:
7925 read_set_type (die
, cu
);
7927 case DW_TAG_pointer_type
:
7928 read_tag_pointer_type (die
, cu
);
7930 case DW_TAG_ptr_to_member_type
:
7931 read_tag_ptr_to_member_type (die
, cu
);
7933 case DW_TAG_reference_type
:
7934 read_tag_reference_type (die
, cu
);
7936 case DW_TAG_const_type
:
7937 read_tag_const_type (die
, cu
);
7939 case DW_TAG_volatile_type
:
7940 read_tag_volatile_type (die
, cu
);
7942 case DW_TAG_string_type
:
7943 read_tag_string_type (die
, cu
);
7945 case DW_TAG_typedef
:
7946 read_typedef (die
, cu
);
7948 case DW_TAG_subrange_type
:
7949 read_subrange_type (die
, cu
);
7951 case DW_TAG_base_type
:
7952 read_base_type (die
, cu
);
7954 case DW_TAG_unspecified_type
:
7955 read_unspecified_type (die
, cu
);
7958 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7959 dwarf_tag_name (die
->tag
));
7963 processing_current_prefix
= old_prefix
;
7964 do_cleanups (back_to
);
7967 /* Return the name of the namespace/class that DIE is defined within,
7968 or "" if we can't tell. The caller should xfree the result. */
7970 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7971 therein) for an example of how to use this function to deal with
7972 DW_AT_specification. */
7975 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7977 struct die_info
*parent
;
7979 if (cu
->language
!= language_cplus
7980 && cu
->language
!= language_java
)
7983 parent
= die
->parent
;
7987 return xstrdup ("");
7991 switch (parent
->tag
) {
7992 case DW_TAG_namespace
:
7994 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7995 before doing this check? */
7996 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
7998 return xstrdup (TYPE_TAG_NAME (parent
->type
));
8003 char *parent_prefix
= determine_prefix (parent
, cu
);
8004 char *retval
= typename_concat (NULL
, parent_prefix
,
8005 namespace_name (parent
, &dummy
,
8008 xfree (parent_prefix
);
8013 case DW_TAG_class_type
:
8014 case DW_TAG_interface_type
:
8015 case DW_TAG_structure_type
:
8017 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
8019 return xstrdup (TYPE_TAG_NAME (parent
->type
));
8023 const char *old_prefix
= processing_current_prefix
;
8024 char *new_prefix
= determine_prefix (parent
, cu
);
8027 processing_current_prefix
= new_prefix
;
8028 retval
= determine_class_name (parent
, cu
);
8029 processing_current_prefix
= old_prefix
;
8036 return determine_prefix (parent
, cu
);
8041 /* Return a newly-allocated string formed by concatenating PREFIX and
8042 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8043 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8044 perform an obconcat, otherwise allocate storage for the result. The CU argument
8045 is used to determine the language and hence, the appropriate separator. */
8047 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8050 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8051 struct dwarf2_cu
*cu
)
8055 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8057 else if (cu
->language
== language_java
)
8064 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8069 strcpy (retval
, prefix
);
8070 strcat (retval
, sep
);
8073 strcat (retval
, suffix
);
8079 /* We have an obstack. */
8080 return obconcat (obs
, prefix
, sep
, suffix
);
8086 copy_die (struct die_info
*old_die
)
8088 struct die_info
*new_die
;
8091 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8092 memset (new_die
, 0, sizeof (struct die_info
));
8094 new_die
->tag
= old_die
->tag
;
8095 new_die
->has_children
= old_die
->has_children
;
8096 new_die
->abbrev
= old_die
->abbrev
;
8097 new_die
->offset
= old_die
->offset
;
8098 new_die
->type
= NULL
;
8100 num_attrs
= old_die
->num_attrs
;
8101 new_die
->num_attrs
= num_attrs
;
8102 new_die
->attrs
= (struct attribute
*)
8103 xmalloc (num_attrs
* sizeof (struct attribute
));
8105 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
8107 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
8108 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
8109 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
8112 new_die
->next
= NULL
;
8117 /* Return sibling of die, NULL if no sibling. */
8119 static struct die_info
*
8120 sibling_die (struct die_info
*die
)
8122 return die
->sibling
;
8125 /* Get linkage name of a die, return NULL if not found. */
8128 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8130 struct attribute
*attr
;
8132 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8133 if (attr
&& DW_STRING (attr
))
8134 return DW_STRING (attr
);
8135 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8136 if (attr
&& DW_STRING (attr
))
8137 return DW_STRING (attr
);
8141 /* Get name of a die, return NULL if not found. */
8144 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8146 struct attribute
*attr
;
8148 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8149 if (attr
&& DW_STRING (attr
))
8150 return DW_STRING (attr
);
8154 /* Return the die that this die in an extension of, or NULL if there
8157 static struct die_info
*
8158 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
8160 struct attribute
*attr
;
8162 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
8166 return follow_die_ref (die
, attr
, cu
);
8169 /* Convert a DIE tag into its string name. */
8172 dwarf_tag_name (unsigned tag
)
8176 case DW_TAG_padding
:
8177 return "DW_TAG_padding";
8178 case DW_TAG_array_type
:
8179 return "DW_TAG_array_type";
8180 case DW_TAG_class_type
:
8181 return "DW_TAG_class_type";
8182 case DW_TAG_entry_point
:
8183 return "DW_TAG_entry_point";
8184 case DW_TAG_enumeration_type
:
8185 return "DW_TAG_enumeration_type";
8186 case DW_TAG_formal_parameter
:
8187 return "DW_TAG_formal_parameter";
8188 case DW_TAG_imported_declaration
:
8189 return "DW_TAG_imported_declaration";
8191 return "DW_TAG_label";
8192 case DW_TAG_lexical_block
:
8193 return "DW_TAG_lexical_block";
8195 return "DW_TAG_member";
8196 case DW_TAG_pointer_type
:
8197 return "DW_TAG_pointer_type";
8198 case DW_TAG_reference_type
:
8199 return "DW_TAG_reference_type";
8200 case DW_TAG_compile_unit
:
8201 return "DW_TAG_compile_unit";
8202 case DW_TAG_string_type
:
8203 return "DW_TAG_string_type";
8204 case DW_TAG_structure_type
:
8205 return "DW_TAG_structure_type";
8206 case DW_TAG_subroutine_type
:
8207 return "DW_TAG_subroutine_type";
8208 case DW_TAG_typedef
:
8209 return "DW_TAG_typedef";
8210 case DW_TAG_union_type
:
8211 return "DW_TAG_union_type";
8212 case DW_TAG_unspecified_parameters
:
8213 return "DW_TAG_unspecified_parameters";
8214 case DW_TAG_variant
:
8215 return "DW_TAG_variant";
8216 case DW_TAG_common_block
:
8217 return "DW_TAG_common_block";
8218 case DW_TAG_common_inclusion
:
8219 return "DW_TAG_common_inclusion";
8220 case DW_TAG_inheritance
:
8221 return "DW_TAG_inheritance";
8222 case DW_TAG_inlined_subroutine
:
8223 return "DW_TAG_inlined_subroutine";
8225 return "DW_TAG_module";
8226 case DW_TAG_ptr_to_member_type
:
8227 return "DW_TAG_ptr_to_member_type";
8228 case DW_TAG_set_type
:
8229 return "DW_TAG_set_type";
8230 case DW_TAG_subrange_type
:
8231 return "DW_TAG_subrange_type";
8232 case DW_TAG_with_stmt
:
8233 return "DW_TAG_with_stmt";
8234 case DW_TAG_access_declaration
:
8235 return "DW_TAG_access_declaration";
8236 case DW_TAG_base_type
:
8237 return "DW_TAG_base_type";
8238 case DW_TAG_catch_block
:
8239 return "DW_TAG_catch_block";
8240 case DW_TAG_const_type
:
8241 return "DW_TAG_const_type";
8242 case DW_TAG_constant
:
8243 return "DW_TAG_constant";
8244 case DW_TAG_enumerator
:
8245 return "DW_TAG_enumerator";
8246 case DW_TAG_file_type
:
8247 return "DW_TAG_file_type";
8249 return "DW_TAG_friend";
8250 case DW_TAG_namelist
:
8251 return "DW_TAG_namelist";
8252 case DW_TAG_namelist_item
:
8253 return "DW_TAG_namelist_item";
8254 case DW_TAG_packed_type
:
8255 return "DW_TAG_packed_type";
8256 case DW_TAG_subprogram
:
8257 return "DW_TAG_subprogram";
8258 case DW_TAG_template_type_param
:
8259 return "DW_TAG_template_type_param";
8260 case DW_TAG_template_value_param
:
8261 return "DW_TAG_template_value_param";
8262 case DW_TAG_thrown_type
:
8263 return "DW_TAG_thrown_type";
8264 case DW_TAG_try_block
:
8265 return "DW_TAG_try_block";
8266 case DW_TAG_variant_part
:
8267 return "DW_TAG_variant_part";
8268 case DW_TAG_variable
:
8269 return "DW_TAG_variable";
8270 case DW_TAG_volatile_type
:
8271 return "DW_TAG_volatile_type";
8272 case DW_TAG_dwarf_procedure
:
8273 return "DW_TAG_dwarf_procedure";
8274 case DW_TAG_restrict_type
:
8275 return "DW_TAG_restrict_type";
8276 case DW_TAG_interface_type
:
8277 return "DW_TAG_interface_type";
8278 case DW_TAG_namespace
:
8279 return "DW_TAG_namespace";
8280 case DW_TAG_imported_module
:
8281 return "DW_TAG_imported_module";
8282 case DW_TAG_unspecified_type
:
8283 return "DW_TAG_unspecified_type";
8284 case DW_TAG_partial_unit
:
8285 return "DW_TAG_partial_unit";
8286 case DW_TAG_imported_unit
:
8287 return "DW_TAG_imported_unit";
8288 case DW_TAG_condition
:
8289 return "DW_TAG_condition";
8290 case DW_TAG_shared_type
:
8291 return "DW_TAG_shared_type";
8292 case DW_TAG_MIPS_loop
:
8293 return "DW_TAG_MIPS_loop";
8294 case DW_TAG_HP_array_descriptor
:
8295 return "DW_TAG_HP_array_descriptor";
8296 case DW_TAG_format_label
:
8297 return "DW_TAG_format_label";
8298 case DW_TAG_function_template
:
8299 return "DW_TAG_function_template";
8300 case DW_TAG_class_template
:
8301 return "DW_TAG_class_template";
8302 case DW_TAG_GNU_BINCL
:
8303 return "DW_TAG_GNU_BINCL";
8304 case DW_TAG_GNU_EINCL
:
8305 return "DW_TAG_GNU_EINCL";
8306 case DW_TAG_upc_shared_type
:
8307 return "DW_TAG_upc_shared_type";
8308 case DW_TAG_upc_strict_type
:
8309 return "DW_TAG_upc_strict_type";
8310 case DW_TAG_upc_relaxed_type
:
8311 return "DW_TAG_upc_relaxed_type";
8312 case DW_TAG_PGI_kanji_type
:
8313 return "DW_TAG_PGI_kanji_type";
8314 case DW_TAG_PGI_interface_block
:
8315 return "DW_TAG_PGI_interface_block";
8317 return "DW_TAG_<unknown>";
8321 /* Convert a DWARF attribute code into its string name. */
8324 dwarf_attr_name (unsigned attr
)
8329 return "DW_AT_sibling";
8330 case DW_AT_location
:
8331 return "DW_AT_location";
8333 return "DW_AT_name";
8334 case DW_AT_ordering
:
8335 return "DW_AT_ordering";
8336 case DW_AT_subscr_data
:
8337 return "DW_AT_subscr_data";
8338 case DW_AT_byte_size
:
8339 return "DW_AT_byte_size";
8340 case DW_AT_bit_offset
:
8341 return "DW_AT_bit_offset";
8342 case DW_AT_bit_size
:
8343 return "DW_AT_bit_size";
8344 case DW_AT_element_list
:
8345 return "DW_AT_element_list";
8346 case DW_AT_stmt_list
:
8347 return "DW_AT_stmt_list";
8349 return "DW_AT_low_pc";
8351 return "DW_AT_high_pc";
8352 case DW_AT_language
:
8353 return "DW_AT_language";
8355 return "DW_AT_member";
8357 return "DW_AT_discr";
8358 case DW_AT_discr_value
:
8359 return "DW_AT_discr_value";
8360 case DW_AT_visibility
:
8361 return "DW_AT_visibility";
8363 return "DW_AT_import";
8364 case DW_AT_string_length
:
8365 return "DW_AT_string_length";
8366 case DW_AT_common_reference
:
8367 return "DW_AT_common_reference";
8368 case DW_AT_comp_dir
:
8369 return "DW_AT_comp_dir";
8370 case DW_AT_const_value
:
8371 return "DW_AT_const_value";
8372 case DW_AT_containing_type
:
8373 return "DW_AT_containing_type";
8374 case DW_AT_default_value
:
8375 return "DW_AT_default_value";
8377 return "DW_AT_inline";
8378 case DW_AT_is_optional
:
8379 return "DW_AT_is_optional";
8380 case DW_AT_lower_bound
:
8381 return "DW_AT_lower_bound";
8382 case DW_AT_producer
:
8383 return "DW_AT_producer";
8384 case DW_AT_prototyped
:
8385 return "DW_AT_prototyped";
8386 case DW_AT_return_addr
:
8387 return "DW_AT_return_addr";
8388 case DW_AT_start_scope
:
8389 return "DW_AT_start_scope";
8390 case DW_AT_bit_stride
:
8391 return "DW_AT_bit_stride";
8392 case DW_AT_upper_bound
:
8393 return "DW_AT_upper_bound";
8394 case DW_AT_abstract_origin
:
8395 return "DW_AT_abstract_origin";
8396 case DW_AT_accessibility
:
8397 return "DW_AT_accessibility";
8398 case DW_AT_address_class
:
8399 return "DW_AT_address_class";
8400 case DW_AT_artificial
:
8401 return "DW_AT_artificial";
8402 case DW_AT_base_types
:
8403 return "DW_AT_base_types";
8404 case DW_AT_calling_convention
:
8405 return "DW_AT_calling_convention";
8407 return "DW_AT_count";
8408 case DW_AT_data_member_location
:
8409 return "DW_AT_data_member_location";
8410 case DW_AT_decl_column
:
8411 return "DW_AT_decl_column";
8412 case DW_AT_decl_file
:
8413 return "DW_AT_decl_file";
8414 case DW_AT_decl_line
:
8415 return "DW_AT_decl_line";
8416 case DW_AT_declaration
:
8417 return "DW_AT_declaration";
8418 case DW_AT_discr_list
:
8419 return "DW_AT_discr_list";
8420 case DW_AT_encoding
:
8421 return "DW_AT_encoding";
8422 case DW_AT_external
:
8423 return "DW_AT_external";
8424 case DW_AT_frame_base
:
8425 return "DW_AT_frame_base";
8427 return "DW_AT_friend";
8428 case DW_AT_identifier_case
:
8429 return "DW_AT_identifier_case";
8430 case DW_AT_macro_info
:
8431 return "DW_AT_macro_info";
8432 case DW_AT_namelist_items
:
8433 return "DW_AT_namelist_items";
8434 case DW_AT_priority
:
8435 return "DW_AT_priority";
8437 return "DW_AT_segment";
8438 case DW_AT_specification
:
8439 return "DW_AT_specification";
8440 case DW_AT_static_link
:
8441 return "DW_AT_static_link";
8443 return "DW_AT_type";
8444 case DW_AT_use_location
:
8445 return "DW_AT_use_location";
8446 case DW_AT_variable_parameter
:
8447 return "DW_AT_variable_parameter";
8448 case DW_AT_virtuality
:
8449 return "DW_AT_virtuality";
8450 case DW_AT_vtable_elem_location
:
8451 return "DW_AT_vtable_elem_location";
8452 /* DWARF 3 values. */
8453 case DW_AT_allocated
:
8454 return "DW_AT_allocated";
8455 case DW_AT_associated
:
8456 return "DW_AT_associated";
8457 case DW_AT_data_location
:
8458 return "DW_AT_data_location";
8459 case DW_AT_byte_stride
:
8460 return "DW_AT_byte_stride";
8461 case DW_AT_entry_pc
:
8462 return "DW_AT_entry_pc";
8463 case DW_AT_use_UTF8
:
8464 return "DW_AT_use_UTF8";
8465 case DW_AT_extension
:
8466 return "DW_AT_extension";
8468 return "DW_AT_ranges";
8469 case DW_AT_trampoline
:
8470 return "DW_AT_trampoline";
8471 case DW_AT_call_column
:
8472 return "DW_AT_call_column";
8473 case DW_AT_call_file
:
8474 return "DW_AT_call_file";
8475 case DW_AT_call_line
:
8476 return "DW_AT_call_line";
8477 case DW_AT_description
:
8478 return "DW_AT_description";
8479 case DW_AT_binary_scale
:
8480 return "DW_AT_binary_scale";
8481 case DW_AT_decimal_scale
:
8482 return "DW_AT_decimal_scale";
8484 return "DW_AT_small";
8485 case DW_AT_decimal_sign
:
8486 return "DW_AT_decimal_sign";
8487 case DW_AT_digit_count
:
8488 return "DW_AT_digit_count";
8489 case DW_AT_picture_string
:
8490 return "DW_AT_picture_string";
8492 return "DW_AT_mutable";
8493 case DW_AT_threads_scaled
:
8494 return "DW_AT_threads_scaled";
8495 case DW_AT_explicit
:
8496 return "DW_AT_explicit";
8497 case DW_AT_object_pointer
:
8498 return "DW_AT_object_pointer";
8499 case DW_AT_endianity
:
8500 return "DW_AT_endianity";
8501 case DW_AT_elemental
:
8502 return "DW_AT_elemental";
8504 return "DW_AT_pure";
8505 case DW_AT_recursive
:
8506 return "DW_AT_recursive";
8508 /* SGI/MIPS extensions. */
8509 case DW_AT_MIPS_fde
:
8510 return "DW_AT_MIPS_fde";
8511 case DW_AT_MIPS_loop_begin
:
8512 return "DW_AT_MIPS_loop_begin";
8513 case DW_AT_MIPS_tail_loop_begin
:
8514 return "DW_AT_MIPS_tail_loop_begin";
8515 case DW_AT_MIPS_epilog_begin
:
8516 return "DW_AT_MIPS_epilog_begin";
8517 case DW_AT_MIPS_loop_unroll_factor
:
8518 return "DW_AT_MIPS_loop_unroll_factor";
8519 case DW_AT_MIPS_software_pipeline_depth
:
8520 return "DW_AT_MIPS_software_pipeline_depth";
8521 case DW_AT_MIPS_linkage_name
:
8522 return "DW_AT_MIPS_linkage_name";
8523 case DW_AT_MIPS_stride
:
8524 return "DW_AT_MIPS_stride";
8525 case DW_AT_MIPS_abstract_name
:
8526 return "DW_AT_MIPS_abstract_name";
8527 case DW_AT_MIPS_clone_origin
:
8528 return "DW_AT_MIPS_clone_origin";
8529 case DW_AT_MIPS_has_inlines
:
8530 return "DW_AT_MIPS_has_inlines";
8532 /* HP extensions. */
8533 case DW_AT_HP_block_index
:
8534 return "DW_AT_HP_block_index";
8535 case DW_AT_HP_unmodifiable
:
8536 return "DW_AT_HP_unmodifiable";
8537 case DW_AT_HP_actuals_stmt_list
:
8538 return "DW_AT_HP_actuals_stmt_list";
8539 case DW_AT_HP_proc_per_section
:
8540 return "DW_AT_HP_proc_per_section";
8541 case DW_AT_HP_raw_data_ptr
:
8542 return "DW_AT_HP_raw_data_ptr";
8543 case DW_AT_HP_pass_by_reference
:
8544 return "DW_AT_HP_pass_by_reference";
8545 case DW_AT_HP_opt_level
:
8546 return "DW_AT_HP_opt_level";
8547 case DW_AT_HP_prof_version_id
:
8548 return "DW_AT_HP_prof_version_id";
8549 case DW_AT_HP_opt_flags
:
8550 return "DW_AT_HP_opt_flags";
8551 case DW_AT_HP_cold_region_low_pc
:
8552 return "DW_AT_HP_cold_region_low_pc";
8553 case DW_AT_HP_cold_region_high_pc
:
8554 return "DW_AT_HP_cold_region_high_pc";
8555 case DW_AT_HP_all_variables_modifiable
:
8556 return "DW_AT_HP_all_variables_modifiable";
8557 case DW_AT_HP_linkage_name
:
8558 return "DW_AT_HP_linkage_name";
8559 case DW_AT_HP_prof_flags
:
8560 return "DW_AT_HP_prof_flags";
8561 /* GNU extensions. */
8562 case DW_AT_sf_names
:
8563 return "DW_AT_sf_names";
8564 case DW_AT_src_info
:
8565 return "DW_AT_src_info";
8566 case DW_AT_mac_info
:
8567 return "DW_AT_mac_info";
8568 case DW_AT_src_coords
:
8569 return "DW_AT_src_coords";
8570 case DW_AT_body_begin
:
8571 return "DW_AT_body_begin";
8572 case DW_AT_body_end
:
8573 return "DW_AT_body_end";
8574 case DW_AT_GNU_vector
:
8575 return "DW_AT_GNU_vector";
8576 /* VMS extensions. */
8577 case DW_AT_VMS_rtnbeg_pd_address
:
8578 return "DW_AT_VMS_rtnbeg_pd_address";
8579 /* UPC extension. */
8580 case DW_AT_upc_threads_scaled
:
8581 return "DW_AT_upc_threads_scaled";
8582 /* PGI (STMicroelectronics) extensions. */
8583 case DW_AT_PGI_lbase
:
8584 return "DW_AT_PGI_lbase";
8585 case DW_AT_PGI_soffset
:
8586 return "DW_AT_PGI_soffset";
8587 case DW_AT_PGI_lstride
:
8588 return "DW_AT_PGI_lstride";
8590 return "DW_AT_<unknown>";
8594 /* Convert a DWARF value form code into its string name. */
8597 dwarf_form_name (unsigned form
)
8602 return "DW_FORM_addr";
8603 case DW_FORM_block2
:
8604 return "DW_FORM_block2";
8605 case DW_FORM_block4
:
8606 return "DW_FORM_block4";
8608 return "DW_FORM_data2";
8610 return "DW_FORM_data4";
8612 return "DW_FORM_data8";
8613 case DW_FORM_string
:
8614 return "DW_FORM_string";
8616 return "DW_FORM_block";
8617 case DW_FORM_block1
:
8618 return "DW_FORM_block1";
8620 return "DW_FORM_data1";
8622 return "DW_FORM_flag";
8624 return "DW_FORM_sdata";
8626 return "DW_FORM_strp";
8628 return "DW_FORM_udata";
8629 case DW_FORM_ref_addr
:
8630 return "DW_FORM_ref_addr";
8632 return "DW_FORM_ref1";
8634 return "DW_FORM_ref2";
8636 return "DW_FORM_ref4";
8638 return "DW_FORM_ref8";
8639 case DW_FORM_ref_udata
:
8640 return "DW_FORM_ref_udata";
8641 case DW_FORM_indirect
:
8642 return "DW_FORM_indirect";
8644 return "DW_FORM_<unknown>";
8648 /* Convert a DWARF stack opcode into its string name. */
8651 dwarf_stack_op_name (unsigned op
)
8656 return "DW_OP_addr";
8658 return "DW_OP_deref";
8660 return "DW_OP_const1u";
8662 return "DW_OP_const1s";
8664 return "DW_OP_const2u";
8666 return "DW_OP_const2s";
8668 return "DW_OP_const4u";
8670 return "DW_OP_const4s";
8672 return "DW_OP_const8u";
8674 return "DW_OP_const8s";
8676 return "DW_OP_constu";
8678 return "DW_OP_consts";
8682 return "DW_OP_drop";
8684 return "DW_OP_over";
8686 return "DW_OP_pick";
8688 return "DW_OP_swap";
8692 return "DW_OP_xderef";
8700 return "DW_OP_minus";
8712 return "DW_OP_plus";
8713 case DW_OP_plus_uconst
:
8714 return "DW_OP_plus_uconst";
8720 return "DW_OP_shra";
8738 return "DW_OP_skip";
8740 return "DW_OP_lit0";
8742 return "DW_OP_lit1";
8744 return "DW_OP_lit2";
8746 return "DW_OP_lit3";
8748 return "DW_OP_lit4";
8750 return "DW_OP_lit5";
8752 return "DW_OP_lit6";
8754 return "DW_OP_lit7";
8756 return "DW_OP_lit8";
8758 return "DW_OP_lit9";
8760 return "DW_OP_lit10";
8762 return "DW_OP_lit11";
8764 return "DW_OP_lit12";
8766 return "DW_OP_lit13";
8768 return "DW_OP_lit14";
8770 return "DW_OP_lit15";
8772 return "DW_OP_lit16";
8774 return "DW_OP_lit17";
8776 return "DW_OP_lit18";
8778 return "DW_OP_lit19";
8780 return "DW_OP_lit20";
8782 return "DW_OP_lit21";
8784 return "DW_OP_lit22";
8786 return "DW_OP_lit23";
8788 return "DW_OP_lit24";
8790 return "DW_OP_lit25";
8792 return "DW_OP_lit26";
8794 return "DW_OP_lit27";
8796 return "DW_OP_lit28";
8798 return "DW_OP_lit29";
8800 return "DW_OP_lit30";
8802 return "DW_OP_lit31";
8804 return "DW_OP_reg0";
8806 return "DW_OP_reg1";
8808 return "DW_OP_reg2";
8810 return "DW_OP_reg3";
8812 return "DW_OP_reg4";
8814 return "DW_OP_reg5";
8816 return "DW_OP_reg6";
8818 return "DW_OP_reg7";
8820 return "DW_OP_reg8";
8822 return "DW_OP_reg9";
8824 return "DW_OP_reg10";
8826 return "DW_OP_reg11";
8828 return "DW_OP_reg12";
8830 return "DW_OP_reg13";
8832 return "DW_OP_reg14";
8834 return "DW_OP_reg15";
8836 return "DW_OP_reg16";
8838 return "DW_OP_reg17";
8840 return "DW_OP_reg18";
8842 return "DW_OP_reg19";
8844 return "DW_OP_reg20";
8846 return "DW_OP_reg21";
8848 return "DW_OP_reg22";
8850 return "DW_OP_reg23";
8852 return "DW_OP_reg24";
8854 return "DW_OP_reg25";
8856 return "DW_OP_reg26";
8858 return "DW_OP_reg27";
8860 return "DW_OP_reg28";
8862 return "DW_OP_reg29";
8864 return "DW_OP_reg30";
8866 return "DW_OP_reg31";
8868 return "DW_OP_breg0";
8870 return "DW_OP_breg1";
8872 return "DW_OP_breg2";
8874 return "DW_OP_breg3";
8876 return "DW_OP_breg4";
8878 return "DW_OP_breg5";
8880 return "DW_OP_breg6";
8882 return "DW_OP_breg7";
8884 return "DW_OP_breg8";
8886 return "DW_OP_breg9";
8888 return "DW_OP_breg10";
8890 return "DW_OP_breg11";
8892 return "DW_OP_breg12";
8894 return "DW_OP_breg13";
8896 return "DW_OP_breg14";
8898 return "DW_OP_breg15";
8900 return "DW_OP_breg16";
8902 return "DW_OP_breg17";
8904 return "DW_OP_breg18";
8906 return "DW_OP_breg19";
8908 return "DW_OP_breg20";
8910 return "DW_OP_breg21";
8912 return "DW_OP_breg22";
8914 return "DW_OP_breg23";
8916 return "DW_OP_breg24";
8918 return "DW_OP_breg25";
8920 return "DW_OP_breg26";
8922 return "DW_OP_breg27";
8924 return "DW_OP_breg28";
8926 return "DW_OP_breg29";
8928 return "DW_OP_breg30";
8930 return "DW_OP_breg31";
8932 return "DW_OP_regx";
8934 return "DW_OP_fbreg";
8936 return "DW_OP_bregx";
8938 return "DW_OP_piece";
8939 case DW_OP_deref_size
:
8940 return "DW_OP_deref_size";
8941 case DW_OP_xderef_size
:
8942 return "DW_OP_xderef_size";
8945 /* DWARF 3 extensions. */
8946 case DW_OP_push_object_address
:
8947 return "DW_OP_push_object_address";
8949 return "DW_OP_call2";
8951 return "DW_OP_call4";
8952 case DW_OP_call_ref
:
8953 return "DW_OP_call_ref";
8954 /* GNU extensions. */
8955 case DW_OP_form_tls_address
:
8956 return "DW_OP_form_tls_address";
8957 case DW_OP_call_frame_cfa
:
8958 return "DW_OP_call_frame_cfa";
8959 case DW_OP_bit_piece
:
8960 return "DW_OP_bit_piece";
8961 case DW_OP_GNU_push_tls_address
:
8962 return "DW_OP_GNU_push_tls_address";
8963 case DW_OP_GNU_uninit
:
8964 return "DW_OP_GNU_uninit";
8965 /* HP extensions. */
8966 case DW_OP_HP_is_value
:
8967 return "DW_OP_HP_is_value";
8968 case DW_OP_HP_fltconst4
:
8969 return "DW_OP_HP_fltconst4";
8970 case DW_OP_HP_fltconst8
:
8971 return "DW_OP_HP_fltconst8";
8972 case DW_OP_HP_mod_range
:
8973 return "DW_OP_HP_mod_range";
8974 case DW_OP_HP_unmod_range
:
8975 return "DW_OP_HP_unmod_range";
8977 return "DW_OP_HP_tls";
8979 return "OP_<unknown>";
8984 dwarf_bool_name (unsigned mybool
)
8992 /* Convert a DWARF type code into its string name. */
8995 dwarf_type_encoding_name (unsigned enc
)
9000 return "DW_ATE_void";
9001 case DW_ATE_address
:
9002 return "DW_ATE_address";
9003 case DW_ATE_boolean
:
9004 return "DW_ATE_boolean";
9005 case DW_ATE_complex_float
:
9006 return "DW_ATE_complex_float";
9008 return "DW_ATE_float";
9010 return "DW_ATE_signed";
9011 case DW_ATE_signed_char
:
9012 return "DW_ATE_signed_char";
9013 case DW_ATE_unsigned
:
9014 return "DW_ATE_unsigned";
9015 case DW_ATE_unsigned_char
:
9016 return "DW_ATE_unsigned_char";
9018 case DW_ATE_imaginary_float
:
9019 return "DW_ATE_imaginary_float";
9020 case DW_ATE_packed_decimal
:
9021 return "DW_ATE_packed_decimal";
9022 case DW_ATE_numeric_string
:
9023 return "DW_ATE_numeric_string";
9025 return "DW_ATE_edited";
9026 case DW_ATE_signed_fixed
:
9027 return "DW_ATE_signed_fixed";
9028 case DW_ATE_unsigned_fixed
:
9029 return "DW_ATE_unsigned_fixed";
9030 case DW_ATE_decimal_float
:
9031 return "DW_ATE_decimal_float";
9032 /* HP extensions. */
9033 case DW_ATE_HP_float80
:
9034 return "DW_ATE_HP_float80";
9035 case DW_ATE_HP_complex_float80
:
9036 return "DW_ATE_HP_complex_float80";
9037 case DW_ATE_HP_float128
:
9038 return "DW_ATE_HP_float128";
9039 case DW_ATE_HP_complex_float128
:
9040 return "DW_ATE_HP_complex_float128";
9041 case DW_ATE_HP_floathpintel
:
9042 return "DW_ATE_HP_floathpintel";
9043 case DW_ATE_HP_imaginary_float80
:
9044 return "DW_ATE_HP_imaginary_float80";
9045 case DW_ATE_HP_imaginary_float128
:
9046 return "DW_ATE_HP_imaginary_float128";
9048 return "DW_ATE_<unknown>";
9052 /* Convert a DWARF call frame info operation to its string name. */
9056 dwarf_cfi_name (unsigned cfi_opc
)
9060 case DW_CFA_advance_loc
:
9061 return "DW_CFA_advance_loc";
9063 return "DW_CFA_offset";
9064 case DW_CFA_restore
:
9065 return "DW_CFA_restore";
9067 return "DW_CFA_nop";
9068 case DW_CFA_set_loc
:
9069 return "DW_CFA_set_loc";
9070 case DW_CFA_advance_loc1
:
9071 return "DW_CFA_advance_loc1";
9072 case DW_CFA_advance_loc2
:
9073 return "DW_CFA_advance_loc2";
9074 case DW_CFA_advance_loc4
:
9075 return "DW_CFA_advance_loc4";
9076 case DW_CFA_offset_extended
:
9077 return "DW_CFA_offset_extended";
9078 case DW_CFA_restore_extended
:
9079 return "DW_CFA_restore_extended";
9080 case DW_CFA_undefined
:
9081 return "DW_CFA_undefined";
9082 case DW_CFA_same_value
:
9083 return "DW_CFA_same_value";
9084 case DW_CFA_register
:
9085 return "DW_CFA_register";
9086 case DW_CFA_remember_state
:
9087 return "DW_CFA_remember_state";
9088 case DW_CFA_restore_state
:
9089 return "DW_CFA_restore_state";
9090 case DW_CFA_def_cfa
:
9091 return "DW_CFA_def_cfa";
9092 case DW_CFA_def_cfa_register
:
9093 return "DW_CFA_def_cfa_register";
9094 case DW_CFA_def_cfa_offset
:
9095 return "DW_CFA_def_cfa_offset";
9097 case DW_CFA_def_cfa_expression
:
9098 return "DW_CFA_def_cfa_expression";
9099 case DW_CFA_expression
:
9100 return "DW_CFA_expression";
9101 case DW_CFA_offset_extended_sf
:
9102 return "DW_CFA_offset_extended_sf";
9103 case DW_CFA_def_cfa_sf
:
9104 return "DW_CFA_def_cfa_sf";
9105 case DW_CFA_def_cfa_offset_sf
:
9106 return "DW_CFA_def_cfa_offset_sf";
9107 case DW_CFA_val_offset
:
9108 return "DW_CFA_val_offset";
9109 case DW_CFA_val_offset_sf
:
9110 return "DW_CFA_val_offset_sf";
9111 case DW_CFA_val_expression
:
9112 return "DW_CFA_val_expression";
9113 /* SGI/MIPS specific. */
9114 case DW_CFA_MIPS_advance_loc8
:
9115 return "DW_CFA_MIPS_advance_loc8";
9116 /* GNU extensions. */
9117 case DW_CFA_GNU_window_save
:
9118 return "DW_CFA_GNU_window_save";
9119 case DW_CFA_GNU_args_size
:
9120 return "DW_CFA_GNU_args_size";
9121 case DW_CFA_GNU_negative_offset_extended
:
9122 return "DW_CFA_GNU_negative_offset_extended";
9124 return "DW_CFA_<unknown>";
9130 dump_die (struct die_info
*die
)
9134 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9135 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9136 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9137 dwarf_bool_name (die
->child
!= NULL
));
9139 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9140 for (i
= 0; i
< die
->num_attrs
; ++i
)
9142 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9143 dwarf_attr_name (die
->attrs
[i
].name
),
9144 dwarf_form_name (die
->attrs
[i
].form
));
9145 switch (die
->attrs
[i
].form
)
9147 case DW_FORM_ref_addr
:
9149 fprintf_unfiltered (gdb_stderr
, "address: ");
9150 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9152 case DW_FORM_block2
:
9153 case DW_FORM_block4
:
9155 case DW_FORM_block1
:
9156 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9161 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9162 (long) (DW_ADDR (&die
->attrs
[i
])));
9170 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9172 case DW_FORM_string
:
9174 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9175 DW_STRING (&die
->attrs
[i
])
9176 ? DW_STRING (&die
->attrs
[i
]) : "");
9179 if (DW_UNSND (&die
->attrs
[i
]))
9180 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9182 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9184 case DW_FORM_indirect
:
9185 /* the reader will have reduced the indirect form to
9186 the "base form" so this form should not occur */
9187 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9190 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9191 die
->attrs
[i
].form
);
9193 fprintf_unfiltered (gdb_stderr
, "\n");
9198 dump_die_list (struct die_info
*die
)
9203 if (die
->child
!= NULL
)
9204 dump_die_list (die
->child
);
9205 if (die
->sibling
!= NULL
)
9206 dump_die_list (die
->sibling
);
9211 store_in_ref_table (unsigned int offset
, struct die_info
*die
,
9212 struct dwarf2_cu
*cu
)
9215 struct die_info
*old
;
9217 h
= (offset
% REF_HASH_SIZE
);
9218 old
= cu
->die_ref_table
[h
];
9219 die
->next_ref
= old
;
9220 cu
->die_ref_table
[h
] = die
;
9224 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9226 unsigned int result
= 0;
9230 case DW_FORM_ref_addr
:
9235 case DW_FORM_ref_udata
:
9236 result
= DW_ADDR (attr
);
9239 complaint (&symfile_complaints
,
9240 _("unsupported die ref attribute form: '%s'"),
9241 dwarf_form_name (attr
->form
));
9246 /* Return the constant value held by the given attribute. Return -1
9247 if the value held by the attribute is not constant. */
9250 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9252 if (attr
->form
== DW_FORM_sdata
)
9253 return DW_SND (attr
);
9254 else if (attr
->form
== DW_FORM_udata
9255 || attr
->form
== DW_FORM_data1
9256 || attr
->form
== DW_FORM_data2
9257 || attr
->form
== DW_FORM_data4
9258 || attr
->form
== DW_FORM_data8
)
9259 return DW_UNSND (attr
);
9262 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9263 dwarf_form_name (attr
->form
));
9264 return default_value
;
9268 static struct die_info
*
9269 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9270 struct dwarf2_cu
*cu
)
9272 struct die_info
*die
;
9273 unsigned int offset
;
9275 struct die_info temp_die
;
9276 struct dwarf2_cu
*target_cu
;
9278 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9280 if (DW_ADDR (attr
) < cu
->header
.offset
9281 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9283 struct dwarf2_per_cu_data
*per_cu
;
9284 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9286 target_cu
= per_cu
->cu
;
9291 h
= (offset
% REF_HASH_SIZE
);
9292 die
= target_cu
->die_ref_table
[h
];
9295 if (die
->offset
== offset
)
9297 die
= die
->next_ref
;
9300 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9301 "at 0x%lx [in module %s]"),
9302 (long) src_die
->offset
, (long) offset
, cu
->objfile
->name
);
9307 /* Decode simple location descriptions.
9308 Given a pointer to a dwarf block that defines a location, compute
9309 the location and return the value.
9311 NOTE drow/2003-11-18: This function is called in two situations
9312 now: for the address of static or global variables (partial symbols
9313 only) and for offsets into structures which are expected to be
9314 (more or less) constant. The partial symbol case should go away,
9315 and only the constant case should remain. That will let this
9316 function complain more accurately. A few special modes are allowed
9317 without complaint for global variables (for instance, global
9318 register values and thread-local values).
9320 A location description containing no operations indicates that the
9321 object is optimized out. The return value is 0 for that case.
9322 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9323 callers will only want a very basic result and this can become a
9326 Note that stack[0] is unused except as a default error return.
9327 Note that stack overflow is not yet handled. */
9330 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9332 struct objfile
*objfile
= cu
->objfile
;
9333 struct comp_unit_head
*cu_header
= &cu
->header
;
9335 int size
= blk
->size
;
9336 gdb_byte
*data
= blk
->data
;
9337 CORE_ADDR stack
[64];
9339 unsigned int bytes_read
, unsnd
;
9383 stack
[++stacki
] = op
- DW_OP_lit0
;
9418 stack
[++stacki
] = op
- DW_OP_reg0
;
9420 dwarf2_complex_location_expr_complaint ();
9424 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9426 stack
[++stacki
] = unsnd
;
9428 dwarf2_complex_location_expr_complaint ();
9432 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9438 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9443 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9448 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9453 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9458 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9463 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9468 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9474 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9479 stack
[stacki
+ 1] = stack
[stacki
];
9484 stack
[stacki
- 1] += stack
[stacki
];
9488 case DW_OP_plus_uconst
:
9489 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9494 stack
[stacki
- 1] -= stack
[stacki
];
9499 /* If we're not the last op, then we definitely can't encode
9500 this using GDB's address_class enum. This is valid for partial
9501 global symbols, although the variable's address will be bogus
9504 dwarf2_complex_location_expr_complaint ();
9507 case DW_OP_GNU_push_tls_address
:
9508 /* The top of the stack has the offset from the beginning
9509 of the thread control block at which the variable is located. */
9510 /* Nothing should follow this operator, so the top of stack would
9512 /* This is valid for partial global symbols, but the variable's
9513 address will be bogus in the psymtab. */
9515 dwarf2_complex_location_expr_complaint ();
9518 case DW_OP_GNU_uninit
:
9522 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9523 dwarf_stack_op_name (op
));
9524 return (stack
[stacki
]);
9527 return (stack
[stacki
]);
9530 /* memory allocation interface */
9532 static struct dwarf_block
*
9533 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9535 struct dwarf_block
*blk
;
9537 blk
= (struct dwarf_block
*)
9538 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9542 static struct abbrev_info
*
9543 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9545 struct abbrev_info
*abbrev
;
9547 abbrev
= (struct abbrev_info
*)
9548 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9549 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9553 static struct die_info
*
9554 dwarf_alloc_die (void)
9556 struct die_info
*die
;
9558 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
9559 memset (die
, 0, sizeof (struct die_info
));
9564 /* Macro support. */
9567 /* Return the full name of file number I in *LH's file name table.
9568 Use COMP_DIR as the name of the current directory of the
9569 compilation. The result is allocated using xmalloc; the caller is
9570 responsible for freeing it. */
9572 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9574 /* Is the file number a valid index into the line header's file name
9575 table? Remember that file numbers start with one, not zero. */
9576 if (1 <= file
&& file
<= lh
->num_file_names
)
9578 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9580 if (IS_ABSOLUTE_PATH (fe
->name
))
9581 return xstrdup (fe
->name
);
9589 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9595 dir_len
= strlen (dir
);
9596 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9597 strcpy (full_name
, dir
);
9598 full_name
[dir_len
] = '/';
9599 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9603 return xstrdup (fe
->name
);
9608 /* The compiler produced a bogus file number. We can at least
9609 record the macro definitions made in the file, even if we
9610 won't be able to find the file by name. */
9612 sprintf (fake_name
, "<bad macro file number %d>", file
);
9614 complaint (&symfile_complaints
,
9615 _("bad file number in macro information (%d)"),
9618 return xstrdup (fake_name
);
9623 static struct macro_source_file
*
9624 macro_start_file (int file
, int line
,
9625 struct macro_source_file
*current_file
,
9626 const char *comp_dir
,
9627 struct line_header
*lh
, struct objfile
*objfile
)
9629 /* The full name of this source file. */
9630 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9632 /* We don't create a macro table for this compilation unit
9633 at all until we actually get a filename. */
9634 if (! pending_macros
)
9635 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9636 objfile
->macro_cache
);
9639 /* If we have no current file, then this must be the start_file
9640 directive for the compilation unit's main source file. */
9641 current_file
= macro_set_main (pending_macros
, full_name
);
9643 current_file
= macro_include (current_file
, line
, full_name
);
9647 return current_file
;
9651 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9652 followed by a null byte. */
9654 copy_string (const char *buf
, int len
)
9656 char *s
= xmalloc (len
+ 1);
9657 memcpy (s
, buf
, len
);
9665 consume_improper_spaces (const char *p
, const char *body
)
9669 complaint (&symfile_complaints
,
9670 _("macro definition contains spaces in formal argument list:\n`%s'"),
9682 parse_macro_definition (struct macro_source_file
*file
, int line
,
9687 /* The body string takes one of two forms. For object-like macro
9688 definitions, it should be:
9690 <macro name> " " <definition>
9692 For function-like macro definitions, it should be:
9694 <macro name> "() " <definition>
9696 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9698 Spaces may appear only where explicitly indicated, and in the
9701 The Dwarf 2 spec says that an object-like macro's name is always
9702 followed by a space, but versions of GCC around March 2002 omit
9703 the space when the macro's definition is the empty string.
9705 The Dwarf 2 spec says that there should be no spaces between the
9706 formal arguments in a function-like macro's formal argument list,
9707 but versions of GCC around March 2002 include spaces after the
9711 /* Find the extent of the macro name. The macro name is terminated
9712 by either a space or null character (for an object-like macro) or
9713 an opening paren (for a function-like macro). */
9714 for (p
= body
; *p
; p
++)
9715 if (*p
== ' ' || *p
== '(')
9718 if (*p
== ' ' || *p
== '\0')
9720 /* It's an object-like macro. */
9721 int name_len
= p
- body
;
9722 char *name
= copy_string (body
, name_len
);
9723 const char *replacement
;
9726 replacement
= body
+ name_len
+ 1;
9729 dwarf2_macro_malformed_definition_complaint (body
);
9730 replacement
= body
+ name_len
;
9733 macro_define_object (file
, line
, name
, replacement
);
9739 /* It's a function-like macro. */
9740 char *name
= copy_string (body
, p
- body
);
9743 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9747 p
= consume_improper_spaces (p
, body
);
9749 /* Parse the formal argument list. */
9750 while (*p
&& *p
!= ')')
9752 /* Find the extent of the current argument name. */
9753 const char *arg_start
= p
;
9755 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9758 if (! *p
|| p
== arg_start
)
9759 dwarf2_macro_malformed_definition_complaint (body
);
9762 /* Make sure argv has room for the new argument. */
9763 if (argc
>= argv_size
)
9766 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9769 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9772 p
= consume_improper_spaces (p
, body
);
9774 /* Consume the comma, if present. */
9779 p
= consume_improper_spaces (p
, body
);
9788 /* Perfectly formed definition, no complaints. */
9789 macro_define_function (file
, line
, name
,
9790 argc
, (const char **) argv
,
9792 else if (*p
== '\0')
9794 /* Complain, but do define it. */
9795 dwarf2_macro_malformed_definition_complaint (body
);
9796 macro_define_function (file
, line
, name
,
9797 argc
, (const char **) argv
,
9801 /* Just complain. */
9802 dwarf2_macro_malformed_definition_complaint (body
);
9805 /* Just complain. */
9806 dwarf2_macro_malformed_definition_complaint (body
);
9812 for (i
= 0; i
< argc
; i
++)
9818 dwarf2_macro_malformed_definition_complaint (body
);
9823 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9824 char *comp_dir
, bfd
*abfd
,
9825 struct dwarf2_cu
*cu
)
9827 gdb_byte
*mac_ptr
, *mac_end
;
9828 struct macro_source_file
*current_file
= 0;
9830 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9832 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9836 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9837 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9838 + dwarf2_per_objfile
->macinfo_size
;
9842 enum dwarf_macinfo_record_type macinfo_type
;
9844 /* Do we at least have room for a macinfo type byte? */
9845 if (mac_ptr
>= mac_end
)
9847 dwarf2_macros_too_long_complaint ();
9851 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9854 switch (macinfo_type
)
9856 /* A zero macinfo type indicates the end of the macro
9861 case DW_MACINFO_define
:
9862 case DW_MACINFO_undef
:
9864 unsigned int bytes_read
;
9868 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9869 mac_ptr
+= bytes_read
;
9870 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9871 mac_ptr
+= bytes_read
;
9874 complaint (&symfile_complaints
,
9875 _("debug info gives macro %s outside of any file: %s"),
9877 DW_MACINFO_define
? "definition" : macinfo_type
==
9878 DW_MACINFO_undef
? "undefinition" :
9879 "something-or-other", body
);
9882 if (macinfo_type
== DW_MACINFO_define
)
9883 parse_macro_definition (current_file
, line
, body
);
9884 else if (macinfo_type
== DW_MACINFO_undef
)
9885 macro_undef (current_file
, line
, body
);
9890 case DW_MACINFO_start_file
:
9892 unsigned int bytes_read
;
9895 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9896 mac_ptr
+= bytes_read
;
9897 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9898 mac_ptr
+= bytes_read
;
9900 current_file
= macro_start_file (file
, line
,
9901 current_file
, comp_dir
,
9906 case DW_MACINFO_end_file
:
9908 complaint (&symfile_complaints
,
9909 _("macro debug info has an unmatched `close_file' directive"));
9912 current_file
= current_file
->included_by
;
9915 enum dwarf_macinfo_record_type next_type
;
9917 /* GCC circa March 2002 doesn't produce the zero
9918 type byte marking the end of the compilation
9919 unit. Complain if it's not there, but exit no
9922 /* Do we at least have room for a macinfo type byte? */
9923 if (mac_ptr
>= mac_end
)
9925 dwarf2_macros_too_long_complaint ();
9929 /* We don't increment mac_ptr here, so this is just
9931 next_type
= read_1_byte (abfd
, mac_ptr
);
9933 complaint (&symfile_complaints
,
9934 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9941 case DW_MACINFO_vendor_ext
:
9943 unsigned int bytes_read
;
9947 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9948 mac_ptr
+= bytes_read
;
9949 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9950 mac_ptr
+= bytes_read
;
9952 /* We don't recognize any vendor extensions. */
9959 /* Check if the attribute's form is a DW_FORM_block*
9960 if so return true else false. */
9962 attr_form_is_block (struct attribute
*attr
)
9964 return (attr
== NULL
? 0 :
9965 attr
->form
== DW_FORM_block1
9966 || attr
->form
== DW_FORM_block2
9967 || attr
->form
== DW_FORM_block4
9968 || attr
->form
== DW_FORM_block
);
9971 /* Return non-zero if ATTR's value is a section offset --- classes
9972 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9973 You may use DW_UNSND (attr) to retrieve such offsets.
9975 Section 7.5.4, "Attribute Encodings", explains that no attribute
9976 may have a value that belongs to more than one of these classes; it
9977 would be ambiguous if we did, because we use the same forms for all
9980 attr_form_is_section_offset (struct attribute
*attr
)
9982 return (attr
->form
== DW_FORM_data4
9983 || attr
->form
== DW_FORM_data8
);
9987 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9988 zero otherwise. When this function returns true, you can apply
9989 dwarf2_get_attr_constant_value to it.
9991 However, note that for some attributes you must check
9992 attr_form_is_section_offset before using this test. DW_FORM_data4
9993 and DW_FORM_data8 are members of both the constant class, and of
9994 the classes that contain offsets into other debug sections
9995 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9996 that, if an attribute's can be either a constant or one of the
9997 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9998 taken as section offsets, not constants. */
10000 attr_form_is_constant (struct attribute
*attr
)
10002 switch (attr
->form
)
10004 case DW_FORM_sdata
:
10005 case DW_FORM_udata
:
10006 case DW_FORM_data1
:
10007 case DW_FORM_data2
:
10008 case DW_FORM_data4
:
10009 case DW_FORM_data8
:
10017 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10018 struct dwarf2_cu
*cu
)
10020 if (attr_form_is_section_offset (attr
)
10021 /* ".debug_loc" may not exist at all, or the offset may be outside
10022 the section. If so, fall through to the complaint in the
10024 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10026 struct dwarf2_loclist_baton
*baton
;
10028 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10029 sizeof (struct dwarf2_loclist_baton
));
10030 baton
->per_cu
= cu
->per_cu
;
10031 gdb_assert (baton
->per_cu
);
10033 /* We don't know how long the location list is, but make sure we
10034 don't run off the edge of the section. */
10035 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10036 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10037 baton
->base_address
= cu
->header
.base_address
;
10038 if (cu
->header
.base_known
== 0)
10039 complaint (&symfile_complaints
,
10040 _("Location list used without specifying the CU base address."));
10042 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10043 SYMBOL_LOCATION_BATON (sym
) = baton
;
10047 struct dwarf2_locexpr_baton
*baton
;
10049 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10050 sizeof (struct dwarf2_locexpr_baton
));
10051 baton
->per_cu
= cu
->per_cu
;
10052 gdb_assert (baton
->per_cu
);
10054 if (attr_form_is_block (attr
))
10056 /* Note that we're just copying the block's data pointer
10057 here, not the actual data. We're still pointing into the
10058 info_buffer for SYM's objfile; right now we never release
10059 that buffer, but when we do clean up properly this may
10061 baton
->size
= DW_BLOCK (attr
)->size
;
10062 baton
->data
= DW_BLOCK (attr
)->data
;
10066 dwarf2_invalid_attrib_class_complaint ("location description",
10067 SYMBOL_NATURAL_NAME (sym
));
10069 baton
->data
= NULL
;
10072 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10073 SYMBOL_LOCATION_BATON (sym
) = baton
;
10077 /* Return the OBJFILE associated with the compilation unit CU. */
10080 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10082 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10084 /* Return the master objfile, so that we can report and look up the
10085 correct file containing this variable. */
10086 if (objfile
->separate_debug_objfile_backlink
)
10087 objfile
= objfile
->separate_debug_objfile_backlink
;
10092 /* Return the address size given in the compilation unit header for CU. */
10095 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10098 return per_cu
->cu
->header
.addr_size
;
10101 /* If the CU is not currently read in, we re-read its header. */
10102 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10103 struct dwarf2_per_objfile
*per_objfile
10104 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10105 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10107 struct comp_unit_head cu_header
;
10108 memset (&cu_header
, 0, sizeof cu_header
);
10109 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10110 return cu_header
.addr_size
;
10114 /* Locate the compilation unit from CU's objfile which contains the
10115 DIE at OFFSET. Raises an error on failure. */
10117 static struct dwarf2_per_cu_data
*
10118 dwarf2_find_containing_comp_unit (unsigned long offset
,
10119 struct objfile
*objfile
)
10121 struct dwarf2_per_cu_data
*this_cu
;
10125 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10128 int mid
= low
+ (high
- low
) / 2;
10129 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10134 gdb_assert (low
== high
);
10135 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10138 error (_("Dwarf Error: could not find partial DIE containing "
10139 "offset 0x%lx [in module %s]"),
10140 (long) offset
, bfd_get_filename (objfile
->obfd
));
10142 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10143 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10147 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10148 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10149 && offset
>= this_cu
->offset
+ this_cu
->length
)
10150 error (_("invalid dwarf2 offset %ld"), offset
);
10151 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10156 /* Locate the compilation unit from OBJFILE which is located at exactly
10157 OFFSET. Raises an error on failure. */
10159 static struct dwarf2_per_cu_data
*
10160 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10162 struct dwarf2_per_cu_data
*this_cu
;
10163 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10164 if (this_cu
->offset
!= offset
)
10165 error (_("no compilation unit with offset %ld."), offset
);
10169 /* Release one cached compilation unit, CU. We unlink it from the tree
10170 of compilation units, but we don't remove it from the read_in_chain;
10171 the caller is responsible for that. */
10174 free_one_comp_unit (void *data
)
10176 struct dwarf2_cu
*cu
= data
;
10178 if (cu
->per_cu
!= NULL
)
10179 cu
->per_cu
->cu
= NULL
;
10182 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10184 free_die_list (cu
->dies
);
10189 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10190 when we're finished with it. We can't free the pointer itself, but be
10191 sure to unlink it from the cache. Also release any associated storage
10192 and perform cache maintenance.
10194 Only used during partial symbol parsing. */
10197 free_stack_comp_unit (void *data
)
10199 struct dwarf2_cu
*cu
= data
;
10201 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10202 cu
->partial_dies
= NULL
;
10204 if (cu
->per_cu
!= NULL
)
10206 /* This compilation unit is on the stack in our caller, so we
10207 should not xfree it. Just unlink it. */
10208 cu
->per_cu
->cu
= NULL
;
10211 /* If we had a per-cu pointer, then we may have other compilation
10212 units loaded, so age them now. */
10213 age_cached_comp_units ();
10217 /* Free all cached compilation units. */
10220 free_cached_comp_units (void *data
)
10222 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10224 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10225 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10226 while (per_cu
!= NULL
)
10228 struct dwarf2_per_cu_data
*next_cu
;
10230 next_cu
= per_cu
->cu
->read_in_chain
;
10232 free_one_comp_unit (per_cu
->cu
);
10233 *last_chain
= next_cu
;
10239 /* Increase the age counter on each cached compilation unit, and free
10240 any that are too old. */
10243 age_cached_comp_units (void)
10245 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10247 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10248 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10249 while (per_cu
!= NULL
)
10251 per_cu
->cu
->last_used
++;
10252 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10253 dwarf2_mark (per_cu
->cu
);
10254 per_cu
= per_cu
->cu
->read_in_chain
;
10257 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10258 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10259 while (per_cu
!= NULL
)
10261 struct dwarf2_per_cu_data
*next_cu
;
10263 next_cu
= per_cu
->cu
->read_in_chain
;
10265 if (!per_cu
->cu
->mark
)
10267 free_one_comp_unit (per_cu
->cu
);
10268 *last_chain
= next_cu
;
10271 last_chain
= &per_cu
->cu
->read_in_chain
;
10277 /* Remove a single compilation unit from the cache. */
10280 free_one_cached_comp_unit (void *target_cu
)
10282 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10284 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10285 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10286 while (per_cu
!= NULL
)
10288 struct dwarf2_per_cu_data
*next_cu
;
10290 next_cu
= per_cu
->cu
->read_in_chain
;
10292 if (per_cu
->cu
== target_cu
)
10294 free_one_comp_unit (per_cu
->cu
);
10295 *last_chain
= next_cu
;
10299 last_chain
= &per_cu
->cu
->read_in_chain
;
10305 /* Release all extra memory associated with OBJFILE. */
10308 dwarf2_free_objfile (struct objfile
*objfile
)
10310 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10312 if (dwarf2_per_objfile
== NULL
)
10315 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10316 free_cached_comp_units (NULL
);
10318 /* Everything else should be on the objfile obstack. */
10321 /* A pair of DIE offset and GDB type pointer. We store these
10322 in a hash table separate from the DIEs, and preserve them
10323 when the DIEs are flushed out of cache. */
10325 struct dwarf2_offset_and_type
10327 unsigned int offset
;
10331 /* Hash function for a dwarf2_offset_and_type. */
10334 offset_and_type_hash (const void *item
)
10336 const struct dwarf2_offset_and_type
*ofs
= item
;
10337 return ofs
->offset
;
10340 /* Equality function for a dwarf2_offset_and_type. */
10343 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10345 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10346 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10347 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10350 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10351 table if necessary. */
10354 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10356 struct dwarf2_offset_and_type
**slot
, ofs
;
10360 if (cu
->per_cu
== NULL
)
10363 if (cu
->per_cu
->type_hash
== NULL
)
10364 cu
->per_cu
->type_hash
10365 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10366 offset_and_type_hash
,
10367 offset_and_type_eq
,
10369 &cu
->objfile
->objfile_obstack
,
10370 hashtab_obstack_allocate
,
10371 dummy_obstack_deallocate
);
10373 ofs
.offset
= die
->offset
;
10375 slot
= (struct dwarf2_offset_and_type
**)
10376 htab_find_slot_with_hash (cu
->per_cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10377 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10381 /* Find the type for DIE in TYPE_HASH, or return NULL if DIE does not
10382 have a saved type. */
10384 static struct type
*
10385 get_die_type (struct die_info
*die
, htab_t type_hash
)
10387 struct dwarf2_offset_and_type
*slot
, ofs
;
10389 ofs
.offset
= die
->offset
;
10390 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10397 /* Restore the types of the DIE tree starting at START_DIE from the hash
10398 table saved in CU. */
10401 reset_die_and_siblings_types (struct die_info
*start_die
, struct dwarf2_cu
*cu
)
10403 struct die_info
*die
;
10405 if (cu
->per_cu
->type_hash
== NULL
)
10408 for (die
= start_die
; die
!= NULL
; die
= die
->sibling
)
10410 die
->type
= get_die_type (die
, cu
->per_cu
->type_hash
);
10411 if (die
->child
!= NULL
)
10412 reset_die_and_siblings_types (die
->child
, cu
);
10416 /* Set the mark field in CU and in every other compilation unit in the
10417 cache that we must keep because we are keeping CU. */
10419 /* Add a dependence relationship from CU to REF_PER_CU. */
10422 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10423 struct dwarf2_per_cu_data
*ref_per_cu
)
10427 if (cu
->dependencies
== NULL
)
10429 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10430 NULL
, &cu
->comp_unit_obstack
,
10431 hashtab_obstack_allocate
,
10432 dummy_obstack_deallocate
);
10434 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10436 *slot
= ref_per_cu
;
10439 /* Set the mark field in CU and in every other compilation unit in the
10440 cache that we must keep because we are keeping CU. */
10443 dwarf2_mark_helper (void **slot
, void *data
)
10445 struct dwarf2_per_cu_data
*per_cu
;
10447 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10448 if (per_cu
->cu
->mark
)
10450 per_cu
->cu
->mark
= 1;
10452 if (per_cu
->cu
->dependencies
!= NULL
)
10453 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10459 dwarf2_mark (struct dwarf2_cu
*cu
)
10464 if (cu
->dependencies
!= NULL
)
10465 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10469 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10473 per_cu
->cu
->mark
= 0;
10474 per_cu
= per_cu
->cu
->read_in_chain
;
10478 /* Trivial hash function for partial_die_info: the hash value of a DIE
10479 is its offset in .debug_info for this objfile. */
10482 partial_die_hash (const void *item
)
10484 const struct partial_die_info
*part_die
= item
;
10485 return part_die
->offset
;
10488 /* Trivial comparison function for partial_die_info structures: two DIEs
10489 are equal if they have the same offset. */
10492 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10494 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10495 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10496 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10499 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10500 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10503 set_dwarf2_cmd (char *args
, int from_tty
)
10505 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10509 show_dwarf2_cmd (char *args
, int from_tty
)
10511 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10514 void _initialize_dwarf2_read (void);
10517 _initialize_dwarf2_read (void)
10519 dwarf2_objfile_data_key
= register_objfile_data ();
10521 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10522 Set DWARF 2 specific variables.\n\
10523 Configure DWARF 2 variables such as the cache size"),
10524 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10525 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10527 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10528 Show DWARF 2 specific variables\n\
10529 Show DWARF 2 variables such as the cache size"),
10530 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10531 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10533 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10534 &dwarf2_max_cache_age
, _("\
10535 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10536 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10537 A higher limit means that cached compilation units will be stored\n\
10538 in memory longer, and more total memory will be used. Zero disables\n\
10539 caching, which can slow down startup."),
10541 show_dwarf2_max_cache_age
,
10542 &set_dwarf2_cmdlist
,
10543 &show_dwarf2_cmdlist
);