1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
51 #include "gdb_string.h"
52 #include "gdb_assert.h"
53 #include <sys/types.h>
58 /* A note on memory usage for this file.
60 At the present time, this code reads the debug info sections into
61 the objfile's objfile_obstack. A definite improvement for startup
62 time, on platforms which do not emit relocations for debug
63 sections, would be to use mmap instead. The object's complete
64 debug information is loaded into memory, partly to simplify
65 absolute DIE references.
67 Whether using obstacks or mmap, the sections should remain loaded
68 until the objfile is released, and pointers into the section data
69 can be used for any other data associated to the objfile (symbol
70 names, type names, location expressions to name a few). */
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 static const struct objfile_data
*dwarf2_objfile_data_key
;
146 struct dwarf2_per_objfile
148 /* Sizes of debugging sections. */
149 unsigned int info_size
;
150 unsigned int abbrev_size
;
151 unsigned int line_size
;
152 unsigned int pubnames_size
;
153 unsigned int aranges_size
;
154 unsigned int loc_size
;
155 unsigned int macinfo_size
;
156 unsigned int str_size
;
157 unsigned int ranges_size
;
158 unsigned int frame_size
;
159 unsigned int eh_frame_size
;
161 /* Loaded data from the sections. */
162 gdb_byte
*info_buffer
;
163 gdb_byte
*abbrev_buffer
;
164 gdb_byte
*line_buffer
;
165 gdb_byte
*str_buffer
;
166 gdb_byte
*macinfo_buffer
;
167 gdb_byte
*ranges_buffer
;
168 gdb_byte
*loc_buffer
;
170 /* A list of all the compilation units. This is used to locate
171 the target compilation unit of a particular reference. */
172 struct dwarf2_per_cu_data
**all_comp_units
;
174 /* The number of compilation units in ALL_COMP_UNITS. */
177 /* A chain of compilation units that are currently read in, so that
178 they can be freed later. */
179 struct dwarf2_per_cu_data
*read_in_chain
;
181 /* A flag indicating wether this objfile has a section loaded at a
183 int has_section_at_zero
;
186 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
188 static asection
*dwarf_info_section
;
189 static asection
*dwarf_abbrev_section
;
190 static asection
*dwarf_line_section
;
191 static asection
*dwarf_pubnames_section
;
192 static asection
*dwarf_aranges_section
;
193 static asection
*dwarf_loc_section
;
194 static asection
*dwarf_macinfo_section
;
195 static asection
*dwarf_str_section
;
196 static asection
*dwarf_ranges_section
;
197 asection
*dwarf_frame_section
;
198 asection
*dwarf_eh_frame_section
;
200 /* names of the debugging sections */
202 /* Note that if the debugging section has been compressed, it might
203 have a name like .zdebug_info. */
205 #define INFO_SECTION "debug_info"
206 #define ABBREV_SECTION "debug_abbrev"
207 #define LINE_SECTION "debug_line"
208 #define PUBNAMES_SECTION "debug_pubnames"
209 #define ARANGES_SECTION "debug_aranges"
210 #define LOC_SECTION "debug_loc"
211 #define MACINFO_SECTION "debug_macinfo"
212 #define STR_SECTION "debug_str"
213 #define RANGES_SECTION "debug_ranges"
214 #define FRAME_SECTION "debug_frame"
215 #define EH_FRAME_SECTION "eh_frame"
217 /* local data types */
219 /* We hold several abbreviation tables in memory at the same time. */
220 #ifndef ABBREV_HASH_SIZE
221 #define ABBREV_HASH_SIZE 121
224 /* The data in a compilation unit header, after target2host
225 translation, looks like this. */
226 struct comp_unit_head
228 unsigned long length
;
230 unsigned int abbrev_offset
;
231 unsigned char addr_size
;
232 unsigned char signed_addr_p
;
234 /* Size of file offsets; either 4 or 8. */
235 unsigned int offset_size
;
237 /* Size of the length field; either 4 or 12. */
238 unsigned int initial_length_size
;
240 /* Offset to the first byte of this compilation unit header in the
241 .debug_info section, for resolving relative reference dies. */
244 /* Pointer to this compilation unit header in the .debug_info
246 gdb_byte
*cu_head_ptr
;
248 /* Pointer to the first die of this compilation unit. This will be
249 the first byte following the compilation unit header. */
250 gdb_byte
*first_die_ptr
;
252 /* Pointer to the next compilation unit header in the program. */
253 struct comp_unit_head
*next
;
255 /* Base address of this compilation unit. */
256 CORE_ADDR base_address
;
258 /* Non-zero if base_address has been set. */
262 /* Fixed size for the DIE hash table. */
263 #ifndef REF_HASH_SIZE
264 #define REF_HASH_SIZE 1021
267 /* Internal state when decoding a particular compilation unit. */
270 /* The objfile containing this compilation unit. */
271 struct objfile
*objfile
;
273 /* The header of the compilation unit.
275 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
276 should logically be moved to the dwarf2_cu structure. */
277 struct comp_unit_head header
;
279 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
281 /* The language we are debugging. */
282 enum language language
;
283 const struct language_defn
*language_defn
;
285 const char *producer
;
287 /* The generic symbol table building routines have separate lists for
288 file scope symbols and all all other scopes (local scopes). So
289 we need to select the right one to pass to add_symbol_to_list().
290 We do it by keeping a pointer to the correct list in list_in_scope.
292 FIXME: The original dwarf code just treated the file scope as the
293 first local scope, and all other local scopes as nested local
294 scopes, and worked fine. Check to see if we really need to
295 distinguish these in buildsym.c. */
296 struct pending
**list_in_scope
;
298 /* DWARF abbreviation table associated with this compilation unit. */
299 struct abbrev_info
**dwarf2_abbrevs
;
301 /* Storage for the abbrev table. */
302 struct obstack abbrev_obstack
;
304 /* Hash table holding all the loaded partial DIEs. */
307 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
308 unsigned long ranges_offset
;
310 /* Storage for things with the same lifetime as this read-in compilation
311 unit, including partial DIEs. */
312 struct obstack comp_unit_obstack
;
314 /* When multiple dwarf2_cu structures are living in memory, this field
315 chains them all together, so that they can be released efficiently.
316 We will probably also want a generation counter so that most-recently-used
317 compilation units are cached... */
318 struct dwarf2_per_cu_data
*read_in_chain
;
320 /* Backchain to our per_cu entry if the tree has been built. */
321 struct dwarf2_per_cu_data
*per_cu
;
323 /* How many compilation units ago was this CU last referenced? */
326 /* A hash table of die offsets for following references. */
327 struct die_info
*die_ref_table
[REF_HASH_SIZE
];
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 unsigned long offset
;
369 unsigned long length
: 30;
371 /* Flag indicating this compilation unit will be read in before
372 any of the current compilation units are processed. */
373 unsigned long queued
: 1;
375 /* This flag will be set if we need to load absolutely all DIEs
376 for this compilation unit, instead of just the ones we think
377 are interesting. It gets set if we look for a DIE in the
378 hash table and don't find it. */
379 unsigned int load_all_dies
: 1;
381 /* Set iff currently read in. */
382 struct dwarf2_cu
*cu
;
384 /* If full symbols for this CU have been read in, then this field
385 holds a map of DIE offsets to types. It isn't always possible
386 to reconstruct this information later, so we have to preserve
390 /* The partial symbol table associated with this compilation unit,
391 or NULL for partial units (which do not have an associated
393 struct partial_symtab
*psymtab
;
396 /* The line number information for a compilation unit (found in the
397 .debug_line section) begins with a "statement program header",
398 which contains the following information. */
401 unsigned int total_length
;
402 unsigned short version
;
403 unsigned int header_length
;
404 unsigned char minimum_instruction_length
;
405 unsigned char default_is_stmt
;
407 unsigned char line_range
;
408 unsigned char opcode_base
;
410 /* standard_opcode_lengths[i] is the number of operands for the
411 standard opcode whose value is i. This means that
412 standard_opcode_lengths[0] is unused, and the last meaningful
413 element is standard_opcode_lengths[opcode_base - 1]. */
414 unsigned char *standard_opcode_lengths
;
416 /* The include_directories table. NOTE! These strings are not
417 allocated with xmalloc; instead, they are pointers into
418 debug_line_buffer. If you try to free them, `free' will get
420 unsigned int num_include_dirs
, include_dirs_size
;
423 /* The file_names table. NOTE! These strings are not allocated
424 with xmalloc; instead, they are pointers into debug_line_buffer.
425 Don't try to free them directly. */
426 unsigned int num_file_names
, file_names_size
;
430 unsigned int dir_index
;
431 unsigned int mod_time
;
433 int included_p
; /* Non-zero if referenced by the Line Number Program. */
434 struct symtab
*symtab
; /* The associated symbol table, if any. */
437 /* The start and end of the statement program following this
438 header. These point into dwarf2_per_objfile->line_buffer. */
439 gdb_byte
*statement_program_start
, *statement_program_end
;
442 /* When we construct a partial symbol table entry we only
443 need this much information. */
444 struct partial_die_info
446 /* Offset of this DIE. */
449 /* DWARF-2 tag for this DIE. */
450 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
452 /* Language code associated with this DIE. This is only used
453 for the compilation unit DIE. */
454 unsigned int language
: 8;
456 /* Assorted flags describing the data found in this DIE. */
457 unsigned int has_children
: 1;
458 unsigned int is_external
: 1;
459 unsigned int is_declaration
: 1;
460 unsigned int has_type
: 1;
461 unsigned int has_specification
: 1;
462 unsigned int has_stmt_list
: 1;
463 unsigned int has_pc_info
: 1;
465 /* Flag set if the SCOPE field of this structure has been
467 unsigned int scope_set
: 1;
469 /* Flag set if the DIE has a byte_size attribute. */
470 unsigned int has_byte_size
: 1;
472 /* The name of this DIE. Normally the value of DW_AT_name, but
473 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
478 /* The scope to prepend to our children. This is generally
479 allocated on the comp_unit_obstack, so will disappear
480 when this compilation unit leaves the cache. */
483 /* The location description associated with this DIE, if any. */
484 struct dwarf_block
*locdesc
;
486 /* If HAS_PC_INFO, the PC range associated with this DIE. */
490 /* Pointer into the info_buffer pointing at the target of
491 DW_AT_sibling, if any. */
494 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
495 DW_AT_specification (or DW_AT_abstract_origin or
497 unsigned int spec_offset
;
499 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
500 unsigned int line_offset
;
502 /* Pointers to this DIE's parent, first child, and next sibling,
504 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
507 /* This data structure holds the information of an abbrev. */
510 unsigned int number
; /* number identifying abbrev */
511 enum dwarf_tag tag
; /* dwarf tag */
512 unsigned short has_children
; /* boolean */
513 unsigned short num_attrs
; /* number of attributes */
514 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
515 struct abbrev_info
*next
; /* next in chain */
520 enum dwarf_attribute name
;
521 enum dwarf_form form
;
524 /* This data structure holds a complete die structure. */
527 enum dwarf_tag tag
; /* Tag indicating type of die */
528 unsigned int abbrev
; /* Abbrev number */
529 unsigned int offset
; /* Offset in .debug_info section */
530 unsigned int num_attrs
; /* Number of attributes */
531 struct attribute
*attrs
; /* An array of attributes */
532 struct die_info
*next_ref
; /* Next die in ref hash table */
534 /* The dies in a compilation unit form an n-ary tree. PARENT
535 points to this die's parent; CHILD points to the first child of
536 this node; and all the children of a given node are chained
537 together via their SIBLING fields, terminated by a die whose
539 struct die_info
*child
; /* Its first child, if any. */
540 struct die_info
*sibling
; /* Its next sibling, if any. */
541 struct die_info
*parent
; /* Its parent, if any. */
543 struct type
*type
; /* Cached type information */
546 /* Attributes have a name and a value */
549 enum dwarf_attribute name
;
550 enum dwarf_form form
;
554 struct dwarf_block
*blk
;
562 struct function_range
565 CORE_ADDR lowpc
, highpc
;
567 struct function_range
*next
;
570 /* Get at parts of an attribute structure */
572 #define DW_STRING(attr) ((attr)->u.str)
573 #define DW_UNSND(attr) ((attr)->u.unsnd)
574 #define DW_BLOCK(attr) ((attr)->u.blk)
575 #define DW_SND(attr) ((attr)->u.snd)
576 #define DW_ADDR(attr) ((attr)->u.addr)
578 /* Blocks are a bunch of untyped bytes. */
585 #ifndef ATTR_ALLOC_CHUNK
586 #define ATTR_ALLOC_CHUNK 4
589 /* Allocate fields for structs, unions and enums in this size. */
590 #ifndef DW_FIELD_ALLOC_CHUNK
591 #define DW_FIELD_ALLOC_CHUNK 4
594 /* A zeroed version of a partial die for initialization purposes. */
595 static struct partial_die_info zeroed_partial_die
;
597 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
598 but this would require a corresponding change in unpack_field_as_long
600 static int bits_per_byte
= 8;
602 /* The routines that read and process dies for a C struct or C++ class
603 pass lists of data member fields and lists of member function fields
604 in an instance of a field_info structure, as defined below. */
607 /* List of data member and baseclasses fields. */
610 struct nextfield
*next
;
617 /* Number of fields. */
620 /* Number of baseclasses. */
623 /* Set if the accesibility of one of the fields is not public. */
624 int non_public_fields
;
626 /* Member function fields array, entries are allocated in the order they
627 are encountered in the object file. */
630 struct nextfnfield
*next
;
631 struct fn_field fnfield
;
635 /* Member function fieldlist array, contains name of possibly overloaded
636 member function, number of overloaded member functions and a pointer
637 to the head of the member function field chain. */
642 struct nextfnfield
*head
;
646 /* Number of entries in the fnfieldlists array. */
650 /* One item on the queue of compilation units to read in full symbols
652 struct dwarf2_queue_item
654 struct dwarf2_per_cu_data
*per_cu
;
655 struct dwarf2_queue_item
*next
;
658 /* The current queue. */
659 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
661 /* Loaded secondary compilation units are kept in memory until they
662 have not been referenced for the processing of this many
663 compilation units. Set this to zero to disable caching. Cache
664 sizes of up to at least twenty will improve startup time for
665 typical inter-CU-reference binaries, at an obvious memory cost. */
666 static int dwarf2_max_cache_age
= 5;
668 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
669 struct cmd_list_element
*c
, const char *value
)
671 fprintf_filtered (file
, _("\
672 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
677 /* Various complaints about symbol reading that don't abort the process */
680 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
682 complaint (&symfile_complaints
,
683 _("statement list doesn't fit in .debug_line section"));
687 dwarf2_debug_line_missing_file_complaint (void)
689 complaint (&symfile_complaints
,
690 _(".debug_line section has line data without a file"));
694 dwarf2_complex_location_expr_complaint (void)
696 complaint (&symfile_complaints
, _("location expression too complex"));
700 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
703 complaint (&symfile_complaints
,
704 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
709 dwarf2_macros_too_long_complaint (void)
711 complaint (&symfile_complaints
,
712 _("macro info runs off end of `.debug_macinfo' section"));
716 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
718 complaint (&symfile_complaints
,
719 _("macro debug info contains a malformed macro definition:\n`%s'"),
724 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
726 complaint (&symfile_complaints
,
727 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
730 /* local function prototypes */
732 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
735 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
738 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
741 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
742 struct partial_die_info
*,
743 struct partial_symtab
*);
745 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
747 static void scan_partial_symbols (struct partial_die_info
*,
748 CORE_ADDR
*, CORE_ADDR
*,
751 static void add_partial_symbol (struct partial_die_info
*,
754 static int pdi_needs_namespace (enum dwarf_tag tag
);
756 static void add_partial_namespace (struct partial_die_info
*pdi
,
757 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
758 struct dwarf2_cu
*cu
);
760 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
761 struct dwarf2_cu
*cu
);
763 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
766 struct dwarf2_cu
*cu
);
768 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
770 static void psymtab_to_symtab_1 (struct partial_symtab
*);
772 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
774 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
776 static void dwarf2_free_abbrev_table (void *);
778 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
781 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
784 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
787 static gdb_byte
*read_partial_die (struct partial_die_info
*,
788 struct abbrev_info
*abbrev
, unsigned int,
789 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
791 static struct partial_die_info
*find_partial_die (unsigned long,
794 static void fixup_partial_die (struct partial_die_info
*,
797 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
798 struct dwarf2_cu
*, int *);
800 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
801 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
803 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
804 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
806 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
808 static int read_1_signed_byte (bfd
*, gdb_byte
*);
810 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
812 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
814 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
816 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
819 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
820 struct comp_unit_head
*, unsigned int *);
822 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
825 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
827 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
829 static char *read_indirect_string (bfd
*, gdb_byte
*,
830 const struct comp_unit_head
*,
833 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
835 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
837 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
839 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
841 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
844 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
845 struct dwarf2_cu
*cu
);
847 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
849 static struct die_info
*die_specification (struct die_info
*die
,
852 static void free_line_header (struct line_header
*lh
);
854 static void add_file_name (struct line_header
*, char *, unsigned int,
855 unsigned int, unsigned int);
857 static struct line_header
*(dwarf_decode_line_header
858 (unsigned int offset
,
859 bfd
*abfd
, struct dwarf2_cu
*cu
));
861 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
862 struct dwarf2_cu
*, struct partial_symtab
*);
864 static void dwarf2_start_subfile (char *, char *, char *);
866 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
869 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
872 static void dwarf2_const_value_data (struct attribute
*attr
,
876 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
878 static struct type
*die_containing_type (struct die_info
*,
881 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
883 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
885 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
887 static char *typename_concat (struct obstack
*,
892 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
894 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
896 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
898 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
900 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
902 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
904 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
905 struct dwarf2_cu
*, struct partial_symtab
*);
907 static int dwarf2_get_pc_bounds (struct die_info
*,
908 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
910 static void get_scope_pc_bounds (struct die_info
*,
911 CORE_ADDR
*, CORE_ADDR
*,
914 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
915 CORE_ADDR
, struct dwarf2_cu
*);
917 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
920 static void dwarf2_attach_fields_to_type (struct field_info
*,
921 struct type
*, struct dwarf2_cu
*);
923 static void dwarf2_add_member_fn (struct field_info
*,
924 struct die_info
*, struct type
*,
927 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
928 struct type
*, struct dwarf2_cu
*);
930 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
932 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
934 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
936 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
938 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
940 static const char *namespace_name (struct die_info
*die
,
941 int *is_anonymous
, struct dwarf2_cu
*);
943 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
945 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
947 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
949 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
951 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
954 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
956 static void read_tag_ptr_to_member_type (struct die_info
*,
959 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
961 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
963 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
965 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
967 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
969 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
971 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
973 gdb_byte
**new_info_ptr
,
974 struct die_info
*parent
);
976 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
978 gdb_byte
**new_info_ptr
,
979 struct die_info
*parent
);
981 static void free_die_list (struct die_info
*);
983 static void process_die (struct die_info
*, struct dwarf2_cu
*);
985 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
987 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
989 static struct die_info
*dwarf2_extension (struct die_info
*die
,
992 static char *dwarf_tag_name (unsigned int);
994 static char *dwarf_attr_name (unsigned int);
996 static char *dwarf_form_name (unsigned int);
998 static char *dwarf_stack_op_name (unsigned int);
1000 static char *dwarf_bool_name (unsigned int);
1002 static char *dwarf_type_encoding_name (unsigned int);
1005 static char *dwarf_cfi_name (unsigned int);
1007 struct die_info
*copy_die (struct die_info
*);
1010 static struct die_info
*sibling_die (struct die_info
*);
1012 static void dump_die (struct die_info
*);
1014 static void dump_die_list (struct die_info
*);
1016 static void store_in_ref_table (unsigned int, struct die_info
*,
1017 struct dwarf2_cu
*);
1019 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
1020 struct dwarf2_cu
*);
1022 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1024 static struct die_info
*follow_die_ref (struct die_info
*,
1026 struct dwarf2_cu
*);
1028 /* memory allocation interface */
1030 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1032 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1034 static struct die_info
*dwarf_alloc_die (void);
1036 static void initialize_cu_func_list (struct dwarf2_cu
*);
1038 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1039 struct dwarf2_cu
*);
1041 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1042 char *, bfd
*, struct dwarf2_cu
*);
1044 static int attr_form_is_block (struct attribute
*);
1046 static int attr_form_is_section_offset (struct attribute
*);
1048 static int attr_form_is_constant (struct attribute
*);
1050 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1052 struct dwarf2_cu
*cu
);
1054 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1055 struct dwarf2_cu
*cu
);
1057 static void free_stack_comp_unit (void *);
1059 static hashval_t
partial_die_hash (const void *item
);
1061 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1063 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1064 (unsigned long offset
, struct objfile
*objfile
);
1066 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1067 (unsigned long offset
, struct objfile
*objfile
);
1069 static void free_one_comp_unit (void *);
1071 static void free_cached_comp_units (void *);
1073 static void age_cached_comp_units (void);
1075 static void free_one_cached_comp_unit (void *);
1077 static void set_die_type (struct die_info
*, struct type
*,
1078 struct dwarf2_cu
*);
1080 static void reset_die_and_siblings_types (struct die_info
*,
1081 struct dwarf2_cu
*);
1083 static void create_all_comp_units (struct objfile
*);
1085 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1088 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1090 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1091 struct dwarf2_per_cu_data
*);
1093 static void dwarf2_mark (struct dwarf2_cu
*);
1095 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1097 static void read_set_type (struct die_info
*, struct dwarf2_cu
*);
1100 /* Try to locate the sections we need for DWARF 2 debugging
1101 information and return true if we have enough to do something. */
1104 dwarf2_has_info (struct objfile
*objfile
)
1106 struct dwarf2_per_objfile
*data
;
1108 /* Initialize per-objfile state. */
1109 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1110 memset (data
, 0, sizeof (*data
));
1111 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1112 dwarf2_per_objfile
= data
;
1114 dwarf_info_section
= 0;
1115 dwarf_abbrev_section
= 0;
1116 dwarf_line_section
= 0;
1117 dwarf_str_section
= 0;
1118 dwarf_macinfo_section
= 0;
1119 dwarf_frame_section
= 0;
1120 dwarf_eh_frame_section
= 0;
1121 dwarf_ranges_section
= 0;
1122 dwarf_loc_section
= 0;
1124 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1125 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1128 /* When loading sections, we can either look for ".<name>", or for
1129 * ".z<name>", which indicates a compressed section. */
1132 section_is_p (asection
*sectp
, const char *name
)
1134 return ((sectp
->name
[0] == '.'
1135 && strcmp (sectp
->name
+ 1, name
) == 0)
1136 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1137 && strcmp (sectp
->name
+ 2, name
) == 0));
1140 /* This function is mapped across the sections and remembers the
1141 offset and size of each of the debugging sections we are interested
1145 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1147 if (section_is_p (sectp
, INFO_SECTION
))
1149 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1150 dwarf_info_section
= sectp
;
1152 else if (section_is_p (sectp
, ABBREV_SECTION
))
1154 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1155 dwarf_abbrev_section
= sectp
;
1157 else if (section_is_p (sectp
, LINE_SECTION
))
1159 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1160 dwarf_line_section
= sectp
;
1162 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1164 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1165 dwarf_pubnames_section
= sectp
;
1167 else if (section_is_p (sectp
, ARANGES_SECTION
))
1169 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1170 dwarf_aranges_section
= sectp
;
1172 else if (section_is_p (sectp
, LOC_SECTION
))
1174 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1175 dwarf_loc_section
= sectp
;
1177 else if (section_is_p (sectp
, MACINFO_SECTION
))
1179 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1180 dwarf_macinfo_section
= sectp
;
1182 else if (section_is_p (sectp
, STR_SECTION
))
1184 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1185 dwarf_str_section
= sectp
;
1187 else if (section_is_p (sectp
, FRAME_SECTION
))
1189 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1190 dwarf_frame_section
= sectp
;
1192 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1194 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1195 if (aflag
& SEC_HAS_CONTENTS
)
1197 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1198 dwarf_eh_frame_section
= sectp
;
1201 else if (section_is_p (sectp
, RANGES_SECTION
))
1203 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1204 dwarf_ranges_section
= sectp
;
1207 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1208 && bfd_section_vma (abfd
, sectp
) == 0)
1209 dwarf2_per_objfile
->has_section_at_zero
= 1;
1212 /* This function is called after decompressing a section, so
1213 dwarf2_per_objfile can record its new, uncompressed size. */
1216 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1218 if (section_is_p (sectp
, INFO_SECTION
))
1219 dwarf2_per_objfile
->info_size
= new_size
;
1220 else if (section_is_p (sectp
, ABBREV_SECTION
))
1221 dwarf2_per_objfile
->abbrev_size
= new_size
;
1222 else if (section_is_p (sectp
, LINE_SECTION
))
1223 dwarf2_per_objfile
->line_size
= new_size
;
1224 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1225 dwarf2_per_objfile
->pubnames_size
= new_size
;
1226 else if (section_is_p (sectp
, ARANGES_SECTION
))
1227 dwarf2_per_objfile
->aranges_size
= new_size
;
1228 else if (section_is_p (sectp
, LOC_SECTION
))
1229 dwarf2_per_objfile
->loc_size
= new_size
;
1230 else if (section_is_p (sectp
, MACINFO_SECTION
))
1231 dwarf2_per_objfile
->macinfo_size
= new_size
;
1232 else if (section_is_p (sectp
, STR_SECTION
))
1233 dwarf2_per_objfile
->str_size
= new_size
;
1234 else if (section_is_p (sectp
, FRAME_SECTION
))
1235 dwarf2_per_objfile
->frame_size
= new_size
;
1236 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1237 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1238 else if (section_is_p (sectp
, RANGES_SECTION
))
1239 dwarf2_per_objfile
->ranges_size
= new_size
;
1241 internal_error (__FILE__
, __LINE__
,
1242 _("dwarf2_resize_section: missing section_is_p check: %s"),
1246 /* Build a partial symbol table. */
1249 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1251 /* We definitely need the .debug_info and .debug_abbrev sections */
1253 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1254 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1256 if (dwarf_line_section
)
1257 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1259 dwarf2_per_objfile
->line_buffer
= NULL
;
1261 if (dwarf_str_section
)
1262 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1264 dwarf2_per_objfile
->str_buffer
= NULL
;
1266 if (dwarf_macinfo_section
)
1267 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1268 dwarf_macinfo_section
);
1270 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1272 if (dwarf_ranges_section
)
1273 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1275 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1277 if (dwarf_loc_section
)
1278 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1280 dwarf2_per_objfile
->loc_buffer
= NULL
;
1283 || (objfile
->global_psymbols
.size
== 0
1284 && objfile
->static_psymbols
.size
== 0))
1286 init_psymbol_list (objfile
, 1024);
1290 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1292 /* Things are significantly easier if we have .debug_aranges and
1293 .debug_pubnames sections */
1295 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1299 /* only test this case for now */
1301 /* In this case we have to work a bit harder */
1302 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1307 /* Build the partial symbol table from the information in the
1308 .debug_pubnames and .debug_aranges sections. */
1311 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1313 bfd
*abfd
= objfile
->obfd
;
1314 char *aranges_buffer
, *pubnames_buffer
;
1315 char *aranges_ptr
, *pubnames_ptr
;
1316 unsigned int entry_length
, version
, info_offset
, info_size
;
1318 pubnames_buffer
= dwarf2_read_section (objfile
,
1319 dwarf_pubnames_section
);
1320 pubnames_ptr
= pubnames_buffer
;
1321 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1323 struct comp_unit_head cu_header
;
1324 unsigned int bytes_read
;
1326 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1328 pubnames_ptr
+= bytes_read
;
1329 version
= read_1_byte (abfd
, pubnames_ptr
);
1331 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1333 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1337 aranges_buffer
= dwarf2_read_section (objfile
,
1338 dwarf_aranges_section
);
1343 /* Read in the comp unit header information from the debug_info at
1347 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1348 gdb_byte
*info_ptr
, bfd
*abfd
)
1351 unsigned int bytes_read
;
1352 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1354 info_ptr
+= bytes_read
;
1355 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1357 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1359 info_ptr
+= bytes_read
;
1360 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1362 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1363 if (signed_addr
< 0)
1364 internal_error (__FILE__
, __LINE__
,
1365 _("read_comp_unit_head: dwarf from non elf file"));
1366 cu_header
->signed_addr_p
= signed_addr
;
1371 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1374 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1376 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1378 if (header
->version
!= 2 && header
->version
!= 3)
1379 error (_("Dwarf Error: wrong version in compilation unit header "
1380 "(is %d, should be %d) [in module %s]"), header
->version
,
1381 2, bfd_get_filename (abfd
));
1383 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1384 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1385 "(offset 0x%lx + 6) [in module %s]"),
1386 (long) header
->abbrev_offset
,
1387 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1388 bfd_get_filename (abfd
));
1390 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1391 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1392 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1393 "(offset 0x%lx + 0) [in module %s]"),
1394 (long) header
->length
,
1395 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1396 bfd_get_filename (abfd
));
1401 /* Allocate a new partial symtab for file named NAME and mark this new
1402 partial symtab as being an include of PST. */
1405 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1406 struct objfile
*objfile
)
1408 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1410 subpst
->section_offsets
= pst
->section_offsets
;
1411 subpst
->textlow
= 0;
1412 subpst
->texthigh
= 0;
1414 subpst
->dependencies
= (struct partial_symtab
**)
1415 obstack_alloc (&objfile
->objfile_obstack
,
1416 sizeof (struct partial_symtab
*));
1417 subpst
->dependencies
[0] = pst
;
1418 subpst
->number_of_dependencies
= 1;
1420 subpst
->globals_offset
= 0;
1421 subpst
->n_global_syms
= 0;
1422 subpst
->statics_offset
= 0;
1423 subpst
->n_static_syms
= 0;
1424 subpst
->symtab
= NULL
;
1425 subpst
->read_symtab
= pst
->read_symtab
;
1428 /* No private part is necessary for include psymtabs. This property
1429 can be used to differentiate between such include psymtabs and
1430 the regular ones. */
1431 subpst
->read_symtab_private
= NULL
;
1434 /* Read the Line Number Program data and extract the list of files
1435 included by the source file represented by PST. Build an include
1436 partial symtab for each of these included files.
1438 This procedure assumes that there *is* a Line Number Program in
1439 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1440 before calling this procedure. */
1443 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1444 struct partial_die_info
*pdi
,
1445 struct partial_symtab
*pst
)
1447 struct objfile
*objfile
= cu
->objfile
;
1448 bfd
*abfd
= objfile
->obfd
;
1449 struct line_header
*lh
;
1451 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1453 return; /* No linetable, so no includes. */
1455 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1457 free_line_header (lh
);
1461 /* Build the partial symbol table by doing a quick pass through the
1462 .debug_info and .debug_abbrev sections. */
1465 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1467 /* Instead of reading this into a big buffer, we should probably use
1468 mmap() on architectures that support it. (FIXME) */
1469 bfd
*abfd
= objfile
->obfd
;
1471 gdb_byte
*beg_of_comp_unit
;
1472 struct partial_die_info comp_unit_die
;
1473 struct partial_symtab
*pst
;
1474 struct cleanup
*back_to
;
1475 CORE_ADDR lowpc
, highpc
, baseaddr
;
1477 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1479 /* Any cached compilation units will be linked by the per-objfile
1480 read_in_chain. Make sure to free them when we're done. */
1481 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1483 create_all_comp_units (objfile
);
1485 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1486 (&objfile
->objfile_obstack
);
1488 /* Since the objects we're extracting from .debug_info vary in
1489 length, only the individual functions to extract them (like
1490 read_comp_unit_head and load_partial_die) can really know whether
1491 the buffer is large enough to hold another complete object.
1493 At the moment, they don't actually check that. If .debug_info
1494 holds just one extra byte after the last compilation unit's dies,
1495 then read_comp_unit_head will happily read off the end of the
1496 buffer. read_partial_die is similarly casual. Those functions
1499 For this loop condition, simply checking whether there's any data
1500 left at all should be sufficient. */
1501 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1502 + dwarf2_per_objfile
->info_size
))
1504 struct cleanup
*back_to_inner
;
1505 struct dwarf2_cu cu
;
1506 struct abbrev_info
*abbrev
;
1507 unsigned int bytes_read
;
1508 struct dwarf2_per_cu_data
*this_cu
;
1510 beg_of_comp_unit
= info_ptr
;
1512 memset (&cu
, 0, sizeof (cu
));
1514 obstack_init (&cu
.comp_unit_obstack
);
1516 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1518 cu
.objfile
= objfile
;
1519 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1521 /* Complete the cu_header */
1522 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1523 cu
.header
.first_die_ptr
= info_ptr
;
1524 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1526 cu
.list_in_scope
= &file_symbols
;
1528 /* Read the abbrevs for this compilation unit into a table */
1529 dwarf2_read_abbrevs (abfd
, &cu
);
1530 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1532 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1534 /* Read the compilation unit die */
1535 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1536 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1537 abfd
, info_ptr
, &cu
);
1539 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1541 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1542 + cu
.header
.initial_length_size
);
1543 do_cleanups (back_to_inner
);
1547 /* Set the language we're debugging */
1548 set_cu_language (comp_unit_die
.language
, &cu
);
1550 /* Allocate a new partial symbol table structure */
1551 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1552 comp_unit_die
.name
? comp_unit_die
.name
: "",
1553 /* TEXTLOW and TEXTHIGH are set below. */
1555 objfile
->global_psymbols
.next
,
1556 objfile
->static_psymbols
.next
);
1558 if (comp_unit_die
.dirname
)
1559 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1561 pst
->read_symtab_private
= (char *) this_cu
;
1563 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1565 /* Store the function that reads in the rest of the symbol table */
1566 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1568 /* If this compilation unit was already read in, free the
1569 cached copy in order to read it in again. This is
1570 necessary because we skipped some symbols when we first
1571 read in the compilation unit (see load_partial_dies).
1572 This problem could be avoided, but the benefit is
1574 if (this_cu
->cu
!= NULL
)
1575 free_one_cached_comp_unit (this_cu
->cu
);
1577 cu
.per_cu
= this_cu
;
1579 /* Note that this is a pointer to our stack frame, being
1580 added to a global data structure. It will be cleaned up
1581 in free_stack_comp_unit when we finish with this
1582 compilation unit. */
1585 this_cu
->psymtab
= pst
;
1587 /* Possibly set the default values of LOWPC and HIGHPC from
1589 if (cu
.has_ranges_offset
)
1591 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1592 &comp_unit_die
.highpc
, &cu
, pst
))
1593 comp_unit_die
.has_pc_info
= 1;
1596 /* Check if comp unit has_children.
1597 If so, read the rest of the partial symbols from this comp unit.
1598 If not, there's no more debug_info for this comp unit. */
1599 if (comp_unit_die
.has_children
)
1601 struct partial_die_info
*first_die
;
1603 lowpc
= ((CORE_ADDR
) -1);
1604 highpc
= ((CORE_ADDR
) 0);
1606 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1608 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1610 /* If we didn't find a lowpc, set it to highpc to avoid
1611 complaints from `maint check'. */
1612 if (lowpc
== ((CORE_ADDR
) -1))
1615 /* If the compilation unit didn't have an explicit address range,
1616 then use the information extracted from its child dies. */
1617 if (! comp_unit_die
.has_pc_info
)
1619 comp_unit_die
.lowpc
= lowpc
;
1620 comp_unit_die
.highpc
= highpc
;
1623 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1624 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1626 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1627 range can be also empty for CUs with no code. */
1628 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1629 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1630 pst
->texthigh
- 1, pst
);
1632 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1633 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1634 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1635 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1636 sort_pst_symbols (pst
);
1638 /* If there is already a psymtab or symtab for a file of this
1639 name, remove it. (If there is a symtab, more drastic things
1640 also happen.) This happens in VxWorks. */
1641 free_named_symtabs (pst
->filename
);
1643 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1644 + cu
.header
.initial_length_size
;
1646 if (comp_unit_die
.has_stmt_list
)
1648 /* Get the list of files included in the current compilation unit,
1649 and build a psymtab for each of them. */
1650 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1653 do_cleanups (back_to_inner
);
1656 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1657 &objfile
->objfile_obstack
);
1659 do_cleanups (back_to
);
1662 /* Load the DIEs for a secondary CU into memory. */
1665 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1667 bfd
*abfd
= objfile
->obfd
;
1668 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1669 struct partial_die_info comp_unit_die
;
1670 struct dwarf2_cu
*cu
;
1671 struct abbrev_info
*abbrev
;
1672 unsigned int bytes_read
;
1673 struct cleanup
*back_to
;
1675 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1676 beg_of_comp_unit
= info_ptr
;
1678 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1679 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1681 obstack_init (&cu
->comp_unit_obstack
);
1683 cu
->objfile
= objfile
;
1684 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1686 /* Complete the cu_header. */
1687 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1688 cu
->header
.first_die_ptr
= info_ptr
;
1689 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1691 /* Read the abbrevs for this compilation unit into a table. */
1692 dwarf2_read_abbrevs (abfd
, cu
);
1693 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1695 /* Read the compilation unit die. */
1696 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1697 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1698 abfd
, info_ptr
, cu
);
1700 /* Set the language we're debugging. */
1701 set_cu_language (comp_unit_die
.language
, cu
);
1703 /* Link this compilation unit into the compilation unit tree. */
1705 cu
->per_cu
= this_cu
;
1707 /* Check if comp unit has_children.
1708 If so, read the rest of the partial symbols from this comp unit.
1709 If not, there's no more debug_info for this comp unit. */
1710 if (comp_unit_die
.has_children
)
1711 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1713 do_cleanups (back_to
);
1716 /* Create a list of all compilation units in OBJFILE. We do this only
1717 if an inter-comp-unit reference is found; presumably if there is one,
1718 there will be many, and one will occur early in the .debug_info section.
1719 So there's no point in building this list incrementally. */
1722 create_all_comp_units (struct objfile
*objfile
)
1726 struct dwarf2_per_cu_data
**all_comp_units
;
1727 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1731 all_comp_units
= xmalloc (n_allocated
1732 * sizeof (struct dwarf2_per_cu_data
*));
1734 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1736 struct comp_unit_head cu_header
;
1737 gdb_byte
*beg_of_comp_unit
;
1738 struct dwarf2_per_cu_data
*this_cu
;
1739 unsigned long offset
;
1740 unsigned int bytes_read
;
1742 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1744 /* Read just enough information to find out where the next
1745 compilation unit is. */
1746 cu_header
.initial_length_size
= 0;
1747 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1748 &cu_header
, &bytes_read
);
1750 /* Save the compilation unit for later lookup. */
1751 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1752 sizeof (struct dwarf2_per_cu_data
));
1753 memset (this_cu
, 0, sizeof (*this_cu
));
1754 this_cu
->offset
= offset
;
1755 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1757 if (n_comp_units
== n_allocated
)
1760 all_comp_units
= xrealloc (all_comp_units
,
1762 * sizeof (struct dwarf2_per_cu_data
*));
1764 all_comp_units
[n_comp_units
++] = this_cu
;
1766 info_ptr
= info_ptr
+ this_cu
->length
;
1769 dwarf2_per_objfile
->all_comp_units
1770 = obstack_alloc (&objfile
->objfile_obstack
,
1771 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1772 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1773 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1774 xfree (all_comp_units
);
1775 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1778 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1779 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1783 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1784 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1786 struct objfile
*objfile
= cu
->objfile
;
1787 bfd
*abfd
= objfile
->obfd
;
1788 struct partial_die_info
*pdi
;
1790 /* Now, march along the PDI's, descending into ones which have
1791 interesting children but skipping the children of the other ones,
1792 until we reach the end of the compilation unit. */
1798 fixup_partial_die (pdi
, cu
);
1800 /* Anonymous namespaces have no name but have interesting
1801 children, so we need to look at them. Ditto for anonymous
1804 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1805 || pdi
->tag
== DW_TAG_enumeration_type
)
1809 case DW_TAG_subprogram
:
1810 if (pdi
->has_pc_info
)
1812 if (pdi
->lowpc
< *lowpc
)
1814 *lowpc
= pdi
->lowpc
;
1816 if (pdi
->highpc
> *highpc
)
1818 *highpc
= pdi
->highpc
;
1820 if (!pdi
->is_declaration
)
1822 add_partial_symbol (pdi
, cu
);
1826 case DW_TAG_variable
:
1827 case DW_TAG_typedef
:
1828 case DW_TAG_union_type
:
1829 if (!pdi
->is_declaration
)
1831 add_partial_symbol (pdi
, cu
);
1834 case DW_TAG_class_type
:
1835 case DW_TAG_interface_type
:
1836 case DW_TAG_structure_type
:
1837 if (!pdi
->is_declaration
)
1839 add_partial_symbol (pdi
, cu
);
1842 case DW_TAG_enumeration_type
:
1843 if (!pdi
->is_declaration
)
1844 add_partial_enumeration (pdi
, cu
);
1846 case DW_TAG_base_type
:
1847 case DW_TAG_subrange_type
:
1848 /* File scope base type definitions are added to the partial
1850 add_partial_symbol (pdi
, cu
);
1852 case DW_TAG_namespace
:
1853 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1860 /* If the die has a sibling, skip to the sibling. */
1862 pdi
= pdi
->die_sibling
;
1866 /* Functions used to compute the fully scoped name of a partial DIE.
1868 Normally, this is simple. For C++, the parent DIE's fully scoped
1869 name is concatenated with "::" and the partial DIE's name. For
1870 Java, the same thing occurs except that "." is used instead of "::".
1871 Enumerators are an exception; they use the scope of their parent
1872 enumeration type, i.e. the name of the enumeration type is not
1873 prepended to the enumerator.
1875 There are two complexities. One is DW_AT_specification; in this
1876 case "parent" means the parent of the target of the specification,
1877 instead of the direct parent of the DIE. The other is compilers
1878 which do not emit DW_TAG_namespace; in this case we try to guess
1879 the fully qualified name of structure types from their members'
1880 linkage names. This must be done using the DIE's children rather
1881 than the children of any DW_AT_specification target. We only need
1882 to do this for structures at the top level, i.e. if the target of
1883 any DW_AT_specification (if any; otherwise the DIE itself) does not
1886 /* Compute the scope prefix associated with PDI's parent, in
1887 compilation unit CU. The result will be allocated on CU's
1888 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1889 field. NULL is returned if no prefix is necessary. */
1891 partial_die_parent_scope (struct partial_die_info
*pdi
,
1892 struct dwarf2_cu
*cu
)
1894 char *grandparent_scope
;
1895 struct partial_die_info
*parent
, *real_pdi
;
1897 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1898 then this means the parent of the specification DIE. */
1901 while (real_pdi
->has_specification
)
1902 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1904 parent
= real_pdi
->die_parent
;
1908 if (parent
->scope_set
)
1909 return parent
->scope
;
1911 fixup_partial_die (parent
, cu
);
1913 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1915 if (parent
->tag
== DW_TAG_namespace
1916 || parent
->tag
== DW_TAG_structure_type
1917 || parent
->tag
== DW_TAG_class_type
1918 || parent
->tag
== DW_TAG_interface_type
1919 || parent
->tag
== DW_TAG_union_type
)
1921 if (grandparent_scope
== NULL
)
1922 parent
->scope
= parent
->name
;
1924 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1927 else if (parent
->tag
== DW_TAG_enumeration_type
)
1928 /* Enumerators should not get the name of the enumeration as a prefix. */
1929 parent
->scope
= grandparent_scope
;
1932 /* FIXME drow/2004-04-01: What should we be doing with
1933 function-local names? For partial symbols, we should probably be
1935 complaint (&symfile_complaints
,
1936 _("unhandled containing DIE tag %d for DIE at %d"),
1937 parent
->tag
, pdi
->offset
);
1938 parent
->scope
= grandparent_scope
;
1941 parent
->scope_set
= 1;
1942 return parent
->scope
;
1945 /* Return the fully scoped name associated with PDI, from compilation unit
1946 CU. The result will be allocated with malloc. */
1948 partial_die_full_name (struct partial_die_info
*pdi
,
1949 struct dwarf2_cu
*cu
)
1953 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1954 if (parent_scope
== NULL
)
1957 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1961 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1963 struct objfile
*objfile
= cu
->objfile
;
1965 char *actual_name
= NULL
;
1966 const char *my_prefix
;
1967 const struct partial_symbol
*psym
= NULL
;
1969 int built_actual_name
= 0;
1971 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1973 if (pdi_needs_namespace (pdi
->tag
))
1975 actual_name
= partial_die_full_name (pdi
, cu
);
1977 built_actual_name
= 1;
1980 if (actual_name
== NULL
)
1981 actual_name
= pdi
->name
;
1985 case DW_TAG_subprogram
:
1986 if (pdi
->is_external
|| cu
->language
== language_ada
)
1988 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1989 of the global scope. But in Ada, we want to be able to access
1990 nested procedures globally. So all Ada subprograms are stored
1991 in the global scope. */
1992 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1993 mst_text, objfile); */
1994 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1995 VAR_DOMAIN
, LOC_BLOCK
,
1996 &objfile
->global_psymbols
,
1997 0, pdi
->lowpc
+ baseaddr
,
1998 cu
->language
, objfile
);
2002 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2003 mst_file_text, objfile); */
2004 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2005 VAR_DOMAIN
, LOC_BLOCK
,
2006 &objfile
->static_psymbols
,
2007 0, pdi
->lowpc
+ baseaddr
,
2008 cu
->language
, objfile
);
2011 case DW_TAG_variable
:
2012 if (pdi
->is_external
)
2015 Don't enter into the minimal symbol tables as there is
2016 a minimal symbol table entry from the ELF symbols already.
2017 Enter into partial symbol table if it has a location
2018 descriptor or a type.
2019 If the location descriptor is missing, new_symbol will create
2020 a LOC_UNRESOLVED symbol, the address of the variable will then
2021 be determined from the minimal symbol table whenever the variable
2023 The address for the partial symbol table entry is not
2024 used by GDB, but it comes in handy for debugging partial symbol
2028 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2029 if (pdi
->locdesc
|| pdi
->has_type
)
2030 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2031 VAR_DOMAIN
, LOC_STATIC
,
2032 &objfile
->global_psymbols
,
2034 cu
->language
, objfile
);
2038 /* Static Variable. Skip symbols without location descriptors. */
2039 if (pdi
->locdesc
== NULL
)
2041 if (built_actual_name
)
2042 xfree (actual_name
);
2045 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2046 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2047 mst_file_data, objfile); */
2048 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2049 VAR_DOMAIN
, LOC_STATIC
,
2050 &objfile
->static_psymbols
,
2052 cu
->language
, objfile
);
2055 case DW_TAG_typedef
:
2056 case DW_TAG_base_type
:
2057 case DW_TAG_subrange_type
:
2058 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2059 VAR_DOMAIN
, LOC_TYPEDEF
,
2060 &objfile
->static_psymbols
,
2061 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2063 case DW_TAG_namespace
:
2064 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2065 VAR_DOMAIN
, LOC_TYPEDEF
,
2066 &objfile
->global_psymbols
,
2067 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2069 case DW_TAG_class_type
:
2070 case DW_TAG_interface_type
:
2071 case DW_TAG_structure_type
:
2072 case DW_TAG_union_type
:
2073 case DW_TAG_enumeration_type
:
2074 /* Skip external references. The DWARF standard says in the section
2075 about "Structure, Union, and Class Type Entries": "An incomplete
2076 structure, union or class type is represented by a structure,
2077 union or class entry that does not have a byte size attribute
2078 and that has a DW_AT_declaration attribute." */
2079 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2081 if (built_actual_name
)
2082 xfree (actual_name
);
2086 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2087 static vs. global. */
2088 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2089 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2090 (cu
->language
== language_cplus
2091 || cu
->language
== language_java
)
2092 ? &objfile
->global_psymbols
2093 : &objfile
->static_psymbols
,
2094 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2096 if (cu
->language
== language_cplus
2097 || cu
->language
== language_java
2098 || cu
->language
== language_ada
)
2100 /* For C++ and Java, these implicitly act as typedefs as well. */
2101 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2102 VAR_DOMAIN
, LOC_TYPEDEF
,
2103 &objfile
->global_psymbols
,
2104 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2107 case DW_TAG_enumerator
:
2108 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2109 VAR_DOMAIN
, LOC_CONST
,
2110 (cu
->language
== language_cplus
2111 || cu
->language
== language_java
)
2112 ? &objfile
->global_psymbols
2113 : &objfile
->static_psymbols
,
2114 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2120 /* Check to see if we should scan the name for possible namespace
2121 info. Only do this if this is C++, if we don't have namespace
2122 debugging info in the file, if the psym is of an appropriate type
2123 (otherwise we'll have psym == NULL), and if we actually had a
2124 mangled name to begin with. */
2126 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2127 cases which do not set PSYM above? */
2129 if (cu
->language
== language_cplus
2130 && cu
->has_namespace_info
== 0
2132 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2133 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2136 if (built_actual_name
)
2137 xfree (actual_name
);
2140 /* Determine whether a die of type TAG living in a C++ class or
2141 namespace needs to have the name of the scope prepended to the
2142 name listed in the die. */
2145 pdi_needs_namespace (enum dwarf_tag tag
)
2149 case DW_TAG_namespace
:
2150 case DW_TAG_typedef
:
2151 case DW_TAG_class_type
:
2152 case DW_TAG_interface_type
:
2153 case DW_TAG_structure_type
:
2154 case DW_TAG_union_type
:
2155 case DW_TAG_enumeration_type
:
2156 case DW_TAG_enumerator
:
2163 /* Read a partial die corresponding to a namespace; also, add a symbol
2164 corresponding to that namespace to the symbol table. NAMESPACE is
2165 the name of the enclosing namespace. */
2168 add_partial_namespace (struct partial_die_info
*pdi
,
2169 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2170 struct dwarf2_cu
*cu
)
2172 struct objfile
*objfile
= cu
->objfile
;
2174 /* Add a symbol for the namespace. */
2176 add_partial_symbol (pdi
, cu
);
2178 /* Now scan partial symbols in that namespace. */
2180 if (pdi
->has_children
)
2181 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2184 /* See if we can figure out if the class lives in a namespace. We do
2185 this by looking for a member function; its demangled name will
2186 contain namespace info, if there is any. */
2189 guess_structure_name (struct partial_die_info
*struct_pdi
,
2190 struct dwarf2_cu
*cu
)
2192 if ((cu
->language
== language_cplus
2193 || cu
->language
== language_java
)
2194 && cu
->has_namespace_info
== 0
2195 && struct_pdi
->has_children
)
2197 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2198 what template types look like, because the demangler
2199 frequently doesn't give the same name as the debug info. We
2200 could fix this by only using the demangled name to get the
2201 prefix (but see comment in read_structure_type). */
2203 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2204 struct partial_die_info
*real_pdi
;
2206 /* If this DIE (this DIE's specification, if any) has a parent, then
2207 we should not do this. We'll prepend the parent's fully qualified
2208 name when we create the partial symbol. */
2210 real_pdi
= struct_pdi
;
2211 while (real_pdi
->has_specification
)
2212 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2214 if (real_pdi
->die_parent
!= NULL
)
2217 while (child_pdi
!= NULL
)
2219 if (child_pdi
->tag
== DW_TAG_subprogram
)
2221 char *actual_class_name
2222 = language_class_name_from_physname (cu
->language_defn
,
2224 if (actual_class_name
!= NULL
)
2227 = obsavestring (actual_class_name
,
2228 strlen (actual_class_name
),
2229 &cu
->comp_unit_obstack
);
2230 xfree (actual_class_name
);
2235 child_pdi
= child_pdi
->die_sibling
;
2240 /* Read a partial die corresponding to an enumeration type. */
2243 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2244 struct dwarf2_cu
*cu
)
2246 struct objfile
*objfile
= cu
->objfile
;
2247 bfd
*abfd
= objfile
->obfd
;
2248 struct partial_die_info
*pdi
;
2250 if (enum_pdi
->name
!= NULL
)
2251 add_partial_symbol (enum_pdi
, cu
);
2253 pdi
= enum_pdi
->die_child
;
2256 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2257 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2259 add_partial_symbol (pdi
, cu
);
2260 pdi
= pdi
->die_sibling
;
2264 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2265 Return the corresponding abbrev, or NULL if the number is zero (indicating
2266 an empty DIE). In either case *BYTES_READ will be set to the length of
2267 the initial number. */
2269 static struct abbrev_info
*
2270 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2271 struct dwarf2_cu
*cu
)
2273 bfd
*abfd
= cu
->objfile
->obfd
;
2274 unsigned int abbrev_number
;
2275 struct abbrev_info
*abbrev
;
2277 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2279 if (abbrev_number
== 0)
2282 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2285 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2286 bfd_get_filename (abfd
));
2292 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2293 pointer to the end of a series of DIEs, terminated by an empty
2294 DIE. Any children of the skipped DIEs will also be skipped. */
2297 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2299 struct abbrev_info
*abbrev
;
2300 unsigned int bytes_read
;
2304 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2306 return info_ptr
+ bytes_read
;
2308 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2312 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2313 should point just after the initial uleb128 of a DIE, and the
2314 abbrev corresponding to that skipped uleb128 should be passed in
2315 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2319 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2320 struct dwarf2_cu
*cu
)
2322 unsigned int bytes_read
;
2323 struct attribute attr
;
2324 bfd
*abfd
= cu
->objfile
->obfd
;
2325 unsigned int form
, i
;
2327 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2329 /* The only abbrev we care about is DW_AT_sibling. */
2330 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2332 read_attribute (&attr
, &abbrev
->attrs
[i
],
2333 abfd
, info_ptr
, cu
);
2334 if (attr
.form
== DW_FORM_ref_addr
)
2335 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2337 return dwarf2_per_objfile
->info_buffer
2338 + dwarf2_get_ref_die_offset (&attr
, cu
);
2341 /* If it isn't DW_AT_sibling, skip this attribute. */
2342 form
= abbrev
->attrs
[i
].form
;
2347 case DW_FORM_ref_addr
:
2348 info_ptr
+= cu
->header
.addr_size
;
2367 case DW_FORM_string
:
2368 read_string (abfd
, info_ptr
, &bytes_read
);
2369 info_ptr
+= bytes_read
;
2372 info_ptr
+= cu
->header
.offset_size
;
2375 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2376 info_ptr
+= bytes_read
;
2378 case DW_FORM_block1
:
2379 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2381 case DW_FORM_block2
:
2382 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2384 case DW_FORM_block4
:
2385 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2389 case DW_FORM_ref_udata
:
2390 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2392 case DW_FORM_indirect
:
2393 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2394 info_ptr
+= bytes_read
;
2395 /* We need to continue parsing from here, so just go back to
2397 goto skip_attribute
;
2400 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2401 dwarf_form_name (form
),
2402 bfd_get_filename (abfd
));
2406 if (abbrev
->has_children
)
2407 return skip_children (info_ptr
, cu
);
2412 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2413 the next DIE after ORIG_PDI. */
2416 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2417 bfd
*abfd
, struct dwarf2_cu
*cu
)
2419 /* Do we know the sibling already? */
2421 if (orig_pdi
->sibling
)
2422 return orig_pdi
->sibling
;
2424 /* Are there any children to deal with? */
2426 if (!orig_pdi
->has_children
)
2429 /* Skip the children the long way. */
2431 return skip_children (info_ptr
, cu
);
2434 /* Expand this partial symbol table into a full symbol table. */
2437 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2439 /* FIXME: This is barely more than a stub. */
2444 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2450 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2451 gdb_flush (gdb_stdout
);
2454 /* Restore our global data. */
2455 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2456 dwarf2_objfile_data_key
);
2458 psymtab_to_symtab_1 (pst
);
2460 /* Finish up the debug error message. */
2462 printf_filtered (_("done.\n"));
2467 /* Add PER_CU to the queue. */
2470 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2472 struct dwarf2_queue_item
*item
;
2475 item
= xmalloc (sizeof (*item
));
2476 item
->per_cu
= per_cu
;
2479 if (dwarf2_queue
== NULL
)
2480 dwarf2_queue
= item
;
2482 dwarf2_queue_tail
->next
= item
;
2484 dwarf2_queue_tail
= item
;
2487 /* Process the queue. */
2490 process_queue (struct objfile
*objfile
)
2492 struct dwarf2_queue_item
*item
, *next_item
;
2494 /* Initially, there is just one item on the queue. Load its DIEs,
2495 and the DIEs of any other compilation units it requires,
2498 for (item
= dwarf2_queue
; item
!= NULL
; item
= item
->next
)
2500 /* Read in this compilation unit. This may add new items to
2501 the end of the queue. */
2502 load_full_comp_unit (item
->per_cu
, objfile
);
2504 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2505 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2507 /* If this compilation unit has already had full symbols created,
2508 reset the TYPE fields in each DIE. */
2509 if (item
->per_cu
->type_hash
)
2510 reset_die_and_siblings_types (item
->per_cu
->cu
->dies
,
2514 /* Now everything left on the queue needs to be read in. Process
2515 them, one at a time, removing from the queue as we finish. */
2516 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2518 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2519 process_full_comp_unit (item
->per_cu
);
2521 item
->per_cu
->queued
= 0;
2522 next_item
= item
->next
;
2526 dwarf2_queue_tail
= NULL
;
2529 /* Free all allocated queue entries. This function only releases anything if
2530 an error was thrown; if the queue was processed then it would have been
2531 freed as we went along. */
2534 dwarf2_release_queue (void *dummy
)
2536 struct dwarf2_queue_item
*item
, *last
;
2538 item
= dwarf2_queue
;
2541 /* Anything still marked queued is likely to be in an
2542 inconsistent state, so discard it. */
2543 if (item
->per_cu
->queued
)
2545 if (item
->per_cu
->cu
!= NULL
)
2546 free_one_cached_comp_unit (item
->per_cu
->cu
);
2547 item
->per_cu
->queued
= 0;
2555 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2558 /* Read in full symbols for PST, and anything it depends on. */
2561 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2563 struct dwarf2_per_cu_data
*per_cu
;
2564 struct cleanup
*back_to
;
2567 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2568 if (!pst
->dependencies
[i
]->readin
)
2570 /* Inform about additional files that need to be read in. */
2573 /* FIXME: i18n: Need to make this a single string. */
2574 fputs_filtered (" ", gdb_stdout
);
2576 fputs_filtered ("and ", gdb_stdout
);
2578 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2579 wrap_here (""); /* Flush output */
2580 gdb_flush (gdb_stdout
);
2582 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2585 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2589 /* It's an include file, no symbols to read for it.
2590 Everything is in the parent symtab. */
2595 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2597 queue_comp_unit (per_cu
);
2599 process_queue (pst
->objfile
);
2601 /* Age the cache, releasing compilation units that have not
2602 been used recently. */
2603 age_cached_comp_units ();
2605 do_cleanups (back_to
);
2608 /* Load the DIEs associated with PST and PER_CU into memory. */
2610 static struct dwarf2_cu
*
2611 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2613 bfd
*abfd
= objfile
->obfd
;
2614 struct dwarf2_cu
*cu
;
2615 unsigned long offset
;
2617 struct cleanup
*back_to
, *free_cu_cleanup
;
2618 struct attribute
*attr
;
2621 /* Set local variables from the partial symbol table info. */
2622 offset
= per_cu
->offset
;
2624 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2626 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2627 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2629 /* If an error occurs while loading, release our storage. */
2630 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2632 cu
->objfile
= objfile
;
2634 /* read in the comp_unit header */
2635 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2637 /* Read the abbrevs for this compilation unit */
2638 dwarf2_read_abbrevs (abfd
, cu
);
2639 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2641 cu
->header
.offset
= offset
;
2643 cu
->per_cu
= per_cu
;
2646 /* We use this obstack for block values in dwarf_alloc_block. */
2647 obstack_init (&cu
->comp_unit_obstack
);
2649 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2651 /* We try not to read any attributes in this function, because not
2652 all objfiles needed for references have been loaded yet, and symbol
2653 table processing isn't initialized. But we have to set the CU language,
2654 or we won't be able to build types correctly. */
2655 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2657 set_cu_language (DW_UNSND (attr
), cu
);
2659 set_cu_language (language_minimal
, cu
);
2661 do_cleanups (back_to
);
2663 /* We've successfully allocated this compilation unit. Let our caller
2664 clean it up when finished with it. */
2665 discard_cleanups (free_cu_cleanup
);
2670 /* Generate full symbol information for PST and CU, whose DIEs have
2671 already been loaded into memory. */
2674 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2676 struct partial_symtab
*pst
= per_cu
->psymtab
;
2677 struct dwarf2_cu
*cu
= per_cu
->cu
;
2678 struct objfile
*objfile
= pst
->objfile
;
2679 bfd
*abfd
= objfile
->obfd
;
2680 CORE_ADDR lowpc
, highpc
;
2681 struct symtab
*symtab
;
2682 struct cleanup
*back_to
;
2683 struct attribute
*attr
;
2686 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2688 /* We're in the global namespace. */
2689 processing_current_prefix
= "";
2692 back_to
= make_cleanup (really_free_pendings
, NULL
);
2694 cu
->list_in_scope
= &file_symbols
;
2696 /* Find the base address of the compilation unit for range lists and
2697 location lists. It will normally be specified by DW_AT_low_pc.
2698 In DWARF-3 draft 4, the base address could be overridden by
2699 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2700 compilation units with discontinuous ranges. */
2702 cu
->header
.base_known
= 0;
2703 cu
->header
.base_address
= 0;
2705 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2708 cu
->header
.base_address
= DW_ADDR (attr
);
2709 cu
->header
.base_known
= 1;
2713 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2716 cu
->header
.base_address
= DW_ADDR (attr
);
2717 cu
->header
.base_known
= 1;
2721 /* Do line number decoding in read_file_scope () */
2722 process_die (cu
->dies
, cu
);
2724 /* Some compilers don't define a DW_AT_high_pc attribute for the
2725 compilation unit. If the DW_AT_high_pc is missing, synthesize
2726 it, by scanning the DIE's below the compilation unit. */
2727 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2729 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2731 /* Set symtab language to language from DW_AT_language.
2732 If the compilation is from a C file generated by language preprocessors,
2733 do not set the language if it was already deduced by start_subfile. */
2735 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2737 symtab
->language
= cu
->language
;
2739 pst
->symtab
= symtab
;
2742 do_cleanups (back_to
);
2745 /* Process a die and its children. */
2748 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2752 case DW_TAG_padding
:
2754 case DW_TAG_compile_unit
:
2755 read_file_scope (die
, cu
);
2757 case DW_TAG_subprogram
:
2758 read_subroutine_type (die
, cu
);
2759 read_func_scope (die
, cu
);
2761 case DW_TAG_inlined_subroutine
:
2762 /* FIXME: These are ignored for now.
2763 They could be used to set breakpoints on all inlined instances
2764 of a function and make GDB `next' properly over inlined functions. */
2766 case DW_TAG_lexical_block
:
2767 case DW_TAG_try_block
:
2768 case DW_TAG_catch_block
:
2769 read_lexical_block_scope (die
, cu
);
2771 case DW_TAG_class_type
:
2772 case DW_TAG_interface_type
:
2773 case DW_TAG_structure_type
:
2774 case DW_TAG_union_type
:
2775 read_structure_type (die
, cu
);
2776 process_structure_scope (die
, cu
);
2778 case DW_TAG_enumeration_type
:
2779 read_enumeration_type (die
, cu
);
2780 process_enumeration_scope (die
, cu
);
2783 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2784 a symbol or process any children. Therefore it doesn't do anything
2785 that won't be done on-demand by read_type_die. */
2786 case DW_TAG_subroutine_type
:
2787 read_subroutine_type (die
, cu
);
2789 case DW_TAG_set_type
:
2790 read_set_type (die
, cu
);
2792 case DW_TAG_array_type
:
2793 read_array_type (die
, cu
);
2795 case DW_TAG_pointer_type
:
2796 read_tag_pointer_type (die
, cu
);
2798 case DW_TAG_ptr_to_member_type
:
2799 read_tag_ptr_to_member_type (die
, cu
);
2801 case DW_TAG_reference_type
:
2802 read_tag_reference_type (die
, cu
);
2804 case DW_TAG_string_type
:
2805 read_tag_string_type (die
, cu
);
2809 case DW_TAG_base_type
:
2810 read_base_type (die
, cu
);
2811 /* Add a typedef symbol for the type definition, if it has a
2813 new_symbol (die
, die
->type
, cu
);
2815 case DW_TAG_subrange_type
:
2816 read_subrange_type (die
, cu
);
2817 /* Add a typedef symbol for the type definition, if it has a
2819 new_symbol (die
, die
->type
, cu
);
2821 case DW_TAG_common_block
:
2822 read_common_block (die
, cu
);
2824 case DW_TAG_common_inclusion
:
2826 case DW_TAG_namespace
:
2827 processing_has_namespace_info
= 1;
2828 read_namespace (die
, cu
);
2830 case DW_TAG_imported_declaration
:
2831 case DW_TAG_imported_module
:
2832 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2833 information contained in these. DW_TAG_imported_declaration
2834 dies shouldn't have children; DW_TAG_imported_module dies
2835 shouldn't in the C++ case, but conceivably could in the
2836 Fortran case, so we'll have to replace this gdb_assert if
2837 Fortran compilers start generating that info. */
2838 processing_has_namespace_info
= 1;
2839 gdb_assert (die
->child
== NULL
);
2842 new_symbol (die
, NULL
, cu
);
2848 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2850 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2854 free_cu_line_header (void *arg
)
2856 struct dwarf2_cu
*cu
= arg
;
2858 free_line_header (cu
->line_header
);
2859 cu
->line_header
= NULL
;
2863 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2865 struct objfile
*objfile
= cu
->objfile
;
2866 struct comp_unit_head
*cu_header
= &cu
->header
;
2867 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2868 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2869 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2870 struct attribute
*attr
;
2872 char *comp_dir
= NULL
;
2873 struct die_info
*child_die
;
2874 bfd
*abfd
= objfile
->obfd
;
2875 struct line_header
*line_header
= 0;
2878 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2880 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2882 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2883 from finish_block. */
2884 if (lowpc
== ((CORE_ADDR
) -1))
2889 /* Find the filename. Do not use dwarf2_name here, since the filename
2890 is not a source language identifier. */
2891 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2894 name
= DW_STRING (attr
);
2897 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2899 comp_dir
= DW_STRING (attr
);
2900 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2902 comp_dir
= ldirname (name
);
2903 if (comp_dir
!= NULL
)
2904 make_cleanup (xfree
, comp_dir
);
2906 if (comp_dir
!= NULL
)
2908 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2909 directory, get rid of it. */
2910 char *cp
= strchr (comp_dir
, ':');
2912 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2919 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2922 set_cu_language (DW_UNSND (attr
), cu
);
2925 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2927 cu
->producer
= DW_STRING (attr
);
2929 /* We assume that we're processing GCC output. */
2930 processing_gcc_compilation
= 2;
2932 start_symtab (name
, comp_dir
, lowpc
);
2933 record_debugformat ("DWARF 2");
2934 record_producer (cu
->producer
);
2936 initialize_cu_func_list (cu
);
2938 /* Decode line number information if present. We do this before
2939 processing child DIEs, so that the line header table is available
2940 for DW_AT_decl_file. */
2941 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2944 unsigned int line_offset
= DW_UNSND (attr
);
2945 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2948 cu
->line_header
= line_header
;
2949 make_cleanup (free_cu_line_header
, cu
);
2950 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2954 /* Process all dies in compilation unit. */
2955 if (die
->child
!= NULL
)
2957 child_die
= die
->child
;
2958 while (child_die
&& child_die
->tag
)
2960 process_die (child_die
, cu
);
2961 child_die
= sibling_die (child_die
);
2965 /* Decode macro information, if present. Dwarf 2 macro information
2966 refers to information in the line number info statement program
2967 header, so we can only read it if we've read the header
2969 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2970 if (attr
&& line_header
)
2972 unsigned int macro_offset
= DW_UNSND (attr
);
2973 dwarf_decode_macros (line_header
, macro_offset
,
2974 comp_dir
, abfd
, cu
);
2976 do_cleanups (back_to
);
2980 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2981 struct dwarf2_cu
*cu
)
2983 struct function_range
*thisfn
;
2985 thisfn
= (struct function_range
*)
2986 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2987 thisfn
->name
= name
;
2988 thisfn
->lowpc
= lowpc
;
2989 thisfn
->highpc
= highpc
;
2990 thisfn
->seen_line
= 0;
2991 thisfn
->next
= NULL
;
2993 if (cu
->last_fn
== NULL
)
2994 cu
->first_fn
= thisfn
;
2996 cu
->last_fn
->next
= thisfn
;
2998 cu
->last_fn
= thisfn
;
3002 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3004 struct objfile
*objfile
= cu
->objfile
;
3005 struct context_stack
*new;
3008 struct die_info
*child_die
;
3009 struct attribute
*attr
;
3011 const char *previous_prefix
= processing_current_prefix
;
3012 struct cleanup
*back_to
= NULL
;
3014 struct block
*block
;
3016 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3018 name
= dwarf2_linkage_name (die
, cu
);
3020 /* Ignore functions with missing or empty names and functions with
3021 missing or invalid low and high pc attributes. */
3022 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3025 if (cu
->language
== language_cplus
3026 || cu
->language
== language_java
)
3028 struct die_info
*spec_die
= die_specification (die
, cu
);
3030 /* NOTE: carlton/2004-01-23: We have to be careful in the
3031 presence of DW_AT_specification. For example, with GCC 3.4,
3036 // Definition of N::foo.
3040 then we'll have a tree of DIEs like this:
3042 1: DW_TAG_compile_unit
3043 2: DW_TAG_namespace // N
3044 3: DW_TAG_subprogram // declaration of N::foo
3045 4: DW_TAG_subprogram // definition of N::foo
3046 DW_AT_specification // refers to die #3
3048 Thus, when processing die #4, we have to pretend that we're
3049 in the context of its DW_AT_specification, namely the contex
3052 if (spec_die
!= NULL
)
3054 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3055 processing_current_prefix
= specification_prefix
;
3056 back_to
= make_cleanup (xfree
, specification_prefix
);
3063 /* Record the function range for dwarf_decode_lines. */
3064 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3066 new = push_context (0, lowpc
);
3067 new->name
= new_symbol (die
, die
->type
, cu
);
3069 /* If there is a location expression for DW_AT_frame_base, record
3071 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3073 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3074 expression is being recorded directly in the function's symbol
3075 and not in a separate frame-base object. I guess this hack is
3076 to avoid adding some sort of frame-base adjunct/annex to the
3077 function's symbol :-(. The problem with doing this is that it
3078 results in a function symbol with a location expression that
3079 has nothing to do with the location of the function, ouch! The
3080 relationship should be: a function's symbol has-a frame base; a
3081 frame-base has-a location expression. */
3082 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3084 cu
->list_in_scope
= &local_symbols
;
3086 if (die
->child
!= NULL
)
3088 child_die
= die
->child
;
3089 while (child_die
&& child_die
->tag
)
3091 process_die (child_die
, cu
);
3092 child_die
= sibling_die (child_die
);
3096 new = pop_context ();
3097 /* Make a block for the local symbols within. */
3098 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3099 lowpc
, highpc
, objfile
);
3101 /* If we have address ranges, record them. */
3102 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3104 /* In C++, we can have functions nested inside functions (e.g., when
3105 a function declares a class that has methods). This means that
3106 when we finish processing a function scope, we may need to go
3107 back to building a containing block's symbol lists. */
3108 local_symbols
= new->locals
;
3109 param_symbols
= new->params
;
3111 /* If we've finished processing a top-level function, subsequent
3112 symbols go in the file symbol list. */
3113 if (outermost_context_p ())
3114 cu
->list_in_scope
= &file_symbols
;
3116 processing_current_prefix
= previous_prefix
;
3117 if (back_to
!= NULL
)
3118 do_cleanups (back_to
);
3121 /* Process all the DIES contained within a lexical block scope. Start
3122 a new scope, process the dies, and then close the scope. */
3125 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3127 struct objfile
*objfile
= cu
->objfile
;
3128 struct context_stack
*new;
3129 CORE_ADDR lowpc
, highpc
;
3130 struct die_info
*child_die
;
3133 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3135 /* Ignore blocks with missing or invalid low and high pc attributes. */
3136 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3137 as multiple lexical blocks? Handling children in a sane way would
3138 be nasty. Might be easier to properly extend generic blocks to
3140 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3145 push_context (0, lowpc
);
3146 if (die
->child
!= NULL
)
3148 child_die
= die
->child
;
3149 while (child_die
&& child_die
->tag
)
3151 process_die (child_die
, cu
);
3152 child_die
= sibling_die (child_die
);
3155 new = pop_context ();
3157 if (local_symbols
!= NULL
)
3160 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3163 /* Note that recording ranges after traversing children, as we
3164 do here, means that recording a parent's ranges entails
3165 walking across all its children's ranges as they appear in
3166 the address map, which is quadratic behavior.
3168 It would be nicer to record the parent's ranges before
3169 traversing its children, simply overriding whatever you find
3170 there. But since we don't even decide whether to create a
3171 block until after we've traversed its children, that's hard
3173 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3175 local_symbols
= new->locals
;
3178 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3179 Return 1 if the attributes are present and valid, otherwise, return 0.
3180 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3183 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3184 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3185 struct partial_symtab
*ranges_pst
)
3187 struct objfile
*objfile
= cu
->objfile
;
3188 struct comp_unit_head
*cu_header
= &cu
->header
;
3189 bfd
*obfd
= objfile
->obfd
;
3190 unsigned int addr_size
= cu_header
->addr_size
;
3191 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3192 /* Base address selection entry. */
3203 found_base
= cu_header
->base_known
;
3204 base
= cu_header
->base_address
;
3206 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3208 complaint (&symfile_complaints
,
3209 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3213 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3215 /* Read in the largest possible address. */
3216 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3217 if ((marker
& mask
) == mask
)
3219 /* If we found the largest possible address, then
3220 read the base address. */
3221 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3222 buffer
+= 2 * addr_size
;
3223 offset
+= 2 * addr_size
;
3229 if (ranges_pst
!= NULL
)
3230 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3234 CORE_ADDR range_beginning
, range_end
;
3236 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3237 buffer
+= addr_size
;
3238 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3239 buffer
+= addr_size
;
3240 offset
+= 2 * addr_size
;
3242 /* An end of list marker is a pair of zero addresses. */
3243 if (range_beginning
== 0 && range_end
== 0)
3244 /* Found the end of list entry. */
3247 /* Each base address selection entry is a pair of 2 values.
3248 The first is the largest possible address, the second is
3249 the base address. Check for a base address here. */
3250 if ((range_beginning
& mask
) == mask
)
3252 /* If we found the largest possible address, then
3253 read the base address. */
3254 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3261 /* We have no valid base address for the ranges
3263 complaint (&symfile_complaints
,
3264 _("Invalid .debug_ranges data (no base address)"));
3268 range_beginning
+= base
;
3271 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3272 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3273 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3276 /* FIXME: This is recording everything as a low-high
3277 segment of consecutive addresses. We should have a
3278 data structure for discontiguous block ranges
3282 low
= range_beginning
;
3288 if (range_beginning
< low
)
3289 low
= range_beginning
;
3290 if (range_end
> high
)
3296 /* If the first entry is an end-of-list marker, the range
3297 describes an empty scope, i.e. no instructions. */
3303 *high_return
= high
;
3307 /* Get low and high pc attributes from a die. Return 1 if the attributes
3308 are present and valid, otherwise, return 0. Return -1 if the range is
3309 discontinuous, i.e. derived from DW_AT_ranges information. */
3311 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3312 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3314 struct attribute
*attr
;
3319 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3322 high
= DW_ADDR (attr
);
3323 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3325 low
= DW_ADDR (attr
);
3327 /* Found high w/o low attribute. */
3330 /* Found consecutive range of addresses. */
3335 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3338 /* Value of the DW_AT_ranges attribute is the offset in the
3339 .debug_ranges section. */
3340 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3342 /* Found discontinuous range of addresses. */
3350 /* When using the GNU linker, .gnu.linkonce. sections are used to
3351 eliminate duplicate copies of functions and vtables and such.
3352 The linker will arbitrarily choose one and discard the others.
3353 The AT_*_pc values for such functions refer to local labels in
3354 these sections. If the section from that file was discarded, the
3355 labels are not in the output, so the relocs get a value of 0.
3356 If this is a discarded function, mark the pc bounds as invalid,
3357 so that GDB will ignore it. */
3358 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3366 /* Get the low and high pc's represented by the scope DIE, and store
3367 them in *LOWPC and *HIGHPC. If the correct values can't be
3368 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3371 get_scope_pc_bounds (struct die_info
*die
,
3372 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3373 struct dwarf2_cu
*cu
)
3375 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3376 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3377 CORE_ADDR current_low
, current_high
;
3379 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3381 best_low
= current_low
;
3382 best_high
= current_high
;
3386 struct die_info
*child
= die
->child
;
3388 while (child
&& child
->tag
)
3390 switch (child
->tag
) {
3391 case DW_TAG_subprogram
:
3392 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3394 best_low
= min (best_low
, current_low
);
3395 best_high
= max (best_high
, current_high
);
3398 case DW_TAG_namespace
:
3399 /* FIXME: carlton/2004-01-16: Should we do this for
3400 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3401 that current GCC's always emit the DIEs corresponding
3402 to definitions of methods of classes as children of a
3403 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3404 the DIEs giving the declarations, which could be
3405 anywhere). But I don't see any reason why the
3406 standards says that they have to be there. */
3407 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3409 if (current_low
!= ((CORE_ADDR
) -1))
3411 best_low
= min (best_low
, current_low
);
3412 best_high
= max (best_high
, current_high
);
3420 child
= sibling_die (child
);
3425 *highpc
= best_high
;
3428 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3431 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3432 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3434 struct attribute
*attr
;
3436 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3439 CORE_ADDR high
= DW_ADDR (attr
);
3440 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3443 CORE_ADDR low
= DW_ADDR (attr
);
3444 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3448 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3451 bfd
*obfd
= cu
->objfile
->obfd
;
3453 /* The value of the DW_AT_ranges attribute is the offset of the
3454 address range list in the .debug_ranges section. */
3455 unsigned long offset
= DW_UNSND (attr
);
3456 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3458 /* For some target architectures, but not others, the
3459 read_address function sign-extends the addresses it returns.
3460 To recognize base address selection entries, we need a
3462 unsigned int addr_size
= cu
->header
.addr_size
;
3463 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3465 /* The base address, to which the next pair is relative. Note
3466 that this 'base' is a DWARF concept: most entries in a range
3467 list are relative, to reduce the number of relocs against the
3468 debugging information. This is separate from this function's
3469 'baseaddr' argument, which GDB uses to relocate debugging
3470 information from a shared library based on the address at
3471 which the library was loaded. */
3472 CORE_ADDR base
= cu
->header
.base_address
;
3473 int base_known
= cu
->header
.base_known
;
3475 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3477 complaint (&symfile_complaints
,
3478 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3485 unsigned int bytes_read
;
3486 CORE_ADDR start
, end
;
3488 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3489 buffer
+= bytes_read
;
3490 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3491 buffer
+= bytes_read
;
3493 /* Did we find the end of the range list? */
3494 if (start
== 0 && end
== 0)
3497 /* Did we find a base address selection entry? */
3498 else if ((start
& base_select_mask
) == base_select_mask
)
3504 /* We found an ordinary address range. */
3509 complaint (&symfile_complaints
,
3510 _("Invalid .debug_ranges data (no base address)"));
3514 record_block_range (block
,
3515 baseaddr
+ base
+ start
,
3516 baseaddr
+ base
+ end
- 1);
3522 /* Add an aggregate field to the field list. */
3525 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3526 struct dwarf2_cu
*cu
)
3528 struct objfile
*objfile
= cu
->objfile
;
3529 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3530 struct nextfield
*new_field
;
3531 struct attribute
*attr
;
3533 char *fieldname
= "";
3535 /* Allocate a new field list entry and link it in. */
3536 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3537 make_cleanup (xfree
, new_field
);
3538 memset (new_field
, 0, sizeof (struct nextfield
));
3539 new_field
->next
= fip
->fields
;
3540 fip
->fields
= new_field
;
3543 /* Handle accessibility and virtuality of field.
3544 The default accessibility for members is public, the default
3545 accessibility for inheritance is private. */
3546 if (die
->tag
!= DW_TAG_inheritance
)
3547 new_field
->accessibility
= DW_ACCESS_public
;
3549 new_field
->accessibility
= DW_ACCESS_private
;
3550 new_field
->virtuality
= DW_VIRTUALITY_none
;
3552 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3554 new_field
->accessibility
= DW_UNSND (attr
);
3555 if (new_field
->accessibility
!= DW_ACCESS_public
)
3556 fip
->non_public_fields
= 1;
3557 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3559 new_field
->virtuality
= DW_UNSND (attr
);
3561 fp
= &new_field
->field
;
3563 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3565 /* Data member other than a C++ static data member. */
3567 /* Get type of field. */
3568 fp
->type
= die_type (die
, cu
);
3570 FIELD_STATIC_KIND (*fp
) = 0;
3572 /* Get bit size of field (zero if none). */
3573 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3576 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3580 FIELD_BITSIZE (*fp
) = 0;
3583 /* Get bit offset of field. */
3584 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3589 if (attr_form_is_section_offset (attr
))
3591 dwarf2_complex_location_expr_complaint ();
3594 else if (attr_form_is_constant (attr
))
3595 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3597 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3599 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3602 FIELD_BITPOS (*fp
) = 0;
3603 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3606 if (gdbarch_bits_big_endian (gdbarch
))
3608 /* For big endian bits, the DW_AT_bit_offset gives the
3609 additional bit offset from the MSB of the containing
3610 anonymous object to the MSB of the field. We don't
3611 have to do anything special since we don't need to
3612 know the size of the anonymous object. */
3613 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3617 /* For little endian bits, compute the bit offset to the
3618 MSB of the anonymous object, subtract off the number of
3619 bits from the MSB of the field to the MSB of the
3620 object, and then subtract off the number of bits of
3621 the field itself. The result is the bit offset of
3622 the LSB of the field. */
3624 int bit_offset
= DW_UNSND (attr
);
3626 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3629 /* The size of the anonymous object containing
3630 the bit field is explicit, so use the
3631 indicated size (in bytes). */
3632 anonymous_size
= DW_UNSND (attr
);
3636 /* The size of the anonymous object containing
3637 the bit field must be inferred from the type
3638 attribute of the data member containing the
3640 anonymous_size
= TYPE_LENGTH (fp
->type
);
3642 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3643 - bit_offset
- FIELD_BITSIZE (*fp
);
3647 /* Get name of field. */
3648 fieldname
= dwarf2_name (die
, cu
);
3649 if (fieldname
== NULL
)
3652 /* The name is already allocated along with this objfile, so we don't
3653 need to duplicate it for the type. */
3654 fp
->name
= fieldname
;
3656 /* Change accessibility for artificial fields (e.g. virtual table
3657 pointer or virtual base class pointer) to private. */
3658 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3660 new_field
->accessibility
= DW_ACCESS_private
;
3661 fip
->non_public_fields
= 1;
3664 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3666 /* C++ static member. */
3668 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3669 is a declaration, but all versions of G++ as of this writing
3670 (so through at least 3.2.1) incorrectly generate
3671 DW_TAG_variable tags. */
3675 /* Get name of field. */
3676 fieldname
= dwarf2_name (die
, cu
);
3677 if (fieldname
== NULL
)
3680 /* Get physical name. */
3681 physname
= dwarf2_linkage_name (die
, cu
);
3683 /* The name is already allocated along with this objfile, so we don't
3684 need to duplicate it for the type. */
3685 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3686 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3687 FIELD_NAME (*fp
) = fieldname
;
3689 else if (die
->tag
== DW_TAG_inheritance
)
3691 /* C++ base class field. */
3692 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3694 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3696 FIELD_BITSIZE (*fp
) = 0;
3697 FIELD_STATIC_KIND (*fp
) = 0;
3698 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3699 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3700 fip
->nbaseclasses
++;
3704 /* Create the vector of fields, and attach it to the type. */
3707 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3708 struct dwarf2_cu
*cu
)
3710 int nfields
= fip
->nfields
;
3712 /* Record the field count, allocate space for the array of fields,
3713 and create blank accessibility bitfields if necessary. */
3714 TYPE_NFIELDS (type
) = nfields
;
3715 TYPE_FIELDS (type
) = (struct field
*)
3716 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3717 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3719 if (fip
->non_public_fields
)
3721 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3723 TYPE_FIELD_PRIVATE_BITS (type
) =
3724 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3725 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3727 TYPE_FIELD_PROTECTED_BITS (type
) =
3728 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3729 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3731 TYPE_FIELD_IGNORE_BITS (type
) =
3732 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3733 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3736 /* If the type has baseclasses, allocate and clear a bit vector for
3737 TYPE_FIELD_VIRTUAL_BITS. */
3738 if (fip
->nbaseclasses
)
3740 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3741 unsigned char *pointer
;
3743 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3744 pointer
= TYPE_ALLOC (type
, num_bytes
);
3745 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3746 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3747 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3750 /* Copy the saved-up fields into the field vector. Start from the head
3751 of the list, adding to the tail of the field array, so that they end
3752 up in the same order in the array in which they were added to the list. */
3753 while (nfields
-- > 0)
3755 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3756 switch (fip
->fields
->accessibility
)
3758 case DW_ACCESS_private
:
3759 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3762 case DW_ACCESS_protected
:
3763 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3766 case DW_ACCESS_public
:
3770 /* Unknown accessibility. Complain and treat it as public. */
3772 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3773 fip
->fields
->accessibility
);
3777 if (nfields
< fip
->nbaseclasses
)
3779 switch (fip
->fields
->virtuality
)
3781 case DW_VIRTUALITY_virtual
:
3782 case DW_VIRTUALITY_pure_virtual
:
3783 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3787 fip
->fields
= fip
->fields
->next
;
3791 /* Add a member function to the proper fieldlist. */
3794 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3795 struct type
*type
, struct dwarf2_cu
*cu
)
3797 struct objfile
*objfile
= cu
->objfile
;
3798 struct attribute
*attr
;
3799 struct fnfieldlist
*flp
;
3801 struct fn_field
*fnp
;
3804 struct nextfnfield
*new_fnfield
;
3806 /* Get name of member function. */
3807 fieldname
= dwarf2_name (die
, cu
);
3808 if (fieldname
== NULL
)
3811 /* Get the mangled name. */
3812 physname
= dwarf2_linkage_name (die
, cu
);
3814 /* Look up member function name in fieldlist. */
3815 for (i
= 0; i
< fip
->nfnfields
; i
++)
3817 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3821 /* Create new list element if necessary. */
3822 if (i
< fip
->nfnfields
)
3823 flp
= &fip
->fnfieldlists
[i
];
3826 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3828 fip
->fnfieldlists
= (struct fnfieldlist
*)
3829 xrealloc (fip
->fnfieldlists
,
3830 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3831 * sizeof (struct fnfieldlist
));
3832 if (fip
->nfnfields
== 0)
3833 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3835 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3836 flp
->name
= fieldname
;
3842 /* Create a new member function field and chain it to the field list
3844 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3845 make_cleanup (xfree
, new_fnfield
);
3846 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3847 new_fnfield
->next
= flp
->head
;
3848 flp
->head
= new_fnfield
;
3851 /* Fill in the member function field info. */
3852 fnp
= &new_fnfield
->fnfield
;
3853 /* The name is already allocated along with this objfile, so we don't
3854 need to duplicate it for the type. */
3855 fnp
->physname
= physname
? physname
: "";
3856 fnp
->type
= alloc_type (objfile
);
3857 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3859 int nparams
= TYPE_NFIELDS (die
->type
);
3861 /* TYPE is the domain of this method, and DIE->TYPE is the type
3862 of the method itself (TYPE_CODE_METHOD). */
3863 smash_to_method_type (fnp
->type
, type
,
3864 TYPE_TARGET_TYPE (die
->type
),
3865 TYPE_FIELDS (die
->type
),
3866 TYPE_NFIELDS (die
->type
),
3867 TYPE_VARARGS (die
->type
));
3869 /* Handle static member functions.
3870 Dwarf2 has no clean way to discern C++ static and non-static
3871 member functions. G++ helps GDB by marking the first
3872 parameter for non-static member functions (which is the
3873 this pointer) as artificial. We obtain this information
3874 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3875 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3876 fnp
->voffset
= VOFFSET_STATIC
;
3879 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3882 /* Get fcontext from DW_AT_containing_type if present. */
3883 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3884 fnp
->fcontext
= die_containing_type (die
, cu
);
3886 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3887 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3889 /* Get accessibility. */
3890 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3893 switch (DW_UNSND (attr
))
3895 case DW_ACCESS_private
:
3896 fnp
->is_private
= 1;
3898 case DW_ACCESS_protected
:
3899 fnp
->is_protected
= 1;
3904 /* Check for artificial methods. */
3905 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3906 if (attr
&& DW_UNSND (attr
) != 0)
3907 fnp
->is_artificial
= 1;
3909 /* Get index in virtual function table if it is a virtual member function. */
3910 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3913 /* Support the .debug_loc offsets */
3914 if (attr_form_is_block (attr
))
3916 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3918 else if (attr_form_is_section_offset (attr
))
3920 dwarf2_complex_location_expr_complaint ();
3924 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3930 /* Create the vector of member function fields, and attach it to the type. */
3933 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3934 struct dwarf2_cu
*cu
)
3936 struct fnfieldlist
*flp
;
3937 int total_length
= 0;
3940 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3941 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3942 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3944 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3946 struct nextfnfield
*nfp
= flp
->head
;
3947 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3950 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3951 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3952 fn_flp
->fn_fields
= (struct fn_field
*)
3953 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3954 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3955 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3957 total_length
+= flp
->length
;
3960 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3961 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3964 /* Returns non-zero if NAME is the name of a vtable member in CU's
3965 language, zero otherwise. */
3967 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3969 static const char vptr
[] = "_vptr";
3970 static const char vtable
[] = "vtable";
3972 /* Look for the C++ and Java forms of the vtable. */
3973 if ((cu
->language
== language_java
3974 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3975 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3976 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3982 /* GCC outputs unnamed structures that are really pointers to member
3983 functions, with the ABI-specified layout. If DIE (from CU) describes
3984 such a structure, set its type, and return nonzero. Otherwise return
3987 GCC shouldn't do this; it should just output pointer to member DIEs.
3988 This is GCC PR debug/28767. */
3991 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3993 struct objfile
*objfile
= cu
->objfile
;
3995 struct die_info
*pfn_die
, *delta_die
;
3996 struct attribute
*pfn_name
, *delta_name
;
3997 struct type
*pfn_type
, *domain_type
;
3999 /* Check for a structure with no name and two children. */
4000 if (die
->tag
!= DW_TAG_structure_type
4001 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4002 || die
->child
== NULL
4003 || die
->child
->sibling
== NULL
4004 || (die
->child
->sibling
->sibling
!= NULL
4005 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4008 /* Check for __pfn and __delta members. */
4009 pfn_die
= die
->child
;
4010 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4011 if (pfn_die
->tag
!= DW_TAG_member
4013 || DW_STRING (pfn_name
) == NULL
4014 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4017 delta_die
= pfn_die
->sibling
;
4018 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4019 if (delta_die
->tag
!= DW_TAG_member
4020 || delta_name
== NULL
4021 || DW_STRING (delta_name
) == NULL
4022 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4025 /* Find the type of the method. */
4026 pfn_type
= die_type (pfn_die
, cu
);
4027 if (pfn_type
== NULL
4028 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4029 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4032 /* Look for the "this" argument. */
4033 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4034 if (TYPE_NFIELDS (pfn_type
) == 0
4035 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4038 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4039 type
= alloc_type (objfile
);
4040 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4041 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4042 TYPE_VARARGS (pfn_type
));
4043 type
= lookup_methodptr_type (type
);
4044 set_die_type (die
, type
, cu
);
4049 /* Called when we find the DIE that starts a structure or union scope
4050 (definition) to process all dies that define the members of the
4053 NOTE: we need to call struct_type regardless of whether or not the
4054 DIE has an at_name attribute, since it might be an anonymous
4055 structure or union. This gets the type entered into our set of
4058 However, if the structure is incomplete (an opaque struct/union)
4059 then suppress creating a symbol table entry for it since gdb only
4060 wants to find the one with the complete definition. Note that if
4061 it is complete, we just call new_symbol, which does it's own
4062 checking about whether the struct/union is anonymous or not (and
4063 suppresses creating a symbol table entry itself). */
4066 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4068 struct objfile
*objfile
= cu
->objfile
;
4070 struct attribute
*attr
;
4071 const char *previous_prefix
= processing_current_prefix
;
4072 struct cleanup
*back_to
= NULL
;
4078 if (quirk_gcc_member_function_pointer (die
, cu
))
4081 type
= alloc_type (objfile
);
4082 INIT_CPLUS_SPECIFIC (type
);
4083 name
= dwarf2_name (die
, cu
);
4086 if (cu
->language
== language_cplus
4087 || cu
->language
== language_java
)
4089 char *new_prefix
= determine_class_name (die
, cu
);
4090 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
4091 strlen (new_prefix
),
4092 &objfile
->objfile_obstack
);
4093 back_to
= make_cleanup (xfree
, new_prefix
);
4094 processing_current_prefix
= new_prefix
;
4098 /* The name is already allocated along with this objfile, so
4099 we don't need to duplicate it for the type. */
4100 TYPE_TAG_NAME (type
) = name
;
4104 if (die
->tag
== DW_TAG_structure_type
)
4106 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4108 else if (die
->tag
== DW_TAG_union_type
)
4110 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4114 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4116 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4119 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4122 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4126 TYPE_LENGTH (type
) = 0;
4129 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB_SUPPORTED
;
4130 if (die_is_declaration (die
, cu
))
4131 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4133 /* We need to add the type field to the die immediately so we don't
4134 infinitely recurse when dealing with pointers to the structure
4135 type within the structure itself. */
4136 set_die_type (die
, type
, cu
);
4138 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4140 struct field_info fi
;
4141 struct die_info
*child_die
;
4142 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
4144 memset (&fi
, 0, sizeof (struct field_info
));
4146 child_die
= die
->child
;
4148 while (child_die
&& child_die
->tag
)
4150 if (child_die
->tag
== DW_TAG_member
4151 || child_die
->tag
== DW_TAG_variable
)
4153 /* NOTE: carlton/2002-11-05: A C++ static data member
4154 should be a DW_TAG_member that is a declaration, but
4155 all versions of G++ as of this writing (so through at
4156 least 3.2.1) incorrectly generate DW_TAG_variable
4157 tags for them instead. */
4158 dwarf2_add_field (&fi
, child_die
, cu
);
4160 else if (child_die
->tag
== DW_TAG_subprogram
)
4162 /* C++ member function. */
4163 read_type_die (child_die
, cu
);
4164 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4166 else if (child_die
->tag
== DW_TAG_inheritance
)
4168 /* C++ base class field. */
4169 dwarf2_add_field (&fi
, child_die
, cu
);
4171 child_die
= sibling_die (child_die
);
4174 /* Attach fields and member functions to the type. */
4176 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4179 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4181 /* Get the type which refers to the base class (possibly this
4182 class itself) which contains the vtable pointer for the current
4183 class from the DW_AT_containing_type attribute. */
4185 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4187 struct type
*t
= die_containing_type (die
, cu
);
4189 TYPE_VPTR_BASETYPE (type
) = t
;
4194 /* Our own class provides vtbl ptr. */
4195 for (i
= TYPE_NFIELDS (t
) - 1;
4196 i
>= TYPE_N_BASECLASSES (t
);
4199 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4201 if (is_vtable_name (fieldname
, cu
))
4203 TYPE_VPTR_FIELDNO (type
) = i
;
4208 /* Complain if virtual function table field not found. */
4209 if (i
< TYPE_N_BASECLASSES (t
))
4210 complaint (&symfile_complaints
,
4211 _("virtual function table pointer not found when defining class '%s'"),
4212 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4217 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4220 else if (cu
->producer
4221 && strncmp (cu
->producer
,
4222 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4224 /* The IBM XLC compiler does not provide direct indication
4225 of the containing type, but the vtable pointer is
4226 always named __vfp. */
4230 for (i
= TYPE_NFIELDS (type
) - 1;
4231 i
>= TYPE_N_BASECLASSES (type
);
4234 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4236 TYPE_VPTR_FIELDNO (type
) = i
;
4237 TYPE_VPTR_BASETYPE (type
) = type
;
4244 do_cleanups (back_to
);
4247 processing_current_prefix
= previous_prefix
;
4248 if (back_to
!= NULL
)
4249 do_cleanups (back_to
);
4253 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4255 struct objfile
*objfile
= cu
->objfile
;
4256 const char *previous_prefix
= processing_current_prefix
;
4257 struct die_info
*child_die
= die
->child
;
4259 if (TYPE_TAG_NAME (die
->type
) != NULL
)
4260 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
4262 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4263 snapshots) has been known to create a die giving a declaration
4264 for a class that has, as a child, a die giving a definition for a
4265 nested class. So we have to process our children even if the
4266 current die is a declaration. Normally, of course, a declaration
4267 won't have any children at all. */
4269 while (child_die
!= NULL
&& child_die
->tag
)
4271 if (child_die
->tag
== DW_TAG_member
4272 || child_die
->tag
== DW_TAG_variable
4273 || child_die
->tag
== DW_TAG_inheritance
)
4278 process_die (child_die
, cu
);
4280 child_die
= sibling_die (child_die
);
4283 /* Do not consider external references. According to the DWARF standard,
4284 these DIEs are identified by the fact that they have no byte_size
4285 attribute, and a declaration attribute. */
4286 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4287 || !die_is_declaration (die
, cu
))
4288 new_symbol (die
, die
->type
, cu
);
4290 processing_current_prefix
= previous_prefix
;
4293 /* Given a DW_AT_enumeration_type die, set its type. We do not
4294 complete the type's fields yet, or create any symbols. */
4297 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4299 struct objfile
*objfile
= cu
->objfile
;
4301 struct attribute
*attr
;
4307 type
= alloc_type (objfile
);
4309 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4310 name
= dwarf2_name (die
, cu
);
4313 if (processing_has_namespace_info
)
4315 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
4316 processing_current_prefix
,
4321 /* The name is already allocated along with this objfile, so
4322 we don't need to duplicate it for the type. */
4323 TYPE_TAG_NAME (type
) = name
;
4327 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4330 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4334 TYPE_LENGTH (type
) = 0;
4337 /* The enumeration DIE can be incomplete. In Ada, any type can be
4338 declared as private in the package spec, and then defined only
4339 inside the package body. Such types are known as Taft Amendment
4340 Types. When another package uses such a type, an incomplete DIE
4341 may be generated by the compiler. */
4342 if (die_is_declaration (die
, cu
))
4343 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4345 set_die_type (die
, type
, cu
);
4348 /* Determine the name of the type represented by DIE, which should be
4349 a named C++ or Java compound type. Return the name in question; the caller
4350 is responsible for xfree()'ing it. */
4353 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4355 struct cleanup
*back_to
= NULL
;
4356 struct die_info
*spec_die
= die_specification (die
, cu
);
4357 char *new_prefix
= NULL
;
4359 /* If this is the definition of a class that is declared by another
4360 die, then processing_current_prefix may not be accurate; see
4361 read_func_scope for a similar example. */
4362 if (spec_die
!= NULL
)
4364 char *specification_prefix
= determine_prefix (spec_die
, cu
);
4365 processing_current_prefix
= specification_prefix
;
4366 back_to
= make_cleanup (xfree
, specification_prefix
);
4369 /* If we don't have namespace debug info, guess the name by trying
4370 to demangle the names of members, just like we did in
4371 guess_structure_name. */
4372 if (!processing_has_namespace_info
)
4374 struct die_info
*child
;
4376 for (child
= die
->child
;
4377 child
!= NULL
&& child
->tag
!= 0;
4378 child
= sibling_die (child
))
4380 if (child
->tag
== DW_TAG_subprogram
)
4383 = language_class_name_from_physname (cu
->language_defn
,
4387 if (new_prefix
!= NULL
)
4393 if (new_prefix
== NULL
)
4395 const char *name
= dwarf2_name (die
, cu
);
4396 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
4397 name
? name
: "<<anonymous>>",
4401 if (back_to
!= NULL
)
4402 do_cleanups (back_to
);
4407 /* Given a pointer to a die which begins an enumeration, process all
4408 the dies that define the members of the enumeration, and create the
4409 symbol for the enumeration type.
4411 NOTE: We reverse the order of the element list. */
4414 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4416 struct objfile
*objfile
= cu
->objfile
;
4417 struct die_info
*child_die
;
4418 struct field
*fields
;
4421 int unsigned_enum
= 1;
4426 if (die
->child
!= NULL
)
4428 child_die
= die
->child
;
4429 while (child_die
&& child_die
->tag
)
4431 if (child_die
->tag
!= DW_TAG_enumerator
)
4433 process_die (child_die
, cu
);
4437 name
= dwarf2_name (child_die
, cu
);
4440 sym
= new_symbol (child_die
, die
->type
, cu
);
4441 if (SYMBOL_VALUE (sym
) < 0)
4444 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4446 fields
= (struct field
*)
4448 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4449 * sizeof (struct field
));
4452 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
4453 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4454 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4455 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4456 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4462 child_die
= sibling_die (child_die
);
4467 TYPE_NFIELDS (die
->type
) = num_fields
;
4468 TYPE_FIELDS (die
->type
) = (struct field
*)
4469 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
4470 memcpy (TYPE_FIELDS (die
->type
), fields
,
4471 sizeof (struct field
) * num_fields
);
4475 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
4478 new_symbol (die
, die
->type
, cu
);
4481 /* Extract all information from a DW_TAG_array_type DIE and put it in
4482 the DIE's type field. For now, this only handles one dimensional
4486 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4488 struct objfile
*objfile
= cu
->objfile
;
4489 struct die_info
*child_die
;
4490 struct type
*type
= NULL
;
4491 struct type
*element_type
, *range_type
, *index_type
;
4492 struct type
**range_types
= NULL
;
4493 struct attribute
*attr
;
4495 struct cleanup
*back_to
;
4498 /* Return if we've already decoded this type. */
4504 element_type
= die_type (die
, cu
);
4506 /* Irix 6.2 native cc creates array types without children for
4507 arrays with unspecified length. */
4508 if (die
->child
== NULL
)
4510 index_type
= builtin_type_int32
;
4511 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4512 set_die_type (die
, create_array_type (NULL
, element_type
, range_type
),
4517 back_to
= make_cleanup (null_cleanup
, NULL
);
4518 child_die
= die
->child
;
4519 while (child_die
&& child_die
->tag
)
4521 if (child_die
->tag
== DW_TAG_subrange_type
)
4523 read_subrange_type (child_die
, cu
);
4525 if (child_die
->type
!= NULL
)
4527 /* The range type was succesfully read. Save it for
4528 the array type creation. */
4529 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4531 range_types
= (struct type
**)
4532 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4533 * sizeof (struct type
*));
4535 make_cleanup (free_current_contents
, &range_types
);
4537 range_types
[ndim
++] = child_die
->type
;
4540 child_die
= sibling_die (child_die
);
4543 /* Dwarf2 dimensions are output from left to right, create the
4544 necessary array types in backwards order. */
4546 type
= element_type
;
4548 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4552 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4557 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4560 /* Understand Dwarf2 support for vector types (like they occur on
4561 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4562 array type. This is not part of the Dwarf2/3 standard yet, but a
4563 custom vendor extension. The main difference between a regular
4564 array and the vector variant is that vectors are passed by value
4566 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4568 make_vector_type (type
);
4570 name
= dwarf2_name (die
, cu
);
4572 TYPE_NAME (type
) = name
;
4574 do_cleanups (back_to
);
4576 /* Install the type in the die. */
4577 set_die_type (die
, type
, cu
);
4580 static enum dwarf_array_dim_ordering
4581 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4583 struct attribute
*attr
;
4585 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4587 if (attr
) return DW_SND (attr
);
4590 GNU F77 is a special case, as at 08/2004 array type info is the
4591 opposite order to the dwarf2 specification, but data is still
4592 laid out as per normal fortran.
4594 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4598 if (cu
->language
== language_fortran
&&
4599 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4601 return DW_ORD_row_major
;
4604 switch (cu
->language_defn
->la_array_ordering
)
4606 case array_column_major
:
4607 return DW_ORD_col_major
;
4608 case array_row_major
:
4610 return DW_ORD_row_major
;
4614 /* Extract all information from a DW_TAG_set_type DIE and put it in
4615 the DIE's type field. */
4618 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4620 if (die
->type
== NULL
)
4621 die
->type
= create_set_type ((struct type
*) NULL
, die_type (die
, cu
));
4624 /* First cut: install each common block member as a global variable. */
4627 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4629 struct die_info
*child_die
;
4630 struct attribute
*attr
;
4632 CORE_ADDR base
= (CORE_ADDR
) 0;
4634 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4637 /* Support the .debug_loc offsets */
4638 if (attr_form_is_block (attr
))
4640 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4642 else if (attr_form_is_section_offset (attr
))
4644 dwarf2_complex_location_expr_complaint ();
4648 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4649 "common block member");
4652 if (die
->child
!= NULL
)
4654 child_die
= die
->child
;
4655 while (child_die
&& child_die
->tag
)
4657 sym
= new_symbol (child_die
, NULL
, cu
);
4658 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4661 SYMBOL_VALUE_ADDRESS (sym
) =
4662 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4663 add_symbol_to_list (sym
, &global_symbols
);
4665 child_die
= sibling_die (child_die
);
4670 /* Read a C++ namespace. */
4673 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4675 struct objfile
*objfile
= cu
->objfile
;
4676 const char *previous_prefix
= processing_current_prefix
;
4679 struct die_info
*current_die
;
4680 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4682 name
= namespace_name (die
, &is_anonymous
, cu
);
4684 /* Now build the name of the current namespace. */
4686 if (previous_prefix
[0] == '\0')
4688 processing_current_prefix
= name
;
4692 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4693 make_cleanup (xfree
, temp_name
);
4694 processing_current_prefix
= temp_name
;
4697 /* Add a symbol associated to this if we haven't seen the namespace
4698 before. Also, add a using directive if it's an anonymous
4701 if (dwarf2_extension (die
, cu
) == NULL
)
4705 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4706 this cast will hopefully become unnecessary. */
4707 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4708 (char *) processing_current_prefix
,
4710 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4712 new_symbol (die
, type
, cu
);
4713 set_die_type (die
, type
, cu
);
4716 cp_add_using_directive (processing_current_prefix
,
4717 strlen (previous_prefix
),
4718 strlen (processing_current_prefix
));
4721 if (die
->child
!= NULL
)
4723 struct die_info
*child_die
= die
->child
;
4725 while (child_die
&& child_die
->tag
)
4727 process_die (child_die
, cu
);
4728 child_die
= sibling_die (child_die
);
4732 processing_current_prefix
= previous_prefix
;
4733 do_cleanups (back_to
);
4736 /* Return the name of the namespace represented by DIE. Set
4737 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4741 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4743 struct die_info
*current_die
;
4744 const char *name
= NULL
;
4746 /* Loop through the extensions until we find a name. */
4748 for (current_die
= die
;
4749 current_die
!= NULL
;
4750 current_die
= dwarf2_extension (die
, cu
))
4752 name
= dwarf2_name (current_die
, cu
);
4757 /* Is it an anonymous namespace? */
4759 *is_anonymous
= (name
== NULL
);
4761 name
= "(anonymous namespace)";
4766 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4767 the user defined type vector. */
4770 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4772 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4773 struct comp_unit_head
*cu_header
= &cu
->header
;
4775 struct attribute
*attr_byte_size
;
4776 struct attribute
*attr_address_class
;
4777 int byte_size
, addr_class
;
4784 type
= lookup_pointer_type (die_type (die
, cu
));
4786 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4788 byte_size
= DW_UNSND (attr_byte_size
);
4790 byte_size
= cu_header
->addr_size
;
4792 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4793 if (attr_address_class
)
4794 addr_class
= DW_UNSND (attr_address_class
);
4796 addr_class
= DW_ADDR_none
;
4798 /* If the pointer size or address class is different than the
4799 default, create a type variant marked as such and set the
4800 length accordingly. */
4801 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4803 if (gdbarch_address_class_type_flags_p (gdbarch
))
4807 type_flags
= gdbarch_address_class_type_flags
4808 (gdbarch
, byte_size
, addr_class
);
4809 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4810 type
= make_type_with_address_space (type
, type_flags
);
4812 else if (TYPE_LENGTH (type
) != byte_size
)
4814 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4817 /* Should we also complain about unhandled address classes? */
4821 TYPE_LENGTH (type
) = byte_size
;
4822 set_die_type (die
, type
, cu
);
4825 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4826 the user defined type vector. */
4829 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4831 struct objfile
*objfile
= cu
->objfile
;
4833 struct type
*to_type
;
4834 struct type
*domain
;
4841 to_type
= die_type (die
, cu
);
4842 domain
= die_containing_type (die
, cu
);
4844 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4845 type
= lookup_methodptr_type (to_type
);
4847 type
= lookup_memberptr_type (to_type
, domain
);
4849 set_die_type (die
, type
, cu
);
4852 /* Extract all information from a DW_TAG_reference_type DIE and add to
4853 the user defined type vector. */
4856 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4858 struct comp_unit_head
*cu_header
= &cu
->header
;
4860 struct attribute
*attr
;
4867 type
= lookup_reference_type (die_type (die
, cu
));
4868 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4871 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4875 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4877 set_die_type (die
, type
, cu
);
4881 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4883 struct type
*base_type
;
4890 base_type
= die_type (die
, cu
);
4891 set_die_type (die
, make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0),
4896 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4898 struct type
*base_type
;
4905 base_type
= die_type (die
, cu
);
4906 set_die_type (die
, make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0),
4910 /* Extract all information from a DW_TAG_string_type DIE and add to
4911 the user defined type vector. It isn't really a user defined type,
4912 but it behaves like one, with other DIE's using an AT_user_def_type
4913 attribute to reference it. */
4916 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4918 struct objfile
*objfile
= cu
->objfile
;
4919 struct type
*type
, *range_type
, *index_type
, *char_type
;
4920 struct attribute
*attr
;
4921 unsigned int length
;
4928 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4931 length
= DW_UNSND (attr
);
4935 /* check for the DW_AT_byte_size attribute */
4936 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4939 length
= DW_UNSND (attr
);
4947 index_type
= builtin_type_int32
;
4948 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4949 type
= create_string_type (NULL
, range_type
);
4951 set_die_type (die
, type
, cu
);
4954 /* Handle DIES due to C code like:
4958 int (*funcp)(int a, long l);
4962 ('funcp' generates a DW_TAG_subroutine_type DIE)
4966 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4968 struct type
*type
; /* Type that this function returns */
4969 struct type
*ftype
; /* Function that returns above type */
4970 struct attribute
*attr
;
4972 /* Decode the type that this subroutine returns */
4977 type
= die_type (die
, cu
);
4978 ftype
= make_function_type (type
, (struct type
**) 0);
4980 /* All functions in C++, Pascal and Java have prototypes. */
4981 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4982 if ((attr
&& (DW_UNSND (attr
) != 0))
4983 || cu
->language
== language_cplus
4984 || cu
->language
== language_java
4985 || cu
->language
== language_pascal
)
4986 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4988 /* Store the calling convention in the type if it's available in
4989 the subroutine die. Otherwise set the calling convention to
4990 the default value DW_CC_normal. */
4991 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4992 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4994 if (die
->child
!= NULL
)
4996 struct die_info
*child_die
;
5000 /* Count the number of parameters.
5001 FIXME: GDB currently ignores vararg functions, but knows about
5002 vararg member functions. */
5003 child_die
= die
->child
;
5004 while (child_die
&& child_die
->tag
)
5006 if (child_die
->tag
== DW_TAG_formal_parameter
)
5008 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5009 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
5010 child_die
= sibling_die (child_die
);
5013 /* Allocate storage for parameters and fill them in. */
5014 TYPE_NFIELDS (ftype
) = nparams
;
5015 TYPE_FIELDS (ftype
) = (struct field
*)
5016 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5018 child_die
= die
->child
;
5019 while (child_die
&& child_die
->tag
)
5021 if (child_die
->tag
== DW_TAG_formal_parameter
)
5023 /* Dwarf2 has no clean way to discern C++ static and non-static
5024 member functions. G++ helps GDB by marking the first
5025 parameter for non-static member functions (which is the
5026 this pointer) as artificial. We pass this information
5027 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5028 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5030 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5032 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5033 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5036 child_die
= sibling_die (child_die
);
5040 set_die_type (die
, ftype
, cu
);
5044 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5046 struct objfile
*objfile
= cu
->objfile
;
5047 struct attribute
*attr
;
5052 name
= dwarf2_name (die
, cu
);
5053 set_die_type (die
, init_type (TYPE_CODE_TYPEDEF
, 0,
5054 TYPE_FLAG_TARGET_STUB
, name
, objfile
),
5056 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
5060 /* Find a representation of a given base type and install
5061 it in the TYPE field of the die. */
5064 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5066 struct objfile
*objfile
= cu
->objfile
;
5068 struct attribute
*attr
;
5069 int encoding
= 0, size
= 0;
5071 enum type_code code
= TYPE_CODE_INT
;
5073 struct type
*target_type
= NULL
;
5075 /* If we've already decoded this die, this is a no-op. */
5081 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5084 encoding
= DW_UNSND (attr
);
5086 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5089 size
= DW_UNSND (attr
);
5091 name
= dwarf2_name (die
, cu
);
5094 complaint (&symfile_complaints
,
5095 _("DW_AT_name missing from DW_TAG_base_type"));
5100 case DW_ATE_address
:
5101 /* Turn DW_ATE_address into a void * pointer. */
5102 code
= TYPE_CODE_PTR
;
5103 type_flags
|= TYPE_FLAG_UNSIGNED
;
5104 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5106 case DW_ATE_boolean
:
5107 code
= TYPE_CODE_BOOL
;
5108 type_flags
|= TYPE_FLAG_UNSIGNED
;
5110 case DW_ATE_complex_float
:
5111 code
= TYPE_CODE_COMPLEX
;
5112 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5114 case DW_ATE_decimal_float
:
5115 code
= TYPE_CODE_DECFLOAT
;
5118 code
= TYPE_CODE_FLT
;
5122 case DW_ATE_unsigned
:
5123 type_flags
|= TYPE_FLAG_UNSIGNED
;
5125 case DW_ATE_signed_char
:
5126 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5127 code
= TYPE_CODE_CHAR
;
5129 case DW_ATE_unsigned_char
:
5130 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5131 code
= TYPE_CODE_CHAR
;
5132 type_flags
|= TYPE_FLAG_UNSIGNED
;
5135 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5136 dwarf_type_encoding_name (encoding
));
5140 type
= init_type (code
, size
, type_flags
, name
, objfile
);
5141 TYPE_TARGET_TYPE (type
) = target_type
;
5143 set_die_type (die
, type
, cu
);
5146 /* Read the given DW_AT_subrange DIE. */
5149 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5151 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5152 struct type
*base_type
;
5153 struct type
*range_type
;
5154 struct attribute
*attr
;
5159 /* If we have already decoded this die, then nothing more to do. */
5163 base_type
= die_type (die
, cu
);
5164 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5166 complaint (&symfile_complaints
,
5167 _("DW_AT_type missing from DW_TAG_subrange_type"));
5169 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5170 0, NULL
, cu
->objfile
);
5173 if (cu
->language
== language_fortran
)
5175 /* FORTRAN implies a lower bound of 1, if not given. */
5179 /* FIXME: For variable sized arrays either of these could be
5180 a variable rather than a constant value. We'll allow it,
5181 but we don't know how to handle it. */
5182 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5184 low
= dwarf2_get_attr_constant_value (attr
, 0);
5186 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5189 if (attr
->form
== DW_FORM_block1
)
5191 /* GCC encodes arrays with unspecified or dynamic length
5192 with a DW_FORM_block1 attribute.
5193 FIXME: GDB does not yet know how to handle dynamic
5194 arrays properly, treat them as arrays with unspecified
5197 FIXME: jimb/2003-09-22: GDB does not really know
5198 how to handle arrays of unspecified length
5199 either; we just represent them as zero-length
5200 arrays. Choose an appropriate upper bound given
5201 the lower bound we've computed above. */
5205 high
= dwarf2_get_attr_constant_value (attr
, 1);
5208 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5210 name
= dwarf2_name (die
, cu
);
5212 TYPE_NAME (range_type
) = name
;
5214 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5216 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5218 set_die_type (die
, range_type
, cu
);
5222 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5229 /* For now, we only support the C meaning of an unspecified type: void. */
5231 type
= init_type (TYPE_CODE_VOID
, 0, 0, dwarf2_name (die
, cu
),
5234 set_die_type (die
, type
, cu
);
5237 /* Read a whole compilation unit into a linked list of dies. */
5239 static struct die_info
*
5240 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5242 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5245 /* Read a single die and all its descendents. Set the die's sibling
5246 field to NULL; set other fields in the die correctly, and set all
5247 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5248 location of the info_ptr after reading all of those dies. PARENT
5249 is the parent of the die in question. */
5251 static struct die_info
*
5252 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5253 struct dwarf2_cu
*cu
,
5254 gdb_byte
**new_info_ptr
,
5255 struct die_info
*parent
)
5257 struct die_info
*die
;
5261 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5262 store_in_ref_table (die
->offset
, die
, cu
);
5266 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5272 *new_info_ptr
= cur_ptr
;
5275 die
->sibling
= NULL
;
5276 die
->parent
= parent
;
5280 /* Read a die, all of its descendents, and all of its siblings; set
5281 all of the fields of all of the dies correctly. Arguments are as
5282 in read_die_and_children. */
5284 static struct die_info
*
5285 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5286 struct dwarf2_cu
*cu
,
5287 gdb_byte
**new_info_ptr
,
5288 struct die_info
*parent
)
5290 struct die_info
*first_die
, *last_sibling
;
5294 first_die
= last_sibling
= NULL
;
5298 struct die_info
*die
5299 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5307 last_sibling
->sibling
= die
;
5312 *new_info_ptr
= cur_ptr
;
5322 /* Free a linked list of dies. */
5325 free_die_list (struct die_info
*dies
)
5327 struct die_info
*die
, *next
;
5332 if (die
->child
!= NULL
)
5333 free_die_list (die
->child
);
5334 next
= die
->sibling
;
5341 /* Decompress a section that was compressed using zlib. Store the
5342 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5345 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5346 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5348 bfd
*abfd
= objfile
->obfd
;
5350 error (_("Support for zlib-compressed DWARF data (from '%s') "
5351 "is disabled in this copy of GDB"),
5352 bfd_get_filename (abfd
));
5354 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5355 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5356 bfd_size_type uncompressed_size
;
5357 gdb_byte
*uncompressed_buffer
;
5360 int header_size
= 12;
5362 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5363 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5364 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5365 bfd_get_filename (abfd
));
5367 /* Read the zlib header. In this case, it should be "ZLIB" followed
5368 by the uncompressed section size, 8 bytes in big-endian order. */
5369 if (compressed_size
< header_size
5370 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5371 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5372 bfd_get_filename (abfd
));
5373 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5374 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5375 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5376 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5377 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5378 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5379 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5380 uncompressed_size
+= compressed_buffer
[11];
5382 /* It is possible the section consists of several compressed
5383 buffers concatenated together, so we uncompress in a loop. */
5387 strm
.avail_in
= compressed_size
- header_size
;
5388 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5389 strm
.avail_out
= uncompressed_size
;
5390 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5392 rc
= inflateInit (&strm
);
5393 while (strm
.avail_in
> 0)
5396 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5397 bfd_get_filename (abfd
), rc
);
5398 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5399 + (uncompressed_size
- strm
.avail_out
));
5400 rc
= inflate (&strm
, Z_FINISH
);
5401 if (rc
!= Z_STREAM_END
)
5402 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5403 bfd_get_filename (abfd
), rc
);
5404 rc
= inflateReset (&strm
);
5406 rc
= inflateEnd (&strm
);
5408 || strm
.avail_out
!= 0)
5409 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5410 bfd_get_filename (abfd
), rc
);
5412 xfree (compressed_buffer
);
5413 *outbuf
= uncompressed_buffer
;
5414 *outsize
= uncompressed_size
;
5419 /* Read the contents of the section at OFFSET and of size SIZE from the
5420 object file specified by OBJFILE into the objfile_obstack and return it.
5421 If the section is compressed, uncompress it before returning. */
5424 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5426 bfd
*abfd
= objfile
->obfd
;
5427 gdb_byte
*buf
, *retbuf
;
5428 bfd_size_type size
= bfd_get_section_size (sectp
);
5429 unsigned char header
[4];
5434 /* Check if the file has a 4-byte header indicating compression. */
5435 if (size
> sizeof (header
)
5436 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5437 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5439 /* Upon decompression, update the buffer and its size. */
5440 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5442 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5443 dwarf2_resize_section (sectp
, size
);
5448 /* If we get here, we are a normal, not-compressed section. */
5449 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5450 /* When debugging .o files, we may need to apply relocations; see
5451 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5452 We never compress sections in .o files, so we only need to
5453 try this when the section is not compressed. */
5454 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5458 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5459 || bfd_bread (buf
, size
, abfd
) != size
)
5460 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5461 bfd_get_filename (abfd
));
5466 /* In DWARF version 2, the description of the debugging information is
5467 stored in a separate .debug_abbrev section. Before we read any
5468 dies from a section we read in all abbreviations and install them
5469 in a hash table. This function also sets flags in CU describing
5470 the data found in the abbrev table. */
5473 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5475 struct comp_unit_head
*cu_header
= &cu
->header
;
5476 gdb_byte
*abbrev_ptr
;
5477 struct abbrev_info
*cur_abbrev
;
5478 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5479 unsigned int abbrev_form
, hash_number
;
5480 struct attr_abbrev
*cur_attrs
;
5481 unsigned int allocated_attrs
;
5483 /* Initialize dwarf2 abbrevs */
5484 obstack_init (&cu
->abbrev_obstack
);
5485 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5487 * sizeof (struct abbrev_info
*)));
5488 memset (cu
->dwarf2_abbrevs
, 0,
5489 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5491 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5492 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5493 abbrev_ptr
+= bytes_read
;
5495 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5496 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5498 /* loop until we reach an abbrev number of 0 */
5499 while (abbrev_number
)
5501 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5503 /* read in abbrev header */
5504 cur_abbrev
->number
= abbrev_number
;
5505 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5506 abbrev_ptr
+= bytes_read
;
5507 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5510 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5511 cu
->has_namespace_info
= 1;
5513 /* now read in declarations */
5514 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5515 abbrev_ptr
+= bytes_read
;
5516 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5517 abbrev_ptr
+= bytes_read
;
5520 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5522 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5524 = xrealloc (cur_attrs
, (allocated_attrs
5525 * sizeof (struct attr_abbrev
)));
5528 /* Record whether this compilation unit might have
5529 inter-compilation-unit references. If we don't know what form
5530 this attribute will have, then it might potentially be a
5531 DW_FORM_ref_addr, so we conservatively expect inter-CU
5534 if (abbrev_form
== DW_FORM_ref_addr
5535 || abbrev_form
== DW_FORM_indirect
)
5536 cu
->has_form_ref_addr
= 1;
5538 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5539 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5540 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5541 abbrev_ptr
+= bytes_read
;
5542 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5543 abbrev_ptr
+= bytes_read
;
5546 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5547 (cur_abbrev
->num_attrs
5548 * sizeof (struct attr_abbrev
)));
5549 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5550 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5552 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5553 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5554 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5556 /* Get next abbreviation.
5557 Under Irix6 the abbreviations for a compilation unit are not
5558 always properly terminated with an abbrev number of 0.
5559 Exit loop if we encounter an abbreviation which we have
5560 already read (which means we are about to read the abbreviations
5561 for the next compile unit) or if the end of the abbreviation
5562 table is reached. */
5563 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5564 >= dwarf2_per_objfile
->abbrev_size
)
5566 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5567 abbrev_ptr
+= bytes_read
;
5568 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5575 /* Release the memory used by the abbrev table for a compilation unit. */
5578 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5580 struct dwarf2_cu
*cu
= ptr_to_cu
;
5582 obstack_free (&cu
->abbrev_obstack
, NULL
);
5583 cu
->dwarf2_abbrevs
= NULL
;
5586 /* Lookup an abbrev_info structure in the abbrev hash table. */
5588 static struct abbrev_info
*
5589 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5591 unsigned int hash_number
;
5592 struct abbrev_info
*abbrev
;
5594 hash_number
= number
% ABBREV_HASH_SIZE
;
5595 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5599 if (abbrev
->number
== number
)
5602 abbrev
= abbrev
->next
;
5607 /* Returns nonzero if TAG represents a type that we might generate a partial
5611 is_type_tag_for_partial (int tag
)
5616 /* Some types that would be reasonable to generate partial symbols for,
5617 that we don't at present. */
5618 case DW_TAG_array_type
:
5619 case DW_TAG_file_type
:
5620 case DW_TAG_ptr_to_member_type
:
5621 case DW_TAG_set_type
:
5622 case DW_TAG_string_type
:
5623 case DW_TAG_subroutine_type
:
5625 case DW_TAG_base_type
:
5626 case DW_TAG_class_type
:
5627 case DW_TAG_interface_type
:
5628 case DW_TAG_enumeration_type
:
5629 case DW_TAG_structure_type
:
5630 case DW_TAG_subrange_type
:
5631 case DW_TAG_typedef
:
5632 case DW_TAG_union_type
:
5639 /* Load all DIEs that are interesting for partial symbols into memory. */
5641 static struct partial_die_info
*
5642 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5643 struct dwarf2_cu
*cu
)
5645 struct partial_die_info
*part_die
;
5646 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5647 struct abbrev_info
*abbrev
;
5648 unsigned int bytes_read
;
5649 unsigned int load_all
= 0;
5651 int nesting_level
= 1;
5656 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5660 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5664 &cu
->comp_unit_obstack
,
5665 hashtab_obstack_allocate
,
5666 dummy_obstack_deallocate
);
5668 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5669 sizeof (struct partial_die_info
));
5673 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5675 /* A NULL abbrev means the end of a series of children. */
5678 if (--nesting_level
== 0)
5680 /* PART_DIE was probably the last thing allocated on the
5681 comp_unit_obstack, so we could call obstack_free
5682 here. We don't do that because the waste is small,
5683 and will be cleaned up when we're done with this
5684 compilation unit. This way, we're also more robust
5685 against other users of the comp_unit_obstack. */
5688 info_ptr
+= bytes_read
;
5689 last_die
= parent_die
;
5690 parent_die
= parent_die
->die_parent
;
5694 /* Check whether this DIE is interesting enough to save. Normally
5695 we would not be interested in members here, but there may be
5696 later variables referencing them via DW_AT_specification (for
5699 && !is_type_tag_for_partial (abbrev
->tag
)
5700 && abbrev
->tag
!= DW_TAG_enumerator
5701 && abbrev
->tag
!= DW_TAG_subprogram
5702 && abbrev
->tag
!= DW_TAG_variable
5703 && abbrev
->tag
!= DW_TAG_namespace
5704 && abbrev
->tag
!= DW_TAG_member
)
5706 /* Otherwise we skip to the next sibling, if any. */
5707 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5711 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5712 abfd
, info_ptr
, cu
);
5714 /* This two-pass algorithm for processing partial symbols has a
5715 high cost in cache pressure. Thus, handle some simple cases
5716 here which cover the majority of C partial symbols. DIEs
5717 which neither have specification tags in them, nor could have
5718 specification tags elsewhere pointing at them, can simply be
5719 processed and discarded.
5721 This segment is also optional; scan_partial_symbols and
5722 add_partial_symbol will handle these DIEs if we chain
5723 them in normally. When compilers which do not emit large
5724 quantities of duplicate debug information are more common,
5725 this code can probably be removed. */
5727 /* Any complete simple types at the top level (pretty much all
5728 of them, for a language without namespaces), can be processed
5730 if (parent_die
== NULL
5731 && part_die
->has_specification
== 0
5732 && part_die
->is_declaration
== 0
5733 && (part_die
->tag
== DW_TAG_typedef
5734 || part_die
->tag
== DW_TAG_base_type
5735 || part_die
->tag
== DW_TAG_subrange_type
))
5737 if (building_psymtab
&& part_die
->name
!= NULL
)
5738 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5739 VAR_DOMAIN
, LOC_TYPEDEF
,
5740 &cu
->objfile
->static_psymbols
,
5741 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5742 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5746 /* If we're at the second level, and we're an enumerator, and
5747 our parent has no specification (meaning possibly lives in a
5748 namespace elsewhere), then we can add the partial symbol now
5749 instead of queueing it. */
5750 if (part_die
->tag
== DW_TAG_enumerator
5751 && parent_die
!= NULL
5752 && parent_die
->die_parent
== NULL
5753 && parent_die
->tag
== DW_TAG_enumeration_type
5754 && parent_die
->has_specification
== 0)
5756 if (part_die
->name
== NULL
)
5757 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5758 else if (building_psymtab
)
5759 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5760 VAR_DOMAIN
, LOC_CONST
,
5761 (cu
->language
== language_cplus
5762 || cu
->language
== language_java
)
5763 ? &cu
->objfile
->global_psymbols
5764 : &cu
->objfile
->static_psymbols
,
5765 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5767 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5771 /* We'll save this DIE so link it in. */
5772 part_die
->die_parent
= parent_die
;
5773 part_die
->die_sibling
= NULL
;
5774 part_die
->die_child
= NULL
;
5776 if (last_die
&& last_die
== parent_die
)
5777 last_die
->die_child
= part_die
;
5779 last_die
->die_sibling
= part_die
;
5781 last_die
= part_die
;
5783 if (first_die
== NULL
)
5784 first_die
= part_die
;
5786 /* Maybe add the DIE to the hash table. Not all DIEs that we
5787 find interesting need to be in the hash table, because we
5788 also have the parent/sibling/child chains; only those that we
5789 might refer to by offset later during partial symbol reading.
5791 For now this means things that might have be the target of a
5792 DW_AT_specification, DW_AT_abstract_origin, or
5793 DW_AT_extension. DW_AT_extension will refer only to
5794 namespaces; DW_AT_abstract_origin refers to functions (and
5795 many things under the function DIE, but we do not recurse
5796 into function DIEs during partial symbol reading) and
5797 possibly variables as well; DW_AT_specification refers to
5798 declarations. Declarations ought to have the DW_AT_declaration
5799 flag. It happens that GCC forgets to put it in sometimes, but
5800 only for functions, not for types.
5802 Adding more things than necessary to the hash table is harmless
5803 except for the performance cost. Adding too few will result in
5804 wasted time in find_partial_die, when we reread the compilation
5805 unit with load_all_dies set. */
5808 || abbrev
->tag
== DW_TAG_subprogram
5809 || abbrev
->tag
== DW_TAG_variable
5810 || abbrev
->tag
== DW_TAG_namespace
5811 || part_die
->is_declaration
)
5815 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5816 part_die
->offset
, INSERT
);
5820 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5821 sizeof (struct partial_die_info
));
5823 /* For some DIEs we want to follow their children (if any). For C
5824 we have no reason to follow the children of structures; for other
5825 languages we have to, both so that we can get at method physnames
5826 to infer fully qualified class names, and for DW_AT_specification. */
5827 if (last_die
->has_children
5829 || last_die
->tag
== DW_TAG_namespace
5830 || last_die
->tag
== DW_TAG_enumeration_type
5831 || (cu
->language
!= language_c
5832 && (last_die
->tag
== DW_TAG_class_type
5833 || last_die
->tag
== DW_TAG_interface_type
5834 || last_die
->tag
== DW_TAG_structure_type
5835 || last_die
->tag
== DW_TAG_union_type
))))
5838 parent_die
= last_die
;
5842 /* Otherwise we skip to the next sibling, if any. */
5843 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5845 /* Back to the top, do it again. */
5849 /* Read a minimal amount of information into the minimal die structure. */
5852 read_partial_die (struct partial_die_info
*part_die
,
5853 struct abbrev_info
*abbrev
,
5854 unsigned int abbrev_len
, bfd
*abfd
,
5855 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5857 unsigned int bytes_read
, i
;
5858 struct attribute attr
;
5859 int has_low_pc_attr
= 0;
5860 int has_high_pc_attr
= 0;
5861 CORE_ADDR base_address
;
5865 base_address_low_pc
,
5866 /* Overrides BASE_ADDRESS_LOW_PC. */
5867 base_address_entry_pc
5869 base_address_type
= base_address_none
;
5871 memset (part_die
, 0, sizeof (struct partial_die_info
));
5873 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5875 info_ptr
+= abbrev_len
;
5880 part_die
->tag
= abbrev
->tag
;
5881 part_die
->has_children
= abbrev
->has_children
;
5883 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5885 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5887 /* Store the data if it is of an attribute we want to keep in a
5888 partial symbol table. */
5893 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5894 if (part_die
->name
== NULL
)
5895 part_die
->name
= DW_STRING (&attr
);
5897 case DW_AT_comp_dir
:
5898 if (part_die
->dirname
== NULL
)
5899 part_die
->dirname
= DW_STRING (&attr
);
5901 case DW_AT_MIPS_linkage_name
:
5902 part_die
->name
= DW_STRING (&attr
);
5905 has_low_pc_attr
= 1;
5906 part_die
->lowpc
= DW_ADDR (&attr
);
5907 if (part_die
->tag
== DW_TAG_compile_unit
5908 && base_address_type
< base_address_low_pc
)
5910 base_address
= DW_ADDR (&attr
);
5911 base_address_type
= base_address_low_pc
;
5915 has_high_pc_attr
= 1;
5916 part_die
->highpc
= DW_ADDR (&attr
);
5918 case DW_AT_entry_pc
:
5919 if (part_die
->tag
== DW_TAG_compile_unit
5920 && base_address_type
< base_address_entry_pc
)
5922 base_address
= DW_ADDR (&attr
);
5923 base_address_type
= base_address_entry_pc
;
5927 if (part_die
->tag
== DW_TAG_compile_unit
)
5929 cu
->ranges_offset
= DW_UNSND (&attr
);
5930 cu
->has_ranges_offset
= 1;
5933 case DW_AT_location
:
5934 /* Support the .debug_loc offsets */
5935 if (attr_form_is_block (&attr
))
5937 part_die
->locdesc
= DW_BLOCK (&attr
);
5939 else if (attr_form_is_section_offset (&attr
))
5941 dwarf2_complex_location_expr_complaint ();
5945 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5946 "partial symbol information");
5949 case DW_AT_language
:
5950 part_die
->language
= DW_UNSND (&attr
);
5952 case DW_AT_external
:
5953 part_die
->is_external
= DW_UNSND (&attr
);
5955 case DW_AT_declaration
:
5956 part_die
->is_declaration
= DW_UNSND (&attr
);
5959 part_die
->has_type
= 1;
5961 case DW_AT_abstract_origin
:
5962 case DW_AT_specification
:
5963 case DW_AT_extension
:
5964 part_die
->has_specification
= 1;
5965 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5968 /* Ignore absolute siblings, they might point outside of
5969 the current compile unit. */
5970 if (attr
.form
== DW_FORM_ref_addr
)
5971 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5973 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5974 + dwarf2_get_ref_die_offset (&attr
, cu
);
5976 case DW_AT_stmt_list
:
5977 part_die
->has_stmt_list
= 1;
5978 part_die
->line_offset
= DW_UNSND (&attr
);
5980 case DW_AT_byte_size
:
5981 part_die
->has_byte_size
= 1;
5983 case DW_AT_calling_convention
:
5984 /* DWARF doesn't provide a way to identify a program's source-level
5985 entry point. DW_AT_calling_convention attributes are only meant
5986 to describe functions' calling conventions.
5988 However, because it's a necessary piece of information in
5989 Fortran, and because DW_CC_program is the only piece of debugging
5990 information whose definition refers to a 'main program' at all,
5991 several compilers have begun marking Fortran main programs with
5992 DW_CC_program --- even when those functions use the standard
5993 calling conventions.
5995 So until DWARF specifies a way to provide this information and
5996 compilers pick up the new representation, we'll support this
5998 if (DW_UNSND (&attr
) == DW_CC_program
5999 && cu
->language
== language_fortran
)
6000 set_main_name (part_die
->name
);
6007 /* When using the GNU linker, .gnu.linkonce. sections are used to
6008 eliminate duplicate copies of functions and vtables and such.
6009 The linker will arbitrarily choose one and discard the others.
6010 The AT_*_pc values for such functions refer to local labels in
6011 these sections. If the section from that file was discarded, the
6012 labels are not in the output, so the relocs get a value of 0.
6013 If this is a discarded function, mark the pc bounds as invalid,
6014 so that GDB will ignore it. */
6015 if (has_low_pc_attr
&& has_high_pc_attr
6016 && part_die
->lowpc
< part_die
->highpc
6017 && (part_die
->lowpc
!= 0
6018 || dwarf2_per_objfile
->has_section_at_zero
))
6019 part_die
->has_pc_info
= 1;
6021 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
6023 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6024 cu
->header
.base_known
= 1;
6025 cu
->header
.base_address
= base_address
;
6031 /* Find a cached partial DIE at OFFSET in CU. */
6033 static struct partial_die_info
*
6034 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
6036 struct partial_die_info
*lookup_die
= NULL
;
6037 struct partial_die_info part_die
;
6039 part_die
.offset
= offset
;
6040 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6045 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6047 static struct partial_die_info
*
6048 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
6050 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6051 struct partial_die_info
*pd
= NULL
;
6053 if (offset
>= cu
->header
.offset
6054 && offset
< cu
->header
.offset
+ cu
->header
.length
)
6056 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6061 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6063 if (per_cu
->cu
== NULL
)
6065 load_comp_unit (per_cu
, cu
->objfile
);
6066 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6067 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6070 per_cu
->cu
->last_used
= 0;
6071 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6073 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6075 struct cleanup
*back_to
;
6076 struct partial_die_info comp_unit_die
;
6077 struct abbrev_info
*abbrev
;
6078 unsigned int bytes_read
;
6081 per_cu
->load_all_dies
= 1;
6083 /* Re-read the DIEs. */
6084 back_to
= make_cleanup (null_cleanup
, 0);
6085 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6087 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6088 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6090 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
6091 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6092 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6093 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6095 if (comp_unit_die
.has_children
)
6096 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6097 do_cleanups (back_to
);
6099 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6103 internal_error (__FILE__
, __LINE__
,
6104 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
6105 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6109 /* Adjust PART_DIE before generating a symbol for it. This function
6110 may set the is_external flag or change the DIE's name. */
6113 fixup_partial_die (struct partial_die_info
*part_die
,
6114 struct dwarf2_cu
*cu
)
6116 /* If we found a reference attribute and the DIE has no name, try
6117 to find a name in the referred to DIE. */
6119 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6121 struct partial_die_info
*spec_die
;
6123 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6125 fixup_partial_die (spec_die
, cu
);
6129 part_die
->name
= spec_die
->name
;
6131 /* Copy DW_AT_external attribute if it is set. */
6132 if (spec_die
->is_external
)
6133 part_die
->is_external
= spec_die
->is_external
;
6137 /* Set default names for some unnamed DIEs. */
6138 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6139 || part_die
->tag
== DW_TAG_class_type
))
6140 part_die
->name
= "(anonymous class)";
6142 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6143 part_die
->name
= "(anonymous namespace)";
6145 if (part_die
->tag
== DW_TAG_structure_type
6146 || part_die
->tag
== DW_TAG_class_type
6147 || part_die
->tag
== DW_TAG_union_type
)
6148 guess_structure_name (part_die
, cu
);
6151 /* Read the die from the .debug_info section buffer. Set DIEP to
6152 point to a newly allocated die with its information, except for its
6153 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6154 whether the die has children or not. */
6157 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6158 struct dwarf2_cu
*cu
, int *has_children
)
6160 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6161 struct abbrev_info
*abbrev
;
6162 struct die_info
*die
;
6164 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6165 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6166 info_ptr
+= bytes_read
;
6169 die
= dwarf_alloc_die ();
6171 die
->abbrev
= abbrev_number
;
6178 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6181 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6183 bfd_get_filename (abfd
));
6185 die
= dwarf_alloc_die ();
6186 die
->offset
= offset
;
6187 die
->tag
= abbrev
->tag
;
6188 die
->abbrev
= abbrev_number
;
6191 die
->num_attrs
= abbrev
->num_attrs
;
6192 die
->attrs
= (struct attribute
*)
6193 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
6195 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6197 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6198 abfd
, info_ptr
, cu
);
6200 /* If this attribute is an absolute reference to a different
6201 compilation unit, make sure that compilation unit is loaded
6203 if (die
->attrs
[i
].form
== DW_FORM_ref_addr
6204 && (DW_ADDR (&die
->attrs
[i
]) < cu
->header
.offset
6205 || (DW_ADDR (&die
->attrs
[i
])
6206 >= cu
->header
.offset
+ cu
->header
.length
)))
6208 struct dwarf2_per_cu_data
*per_cu
;
6209 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (&die
->attrs
[i
]),
6212 /* Mark the dependence relation so that we don't flush PER_CU
6214 dwarf2_add_dependence (cu
, per_cu
);
6216 /* If it's already on the queue, we have nothing to do. */
6220 /* If the compilation unit is already loaded, just mark it as
6222 if (per_cu
->cu
!= NULL
)
6224 per_cu
->cu
->last_used
= 0;
6228 /* Add it to the queue. */
6229 queue_comp_unit (per_cu
);
6234 *has_children
= abbrev
->has_children
;
6238 /* Read an attribute value described by an attribute form. */
6241 read_attribute_value (struct attribute
*attr
, unsigned form
,
6242 bfd
*abfd
, gdb_byte
*info_ptr
,
6243 struct dwarf2_cu
*cu
)
6245 struct comp_unit_head
*cu_header
= &cu
->header
;
6246 unsigned int bytes_read
;
6247 struct dwarf_block
*blk
;
6253 case DW_FORM_ref_addr
:
6254 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6255 info_ptr
+= bytes_read
;
6257 case DW_FORM_block2
:
6258 blk
= dwarf_alloc_block (cu
);
6259 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6261 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6262 info_ptr
+= blk
->size
;
6263 DW_BLOCK (attr
) = blk
;
6265 case DW_FORM_block4
:
6266 blk
= dwarf_alloc_block (cu
);
6267 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6269 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6270 info_ptr
+= blk
->size
;
6271 DW_BLOCK (attr
) = blk
;
6274 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6278 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6282 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6285 case DW_FORM_string
:
6286 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6287 info_ptr
+= bytes_read
;
6290 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6292 info_ptr
+= bytes_read
;
6295 blk
= dwarf_alloc_block (cu
);
6296 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6297 info_ptr
+= bytes_read
;
6298 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6299 info_ptr
+= blk
->size
;
6300 DW_BLOCK (attr
) = blk
;
6302 case DW_FORM_block1
:
6303 blk
= dwarf_alloc_block (cu
);
6304 blk
->size
= read_1_byte (abfd
, info_ptr
);
6306 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6307 info_ptr
+= blk
->size
;
6308 DW_BLOCK (attr
) = blk
;
6311 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6315 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6319 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6320 info_ptr
+= bytes_read
;
6323 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6324 info_ptr
+= bytes_read
;
6327 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6331 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6335 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6339 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6342 case DW_FORM_ref_udata
:
6343 DW_ADDR (attr
) = (cu
->header
.offset
6344 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6345 info_ptr
+= bytes_read
;
6347 case DW_FORM_indirect
:
6348 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6349 info_ptr
+= bytes_read
;
6350 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6353 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6354 dwarf_form_name (form
),
6355 bfd_get_filename (abfd
));
6360 /* Read an attribute described by an abbreviated attribute. */
6363 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6364 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6366 attr
->name
= abbrev
->name
;
6367 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6370 /* read dwarf information from a buffer */
6373 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6375 return bfd_get_8 (abfd
, buf
);
6379 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6381 return bfd_get_signed_8 (abfd
, buf
);
6385 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6387 return bfd_get_16 (abfd
, buf
);
6391 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6393 return bfd_get_signed_16 (abfd
, buf
);
6397 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6399 return bfd_get_32 (abfd
, buf
);
6403 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6405 return bfd_get_signed_32 (abfd
, buf
);
6408 static unsigned long
6409 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6411 return bfd_get_64 (abfd
, buf
);
6415 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6416 unsigned int *bytes_read
)
6418 struct comp_unit_head
*cu_header
= &cu
->header
;
6419 CORE_ADDR retval
= 0;
6421 if (cu_header
->signed_addr_p
)
6423 switch (cu_header
->addr_size
)
6426 retval
= bfd_get_signed_16 (abfd
, buf
);
6429 retval
= bfd_get_signed_32 (abfd
, buf
);
6432 retval
= bfd_get_signed_64 (abfd
, buf
);
6435 internal_error (__FILE__
, __LINE__
,
6436 _("read_address: bad switch, signed [in module %s]"),
6437 bfd_get_filename (abfd
));
6442 switch (cu_header
->addr_size
)
6445 retval
= bfd_get_16 (abfd
, buf
);
6448 retval
= bfd_get_32 (abfd
, buf
);
6451 retval
= bfd_get_64 (abfd
, buf
);
6454 internal_error (__FILE__
, __LINE__
,
6455 _("read_address: bad switch, unsigned [in module %s]"),
6456 bfd_get_filename (abfd
));
6460 *bytes_read
= cu_header
->addr_size
;
6464 /* Read the initial length from a section. The (draft) DWARF 3
6465 specification allows the initial length to take up either 4 bytes
6466 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6467 bytes describe the length and all offsets will be 8 bytes in length
6470 An older, non-standard 64-bit format is also handled by this
6471 function. The older format in question stores the initial length
6472 as an 8-byte quantity without an escape value. Lengths greater
6473 than 2^32 aren't very common which means that the initial 4 bytes
6474 is almost always zero. Since a length value of zero doesn't make
6475 sense for the 32-bit format, this initial zero can be considered to
6476 be an escape value which indicates the presence of the older 64-bit
6477 format. As written, the code can't detect (old format) lengths
6478 greater than 4GB. If it becomes necessary to handle lengths
6479 somewhat larger than 4GB, we could allow other small values (such
6480 as the non-sensical values of 1, 2, and 3) to also be used as
6481 escape values indicating the presence of the old format.
6483 The value returned via bytes_read should be used to increment the
6484 relevant pointer after calling read_initial_length().
6486 As a side effect, this function sets the fields initial_length_size
6487 and offset_size in cu_header to the values appropriate for the
6488 length field. (The format of the initial length field determines
6489 the width of file offsets to be fetched later with read_offset().)
6491 [ Note: read_initial_length() and read_offset() are based on the
6492 document entitled "DWARF Debugging Information Format", revision
6493 3, draft 8, dated November 19, 2001. This document was obtained
6496 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6498 This document is only a draft and is subject to change. (So beware.)
6500 Details regarding the older, non-standard 64-bit format were
6501 determined empirically by examining 64-bit ELF files produced by
6502 the SGI toolchain on an IRIX 6.5 machine.
6504 - Kevin, July 16, 2002
6508 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6509 unsigned int *bytes_read
)
6511 LONGEST length
= bfd_get_32 (abfd
, buf
);
6513 if (length
== 0xffffffff)
6515 length
= bfd_get_64 (abfd
, buf
+ 4);
6518 else if (length
== 0)
6520 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6521 length
= bfd_get_64 (abfd
, buf
);
6531 gdb_assert (cu_header
->initial_length_size
== 0
6532 || cu_header
->initial_length_size
== 4
6533 || cu_header
->initial_length_size
== 8
6534 || cu_header
->initial_length_size
== 12);
6536 if (cu_header
->initial_length_size
!= 0
6537 && cu_header
->initial_length_size
!= *bytes_read
)
6538 complaint (&symfile_complaints
,
6539 _("intermixed 32-bit and 64-bit DWARF sections"));
6541 cu_header
->initial_length_size
= *bytes_read
;
6542 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6548 /* Read an offset from the data stream. The size of the offset is
6549 given by cu_header->offset_size. */
6552 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6553 unsigned int *bytes_read
)
6557 switch (cu_header
->offset_size
)
6560 retval
= bfd_get_32 (abfd
, buf
);
6564 retval
= bfd_get_64 (abfd
, buf
);
6568 internal_error (__FILE__
, __LINE__
,
6569 _("read_offset: bad switch [in module %s]"),
6570 bfd_get_filename (abfd
));
6577 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6579 /* If the size of a host char is 8 bits, we can return a pointer
6580 to the buffer, otherwise we have to copy the data to a buffer
6581 allocated on the temporary obstack. */
6582 gdb_assert (HOST_CHAR_BIT
== 8);
6587 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6589 /* If the size of a host char is 8 bits, we can return a pointer
6590 to the string, otherwise we have to copy the string to a buffer
6591 allocated on the temporary obstack. */
6592 gdb_assert (HOST_CHAR_BIT
== 8);
6595 *bytes_read_ptr
= 1;
6598 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6599 return (char *) buf
;
6603 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6604 const struct comp_unit_head
*cu_header
,
6605 unsigned int *bytes_read_ptr
)
6607 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6610 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6612 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6613 bfd_get_filename (abfd
));
6616 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6618 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6619 bfd_get_filename (abfd
));
6622 gdb_assert (HOST_CHAR_BIT
== 8);
6623 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6625 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6628 static unsigned long
6629 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6631 unsigned long result
;
6632 unsigned int num_read
;
6642 byte
= bfd_get_8 (abfd
, buf
);
6645 result
|= ((unsigned long)(byte
& 127) << shift
);
6646 if ((byte
& 128) == 0)
6652 *bytes_read_ptr
= num_read
;
6657 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6660 int i
, shift
, num_read
;
6669 byte
= bfd_get_8 (abfd
, buf
);
6672 result
|= ((long)(byte
& 127) << shift
);
6674 if ((byte
& 128) == 0)
6679 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6680 result
|= -(((long)1) << shift
);
6681 *bytes_read_ptr
= num_read
;
6685 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6688 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6694 byte
= bfd_get_8 (abfd
, buf
);
6696 if ((byte
& 128) == 0)
6702 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6708 cu
->language
= language_c
;
6710 case DW_LANG_C_plus_plus
:
6711 cu
->language
= language_cplus
;
6713 case DW_LANG_Fortran77
:
6714 case DW_LANG_Fortran90
:
6715 case DW_LANG_Fortran95
:
6716 cu
->language
= language_fortran
;
6718 case DW_LANG_Mips_Assembler
:
6719 cu
->language
= language_asm
;
6722 cu
->language
= language_java
;
6726 cu
->language
= language_ada
;
6728 case DW_LANG_Modula2
:
6729 cu
->language
= language_m2
;
6731 case DW_LANG_Pascal83
:
6732 cu
->language
= language_pascal
;
6735 cu
->language
= language_objc
;
6737 case DW_LANG_Cobol74
:
6738 case DW_LANG_Cobol85
:
6740 cu
->language
= language_minimal
;
6743 cu
->language_defn
= language_def (cu
->language
);
6746 /* Return the named attribute or NULL if not there. */
6748 static struct attribute
*
6749 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6752 struct attribute
*spec
= NULL
;
6754 for (i
= 0; i
< die
->num_attrs
; ++i
)
6756 if (die
->attrs
[i
].name
== name
)
6757 return &die
->attrs
[i
];
6758 if (die
->attrs
[i
].name
== DW_AT_specification
6759 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6760 spec
= &die
->attrs
[i
];
6764 return dwarf2_attr (follow_die_ref (die
, spec
, cu
), name
, cu
);
6769 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6770 and holds a non-zero value. This function should only be used for
6771 DW_FORM_flag attributes. */
6774 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6776 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6778 return (attr
&& DW_UNSND (attr
));
6782 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6784 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6785 which value is non-zero. However, we have to be careful with
6786 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6787 (via dwarf2_flag_true_p) follows this attribute. So we may
6788 end up accidently finding a declaration attribute that belongs
6789 to a different DIE referenced by the specification attribute,
6790 even though the given DIE does not have a declaration attribute. */
6791 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6792 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6795 /* Return the die giving the specification for DIE, if there is
6798 static struct die_info
*
6799 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6801 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6803 if (spec_attr
== NULL
)
6806 return follow_die_ref (die
, spec_attr
, cu
);
6809 /* Free the line_header structure *LH, and any arrays and strings it
6812 free_line_header (struct line_header
*lh
)
6814 if (lh
->standard_opcode_lengths
)
6815 xfree (lh
->standard_opcode_lengths
);
6817 /* Remember that all the lh->file_names[i].name pointers are
6818 pointers into debug_line_buffer, and don't need to be freed. */
6820 xfree (lh
->file_names
);
6822 /* Similarly for the include directory names. */
6823 if (lh
->include_dirs
)
6824 xfree (lh
->include_dirs
);
6830 /* Add an entry to LH's include directory table. */
6832 add_include_dir (struct line_header
*lh
, char *include_dir
)
6834 /* Grow the array if necessary. */
6835 if (lh
->include_dirs_size
== 0)
6837 lh
->include_dirs_size
= 1; /* for testing */
6838 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6839 * sizeof (*lh
->include_dirs
));
6841 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6843 lh
->include_dirs_size
*= 2;
6844 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6845 (lh
->include_dirs_size
6846 * sizeof (*lh
->include_dirs
)));
6849 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6853 /* Add an entry to LH's file name table. */
6855 add_file_name (struct line_header
*lh
,
6857 unsigned int dir_index
,
6858 unsigned int mod_time
,
6859 unsigned int length
)
6861 struct file_entry
*fe
;
6863 /* Grow the array if necessary. */
6864 if (lh
->file_names_size
== 0)
6866 lh
->file_names_size
= 1; /* for testing */
6867 lh
->file_names
= xmalloc (lh
->file_names_size
6868 * sizeof (*lh
->file_names
));
6870 else if (lh
->num_file_names
>= lh
->file_names_size
)
6872 lh
->file_names_size
*= 2;
6873 lh
->file_names
= xrealloc (lh
->file_names
,
6874 (lh
->file_names_size
6875 * sizeof (*lh
->file_names
)));
6878 fe
= &lh
->file_names
[lh
->num_file_names
++];
6880 fe
->dir_index
= dir_index
;
6881 fe
->mod_time
= mod_time
;
6882 fe
->length
= length
;
6888 /* Read the statement program header starting at OFFSET in
6889 .debug_line, according to the endianness of ABFD. Return a pointer
6890 to a struct line_header, allocated using xmalloc.
6892 NOTE: the strings in the include directory and file name tables of
6893 the returned object point into debug_line_buffer, and must not be
6895 static struct line_header
*
6896 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6897 struct dwarf2_cu
*cu
)
6899 struct cleanup
*back_to
;
6900 struct line_header
*lh
;
6902 unsigned int bytes_read
;
6904 char *cur_dir
, *cur_file
;
6906 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6908 complaint (&symfile_complaints
, _("missing .debug_line section"));
6912 /* Make sure that at least there's room for the total_length field.
6913 That could be 12 bytes long, but we're just going to fudge that. */
6914 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6916 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6920 lh
= xmalloc (sizeof (*lh
));
6921 memset (lh
, 0, sizeof (*lh
));
6922 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6925 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6927 /* Read in the header. */
6929 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6930 line_ptr
+= bytes_read
;
6931 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6932 + dwarf2_per_objfile
->line_size
))
6934 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6937 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6938 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6940 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6941 line_ptr
+= bytes_read
;
6942 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6944 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6946 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6948 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6950 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6952 lh
->standard_opcode_lengths
6953 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6955 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6956 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6958 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6962 /* Read directory table. */
6963 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6965 line_ptr
+= bytes_read
;
6966 add_include_dir (lh
, cur_dir
);
6968 line_ptr
+= bytes_read
;
6970 /* Read file name table. */
6971 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6973 unsigned int dir_index
, mod_time
, length
;
6975 line_ptr
+= bytes_read
;
6976 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6977 line_ptr
+= bytes_read
;
6978 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6979 line_ptr
+= bytes_read
;
6980 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6981 line_ptr
+= bytes_read
;
6983 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6985 line_ptr
+= bytes_read
;
6986 lh
->statement_program_start
= line_ptr
;
6988 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6989 + dwarf2_per_objfile
->line_size
))
6990 complaint (&symfile_complaints
,
6991 _("line number info header doesn't fit in `.debug_line' section"));
6993 discard_cleanups (back_to
);
6997 /* This function exists to work around a bug in certain compilers
6998 (particularly GCC 2.95), in which the first line number marker of a
6999 function does not show up until after the prologue, right before
7000 the second line number marker. This function shifts ADDRESS down
7001 to the beginning of the function if necessary, and is called on
7002 addresses passed to record_line. */
7005 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7007 struct function_range
*fn
;
7009 /* Find the function_range containing address. */
7014 cu
->cached_fn
= cu
->first_fn
;
7018 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7024 while (fn
&& fn
!= cu
->cached_fn
)
7025 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7035 if (address
!= fn
->lowpc
)
7036 complaint (&symfile_complaints
,
7037 _("misplaced first line number at 0x%lx for '%s'"),
7038 (unsigned long) address
, fn
->name
);
7043 /* Decode the Line Number Program (LNP) for the given line_header
7044 structure and CU. The actual information extracted and the type
7045 of structures created from the LNP depends on the value of PST.
7047 1. If PST is NULL, then this procedure uses the data from the program
7048 to create all necessary symbol tables, and their linetables.
7049 The compilation directory of the file is passed in COMP_DIR,
7050 and must not be NULL.
7052 2. If PST is not NULL, this procedure reads the program to determine
7053 the list of files included by the unit represented by PST, and
7054 builds all the associated partial symbol tables. In this case,
7055 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7056 is not used to compute the full name of the symtab, and therefore
7057 omitting it when building the partial symtab does not introduce
7058 the potential for inconsistency - a partial symtab and its associated
7059 symbtab having a different fullname -). */
7062 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7063 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7065 gdb_byte
*line_ptr
, *extended_end
;
7067 unsigned int bytes_read
, extended_len
;
7068 unsigned char op_code
, extended_op
, adj_opcode
;
7070 struct objfile
*objfile
= cu
->objfile
;
7071 const int decode_for_pst_p
= (pst
!= NULL
);
7072 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7074 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7076 line_ptr
= lh
->statement_program_start
;
7077 line_end
= lh
->statement_program_end
;
7079 /* Read the statement sequences until there's nothing left. */
7080 while (line_ptr
< line_end
)
7082 /* state machine registers */
7083 CORE_ADDR address
= 0;
7084 unsigned int file
= 1;
7085 unsigned int line
= 1;
7086 unsigned int column
= 0;
7087 int is_stmt
= lh
->default_is_stmt
;
7088 int basic_block
= 0;
7089 int end_sequence
= 0;
7091 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7093 /* Start a subfile for the current file of the state machine. */
7094 /* lh->include_dirs and lh->file_names are 0-based, but the
7095 directory and file name numbers in the statement program
7097 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7101 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7103 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7106 /* Decode the table. */
7107 while (!end_sequence
)
7109 op_code
= read_1_byte (abfd
, line_ptr
);
7112 if (op_code
>= lh
->opcode_base
)
7114 /* Special operand. */
7115 adj_opcode
= op_code
- lh
->opcode_base
;
7116 address
+= (adj_opcode
/ lh
->line_range
)
7117 * lh
->minimum_instruction_length
;
7118 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7119 if (lh
->num_file_names
< file
)
7120 dwarf2_debug_line_missing_file_complaint ();
7123 lh
->file_names
[file
- 1].included_p
= 1;
7124 if (!decode_for_pst_p
)
7126 if (last_subfile
!= current_subfile
)
7129 record_line (last_subfile
, 0, address
);
7130 last_subfile
= current_subfile
;
7132 /* Append row to matrix using current values. */
7133 record_line (current_subfile
, line
,
7134 check_cu_functions (address
, cu
));
7139 else switch (op_code
)
7141 case DW_LNS_extended_op
:
7142 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7143 line_ptr
+= bytes_read
;
7144 extended_end
= line_ptr
+ extended_len
;
7145 extended_op
= read_1_byte (abfd
, line_ptr
);
7147 switch (extended_op
)
7149 case DW_LNE_end_sequence
:
7152 if (lh
->num_file_names
< file
)
7153 dwarf2_debug_line_missing_file_complaint ();
7156 lh
->file_names
[file
- 1].included_p
= 1;
7157 if (!decode_for_pst_p
)
7158 record_line (current_subfile
, 0, address
);
7161 case DW_LNE_set_address
:
7162 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7163 line_ptr
+= bytes_read
;
7164 address
+= baseaddr
;
7166 case DW_LNE_define_file
:
7169 unsigned int dir_index
, mod_time
, length
;
7171 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7172 line_ptr
+= bytes_read
;
7174 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7175 line_ptr
+= bytes_read
;
7177 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7178 line_ptr
+= bytes_read
;
7180 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7181 line_ptr
+= bytes_read
;
7182 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7186 complaint (&symfile_complaints
,
7187 _("mangled .debug_line section"));
7190 /* Make sure that we parsed the extended op correctly. If e.g.
7191 we expected a different address size than the producer used,
7192 we may have read the wrong number of bytes. */
7193 if (line_ptr
!= extended_end
)
7195 complaint (&symfile_complaints
,
7196 _("mangled .debug_line section"));
7201 if (lh
->num_file_names
< file
)
7202 dwarf2_debug_line_missing_file_complaint ();
7205 lh
->file_names
[file
- 1].included_p
= 1;
7206 if (!decode_for_pst_p
)
7208 if (last_subfile
!= current_subfile
)
7211 record_line (last_subfile
, 0, address
);
7212 last_subfile
= current_subfile
;
7214 record_line (current_subfile
, line
,
7215 check_cu_functions (address
, cu
));
7220 case DW_LNS_advance_pc
:
7221 address
+= lh
->minimum_instruction_length
7222 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7223 line_ptr
+= bytes_read
;
7225 case DW_LNS_advance_line
:
7226 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7227 line_ptr
+= bytes_read
;
7229 case DW_LNS_set_file
:
7231 /* The arrays lh->include_dirs and lh->file_names are
7232 0-based, but the directory and file name numbers in
7233 the statement program are 1-based. */
7234 struct file_entry
*fe
;
7237 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7238 line_ptr
+= bytes_read
;
7239 if (lh
->num_file_names
< file
)
7240 dwarf2_debug_line_missing_file_complaint ();
7243 fe
= &lh
->file_names
[file
- 1];
7245 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7246 if (!decode_for_pst_p
)
7248 last_subfile
= current_subfile
;
7249 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7254 case DW_LNS_set_column
:
7255 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7256 line_ptr
+= bytes_read
;
7258 case DW_LNS_negate_stmt
:
7259 is_stmt
= (!is_stmt
);
7261 case DW_LNS_set_basic_block
:
7264 /* Add to the address register of the state machine the
7265 address increment value corresponding to special opcode
7266 255. I.e., this value is scaled by the minimum
7267 instruction length since special opcode 255 would have
7268 scaled the the increment. */
7269 case DW_LNS_const_add_pc
:
7270 address
+= (lh
->minimum_instruction_length
7271 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7273 case DW_LNS_fixed_advance_pc
:
7274 address
+= read_2_bytes (abfd
, line_ptr
);
7279 /* Unknown standard opcode, ignore it. */
7282 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7284 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7285 line_ptr
+= bytes_read
;
7292 if (decode_for_pst_p
)
7296 /* Now that we're done scanning the Line Header Program, we can
7297 create the psymtab of each included file. */
7298 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7299 if (lh
->file_names
[file_index
].included_p
== 1)
7301 const struct file_entry fe
= lh
->file_names
[file_index
];
7302 char *include_name
= fe
.name
;
7303 char *dir_name
= NULL
;
7304 char *pst_filename
= pst
->filename
;
7307 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7309 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7311 include_name
= concat (dir_name
, SLASH_STRING
,
7312 include_name
, (char *)NULL
);
7313 make_cleanup (xfree
, include_name
);
7316 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7318 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7319 pst_filename
, (char *)NULL
);
7320 make_cleanup (xfree
, pst_filename
);
7323 if (strcmp (include_name
, pst_filename
) != 0)
7324 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7329 /* Make sure a symtab is created for every file, even files
7330 which contain only variables (i.e. no code with associated
7334 struct file_entry
*fe
;
7336 for (i
= 0; i
< lh
->num_file_names
; i
++)
7339 fe
= &lh
->file_names
[i
];
7341 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7342 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7344 /* Skip the main file; we don't need it, and it must be
7345 allocated last, so that it will show up before the
7346 non-primary symtabs in the objfile's symtab list. */
7347 if (current_subfile
== first_subfile
)
7350 if (current_subfile
->symtab
== NULL
)
7351 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7353 fe
->symtab
= current_subfile
->symtab
;
7358 /* Start a subfile for DWARF. FILENAME is the name of the file and
7359 DIRNAME the name of the source directory which contains FILENAME
7360 or NULL if not known. COMP_DIR is the compilation directory for the
7361 linetable's compilation unit or NULL if not known.
7362 This routine tries to keep line numbers from identical absolute and
7363 relative file names in a common subfile.
7365 Using the `list' example from the GDB testsuite, which resides in
7366 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7367 of /srcdir/list0.c yields the following debugging information for list0.c:
7369 DW_AT_name: /srcdir/list0.c
7370 DW_AT_comp_dir: /compdir
7371 files.files[0].name: list0.h
7372 files.files[0].dir: /srcdir
7373 files.files[1].name: list0.c
7374 files.files[1].dir: /srcdir
7376 The line number information for list0.c has to end up in a single
7377 subfile, so that `break /srcdir/list0.c:1' works as expected.
7378 start_subfile will ensure that this happens provided that we pass the
7379 concatenation of files.files[1].dir and files.files[1].name as the
7383 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7387 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7388 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7389 second argument to start_subfile. To be consistent, we do the
7390 same here. In order not to lose the line information directory,
7391 we concatenate it to the filename when it makes sense.
7392 Note that the Dwarf3 standard says (speaking of filenames in line
7393 information): ``The directory index is ignored for file names
7394 that represent full path names''. Thus ignoring dirname in the
7395 `else' branch below isn't an issue. */
7397 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7398 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7400 fullname
= filename
;
7402 start_subfile (fullname
, comp_dir
);
7404 if (fullname
!= filename
)
7409 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7410 struct dwarf2_cu
*cu
)
7412 struct objfile
*objfile
= cu
->objfile
;
7413 struct comp_unit_head
*cu_header
= &cu
->header
;
7415 /* NOTE drow/2003-01-30: There used to be a comment and some special
7416 code here to turn a symbol with DW_AT_external and a
7417 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7418 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7419 with some versions of binutils) where shared libraries could have
7420 relocations against symbols in their debug information - the
7421 minimal symbol would have the right address, but the debug info
7422 would not. It's no longer necessary, because we will explicitly
7423 apply relocations when we read in the debug information now. */
7425 /* A DW_AT_location attribute with no contents indicates that a
7426 variable has been optimized away. */
7427 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7429 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7433 /* Handle one degenerate form of location expression specially, to
7434 preserve GDB's previous behavior when section offsets are
7435 specified. If this is just a DW_OP_addr then mark this symbol
7438 if (attr_form_is_block (attr
)
7439 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7440 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7444 SYMBOL_VALUE_ADDRESS (sym
) =
7445 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7446 fixup_symbol_section (sym
, objfile
);
7447 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7448 SYMBOL_SECTION (sym
));
7449 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7453 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7454 expression evaluator, and use LOC_COMPUTED only when necessary
7455 (i.e. when the value of a register or memory location is
7456 referenced, or a thread-local block, etc.). Then again, it might
7457 not be worthwhile. I'm assuming that it isn't unless performance
7458 or memory numbers show me otherwise. */
7460 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7461 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7464 /* Given a pointer to a DWARF information entry, figure out if we need
7465 to make a symbol table entry for it, and if so, create a new entry
7466 and return a pointer to it.
7467 If TYPE is NULL, determine symbol type from the die, otherwise
7468 used the passed type. */
7470 static struct symbol
*
7471 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7473 struct objfile
*objfile
= cu
->objfile
;
7474 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7475 struct symbol
*sym
= NULL
;
7477 struct attribute
*attr
= NULL
;
7478 struct attribute
*attr2
= NULL
;
7481 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7483 if (die
->tag
!= DW_TAG_namespace
)
7484 name
= dwarf2_linkage_name (die
, cu
);
7486 name
= TYPE_NAME (type
);
7490 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7491 sizeof (struct symbol
));
7492 OBJSTAT (objfile
, n_syms
++);
7493 memset (sym
, 0, sizeof (struct symbol
));
7495 /* Cache this symbol's name and the name's demangled form (if any). */
7496 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7497 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7499 /* Default assumptions.
7500 Use the passed type or decode it from the die. */
7501 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7502 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7504 SYMBOL_TYPE (sym
) = type
;
7506 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7507 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7510 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7513 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7516 int file_index
= DW_UNSND (attr
);
7517 if (cu
->line_header
== NULL
7518 || file_index
> cu
->line_header
->num_file_names
)
7519 complaint (&symfile_complaints
,
7520 _("file index out of range"));
7521 else if (file_index
> 0)
7523 struct file_entry
*fe
;
7524 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7525 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7532 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7535 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7537 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7539 case DW_TAG_subprogram
:
7540 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7542 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7543 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7544 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7545 || cu
->language
== language_ada
)
7547 /* Subprograms marked external are stored as a global symbol.
7548 Ada subprograms, whether marked external or not, are always
7549 stored as a global symbol, because we want to be able to
7550 access them globally. For instance, we want to be able
7551 to break on a nested subprogram without having to
7552 specify the context. */
7553 add_symbol_to_list (sym
, &global_symbols
);
7557 add_symbol_to_list (sym
, cu
->list_in_scope
);
7560 case DW_TAG_variable
:
7561 /* Compilation with minimal debug info may result in variables
7562 with missing type entries. Change the misleading `void' type
7563 to something sensible. */
7564 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7566 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7568 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7571 dwarf2_const_value (attr
, sym
, cu
);
7572 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7573 if (attr2
&& (DW_UNSND (attr2
) != 0))
7574 add_symbol_to_list (sym
, &global_symbols
);
7576 add_symbol_to_list (sym
, cu
->list_in_scope
);
7579 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7582 var_decode_location (attr
, sym
, cu
);
7583 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7584 if (attr2
&& (DW_UNSND (attr2
) != 0))
7585 add_symbol_to_list (sym
, &global_symbols
);
7587 add_symbol_to_list (sym
, cu
->list_in_scope
);
7591 /* We do not know the address of this symbol.
7592 If it is an external symbol and we have type information
7593 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7594 The address of the variable will then be determined from
7595 the minimal symbol table whenever the variable is
7597 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7598 if (attr2
&& (DW_UNSND (attr2
) != 0)
7599 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7601 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7602 add_symbol_to_list (sym
, &global_symbols
);
7606 case DW_TAG_formal_parameter
:
7607 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7610 var_decode_location (attr
, sym
, cu
);
7611 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
7612 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
7613 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
7615 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7618 dwarf2_const_value (attr
, sym
, cu
);
7620 add_symbol_to_list (sym
, cu
->list_in_scope
);
7622 case DW_TAG_unspecified_parameters
:
7623 /* From varargs functions; gdb doesn't seem to have any
7624 interest in this information, so just ignore it for now.
7627 case DW_TAG_class_type
:
7628 case DW_TAG_interface_type
:
7629 case DW_TAG_structure_type
:
7630 case DW_TAG_union_type
:
7631 case DW_TAG_set_type
:
7632 case DW_TAG_enumeration_type
:
7633 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7634 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7636 /* Make sure that the symbol includes appropriate enclosing
7637 classes/namespaces in its name. These are calculated in
7638 read_structure_type, and the correct name is saved in
7641 if (cu
->language
== language_cplus
7642 || cu
->language
== language_java
)
7644 struct type
*type
= SYMBOL_TYPE (sym
);
7646 if (TYPE_TAG_NAME (type
) != NULL
)
7648 /* FIXME: carlton/2003-11-10: Should this use
7649 SYMBOL_SET_NAMES instead? (The same problem also
7650 arises further down in this function.) */
7651 /* The type's name is already allocated along with
7652 this objfile, so we don't need to duplicate it
7654 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7659 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7660 really ever be static objects: otherwise, if you try
7661 to, say, break of a class's method and you're in a file
7662 which doesn't mention that class, it won't work unless
7663 the check for all static symbols in lookup_symbol_aux
7664 saves you. See the OtherFileClass tests in
7665 gdb.c++/namespace.exp. */
7667 struct pending
**list_to_add
;
7669 list_to_add
= (cu
->list_in_scope
== &file_symbols
7670 && (cu
->language
== language_cplus
7671 || cu
->language
== language_java
)
7672 ? &global_symbols
: cu
->list_in_scope
);
7674 add_symbol_to_list (sym
, list_to_add
);
7676 /* The semantics of C++ state that "struct foo { ... }" also
7677 defines a typedef for "foo". A Java class declaration also
7678 defines a typedef for the class. Synthesize a typedef symbol
7679 so that "ptype foo" works as expected. */
7680 if (cu
->language
== language_cplus
7681 || cu
->language
== language_java
7682 || cu
->language
== language_ada
)
7684 struct symbol
*typedef_sym
= (struct symbol
*)
7685 obstack_alloc (&objfile
->objfile_obstack
,
7686 sizeof (struct symbol
));
7687 *typedef_sym
= *sym
;
7688 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
7689 /* The symbol's name is already allocated along with
7690 this objfile, so we don't need to duplicate it for
7692 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7693 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7694 add_symbol_to_list (typedef_sym
, list_to_add
);
7698 case DW_TAG_typedef
:
7699 if (processing_has_namespace_info
7700 && processing_current_prefix
[0] != '\0')
7702 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7703 processing_current_prefix
,
7706 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7707 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7708 add_symbol_to_list (sym
, cu
->list_in_scope
);
7710 case DW_TAG_base_type
:
7711 case DW_TAG_subrange_type
:
7712 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7713 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7714 add_symbol_to_list (sym
, cu
->list_in_scope
);
7716 case DW_TAG_enumerator
:
7717 if (processing_has_namespace_info
7718 && processing_current_prefix
[0] != '\0')
7720 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7721 processing_current_prefix
,
7724 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7727 dwarf2_const_value (attr
, sym
, cu
);
7730 /* NOTE: carlton/2003-11-10: See comment above in the
7731 DW_TAG_class_type, etc. block. */
7733 struct pending
**list_to_add
;
7735 list_to_add
= (cu
->list_in_scope
== &file_symbols
7736 && (cu
->language
== language_cplus
7737 || cu
->language
== language_java
)
7738 ? &global_symbols
: cu
->list_in_scope
);
7740 add_symbol_to_list (sym
, list_to_add
);
7743 case DW_TAG_namespace
:
7744 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7745 add_symbol_to_list (sym
, &global_symbols
);
7748 /* Not a tag we recognize. Hopefully we aren't processing
7749 trash data, but since we must specifically ignore things
7750 we don't recognize, there is nothing else we should do at
7752 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7753 dwarf_tag_name (die
->tag
));
7760 /* Copy constant value from an attribute to a symbol. */
7763 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7764 struct dwarf2_cu
*cu
)
7766 struct objfile
*objfile
= cu
->objfile
;
7767 struct comp_unit_head
*cu_header
= &cu
->header
;
7768 struct dwarf_block
*blk
;
7773 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7774 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7775 cu_header
->addr_size
,
7776 TYPE_LENGTH (SYMBOL_TYPE
7778 SYMBOL_VALUE_BYTES (sym
) =
7779 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7780 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7781 it's body - store_unsigned_integer. */
7782 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7784 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7787 /* DW_STRING is already allocated on the obstack, point directly
7789 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7790 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7792 case DW_FORM_block1
:
7793 case DW_FORM_block2
:
7794 case DW_FORM_block4
:
7796 blk
= DW_BLOCK (attr
);
7797 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7798 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7800 TYPE_LENGTH (SYMBOL_TYPE
7802 SYMBOL_VALUE_BYTES (sym
) =
7803 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7804 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7805 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7808 /* The DW_AT_const_value attributes are supposed to carry the
7809 symbol's value "represented as it would be on the target
7810 architecture." By the time we get here, it's already been
7811 converted to host endianness, so we just need to sign- or
7812 zero-extend it as appropriate. */
7814 dwarf2_const_value_data (attr
, sym
, 8);
7817 dwarf2_const_value_data (attr
, sym
, 16);
7820 dwarf2_const_value_data (attr
, sym
, 32);
7823 dwarf2_const_value_data (attr
, sym
, 64);
7827 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7828 SYMBOL_CLASS (sym
) = LOC_CONST
;
7832 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7833 SYMBOL_CLASS (sym
) = LOC_CONST
;
7837 complaint (&symfile_complaints
,
7838 _("unsupported const value attribute form: '%s'"),
7839 dwarf_form_name (attr
->form
));
7840 SYMBOL_VALUE (sym
) = 0;
7841 SYMBOL_CLASS (sym
) = LOC_CONST
;
7847 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7848 or zero-extend it as appropriate for the symbol's type. */
7850 dwarf2_const_value_data (struct attribute
*attr
,
7854 LONGEST l
= DW_UNSND (attr
);
7856 if (bits
< sizeof (l
) * 8)
7858 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7859 l
&= ((LONGEST
) 1 << bits
) - 1;
7861 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7864 SYMBOL_VALUE (sym
) = l
;
7865 SYMBOL_CLASS (sym
) = LOC_CONST
;
7869 /* Return the type of the die in question using its DW_AT_type attribute. */
7871 static struct type
*
7872 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7874 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7876 struct attribute
*type_attr
;
7877 struct die_info
*type_die
;
7879 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7882 /* A missing DW_AT_type represents a void type. */
7883 return builtin_type (gdbarch
)->builtin_void
;
7886 type_die
= follow_die_ref (die
, type_attr
, cu
);
7888 type
= tag_type_to_type (type_die
, cu
);
7891 dump_die (type_die
);
7892 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7898 /* Return the containing type of the die in question using its
7899 DW_AT_containing_type attribute. */
7901 static struct type
*
7902 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7904 struct type
*type
= NULL
;
7905 struct attribute
*type_attr
;
7906 struct die_info
*type_die
= NULL
;
7908 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7911 type_die
= follow_die_ref (die
, type_attr
, cu
);
7912 type
= tag_type_to_type (type_die
, cu
);
7917 dump_die (type_die
);
7918 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7924 static struct type
*
7925 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7933 read_type_die (die
, cu
);
7937 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7945 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7947 char *prefix
= determine_prefix (die
, cu
);
7948 const char *old_prefix
= processing_current_prefix
;
7949 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
7950 processing_current_prefix
= prefix
;
7954 case DW_TAG_class_type
:
7955 case DW_TAG_interface_type
:
7956 case DW_TAG_structure_type
:
7957 case DW_TAG_union_type
:
7958 read_structure_type (die
, cu
);
7960 case DW_TAG_enumeration_type
:
7961 read_enumeration_type (die
, cu
);
7963 case DW_TAG_subprogram
:
7964 case DW_TAG_subroutine_type
:
7965 read_subroutine_type (die
, cu
);
7967 case DW_TAG_array_type
:
7968 read_array_type (die
, cu
);
7970 case DW_TAG_set_type
:
7971 read_set_type (die
, cu
);
7973 case DW_TAG_pointer_type
:
7974 read_tag_pointer_type (die
, cu
);
7976 case DW_TAG_ptr_to_member_type
:
7977 read_tag_ptr_to_member_type (die
, cu
);
7979 case DW_TAG_reference_type
:
7980 read_tag_reference_type (die
, cu
);
7982 case DW_TAG_const_type
:
7983 read_tag_const_type (die
, cu
);
7985 case DW_TAG_volatile_type
:
7986 read_tag_volatile_type (die
, cu
);
7988 case DW_TAG_string_type
:
7989 read_tag_string_type (die
, cu
);
7991 case DW_TAG_typedef
:
7992 read_typedef (die
, cu
);
7994 case DW_TAG_subrange_type
:
7995 read_subrange_type (die
, cu
);
7997 case DW_TAG_base_type
:
7998 read_base_type (die
, cu
);
8000 case DW_TAG_unspecified_type
:
8001 read_unspecified_type (die
, cu
);
8004 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8005 dwarf_tag_name (die
->tag
));
8009 processing_current_prefix
= old_prefix
;
8010 do_cleanups (back_to
);
8013 /* Return the name of the namespace/class that DIE is defined within,
8014 or "" if we can't tell. The caller should xfree the result. */
8016 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
8017 therein) for an example of how to use this function to deal with
8018 DW_AT_specification. */
8021 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8023 struct die_info
*parent
;
8025 if (cu
->language
!= language_cplus
8026 && cu
->language
!= language_java
)
8029 parent
= die
->parent
;
8033 return xstrdup ("");
8037 switch (parent
->tag
) {
8038 case DW_TAG_namespace
:
8040 /* FIXME: carlton/2004-03-05: Should I follow extension dies
8041 before doing this check? */
8042 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
8044 return xstrdup (TYPE_TAG_NAME (parent
->type
));
8049 char *parent_prefix
= determine_prefix (parent
, cu
);
8050 char *retval
= typename_concat (NULL
, parent_prefix
,
8051 namespace_name (parent
, &dummy
,
8054 xfree (parent_prefix
);
8059 case DW_TAG_class_type
:
8060 case DW_TAG_interface_type
:
8061 case DW_TAG_structure_type
:
8063 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
8065 return xstrdup (TYPE_TAG_NAME (parent
->type
));
8069 const char *old_prefix
= processing_current_prefix
;
8070 char *new_prefix
= determine_prefix (parent
, cu
);
8073 processing_current_prefix
= new_prefix
;
8074 retval
= determine_class_name (parent
, cu
);
8075 processing_current_prefix
= old_prefix
;
8082 return determine_prefix (parent
, cu
);
8087 /* Return a newly-allocated string formed by concatenating PREFIX and
8088 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8089 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8090 perform an obconcat, otherwise allocate storage for the result. The CU argument
8091 is used to determine the language and hence, the appropriate separator. */
8093 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8096 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8097 struct dwarf2_cu
*cu
)
8101 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8103 else if (cu
->language
== language_java
)
8110 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8115 strcpy (retval
, prefix
);
8116 strcat (retval
, sep
);
8119 strcat (retval
, suffix
);
8125 /* We have an obstack. */
8126 return obconcat (obs
, prefix
, sep
, suffix
);
8132 copy_die (struct die_info
*old_die
)
8134 struct die_info
*new_die
;
8137 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8138 memset (new_die
, 0, sizeof (struct die_info
));
8140 new_die
->tag
= old_die
->tag
;
8141 new_die
->has_children
= old_die
->has_children
;
8142 new_die
->abbrev
= old_die
->abbrev
;
8143 new_die
->offset
= old_die
->offset
;
8144 new_die
->type
= NULL
;
8146 num_attrs
= old_die
->num_attrs
;
8147 new_die
->num_attrs
= num_attrs
;
8148 new_die
->attrs
= (struct attribute
*)
8149 xmalloc (num_attrs
* sizeof (struct attribute
));
8151 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
8153 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
8154 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
8155 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
8158 new_die
->next
= NULL
;
8163 /* Return sibling of die, NULL if no sibling. */
8165 static struct die_info
*
8166 sibling_die (struct die_info
*die
)
8168 return die
->sibling
;
8171 /* Get linkage name of a die, return NULL if not found. */
8174 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8176 struct attribute
*attr
;
8178 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8179 if (attr
&& DW_STRING (attr
))
8180 return DW_STRING (attr
);
8181 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8182 if (attr
&& DW_STRING (attr
))
8183 return DW_STRING (attr
);
8187 /* Get name of a die, return NULL if not found. */
8190 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8192 struct attribute
*attr
;
8194 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8195 if (attr
&& DW_STRING (attr
))
8196 return DW_STRING (attr
);
8200 /* Return the die that this die in an extension of, or NULL if there
8203 static struct die_info
*
8204 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
8206 struct attribute
*attr
;
8208 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
8212 return follow_die_ref (die
, attr
, cu
);
8215 /* Convert a DIE tag into its string name. */
8218 dwarf_tag_name (unsigned tag
)
8222 case DW_TAG_padding
:
8223 return "DW_TAG_padding";
8224 case DW_TAG_array_type
:
8225 return "DW_TAG_array_type";
8226 case DW_TAG_class_type
:
8227 return "DW_TAG_class_type";
8228 case DW_TAG_entry_point
:
8229 return "DW_TAG_entry_point";
8230 case DW_TAG_enumeration_type
:
8231 return "DW_TAG_enumeration_type";
8232 case DW_TAG_formal_parameter
:
8233 return "DW_TAG_formal_parameter";
8234 case DW_TAG_imported_declaration
:
8235 return "DW_TAG_imported_declaration";
8237 return "DW_TAG_label";
8238 case DW_TAG_lexical_block
:
8239 return "DW_TAG_lexical_block";
8241 return "DW_TAG_member";
8242 case DW_TAG_pointer_type
:
8243 return "DW_TAG_pointer_type";
8244 case DW_TAG_reference_type
:
8245 return "DW_TAG_reference_type";
8246 case DW_TAG_compile_unit
:
8247 return "DW_TAG_compile_unit";
8248 case DW_TAG_string_type
:
8249 return "DW_TAG_string_type";
8250 case DW_TAG_structure_type
:
8251 return "DW_TAG_structure_type";
8252 case DW_TAG_subroutine_type
:
8253 return "DW_TAG_subroutine_type";
8254 case DW_TAG_typedef
:
8255 return "DW_TAG_typedef";
8256 case DW_TAG_union_type
:
8257 return "DW_TAG_union_type";
8258 case DW_TAG_unspecified_parameters
:
8259 return "DW_TAG_unspecified_parameters";
8260 case DW_TAG_variant
:
8261 return "DW_TAG_variant";
8262 case DW_TAG_common_block
:
8263 return "DW_TAG_common_block";
8264 case DW_TAG_common_inclusion
:
8265 return "DW_TAG_common_inclusion";
8266 case DW_TAG_inheritance
:
8267 return "DW_TAG_inheritance";
8268 case DW_TAG_inlined_subroutine
:
8269 return "DW_TAG_inlined_subroutine";
8271 return "DW_TAG_module";
8272 case DW_TAG_ptr_to_member_type
:
8273 return "DW_TAG_ptr_to_member_type";
8274 case DW_TAG_set_type
:
8275 return "DW_TAG_set_type";
8276 case DW_TAG_subrange_type
:
8277 return "DW_TAG_subrange_type";
8278 case DW_TAG_with_stmt
:
8279 return "DW_TAG_with_stmt";
8280 case DW_TAG_access_declaration
:
8281 return "DW_TAG_access_declaration";
8282 case DW_TAG_base_type
:
8283 return "DW_TAG_base_type";
8284 case DW_TAG_catch_block
:
8285 return "DW_TAG_catch_block";
8286 case DW_TAG_const_type
:
8287 return "DW_TAG_const_type";
8288 case DW_TAG_constant
:
8289 return "DW_TAG_constant";
8290 case DW_TAG_enumerator
:
8291 return "DW_TAG_enumerator";
8292 case DW_TAG_file_type
:
8293 return "DW_TAG_file_type";
8295 return "DW_TAG_friend";
8296 case DW_TAG_namelist
:
8297 return "DW_TAG_namelist";
8298 case DW_TAG_namelist_item
:
8299 return "DW_TAG_namelist_item";
8300 case DW_TAG_packed_type
:
8301 return "DW_TAG_packed_type";
8302 case DW_TAG_subprogram
:
8303 return "DW_TAG_subprogram";
8304 case DW_TAG_template_type_param
:
8305 return "DW_TAG_template_type_param";
8306 case DW_TAG_template_value_param
:
8307 return "DW_TAG_template_value_param";
8308 case DW_TAG_thrown_type
:
8309 return "DW_TAG_thrown_type";
8310 case DW_TAG_try_block
:
8311 return "DW_TAG_try_block";
8312 case DW_TAG_variant_part
:
8313 return "DW_TAG_variant_part";
8314 case DW_TAG_variable
:
8315 return "DW_TAG_variable";
8316 case DW_TAG_volatile_type
:
8317 return "DW_TAG_volatile_type";
8318 case DW_TAG_dwarf_procedure
:
8319 return "DW_TAG_dwarf_procedure";
8320 case DW_TAG_restrict_type
:
8321 return "DW_TAG_restrict_type";
8322 case DW_TAG_interface_type
:
8323 return "DW_TAG_interface_type";
8324 case DW_TAG_namespace
:
8325 return "DW_TAG_namespace";
8326 case DW_TAG_imported_module
:
8327 return "DW_TAG_imported_module";
8328 case DW_TAG_unspecified_type
:
8329 return "DW_TAG_unspecified_type";
8330 case DW_TAG_partial_unit
:
8331 return "DW_TAG_partial_unit";
8332 case DW_TAG_imported_unit
:
8333 return "DW_TAG_imported_unit";
8334 case DW_TAG_condition
:
8335 return "DW_TAG_condition";
8336 case DW_TAG_shared_type
:
8337 return "DW_TAG_shared_type";
8338 case DW_TAG_MIPS_loop
:
8339 return "DW_TAG_MIPS_loop";
8340 case DW_TAG_HP_array_descriptor
:
8341 return "DW_TAG_HP_array_descriptor";
8342 case DW_TAG_format_label
:
8343 return "DW_TAG_format_label";
8344 case DW_TAG_function_template
:
8345 return "DW_TAG_function_template";
8346 case DW_TAG_class_template
:
8347 return "DW_TAG_class_template";
8348 case DW_TAG_GNU_BINCL
:
8349 return "DW_TAG_GNU_BINCL";
8350 case DW_TAG_GNU_EINCL
:
8351 return "DW_TAG_GNU_EINCL";
8352 case DW_TAG_upc_shared_type
:
8353 return "DW_TAG_upc_shared_type";
8354 case DW_TAG_upc_strict_type
:
8355 return "DW_TAG_upc_strict_type";
8356 case DW_TAG_upc_relaxed_type
:
8357 return "DW_TAG_upc_relaxed_type";
8358 case DW_TAG_PGI_kanji_type
:
8359 return "DW_TAG_PGI_kanji_type";
8360 case DW_TAG_PGI_interface_block
:
8361 return "DW_TAG_PGI_interface_block";
8363 return "DW_TAG_<unknown>";
8367 /* Convert a DWARF attribute code into its string name. */
8370 dwarf_attr_name (unsigned attr
)
8375 return "DW_AT_sibling";
8376 case DW_AT_location
:
8377 return "DW_AT_location";
8379 return "DW_AT_name";
8380 case DW_AT_ordering
:
8381 return "DW_AT_ordering";
8382 case DW_AT_subscr_data
:
8383 return "DW_AT_subscr_data";
8384 case DW_AT_byte_size
:
8385 return "DW_AT_byte_size";
8386 case DW_AT_bit_offset
:
8387 return "DW_AT_bit_offset";
8388 case DW_AT_bit_size
:
8389 return "DW_AT_bit_size";
8390 case DW_AT_element_list
:
8391 return "DW_AT_element_list";
8392 case DW_AT_stmt_list
:
8393 return "DW_AT_stmt_list";
8395 return "DW_AT_low_pc";
8397 return "DW_AT_high_pc";
8398 case DW_AT_language
:
8399 return "DW_AT_language";
8401 return "DW_AT_member";
8403 return "DW_AT_discr";
8404 case DW_AT_discr_value
:
8405 return "DW_AT_discr_value";
8406 case DW_AT_visibility
:
8407 return "DW_AT_visibility";
8409 return "DW_AT_import";
8410 case DW_AT_string_length
:
8411 return "DW_AT_string_length";
8412 case DW_AT_common_reference
:
8413 return "DW_AT_common_reference";
8414 case DW_AT_comp_dir
:
8415 return "DW_AT_comp_dir";
8416 case DW_AT_const_value
:
8417 return "DW_AT_const_value";
8418 case DW_AT_containing_type
:
8419 return "DW_AT_containing_type";
8420 case DW_AT_default_value
:
8421 return "DW_AT_default_value";
8423 return "DW_AT_inline";
8424 case DW_AT_is_optional
:
8425 return "DW_AT_is_optional";
8426 case DW_AT_lower_bound
:
8427 return "DW_AT_lower_bound";
8428 case DW_AT_producer
:
8429 return "DW_AT_producer";
8430 case DW_AT_prototyped
:
8431 return "DW_AT_prototyped";
8432 case DW_AT_return_addr
:
8433 return "DW_AT_return_addr";
8434 case DW_AT_start_scope
:
8435 return "DW_AT_start_scope";
8436 case DW_AT_bit_stride
:
8437 return "DW_AT_bit_stride";
8438 case DW_AT_upper_bound
:
8439 return "DW_AT_upper_bound";
8440 case DW_AT_abstract_origin
:
8441 return "DW_AT_abstract_origin";
8442 case DW_AT_accessibility
:
8443 return "DW_AT_accessibility";
8444 case DW_AT_address_class
:
8445 return "DW_AT_address_class";
8446 case DW_AT_artificial
:
8447 return "DW_AT_artificial";
8448 case DW_AT_base_types
:
8449 return "DW_AT_base_types";
8450 case DW_AT_calling_convention
:
8451 return "DW_AT_calling_convention";
8453 return "DW_AT_count";
8454 case DW_AT_data_member_location
:
8455 return "DW_AT_data_member_location";
8456 case DW_AT_decl_column
:
8457 return "DW_AT_decl_column";
8458 case DW_AT_decl_file
:
8459 return "DW_AT_decl_file";
8460 case DW_AT_decl_line
:
8461 return "DW_AT_decl_line";
8462 case DW_AT_declaration
:
8463 return "DW_AT_declaration";
8464 case DW_AT_discr_list
:
8465 return "DW_AT_discr_list";
8466 case DW_AT_encoding
:
8467 return "DW_AT_encoding";
8468 case DW_AT_external
:
8469 return "DW_AT_external";
8470 case DW_AT_frame_base
:
8471 return "DW_AT_frame_base";
8473 return "DW_AT_friend";
8474 case DW_AT_identifier_case
:
8475 return "DW_AT_identifier_case";
8476 case DW_AT_macro_info
:
8477 return "DW_AT_macro_info";
8478 case DW_AT_namelist_items
:
8479 return "DW_AT_namelist_items";
8480 case DW_AT_priority
:
8481 return "DW_AT_priority";
8483 return "DW_AT_segment";
8484 case DW_AT_specification
:
8485 return "DW_AT_specification";
8486 case DW_AT_static_link
:
8487 return "DW_AT_static_link";
8489 return "DW_AT_type";
8490 case DW_AT_use_location
:
8491 return "DW_AT_use_location";
8492 case DW_AT_variable_parameter
:
8493 return "DW_AT_variable_parameter";
8494 case DW_AT_virtuality
:
8495 return "DW_AT_virtuality";
8496 case DW_AT_vtable_elem_location
:
8497 return "DW_AT_vtable_elem_location";
8498 /* DWARF 3 values. */
8499 case DW_AT_allocated
:
8500 return "DW_AT_allocated";
8501 case DW_AT_associated
:
8502 return "DW_AT_associated";
8503 case DW_AT_data_location
:
8504 return "DW_AT_data_location";
8505 case DW_AT_byte_stride
:
8506 return "DW_AT_byte_stride";
8507 case DW_AT_entry_pc
:
8508 return "DW_AT_entry_pc";
8509 case DW_AT_use_UTF8
:
8510 return "DW_AT_use_UTF8";
8511 case DW_AT_extension
:
8512 return "DW_AT_extension";
8514 return "DW_AT_ranges";
8515 case DW_AT_trampoline
:
8516 return "DW_AT_trampoline";
8517 case DW_AT_call_column
:
8518 return "DW_AT_call_column";
8519 case DW_AT_call_file
:
8520 return "DW_AT_call_file";
8521 case DW_AT_call_line
:
8522 return "DW_AT_call_line";
8523 case DW_AT_description
:
8524 return "DW_AT_description";
8525 case DW_AT_binary_scale
:
8526 return "DW_AT_binary_scale";
8527 case DW_AT_decimal_scale
:
8528 return "DW_AT_decimal_scale";
8530 return "DW_AT_small";
8531 case DW_AT_decimal_sign
:
8532 return "DW_AT_decimal_sign";
8533 case DW_AT_digit_count
:
8534 return "DW_AT_digit_count";
8535 case DW_AT_picture_string
:
8536 return "DW_AT_picture_string";
8538 return "DW_AT_mutable";
8539 case DW_AT_threads_scaled
:
8540 return "DW_AT_threads_scaled";
8541 case DW_AT_explicit
:
8542 return "DW_AT_explicit";
8543 case DW_AT_object_pointer
:
8544 return "DW_AT_object_pointer";
8545 case DW_AT_endianity
:
8546 return "DW_AT_endianity";
8547 case DW_AT_elemental
:
8548 return "DW_AT_elemental";
8550 return "DW_AT_pure";
8551 case DW_AT_recursive
:
8552 return "DW_AT_recursive";
8554 /* SGI/MIPS extensions. */
8555 case DW_AT_MIPS_fde
:
8556 return "DW_AT_MIPS_fde";
8557 case DW_AT_MIPS_loop_begin
:
8558 return "DW_AT_MIPS_loop_begin";
8559 case DW_AT_MIPS_tail_loop_begin
:
8560 return "DW_AT_MIPS_tail_loop_begin";
8561 case DW_AT_MIPS_epilog_begin
:
8562 return "DW_AT_MIPS_epilog_begin";
8563 case DW_AT_MIPS_loop_unroll_factor
:
8564 return "DW_AT_MIPS_loop_unroll_factor";
8565 case DW_AT_MIPS_software_pipeline_depth
:
8566 return "DW_AT_MIPS_software_pipeline_depth";
8567 case DW_AT_MIPS_linkage_name
:
8568 return "DW_AT_MIPS_linkage_name";
8569 case DW_AT_MIPS_stride
:
8570 return "DW_AT_MIPS_stride";
8571 case DW_AT_MIPS_abstract_name
:
8572 return "DW_AT_MIPS_abstract_name";
8573 case DW_AT_MIPS_clone_origin
:
8574 return "DW_AT_MIPS_clone_origin";
8575 case DW_AT_MIPS_has_inlines
:
8576 return "DW_AT_MIPS_has_inlines";
8578 /* HP extensions. */
8579 case DW_AT_HP_block_index
:
8580 return "DW_AT_HP_block_index";
8581 case DW_AT_HP_unmodifiable
:
8582 return "DW_AT_HP_unmodifiable";
8583 case DW_AT_HP_actuals_stmt_list
:
8584 return "DW_AT_HP_actuals_stmt_list";
8585 case DW_AT_HP_proc_per_section
:
8586 return "DW_AT_HP_proc_per_section";
8587 case DW_AT_HP_raw_data_ptr
:
8588 return "DW_AT_HP_raw_data_ptr";
8589 case DW_AT_HP_pass_by_reference
:
8590 return "DW_AT_HP_pass_by_reference";
8591 case DW_AT_HP_opt_level
:
8592 return "DW_AT_HP_opt_level";
8593 case DW_AT_HP_prof_version_id
:
8594 return "DW_AT_HP_prof_version_id";
8595 case DW_AT_HP_opt_flags
:
8596 return "DW_AT_HP_opt_flags";
8597 case DW_AT_HP_cold_region_low_pc
:
8598 return "DW_AT_HP_cold_region_low_pc";
8599 case DW_AT_HP_cold_region_high_pc
:
8600 return "DW_AT_HP_cold_region_high_pc";
8601 case DW_AT_HP_all_variables_modifiable
:
8602 return "DW_AT_HP_all_variables_modifiable";
8603 case DW_AT_HP_linkage_name
:
8604 return "DW_AT_HP_linkage_name";
8605 case DW_AT_HP_prof_flags
:
8606 return "DW_AT_HP_prof_flags";
8607 /* GNU extensions. */
8608 case DW_AT_sf_names
:
8609 return "DW_AT_sf_names";
8610 case DW_AT_src_info
:
8611 return "DW_AT_src_info";
8612 case DW_AT_mac_info
:
8613 return "DW_AT_mac_info";
8614 case DW_AT_src_coords
:
8615 return "DW_AT_src_coords";
8616 case DW_AT_body_begin
:
8617 return "DW_AT_body_begin";
8618 case DW_AT_body_end
:
8619 return "DW_AT_body_end";
8620 case DW_AT_GNU_vector
:
8621 return "DW_AT_GNU_vector";
8622 /* VMS extensions. */
8623 case DW_AT_VMS_rtnbeg_pd_address
:
8624 return "DW_AT_VMS_rtnbeg_pd_address";
8625 /* UPC extension. */
8626 case DW_AT_upc_threads_scaled
:
8627 return "DW_AT_upc_threads_scaled";
8628 /* PGI (STMicroelectronics) extensions. */
8629 case DW_AT_PGI_lbase
:
8630 return "DW_AT_PGI_lbase";
8631 case DW_AT_PGI_soffset
:
8632 return "DW_AT_PGI_soffset";
8633 case DW_AT_PGI_lstride
:
8634 return "DW_AT_PGI_lstride";
8636 return "DW_AT_<unknown>";
8640 /* Convert a DWARF value form code into its string name. */
8643 dwarf_form_name (unsigned form
)
8648 return "DW_FORM_addr";
8649 case DW_FORM_block2
:
8650 return "DW_FORM_block2";
8651 case DW_FORM_block4
:
8652 return "DW_FORM_block4";
8654 return "DW_FORM_data2";
8656 return "DW_FORM_data4";
8658 return "DW_FORM_data8";
8659 case DW_FORM_string
:
8660 return "DW_FORM_string";
8662 return "DW_FORM_block";
8663 case DW_FORM_block1
:
8664 return "DW_FORM_block1";
8666 return "DW_FORM_data1";
8668 return "DW_FORM_flag";
8670 return "DW_FORM_sdata";
8672 return "DW_FORM_strp";
8674 return "DW_FORM_udata";
8675 case DW_FORM_ref_addr
:
8676 return "DW_FORM_ref_addr";
8678 return "DW_FORM_ref1";
8680 return "DW_FORM_ref2";
8682 return "DW_FORM_ref4";
8684 return "DW_FORM_ref8";
8685 case DW_FORM_ref_udata
:
8686 return "DW_FORM_ref_udata";
8687 case DW_FORM_indirect
:
8688 return "DW_FORM_indirect";
8690 return "DW_FORM_<unknown>";
8694 /* Convert a DWARF stack opcode into its string name. */
8697 dwarf_stack_op_name (unsigned op
)
8702 return "DW_OP_addr";
8704 return "DW_OP_deref";
8706 return "DW_OP_const1u";
8708 return "DW_OP_const1s";
8710 return "DW_OP_const2u";
8712 return "DW_OP_const2s";
8714 return "DW_OP_const4u";
8716 return "DW_OP_const4s";
8718 return "DW_OP_const8u";
8720 return "DW_OP_const8s";
8722 return "DW_OP_constu";
8724 return "DW_OP_consts";
8728 return "DW_OP_drop";
8730 return "DW_OP_over";
8732 return "DW_OP_pick";
8734 return "DW_OP_swap";
8738 return "DW_OP_xderef";
8746 return "DW_OP_minus";
8758 return "DW_OP_plus";
8759 case DW_OP_plus_uconst
:
8760 return "DW_OP_plus_uconst";
8766 return "DW_OP_shra";
8784 return "DW_OP_skip";
8786 return "DW_OP_lit0";
8788 return "DW_OP_lit1";
8790 return "DW_OP_lit2";
8792 return "DW_OP_lit3";
8794 return "DW_OP_lit4";
8796 return "DW_OP_lit5";
8798 return "DW_OP_lit6";
8800 return "DW_OP_lit7";
8802 return "DW_OP_lit8";
8804 return "DW_OP_lit9";
8806 return "DW_OP_lit10";
8808 return "DW_OP_lit11";
8810 return "DW_OP_lit12";
8812 return "DW_OP_lit13";
8814 return "DW_OP_lit14";
8816 return "DW_OP_lit15";
8818 return "DW_OP_lit16";
8820 return "DW_OP_lit17";
8822 return "DW_OP_lit18";
8824 return "DW_OP_lit19";
8826 return "DW_OP_lit20";
8828 return "DW_OP_lit21";
8830 return "DW_OP_lit22";
8832 return "DW_OP_lit23";
8834 return "DW_OP_lit24";
8836 return "DW_OP_lit25";
8838 return "DW_OP_lit26";
8840 return "DW_OP_lit27";
8842 return "DW_OP_lit28";
8844 return "DW_OP_lit29";
8846 return "DW_OP_lit30";
8848 return "DW_OP_lit31";
8850 return "DW_OP_reg0";
8852 return "DW_OP_reg1";
8854 return "DW_OP_reg2";
8856 return "DW_OP_reg3";
8858 return "DW_OP_reg4";
8860 return "DW_OP_reg5";
8862 return "DW_OP_reg6";
8864 return "DW_OP_reg7";
8866 return "DW_OP_reg8";
8868 return "DW_OP_reg9";
8870 return "DW_OP_reg10";
8872 return "DW_OP_reg11";
8874 return "DW_OP_reg12";
8876 return "DW_OP_reg13";
8878 return "DW_OP_reg14";
8880 return "DW_OP_reg15";
8882 return "DW_OP_reg16";
8884 return "DW_OP_reg17";
8886 return "DW_OP_reg18";
8888 return "DW_OP_reg19";
8890 return "DW_OP_reg20";
8892 return "DW_OP_reg21";
8894 return "DW_OP_reg22";
8896 return "DW_OP_reg23";
8898 return "DW_OP_reg24";
8900 return "DW_OP_reg25";
8902 return "DW_OP_reg26";
8904 return "DW_OP_reg27";
8906 return "DW_OP_reg28";
8908 return "DW_OP_reg29";
8910 return "DW_OP_reg30";
8912 return "DW_OP_reg31";
8914 return "DW_OP_breg0";
8916 return "DW_OP_breg1";
8918 return "DW_OP_breg2";
8920 return "DW_OP_breg3";
8922 return "DW_OP_breg4";
8924 return "DW_OP_breg5";
8926 return "DW_OP_breg6";
8928 return "DW_OP_breg7";
8930 return "DW_OP_breg8";
8932 return "DW_OP_breg9";
8934 return "DW_OP_breg10";
8936 return "DW_OP_breg11";
8938 return "DW_OP_breg12";
8940 return "DW_OP_breg13";
8942 return "DW_OP_breg14";
8944 return "DW_OP_breg15";
8946 return "DW_OP_breg16";
8948 return "DW_OP_breg17";
8950 return "DW_OP_breg18";
8952 return "DW_OP_breg19";
8954 return "DW_OP_breg20";
8956 return "DW_OP_breg21";
8958 return "DW_OP_breg22";
8960 return "DW_OP_breg23";
8962 return "DW_OP_breg24";
8964 return "DW_OP_breg25";
8966 return "DW_OP_breg26";
8968 return "DW_OP_breg27";
8970 return "DW_OP_breg28";
8972 return "DW_OP_breg29";
8974 return "DW_OP_breg30";
8976 return "DW_OP_breg31";
8978 return "DW_OP_regx";
8980 return "DW_OP_fbreg";
8982 return "DW_OP_bregx";
8984 return "DW_OP_piece";
8985 case DW_OP_deref_size
:
8986 return "DW_OP_deref_size";
8987 case DW_OP_xderef_size
:
8988 return "DW_OP_xderef_size";
8991 /* DWARF 3 extensions. */
8992 case DW_OP_push_object_address
:
8993 return "DW_OP_push_object_address";
8995 return "DW_OP_call2";
8997 return "DW_OP_call4";
8998 case DW_OP_call_ref
:
8999 return "DW_OP_call_ref";
9000 /* GNU extensions. */
9001 case DW_OP_form_tls_address
:
9002 return "DW_OP_form_tls_address";
9003 case DW_OP_call_frame_cfa
:
9004 return "DW_OP_call_frame_cfa";
9005 case DW_OP_bit_piece
:
9006 return "DW_OP_bit_piece";
9007 case DW_OP_GNU_push_tls_address
:
9008 return "DW_OP_GNU_push_tls_address";
9009 case DW_OP_GNU_uninit
:
9010 return "DW_OP_GNU_uninit";
9011 /* HP extensions. */
9012 case DW_OP_HP_is_value
:
9013 return "DW_OP_HP_is_value";
9014 case DW_OP_HP_fltconst4
:
9015 return "DW_OP_HP_fltconst4";
9016 case DW_OP_HP_fltconst8
:
9017 return "DW_OP_HP_fltconst8";
9018 case DW_OP_HP_mod_range
:
9019 return "DW_OP_HP_mod_range";
9020 case DW_OP_HP_unmod_range
:
9021 return "DW_OP_HP_unmod_range";
9023 return "DW_OP_HP_tls";
9025 return "OP_<unknown>";
9030 dwarf_bool_name (unsigned mybool
)
9038 /* Convert a DWARF type code into its string name. */
9041 dwarf_type_encoding_name (unsigned enc
)
9046 return "DW_ATE_void";
9047 case DW_ATE_address
:
9048 return "DW_ATE_address";
9049 case DW_ATE_boolean
:
9050 return "DW_ATE_boolean";
9051 case DW_ATE_complex_float
:
9052 return "DW_ATE_complex_float";
9054 return "DW_ATE_float";
9056 return "DW_ATE_signed";
9057 case DW_ATE_signed_char
:
9058 return "DW_ATE_signed_char";
9059 case DW_ATE_unsigned
:
9060 return "DW_ATE_unsigned";
9061 case DW_ATE_unsigned_char
:
9062 return "DW_ATE_unsigned_char";
9064 case DW_ATE_imaginary_float
:
9065 return "DW_ATE_imaginary_float";
9066 case DW_ATE_packed_decimal
:
9067 return "DW_ATE_packed_decimal";
9068 case DW_ATE_numeric_string
:
9069 return "DW_ATE_numeric_string";
9071 return "DW_ATE_edited";
9072 case DW_ATE_signed_fixed
:
9073 return "DW_ATE_signed_fixed";
9074 case DW_ATE_unsigned_fixed
:
9075 return "DW_ATE_unsigned_fixed";
9076 case DW_ATE_decimal_float
:
9077 return "DW_ATE_decimal_float";
9078 /* HP extensions. */
9079 case DW_ATE_HP_float80
:
9080 return "DW_ATE_HP_float80";
9081 case DW_ATE_HP_complex_float80
:
9082 return "DW_ATE_HP_complex_float80";
9083 case DW_ATE_HP_float128
:
9084 return "DW_ATE_HP_float128";
9085 case DW_ATE_HP_complex_float128
:
9086 return "DW_ATE_HP_complex_float128";
9087 case DW_ATE_HP_floathpintel
:
9088 return "DW_ATE_HP_floathpintel";
9089 case DW_ATE_HP_imaginary_float80
:
9090 return "DW_ATE_HP_imaginary_float80";
9091 case DW_ATE_HP_imaginary_float128
:
9092 return "DW_ATE_HP_imaginary_float128";
9094 return "DW_ATE_<unknown>";
9098 /* Convert a DWARF call frame info operation to its string name. */
9102 dwarf_cfi_name (unsigned cfi_opc
)
9106 case DW_CFA_advance_loc
:
9107 return "DW_CFA_advance_loc";
9109 return "DW_CFA_offset";
9110 case DW_CFA_restore
:
9111 return "DW_CFA_restore";
9113 return "DW_CFA_nop";
9114 case DW_CFA_set_loc
:
9115 return "DW_CFA_set_loc";
9116 case DW_CFA_advance_loc1
:
9117 return "DW_CFA_advance_loc1";
9118 case DW_CFA_advance_loc2
:
9119 return "DW_CFA_advance_loc2";
9120 case DW_CFA_advance_loc4
:
9121 return "DW_CFA_advance_loc4";
9122 case DW_CFA_offset_extended
:
9123 return "DW_CFA_offset_extended";
9124 case DW_CFA_restore_extended
:
9125 return "DW_CFA_restore_extended";
9126 case DW_CFA_undefined
:
9127 return "DW_CFA_undefined";
9128 case DW_CFA_same_value
:
9129 return "DW_CFA_same_value";
9130 case DW_CFA_register
:
9131 return "DW_CFA_register";
9132 case DW_CFA_remember_state
:
9133 return "DW_CFA_remember_state";
9134 case DW_CFA_restore_state
:
9135 return "DW_CFA_restore_state";
9136 case DW_CFA_def_cfa
:
9137 return "DW_CFA_def_cfa";
9138 case DW_CFA_def_cfa_register
:
9139 return "DW_CFA_def_cfa_register";
9140 case DW_CFA_def_cfa_offset
:
9141 return "DW_CFA_def_cfa_offset";
9143 case DW_CFA_def_cfa_expression
:
9144 return "DW_CFA_def_cfa_expression";
9145 case DW_CFA_expression
:
9146 return "DW_CFA_expression";
9147 case DW_CFA_offset_extended_sf
:
9148 return "DW_CFA_offset_extended_sf";
9149 case DW_CFA_def_cfa_sf
:
9150 return "DW_CFA_def_cfa_sf";
9151 case DW_CFA_def_cfa_offset_sf
:
9152 return "DW_CFA_def_cfa_offset_sf";
9153 case DW_CFA_val_offset
:
9154 return "DW_CFA_val_offset";
9155 case DW_CFA_val_offset_sf
:
9156 return "DW_CFA_val_offset_sf";
9157 case DW_CFA_val_expression
:
9158 return "DW_CFA_val_expression";
9159 /* SGI/MIPS specific. */
9160 case DW_CFA_MIPS_advance_loc8
:
9161 return "DW_CFA_MIPS_advance_loc8";
9162 /* GNU extensions. */
9163 case DW_CFA_GNU_window_save
:
9164 return "DW_CFA_GNU_window_save";
9165 case DW_CFA_GNU_args_size
:
9166 return "DW_CFA_GNU_args_size";
9167 case DW_CFA_GNU_negative_offset_extended
:
9168 return "DW_CFA_GNU_negative_offset_extended";
9170 return "DW_CFA_<unknown>";
9176 dump_die (struct die_info
*die
)
9180 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9181 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9182 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9183 dwarf_bool_name (die
->child
!= NULL
));
9185 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9186 for (i
= 0; i
< die
->num_attrs
; ++i
)
9188 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9189 dwarf_attr_name (die
->attrs
[i
].name
),
9190 dwarf_form_name (die
->attrs
[i
].form
));
9191 switch (die
->attrs
[i
].form
)
9193 case DW_FORM_ref_addr
:
9195 fprintf_unfiltered (gdb_stderr
, "address: ");
9196 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9198 case DW_FORM_block2
:
9199 case DW_FORM_block4
:
9201 case DW_FORM_block1
:
9202 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9207 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9208 (long) (DW_ADDR (&die
->attrs
[i
])));
9216 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9218 case DW_FORM_string
:
9220 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9221 DW_STRING (&die
->attrs
[i
])
9222 ? DW_STRING (&die
->attrs
[i
]) : "");
9225 if (DW_UNSND (&die
->attrs
[i
]))
9226 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9228 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9230 case DW_FORM_indirect
:
9231 /* the reader will have reduced the indirect form to
9232 the "base form" so this form should not occur */
9233 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9236 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9237 die
->attrs
[i
].form
);
9239 fprintf_unfiltered (gdb_stderr
, "\n");
9244 dump_die_list (struct die_info
*die
)
9249 if (die
->child
!= NULL
)
9250 dump_die_list (die
->child
);
9251 if (die
->sibling
!= NULL
)
9252 dump_die_list (die
->sibling
);
9257 store_in_ref_table (unsigned int offset
, struct die_info
*die
,
9258 struct dwarf2_cu
*cu
)
9261 struct die_info
*old
;
9263 h
= (offset
% REF_HASH_SIZE
);
9264 old
= cu
->die_ref_table
[h
];
9265 die
->next_ref
= old
;
9266 cu
->die_ref_table
[h
] = die
;
9270 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9272 unsigned int result
= 0;
9276 case DW_FORM_ref_addr
:
9281 case DW_FORM_ref_udata
:
9282 result
= DW_ADDR (attr
);
9285 complaint (&symfile_complaints
,
9286 _("unsupported die ref attribute form: '%s'"),
9287 dwarf_form_name (attr
->form
));
9292 /* Return the constant value held by the given attribute. Return -1
9293 if the value held by the attribute is not constant. */
9296 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9298 if (attr
->form
== DW_FORM_sdata
)
9299 return DW_SND (attr
);
9300 else if (attr
->form
== DW_FORM_udata
9301 || attr
->form
== DW_FORM_data1
9302 || attr
->form
== DW_FORM_data2
9303 || attr
->form
== DW_FORM_data4
9304 || attr
->form
== DW_FORM_data8
)
9305 return DW_UNSND (attr
);
9308 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9309 dwarf_form_name (attr
->form
));
9310 return default_value
;
9314 static struct die_info
*
9315 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9316 struct dwarf2_cu
*cu
)
9318 struct die_info
*die
;
9319 unsigned int offset
;
9321 struct die_info temp_die
;
9322 struct dwarf2_cu
*target_cu
;
9324 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9326 if (DW_ADDR (attr
) < cu
->header
.offset
9327 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9329 struct dwarf2_per_cu_data
*per_cu
;
9330 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9332 target_cu
= per_cu
->cu
;
9337 h
= (offset
% REF_HASH_SIZE
);
9338 die
= target_cu
->die_ref_table
[h
];
9341 if (die
->offset
== offset
)
9343 die
= die
->next_ref
;
9346 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9347 "at 0x%lx [in module %s]"),
9348 (long) src_die
->offset
, (long) offset
, cu
->objfile
->name
);
9353 /* Decode simple location descriptions.
9354 Given a pointer to a dwarf block that defines a location, compute
9355 the location and return the value.
9357 NOTE drow/2003-11-18: This function is called in two situations
9358 now: for the address of static or global variables (partial symbols
9359 only) and for offsets into structures which are expected to be
9360 (more or less) constant. The partial symbol case should go away,
9361 and only the constant case should remain. That will let this
9362 function complain more accurately. A few special modes are allowed
9363 without complaint for global variables (for instance, global
9364 register values and thread-local values).
9366 A location description containing no operations indicates that the
9367 object is optimized out. The return value is 0 for that case.
9368 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9369 callers will only want a very basic result and this can become a
9372 Note that stack[0] is unused except as a default error return.
9373 Note that stack overflow is not yet handled. */
9376 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9378 struct objfile
*objfile
= cu
->objfile
;
9379 struct comp_unit_head
*cu_header
= &cu
->header
;
9381 int size
= blk
->size
;
9382 gdb_byte
*data
= blk
->data
;
9383 CORE_ADDR stack
[64];
9385 unsigned int bytes_read
, unsnd
;
9429 stack
[++stacki
] = op
- DW_OP_lit0
;
9464 stack
[++stacki
] = op
- DW_OP_reg0
;
9466 dwarf2_complex_location_expr_complaint ();
9470 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9472 stack
[++stacki
] = unsnd
;
9474 dwarf2_complex_location_expr_complaint ();
9478 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9484 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9489 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9494 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9499 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9504 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9509 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9514 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9520 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9525 stack
[stacki
+ 1] = stack
[stacki
];
9530 stack
[stacki
- 1] += stack
[stacki
];
9534 case DW_OP_plus_uconst
:
9535 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9540 stack
[stacki
- 1] -= stack
[stacki
];
9545 /* If we're not the last op, then we definitely can't encode
9546 this using GDB's address_class enum. This is valid for partial
9547 global symbols, although the variable's address will be bogus
9550 dwarf2_complex_location_expr_complaint ();
9553 case DW_OP_GNU_push_tls_address
:
9554 /* The top of the stack has the offset from the beginning
9555 of the thread control block at which the variable is located. */
9556 /* Nothing should follow this operator, so the top of stack would
9558 /* This is valid for partial global symbols, but the variable's
9559 address will be bogus in the psymtab. */
9561 dwarf2_complex_location_expr_complaint ();
9564 case DW_OP_GNU_uninit
:
9568 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9569 dwarf_stack_op_name (op
));
9570 return (stack
[stacki
]);
9573 return (stack
[stacki
]);
9576 /* memory allocation interface */
9578 static struct dwarf_block
*
9579 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9581 struct dwarf_block
*blk
;
9583 blk
= (struct dwarf_block
*)
9584 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9588 static struct abbrev_info
*
9589 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9591 struct abbrev_info
*abbrev
;
9593 abbrev
= (struct abbrev_info
*)
9594 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9595 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9599 static struct die_info
*
9600 dwarf_alloc_die (void)
9602 struct die_info
*die
;
9604 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
9605 memset (die
, 0, sizeof (struct die_info
));
9610 /* Macro support. */
9613 /* Return the full name of file number I in *LH's file name table.
9614 Use COMP_DIR as the name of the current directory of the
9615 compilation. The result is allocated using xmalloc; the caller is
9616 responsible for freeing it. */
9618 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9620 /* Is the file number a valid index into the line header's file name
9621 table? Remember that file numbers start with one, not zero. */
9622 if (1 <= file
&& file
<= lh
->num_file_names
)
9624 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9626 if (IS_ABSOLUTE_PATH (fe
->name
))
9627 return xstrdup (fe
->name
);
9635 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9641 dir_len
= strlen (dir
);
9642 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9643 strcpy (full_name
, dir
);
9644 full_name
[dir_len
] = '/';
9645 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9649 return xstrdup (fe
->name
);
9654 /* The compiler produced a bogus file number. We can at least
9655 record the macro definitions made in the file, even if we
9656 won't be able to find the file by name. */
9658 sprintf (fake_name
, "<bad macro file number %d>", file
);
9660 complaint (&symfile_complaints
,
9661 _("bad file number in macro information (%d)"),
9664 return xstrdup (fake_name
);
9669 static struct macro_source_file
*
9670 macro_start_file (int file
, int line
,
9671 struct macro_source_file
*current_file
,
9672 const char *comp_dir
,
9673 struct line_header
*lh
, struct objfile
*objfile
)
9675 /* The full name of this source file. */
9676 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9678 /* We don't create a macro table for this compilation unit
9679 at all until we actually get a filename. */
9680 if (! pending_macros
)
9681 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9682 objfile
->macro_cache
);
9685 /* If we have no current file, then this must be the start_file
9686 directive for the compilation unit's main source file. */
9687 current_file
= macro_set_main (pending_macros
, full_name
);
9689 current_file
= macro_include (current_file
, line
, full_name
);
9693 return current_file
;
9697 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9698 followed by a null byte. */
9700 copy_string (const char *buf
, int len
)
9702 char *s
= xmalloc (len
+ 1);
9703 memcpy (s
, buf
, len
);
9711 consume_improper_spaces (const char *p
, const char *body
)
9715 complaint (&symfile_complaints
,
9716 _("macro definition contains spaces in formal argument list:\n`%s'"),
9728 parse_macro_definition (struct macro_source_file
*file
, int line
,
9733 /* The body string takes one of two forms. For object-like macro
9734 definitions, it should be:
9736 <macro name> " " <definition>
9738 For function-like macro definitions, it should be:
9740 <macro name> "() " <definition>
9742 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9744 Spaces may appear only where explicitly indicated, and in the
9747 The Dwarf 2 spec says that an object-like macro's name is always
9748 followed by a space, but versions of GCC around March 2002 omit
9749 the space when the macro's definition is the empty string.
9751 The Dwarf 2 spec says that there should be no spaces between the
9752 formal arguments in a function-like macro's formal argument list,
9753 but versions of GCC around March 2002 include spaces after the
9757 /* Find the extent of the macro name. The macro name is terminated
9758 by either a space or null character (for an object-like macro) or
9759 an opening paren (for a function-like macro). */
9760 for (p
= body
; *p
; p
++)
9761 if (*p
== ' ' || *p
== '(')
9764 if (*p
== ' ' || *p
== '\0')
9766 /* It's an object-like macro. */
9767 int name_len
= p
- body
;
9768 char *name
= copy_string (body
, name_len
);
9769 const char *replacement
;
9772 replacement
= body
+ name_len
+ 1;
9775 dwarf2_macro_malformed_definition_complaint (body
);
9776 replacement
= body
+ name_len
;
9779 macro_define_object (file
, line
, name
, replacement
);
9785 /* It's a function-like macro. */
9786 char *name
= copy_string (body
, p
- body
);
9789 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9793 p
= consume_improper_spaces (p
, body
);
9795 /* Parse the formal argument list. */
9796 while (*p
&& *p
!= ')')
9798 /* Find the extent of the current argument name. */
9799 const char *arg_start
= p
;
9801 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9804 if (! *p
|| p
== arg_start
)
9805 dwarf2_macro_malformed_definition_complaint (body
);
9808 /* Make sure argv has room for the new argument. */
9809 if (argc
>= argv_size
)
9812 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9815 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9818 p
= consume_improper_spaces (p
, body
);
9820 /* Consume the comma, if present. */
9825 p
= consume_improper_spaces (p
, body
);
9834 /* Perfectly formed definition, no complaints. */
9835 macro_define_function (file
, line
, name
,
9836 argc
, (const char **) argv
,
9838 else if (*p
== '\0')
9840 /* Complain, but do define it. */
9841 dwarf2_macro_malformed_definition_complaint (body
);
9842 macro_define_function (file
, line
, name
,
9843 argc
, (const char **) argv
,
9847 /* Just complain. */
9848 dwarf2_macro_malformed_definition_complaint (body
);
9851 /* Just complain. */
9852 dwarf2_macro_malformed_definition_complaint (body
);
9858 for (i
= 0; i
< argc
; i
++)
9864 dwarf2_macro_malformed_definition_complaint (body
);
9869 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9870 char *comp_dir
, bfd
*abfd
,
9871 struct dwarf2_cu
*cu
)
9873 gdb_byte
*mac_ptr
, *mac_end
;
9874 struct macro_source_file
*current_file
= 0;
9876 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9878 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9882 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9883 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9884 + dwarf2_per_objfile
->macinfo_size
;
9888 enum dwarf_macinfo_record_type macinfo_type
;
9890 /* Do we at least have room for a macinfo type byte? */
9891 if (mac_ptr
>= mac_end
)
9893 dwarf2_macros_too_long_complaint ();
9897 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9900 switch (macinfo_type
)
9902 /* A zero macinfo type indicates the end of the macro
9907 case DW_MACINFO_define
:
9908 case DW_MACINFO_undef
:
9910 unsigned int bytes_read
;
9914 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9915 mac_ptr
+= bytes_read
;
9916 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9917 mac_ptr
+= bytes_read
;
9920 complaint (&symfile_complaints
,
9921 _("debug info gives macro %s outside of any file: %s"),
9923 DW_MACINFO_define
? "definition" : macinfo_type
==
9924 DW_MACINFO_undef
? "undefinition" :
9925 "something-or-other", body
);
9928 if (macinfo_type
== DW_MACINFO_define
)
9929 parse_macro_definition (current_file
, line
, body
);
9930 else if (macinfo_type
== DW_MACINFO_undef
)
9931 macro_undef (current_file
, line
, body
);
9936 case DW_MACINFO_start_file
:
9938 unsigned int bytes_read
;
9941 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9942 mac_ptr
+= bytes_read
;
9943 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9944 mac_ptr
+= bytes_read
;
9946 current_file
= macro_start_file (file
, line
,
9947 current_file
, comp_dir
,
9952 case DW_MACINFO_end_file
:
9954 complaint (&symfile_complaints
,
9955 _("macro debug info has an unmatched `close_file' directive"));
9958 current_file
= current_file
->included_by
;
9961 enum dwarf_macinfo_record_type next_type
;
9963 /* GCC circa March 2002 doesn't produce the zero
9964 type byte marking the end of the compilation
9965 unit. Complain if it's not there, but exit no
9968 /* Do we at least have room for a macinfo type byte? */
9969 if (mac_ptr
>= mac_end
)
9971 dwarf2_macros_too_long_complaint ();
9975 /* We don't increment mac_ptr here, so this is just
9977 next_type
= read_1_byte (abfd
, mac_ptr
);
9979 complaint (&symfile_complaints
,
9980 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9987 case DW_MACINFO_vendor_ext
:
9989 unsigned int bytes_read
;
9993 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9994 mac_ptr
+= bytes_read
;
9995 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9996 mac_ptr
+= bytes_read
;
9998 /* We don't recognize any vendor extensions. */
10005 /* Check if the attribute's form is a DW_FORM_block*
10006 if so return true else false. */
10008 attr_form_is_block (struct attribute
*attr
)
10010 return (attr
== NULL
? 0 :
10011 attr
->form
== DW_FORM_block1
10012 || attr
->form
== DW_FORM_block2
10013 || attr
->form
== DW_FORM_block4
10014 || attr
->form
== DW_FORM_block
);
10017 /* Return non-zero if ATTR's value is a section offset --- classes
10018 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10019 You may use DW_UNSND (attr) to retrieve such offsets.
10021 Section 7.5.4, "Attribute Encodings", explains that no attribute
10022 may have a value that belongs to more than one of these classes; it
10023 would be ambiguous if we did, because we use the same forms for all
10026 attr_form_is_section_offset (struct attribute
*attr
)
10028 return (attr
->form
== DW_FORM_data4
10029 || attr
->form
== DW_FORM_data8
);
10033 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10034 zero otherwise. When this function returns true, you can apply
10035 dwarf2_get_attr_constant_value to it.
10037 However, note that for some attributes you must check
10038 attr_form_is_section_offset before using this test. DW_FORM_data4
10039 and DW_FORM_data8 are members of both the constant class, and of
10040 the classes that contain offsets into other debug sections
10041 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10042 that, if an attribute's can be either a constant or one of the
10043 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10044 taken as section offsets, not constants. */
10046 attr_form_is_constant (struct attribute
*attr
)
10048 switch (attr
->form
)
10050 case DW_FORM_sdata
:
10051 case DW_FORM_udata
:
10052 case DW_FORM_data1
:
10053 case DW_FORM_data2
:
10054 case DW_FORM_data4
:
10055 case DW_FORM_data8
:
10063 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10064 struct dwarf2_cu
*cu
)
10066 if (attr_form_is_section_offset (attr
)
10067 /* ".debug_loc" may not exist at all, or the offset may be outside
10068 the section. If so, fall through to the complaint in the
10070 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10072 struct dwarf2_loclist_baton
*baton
;
10074 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10075 sizeof (struct dwarf2_loclist_baton
));
10076 baton
->per_cu
= cu
->per_cu
;
10077 gdb_assert (baton
->per_cu
);
10079 /* We don't know how long the location list is, but make sure we
10080 don't run off the edge of the section. */
10081 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10082 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10083 baton
->base_address
= cu
->header
.base_address
;
10084 if (cu
->header
.base_known
== 0)
10085 complaint (&symfile_complaints
,
10086 _("Location list used without specifying the CU base address."));
10088 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10089 SYMBOL_LOCATION_BATON (sym
) = baton
;
10093 struct dwarf2_locexpr_baton
*baton
;
10095 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10096 sizeof (struct dwarf2_locexpr_baton
));
10097 baton
->per_cu
= cu
->per_cu
;
10098 gdb_assert (baton
->per_cu
);
10100 if (attr_form_is_block (attr
))
10102 /* Note that we're just copying the block's data pointer
10103 here, not the actual data. We're still pointing into the
10104 info_buffer for SYM's objfile; right now we never release
10105 that buffer, but when we do clean up properly this may
10107 baton
->size
= DW_BLOCK (attr
)->size
;
10108 baton
->data
= DW_BLOCK (attr
)->data
;
10112 dwarf2_invalid_attrib_class_complaint ("location description",
10113 SYMBOL_NATURAL_NAME (sym
));
10115 baton
->data
= NULL
;
10118 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10119 SYMBOL_LOCATION_BATON (sym
) = baton
;
10123 /* Return the OBJFILE associated with the compilation unit CU. */
10126 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10128 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10130 /* Return the master objfile, so that we can report and look up the
10131 correct file containing this variable. */
10132 if (objfile
->separate_debug_objfile_backlink
)
10133 objfile
= objfile
->separate_debug_objfile_backlink
;
10138 /* Return the address size given in the compilation unit header for CU. */
10141 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10144 return per_cu
->cu
->header
.addr_size
;
10147 /* If the CU is not currently read in, we re-read its header. */
10148 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10149 struct dwarf2_per_objfile
*per_objfile
10150 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10151 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10153 struct comp_unit_head cu_header
;
10154 memset (&cu_header
, 0, sizeof cu_header
);
10155 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10156 return cu_header
.addr_size
;
10160 /* Locate the compilation unit from CU's objfile which contains the
10161 DIE at OFFSET. Raises an error on failure. */
10163 static struct dwarf2_per_cu_data
*
10164 dwarf2_find_containing_comp_unit (unsigned long offset
,
10165 struct objfile
*objfile
)
10167 struct dwarf2_per_cu_data
*this_cu
;
10171 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10174 int mid
= low
+ (high
- low
) / 2;
10175 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10180 gdb_assert (low
== high
);
10181 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10184 error (_("Dwarf Error: could not find partial DIE containing "
10185 "offset 0x%lx [in module %s]"),
10186 (long) offset
, bfd_get_filename (objfile
->obfd
));
10188 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10189 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10193 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10194 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10195 && offset
>= this_cu
->offset
+ this_cu
->length
)
10196 error (_("invalid dwarf2 offset %ld"), offset
);
10197 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10202 /* Locate the compilation unit from OBJFILE which is located at exactly
10203 OFFSET. Raises an error on failure. */
10205 static struct dwarf2_per_cu_data
*
10206 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10208 struct dwarf2_per_cu_data
*this_cu
;
10209 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10210 if (this_cu
->offset
!= offset
)
10211 error (_("no compilation unit with offset %ld."), offset
);
10215 /* Release one cached compilation unit, CU. We unlink it from the tree
10216 of compilation units, but we don't remove it from the read_in_chain;
10217 the caller is responsible for that. */
10220 free_one_comp_unit (void *data
)
10222 struct dwarf2_cu
*cu
= data
;
10224 if (cu
->per_cu
!= NULL
)
10225 cu
->per_cu
->cu
= NULL
;
10228 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10230 free_die_list (cu
->dies
);
10235 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10236 when we're finished with it. We can't free the pointer itself, but be
10237 sure to unlink it from the cache. Also release any associated storage
10238 and perform cache maintenance.
10240 Only used during partial symbol parsing. */
10243 free_stack_comp_unit (void *data
)
10245 struct dwarf2_cu
*cu
= data
;
10247 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10248 cu
->partial_dies
= NULL
;
10250 if (cu
->per_cu
!= NULL
)
10252 /* This compilation unit is on the stack in our caller, so we
10253 should not xfree it. Just unlink it. */
10254 cu
->per_cu
->cu
= NULL
;
10257 /* If we had a per-cu pointer, then we may have other compilation
10258 units loaded, so age them now. */
10259 age_cached_comp_units ();
10263 /* Free all cached compilation units. */
10266 free_cached_comp_units (void *data
)
10268 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10270 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10271 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10272 while (per_cu
!= NULL
)
10274 struct dwarf2_per_cu_data
*next_cu
;
10276 next_cu
= per_cu
->cu
->read_in_chain
;
10278 free_one_comp_unit (per_cu
->cu
);
10279 *last_chain
= next_cu
;
10285 /* Increase the age counter on each cached compilation unit, and free
10286 any that are too old. */
10289 age_cached_comp_units (void)
10291 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10293 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10294 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10295 while (per_cu
!= NULL
)
10297 per_cu
->cu
->last_used
++;
10298 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10299 dwarf2_mark (per_cu
->cu
);
10300 per_cu
= per_cu
->cu
->read_in_chain
;
10303 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10304 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10305 while (per_cu
!= NULL
)
10307 struct dwarf2_per_cu_data
*next_cu
;
10309 next_cu
= per_cu
->cu
->read_in_chain
;
10311 if (!per_cu
->cu
->mark
)
10313 free_one_comp_unit (per_cu
->cu
);
10314 *last_chain
= next_cu
;
10317 last_chain
= &per_cu
->cu
->read_in_chain
;
10323 /* Remove a single compilation unit from the cache. */
10326 free_one_cached_comp_unit (void *target_cu
)
10328 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10330 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10331 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10332 while (per_cu
!= NULL
)
10334 struct dwarf2_per_cu_data
*next_cu
;
10336 next_cu
= per_cu
->cu
->read_in_chain
;
10338 if (per_cu
->cu
== target_cu
)
10340 free_one_comp_unit (per_cu
->cu
);
10341 *last_chain
= next_cu
;
10345 last_chain
= &per_cu
->cu
->read_in_chain
;
10351 /* Release all extra memory associated with OBJFILE. */
10354 dwarf2_free_objfile (struct objfile
*objfile
)
10356 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10358 if (dwarf2_per_objfile
== NULL
)
10361 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10362 free_cached_comp_units (NULL
);
10364 /* Everything else should be on the objfile obstack. */
10367 /* A pair of DIE offset and GDB type pointer. We store these
10368 in a hash table separate from the DIEs, and preserve them
10369 when the DIEs are flushed out of cache. */
10371 struct dwarf2_offset_and_type
10373 unsigned int offset
;
10377 /* Hash function for a dwarf2_offset_and_type. */
10380 offset_and_type_hash (const void *item
)
10382 const struct dwarf2_offset_and_type
*ofs
= item
;
10383 return ofs
->offset
;
10386 /* Equality function for a dwarf2_offset_and_type. */
10389 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10391 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10392 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10393 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10396 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10397 table if necessary. */
10400 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10402 struct dwarf2_offset_and_type
**slot
, ofs
;
10406 if (cu
->per_cu
== NULL
)
10409 if (cu
->per_cu
->type_hash
== NULL
)
10410 cu
->per_cu
->type_hash
10411 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10412 offset_and_type_hash
,
10413 offset_and_type_eq
,
10415 &cu
->objfile
->objfile_obstack
,
10416 hashtab_obstack_allocate
,
10417 dummy_obstack_deallocate
);
10419 ofs
.offset
= die
->offset
;
10421 slot
= (struct dwarf2_offset_and_type
**)
10422 htab_find_slot_with_hash (cu
->per_cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10423 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10427 /* Find the type for DIE in TYPE_HASH, or return NULL if DIE does not
10428 have a saved type. */
10430 static struct type
*
10431 get_die_type (struct die_info
*die
, htab_t type_hash
)
10433 struct dwarf2_offset_and_type
*slot
, ofs
;
10435 ofs
.offset
= die
->offset
;
10436 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10443 /* Restore the types of the DIE tree starting at START_DIE from the hash
10444 table saved in CU. */
10447 reset_die_and_siblings_types (struct die_info
*start_die
, struct dwarf2_cu
*cu
)
10449 struct die_info
*die
;
10451 if (cu
->per_cu
->type_hash
== NULL
)
10454 for (die
= start_die
; die
!= NULL
; die
= die
->sibling
)
10456 die
->type
= get_die_type (die
, cu
->per_cu
->type_hash
);
10457 if (die
->child
!= NULL
)
10458 reset_die_and_siblings_types (die
->child
, cu
);
10462 /* Set the mark field in CU and in every other compilation unit in the
10463 cache that we must keep because we are keeping CU. */
10465 /* Add a dependence relationship from CU to REF_PER_CU. */
10468 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10469 struct dwarf2_per_cu_data
*ref_per_cu
)
10473 if (cu
->dependencies
== NULL
)
10475 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10476 NULL
, &cu
->comp_unit_obstack
,
10477 hashtab_obstack_allocate
,
10478 dummy_obstack_deallocate
);
10480 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10482 *slot
= ref_per_cu
;
10485 /* Set the mark field in CU and in every other compilation unit in the
10486 cache that we must keep because we are keeping CU. */
10489 dwarf2_mark_helper (void **slot
, void *data
)
10491 struct dwarf2_per_cu_data
*per_cu
;
10493 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10494 if (per_cu
->cu
->mark
)
10496 per_cu
->cu
->mark
= 1;
10498 if (per_cu
->cu
->dependencies
!= NULL
)
10499 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10505 dwarf2_mark (struct dwarf2_cu
*cu
)
10510 if (cu
->dependencies
!= NULL
)
10511 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10515 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10519 per_cu
->cu
->mark
= 0;
10520 per_cu
= per_cu
->cu
->read_in_chain
;
10524 /* Trivial hash function for partial_die_info: the hash value of a DIE
10525 is its offset in .debug_info for this objfile. */
10528 partial_die_hash (const void *item
)
10530 const struct partial_die_info
*part_die
= item
;
10531 return part_die
->offset
;
10534 /* Trivial comparison function for partial_die_info structures: two DIEs
10535 are equal if they have the same offset. */
10538 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10540 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10541 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10542 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10545 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10546 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10549 set_dwarf2_cmd (char *args
, int from_tty
)
10551 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10555 show_dwarf2_cmd (char *args
, int from_tty
)
10557 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10560 void _initialize_dwarf2_read (void);
10563 _initialize_dwarf2_read (void)
10565 dwarf2_objfile_data_key
= register_objfile_data ();
10567 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10568 Set DWARF 2 specific variables.\n\
10569 Configure DWARF 2 variables such as the cache size"),
10570 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10571 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10573 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10574 Show DWARF 2 specific variables\n\
10575 Show DWARF 2 variables such as the cache size"),
10576 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10577 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10579 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10580 &dwarf2_max_cache_age
, _("\
10581 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10582 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10583 A higher limit means that cached compilation units will be stored\n\
10584 in memory longer, and more total memory will be used. Zero disables\n\
10585 caching, which can slow down startup."),
10587 show_dwarf2_max_cache_age
,
10588 &set_dwarf2_cmdlist
,
10589 &show_dwarf2_cmdlist
);