1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
59 /* A note on memory usage for this file.
61 At the present time, this code reads the debug info sections into
62 the objfile's objfile_obstack. A definite improvement for startup
63 time, on platforms which do not emit relocations for debug
64 sections, would be to use mmap instead. The object's complete
65 debug information is loaded into memory, partly to simplify
66 absolute DIE references.
68 Whether using obstacks or mmap, the sections should remain loaded
69 until the objfile is released, and pointers into the section data
70 can be used for any other data associated to the objfile (symbol
71 names, type names, location expressions to name a few). */
74 /* .debug_info header for a compilation unit
75 Because of alignment constraints, this structure has padding and cannot
76 be mapped directly onto the beginning of the .debug_info section. */
77 typedef struct comp_unit_header
79 unsigned int length
; /* length of the .debug_info
81 unsigned short version
; /* version number -- 2 for DWARF
83 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
84 unsigned char addr_size
; /* byte size of an address -- 4 */
87 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
90 /* .debug_pubnames header
91 Because of alignment constraints, this structure has padding and cannot
92 be mapped directly onto the beginning of the .debug_info section. */
93 typedef struct pubnames_header
95 unsigned int length
; /* length of the .debug_pubnames
97 unsigned char version
; /* version number -- 2 for DWARF
99 unsigned int info_offset
; /* offset into .debug_info section */
100 unsigned int info_size
; /* byte size of .debug_info section
104 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
106 /* .debug_pubnames header
107 Because of alignment constraints, this structure has padding and cannot
108 be mapped directly onto the beginning of the .debug_info section. */
109 typedef struct aranges_header
111 unsigned int length
; /* byte len of the .debug_aranges
113 unsigned short version
; /* version number -- 2 for DWARF
115 unsigned int info_offset
; /* offset into .debug_info section */
116 unsigned char addr_size
; /* byte size of an address */
117 unsigned char seg_size
; /* byte size of segment descriptor */
120 #define _ACTUAL_ARANGES_HEADER_SIZE 12
122 /* .debug_line statement program prologue
123 Because of alignment constraints, this structure has padding and cannot
124 be mapped directly onto the beginning of the .debug_info section. */
125 typedef struct statement_prologue
127 unsigned int total_length
; /* byte length of the statement
129 unsigned short version
; /* version number -- 2 for DWARF
131 unsigned int prologue_length
; /* # bytes between prologue &
133 unsigned char minimum_instruction_length
; /* byte size of
135 unsigned char default_is_stmt
; /* initial value of is_stmt
138 unsigned char line_range
;
139 unsigned char opcode_base
; /* number assigned to first special
141 unsigned char *standard_opcode_lengths
;
145 /* When non-zero, dump DIEs after they are read in. */
146 static int dwarf2_die_debug
= 0;
148 /* When set, the file that we're processing is known to have debugging
149 info for C++ namespaces. GCC 3.3.x did not produce this information,
150 but later versions do. */
152 static int processing_has_namespace_info
;
154 static const struct objfile_data
*dwarf2_objfile_data_key
;
156 struct dwarf2_per_objfile
158 /* Sizes of debugging sections. */
159 unsigned int info_size
;
160 unsigned int abbrev_size
;
161 unsigned int line_size
;
162 unsigned int pubnames_size
;
163 unsigned int aranges_size
;
164 unsigned int loc_size
;
165 unsigned int macinfo_size
;
166 unsigned int str_size
;
167 unsigned int ranges_size
;
168 unsigned int frame_size
;
169 unsigned int eh_frame_size
;
171 /* Loaded data from the sections. */
172 gdb_byte
*info_buffer
;
173 gdb_byte
*abbrev_buffer
;
174 gdb_byte
*line_buffer
;
175 gdb_byte
*str_buffer
;
176 gdb_byte
*macinfo_buffer
;
177 gdb_byte
*ranges_buffer
;
178 gdb_byte
*loc_buffer
;
180 /* A list of all the compilation units. This is used to locate
181 the target compilation unit of a particular reference. */
182 struct dwarf2_per_cu_data
**all_comp_units
;
184 /* The number of compilation units in ALL_COMP_UNITS. */
187 /* A chain of compilation units that are currently read in, so that
188 they can be freed later. */
189 struct dwarf2_per_cu_data
*read_in_chain
;
191 /* A flag indicating wether this objfile has a section loaded at a
193 int has_section_at_zero
;
196 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
198 static asection
*dwarf_info_section
;
199 static asection
*dwarf_abbrev_section
;
200 static asection
*dwarf_line_section
;
201 static asection
*dwarf_pubnames_section
;
202 static asection
*dwarf_aranges_section
;
203 static asection
*dwarf_loc_section
;
204 static asection
*dwarf_macinfo_section
;
205 static asection
*dwarf_str_section
;
206 static asection
*dwarf_ranges_section
;
207 asection
*dwarf_frame_section
;
208 asection
*dwarf_eh_frame_section
;
210 /* names of the debugging sections */
212 /* Note that if the debugging section has been compressed, it might
213 have a name like .zdebug_info. */
215 #define INFO_SECTION "debug_info"
216 #define ABBREV_SECTION "debug_abbrev"
217 #define LINE_SECTION "debug_line"
218 #define PUBNAMES_SECTION "debug_pubnames"
219 #define ARANGES_SECTION "debug_aranges"
220 #define LOC_SECTION "debug_loc"
221 #define MACINFO_SECTION "debug_macinfo"
222 #define STR_SECTION "debug_str"
223 #define RANGES_SECTION "debug_ranges"
224 #define FRAME_SECTION "debug_frame"
225 #define EH_FRAME_SECTION "eh_frame"
227 /* local data types */
229 /* We hold several abbreviation tables in memory at the same time. */
230 #ifndef ABBREV_HASH_SIZE
231 #define ABBREV_HASH_SIZE 121
234 /* The data in a compilation unit header, after target2host
235 translation, looks like this. */
236 struct comp_unit_head
240 unsigned char addr_size
;
241 unsigned char signed_addr_p
;
242 unsigned int abbrev_offset
;
244 /* Size of file offsets; either 4 or 8. */
245 unsigned int offset_size
;
247 /* Size of the length field; either 4 or 12. */
248 unsigned int initial_length_size
;
250 /* Offset to the first byte of this compilation unit header in the
251 .debug_info section, for resolving relative reference dies. */
254 /* Offset to first die in this cu from the start of the cu.
255 This will be the first byte following the compilation unit header. */
256 unsigned int first_die_offset
;
259 /* Internal state when decoding a particular compilation unit. */
262 /* The objfile containing this compilation unit. */
263 struct objfile
*objfile
;
265 /* The header of the compilation unit. */
266 struct comp_unit_head header
;
268 /* Base address of this compilation unit. */
269 CORE_ADDR base_address
;
271 /* Non-zero if base_address has been set. */
274 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
276 /* The language we are debugging. */
277 enum language language
;
278 const struct language_defn
*language_defn
;
280 const char *producer
;
282 /* The generic symbol table building routines have separate lists for
283 file scope symbols and all all other scopes (local scopes). So
284 we need to select the right one to pass to add_symbol_to_list().
285 We do it by keeping a pointer to the correct list in list_in_scope.
287 FIXME: The original dwarf code just treated the file scope as the
288 first local scope, and all other local scopes as nested local
289 scopes, and worked fine. Check to see if we really need to
290 distinguish these in buildsym.c. */
291 struct pending
**list_in_scope
;
293 /* DWARF abbreviation table associated with this compilation unit. */
294 struct abbrev_info
**dwarf2_abbrevs
;
296 /* Storage for the abbrev table. */
297 struct obstack abbrev_obstack
;
299 /* Hash table holding all the loaded partial DIEs. */
302 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
303 unsigned int ranges_offset
;
305 /* Storage for things with the same lifetime as this read-in compilation
306 unit, including partial DIEs. */
307 struct obstack comp_unit_obstack
;
309 /* When multiple dwarf2_cu structures are living in memory, this field
310 chains them all together, so that they can be released efficiently.
311 We will probably also want a generation counter so that most-recently-used
312 compilation units are cached... */
313 struct dwarf2_per_cu_data
*read_in_chain
;
315 /* Backchain to our per_cu entry if the tree has been built. */
316 struct dwarf2_per_cu_data
*per_cu
;
318 /* Pointer to the die -> type map. Although it is stored
319 permanently in per_cu, we copy it here to avoid double
323 /* How many compilation units ago was this CU last referenced? */
326 /* A hash table of die offsets for following references. */
329 /* Full DIEs if read in. */
330 struct die_info
*dies
;
332 /* A set of pointers to dwarf2_per_cu_data objects for compilation
333 units referenced by this one. Only set during full symbol processing;
334 partial symbol tables do not have dependencies. */
337 /* Header data from the line table, during full symbol processing. */
338 struct line_header
*line_header
;
340 /* Mark used when releasing cached dies. */
341 unsigned int mark
: 1;
343 /* This flag will be set if this compilation unit might include
344 inter-compilation-unit references. */
345 unsigned int has_form_ref_addr
: 1;
347 /* This flag will be set if this compilation unit includes any
348 DW_TAG_namespace DIEs. If we know that there are explicit
349 DIEs for namespaces, we don't need to try to infer them
350 from mangled names. */
351 unsigned int has_namespace_info
: 1;
353 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
354 unsigned int has_ranges_offset
: 1;
357 /* Persistent data held for a compilation unit, even when not
358 processing it. We put a pointer to this structure in the
359 read_symtab_private field of the psymtab. If we encounter
360 inter-compilation-unit references, we also maintain a sorted
361 list of all compilation units. */
363 struct dwarf2_per_cu_data
365 /* The start offset and length of this compilation unit. 2**30-1
366 bytes should suffice to store the length of any compilation unit
367 - if it doesn't, GDB will fall over anyway.
368 NOTE: Unlike comp_unit_head.length, this length includes
369 initial_length_size. */
371 unsigned int length
: 30;
373 /* Flag indicating this compilation unit will be read in before
374 any of the current compilation units are processed. */
375 unsigned int queued
: 1;
377 /* This flag will be set if we need to load absolutely all DIEs
378 for this compilation unit, instead of just the ones we think
379 are interesting. It gets set if we look for a DIE in the
380 hash table and don't find it. */
381 unsigned int load_all_dies
: 1;
383 /* Set iff currently read in. */
384 struct dwarf2_cu
*cu
;
386 /* If full symbols for this CU have been read in, then this field
387 holds a map of DIE offsets to types. It isn't always possible
388 to reconstruct this information later, so we have to preserve
392 /* The partial symbol table associated with this compilation unit,
393 or NULL for partial units (which do not have an associated
395 struct partial_symtab
*psymtab
;
398 /* The line number information for a compilation unit (found in the
399 .debug_line section) begins with a "statement program header",
400 which contains the following information. */
403 unsigned int total_length
;
404 unsigned short version
;
405 unsigned int header_length
;
406 unsigned char minimum_instruction_length
;
407 unsigned char default_is_stmt
;
409 unsigned char line_range
;
410 unsigned char opcode_base
;
412 /* standard_opcode_lengths[i] is the number of operands for the
413 standard opcode whose value is i. This means that
414 standard_opcode_lengths[0] is unused, and the last meaningful
415 element is standard_opcode_lengths[opcode_base - 1]. */
416 unsigned char *standard_opcode_lengths
;
418 /* The include_directories table. NOTE! These strings are not
419 allocated with xmalloc; instead, they are pointers into
420 debug_line_buffer. If you try to free them, `free' will get
422 unsigned int num_include_dirs
, include_dirs_size
;
425 /* The file_names table. NOTE! These strings are not allocated
426 with xmalloc; instead, they are pointers into debug_line_buffer.
427 Don't try to free them directly. */
428 unsigned int num_file_names
, file_names_size
;
432 unsigned int dir_index
;
433 unsigned int mod_time
;
435 int included_p
; /* Non-zero if referenced by the Line Number Program. */
436 struct symtab
*symtab
; /* The associated symbol table, if any. */
439 /* The start and end of the statement program following this
440 header. These point into dwarf2_per_objfile->line_buffer. */
441 gdb_byte
*statement_program_start
, *statement_program_end
;
444 /* When we construct a partial symbol table entry we only
445 need this much information. */
446 struct partial_die_info
448 /* Offset of this DIE. */
451 /* DWARF-2 tag for this DIE. */
452 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
454 /* Language code associated with this DIE. This is only used
455 for the compilation unit DIE. */
456 unsigned int language
: 8;
458 /* Assorted flags describing the data found in this DIE. */
459 unsigned int has_children
: 1;
460 unsigned int is_external
: 1;
461 unsigned int is_declaration
: 1;
462 unsigned int has_type
: 1;
463 unsigned int has_specification
: 1;
464 unsigned int has_stmt_list
: 1;
465 unsigned int has_pc_info
: 1;
467 /* Flag set if the SCOPE field of this structure has been
469 unsigned int scope_set
: 1;
471 /* Flag set if the DIE has a byte_size attribute. */
472 unsigned int has_byte_size
: 1;
474 /* The name of this DIE. Normally the value of DW_AT_name, but
475 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
480 /* The scope to prepend to our children. This is generally
481 allocated on the comp_unit_obstack, so will disappear
482 when this compilation unit leaves the cache. */
485 /* The location description associated with this DIE, if any. */
486 struct dwarf_block
*locdesc
;
488 /* If HAS_PC_INFO, the PC range associated with this DIE. */
492 /* Pointer into the info_buffer pointing at the target of
493 DW_AT_sibling, if any. */
496 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
497 DW_AT_specification (or DW_AT_abstract_origin or
499 unsigned int spec_offset
;
501 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
502 unsigned int line_offset
;
504 /* Pointers to this DIE's parent, first child, and next sibling,
506 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
509 /* This data structure holds the information of an abbrev. */
512 unsigned int number
; /* number identifying abbrev */
513 enum dwarf_tag tag
; /* dwarf tag */
514 unsigned short has_children
; /* boolean */
515 unsigned short num_attrs
; /* number of attributes */
516 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
517 struct abbrev_info
*next
; /* next in chain */
522 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
523 ENUM_BITFIELD(dwarf_form
) form
: 16;
526 /* Attributes have a name and a value */
529 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
530 ENUM_BITFIELD(dwarf_form
) form
: 16;
534 struct dwarf_block
*blk
;
542 /* This data structure holds a complete die structure. */
545 /* DWARF-2 tag for this DIE. */
546 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
548 /* Number of attributes */
549 unsigned short num_attrs
;
554 /* Offset in .debug_info section */
557 /* The dies in a compilation unit form an n-ary tree. PARENT
558 points to this die's parent; CHILD points to the first child of
559 this node; and all the children of a given node are chained
560 together via their SIBLING fields, terminated by a die whose
562 struct die_info
*child
; /* Its first child, if any. */
563 struct die_info
*sibling
; /* Its next sibling, if any. */
564 struct die_info
*parent
; /* Its parent, if any. */
566 /* An array of attributes, with NUM_ATTRS elements. There may be
567 zero, but it's not common and zero-sized arrays are not
568 sufficiently portable C. */
569 struct attribute attrs
[1];
572 struct function_range
575 CORE_ADDR lowpc
, highpc
;
577 struct function_range
*next
;
580 /* Get at parts of an attribute structure */
582 #define DW_STRING(attr) ((attr)->u.str)
583 #define DW_UNSND(attr) ((attr)->u.unsnd)
584 #define DW_BLOCK(attr) ((attr)->u.blk)
585 #define DW_SND(attr) ((attr)->u.snd)
586 #define DW_ADDR(attr) ((attr)->u.addr)
588 /* Blocks are a bunch of untyped bytes. */
595 #ifndef ATTR_ALLOC_CHUNK
596 #define ATTR_ALLOC_CHUNK 4
599 /* Allocate fields for structs, unions and enums in this size. */
600 #ifndef DW_FIELD_ALLOC_CHUNK
601 #define DW_FIELD_ALLOC_CHUNK 4
604 /* A zeroed version of a partial die for initialization purposes. */
605 static struct partial_die_info zeroed_partial_die
;
607 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
608 but this would require a corresponding change in unpack_field_as_long
610 static int bits_per_byte
= 8;
612 /* The routines that read and process dies for a C struct or C++ class
613 pass lists of data member fields and lists of member function fields
614 in an instance of a field_info structure, as defined below. */
617 /* List of data member and baseclasses fields. */
620 struct nextfield
*next
;
627 /* Number of fields. */
630 /* Number of baseclasses. */
633 /* Set if the accesibility of one of the fields is not public. */
634 int non_public_fields
;
636 /* Member function fields array, entries are allocated in the order they
637 are encountered in the object file. */
640 struct nextfnfield
*next
;
641 struct fn_field fnfield
;
645 /* Member function fieldlist array, contains name of possibly overloaded
646 member function, number of overloaded member functions and a pointer
647 to the head of the member function field chain. */
652 struct nextfnfield
*head
;
656 /* Number of entries in the fnfieldlists array. */
660 /* One item on the queue of compilation units to read in full symbols
662 struct dwarf2_queue_item
664 struct dwarf2_per_cu_data
*per_cu
;
665 struct dwarf2_queue_item
*next
;
668 /* The current queue. */
669 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
671 /* Loaded secondary compilation units are kept in memory until they
672 have not been referenced for the processing of this many
673 compilation units. Set this to zero to disable caching. Cache
674 sizes of up to at least twenty will improve startup time for
675 typical inter-CU-reference binaries, at an obvious memory cost. */
676 static int dwarf2_max_cache_age
= 5;
678 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
679 struct cmd_list_element
*c
, const char *value
)
681 fprintf_filtered (file
, _("\
682 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
687 /* Various complaints about symbol reading that don't abort the process */
690 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
692 complaint (&symfile_complaints
,
693 _("statement list doesn't fit in .debug_line section"));
697 dwarf2_debug_line_missing_file_complaint (void)
699 complaint (&symfile_complaints
,
700 _(".debug_line section has line data without a file"));
704 dwarf2_debug_line_missing_end_sequence_complaint (void)
706 complaint (&symfile_complaints
,
707 _(".debug_line section has line program sequence without an end"));
711 dwarf2_complex_location_expr_complaint (void)
713 complaint (&symfile_complaints
, _("location expression too complex"));
717 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
720 complaint (&symfile_complaints
,
721 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
726 dwarf2_macros_too_long_complaint (void)
728 complaint (&symfile_complaints
,
729 _("macro info runs off end of `.debug_macinfo' section"));
733 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
735 complaint (&symfile_complaints
,
736 _("macro debug info contains a malformed macro definition:\n`%s'"),
741 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
743 complaint (&symfile_complaints
,
744 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
747 /* local function prototypes */
749 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
752 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
755 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
758 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
759 struct partial_die_info
*,
760 struct partial_symtab
*);
762 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
764 static void scan_partial_symbols (struct partial_die_info
*,
765 CORE_ADDR
*, CORE_ADDR
*,
766 int, struct dwarf2_cu
*);
768 static void add_partial_symbol (struct partial_die_info
*,
771 static int pdi_needs_namespace (enum dwarf_tag tag
);
773 static void add_partial_namespace (struct partial_die_info
*pdi
,
774 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
775 int need_pc
, struct dwarf2_cu
*cu
);
777 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
778 CORE_ADDR
*highpc
, int need_pc
,
779 struct dwarf2_cu
*cu
);
781 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
782 struct dwarf2_cu
*cu
);
784 static void add_partial_subprogram (struct partial_die_info
*pdi
,
785 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
786 int need_pc
, struct dwarf2_cu
*cu
);
788 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
791 struct dwarf2_cu
*cu
);
793 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
795 static void psymtab_to_symtab_1 (struct partial_symtab
*);
797 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
799 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
801 static void dwarf2_free_abbrev_table (void *);
803 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
806 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
809 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
812 static gdb_byte
*read_partial_die (struct partial_die_info
*,
813 struct abbrev_info
*abbrev
, unsigned int,
814 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
816 static struct partial_die_info
*find_partial_die (unsigned int,
819 static void fixup_partial_die (struct partial_die_info
*,
822 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
823 struct dwarf2_cu
*, int *);
825 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
826 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
828 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
829 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
831 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
833 static int read_1_signed_byte (bfd
*, gdb_byte
*);
835 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
837 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
839 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
841 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
844 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
846 static LONGEST read_checked_initial_length_and_offset
847 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
848 unsigned int *, unsigned int *);
850 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
853 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
855 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
857 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
859 static char *read_indirect_string (bfd
*, gdb_byte
*,
860 const struct comp_unit_head
*,
863 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
865 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
867 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
869 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
871 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
874 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
875 struct dwarf2_cu
*cu
);
877 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
879 static struct die_info
*die_specification (struct die_info
*die
,
880 struct dwarf2_cu
**);
882 static void free_line_header (struct line_header
*lh
);
884 static void add_file_name (struct line_header
*, char *, unsigned int,
885 unsigned int, unsigned int);
887 static struct line_header
*(dwarf_decode_line_header
888 (unsigned int offset
,
889 bfd
*abfd
, struct dwarf2_cu
*cu
));
891 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
892 struct dwarf2_cu
*, struct partial_symtab
*);
894 static void dwarf2_start_subfile (char *, char *, char *);
896 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
899 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
902 static void dwarf2_const_value_data (struct attribute
*attr
,
906 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
908 static struct type
*die_containing_type (struct die_info
*,
911 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
913 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
915 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
917 static char *typename_concat (struct obstack
*,
922 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
924 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
926 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
928 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
929 struct dwarf2_cu
*, struct partial_symtab
*);
931 static int dwarf2_get_pc_bounds (struct die_info
*,
932 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
934 static void get_scope_pc_bounds (struct die_info
*,
935 CORE_ADDR
*, CORE_ADDR
*,
938 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
939 CORE_ADDR
, struct dwarf2_cu
*);
941 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
944 static void dwarf2_attach_fields_to_type (struct field_info
*,
945 struct type
*, struct dwarf2_cu
*);
947 static void dwarf2_add_member_fn (struct field_info
*,
948 struct die_info
*, struct type
*,
951 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
952 struct type
*, struct dwarf2_cu
*);
954 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
956 static const char *determine_class_name (struct die_info
*die
,
957 struct dwarf2_cu
*cu
);
959 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
961 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
963 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
965 static const char *namespace_name (struct die_info
*die
,
966 int *is_anonymous
, struct dwarf2_cu
*);
968 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
970 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
972 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
975 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
977 static struct die_info
*read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
979 gdb_byte
**new_info_ptr
,
980 struct die_info
*parent
);
982 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
984 gdb_byte
**new_info_ptr
,
985 struct die_info
*parent
);
987 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
989 gdb_byte
**new_info_ptr
,
990 struct die_info
*parent
);
992 static void process_die (struct die_info
*, struct dwarf2_cu
*);
994 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
996 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
998 static struct die_info
*dwarf2_extension (struct die_info
*die
,
999 struct dwarf2_cu
**);
1001 static char *dwarf_tag_name (unsigned int);
1003 static char *dwarf_attr_name (unsigned int);
1005 static char *dwarf_form_name (unsigned int);
1007 static char *dwarf_stack_op_name (unsigned int);
1009 static char *dwarf_bool_name (unsigned int);
1011 static char *dwarf_type_encoding_name (unsigned int);
1014 static char *dwarf_cfi_name (unsigned int);
1017 static struct die_info
*sibling_die (struct die_info
*);
1019 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1021 static void dump_die_for_error (struct die_info
*);
1023 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1026 /*static*/ void dump_die (struct die_info
*, int max_level
);
1028 static void store_in_ref_table (struct die_info
*,
1029 struct dwarf2_cu
*);
1031 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1033 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1035 static struct die_info
*follow_die_ref (struct die_info
*,
1037 struct dwarf2_cu
**);
1039 /* memory allocation interface */
1041 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1043 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1045 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1047 static void initialize_cu_func_list (struct dwarf2_cu
*);
1049 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1050 struct dwarf2_cu
*);
1052 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1053 char *, bfd
*, struct dwarf2_cu
*);
1055 static int attr_form_is_block (struct attribute
*);
1057 static int attr_form_is_section_offset (struct attribute
*);
1059 static int attr_form_is_constant (struct attribute
*);
1061 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1063 struct dwarf2_cu
*cu
);
1065 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1066 struct dwarf2_cu
*cu
);
1068 static void free_stack_comp_unit (void *);
1070 static hashval_t
partial_die_hash (const void *item
);
1072 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1074 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1075 (unsigned int offset
, struct objfile
*objfile
);
1077 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1078 (unsigned int offset
, struct objfile
*objfile
);
1080 static void free_one_comp_unit (void *);
1082 static void free_cached_comp_units (void *);
1084 static void age_cached_comp_units (void);
1086 static void free_one_cached_comp_unit (void *);
1088 static struct type
*set_die_type (struct die_info
*, struct type
*,
1089 struct dwarf2_cu
*);
1091 static void create_all_comp_units (struct objfile
*);
1093 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1096 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1098 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1099 struct dwarf2_per_cu_data
*);
1101 static void dwarf2_mark (struct dwarf2_cu
*);
1103 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1105 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1107 /* Try to locate the sections we need for DWARF 2 debugging
1108 information and return true if we have enough to do something. */
1111 dwarf2_has_info (struct objfile
*objfile
)
1113 struct dwarf2_per_objfile
*data
;
1115 /* Initialize per-objfile state. */
1116 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1117 memset (data
, 0, sizeof (*data
));
1118 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1119 dwarf2_per_objfile
= data
;
1121 dwarf_info_section
= 0;
1122 dwarf_abbrev_section
= 0;
1123 dwarf_line_section
= 0;
1124 dwarf_str_section
= 0;
1125 dwarf_macinfo_section
= 0;
1126 dwarf_frame_section
= 0;
1127 dwarf_eh_frame_section
= 0;
1128 dwarf_ranges_section
= 0;
1129 dwarf_loc_section
= 0;
1131 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1132 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1135 /* When loading sections, we can either look for ".<name>", or for
1136 * ".z<name>", which indicates a compressed section. */
1139 section_is_p (asection
*sectp
, const char *name
)
1141 return ((sectp
->name
[0] == '.'
1142 && strcmp (sectp
->name
+ 1, name
) == 0)
1143 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1144 && strcmp (sectp
->name
+ 2, name
) == 0));
1147 /* This function is mapped across the sections and remembers the
1148 offset and size of each of the debugging sections we are interested
1152 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1154 if (section_is_p (sectp
, INFO_SECTION
))
1156 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1157 dwarf_info_section
= sectp
;
1159 else if (section_is_p (sectp
, ABBREV_SECTION
))
1161 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1162 dwarf_abbrev_section
= sectp
;
1164 else if (section_is_p (sectp
, LINE_SECTION
))
1166 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1167 dwarf_line_section
= sectp
;
1169 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1171 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1172 dwarf_pubnames_section
= sectp
;
1174 else if (section_is_p (sectp
, ARANGES_SECTION
))
1176 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1177 dwarf_aranges_section
= sectp
;
1179 else if (section_is_p (sectp
, LOC_SECTION
))
1181 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1182 dwarf_loc_section
= sectp
;
1184 else if (section_is_p (sectp
, MACINFO_SECTION
))
1186 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1187 dwarf_macinfo_section
= sectp
;
1189 else if (section_is_p (sectp
, STR_SECTION
))
1191 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1192 dwarf_str_section
= sectp
;
1194 else if (section_is_p (sectp
, FRAME_SECTION
))
1196 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1197 dwarf_frame_section
= sectp
;
1199 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1201 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1202 if (aflag
& SEC_HAS_CONTENTS
)
1204 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1205 dwarf_eh_frame_section
= sectp
;
1208 else if (section_is_p (sectp
, RANGES_SECTION
))
1210 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1211 dwarf_ranges_section
= sectp
;
1214 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1215 && bfd_section_vma (abfd
, sectp
) == 0)
1216 dwarf2_per_objfile
->has_section_at_zero
= 1;
1219 /* This function is called after decompressing a section, so
1220 dwarf2_per_objfile can record its new, uncompressed size. */
1223 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1225 if (section_is_p (sectp
, INFO_SECTION
))
1226 dwarf2_per_objfile
->info_size
= new_size
;
1227 else if (section_is_p (sectp
, ABBREV_SECTION
))
1228 dwarf2_per_objfile
->abbrev_size
= new_size
;
1229 else if (section_is_p (sectp
, LINE_SECTION
))
1230 dwarf2_per_objfile
->line_size
= new_size
;
1231 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1232 dwarf2_per_objfile
->pubnames_size
= new_size
;
1233 else if (section_is_p (sectp
, ARANGES_SECTION
))
1234 dwarf2_per_objfile
->aranges_size
= new_size
;
1235 else if (section_is_p (sectp
, LOC_SECTION
))
1236 dwarf2_per_objfile
->loc_size
= new_size
;
1237 else if (section_is_p (sectp
, MACINFO_SECTION
))
1238 dwarf2_per_objfile
->macinfo_size
= new_size
;
1239 else if (section_is_p (sectp
, STR_SECTION
))
1240 dwarf2_per_objfile
->str_size
= new_size
;
1241 else if (section_is_p (sectp
, FRAME_SECTION
))
1242 dwarf2_per_objfile
->frame_size
= new_size
;
1243 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1244 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1245 else if (section_is_p (sectp
, RANGES_SECTION
))
1246 dwarf2_per_objfile
->ranges_size
= new_size
;
1248 internal_error (__FILE__
, __LINE__
,
1249 _("dwarf2_resize_section: missing section_is_p check: %s"),
1253 /* Build a partial symbol table. */
1256 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1258 /* We definitely need the .debug_info and .debug_abbrev sections */
1260 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1261 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1263 if (dwarf_line_section
)
1264 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1266 dwarf2_per_objfile
->line_buffer
= NULL
;
1268 if (dwarf_str_section
)
1269 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1271 dwarf2_per_objfile
->str_buffer
= NULL
;
1273 if (dwarf_macinfo_section
)
1274 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1275 dwarf_macinfo_section
);
1277 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1279 if (dwarf_ranges_section
)
1280 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1282 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1284 if (dwarf_loc_section
)
1285 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1287 dwarf2_per_objfile
->loc_buffer
= NULL
;
1290 || (objfile
->global_psymbols
.size
== 0
1291 && objfile
->static_psymbols
.size
== 0))
1293 init_psymbol_list (objfile
, 1024);
1297 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1299 /* Things are significantly easier if we have .debug_aranges and
1300 .debug_pubnames sections */
1302 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1306 /* only test this case for now */
1308 /* In this case we have to work a bit harder */
1309 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1314 /* Build the partial symbol table from the information in the
1315 .debug_pubnames and .debug_aranges sections. */
1318 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1320 bfd
*abfd
= objfile
->obfd
;
1321 char *aranges_buffer
, *pubnames_buffer
;
1322 char *aranges_ptr
, *pubnames_ptr
;
1323 unsigned int entry_length
, version
, info_offset
, info_size
;
1325 pubnames_buffer
= dwarf2_read_section (objfile
,
1326 dwarf_pubnames_section
);
1327 pubnames_ptr
= pubnames_buffer
;
1328 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1330 unsigned int bytes_read
;
1332 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1333 pubnames_ptr
+= bytes_read
;
1334 version
= read_1_byte (abfd
, pubnames_ptr
);
1336 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1338 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1342 aranges_buffer
= dwarf2_read_section (objfile
,
1343 dwarf_aranges_section
);
1348 /* Return TRUE if OFFSET is within CU_HEADER. */
1351 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1353 unsigned int bottom
= cu_header
->offset
;
1354 unsigned int top
= (cu_header
->offset
1356 + cu_header
->initial_length_size
);
1357 return (offset
>= bottom
&& offset
< top
);
1360 /* Read in the comp unit header information from the debug_info at
1364 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1365 gdb_byte
*info_ptr
, bfd
*abfd
)
1368 unsigned int bytes_read
;
1370 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1371 cu_header
->initial_length_size
= bytes_read
;
1372 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1373 info_ptr
+= bytes_read
;
1374 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1376 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1378 info_ptr
+= bytes_read
;
1379 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1381 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1382 if (signed_addr
< 0)
1383 internal_error (__FILE__
, __LINE__
,
1384 _("read_comp_unit_head: dwarf from non elf file"));
1385 cu_header
->signed_addr_p
= signed_addr
;
1391 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1394 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1396 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1398 if (header
->version
!= 2 && header
->version
!= 3)
1399 error (_("Dwarf Error: wrong version in compilation unit header "
1400 "(is %d, should be %d) [in module %s]"), header
->version
,
1401 2, bfd_get_filename (abfd
));
1403 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1404 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1405 "(offset 0x%lx + 6) [in module %s]"),
1406 (long) header
->abbrev_offset
,
1407 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1408 bfd_get_filename (abfd
));
1410 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1411 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1412 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1413 "(offset 0x%lx + 0) [in module %s]"),
1414 (long) header
->length
,
1415 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1416 bfd_get_filename (abfd
));
1421 /* Allocate a new partial symtab for file named NAME and mark this new
1422 partial symtab as being an include of PST. */
1425 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1426 struct objfile
*objfile
)
1428 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1430 subpst
->section_offsets
= pst
->section_offsets
;
1431 subpst
->textlow
= 0;
1432 subpst
->texthigh
= 0;
1434 subpst
->dependencies
= (struct partial_symtab
**)
1435 obstack_alloc (&objfile
->objfile_obstack
,
1436 sizeof (struct partial_symtab
*));
1437 subpst
->dependencies
[0] = pst
;
1438 subpst
->number_of_dependencies
= 1;
1440 subpst
->globals_offset
= 0;
1441 subpst
->n_global_syms
= 0;
1442 subpst
->statics_offset
= 0;
1443 subpst
->n_static_syms
= 0;
1444 subpst
->symtab
= NULL
;
1445 subpst
->read_symtab
= pst
->read_symtab
;
1448 /* No private part is necessary for include psymtabs. This property
1449 can be used to differentiate between such include psymtabs and
1450 the regular ones. */
1451 subpst
->read_symtab_private
= NULL
;
1454 /* Read the Line Number Program data and extract the list of files
1455 included by the source file represented by PST. Build an include
1456 partial symtab for each of these included files.
1458 This procedure assumes that there *is* a Line Number Program in
1459 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1460 before calling this procedure. */
1463 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1464 struct partial_die_info
*pdi
,
1465 struct partial_symtab
*pst
)
1467 struct objfile
*objfile
= cu
->objfile
;
1468 bfd
*abfd
= objfile
->obfd
;
1469 struct line_header
*lh
;
1471 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1473 return; /* No linetable, so no includes. */
1475 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1477 free_line_header (lh
);
1481 /* Build the partial symbol table by doing a quick pass through the
1482 .debug_info and .debug_abbrev sections. */
1485 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1487 /* Instead of reading this into a big buffer, we should probably use
1488 mmap() on architectures that support it. (FIXME) */
1489 bfd
*abfd
= objfile
->obfd
;
1491 gdb_byte
*beg_of_comp_unit
;
1492 struct partial_die_info comp_unit_die
;
1493 struct partial_symtab
*pst
;
1494 struct cleanup
*back_to
;
1497 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1499 /* Any cached compilation units will be linked by the per-objfile
1500 read_in_chain. Make sure to free them when we're done. */
1501 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1503 create_all_comp_units (objfile
);
1505 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1506 (&objfile
->objfile_obstack
);
1508 /* Since the objects we're extracting from .debug_info vary in
1509 length, only the individual functions to extract them (like
1510 read_comp_unit_head and load_partial_die) can really know whether
1511 the buffer is large enough to hold another complete object.
1513 At the moment, they don't actually check that. If .debug_info
1514 holds just one extra byte after the last compilation unit's dies,
1515 then read_comp_unit_head will happily read off the end of the
1516 buffer. read_partial_die is similarly casual. Those functions
1519 For this loop condition, simply checking whether there's any data
1520 left at all should be sufficient. */
1521 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1522 + dwarf2_per_objfile
->info_size
))
1524 struct cleanup
*back_to_inner
;
1525 struct dwarf2_cu cu
;
1526 struct abbrev_info
*abbrev
;
1527 unsigned int bytes_read
;
1528 struct dwarf2_per_cu_data
*this_cu
;
1530 beg_of_comp_unit
= info_ptr
;
1532 memset (&cu
, 0, sizeof (cu
));
1534 obstack_init (&cu
.comp_unit_obstack
);
1536 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1538 cu
.objfile
= objfile
;
1539 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1541 /* Complete the cu_header */
1542 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1543 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1545 cu
.list_in_scope
= &file_symbols
;
1547 /* Read the abbrevs for this compilation unit into a table */
1548 dwarf2_read_abbrevs (abfd
, &cu
);
1549 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1551 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1553 /* Read the compilation unit die */
1554 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1555 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1556 abfd
, info_ptr
, &cu
);
1558 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1560 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1561 + cu
.header
.initial_length_size
);
1562 do_cleanups (back_to_inner
);
1566 /* Set the language we're debugging */
1567 set_cu_language (comp_unit_die
.language
, &cu
);
1569 /* Allocate a new partial symbol table structure */
1570 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1571 comp_unit_die
.name
? comp_unit_die
.name
: "",
1572 /* TEXTLOW and TEXTHIGH are set below. */
1574 objfile
->global_psymbols
.next
,
1575 objfile
->static_psymbols
.next
);
1577 if (comp_unit_die
.dirname
)
1578 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1579 strlen (comp_unit_die
.dirname
),
1580 &objfile
->objfile_obstack
);
1582 pst
->read_symtab_private
= (char *) this_cu
;
1584 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1586 /* Store the function that reads in the rest of the symbol table */
1587 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1589 /* If this compilation unit was already read in, free the
1590 cached copy in order to read it in again. This is
1591 necessary because we skipped some symbols when we first
1592 read in the compilation unit (see load_partial_dies).
1593 This problem could be avoided, but the benefit is
1595 if (this_cu
->cu
!= NULL
)
1596 free_one_cached_comp_unit (this_cu
->cu
);
1598 cu
.per_cu
= this_cu
;
1600 /* Note that this is a pointer to our stack frame, being
1601 added to a global data structure. It will be cleaned up
1602 in free_stack_comp_unit when we finish with this
1603 compilation unit. */
1606 this_cu
->psymtab
= pst
;
1608 /* Possibly set the default values of LOWPC and HIGHPC from
1610 if (cu
.has_ranges_offset
)
1612 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1613 &comp_unit_die
.highpc
, &cu
, pst
))
1614 comp_unit_die
.has_pc_info
= 1;
1616 else if (comp_unit_die
.has_pc_info
1617 && comp_unit_die
.lowpc
< comp_unit_die
.highpc
)
1618 /* Store the contiguous range if it is not empty; it can be empty for
1619 CUs with no code. */
1620 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1621 comp_unit_die
.lowpc
+ baseaddr
,
1622 comp_unit_die
.highpc
+ baseaddr
- 1, pst
);
1624 /* Check if comp unit has_children.
1625 If so, read the rest of the partial symbols from this comp unit.
1626 If not, there's no more debug_info for this comp unit. */
1627 if (comp_unit_die
.has_children
)
1629 struct partial_die_info
*first_die
;
1630 CORE_ADDR lowpc
, highpc
;
1632 lowpc
= ((CORE_ADDR
) -1);
1633 highpc
= ((CORE_ADDR
) 0);
1635 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1637 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1638 ! comp_unit_die
.has_pc_info
, &cu
);
1640 /* If we didn't find a lowpc, set it to highpc to avoid
1641 complaints from `maint check'. */
1642 if (lowpc
== ((CORE_ADDR
) -1))
1645 /* If the compilation unit didn't have an explicit address range,
1646 then use the information extracted from its child dies. */
1647 if (! comp_unit_die
.has_pc_info
)
1649 comp_unit_die
.lowpc
= lowpc
;
1650 comp_unit_die
.highpc
= highpc
;
1653 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1654 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1656 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1657 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1658 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1659 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1660 sort_pst_symbols (pst
);
1662 /* If there is already a psymtab or symtab for a file of this
1663 name, remove it. (If there is a symtab, more drastic things
1664 also happen.) This happens in VxWorks. */
1665 free_named_symtabs (pst
->filename
);
1667 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1668 + cu
.header
.initial_length_size
;
1670 if (comp_unit_die
.has_stmt_list
)
1672 /* Get the list of files included in the current compilation unit,
1673 and build a psymtab for each of them. */
1674 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1677 do_cleanups (back_to_inner
);
1680 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1681 &objfile
->objfile_obstack
);
1683 do_cleanups (back_to
);
1686 /* Load the DIEs for a secondary CU into memory. */
1689 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1691 bfd
*abfd
= objfile
->obfd
;
1692 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1693 struct partial_die_info comp_unit_die
;
1694 struct dwarf2_cu
*cu
;
1695 struct abbrev_info
*abbrev
;
1696 unsigned int bytes_read
;
1697 struct cleanup
*back_to
;
1699 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1700 beg_of_comp_unit
= info_ptr
;
1702 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1703 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1705 obstack_init (&cu
->comp_unit_obstack
);
1707 cu
->objfile
= objfile
;
1708 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1710 /* Complete the cu_header. */
1711 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1712 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1714 /* Read the abbrevs for this compilation unit into a table. */
1715 dwarf2_read_abbrevs (abfd
, cu
);
1716 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1718 /* Read the compilation unit die. */
1719 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1720 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1721 abfd
, info_ptr
, cu
);
1723 /* Set the language we're debugging. */
1724 set_cu_language (comp_unit_die
.language
, cu
);
1726 /* Link this compilation unit into the compilation unit tree. */
1728 cu
->per_cu
= this_cu
;
1729 cu
->type_hash
= cu
->per_cu
->type_hash
;
1731 /* Check if comp unit has_children.
1732 If so, read the rest of the partial symbols from this comp unit.
1733 If not, there's no more debug_info for this comp unit. */
1734 if (comp_unit_die
.has_children
)
1735 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1737 do_cleanups (back_to
);
1740 /* Create a list of all compilation units in OBJFILE. We do this only
1741 if an inter-comp-unit reference is found; presumably if there is one,
1742 there will be many, and one will occur early in the .debug_info section.
1743 So there's no point in building this list incrementally. */
1746 create_all_comp_units (struct objfile
*objfile
)
1750 struct dwarf2_per_cu_data
**all_comp_units
;
1751 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1755 all_comp_units
= xmalloc (n_allocated
1756 * sizeof (struct dwarf2_per_cu_data
*));
1758 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1760 unsigned int length
, initial_length_size
;
1761 gdb_byte
*beg_of_comp_unit
;
1762 struct dwarf2_per_cu_data
*this_cu
;
1763 unsigned int offset
;
1765 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1767 /* Read just enough information to find out where the next
1768 compilation unit is. */
1769 length
= read_initial_length (objfile
->obfd
, info_ptr
,
1770 &initial_length_size
);
1772 /* Save the compilation unit for later lookup. */
1773 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1774 sizeof (struct dwarf2_per_cu_data
));
1775 memset (this_cu
, 0, sizeof (*this_cu
));
1776 this_cu
->offset
= offset
;
1777 this_cu
->length
= length
+ initial_length_size
;
1779 if (n_comp_units
== n_allocated
)
1782 all_comp_units
= xrealloc (all_comp_units
,
1784 * sizeof (struct dwarf2_per_cu_data
*));
1786 all_comp_units
[n_comp_units
++] = this_cu
;
1788 info_ptr
= info_ptr
+ this_cu
->length
;
1791 dwarf2_per_objfile
->all_comp_units
1792 = obstack_alloc (&objfile
->objfile_obstack
,
1793 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1794 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1795 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1796 xfree (all_comp_units
);
1797 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1800 /* Process all loaded DIEs for compilation unit CU, starting at
1801 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
1802 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
1803 DW_AT_ranges). If NEED_PC is set, then this function will set
1804 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
1805 and record the covered ranges in the addrmap. */
1808 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1809 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
1811 struct objfile
*objfile
= cu
->objfile
;
1812 bfd
*abfd
= objfile
->obfd
;
1813 struct partial_die_info
*pdi
;
1815 /* Now, march along the PDI's, descending into ones which have
1816 interesting children but skipping the children of the other ones,
1817 until we reach the end of the compilation unit. */
1823 fixup_partial_die (pdi
, cu
);
1825 /* Anonymous namespaces have no name but have interesting
1826 children, so we need to look at them. Ditto for anonymous
1829 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1830 || pdi
->tag
== DW_TAG_enumeration_type
)
1834 case DW_TAG_subprogram
:
1835 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
1837 case DW_TAG_variable
:
1838 case DW_TAG_typedef
:
1839 case DW_TAG_union_type
:
1840 if (!pdi
->is_declaration
)
1842 add_partial_symbol (pdi
, cu
);
1845 case DW_TAG_class_type
:
1846 case DW_TAG_interface_type
:
1847 case DW_TAG_structure_type
:
1848 if (!pdi
->is_declaration
)
1850 add_partial_symbol (pdi
, cu
);
1853 case DW_TAG_enumeration_type
:
1854 if (!pdi
->is_declaration
)
1855 add_partial_enumeration (pdi
, cu
);
1857 case DW_TAG_base_type
:
1858 case DW_TAG_subrange_type
:
1859 /* File scope base type definitions are added to the partial
1861 add_partial_symbol (pdi
, cu
);
1863 case DW_TAG_namespace
:
1864 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
1867 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
1874 /* If the die has a sibling, skip to the sibling. */
1876 pdi
= pdi
->die_sibling
;
1880 /* Functions used to compute the fully scoped name of a partial DIE.
1882 Normally, this is simple. For C++, the parent DIE's fully scoped
1883 name is concatenated with "::" and the partial DIE's name. For
1884 Java, the same thing occurs except that "." is used instead of "::".
1885 Enumerators are an exception; they use the scope of their parent
1886 enumeration type, i.e. the name of the enumeration type is not
1887 prepended to the enumerator.
1889 There are two complexities. One is DW_AT_specification; in this
1890 case "parent" means the parent of the target of the specification,
1891 instead of the direct parent of the DIE. The other is compilers
1892 which do not emit DW_TAG_namespace; in this case we try to guess
1893 the fully qualified name of structure types from their members'
1894 linkage names. This must be done using the DIE's children rather
1895 than the children of any DW_AT_specification target. We only need
1896 to do this for structures at the top level, i.e. if the target of
1897 any DW_AT_specification (if any; otherwise the DIE itself) does not
1900 /* Compute the scope prefix associated with PDI's parent, in
1901 compilation unit CU. The result will be allocated on CU's
1902 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1903 field. NULL is returned if no prefix is necessary. */
1905 partial_die_parent_scope (struct partial_die_info
*pdi
,
1906 struct dwarf2_cu
*cu
)
1908 char *grandparent_scope
;
1909 struct partial_die_info
*parent
, *real_pdi
;
1911 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1912 then this means the parent of the specification DIE. */
1915 while (real_pdi
->has_specification
)
1916 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1918 parent
= real_pdi
->die_parent
;
1922 if (parent
->scope_set
)
1923 return parent
->scope
;
1925 fixup_partial_die (parent
, cu
);
1927 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1929 if (parent
->tag
== DW_TAG_namespace
1930 || parent
->tag
== DW_TAG_structure_type
1931 || parent
->tag
== DW_TAG_class_type
1932 || parent
->tag
== DW_TAG_interface_type
1933 || parent
->tag
== DW_TAG_union_type
)
1935 if (grandparent_scope
== NULL
)
1936 parent
->scope
= parent
->name
;
1938 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1941 else if (parent
->tag
== DW_TAG_enumeration_type
)
1942 /* Enumerators should not get the name of the enumeration as a prefix. */
1943 parent
->scope
= grandparent_scope
;
1946 /* FIXME drow/2004-04-01: What should we be doing with
1947 function-local names? For partial symbols, we should probably be
1949 complaint (&symfile_complaints
,
1950 _("unhandled containing DIE tag %d for DIE at %d"),
1951 parent
->tag
, pdi
->offset
);
1952 parent
->scope
= grandparent_scope
;
1955 parent
->scope_set
= 1;
1956 return parent
->scope
;
1959 /* Return the fully scoped name associated with PDI, from compilation unit
1960 CU. The result will be allocated with malloc. */
1962 partial_die_full_name (struct partial_die_info
*pdi
,
1963 struct dwarf2_cu
*cu
)
1967 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1968 if (parent_scope
== NULL
)
1971 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1975 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1977 struct objfile
*objfile
= cu
->objfile
;
1979 char *actual_name
= NULL
;
1980 const char *my_prefix
;
1981 const struct partial_symbol
*psym
= NULL
;
1983 int built_actual_name
= 0;
1985 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1987 if (pdi_needs_namespace (pdi
->tag
))
1989 actual_name
= partial_die_full_name (pdi
, cu
);
1991 built_actual_name
= 1;
1994 if (actual_name
== NULL
)
1995 actual_name
= pdi
->name
;
1999 case DW_TAG_subprogram
:
2000 if (pdi
->is_external
|| cu
->language
== language_ada
)
2002 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2003 of the global scope. But in Ada, we want to be able to access
2004 nested procedures globally. So all Ada subprograms are stored
2005 in the global scope. */
2006 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2007 mst_text, objfile); */
2008 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2009 VAR_DOMAIN
, LOC_BLOCK
,
2010 &objfile
->global_psymbols
,
2011 0, pdi
->lowpc
+ baseaddr
,
2012 cu
->language
, objfile
);
2016 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2017 mst_file_text, objfile); */
2018 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2019 VAR_DOMAIN
, LOC_BLOCK
,
2020 &objfile
->static_psymbols
,
2021 0, pdi
->lowpc
+ baseaddr
,
2022 cu
->language
, objfile
);
2025 case DW_TAG_variable
:
2026 if (pdi
->is_external
)
2029 Don't enter into the minimal symbol tables as there is
2030 a minimal symbol table entry from the ELF symbols already.
2031 Enter into partial symbol table if it has a location
2032 descriptor or a type.
2033 If the location descriptor is missing, new_symbol will create
2034 a LOC_UNRESOLVED symbol, the address of the variable will then
2035 be determined from the minimal symbol table whenever the variable
2037 The address for the partial symbol table entry is not
2038 used by GDB, but it comes in handy for debugging partial symbol
2042 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2043 if (pdi
->locdesc
|| pdi
->has_type
)
2044 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2045 VAR_DOMAIN
, LOC_STATIC
,
2046 &objfile
->global_psymbols
,
2048 cu
->language
, objfile
);
2052 /* Static Variable. Skip symbols without location descriptors. */
2053 if (pdi
->locdesc
== NULL
)
2055 if (built_actual_name
)
2056 xfree (actual_name
);
2059 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2060 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2061 mst_file_data, objfile); */
2062 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2063 VAR_DOMAIN
, LOC_STATIC
,
2064 &objfile
->static_psymbols
,
2066 cu
->language
, objfile
);
2069 case DW_TAG_typedef
:
2070 case DW_TAG_base_type
:
2071 case DW_TAG_subrange_type
:
2072 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2073 VAR_DOMAIN
, LOC_TYPEDEF
,
2074 &objfile
->static_psymbols
,
2075 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2077 case DW_TAG_namespace
:
2078 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2079 VAR_DOMAIN
, LOC_TYPEDEF
,
2080 &objfile
->global_psymbols
,
2081 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2083 case DW_TAG_class_type
:
2084 case DW_TAG_interface_type
:
2085 case DW_TAG_structure_type
:
2086 case DW_TAG_union_type
:
2087 case DW_TAG_enumeration_type
:
2088 /* Skip external references. The DWARF standard says in the section
2089 about "Structure, Union, and Class Type Entries": "An incomplete
2090 structure, union or class type is represented by a structure,
2091 union or class entry that does not have a byte size attribute
2092 and that has a DW_AT_declaration attribute." */
2093 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2095 if (built_actual_name
)
2096 xfree (actual_name
);
2100 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2101 static vs. global. */
2102 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2103 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2104 (cu
->language
== language_cplus
2105 || cu
->language
== language_java
)
2106 ? &objfile
->global_psymbols
2107 : &objfile
->static_psymbols
,
2108 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2111 case DW_TAG_enumerator
:
2112 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2113 VAR_DOMAIN
, LOC_CONST
,
2114 (cu
->language
== language_cplus
2115 || cu
->language
== language_java
)
2116 ? &objfile
->global_psymbols
2117 : &objfile
->static_psymbols
,
2118 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2124 /* Check to see if we should scan the name for possible namespace
2125 info. Only do this if this is C++, if we don't have namespace
2126 debugging info in the file, if the psym is of an appropriate type
2127 (otherwise we'll have psym == NULL), and if we actually had a
2128 mangled name to begin with. */
2130 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2131 cases which do not set PSYM above? */
2133 if (cu
->language
== language_cplus
2134 && cu
->has_namespace_info
== 0
2136 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2137 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2140 if (built_actual_name
)
2141 xfree (actual_name
);
2144 /* Determine whether a die of type TAG living in a C++ class or
2145 namespace needs to have the name of the scope prepended to the
2146 name listed in the die. */
2149 pdi_needs_namespace (enum dwarf_tag tag
)
2153 case DW_TAG_namespace
:
2154 case DW_TAG_typedef
:
2155 case DW_TAG_class_type
:
2156 case DW_TAG_interface_type
:
2157 case DW_TAG_structure_type
:
2158 case DW_TAG_union_type
:
2159 case DW_TAG_enumeration_type
:
2160 case DW_TAG_enumerator
:
2167 /* Read a partial die corresponding to a namespace; also, add a symbol
2168 corresponding to that namespace to the symbol table. NAMESPACE is
2169 the name of the enclosing namespace. */
2172 add_partial_namespace (struct partial_die_info
*pdi
,
2173 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2174 int need_pc
, struct dwarf2_cu
*cu
)
2176 struct objfile
*objfile
= cu
->objfile
;
2178 /* Add a symbol for the namespace. */
2180 add_partial_symbol (pdi
, cu
);
2182 /* Now scan partial symbols in that namespace. */
2184 if (pdi
->has_children
)
2185 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2188 /* Read a partial die corresponding to a Fortran module. */
2191 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2192 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2194 /* Now scan partial symbols in that module.
2196 FIXME: Support the separate Fortran module namespaces. */
2198 if (pdi
->has_children
)
2199 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2202 /* Read a partial die corresponding to a subprogram and create a partial
2203 symbol for that subprogram. When the CU language allows it, this
2204 routine also defines a partial symbol for each nested subprogram
2205 that this subprogram contains.
2207 DIE my also be a lexical block, in which case we simply search
2208 recursively for suprograms defined inside that lexical block.
2209 Again, this is only performed when the CU language allows this
2210 type of definitions. */
2213 add_partial_subprogram (struct partial_die_info
*pdi
,
2214 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2215 int need_pc
, struct dwarf2_cu
*cu
)
2217 if (pdi
->tag
== DW_TAG_subprogram
)
2219 if (pdi
->has_pc_info
)
2221 if (pdi
->lowpc
< *lowpc
)
2222 *lowpc
= pdi
->lowpc
;
2223 if (pdi
->highpc
> *highpc
)
2224 *highpc
= pdi
->highpc
;
2228 struct objfile
*objfile
= cu
->objfile
;
2230 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2231 SECT_OFF_TEXT (objfile
));
2232 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2233 pdi
->lowpc
, pdi
->highpc
- 1,
2234 cu
->per_cu
->psymtab
);
2236 if (!pdi
->is_declaration
)
2237 add_partial_symbol (pdi
, cu
);
2241 if (! pdi
->has_children
)
2244 if (cu
->language
== language_ada
)
2246 pdi
= pdi
->die_child
;
2249 fixup_partial_die (pdi
, cu
);
2250 if (pdi
->tag
== DW_TAG_subprogram
2251 || pdi
->tag
== DW_TAG_lexical_block
)
2252 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2253 pdi
= pdi
->die_sibling
;
2258 /* See if we can figure out if the class lives in a namespace. We do
2259 this by looking for a member function; its demangled name will
2260 contain namespace info, if there is any. */
2263 guess_structure_name (struct partial_die_info
*struct_pdi
,
2264 struct dwarf2_cu
*cu
)
2266 if ((cu
->language
== language_cplus
2267 || cu
->language
== language_java
)
2268 && cu
->has_namespace_info
== 0
2269 && struct_pdi
->has_children
)
2271 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2272 what template types look like, because the demangler
2273 frequently doesn't give the same name as the debug info. We
2274 could fix this by only using the demangled name to get the
2275 prefix (but see comment in read_structure_type). */
2277 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2278 struct partial_die_info
*real_pdi
;
2280 /* If this DIE (this DIE's specification, if any) has a parent, then
2281 we should not do this. We'll prepend the parent's fully qualified
2282 name when we create the partial symbol. */
2284 real_pdi
= struct_pdi
;
2285 while (real_pdi
->has_specification
)
2286 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2288 if (real_pdi
->die_parent
!= NULL
)
2291 while (child_pdi
!= NULL
)
2293 if (child_pdi
->tag
== DW_TAG_subprogram
)
2295 char *actual_class_name
2296 = language_class_name_from_physname (cu
->language_defn
,
2298 if (actual_class_name
!= NULL
)
2301 = obsavestring (actual_class_name
,
2302 strlen (actual_class_name
),
2303 &cu
->comp_unit_obstack
);
2304 xfree (actual_class_name
);
2309 child_pdi
= child_pdi
->die_sibling
;
2314 /* Read a partial die corresponding to an enumeration type. */
2317 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2318 struct dwarf2_cu
*cu
)
2320 struct objfile
*objfile
= cu
->objfile
;
2321 bfd
*abfd
= objfile
->obfd
;
2322 struct partial_die_info
*pdi
;
2324 if (enum_pdi
->name
!= NULL
)
2325 add_partial_symbol (enum_pdi
, cu
);
2327 pdi
= enum_pdi
->die_child
;
2330 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2331 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2333 add_partial_symbol (pdi
, cu
);
2334 pdi
= pdi
->die_sibling
;
2338 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2339 Return the corresponding abbrev, or NULL if the number is zero (indicating
2340 an empty DIE). In either case *BYTES_READ will be set to the length of
2341 the initial number. */
2343 static struct abbrev_info
*
2344 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2345 struct dwarf2_cu
*cu
)
2347 bfd
*abfd
= cu
->objfile
->obfd
;
2348 unsigned int abbrev_number
;
2349 struct abbrev_info
*abbrev
;
2351 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2353 if (abbrev_number
== 0)
2356 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2359 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2360 bfd_get_filename (abfd
));
2366 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2367 pointer to the end of a series of DIEs, terminated by an empty
2368 DIE. Any children of the skipped DIEs will also be skipped. */
2371 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2373 struct abbrev_info
*abbrev
;
2374 unsigned int bytes_read
;
2378 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2380 return info_ptr
+ bytes_read
;
2382 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2386 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2387 should point just after the initial uleb128 of a DIE, and the
2388 abbrev corresponding to that skipped uleb128 should be passed in
2389 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2393 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2394 struct dwarf2_cu
*cu
)
2396 unsigned int bytes_read
;
2397 struct attribute attr
;
2398 bfd
*abfd
= cu
->objfile
->obfd
;
2399 unsigned int form
, i
;
2401 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2403 /* The only abbrev we care about is DW_AT_sibling. */
2404 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2406 read_attribute (&attr
, &abbrev
->attrs
[i
],
2407 abfd
, info_ptr
, cu
);
2408 if (attr
.form
== DW_FORM_ref_addr
)
2409 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2411 return dwarf2_per_objfile
->info_buffer
2412 + dwarf2_get_ref_die_offset (&attr
);
2415 /* If it isn't DW_AT_sibling, skip this attribute. */
2416 form
= abbrev
->attrs
[i
].form
;
2421 case DW_FORM_ref_addr
:
2422 info_ptr
+= cu
->header
.addr_size
;
2441 case DW_FORM_string
:
2442 read_string (abfd
, info_ptr
, &bytes_read
);
2443 info_ptr
+= bytes_read
;
2446 info_ptr
+= cu
->header
.offset_size
;
2449 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2450 info_ptr
+= bytes_read
;
2452 case DW_FORM_block1
:
2453 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2455 case DW_FORM_block2
:
2456 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2458 case DW_FORM_block4
:
2459 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2463 case DW_FORM_ref_udata
:
2464 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2466 case DW_FORM_indirect
:
2467 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2468 info_ptr
+= bytes_read
;
2469 /* We need to continue parsing from here, so just go back to
2471 goto skip_attribute
;
2474 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2475 dwarf_form_name (form
),
2476 bfd_get_filename (abfd
));
2480 if (abbrev
->has_children
)
2481 return skip_children (info_ptr
, cu
);
2486 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2487 the next DIE after ORIG_PDI. */
2490 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2491 bfd
*abfd
, struct dwarf2_cu
*cu
)
2493 /* Do we know the sibling already? */
2495 if (orig_pdi
->sibling
)
2496 return orig_pdi
->sibling
;
2498 /* Are there any children to deal with? */
2500 if (!orig_pdi
->has_children
)
2503 /* Skip the children the long way. */
2505 return skip_children (info_ptr
, cu
);
2508 /* Expand this partial symbol table into a full symbol table. */
2511 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2513 /* FIXME: This is barely more than a stub. */
2518 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2524 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2525 gdb_flush (gdb_stdout
);
2528 /* Restore our global data. */
2529 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2530 dwarf2_objfile_data_key
);
2532 psymtab_to_symtab_1 (pst
);
2534 /* Finish up the debug error message. */
2536 printf_filtered (_("done.\n"));
2541 /* Add PER_CU to the queue. */
2544 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2546 struct dwarf2_queue_item
*item
;
2549 item
= xmalloc (sizeof (*item
));
2550 item
->per_cu
= per_cu
;
2553 if (dwarf2_queue
== NULL
)
2554 dwarf2_queue
= item
;
2556 dwarf2_queue_tail
->next
= item
;
2558 dwarf2_queue_tail
= item
;
2560 /* Either PER_CU is the CU we want to process, or we're following a reference
2561 pointing into PER_CU. Either way, we need its DIEs now. */
2562 load_full_comp_unit (item
->per_cu
, objfile
);
2563 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2564 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2567 /* Process the queue. */
2570 process_queue (struct objfile
*objfile
)
2572 struct dwarf2_queue_item
*item
, *next_item
;
2574 /* The queue starts out with one item, but following a DIE reference
2575 may load a new CU, adding it to the end of the queue. */
2576 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2578 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2579 process_full_comp_unit (item
->per_cu
);
2581 item
->per_cu
->queued
= 0;
2582 next_item
= item
->next
;
2586 dwarf2_queue_tail
= NULL
;
2589 /* Free all allocated queue entries. This function only releases anything if
2590 an error was thrown; if the queue was processed then it would have been
2591 freed as we went along. */
2594 dwarf2_release_queue (void *dummy
)
2596 struct dwarf2_queue_item
*item
, *last
;
2598 item
= dwarf2_queue
;
2601 /* Anything still marked queued is likely to be in an
2602 inconsistent state, so discard it. */
2603 if (item
->per_cu
->queued
)
2605 if (item
->per_cu
->cu
!= NULL
)
2606 free_one_cached_comp_unit (item
->per_cu
->cu
);
2607 item
->per_cu
->queued
= 0;
2615 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2618 /* Read in full symbols for PST, and anything it depends on. */
2621 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2623 struct dwarf2_per_cu_data
*per_cu
;
2624 struct cleanup
*back_to
;
2627 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2628 if (!pst
->dependencies
[i
]->readin
)
2630 /* Inform about additional files that need to be read in. */
2633 /* FIXME: i18n: Need to make this a single string. */
2634 fputs_filtered (" ", gdb_stdout
);
2636 fputs_filtered ("and ", gdb_stdout
);
2638 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2639 wrap_here (""); /* Flush output */
2640 gdb_flush (gdb_stdout
);
2642 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2645 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2649 /* It's an include file, no symbols to read for it.
2650 Everything is in the parent symtab. */
2655 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2657 queue_comp_unit (per_cu
, pst
->objfile
);
2659 process_queue (pst
->objfile
);
2661 /* Age the cache, releasing compilation units that have not
2662 been used recently. */
2663 age_cached_comp_units ();
2665 do_cleanups (back_to
);
2668 /* Load the DIEs associated with PST and PER_CU into memory. */
2670 static struct dwarf2_cu
*
2671 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2673 bfd
*abfd
= objfile
->obfd
;
2674 struct dwarf2_cu
*cu
;
2675 unsigned int offset
;
2677 struct cleanup
*back_to
, *free_cu_cleanup
;
2678 struct attribute
*attr
;
2681 /* Set local variables from the partial symbol table info. */
2682 offset
= per_cu
->offset
;
2684 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2686 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2687 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2689 /* If an error occurs while loading, release our storage. */
2690 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2692 cu
->objfile
= objfile
;
2694 /* read in the comp_unit header */
2695 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2697 /* Read the abbrevs for this compilation unit */
2698 dwarf2_read_abbrevs (abfd
, cu
);
2699 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2701 cu
->header
.offset
= offset
;
2703 cu
->per_cu
= per_cu
;
2705 cu
->type_hash
= per_cu
->type_hash
;
2707 /* We use this obstack for block values in dwarf_alloc_block. */
2708 obstack_init (&cu
->comp_unit_obstack
);
2710 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2712 /* We try not to read any attributes in this function, because not
2713 all objfiles needed for references have been loaded yet, and symbol
2714 table processing isn't initialized. But we have to set the CU language,
2715 or we won't be able to build types correctly. */
2716 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2718 set_cu_language (DW_UNSND (attr
), cu
);
2720 set_cu_language (language_minimal
, cu
);
2722 do_cleanups (back_to
);
2724 /* We've successfully allocated this compilation unit. Let our caller
2725 clean it up when finished with it. */
2726 discard_cleanups (free_cu_cleanup
);
2731 /* Generate full symbol information for PST and CU, whose DIEs have
2732 already been loaded into memory. */
2735 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2737 struct partial_symtab
*pst
= per_cu
->psymtab
;
2738 struct dwarf2_cu
*cu
= per_cu
->cu
;
2739 struct objfile
*objfile
= pst
->objfile
;
2740 bfd
*abfd
= objfile
->obfd
;
2741 CORE_ADDR lowpc
, highpc
;
2742 struct symtab
*symtab
;
2743 struct cleanup
*back_to
;
2744 struct attribute
*attr
;
2747 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2750 back_to
= make_cleanup (really_free_pendings
, NULL
);
2752 cu
->list_in_scope
= &file_symbols
;
2754 /* Find the base address of the compilation unit for range lists and
2755 location lists. It will normally be specified by DW_AT_low_pc.
2756 In DWARF-3 draft 4, the base address could be overridden by
2757 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2758 compilation units with discontinuous ranges. */
2761 cu
->base_address
= 0;
2763 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2766 cu
->base_address
= DW_ADDR (attr
);
2771 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2774 cu
->base_address
= DW_ADDR (attr
);
2779 /* Do line number decoding in read_file_scope () */
2780 process_die (cu
->dies
, cu
);
2782 /* Some compilers don't define a DW_AT_high_pc attribute for the
2783 compilation unit. If the DW_AT_high_pc is missing, synthesize
2784 it, by scanning the DIE's below the compilation unit. */
2785 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2787 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2789 /* Set symtab language to language from DW_AT_language.
2790 If the compilation is from a C file generated by language preprocessors,
2791 do not set the language if it was already deduced by start_subfile. */
2793 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2795 symtab
->language
= cu
->language
;
2797 pst
->symtab
= symtab
;
2800 do_cleanups (back_to
);
2803 /* Process a die and its children. */
2806 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2810 case DW_TAG_padding
:
2812 case DW_TAG_compile_unit
:
2813 read_file_scope (die
, cu
);
2815 case DW_TAG_subprogram
:
2816 read_func_scope (die
, cu
);
2818 case DW_TAG_inlined_subroutine
:
2819 /* FIXME: These are ignored for now.
2820 They could be used to set breakpoints on all inlined instances
2821 of a function and make GDB `next' properly over inlined functions. */
2823 case DW_TAG_lexical_block
:
2824 case DW_TAG_try_block
:
2825 case DW_TAG_catch_block
:
2826 read_lexical_block_scope (die
, cu
);
2828 case DW_TAG_class_type
:
2829 case DW_TAG_interface_type
:
2830 case DW_TAG_structure_type
:
2831 case DW_TAG_union_type
:
2832 process_structure_scope (die
, cu
);
2834 case DW_TAG_enumeration_type
:
2835 process_enumeration_scope (die
, cu
);
2838 /* These dies have a type, but processing them does not create
2839 a symbol or recurse to process the children. Therefore we can
2840 read them on-demand through read_type_die. */
2841 case DW_TAG_subroutine_type
:
2842 case DW_TAG_set_type
:
2843 case DW_TAG_array_type
:
2844 case DW_TAG_pointer_type
:
2845 case DW_TAG_ptr_to_member_type
:
2846 case DW_TAG_reference_type
:
2847 case DW_TAG_string_type
:
2850 case DW_TAG_base_type
:
2851 case DW_TAG_subrange_type
:
2852 /* Add a typedef symbol for the type definition, if it has a
2854 new_symbol (die
, read_type_die (die
, cu
), cu
);
2856 case DW_TAG_common_block
:
2857 read_common_block (die
, cu
);
2859 case DW_TAG_common_inclusion
:
2861 case DW_TAG_namespace
:
2862 processing_has_namespace_info
= 1;
2863 read_namespace (die
, cu
);
2866 read_module (die
, cu
);
2868 case DW_TAG_imported_declaration
:
2869 case DW_TAG_imported_module
:
2870 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2871 information contained in these. DW_TAG_imported_declaration
2872 dies shouldn't have children; DW_TAG_imported_module dies
2873 shouldn't in the C++ case, but conceivably could in the
2875 processing_has_namespace_info
= 1;
2876 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2877 dwarf_tag_name (die
->tag
));
2880 new_symbol (die
, NULL
, cu
);
2885 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2886 If scope qualifiers are appropriate they will be added. The result
2887 will be allocated on the objfile_obstack, or NULL if the DIE does
2891 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2893 struct attribute
*attr
;
2894 char *prefix
, *name
;
2895 struct ui_file
*buf
= NULL
;
2897 name
= dwarf2_name (die
, cu
);
2901 /* These are the only languages we know how to qualify names in. */
2902 if (cu
->language
!= language_cplus
2903 && cu
->language
!= language_java
)
2906 /* If no prefix is necessary for this type of DIE, return the
2907 unqualified name. The other three tags listed could be handled
2908 in pdi_needs_namespace, but that requires broader changes. */
2909 if (!pdi_needs_namespace (die
->tag
)
2910 && die
->tag
!= DW_TAG_subprogram
2911 && die
->tag
!= DW_TAG_variable
2912 && die
->tag
!= DW_TAG_member
)
2915 prefix
= determine_prefix (die
, cu
);
2916 if (*prefix
!= '\0')
2917 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2924 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2926 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2930 free_cu_line_header (void *arg
)
2932 struct dwarf2_cu
*cu
= arg
;
2934 free_line_header (cu
->line_header
);
2935 cu
->line_header
= NULL
;
2939 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2941 struct objfile
*objfile
= cu
->objfile
;
2942 struct comp_unit_head
*cu_header
= &cu
->header
;
2943 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2944 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2945 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2946 struct attribute
*attr
;
2948 char *comp_dir
= NULL
;
2949 struct die_info
*child_die
;
2950 bfd
*abfd
= objfile
->obfd
;
2951 struct line_header
*line_header
= 0;
2954 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2956 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2958 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2959 from finish_block. */
2960 if (lowpc
== ((CORE_ADDR
) -1))
2965 /* Find the filename. Do not use dwarf2_name here, since the filename
2966 is not a source language identifier. */
2967 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2970 name
= DW_STRING (attr
);
2973 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2975 comp_dir
= DW_STRING (attr
);
2976 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2978 comp_dir
= ldirname (name
);
2979 if (comp_dir
!= NULL
)
2980 make_cleanup (xfree
, comp_dir
);
2982 if (comp_dir
!= NULL
)
2984 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2985 directory, get rid of it. */
2986 char *cp
= strchr (comp_dir
, ':');
2988 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2995 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2998 set_cu_language (DW_UNSND (attr
), cu
);
3001 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3003 cu
->producer
= DW_STRING (attr
);
3005 /* We assume that we're processing GCC output. */
3006 processing_gcc_compilation
= 2;
3008 processing_has_namespace_info
= 0;
3010 start_symtab (name
, comp_dir
, lowpc
);
3011 record_debugformat ("DWARF 2");
3012 record_producer (cu
->producer
);
3014 initialize_cu_func_list (cu
);
3016 /* Decode line number information if present. We do this before
3017 processing child DIEs, so that the line header table is available
3018 for DW_AT_decl_file. */
3019 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3022 unsigned int line_offset
= DW_UNSND (attr
);
3023 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3026 cu
->line_header
= line_header
;
3027 make_cleanup (free_cu_line_header
, cu
);
3028 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3032 /* Process all dies in compilation unit. */
3033 if (die
->child
!= NULL
)
3035 child_die
= die
->child
;
3036 while (child_die
&& child_die
->tag
)
3038 process_die (child_die
, cu
);
3039 child_die
= sibling_die (child_die
);
3043 /* Decode macro information, if present. Dwarf 2 macro information
3044 refers to information in the line number info statement program
3045 header, so we can only read it if we've read the header
3047 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3048 if (attr
&& line_header
)
3050 unsigned int macro_offset
= DW_UNSND (attr
);
3051 dwarf_decode_macros (line_header
, macro_offset
,
3052 comp_dir
, abfd
, cu
);
3054 do_cleanups (back_to
);
3058 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3059 struct dwarf2_cu
*cu
)
3061 struct function_range
*thisfn
;
3063 thisfn
= (struct function_range
*)
3064 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3065 thisfn
->name
= name
;
3066 thisfn
->lowpc
= lowpc
;
3067 thisfn
->highpc
= highpc
;
3068 thisfn
->seen_line
= 0;
3069 thisfn
->next
= NULL
;
3071 if (cu
->last_fn
== NULL
)
3072 cu
->first_fn
= thisfn
;
3074 cu
->last_fn
->next
= thisfn
;
3076 cu
->last_fn
= thisfn
;
3080 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3082 struct objfile
*objfile
= cu
->objfile
;
3083 struct context_stack
*new;
3086 struct die_info
*child_die
;
3087 struct attribute
*attr
;
3090 struct block
*block
;
3092 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3094 name
= dwarf2_linkage_name (die
, cu
);
3096 /* Ignore functions with missing or empty names and functions with
3097 missing or invalid low and high pc attributes. */
3098 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3104 /* Record the function range for dwarf_decode_lines. */
3105 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3107 new = push_context (0, lowpc
);
3108 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3110 /* If there is a location expression for DW_AT_frame_base, record
3112 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3114 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3115 expression is being recorded directly in the function's symbol
3116 and not in a separate frame-base object. I guess this hack is
3117 to avoid adding some sort of frame-base adjunct/annex to the
3118 function's symbol :-(. The problem with doing this is that it
3119 results in a function symbol with a location expression that
3120 has nothing to do with the location of the function, ouch! The
3121 relationship should be: a function's symbol has-a frame base; a
3122 frame-base has-a location expression. */
3123 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3125 cu
->list_in_scope
= &local_symbols
;
3127 if (die
->child
!= NULL
)
3129 child_die
= die
->child
;
3130 while (child_die
&& child_die
->tag
)
3132 process_die (child_die
, cu
);
3133 child_die
= sibling_die (child_die
);
3137 new = pop_context ();
3138 /* Make a block for the local symbols within. */
3139 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3140 lowpc
, highpc
, objfile
);
3142 /* For C++, set the block's scope. */
3143 if (cu
->language
== language_cplus
)
3144 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3145 determine_prefix (die
, cu
),
3146 processing_has_namespace_info
);
3148 /* If we have address ranges, record them. */
3149 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3151 /* In C++, we can have functions nested inside functions (e.g., when
3152 a function declares a class that has methods). This means that
3153 when we finish processing a function scope, we may need to go
3154 back to building a containing block's symbol lists. */
3155 local_symbols
= new->locals
;
3156 param_symbols
= new->params
;
3158 /* If we've finished processing a top-level function, subsequent
3159 symbols go in the file symbol list. */
3160 if (outermost_context_p ())
3161 cu
->list_in_scope
= &file_symbols
;
3164 /* Process all the DIES contained within a lexical block scope. Start
3165 a new scope, process the dies, and then close the scope. */
3168 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3170 struct objfile
*objfile
= cu
->objfile
;
3171 struct context_stack
*new;
3172 CORE_ADDR lowpc
, highpc
;
3173 struct die_info
*child_die
;
3176 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3178 /* Ignore blocks with missing or invalid low and high pc attributes. */
3179 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3180 as multiple lexical blocks? Handling children in a sane way would
3181 be nasty. Might be easier to properly extend generic blocks to
3183 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3188 push_context (0, lowpc
);
3189 if (die
->child
!= NULL
)
3191 child_die
= die
->child
;
3192 while (child_die
&& child_die
->tag
)
3194 process_die (child_die
, cu
);
3195 child_die
= sibling_die (child_die
);
3198 new = pop_context ();
3200 if (local_symbols
!= NULL
)
3203 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3206 /* Note that recording ranges after traversing children, as we
3207 do here, means that recording a parent's ranges entails
3208 walking across all its children's ranges as they appear in
3209 the address map, which is quadratic behavior.
3211 It would be nicer to record the parent's ranges before
3212 traversing its children, simply overriding whatever you find
3213 there. But since we don't even decide whether to create a
3214 block until after we've traversed its children, that's hard
3216 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3218 local_symbols
= new->locals
;
3221 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3222 Return 1 if the attributes are present and valid, otherwise, return 0.
3223 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3226 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3227 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3228 struct partial_symtab
*ranges_pst
)
3230 struct objfile
*objfile
= cu
->objfile
;
3231 struct comp_unit_head
*cu_header
= &cu
->header
;
3232 bfd
*obfd
= objfile
->obfd
;
3233 unsigned int addr_size
= cu_header
->addr_size
;
3234 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3235 /* Base address selection entry. */
3246 found_base
= cu
->base_known
;
3247 base
= cu
->base_address
;
3249 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3251 complaint (&symfile_complaints
,
3252 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3256 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3258 /* Read in the largest possible address. */
3259 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3260 if ((marker
& mask
) == mask
)
3262 /* If we found the largest possible address, then
3263 read the base address. */
3264 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3265 buffer
+= 2 * addr_size
;
3266 offset
+= 2 * addr_size
;
3272 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3276 CORE_ADDR range_beginning
, range_end
;
3278 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3279 buffer
+= addr_size
;
3280 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3281 buffer
+= addr_size
;
3282 offset
+= 2 * addr_size
;
3284 /* An end of list marker is a pair of zero addresses. */
3285 if (range_beginning
== 0 && range_end
== 0)
3286 /* Found the end of list entry. */
3289 /* Each base address selection entry is a pair of 2 values.
3290 The first is the largest possible address, the second is
3291 the base address. Check for a base address here. */
3292 if ((range_beginning
& mask
) == mask
)
3294 /* If we found the largest possible address, then
3295 read the base address. */
3296 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3303 /* We have no valid base address for the ranges
3305 complaint (&symfile_complaints
,
3306 _("Invalid .debug_ranges data (no base address)"));
3310 range_beginning
+= base
;
3313 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3314 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3315 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3318 /* FIXME: This is recording everything as a low-high
3319 segment of consecutive addresses. We should have a
3320 data structure for discontiguous block ranges
3324 low
= range_beginning
;
3330 if (range_beginning
< low
)
3331 low
= range_beginning
;
3332 if (range_end
> high
)
3338 /* If the first entry is an end-of-list marker, the range
3339 describes an empty scope, i.e. no instructions. */
3345 *high_return
= high
;
3349 /* Get low and high pc attributes from a die. Return 1 if the attributes
3350 are present and valid, otherwise, return 0. Return -1 if the range is
3351 discontinuous, i.e. derived from DW_AT_ranges information. */
3353 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3354 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3356 struct attribute
*attr
;
3361 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3364 high
= DW_ADDR (attr
);
3365 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3367 low
= DW_ADDR (attr
);
3369 /* Found high w/o low attribute. */
3372 /* Found consecutive range of addresses. */
3377 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3380 /* Value of the DW_AT_ranges attribute is the offset in the
3381 .debug_ranges section. */
3382 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3384 /* Found discontinuous range of addresses. */
3392 /* When using the GNU linker, .gnu.linkonce. sections are used to
3393 eliminate duplicate copies of functions and vtables and such.
3394 The linker will arbitrarily choose one and discard the others.
3395 The AT_*_pc values for such functions refer to local labels in
3396 these sections. If the section from that file was discarded, the
3397 labels are not in the output, so the relocs get a value of 0.
3398 If this is a discarded function, mark the pc bounds as invalid,
3399 so that GDB will ignore it. */
3400 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3408 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3409 its low and high PC addresses. Do nothing if these addresses could not
3410 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3411 and HIGHPC to the high address if greater than HIGHPC. */
3414 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3415 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3416 struct dwarf2_cu
*cu
)
3418 CORE_ADDR low
, high
;
3419 struct die_info
*child
= die
->child
;
3421 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3423 *lowpc
= min (*lowpc
, low
);
3424 *highpc
= max (*highpc
, high
);
3427 /* If the language does not allow nested subprograms (either inside
3428 subprograms or lexical blocks), we're done. */
3429 if (cu
->language
!= language_ada
)
3432 /* Check all the children of the given DIE. If it contains nested
3433 subprograms, then check their pc bounds. Likewise, we need to
3434 check lexical blocks as well, as they may also contain subprogram
3436 while (child
&& child
->tag
)
3438 if (child
->tag
== DW_TAG_subprogram
3439 || child
->tag
== DW_TAG_lexical_block
)
3440 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3441 child
= sibling_die (child
);
3445 /* Get the low and high pc's represented by the scope DIE, and store
3446 them in *LOWPC and *HIGHPC. If the correct values can't be
3447 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3450 get_scope_pc_bounds (struct die_info
*die
,
3451 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3452 struct dwarf2_cu
*cu
)
3454 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3455 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3456 CORE_ADDR current_low
, current_high
;
3458 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3460 best_low
= current_low
;
3461 best_high
= current_high
;
3465 struct die_info
*child
= die
->child
;
3467 while (child
&& child
->tag
)
3469 switch (child
->tag
) {
3470 case DW_TAG_subprogram
:
3471 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3473 case DW_TAG_namespace
:
3474 /* FIXME: carlton/2004-01-16: Should we do this for
3475 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3476 that current GCC's always emit the DIEs corresponding
3477 to definitions of methods of classes as children of a
3478 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3479 the DIEs giving the declarations, which could be
3480 anywhere). But I don't see any reason why the
3481 standards says that they have to be there. */
3482 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3484 if (current_low
!= ((CORE_ADDR
) -1))
3486 best_low
= min (best_low
, current_low
);
3487 best_high
= max (best_high
, current_high
);
3495 child
= sibling_die (child
);
3500 *highpc
= best_high
;
3503 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3506 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3507 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3509 struct attribute
*attr
;
3511 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3514 CORE_ADDR high
= DW_ADDR (attr
);
3515 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3518 CORE_ADDR low
= DW_ADDR (attr
);
3519 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3523 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3526 bfd
*obfd
= cu
->objfile
->obfd
;
3528 /* The value of the DW_AT_ranges attribute is the offset of the
3529 address range list in the .debug_ranges section. */
3530 unsigned long offset
= DW_UNSND (attr
);
3531 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3533 /* For some target architectures, but not others, the
3534 read_address function sign-extends the addresses it returns.
3535 To recognize base address selection entries, we need a
3537 unsigned int addr_size
= cu
->header
.addr_size
;
3538 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3540 /* The base address, to which the next pair is relative. Note
3541 that this 'base' is a DWARF concept: most entries in a range
3542 list are relative, to reduce the number of relocs against the
3543 debugging information. This is separate from this function's
3544 'baseaddr' argument, which GDB uses to relocate debugging
3545 information from a shared library based on the address at
3546 which the library was loaded. */
3547 CORE_ADDR base
= cu
->base_address
;
3548 int base_known
= cu
->base_known
;
3550 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3552 complaint (&symfile_complaints
,
3553 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3560 unsigned int bytes_read
;
3561 CORE_ADDR start
, end
;
3563 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3564 buffer
+= bytes_read
;
3565 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3566 buffer
+= bytes_read
;
3568 /* Did we find the end of the range list? */
3569 if (start
== 0 && end
== 0)
3572 /* Did we find a base address selection entry? */
3573 else if ((start
& base_select_mask
) == base_select_mask
)
3579 /* We found an ordinary address range. */
3584 complaint (&symfile_complaints
,
3585 _("Invalid .debug_ranges data (no base address)"));
3589 record_block_range (block
,
3590 baseaddr
+ base
+ start
,
3591 baseaddr
+ base
+ end
- 1);
3597 /* Add an aggregate field to the field list. */
3600 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3601 struct dwarf2_cu
*cu
)
3603 struct objfile
*objfile
= cu
->objfile
;
3604 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3605 struct nextfield
*new_field
;
3606 struct attribute
*attr
;
3608 char *fieldname
= "";
3610 /* Allocate a new field list entry and link it in. */
3611 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3612 make_cleanup (xfree
, new_field
);
3613 memset (new_field
, 0, sizeof (struct nextfield
));
3614 new_field
->next
= fip
->fields
;
3615 fip
->fields
= new_field
;
3618 /* Handle accessibility and virtuality of field.
3619 The default accessibility for members is public, the default
3620 accessibility for inheritance is private. */
3621 if (die
->tag
!= DW_TAG_inheritance
)
3622 new_field
->accessibility
= DW_ACCESS_public
;
3624 new_field
->accessibility
= DW_ACCESS_private
;
3625 new_field
->virtuality
= DW_VIRTUALITY_none
;
3627 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3629 new_field
->accessibility
= DW_UNSND (attr
);
3630 if (new_field
->accessibility
!= DW_ACCESS_public
)
3631 fip
->non_public_fields
= 1;
3632 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3634 new_field
->virtuality
= DW_UNSND (attr
);
3636 fp
= &new_field
->field
;
3638 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3640 /* Data member other than a C++ static data member. */
3642 /* Get type of field. */
3643 fp
->type
= die_type (die
, cu
);
3645 SET_FIELD_BITPOS (*fp
, 0);
3647 /* Get bit size of field (zero if none). */
3648 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3651 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3655 FIELD_BITSIZE (*fp
) = 0;
3658 /* Get bit offset of field. */
3659 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3664 if (attr_form_is_section_offset (attr
))
3666 dwarf2_complex_location_expr_complaint ();
3669 else if (attr_form_is_constant (attr
))
3670 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3672 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3674 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3676 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3679 if (gdbarch_bits_big_endian (gdbarch
))
3681 /* For big endian bits, the DW_AT_bit_offset gives the
3682 additional bit offset from the MSB of the containing
3683 anonymous object to the MSB of the field. We don't
3684 have to do anything special since we don't need to
3685 know the size of the anonymous object. */
3686 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3690 /* For little endian bits, compute the bit offset to the
3691 MSB of the anonymous object, subtract off the number of
3692 bits from the MSB of the field to the MSB of the
3693 object, and then subtract off the number of bits of
3694 the field itself. The result is the bit offset of
3695 the LSB of the field. */
3697 int bit_offset
= DW_UNSND (attr
);
3699 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3702 /* The size of the anonymous object containing
3703 the bit field is explicit, so use the
3704 indicated size (in bytes). */
3705 anonymous_size
= DW_UNSND (attr
);
3709 /* The size of the anonymous object containing
3710 the bit field must be inferred from the type
3711 attribute of the data member containing the
3713 anonymous_size
= TYPE_LENGTH (fp
->type
);
3715 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3716 - bit_offset
- FIELD_BITSIZE (*fp
);
3720 /* Get name of field. */
3721 fieldname
= dwarf2_name (die
, cu
);
3722 if (fieldname
== NULL
)
3725 /* The name is already allocated along with this objfile, so we don't
3726 need to duplicate it for the type. */
3727 fp
->name
= fieldname
;
3729 /* Change accessibility for artificial fields (e.g. virtual table
3730 pointer or virtual base class pointer) to private. */
3731 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3733 new_field
->accessibility
= DW_ACCESS_private
;
3734 fip
->non_public_fields
= 1;
3737 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3739 /* C++ static member. */
3741 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3742 is a declaration, but all versions of G++ as of this writing
3743 (so through at least 3.2.1) incorrectly generate
3744 DW_TAG_variable tags. */
3748 /* Get name of field. */
3749 fieldname
= dwarf2_name (die
, cu
);
3750 if (fieldname
== NULL
)
3753 /* Get physical name. */
3754 physname
= dwarf2_linkage_name (die
, cu
);
3756 /* The name is already allocated along with this objfile, so we don't
3757 need to duplicate it for the type. */
3758 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3759 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3760 FIELD_NAME (*fp
) = fieldname
;
3762 else if (die
->tag
== DW_TAG_inheritance
)
3764 /* C++ base class field. */
3765 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3767 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
3769 FIELD_BITSIZE (*fp
) = 0;
3770 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3771 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3772 fip
->nbaseclasses
++;
3776 /* Create the vector of fields, and attach it to the type. */
3779 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3780 struct dwarf2_cu
*cu
)
3782 int nfields
= fip
->nfields
;
3784 /* Record the field count, allocate space for the array of fields,
3785 and create blank accessibility bitfields if necessary. */
3786 TYPE_NFIELDS (type
) = nfields
;
3787 TYPE_FIELDS (type
) = (struct field
*)
3788 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3789 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3791 if (fip
->non_public_fields
)
3793 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3795 TYPE_FIELD_PRIVATE_BITS (type
) =
3796 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3797 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3799 TYPE_FIELD_PROTECTED_BITS (type
) =
3800 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3801 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3803 TYPE_FIELD_IGNORE_BITS (type
) =
3804 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3805 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3808 /* If the type has baseclasses, allocate and clear a bit vector for
3809 TYPE_FIELD_VIRTUAL_BITS. */
3810 if (fip
->nbaseclasses
)
3812 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3813 unsigned char *pointer
;
3815 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3816 pointer
= TYPE_ALLOC (type
, num_bytes
);
3817 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3818 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3819 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3822 /* Copy the saved-up fields into the field vector. Start from the head
3823 of the list, adding to the tail of the field array, so that they end
3824 up in the same order in the array in which they were added to the list. */
3825 while (nfields
-- > 0)
3827 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3828 switch (fip
->fields
->accessibility
)
3830 case DW_ACCESS_private
:
3831 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3834 case DW_ACCESS_protected
:
3835 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3838 case DW_ACCESS_public
:
3842 /* Unknown accessibility. Complain and treat it as public. */
3844 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3845 fip
->fields
->accessibility
);
3849 if (nfields
< fip
->nbaseclasses
)
3851 switch (fip
->fields
->virtuality
)
3853 case DW_VIRTUALITY_virtual
:
3854 case DW_VIRTUALITY_pure_virtual
:
3855 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3859 fip
->fields
= fip
->fields
->next
;
3863 /* Add a member function to the proper fieldlist. */
3866 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3867 struct type
*type
, struct dwarf2_cu
*cu
)
3869 struct objfile
*objfile
= cu
->objfile
;
3870 struct attribute
*attr
;
3871 struct fnfieldlist
*flp
;
3873 struct fn_field
*fnp
;
3876 struct nextfnfield
*new_fnfield
;
3877 struct type
*this_type
;
3879 /* Get name of member function. */
3880 fieldname
= dwarf2_name (die
, cu
);
3881 if (fieldname
== NULL
)
3884 /* Get the mangled name. */
3885 physname
= dwarf2_linkage_name (die
, cu
);
3887 /* Look up member function name in fieldlist. */
3888 for (i
= 0; i
< fip
->nfnfields
; i
++)
3890 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3894 /* Create new list element if necessary. */
3895 if (i
< fip
->nfnfields
)
3896 flp
= &fip
->fnfieldlists
[i
];
3899 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3901 fip
->fnfieldlists
= (struct fnfieldlist
*)
3902 xrealloc (fip
->fnfieldlists
,
3903 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3904 * sizeof (struct fnfieldlist
));
3905 if (fip
->nfnfields
== 0)
3906 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3908 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3909 flp
->name
= fieldname
;
3915 /* Create a new member function field and chain it to the field list
3917 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3918 make_cleanup (xfree
, new_fnfield
);
3919 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3920 new_fnfield
->next
= flp
->head
;
3921 flp
->head
= new_fnfield
;
3924 /* Fill in the member function field info. */
3925 fnp
= &new_fnfield
->fnfield
;
3926 /* The name is already allocated along with this objfile, so we don't
3927 need to duplicate it for the type. */
3928 fnp
->physname
= physname
? physname
: "";
3929 fnp
->type
= alloc_type (objfile
);
3930 this_type
= read_type_die (die
, cu
);
3931 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3933 int nparams
= TYPE_NFIELDS (this_type
);
3935 /* TYPE is the domain of this method, and THIS_TYPE is the type
3936 of the method itself (TYPE_CODE_METHOD). */
3937 smash_to_method_type (fnp
->type
, type
,
3938 TYPE_TARGET_TYPE (this_type
),
3939 TYPE_FIELDS (this_type
),
3940 TYPE_NFIELDS (this_type
),
3941 TYPE_VARARGS (this_type
));
3943 /* Handle static member functions.
3944 Dwarf2 has no clean way to discern C++ static and non-static
3945 member functions. G++ helps GDB by marking the first
3946 parameter for non-static member functions (which is the
3947 this pointer) as artificial. We obtain this information
3948 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3949 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3950 fnp
->voffset
= VOFFSET_STATIC
;
3953 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3956 /* Get fcontext from DW_AT_containing_type if present. */
3957 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3958 fnp
->fcontext
= die_containing_type (die
, cu
);
3960 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3961 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3963 /* Get accessibility. */
3964 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3967 switch (DW_UNSND (attr
))
3969 case DW_ACCESS_private
:
3970 fnp
->is_private
= 1;
3972 case DW_ACCESS_protected
:
3973 fnp
->is_protected
= 1;
3978 /* Check for artificial methods. */
3979 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3980 if (attr
&& DW_UNSND (attr
) != 0)
3981 fnp
->is_artificial
= 1;
3983 /* Get index in virtual function table if it is a virtual member function. */
3984 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3987 /* Support the .debug_loc offsets */
3988 if (attr_form_is_block (attr
))
3990 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3992 else if (attr_form_is_section_offset (attr
))
3994 dwarf2_complex_location_expr_complaint ();
3998 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4004 /* Create the vector of member function fields, and attach it to the type. */
4007 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4008 struct dwarf2_cu
*cu
)
4010 struct fnfieldlist
*flp
;
4011 int total_length
= 0;
4014 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4015 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4016 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4018 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4020 struct nextfnfield
*nfp
= flp
->head
;
4021 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4024 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4025 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4026 fn_flp
->fn_fields
= (struct fn_field
*)
4027 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4028 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4029 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4031 total_length
+= flp
->length
;
4034 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4035 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4038 /* Returns non-zero if NAME is the name of a vtable member in CU's
4039 language, zero otherwise. */
4041 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4043 static const char vptr
[] = "_vptr";
4044 static const char vtable
[] = "vtable";
4046 /* Look for the C++ and Java forms of the vtable. */
4047 if ((cu
->language
== language_java
4048 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4049 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4050 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4056 /* GCC outputs unnamed structures that are really pointers to member
4057 functions, with the ABI-specified layout. If DIE (from CU) describes
4058 such a structure, set its type, and return nonzero. Otherwise return
4061 GCC shouldn't do this; it should just output pointer to member DIEs.
4062 This is GCC PR debug/28767. */
4064 static struct type
*
4065 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4067 struct objfile
*objfile
= cu
->objfile
;
4069 struct die_info
*pfn_die
, *delta_die
;
4070 struct attribute
*pfn_name
, *delta_name
;
4071 struct type
*pfn_type
, *domain_type
;
4073 /* Check for a structure with no name and two children. */
4074 if (die
->tag
!= DW_TAG_structure_type
4075 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4076 || die
->child
== NULL
4077 || die
->child
->sibling
== NULL
4078 || (die
->child
->sibling
->sibling
!= NULL
4079 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4082 /* Check for __pfn and __delta members. */
4083 pfn_die
= die
->child
;
4084 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4085 if (pfn_die
->tag
!= DW_TAG_member
4087 || DW_STRING (pfn_name
) == NULL
4088 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4091 delta_die
= pfn_die
->sibling
;
4092 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4093 if (delta_die
->tag
!= DW_TAG_member
4094 || delta_name
== NULL
4095 || DW_STRING (delta_name
) == NULL
4096 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4099 /* Find the type of the method. */
4100 pfn_type
= die_type (pfn_die
, cu
);
4101 if (pfn_type
== NULL
4102 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4103 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4106 /* Look for the "this" argument. */
4107 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4108 if (TYPE_NFIELDS (pfn_type
) == 0
4109 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4112 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4113 type
= alloc_type (objfile
);
4114 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4115 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4116 TYPE_VARARGS (pfn_type
));
4117 type
= lookup_methodptr_type (type
);
4118 return set_die_type (die
, type
, cu
);
4121 /* Called when we find the DIE that starts a structure or union scope
4122 (definition) to process all dies that define the members of the
4125 NOTE: we need to call struct_type regardless of whether or not the
4126 DIE has an at_name attribute, since it might be an anonymous
4127 structure or union. This gets the type entered into our set of
4130 However, if the structure is incomplete (an opaque struct/union)
4131 then suppress creating a symbol table entry for it since gdb only
4132 wants to find the one with the complete definition. Note that if
4133 it is complete, we just call new_symbol, which does it's own
4134 checking about whether the struct/union is anonymous or not (and
4135 suppresses creating a symbol table entry itself). */
4137 static struct type
*
4138 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4140 struct objfile
*objfile
= cu
->objfile
;
4142 struct attribute
*attr
;
4144 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4146 type
= quirk_gcc_member_function_pointer (die
, cu
);
4150 type
= alloc_type (objfile
);
4151 INIT_CPLUS_SPECIFIC (type
);
4152 name
= dwarf2_name (die
, cu
);
4155 if (cu
->language
== language_cplus
4156 || cu
->language
== language_java
)
4158 const char *new_prefix
= determine_class_name (die
, cu
);
4159 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4163 /* The name is already allocated along with this objfile, so
4164 we don't need to duplicate it for the type. */
4165 TYPE_TAG_NAME (type
) = name
;
4169 if (die
->tag
== DW_TAG_structure_type
)
4171 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4173 else if (die
->tag
== DW_TAG_union_type
)
4175 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4179 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4181 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4184 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4187 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4191 TYPE_LENGTH (type
) = 0;
4194 TYPE_STUB_SUPPORTED (type
) = 1;
4195 if (die_is_declaration (die
, cu
))
4196 TYPE_STUB (type
) = 1;
4198 /* We need to add the type field to the die immediately so we don't
4199 infinitely recurse when dealing with pointers to the structure
4200 type within the structure itself. */
4201 set_die_type (die
, type
, cu
);
4203 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4205 struct field_info fi
;
4206 struct die_info
*child_die
;
4208 memset (&fi
, 0, sizeof (struct field_info
));
4210 child_die
= die
->child
;
4212 while (child_die
&& child_die
->tag
)
4214 if (child_die
->tag
== DW_TAG_member
4215 || child_die
->tag
== DW_TAG_variable
)
4217 /* NOTE: carlton/2002-11-05: A C++ static data member
4218 should be a DW_TAG_member that is a declaration, but
4219 all versions of G++ as of this writing (so through at
4220 least 3.2.1) incorrectly generate DW_TAG_variable
4221 tags for them instead. */
4222 dwarf2_add_field (&fi
, child_die
, cu
);
4224 else if (child_die
->tag
== DW_TAG_subprogram
)
4226 /* C++ member function. */
4227 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4229 else if (child_die
->tag
== DW_TAG_inheritance
)
4231 /* C++ base class field. */
4232 dwarf2_add_field (&fi
, child_die
, cu
);
4234 child_die
= sibling_die (child_die
);
4237 /* Attach fields and member functions to the type. */
4239 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4242 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4244 /* Get the type which refers to the base class (possibly this
4245 class itself) which contains the vtable pointer for the current
4246 class from the DW_AT_containing_type attribute. */
4248 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4250 struct type
*t
= die_containing_type (die
, cu
);
4252 TYPE_VPTR_BASETYPE (type
) = t
;
4257 /* Our own class provides vtbl ptr. */
4258 for (i
= TYPE_NFIELDS (t
) - 1;
4259 i
>= TYPE_N_BASECLASSES (t
);
4262 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4264 if (is_vtable_name (fieldname
, cu
))
4266 TYPE_VPTR_FIELDNO (type
) = i
;
4271 /* Complain if virtual function table field not found. */
4272 if (i
< TYPE_N_BASECLASSES (t
))
4273 complaint (&symfile_complaints
,
4274 _("virtual function table pointer not found when defining class '%s'"),
4275 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4280 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4283 else if (cu
->producer
4284 && strncmp (cu
->producer
,
4285 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4287 /* The IBM XLC compiler does not provide direct indication
4288 of the containing type, but the vtable pointer is
4289 always named __vfp. */
4293 for (i
= TYPE_NFIELDS (type
) - 1;
4294 i
>= TYPE_N_BASECLASSES (type
);
4297 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4299 TYPE_VPTR_FIELDNO (type
) = i
;
4300 TYPE_VPTR_BASETYPE (type
) = type
;
4308 do_cleanups (back_to
);
4313 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4315 struct objfile
*objfile
= cu
->objfile
;
4316 struct die_info
*child_die
= die
->child
;
4317 struct type
*this_type
;
4319 this_type
= get_die_type (die
, cu
);
4320 if (this_type
== NULL
)
4321 this_type
= read_structure_type (die
, cu
);
4323 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4324 snapshots) has been known to create a die giving a declaration
4325 for a class that has, as a child, a die giving a definition for a
4326 nested class. So we have to process our children even if the
4327 current die is a declaration. Normally, of course, a declaration
4328 won't have any children at all. */
4330 while (child_die
!= NULL
&& child_die
->tag
)
4332 if (child_die
->tag
== DW_TAG_member
4333 || child_die
->tag
== DW_TAG_variable
4334 || child_die
->tag
== DW_TAG_inheritance
)
4339 process_die (child_die
, cu
);
4341 child_die
= sibling_die (child_die
);
4344 /* Do not consider external references. According to the DWARF standard,
4345 these DIEs are identified by the fact that they have no byte_size
4346 attribute, and a declaration attribute. */
4347 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4348 || !die_is_declaration (die
, cu
))
4349 new_symbol (die
, this_type
, cu
);
4352 /* Given a DW_AT_enumeration_type die, set its type. We do not
4353 complete the type's fields yet, or create any symbols. */
4355 static struct type
*
4356 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4358 struct objfile
*objfile
= cu
->objfile
;
4360 struct attribute
*attr
;
4363 type
= alloc_type (objfile
);
4365 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4366 name
= dwarf2_full_name (die
, cu
);
4368 TYPE_TAG_NAME (type
) = (char *) name
;
4370 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4373 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4377 TYPE_LENGTH (type
) = 0;
4380 /* The enumeration DIE can be incomplete. In Ada, any type can be
4381 declared as private in the package spec, and then defined only
4382 inside the package body. Such types are known as Taft Amendment
4383 Types. When another package uses such a type, an incomplete DIE
4384 may be generated by the compiler. */
4385 if (die_is_declaration (die
, cu
))
4386 TYPE_STUB (type
) = 1;
4388 return set_die_type (die
, type
, cu
);
4391 /* Determine the name of the type represented by DIE, which should be
4392 a named C++ or Java compound type. Return the name in question,
4393 allocated on the objfile obstack. */
4396 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4398 const char *new_prefix
= NULL
;
4400 /* If we don't have namespace debug info, guess the name by trying
4401 to demangle the names of members, just like we did in
4402 guess_structure_name. */
4403 if (!processing_has_namespace_info
)
4405 struct die_info
*child
;
4407 for (child
= die
->child
;
4408 child
!= NULL
&& child
->tag
!= 0;
4409 child
= sibling_die (child
))
4411 if (child
->tag
== DW_TAG_subprogram
)
4414 = language_class_name_from_physname (cu
->language_defn
,
4418 if (phys_prefix
!= NULL
)
4421 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4422 &cu
->objfile
->objfile_obstack
);
4423 xfree (phys_prefix
);
4430 if (new_prefix
== NULL
)
4431 new_prefix
= dwarf2_full_name (die
, cu
);
4436 /* Given a pointer to a die which begins an enumeration, process all
4437 the dies that define the members of the enumeration, and create the
4438 symbol for the enumeration type.
4440 NOTE: We reverse the order of the element list. */
4443 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4445 struct objfile
*objfile
= cu
->objfile
;
4446 struct die_info
*child_die
;
4447 struct field
*fields
;
4450 int unsigned_enum
= 1;
4452 struct type
*this_type
;
4456 this_type
= get_die_type (die
, cu
);
4457 if (this_type
== NULL
)
4458 this_type
= read_enumeration_type (die
, cu
);
4459 if (die
->child
!= NULL
)
4461 child_die
= die
->child
;
4462 while (child_die
&& child_die
->tag
)
4464 if (child_die
->tag
!= DW_TAG_enumerator
)
4466 process_die (child_die
, cu
);
4470 name
= dwarf2_name (child_die
, cu
);
4473 sym
= new_symbol (child_die
, this_type
, cu
);
4474 if (SYMBOL_VALUE (sym
) < 0)
4477 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4479 fields
= (struct field
*)
4481 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4482 * sizeof (struct field
));
4485 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4486 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4487 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4488 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4494 child_die
= sibling_die (child_die
);
4499 TYPE_NFIELDS (this_type
) = num_fields
;
4500 TYPE_FIELDS (this_type
) = (struct field
*)
4501 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4502 memcpy (TYPE_FIELDS (this_type
), fields
,
4503 sizeof (struct field
) * num_fields
);
4507 TYPE_UNSIGNED (this_type
) = 1;
4510 new_symbol (die
, this_type
, cu
);
4513 /* Extract all information from a DW_TAG_array_type DIE and put it in
4514 the DIE's type field. For now, this only handles one dimensional
4517 static struct type
*
4518 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4520 struct objfile
*objfile
= cu
->objfile
;
4521 struct die_info
*child_die
;
4522 struct type
*type
= NULL
;
4523 struct type
*element_type
, *range_type
, *index_type
;
4524 struct type
**range_types
= NULL
;
4525 struct attribute
*attr
;
4527 struct cleanup
*back_to
;
4530 element_type
= die_type (die
, cu
);
4532 /* Irix 6.2 native cc creates array types without children for
4533 arrays with unspecified length. */
4534 if (die
->child
== NULL
)
4536 index_type
= builtin_type_int32
;
4537 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4538 type
= create_array_type (NULL
, element_type
, range_type
);
4539 return set_die_type (die
, type
, cu
);
4542 back_to
= make_cleanup (null_cleanup
, NULL
);
4543 child_die
= die
->child
;
4544 while (child_die
&& child_die
->tag
)
4546 if (child_die
->tag
== DW_TAG_subrange_type
)
4548 struct type
*child_type
= read_type_die (child_die
, cu
);
4549 if (child_type
!= NULL
)
4551 /* The range type was succesfully read. Save it for
4552 the array type creation. */
4553 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4555 range_types
= (struct type
**)
4556 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4557 * sizeof (struct type
*));
4559 make_cleanup (free_current_contents
, &range_types
);
4561 range_types
[ndim
++] = child_type
;
4564 child_die
= sibling_die (child_die
);
4567 /* Dwarf2 dimensions are output from left to right, create the
4568 necessary array types in backwards order. */
4570 type
= element_type
;
4572 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4576 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4581 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4584 /* Understand Dwarf2 support for vector types (like they occur on
4585 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4586 array type. This is not part of the Dwarf2/3 standard yet, but a
4587 custom vendor extension. The main difference between a regular
4588 array and the vector variant is that vectors are passed by value
4590 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4592 make_vector_type (type
);
4594 name
= dwarf2_name (die
, cu
);
4596 TYPE_NAME (type
) = name
;
4598 do_cleanups (back_to
);
4600 /* Install the type in the die. */
4601 return set_die_type (die
, type
, cu
);
4604 static enum dwarf_array_dim_ordering
4605 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4607 struct attribute
*attr
;
4609 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4611 if (attr
) return DW_SND (attr
);
4614 GNU F77 is a special case, as at 08/2004 array type info is the
4615 opposite order to the dwarf2 specification, but data is still
4616 laid out as per normal fortran.
4618 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4622 if (cu
->language
== language_fortran
&&
4623 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4625 return DW_ORD_row_major
;
4628 switch (cu
->language_defn
->la_array_ordering
)
4630 case array_column_major
:
4631 return DW_ORD_col_major
;
4632 case array_row_major
:
4634 return DW_ORD_row_major
;
4638 /* Extract all information from a DW_TAG_set_type DIE and put it in
4639 the DIE's type field. */
4641 static struct type
*
4642 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4644 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4646 return set_die_type (die
, set_type
, cu
);
4649 /* First cut: install each common block member as a global variable. */
4652 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4654 struct die_info
*child_die
;
4655 struct attribute
*attr
;
4657 CORE_ADDR base
= (CORE_ADDR
) 0;
4659 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4662 /* Support the .debug_loc offsets */
4663 if (attr_form_is_block (attr
))
4665 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4667 else if (attr_form_is_section_offset (attr
))
4669 dwarf2_complex_location_expr_complaint ();
4673 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4674 "common block member");
4677 if (die
->child
!= NULL
)
4679 child_die
= die
->child
;
4680 while (child_die
&& child_die
->tag
)
4682 sym
= new_symbol (child_die
, NULL
, cu
);
4683 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4686 SYMBOL_VALUE_ADDRESS (sym
) =
4687 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4688 add_symbol_to_list (sym
, &global_symbols
);
4690 child_die
= sibling_die (child_die
);
4695 /* Create a type for a C++ namespace. */
4697 static struct type
*
4698 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4700 struct objfile
*objfile
= cu
->objfile
;
4701 const char *previous_prefix
, *name
;
4705 /* For extensions, reuse the type of the original namespace. */
4706 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4708 struct die_info
*ext_die
;
4709 struct dwarf2_cu
*ext_cu
= cu
;
4710 ext_die
= dwarf2_extension (die
, &ext_cu
);
4711 type
= read_type_die (ext_die
, ext_cu
);
4712 return set_die_type (die
, type
, cu
);
4715 name
= namespace_name (die
, &is_anonymous
, cu
);
4717 /* Now build the name of the current namespace. */
4719 previous_prefix
= determine_prefix (die
, cu
);
4720 if (previous_prefix
[0] != '\0')
4721 name
= typename_concat (&objfile
->objfile_obstack
,
4722 previous_prefix
, name
, cu
);
4724 /* Create the type. */
4725 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4727 TYPE_NAME (type
) = (char *) name
;
4728 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4730 set_die_type (die
, type
, cu
);
4735 /* Read a C++ namespace. */
4738 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4740 struct objfile
*objfile
= cu
->objfile
;
4744 /* Add a symbol associated to this if we haven't seen the namespace
4745 before. Also, add a using directive if it's an anonymous
4748 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4752 type
= read_type_die (die
, cu
);
4753 new_symbol (die
, type
, cu
);
4755 name
= namespace_name (die
, &is_anonymous
, cu
);
4758 const char *previous_prefix
= determine_prefix (die
, cu
);
4759 cp_add_using_directive (TYPE_NAME (type
),
4760 strlen (previous_prefix
),
4761 strlen (TYPE_NAME (type
)));
4765 if (die
->child
!= NULL
)
4767 struct die_info
*child_die
= die
->child
;
4769 while (child_die
&& child_die
->tag
)
4771 process_die (child_die
, cu
);
4772 child_die
= sibling_die (child_die
);
4777 /* Read a Fortran module. */
4780 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
4782 struct die_info
*child_die
= die
->child
;
4784 /* FIXME: Support the separate Fortran module namespaces. */
4786 while (child_die
&& child_die
->tag
)
4788 process_die (child_die
, cu
);
4789 child_die
= sibling_die (child_die
);
4793 /* Return the name of the namespace represented by DIE. Set
4794 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4798 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4800 struct die_info
*current_die
;
4801 const char *name
= NULL
;
4803 /* Loop through the extensions until we find a name. */
4805 for (current_die
= die
;
4806 current_die
!= NULL
;
4807 current_die
= dwarf2_extension (die
, &cu
))
4809 name
= dwarf2_name (current_die
, cu
);
4814 /* Is it an anonymous namespace? */
4816 *is_anonymous
= (name
== NULL
);
4818 name
= "(anonymous namespace)";
4823 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4824 the user defined type vector. */
4826 static struct type
*
4827 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4829 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4830 struct comp_unit_head
*cu_header
= &cu
->header
;
4832 struct attribute
*attr_byte_size
;
4833 struct attribute
*attr_address_class
;
4834 int byte_size
, addr_class
;
4836 type
= lookup_pointer_type (die_type (die
, cu
));
4838 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4840 byte_size
= DW_UNSND (attr_byte_size
);
4842 byte_size
= cu_header
->addr_size
;
4844 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4845 if (attr_address_class
)
4846 addr_class
= DW_UNSND (attr_address_class
);
4848 addr_class
= DW_ADDR_none
;
4850 /* If the pointer size or address class is different than the
4851 default, create a type variant marked as such and set the
4852 length accordingly. */
4853 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4855 if (gdbarch_address_class_type_flags_p (gdbarch
))
4859 type_flags
= gdbarch_address_class_type_flags
4860 (gdbarch
, byte_size
, addr_class
);
4861 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4863 type
= make_type_with_address_space (type
, type_flags
);
4865 else if (TYPE_LENGTH (type
) != byte_size
)
4867 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4870 /* Should we also complain about unhandled address classes? */
4874 TYPE_LENGTH (type
) = byte_size
;
4875 return set_die_type (die
, type
, cu
);
4878 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4879 the user defined type vector. */
4881 static struct type
*
4882 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4884 struct objfile
*objfile
= cu
->objfile
;
4886 struct type
*to_type
;
4887 struct type
*domain
;
4889 to_type
= die_type (die
, cu
);
4890 domain
= die_containing_type (die
, cu
);
4892 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4893 type
= lookup_methodptr_type (to_type
);
4895 type
= lookup_memberptr_type (to_type
, domain
);
4897 return set_die_type (die
, type
, cu
);
4900 /* Extract all information from a DW_TAG_reference_type DIE and add to
4901 the user defined type vector. */
4903 static struct type
*
4904 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4906 struct comp_unit_head
*cu_header
= &cu
->header
;
4908 struct attribute
*attr
;
4910 type
= lookup_reference_type (die_type (die
, cu
));
4911 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4914 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4918 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4920 return set_die_type (die
, type
, cu
);
4923 static struct type
*
4924 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4926 struct type
*base_type
, *cv_type
;
4928 base_type
= die_type (die
, cu
);
4929 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4930 return set_die_type (die
, cv_type
, cu
);
4933 static struct type
*
4934 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4936 struct type
*base_type
, *cv_type
;
4938 base_type
= die_type (die
, cu
);
4939 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4940 return set_die_type (die
, cv_type
, cu
);
4943 /* Extract all information from a DW_TAG_string_type DIE and add to
4944 the user defined type vector. It isn't really a user defined type,
4945 but it behaves like one, with other DIE's using an AT_user_def_type
4946 attribute to reference it. */
4948 static struct type
*
4949 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4951 struct objfile
*objfile
= cu
->objfile
;
4952 struct type
*type
, *range_type
, *index_type
, *char_type
;
4953 struct attribute
*attr
;
4954 unsigned int length
;
4956 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4959 length
= DW_UNSND (attr
);
4963 /* check for the DW_AT_byte_size attribute */
4964 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4967 length
= DW_UNSND (attr
);
4975 index_type
= builtin_type_int32
;
4976 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4977 type
= create_string_type (NULL
, range_type
);
4979 return set_die_type (die
, type
, cu
);
4982 /* Handle DIES due to C code like:
4986 int (*funcp)(int a, long l);
4990 ('funcp' generates a DW_TAG_subroutine_type DIE)
4993 static struct type
*
4994 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4996 struct type
*type
; /* Type that this function returns */
4997 struct type
*ftype
; /* Function that returns above type */
4998 struct attribute
*attr
;
5000 type
= die_type (die
, cu
);
5001 ftype
= make_function_type (type
, (struct type
**) 0);
5003 /* All functions in C++, Pascal and Java have prototypes. */
5004 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5005 if ((attr
&& (DW_UNSND (attr
) != 0))
5006 || cu
->language
== language_cplus
5007 || cu
->language
== language_java
5008 || cu
->language
== language_pascal
)
5009 TYPE_PROTOTYPED (ftype
) = 1;
5011 /* Store the calling convention in the type if it's available in
5012 the subroutine die. Otherwise set the calling convention to
5013 the default value DW_CC_normal. */
5014 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5015 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5017 if (die
->child
!= NULL
)
5019 struct die_info
*child_die
;
5023 /* Count the number of parameters.
5024 FIXME: GDB currently ignores vararg functions, but knows about
5025 vararg member functions. */
5026 child_die
= die
->child
;
5027 while (child_die
&& child_die
->tag
)
5029 if (child_die
->tag
== DW_TAG_formal_parameter
)
5031 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5032 TYPE_VARARGS (ftype
) = 1;
5033 child_die
= sibling_die (child_die
);
5036 /* Allocate storage for parameters and fill them in. */
5037 TYPE_NFIELDS (ftype
) = nparams
;
5038 TYPE_FIELDS (ftype
) = (struct field
*)
5039 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5041 child_die
= die
->child
;
5042 while (child_die
&& child_die
->tag
)
5044 if (child_die
->tag
== DW_TAG_formal_parameter
)
5046 /* Dwarf2 has no clean way to discern C++ static and non-static
5047 member functions. G++ helps GDB by marking the first
5048 parameter for non-static member functions (which is the
5049 this pointer) as artificial. We pass this information
5050 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5051 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5053 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5055 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5056 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5059 child_die
= sibling_die (child_die
);
5063 return set_die_type (die
, ftype
, cu
);
5066 static struct type
*
5067 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5069 struct objfile
*objfile
= cu
->objfile
;
5070 struct attribute
*attr
;
5071 const char *name
= NULL
;
5072 struct type
*this_type
;
5074 name
= dwarf2_full_name (die
, cu
);
5075 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5076 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5077 TYPE_NAME (this_type
) = (char *) name
;
5078 set_die_type (die
, this_type
, cu
);
5079 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5083 /* Find a representation of a given base type and install
5084 it in the TYPE field of the die. */
5086 static struct type
*
5087 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5089 struct objfile
*objfile
= cu
->objfile
;
5091 struct attribute
*attr
;
5092 int encoding
= 0, size
= 0;
5094 enum type_code code
= TYPE_CODE_INT
;
5096 struct type
*target_type
= NULL
;
5098 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5101 encoding
= DW_UNSND (attr
);
5103 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5106 size
= DW_UNSND (attr
);
5108 name
= dwarf2_name (die
, cu
);
5111 complaint (&symfile_complaints
,
5112 _("DW_AT_name missing from DW_TAG_base_type"));
5117 case DW_ATE_address
:
5118 /* Turn DW_ATE_address into a void * pointer. */
5119 code
= TYPE_CODE_PTR
;
5120 type_flags
|= TYPE_FLAG_UNSIGNED
;
5121 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5123 case DW_ATE_boolean
:
5124 code
= TYPE_CODE_BOOL
;
5125 type_flags
|= TYPE_FLAG_UNSIGNED
;
5127 case DW_ATE_complex_float
:
5128 code
= TYPE_CODE_COMPLEX
;
5129 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5131 case DW_ATE_decimal_float
:
5132 code
= TYPE_CODE_DECFLOAT
;
5135 code
= TYPE_CODE_FLT
;
5139 case DW_ATE_unsigned
:
5140 type_flags
|= TYPE_FLAG_UNSIGNED
;
5142 case DW_ATE_signed_char
:
5143 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5144 || cu
->language
== language_pascal
)
5145 code
= TYPE_CODE_CHAR
;
5147 case DW_ATE_unsigned_char
:
5148 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5149 || cu
->language
== language_pascal
)
5150 code
= TYPE_CODE_CHAR
;
5151 type_flags
|= TYPE_FLAG_UNSIGNED
;
5154 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5155 dwarf_type_encoding_name (encoding
));
5159 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5160 TYPE_NAME (type
) = name
;
5161 TYPE_TARGET_TYPE (type
) = target_type
;
5163 if (name
&& strcmp (name
, "char") == 0)
5164 TYPE_NOSIGN (type
) = 1;
5166 return set_die_type (die
, type
, cu
);
5169 /* Read the given DW_AT_subrange DIE. */
5171 static struct type
*
5172 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5174 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5175 struct type
*base_type
;
5176 struct type
*range_type
;
5177 struct attribute
*attr
;
5182 base_type
= die_type (die
, cu
);
5183 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5185 complaint (&symfile_complaints
,
5186 _("DW_AT_type missing from DW_TAG_subrange_type"));
5188 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5189 0, NULL
, cu
->objfile
);
5192 if (cu
->language
== language_fortran
)
5194 /* FORTRAN implies a lower bound of 1, if not given. */
5198 /* FIXME: For variable sized arrays either of these could be
5199 a variable rather than a constant value. We'll allow it,
5200 but we don't know how to handle it. */
5201 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5203 low
= dwarf2_get_attr_constant_value (attr
, 0);
5205 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5208 if (attr
->form
== DW_FORM_block1
)
5210 /* GCC encodes arrays with unspecified or dynamic length
5211 with a DW_FORM_block1 attribute.
5212 FIXME: GDB does not yet know how to handle dynamic
5213 arrays properly, treat them as arrays with unspecified
5216 FIXME: jimb/2003-09-22: GDB does not really know
5217 how to handle arrays of unspecified length
5218 either; we just represent them as zero-length
5219 arrays. Choose an appropriate upper bound given
5220 the lower bound we've computed above. */
5224 high
= dwarf2_get_attr_constant_value (attr
, 1);
5227 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5229 name
= dwarf2_name (die
, cu
);
5231 TYPE_NAME (range_type
) = name
;
5233 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5235 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5237 return set_die_type (die
, range_type
, cu
);
5240 static struct type
*
5241 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5245 /* For now, we only support the C meaning of an unspecified type: void. */
5247 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5248 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5250 return set_die_type (die
, type
, cu
);
5253 /* Trivial hash function for die_info: the hash value of a DIE
5254 is its offset in .debug_info for this objfile. */
5257 die_hash (const void *item
)
5259 const struct die_info
*die
= item
;
5263 /* Trivial comparison function for die_info structures: two DIEs
5264 are equal if they have the same offset. */
5267 die_eq (const void *item_lhs
, const void *item_rhs
)
5269 const struct die_info
*die_lhs
= item_lhs
;
5270 const struct die_info
*die_rhs
= item_rhs
;
5271 return die_lhs
->offset
== die_rhs
->offset
;
5274 /* Read a whole compilation unit into a linked list of dies. */
5276 static struct die_info
*
5277 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5280 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5284 &cu
->comp_unit_obstack
,
5285 hashtab_obstack_allocate
,
5286 dummy_obstack_deallocate
);
5288 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5291 /* Main entry point for reading a DIE and all children.
5292 Read the DIE and dump it if requested. */
5294 static struct die_info
*
5295 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5296 struct dwarf2_cu
*cu
,
5297 gdb_byte
**new_info_ptr
,
5298 struct die_info
*parent
)
5300 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5301 new_info_ptr
, parent
);
5303 if (dwarf2_die_debug
)
5305 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5306 dump_die (result
, dwarf2_die_debug
);
5312 /* Read a single die and all its descendents. Set the die's sibling
5313 field to NULL; set other fields in the die correctly, and set all
5314 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5315 location of the info_ptr after reading all of those dies. PARENT
5316 is the parent of the die in question. */
5318 static struct die_info
*
5319 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5320 struct dwarf2_cu
*cu
,
5321 gdb_byte
**new_info_ptr
,
5322 struct die_info
*parent
)
5324 struct die_info
*die
;
5328 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5331 *new_info_ptr
= cur_ptr
;
5334 store_in_ref_table (die
, cu
);
5338 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5344 *new_info_ptr
= cur_ptr
;
5347 die
->sibling
= NULL
;
5348 die
->parent
= parent
;
5352 /* Read a die, all of its descendents, and all of its siblings; set
5353 all of the fields of all of the dies correctly. Arguments are as
5354 in read_die_and_children. */
5356 static struct die_info
*
5357 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5358 struct dwarf2_cu
*cu
,
5359 gdb_byte
**new_info_ptr
,
5360 struct die_info
*parent
)
5362 struct die_info
*first_die
, *last_sibling
;
5366 first_die
= last_sibling
= NULL
;
5370 struct die_info
*die
5371 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5375 *new_info_ptr
= cur_ptr
;
5382 last_sibling
->sibling
= die
;
5388 /* Decompress a section that was compressed using zlib. Store the
5389 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5392 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5393 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5395 bfd
*abfd
= objfile
->obfd
;
5397 error (_("Support for zlib-compressed DWARF data (from '%s') "
5398 "is disabled in this copy of GDB"),
5399 bfd_get_filename (abfd
));
5401 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5402 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5403 bfd_size_type uncompressed_size
;
5404 gdb_byte
*uncompressed_buffer
;
5407 int header_size
= 12;
5409 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5410 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5411 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5412 bfd_get_filename (abfd
));
5414 /* Read the zlib header. In this case, it should be "ZLIB" followed
5415 by the uncompressed section size, 8 bytes in big-endian order. */
5416 if (compressed_size
< header_size
5417 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5418 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5419 bfd_get_filename (abfd
));
5420 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5421 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5422 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5423 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5424 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5425 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5426 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5427 uncompressed_size
+= compressed_buffer
[11];
5429 /* It is possible the section consists of several compressed
5430 buffers concatenated together, so we uncompress in a loop. */
5434 strm
.avail_in
= compressed_size
- header_size
;
5435 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5436 strm
.avail_out
= uncompressed_size
;
5437 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5439 rc
= inflateInit (&strm
);
5440 while (strm
.avail_in
> 0)
5443 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5444 bfd_get_filename (abfd
), rc
);
5445 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5446 + (uncompressed_size
- strm
.avail_out
));
5447 rc
= inflate (&strm
, Z_FINISH
);
5448 if (rc
!= Z_STREAM_END
)
5449 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5450 bfd_get_filename (abfd
), rc
);
5451 rc
= inflateReset (&strm
);
5453 rc
= inflateEnd (&strm
);
5455 || strm
.avail_out
!= 0)
5456 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5457 bfd_get_filename (abfd
), rc
);
5459 xfree (compressed_buffer
);
5460 *outbuf
= uncompressed_buffer
;
5461 *outsize
= uncompressed_size
;
5466 /* Read the contents of the section at OFFSET and of size SIZE from the
5467 object file specified by OBJFILE into the objfile_obstack and return it.
5468 If the section is compressed, uncompress it before returning. */
5471 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5473 bfd
*abfd
= objfile
->obfd
;
5474 gdb_byte
*buf
, *retbuf
;
5475 bfd_size_type size
= bfd_get_section_size (sectp
);
5476 unsigned char header
[4];
5481 /* Check if the file has a 4-byte header indicating compression. */
5482 if (size
> sizeof (header
)
5483 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5484 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5486 /* Upon decompression, update the buffer and its size. */
5487 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5489 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5490 dwarf2_resize_section (sectp
, size
);
5495 /* If we get here, we are a normal, not-compressed section. */
5496 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5497 /* When debugging .o files, we may need to apply relocations; see
5498 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5499 We never compress sections in .o files, so we only need to
5500 try this when the section is not compressed. */
5501 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5505 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5506 || bfd_bread (buf
, size
, abfd
) != size
)
5507 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5508 bfd_get_filename (abfd
));
5513 /* In DWARF version 2, the description of the debugging information is
5514 stored in a separate .debug_abbrev section. Before we read any
5515 dies from a section we read in all abbreviations and install them
5516 in a hash table. This function also sets flags in CU describing
5517 the data found in the abbrev table. */
5520 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5522 struct comp_unit_head
*cu_header
= &cu
->header
;
5523 gdb_byte
*abbrev_ptr
;
5524 struct abbrev_info
*cur_abbrev
;
5525 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5526 unsigned int abbrev_form
, hash_number
;
5527 struct attr_abbrev
*cur_attrs
;
5528 unsigned int allocated_attrs
;
5530 /* Initialize dwarf2 abbrevs */
5531 obstack_init (&cu
->abbrev_obstack
);
5532 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5534 * sizeof (struct abbrev_info
*)));
5535 memset (cu
->dwarf2_abbrevs
, 0,
5536 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5538 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5539 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5540 abbrev_ptr
+= bytes_read
;
5542 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5543 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5545 /* loop until we reach an abbrev number of 0 */
5546 while (abbrev_number
)
5548 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5550 /* read in abbrev header */
5551 cur_abbrev
->number
= abbrev_number
;
5552 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5553 abbrev_ptr
+= bytes_read
;
5554 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5557 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5558 cu
->has_namespace_info
= 1;
5560 /* now read in declarations */
5561 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5562 abbrev_ptr
+= bytes_read
;
5563 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5564 abbrev_ptr
+= bytes_read
;
5567 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5569 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5571 = xrealloc (cur_attrs
, (allocated_attrs
5572 * sizeof (struct attr_abbrev
)));
5575 /* Record whether this compilation unit might have
5576 inter-compilation-unit references. If we don't know what form
5577 this attribute will have, then it might potentially be a
5578 DW_FORM_ref_addr, so we conservatively expect inter-CU
5581 if (abbrev_form
== DW_FORM_ref_addr
5582 || abbrev_form
== DW_FORM_indirect
)
5583 cu
->has_form_ref_addr
= 1;
5585 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5586 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5587 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5588 abbrev_ptr
+= bytes_read
;
5589 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5590 abbrev_ptr
+= bytes_read
;
5593 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5594 (cur_abbrev
->num_attrs
5595 * sizeof (struct attr_abbrev
)));
5596 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5597 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5599 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5600 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5601 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5603 /* Get next abbreviation.
5604 Under Irix6 the abbreviations for a compilation unit are not
5605 always properly terminated with an abbrev number of 0.
5606 Exit loop if we encounter an abbreviation which we have
5607 already read (which means we are about to read the abbreviations
5608 for the next compile unit) or if the end of the abbreviation
5609 table is reached. */
5610 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5611 >= dwarf2_per_objfile
->abbrev_size
)
5613 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5614 abbrev_ptr
+= bytes_read
;
5615 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5622 /* Release the memory used by the abbrev table for a compilation unit. */
5625 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5627 struct dwarf2_cu
*cu
= ptr_to_cu
;
5629 obstack_free (&cu
->abbrev_obstack
, NULL
);
5630 cu
->dwarf2_abbrevs
= NULL
;
5633 /* Lookup an abbrev_info structure in the abbrev hash table. */
5635 static struct abbrev_info
*
5636 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5638 unsigned int hash_number
;
5639 struct abbrev_info
*abbrev
;
5641 hash_number
= number
% ABBREV_HASH_SIZE
;
5642 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5646 if (abbrev
->number
== number
)
5649 abbrev
= abbrev
->next
;
5654 /* Returns nonzero if TAG represents a type that we might generate a partial
5658 is_type_tag_for_partial (int tag
)
5663 /* Some types that would be reasonable to generate partial symbols for,
5664 that we don't at present. */
5665 case DW_TAG_array_type
:
5666 case DW_TAG_file_type
:
5667 case DW_TAG_ptr_to_member_type
:
5668 case DW_TAG_set_type
:
5669 case DW_TAG_string_type
:
5670 case DW_TAG_subroutine_type
:
5672 case DW_TAG_base_type
:
5673 case DW_TAG_class_type
:
5674 case DW_TAG_interface_type
:
5675 case DW_TAG_enumeration_type
:
5676 case DW_TAG_structure_type
:
5677 case DW_TAG_subrange_type
:
5678 case DW_TAG_typedef
:
5679 case DW_TAG_union_type
:
5686 /* Load all DIEs that are interesting for partial symbols into memory. */
5688 static struct partial_die_info
*
5689 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5690 struct dwarf2_cu
*cu
)
5692 struct partial_die_info
*part_die
;
5693 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5694 struct abbrev_info
*abbrev
;
5695 unsigned int bytes_read
;
5696 unsigned int load_all
= 0;
5698 int nesting_level
= 1;
5703 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5707 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5711 &cu
->comp_unit_obstack
,
5712 hashtab_obstack_allocate
,
5713 dummy_obstack_deallocate
);
5715 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5716 sizeof (struct partial_die_info
));
5720 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5722 /* A NULL abbrev means the end of a series of children. */
5725 if (--nesting_level
== 0)
5727 /* PART_DIE was probably the last thing allocated on the
5728 comp_unit_obstack, so we could call obstack_free
5729 here. We don't do that because the waste is small,
5730 and will be cleaned up when we're done with this
5731 compilation unit. This way, we're also more robust
5732 against other users of the comp_unit_obstack. */
5735 info_ptr
+= bytes_read
;
5736 last_die
= parent_die
;
5737 parent_die
= parent_die
->die_parent
;
5741 /* Check whether this DIE is interesting enough to save. Normally
5742 we would not be interested in members here, but there may be
5743 later variables referencing them via DW_AT_specification (for
5746 && !is_type_tag_for_partial (abbrev
->tag
)
5747 && abbrev
->tag
!= DW_TAG_enumerator
5748 && abbrev
->tag
!= DW_TAG_subprogram
5749 && abbrev
->tag
!= DW_TAG_lexical_block
5750 && abbrev
->tag
!= DW_TAG_variable
5751 && abbrev
->tag
!= DW_TAG_namespace
5752 && abbrev
->tag
!= DW_TAG_member
)
5754 /* Otherwise we skip to the next sibling, if any. */
5755 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5759 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5760 abfd
, info_ptr
, cu
);
5762 /* This two-pass algorithm for processing partial symbols has a
5763 high cost in cache pressure. Thus, handle some simple cases
5764 here which cover the majority of C partial symbols. DIEs
5765 which neither have specification tags in them, nor could have
5766 specification tags elsewhere pointing at them, can simply be
5767 processed and discarded.
5769 This segment is also optional; scan_partial_symbols and
5770 add_partial_symbol will handle these DIEs if we chain
5771 them in normally. When compilers which do not emit large
5772 quantities of duplicate debug information are more common,
5773 this code can probably be removed. */
5775 /* Any complete simple types at the top level (pretty much all
5776 of them, for a language without namespaces), can be processed
5778 if (parent_die
== NULL
5779 && part_die
->has_specification
== 0
5780 && part_die
->is_declaration
== 0
5781 && (part_die
->tag
== DW_TAG_typedef
5782 || part_die
->tag
== DW_TAG_base_type
5783 || part_die
->tag
== DW_TAG_subrange_type
))
5785 if (building_psymtab
&& part_die
->name
!= NULL
)
5786 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5787 VAR_DOMAIN
, LOC_TYPEDEF
,
5788 &cu
->objfile
->static_psymbols
,
5789 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5790 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5794 /* If we're at the second level, and we're an enumerator, and
5795 our parent has no specification (meaning possibly lives in a
5796 namespace elsewhere), then we can add the partial symbol now
5797 instead of queueing it. */
5798 if (part_die
->tag
== DW_TAG_enumerator
5799 && parent_die
!= NULL
5800 && parent_die
->die_parent
== NULL
5801 && parent_die
->tag
== DW_TAG_enumeration_type
5802 && parent_die
->has_specification
== 0)
5804 if (part_die
->name
== NULL
)
5805 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5806 else if (building_psymtab
)
5807 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5808 VAR_DOMAIN
, LOC_CONST
,
5809 (cu
->language
== language_cplus
5810 || cu
->language
== language_java
)
5811 ? &cu
->objfile
->global_psymbols
5812 : &cu
->objfile
->static_psymbols
,
5813 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5815 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5819 /* We'll save this DIE so link it in. */
5820 part_die
->die_parent
= parent_die
;
5821 part_die
->die_sibling
= NULL
;
5822 part_die
->die_child
= NULL
;
5824 if (last_die
&& last_die
== parent_die
)
5825 last_die
->die_child
= part_die
;
5827 last_die
->die_sibling
= part_die
;
5829 last_die
= part_die
;
5831 if (first_die
== NULL
)
5832 first_die
= part_die
;
5834 /* Maybe add the DIE to the hash table. Not all DIEs that we
5835 find interesting need to be in the hash table, because we
5836 also have the parent/sibling/child chains; only those that we
5837 might refer to by offset later during partial symbol reading.
5839 For now this means things that might have be the target of a
5840 DW_AT_specification, DW_AT_abstract_origin, or
5841 DW_AT_extension. DW_AT_extension will refer only to
5842 namespaces; DW_AT_abstract_origin refers to functions (and
5843 many things under the function DIE, but we do not recurse
5844 into function DIEs during partial symbol reading) and
5845 possibly variables as well; DW_AT_specification refers to
5846 declarations. Declarations ought to have the DW_AT_declaration
5847 flag. It happens that GCC forgets to put it in sometimes, but
5848 only for functions, not for types.
5850 Adding more things than necessary to the hash table is harmless
5851 except for the performance cost. Adding too few will result in
5852 wasted time in find_partial_die, when we reread the compilation
5853 unit with load_all_dies set. */
5856 || abbrev
->tag
== DW_TAG_subprogram
5857 || abbrev
->tag
== DW_TAG_variable
5858 || abbrev
->tag
== DW_TAG_namespace
5859 || part_die
->is_declaration
)
5863 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5864 part_die
->offset
, INSERT
);
5868 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5869 sizeof (struct partial_die_info
));
5871 /* For some DIEs we want to follow their children (if any). For C
5872 we have no reason to follow the children of structures; for other
5873 languages we have to, both so that we can get at method physnames
5874 to infer fully qualified class names, and for DW_AT_specification.
5876 For Ada, we need to scan the children of subprograms and lexical
5877 blocks as well because Ada allows the definition of nested
5878 entities that could be interesting for the debugger, such as
5879 nested subprograms for instance. */
5880 if (last_die
->has_children
5882 || last_die
->tag
== DW_TAG_namespace
5883 || last_die
->tag
== DW_TAG_enumeration_type
5884 || (cu
->language
!= language_c
5885 && (last_die
->tag
== DW_TAG_class_type
5886 || last_die
->tag
== DW_TAG_interface_type
5887 || last_die
->tag
== DW_TAG_structure_type
5888 || last_die
->tag
== DW_TAG_union_type
))
5889 || (cu
->language
== language_ada
5890 && (last_die
->tag
== DW_TAG_subprogram
5891 || last_die
->tag
== DW_TAG_lexical_block
))))
5894 parent_die
= last_die
;
5898 /* Otherwise we skip to the next sibling, if any. */
5899 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5901 /* Back to the top, do it again. */
5905 /* Read a minimal amount of information into the minimal die structure. */
5908 read_partial_die (struct partial_die_info
*part_die
,
5909 struct abbrev_info
*abbrev
,
5910 unsigned int abbrev_len
, bfd
*abfd
,
5911 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5913 unsigned int bytes_read
, i
;
5914 struct attribute attr
;
5915 int has_low_pc_attr
= 0;
5916 int has_high_pc_attr
= 0;
5917 CORE_ADDR base_address
= 0;
5921 base_address_low_pc
,
5922 /* Overrides BASE_ADDRESS_LOW_PC. */
5923 base_address_entry_pc
5925 base_address_type
= base_address_none
;
5927 memset (part_die
, 0, sizeof (struct partial_die_info
));
5929 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5931 info_ptr
+= abbrev_len
;
5936 part_die
->tag
= abbrev
->tag
;
5937 part_die
->has_children
= abbrev
->has_children
;
5939 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5941 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5943 /* Store the data if it is of an attribute we want to keep in a
5944 partial symbol table. */
5949 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5950 if (part_die
->name
== NULL
)
5951 part_die
->name
= DW_STRING (&attr
);
5953 case DW_AT_comp_dir
:
5954 if (part_die
->dirname
== NULL
)
5955 part_die
->dirname
= DW_STRING (&attr
);
5957 case DW_AT_MIPS_linkage_name
:
5958 part_die
->name
= DW_STRING (&attr
);
5961 has_low_pc_attr
= 1;
5962 part_die
->lowpc
= DW_ADDR (&attr
);
5963 if (part_die
->tag
== DW_TAG_compile_unit
5964 && base_address_type
< base_address_low_pc
)
5966 base_address
= DW_ADDR (&attr
);
5967 base_address_type
= base_address_low_pc
;
5971 has_high_pc_attr
= 1;
5972 part_die
->highpc
= DW_ADDR (&attr
);
5974 case DW_AT_entry_pc
:
5975 if (part_die
->tag
== DW_TAG_compile_unit
5976 && base_address_type
< base_address_entry_pc
)
5978 base_address
= DW_ADDR (&attr
);
5979 base_address_type
= base_address_entry_pc
;
5983 if (part_die
->tag
== DW_TAG_compile_unit
)
5985 cu
->ranges_offset
= DW_UNSND (&attr
);
5986 cu
->has_ranges_offset
= 1;
5989 case DW_AT_location
:
5990 /* Support the .debug_loc offsets */
5991 if (attr_form_is_block (&attr
))
5993 part_die
->locdesc
= DW_BLOCK (&attr
);
5995 else if (attr_form_is_section_offset (&attr
))
5997 dwarf2_complex_location_expr_complaint ();
6001 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6002 "partial symbol information");
6005 case DW_AT_language
:
6006 part_die
->language
= DW_UNSND (&attr
);
6008 case DW_AT_external
:
6009 part_die
->is_external
= DW_UNSND (&attr
);
6011 case DW_AT_declaration
:
6012 part_die
->is_declaration
= DW_UNSND (&attr
);
6015 part_die
->has_type
= 1;
6017 case DW_AT_abstract_origin
:
6018 case DW_AT_specification
:
6019 case DW_AT_extension
:
6020 part_die
->has_specification
= 1;
6021 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6024 /* Ignore absolute siblings, they might point outside of
6025 the current compile unit. */
6026 if (attr
.form
== DW_FORM_ref_addr
)
6027 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6029 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
6030 + dwarf2_get_ref_die_offset (&attr
);
6032 case DW_AT_stmt_list
:
6033 part_die
->has_stmt_list
= 1;
6034 part_die
->line_offset
= DW_UNSND (&attr
);
6036 case DW_AT_byte_size
:
6037 part_die
->has_byte_size
= 1;
6039 case DW_AT_calling_convention
:
6040 /* DWARF doesn't provide a way to identify a program's source-level
6041 entry point. DW_AT_calling_convention attributes are only meant
6042 to describe functions' calling conventions.
6044 However, because it's a necessary piece of information in
6045 Fortran, and because DW_CC_program is the only piece of debugging
6046 information whose definition refers to a 'main program' at all,
6047 several compilers have begun marking Fortran main programs with
6048 DW_CC_program --- even when those functions use the standard
6049 calling conventions.
6051 So until DWARF specifies a way to provide this information and
6052 compilers pick up the new representation, we'll support this
6054 if (DW_UNSND (&attr
) == DW_CC_program
6055 && cu
->language
== language_fortran
)
6056 set_main_name (part_die
->name
);
6063 /* When using the GNU linker, .gnu.linkonce. sections are used to
6064 eliminate duplicate copies of functions and vtables and such.
6065 The linker will arbitrarily choose one and discard the others.
6066 The AT_*_pc values for such functions refer to local labels in
6067 these sections. If the section from that file was discarded, the
6068 labels are not in the output, so the relocs get a value of 0.
6069 If this is a discarded function, mark the pc bounds as invalid,
6070 so that GDB will ignore it. */
6071 if (has_low_pc_attr
&& has_high_pc_attr
6072 && part_die
->lowpc
< part_die
->highpc
6073 && (part_die
->lowpc
!= 0
6074 || dwarf2_per_objfile
->has_section_at_zero
))
6075 part_die
->has_pc_info
= 1;
6077 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6079 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6081 cu
->base_address
= base_address
;
6087 /* Find a cached partial DIE at OFFSET in CU. */
6089 static struct partial_die_info
*
6090 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6092 struct partial_die_info
*lookup_die
= NULL
;
6093 struct partial_die_info part_die
;
6095 part_die
.offset
= offset
;
6096 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6101 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6103 static struct partial_die_info
*
6104 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6106 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6107 struct partial_die_info
*pd
= NULL
;
6109 if (offset_in_cu_p (&cu
->header
, offset
))
6111 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6116 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6118 if (per_cu
->cu
== NULL
)
6120 load_comp_unit (per_cu
, cu
->objfile
);
6121 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6122 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6125 per_cu
->cu
->last_used
= 0;
6126 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6128 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6130 struct cleanup
*back_to
;
6131 struct partial_die_info comp_unit_die
;
6132 struct abbrev_info
*abbrev
;
6133 unsigned int bytes_read
;
6136 per_cu
->load_all_dies
= 1;
6138 /* Re-read the DIEs. */
6139 back_to
= make_cleanup (null_cleanup
, 0);
6140 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6142 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6143 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6145 info_ptr
= (dwarf2_per_objfile
->info_buffer
6146 + per_cu
->cu
->header
.offset
6147 + per_cu
->cu
->header
.first_die_offset
);
6148 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6149 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6150 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6152 if (comp_unit_die
.has_children
)
6153 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6154 do_cleanups (back_to
);
6156 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6160 internal_error (__FILE__
, __LINE__
,
6161 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6162 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6166 /* Adjust PART_DIE before generating a symbol for it. This function
6167 may set the is_external flag or change the DIE's name. */
6170 fixup_partial_die (struct partial_die_info
*part_die
,
6171 struct dwarf2_cu
*cu
)
6173 /* If we found a reference attribute and the DIE has no name, try
6174 to find a name in the referred to DIE. */
6176 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6178 struct partial_die_info
*spec_die
;
6180 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6182 fixup_partial_die (spec_die
, cu
);
6186 part_die
->name
= spec_die
->name
;
6188 /* Copy DW_AT_external attribute if it is set. */
6189 if (spec_die
->is_external
)
6190 part_die
->is_external
= spec_die
->is_external
;
6194 /* Set default names for some unnamed DIEs. */
6195 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6196 || part_die
->tag
== DW_TAG_class_type
))
6197 part_die
->name
= "(anonymous class)";
6199 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6200 part_die
->name
= "(anonymous namespace)";
6202 if (part_die
->tag
== DW_TAG_structure_type
6203 || part_die
->tag
== DW_TAG_class_type
6204 || part_die
->tag
== DW_TAG_union_type
)
6205 guess_structure_name (part_die
, cu
);
6208 /* Read the die from the .debug_info section buffer. Set DIEP to
6209 point to a newly allocated die with its information, except for its
6210 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6211 whether the die has children or not. */
6214 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6215 struct dwarf2_cu
*cu
, int *has_children
)
6217 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6218 struct abbrev_info
*abbrev
;
6219 struct die_info
*die
;
6221 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6222 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6223 info_ptr
+= bytes_read
;
6231 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6234 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6236 bfd_get_filename (abfd
));
6238 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6239 die
->offset
= offset
;
6240 die
->tag
= abbrev
->tag
;
6241 die
->abbrev
= abbrev_number
;
6243 die
->num_attrs
= abbrev
->num_attrs
;
6245 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6246 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6247 abfd
, info_ptr
, cu
);
6250 *has_children
= abbrev
->has_children
;
6254 /* Read an attribute value described by an attribute form. */
6257 read_attribute_value (struct attribute
*attr
, unsigned form
,
6258 bfd
*abfd
, gdb_byte
*info_ptr
,
6259 struct dwarf2_cu
*cu
)
6261 struct comp_unit_head
*cu_header
= &cu
->header
;
6262 unsigned int bytes_read
;
6263 struct dwarf_block
*blk
;
6269 case DW_FORM_ref_addr
:
6270 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6271 info_ptr
+= bytes_read
;
6273 case DW_FORM_block2
:
6274 blk
= dwarf_alloc_block (cu
);
6275 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6277 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6278 info_ptr
+= blk
->size
;
6279 DW_BLOCK (attr
) = blk
;
6281 case DW_FORM_block4
:
6282 blk
= dwarf_alloc_block (cu
);
6283 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6285 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6286 info_ptr
+= blk
->size
;
6287 DW_BLOCK (attr
) = blk
;
6290 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6294 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6298 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6301 case DW_FORM_string
:
6302 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6303 info_ptr
+= bytes_read
;
6306 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6308 info_ptr
+= bytes_read
;
6311 blk
= dwarf_alloc_block (cu
);
6312 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6313 info_ptr
+= bytes_read
;
6314 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6315 info_ptr
+= blk
->size
;
6316 DW_BLOCK (attr
) = blk
;
6318 case DW_FORM_block1
:
6319 blk
= dwarf_alloc_block (cu
);
6320 blk
->size
= read_1_byte (abfd
, info_ptr
);
6322 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6323 info_ptr
+= blk
->size
;
6324 DW_BLOCK (attr
) = blk
;
6327 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6331 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6335 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6336 info_ptr
+= bytes_read
;
6339 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6340 info_ptr
+= bytes_read
;
6343 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6347 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6351 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6355 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6358 case DW_FORM_ref_udata
:
6359 DW_ADDR (attr
) = (cu
->header
.offset
6360 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6361 info_ptr
+= bytes_read
;
6363 case DW_FORM_indirect
:
6364 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6365 info_ptr
+= bytes_read
;
6366 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6369 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6370 dwarf_form_name (form
),
6371 bfd_get_filename (abfd
));
6374 /* We have seen instances where the compiler tried to emit a byte
6375 size attribute of -1 which ended up being encoded as an unsigned
6376 0xffffffff. Although 0xffffffff is technically a valid size value,
6377 an object of this size seems pretty unlikely so we can relatively
6378 safely treat these cases as if the size attribute was invalid and
6379 treat them as zero by default. */
6380 if (attr
->name
== DW_AT_byte_size
6381 && form
== DW_FORM_data4
6382 && DW_UNSND (attr
) >= 0xffffffff)
6385 (&symfile_complaints
,
6386 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6388 DW_UNSND (attr
) = 0;
6394 /* Read an attribute described by an abbreviated attribute. */
6397 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6398 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6400 attr
->name
= abbrev
->name
;
6401 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6404 /* read dwarf information from a buffer */
6407 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6409 return bfd_get_8 (abfd
, buf
);
6413 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6415 return bfd_get_signed_8 (abfd
, buf
);
6419 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6421 return bfd_get_16 (abfd
, buf
);
6425 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6427 return bfd_get_signed_16 (abfd
, buf
);
6431 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6433 return bfd_get_32 (abfd
, buf
);
6437 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6439 return bfd_get_signed_32 (abfd
, buf
);
6442 static unsigned long
6443 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6445 return bfd_get_64 (abfd
, buf
);
6449 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6450 unsigned int *bytes_read
)
6452 struct comp_unit_head
*cu_header
= &cu
->header
;
6453 CORE_ADDR retval
= 0;
6455 if (cu_header
->signed_addr_p
)
6457 switch (cu_header
->addr_size
)
6460 retval
= bfd_get_signed_16 (abfd
, buf
);
6463 retval
= bfd_get_signed_32 (abfd
, buf
);
6466 retval
= bfd_get_signed_64 (abfd
, buf
);
6469 internal_error (__FILE__
, __LINE__
,
6470 _("read_address: bad switch, signed [in module %s]"),
6471 bfd_get_filename (abfd
));
6476 switch (cu_header
->addr_size
)
6479 retval
= bfd_get_16 (abfd
, buf
);
6482 retval
= bfd_get_32 (abfd
, buf
);
6485 retval
= bfd_get_64 (abfd
, buf
);
6488 internal_error (__FILE__
, __LINE__
,
6489 _("read_address: bad switch, unsigned [in module %s]"),
6490 bfd_get_filename (abfd
));
6494 *bytes_read
= cu_header
->addr_size
;
6498 /* Read the initial length from a section. The (draft) DWARF 3
6499 specification allows the initial length to take up either 4 bytes
6500 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6501 bytes describe the length and all offsets will be 8 bytes in length
6504 An older, non-standard 64-bit format is also handled by this
6505 function. The older format in question stores the initial length
6506 as an 8-byte quantity without an escape value. Lengths greater
6507 than 2^32 aren't very common which means that the initial 4 bytes
6508 is almost always zero. Since a length value of zero doesn't make
6509 sense for the 32-bit format, this initial zero can be considered to
6510 be an escape value which indicates the presence of the older 64-bit
6511 format. As written, the code can't detect (old format) lengths
6512 greater than 4GB. If it becomes necessary to handle lengths
6513 somewhat larger than 4GB, we could allow other small values (such
6514 as the non-sensical values of 1, 2, and 3) to also be used as
6515 escape values indicating the presence of the old format.
6517 The value returned via bytes_read should be used to increment the
6518 relevant pointer after calling read_initial_length().
6520 [ Note: read_initial_length() and read_offset() are based on the
6521 document entitled "DWARF Debugging Information Format", revision
6522 3, draft 8, dated November 19, 2001. This document was obtained
6525 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6527 This document is only a draft and is subject to change. (So beware.)
6529 Details regarding the older, non-standard 64-bit format were
6530 determined empirically by examining 64-bit ELF files produced by
6531 the SGI toolchain on an IRIX 6.5 machine.
6533 - Kevin, July 16, 2002
6537 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6539 LONGEST length
= bfd_get_32 (abfd
, buf
);
6541 if (length
== 0xffffffff)
6543 length
= bfd_get_64 (abfd
, buf
+ 4);
6546 else if (length
== 0)
6548 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6549 length
= bfd_get_64 (abfd
, buf
);
6560 /* Cover function for read_initial_length.
6561 Returns the length of the object at BUF, and stores the size of the
6562 initial length in *BYTES_READ and stores the size that offsets will be in
6564 If the initial length size is not equivalent to that specified in
6565 CU_HEADER then issue a complaint.
6566 This is useful when reading non-comp-unit headers. */
6569 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6570 const struct comp_unit_head
*cu_header
,
6571 unsigned int *bytes_read
,
6572 unsigned int *offset_size
)
6574 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6576 gdb_assert (cu_header
->initial_length_size
== 4
6577 || cu_header
->initial_length_size
== 8
6578 || cu_header
->initial_length_size
== 12);
6580 if (cu_header
->initial_length_size
!= *bytes_read
)
6581 complaint (&symfile_complaints
,
6582 _("intermixed 32-bit and 64-bit DWARF sections"));
6584 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6588 /* Read an offset from the data stream. The size of the offset is
6589 given by cu_header->offset_size. */
6592 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6593 unsigned int *bytes_read
)
6595 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6596 *bytes_read
= cu_header
->offset_size
;
6600 /* Read an offset from the data stream. */
6603 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6607 switch (offset_size
)
6610 retval
= bfd_get_32 (abfd
, buf
);
6613 retval
= bfd_get_64 (abfd
, buf
);
6616 internal_error (__FILE__
, __LINE__
,
6617 _("read_offset_1: bad switch [in module %s]"),
6618 bfd_get_filename (abfd
));
6625 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6627 /* If the size of a host char is 8 bits, we can return a pointer
6628 to the buffer, otherwise we have to copy the data to a buffer
6629 allocated on the temporary obstack. */
6630 gdb_assert (HOST_CHAR_BIT
== 8);
6635 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6637 /* If the size of a host char is 8 bits, we can return a pointer
6638 to the string, otherwise we have to copy the string to a buffer
6639 allocated on the temporary obstack. */
6640 gdb_assert (HOST_CHAR_BIT
== 8);
6643 *bytes_read_ptr
= 1;
6646 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6647 return (char *) buf
;
6651 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6652 const struct comp_unit_head
*cu_header
,
6653 unsigned int *bytes_read_ptr
)
6655 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6657 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6659 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6660 bfd_get_filename (abfd
));
6663 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6665 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6666 bfd_get_filename (abfd
));
6669 gdb_assert (HOST_CHAR_BIT
== 8);
6670 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6672 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6675 static unsigned long
6676 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6678 unsigned long result
;
6679 unsigned int num_read
;
6689 byte
= bfd_get_8 (abfd
, buf
);
6692 result
|= ((unsigned long)(byte
& 127) << shift
);
6693 if ((byte
& 128) == 0)
6699 *bytes_read_ptr
= num_read
;
6704 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6707 int i
, shift
, num_read
;
6716 byte
= bfd_get_8 (abfd
, buf
);
6719 result
|= ((long)(byte
& 127) << shift
);
6721 if ((byte
& 128) == 0)
6726 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6727 result
|= -(((long)1) << shift
);
6728 *bytes_read_ptr
= num_read
;
6732 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6735 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6741 byte
= bfd_get_8 (abfd
, buf
);
6743 if ((byte
& 128) == 0)
6749 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6755 cu
->language
= language_c
;
6757 case DW_LANG_C_plus_plus
:
6758 cu
->language
= language_cplus
;
6760 case DW_LANG_Fortran77
:
6761 case DW_LANG_Fortran90
:
6762 case DW_LANG_Fortran95
:
6763 cu
->language
= language_fortran
;
6765 case DW_LANG_Mips_Assembler
:
6766 cu
->language
= language_asm
;
6769 cu
->language
= language_java
;
6773 cu
->language
= language_ada
;
6775 case DW_LANG_Modula2
:
6776 cu
->language
= language_m2
;
6778 case DW_LANG_Pascal83
:
6779 cu
->language
= language_pascal
;
6782 cu
->language
= language_objc
;
6784 case DW_LANG_Cobol74
:
6785 case DW_LANG_Cobol85
:
6787 cu
->language
= language_minimal
;
6790 cu
->language_defn
= language_def (cu
->language
);
6793 /* Return the named attribute or NULL if not there. */
6795 static struct attribute
*
6796 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6799 struct attribute
*spec
= NULL
;
6801 for (i
= 0; i
< die
->num_attrs
; ++i
)
6803 if (die
->attrs
[i
].name
== name
)
6804 return &die
->attrs
[i
];
6805 if (die
->attrs
[i
].name
== DW_AT_specification
6806 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6807 spec
= &die
->attrs
[i
];
6812 die
= follow_die_ref (die
, spec
, &cu
);
6813 return dwarf2_attr (die
, name
, cu
);
6819 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6820 and holds a non-zero value. This function should only be used for
6821 DW_FORM_flag attributes. */
6824 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6826 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6828 return (attr
&& DW_UNSND (attr
));
6832 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6834 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6835 which value is non-zero. However, we have to be careful with
6836 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6837 (via dwarf2_flag_true_p) follows this attribute. So we may
6838 end up accidently finding a declaration attribute that belongs
6839 to a different DIE referenced by the specification attribute,
6840 even though the given DIE does not have a declaration attribute. */
6841 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6842 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6845 /* Return the die giving the specification for DIE, if there is
6846 one. *SPEC_CU is the CU containing DIE on input, and the CU
6847 containing the return value on output. */
6849 static struct die_info
*
6850 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6852 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6855 if (spec_attr
== NULL
)
6858 return follow_die_ref (die
, spec_attr
, spec_cu
);
6861 /* Free the line_header structure *LH, and any arrays and strings it
6864 free_line_header (struct line_header
*lh
)
6866 if (lh
->standard_opcode_lengths
)
6867 xfree (lh
->standard_opcode_lengths
);
6869 /* Remember that all the lh->file_names[i].name pointers are
6870 pointers into debug_line_buffer, and don't need to be freed. */
6872 xfree (lh
->file_names
);
6874 /* Similarly for the include directory names. */
6875 if (lh
->include_dirs
)
6876 xfree (lh
->include_dirs
);
6882 /* Add an entry to LH's include directory table. */
6884 add_include_dir (struct line_header
*lh
, char *include_dir
)
6886 /* Grow the array if necessary. */
6887 if (lh
->include_dirs_size
== 0)
6889 lh
->include_dirs_size
= 1; /* for testing */
6890 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6891 * sizeof (*lh
->include_dirs
));
6893 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6895 lh
->include_dirs_size
*= 2;
6896 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6897 (lh
->include_dirs_size
6898 * sizeof (*lh
->include_dirs
)));
6901 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6905 /* Add an entry to LH's file name table. */
6907 add_file_name (struct line_header
*lh
,
6909 unsigned int dir_index
,
6910 unsigned int mod_time
,
6911 unsigned int length
)
6913 struct file_entry
*fe
;
6915 /* Grow the array if necessary. */
6916 if (lh
->file_names_size
== 0)
6918 lh
->file_names_size
= 1; /* for testing */
6919 lh
->file_names
= xmalloc (lh
->file_names_size
6920 * sizeof (*lh
->file_names
));
6922 else if (lh
->num_file_names
>= lh
->file_names_size
)
6924 lh
->file_names_size
*= 2;
6925 lh
->file_names
= xrealloc (lh
->file_names
,
6926 (lh
->file_names_size
6927 * sizeof (*lh
->file_names
)));
6930 fe
= &lh
->file_names
[lh
->num_file_names
++];
6932 fe
->dir_index
= dir_index
;
6933 fe
->mod_time
= mod_time
;
6934 fe
->length
= length
;
6940 /* Read the statement program header starting at OFFSET in
6941 .debug_line, according to the endianness of ABFD. Return a pointer
6942 to a struct line_header, allocated using xmalloc.
6944 NOTE: the strings in the include directory and file name tables of
6945 the returned object point into debug_line_buffer, and must not be
6947 static struct line_header
*
6948 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6949 struct dwarf2_cu
*cu
)
6951 struct cleanup
*back_to
;
6952 struct line_header
*lh
;
6954 unsigned int bytes_read
, offset_size
;
6956 char *cur_dir
, *cur_file
;
6958 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6960 complaint (&symfile_complaints
, _("missing .debug_line section"));
6964 /* Make sure that at least there's room for the total_length field.
6965 That could be 12 bytes long, but we're just going to fudge that. */
6966 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6968 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6972 lh
= xmalloc (sizeof (*lh
));
6973 memset (lh
, 0, sizeof (*lh
));
6974 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6977 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6979 /* Read in the header. */
6981 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
6982 &bytes_read
, &offset_size
);
6983 line_ptr
+= bytes_read
;
6984 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6985 + dwarf2_per_objfile
->line_size
))
6987 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6990 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6991 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6993 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
6994 line_ptr
+= offset_size
;
6995 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6997 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6999 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7001 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7003 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7005 lh
->standard_opcode_lengths
7006 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7008 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7009 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7011 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7015 /* Read directory table. */
7016 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7018 line_ptr
+= bytes_read
;
7019 add_include_dir (lh
, cur_dir
);
7021 line_ptr
+= bytes_read
;
7023 /* Read file name table. */
7024 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7026 unsigned int dir_index
, mod_time
, length
;
7028 line_ptr
+= bytes_read
;
7029 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7030 line_ptr
+= bytes_read
;
7031 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7032 line_ptr
+= bytes_read
;
7033 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7034 line_ptr
+= bytes_read
;
7036 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7038 line_ptr
+= bytes_read
;
7039 lh
->statement_program_start
= line_ptr
;
7041 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
7042 + dwarf2_per_objfile
->line_size
))
7043 complaint (&symfile_complaints
,
7044 _("line number info header doesn't fit in `.debug_line' section"));
7046 discard_cleanups (back_to
);
7050 /* This function exists to work around a bug in certain compilers
7051 (particularly GCC 2.95), in which the first line number marker of a
7052 function does not show up until after the prologue, right before
7053 the second line number marker. This function shifts ADDRESS down
7054 to the beginning of the function if necessary, and is called on
7055 addresses passed to record_line. */
7058 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7060 struct function_range
*fn
;
7062 /* Find the function_range containing address. */
7067 cu
->cached_fn
= cu
->first_fn
;
7071 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7077 while (fn
&& fn
!= cu
->cached_fn
)
7078 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7088 if (address
!= fn
->lowpc
)
7089 complaint (&symfile_complaints
,
7090 _("misplaced first line number at 0x%lx for '%s'"),
7091 (unsigned long) address
, fn
->name
);
7096 /* Decode the Line Number Program (LNP) for the given line_header
7097 structure and CU. The actual information extracted and the type
7098 of structures created from the LNP depends on the value of PST.
7100 1. If PST is NULL, then this procedure uses the data from the program
7101 to create all necessary symbol tables, and their linetables.
7102 The compilation directory of the file is passed in COMP_DIR,
7103 and must not be NULL.
7105 2. If PST is not NULL, this procedure reads the program to determine
7106 the list of files included by the unit represented by PST, and
7107 builds all the associated partial symbol tables. In this case,
7108 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7109 is not used to compute the full name of the symtab, and therefore
7110 omitting it when building the partial symtab does not introduce
7111 the potential for inconsistency - a partial symtab and its associated
7112 symbtab having a different fullname -). */
7115 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7116 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7118 gdb_byte
*line_ptr
, *extended_end
;
7120 unsigned int bytes_read
, extended_len
;
7121 unsigned char op_code
, extended_op
, adj_opcode
;
7123 struct objfile
*objfile
= cu
->objfile
;
7124 const int decode_for_pst_p
= (pst
!= NULL
);
7125 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7127 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7129 line_ptr
= lh
->statement_program_start
;
7130 line_end
= lh
->statement_program_end
;
7132 /* Read the statement sequences until there's nothing left. */
7133 while (line_ptr
< line_end
)
7135 /* state machine registers */
7136 CORE_ADDR address
= 0;
7137 unsigned int file
= 1;
7138 unsigned int line
= 1;
7139 unsigned int column
= 0;
7140 int is_stmt
= lh
->default_is_stmt
;
7141 int basic_block
= 0;
7142 int end_sequence
= 0;
7144 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7146 /* Start a subfile for the current file of the state machine. */
7147 /* lh->include_dirs and lh->file_names are 0-based, but the
7148 directory and file name numbers in the statement program
7150 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7154 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7156 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7159 /* Decode the table. */
7160 while (!end_sequence
)
7162 op_code
= read_1_byte (abfd
, line_ptr
);
7164 if (line_ptr
> line_end
)
7166 dwarf2_debug_line_missing_end_sequence_complaint ();
7170 if (op_code
>= lh
->opcode_base
)
7172 /* Special operand. */
7173 adj_opcode
= op_code
- lh
->opcode_base
;
7174 address
+= (adj_opcode
/ lh
->line_range
)
7175 * lh
->minimum_instruction_length
;
7176 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7177 if (lh
->num_file_names
< file
|| file
== 0)
7178 dwarf2_debug_line_missing_file_complaint ();
7181 lh
->file_names
[file
- 1].included_p
= 1;
7182 if (!decode_for_pst_p
)
7184 if (last_subfile
!= current_subfile
)
7187 record_line (last_subfile
, 0, address
);
7188 last_subfile
= current_subfile
;
7190 /* Append row to matrix using current values. */
7191 record_line (current_subfile
, line
,
7192 check_cu_functions (address
, cu
));
7197 else switch (op_code
)
7199 case DW_LNS_extended_op
:
7200 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7201 line_ptr
+= bytes_read
;
7202 extended_end
= line_ptr
+ extended_len
;
7203 extended_op
= read_1_byte (abfd
, line_ptr
);
7205 switch (extended_op
)
7207 case DW_LNE_end_sequence
:
7210 case DW_LNE_set_address
:
7211 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7212 line_ptr
+= bytes_read
;
7213 address
+= baseaddr
;
7215 case DW_LNE_define_file
:
7218 unsigned int dir_index
, mod_time
, length
;
7220 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7221 line_ptr
+= bytes_read
;
7223 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7224 line_ptr
+= bytes_read
;
7226 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7227 line_ptr
+= bytes_read
;
7229 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7230 line_ptr
+= bytes_read
;
7231 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7235 complaint (&symfile_complaints
,
7236 _("mangled .debug_line section"));
7239 /* Make sure that we parsed the extended op correctly. If e.g.
7240 we expected a different address size than the producer used,
7241 we may have read the wrong number of bytes. */
7242 if (line_ptr
!= extended_end
)
7244 complaint (&symfile_complaints
,
7245 _("mangled .debug_line section"));
7250 if (lh
->num_file_names
< file
|| file
== 0)
7251 dwarf2_debug_line_missing_file_complaint ();
7254 lh
->file_names
[file
- 1].included_p
= 1;
7255 if (!decode_for_pst_p
)
7257 if (last_subfile
!= current_subfile
)
7260 record_line (last_subfile
, 0, address
);
7261 last_subfile
= current_subfile
;
7263 record_line (current_subfile
, line
,
7264 check_cu_functions (address
, cu
));
7269 case DW_LNS_advance_pc
:
7270 address
+= lh
->minimum_instruction_length
7271 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7272 line_ptr
+= bytes_read
;
7274 case DW_LNS_advance_line
:
7275 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7276 line_ptr
+= bytes_read
;
7278 case DW_LNS_set_file
:
7280 /* The arrays lh->include_dirs and lh->file_names are
7281 0-based, but the directory and file name numbers in
7282 the statement program are 1-based. */
7283 struct file_entry
*fe
;
7286 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7287 line_ptr
+= bytes_read
;
7288 if (lh
->num_file_names
< file
|| file
== 0)
7289 dwarf2_debug_line_missing_file_complaint ();
7292 fe
= &lh
->file_names
[file
- 1];
7294 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7295 if (!decode_for_pst_p
)
7297 last_subfile
= current_subfile
;
7298 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7303 case DW_LNS_set_column
:
7304 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7305 line_ptr
+= bytes_read
;
7307 case DW_LNS_negate_stmt
:
7308 is_stmt
= (!is_stmt
);
7310 case DW_LNS_set_basic_block
:
7313 /* Add to the address register of the state machine the
7314 address increment value corresponding to special opcode
7315 255. I.e., this value is scaled by the minimum
7316 instruction length since special opcode 255 would have
7317 scaled the the increment. */
7318 case DW_LNS_const_add_pc
:
7319 address
+= (lh
->minimum_instruction_length
7320 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7322 case DW_LNS_fixed_advance_pc
:
7323 address
+= read_2_bytes (abfd
, line_ptr
);
7328 /* Unknown standard opcode, ignore it. */
7331 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7333 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7334 line_ptr
+= bytes_read
;
7339 if (lh
->num_file_names
< file
|| file
== 0)
7340 dwarf2_debug_line_missing_file_complaint ();
7343 lh
->file_names
[file
- 1].included_p
= 1;
7344 if (!decode_for_pst_p
)
7345 record_line (current_subfile
, 0, address
);
7349 if (decode_for_pst_p
)
7353 /* Now that we're done scanning the Line Header Program, we can
7354 create the psymtab of each included file. */
7355 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7356 if (lh
->file_names
[file_index
].included_p
== 1)
7358 const struct file_entry fe
= lh
->file_names
[file_index
];
7359 char *include_name
= fe
.name
;
7360 char *dir_name
= NULL
;
7361 char *pst_filename
= pst
->filename
;
7364 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7366 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7368 include_name
= concat (dir_name
, SLASH_STRING
,
7369 include_name
, (char *)NULL
);
7370 make_cleanup (xfree
, include_name
);
7373 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7375 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7376 pst_filename
, (char *)NULL
);
7377 make_cleanup (xfree
, pst_filename
);
7380 if (strcmp (include_name
, pst_filename
) != 0)
7381 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7386 /* Make sure a symtab is created for every file, even files
7387 which contain only variables (i.e. no code with associated
7391 struct file_entry
*fe
;
7393 for (i
= 0; i
< lh
->num_file_names
; i
++)
7396 fe
= &lh
->file_names
[i
];
7398 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7399 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7401 /* Skip the main file; we don't need it, and it must be
7402 allocated last, so that it will show up before the
7403 non-primary symtabs in the objfile's symtab list. */
7404 if (current_subfile
== first_subfile
)
7407 if (current_subfile
->symtab
== NULL
)
7408 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7410 fe
->symtab
= current_subfile
->symtab
;
7415 /* Start a subfile for DWARF. FILENAME is the name of the file and
7416 DIRNAME the name of the source directory which contains FILENAME
7417 or NULL if not known. COMP_DIR is the compilation directory for the
7418 linetable's compilation unit or NULL if not known.
7419 This routine tries to keep line numbers from identical absolute and
7420 relative file names in a common subfile.
7422 Using the `list' example from the GDB testsuite, which resides in
7423 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7424 of /srcdir/list0.c yields the following debugging information for list0.c:
7426 DW_AT_name: /srcdir/list0.c
7427 DW_AT_comp_dir: /compdir
7428 files.files[0].name: list0.h
7429 files.files[0].dir: /srcdir
7430 files.files[1].name: list0.c
7431 files.files[1].dir: /srcdir
7433 The line number information for list0.c has to end up in a single
7434 subfile, so that `break /srcdir/list0.c:1' works as expected.
7435 start_subfile will ensure that this happens provided that we pass the
7436 concatenation of files.files[1].dir and files.files[1].name as the
7440 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7444 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7445 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7446 second argument to start_subfile. To be consistent, we do the
7447 same here. In order not to lose the line information directory,
7448 we concatenate it to the filename when it makes sense.
7449 Note that the Dwarf3 standard says (speaking of filenames in line
7450 information): ``The directory index is ignored for file names
7451 that represent full path names''. Thus ignoring dirname in the
7452 `else' branch below isn't an issue. */
7454 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7455 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7457 fullname
= filename
;
7459 start_subfile (fullname
, comp_dir
);
7461 if (fullname
!= filename
)
7466 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7467 struct dwarf2_cu
*cu
)
7469 struct objfile
*objfile
= cu
->objfile
;
7470 struct comp_unit_head
*cu_header
= &cu
->header
;
7472 /* NOTE drow/2003-01-30: There used to be a comment and some special
7473 code here to turn a symbol with DW_AT_external and a
7474 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7475 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7476 with some versions of binutils) where shared libraries could have
7477 relocations against symbols in their debug information - the
7478 minimal symbol would have the right address, but the debug info
7479 would not. It's no longer necessary, because we will explicitly
7480 apply relocations when we read in the debug information now. */
7482 /* A DW_AT_location attribute with no contents indicates that a
7483 variable has been optimized away. */
7484 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7486 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7490 /* Handle one degenerate form of location expression specially, to
7491 preserve GDB's previous behavior when section offsets are
7492 specified. If this is just a DW_OP_addr then mark this symbol
7495 if (attr_form_is_block (attr
)
7496 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7497 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7501 SYMBOL_VALUE_ADDRESS (sym
) =
7502 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7503 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7504 fixup_symbol_section (sym
, objfile
);
7505 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7506 SYMBOL_SECTION (sym
));
7510 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7511 expression evaluator, and use LOC_COMPUTED only when necessary
7512 (i.e. when the value of a register or memory location is
7513 referenced, or a thread-local block, etc.). Then again, it might
7514 not be worthwhile. I'm assuming that it isn't unless performance
7515 or memory numbers show me otherwise. */
7517 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7518 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7521 /* Given a pointer to a DWARF information entry, figure out if we need
7522 to make a symbol table entry for it, and if so, create a new entry
7523 and return a pointer to it.
7524 If TYPE is NULL, determine symbol type from the die, otherwise
7525 used the passed type. */
7527 static struct symbol
*
7528 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7530 struct objfile
*objfile
= cu
->objfile
;
7531 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7532 struct symbol
*sym
= NULL
;
7534 struct attribute
*attr
= NULL
;
7535 struct attribute
*attr2
= NULL
;
7538 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7540 if (die
->tag
!= DW_TAG_namespace
)
7541 name
= dwarf2_linkage_name (die
, cu
);
7543 name
= TYPE_NAME (type
);
7547 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7548 sizeof (struct symbol
));
7549 OBJSTAT (objfile
, n_syms
++);
7550 memset (sym
, 0, sizeof (struct symbol
));
7552 /* Cache this symbol's name and the name's demangled form (if any). */
7553 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7554 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7556 /* Default assumptions.
7557 Use the passed type or decode it from the die. */
7558 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7559 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7561 SYMBOL_TYPE (sym
) = type
;
7563 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7564 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7567 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7570 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7573 int file_index
= DW_UNSND (attr
);
7574 if (cu
->line_header
== NULL
7575 || file_index
> cu
->line_header
->num_file_names
)
7576 complaint (&symfile_complaints
,
7577 _("file index out of range"));
7578 else if (file_index
> 0)
7580 struct file_entry
*fe
;
7581 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7582 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7589 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7592 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7594 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7596 case DW_TAG_subprogram
:
7597 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7599 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7600 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7601 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7602 || cu
->language
== language_ada
)
7604 /* Subprograms marked external are stored as a global symbol.
7605 Ada subprograms, whether marked external or not, are always
7606 stored as a global symbol, because we want to be able to
7607 access them globally. For instance, we want to be able
7608 to break on a nested subprogram without having to
7609 specify the context. */
7610 add_symbol_to_list (sym
, &global_symbols
);
7614 add_symbol_to_list (sym
, cu
->list_in_scope
);
7617 case DW_TAG_variable
:
7618 /* Compilation with minimal debug info may result in variables
7619 with missing type entries. Change the misleading `void' type
7620 to something sensible. */
7621 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7623 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7625 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7628 dwarf2_const_value (attr
, sym
, cu
);
7629 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7630 if (attr2
&& (DW_UNSND (attr2
) != 0))
7631 add_symbol_to_list (sym
, &global_symbols
);
7633 add_symbol_to_list (sym
, cu
->list_in_scope
);
7636 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7639 var_decode_location (attr
, sym
, cu
);
7640 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7641 if (attr2
&& (DW_UNSND (attr2
) != 0))
7642 add_symbol_to_list (sym
, &global_symbols
);
7644 add_symbol_to_list (sym
, cu
->list_in_scope
);
7648 /* We do not know the address of this symbol.
7649 If it is an external symbol and we have type information
7650 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7651 The address of the variable will then be determined from
7652 the minimal symbol table whenever the variable is
7654 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7655 if (attr2
&& (DW_UNSND (attr2
) != 0)
7656 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7658 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7659 add_symbol_to_list (sym
, &global_symbols
);
7663 case DW_TAG_formal_parameter
:
7664 SYMBOL_IS_ARGUMENT (sym
) = 1;
7665 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7668 var_decode_location (attr
, sym
, cu
);
7670 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7673 dwarf2_const_value (attr
, sym
, cu
);
7675 add_symbol_to_list (sym
, cu
->list_in_scope
);
7677 case DW_TAG_unspecified_parameters
:
7678 /* From varargs functions; gdb doesn't seem to have any
7679 interest in this information, so just ignore it for now.
7682 case DW_TAG_class_type
:
7683 case DW_TAG_interface_type
:
7684 case DW_TAG_structure_type
:
7685 case DW_TAG_union_type
:
7686 case DW_TAG_set_type
:
7687 case DW_TAG_enumeration_type
:
7688 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7689 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7691 /* Make sure that the symbol includes appropriate enclosing
7692 classes/namespaces in its name. These are calculated in
7693 read_structure_type, and the correct name is saved in
7696 if (cu
->language
== language_cplus
7697 || cu
->language
== language_java
)
7699 struct type
*type
= SYMBOL_TYPE (sym
);
7701 if (TYPE_TAG_NAME (type
) != NULL
)
7703 /* FIXME: carlton/2003-11-10: Should this use
7704 SYMBOL_SET_NAMES instead? (The same problem also
7705 arises further down in this function.) */
7706 /* The type's name is already allocated along with
7707 this objfile, so we don't need to duplicate it
7709 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7714 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7715 really ever be static objects: otherwise, if you try
7716 to, say, break of a class's method and you're in a file
7717 which doesn't mention that class, it won't work unless
7718 the check for all static symbols in lookup_symbol_aux
7719 saves you. See the OtherFileClass tests in
7720 gdb.c++/namespace.exp. */
7722 struct pending
**list_to_add
;
7724 list_to_add
= (cu
->list_in_scope
== &file_symbols
7725 && (cu
->language
== language_cplus
7726 || cu
->language
== language_java
)
7727 ? &global_symbols
: cu
->list_in_scope
);
7729 add_symbol_to_list (sym
, list_to_add
);
7731 /* The semantics of C++ state that "struct foo { ... }" also
7732 defines a typedef for "foo". A Java class declaration also
7733 defines a typedef for the class. */
7734 if (cu
->language
== language_cplus
7735 || cu
->language
== language_java
7736 || cu
->language
== language_ada
)
7738 /* The symbol's name is already allocated along with
7739 this objfile, so we don't need to duplicate it for
7741 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7742 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7746 case DW_TAG_typedef
:
7747 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7748 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7749 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7750 add_symbol_to_list (sym
, cu
->list_in_scope
);
7752 case DW_TAG_base_type
:
7753 case DW_TAG_subrange_type
:
7754 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7755 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7756 add_symbol_to_list (sym
, cu
->list_in_scope
);
7758 case DW_TAG_enumerator
:
7759 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7760 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7763 dwarf2_const_value (attr
, sym
, cu
);
7766 /* NOTE: carlton/2003-11-10: See comment above in the
7767 DW_TAG_class_type, etc. block. */
7769 struct pending
**list_to_add
;
7771 list_to_add
= (cu
->list_in_scope
== &file_symbols
7772 && (cu
->language
== language_cplus
7773 || cu
->language
== language_java
)
7774 ? &global_symbols
: cu
->list_in_scope
);
7776 add_symbol_to_list (sym
, list_to_add
);
7779 case DW_TAG_namespace
:
7780 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7781 add_symbol_to_list (sym
, &global_symbols
);
7784 /* Not a tag we recognize. Hopefully we aren't processing
7785 trash data, but since we must specifically ignore things
7786 we don't recognize, there is nothing else we should do at
7788 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7789 dwarf_tag_name (die
->tag
));
7793 /* For the benefit of old versions of GCC, check for anonymous
7794 namespaces based on the demangled name. */
7795 if (!processing_has_namespace_info
7796 && cu
->language
== language_cplus
7797 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7798 cp_scan_for_anonymous_namespaces (sym
);
7803 /* Copy constant value from an attribute to a symbol. */
7806 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7807 struct dwarf2_cu
*cu
)
7809 struct objfile
*objfile
= cu
->objfile
;
7810 struct comp_unit_head
*cu_header
= &cu
->header
;
7811 struct dwarf_block
*blk
;
7816 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7817 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7818 cu_header
->addr_size
,
7819 TYPE_LENGTH (SYMBOL_TYPE
7821 SYMBOL_VALUE_BYTES (sym
) =
7822 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7823 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7824 it's body - store_unsigned_integer. */
7825 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7827 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7830 /* DW_STRING is already allocated on the obstack, point directly
7832 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7833 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7835 case DW_FORM_block1
:
7836 case DW_FORM_block2
:
7837 case DW_FORM_block4
:
7839 blk
= DW_BLOCK (attr
);
7840 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7841 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7843 TYPE_LENGTH (SYMBOL_TYPE
7845 SYMBOL_VALUE_BYTES (sym
) =
7846 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7847 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7848 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7851 /* The DW_AT_const_value attributes are supposed to carry the
7852 symbol's value "represented as it would be on the target
7853 architecture." By the time we get here, it's already been
7854 converted to host endianness, so we just need to sign- or
7855 zero-extend it as appropriate. */
7857 dwarf2_const_value_data (attr
, sym
, 8);
7860 dwarf2_const_value_data (attr
, sym
, 16);
7863 dwarf2_const_value_data (attr
, sym
, 32);
7866 dwarf2_const_value_data (attr
, sym
, 64);
7870 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7871 SYMBOL_CLASS (sym
) = LOC_CONST
;
7875 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7876 SYMBOL_CLASS (sym
) = LOC_CONST
;
7880 complaint (&symfile_complaints
,
7881 _("unsupported const value attribute form: '%s'"),
7882 dwarf_form_name (attr
->form
));
7883 SYMBOL_VALUE (sym
) = 0;
7884 SYMBOL_CLASS (sym
) = LOC_CONST
;
7890 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7891 or zero-extend it as appropriate for the symbol's type. */
7893 dwarf2_const_value_data (struct attribute
*attr
,
7897 LONGEST l
= DW_UNSND (attr
);
7899 if (bits
< sizeof (l
) * 8)
7901 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7902 l
&= ((LONGEST
) 1 << bits
) - 1;
7904 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7907 SYMBOL_VALUE (sym
) = l
;
7908 SYMBOL_CLASS (sym
) = LOC_CONST
;
7912 /* Return the type of the die in question using its DW_AT_type attribute. */
7914 static struct type
*
7915 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7917 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7919 struct attribute
*type_attr
;
7920 struct die_info
*type_die
;
7922 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7925 /* A missing DW_AT_type represents a void type. */
7926 return builtin_type (gdbarch
)->builtin_void
;
7929 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7931 type
= tag_type_to_type (type_die
, cu
);
7934 dump_die_for_error (type_die
);
7935 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7941 /* Return the containing type of the die in question using its
7942 DW_AT_containing_type attribute. */
7944 static struct type
*
7945 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7947 struct type
*type
= NULL
;
7948 struct attribute
*type_attr
;
7949 struct die_info
*type_die
= NULL
;
7951 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7954 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7955 type
= tag_type_to_type (type_die
, cu
);
7960 dump_die_for_error (type_die
);
7961 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7967 static struct type
*
7968 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7970 struct type
*this_type
;
7972 this_type
= read_type_die (die
, cu
);
7975 dump_die_for_error (die
);
7976 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7982 static struct type
*
7983 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7985 struct type
*this_type
;
7987 this_type
= get_die_type (die
, cu
);
7993 case DW_TAG_class_type
:
7994 case DW_TAG_interface_type
:
7995 case DW_TAG_structure_type
:
7996 case DW_TAG_union_type
:
7997 this_type
= read_structure_type (die
, cu
);
7999 case DW_TAG_enumeration_type
:
8000 this_type
= read_enumeration_type (die
, cu
);
8002 case DW_TAG_subprogram
:
8003 case DW_TAG_subroutine_type
:
8004 this_type
= read_subroutine_type (die
, cu
);
8006 case DW_TAG_array_type
:
8007 this_type
= read_array_type (die
, cu
);
8009 case DW_TAG_set_type
:
8010 this_type
= read_set_type (die
, cu
);
8012 case DW_TAG_pointer_type
:
8013 this_type
= read_tag_pointer_type (die
, cu
);
8015 case DW_TAG_ptr_to_member_type
:
8016 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8018 case DW_TAG_reference_type
:
8019 this_type
= read_tag_reference_type (die
, cu
);
8021 case DW_TAG_const_type
:
8022 this_type
= read_tag_const_type (die
, cu
);
8024 case DW_TAG_volatile_type
:
8025 this_type
= read_tag_volatile_type (die
, cu
);
8027 case DW_TAG_string_type
:
8028 this_type
= read_tag_string_type (die
, cu
);
8030 case DW_TAG_typedef
:
8031 this_type
= read_typedef (die
, cu
);
8033 case DW_TAG_subrange_type
:
8034 this_type
= read_subrange_type (die
, cu
);
8036 case DW_TAG_base_type
:
8037 this_type
= read_base_type (die
, cu
);
8039 case DW_TAG_unspecified_type
:
8040 this_type
= read_unspecified_type (die
, cu
);
8042 case DW_TAG_namespace
:
8043 this_type
= read_namespace_type (die
, cu
);
8046 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8047 dwarf_tag_name (die
->tag
));
8054 /* Return the name of the namespace/class that DIE is defined within,
8055 or "" if we can't tell. The caller should not xfree the result.
8057 For example, if we're within the method foo() in the following
8067 then determine_prefix on foo's die will return "N::C". */
8070 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8072 struct die_info
*parent
, *spec_die
;
8073 struct dwarf2_cu
*spec_cu
;
8074 struct type
*parent_type
;
8076 if (cu
->language
!= language_cplus
8077 && cu
->language
!= language_java
)
8080 /* We have to be careful in the presence of DW_AT_specification.
8081 For example, with GCC 3.4, given the code
8085 // Definition of N::foo.
8089 then we'll have a tree of DIEs like this:
8091 1: DW_TAG_compile_unit
8092 2: DW_TAG_namespace // N
8093 3: DW_TAG_subprogram // declaration of N::foo
8094 4: DW_TAG_subprogram // definition of N::foo
8095 DW_AT_specification // refers to die #3
8097 Thus, when processing die #4, we have to pretend that we're in
8098 the context of its DW_AT_specification, namely the contex of die
8101 spec_die
= die_specification (die
, &spec_cu
);
8102 if (spec_die
== NULL
)
8103 parent
= die
->parent
;
8106 parent
= spec_die
->parent
;
8113 switch (parent
->tag
)
8115 case DW_TAG_namespace
:
8116 parent_type
= read_type_die (parent
, cu
);
8117 /* We give a name to even anonymous namespaces. */
8118 return TYPE_TAG_NAME (parent_type
);
8119 case DW_TAG_class_type
:
8120 case DW_TAG_interface_type
:
8121 case DW_TAG_structure_type
:
8122 case DW_TAG_union_type
:
8123 parent_type
= read_type_die (parent
, cu
);
8124 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8125 return TYPE_TAG_NAME (parent_type
);
8127 /* An anonymous structure is only allowed non-static data
8128 members; no typedefs, no member functions, et cetera.
8129 So it does not need a prefix. */
8132 return determine_prefix (parent
, cu
);
8136 /* Return a newly-allocated string formed by concatenating PREFIX and
8137 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8138 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8139 perform an obconcat, otherwise allocate storage for the result. The CU argument
8140 is used to determine the language and hence, the appropriate separator. */
8142 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8145 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8146 struct dwarf2_cu
*cu
)
8150 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8152 else if (cu
->language
== language_java
)
8164 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8165 strcpy (retval
, prefix
);
8166 strcat (retval
, sep
);
8167 strcat (retval
, suffix
);
8172 /* We have an obstack. */
8173 return obconcat (obs
, prefix
, sep
, suffix
);
8177 /* Return sibling of die, NULL if no sibling. */
8179 static struct die_info
*
8180 sibling_die (struct die_info
*die
)
8182 return die
->sibling
;
8185 /* Get linkage name of a die, return NULL if not found. */
8188 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8190 struct attribute
*attr
;
8192 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8193 if (attr
&& DW_STRING (attr
))
8194 return DW_STRING (attr
);
8195 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8196 if (attr
&& DW_STRING (attr
))
8197 return DW_STRING (attr
);
8201 /* Get name of a die, return NULL if not found. */
8204 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8206 struct attribute
*attr
;
8208 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8209 if (attr
&& DW_STRING (attr
))
8210 return DW_STRING (attr
);
8214 /* Return the die that this die in an extension of, or NULL if there
8215 is none. *EXT_CU is the CU containing DIE on input, and the CU
8216 containing the return value on output. */
8218 static struct die_info
*
8219 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8221 struct attribute
*attr
;
8223 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8227 return follow_die_ref (die
, attr
, ext_cu
);
8230 /* Convert a DIE tag into its string name. */
8233 dwarf_tag_name (unsigned tag
)
8237 case DW_TAG_padding
:
8238 return "DW_TAG_padding";
8239 case DW_TAG_array_type
:
8240 return "DW_TAG_array_type";
8241 case DW_TAG_class_type
:
8242 return "DW_TAG_class_type";
8243 case DW_TAG_entry_point
:
8244 return "DW_TAG_entry_point";
8245 case DW_TAG_enumeration_type
:
8246 return "DW_TAG_enumeration_type";
8247 case DW_TAG_formal_parameter
:
8248 return "DW_TAG_formal_parameter";
8249 case DW_TAG_imported_declaration
:
8250 return "DW_TAG_imported_declaration";
8252 return "DW_TAG_label";
8253 case DW_TAG_lexical_block
:
8254 return "DW_TAG_lexical_block";
8256 return "DW_TAG_member";
8257 case DW_TAG_pointer_type
:
8258 return "DW_TAG_pointer_type";
8259 case DW_TAG_reference_type
:
8260 return "DW_TAG_reference_type";
8261 case DW_TAG_compile_unit
:
8262 return "DW_TAG_compile_unit";
8263 case DW_TAG_string_type
:
8264 return "DW_TAG_string_type";
8265 case DW_TAG_structure_type
:
8266 return "DW_TAG_structure_type";
8267 case DW_TAG_subroutine_type
:
8268 return "DW_TAG_subroutine_type";
8269 case DW_TAG_typedef
:
8270 return "DW_TAG_typedef";
8271 case DW_TAG_union_type
:
8272 return "DW_TAG_union_type";
8273 case DW_TAG_unspecified_parameters
:
8274 return "DW_TAG_unspecified_parameters";
8275 case DW_TAG_variant
:
8276 return "DW_TAG_variant";
8277 case DW_TAG_common_block
:
8278 return "DW_TAG_common_block";
8279 case DW_TAG_common_inclusion
:
8280 return "DW_TAG_common_inclusion";
8281 case DW_TAG_inheritance
:
8282 return "DW_TAG_inheritance";
8283 case DW_TAG_inlined_subroutine
:
8284 return "DW_TAG_inlined_subroutine";
8286 return "DW_TAG_module";
8287 case DW_TAG_ptr_to_member_type
:
8288 return "DW_TAG_ptr_to_member_type";
8289 case DW_TAG_set_type
:
8290 return "DW_TAG_set_type";
8291 case DW_TAG_subrange_type
:
8292 return "DW_TAG_subrange_type";
8293 case DW_TAG_with_stmt
:
8294 return "DW_TAG_with_stmt";
8295 case DW_TAG_access_declaration
:
8296 return "DW_TAG_access_declaration";
8297 case DW_TAG_base_type
:
8298 return "DW_TAG_base_type";
8299 case DW_TAG_catch_block
:
8300 return "DW_TAG_catch_block";
8301 case DW_TAG_const_type
:
8302 return "DW_TAG_const_type";
8303 case DW_TAG_constant
:
8304 return "DW_TAG_constant";
8305 case DW_TAG_enumerator
:
8306 return "DW_TAG_enumerator";
8307 case DW_TAG_file_type
:
8308 return "DW_TAG_file_type";
8310 return "DW_TAG_friend";
8311 case DW_TAG_namelist
:
8312 return "DW_TAG_namelist";
8313 case DW_TAG_namelist_item
:
8314 return "DW_TAG_namelist_item";
8315 case DW_TAG_packed_type
:
8316 return "DW_TAG_packed_type";
8317 case DW_TAG_subprogram
:
8318 return "DW_TAG_subprogram";
8319 case DW_TAG_template_type_param
:
8320 return "DW_TAG_template_type_param";
8321 case DW_TAG_template_value_param
:
8322 return "DW_TAG_template_value_param";
8323 case DW_TAG_thrown_type
:
8324 return "DW_TAG_thrown_type";
8325 case DW_TAG_try_block
:
8326 return "DW_TAG_try_block";
8327 case DW_TAG_variant_part
:
8328 return "DW_TAG_variant_part";
8329 case DW_TAG_variable
:
8330 return "DW_TAG_variable";
8331 case DW_TAG_volatile_type
:
8332 return "DW_TAG_volatile_type";
8333 case DW_TAG_dwarf_procedure
:
8334 return "DW_TAG_dwarf_procedure";
8335 case DW_TAG_restrict_type
:
8336 return "DW_TAG_restrict_type";
8337 case DW_TAG_interface_type
:
8338 return "DW_TAG_interface_type";
8339 case DW_TAG_namespace
:
8340 return "DW_TAG_namespace";
8341 case DW_TAG_imported_module
:
8342 return "DW_TAG_imported_module";
8343 case DW_TAG_unspecified_type
:
8344 return "DW_TAG_unspecified_type";
8345 case DW_TAG_partial_unit
:
8346 return "DW_TAG_partial_unit";
8347 case DW_TAG_imported_unit
:
8348 return "DW_TAG_imported_unit";
8349 case DW_TAG_condition
:
8350 return "DW_TAG_condition";
8351 case DW_TAG_shared_type
:
8352 return "DW_TAG_shared_type";
8353 case DW_TAG_MIPS_loop
:
8354 return "DW_TAG_MIPS_loop";
8355 case DW_TAG_HP_array_descriptor
:
8356 return "DW_TAG_HP_array_descriptor";
8357 case DW_TAG_format_label
:
8358 return "DW_TAG_format_label";
8359 case DW_TAG_function_template
:
8360 return "DW_TAG_function_template";
8361 case DW_TAG_class_template
:
8362 return "DW_TAG_class_template";
8363 case DW_TAG_GNU_BINCL
:
8364 return "DW_TAG_GNU_BINCL";
8365 case DW_TAG_GNU_EINCL
:
8366 return "DW_TAG_GNU_EINCL";
8367 case DW_TAG_upc_shared_type
:
8368 return "DW_TAG_upc_shared_type";
8369 case DW_TAG_upc_strict_type
:
8370 return "DW_TAG_upc_strict_type";
8371 case DW_TAG_upc_relaxed_type
:
8372 return "DW_TAG_upc_relaxed_type";
8373 case DW_TAG_PGI_kanji_type
:
8374 return "DW_TAG_PGI_kanji_type";
8375 case DW_TAG_PGI_interface_block
:
8376 return "DW_TAG_PGI_interface_block";
8378 return "DW_TAG_<unknown>";
8382 /* Convert a DWARF attribute code into its string name. */
8385 dwarf_attr_name (unsigned attr
)
8390 return "DW_AT_sibling";
8391 case DW_AT_location
:
8392 return "DW_AT_location";
8394 return "DW_AT_name";
8395 case DW_AT_ordering
:
8396 return "DW_AT_ordering";
8397 case DW_AT_subscr_data
:
8398 return "DW_AT_subscr_data";
8399 case DW_AT_byte_size
:
8400 return "DW_AT_byte_size";
8401 case DW_AT_bit_offset
:
8402 return "DW_AT_bit_offset";
8403 case DW_AT_bit_size
:
8404 return "DW_AT_bit_size";
8405 case DW_AT_element_list
:
8406 return "DW_AT_element_list";
8407 case DW_AT_stmt_list
:
8408 return "DW_AT_stmt_list";
8410 return "DW_AT_low_pc";
8412 return "DW_AT_high_pc";
8413 case DW_AT_language
:
8414 return "DW_AT_language";
8416 return "DW_AT_member";
8418 return "DW_AT_discr";
8419 case DW_AT_discr_value
:
8420 return "DW_AT_discr_value";
8421 case DW_AT_visibility
:
8422 return "DW_AT_visibility";
8424 return "DW_AT_import";
8425 case DW_AT_string_length
:
8426 return "DW_AT_string_length";
8427 case DW_AT_common_reference
:
8428 return "DW_AT_common_reference";
8429 case DW_AT_comp_dir
:
8430 return "DW_AT_comp_dir";
8431 case DW_AT_const_value
:
8432 return "DW_AT_const_value";
8433 case DW_AT_containing_type
:
8434 return "DW_AT_containing_type";
8435 case DW_AT_default_value
:
8436 return "DW_AT_default_value";
8438 return "DW_AT_inline";
8439 case DW_AT_is_optional
:
8440 return "DW_AT_is_optional";
8441 case DW_AT_lower_bound
:
8442 return "DW_AT_lower_bound";
8443 case DW_AT_producer
:
8444 return "DW_AT_producer";
8445 case DW_AT_prototyped
:
8446 return "DW_AT_prototyped";
8447 case DW_AT_return_addr
:
8448 return "DW_AT_return_addr";
8449 case DW_AT_start_scope
:
8450 return "DW_AT_start_scope";
8451 case DW_AT_bit_stride
:
8452 return "DW_AT_bit_stride";
8453 case DW_AT_upper_bound
:
8454 return "DW_AT_upper_bound";
8455 case DW_AT_abstract_origin
:
8456 return "DW_AT_abstract_origin";
8457 case DW_AT_accessibility
:
8458 return "DW_AT_accessibility";
8459 case DW_AT_address_class
:
8460 return "DW_AT_address_class";
8461 case DW_AT_artificial
:
8462 return "DW_AT_artificial";
8463 case DW_AT_base_types
:
8464 return "DW_AT_base_types";
8465 case DW_AT_calling_convention
:
8466 return "DW_AT_calling_convention";
8468 return "DW_AT_count";
8469 case DW_AT_data_member_location
:
8470 return "DW_AT_data_member_location";
8471 case DW_AT_decl_column
:
8472 return "DW_AT_decl_column";
8473 case DW_AT_decl_file
:
8474 return "DW_AT_decl_file";
8475 case DW_AT_decl_line
:
8476 return "DW_AT_decl_line";
8477 case DW_AT_declaration
:
8478 return "DW_AT_declaration";
8479 case DW_AT_discr_list
:
8480 return "DW_AT_discr_list";
8481 case DW_AT_encoding
:
8482 return "DW_AT_encoding";
8483 case DW_AT_external
:
8484 return "DW_AT_external";
8485 case DW_AT_frame_base
:
8486 return "DW_AT_frame_base";
8488 return "DW_AT_friend";
8489 case DW_AT_identifier_case
:
8490 return "DW_AT_identifier_case";
8491 case DW_AT_macro_info
:
8492 return "DW_AT_macro_info";
8493 case DW_AT_namelist_items
:
8494 return "DW_AT_namelist_items";
8495 case DW_AT_priority
:
8496 return "DW_AT_priority";
8498 return "DW_AT_segment";
8499 case DW_AT_specification
:
8500 return "DW_AT_specification";
8501 case DW_AT_static_link
:
8502 return "DW_AT_static_link";
8504 return "DW_AT_type";
8505 case DW_AT_use_location
:
8506 return "DW_AT_use_location";
8507 case DW_AT_variable_parameter
:
8508 return "DW_AT_variable_parameter";
8509 case DW_AT_virtuality
:
8510 return "DW_AT_virtuality";
8511 case DW_AT_vtable_elem_location
:
8512 return "DW_AT_vtable_elem_location";
8513 /* DWARF 3 values. */
8514 case DW_AT_allocated
:
8515 return "DW_AT_allocated";
8516 case DW_AT_associated
:
8517 return "DW_AT_associated";
8518 case DW_AT_data_location
:
8519 return "DW_AT_data_location";
8520 case DW_AT_byte_stride
:
8521 return "DW_AT_byte_stride";
8522 case DW_AT_entry_pc
:
8523 return "DW_AT_entry_pc";
8524 case DW_AT_use_UTF8
:
8525 return "DW_AT_use_UTF8";
8526 case DW_AT_extension
:
8527 return "DW_AT_extension";
8529 return "DW_AT_ranges";
8530 case DW_AT_trampoline
:
8531 return "DW_AT_trampoline";
8532 case DW_AT_call_column
:
8533 return "DW_AT_call_column";
8534 case DW_AT_call_file
:
8535 return "DW_AT_call_file";
8536 case DW_AT_call_line
:
8537 return "DW_AT_call_line";
8538 case DW_AT_description
:
8539 return "DW_AT_description";
8540 case DW_AT_binary_scale
:
8541 return "DW_AT_binary_scale";
8542 case DW_AT_decimal_scale
:
8543 return "DW_AT_decimal_scale";
8545 return "DW_AT_small";
8546 case DW_AT_decimal_sign
:
8547 return "DW_AT_decimal_sign";
8548 case DW_AT_digit_count
:
8549 return "DW_AT_digit_count";
8550 case DW_AT_picture_string
:
8551 return "DW_AT_picture_string";
8553 return "DW_AT_mutable";
8554 case DW_AT_threads_scaled
:
8555 return "DW_AT_threads_scaled";
8556 case DW_AT_explicit
:
8557 return "DW_AT_explicit";
8558 case DW_AT_object_pointer
:
8559 return "DW_AT_object_pointer";
8560 case DW_AT_endianity
:
8561 return "DW_AT_endianity";
8562 case DW_AT_elemental
:
8563 return "DW_AT_elemental";
8565 return "DW_AT_pure";
8566 case DW_AT_recursive
:
8567 return "DW_AT_recursive";
8568 /* SGI/MIPS extensions. */
8569 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8570 case DW_AT_MIPS_fde
:
8571 return "DW_AT_MIPS_fde";
8573 case DW_AT_MIPS_loop_begin
:
8574 return "DW_AT_MIPS_loop_begin";
8575 case DW_AT_MIPS_tail_loop_begin
:
8576 return "DW_AT_MIPS_tail_loop_begin";
8577 case DW_AT_MIPS_epilog_begin
:
8578 return "DW_AT_MIPS_epilog_begin";
8579 case DW_AT_MIPS_loop_unroll_factor
:
8580 return "DW_AT_MIPS_loop_unroll_factor";
8581 case DW_AT_MIPS_software_pipeline_depth
:
8582 return "DW_AT_MIPS_software_pipeline_depth";
8583 case DW_AT_MIPS_linkage_name
:
8584 return "DW_AT_MIPS_linkage_name";
8585 case DW_AT_MIPS_stride
:
8586 return "DW_AT_MIPS_stride";
8587 case DW_AT_MIPS_abstract_name
:
8588 return "DW_AT_MIPS_abstract_name";
8589 case DW_AT_MIPS_clone_origin
:
8590 return "DW_AT_MIPS_clone_origin";
8591 case DW_AT_MIPS_has_inlines
:
8592 return "DW_AT_MIPS_has_inlines";
8593 /* HP extensions. */
8594 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8595 case DW_AT_HP_block_index
:
8596 return "DW_AT_HP_block_index";
8598 case DW_AT_HP_unmodifiable
:
8599 return "DW_AT_HP_unmodifiable";
8600 case DW_AT_HP_actuals_stmt_list
:
8601 return "DW_AT_HP_actuals_stmt_list";
8602 case DW_AT_HP_proc_per_section
:
8603 return "DW_AT_HP_proc_per_section";
8604 case DW_AT_HP_raw_data_ptr
:
8605 return "DW_AT_HP_raw_data_ptr";
8606 case DW_AT_HP_pass_by_reference
:
8607 return "DW_AT_HP_pass_by_reference";
8608 case DW_AT_HP_opt_level
:
8609 return "DW_AT_HP_opt_level";
8610 case DW_AT_HP_prof_version_id
:
8611 return "DW_AT_HP_prof_version_id";
8612 case DW_AT_HP_opt_flags
:
8613 return "DW_AT_HP_opt_flags";
8614 case DW_AT_HP_cold_region_low_pc
:
8615 return "DW_AT_HP_cold_region_low_pc";
8616 case DW_AT_HP_cold_region_high_pc
:
8617 return "DW_AT_HP_cold_region_high_pc";
8618 case DW_AT_HP_all_variables_modifiable
:
8619 return "DW_AT_HP_all_variables_modifiable";
8620 case DW_AT_HP_linkage_name
:
8621 return "DW_AT_HP_linkage_name";
8622 case DW_AT_HP_prof_flags
:
8623 return "DW_AT_HP_prof_flags";
8624 /* GNU extensions. */
8625 case DW_AT_sf_names
:
8626 return "DW_AT_sf_names";
8627 case DW_AT_src_info
:
8628 return "DW_AT_src_info";
8629 case DW_AT_mac_info
:
8630 return "DW_AT_mac_info";
8631 case DW_AT_src_coords
:
8632 return "DW_AT_src_coords";
8633 case DW_AT_body_begin
:
8634 return "DW_AT_body_begin";
8635 case DW_AT_body_end
:
8636 return "DW_AT_body_end";
8637 case DW_AT_GNU_vector
:
8638 return "DW_AT_GNU_vector";
8639 /* VMS extensions. */
8640 case DW_AT_VMS_rtnbeg_pd_address
:
8641 return "DW_AT_VMS_rtnbeg_pd_address";
8642 /* UPC extension. */
8643 case DW_AT_upc_threads_scaled
:
8644 return "DW_AT_upc_threads_scaled";
8645 /* PGI (STMicroelectronics) extensions. */
8646 case DW_AT_PGI_lbase
:
8647 return "DW_AT_PGI_lbase";
8648 case DW_AT_PGI_soffset
:
8649 return "DW_AT_PGI_soffset";
8650 case DW_AT_PGI_lstride
:
8651 return "DW_AT_PGI_lstride";
8653 return "DW_AT_<unknown>";
8657 /* Convert a DWARF value form code into its string name. */
8660 dwarf_form_name (unsigned form
)
8665 return "DW_FORM_addr";
8666 case DW_FORM_block2
:
8667 return "DW_FORM_block2";
8668 case DW_FORM_block4
:
8669 return "DW_FORM_block4";
8671 return "DW_FORM_data2";
8673 return "DW_FORM_data4";
8675 return "DW_FORM_data8";
8676 case DW_FORM_string
:
8677 return "DW_FORM_string";
8679 return "DW_FORM_block";
8680 case DW_FORM_block1
:
8681 return "DW_FORM_block1";
8683 return "DW_FORM_data1";
8685 return "DW_FORM_flag";
8687 return "DW_FORM_sdata";
8689 return "DW_FORM_strp";
8691 return "DW_FORM_udata";
8692 case DW_FORM_ref_addr
:
8693 return "DW_FORM_ref_addr";
8695 return "DW_FORM_ref1";
8697 return "DW_FORM_ref2";
8699 return "DW_FORM_ref4";
8701 return "DW_FORM_ref8";
8702 case DW_FORM_ref_udata
:
8703 return "DW_FORM_ref_udata";
8704 case DW_FORM_indirect
:
8705 return "DW_FORM_indirect";
8707 return "DW_FORM_<unknown>";
8711 /* Convert a DWARF stack opcode into its string name. */
8714 dwarf_stack_op_name (unsigned op
)
8719 return "DW_OP_addr";
8721 return "DW_OP_deref";
8723 return "DW_OP_const1u";
8725 return "DW_OP_const1s";
8727 return "DW_OP_const2u";
8729 return "DW_OP_const2s";
8731 return "DW_OP_const4u";
8733 return "DW_OP_const4s";
8735 return "DW_OP_const8u";
8737 return "DW_OP_const8s";
8739 return "DW_OP_constu";
8741 return "DW_OP_consts";
8745 return "DW_OP_drop";
8747 return "DW_OP_over";
8749 return "DW_OP_pick";
8751 return "DW_OP_swap";
8755 return "DW_OP_xderef";
8763 return "DW_OP_minus";
8775 return "DW_OP_plus";
8776 case DW_OP_plus_uconst
:
8777 return "DW_OP_plus_uconst";
8783 return "DW_OP_shra";
8801 return "DW_OP_skip";
8803 return "DW_OP_lit0";
8805 return "DW_OP_lit1";
8807 return "DW_OP_lit2";
8809 return "DW_OP_lit3";
8811 return "DW_OP_lit4";
8813 return "DW_OP_lit5";
8815 return "DW_OP_lit6";
8817 return "DW_OP_lit7";
8819 return "DW_OP_lit8";
8821 return "DW_OP_lit9";
8823 return "DW_OP_lit10";
8825 return "DW_OP_lit11";
8827 return "DW_OP_lit12";
8829 return "DW_OP_lit13";
8831 return "DW_OP_lit14";
8833 return "DW_OP_lit15";
8835 return "DW_OP_lit16";
8837 return "DW_OP_lit17";
8839 return "DW_OP_lit18";
8841 return "DW_OP_lit19";
8843 return "DW_OP_lit20";
8845 return "DW_OP_lit21";
8847 return "DW_OP_lit22";
8849 return "DW_OP_lit23";
8851 return "DW_OP_lit24";
8853 return "DW_OP_lit25";
8855 return "DW_OP_lit26";
8857 return "DW_OP_lit27";
8859 return "DW_OP_lit28";
8861 return "DW_OP_lit29";
8863 return "DW_OP_lit30";
8865 return "DW_OP_lit31";
8867 return "DW_OP_reg0";
8869 return "DW_OP_reg1";
8871 return "DW_OP_reg2";
8873 return "DW_OP_reg3";
8875 return "DW_OP_reg4";
8877 return "DW_OP_reg5";
8879 return "DW_OP_reg6";
8881 return "DW_OP_reg7";
8883 return "DW_OP_reg8";
8885 return "DW_OP_reg9";
8887 return "DW_OP_reg10";
8889 return "DW_OP_reg11";
8891 return "DW_OP_reg12";
8893 return "DW_OP_reg13";
8895 return "DW_OP_reg14";
8897 return "DW_OP_reg15";
8899 return "DW_OP_reg16";
8901 return "DW_OP_reg17";
8903 return "DW_OP_reg18";
8905 return "DW_OP_reg19";
8907 return "DW_OP_reg20";
8909 return "DW_OP_reg21";
8911 return "DW_OP_reg22";
8913 return "DW_OP_reg23";
8915 return "DW_OP_reg24";
8917 return "DW_OP_reg25";
8919 return "DW_OP_reg26";
8921 return "DW_OP_reg27";
8923 return "DW_OP_reg28";
8925 return "DW_OP_reg29";
8927 return "DW_OP_reg30";
8929 return "DW_OP_reg31";
8931 return "DW_OP_breg0";
8933 return "DW_OP_breg1";
8935 return "DW_OP_breg2";
8937 return "DW_OP_breg3";
8939 return "DW_OP_breg4";
8941 return "DW_OP_breg5";
8943 return "DW_OP_breg6";
8945 return "DW_OP_breg7";
8947 return "DW_OP_breg8";
8949 return "DW_OP_breg9";
8951 return "DW_OP_breg10";
8953 return "DW_OP_breg11";
8955 return "DW_OP_breg12";
8957 return "DW_OP_breg13";
8959 return "DW_OP_breg14";
8961 return "DW_OP_breg15";
8963 return "DW_OP_breg16";
8965 return "DW_OP_breg17";
8967 return "DW_OP_breg18";
8969 return "DW_OP_breg19";
8971 return "DW_OP_breg20";
8973 return "DW_OP_breg21";
8975 return "DW_OP_breg22";
8977 return "DW_OP_breg23";
8979 return "DW_OP_breg24";
8981 return "DW_OP_breg25";
8983 return "DW_OP_breg26";
8985 return "DW_OP_breg27";
8987 return "DW_OP_breg28";
8989 return "DW_OP_breg29";
8991 return "DW_OP_breg30";
8993 return "DW_OP_breg31";
8995 return "DW_OP_regx";
8997 return "DW_OP_fbreg";
8999 return "DW_OP_bregx";
9001 return "DW_OP_piece";
9002 case DW_OP_deref_size
:
9003 return "DW_OP_deref_size";
9004 case DW_OP_xderef_size
:
9005 return "DW_OP_xderef_size";
9008 /* DWARF 3 extensions. */
9009 case DW_OP_push_object_address
:
9010 return "DW_OP_push_object_address";
9012 return "DW_OP_call2";
9014 return "DW_OP_call4";
9015 case DW_OP_call_ref
:
9016 return "DW_OP_call_ref";
9017 /* GNU extensions. */
9018 case DW_OP_form_tls_address
:
9019 return "DW_OP_form_tls_address";
9020 case DW_OP_call_frame_cfa
:
9021 return "DW_OP_call_frame_cfa";
9022 case DW_OP_bit_piece
:
9023 return "DW_OP_bit_piece";
9024 case DW_OP_GNU_push_tls_address
:
9025 return "DW_OP_GNU_push_tls_address";
9026 case DW_OP_GNU_uninit
:
9027 return "DW_OP_GNU_uninit";
9028 /* HP extensions. */
9029 case DW_OP_HP_is_value
:
9030 return "DW_OP_HP_is_value";
9031 case DW_OP_HP_fltconst4
:
9032 return "DW_OP_HP_fltconst4";
9033 case DW_OP_HP_fltconst8
:
9034 return "DW_OP_HP_fltconst8";
9035 case DW_OP_HP_mod_range
:
9036 return "DW_OP_HP_mod_range";
9037 case DW_OP_HP_unmod_range
:
9038 return "DW_OP_HP_unmod_range";
9040 return "DW_OP_HP_tls";
9042 return "OP_<unknown>";
9047 dwarf_bool_name (unsigned mybool
)
9055 /* Convert a DWARF type code into its string name. */
9058 dwarf_type_encoding_name (unsigned enc
)
9063 return "DW_ATE_void";
9064 case DW_ATE_address
:
9065 return "DW_ATE_address";
9066 case DW_ATE_boolean
:
9067 return "DW_ATE_boolean";
9068 case DW_ATE_complex_float
:
9069 return "DW_ATE_complex_float";
9071 return "DW_ATE_float";
9073 return "DW_ATE_signed";
9074 case DW_ATE_signed_char
:
9075 return "DW_ATE_signed_char";
9076 case DW_ATE_unsigned
:
9077 return "DW_ATE_unsigned";
9078 case DW_ATE_unsigned_char
:
9079 return "DW_ATE_unsigned_char";
9081 case DW_ATE_imaginary_float
:
9082 return "DW_ATE_imaginary_float";
9083 case DW_ATE_packed_decimal
:
9084 return "DW_ATE_packed_decimal";
9085 case DW_ATE_numeric_string
:
9086 return "DW_ATE_numeric_string";
9088 return "DW_ATE_edited";
9089 case DW_ATE_signed_fixed
:
9090 return "DW_ATE_signed_fixed";
9091 case DW_ATE_unsigned_fixed
:
9092 return "DW_ATE_unsigned_fixed";
9093 case DW_ATE_decimal_float
:
9094 return "DW_ATE_decimal_float";
9095 /* HP extensions. */
9096 case DW_ATE_HP_float80
:
9097 return "DW_ATE_HP_float80";
9098 case DW_ATE_HP_complex_float80
:
9099 return "DW_ATE_HP_complex_float80";
9100 case DW_ATE_HP_float128
:
9101 return "DW_ATE_HP_float128";
9102 case DW_ATE_HP_complex_float128
:
9103 return "DW_ATE_HP_complex_float128";
9104 case DW_ATE_HP_floathpintel
:
9105 return "DW_ATE_HP_floathpintel";
9106 case DW_ATE_HP_imaginary_float80
:
9107 return "DW_ATE_HP_imaginary_float80";
9108 case DW_ATE_HP_imaginary_float128
:
9109 return "DW_ATE_HP_imaginary_float128";
9111 return "DW_ATE_<unknown>";
9115 /* Convert a DWARF call frame info operation to its string name. */
9119 dwarf_cfi_name (unsigned cfi_opc
)
9123 case DW_CFA_advance_loc
:
9124 return "DW_CFA_advance_loc";
9126 return "DW_CFA_offset";
9127 case DW_CFA_restore
:
9128 return "DW_CFA_restore";
9130 return "DW_CFA_nop";
9131 case DW_CFA_set_loc
:
9132 return "DW_CFA_set_loc";
9133 case DW_CFA_advance_loc1
:
9134 return "DW_CFA_advance_loc1";
9135 case DW_CFA_advance_loc2
:
9136 return "DW_CFA_advance_loc2";
9137 case DW_CFA_advance_loc4
:
9138 return "DW_CFA_advance_loc4";
9139 case DW_CFA_offset_extended
:
9140 return "DW_CFA_offset_extended";
9141 case DW_CFA_restore_extended
:
9142 return "DW_CFA_restore_extended";
9143 case DW_CFA_undefined
:
9144 return "DW_CFA_undefined";
9145 case DW_CFA_same_value
:
9146 return "DW_CFA_same_value";
9147 case DW_CFA_register
:
9148 return "DW_CFA_register";
9149 case DW_CFA_remember_state
:
9150 return "DW_CFA_remember_state";
9151 case DW_CFA_restore_state
:
9152 return "DW_CFA_restore_state";
9153 case DW_CFA_def_cfa
:
9154 return "DW_CFA_def_cfa";
9155 case DW_CFA_def_cfa_register
:
9156 return "DW_CFA_def_cfa_register";
9157 case DW_CFA_def_cfa_offset
:
9158 return "DW_CFA_def_cfa_offset";
9160 case DW_CFA_def_cfa_expression
:
9161 return "DW_CFA_def_cfa_expression";
9162 case DW_CFA_expression
:
9163 return "DW_CFA_expression";
9164 case DW_CFA_offset_extended_sf
:
9165 return "DW_CFA_offset_extended_sf";
9166 case DW_CFA_def_cfa_sf
:
9167 return "DW_CFA_def_cfa_sf";
9168 case DW_CFA_def_cfa_offset_sf
:
9169 return "DW_CFA_def_cfa_offset_sf";
9170 case DW_CFA_val_offset
:
9171 return "DW_CFA_val_offset";
9172 case DW_CFA_val_offset_sf
:
9173 return "DW_CFA_val_offset_sf";
9174 case DW_CFA_val_expression
:
9175 return "DW_CFA_val_expression";
9176 /* SGI/MIPS specific. */
9177 case DW_CFA_MIPS_advance_loc8
:
9178 return "DW_CFA_MIPS_advance_loc8";
9179 /* GNU extensions. */
9180 case DW_CFA_GNU_window_save
:
9181 return "DW_CFA_GNU_window_save";
9182 case DW_CFA_GNU_args_size
:
9183 return "DW_CFA_GNU_args_size";
9184 case DW_CFA_GNU_negative_offset_extended
:
9185 return "DW_CFA_GNU_negative_offset_extended";
9187 return "DW_CFA_<unknown>";
9193 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9197 print_spaces (indent
, f
);
9198 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9199 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9201 if (die
->parent
!= NULL
)
9203 print_spaces (indent
, f
);
9204 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9205 die
->parent
->offset
);
9208 print_spaces (indent
, f
);
9209 fprintf_unfiltered (f
, " has children: %s\n",
9210 dwarf_bool_name (die
->child
!= NULL
));
9212 print_spaces (indent
, f
);
9213 fprintf_unfiltered (f
, " attributes:\n");
9215 for (i
= 0; i
< die
->num_attrs
; ++i
)
9217 print_spaces (indent
, f
);
9218 fprintf_unfiltered (f
, " %s (%s) ",
9219 dwarf_attr_name (die
->attrs
[i
].name
),
9220 dwarf_form_name (die
->attrs
[i
].form
));
9222 switch (die
->attrs
[i
].form
)
9224 case DW_FORM_ref_addr
:
9226 fprintf_unfiltered (f
, "address: ");
9227 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9229 case DW_FORM_block2
:
9230 case DW_FORM_block4
:
9232 case DW_FORM_block1
:
9233 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9238 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9239 (long) (DW_ADDR (&die
->attrs
[i
])));
9247 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9249 case DW_FORM_string
:
9251 fprintf_unfiltered (f
, "string: \"%s\"",
9252 DW_STRING (&die
->attrs
[i
])
9253 ? DW_STRING (&die
->attrs
[i
]) : "");
9256 if (DW_UNSND (&die
->attrs
[i
]))
9257 fprintf_unfiltered (f
, "flag: TRUE");
9259 fprintf_unfiltered (f
, "flag: FALSE");
9261 case DW_FORM_indirect
:
9262 /* the reader will have reduced the indirect form to
9263 the "base form" so this form should not occur */
9264 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9267 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9268 die
->attrs
[i
].form
);
9271 fprintf_unfiltered (f
, "\n");
9276 dump_die_for_error (struct die_info
*die
)
9278 dump_die_shallow (gdb_stderr
, 0, die
);
9282 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9284 int indent
= level
* 4;
9286 gdb_assert (die
!= NULL
);
9288 if (level
>= max_level
)
9291 dump_die_shallow (f
, indent
, die
);
9293 if (die
->child
!= NULL
)
9295 print_spaces (indent
, f
);
9296 fprintf_unfiltered (f
, " Children:");
9297 if (level
+ 1 < max_level
)
9299 fprintf_unfiltered (f
, "\n");
9300 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9304 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9308 if (die
->sibling
!= NULL
&& level
> 0)
9310 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9314 /* This is called from the pdie macro in gdbinit.in.
9315 It's not static so gcc will keep a copy callable from gdb. */
9318 dump_die (struct die_info
*die
, int max_level
)
9320 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9324 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9328 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9334 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9336 unsigned int result
= 0;
9340 case DW_FORM_ref_addr
:
9345 case DW_FORM_ref_udata
:
9346 result
= DW_ADDR (attr
);
9349 complaint (&symfile_complaints
,
9350 _("unsupported die ref attribute form: '%s'"),
9351 dwarf_form_name (attr
->form
));
9356 /* Return the constant value held by the given attribute. Return -1
9357 if the value held by the attribute is not constant. */
9360 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9362 if (attr
->form
== DW_FORM_sdata
)
9363 return DW_SND (attr
);
9364 else if (attr
->form
== DW_FORM_udata
9365 || attr
->form
== DW_FORM_data1
9366 || attr
->form
== DW_FORM_data2
9367 || attr
->form
== DW_FORM_data4
9368 || attr
->form
== DW_FORM_data8
)
9369 return DW_UNSND (attr
);
9372 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9373 dwarf_form_name (attr
->form
));
9374 return default_value
;
9378 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9379 unit and add it to our queue. */
9382 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9383 struct dwarf2_per_cu_data
*per_cu
)
9385 /* Mark the dependence relation so that we don't flush PER_CU
9387 dwarf2_add_dependence (this_cu
, per_cu
);
9389 /* If it's already on the queue, we have nothing to do. */
9393 /* If the compilation unit is already loaded, just mark it as
9395 if (per_cu
->cu
!= NULL
)
9397 per_cu
->cu
->last_used
= 0;
9401 /* Add it to the queue. */
9402 queue_comp_unit (per_cu
, this_cu
->objfile
);
9405 static struct die_info
*
9406 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9407 struct dwarf2_cu
**ref_cu
)
9409 struct die_info
*die
;
9410 unsigned int offset
;
9411 struct die_info temp_die
;
9412 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9414 offset
= dwarf2_get_ref_die_offset (attr
);
9416 if (! offset_in_cu_p (&cu
->header
, offset
))
9418 struct dwarf2_per_cu_data
*per_cu
;
9419 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9421 /* If necessary, add it to the queue and load its DIEs. */
9422 maybe_queue_comp_unit (cu
, per_cu
);
9424 target_cu
= per_cu
->cu
;
9429 *ref_cu
= target_cu
;
9430 temp_die
.offset
= offset
;
9431 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9435 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9436 "at 0x%lx [in module %s]"),
9437 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9440 /* Decode simple location descriptions.
9441 Given a pointer to a dwarf block that defines a location, compute
9442 the location and return the value.
9444 NOTE drow/2003-11-18: This function is called in two situations
9445 now: for the address of static or global variables (partial symbols
9446 only) and for offsets into structures which are expected to be
9447 (more or less) constant. The partial symbol case should go away,
9448 and only the constant case should remain. That will let this
9449 function complain more accurately. A few special modes are allowed
9450 without complaint for global variables (for instance, global
9451 register values and thread-local values).
9453 A location description containing no operations indicates that the
9454 object is optimized out. The return value is 0 for that case.
9455 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9456 callers will only want a very basic result and this can become a
9459 Note that stack[0] is unused except as a default error return.
9460 Note that stack overflow is not yet handled. */
9463 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9465 struct objfile
*objfile
= cu
->objfile
;
9466 struct comp_unit_head
*cu_header
= &cu
->header
;
9468 int size
= blk
->size
;
9469 gdb_byte
*data
= blk
->data
;
9470 CORE_ADDR stack
[64];
9472 unsigned int bytes_read
, unsnd
;
9516 stack
[++stacki
] = op
- DW_OP_lit0
;
9551 stack
[++stacki
] = op
- DW_OP_reg0
;
9553 dwarf2_complex_location_expr_complaint ();
9557 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9559 stack
[++stacki
] = unsnd
;
9561 dwarf2_complex_location_expr_complaint ();
9565 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9571 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9576 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9581 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9586 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9591 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9596 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9601 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9607 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9612 stack
[stacki
+ 1] = stack
[stacki
];
9617 stack
[stacki
- 1] += stack
[stacki
];
9621 case DW_OP_plus_uconst
:
9622 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9627 stack
[stacki
- 1] -= stack
[stacki
];
9632 /* If we're not the last op, then we definitely can't encode
9633 this using GDB's address_class enum. This is valid for partial
9634 global symbols, although the variable's address will be bogus
9637 dwarf2_complex_location_expr_complaint ();
9640 case DW_OP_GNU_push_tls_address
:
9641 /* The top of the stack has the offset from the beginning
9642 of the thread control block at which the variable is located. */
9643 /* Nothing should follow this operator, so the top of stack would
9645 /* This is valid for partial global symbols, but the variable's
9646 address will be bogus in the psymtab. */
9648 dwarf2_complex_location_expr_complaint ();
9651 case DW_OP_GNU_uninit
:
9655 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9656 dwarf_stack_op_name (op
));
9657 return (stack
[stacki
]);
9660 return (stack
[stacki
]);
9663 /* memory allocation interface */
9665 static struct dwarf_block
*
9666 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9668 struct dwarf_block
*blk
;
9670 blk
= (struct dwarf_block
*)
9671 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9675 static struct abbrev_info
*
9676 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9678 struct abbrev_info
*abbrev
;
9680 abbrev
= (struct abbrev_info
*)
9681 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9682 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9686 static struct die_info
*
9687 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9689 struct die_info
*die
;
9690 size_t size
= sizeof (struct die_info
);
9693 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9695 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9696 memset (die
, 0, sizeof (struct die_info
));
9701 /* Macro support. */
9704 /* Return the full name of file number I in *LH's file name table.
9705 Use COMP_DIR as the name of the current directory of the
9706 compilation. The result is allocated using xmalloc; the caller is
9707 responsible for freeing it. */
9709 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9711 /* Is the file number a valid index into the line header's file name
9712 table? Remember that file numbers start with one, not zero. */
9713 if (1 <= file
&& file
<= lh
->num_file_names
)
9715 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9717 if (IS_ABSOLUTE_PATH (fe
->name
))
9718 return xstrdup (fe
->name
);
9726 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9732 dir_len
= strlen (dir
);
9733 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9734 strcpy (full_name
, dir
);
9735 full_name
[dir_len
] = '/';
9736 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9740 return xstrdup (fe
->name
);
9745 /* The compiler produced a bogus file number. We can at least
9746 record the macro definitions made in the file, even if we
9747 won't be able to find the file by name. */
9749 sprintf (fake_name
, "<bad macro file number %d>", file
);
9751 complaint (&symfile_complaints
,
9752 _("bad file number in macro information (%d)"),
9755 return xstrdup (fake_name
);
9760 static struct macro_source_file
*
9761 macro_start_file (int file
, int line
,
9762 struct macro_source_file
*current_file
,
9763 const char *comp_dir
,
9764 struct line_header
*lh
, struct objfile
*objfile
)
9766 /* The full name of this source file. */
9767 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9769 /* We don't create a macro table for this compilation unit
9770 at all until we actually get a filename. */
9771 if (! pending_macros
)
9772 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9773 objfile
->macro_cache
);
9776 /* If we have no current file, then this must be the start_file
9777 directive for the compilation unit's main source file. */
9778 current_file
= macro_set_main (pending_macros
, full_name
);
9780 current_file
= macro_include (current_file
, line
, full_name
);
9784 return current_file
;
9788 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9789 followed by a null byte. */
9791 copy_string (const char *buf
, int len
)
9793 char *s
= xmalloc (len
+ 1);
9794 memcpy (s
, buf
, len
);
9802 consume_improper_spaces (const char *p
, const char *body
)
9806 complaint (&symfile_complaints
,
9807 _("macro definition contains spaces in formal argument list:\n`%s'"),
9819 parse_macro_definition (struct macro_source_file
*file
, int line
,
9824 /* The body string takes one of two forms. For object-like macro
9825 definitions, it should be:
9827 <macro name> " " <definition>
9829 For function-like macro definitions, it should be:
9831 <macro name> "() " <definition>
9833 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9835 Spaces may appear only where explicitly indicated, and in the
9838 The Dwarf 2 spec says that an object-like macro's name is always
9839 followed by a space, but versions of GCC around March 2002 omit
9840 the space when the macro's definition is the empty string.
9842 The Dwarf 2 spec says that there should be no spaces between the
9843 formal arguments in a function-like macro's formal argument list,
9844 but versions of GCC around March 2002 include spaces after the
9848 /* Find the extent of the macro name. The macro name is terminated
9849 by either a space or null character (for an object-like macro) or
9850 an opening paren (for a function-like macro). */
9851 for (p
= body
; *p
; p
++)
9852 if (*p
== ' ' || *p
== '(')
9855 if (*p
== ' ' || *p
== '\0')
9857 /* It's an object-like macro. */
9858 int name_len
= p
- body
;
9859 char *name
= copy_string (body
, name_len
);
9860 const char *replacement
;
9863 replacement
= body
+ name_len
+ 1;
9866 dwarf2_macro_malformed_definition_complaint (body
);
9867 replacement
= body
+ name_len
;
9870 macro_define_object (file
, line
, name
, replacement
);
9876 /* It's a function-like macro. */
9877 char *name
= copy_string (body
, p
- body
);
9880 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9884 p
= consume_improper_spaces (p
, body
);
9886 /* Parse the formal argument list. */
9887 while (*p
&& *p
!= ')')
9889 /* Find the extent of the current argument name. */
9890 const char *arg_start
= p
;
9892 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9895 if (! *p
|| p
== arg_start
)
9896 dwarf2_macro_malformed_definition_complaint (body
);
9899 /* Make sure argv has room for the new argument. */
9900 if (argc
>= argv_size
)
9903 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9906 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9909 p
= consume_improper_spaces (p
, body
);
9911 /* Consume the comma, if present. */
9916 p
= consume_improper_spaces (p
, body
);
9925 /* Perfectly formed definition, no complaints. */
9926 macro_define_function (file
, line
, name
,
9927 argc
, (const char **) argv
,
9929 else if (*p
== '\0')
9931 /* Complain, but do define it. */
9932 dwarf2_macro_malformed_definition_complaint (body
);
9933 macro_define_function (file
, line
, name
,
9934 argc
, (const char **) argv
,
9938 /* Just complain. */
9939 dwarf2_macro_malformed_definition_complaint (body
);
9942 /* Just complain. */
9943 dwarf2_macro_malformed_definition_complaint (body
);
9949 for (i
= 0; i
< argc
; i
++)
9955 dwarf2_macro_malformed_definition_complaint (body
);
9960 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9961 char *comp_dir
, bfd
*abfd
,
9962 struct dwarf2_cu
*cu
)
9964 gdb_byte
*mac_ptr
, *mac_end
;
9965 struct macro_source_file
*current_file
= 0;
9966 enum dwarf_macinfo_record_type macinfo_type
;
9969 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9971 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9975 /* First pass: Find the name of the base filename.
9976 This filename is needed in order to process all macros whose definition
9977 (or undefinition) comes from the command line. These macros are defined
9978 before the first DW_MACINFO_start_file entry, and yet still need to be
9979 associated to the base file.
9981 To determine the base file name, we scan the macro definitions until we
9982 reach the first DW_MACINFO_start_file entry. We then initialize
9983 CURRENT_FILE accordingly so that any macro definition found before the
9984 first DW_MACINFO_start_file can still be associated to the base file. */
9986 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9987 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9988 + dwarf2_per_objfile
->macinfo_size
;
9992 /* Do we at least have room for a macinfo type byte? */
9993 if (mac_ptr
>= mac_end
)
9995 /* Complaint is printed during the second pass as GDB will probably
9996 stop the first pass earlier upon finding DW_MACINFO_start_file. */
10000 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10003 switch (macinfo_type
)
10005 /* A zero macinfo type indicates the end of the macro
10010 case DW_MACINFO_define
:
10011 case DW_MACINFO_undef
:
10012 /* Only skip the data by MAC_PTR. */
10014 unsigned int bytes_read
;
10016 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10017 mac_ptr
+= bytes_read
;
10018 read_string (abfd
, mac_ptr
, &bytes_read
);
10019 mac_ptr
+= bytes_read
;
10023 case DW_MACINFO_start_file
:
10025 unsigned int bytes_read
;
10028 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10029 mac_ptr
+= bytes_read
;
10030 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10031 mac_ptr
+= bytes_read
;
10033 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
10038 case DW_MACINFO_end_file
:
10039 /* No data to skip by MAC_PTR. */
10042 case DW_MACINFO_vendor_ext
:
10043 /* Only skip the data by MAC_PTR. */
10045 unsigned int bytes_read
;
10047 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10048 mac_ptr
+= bytes_read
;
10049 read_string (abfd
, mac_ptr
, &bytes_read
);
10050 mac_ptr
+= bytes_read
;
10057 } while (macinfo_type
!= 0 && current_file
== NULL
);
10059 /* Second pass: Process all entries.
10061 Use the AT_COMMAND_LINE flag to determine whether we are still processing
10062 command-line macro definitions/undefinitions. This flag is unset when we
10063 reach the first DW_MACINFO_start_file entry. */
10065 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
10067 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
10068 GDB is still reading the definitions from command line. First
10069 DW_MACINFO_start_file will need to be ignored as it was already executed
10070 to create CURRENT_FILE for the main source holding also the command line
10071 definitions. On first met DW_MACINFO_start_file this flag is reset to
10072 normally execute all the remaining DW_MACINFO_start_file macinfos. */
10074 at_commandline
= 1;
10078 /* Do we at least have room for a macinfo type byte? */
10079 if (mac_ptr
>= mac_end
)
10081 dwarf2_macros_too_long_complaint ();
10085 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10088 switch (macinfo_type
)
10090 /* A zero macinfo type indicates the end of the macro
10095 case DW_MACINFO_define
:
10096 case DW_MACINFO_undef
:
10098 unsigned int bytes_read
;
10102 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10103 mac_ptr
+= bytes_read
;
10104 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
10105 mac_ptr
+= bytes_read
;
10107 if (! current_file
)
10109 /* DWARF violation as no main source is present. */
10110 complaint (&symfile_complaints
,
10111 _("debug info with no main source gives macro %s "
10114 DW_MACINFO_define
? _("definition") : macinfo_type
==
10115 DW_MACINFO_undef
? _("undefinition") :
10116 "something-or-other", line
, body
);
10119 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10120 complaint (&symfile_complaints
,
10121 _("debug info gives %s macro %s with %s line %d: %s"),
10122 at_commandline
? _("command-line") : _("in-file"),
10124 DW_MACINFO_define
? _("definition") : macinfo_type
==
10125 DW_MACINFO_undef
? _("undefinition") :
10126 "something-or-other",
10127 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
10129 if (macinfo_type
== DW_MACINFO_define
)
10130 parse_macro_definition (current_file
, line
, body
);
10131 else if (macinfo_type
== DW_MACINFO_undef
)
10132 macro_undef (current_file
, line
, body
);
10136 case DW_MACINFO_start_file
:
10138 unsigned int bytes_read
;
10141 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10142 mac_ptr
+= bytes_read
;
10143 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10144 mac_ptr
+= bytes_read
;
10146 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10147 complaint (&symfile_complaints
,
10148 _("debug info gives source %d included "
10149 "from %s at %s line %d"),
10150 file
, at_commandline
? _("command-line") : _("file"),
10151 line
== 0 ? _("zero") : _("non-zero"), line
);
10153 if (at_commandline
)
10155 /* This DW_MACINFO_start_file was executed in the pass one. */
10156 at_commandline
= 0;
10159 current_file
= macro_start_file (file
, line
,
10160 current_file
, comp_dir
,
10165 case DW_MACINFO_end_file
:
10166 if (! current_file
)
10167 complaint (&symfile_complaints
,
10168 _("macro debug info has an unmatched `close_file' directive"));
10171 current_file
= current_file
->included_by
;
10172 if (! current_file
)
10174 enum dwarf_macinfo_record_type next_type
;
10176 /* GCC circa March 2002 doesn't produce the zero
10177 type byte marking the end of the compilation
10178 unit. Complain if it's not there, but exit no
10181 /* Do we at least have room for a macinfo type byte? */
10182 if (mac_ptr
>= mac_end
)
10184 dwarf2_macros_too_long_complaint ();
10188 /* We don't increment mac_ptr here, so this is just
10190 next_type
= read_1_byte (abfd
, mac_ptr
);
10191 if (next_type
!= 0)
10192 complaint (&symfile_complaints
,
10193 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10200 case DW_MACINFO_vendor_ext
:
10202 unsigned int bytes_read
;
10206 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10207 mac_ptr
+= bytes_read
;
10208 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10209 mac_ptr
+= bytes_read
;
10211 /* We don't recognize any vendor extensions. */
10215 } while (macinfo_type
!= 0);
10218 /* Check if the attribute's form is a DW_FORM_block*
10219 if so return true else false. */
10221 attr_form_is_block (struct attribute
*attr
)
10223 return (attr
== NULL
? 0 :
10224 attr
->form
== DW_FORM_block1
10225 || attr
->form
== DW_FORM_block2
10226 || attr
->form
== DW_FORM_block4
10227 || attr
->form
== DW_FORM_block
);
10230 /* Return non-zero if ATTR's value is a section offset --- classes
10231 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10232 You may use DW_UNSND (attr) to retrieve such offsets.
10234 Section 7.5.4, "Attribute Encodings", explains that no attribute
10235 may have a value that belongs to more than one of these classes; it
10236 would be ambiguous if we did, because we use the same forms for all
10239 attr_form_is_section_offset (struct attribute
*attr
)
10241 return (attr
->form
== DW_FORM_data4
10242 || attr
->form
== DW_FORM_data8
);
10246 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10247 zero otherwise. When this function returns true, you can apply
10248 dwarf2_get_attr_constant_value to it.
10250 However, note that for some attributes you must check
10251 attr_form_is_section_offset before using this test. DW_FORM_data4
10252 and DW_FORM_data8 are members of both the constant class, and of
10253 the classes that contain offsets into other debug sections
10254 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10255 that, if an attribute's can be either a constant or one of the
10256 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10257 taken as section offsets, not constants. */
10259 attr_form_is_constant (struct attribute
*attr
)
10261 switch (attr
->form
)
10263 case DW_FORM_sdata
:
10264 case DW_FORM_udata
:
10265 case DW_FORM_data1
:
10266 case DW_FORM_data2
:
10267 case DW_FORM_data4
:
10268 case DW_FORM_data8
:
10276 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10277 struct dwarf2_cu
*cu
)
10279 if (attr_form_is_section_offset (attr
)
10280 /* ".debug_loc" may not exist at all, or the offset may be outside
10281 the section. If so, fall through to the complaint in the
10283 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10285 struct dwarf2_loclist_baton
*baton
;
10287 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10288 sizeof (struct dwarf2_loclist_baton
));
10289 baton
->per_cu
= cu
->per_cu
;
10290 gdb_assert (baton
->per_cu
);
10292 /* We don't know how long the location list is, but make sure we
10293 don't run off the edge of the section. */
10294 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10295 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10296 baton
->base_address
= cu
->base_address
;
10297 if (cu
->base_known
== 0)
10298 complaint (&symfile_complaints
,
10299 _("Location list used without specifying the CU base address."));
10301 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10302 SYMBOL_LOCATION_BATON (sym
) = baton
;
10306 struct dwarf2_locexpr_baton
*baton
;
10308 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10309 sizeof (struct dwarf2_locexpr_baton
));
10310 baton
->per_cu
= cu
->per_cu
;
10311 gdb_assert (baton
->per_cu
);
10313 if (attr_form_is_block (attr
))
10315 /* Note that we're just copying the block's data pointer
10316 here, not the actual data. We're still pointing into the
10317 info_buffer for SYM's objfile; right now we never release
10318 that buffer, but when we do clean up properly this may
10320 baton
->size
= DW_BLOCK (attr
)->size
;
10321 baton
->data
= DW_BLOCK (attr
)->data
;
10325 dwarf2_invalid_attrib_class_complaint ("location description",
10326 SYMBOL_NATURAL_NAME (sym
));
10328 baton
->data
= NULL
;
10331 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10332 SYMBOL_LOCATION_BATON (sym
) = baton
;
10336 /* Return the OBJFILE associated with the compilation unit CU. */
10339 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10341 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10343 /* Return the master objfile, so that we can report and look up the
10344 correct file containing this variable. */
10345 if (objfile
->separate_debug_objfile_backlink
)
10346 objfile
= objfile
->separate_debug_objfile_backlink
;
10351 /* Return the address size given in the compilation unit header for CU. */
10354 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10357 return per_cu
->cu
->header
.addr_size
;
10360 /* If the CU is not currently read in, we re-read its header. */
10361 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10362 struct dwarf2_per_objfile
*per_objfile
10363 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10364 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10366 struct comp_unit_head cu_header
;
10367 memset (&cu_header
, 0, sizeof cu_header
);
10368 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10369 return cu_header
.addr_size
;
10373 /* Locate the compilation unit from CU's objfile which contains the
10374 DIE at OFFSET. Raises an error on failure. */
10376 static struct dwarf2_per_cu_data
*
10377 dwarf2_find_containing_comp_unit (unsigned int offset
,
10378 struct objfile
*objfile
)
10380 struct dwarf2_per_cu_data
*this_cu
;
10384 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10387 int mid
= low
+ (high
- low
) / 2;
10388 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10393 gdb_assert (low
== high
);
10394 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10397 error (_("Dwarf Error: could not find partial DIE containing "
10398 "offset 0x%lx [in module %s]"),
10399 (long) offset
, bfd_get_filename (objfile
->obfd
));
10401 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10402 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10406 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10407 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10408 && offset
>= this_cu
->offset
+ this_cu
->length
)
10409 error (_("invalid dwarf2 offset %u"), offset
);
10410 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10415 /* Locate the compilation unit from OBJFILE which is located at exactly
10416 OFFSET. Raises an error on failure. */
10418 static struct dwarf2_per_cu_data
*
10419 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10421 struct dwarf2_per_cu_data
*this_cu
;
10422 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10423 if (this_cu
->offset
!= offset
)
10424 error (_("no compilation unit with offset %u."), offset
);
10428 /* Release one cached compilation unit, CU. We unlink it from the tree
10429 of compilation units, but we don't remove it from the read_in_chain;
10430 the caller is responsible for that. */
10433 free_one_comp_unit (void *data
)
10435 struct dwarf2_cu
*cu
= data
;
10437 if (cu
->per_cu
!= NULL
)
10438 cu
->per_cu
->cu
= NULL
;
10441 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10446 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10447 when we're finished with it. We can't free the pointer itself, but be
10448 sure to unlink it from the cache. Also release any associated storage
10449 and perform cache maintenance.
10451 Only used during partial symbol parsing. */
10454 free_stack_comp_unit (void *data
)
10456 struct dwarf2_cu
*cu
= data
;
10458 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10459 cu
->partial_dies
= NULL
;
10461 if (cu
->per_cu
!= NULL
)
10463 /* This compilation unit is on the stack in our caller, so we
10464 should not xfree it. Just unlink it. */
10465 cu
->per_cu
->cu
= NULL
;
10468 /* If we had a per-cu pointer, then we may have other compilation
10469 units loaded, so age them now. */
10470 age_cached_comp_units ();
10474 /* Free all cached compilation units. */
10477 free_cached_comp_units (void *data
)
10479 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10481 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10482 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10483 while (per_cu
!= NULL
)
10485 struct dwarf2_per_cu_data
*next_cu
;
10487 next_cu
= per_cu
->cu
->read_in_chain
;
10489 free_one_comp_unit (per_cu
->cu
);
10490 *last_chain
= next_cu
;
10496 /* Increase the age counter on each cached compilation unit, and free
10497 any that are too old. */
10500 age_cached_comp_units (void)
10502 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10504 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10505 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10506 while (per_cu
!= NULL
)
10508 per_cu
->cu
->last_used
++;
10509 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10510 dwarf2_mark (per_cu
->cu
);
10511 per_cu
= per_cu
->cu
->read_in_chain
;
10514 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10515 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10516 while (per_cu
!= NULL
)
10518 struct dwarf2_per_cu_data
*next_cu
;
10520 next_cu
= per_cu
->cu
->read_in_chain
;
10522 if (!per_cu
->cu
->mark
)
10524 free_one_comp_unit (per_cu
->cu
);
10525 *last_chain
= next_cu
;
10528 last_chain
= &per_cu
->cu
->read_in_chain
;
10534 /* Remove a single compilation unit from the cache. */
10537 free_one_cached_comp_unit (void *target_cu
)
10539 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10541 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10542 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10543 while (per_cu
!= NULL
)
10545 struct dwarf2_per_cu_data
*next_cu
;
10547 next_cu
= per_cu
->cu
->read_in_chain
;
10549 if (per_cu
->cu
== target_cu
)
10551 free_one_comp_unit (per_cu
->cu
);
10552 *last_chain
= next_cu
;
10556 last_chain
= &per_cu
->cu
->read_in_chain
;
10562 /* Release all extra memory associated with OBJFILE. */
10565 dwarf2_free_objfile (struct objfile
*objfile
)
10567 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10569 if (dwarf2_per_objfile
== NULL
)
10572 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10573 free_cached_comp_units (NULL
);
10575 /* Everything else should be on the objfile obstack. */
10578 /* A pair of DIE offset and GDB type pointer. We store these
10579 in a hash table separate from the DIEs, and preserve them
10580 when the DIEs are flushed out of cache. */
10582 struct dwarf2_offset_and_type
10584 unsigned int offset
;
10588 /* Hash function for a dwarf2_offset_and_type. */
10591 offset_and_type_hash (const void *item
)
10593 const struct dwarf2_offset_and_type
*ofs
= item
;
10594 return ofs
->offset
;
10597 /* Equality function for a dwarf2_offset_and_type. */
10600 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10602 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10603 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10604 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10607 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10608 table if necessary. For convenience, return TYPE. */
10610 static struct type
*
10611 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10613 struct dwarf2_offset_and_type
**slot
, ofs
;
10615 if (cu
->type_hash
== NULL
)
10617 gdb_assert (cu
->per_cu
!= NULL
);
10618 cu
->per_cu
->type_hash
10619 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10620 offset_and_type_hash
,
10621 offset_and_type_eq
,
10623 &cu
->objfile
->objfile_obstack
,
10624 hashtab_obstack_allocate
,
10625 dummy_obstack_deallocate
);
10626 cu
->type_hash
= cu
->per_cu
->type_hash
;
10629 ofs
.offset
= die
->offset
;
10631 slot
= (struct dwarf2_offset_and_type
**)
10632 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10633 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10638 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10639 not have a saved type. */
10641 static struct type
*
10642 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10644 struct dwarf2_offset_and_type
*slot
, ofs
;
10645 htab_t type_hash
= cu
->type_hash
;
10647 if (type_hash
== NULL
)
10650 ofs
.offset
= die
->offset
;
10651 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10658 /* Set the mark field in CU and in every other compilation unit in the
10659 cache that we must keep because we are keeping CU. */
10661 /* Add a dependence relationship from CU to REF_PER_CU. */
10664 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10665 struct dwarf2_per_cu_data
*ref_per_cu
)
10669 if (cu
->dependencies
== NULL
)
10671 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10672 NULL
, &cu
->comp_unit_obstack
,
10673 hashtab_obstack_allocate
,
10674 dummy_obstack_deallocate
);
10676 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10678 *slot
= ref_per_cu
;
10681 /* Set the mark field in CU and in every other compilation unit in the
10682 cache that we must keep because we are keeping CU. */
10685 dwarf2_mark_helper (void **slot
, void *data
)
10687 struct dwarf2_per_cu_data
*per_cu
;
10689 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10690 if (per_cu
->cu
->mark
)
10692 per_cu
->cu
->mark
= 1;
10694 if (per_cu
->cu
->dependencies
!= NULL
)
10695 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10701 dwarf2_mark (struct dwarf2_cu
*cu
)
10706 if (cu
->dependencies
!= NULL
)
10707 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10711 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10715 per_cu
->cu
->mark
= 0;
10716 per_cu
= per_cu
->cu
->read_in_chain
;
10720 /* Trivial hash function for partial_die_info: the hash value of a DIE
10721 is its offset in .debug_info for this objfile. */
10724 partial_die_hash (const void *item
)
10726 const struct partial_die_info
*part_die
= item
;
10727 return part_die
->offset
;
10730 /* Trivial comparison function for partial_die_info structures: two DIEs
10731 are equal if they have the same offset. */
10734 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10736 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10737 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10738 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10741 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10742 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10745 set_dwarf2_cmd (char *args
, int from_tty
)
10747 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10751 show_dwarf2_cmd (char *args
, int from_tty
)
10753 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10756 void _initialize_dwarf2_read (void);
10759 _initialize_dwarf2_read (void)
10761 dwarf2_objfile_data_key
= register_objfile_data ();
10763 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10764 Set DWARF 2 specific variables.\n\
10765 Configure DWARF 2 variables such as the cache size"),
10766 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10767 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10769 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10770 Show DWARF 2 specific variables\n\
10771 Show DWARF 2 variables such as the cache size"),
10772 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10773 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10775 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10776 &dwarf2_max_cache_age
, _("\
10777 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10778 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10779 A higher limit means that cached compilation units will be stored\n\
10780 in memory longer, and more total memory will be used. Zero disables\n\
10781 caching, which can slow down startup."),
10783 show_dwarf2_max_cache_age
,
10784 &set_dwarf2_cmdlist
,
10785 &show_dwarf2_cmdlist
);
10787 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
10788 Set debugging of the dwarf2 DIE reader."), _("\
10789 Show debugging of the dwarf2 DIE reader."), _("\
10790 When enabled (non-zero), DIEs are dumped after they are read in.\n\
10791 The value is the maximum depth to print."),
10794 &setdebuglist
, &showdebuglist
);