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 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3233 CORE_ADDR range_beginning
, range_end
;
3235 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3236 buffer
+= addr_size
;
3237 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3238 buffer
+= addr_size
;
3239 offset
+= 2 * addr_size
;
3241 /* An end of list marker is a pair of zero addresses. */
3242 if (range_beginning
== 0 && range_end
== 0)
3243 /* Found the end of list entry. */
3246 /* Each base address selection entry is a pair of 2 values.
3247 The first is the largest possible address, the second is
3248 the base address. Check for a base address here. */
3249 if ((range_beginning
& mask
) == mask
)
3251 /* If we found the largest possible address, then
3252 read the base address. */
3253 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3260 /* We have no valid base address for the ranges
3262 complaint (&symfile_complaints
,
3263 _("Invalid .debug_ranges data (no base address)"));
3267 range_beginning
+= base
;
3270 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3271 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3272 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3275 /* FIXME: This is recording everything as a low-high
3276 segment of consecutive addresses. We should have a
3277 data structure for discontiguous block ranges
3281 low
= range_beginning
;
3287 if (range_beginning
< low
)
3288 low
= range_beginning
;
3289 if (range_end
> high
)
3295 /* If the first entry is an end-of-list marker, the range
3296 describes an empty scope, i.e. no instructions. */
3302 *high_return
= high
;
3306 /* Get low and high pc attributes from a die. Return 1 if the attributes
3307 are present and valid, otherwise, return 0. Return -1 if the range is
3308 discontinuous, i.e. derived from DW_AT_ranges information. */
3310 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3311 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3313 struct attribute
*attr
;
3318 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3321 high
= DW_ADDR (attr
);
3322 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3324 low
= DW_ADDR (attr
);
3326 /* Found high w/o low attribute. */
3329 /* Found consecutive range of addresses. */
3334 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3337 /* Value of the DW_AT_ranges attribute is the offset in the
3338 .debug_ranges section. */
3339 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3341 /* Found discontinuous range of addresses. */
3349 /* When using the GNU linker, .gnu.linkonce. sections are used to
3350 eliminate duplicate copies of functions and vtables and such.
3351 The linker will arbitrarily choose one and discard the others.
3352 The AT_*_pc values for such functions refer to local labels in
3353 these sections. If the section from that file was discarded, the
3354 labels are not in the output, so the relocs get a value of 0.
3355 If this is a discarded function, mark the pc bounds as invalid,
3356 so that GDB will ignore it. */
3357 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3365 /* Get the low and high pc's represented by the scope DIE, and store
3366 them in *LOWPC and *HIGHPC. If the correct values can't be
3367 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3370 get_scope_pc_bounds (struct die_info
*die
,
3371 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3372 struct dwarf2_cu
*cu
)
3374 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3375 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3376 CORE_ADDR current_low
, current_high
;
3378 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3380 best_low
= current_low
;
3381 best_high
= current_high
;
3385 struct die_info
*child
= die
->child
;
3387 while (child
&& child
->tag
)
3389 switch (child
->tag
) {
3390 case DW_TAG_subprogram
:
3391 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3393 best_low
= min (best_low
, current_low
);
3394 best_high
= max (best_high
, current_high
);
3397 case DW_TAG_namespace
:
3398 /* FIXME: carlton/2004-01-16: Should we do this for
3399 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3400 that current GCC's always emit the DIEs corresponding
3401 to definitions of methods of classes as children of a
3402 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3403 the DIEs giving the declarations, which could be
3404 anywhere). But I don't see any reason why the
3405 standards says that they have to be there. */
3406 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3408 if (current_low
!= ((CORE_ADDR
) -1))
3410 best_low
= min (best_low
, current_low
);
3411 best_high
= max (best_high
, current_high
);
3419 child
= sibling_die (child
);
3424 *highpc
= best_high
;
3427 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3430 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3431 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3433 struct attribute
*attr
;
3435 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3438 CORE_ADDR high
= DW_ADDR (attr
);
3439 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3442 CORE_ADDR low
= DW_ADDR (attr
);
3443 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3447 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3450 bfd
*obfd
= cu
->objfile
->obfd
;
3452 /* The value of the DW_AT_ranges attribute is the offset of the
3453 address range list in the .debug_ranges section. */
3454 unsigned long offset
= DW_UNSND (attr
);
3455 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3457 /* For some target architectures, but not others, the
3458 read_address function sign-extends the addresses it returns.
3459 To recognize base address selection entries, we need a
3461 unsigned int addr_size
= cu
->header
.addr_size
;
3462 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3464 /* The base address, to which the next pair is relative. Note
3465 that this 'base' is a DWARF concept: most entries in a range
3466 list are relative, to reduce the number of relocs against the
3467 debugging information. This is separate from this function's
3468 'baseaddr' argument, which GDB uses to relocate debugging
3469 information from a shared library based on the address at
3470 which the library was loaded. */
3471 CORE_ADDR base
= cu
->header
.base_address
;
3472 int base_known
= cu
->header
.base_known
;
3474 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3476 complaint (&symfile_complaints
,
3477 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3484 unsigned int bytes_read
;
3485 CORE_ADDR start
, end
;
3487 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3488 buffer
+= bytes_read
;
3489 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3490 buffer
+= bytes_read
;
3492 /* Did we find the end of the range list? */
3493 if (start
== 0 && end
== 0)
3496 /* Did we find a base address selection entry? */
3497 else if ((start
& base_select_mask
) == base_select_mask
)
3503 /* We found an ordinary address range. */
3508 complaint (&symfile_complaints
,
3509 _("Invalid .debug_ranges data (no base address)"));
3513 record_block_range (block
,
3514 baseaddr
+ base
+ start
,
3515 baseaddr
+ base
+ end
- 1);
3521 /* Add an aggregate field to the field list. */
3524 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3525 struct dwarf2_cu
*cu
)
3527 struct objfile
*objfile
= cu
->objfile
;
3528 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3529 struct nextfield
*new_field
;
3530 struct attribute
*attr
;
3532 char *fieldname
= "";
3534 /* Allocate a new field list entry and link it in. */
3535 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3536 make_cleanup (xfree
, new_field
);
3537 memset (new_field
, 0, sizeof (struct nextfield
));
3538 new_field
->next
= fip
->fields
;
3539 fip
->fields
= new_field
;
3542 /* Handle accessibility and virtuality of field.
3543 The default accessibility for members is public, the default
3544 accessibility for inheritance is private. */
3545 if (die
->tag
!= DW_TAG_inheritance
)
3546 new_field
->accessibility
= DW_ACCESS_public
;
3548 new_field
->accessibility
= DW_ACCESS_private
;
3549 new_field
->virtuality
= DW_VIRTUALITY_none
;
3551 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3553 new_field
->accessibility
= DW_UNSND (attr
);
3554 if (new_field
->accessibility
!= DW_ACCESS_public
)
3555 fip
->non_public_fields
= 1;
3556 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3558 new_field
->virtuality
= DW_UNSND (attr
);
3560 fp
= &new_field
->field
;
3562 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3564 /* Data member other than a C++ static data member. */
3566 /* Get type of field. */
3567 fp
->type
= die_type (die
, cu
);
3569 FIELD_STATIC_KIND (*fp
) = 0;
3571 /* Get bit size of field (zero if none). */
3572 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3575 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3579 FIELD_BITSIZE (*fp
) = 0;
3582 /* Get bit offset of field. */
3583 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3588 if (attr_form_is_section_offset (attr
))
3590 dwarf2_complex_location_expr_complaint ();
3593 else if (attr_form_is_constant (attr
))
3594 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3596 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3598 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3601 FIELD_BITPOS (*fp
) = 0;
3602 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3605 if (gdbarch_bits_big_endian (gdbarch
))
3607 /* For big endian bits, the DW_AT_bit_offset gives the
3608 additional bit offset from the MSB of the containing
3609 anonymous object to the MSB of the field. We don't
3610 have to do anything special since we don't need to
3611 know the size of the anonymous object. */
3612 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3616 /* For little endian bits, compute the bit offset to the
3617 MSB of the anonymous object, subtract off the number of
3618 bits from the MSB of the field to the MSB of the
3619 object, and then subtract off the number of bits of
3620 the field itself. The result is the bit offset of
3621 the LSB of the field. */
3623 int bit_offset
= DW_UNSND (attr
);
3625 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3628 /* The size of the anonymous object containing
3629 the bit field is explicit, so use the
3630 indicated size (in bytes). */
3631 anonymous_size
= DW_UNSND (attr
);
3635 /* The size of the anonymous object containing
3636 the bit field must be inferred from the type
3637 attribute of the data member containing the
3639 anonymous_size
= TYPE_LENGTH (fp
->type
);
3641 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3642 - bit_offset
- FIELD_BITSIZE (*fp
);
3646 /* Get name of field. */
3647 fieldname
= dwarf2_name (die
, cu
);
3648 if (fieldname
== NULL
)
3651 /* The name is already allocated along with this objfile, so we don't
3652 need to duplicate it for the type. */
3653 fp
->name
= fieldname
;
3655 /* Change accessibility for artificial fields (e.g. virtual table
3656 pointer or virtual base class pointer) to private. */
3657 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3659 new_field
->accessibility
= DW_ACCESS_private
;
3660 fip
->non_public_fields
= 1;
3663 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3665 /* C++ static member. */
3667 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3668 is a declaration, but all versions of G++ as of this writing
3669 (so through at least 3.2.1) incorrectly generate
3670 DW_TAG_variable tags. */
3674 /* Get name of field. */
3675 fieldname
= dwarf2_name (die
, cu
);
3676 if (fieldname
== NULL
)
3679 /* Get physical name. */
3680 physname
= dwarf2_linkage_name (die
, cu
);
3682 /* The name is already allocated along with this objfile, so we don't
3683 need to duplicate it for the type. */
3684 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3685 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3686 FIELD_NAME (*fp
) = fieldname
;
3688 else if (die
->tag
== DW_TAG_inheritance
)
3690 /* C++ base class field. */
3691 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3693 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3695 FIELD_BITSIZE (*fp
) = 0;
3696 FIELD_STATIC_KIND (*fp
) = 0;
3697 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3698 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3699 fip
->nbaseclasses
++;
3703 /* Create the vector of fields, and attach it to the type. */
3706 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3707 struct dwarf2_cu
*cu
)
3709 int nfields
= fip
->nfields
;
3711 /* Record the field count, allocate space for the array of fields,
3712 and create blank accessibility bitfields if necessary. */
3713 TYPE_NFIELDS (type
) = nfields
;
3714 TYPE_FIELDS (type
) = (struct field
*)
3715 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3716 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3718 if (fip
->non_public_fields
)
3720 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3722 TYPE_FIELD_PRIVATE_BITS (type
) =
3723 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3724 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3726 TYPE_FIELD_PROTECTED_BITS (type
) =
3727 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3728 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3730 TYPE_FIELD_IGNORE_BITS (type
) =
3731 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3732 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3735 /* If the type has baseclasses, allocate and clear a bit vector for
3736 TYPE_FIELD_VIRTUAL_BITS. */
3737 if (fip
->nbaseclasses
)
3739 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3740 unsigned char *pointer
;
3742 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3743 pointer
= TYPE_ALLOC (type
, num_bytes
);
3744 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3745 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3746 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3749 /* Copy the saved-up fields into the field vector. Start from the head
3750 of the list, adding to the tail of the field array, so that they end
3751 up in the same order in the array in which they were added to the list. */
3752 while (nfields
-- > 0)
3754 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3755 switch (fip
->fields
->accessibility
)
3757 case DW_ACCESS_private
:
3758 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3761 case DW_ACCESS_protected
:
3762 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3765 case DW_ACCESS_public
:
3769 /* Unknown accessibility. Complain and treat it as public. */
3771 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3772 fip
->fields
->accessibility
);
3776 if (nfields
< fip
->nbaseclasses
)
3778 switch (fip
->fields
->virtuality
)
3780 case DW_VIRTUALITY_virtual
:
3781 case DW_VIRTUALITY_pure_virtual
:
3782 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3786 fip
->fields
= fip
->fields
->next
;
3790 /* Add a member function to the proper fieldlist. */
3793 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3794 struct type
*type
, struct dwarf2_cu
*cu
)
3796 struct objfile
*objfile
= cu
->objfile
;
3797 struct attribute
*attr
;
3798 struct fnfieldlist
*flp
;
3800 struct fn_field
*fnp
;
3803 struct nextfnfield
*new_fnfield
;
3805 /* Get name of member function. */
3806 fieldname
= dwarf2_name (die
, cu
);
3807 if (fieldname
== NULL
)
3810 /* Get the mangled name. */
3811 physname
= dwarf2_linkage_name (die
, cu
);
3813 /* Look up member function name in fieldlist. */
3814 for (i
= 0; i
< fip
->nfnfields
; i
++)
3816 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3820 /* Create new list element if necessary. */
3821 if (i
< fip
->nfnfields
)
3822 flp
= &fip
->fnfieldlists
[i
];
3825 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3827 fip
->fnfieldlists
= (struct fnfieldlist
*)
3828 xrealloc (fip
->fnfieldlists
,
3829 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3830 * sizeof (struct fnfieldlist
));
3831 if (fip
->nfnfields
== 0)
3832 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3834 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3835 flp
->name
= fieldname
;
3841 /* Create a new member function field and chain it to the field list
3843 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3844 make_cleanup (xfree
, new_fnfield
);
3845 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3846 new_fnfield
->next
= flp
->head
;
3847 flp
->head
= new_fnfield
;
3850 /* Fill in the member function field info. */
3851 fnp
= &new_fnfield
->fnfield
;
3852 /* The name is already allocated along with this objfile, so we don't
3853 need to duplicate it for the type. */
3854 fnp
->physname
= physname
? physname
: "";
3855 fnp
->type
= alloc_type (objfile
);
3856 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3858 int nparams
= TYPE_NFIELDS (die
->type
);
3860 /* TYPE is the domain of this method, and DIE->TYPE is the type
3861 of the method itself (TYPE_CODE_METHOD). */
3862 smash_to_method_type (fnp
->type
, type
,
3863 TYPE_TARGET_TYPE (die
->type
),
3864 TYPE_FIELDS (die
->type
),
3865 TYPE_NFIELDS (die
->type
),
3866 TYPE_VARARGS (die
->type
));
3868 /* Handle static member functions.
3869 Dwarf2 has no clean way to discern C++ static and non-static
3870 member functions. G++ helps GDB by marking the first
3871 parameter for non-static member functions (which is the
3872 this pointer) as artificial. We obtain this information
3873 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3874 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3875 fnp
->voffset
= VOFFSET_STATIC
;
3878 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3881 /* Get fcontext from DW_AT_containing_type if present. */
3882 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3883 fnp
->fcontext
= die_containing_type (die
, cu
);
3885 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3886 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3888 /* Get accessibility. */
3889 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3892 switch (DW_UNSND (attr
))
3894 case DW_ACCESS_private
:
3895 fnp
->is_private
= 1;
3897 case DW_ACCESS_protected
:
3898 fnp
->is_protected
= 1;
3903 /* Check for artificial methods. */
3904 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3905 if (attr
&& DW_UNSND (attr
) != 0)
3906 fnp
->is_artificial
= 1;
3908 /* Get index in virtual function table if it is a virtual member function. */
3909 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3912 /* Support the .debug_loc offsets */
3913 if (attr_form_is_block (attr
))
3915 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3917 else if (attr_form_is_section_offset (attr
))
3919 dwarf2_complex_location_expr_complaint ();
3923 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3929 /* Create the vector of member function fields, and attach it to the type. */
3932 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3933 struct dwarf2_cu
*cu
)
3935 struct fnfieldlist
*flp
;
3936 int total_length
= 0;
3939 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3940 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3941 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3943 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3945 struct nextfnfield
*nfp
= flp
->head
;
3946 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3949 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3950 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3951 fn_flp
->fn_fields
= (struct fn_field
*)
3952 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3953 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3954 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3956 total_length
+= flp
->length
;
3959 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3960 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3963 /* Returns non-zero if NAME is the name of a vtable member in CU's
3964 language, zero otherwise. */
3966 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3968 static const char vptr
[] = "_vptr";
3969 static const char vtable
[] = "vtable";
3971 /* Look for the C++ and Java forms of the vtable. */
3972 if ((cu
->language
== language_java
3973 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3974 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3975 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3981 /* GCC outputs unnamed structures that are really pointers to member
3982 functions, with the ABI-specified layout. If DIE (from CU) describes
3983 such a structure, set its type, and return nonzero. Otherwise return
3986 GCC shouldn't do this; it should just output pointer to member DIEs.
3987 This is GCC PR debug/28767. */
3990 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3992 struct objfile
*objfile
= cu
->objfile
;
3994 struct die_info
*pfn_die
, *delta_die
;
3995 struct attribute
*pfn_name
, *delta_name
;
3996 struct type
*pfn_type
, *domain_type
;
3998 /* Check for a structure with no name and two children. */
3999 if (die
->tag
!= DW_TAG_structure_type
4000 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4001 || die
->child
== NULL
4002 || die
->child
->sibling
== NULL
4003 || (die
->child
->sibling
->sibling
!= NULL
4004 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4007 /* Check for __pfn and __delta members. */
4008 pfn_die
= die
->child
;
4009 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4010 if (pfn_die
->tag
!= DW_TAG_member
4012 || DW_STRING (pfn_name
) == NULL
4013 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4016 delta_die
= pfn_die
->sibling
;
4017 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4018 if (delta_die
->tag
!= DW_TAG_member
4019 || delta_name
== NULL
4020 || DW_STRING (delta_name
) == NULL
4021 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4024 /* Find the type of the method. */
4025 pfn_type
= die_type (pfn_die
, cu
);
4026 if (pfn_type
== NULL
4027 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4028 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4031 /* Look for the "this" argument. */
4032 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4033 if (TYPE_NFIELDS (pfn_type
) == 0
4034 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4037 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4038 type
= alloc_type (objfile
);
4039 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4040 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4041 TYPE_VARARGS (pfn_type
));
4042 type
= lookup_methodptr_type (type
);
4043 set_die_type (die
, type
, cu
);
4048 /* Called when we find the DIE that starts a structure or union scope
4049 (definition) to process all dies that define the members of the
4052 NOTE: we need to call struct_type regardless of whether or not the
4053 DIE has an at_name attribute, since it might be an anonymous
4054 structure or union. This gets the type entered into our set of
4057 However, if the structure is incomplete (an opaque struct/union)
4058 then suppress creating a symbol table entry for it since gdb only
4059 wants to find the one with the complete definition. Note that if
4060 it is complete, we just call new_symbol, which does it's own
4061 checking about whether the struct/union is anonymous or not (and
4062 suppresses creating a symbol table entry itself). */
4065 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4067 struct objfile
*objfile
= cu
->objfile
;
4069 struct attribute
*attr
;
4070 const char *previous_prefix
= processing_current_prefix
;
4071 struct cleanup
*back_to
= NULL
;
4077 if (quirk_gcc_member_function_pointer (die
, cu
))
4080 type
= alloc_type (objfile
);
4081 INIT_CPLUS_SPECIFIC (type
);
4082 name
= dwarf2_name (die
, cu
);
4085 if (cu
->language
== language_cplus
4086 || cu
->language
== language_java
)
4088 char *new_prefix
= determine_class_name (die
, cu
);
4089 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
4090 strlen (new_prefix
),
4091 &objfile
->objfile_obstack
);
4092 back_to
= make_cleanup (xfree
, new_prefix
);
4093 processing_current_prefix
= new_prefix
;
4097 /* The name is already allocated along with this objfile, so
4098 we don't need to duplicate it for the type. */
4099 TYPE_TAG_NAME (type
) = name
;
4103 if (die
->tag
== DW_TAG_structure_type
)
4105 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4107 else if (die
->tag
== DW_TAG_union_type
)
4109 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4113 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4115 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4118 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4121 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4125 TYPE_LENGTH (type
) = 0;
4128 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB_SUPPORTED
;
4129 if (die_is_declaration (die
, cu
))
4130 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4132 /* We need to add the type field to the die immediately so we don't
4133 infinitely recurse when dealing with pointers to the structure
4134 type within the structure itself. */
4135 set_die_type (die
, type
, cu
);
4137 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4139 struct field_info fi
;
4140 struct die_info
*child_die
;
4141 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
4143 memset (&fi
, 0, sizeof (struct field_info
));
4145 child_die
= die
->child
;
4147 while (child_die
&& child_die
->tag
)
4149 if (child_die
->tag
== DW_TAG_member
4150 || child_die
->tag
== DW_TAG_variable
)
4152 /* NOTE: carlton/2002-11-05: A C++ static data member
4153 should be a DW_TAG_member that is a declaration, but
4154 all versions of G++ as of this writing (so through at
4155 least 3.2.1) incorrectly generate DW_TAG_variable
4156 tags for them instead. */
4157 dwarf2_add_field (&fi
, child_die
, cu
);
4159 else if (child_die
->tag
== DW_TAG_subprogram
)
4161 /* C++ member function. */
4162 read_type_die (child_die
, cu
);
4163 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4165 else if (child_die
->tag
== DW_TAG_inheritance
)
4167 /* C++ base class field. */
4168 dwarf2_add_field (&fi
, child_die
, cu
);
4170 child_die
= sibling_die (child_die
);
4173 /* Attach fields and member functions to the type. */
4175 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4178 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4180 /* Get the type which refers to the base class (possibly this
4181 class itself) which contains the vtable pointer for the current
4182 class from the DW_AT_containing_type attribute. */
4184 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4186 struct type
*t
= die_containing_type (die
, cu
);
4188 TYPE_VPTR_BASETYPE (type
) = t
;
4193 /* Our own class provides vtbl ptr. */
4194 for (i
= TYPE_NFIELDS (t
) - 1;
4195 i
>= TYPE_N_BASECLASSES (t
);
4198 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4200 if (is_vtable_name (fieldname
, cu
))
4202 TYPE_VPTR_FIELDNO (type
) = i
;
4207 /* Complain if virtual function table field not found. */
4208 if (i
< TYPE_N_BASECLASSES (t
))
4209 complaint (&symfile_complaints
,
4210 _("virtual function table pointer not found when defining class '%s'"),
4211 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4216 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4219 else if (cu
->producer
4220 && strncmp (cu
->producer
,
4221 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4223 /* The IBM XLC compiler does not provide direct indication
4224 of the containing type, but the vtable pointer is
4225 always named __vfp. */
4229 for (i
= TYPE_NFIELDS (type
) - 1;
4230 i
>= TYPE_N_BASECLASSES (type
);
4233 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4235 TYPE_VPTR_FIELDNO (type
) = i
;
4236 TYPE_VPTR_BASETYPE (type
) = type
;
4243 do_cleanups (back_to
);
4246 processing_current_prefix
= previous_prefix
;
4247 if (back_to
!= NULL
)
4248 do_cleanups (back_to
);
4252 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4254 struct objfile
*objfile
= cu
->objfile
;
4255 const char *previous_prefix
= processing_current_prefix
;
4256 struct die_info
*child_die
= die
->child
;
4258 if (TYPE_TAG_NAME (die
->type
) != NULL
)
4259 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
4261 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4262 snapshots) has been known to create a die giving a declaration
4263 for a class that has, as a child, a die giving a definition for a
4264 nested class. So we have to process our children even if the
4265 current die is a declaration. Normally, of course, a declaration
4266 won't have any children at all. */
4268 while (child_die
!= NULL
&& child_die
->tag
)
4270 if (child_die
->tag
== DW_TAG_member
4271 || child_die
->tag
== DW_TAG_variable
4272 || child_die
->tag
== DW_TAG_inheritance
)
4277 process_die (child_die
, cu
);
4279 child_die
= sibling_die (child_die
);
4282 /* Do not consider external references. According to the DWARF standard,
4283 these DIEs are identified by the fact that they have no byte_size
4284 attribute, and a declaration attribute. */
4285 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4286 || !die_is_declaration (die
, cu
))
4287 new_symbol (die
, die
->type
, cu
);
4289 processing_current_prefix
= previous_prefix
;
4292 /* Given a DW_AT_enumeration_type die, set its type. We do not
4293 complete the type's fields yet, or create any symbols. */
4296 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4298 struct objfile
*objfile
= cu
->objfile
;
4300 struct attribute
*attr
;
4306 type
= alloc_type (objfile
);
4308 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4309 name
= dwarf2_name (die
, cu
);
4312 if (processing_has_namespace_info
)
4314 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
4315 processing_current_prefix
,
4320 /* The name is already allocated along with this objfile, so
4321 we don't need to duplicate it for the type. */
4322 TYPE_TAG_NAME (type
) = name
;
4326 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4329 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4333 TYPE_LENGTH (type
) = 0;
4336 /* The enumeration DIE can be incomplete. In Ada, any type can be
4337 declared as private in the package spec, and then defined only
4338 inside the package body. Such types are known as Taft Amendment
4339 Types. When another package uses such a type, an incomplete DIE
4340 may be generated by the compiler. */
4341 if (die_is_declaration (die
, cu
))
4342 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
4344 set_die_type (die
, type
, cu
);
4347 /* Determine the name of the type represented by DIE, which should be
4348 a named C++ or Java compound type. Return the name in question; the caller
4349 is responsible for xfree()'ing it. */
4352 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4354 struct cleanup
*back_to
= NULL
;
4355 struct die_info
*spec_die
= die_specification (die
, cu
);
4356 char *new_prefix
= NULL
;
4358 /* If this is the definition of a class that is declared by another
4359 die, then processing_current_prefix may not be accurate; see
4360 read_func_scope for a similar example. */
4361 if (spec_die
!= NULL
)
4363 char *specification_prefix
= determine_prefix (spec_die
, cu
);
4364 processing_current_prefix
= specification_prefix
;
4365 back_to
= make_cleanup (xfree
, specification_prefix
);
4368 /* If we don't have namespace debug info, guess the name by trying
4369 to demangle the names of members, just like we did in
4370 guess_structure_name. */
4371 if (!processing_has_namespace_info
)
4373 struct die_info
*child
;
4375 for (child
= die
->child
;
4376 child
!= NULL
&& child
->tag
!= 0;
4377 child
= sibling_die (child
))
4379 if (child
->tag
== DW_TAG_subprogram
)
4382 = language_class_name_from_physname (cu
->language_defn
,
4386 if (new_prefix
!= NULL
)
4392 if (new_prefix
== NULL
)
4394 const char *name
= dwarf2_name (die
, cu
);
4395 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
4396 name
? name
: "<<anonymous>>",
4400 if (back_to
!= NULL
)
4401 do_cleanups (back_to
);
4406 /* Given a pointer to a die which begins an enumeration, process all
4407 the dies that define the members of the enumeration, and create the
4408 symbol for the enumeration type.
4410 NOTE: We reverse the order of the element list. */
4413 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4415 struct objfile
*objfile
= cu
->objfile
;
4416 struct die_info
*child_die
;
4417 struct field
*fields
;
4420 int unsigned_enum
= 1;
4425 if (die
->child
!= NULL
)
4427 child_die
= die
->child
;
4428 while (child_die
&& child_die
->tag
)
4430 if (child_die
->tag
!= DW_TAG_enumerator
)
4432 process_die (child_die
, cu
);
4436 name
= dwarf2_name (child_die
, cu
);
4439 sym
= new_symbol (child_die
, die
->type
, cu
);
4440 if (SYMBOL_VALUE (sym
) < 0)
4443 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4445 fields
= (struct field
*)
4447 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4448 * sizeof (struct field
));
4451 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
4452 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4453 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4454 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4455 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4461 child_die
= sibling_die (child_die
);
4466 TYPE_NFIELDS (die
->type
) = num_fields
;
4467 TYPE_FIELDS (die
->type
) = (struct field
*)
4468 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
4469 memcpy (TYPE_FIELDS (die
->type
), fields
,
4470 sizeof (struct field
) * num_fields
);
4474 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
4477 new_symbol (die
, die
->type
, cu
);
4480 /* Extract all information from a DW_TAG_array_type DIE and put it in
4481 the DIE's type field. For now, this only handles one dimensional
4485 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4487 struct objfile
*objfile
= cu
->objfile
;
4488 struct die_info
*child_die
;
4489 struct type
*type
= NULL
;
4490 struct type
*element_type
, *range_type
, *index_type
;
4491 struct type
**range_types
= NULL
;
4492 struct attribute
*attr
;
4494 struct cleanup
*back_to
;
4497 /* Return if we've already decoded this type. */
4503 element_type
= die_type (die
, cu
);
4505 /* Irix 6.2 native cc creates array types without children for
4506 arrays with unspecified length. */
4507 if (die
->child
== NULL
)
4509 index_type
= builtin_type_int32
;
4510 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4511 set_die_type (die
, create_array_type (NULL
, element_type
, range_type
),
4516 back_to
= make_cleanup (null_cleanup
, NULL
);
4517 child_die
= die
->child
;
4518 while (child_die
&& child_die
->tag
)
4520 if (child_die
->tag
== DW_TAG_subrange_type
)
4522 read_subrange_type (child_die
, cu
);
4524 if (child_die
->type
!= NULL
)
4526 /* The range type was succesfully read. Save it for
4527 the array type creation. */
4528 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4530 range_types
= (struct type
**)
4531 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4532 * sizeof (struct type
*));
4534 make_cleanup (free_current_contents
, &range_types
);
4536 range_types
[ndim
++] = child_die
->type
;
4539 child_die
= sibling_die (child_die
);
4542 /* Dwarf2 dimensions are output from left to right, create the
4543 necessary array types in backwards order. */
4545 type
= element_type
;
4547 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4551 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4556 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4559 /* Understand Dwarf2 support for vector types (like they occur on
4560 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4561 array type. This is not part of the Dwarf2/3 standard yet, but a
4562 custom vendor extension. The main difference between a regular
4563 array and the vector variant is that vectors are passed by value
4565 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4567 make_vector_type (type
);
4569 name
= dwarf2_name (die
, cu
);
4571 TYPE_NAME (type
) = name
;
4573 do_cleanups (back_to
);
4575 /* Install the type in the die. */
4576 set_die_type (die
, type
, cu
);
4579 static enum dwarf_array_dim_ordering
4580 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4582 struct attribute
*attr
;
4584 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4586 if (attr
) return DW_SND (attr
);
4589 GNU F77 is a special case, as at 08/2004 array type info is the
4590 opposite order to the dwarf2 specification, but data is still
4591 laid out as per normal fortran.
4593 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4597 if (cu
->language
== language_fortran
&&
4598 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4600 return DW_ORD_row_major
;
4603 switch (cu
->language_defn
->la_array_ordering
)
4605 case array_column_major
:
4606 return DW_ORD_col_major
;
4607 case array_row_major
:
4609 return DW_ORD_row_major
;
4613 /* Extract all information from a DW_TAG_set_type DIE and put it in
4614 the DIE's type field. */
4617 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4619 if (die
->type
== NULL
)
4620 die
->type
= create_set_type ((struct type
*) NULL
, die_type (die
, cu
));
4623 /* First cut: install each common block member as a global variable. */
4626 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4628 struct die_info
*child_die
;
4629 struct attribute
*attr
;
4631 CORE_ADDR base
= (CORE_ADDR
) 0;
4633 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4636 /* Support the .debug_loc offsets */
4637 if (attr_form_is_block (attr
))
4639 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4641 else if (attr_form_is_section_offset (attr
))
4643 dwarf2_complex_location_expr_complaint ();
4647 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4648 "common block member");
4651 if (die
->child
!= NULL
)
4653 child_die
= die
->child
;
4654 while (child_die
&& child_die
->tag
)
4656 sym
= new_symbol (child_die
, NULL
, cu
);
4657 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4660 SYMBOL_VALUE_ADDRESS (sym
) =
4661 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4662 add_symbol_to_list (sym
, &global_symbols
);
4664 child_die
= sibling_die (child_die
);
4669 /* Read a C++ namespace. */
4672 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4674 struct objfile
*objfile
= cu
->objfile
;
4675 const char *previous_prefix
= processing_current_prefix
;
4678 struct die_info
*current_die
;
4679 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4681 name
= namespace_name (die
, &is_anonymous
, cu
);
4683 /* Now build the name of the current namespace. */
4685 if (previous_prefix
[0] == '\0')
4687 processing_current_prefix
= name
;
4691 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4692 make_cleanup (xfree
, temp_name
);
4693 processing_current_prefix
= temp_name
;
4696 /* Add a symbol associated to this if we haven't seen the namespace
4697 before. Also, add a using directive if it's an anonymous
4700 if (dwarf2_extension (die
, cu
) == NULL
)
4704 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4705 this cast will hopefully become unnecessary. */
4706 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4707 (char *) processing_current_prefix
,
4709 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4711 new_symbol (die
, type
, cu
);
4712 set_die_type (die
, type
, cu
);
4715 cp_add_using_directive (processing_current_prefix
,
4716 strlen (previous_prefix
),
4717 strlen (processing_current_prefix
));
4720 if (die
->child
!= NULL
)
4722 struct die_info
*child_die
= die
->child
;
4724 while (child_die
&& child_die
->tag
)
4726 process_die (child_die
, cu
);
4727 child_die
= sibling_die (child_die
);
4731 processing_current_prefix
= previous_prefix
;
4732 do_cleanups (back_to
);
4735 /* Return the name of the namespace represented by DIE. Set
4736 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4740 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4742 struct die_info
*current_die
;
4743 const char *name
= NULL
;
4745 /* Loop through the extensions until we find a name. */
4747 for (current_die
= die
;
4748 current_die
!= NULL
;
4749 current_die
= dwarf2_extension (die
, cu
))
4751 name
= dwarf2_name (current_die
, cu
);
4756 /* Is it an anonymous namespace? */
4758 *is_anonymous
= (name
== NULL
);
4760 name
= "(anonymous namespace)";
4765 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4766 the user defined type vector. */
4769 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4771 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4772 struct comp_unit_head
*cu_header
= &cu
->header
;
4774 struct attribute
*attr_byte_size
;
4775 struct attribute
*attr_address_class
;
4776 int byte_size
, addr_class
;
4783 type
= lookup_pointer_type (die_type (die
, cu
));
4785 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4787 byte_size
= DW_UNSND (attr_byte_size
);
4789 byte_size
= cu_header
->addr_size
;
4791 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4792 if (attr_address_class
)
4793 addr_class
= DW_UNSND (attr_address_class
);
4795 addr_class
= DW_ADDR_none
;
4797 /* If the pointer size or address class is different than the
4798 default, create a type variant marked as such and set the
4799 length accordingly. */
4800 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4802 if (gdbarch_address_class_type_flags_p (gdbarch
))
4806 type_flags
= gdbarch_address_class_type_flags
4807 (gdbarch
, byte_size
, addr_class
);
4808 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4809 type
= make_type_with_address_space (type
, type_flags
);
4811 else if (TYPE_LENGTH (type
) != byte_size
)
4813 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4816 /* Should we also complain about unhandled address classes? */
4820 TYPE_LENGTH (type
) = byte_size
;
4821 set_die_type (die
, type
, cu
);
4824 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4825 the user defined type vector. */
4828 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4830 struct objfile
*objfile
= cu
->objfile
;
4832 struct type
*to_type
;
4833 struct type
*domain
;
4840 to_type
= die_type (die
, cu
);
4841 domain
= die_containing_type (die
, cu
);
4843 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4844 type
= lookup_methodptr_type (to_type
);
4846 type
= lookup_memberptr_type (to_type
, domain
);
4848 set_die_type (die
, type
, cu
);
4851 /* Extract all information from a DW_TAG_reference_type DIE and add to
4852 the user defined type vector. */
4855 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4857 struct comp_unit_head
*cu_header
= &cu
->header
;
4859 struct attribute
*attr
;
4866 type
= lookup_reference_type (die_type (die
, cu
));
4867 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4870 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4874 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4876 set_die_type (die
, type
, cu
);
4880 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4882 struct type
*base_type
;
4889 base_type
= die_type (die
, cu
);
4890 set_die_type (die
, make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0),
4895 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4897 struct type
*base_type
;
4904 base_type
= die_type (die
, cu
);
4905 set_die_type (die
, make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0),
4909 /* Extract all information from a DW_TAG_string_type DIE and add to
4910 the user defined type vector. It isn't really a user defined type,
4911 but it behaves like one, with other DIE's using an AT_user_def_type
4912 attribute to reference it. */
4915 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4917 struct objfile
*objfile
= cu
->objfile
;
4918 struct type
*type
, *range_type
, *index_type
, *char_type
;
4919 struct attribute
*attr
;
4920 unsigned int length
;
4927 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4930 length
= DW_UNSND (attr
);
4934 /* check for the DW_AT_byte_size attribute */
4935 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4938 length
= DW_UNSND (attr
);
4946 index_type
= builtin_type_int32
;
4947 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4948 type
= create_string_type (NULL
, range_type
);
4950 set_die_type (die
, type
, cu
);
4953 /* Handle DIES due to C code like:
4957 int (*funcp)(int a, long l);
4961 ('funcp' generates a DW_TAG_subroutine_type DIE)
4965 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4967 struct type
*type
; /* Type that this function returns */
4968 struct type
*ftype
; /* Function that returns above type */
4969 struct attribute
*attr
;
4971 /* Decode the type that this subroutine returns */
4976 type
= die_type (die
, cu
);
4977 ftype
= make_function_type (type
, (struct type
**) 0);
4979 /* All functions in C++, Pascal and Java have prototypes. */
4980 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4981 if ((attr
&& (DW_UNSND (attr
) != 0))
4982 || cu
->language
== language_cplus
4983 || cu
->language
== language_java
4984 || cu
->language
== language_pascal
)
4985 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4987 /* Store the calling convention in the type if it's available in
4988 the subroutine die. Otherwise set the calling convention to
4989 the default value DW_CC_normal. */
4990 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4991 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4993 if (die
->child
!= NULL
)
4995 struct die_info
*child_die
;
4999 /* Count the number of parameters.
5000 FIXME: GDB currently ignores vararg functions, but knows about
5001 vararg member functions. */
5002 child_die
= die
->child
;
5003 while (child_die
&& child_die
->tag
)
5005 if (child_die
->tag
== DW_TAG_formal_parameter
)
5007 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5008 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
5009 child_die
= sibling_die (child_die
);
5012 /* Allocate storage for parameters and fill them in. */
5013 TYPE_NFIELDS (ftype
) = nparams
;
5014 TYPE_FIELDS (ftype
) = (struct field
*)
5015 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5017 child_die
= die
->child
;
5018 while (child_die
&& child_die
->tag
)
5020 if (child_die
->tag
== DW_TAG_formal_parameter
)
5022 /* Dwarf2 has no clean way to discern C++ static and non-static
5023 member functions. G++ helps GDB by marking the first
5024 parameter for non-static member functions (which is the
5025 this pointer) as artificial. We pass this information
5026 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5027 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5029 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5031 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5032 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5035 child_die
= sibling_die (child_die
);
5039 set_die_type (die
, ftype
, cu
);
5043 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5045 struct objfile
*objfile
= cu
->objfile
;
5046 struct attribute
*attr
;
5051 name
= dwarf2_name (die
, cu
);
5052 set_die_type (die
, init_type (TYPE_CODE_TYPEDEF
, 0,
5053 TYPE_FLAG_TARGET_STUB
, name
, objfile
),
5055 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
5059 /* Find a representation of a given base type and install
5060 it in the TYPE field of the die. */
5063 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5065 struct objfile
*objfile
= cu
->objfile
;
5067 struct attribute
*attr
;
5068 int encoding
= 0, size
= 0;
5070 enum type_code code
= TYPE_CODE_INT
;
5072 struct type
*target_type
= NULL
;
5074 /* If we've already decoded this die, this is a no-op. */
5080 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5083 encoding
= DW_UNSND (attr
);
5085 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5088 size
= DW_UNSND (attr
);
5090 name
= dwarf2_name (die
, cu
);
5093 complaint (&symfile_complaints
,
5094 _("DW_AT_name missing from DW_TAG_base_type"));
5099 case DW_ATE_address
:
5100 /* Turn DW_ATE_address into a void * pointer. */
5101 code
= TYPE_CODE_PTR
;
5102 type_flags
|= TYPE_FLAG_UNSIGNED
;
5103 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5105 case DW_ATE_boolean
:
5106 code
= TYPE_CODE_BOOL
;
5107 type_flags
|= TYPE_FLAG_UNSIGNED
;
5109 case DW_ATE_complex_float
:
5110 code
= TYPE_CODE_COMPLEX
;
5111 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5113 case DW_ATE_decimal_float
:
5114 code
= TYPE_CODE_DECFLOAT
;
5117 code
= TYPE_CODE_FLT
;
5121 case DW_ATE_unsigned
:
5122 type_flags
|= TYPE_FLAG_UNSIGNED
;
5124 case DW_ATE_signed_char
:
5125 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5126 code
= TYPE_CODE_CHAR
;
5128 case DW_ATE_unsigned_char
:
5129 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5130 code
= TYPE_CODE_CHAR
;
5131 type_flags
|= TYPE_FLAG_UNSIGNED
;
5134 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5135 dwarf_type_encoding_name (encoding
));
5139 type
= init_type (code
, size
, type_flags
, name
, objfile
);
5140 TYPE_TARGET_TYPE (type
) = target_type
;
5142 set_die_type (die
, type
, cu
);
5145 /* Read the given DW_AT_subrange DIE. */
5148 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5150 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5151 struct type
*base_type
;
5152 struct type
*range_type
;
5153 struct attribute
*attr
;
5158 /* If we have already decoded this die, then nothing more to do. */
5162 base_type
= die_type (die
, cu
);
5163 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5165 complaint (&symfile_complaints
,
5166 _("DW_AT_type missing from DW_TAG_subrange_type"));
5168 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5169 0, NULL
, cu
->objfile
);
5172 if (cu
->language
== language_fortran
)
5174 /* FORTRAN implies a lower bound of 1, if not given. */
5178 /* FIXME: For variable sized arrays either of these could be
5179 a variable rather than a constant value. We'll allow it,
5180 but we don't know how to handle it. */
5181 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5183 low
= dwarf2_get_attr_constant_value (attr
, 0);
5185 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5188 if (attr
->form
== DW_FORM_block1
)
5190 /* GCC encodes arrays with unspecified or dynamic length
5191 with a DW_FORM_block1 attribute.
5192 FIXME: GDB does not yet know how to handle dynamic
5193 arrays properly, treat them as arrays with unspecified
5196 FIXME: jimb/2003-09-22: GDB does not really know
5197 how to handle arrays of unspecified length
5198 either; we just represent them as zero-length
5199 arrays. Choose an appropriate upper bound given
5200 the lower bound we've computed above. */
5204 high
= dwarf2_get_attr_constant_value (attr
, 1);
5207 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5209 name
= dwarf2_name (die
, cu
);
5211 TYPE_NAME (range_type
) = name
;
5213 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5215 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5217 set_die_type (die
, range_type
, cu
);
5221 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5228 /* For now, we only support the C meaning of an unspecified type: void. */
5230 type
= init_type (TYPE_CODE_VOID
, 0, 0, dwarf2_name (die
, cu
),
5233 set_die_type (die
, type
, cu
);
5236 /* Read a whole compilation unit into a linked list of dies. */
5238 static struct die_info
*
5239 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5241 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5244 /* Read a single die and all its descendents. Set the die's sibling
5245 field to NULL; set other fields in the die correctly, and set all
5246 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5247 location of the info_ptr after reading all of those dies. PARENT
5248 is the parent of the die in question. */
5250 static struct die_info
*
5251 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5252 struct dwarf2_cu
*cu
,
5253 gdb_byte
**new_info_ptr
,
5254 struct die_info
*parent
)
5256 struct die_info
*die
;
5260 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5261 store_in_ref_table (die
->offset
, die
, cu
);
5265 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5271 *new_info_ptr
= cur_ptr
;
5274 die
->sibling
= NULL
;
5275 die
->parent
= parent
;
5279 /* Read a die, all of its descendents, and all of its siblings; set
5280 all of the fields of all of the dies correctly. Arguments are as
5281 in read_die_and_children. */
5283 static struct die_info
*
5284 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5285 struct dwarf2_cu
*cu
,
5286 gdb_byte
**new_info_ptr
,
5287 struct die_info
*parent
)
5289 struct die_info
*first_die
, *last_sibling
;
5293 first_die
= last_sibling
= NULL
;
5297 struct die_info
*die
5298 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5306 last_sibling
->sibling
= die
;
5311 *new_info_ptr
= cur_ptr
;
5321 /* Free a linked list of dies. */
5324 free_die_list (struct die_info
*dies
)
5326 struct die_info
*die
, *next
;
5331 if (die
->child
!= NULL
)
5332 free_die_list (die
->child
);
5333 next
= die
->sibling
;
5340 /* Decompress a section that was compressed using zlib. Store the
5341 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5344 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5345 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5347 bfd
*abfd
= objfile
->obfd
;
5349 error (_("Support for zlib-compressed DWARF data (from '%s') "
5350 "is disabled in this copy of GDB"),
5351 bfd_get_filename (abfd
));
5353 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5354 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5355 bfd_size_type uncompressed_size
;
5356 gdb_byte
*uncompressed_buffer
;
5359 int header_size
= 12;
5361 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5362 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5363 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5364 bfd_get_filename (abfd
));
5366 /* Read the zlib header. In this case, it should be "ZLIB" followed
5367 by the uncompressed section size, 8 bytes in big-endian order. */
5368 if (compressed_size
< header_size
5369 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5370 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5371 bfd_get_filename (abfd
));
5372 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5373 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5374 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5375 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5376 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5377 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5378 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5379 uncompressed_size
+= compressed_buffer
[11];
5381 /* It is possible the section consists of several compressed
5382 buffers concatenated together, so we uncompress in a loop. */
5386 strm
.avail_in
= compressed_size
- header_size
;
5387 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5388 strm
.avail_out
= uncompressed_size
;
5389 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5391 rc
= inflateInit (&strm
);
5392 while (strm
.avail_in
> 0)
5395 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5396 bfd_get_filename (abfd
), rc
);
5397 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5398 + (uncompressed_size
- strm
.avail_out
));
5399 rc
= inflate (&strm
, Z_FINISH
);
5400 if (rc
!= Z_STREAM_END
)
5401 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5402 bfd_get_filename (abfd
), rc
);
5403 rc
= inflateReset (&strm
);
5405 rc
= inflateEnd (&strm
);
5407 || strm
.avail_out
!= 0)
5408 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5409 bfd_get_filename (abfd
), rc
);
5411 xfree (compressed_buffer
);
5412 *outbuf
= uncompressed_buffer
;
5413 *outsize
= uncompressed_size
;
5418 /* Read the contents of the section at OFFSET and of size SIZE from the
5419 object file specified by OBJFILE into the objfile_obstack and return it.
5420 If the section is compressed, uncompress it before returning. */
5423 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5425 bfd
*abfd
= objfile
->obfd
;
5426 gdb_byte
*buf
, *retbuf
;
5427 bfd_size_type size
= bfd_get_section_size (sectp
);
5428 unsigned char header
[4];
5433 /* Check if the file has a 4-byte header indicating compression. */
5434 if (size
> sizeof (header
)
5435 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5436 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5438 /* Upon decompression, update the buffer and its size. */
5439 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5441 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5442 dwarf2_resize_section (sectp
, size
);
5447 /* If we get here, we are a normal, not-compressed section. */
5448 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5449 /* When debugging .o files, we may need to apply relocations; see
5450 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5451 We never compress sections in .o files, so we only need to
5452 try this when the section is not compressed. */
5453 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5457 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5458 || bfd_bread (buf
, size
, abfd
) != size
)
5459 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5460 bfd_get_filename (abfd
));
5465 /* In DWARF version 2, the description of the debugging information is
5466 stored in a separate .debug_abbrev section. Before we read any
5467 dies from a section we read in all abbreviations and install them
5468 in a hash table. This function also sets flags in CU describing
5469 the data found in the abbrev table. */
5472 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5474 struct comp_unit_head
*cu_header
= &cu
->header
;
5475 gdb_byte
*abbrev_ptr
;
5476 struct abbrev_info
*cur_abbrev
;
5477 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5478 unsigned int abbrev_form
, hash_number
;
5479 struct attr_abbrev
*cur_attrs
;
5480 unsigned int allocated_attrs
;
5482 /* Initialize dwarf2 abbrevs */
5483 obstack_init (&cu
->abbrev_obstack
);
5484 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5486 * sizeof (struct abbrev_info
*)));
5487 memset (cu
->dwarf2_abbrevs
, 0,
5488 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5490 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5491 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5492 abbrev_ptr
+= bytes_read
;
5494 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5495 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5497 /* loop until we reach an abbrev number of 0 */
5498 while (abbrev_number
)
5500 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5502 /* read in abbrev header */
5503 cur_abbrev
->number
= abbrev_number
;
5504 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5505 abbrev_ptr
+= bytes_read
;
5506 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5509 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5510 cu
->has_namespace_info
= 1;
5512 /* now read in declarations */
5513 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5514 abbrev_ptr
+= bytes_read
;
5515 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5516 abbrev_ptr
+= bytes_read
;
5519 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5521 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5523 = xrealloc (cur_attrs
, (allocated_attrs
5524 * sizeof (struct attr_abbrev
)));
5527 /* Record whether this compilation unit might have
5528 inter-compilation-unit references. If we don't know what form
5529 this attribute will have, then it might potentially be a
5530 DW_FORM_ref_addr, so we conservatively expect inter-CU
5533 if (abbrev_form
== DW_FORM_ref_addr
5534 || abbrev_form
== DW_FORM_indirect
)
5535 cu
->has_form_ref_addr
= 1;
5537 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5538 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5539 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5540 abbrev_ptr
+= bytes_read
;
5541 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5542 abbrev_ptr
+= bytes_read
;
5545 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5546 (cur_abbrev
->num_attrs
5547 * sizeof (struct attr_abbrev
)));
5548 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5549 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5551 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5552 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5553 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5555 /* Get next abbreviation.
5556 Under Irix6 the abbreviations for a compilation unit are not
5557 always properly terminated with an abbrev number of 0.
5558 Exit loop if we encounter an abbreviation which we have
5559 already read (which means we are about to read the abbreviations
5560 for the next compile unit) or if the end of the abbreviation
5561 table is reached. */
5562 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5563 >= dwarf2_per_objfile
->abbrev_size
)
5565 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5566 abbrev_ptr
+= bytes_read
;
5567 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5574 /* Release the memory used by the abbrev table for a compilation unit. */
5577 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5579 struct dwarf2_cu
*cu
= ptr_to_cu
;
5581 obstack_free (&cu
->abbrev_obstack
, NULL
);
5582 cu
->dwarf2_abbrevs
= NULL
;
5585 /* Lookup an abbrev_info structure in the abbrev hash table. */
5587 static struct abbrev_info
*
5588 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5590 unsigned int hash_number
;
5591 struct abbrev_info
*abbrev
;
5593 hash_number
= number
% ABBREV_HASH_SIZE
;
5594 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5598 if (abbrev
->number
== number
)
5601 abbrev
= abbrev
->next
;
5606 /* Returns nonzero if TAG represents a type that we might generate a partial
5610 is_type_tag_for_partial (int tag
)
5615 /* Some types that would be reasonable to generate partial symbols for,
5616 that we don't at present. */
5617 case DW_TAG_array_type
:
5618 case DW_TAG_file_type
:
5619 case DW_TAG_ptr_to_member_type
:
5620 case DW_TAG_set_type
:
5621 case DW_TAG_string_type
:
5622 case DW_TAG_subroutine_type
:
5624 case DW_TAG_base_type
:
5625 case DW_TAG_class_type
:
5626 case DW_TAG_interface_type
:
5627 case DW_TAG_enumeration_type
:
5628 case DW_TAG_structure_type
:
5629 case DW_TAG_subrange_type
:
5630 case DW_TAG_typedef
:
5631 case DW_TAG_union_type
:
5638 /* Load all DIEs that are interesting for partial symbols into memory. */
5640 static struct partial_die_info
*
5641 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5642 struct dwarf2_cu
*cu
)
5644 struct partial_die_info
*part_die
;
5645 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5646 struct abbrev_info
*abbrev
;
5647 unsigned int bytes_read
;
5648 unsigned int load_all
= 0;
5650 int nesting_level
= 1;
5655 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5659 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5663 &cu
->comp_unit_obstack
,
5664 hashtab_obstack_allocate
,
5665 dummy_obstack_deallocate
);
5667 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5668 sizeof (struct partial_die_info
));
5672 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5674 /* A NULL abbrev means the end of a series of children. */
5677 if (--nesting_level
== 0)
5679 /* PART_DIE was probably the last thing allocated on the
5680 comp_unit_obstack, so we could call obstack_free
5681 here. We don't do that because the waste is small,
5682 and will be cleaned up when we're done with this
5683 compilation unit. This way, we're also more robust
5684 against other users of the comp_unit_obstack. */
5687 info_ptr
+= bytes_read
;
5688 last_die
= parent_die
;
5689 parent_die
= parent_die
->die_parent
;
5693 /* Check whether this DIE is interesting enough to save. Normally
5694 we would not be interested in members here, but there may be
5695 later variables referencing them via DW_AT_specification (for
5698 && !is_type_tag_for_partial (abbrev
->tag
)
5699 && abbrev
->tag
!= DW_TAG_enumerator
5700 && abbrev
->tag
!= DW_TAG_subprogram
5701 && abbrev
->tag
!= DW_TAG_variable
5702 && abbrev
->tag
!= DW_TAG_namespace
5703 && abbrev
->tag
!= DW_TAG_member
)
5705 /* Otherwise we skip to the next sibling, if any. */
5706 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5710 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5711 abfd
, info_ptr
, cu
);
5713 /* This two-pass algorithm for processing partial symbols has a
5714 high cost in cache pressure. Thus, handle some simple cases
5715 here which cover the majority of C partial symbols. DIEs
5716 which neither have specification tags in them, nor could have
5717 specification tags elsewhere pointing at them, can simply be
5718 processed and discarded.
5720 This segment is also optional; scan_partial_symbols and
5721 add_partial_symbol will handle these DIEs if we chain
5722 them in normally. When compilers which do not emit large
5723 quantities of duplicate debug information are more common,
5724 this code can probably be removed. */
5726 /* Any complete simple types at the top level (pretty much all
5727 of them, for a language without namespaces), can be processed
5729 if (parent_die
== NULL
5730 && part_die
->has_specification
== 0
5731 && part_die
->is_declaration
== 0
5732 && (part_die
->tag
== DW_TAG_typedef
5733 || part_die
->tag
== DW_TAG_base_type
5734 || part_die
->tag
== DW_TAG_subrange_type
))
5736 if (building_psymtab
&& part_die
->name
!= NULL
)
5737 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5738 VAR_DOMAIN
, LOC_TYPEDEF
,
5739 &cu
->objfile
->static_psymbols
,
5740 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5741 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5745 /* If we're at the second level, and we're an enumerator, and
5746 our parent has no specification (meaning possibly lives in a
5747 namespace elsewhere), then we can add the partial symbol now
5748 instead of queueing it. */
5749 if (part_die
->tag
== DW_TAG_enumerator
5750 && parent_die
!= NULL
5751 && parent_die
->die_parent
== NULL
5752 && parent_die
->tag
== DW_TAG_enumeration_type
5753 && parent_die
->has_specification
== 0)
5755 if (part_die
->name
== NULL
)
5756 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5757 else if (building_psymtab
)
5758 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5759 VAR_DOMAIN
, LOC_CONST
,
5760 (cu
->language
== language_cplus
5761 || cu
->language
== language_java
)
5762 ? &cu
->objfile
->global_psymbols
5763 : &cu
->objfile
->static_psymbols
,
5764 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5766 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5770 /* We'll save this DIE so link it in. */
5771 part_die
->die_parent
= parent_die
;
5772 part_die
->die_sibling
= NULL
;
5773 part_die
->die_child
= NULL
;
5775 if (last_die
&& last_die
== parent_die
)
5776 last_die
->die_child
= part_die
;
5778 last_die
->die_sibling
= part_die
;
5780 last_die
= part_die
;
5782 if (first_die
== NULL
)
5783 first_die
= part_die
;
5785 /* Maybe add the DIE to the hash table. Not all DIEs that we
5786 find interesting need to be in the hash table, because we
5787 also have the parent/sibling/child chains; only those that we
5788 might refer to by offset later during partial symbol reading.
5790 For now this means things that might have be the target of a
5791 DW_AT_specification, DW_AT_abstract_origin, or
5792 DW_AT_extension. DW_AT_extension will refer only to
5793 namespaces; DW_AT_abstract_origin refers to functions (and
5794 many things under the function DIE, but we do not recurse
5795 into function DIEs during partial symbol reading) and
5796 possibly variables as well; DW_AT_specification refers to
5797 declarations. Declarations ought to have the DW_AT_declaration
5798 flag. It happens that GCC forgets to put it in sometimes, but
5799 only for functions, not for types.
5801 Adding more things than necessary to the hash table is harmless
5802 except for the performance cost. Adding too few will result in
5803 wasted time in find_partial_die, when we reread the compilation
5804 unit with load_all_dies set. */
5807 || abbrev
->tag
== DW_TAG_subprogram
5808 || abbrev
->tag
== DW_TAG_variable
5809 || abbrev
->tag
== DW_TAG_namespace
5810 || part_die
->is_declaration
)
5814 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5815 part_die
->offset
, INSERT
);
5819 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5820 sizeof (struct partial_die_info
));
5822 /* For some DIEs we want to follow their children (if any). For C
5823 we have no reason to follow the children of structures; for other
5824 languages we have to, both so that we can get at method physnames
5825 to infer fully qualified class names, and for DW_AT_specification. */
5826 if (last_die
->has_children
5828 || last_die
->tag
== DW_TAG_namespace
5829 || last_die
->tag
== DW_TAG_enumeration_type
5830 || (cu
->language
!= language_c
5831 && (last_die
->tag
== DW_TAG_class_type
5832 || last_die
->tag
== DW_TAG_interface_type
5833 || last_die
->tag
== DW_TAG_structure_type
5834 || last_die
->tag
== DW_TAG_union_type
))))
5837 parent_die
= last_die
;
5841 /* Otherwise we skip to the next sibling, if any. */
5842 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5844 /* Back to the top, do it again. */
5848 /* Read a minimal amount of information into the minimal die structure. */
5851 read_partial_die (struct partial_die_info
*part_die
,
5852 struct abbrev_info
*abbrev
,
5853 unsigned int abbrev_len
, bfd
*abfd
,
5854 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5856 unsigned int bytes_read
, i
;
5857 struct attribute attr
;
5858 int has_low_pc_attr
= 0;
5859 int has_high_pc_attr
= 0;
5860 CORE_ADDR base_address
= 0;
5864 base_address_low_pc
,
5865 /* Overrides BASE_ADDRESS_LOW_PC. */
5866 base_address_entry_pc
5868 base_address_type
= base_address_none
;
5870 memset (part_die
, 0, sizeof (struct partial_die_info
));
5872 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5874 info_ptr
+= abbrev_len
;
5879 part_die
->tag
= abbrev
->tag
;
5880 part_die
->has_children
= abbrev
->has_children
;
5882 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5884 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5886 /* Store the data if it is of an attribute we want to keep in a
5887 partial symbol table. */
5892 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5893 if (part_die
->name
== NULL
)
5894 part_die
->name
= DW_STRING (&attr
);
5896 case DW_AT_comp_dir
:
5897 if (part_die
->dirname
== NULL
)
5898 part_die
->dirname
= DW_STRING (&attr
);
5900 case DW_AT_MIPS_linkage_name
:
5901 part_die
->name
= DW_STRING (&attr
);
5904 has_low_pc_attr
= 1;
5905 part_die
->lowpc
= DW_ADDR (&attr
);
5906 if (part_die
->tag
== DW_TAG_compile_unit
5907 && base_address_type
< base_address_low_pc
)
5909 base_address
= DW_ADDR (&attr
);
5910 base_address_type
= base_address_low_pc
;
5914 has_high_pc_attr
= 1;
5915 part_die
->highpc
= DW_ADDR (&attr
);
5917 case DW_AT_entry_pc
:
5918 if (part_die
->tag
== DW_TAG_compile_unit
5919 && base_address_type
< base_address_entry_pc
)
5921 base_address
= DW_ADDR (&attr
);
5922 base_address_type
= base_address_entry_pc
;
5926 if (part_die
->tag
== DW_TAG_compile_unit
)
5928 cu
->ranges_offset
= DW_UNSND (&attr
);
5929 cu
->has_ranges_offset
= 1;
5932 case DW_AT_location
:
5933 /* Support the .debug_loc offsets */
5934 if (attr_form_is_block (&attr
))
5936 part_die
->locdesc
= DW_BLOCK (&attr
);
5938 else if (attr_form_is_section_offset (&attr
))
5940 dwarf2_complex_location_expr_complaint ();
5944 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5945 "partial symbol information");
5948 case DW_AT_language
:
5949 part_die
->language
= DW_UNSND (&attr
);
5951 case DW_AT_external
:
5952 part_die
->is_external
= DW_UNSND (&attr
);
5954 case DW_AT_declaration
:
5955 part_die
->is_declaration
= DW_UNSND (&attr
);
5958 part_die
->has_type
= 1;
5960 case DW_AT_abstract_origin
:
5961 case DW_AT_specification
:
5962 case DW_AT_extension
:
5963 part_die
->has_specification
= 1;
5964 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5967 /* Ignore absolute siblings, they might point outside of
5968 the current compile unit. */
5969 if (attr
.form
== DW_FORM_ref_addr
)
5970 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5972 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5973 + dwarf2_get_ref_die_offset (&attr
, cu
);
5975 case DW_AT_stmt_list
:
5976 part_die
->has_stmt_list
= 1;
5977 part_die
->line_offset
= DW_UNSND (&attr
);
5979 case DW_AT_byte_size
:
5980 part_die
->has_byte_size
= 1;
5982 case DW_AT_calling_convention
:
5983 /* DWARF doesn't provide a way to identify a program's source-level
5984 entry point. DW_AT_calling_convention attributes are only meant
5985 to describe functions' calling conventions.
5987 However, because it's a necessary piece of information in
5988 Fortran, and because DW_CC_program is the only piece of debugging
5989 information whose definition refers to a 'main program' at all,
5990 several compilers have begun marking Fortran main programs with
5991 DW_CC_program --- even when those functions use the standard
5992 calling conventions.
5994 So until DWARF specifies a way to provide this information and
5995 compilers pick up the new representation, we'll support this
5997 if (DW_UNSND (&attr
) == DW_CC_program
5998 && cu
->language
== language_fortran
)
5999 set_main_name (part_die
->name
);
6006 /* When using the GNU linker, .gnu.linkonce. sections are used to
6007 eliminate duplicate copies of functions and vtables and such.
6008 The linker will arbitrarily choose one and discard the others.
6009 The AT_*_pc values for such functions refer to local labels in
6010 these sections. If the section from that file was discarded, the
6011 labels are not in the output, so the relocs get a value of 0.
6012 If this is a discarded function, mark the pc bounds as invalid,
6013 so that GDB will ignore it. */
6014 if (has_low_pc_attr
&& has_high_pc_attr
6015 && part_die
->lowpc
< part_die
->highpc
6016 && (part_die
->lowpc
!= 0
6017 || dwarf2_per_objfile
->has_section_at_zero
))
6018 part_die
->has_pc_info
= 1;
6020 if (base_address_type
!= base_address_none
&& !cu
->header
.base_known
)
6022 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6023 cu
->header
.base_known
= 1;
6024 cu
->header
.base_address
= base_address
;
6030 /* Find a cached partial DIE at OFFSET in CU. */
6032 static struct partial_die_info
*
6033 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
6035 struct partial_die_info
*lookup_die
= NULL
;
6036 struct partial_die_info part_die
;
6038 part_die
.offset
= offset
;
6039 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6044 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6046 static struct partial_die_info
*
6047 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
6049 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6050 struct partial_die_info
*pd
= NULL
;
6052 if (offset
>= cu
->header
.offset
6053 && offset
< cu
->header
.offset
+ cu
->header
.length
)
6055 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6060 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6062 if (per_cu
->cu
== NULL
)
6064 load_comp_unit (per_cu
, cu
->objfile
);
6065 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6066 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6069 per_cu
->cu
->last_used
= 0;
6070 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6072 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6074 struct cleanup
*back_to
;
6075 struct partial_die_info comp_unit_die
;
6076 struct abbrev_info
*abbrev
;
6077 unsigned int bytes_read
;
6080 per_cu
->load_all_dies
= 1;
6082 /* Re-read the DIEs. */
6083 back_to
= make_cleanup (null_cleanup
, 0);
6084 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6086 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6087 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6089 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
6090 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6091 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6092 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6094 if (comp_unit_die
.has_children
)
6095 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6096 do_cleanups (back_to
);
6098 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6102 internal_error (__FILE__
, __LINE__
,
6103 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
6104 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6108 /* Adjust PART_DIE before generating a symbol for it. This function
6109 may set the is_external flag or change the DIE's name. */
6112 fixup_partial_die (struct partial_die_info
*part_die
,
6113 struct dwarf2_cu
*cu
)
6115 /* If we found a reference attribute and the DIE has no name, try
6116 to find a name in the referred to DIE. */
6118 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6120 struct partial_die_info
*spec_die
;
6122 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6124 fixup_partial_die (spec_die
, cu
);
6128 part_die
->name
= spec_die
->name
;
6130 /* Copy DW_AT_external attribute if it is set. */
6131 if (spec_die
->is_external
)
6132 part_die
->is_external
= spec_die
->is_external
;
6136 /* Set default names for some unnamed DIEs. */
6137 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6138 || part_die
->tag
== DW_TAG_class_type
))
6139 part_die
->name
= "(anonymous class)";
6141 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6142 part_die
->name
= "(anonymous namespace)";
6144 if (part_die
->tag
== DW_TAG_structure_type
6145 || part_die
->tag
== DW_TAG_class_type
6146 || part_die
->tag
== DW_TAG_union_type
)
6147 guess_structure_name (part_die
, cu
);
6150 /* Read the die from the .debug_info section buffer. Set DIEP to
6151 point to a newly allocated die with its information, except for its
6152 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6153 whether the die has children or not. */
6156 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6157 struct dwarf2_cu
*cu
, int *has_children
)
6159 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6160 struct abbrev_info
*abbrev
;
6161 struct die_info
*die
;
6163 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6164 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6165 info_ptr
+= bytes_read
;
6168 die
= dwarf_alloc_die ();
6170 die
->abbrev
= abbrev_number
;
6177 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6180 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6182 bfd_get_filename (abfd
));
6184 die
= dwarf_alloc_die ();
6185 die
->offset
= offset
;
6186 die
->tag
= abbrev
->tag
;
6187 die
->abbrev
= abbrev_number
;
6190 die
->num_attrs
= abbrev
->num_attrs
;
6191 die
->attrs
= (struct attribute
*)
6192 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
6194 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6196 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6197 abfd
, info_ptr
, cu
);
6199 /* If this attribute is an absolute reference to a different
6200 compilation unit, make sure that compilation unit is loaded
6202 if (die
->attrs
[i
].form
== DW_FORM_ref_addr
6203 && (DW_ADDR (&die
->attrs
[i
]) < cu
->header
.offset
6204 || (DW_ADDR (&die
->attrs
[i
])
6205 >= cu
->header
.offset
+ cu
->header
.length
)))
6207 struct dwarf2_per_cu_data
*per_cu
;
6208 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (&die
->attrs
[i
]),
6211 /* Mark the dependence relation so that we don't flush PER_CU
6213 dwarf2_add_dependence (cu
, per_cu
);
6215 /* If it's already on the queue, we have nothing to do. */
6219 /* If the compilation unit is already loaded, just mark it as
6221 if (per_cu
->cu
!= NULL
)
6223 per_cu
->cu
->last_used
= 0;
6227 /* Add it to the queue. */
6228 queue_comp_unit (per_cu
);
6233 *has_children
= abbrev
->has_children
;
6237 /* Read an attribute value described by an attribute form. */
6240 read_attribute_value (struct attribute
*attr
, unsigned form
,
6241 bfd
*abfd
, gdb_byte
*info_ptr
,
6242 struct dwarf2_cu
*cu
)
6244 struct comp_unit_head
*cu_header
= &cu
->header
;
6245 unsigned int bytes_read
;
6246 struct dwarf_block
*blk
;
6252 case DW_FORM_ref_addr
:
6253 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6254 info_ptr
+= bytes_read
;
6256 case DW_FORM_block2
:
6257 blk
= dwarf_alloc_block (cu
);
6258 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6260 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6261 info_ptr
+= blk
->size
;
6262 DW_BLOCK (attr
) = blk
;
6264 case DW_FORM_block4
:
6265 blk
= dwarf_alloc_block (cu
);
6266 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6268 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6269 info_ptr
+= blk
->size
;
6270 DW_BLOCK (attr
) = blk
;
6273 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6277 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6281 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6284 case DW_FORM_string
:
6285 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6286 info_ptr
+= bytes_read
;
6289 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6291 info_ptr
+= bytes_read
;
6294 blk
= dwarf_alloc_block (cu
);
6295 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6296 info_ptr
+= bytes_read
;
6297 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6298 info_ptr
+= blk
->size
;
6299 DW_BLOCK (attr
) = blk
;
6301 case DW_FORM_block1
:
6302 blk
= dwarf_alloc_block (cu
);
6303 blk
->size
= read_1_byte (abfd
, info_ptr
);
6305 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6306 info_ptr
+= blk
->size
;
6307 DW_BLOCK (attr
) = blk
;
6310 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6314 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6318 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6319 info_ptr
+= bytes_read
;
6322 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6323 info_ptr
+= bytes_read
;
6326 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6330 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6334 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6338 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6341 case DW_FORM_ref_udata
:
6342 DW_ADDR (attr
) = (cu
->header
.offset
6343 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6344 info_ptr
+= bytes_read
;
6346 case DW_FORM_indirect
:
6347 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6348 info_ptr
+= bytes_read
;
6349 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6352 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6353 dwarf_form_name (form
),
6354 bfd_get_filename (abfd
));
6359 /* Read an attribute described by an abbreviated attribute. */
6362 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6363 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6365 attr
->name
= abbrev
->name
;
6366 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6369 /* read dwarf information from a buffer */
6372 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6374 return bfd_get_8 (abfd
, buf
);
6378 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6380 return bfd_get_signed_8 (abfd
, buf
);
6384 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6386 return bfd_get_16 (abfd
, buf
);
6390 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6392 return bfd_get_signed_16 (abfd
, buf
);
6396 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6398 return bfd_get_32 (abfd
, buf
);
6402 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6404 return bfd_get_signed_32 (abfd
, buf
);
6407 static unsigned long
6408 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6410 return bfd_get_64 (abfd
, buf
);
6414 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6415 unsigned int *bytes_read
)
6417 struct comp_unit_head
*cu_header
= &cu
->header
;
6418 CORE_ADDR retval
= 0;
6420 if (cu_header
->signed_addr_p
)
6422 switch (cu_header
->addr_size
)
6425 retval
= bfd_get_signed_16 (abfd
, buf
);
6428 retval
= bfd_get_signed_32 (abfd
, buf
);
6431 retval
= bfd_get_signed_64 (abfd
, buf
);
6434 internal_error (__FILE__
, __LINE__
,
6435 _("read_address: bad switch, signed [in module %s]"),
6436 bfd_get_filename (abfd
));
6441 switch (cu_header
->addr_size
)
6444 retval
= bfd_get_16 (abfd
, buf
);
6447 retval
= bfd_get_32 (abfd
, buf
);
6450 retval
= bfd_get_64 (abfd
, buf
);
6453 internal_error (__FILE__
, __LINE__
,
6454 _("read_address: bad switch, unsigned [in module %s]"),
6455 bfd_get_filename (abfd
));
6459 *bytes_read
= cu_header
->addr_size
;
6463 /* Read the initial length from a section. The (draft) DWARF 3
6464 specification allows the initial length to take up either 4 bytes
6465 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6466 bytes describe the length and all offsets will be 8 bytes in length
6469 An older, non-standard 64-bit format is also handled by this
6470 function. The older format in question stores the initial length
6471 as an 8-byte quantity without an escape value. Lengths greater
6472 than 2^32 aren't very common which means that the initial 4 bytes
6473 is almost always zero. Since a length value of zero doesn't make
6474 sense for the 32-bit format, this initial zero can be considered to
6475 be an escape value which indicates the presence of the older 64-bit
6476 format. As written, the code can't detect (old format) lengths
6477 greater than 4GB. If it becomes necessary to handle lengths
6478 somewhat larger than 4GB, we could allow other small values (such
6479 as the non-sensical values of 1, 2, and 3) to also be used as
6480 escape values indicating the presence of the old format.
6482 The value returned via bytes_read should be used to increment the
6483 relevant pointer after calling read_initial_length().
6485 As a side effect, this function sets the fields initial_length_size
6486 and offset_size in cu_header to the values appropriate for the
6487 length field. (The format of the initial length field determines
6488 the width of file offsets to be fetched later with read_offset().)
6490 [ Note: read_initial_length() and read_offset() are based on the
6491 document entitled "DWARF Debugging Information Format", revision
6492 3, draft 8, dated November 19, 2001. This document was obtained
6495 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6497 This document is only a draft and is subject to change. (So beware.)
6499 Details regarding the older, non-standard 64-bit format were
6500 determined empirically by examining 64-bit ELF files produced by
6501 the SGI toolchain on an IRIX 6.5 machine.
6503 - Kevin, July 16, 2002
6507 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6508 unsigned int *bytes_read
)
6510 LONGEST length
= bfd_get_32 (abfd
, buf
);
6512 if (length
== 0xffffffff)
6514 length
= bfd_get_64 (abfd
, buf
+ 4);
6517 else if (length
== 0)
6519 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6520 length
= bfd_get_64 (abfd
, buf
);
6530 gdb_assert (cu_header
->initial_length_size
== 0
6531 || cu_header
->initial_length_size
== 4
6532 || cu_header
->initial_length_size
== 8
6533 || cu_header
->initial_length_size
== 12);
6535 if (cu_header
->initial_length_size
!= 0
6536 && cu_header
->initial_length_size
!= *bytes_read
)
6537 complaint (&symfile_complaints
,
6538 _("intermixed 32-bit and 64-bit DWARF sections"));
6540 cu_header
->initial_length_size
= *bytes_read
;
6541 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6547 /* Read an offset from the data stream. The size of the offset is
6548 given by cu_header->offset_size. */
6551 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6552 unsigned int *bytes_read
)
6556 switch (cu_header
->offset_size
)
6559 retval
= bfd_get_32 (abfd
, buf
);
6563 retval
= bfd_get_64 (abfd
, buf
);
6567 internal_error (__FILE__
, __LINE__
,
6568 _("read_offset: bad switch [in module %s]"),
6569 bfd_get_filename (abfd
));
6576 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6578 /* If the size of a host char is 8 bits, we can return a pointer
6579 to the buffer, otherwise we have to copy the data to a buffer
6580 allocated on the temporary obstack. */
6581 gdb_assert (HOST_CHAR_BIT
== 8);
6586 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6588 /* If the size of a host char is 8 bits, we can return a pointer
6589 to the string, otherwise we have to copy the string to a buffer
6590 allocated on the temporary obstack. */
6591 gdb_assert (HOST_CHAR_BIT
== 8);
6594 *bytes_read_ptr
= 1;
6597 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6598 return (char *) buf
;
6602 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6603 const struct comp_unit_head
*cu_header
,
6604 unsigned int *bytes_read_ptr
)
6606 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6609 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6611 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6612 bfd_get_filename (abfd
));
6615 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6617 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6618 bfd_get_filename (abfd
));
6621 gdb_assert (HOST_CHAR_BIT
== 8);
6622 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6624 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6627 static unsigned long
6628 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6630 unsigned long result
;
6631 unsigned int num_read
;
6641 byte
= bfd_get_8 (abfd
, buf
);
6644 result
|= ((unsigned long)(byte
& 127) << shift
);
6645 if ((byte
& 128) == 0)
6651 *bytes_read_ptr
= num_read
;
6656 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6659 int i
, shift
, num_read
;
6668 byte
= bfd_get_8 (abfd
, buf
);
6671 result
|= ((long)(byte
& 127) << shift
);
6673 if ((byte
& 128) == 0)
6678 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6679 result
|= -(((long)1) << shift
);
6680 *bytes_read_ptr
= num_read
;
6684 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6687 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6693 byte
= bfd_get_8 (abfd
, buf
);
6695 if ((byte
& 128) == 0)
6701 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6707 cu
->language
= language_c
;
6709 case DW_LANG_C_plus_plus
:
6710 cu
->language
= language_cplus
;
6712 case DW_LANG_Fortran77
:
6713 case DW_LANG_Fortran90
:
6714 case DW_LANG_Fortran95
:
6715 cu
->language
= language_fortran
;
6717 case DW_LANG_Mips_Assembler
:
6718 cu
->language
= language_asm
;
6721 cu
->language
= language_java
;
6725 cu
->language
= language_ada
;
6727 case DW_LANG_Modula2
:
6728 cu
->language
= language_m2
;
6730 case DW_LANG_Pascal83
:
6731 cu
->language
= language_pascal
;
6734 cu
->language
= language_objc
;
6736 case DW_LANG_Cobol74
:
6737 case DW_LANG_Cobol85
:
6739 cu
->language
= language_minimal
;
6742 cu
->language_defn
= language_def (cu
->language
);
6745 /* Return the named attribute or NULL if not there. */
6747 static struct attribute
*
6748 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6751 struct attribute
*spec
= NULL
;
6753 for (i
= 0; i
< die
->num_attrs
; ++i
)
6755 if (die
->attrs
[i
].name
== name
)
6756 return &die
->attrs
[i
];
6757 if (die
->attrs
[i
].name
== DW_AT_specification
6758 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6759 spec
= &die
->attrs
[i
];
6763 return dwarf2_attr (follow_die_ref (die
, spec
, cu
), name
, cu
);
6768 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6769 and holds a non-zero value. This function should only be used for
6770 DW_FORM_flag attributes. */
6773 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6775 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6777 return (attr
&& DW_UNSND (attr
));
6781 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6783 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6784 which value is non-zero. However, we have to be careful with
6785 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6786 (via dwarf2_flag_true_p) follows this attribute. So we may
6787 end up accidently finding a declaration attribute that belongs
6788 to a different DIE referenced by the specification attribute,
6789 even though the given DIE does not have a declaration attribute. */
6790 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6791 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6794 /* Return the die giving the specification for DIE, if there is
6797 static struct die_info
*
6798 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6800 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6802 if (spec_attr
== NULL
)
6805 return follow_die_ref (die
, spec_attr
, cu
);
6808 /* Free the line_header structure *LH, and any arrays and strings it
6811 free_line_header (struct line_header
*lh
)
6813 if (lh
->standard_opcode_lengths
)
6814 xfree (lh
->standard_opcode_lengths
);
6816 /* Remember that all the lh->file_names[i].name pointers are
6817 pointers into debug_line_buffer, and don't need to be freed. */
6819 xfree (lh
->file_names
);
6821 /* Similarly for the include directory names. */
6822 if (lh
->include_dirs
)
6823 xfree (lh
->include_dirs
);
6829 /* Add an entry to LH's include directory table. */
6831 add_include_dir (struct line_header
*lh
, char *include_dir
)
6833 /* Grow the array if necessary. */
6834 if (lh
->include_dirs_size
== 0)
6836 lh
->include_dirs_size
= 1; /* for testing */
6837 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6838 * sizeof (*lh
->include_dirs
));
6840 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6842 lh
->include_dirs_size
*= 2;
6843 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6844 (lh
->include_dirs_size
6845 * sizeof (*lh
->include_dirs
)));
6848 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6852 /* Add an entry to LH's file name table. */
6854 add_file_name (struct line_header
*lh
,
6856 unsigned int dir_index
,
6857 unsigned int mod_time
,
6858 unsigned int length
)
6860 struct file_entry
*fe
;
6862 /* Grow the array if necessary. */
6863 if (lh
->file_names_size
== 0)
6865 lh
->file_names_size
= 1; /* for testing */
6866 lh
->file_names
= xmalloc (lh
->file_names_size
6867 * sizeof (*lh
->file_names
));
6869 else if (lh
->num_file_names
>= lh
->file_names_size
)
6871 lh
->file_names_size
*= 2;
6872 lh
->file_names
= xrealloc (lh
->file_names
,
6873 (lh
->file_names_size
6874 * sizeof (*lh
->file_names
)));
6877 fe
= &lh
->file_names
[lh
->num_file_names
++];
6879 fe
->dir_index
= dir_index
;
6880 fe
->mod_time
= mod_time
;
6881 fe
->length
= length
;
6887 /* Read the statement program header starting at OFFSET in
6888 .debug_line, according to the endianness of ABFD. Return a pointer
6889 to a struct line_header, allocated using xmalloc.
6891 NOTE: the strings in the include directory and file name tables of
6892 the returned object point into debug_line_buffer, and must not be
6894 static struct line_header
*
6895 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6896 struct dwarf2_cu
*cu
)
6898 struct cleanup
*back_to
;
6899 struct line_header
*lh
;
6901 unsigned int bytes_read
;
6903 char *cur_dir
, *cur_file
;
6905 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6907 complaint (&symfile_complaints
, _("missing .debug_line section"));
6911 /* Make sure that at least there's room for the total_length field.
6912 That could be 12 bytes long, but we're just going to fudge that. */
6913 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6915 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6919 lh
= xmalloc (sizeof (*lh
));
6920 memset (lh
, 0, sizeof (*lh
));
6921 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6924 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6926 /* Read in the header. */
6928 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6929 line_ptr
+= bytes_read
;
6930 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6931 + dwarf2_per_objfile
->line_size
))
6933 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6936 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6937 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6939 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6940 line_ptr
+= bytes_read
;
6941 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6943 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6945 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6947 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6949 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6951 lh
->standard_opcode_lengths
6952 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6954 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6955 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6957 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6961 /* Read directory table. */
6962 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6964 line_ptr
+= bytes_read
;
6965 add_include_dir (lh
, cur_dir
);
6967 line_ptr
+= bytes_read
;
6969 /* Read file name table. */
6970 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6972 unsigned int dir_index
, mod_time
, length
;
6974 line_ptr
+= bytes_read
;
6975 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6976 line_ptr
+= bytes_read
;
6977 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6978 line_ptr
+= bytes_read
;
6979 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6980 line_ptr
+= bytes_read
;
6982 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6984 line_ptr
+= bytes_read
;
6985 lh
->statement_program_start
= line_ptr
;
6987 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6988 + dwarf2_per_objfile
->line_size
))
6989 complaint (&symfile_complaints
,
6990 _("line number info header doesn't fit in `.debug_line' section"));
6992 discard_cleanups (back_to
);
6996 /* This function exists to work around a bug in certain compilers
6997 (particularly GCC 2.95), in which the first line number marker of a
6998 function does not show up until after the prologue, right before
6999 the second line number marker. This function shifts ADDRESS down
7000 to the beginning of the function if necessary, and is called on
7001 addresses passed to record_line. */
7004 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7006 struct function_range
*fn
;
7008 /* Find the function_range containing address. */
7013 cu
->cached_fn
= cu
->first_fn
;
7017 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7023 while (fn
&& fn
!= cu
->cached_fn
)
7024 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7034 if (address
!= fn
->lowpc
)
7035 complaint (&symfile_complaints
,
7036 _("misplaced first line number at 0x%lx for '%s'"),
7037 (unsigned long) address
, fn
->name
);
7042 /* Decode the Line Number Program (LNP) for the given line_header
7043 structure and CU. The actual information extracted and the type
7044 of structures created from the LNP depends on the value of PST.
7046 1. If PST is NULL, then this procedure uses the data from the program
7047 to create all necessary symbol tables, and their linetables.
7048 The compilation directory of the file is passed in COMP_DIR,
7049 and must not be NULL.
7051 2. If PST is not NULL, this procedure reads the program to determine
7052 the list of files included by the unit represented by PST, and
7053 builds all the associated partial symbol tables. In this case,
7054 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7055 is not used to compute the full name of the symtab, and therefore
7056 omitting it when building the partial symtab does not introduce
7057 the potential for inconsistency - a partial symtab and its associated
7058 symbtab having a different fullname -). */
7061 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7062 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7064 gdb_byte
*line_ptr
, *extended_end
;
7066 unsigned int bytes_read
, extended_len
;
7067 unsigned char op_code
, extended_op
, adj_opcode
;
7069 struct objfile
*objfile
= cu
->objfile
;
7070 const int decode_for_pst_p
= (pst
!= NULL
);
7071 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7073 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7075 line_ptr
= lh
->statement_program_start
;
7076 line_end
= lh
->statement_program_end
;
7078 /* Read the statement sequences until there's nothing left. */
7079 while (line_ptr
< line_end
)
7081 /* state machine registers */
7082 CORE_ADDR address
= 0;
7083 unsigned int file
= 1;
7084 unsigned int line
= 1;
7085 unsigned int column
= 0;
7086 int is_stmt
= lh
->default_is_stmt
;
7087 int basic_block
= 0;
7088 int end_sequence
= 0;
7090 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7092 /* Start a subfile for the current file of the state machine. */
7093 /* lh->include_dirs and lh->file_names are 0-based, but the
7094 directory and file name numbers in the statement program
7096 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7100 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7102 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7105 /* Decode the table. */
7106 while (!end_sequence
)
7108 op_code
= read_1_byte (abfd
, line_ptr
);
7111 if (op_code
>= lh
->opcode_base
)
7113 /* Special operand. */
7114 adj_opcode
= op_code
- lh
->opcode_base
;
7115 address
+= (adj_opcode
/ lh
->line_range
)
7116 * lh
->minimum_instruction_length
;
7117 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7118 if (lh
->num_file_names
< file
)
7119 dwarf2_debug_line_missing_file_complaint ();
7122 lh
->file_names
[file
- 1].included_p
= 1;
7123 if (!decode_for_pst_p
)
7125 if (last_subfile
!= current_subfile
)
7128 record_line (last_subfile
, 0, address
);
7129 last_subfile
= current_subfile
;
7131 /* Append row to matrix using current values. */
7132 record_line (current_subfile
, line
,
7133 check_cu_functions (address
, cu
));
7138 else switch (op_code
)
7140 case DW_LNS_extended_op
:
7141 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7142 line_ptr
+= bytes_read
;
7143 extended_end
= line_ptr
+ extended_len
;
7144 extended_op
= read_1_byte (abfd
, line_ptr
);
7146 switch (extended_op
)
7148 case DW_LNE_end_sequence
:
7151 if (lh
->num_file_names
< file
)
7152 dwarf2_debug_line_missing_file_complaint ();
7155 lh
->file_names
[file
- 1].included_p
= 1;
7156 if (!decode_for_pst_p
)
7157 record_line (current_subfile
, 0, address
);
7160 case DW_LNE_set_address
:
7161 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7162 line_ptr
+= bytes_read
;
7163 address
+= baseaddr
;
7165 case DW_LNE_define_file
:
7168 unsigned int dir_index
, mod_time
, length
;
7170 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7171 line_ptr
+= bytes_read
;
7173 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7174 line_ptr
+= bytes_read
;
7176 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7177 line_ptr
+= bytes_read
;
7179 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7180 line_ptr
+= bytes_read
;
7181 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7185 complaint (&symfile_complaints
,
7186 _("mangled .debug_line section"));
7189 /* Make sure that we parsed the extended op correctly. If e.g.
7190 we expected a different address size than the producer used,
7191 we may have read the wrong number of bytes. */
7192 if (line_ptr
!= extended_end
)
7194 complaint (&symfile_complaints
,
7195 _("mangled .debug_line section"));
7200 if (lh
->num_file_names
< file
)
7201 dwarf2_debug_line_missing_file_complaint ();
7204 lh
->file_names
[file
- 1].included_p
= 1;
7205 if (!decode_for_pst_p
)
7207 if (last_subfile
!= current_subfile
)
7210 record_line (last_subfile
, 0, address
);
7211 last_subfile
= current_subfile
;
7213 record_line (current_subfile
, line
,
7214 check_cu_functions (address
, cu
));
7219 case DW_LNS_advance_pc
:
7220 address
+= lh
->minimum_instruction_length
7221 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7222 line_ptr
+= bytes_read
;
7224 case DW_LNS_advance_line
:
7225 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7226 line_ptr
+= bytes_read
;
7228 case DW_LNS_set_file
:
7230 /* The arrays lh->include_dirs and lh->file_names are
7231 0-based, but the directory and file name numbers in
7232 the statement program are 1-based. */
7233 struct file_entry
*fe
;
7236 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7237 line_ptr
+= bytes_read
;
7238 if (lh
->num_file_names
< file
)
7239 dwarf2_debug_line_missing_file_complaint ();
7242 fe
= &lh
->file_names
[file
- 1];
7244 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7245 if (!decode_for_pst_p
)
7247 last_subfile
= current_subfile
;
7248 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7253 case DW_LNS_set_column
:
7254 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7255 line_ptr
+= bytes_read
;
7257 case DW_LNS_negate_stmt
:
7258 is_stmt
= (!is_stmt
);
7260 case DW_LNS_set_basic_block
:
7263 /* Add to the address register of the state machine the
7264 address increment value corresponding to special opcode
7265 255. I.e., this value is scaled by the minimum
7266 instruction length since special opcode 255 would have
7267 scaled the the increment. */
7268 case DW_LNS_const_add_pc
:
7269 address
+= (lh
->minimum_instruction_length
7270 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7272 case DW_LNS_fixed_advance_pc
:
7273 address
+= read_2_bytes (abfd
, line_ptr
);
7278 /* Unknown standard opcode, ignore it. */
7281 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7283 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7284 line_ptr
+= bytes_read
;
7291 if (decode_for_pst_p
)
7295 /* Now that we're done scanning the Line Header Program, we can
7296 create the psymtab of each included file. */
7297 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7298 if (lh
->file_names
[file_index
].included_p
== 1)
7300 const struct file_entry fe
= lh
->file_names
[file_index
];
7301 char *include_name
= fe
.name
;
7302 char *dir_name
= NULL
;
7303 char *pst_filename
= pst
->filename
;
7306 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7308 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7310 include_name
= concat (dir_name
, SLASH_STRING
,
7311 include_name
, (char *)NULL
);
7312 make_cleanup (xfree
, include_name
);
7315 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7317 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7318 pst_filename
, (char *)NULL
);
7319 make_cleanup (xfree
, pst_filename
);
7322 if (strcmp (include_name
, pst_filename
) != 0)
7323 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7328 /* Make sure a symtab is created for every file, even files
7329 which contain only variables (i.e. no code with associated
7333 struct file_entry
*fe
;
7335 for (i
= 0; i
< lh
->num_file_names
; i
++)
7338 fe
= &lh
->file_names
[i
];
7340 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7341 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7343 /* Skip the main file; we don't need it, and it must be
7344 allocated last, so that it will show up before the
7345 non-primary symtabs in the objfile's symtab list. */
7346 if (current_subfile
== first_subfile
)
7349 if (current_subfile
->symtab
== NULL
)
7350 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7352 fe
->symtab
= current_subfile
->symtab
;
7357 /* Start a subfile for DWARF. FILENAME is the name of the file and
7358 DIRNAME the name of the source directory which contains FILENAME
7359 or NULL if not known. COMP_DIR is the compilation directory for the
7360 linetable's compilation unit or NULL if not known.
7361 This routine tries to keep line numbers from identical absolute and
7362 relative file names in a common subfile.
7364 Using the `list' example from the GDB testsuite, which resides in
7365 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7366 of /srcdir/list0.c yields the following debugging information for list0.c:
7368 DW_AT_name: /srcdir/list0.c
7369 DW_AT_comp_dir: /compdir
7370 files.files[0].name: list0.h
7371 files.files[0].dir: /srcdir
7372 files.files[1].name: list0.c
7373 files.files[1].dir: /srcdir
7375 The line number information for list0.c has to end up in a single
7376 subfile, so that `break /srcdir/list0.c:1' works as expected.
7377 start_subfile will ensure that this happens provided that we pass the
7378 concatenation of files.files[1].dir and files.files[1].name as the
7382 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7386 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7387 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7388 second argument to start_subfile. To be consistent, we do the
7389 same here. In order not to lose the line information directory,
7390 we concatenate it to the filename when it makes sense.
7391 Note that the Dwarf3 standard says (speaking of filenames in line
7392 information): ``The directory index is ignored for file names
7393 that represent full path names''. Thus ignoring dirname in the
7394 `else' branch below isn't an issue. */
7396 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7397 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7399 fullname
= filename
;
7401 start_subfile (fullname
, comp_dir
);
7403 if (fullname
!= filename
)
7408 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7409 struct dwarf2_cu
*cu
)
7411 struct objfile
*objfile
= cu
->objfile
;
7412 struct comp_unit_head
*cu_header
= &cu
->header
;
7414 /* NOTE drow/2003-01-30: There used to be a comment and some special
7415 code here to turn a symbol with DW_AT_external and a
7416 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7417 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7418 with some versions of binutils) where shared libraries could have
7419 relocations against symbols in their debug information - the
7420 minimal symbol would have the right address, but the debug info
7421 would not. It's no longer necessary, because we will explicitly
7422 apply relocations when we read in the debug information now. */
7424 /* A DW_AT_location attribute with no contents indicates that a
7425 variable has been optimized away. */
7426 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7428 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7432 /* Handle one degenerate form of location expression specially, to
7433 preserve GDB's previous behavior when section offsets are
7434 specified. If this is just a DW_OP_addr then mark this symbol
7437 if (attr_form_is_block (attr
)
7438 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7439 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7443 SYMBOL_VALUE_ADDRESS (sym
) =
7444 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7445 fixup_symbol_section (sym
, objfile
);
7446 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7447 SYMBOL_SECTION (sym
));
7448 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7452 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7453 expression evaluator, and use LOC_COMPUTED only when necessary
7454 (i.e. when the value of a register or memory location is
7455 referenced, or a thread-local block, etc.). Then again, it might
7456 not be worthwhile. I'm assuming that it isn't unless performance
7457 or memory numbers show me otherwise. */
7459 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7460 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7463 /* Given a pointer to a DWARF information entry, figure out if we need
7464 to make a symbol table entry for it, and if so, create a new entry
7465 and return a pointer to it.
7466 If TYPE is NULL, determine symbol type from the die, otherwise
7467 used the passed type. */
7469 static struct symbol
*
7470 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7472 struct objfile
*objfile
= cu
->objfile
;
7473 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7474 struct symbol
*sym
= NULL
;
7476 struct attribute
*attr
= NULL
;
7477 struct attribute
*attr2
= NULL
;
7480 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7482 if (die
->tag
!= DW_TAG_namespace
)
7483 name
= dwarf2_linkage_name (die
, cu
);
7485 name
= TYPE_NAME (type
);
7489 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7490 sizeof (struct symbol
));
7491 OBJSTAT (objfile
, n_syms
++);
7492 memset (sym
, 0, sizeof (struct symbol
));
7494 /* Cache this symbol's name and the name's demangled form (if any). */
7495 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7496 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7498 /* Default assumptions.
7499 Use the passed type or decode it from the die. */
7500 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7501 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7503 SYMBOL_TYPE (sym
) = type
;
7505 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7506 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7509 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7512 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7515 int file_index
= DW_UNSND (attr
);
7516 if (cu
->line_header
== NULL
7517 || file_index
> cu
->line_header
->num_file_names
)
7518 complaint (&symfile_complaints
,
7519 _("file index out of range"));
7520 else if (file_index
> 0)
7522 struct file_entry
*fe
;
7523 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7524 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7531 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7534 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7536 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7538 case DW_TAG_subprogram
:
7539 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7541 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7542 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7543 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7544 || cu
->language
== language_ada
)
7546 /* Subprograms marked external are stored as a global symbol.
7547 Ada subprograms, whether marked external or not, are always
7548 stored as a global symbol, because we want to be able to
7549 access them globally. For instance, we want to be able
7550 to break on a nested subprogram without having to
7551 specify the context. */
7552 add_symbol_to_list (sym
, &global_symbols
);
7556 add_symbol_to_list (sym
, cu
->list_in_scope
);
7559 case DW_TAG_variable
:
7560 /* Compilation with minimal debug info may result in variables
7561 with missing type entries. Change the misleading `void' type
7562 to something sensible. */
7563 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7565 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7567 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7570 dwarf2_const_value (attr
, sym
, cu
);
7571 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7572 if (attr2
&& (DW_UNSND (attr2
) != 0))
7573 add_symbol_to_list (sym
, &global_symbols
);
7575 add_symbol_to_list (sym
, cu
->list_in_scope
);
7578 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7581 var_decode_location (attr
, sym
, cu
);
7582 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7583 if (attr2
&& (DW_UNSND (attr2
) != 0))
7584 add_symbol_to_list (sym
, &global_symbols
);
7586 add_symbol_to_list (sym
, cu
->list_in_scope
);
7590 /* We do not know the address of this symbol.
7591 If it is an external symbol and we have type information
7592 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7593 The address of the variable will then be determined from
7594 the minimal symbol table whenever the variable is
7596 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7597 if (attr2
&& (DW_UNSND (attr2
) != 0)
7598 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7600 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7601 add_symbol_to_list (sym
, &global_symbols
);
7605 case DW_TAG_formal_parameter
:
7606 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7609 var_decode_location (attr
, sym
, cu
);
7610 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
7611 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
7612 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
7614 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7617 dwarf2_const_value (attr
, sym
, cu
);
7619 add_symbol_to_list (sym
, cu
->list_in_scope
);
7621 case DW_TAG_unspecified_parameters
:
7622 /* From varargs functions; gdb doesn't seem to have any
7623 interest in this information, so just ignore it for now.
7626 case DW_TAG_class_type
:
7627 case DW_TAG_interface_type
:
7628 case DW_TAG_structure_type
:
7629 case DW_TAG_union_type
:
7630 case DW_TAG_set_type
:
7631 case DW_TAG_enumeration_type
:
7632 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7633 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7635 /* Make sure that the symbol includes appropriate enclosing
7636 classes/namespaces in its name. These are calculated in
7637 read_structure_type, and the correct name is saved in
7640 if (cu
->language
== language_cplus
7641 || cu
->language
== language_java
)
7643 struct type
*type
= SYMBOL_TYPE (sym
);
7645 if (TYPE_TAG_NAME (type
) != NULL
)
7647 /* FIXME: carlton/2003-11-10: Should this use
7648 SYMBOL_SET_NAMES instead? (The same problem also
7649 arises further down in this function.) */
7650 /* The type's name is already allocated along with
7651 this objfile, so we don't need to duplicate it
7653 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7658 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7659 really ever be static objects: otherwise, if you try
7660 to, say, break of a class's method and you're in a file
7661 which doesn't mention that class, it won't work unless
7662 the check for all static symbols in lookup_symbol_aux
7663 saves you. See the OtherFileClass tests in
7664 gdb.c++/namespace.exp. */
7666 struct pending
**list_to_add
;
7668 list_to_add
= (cu
->list_in_scope
== &file_symbols
7669 && (cu
->language
== language_cplus
7670 || cu
->language
== language_java
)
7671 ? &global_symbols
: cu
->list_in_scope
);
7673 add_symbol_to_list (sym
, list_to_add
);
7675 /* The semantics of C++ state that "struct foo { ... }" also
7676 defines a typedef for "foo". A Java class declaration also
7677 defines a typedef for the class. Synthesize a typedef symbol
7678 so that "ptype foo" works as expected. */
7679 if (cu
->language
== language_cplus
7680 || cu
->language
== language_java
7681 || cu
->language
== language_ada
)
7683 struct symbol
*typedef_sym
= (struct symbol
*)
7684 obstack_alloc (&objfile
->objfile_obstack
,
7685 sizeof (struct symbol
));
7686 *typedef_sym
= *sym
;
7687 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
7688 /* The symbol's name is already allocated along with
7689 this objfile, so we don't need to duplicate it for
7691 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7692 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7693 add_symbol_to_list (typedef_sym
, list_to_add
);
7697 case DW_TAG_typedef
:
7698 if (processing_has_namespace_info
7699 && processing_current_prefix
[0] != '\0')
7701 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7702 processing_current_prefix
,
7705 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7706 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7707 add_symbol_to_list (sym
, cu
->list_in_scope
);
7709 case DW_TAG_base_type
:
7710 case DW_TAG_subrange_type
:
7711 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7712 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7713 add_symbol_to_list (sym
, cu
->list_in_scope
);
7715 case DW_TAG_enumerator
:
7716 if (processing_has_namespace_info
7717 && processing_current_prefix
[0] != '\0')
7719 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7720 processing_current_prefix
,
7723 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7726 dwarf2_const_value (attr
, sym
, cu
);
7729 /* NOTE: carlton/2003-11-10: See comment above in the
7730 DW_TAG_class_type, etc. block. */
7732 struct pending
**list_to_add
;
7734 list_to_add
= (cu
->list_in_scope
== &file_symbols
7735 && (cu
->language
== language_cplus
7736 || cu
->language
== language_java
)
7737 ? &global_symbols
: cu
->list_in_scope
);
7739 add_symbol_to_list (sym
, list_to_add
);
7742 case DW_TAG_namespace
:
7743 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7744 add_symbol_to_list (sym
, &global_symbols
);
7747 /* Not a tag we recognize. Hopefully we aren't processing
7748 trash data, but since we must specifically ignore things
7749 we don't recognize, there is nothing else we should do at
7751 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7752 dwarf_tag_name (die
->tag
));
7759 /* Copy constant value from an attribute to a symbol. */
7762 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7763 struct dwarf2_cu
*cu
)
7765 struct objfile
*objfile
= cu
->objfile
;
7766 struct comp_unit_head
*cu_header
= &cu
->header
;
7767 struct dwarf_block
*blk
;
7772 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7773 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7774 cu_header
->addr_size
,
7775 TYPE_LENGTH (SYMBOL_TYPE
7777 SYMBOL_VALUE_BYTES (sym
) =
7778 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7779 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7780 it's body - store_unsigned_integer. */
7781 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7783 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7786 /* DW_STRING is already allocated on the obstack, point directly
7788 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7789 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7791 case DW_FORM_block1
:
7792 case DW_FORM_block2
:
7793 case DW_FORM_block4
:
7795 blk
= DW_BLOCK (attr
);
7796 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7797 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7799 TYPE_LENGTH (SYMBOL_TYPE
7801 SYMBOL_VALUE_BYTES (sym
) =
7802 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7803 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7804 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7807 /* The DW_AT_const_value attributes are supposed to carry the
7808 symbol's value "represented as it would be on the target
7809 architecture." By the time we get here, it's already been
7810 converted to host endianness, so we just need to sign- or
7811 zero-extend it as appropriate. */
7813 dwarf2_const_value_data (attr
, sym
, 8);
7816 dwarf2_const_value_data (attr
, sym
, 16);
7819 dwarf2_const_value_data (attr
, sym
, 32);
7822 dwarf2_const_value_data (attr
, sym
, 64);
7826 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7827 SYMBOL_CLASS (sym
) = LOC_CONST
;
7831 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7832 SYMBOL_CLASS (sym
) = LOC_CONST
;
7836 complaint (&symfile_complaints
,
7837 _("unsupported const value attribute form: '%s'"),
7838 dwarf_form_name (attr
->form
));
7839 SYMBOL_VALUE (sym
) = 0;
7840 SYMBOL_CLASS (sym
) = LOC_CONST
;
7846 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7847 or zero-extend it as appropriate for the symbol's type. */
7849 dwarf2_const_value_data (struct attribute
*attr
,
7853 LONGEST l
= DW_UNSND (attr
);
7855 if (bits
< sizeof (l
) * 8)
7857 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7858 l
&= ((LONGEST
) 1 << bits
) - 1;
7860 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7863 SYMBOL_VALUE (sym
) = l
;
7864 SYMBOL_CLASS (sym
) = LOC_CONST
;
7868 /* Return the type of the die in question using its DW_AT_type attribute. */
7870 static struct type
*
7871 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7873 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7875 struct attribute
*type_attr
;
7876 struct die_info
*type_die
;
7878 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7881 /* A missing DW_AT_type represents a void type. */
7882 return builtin_type (gdbarch
)->builtin_void
;
7885 type_die
= follow_die_ref (die
, type_attr
, cu
);
7887 type
= tag_type_to_type (type_die
, cu
);
7890 dump_die (type_die
);
7891 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7897 /* Return the containing type of the die in question using its
7898 DW_AT_containing_type attribute. */
7900 static struct type
*
7901 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7903 struct type
*type
= NULL
;
7904 struct attribute
*type_attr
;
7905 struct die_info
*type_die
= NULL
;
7907 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7910 type_die
= follow_die_ref (die
, type_attr
, cu
);
7911 type
= tag_type_to_type (type_die
, cu
);
7916 dump_die (type_die
);
7917 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7923 static struct type
*
7924 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7932 read_type_die (die
, cu
);
7936 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7944 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7946 char *prefix
= determine_prefix (die
, cu
);
7947 const char *old_prefix
= processing_current_prefix
;
7948 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
7949 processing_current_prefix
= prefix
;
7953 case DW_TAG_class_type
:
7954 case DW_TAG_interface_type
:
7955 case DW_TAG_structure_type
:
7956 case DW_TAG_union_type
:
7957 read_structure_type (die
, cu
);
7959 case DW_TAG_enumeration_type
:
7960 read_enumeration_type (die
, cu
);
7962 case DW_TAG_subprogram
:
7963 case DW_TAG_subroutine_type
:
7964 read_subroutine_type (die
, cu
);
7966 case DW_TAG_array_type
:
7967 read_array_type (die
, cu
);
7969 case DW_TAG_set_type
:
7970 read_set_type (die
, cu
);
7972 case DW_TAG_pointer_type
:
7973 read_tag_pointer_type (die
, cu
);
7975 case DW_TAG_ptr_to_member_type
:
7976 read_tag_ptr_to_member_type (die
, cu
);
7978 case DW_TAG_reference_type
:
7979 read_tag_reference_type (die
, cu
);
7981 case DW_TAG_const_type
:
7982 read_tag_const_type (die
, cu
);
7984 case DW_TAG_volatile_type
:
7985 read_tag_volatile_type (die
, cu
);
7987 case DW_TAG_string_type
:
7988 read_tag_string_type (die
, cu
);
7990 case DW_TAG_typedef
:
7991 read_typedef (die
, cu
);
7993 case DW_TAG_subrange_type
:
7994 read_subrange_type (die
, cu
);
7996 case DW_TAG_base_type
:
7997 read_base_type (die
, cu
);
7999 case DW_TAG_unspecified_type
:
8000 read_unspecified_type (die
, cu
);
8003 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8004 dwarf_tag_name (die
->tag
));
8008 processing_current_prefix
= old_prefix
;
8009 do_cleanups (back_to
);
8012 /* Return the name of the namespace/class that DIE is defined within,
8013 or "" if we can't tell. The caller should xfree the result. */
8015 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
8016 therein) for an example of how to use this function to deal with
8017 DW_AT_specification. */
8020 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8022 struct die_info
*parent
;
8024 if (cu
->language
!= language_cplus
8025 && cu
->language
!= language_java
)
8028 parent
= die
->parent
;
8032 return xstrdup ("");
8036 switch (parent
->tag
) {
8037 case DW_TAG_namespace
:
8039 /* FIXME: carlton/2004-03-05: Should I follow extension dies
8040 before doing this check? */
8041 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
8043 return xstrdup (TYPE_TAG_NAME (parent
->type
));
8048 char *parent_prefix
= determine_prefix (parent
, cu
);
8049 char *retval
= typename_concat (NULL
, parent_prefix
,
8050 namespace_name (parent
, &dummy
,
8053 xfree (parent_prefix
);
8058 case DW_TAG_class_type
:
8059 case DW_TAG_interface_type
:
8060 case DW_TAG_structure_type
:
8062 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
8064 return xstrdup (TYPE_TAG_NAME (parent
->type
));
8068 const char *old_prefix
= processing_current_prefix
;
8069 char *new_prefix
= determine_prefix (parent
, cu
);
8072 processing_current_prefix
= new_prefix
;
8073 retval
= determine_class_name (parent
, cu
);
8074 processing_current_prefix
= old_prefix
;
8081 return determine_prefix (parent
, cu
);
8086 /* Return a newly-allocated string formed by concatenating PREFIX and
8087 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8088 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8089 perform an obconcat, otherwise allocate storage for the result. The CU argument
8090 is used to determine the language and hence, the appropriate separator. */
8092 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8095 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8096 struct dwarf2_cu
*cu
)
8100 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8102 else if (cu
->language
== language_java
)
8109 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8114 strcpy (retval
, prefix
);
8115 strcat (retval
, sep
);
8118 strcat (retval
, suffix
);
8124 /* We have an obstack. */
8125 return obconcat (obs
, prefix
, sep
, suffix
);
8131 copy_die (struct die_info
*old_die
)
8133 struct die_info
*new_die
;
8136 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8137 memset (new_die
, 0, sizeof (struct die_info
));
8139 new_die
->tag
= old_die
->tag
;
8140 new_die
->has_children
= old_die
->has_children
;
8141 new_die
->abbrev
= old_die
->abbrev
;
8142 new_die
->offset
= old_die
->offset
;
8143 new_die
->type
= NULL
;
8145 num_attrs
= old_die
->num_attrs
;
8146 new_die
->num_attrs
= num_attrs
;
8147 new_die
->attrs
= (struct attribute
*)
8148 xmalloc (num_attrs
* sizeof (struct attribute
));
8150 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
8152 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
8153 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
8154 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
8157 new_die
->next
= NULL
;
8162 /* Return sibling of die, NULL if no sibling. */
8164 static struct die_info
*
8165 sibling_die (struct die_info
*die
)
8167 return die
->sibling
;
8170 /* Get linkage name of a die, return NULL if not found. */
8173 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8175 struct attribute
*attr
;
8177 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8178 if (attr
&& DW_STRING (attr
))
8179 return DW_STRING (attr
);
8180 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8181 if (attr
&& DW_STRING (attr
))
8182 return DW_STRING (attr
);
8186 /* Get name of a die, return NULL if not found. */
8189 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8191 struct attribute
*attr
;
8193 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8194 if (attr
&& DW_STRING (attr
))
8195 return DW_STRING (attr
);
8199 /* Return the die that this die in an extension of, or NULL if there
8202 static struct die_info
*
8203 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
8205 struct attribute
*attr
;
8207 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
8211 return follow_die_ref (die
, attr
, cu
);
8214 /* Convert a DIE tag into its string name. */
8217 dwarf_tag_name (unsigned tag
)
8221 case DW_TAG_padding
:
8222 return "DW_TAG_padding";
8223 case DW_TAG_array_type
:
8224 return "DW_TAG_array_type";
8225 case DW_TAG_class_type
:
8226 return "DW_TAG_class_type";
8227 case DW_TAG_entry_point
:
8228 return "DW_TAG_entry_point";
8229 case DW_TAG_enumeration_type
:
8230 return "DW_TAG_enumeration_type";
8231 case DW_TAG_formal_parameter
:
8232 return "DW_TAG_formal_parameter";
8233 case DW_TAG_imported_declaration
:
8234 return "DW_TAG_imported_declaration";
8236 return "DW_TAG_label";
8237 case DW_TAG_lexical_block
:
8238 return "DW_TAG_lexical_block";
8240 return "DW_TAG_member";
8241 case DW_TAG_pointer_type
:
8242 return "DW_TAG_pointer_type";
8243 case DW_TAG_reference_type
:
8244 return "DW_TAG_reference_type";
8245 case DW_TAG_compile_unit
:
8246 return "DW_TAG_compile_unit";
8247 case DW_TAG_string_type
:
8248 return "DW_TAG_string_type";
8249 case DW_TAG_structure_type
:
8250 return "DW_TAG_structure_type";
8251 case DW_TAG_subroutine_type
:
8252 return "DW_TAG_subroutine_type";
8253 case DW_TAG_typedef
:
8254 return "DW_TAG_typedef";
8255 case DW_TAG_union_type
:
8256 return "DW_TAG_union_type";
8257 case DW_TAG_unspecified_parameters
:
8258 return "DW_TAG_unspecified_parameters";
8259 case DW_TAG_variant
:
8260 return "DW_TAG_variant";
8261 case DW_TAG_common_block
:
8262 return "DW_TAG_common_block";
8263 case DW_TAG_common_inclusion
:
8264 return "DW_TAG_common_inclusion";
8265 case DW_TAG_inheritance
:
8266 return "DW_TAG_inheritance";
8267 case DW_TAG_inlined_subroutine
:
8268 return "DW_TAG_inlined_subroutine";
8270 return "DW_TAG_module";
8271 case DW_TAG_ptr_to_member_type
:
8272 return "DW_TAG_ptr_to_member_type";
8273 case DW_TAG_set_type
:
8274 return "DW_TAG_set_type";
8275 case DW_TAG_subrange_type
:
8276 return "DW_TAG_subrange_type";
8277 case DW_TAG_with_stmt
:
8278 return "DW_TAG_with_stmt";
8279 case DW_TAG_access_declaration
:
8280 return "DW_TAG_access_declaration";
8281 case DW_TAG_base_type
:
8282 return "DW_TAG_base_type";
8283 case DW_TAG_catch_block
:
8284 return "DW_TAG_catch_block";
8285 case DW_TAG_const_type
:
8286 return "DW_TAG_const_type";
8287 case DW_TAG_constant
:
8288 return "DW_TAG_constant";
8289 case DW_TAG_enumerator
:
8290 return "DW_TAG_enumerator";
8291 case DW_TAG_file_type
:
8292 return "DW_TAG_file_type";
8294 return "DW_TAG_friend";
8295 case DW_TAG_namelist
:
8296 return "DW_TAG_namelist";
8297 case DW_TAG_namelist_item
:
8298 return "DW_TAG_namelist_item";
8299 case DW_TAG_packed_type
:
8300 return "DW_TAG_packed_type";
8301 case DW_TAG_subprogram
:
8302 return "DW_TAG_subprogram";
8303 case DW_TAG_template_type_param
:
8304 return "DW_TAG_template_type_param";
8305 case DW_TAG_template_value_param
:
8306 return "DW_TAG_template_value_param";
8307 case DW_TAG_thrown_type
:
8308 return "DW_TAG_thrown_type";
8309 case DW_TAG_try_block
:
8310 return "DW_TAG_try_block";
8311 case DW_TAG_variant_part
:
8312 return "DW_TAG_variant_part";
8313 case DW_TAG_variable
:
8314 return "DW_TAG_variable";
8315 case DW_TAG_volatile_type
:
8316 return "DW_TAG_volatile_type";
8317 case DW_TAG_dwarf_procedure
:
8318 return "DW_TAG_dwarf_procedure";
8319 case DW_TAG_restrict_type
:
8320 return "DW_TAG_restrict_type";
8321 case DW_TAG_interface_type
:
8322 return "DW_TAG_interface_type";
8323 case DW_TAG_namespace
:
8324 return "DW_TAG_namespace";
8325 case DW_TAG_imported_module
:
8326 return "DW_TAG_imported_module";
8327 case DW_TAG_unspecified_type
:
8328 return "DW_TAG_unspecified_type";
8329 case DW_TAG_partial_unit
:
8330 return "DW_TAG_partial_unit";
8331 case DW_TAG_imported_unit
:
8332 return "DW_TAG_imported_unit";
8333 case DW_TAG_condition
:
8334 return "DW_TAG_condition";
8335 case DW_TAG_shared_type
:
8336 return "DW_TAG_shared_type";
8337 case DW_TAG_MIPS_loop
:
8338 return "DW_TAG_MIPS_loop";
8339 case DW_TAG_HP_array_descriptor
:
8340 return "DW_TAG_HP_array_descriptor";
8341 case DW_TAG_format_label
:
8342 return "DW_TAG_format_label";
8343 case DW_TAG_function_template
:
8344 return "DW_TAG_function_template";
8345 case DW_TAG_class_template
:
8346 return "DW_TAG_class_template";
8347 case DW_TAG_GNU_BINCL
:
8348 return "DW_TAG_GNU_BINCL";
8349 case DW_TAG_GNU_EINCL
:
8350 return "DW_TAG_GNU_EINCL";
8351 case DW_TAG_upc_shared_type
:
8352 return "DW_TAG_upc_shared_type";
8353 case DW_TAG_upc_strict_type
:
8354 return "DW_TAG_upc_strict_type";
8355 case DW_TAG_upc_relaxed_type
:
8356 return "DW_TAG_upc_relaxed_type";
8357 case DW_TAG_PGI_kanji_type
:
8358 return "DW_TAG_PGI_kanji_type";
8359 case DW_TAG_PGI_interface_block
:
8360 return "DW_TAG_PGI_interface_block";
8362 return "DW_TAG_<unknown>";
8366 /* Convert a DWARF attribute code into its string name. */
8369 dwarf_attr_name (unsigned attr
)
8374 return "DW_AT_sibling";
8375 case DW_AT_location
:
8376 return "DW_AT_location";
8378 return "DW_AT_name";
8379 case DW_AT_ordering
:
8380 return "DW_AT_ordering";
8381 case DW_AT_subscr_data
:
8382 return "DW_AT_subscr_data";
8383 case DW_AT_byte_size
:
8384 return "DW_AT_byte_size";
8385 case DW_AT_bit_offset
:
8386 return "DW_AT_bit_offset";
8387 case DW_AT_bit_size
:
8388 return "DW_AT_bit_size";
8389 case DW_AT_element_list
:
8390 return "DW_AT_element_list";
8391 case DW_AT_stmt_list
:
8392 return "DW_AT_stmt_list";
8394 return "DW_AT_low_pc";
8396 return "DW_AT_high_pc";
8397 case DW_AT_language
:
8398 return "DW_AT_language";
8400 return "DW_AT_member";
8402 return "DW_AT_discr";
8403 case DW_AT_discr_value
:
8404 return "DW_AT_discr_value";
8405 case DW_AT_visibility
:
8406 return "DW_AT_visibility";
8408 return "DW_AT_import";
8409 case DW_AT_string_length
:
8410 return "DW_AT_string_length";
8411 case DW_AT_common_reference
:
8412 return "DW_AT_common_reference";
8413 case DW_AT_comp_dir
:
8414 return "DW_AT_comp_dir";
8415 case DW_AT_const_value
:
8416 return "DW_AT_const_value";
8417 case DW_AT_containing_type
:
8418 return "DW_AT_containing_type";
8419 case DW_AT_default_value
:
8420 return "DW_AT_default_value";
8422 return "DW_AT_inline";
8423 case DW_AT_is_optional
:
8424 return "DW_AT_is_optional";
8425 case DW_AT_lower_bound
:
8426 return "DW_AT_lower_bound";
8427 case DW_AT_producer
:
8428 return "DW_AT_producer";
8429 case DW_AT_prototyped
:
8430 return "DW_AT_prototyped";
8431 case DW_AT_return_addr
:
8432 return "DW_AT_return_addr";
8433 case DW_AT_start_scope
:
8434 return "DW_AT_start_scope";
8435 case DW_AT_bit_stride
:
8436 return "DW_AT_bit_stride";
8437 case DW_AT_upper_bound
:
8438 return "DW_AT_upper_bound";
8439 case DW_AT_abstract_origin
:
8440 return "DW_AT_abstract_origin";
8441 case DW_AT_accessibility
:
8442 return "DW_AT_accessibility";
8443 case DW_AT_address_class
:
8444 return "DW_AT_address_class";
8445 case DW_AT_artificial
:
8446 return "DW_AT_artificial";
8447 case DW_AT_base_types
:
8448 return "DW_AT_base_types";
8449 case DW_AT_calling_convention
:
8450 return "DW_AT_calling_convention";
8452 return "DW_AT_count";
8453 case DW_AT_data_member_location
:
8454 return "DW_AT_data_member_location";
8455 case DW_AT_decl_column
:
8456 return "DW_AT_decl_column";
8457 case DW_AT_decl_file
:
8458 return "DW_AT_decl_file";
8459 case DW_AT_decl_line
:
8460 return "DW_AT_decl_line";
8461 case DW_AT_declaration
:
8462 return "DW_AT_declaration";
8463 case DW_AT_discr_list
:
8464 return "DW_AT_discr_list";
8465 case DW_AT_encoding
:
8466 return "DW_AT_encoding";
8467 case DW_AT_external
:
8468 return "DW_AT_external";
8469 case DW_AT_frame_base
:
8470 return "DW_AT_frame_base";
8472 return "DW_AT_friend";
8473 case DW_AT_identifier_case
:
8474 return "DW_AT_identifier_case";
8475 case DW_AT_macro_info
:
8476 return "DW_AT_macro_info";
8477 case DW_AT_namelist_items
:
8478 return "DW_AT_namelist_items";
8479 case DW_AT_priority
:
8480 return "DW_AT_priority";
8482 return "DW_AT_segment";
8483 case DW_AT_specification
:
8484 return "DW_AT_specification";
8485 case DW_AT_static_link
:
8486 return "DW_AT_static_link";
8488 return "DW_AT_type";
8489 case DW_AT_use_location
:
8490 return "DW_AT_use_location";
8491 case DW_AT_variable_parameter
:
8492 return "DW_AT_variable_parameter";
8493 case DW_AT_virtuality
:
8494 return "DW_AT_virtuality";
8495 case DW_AT_vtable_elem_location
:
8496 return "DW_AT_vtable_elem_location";
8497 /* DWARF 3 values. */
8498 case DW_AT_allocated
:
8499 return "DW_AT_allocated";
8500 case DW_AT_associated
:
8501 return "DW_AT_associated";
8502 case DW_AT_data_location
:
8503 return "DW_AT_data_location";
8504 case DW_AT_byte_stride
:
8505 return "DW_AT_byte_stride";
8506 case DW_AT_entry_pc
:
8507 return "DW_AT_entry_pc";
8508 case DW_AT_use_UTF8
:
8509 return "DW_AT_use_UTF8";
8510 case DW_AT_extension
:
8511 return "DW_AT_extension";
8513 return "DW_AT_ranges";
8514 case DW_AT_trampoline
:
8515 return "DW_AT_trampoline";
8516 case DW_AT_call_column
:
8517 return "DW_AT_call_column";
8518 case DW_AT_call_file
:
8519 return "DW_AT_call_file";
8520 case DW_AT_call_line
:
8521 return "DW_AT_call_line";
8522 case DW_AT_description
:
8523 return "DW_AT_description";
8524 case DW_AT_binary_scale
:
8525 return "DW_AT_binary_scale";
8526 case DW_AT_decimal_scale
:
8527 return "DW_AT_decimal_scale";
8529 return "DW_AT_small";
8530 case DW_AT_decimal_sign
:
8531 return "DW_AT_decimal_sign";
8532 case DW_AT_digit_count
:
8533 return "DW_AT_digit_count";
8534 case DW_AT_picture_string
:
8535 return "DW_AT_picture_string";
8537 return "DW_AT_mutable";
8538 case DW_AT_threads_scaled
:
8539 return "DW_AT_threads_scaled";
8540 case DW_AT_explicit
:
8541 return "DW_AT_explicit";
8542 case DW_AT_object_pointer
:
8543 return "DW_AT_object_pointer";
8544 case DW_AT_endianity
:
8545 return "DW_AT_endianity";
8546 case DW_AT_elemental
:
8547 return "DW_AT_elemental";
8549 return "DW_AT_pure";
8550 case DW_AT_recursive
:
8551 return "DW_AT_recursive";
8553 /* SGI/MIPS extensions. */
8554 case DW_AT_MIPS_fde
:
8555 return "DW_AT_MIPS_fde";
8556 case DW_AT_MIPS_loop_begin
:
8557 return "DW_AT_MIPS_loop_begin";
8558 case DW_AT_MIPS_tail_loop_begin
:
8559 return "DW_AT_MIPS_tail_loop_begin";
8560 case DW_AT_MIPS_epilog_begin
:
8561 return "DW_AT_MIPS_epilog_begin";
8562 case DW_AT_MIPS_loop_unroll_factor
:
8563 return "DW_AT_MIPS_loop_unroll_factor";
8564 case DW_AT_MIPS_software_pipeline_depth
:
8565 return "DW_AT_MIPS_software_pipeline_depth";
8566 case DW_AT_MIPS_linkage_name
:
8567 return "DW_AT_MIPS_linkage_name";
8568 case DW_AT_MIPS_stride
:
8569 return "DW_AT_MIPS_stride";
8570 case DW_AT_MIPS_abstract_name
:
8571 return "DW_AT_MIPS_abstract_name";
8572 case DW_AT_MIPS_clone_origin
:
8573 return "DW_AT_MIPS_clone_origin";
8574 case DW_AT_MIPS_has_inlines
:
8575 return "DW_AT_MIPS_has_inlines";
8577 /* HP extensions. */
8578 case DW_AT_HP_block_index
:
8579 return "DW_AT_HP_block_index";
8580 case DW_AT_HP_unmodifiable
:
8581 return "DW_AT_HP_unmodifiable";
8582 case DW_AT_HP_actuals_stmt_list
:
8583 return "DW_AT_HP_actuals_stmt_list";
8584 case DW_AT_HP_proc_per_section
:
8585 return "DW_AT_HP_proc_per_section";
8586 case DW_AT_HP_raw_data_ptr
:
8587 return "DW_AT_HP_raw_data_ptr";
8588 case DW_AT_HP_pass_by_reference
:
8589 return "DW_AT_HP_pass_by_reference";
8590 case DW_AT_HP_opt_level
:
8591 return "DW_AT_HP_opt_level";
8592 case DW_AT_HP_prof_version_id
:
8593 return "DW_AT_HP_prof_version_id";
8594 case DW_AT_HP_opt_flags
:
8595 return "DW_AT_HP_opt_flags";
8596 case DW_AT_HP_cold_region_low_pc
:
8597 return "DW_AT_HP_cold_region_low_pc";
8598 case DW_AT_HP_cold_region_high_pc
:
8599 return "DW_AT_HP_cold_region_high_pc";
8600 case DW_AT_HP_all_variables_modifiable
:
8601 return "DW_AT_HP_all_variables_modifiable";
8602 case DW_AT_HP_linkage_name
:
8603 return "DW_AT_HP_linkage_name";
8604 case DW_AT_HP_prof_flags
:
8605 return "DW_AT_HP_prof_flags";
8606 /* GNU extensions. */
8607 case DW_AT_sf_names
:
8608 return "DW_AT_sf_names";
8609 case DW_AT_src_info
:
8610 return "DW_AT_src_info";
8611 case DW_AT_mac_info
:
8612 return "DW_AT_mac_info";
8613 case DW_AT_src_coords
:
8614 return "DW_AT_src_coords";
8615 case DW_AT_body_begin
:
8616 return "DW_AT_body_begin";
8617 case DW_AT_body_end
:
8618 return "DW_AT_body_end";
8619 case DW_AT_GNU_vector
:
8620 return "DW_AT_GNU_vector";
8621 /* VMS extensions. */
8622 case DW_AT_VMS_rtnbeg_pd_address
:
8623 return "DW_AT_VMS_rtnbeg_pd_address";
8624 /* UPC extension. */
8625 case DW_AT_upc_threads_scaled
:
8626 return "DW_AT_upc_threads_scaled";
8627 /* PGI (STMicroelectronics) extensions. */
8628 case DW_AT_PGI_lbase
:
8629 return "DW_AT_PGI_lbase";
8630 case DW_AT_PGI_soffset
:
8631 return "DW_AT_PGI_soffset";
8632 case DW_AT_PGI_lstride
:
8633 return "DW_AT_PGI_lstride";
8635 return "DW_AT_<unknown>";
8639 /* Convert a DWARF value form code into its string name. */
8642 dwarf_form_name (unsigned form
)
8647 return "DW_FORM_addr";
8648 case DW_FORM_block2
:
8649 return "DW_FORM_block2";
8650 case DW_FORM_block4
:
8651 return "DW_FORM_block4";
8653 return "DW_FORM_data2";
8655 return "DW_FORM_data4";
8657 return "DW_FORM_data8";
8658 case DW_FORM_string
:
8659 return "DW_FORM_string";
8661 return "DW_FORM_block";
8662 case DW_FORM_block1
:
8663 return "DW_FORM_block1";
8665 return "DW_FORM_data1";
8667 return "DW_FORM_flag";
8669 return "DW_FORM_sdata";
8671 return "DW_FORM_strp";
8673 return "DW_FORM_udata";
8674 case DW_FORM_ref_addr
:
8675 return "DW_FORM_ref_addr";
8677 return "DW_FORM_ref1";
8679 return "DW_FORM_ref2";
8681 return "DW_FORM_ref4";
8683 return "DW_FORM_ref8";
8684 case DW_FORM_ref_udata
:
8685 return "DW_FORM_ref_udata";
8686 case DW_FORM_indirect
:
8687 return "DW_FORM_indirect";
8689 return "DW_FORM_<unknown>";
8693 /* Convert a DWARF stack opcode into its string name. */
8696 dwarf_stack_op_name (unsigned op
)
8701 return "DW_OP_addr";
8703 return "DW_OP_deref";
8705 return "DW_OP_const1u";
8707 return "DW_OP_const1s";
8709 return "DW_OP_const2u";
8711 return "DW_OP_const2s";
8713 return "DW_OP_const4u";
8715 return "DW_OP_const4s";
8717 return "DW_OP_const8u";
8719 return "DW_OP_const8s";
8721 return "DW_OP_constu";
8723 return "DW_OP_consts";
8727 return "DW_OP_drop";
8729 return "DW_OP_over";
8731 return "DW_OP_pick";
8733 return "DW_OP_swap";
8737 return "DW_OP_xderef";
8745 return "DW_OP_minus";
8757 return "DW_OP_plus";
8758 case DW_OP_plus_uconst
:
8759 return "DW_OP_plus_uconst";
8765 return "DW_OP_shra";
8783 return "DW_OP_skip";
8785 return "DW_OP_lit0";
8787 return "DW_OP_lit1";
8789 return "DW_OP_lit2";
8791 return "DW_OP_lit3";
8793 return "DW_OP_lit4";
8795 return "DW_OP_lit5";
8797 return "DW_OP_lit6";
8799 return "DW_OP_lit7";
8801 return "DW_OP_lit8";
8803 return "DW_OP_lit9";
8805 return "DW_OP_lit10";
8807 return "DW_OP_lit11";
8809 return "DW_OP_lit12";
8811 return "DW_OP_lit13";
8813 return "DW_OP_lit14";
8815 return "DW_OP_lit15";
8817 return "DW_OP_lit16";
8819 return "DW_OP_lit17";
8821 return "DW_OP_lit18";
8823 return "DW_OP_lit19";
8825 return "DW_OP_lit20";
8827 return "DW_OP_lit21";
8829 return "DW_OP_lit22";
8831 return "DW_OP_lit23";
8833 return "DW_OP_lit24";
8835 return "DW_OP_lit25";
8837 return "DW_OP_lit26";
8839 return "DW_OP_lit27";
8841 return "DW_OP_lit28";
8843 return "DW_OP_lit29";
8845 return "DW_OP_lit30";
8847 return "DW_OP_lit31";
8849 return "DW_OP_reg0";
8851 return "DW_OP_reg1";
8853 return "DW_OP_reg2";
8855 return "DW_OP_reg3";
8857 return "DW_OP_reg4";
8859 return "DW_OP_reg5";
8861 return "DW_OP_reg6";
8863 return "DW_OP_reg7";
8865 return "DW_OP_reg8";
8867 return "DW_OP_reg9";
8869 return "DW_OP_reg10";
8871 return "DW_OP_reg11";
8873 return "DW_OP_reg12";
8875 return "DW_OP_reg13";
8877 return "DW_OP_reg14";
8879 return "DW_OP_reg15";
8881 return "DW_OP_reg16";
8883 return "DW_OP_reg17";
8885 return "DW_OP_reg18";
8887 return "DW_OP_reg19";
8889 return "DW_OP_reg20";
8891 return "DW_OP_reg21";
8893 return "DW_OP_reg22";
8895 return "DW_OP_reg23";
8897 return "DW_OP_reg24";
8899 return "DW_OP_reg25";
8901 return "DW_OP_reg26";
8903 return "DW_OP_reg27";
8905 return "DW_OP_reg28";
8907 return "DW_OP_reg29";
8909 return "DW_OP_reg30";
8911 return "DW_OP_reg31";
8913 return "DW_OP_breg0";
8915 return "DW_OP_breg1";
8917 return "DW_OP_breg2";
8919 return "DW_OP_breg3";
8921 return "DW_OP_breg4";
8923 return "DW_OP_breg5";
8925 return "DW_OP_breg6";
8927 return "DW_OP_breg7";
8929 return "DW_OP_breg8";
8931 return "DW_OP_breg9";
8933 return "DW_OP_breg10";
8935 return "DW_OP_breg11";
8937 return "DW_OP_breg12";
8939 return "DW_OP_breg13";
8941 return "DW_OP_breg14";
8943 return "DW_OP_breg15";
8945 return "DW_OP_breg16";
8947 return "DW_OP_breg17";
8949 return "DW_OP_breg18";
8951 return "DW_OP_breg19";
8953 return "DW_OP_breg20";
8955 return "DW_OP_breg21";
8957 return "DW_OP_breg22";
8959 return "DW_OP_breg23";
8961 return "DW_OP_breg24";
8963 return "DW_OP_breg25";
8965 return "DW_OP_breg26";
8967 return "DW_OP_breg27";
8969 return "DW_OP_breg28";
8971 return "DW_OP_breg29";
8973 return "DW_OP_breg30";
8975 return "DW_OP_breg31";
8977 return "DW_OP_regx";
8979 return "DW_OP_fbreg";
8981 return "DW_OP_bregx";
8983 return "DW_OP_piece";
8984 case DW_OP_deref_size
:
8985 return "DW_OP_deref_size";
8986 case DW_OP_xderef_size
:
8987 return "DW_OP_xderef_size";
8990 /* DWARF 3 extensions. */
8991 case DW_OP_push_object_address
:
8992 return "DW_OP_push_object_address";
8994 return "DW_OP_call2";
8996 return "DW_OP_call4";
8997 case DW_OP_call_ref
:
8998 return "DW_OP_call_ref";
8999 /* GNU extensions. */
9000 case DW_OP_form_tls_address
:
9001 return "DW_OP_form_tls_address";
9002 case DW_OP_call_frame_cfa
:
9003 return "DW_OP_call_frame_cfa";
9004 case DW_OP_bit_piece
:
9005 return "DW_OP_bit_piece";
9006 case DW_OP_GNU_push_tls_address
:
9007 return "DW_OP_GNU_push_tls_address";
9008 case DW_OP_GNU_uninit
:
9009 return "DW_OP_GNU_uninit";
9010 /* HP extensions. */
9011 case DW_OP_HP_is_value
:
9012 return "DW_OP_HP_is_value";
9013 case DW_OP_HP_fltconst4
:
9014 return "DW_OP_HP_fltconst4";
9015 case DW_OP_HP_fltconst8
:
9016 return "DW_OP_HP_fltconst8";
9017 case DW_OP_HP_mod_range
:
9018 return "DW_OP_HP_mod_range";
9019 case DW_OP_HP_unmod_range
:
9020 return "DW_OP_HP_unmod_range";
9022 return "DW_OP_HP_tls";
9024 return "OP_<unknown>";
9029 dwarf_bool_name (unsigned mybool
)
9037 /* Convert a DWARF type code into its string name. */
9040 dwarf_type_encoding_name (unsigned enc
)
9045 return "DW_ATE_void";
9046 case DW_ATE_address
:
9047 return "DW_ATE_address";
9048 case DW_ATE_boolean
:
9049 return "DW_ATE_boolean";
9050 case DW_ATE_complex_float
:
9051 return "DW_ATE_complex_float";
9053 return "DW_ATE_float";
9055 return "DW_ATE_signed";
9056 case DW_ATE_signed_char
:
9057 return "DW_ATE_signed_char";
9058 case DW_ATE_unsigned
:
9059 return "DW_ATE_unsigned";
9060 case DW_ATE_unsigned_char
:
9061 return "DW_ATE_unsigned_char";
9063 case DW_ATE_imaginary_float
:
9064 return "DW_ATE_imaginary_float";
9065 case DW_ATE_packed_decimal
:
9066 return "DW_ATE_packed_decimal";
9067 case DW_ATE_numeric_string
:
9068 return "DW_ATE_numeric_string";
9070 return "DW_ATE_edited";
9071 case DW_ATE_signed_fixed
:
9072 return "DW_ATE_signed_fixed";
9073 case DW_ATE_unsigned_fixed
:
9074 return "DW_ATE_unsigned_fixed";
9075 case DW_ATE_decimal_float
:
9076 return "DW_ATE_decimal_float";
9077 /* HP extensions. */
9078 case DW_ATE_HP_float80
:
9079 return "DW_ATE_HP_float80";
9080 case DW_ATE_HP_complex_float80
:
9081 return "DW_ATE_HP_complex_float80";
9082 case DW_ATE_HP_float128
:
9083 return "DW_ATE_HP_float128";
9084 case DW_ATE_HP_complex_float128
:
9085 return "DW_ATE_HP_complex_float128";
9086 case DW_ATE_HP_floathpintel
:
9087 return "DW_ATE_HP_floathpintel";
9088 case DW_ATE_HP_imaginary_float80
:
9089 return "DW_ATE_HP_imaginary_float80";
9090 case DW_ATE_HP_imaginary_float128
:
9091 return "DW_ATE_HP_imaginary_float128";
9093 return "DW_ATE_<unknown>";
9097 /* Convert a DWARF call frame info operation to its string name. */
9101 dwarf_cfi_name (unsigned cfi_opc
)
9105 case DW_CFA_advance_loc
:
9106 return "DW_CFA_advance_loc";
9108 return "DW_CFA_offset";
9109 case DW_CFA_restore
:
9110 return "DW_CFA_restore";
9112 return "DW_CFA_nop";
9113 case DW_CFA_set_loc
:
9114 return "DW_CFA_set_loc";
9115 case DW_CFA_advance_loc1
:
9116 return "DW_CFA_advance_loc1";
9117 case DW_CFA_advance_loc2
:
9118 return "DW_CFA_advance_loc2";
9119 case DW_CFA_advance_loc4
:
9120 return "DW_CFA_advance_loc4";
9121 case DW_CFA_offset_extended
:
9122 return "DW_CFA_offset_extended";
9123 case DW_CFA_restore_extended
:
9124 return "DW_CFA_restore_extended";
9125 case DW_CFA_undefined
:
9126 return "DW_CFA_undefined";
9127 case DW_CFA_same_value
:
9128 return "DW_CFA_same_value";
9129 case DW_CFA_register
:
9130 return "DW_CFA_register";
9131 case DW_CFA_remember_state
:
9132 return "DW_CFA_remember_state";
9133 case DW_CFA_restore_state
:
9134 return "DW_CFA_restore_state";
9135 case DW_CFA_def_cfa
:
9136 return "DW_CFA_def_cfa";
9137 case DW_CFA_def_cfa_register
:
9138 return "DW_CFA_def_cfa_register";
9139 case DW_CFA_def_cfa_offset
:
9140 return "DW_CFA_def_cfa_offset";
9142 case DW_CFA_def_cfa_expression
:
9143 return "DW_CFA_def_cfa_expression";
9144 case DW_CFA_expression
:
9145 return "DW_CFA_expression";
9146 case DW_CFA_offset_extended_sf
:
9147 return "DW_CFA_offset_extended_sf";
9148 case DW_CFA_def_cfa_sf
:
9149 return "DW_CFA_def_cfa_sf";
9150 case DW_CFA_def_cfa_offset_sf
:
9151 return "DW_CFA_def_cfa_offset_sf";
9152 case DW_CFA_val_offset
:
9153 return "DW_CFA_val_offset";
9154 case DW_CFA_val_offset_sf
:
9155 return "DW_CFA_val_offset_sf";
9156 case DW_CFA_val_expression
:
9157 return "DW_CFA_val_expression";
9158 /* SGI/MIPS specific. */
9159 case DW_CFA_MIPS_advance_loc8
:
9160 return "DW_CFA_MIPS_advance_loc8";
9161 /* GNU extensions. */
9162 case DW_CFA_GNU_window_save
:
9163 return "DW_CFA_GNU_window_save";
9164 case DW_CFA_GNU_args_size
:
9165 return "DW_CFA_GNU_args_size";
9166 case DW_CFA_GNU_negative_offset_extended
:
9167 return "DW_CFA_GNU_negative_offset_extended";
9169 return "DW_CFA_<unknown>";
9175 dump_die (struct die_info
*die
)
9179 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9180 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9181 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9182 dwarf_bool_name (die
->child
!= NULL
));
9184 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9185 for (i
= 0; i
< die
->num_attrs
; ++i
)
9187 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9188 dwarf_attr_name (die
->attrs
[i
].name
),
9189 dwarf_form_name (die
->attrs
[i
].form
));
9190 switch (die
->attrs
[i
].form
)
9192 case DW_FORM_ref_addr
:
9194 fprintf_unfiltered (gdb_stderr
, "address: ");
9195 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9197 case DW_FORM_block2
:
9198 case DW_FORM_block4
:
9200 case DW_FORM_block1
:
9201 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9206 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9207 (long) (DW_ADDR (&die
->attrs
[i
])));
9215 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9217 case DW_FORM_string
:
9219 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9220 DW_STRING (&die
->attrs
[i
])
9221 ? DW_STRING (&die
->attrs
[i
]) : "");
9224 if (DW_UNSND (&die
->attrs
[i
]))
9225 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9227 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9229 case DW_FORM_indirect
:
9230 /* the reader will have reduced the indirect form to
9231 the "base form" so this form should not occur */
9232 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9235 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9236 die
->attrs
[i
].form
);
9238 fprintf_unfiltered (gdb_stderr
, "\n");
9243 dump_die_list (struct die_info
*die
)
9248 if (die
->child
!= NULL
)
9249 dump_die_list (die
->child
);
9250 if (die
->sibling
!= NULL
)
9251 dump_die_list (die
->sibling
);
9256 store_in_ref_table (unsigned int offset
, struct die_info
*die
,
9257 struct dwarf2_cu
*cu
)
9260 struct die_info
*old
;
9262 h
= (offset
% REF_HASH_SIZE
);
9263 old
= cu
->die_ref_table
[h
];
9264 die
->next_ref
= old
;
9265 cu
->die_ref_table
[h
] = die
;
9269 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9271 unsigned int result
= 0;
9275 case DW_FORM_ref_addr
:
9280 case DW_FORM_ref_udata
:
9281 result
= DW_ADDR (attr
);
9284 complaint (&symfile_complaints
,
9285 _("unsupported die ref attribute form: '%s'"),
9286 dwarf_form_name (attr
->form
));
9291 /* Return the constant value held by the given attribute. Return -1
9292 if the value held by the attribute is not constant. */
9295 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9297 if (attr
->form
== DW_FORM_sdata
)
9298 return DW_SND (attr
);
9299 else if (attr
->form
== DW_FORM_udata
9300 || attr
->form
== DW_FORM_data1
9301 || attr
->form
== DW_FORM_data2
9302 || attr
->form
== DW_FORM_data4
9303 || attr
->form
== DW_FORM_data8
)
9304 return DW_UNSND (attr
);
9307 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9308 dwarf_form_name (attr
->form
));
9309 return default_value
;
9313 static struct die_info
*
9314 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9315 struct dwarf2_cu
*cu
)
9317 struct die_info
*die
;
9318 unsigned int offset
;
9320 struct die_info temp_die
;
9321 struct dwarf2_cu
*target_cu
;
9323 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9325 if (DW_ADDR (attr
) < cu
->header
.offset
9326 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
9328 struct dwarf2_per_cu_data
*per_cu
;
9329 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
9331 target_cu
= per_cu
->cu
;
9336 h
= (offset
% REF_HASH_SIZE
);
9337 die
= target_cu
->die_ref_table
[h
];
9340 if (die
->offset
== offset
)
9342 die
= die
->next_ref
;
9345 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9346 "at 0x%lx [in module %s]"),
9347 (long) src_die
->offset
, (long) offset
, cu
->objfile
->name
);
9352 /* Decode simple location descriptions.
9353 Given a pointer to a dwarf block that defines a location, compute
9354 the location and return the value.
9356 NOTE drow/2003-11-18: This function is called in two situations
9357 now: for the address of static or global variables (partial symbols
9358 only) and for offsets into structures which are expected to be
9359 (more or less) constant. The partial symbol case should go away,
9360 and only the constant case should remain. That will let this
9361 function complain more accurately. A few special modes are allowed
9362 without complaint for global variables (for instance, global
9363 register values and thread-local values).
9365 A location description containing no operations indicates that the
9366 object is optimized out. The return value is 0 for that case.
9367 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9368 callers will only want a very basic result and this can become a
9371 Note that stack[0] is unused except as a default error return.
9372 Note that stack overflow is not yet handled. */
9375 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9377 struct objfile
*objfile
= cu
->objfile
;
9378 struct comp_unit_head
*cu_header
= &cu
->header
;
9380 int size
= blk
->size
;
9381 gdb_byte
*data
= blk
->data
;
9382 CORE_ADDR stack
[64];
9384 unsigned int bytes_read
, unsnd
;
9428 stack
[++stacki
] = op
- DW_OP_lit0
;
9463 stack
[++stacki
] = op
- DW_OP_reg0
;
9465 dwarf2_complex_location_expr_complaint ();
9469 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9471 stack
[++stacki
] = unsnd
;
9473 dwarf2_complex_location_expr_complaint ();
9477 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9483 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9488 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9493 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9498 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9503 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9508 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9513 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9519 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9524 stack
[stacki
+ 1] = stack
[stacki
];
9529 stack
[stacki
- 1] += stack
[stacki
];
9533 case DW_OP_plus_uconst
:
9534 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9539 stack
[stacki
- 1] -= stack
[stacki
];
9544 /* If we're not the last op, then we definitely can't encode
9545 this using GDB's address_class enum. This is valid for partial
9546 global symbols, although the variable's address will be bogus
9549 dwarf2_complex_location_expr_complaint ();
9552 case DW_OP_GNU_push_tls_address
:
9553 /* The top of the stack has the offset from the beginning
9554 of the thread control block at which the variable is located. */
9555 /* Nothing should follow this operator, so the top of stack would
9557 /* This is valid for partial global symbols, but the variable's
9558 address will be bogus in the psymtab. */
9560 dwarf2_complex_location_expr_complaint ();
9563 case DW_OP_GNU_uninit
:
9567 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9568 dwarf_stack_op_name (op
));
9569 return (stack
[stacki
]);
9572 return (stack
[stacki
]);
9575 /* memory allocation interface */
9577 static struct dwarf_block
*
9578 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9580 struct dwarf_block
*blk
;
9582 blk
= (struct dwarf_block
*)
9583 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9587 static struct abbrev_info
*
9588 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9590 struct abbrev_info
*abbrev
;
9592 abbrev
= (struct abbrev_info
*)
9593 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9594 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9598 static struct die_info
*
9599 dwarf_alloc_die (void)
9601 struct die_info
*die
;
9603 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
9604 memset (die
, 0, sizeof (struct die_info
));
9609 /* Macro support. */
9612 /* Return the full name of file number I in *LH's file name table.
9613 Use COMP_DIR as the name of the current directory of the
9614 compilation. The result is allocated using xmalloc; the caller is
9615 responsible for freeing it. */
9617 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9619 /* Is the file number a valid index into the line header's file name
9620 table? Remember that file numbers start with one, not zero. */
9621 if (1 <= file
&& file
<= lh
->num_file_names
)
9623 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9625 if (IS_ABSOLUTE_PATH (fe
->name
))
9626 return xstrdup (fe
->name
);
9634 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9640 dir_len
= strlen (dir
);
9641 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9642 strcpy (full_name
, dir
);
9643 full_name
[dir_len
] = '/';
9644 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9648 return xstrdup (fe
->name
);
9653 /* The compiler produced a bogus file number. We can at least
9654 record the macro definitions made in the file, even if we
9655 won't be able to find the file by name. */
9657 sprintf (fake_name
, "<bad macro file number %d>", file
);
9659 complaint (&symfile_complaints
,
9660 _("bad file number in macro information (%d)"),
9663 return xstrdup (fake_name
);
9668 static struct macro_source_file
*
9669 macro_start_file (int file
, int line
,
9670 struct macro_source_file
*current_file
,
9671 const char *comp_dir
,
9672 struct line_header
*lh
, struct objfile
*objfile
)
9674 /* The full name of this source file. */
9675 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9677 /* We don't create a macro table for this compilation unit
9678 at all until we actually get a filename. */
9679 if (! pending_macros
)
9680 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9681 objfile
->macro_cache
);
9684 /* If we have no current file, then this must be the start_file
9685 directive for the compilation unit's main source file. */
9686 current_file
= macro_set_main (pending_macros
, full_name
);
9688 current_file
= macro_include (current_file
, line
, full_name
);
9692 return current_file
;
9696 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9697 followed by a null byte. */
9699 copy_string (const char *buf
, int len
)
9701 char *s
= xmalloc (len
+ 1);
9702 memcpy (s
, buf
, len
);
9710 consume_improper_spaces (const char *p
, const char *body
)
9714 complaint (&symfile_complaints
,
9715 _("macro definition contains spaces in formal argument list:\n`%s'"),
9727 parse_macro_definition (struct macro_source_file
*file
, int line
,
9732 /* The body string takes one of two forms. For object-like macro
9733 definitions, it should be:
9735 <macro name> " " <definition>
9737 For function-like macro definitions, it should be:
9739 <macro name> "() " <definition>
9741 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9743 Spaces may appear only where explicitly indicated, and in the
9746 The Dwarf 2 spec says that an object-like macro's name is always
9747 followed by a space, but versions of GCC around March 2002 omit
9748 the space when the macro's definition is the empty string.
9750 The Dwarf 2 spec says that there should be no spaces between the
9751 formal arguments in a function-like macro's formal argument list,
9752 but versions of GCC around March 2002 include spaces after the
9756 /* Find the extent of the macro name. The macro name is terminated
9757 by either a space or null character (for an object-like macro) or
9758 an opening paren (for a function-like macro). */
9759 for (p
= body
; *p
; p
++)
9760 if (*p
== ' ' || *p
== '(')
9763 if (*p
== ' ' || *p
== '\0')
9765 /* It's an object-like macro. */
9766 int name_len
= p
- body
;
9767 char *name
= copy_string (body
, name_len
);
9768 const char *replacement
;
9771 replacement
= body
+ name_len
+ 1;
9774 dwarf2_macro_malformed_definition_complaint (body
);
9775 replacement
= body
+ name_len
;
9778 macro_define_object (file
, line
, name
, replacement
);
9784 /* It's a function-like macro. */
9785 char *name
= copy_string (body
, p
- body
);
9788 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9792 p
= consume_improper_spaces (p
, body
);
9794 /* Parse the formal argument list. */
9795 while (*p
&& *p
!= ')')
9797 /* Find the extent of the current argument name. */
9798 const char *arg_start
= p
;
9800 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9803 if (! *p
|| p
== arg_start
)
9804 dwarf2_macro_malformed_definition_complaint (body
);
9807 /* Make sure argv has room for the new argument. */
9808 if (argc
>= argv_size
)
9811 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9814 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9817 p
= consume_improper_spaces (p
, body
);
9819 /* Consume the comma, if present. */
9824 p
= consume_improper_spaces (p
, body
);
9833 /* Perfectly formed definition, no complaints. */
9834 macro_define_function (file
, line
, name
,
9835 argc
, (const char **) argv
,
9837 else if (*p
== '\0')
9839 /* Complain, but do define it. */
9840 dwarf2_macro_malformed_definition_complaint (body
);
9841 macro_define_function (file
, line
, name
,
9842 argc
, (const char **) argv
,
9846 /* Just complain. */
9847 dwarf2_macro_malformed_definition_complaint (body
);
9850 /* Just complain. */
9851 dwarf2_macro_malformed_definition_complaint (body
);
9857 for (i
= 0; i
< argc
; i
++)
9863 dwarf2_macro_malformed_definition_complaint (body
);
9868 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9869 char *comp_dir
, bfd
*abfd
,
9870 struct dwarf2_cu
*cu
)
9872 gdb_byte
*mac_ptr
, *mac_end
;
9873 struct macro_source_file
*current_file
= 0;
9875 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9877 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9881 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9882 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9883 + dwarf2_per_objfile
->macinfo_size
;
9887 enum dwarf_macinfo_record_type macinfo_type
;
9889 /* Do we at least have room for a macinfo type byte? */
9890 if (mac_ptr
>= mac_end
)
9892 dwarf2_macros_too_long_complaint ();
9896 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9899 switch (macinfo_type
)
9901 /* A zero macinfo type indicates the end of the macro
9906 case DW_MACINFO_define
:
9907 case DW_MACINFO_undef
:
9909 unsigned int bytes_read
;
9913 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9914 mac_ptr
+= bytes_read
;
9915 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9916 mac_ptr
+= bytes_read
;
9919 complaint (&symfile_complaints
,
9920 _("debug info gives macro %s outside of any file: %s"),
9922 DW_MACINFO_define
? "definition" : macinfo_type
==
9923 DW_MACINFO_undef
? "undefinition" :
9924 "something-or-other", body
);
9927 if (macinfo_type
== DW_MACINFO_define
)
9928 parse_macro_definition (current_file
, line
, body
);
9929 else if (macinfo_type
== DW_MACINFO_undef
)
9930 macro_undef (current_file
, line
, body
);
9935 case DW_MACINFO_start_file
:
9937 unsigned int bytes_read
;
9940 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9941 mac_ptr
+= bytes_read
;
9942 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9943 mac_ptr
+= bytes_read
;
9945 current_file
= macro_start_file (file
, line
,
9946 current_file
, comp_dir
,
9951 case DW_MACINFO_end_file
:
9953 complaint (&symfile_complaints
,
9954 _("macro debug info has an unmatched `close_file' directive"));
9957 current_file
= current_file
->included_by
;
9960 enum dwarf_macinfo_record_type next_type
;
9962 /* GCC circa March 2002 doesn't produce the zero
9963 type byte marking the end of the compilation
9964 unit. Complain if it's not there, but exit no
9967 /* Do we at least have room for a macinfo type byte? */
9968 if (mac_ptr
>= mac_end
)
9970 dwarf2_macros_too_long_complaint ();
9974 /* We don't increment mac_ptr here, so this is just
9976 next_type
= read_1_byte (abfd
, mac_ptr
);
9978 complaint (&symfile_complaints
,
9979 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9986 case DW_MACINFO_vendor_ext
:
9988 unsigned int bytes_read
;
9992 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9993 mac_ptr
+= bytes_read
;
9994 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9995 mac_ptr
+= bytes_read
;
9997 /* We don't recognize any vendor extensions. */
10004 /* Check if the attribute's form is a DW_FORM_block*
10005 if so return true else false. */
10007 attr_form_is_block (struct attribute
*attr
)
10009 return (attr
== NULL
? 0 :
10010 attr
->form
== DW_FORM_block1
10011 || attr
->form
== DW_FORM_block2
10012 || attr
->form
== DW_FORM_block4
10013 || attr
->form
== DW_FORM_block
);
10016 /* Return non-zero if ATTR's value is a section offset --- classes
10017 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10018 You may use DW_UNSND (attr) to retrieve such offsets.
10020 Section 7.5.4, "Attribute Encodings", explains that no attribute
10021 may have a value that belongs to more than one of these classes; it
10022 would be ambiguous if we did, because we use the same forms for all
10025 attr_form_is_section_offset (struct attribute
*attr
)
10027 return (attr
->form
== DW_FORM_data4
10028 || attr
->form
== DW_FORM_data8
);
10032 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10033 zero otherwise. When this function returns true, you can apply
10034 dwarf2_get_attr_constant_value to it.
10036 However, note that for some attributes you must check
10037 attr_form_is_section_offset before using this test. DW_FORM_data4
10038 and DW_FORM_data8 are members of both the constant class, and of
10039 the classes that contain offsets into other debug sections
10040 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10041 that, if an attribute's can be either a constant or one of the
10042 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10043 taken as section offsets, not constants. */
10045 attr_form_is_constant (struct attribute
*attr
)
10047 switch (attr
->form
)
10049 case DW_FORM_sdata
:
10050 case DW_FORM_udata
:
10051 case DW_FORM_data1
:
10052 case DW_FORM_data2
:
10053 case DW_FORM_data4
:
10054 case DW_FORM_data8
:
10062 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10063 struct dwarf2_cu
*cu
)
10065 if (attr_form_is_section_offset (attr
)
10066 /* ".debug_loc" may not exist at all, or the offset may be outside
10067 the section. If so, fall through to the complaint in the
10069 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
10071 struct dwarf2_loclist_baton
*baton
;
10073 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10074 sizeof (struct dwarf2_loclist_baton
));
10075 baton
->per_cu
= cu
->per_cu
;
10076 gdb_assert (baton
->per_cu
);
10078 /* We don't know how long the location list is, but make sure we
10079 don't run off the edge of the section. */
10080 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10081 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10082 baton
->base_address
= cu
->header
.base_address
;
10083 if (cu
->header
.base_known
== 0)
10084 complaint (&symfile_complaints
,
10085 _("Location list used without specifying the CU base address."));
10087 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10088 SYMBOL_LOCATION_BATON (sym
) = baton
;
10092 struct dwarf2_locexpr_baton
*baton
;
10094 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10095 sizeof (struct dwarf2_locexpr_baton
));
10096 baton
->per_cu
= cu
->per_cu
;
10097 gdb_assert (baton
->per_cu
);
10099 if (attr_form_is_block (attr
))
10101 /* Note that we're just copying the block's data pointer
10102 here, not the actual data. We're still pointing into the
10103 info_buffer for SYM's objfile; right now we never release
10104 that buffer, but when we do clean up properly this may
10106 baton
->size
= DW_BLOCK (attr
)->size
;
10107 baton
->data
= DW_BLOCK (attr
)->data
;
10111 dwarf2_invalid_attrib_class_complaint ("location description",
10112 SYMBOL_NATURAL_NAME (sym
));
10114 baton
->data
= NULL
;
10117 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10118 SYMBOL_LOCATION_BATON (sym
) = baton
;
10122 /* Return the OBJFILE associated with the compilation unit CU. */
10125 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10127 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10129 /* Return the master objfile, so that we can report and look up the
10130 correct file containing this variable. */
10131 if (objfile
->separate_debug_objfile_backlink
)
10132 objfile
= objfile
->separate_debug_objfile_backlink
;
10137 /* Return the address size given in the compilation unit header for CU. */
10140 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10143 return per_cu
->cu
->header
.addr_size
;
10146 /* If the CU is not currently read in, we re-read its header. */
10147 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10148 struct dwarf2_per_objfile
*per_objfile
10149 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10150 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10152 struct comp_unit_head cu_header
;
10153 memset (&cu_header
, 0, sizeof cu_header
);
10154 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10155 return cu_header
.addr_size
;
10159 /* Locate the compilation unit from CU's objfile which contains the
10160 DIE at OFFSET. Raises an error on failure. */
10162 static struct dwarf2_per_cu_data
*
10163 dwarf2_find_containing_comp_unit (unsigned long offset
,
10164 struct objfile
*objfile
)
10166 struct dwarf2_per_cu_data
*this_cu
;
10170 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10173 int mid
= low
+ (high
- low
) / 2;
10174 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10179 gdb_assert (low
== high
);
10180 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10183 error (_("Dwarf Error: could not find partial DIE containing "
10184 "offset 0x%lx [in module %s]"),
10185 (long) offset
, bfd_get_filename (objfile
->obfd
));
10187 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10188 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10192 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10193 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10194 && offset
>= this_cu
->offset
+ this_cu
->length
)
10195 error (_("invalid dwarf2 offset %ld"), offset
);
10196 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10201 /* Locate the compilation unit from OBJFILE which is located at exactly
10202 OFFSET. Raises an error on failure. */
10204 static struct dwarf2_per_cu_data
*
10205 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10207 struct dwarf2_per_cu_data
*this_cu
;
10208 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10209 if (this_cu
->offset
!= offset
)
10210 error (_("no compilation unit with offset %ld."), offset
);
10214 /* Release one cached compilation unit, CU. We unlink it from the tree
10215 of compilation units, but we don't remove it from the read_in_chain;
10216 the caller is responsible for that. */
10219 free_one_comp_unit (void *data
)
10221 struct dwarf2_cu
*cu
= data
;
10223 if (cu
->per_cu
!= NULL
)
10224 cu
->per_cu
->cu
= NULL
;
10227 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10229 free_die_list (cu
->dies
);
10234 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10235 when we're finished with it. We can't free the pointer itself, but be
10236 sure to unlink it from the cache. Also release any associated storage
10237 and perform cache maintenance.
10239 Only used during partial symbol parsing. */
10242 free_stack_comp_unit (void *data
)
10244 struct dwarf2_cu
*cu
= data
;
10246 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10247 cu
->partial_dies
= NULL
;
10249 if (cu
->per_cu
!= NULL
)
10251 /* This compilation unit is on the stack in our caller, so we
10252 should not xfree it. Just unlink it. */
10253 cu
->per_cu
->cu
= NULL
;
10256 /* If we had a per-cu pointer, then we may have other compilation
10257 units loaded, so age them now. */
10258 age_cached_comp_units ();
10262 /* Free all cached compilation units. */
10265 free_cached_comp_units (void *data
)
10267 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10269 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10270 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10271 while (per_cu
!= NULL
)
10273 struct dwarf2_per_cu_data
*next_cu
;
10275 next_cu
= per_cu
->cu
->read_in_chain
;
10277 free_one_comp_unit (per_cu
->cu
);
10278 *last_chain
= next_cu
;
10284 /* Increase the age counter on each cached compilation unit, and free
10285 any that are too old. */
10288 age_cached_comp_units (void)
10290 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10292 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10293 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10294 while (per_cu
!= NULL
)
10296 per_cu
->cu
->last_used
++;
10297 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10298 dwarf2_mark (per_cu
->cu
);
10299 per_cu
= per_cu
->cu
->read_in_chain
;
10302 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10303 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10304 while (per_cu
!= NULL
)
10306 struct dwarf2_per_cu_data
*next_cu
;
10308 next_cu
= per_cu
->cu
->read_in_chain
;
10310 if (!per_cu
->cu
->mark
)
10312 free_one_comp_unit (per_cu
->cu
);
10313 *last_chain
= next_cu
;
10316 last_chain
= &per_cu
->cu
->read_in_chain
;
10322 /* Remove a single compilation unit from the cache. */
10325 free_one_cached_comp_unit (void *target_cu
)
10327 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10329 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10330 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10331 while (per_cu
!= NULL
)
10333 struct dwarf2_per_cu_data
*next_cu
;
10335 next_cu
= per_cu
->cu
->read_in_chain
;
10337 if (per_cu
->cu
== target_cu
)
10339 free_one_comp_unit (per_cu
->cu
);
10340 *last_chain
= next_cu
;
10344 last_chain
= &per_cu
->cu
->read_in_chain
;
10350 /* Release all extra memory associated with OBJFILE. */
10353 dwarf2_free_objfile (struct objfile
*objfile
)
10355 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10357 if (dwarf2_per_objfile
== NULL
)
10360 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10361 free_cached_comp_units (NULL
);
10363 /* Everything else should be on the objfile obstack. */
10366 /* A pair of DIE offset and GDB type pointer. We store these
10367 in a hash table separate from the DIEs, and preserve them
10368 when the DIEs are flushed out of cache. */
10370 struct dwarf2_offset_and_type
10372 unsigned int offset
;
10376 /* Hash function for a dwarf2_offset_and_type. */
10379 offset_and_type_hash (const void *item
)
10381 const struct dwarf2_offset_and_type
*ofs
= item
;
10382 return ofs
->offset
;
10385 /* Equality function for a dwarf2_offset_and_type. */
10388 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10390 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10391 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10392 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10395 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10396 table if necessary. */
10399 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10401 struct dwarf2_offset_and_type
**slot
, ofs
;
10405 if (cu
->per_cu
== NULL
)
10408 if (cu
->per_cu
->type_hash
== NULL
)
10409 cu
->per_cu
->type_hash
10410 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10411 offset_and_type_hash
,
10412 offset_and_type_eq
,
10414 &cu
->objfile
->objfile_obstack
,
10415 hashtab_obstack_allocate
,
10416 dummy_obstack_deallocate
);
10418 ofs
.offset
= die
->offset
;
10420 slot
= (struct dwarf2_offset_and_type
**)
10421 htab_find_slot_with_hash (cu
->per_cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10422 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10426 /* Find the type for DIE in TYPE_HASH, or return NULL if DIE does not
10427 have a saved type. */
10429 static struct type
*
10430 get_die_type (struct die_info
*die
, htab_t type_hash
)
10432 struct dwarf2_offset_and_type
*slot
, ofs
;
10434 ofs
.offset
= die
->offset
;
10435 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10442 /* Restore the types of the DIE tree starting at START_DIE from the hash
10443 table saved in CU. */
10446 reset_die_and_siblings_types (struct die_info
*start_die
, struct dwarf2_cu
*cu
)
10448 struct die_info
*die
;
10450 if (cu
->per_cu
->type_hash
== NULL
)
10453 for (die
= start_die
; die
!= NULL
; die
= die
->sibling
)
10455 die
->type
= get_die_type (die
, cu
->per_cu
->type_hash
);
10456 if (die
->child
!= NULL
)
10457 reset_die_and_siblings_types (die
->child
, cu
);
10461 /* Set the mark field in CU and in every other compilation unit in the
10462 cache that we must keep because we are keeping CU. */
10464 /* Add a dependence relationship from CU to REF_PER_CU. */
10467 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10468 struct dwarf2_per_cu_data
*ref_per_cu
)
10472 if (cu
->dependencies
== NULL
)
10474 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10475 NULL
, &cu
->comp_unit_obstack
,
10476 hashtab_obstack_allocate
,
10477 dummy_obstack_deallocate
);
10479 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10481 *slot
= ref_per_cu
;
10484 /* Set the mark field in CU and in every other compilation unit in the
10485 cache that we must keep because we are keeping CU. */
10488 dwarf2_mark_helper (void **slot
, void *data
)
10490 struct dwarf2_per_cu_data
*per_cu
;
10492 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10493 if (per_cu
->cu
->mark
)
10495 per_cu
->cu
->mark
= 1;
10497 if (per_cu
->cu
->dependencies
!= NULL
)
10498 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10504 dwarf2_mark (struct dwarf2_cu
*cu
)
10509 if (cu
->dependencies
!= NULL
)
10510 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10514 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10518 per_cu
->cu
->mark
= 0;
10519 per_cu
= per_cu
->cu
->read_in_chain
;
10523 /* Trivial hash function for partial_die_info: the hash value of a DIE
10524 is its offset in .debug_info for this objfile. */
10527 partial_die_hash (const void *item
)
10529 const struct partial_die_info
*part_die
= item
;
10530 return part_die
->offset
;
10533 /* Trivial comparison function for partial_die_info structures: two DIEs
10534 are equal if they have the same offset. */
10537 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10539 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10540 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10541 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10544 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10545 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10548 set_dwarf2_cmd (char *args
, int from_tty
)
10550 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10554 show_dwarf2_cmd (char *args
, int from_tty
)
10556 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10559 void _initialize_dwarf2_read (void);
10562 _initialize_dwarf2_read (void)
10564 dwarf2_objfile_data_key
= register_objfile_data ();
10566 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10567 Set DWARF 2 specific variables.\n\
10568 Configure DWARF 2 variables such as the cache size"),
10569 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10570 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10572 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10573 Show DWARF 2 specific variables\n\
10574 Show DWARF 2 variables such as the cache size"),
10575 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10576 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10578 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10579 &dwarf2_max_cache_age
, _("\
10580 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10581 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10582 A higher limit means that cached compilation units will be stored\n\
10583 in memory longer, and more total memory will be used. Zero disables\n\
10584 caching, which can slow down startup."),
10586 show_dwarf2_max_cache_age
,
10587 &set_dwarf2_cmdlist
,
10588 &show_dwarf2_cmdlist
);