1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
37 #include "filenames.h" /* for DOSish file names */
40 #include "complaints.h"
42 #include "dwarf2expr.h"
43 #include "dwarf2loc.h"
44 #include "cp-support.h"
51 #include "gdb_string.h"
52 #include "gdb_assert.h"
53 #include <sys/types.h>
58 /* A note on memory usage for this file.
60 At the present time, this code reads the debug info sections into
61 the objfile's objfile_obstack. A definite improvement for startup
62 time, on platforms which do not emit relocations for debug
63 sections, would be to use mmap instead. The object's complete
64 debug information is loaded into memory, partly to simplify
65 absolute DIE references.
67 Whether using obstacks or mmap, the sections should remain loaded
68 until the objfile is released, and pointers into the section data
69 can be used for any other data associated to the objfile (symbol
70 names, type names, location expressions to name a few). */
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length
; /* length of the .debug_info
80 unsigned short version
; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
83 unsigned char addr_size
; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length
; /* length of the .debug_pubnames
96 unsigned char version
; /* version number -- 2 for DWARF
98 unsigned int info_offset
; /* offset into .debug_info section */
99 unsigned int info_size
; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length
; /* byte len of the .debug_aranges
112 unsigned short version
; /* version number -- 2 for DWARF
114 unsigned int info_offset
; /* offset into .debug_info section */
115 unsigned char addr_size
; /* byte size of an address */
116 unsigned char seg_size
; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length
; /* byte length of the statement
128 unsigned short version
; /* version number -- 2 for DWARF
130 unsigned int prologue_length
; /* # bytes between prologue &
132 unsigned char minimum_instruction_length
; /* byte size of
134 unsigned char default_is_stmt
; /* initial value of is_stmt
137 unsigned char line_range
;
138 unsigned char opcode_base
; /* number assigned to first special
140 unsigned char *standard_opcode_lengths
;
144 /* When set, the file that we're processing is known to have debugging
145 info for C++ namespaces. GCC 3.3.x did not produce this information,
146 but later versions do. */
148 static int processing_has_namespace_info
;
150 static const struct objfile_data
*dwarf2_objfile_data_key
;
152 struct dwarf2_per_objfile
154 /* Sizes of debugging sections. */
155 unsigned int info_size
;
156 unsigned int abbrev_size
;
157 unsigned int line_size
;
158 unsigned int pubnames_size
;
159 unsigned int aranges_size
;
160 unsigned int loc_size
;
161 unsigned int macinfo_size
;
162 unsigned int str_size
;
163 unsigned int ranges_size
;
164 unsigned int frame_size
;
165 unsigned int eh_frame_size
;
167 /* Loaded data from the sections. */
168 gdb_byte
*info_buffer
;
169 gdb_byte
*abbrev_buffer
;
170 gdb_byte
*line_buffer
;
171 gdb_byte
*str_buffer
;
172 gdb_byte
*macinfo_buffer
;
173 gdb_byte
*ranges_buffer
;
174 gdb_byte
*loc_buffer
;
176 /* A list of all the compilation units. This is used to locate
177 the target compilation unit of a particular reference. */
178 struct dwarf2_per_cu_data
**all_comp_units
;
180 /* The number of compilation units in ALL_COMP_UNITS. */
183 /* A chain of compilation units that are currently read in, so that
184 they can be freed later. */
185 struct dwarf2_per_cu_data
*read_in_chain
;
187 /* A flag indicating wether this objfile has a section loaded at a
189 int has_section_at_zero
;
192 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
194 static asection
*dwarf_info_section
;
195 static asection
*dwarf_abbrev_section
;
196 static asection
*dwarf_line_section
;
197 static asection
*dwarf_pubnames_section
;
198 static asection
*dwarf_aranges_section
;
199 static asection
*dwarf_loc_section
;
200 static asection
*dwarf_macinfo_section
;
201 static asection
*dwarf_str_section
;
202 static asection
*dwarf_ranges_section
;
203 asection
*dwarf_frame_section
;
204 asection
*dwarf_eh_frame_section
;
206 /* names of the debugging sections */
208 /* Note that if the debugging section has been compressed, it might
209 have a name like .zdebug_info. */
211 #define INFO_SECTION "debug_info"
212 #define ABBREV_SECTION "debug_abbrev"
213 #define LINE_SECTION "debug_line"
214 #define PUBNAMES_SECTION "debug_pubnames"
215 #define ARANGES_SECTION "debug_aranges"
216 #define LOC_SECTION "debug_loc"
217 #define MACINFO_SECTION "debug_macinfo"
218 #define STR_SECTION "debug_str"
219 #define RANGES_SECTION "debug_ranges"
220 #define FRAME_SECTION "debug_frame"
221 #define EH_FRAME_SECTION "eh_frame"
223 /* local data types */
225 /* We hold several abbreviation tables in memory at the same time. */
226 #ifndef ABBREV_HASH_SIZE
227 #define ABBREV_HASH_SIZE 121
230 /* The data in a compilation unit header, after target2host
231 translation, looks like this. */
232 struct comp_unit_head
234 unsigned long length
;
236 unsigned char addr_size
;
237 unsigned char signed_addr_p
;
238 unsigned int abbrev_offset
;
240 /* Size of file offsets; either 4 or 8. */
241 unsigned int offset_size
;
243 /* Size of the length field; either 4 or 12. */
244 unsigned int initial_length_size
;
246 /* Offset to the first byte of this compilation unit header in the
247 .debug_info section, for resolving relative reference dies. */
250 /* Offset to first die in this cu from the start of the cu.
251 This will be the first byte following the compilation unit header. */
252 unsigned int first_die_offset
;
255 /* Internal state when decoding a particular compilation unit. */
258 /* The objfile containing this compilation unit. */
259 struct objfile
*objfile
;
261 /* The header of the compilation unit. */
262 struct comp_unit_head header
;
264 /* Base address of this compilation unit. */
265 CORE_ADDR base_address
;
267 /* Non-zero if base_address has been set. */
270 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
272 /* The language we are debugging. */
273 enum language language
;
274 const struct language_defn
*language_defn
;
276 const char *producer
;
278 /* The generic symbol table building routines have separate lists for
279 file scope symbols and all all other scopes (local scopes). So
280 we need to select the right one to pass to add_symbol_to_list().
281 We do it by keeping a pointer to the correct list in list_in_scope.
283 FIXME: The original dwarf code just treated the file scope as the
284 first local scope, and all other local scopes as nested local
285 scopes, and worked fine. Check to see if we really need to
286 distinguish these in buildsym.c. */
287 struct pending
**list_in_scope
;
289 /* DWARF abbreviation table associated with this compilation unit. */
290 struct abbrev_info
**dwarf2_abbrevs
;
292 /* Storage for the abbrev table. */
293 struct obstack abbrev_obstack
;
295 /* Hash table holding all the loaded partial DIEs. */
298 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
299 unsigned long ranges_offset
;
301 /* Storage for things with the same lifetime as this read-in compilation
302 unit, including partial DIEs. */
303 struct obstack comp_unit_obstack
;
305 /* When multiple dwarf2_cu structures are living in memory, this field
306 chains them all together, so that they can be released efficiently.
307 We will probably also want a generation counter so that most-recently-used
308 compilation units are cached... */
309 struct dwarf2_per_cu_data
*read_in_chain
;
311 /* Backchain to our per_cu entry if the tree has been built. */
312 struct dwarf2_per_cu_data
*per_cu
;
314 /* Pointer to the die -> type map. Although it is stored
315 permanently in per_cu, we copy it here to avoid double
319 /* How many compilation units ago was this CU last referenced? */
322 /* A hash table of die offsets for following references. */
325 /* Full DIEs if read in. */
326 struct die_info
*dies
;
328 /* A set of pointers to dwarf2_per_cu_data objects for compilation
329 units referenced by this one. Only set during full symbol processing;
330 partial symbol tables do not have dependencies. */
333 /* Header data from the line table, during full symbol processing. */
334 struct line_header
*line_header
;
336 /* Mark used when releasing cached dies. */
337 unsigned int mark
: 1;
339 /* This flag will be set if this compilation unit might include
340 inter-compilation-unit references. */
341 unsigned int has_form_ref_addr
: 1;
343 /* This flag will be set if this compilation unit includes any
344 DW_TAG_namespace DIEs. If we know that there are explicit
345 DIEs for namespaces, we don't need to try to infer them
346 from mangled names. */
347 unsigned int has_namespace_info
: 1;
349 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
350 unsigned int has_ranges_offset
: 1;
353 /* Persistent data held for a compilation unit, even when not
354 processing it. We put a pointer to this structure in the
355 read_symtab_private field of the psymtab. If we encounter
356 inter-compilation-unit references, we also maintain a sorted
357 list of all compilation units. */
359 struct dwarf2_per_cu_data
361 /* The start offset and length of this compilation unit. 2**30-1
362 bytes should suffice to store the length of any compilation unit
363 - if it doesn't, GDB will fall over anyway.
364 NOTE: Unlike comp_unit_head.length, this length includes
365 initial_length_size. */
366 unsigned long offset
;
367 unsigned long length
: 30;
369 /* Flag indicating this compilation unit will be read in before
370 any of the current compilation units are processed. */
371 unsigned long queued
: 1;
373 /* This flag will be set if we need to load absolutely all DIEs
374 for this compilation unit, instead of just the ones we think
375 are interesting. It gets set if we look for a DIE in the
376 hash table and don't find it. */
377 unsigned int load_all_dies
: 1;
379 /* Set iff currently read in. */
380 struct dwarf2_cu
*cu
;
382 /* If full symbols for this CU have been read in, then this field
383 holds a map of DIE offsets to types. It isn't always possible
384 to reconstruct this information later, so we have to preserve
388 /* The partial symbol table associated with this compilation unit,
389 or NULL for partial units (which do not have an associated
391 struct partial_symtab
*psymtab
;
394 /* The line number information for a compilation unit (found in the
395 .debug_line section) begins with a "statement program header",
396 which contains the following information. */
399 unsigned int total_length
;
400 unsigned short version
;
401 unsigned int header_length
;
402 unsigned char minimum_instruction_length
;
403 unsigned char default_is_stmt
;
405 unsigned char line_range
;
406 unsigned char opcode_base
;
408 /* standard_opcode_lengths[i] is the number of operands for the
409 standard opcode whose value is i. This means that
410 standard_opcode_lengths[0] is unused, and the last meaningful
411 element is standard_opcode_lengths[opcode_base - 1]. */
412 unsigned char *standard_opcode_lengths
;
414 /* The include_directories table. NOTE! These strings are not
415 allocated with xmalloc; instead, they are pointers into
416 debug_line_buffer. If you try to free them, `free' will get
418 unsigned int num_include_dirs
, include_dirs_size
;
421 /* The file_names table. NOTE! These strings are not allocated
422 with xmalloc; instead, they are pointers into debug_line_buffer.
423 Don't try to free them directly. */
424 unsigned int num_file_names
, file_names_size
;
428 unsigned int dir_index
;
429 unsigned int mod_time
;
431 int included_p
; /* Non-zero if referenced by the Line Number Program. */
432 struct symtab
*symtab
; /* The associated symbol table, if any. */
435 /* The start and end of the statement program following this
436 header. These point into dwarf2_per_objfile->line_buffer. */
437 gdb_byte
*statement_program_start
, *statement_program_end
;
440 /* When we construct a partial symbol table entry we only
441 need this much information. */
442 struct partial_die_info
444 /* Offset of this DIE. */
447 /* DWARF-2 tag for this DIE. */
448 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
450 /* Language code associated with this DIE. This is only used
451 for the compilation unit DIE. */
452 unsigned int language
: 8;
454 /* Assorted flags describing the data found in this DIE. */
455 unsigned int has_children
: 1;
456 unsigned int is_external
: 1;
457 unsigned int is_declaration
: 1;
458 unsigned int has_type
: 1;
459 unsigned int has_specification
: 1;
460 unsigned int has_stmt_list
: 1;
461 unsigned int has_pc_info
: 1;
463 /* Flag set if the SCOPE field of this structure has been
465 unsigned int scope_set
: 1;
467 /* Flag set if the DIE has a byte_size attribute. */
468 unsigned int has_byte_size
: 1;
470 /* The name of this DIE. Normally the value of DW_AT_name, but
471 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
476 /* The scope to prepend to our children. This is generally
477 allocated on the comp_unit_obstack, so will disappear
478 when this compilation unit leaves the cache. */
481 /* The location description associated with this DIE, if any. */
482 struct dwarf_block
*locdesc
;
484 /* If HAS_PC_INFO, the PC range associated with this DIE. */
488 /* Pointer into the info_buffer pointing at the target of
489 DW_AT_sibling, if any. */
492 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
493 DW_AT_specification (or DW_AT_abstract_origin or
495 unsigned int spec_offset
;
497 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
498 unsigned int line_offset
;
500 /* Pointers to this DIE's parent, first child, and next sibling,
502 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
505 /* This data structure holds the information of an abbrev. */
508 unsigned int number
; /* number identifying abbrev */
509 enum dwarf_tag tag
; /* dwarf tag */
510 unsigned short has_children
; /* boolean */
511 unsigned short num_attrs
; /* number of attributes */
512 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
513 struct abbrev_info
*next
; /* next in chain */
518 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
519 ENUM_BITFIELD(dwarf_form
) form
: 16;
522 /* Attributes have a name and a value */
525 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
526 ENUM_BITFIELD(dwarf_form
) form
: 16;
530 struct dwarf_block
*blk
;
538 /* This data structure holds a complete die structure. */
541 /* DWARF-2 tag for this DIE. */
542 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
544 /* Number of attributes */
545 unsigned short num_attrs
;
550 /* Offset in .debug_info section */
553 /* The dies in a compilation unit form an n-ary tree. PARENT
554 points to this die's parent; CHILD points to the first child of
555 this node; and all the children of a given node are chained
556 together via their SIBLING fields, terminated by a die whose
558 struct die_info
*child
; /* Its first child, if any. */
559 struct die_info
*sibling
; /* Its next sibling, if any. */
560 struct die_info
*parent
; /* Its parent, if any. */
562 /* An array of attributes, with NUM_ATTRS elements. There may be
563 zero, but it's not common and zero-sized arrays are not
564 sufficiently portable C. */
565 struct attribute attrs
[1];
568 struct function_range
571 CORE_ADDR lowpc
, highpc
;
573 struct function_range
*next
;
576 /* Get at parts of an attribute structure */
578 #define DW_STRING(attr) ((attr)->u.str)
579 #define DW_UNSND(attr) ((attr)->u.unsnd)
580 #define DW_BLOCK(attr) ((attr)->u.blk)
581 #define DW_SND(attr) ((attr)->u.snd)
582 #define DW_ADDR(attr) ((attr)->u.addr)
584 /* Blocks are a bunch of untyped bytes. */
591 #ifndef ATTR_ALLOC_CHUNK
592 #define ATTR_ALLOC_CHUNK 4
595 /* Allocate fields for structs, unions and enums in this size. */
596 #ifndef DW_FIELD_ALLOC_CHUNK
597 #define DW_FIELD_ALLOC_CHUNK 4
600 /* A zeroed version of a partial die for initialization purposes. */
601 static struct partial_die_info zeroed_partial_die
;
603 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
604 but this would require a corresponding change in unpack_field_as_long
606 static int bits_per_byte
= 8;
608 /* The routines that read and process dies for a C struct or C++ class
609 pass lists of data member fields and lists of member function fields
610 in an instance of a field_info structure, as defined below. */
613 /* List of data member and baseclasses fields. */
616 struct nextfield
*next
;
623 /* Number of fields. */
626 /* Number of baseclasses. */
629 /* Set if the accesibility of one of the fields is not public. */
630 int non_public_fields
;
632 /* Member function fields array, entries are allocated in the order they
633 are encountered in the object file. */
636 struct nextfnfield
*next
;
637 struct fn_field fnfield
;
641 /* Member function fieldlist array, contains name of possibly overloaded
642 member function, number of overloaded member functions and a pointer
643 to the head of the member function field chain. */
648 struct nextfnfield
*head
;
652 /* Number of entries in the fnfieldlists array. */
656 /* One item on the queue of compilation units to read in full symbols
658 struct dwarf2_queue_item
660 struct dwarf2_per_cu_data
*per_cu
;
661 struct dwarf2_queue_item
*next
;
664 /* The current queue. */
665 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
667 /* Loaded secondary compilation units are kept in memory until they
668 have not been referenced for the processing of this many
669 compilation units. Set this to zero to disable caching. Cache
670 sizes of up to at least twenty will improve startup time for
671 typical inter-CU-reference binaries, at an obvious memory cost. */
672 static int dwarf2_max_cache_age
= 5;
674 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
675 struct cmd_list_element
*c
, const char *value
)
677 fprintf_filtered (file
, _("\
678 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
683 /* Various complaints about symbol reading that don't abort the process */
686 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
688 complaint (&symfile_complaints
,
689 _("statement list doesn't fit in .debug_line section"));
693 dwarf2_debug_line_missing_file_complaint (void)
695 complaint (&symfile_complaints
,
696 _(".debug_line section has line data without a file"));
700 dwarf2_complex_location_expr_complaint (void)
702 complaint (&symfile_complaints
, _("location expression too complex"));
706 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
709 complaint (&symfile_complaints
,
710 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
715 dwarf2_macros_too_long_complaint (void)
717 complaint (&symfile_complaints
,
718 _("macro info runs off end of `.debug_macinfo' section"));
722 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
724 complaint (&symfile_complaints
,
725 _("macro debug info contains a malformed macro definition:\n`%s'"),
730 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
732 complaint (&symfile_complaints
,
733 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
736 /* local function prototypes */
738 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
741 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
744 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
747 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
748 struct partial_die_info
*,
749 struct partial_symtab
*);
751 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
753 static void scan_partial_symbols (struct partial_die_info
*,
754 CORE_ADDR
*, CORE_ADDR
*,
757 static void add_partial_symbol (struct partial_die_info
*,
760 static int pdi_needs_namespace (enum dwarf_tag tag
);
762 static void add_partial_namespace (struct partial_die_info
*pdi
,
763 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
764 struct dwarf2_cu
*cu
);
766 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
767 struct dwarf2_cu
*cu
);
769 static void add_partial_subprogram (struct partial_die_info
*pdi
,
770 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
771 struct dwarf2_cu
*cu
);
773 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
776 struct dwarf2_cu
*cu
);
778 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
780 static void psymtab_to_symtab_1 (struct partial_symtab
*);
782 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
784 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
786 static void dwarf2_free_abbrev_table (void *);
788 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
791 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
794 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
797 static gdb_byte
*read_partial_die (struct partial_die_info
*,
798 struct abbrev_info
*abbrev
, unsigned int,
799 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
801 static struct partial_die_info
*find_partial_die (unsigned long,
804 static void fixup_partial_die (struct partial_die_info
*,
807 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
808 struct dwarf2_cu
*, int *);
810 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
811 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
813 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
814 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
816 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
818 static int read_1_signed_byte (bfd
*, gdb_byte
*);
820 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
822 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
824 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
826 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
829 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
830 struct comp_unit_head
*, unsigned int *);
832 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
835 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
837 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
839 static char *read_indirect_string (bfd
*, gdb_byte
*,
840 const struct comp_unit_head
*,
843 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
845 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
847 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
849 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
851 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
854 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
855 struct dwarf2_cu
*cu
);
857 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
859 static struct die_info
*die_specification (struct die_info
*die
,
860 struct dwarf2_cu
**);
862 static void free_line_header (struct line_header
*lh
);
864 static void add_file_name (struct line_header
*, char *, unsigned int,
865 unsigned int, unsigned int);
867 static struct line_header
*(dwarf_decode_line_header
868 (unsigned int offset
,
869 bfd
*abfd
, struct dwarf2_cu
*cu
));
871 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
872 struct dwarf2_cu
*, struct partial_symtab
*);
874 static void dwarf2_start_subfile (char *, char *, char *);
876 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
879 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
882 static void dwarf2_const_value_data (struct attribute
*attr
,
886 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
888 static struct type
*die_containing_type (struct die_info
*,
891 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
893 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
895 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
897 static char *typename_concat (struct obstack
*,
902 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
904 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
906 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
908 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
909 struct dwarf2_cu
*, struct partial_symtab
*);
911 static int dwarf2_get_pc_bounds (struct die_info
*,
912 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
914 static void get_scope_pc_bounds (struct die_info
*,
915 CORE_ADDR
*, CORE_ADDR
*,
918 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
919 CORE_ADDR
, struct dwarf2_cu
*);
921 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
924 static void dwarf2_attach_fields_to_type (struct field_info
*,
925 struct type
*, struct dwarf2_cu
*);
927 static void dwarf2_add_member_fn (struct field_info
*,
928 struct die_info
*, struct type
*,
931 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
932 struct type
*, struct dwarf2_cu
*);
934 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
936 static const char *determine_class_name (struct die_info
*die
,
937 struct dwarf2_cu
*cu
);
939 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
941 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
943 static const char *namespace_name (struct die_info
*die
,
944 int *is_anonymous
, struct dwarf2_cu
*);
946 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
948 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
950 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
953 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
955 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
957 gdb_byte
**new_info_ptr
,
958 struct die_info
*parent
);
960 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
962 gdb_byte
**new_info_ptr
,
963 struct die_info
*parent
);
965 static void process_die (struct die_info
*, struct dwarf2_cu
*);
967 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
969 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
971 static struct die_info
*dwarf2_extension (struct die_info
*die
,
972 struct dwarf2_cu
**);
974 static char *dwarf_tag_name (unsigned int);
976 static char *dwarf_attr_name (unsigned int);
978 static char *dwarf_form_name (unsigned int);
980 static char *dwarf_stack_op_name (unsigned int);
982 static char *dwarf_bool_name (unsigned int);
984 static char *dwarf_type_encoding_name (unsigned int);
987 static char *dwarf_cfi_name (unsigned int);
990 static struct die_info
*sibling_die (struct die_info
*);
992 static void dump_die (struct die_info
*);
994 static void dump_die_list (struct die_info
*);
996 static void store_in_ref_table (struct die_info
*,
999 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
1000 struct dwarf2_cu
*);
1002 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1004 static struct die_info
*follow_die_ref (struct die_info
*,
1006 struct dwarf2_cu
**);
1008 /* memory allocation interface */
1010 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1012 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1014 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1016 static void initialize_cu_func_list (struct dwarf2_cu
*);
1018 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1019 struct dwarf2_cu
*);
1021 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1022 char *, bfd
*, struct dwarf2_cu
*);
1024 static int attr_form_is_block (struct attribute
*);
1026 static int attr_form_is_section_offset (struct attribute
*);
1028 static int attr_form_is_constant (struct attribute
*);
1030 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1032 struct dwarf2_cu
*cu
);
1034 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1035 struct dwarf2_cu
*cu
);
1037 static void free_stack_comp_unit (void *);
1039 static hashval_t
partial_die_hash (const void *item
);
1041 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1043 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1044 (unsigned long offset
, struct objfile
*objfile
);
1046 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1047 (unsigned long offset
, struct objfile
*objfile
);
1049 static void free_one_comp_unit (void *);
1051 static void free_cached_comp_units (void *);
1053 static void age_cached_comp_units (void);
1055 static void free_one_cached_comp_unit (void *);
1057 static struct type
*set_die_type (struct die_info
*, struct type
*,
1058 struct dwarf2_cu
*);
1060 static void create_all_comp_units (struct objfile
*);
1062 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1065 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1067 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1068 struct dwarf2_per_cu_data
*);
1070 static void dwarf2_mark (struct dwarf2_cu
*);
1072 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1074 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1076 /* Try to locate the sections we need for DWARF 2 debugging
1077 information and return true if we have enough to do something. */
1080 dwarf2_has_info (struct objfile
*objfile
)
1082 struct dwarf2_per_objfile
*data
;
1084 /* Initialize per-objfile state. */
1085 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1086 memset (data
, 0, sizeof (*data
));
1087 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1088 dwarf2_per_objfile
= data
;
1090 dwarf_info_section
= 0;
1091 dwarf_abbrev_section
= 0;
1092 dwarf_line_section
= 0;
1093 dwarf_str_section
= 0;
1094 dwarf_macinfo_section
= 0;
1095 dwarf_frame_section
= 0;
1096 dwarf_eh_frame_section
= 0;
1097 dwarf_ranges_section
= 0;
1098 dwarf_loc_section
= 0;
1100 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1101 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1104 /* When loading sections, we can either look for ".<name>", or for
1105 * ".z<name>", which indicates a compressed section. */
1108 section_is_p (asection
*sectp
, const char *name
)
1110 return ((sectp
->name
[0] == '.'
1111 && strcmp (sectp
->name
+ 1, name
) == 0)
1112 || (sectp
->name
[0] == '.' && sectp
->name
[1] == 'z'
1113 && strcmp (sectp
->name
+ 2, name
) == 0));
1116 /* This function is mapped across the sections and remembers the
1117 offset and size of each of the debugging sections we are interested
1121 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1123 if (section_is_p (sectp
, INFO_SECTION
))
1125 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1126 dwarf_info_section
= sectp
;
1128 else if (section_is_p (sectp
, ABBREV_SECTION
))
1130 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1131 dwarf_abbrev_section
= sectp
;
1133 else if (section_is_p (sectp
, LINE_SECTION
))
1135 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1136 dwarf_line_section
= sectp
;
1138 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1140 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1141 dwarf_pubnames_section
= sectp
;
1143 else if (section_is_p (sectp
, ARANGES_SECTION
))
1145 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1146 dwarf_aranges_section
= sectp
;
1148 else if (section_is_p (sectp
, LOC_SECTION
))
1150 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1151 dwarf_loc_section
= sectp
;
1153 else if (section_is_p (sectp
, MACINFO_SECTION
))
1155 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1156 dwarf_macinfo_section
= sectp
;
1158 else if (section_is_p (sectp
, STR_SECTION
))
1160 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1161 dwarf_str_section
= sectp
;
1163 else if (section_is_p (sectp
, FRAME_SECTION
))
1165 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1166 dwarf_frame_section
= sectp
;
1168 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1170 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1171 if (aflag
& SEC_HAS_CONTENTS
)
1173 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1174 dwarf_eh_frame_section
= sectp
;
1177 else if (section_is_p (sectp
, RANGES_SECTION
))
1179 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1180 dwarf_ranges_section
= sectp
;
1183 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1184 && bfd_section_vma (abfd
, sectp
) == 0)
1185 dwarf2_per_objfile
->has_section_at_zero
= 1;
1188 /* This function is called after decompressing a section, so
1189 dwarf2_per_objfile can record its new, uncompressed size. */
1192 dwarf2_resize_section (asection
*sectp
, bfd_size_type new_size
)
1194 if (section_is_p (sectp
, INFO_SECTION
))
1195 dwarf2_per_objfile
->info_size
= new_size
;
1196 else if (section_is_p (sectp
, ABBREV_SECTION
))
1197 dwarf2_per_objfile
->abbrev_size
= new_size
;
1198 else if (section_is_p (sectp
, LINE_SECTION
))
1199 dwarf2_per_objfile
->line_size
= new_size
;
1200 else if (section_is_p (sectp
, PUBNAMES_SECTION
))
1201 dwarf2_per_objfile
->pubnames_size
= new_size
;
1202 else if (section_is_p (sectp
, ARANGES_SECTION
))
1203 dwarf2_per_objfile
->aranges_size
= new_size
;
1204 else if (section_is_p (sectp
, LOC_SECTION
))
1205 dwarf2_per_objfile
->loc_size
= new_size
;
1206 else if (section_is_p (sectp
, MACINFO_SECTION
))
1207 dwarf2_per_objfile
->macinfo_size
= new_size
;
1208 else if (section_is_p (sectp
, STR_SECTION
))
1209 dwarf2_per_objfile
->str_size
= new_size
;
1210 else if (section_is_p (sectp
, FRAME_SECTION
))
1211 dwarf2_per_objfile
->frame_size
= new_size
;
1212 else if (section_is_p (sectp
, EH_FRAME_SECTION
))
1213 dwarf2_per_objfile
->eh_frame_size
= new_size
;
1214 else if (section_is_p (sectp
, RANGES_SECTION
))
1215 dwarf2_per_objfile
->ranges_size
= new_size
;
1217 internal_error (__FILE__
, __LINE__
,
1218 _("dwarf2_resize_section: missing section_is_p check: %s"),
1222 /* Build a partial symbol table. */
1225 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1227 /* We definitely need the .debug_info and .debug_abbrev sections */
1229 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1230 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1232 if (dwarf_line_section
)
1233 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1235 dwarf2_per_objfile
->line_buffer
= NULL
;
1237 if (dwarf_str_section
)
1238 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1240 dwarf2_per_objfile
->str_buffer
= NULL
;
1242 if (dwarf_macinfo_section
)
1243 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1244 dwarf_macinfo_section
);
1246 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1248 if (dwarf_ranges_section
)
1249 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1251 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1253 if (dwarf_loc_section
)
1254 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1256 dwarf2_per_objfile
->loc_buffer
= NULL
;
1259 || (objfile
->global_psymbols
.size
== 0
1260 && objfile
->static_psymbols
.size
== 0))
1262 init_psymbol_list (objfile
, 1024);
1266 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1268 /* Things are significantly easier if we have .debug_aranges and
1269 .debug_pubnames sections */
1271 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1275 /* only test this case for now */
1277 /* In this case we have to work a bit harder */
1278 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1283 /* Build the partial symbol table from the information in the
1284 .debug_pubnames and .debug_aranges sections. */
1287 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1289 bfd
*abfd
= objfile
->obfd
;
1290 char *aranges_buffer
, *pubnames_buffer
;
1291 char *aranges_ptr
, *pubnames_ptr
;
1292 unsigned int entry_length
, version
, info_offset
, info_size
;
1294 pubnames_buffer
= dwarf2_read_section (objfile
,
1295 dwarf_pubnames_section
);
1296 pubnames_ptr
= pubnames_buffer
;
1297 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1299 struct comp_unit_head cu_header
;
1300 unsigned int bytes_read
;
1302 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1304 pubnames_ptr
+= bytes_read
;
1305 version
= read_1_byte (abfd
, pubnames_ptr
);
1307 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1309 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1313 aranges_buffer
= dwarf2_read_section (objfile
,
1314 dwarf_aranges_section
);
1319 /* Return TRUE if OFFSET is within CU_HEADER. */
1322 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1324 unsigned int bottom
= cu_header
->offset
;
1325 unsigned int top
= (cu_header
->offset
1327 + cu_header
->initial_length_size
);
1328 return (offset
>= bottom
&& offset
< top
);
1331 /* Read in the comp unit header information from the debug_info at
1335 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1336 gdb_byte
*info_ptr
, bfd
*abfd
)
1339 unsigned int bytes_read
;
1340 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1342 info_ptr
+= bytes_read
;
1343 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1345 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1347 info_ptr
+= bytes_read
;
1348 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1350 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1351 if (signed_addr
< 0)
1352 internal_error (__FILE__
, __LINE__
,
1353 _("read_comp_unit_head: dwarf from non elf file"));
1354 cu_header
->signed_addr_p
= signed_addr
;
1359 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1362 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1364 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1366 if (header
->version
!= 2 && header
->version
!= 3)
1367 error (_("Dwarf Error: wrong version in compilation unit header "
1368 "(is %d, should be %d) [in module %s]"), header
->version
,
1369 2, bfd_get_filename (abfd
));
1371 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1372 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1373 "(offset 0x%lx + 6) [in module %s]"),
1374 (long) header
->abbrev_offset
,
1375 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1376 bfd_get_filename (abfd
));
1378 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1379 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1380 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1381 "(offset 0x%lx + 0) [in module %s]"),
1382 (long) header
->length
,
1383 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1384 bfd_get_filename (abfd
));
1389 /* Allocate a new partial symtab for file named NAME and mark this new
1390 partial symtab as being an include of PST. */
1393 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1394 struct objfile
*objfile
)
1396 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1398 subpst
->section_offsets
= pst
->section_offsets
;
1399 subpst
->textlow
= 0;
1400 subpst
->texthigh
= 0;
1402 subpst
->dependencies
= (struct partial_symtab
**)
1403 obstack_alloc (&objfile
->objfile_obstack
,
1404 sizeof (struct partial_symtab
*));
1405 subpst
->dependencies
[0] = pst
;
1406 subpst
->number_of_dependencies
= 1;
1408 subpst
->globals_offset
= 0;
1409 subpst
->n_global_syms
= 0;
1410 subpst
->statics_offset
= 0;
1411 subpst
->n_static_syms
= 0;
1412 subpst
->symtab
= NULL
;
1413 subpst
->read_symtab
= pst
->read_symtab
;
1416 /* No private part is necessary for include psymtabs. This property
1417 can be used to differentiate between such include psymtabs and
1418 the regular ones. */
1419 subpst
->read_symtab_private
= NULL
;
1422 /* Read the Line Number Program data and extract the list of files
1423 included by the source file represented by PST. Build an include
1424 partial symtab for each of these included files.
1426 This procedure assumes that there *is* a Line Number Program in
1427 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1428 before calling this procedure. */
1431 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1432 struct partial_die_info
*pdi
,
1433 struct partial_symtab
*pst
)
1435 struct objfile
*objfile
= cu
->objfile
;
1436 bfd
*abfd
= objfile
->obfd
;
1437 struct line_header
*lh
;
1439 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1441 return; /* No linetable, so no includes. */
1443 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1445 free_line_header (lh
);
1449 /* Build the partial symbol table by doing a quick pass through the
1450 .debug_info and .debug_abbrev sections. */
1453 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1455 /* Instead of reading this into a big buffer, we should probably use
1456 mmap() on architectures that support it. (FIXME) */
1457 bfd
*abfd
= objfile
->obfd
;
1459 gdb_byte
*beg_of_comp_unit
;
1460 struct partial_die_info comp_unit_die
;
1461 struct partial_symtab
*pst
;
1462 struct cleanup
*back_to
;
1463 CORE_ADDR lowpc
, highpc
, baseaddr
;
1465 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1467 /* Any cached compilation units will be linked by the per-objfile
1468 read_in_chain. Make sure to free them when we're done. */
1469 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1471 create_all_comp_units (objfile
);
1473 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1474 (&objfile
->objfile_obstack
);
1476 /* Since the objects we're extracting from .debug_info vary in
1477 length, only the individual functions to extract them (like
1478 read_comp_unit_head and load_partial_die) can really know whether
1479 the buffer is large enough to hold another complete object.
1481 At the moment, they don't actually check that. If .debug_info
1482 holds just one extra byte after the last compilation unit's dies,
1483 then read_comp_unit_head will happily read off the end of the
1484 buffer. read_partial_die is similarly casual. Those functions
1487 For this loop condition, simply checking whether there's any data
1488 left at all should be sufficient. */
1489 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1490 + dwarf2_per_objfile
->info_size
))
1492 struct cleanup
*back_to_inner
;
1493 struct dwarf2_cu cu
;
1494 struct abbrev_info
*abbrev
;
1495 unsigned int bytes_read
;
1496 struct dwarf2_per_cu_data
*this_cu
;
1498 beg_of_comp_unit
= info_ptr
;
1500 memset (&cu
, 0, sizeof (cu
));
1502 obstack_init (&cu
.comp_unit_obstack
);
1504 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1506 cu
.objfile
= objfile
;
1507 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1509 /* Complete the cu_header */
1510 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1511 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1513 cu
.list_in_scope
= &file_symbols
;
1515 /* Read the abbrevs for this compilation unit into a table */
1516 dwarf2_read_abbrevs (abfd
, &cu
);
1517 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1519 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1521 /* Read the compilation unit die */
1522 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1523 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1524 abfd
, info_ptr
, &cu
);
1526 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1528 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1529 + cu
.header
.initial_length_size
);
1530 do_cleanups (back_to_inner
);
1534 /* Set the language we're debugging */
1535 set_cu_language (comp_unit_die
.language
, &cu
);
1537 /* Allocate a new partial symbol table structure */
1538 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1539 comp_unit_die
.name
? comp_unit_die
.name
: "",
1540 /* TEXTLOW and TEXTHIGH are set below. */
1542 objfile
->global_psymbols
.next
,
1543 objfile
->static_psymbols
.next
);
1545 if (comp_unit_die
.dirname
)
1546 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1547 strlen (comp_unit_die
.dirname
),
1548 &objfile
->objfile_obstack
);
1550 pst
->read_symtab_private
= (char *) this_cu
;
1552 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1554 /* Store the function that reads in the rest of the symbol table */
1555 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1557 /* If this compilation unit was already read in, free the
1558 cached copy in order to read it in again. This is
1559 necessary because we skipped some symbols when we first
1560 read in the compilation unit (see load_partial_dies).
1561 This problem could be avoided, but the benefit is
1563 if (this_cu
->cu
!= NULL
)
1564 free_one_cached_comp_unit (this_cu
->cu
);
1566 cu
.per_cu
= this_cu
;
1568 /* Note that this is a pointer to our stack frame, being
1569 added to a global data structure. It will be cleaned up
1570 in free_stack_comp_unit when we finish with this
1571 compilation unit. */
1574 this_cu
->psymtab
= pst
;
1576 /* Possibly set the default values of LOWPC and HIGHPC from
1578 if (cu
.has_ranges_offset
)
1580 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1581 &comp_unit_die
.highpc
, &cu
, pst
))
1582 comp_unit_die
.has_pc_info
= 1;
1585 /* Check if comp unit has_children.
1586 If so, read the rest of the partial symbols from this comp unit.
1587 If not, there's no more debug_info for this comp unit. */
1588 if (comp_unit_die
.has_children
)
1590 struct partial_die_info
*first_die
;
1592 lowpc
= ((CORE_ADDR
) -1);
1593 highpc
= ((CORE_ADDR
) 0);
1595 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1597 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1599 /* If we didn't find a lowpc, set it to highpc to avoid
1600 complaints from `maint check'. */
1601 if (lowpc
== ((CORE_ADDR
) -1))
1604 /* If the compilation unit didn't have an explicit address range,
1605 then use the information extracted from its child dies. */
1606 if (! comp_unit_die
.has_pc_info
)
1608 comp_unit_die
.lowpc
= lowpc
;
1609 comp_unit_die
.highpc
= highpc
;
1612 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1613 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1615 /* Store the contiguous range; `DW_AT_ranges' range is stored above. The
1616 range can be also empty for CUs with no code. */
1617 if (!cu
.has_ranges_offset
&& pst
->textlow
< pst
->texthigh
)
1618 addrmap_set_empty (objfile
->psymtabs_addrmap
, pst
->textlow
,
1619 pst
->texthigh
- 1, pst
);
1621 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1622 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1623 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1624 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1625 sort_pst_symbols (pst
);
1627 /* If there is already a psymtab or symtab for a file of this
1628 name, remove it. (If there is a symtab, more drastic things
1629 also happen.) This happens in VxWorks. */
1630 free_named_symtabs (pst
->filename
);
1632 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1633 + cu
.header
.initial_length_size
;
1635 if (comp_unit_die
.has_stmt_list
)
1637 /* Get the list of files included in the current compilation unit,
1638 and build a psymtab for each of them. */
1639 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1642 do_cleanups (back_to_inner
);
1645 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1646 &objfile
->objfile_obstack
);
1648 do_cleanups (back_to
);
1651 /* Load the DIEs for a secondary CU into memory. */
1654 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1656 bfd
*abfd
= objfile
->obfd
;
1657 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1658 struct partial_die_info comp_unit_die
;
1659 struct dwarf2_cu
*cu
;
1660 struct abbrev_info
*abbrev
;
1661 unsigned int bytes_read
;
1662 struct cleanup
*back_to
;
1664 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1665 beg_of_comp_unit
= info_ptr
;
1667 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1668 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1670 obstack_init (&cu
->comp_unit_obstack
);
1672 cu
->objfile
= objfile
;
1673 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1675 /* Complete the cu_header. */
1676 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1677 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1679 /* Read the abbrevs for this compilation unit into a table. */
1680 dwarf2_read_abbrevs (abfd
, cu
);
1681 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1683 /* Read the compilation unit die. */
1684 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1685 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1686 abfd
, info_ptr
, cu
);
1688 /* Set the language we're debugging. */
1689 set_cu_language (comp_unit_die
.language
, cu
);
1691 /* Link this compilation unit into the compilation unit tree. */
1693 cu
->per_cu
= this_cu
;
1694 cu
->type_hash
= cu
->per_cu
->type_hash
;
1696 /* Check if comp unit has_children.
1697 If so, read the rest of the partial symbols from this comp unit.
1698 If not, there's no more debug_info for this comp unit. */
1699 if (comp_unit_die
.has_children
)
1700 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1702 do_cleanups (back_to
);
1705 /* Create a list of all compilation units in OBJFILE. We do this only
1706 if an inter-comp-unit reference is found; presumably if there is one,
1707 there will be many, and one will occur early in the .debug_info section.
1708 So there's no point in building this list incrementally. */
1711 create_all_comp_units (struct objfile
*objfile
)
1715 struct dwarf2_per_cu_data
**all_comp_units
;
1716 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1720 all_comp_units
= xmalloc (n_allocated
1721 * sizeof (struct dwarf2_per_cu_data
*));
1723 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1725 struct comp_unit_head cu_header
;
1726 gdb_byte
*beg_of_comp_unit
;
1727 struct dwarf2_per_cu_data
*this_cu
;
1728 unsigned long offset
;
1729 unsigned int bytes_read
;
1731 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1733 /* Read just enough information to find out where the next
1734 compilation unit is. */
1735 cu_header
.initial_length_size
= 0;
1736 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1737 &cu_header
, &bytes_read
);
1739 /* Save the compilation unit for later lookup. */
1740 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1741 sizeof (struct dwarf2_per_cu_data
));
1742 memset (this_cu
, 0, sizeof (*this_cu
));
1743 this_cu
->offset
= offset
;
1744 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1746 if (n_comp_units
== n_allocated
)
1749 all_comp_units
= xrealloc (all_comp_units
,
1751 * sizeof (struct dwarf2_per_cu_data
*));
1753 all_comp_units
[n_comp_units
++] = this_cu
;
1755 info_ptr
= info_ptr
+ this_cu
->length
;
1758 dwarf2_per_objfile
->all_comp_units
1759 = obstack_alloc (&objfile
->objfile_obstack
,
1760 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1761 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1762 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1763 xfree (all_comp_units
);
1764 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1767 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1768 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1772 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1773 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1775 struct objfile
*objfile
= cu
->objfile
;
1776 bfd
*abfd
= objfile
->obfd
;
1777 struct partial_die_info
*pdi
;
1779 /* Now, march along the PDI's, descending into ones which have
1780 interesting children but skipping the children of the other ones,
1781 until we reach the end of the compilation unit. */
1787 fixup_partial_die (pdi
, cu
);
1789 /* Anonymous namespaces have no name but have interesting
1790 children, so we need to look at them. Ditto for anonymous
1793 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1794 || pdi
->tag
== DW_TAG_enumeration_type
)
1798 case DW_TAG_subprogram
:
1799 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
1801 case DW_TAG_variable
:
1802 case DW_TAG_typedef
:
1803 case DW_TAG_union_type
:
1804 if (!pdi
->is_declaration
)
1806 add_partial_symbol (pdi
, cu
);
1809 case DW_TAG_class_type
:
1810 case DW_TAG_interface_type
:
1811 case DW_TAG_structure_type
:
1812 if (!pdi
->is_declaration
)
1814 add_partial_symbol (pdi
, cu
);
1817 case DW_TAG_enumeration_type
:
1818 if (!pdi
->is_declaration
)
1819 add_partial_enumeration (pdi
, cu
);
1821 case DW_TAG_base_type
:
1822 case DW_TAG_subrange_type
:
1823 /* File scope base type definitions are added to the partial
1825 add_partial_symbol (pdi
, cu
);
1827 case DW_TAG_namespace
:
1828 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1835 /* If the die has a sibling, skip to the sibling. */
1837 pdi
= pdi
->die_sibling
;
1841 /* Functions used to compute the fully scoped name of a partial DIE.
1843 Normally, this is simple. For C++, the parent DIE's fully scoped
1844 name is concatenated with "::" and the partial DIE's name. For
1845 Java, the same thing occurs except that "." is used instead of "::".
1846 Enumerators are an exception; they use the scope of their parent
1847 enumeration type, i.e. the name of the enumeration type is not
1848 prepended to the enumerator.
1850 There are two complexities. One is DW_AT_specification; in this
1851 case "parent" means the parent of the target of the specification,
1852 instead of the direct parent of the DIE. The other is compilers
1853 which do not emit DW_TAG_namespace; in this case we try to guess
1854 the fully qualified name of structure types from their members'
1855 linkage names. This must be done using the DIE's children rather
1856 than the children of any DW_AT_specification target. We only need
1857 to do this for structures at the top level, i.e. if the target of
1858 any DW_AT_specification (if any; otherwise the DIE itself) does not
1861 /* Compute the scope prefix associated with PDI's parent, in
1862 compilation unit CU. The result will be allocated on CU's
1863 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1864 field. NULL is returned if no prefix is necessary. */
1866 partial_die_parent_scope (struct partial_die_info
*pdi
,
1867 struct dwarf2_cu
*cu
)
1869 char *grandparent_scope
;
1870 struct partial_die_info
*parent
, *real_pdi
;
1872 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1873 then this means the parent of the specification DIE. */
1876 while (real_pdi
->has_specification
)
1877 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1879 parent
= real_pdi
->die_parent
;
1883 if (parent
->scope_set
)
1884 return parent
->scope
;
1886 fixup_partial_die (parent
, cu
);
1888 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1890 if (parent
->tag
== DW_TAG_namespace
1891 || parent
->tag
== DW_TAG_structure_type
1892 || parent
->tag
== DW_TAG_class_type
1893 || parent
->tag
== DW_TAG_interface_type
1894 || parent
->tag
== DW_TAG_union_type
)
1896 if (grandparent_scope
== NULL
)
1897 parent
->scope
= parent
->name
;
1899 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1902 else if (parent
->tag
== DW_TAG_enumeration_type
)
1903 /* Enumerators should not get the name of the enumeration as a prefix. */
1904 parent
->scope
= grandparent_scope
;
1907 /* FIXME drow/2004-04-01: What should we be doing with
1908 function-local names? For partial symbols, we should probably be
1910 complaint (&symfile_complaints
,
1911 _("unhandled containing DIE tag %d for DIE at %d"),
1912 parent
->tag
, pdi
->offset
);
1913 parent
->scope
= grandparent_scope
;
1916 parent
->scope_set
= 1;
1917 return parent
->scope
;
1920 /* Return the fully scoped name associated with PDI, from compilation unit
1921 CU. The result will be allocated with malloc. */
1923 partial_die_full_name (struct partial_die_info
*pdi
,
1924 struct dwarf2_cu
*cu
)
1928 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1929 if (parent_scope
== NULL
)
1932 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1936 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1938 struct objfile
*objfile
= cu
->objfile
;
1940 char *actual_name
= NULL
;
1941 const char *my_prefix
;
1942 const struct partial_symbol
*psym
= NULL
;
1944 int built_actual_name
= 0;
1946 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1948 if (pdi_needs_namespace (pdi
->tag
))
1950 actual_name
= partial_die_full_name (pdi
, cu
);
1952 built_actual_name
= 1;
1955 if (actual_name
== NULL
)
1956 actual_name
= pdi
->name
;
1960 case DW_TAG_subprogram
:
1961 if (pdi
->is_external
|| cu
->language
== language_ada
)
1963 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
1964 of the global scope. But in Ada, we want to be able to access
1965 nested procedures globally. So all Ada subprograms are stored
1966 in the global scope. */
1967 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1968 mst_text, objfile); */
1969 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1970 VAR_DOMAIN
, LOC_BLOCK
,
1971 &objfile
->global_psymbols
,
1972 0, pdi
->lowpc
+ baseaddr
,
1973 cu
->language
, objfile
);
1977 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1978 mst_file_text, objfile); */
1979 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1980 VAR_DOMAIN
, LOC_BLOCK
,
1981 &objfile
->static_psymbols
,
1982 0, pdi
->lowpc
+ baseaddr
,
1983 cu
->language
, objfile
);
1986 case DW_TAG_variable
:
1987 if (pdi
->is_external
)
1990 Don't enter into the minimal symbol tables as there is
1991 a minimal symbol table entry from the ELF symbols already.
1992 Enter into partial symbol table if it has a location
1993 descriptor or a type.
1994 If the location descriptor is missing, new_symbol will create
1995 a LOC_UNRESOLVED symbol, the address of the variable will then
1996 be determined from the minimal symbol table whenever the variable
1998 The address for the partial symbol table entry is not
1999 used by GDB, but it comes in handy for debugging partial symbol
2003 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2004 if (pdi
->locdesc
|| pdi
->has_type
)
2005 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2006 VAR_DOMAIN
, LOC_STATIC
,
2007 &objfile
->global_psymbols
,
2009 cu
->language
, objfile
);
2013 /* Static Variable. Skip symbols without location descriptors. */
2014 if (pdi
->locdesc
== NULL
)
2016 if (built_actual_name
)
2017 xfree (actual_name
);
2020 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2021 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2022 mst_file_data, objfile); */
2023 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2024 VAR_DOMAIN
, LOC_STATIC
,
2025 &objfile
->static_psymbols
,
2027 cu
->language
, objfile
);
2030 case DW_TAG_typedef
:
2031 case DW_TAG_base_type
:
2032 case DW_TAG_subrange_type
:
2033 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2034 VAR_DOMAIN
, LOC_TYPEDEF
,
2035 &objfile
->static_psymbols
,
2036 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2038 case DW_TAG_namespace
:
2039 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2040 VAR_DOMAIN
, LOC_TYPEDEF
,
2041 &objfile
->global_psymbols
,
2042 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2044 case DW_TAG_class_type
:
2045 case DW_TAG_interface_type
:
2046 case DW_TAG_structure_type
:
2047 case DW_TAG_union_type
:
2048 case DW_TAG_enumeration_type
:
2049 /* Skip external references. The DWARF standard says in the section
2050 about "Structure, Union, and Class Type Entries": "An incomplete
2051 structure, union or class type is represented by a structure,
2052 union or class entry that does not have a byte size attribute
2053 and that has a DW_AT_declaration attribute." */
2054 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2056 if (built_actual_name
)
2057 xfree (actual_name
);
2061 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2062 static vs. global. */
2063 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2064 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2065 (cu
->language
== language_cplus
2066 || cu
->language
== language_java
)
2067 ? &objfile
->global_psymbols
2068 : &objfile
->static_psymbols
,
2069 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2072 case DW_TAG_enumerator
:
2073 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2074 VAR_DOMAIN
, LOC_CONST
,
2075 (cu
->language
== language_cplus
2076 || cu
->language
== language_java
)
2077 ? &objfile
->global_psymbols
2078 : &objfile
->static_psymbols
,
2079 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2085 /* Check to see if we should scan the name for possible namespace
2086 info. Only do this if this is C++, if we don't have namespace
2087 debugging info in the file, if the psym is of an appropriate type
2088 (otherwise we'll have psym == NULL), and if we actually had a
2089 mangled name to begin with. */
2091 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2092 cases which do not set PSYM above? */
2094 if (cu
->language
== language_cplus
2095 && cu
->has_namespace_info
== 0
2097 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2098 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2101 if (built_actual_name
)
2102 xfree (actual_name
);
2105 /* Determine whether a die of type TAG living in a C++ class or
2106 namespace needs to have the name of the scope prepended to the
2107 name listed in the die. */
2110 pdi_needs_namespace (enum dwarf_tag tag
)
2114 case DW_TAG_namespace
:
2115 case DW_TAG_typedef
:
2116 case DW_TAG_class_type
:
2117 case DW_TAG_interface_type
:
2118 case DW_TAG_structure_type
:
2119 case DW_TAG_union_type
:
2120 case DW_TAG_enumeration_type
:
2121 case DW_TAG_enumerator
:
2128 /* Read a partial die corresponding to a namespace; also, add a symbol
2129 corresponding to that namespace to the symbol table. NAMESPACE is
2130 the name of the enclosing namespace. */
2133 add_partial_namespace (struct partial_die_info
*pdi
,
2134 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2135 struct dwarf2_cu
*cu
)
2137 struct objfile
*objfile
= cu
->objfile
;
2139 /* Add a symbol for the namespace. */
2141 add_partial_symbol (pdi
, cu
);
2143 /* Now scan partial symbols in that namespace. */
2145 if (pdi
->has_children
)
2146 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2149 /* Read a partial die corresponding to a subprogram and create a partial
2150 symbol for that subprogram. When the CU language allows it, this
2151 routine also defines a partial symbol for each nested subprogram
2152 that this subprogram contains.
2154 DIE my also be a lexical block, in which case we simply search
2155 recursively for suprograms defined inside that lexical block.
2156 Again, this is only performed when the CU language allows this
2157 type of definitions. */
2160 add_partial_subprogram (struct partial_die_info
*pdi
,
2161 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2162 struct dwarf2_cu
*cu
)
2164 if (pdi
->tag
== DW_TAG_subprogram
)
2166 if (pdi
->has_pc_info
)
2168 if (pdi
->lowpc
< *lowpc
)
2169 *lowpc
= pdi
->lowpc
;
2170 if (pdi
->highpc
> *highpc
)
2171 *highpc
= pdi
->highpc
;
2172 if (!pdi
->is_declaration
)
2173 add_partial_symbol (pdi
, cu
);
2177 if (! pdi
->has_children
)
2180 if (cu
->language
== language_ada
)
2182 pdi
= pdi
->die_child
;
2185 fixup_partial_die (pdi
, cu
);
2186 if (pdi
->tag
== DW_TAG_subprogram
2187 || pdi
->tag
== DW_TAG_lexical_block
)
2188 add_partial_subprogram (pdi
, lowpc
, highpc
, cu
);
2189 pdi
= pdi
->die_sibling
;
2194 /* See if we can figure out if the class lives in a namespace. We do
2195 this by looking for a member function; its demangled name will
2196 contain namespace info, if there is any. */
2199 guess_structure_name (struct partial_die_info
*struct_pdi
,
2200 struct dwarf2_cu
*cu
)
2202 if ((cu
->language
== language_cplus
2203 || cu
->language
== language_java
)
2204 && cu
->has_namespace_info
== 0
2205 && struct_pdi
->has_children
)
2207 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2208 what template types look like, because the demangler
2209 frequently doesn't give the same name as the debug info. We
2210 could fix this by only using the demangled name to get the
2211 prefix (but see comment in read_structure_type). */
2213 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2214 struct partial_die_info
*real_pdi
;
2216 /* If this DIE (this DIE's specification, if any) has a parent, then
2217 we should not do this. We'll prepend the parent's fully qualified
2218 name when we create the partial symbol. */
2220 real_pdi
= struct_pdi
;
2221 while (real_pdi
->has_specification
)
2222 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2224 if (real_pdi
->die_parent
!= NULL
)
2227 while (child_pdi
!= NULL
)
2229 if (child_pdi
->tag
== DW_TAG_subprogram
)
2231 char *actual_class_name
2232 = language_class_name_from_physname (cu
->language_defn
,
2234 if (actual_class_name
!= NULL
)
2237 = obsavestring (actual_class_name
,
2238 strlen (actual_class_name
),
2239 &cu
->comp_unit_obstack
);
2240 xfree (actual_class_name
);
2245 child_pdi
= child_pdi
->die_sibling
;
2250 /* Read a partial die corresponding to an enumeration type. */
2253 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2254 struct dwarf2_cu
*cu
)
2256 struct objfile
*objfile
= cu
->objfile
;
2257 bfd
*abfd
= objfile
->obfd
;
2258 struct partial_die_info
*pdi
;
2260 if (enum_pdi
->name
!= NULL
)
2261 add_partial_symbol (enum_pdi
, cu
);
2263 pdi
= enum_pdi
->die_child
;
2266 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2267 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2269 add_partial_symbol (pdi
, cu
);
2270 pdi
= pdi
->die_sibling
;
2274 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2275 Return the corresponding abbrev, or NULL if the number is zero (indicating
2276 an empty DIE). In either case *BYTES_READ will be set to the length of
2277 the initial number. */
2279 static struct abbrev_info
*
2280 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2281 struct dwarf2_cu
*cu
)
2283 bfd
*abfd
= cu
->objfile
->obfd
;
2284 unsigned int abbrev_number
;
2285 struct abbrev_info
*abbrev
;
2287 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2289 if (abbrev_number
== 0)
2292 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2295 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2296 bfd_get_filename (abfd
));
2302 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2303 pointer to the end of a series of DIEs, terminated by an empty
2304 DIE. Any children of the skipped DIEs will also be skipped. */
2307 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2309 struct abbrev_info
*abbrev
;
2310 unsigned int bytes_read
;
2314 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2316 return info_ptr
+ bytes_read
;
2318 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2322 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2323 should point just after the initial uleb128 of a DIE, and the
2324 abbrev corresponding to that skipped uleb128 should be passed in
2325 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2329 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2330 struct dwarf2_cu
*cu
)
2332 unsigned int bytes_read
;
2333 struct attribute attr
;
2334 bfd
*abfd
= cu
->objfile
->obfd
;
2335 unsigned int form
, i
;
2337 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2339 /* The only abbrev we care about is DW_AT_sibling. */
2340 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2342 read_attribute (&attr
, &abbrev
->attrs
[i
],
2343 abfd
, info_ptr
, cu
);
2344 if (attr
.form
== DW_FORM_ref_addr
)
2345 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2347 return dwarf2_per_objfile
->info_buffer
2348 + dwarf2_get_ref_die_offset (&attr
, cu
);
2351 /* If it isn't DW_AT_sibling, skip this attribute. */
2352 form
= abbrev
->attrs
[i
].form
;
2357 case DW_FORM_ref_addr
:
2358 info_ptr
+= cu
->header
.addr_size
;
2377 case DW_FORM_string
:
2378 read_string (abfd
, info_ptr
, &bytes_read
);
2379 info_ptr
+= bytes_read
;
2382 info_ptr
+= cu
->header
.offset_size
;
2385 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2386 info_ptr
+= bytes_read
;
2388 case DW_FORM_block1
:
2389 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2391 case DW_FORM_block2
:
2392 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2394 case DW_FORM_block4
:
2395 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2399 case DW_FORM_ref_udata
:
2400 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2402 case DW_FORM_indirect
:
2403 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2404 info_ptr
+= bytes_read
;
2405 /* We need to continue parsing from here, so just go back to
2407 goto skip_attribute
;
2410 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2411 dwarf_form_name (form
),
2412 bfd_get_filename (abfd
));
2416 if (abbrev
->has_children
)
2417 return skip_children (info_ptr
, cu
);
2422 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2423 the next DIE after ORIG_PDI. */
2426 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2427 bfd
*abfd
, struct dwarf2_cu
*cu
)
2429 /* Do we know the sibling already? */
2431 if (orig_pdi
->sibling
)
2432 return orig_pdi
->sibling
;
2434 /* Are there any children to deal with? */
2436 if (!orig_pdi
->has_children
)
2439 /* Skip the children the long way. */
2441 return skip_children (info_ptr
, cu
);
2444 /* Expand this partial symbol table into a full symbol table. */
2447 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2449 /* FIXME: This is barely more than a stub. */
2454 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2460 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2461 gdb_flush (gdb_stdout
);
2464 /* Restore our global data. */
2465 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2466 dwarf2_objfile_data_key
);
2468 psymtab_to_symtab_1 (pst
);
2470 /* Finish up the debug error message. */
2472 printf_filtered (_("done.\n"));
2477 /* Add PER_CU to the queue. */
2480 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2482 struct dwarf2_queue_item
*item
;
2485 item
= xmalloc (sizeof (*item
));
2486 item
->per_cu
= per_cu
;
2489 if (dwarf2_queue
== NULL
)
2490 dwarf2_queue
= item
;
2492 dwarf2_queue_tail
->next
= item
;
2494 dwarf2_queue_tail
= item
;
2496 /* Either PER_CU is the CU we want to process, or we're following a reference
2497 pointing into PER_CU. Either way, we need its DIEs now. */
2498 load_full_comp_unit (item
->per_cu
, objfile
);
2499 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2500 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2503 /* Process the queue. */
2506 process_queue (struct objfile
*objfile
)
2508 struct dwarf2_queue_item
*item
, *next_item
;
2510 /* The queue starts out with one item, but following a DIE reference
2511 may load a new CU, adding it to the end of the queue. */
2512 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2514 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2515 process_full_comp_unit (item
->per_cu
);
2517 item
->per_cu
->queued
= 0;
2518 next_item
= item
->next
;
2522 dwarf2_queue_tail
= NULL
;
2525 /* Free all allocated queue entries. This function only releases anything if
2526 an error was thrown; if the queue was processed then it would have been
2527 freed as we went along. */
2530 dwarf2_release_queue (void *dummy
)
2532 struct dwarf2_queue_item
*item
, *last
;
2534 item
= dwarf2_queue
;
2537 /* Anything still marked queued is likely to be in an
2538 inconsistent state, so discard it. */
2539 if (item
->per_cu
->queued
)
2541 if (item
->per_cu
->cu
!= NULL
)
2542 free_one_cached_comp_unit (item
->per_cu
->cu
);
2543 item
->per_cu
->queued
= 0;
2551 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2554 /* Read in full symbols for PST, and anything it depends on. */
2557 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2559 struct dwarf2_per_cu_data
*per_cu
;
2560 struct cleanup
*back_to
;
2563 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2564 if (!pst
->dependencies
[i
]->readin
)
2566 /* Inform about additional files that need to be read in. */
2569 /* FIXME: i18n: Need to make this a single string. */
2570 fputs_filtered (" ", gdb_stdout
);
2572 fputs_filtered ("and ", gdb_stdout
);
2574 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2575 wrap_here (""); /* Flush output */
2576 gdb_flush (gdb_stdout
);
2578 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2581 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2585 /* It's an include file, no symbols to read for it.
2586 Everything is in the parent symtab. */
2591 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2593 queue_comp_unit (per_cu
, pst
->objfile
);
2595 process_queue (pst
->objfile
);
2597 /* Age the cache, releasing compilation units that have not
2598 been used recently. */
2599 age_cached_comp_units ();
2601 do_cleanups (back_to
);
2604 /* Load the DIEs associated with PST and PER_CU into memory. */
2606 static struct dwarf2_cu
*
2607 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2609 bfd
*abfd
= objfile
->obfd
;
2610 struct dwarf2_cu
*cu
;
2611 unsigned long offset
;
2613 struct cleanup
*back_to
, *free_cu_cleanup
;
2614 struct attribute
*attr
;
2617 /* Set local variables from the partial symbol table info. */
2618 offset
= per_cu
->offset
;
2620 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2622 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2623 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2625 /* If an error occurs while loading, release our storage. */
2626 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2628 cu
->objfile
= objfile
;
2630 /* read in the comp_unit header */
2631 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2633 /* Read the abbrevs for this compilation unit */
2634 dwarf2_read_abbrevs (abfd
, cu
);
2635 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2637 cu
->header
.offset
= offset
;
2639 cu
->per_cu
= per_cu
;
2641 cu
->type_hash
= per_cu
->type_hash
;
2643 /* We use this obstack for block values in dwarf_alloc_block. */
2644 obstack_init (&cu
->comp_unit_obstack
);
2646 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2648 /* We try not to read any attributes in this function, because not
2649 all objfiles needed for references have been loaded yet, and symbol
2650 table processing isn't initialized. But we have to set the CU language,
2651 or we won't be able to build types correctly. */
2652 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2654 set_cu_language (DW_UNSND (attr
), cu
);
2656 set_cu_language (language_minimal
, cu
);
2658 do_cleanups (back_to
);
2660 /* We've successfully allocated this compilation unit. Let our caller
2661 clean it up when finished with it. */
2662 discard_cleanups (free_cu_cleanup
);
2667 /* Generate full symbol information for PST and CU, whose DIEs have
2668 already been loaded into memory. */
2671 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2673 struct partial_symtab
*pst
= per_cu
->psymtab
;
2674 struct dwarf2_cu
*cu
= per_cu
->cu
;
2675 struct objfile
*objfile
= pst
->objfile
;
2676 bfd
*abfd
= objfile
->obfd
;
2677 CORE_ADDR lowpc
, highpc
;
2678 struct symtab
*symtab
;
2679 struct cleanup
*back_to
;
2680 struct attribute
*attr
;
2683 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2686 back_to
= make_cleanup (really_free_pendings
, NULL
);
2688 cu
->list_in_scope
= &file_symbols
;
2690 /* Find the base address of the compilation unit for range lists and
2691 location lists. It will normally be specified by DW_AT_low_pc.
2692 In DWARF-3 draft 4, the base address could be overridden by
2693 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2694 compilation units with discontinuous ranges. */
2697 cu
->base_address
= 0;
2699 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2702 cu
->base_address
= DW_ADDR (attr
);
2707 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2710 cu
->base_address
= DW_ADDR (attr
);
2715 /* Do line number decoding in read_file_scope () */
2716 process_die (cu
->dies
, cu
);
2718 /* Some compilers don't define a DW_AT_high_pc attribute for the
2719 compilation unit. If the DW_AT_high_pc is missing, synthesize
2720 it, by scanning the DIE's below the compilation unit. */
2721 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2723 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2725 /* Set symtab language to language from DW_AT_language.
2726 If the compilation is from a C file generated by language preprocessors,
2727 do not set the language if it was already deduced by start_subfile. */
2729 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2731 symtab
->language
= cu
->language
;
2733 pst
->symtab
= symtab
;
2736 do_cleanups (back_to
);
2739 /* Process a die and its children. */
2742 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2746 case DW_TAG_padding
:
2748 case DW_TAG_compile_unit
:
2749 read_file_scope (die
, cu
);
2751 case DW_TAG_subprogram
:
2752 read_func_scope (die
, cu
);
2754 case DW_TAG_inlined_subroutine
:
2755 /* FIXME: These are ignored for now.
2756 They could be used to set breakpoints on all inlined instances
2757 of a function and make GDB `next' properly over inlined functions. */
2759 case DW_TAG_lexical_block
:
2760 case DW_TAG_try_block
:
2761 case DW_TAG_catch_block
:
2762 read_lexical_block_scope (die
, cu
);
2764 case DW_TAG_class_type
:
2765 case DW_TAG_interface_type
:
2766 case DW_TAG_structure_type
:
2767 case DW_TAG_union_type
:
2768 process_structure_scope (die
, cu
);
2770 case DW_TAG_enumeration_type
:
2771 process_enumeration_scope (die
, cu
);
2774 /* These dies have a type, but processing them does not create
2775 a symbol or recurse to process the children. Therefore we can
2776 read them on-demand through read_type_die. */
2777 case DW_TAG_subroutine_type
:
2778 case DW_TAG_set_type
:
2779 case DW_TAG_array_type
:
2780 case DW_TAG_pointer_type
:
2781 case DW_TAG_ptr_to_member_type
:
2782 case DW_TAG_reference_type
:
2783 case DW_TAG_string_type
:
2786 case DW_TAG_base_type
:
2787 case DW_TAG_subrange_type
:
2788 /* Add a typedef symbol for the type definition, if it has a
2790 new_symbol (die
, read_type_die (die
, cu
), cu
);
2792 case DW_TAG_common_block
:
2793 read_common_block (die
, cu
);
2795 case DW_TAG_common_inclusion
:
2797 case DW_TAG_namespace
:
2798 processing_has_namespace_info
= 1;
2799 read_namespace (die
, cu
);
2801 case DW_TAG_imported_declaration
:
2802 case DW_TAG_imported_module
:
2803 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2804 information contained in these. DW_TAG_imported_declaration
2805 dies shouldn't have children; DW_TAG_imported_module dies
2806 shouldn't in the C++ case, but conceivably could in the
2808 processing_has_namespace_info
= 1;
2809 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
2810 dwarf_tag_name (die
->tag
));
2813 new_symbol (die
, NULL
, cu
);
2818 /* Return the fully qualified name of DIE, based on its DW_AT_name.
2819 If scope qualifiers are appropriate they will be added. The result
2820 will be allocated on the objfile_obstack, or NULL if the DIE does
2824 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
2826 struct attribute
*attr
;
2827 char *prefix
, *name
;
2828 struct ui_file
*buf
= NULL
;
2830 name
= dwarf2_name (die
, cu
);
2834 /* These are the only languages we know how to qualify names in. */
2835 if (cu
->language
!= language_cplus
2836 && cu
->language
!= language_java
)
2839 /* If no prefix is necessary for this type of DIE, return the
2840 unqualified name. The other three tags listed could be handled
2841 in pdi_needs_namespace, but that requires broader changes. */
2842 if (!pdi_needs_namespace (die
->tag
)
2843 && die
->tag
!= DW_TAG_subprogram
2844 && die
->tag
!= DW_TAG_variable
2845 && die
->tag
!= DW_TAG_member
)
2848 prefix
= determine_prefix (die
, cu
);
2849 if (*prefix
!= '\0')
2850 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
2857 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2859 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2863 free_cu_line_header (void *arg
)
2865 struct dwarf2_cu
*cu
= arg
;
2867 free_line_header (cu
->line_header
);
2868 cu
->line_header
= NULL
;
2872 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2874 struct objfile
*objfile
= cu
->objfile
;
2875 struct comp_unit_head
*cu_header
= &cu
->header
;
2876 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2877 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2878 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2879 struct attribute
*attr
;
2881 char *comp_dir
= NULL
;
2882 struct die_info
*child_die
;
2883 bfd
*abfd
= objfile
->obfd
;
2884 struct line_header
*line_header
= 0;
2887 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2889 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2891 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2892 from finish_block. */
2893 if (lowpc
== ((CORE_ADDR
) -1))
2898 /* Find the filename. Do not use dwarf2_name here, since the filename
2899 is not a source language identifier. */
2900 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2903 name
= DW_STRING (attr
);
2906 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2908 comp_dir
= DW_STRING (attr
);
2909 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
2911 comp_dir
= ldirname (name
);
2912 if (comp_dir
!= NULL
)
2913 make_cleanup (xfree
, comp_dir
);
2915 if (comp_dir
!= NULL
)
2917 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2918 directory, get rid of it. */
2919 char *cp
= strchr (comp_dir
, ':');
2921 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2928 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2931 set_cu_language (DW_UNSND (attr
), cu
);
2934 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2936 cu
->producer
= DW_STRING (attr
);
2938 /* We assume that we're processing GCC output. */
2939 processing_gcc_compilation
= 2;
2941 processing_has_namespace_info
= 0;
2943 start_symtab (name
, comp_dir
, lowpc
);
2944 record_debugformat ("DWARF 2");
2945 record_producer (cu
->producer
);
2947 initialize_cu_func_list (cu
);
2949 /* Decode line number information if present. We do this before
2950 processing child DIEs, so that the line header table is available
2951 for DW_AT_decl_file. */
2952 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2955 unsigned int line_offset
= DW_UNSND (attr
);
2956 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2959 cu
->line_header
= line_header
;
2960 make_cleanup (free_cu_line_header
, cu
);
2961 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2965 /* Process all dies in compilation unit. */
2966 if (die
->child
!= NULL
)
2968 child_die
= die
->child
;
2969 while (child_die
&& child_die
->tag
)
2971 process_die (child_die
, cu
);
2972 child_die
= sibling_die (child_die
);
2976 /* Decode macro information, if present. Dwarf 2 macro information
2977 refers to information in the line number info statement program
2978 header, so we can only read it if we've read the header
2980 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2981 if (attr
&& line_header
)
2983 unsigned int macro_offset
= DW_UNSND (attr
);
2984 dwarf_decode_macros (line_header
, macro_offset
,
2985 comp_dir
, abfd
, cu
);
2987 do_cleanups (back_to
);
2991 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2992 struct dwarf2_cu
*cu
)
2994 struct function_range
*thisfn
;
2996 thisfn
= (struct function_range
*)
2997 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2998 thisfn
->name
= name
;
2999 thisfn
->lowpc
= lowpc
;
3000 thisfn
->highpc
= highpc
;
3001 thisfn
->seen_line
= 0;
3002 thisfn
->next
= NULL
;
3004 if (cu
->last_fn
== NULL
)
3005 cu
->first_fn
= thisfn
;
3007 cu
->last_fn
->next
= thisfn
;
3009 cu
->last_fn
= thisfn
;
3013 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3015 struct objfile
*objfile
= cu
->objfile
;
3016 struct context_stack
*new;
3019 struct die_info
*child_die
;
3020 struct attribute
*attr
;
3023 struct block
*block
;
3025 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3027 name
= dwarf2_linkage_name (die
, cu
);
3029 /* Ignore functions with missing or empty names and functions with
3030 missing or invalid low and high pc attributes. */
3031 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3037 /* Record the function range for dwarf_decode_lines. */
3038 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3040 new = push_context (0, lowpc
);
3041 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3043 /* If there is a location expression for DW_AT_frame_base, record
3045 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3047 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3048 expression is being recorded directly in the function's symbol
3049 and not in a separate frame-base object. I guess this hack is
3050 to avoid adding some sort of frame-base adjunct/annex to the
3051 function's symbol :-(. The problem with doing this is that it
3052 results in a function symbol with a location expression that
3053 has nothing to do with the location of the function, ouch! The
3054 relationship should be: a function's symbol has-a frame base; a
3055 frame-base has-a location expression. */
3056 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3058 cu
->list_in_scope
= &local_symbols
;
3060 if (die
->child
!= NULL
)
3062 child_die
= die
->child
;
3063 while (child_die
&& child_die
->tag
)
3065 process_die (child_die
, cu
);
3066 child_die
= sibling_die (child_die
);
3070 new = pop_context ();
3071 /* Make a block for the local symbols within. */
3072 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3073 lowpc
, highpc
, objfile
);
3075 /* For C++, set the block's scope. */
3076 if (cu
->language
== language_cplus
)
3077 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3078 determine_prefix (die
, cu
),
3079 processing_has_namespace_info
);
3081 /* If we have address ranges, record them. */
3082 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3084 /* In C++, we can have functions nested inside functions (e.g., when
3085 a function declares a class that has methods). This means that
3086 when we finish processing a function scope, we may need to go
3087 back to building a containing block's symbol lists. */
3088 local_symbols
= new->locals
;
3089 param_symbols
= new->params
;
3091 /* If we've finished processing a top-level function, subsequent
3092 symbols go in the file symbol list. */
3093 if (outermost_context_p ())
3094 cu
->list_in_scope
= &file_symbols
;
3097 /* Process all the DIES contained within a lexical block scope. Start
3098 a new scope, process the dies, and then close the scope. */
3101 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3103 struct objfile
*objfile
= cu
->objfile
;
3104 struct context_stack
*new;
3105 CORE_ADDR lowpc
, highpc
;
3106 struct die_info
*child_die
;
3109 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3111 /* Ignore blocks with missing or invalid low and high pc attributes. */
3112 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3113 as multiple lexical blocks? Handling children in a sane way would
3114 be nasty. Might be easier to properly extend generic blocks to
3116 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3121 push_context (0, lowpc
);
3122 if (die
->child
!= NULL
)
3124 child_die
= die
->child
;
3125 while (child_die
&& child_die
->tag
)
3127 process_die (child_die
, cu
);
3128 child_die
= sibling_die (child_die
);
3131 new = pop_context ();
3133 if (local_symbols
!= NULL
)
3136 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3139 /* Note that recording ranges after traversing children, as we
3140 do here, means that recording a parent's ranges entails
3141 walking across all its children's ranges as they appear in
3142 the address map, which is quadratic behavior.
3144 It would be nicer to record the parent's ranges before
3145 traversing its children, simply overriding whatever you find
3146 there. But since we don't even decide whether to create a
3147 block until after we've traversed its children, that's hard
3149 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3151 local_symbols
= new->locals
;
3154 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3155 Return 1 if the attributes are present and valid, otherwise, return 0.
3156 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3159 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3160 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3161 struct partial_symtab
*ranges_pst
)
3163 struct objfile
*objfile
= cu
->objfile
;
3164 struct comp_unit_head
*cu_header
= &cu
->header
;
3165 bfd
*obfd
= objfile
->obfd
;
3166 unsigned int addr_size
= cu_header
->addr_size
;
3167 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3168 /* Base address selection entry. */
3179 found_base
= cu
->base_known
;
3180 base
= cu
->base_address
;
3182 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3184 complaint (&symfile_complaints
,
3185 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3189 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3191 /* Read in the largest possible address. */
3192 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3193 if ((marker
& mask
) == mask
)
3195 /* If we found the largest possible address, then
3196 read the base address. */
3197 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3198 buffer
+= 2 * addr_size
;
3199 offset
+= 2 * addr_size
;
3205 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3209 CORE_ADDR range_beginning
, range_end
;
3211 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3212 buffer
+= addr_size
;
3213 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3214 buffer
+= addr_size
;
3215 offset
+= 2 * addr_size
;
3217 /* An end of list marker is a pair of zero addresses. */
3218 if (range_beginning
== 0 && range_end
== 0)
3219 /* Found the end of list entry. */
3222 /* Each base address selection entry is a pair of 2 values.
3223 The first is the largest possible address, the second is
3224 the base address. Check for a base address here. */
3225 if ((range_beginning
& mask
) == mask
)
3227 /* If we found the largest possible address, then
3228 read the base address. */
3229 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3236 /* We have no valid base address for the ranges
3238 complaint (&symfile_complaints
,
3239 _("Invalid .debug_ranges data (no base address)"));
3243 range_beginning
+= base
;
3246 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3247 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3248 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3251 /* FIXME: This is recording everything as a low-high
3252 segment of consecutive addresses. We should have a
3253 data structure for discontiguous block ranges
3257 low
= range_beginning
;
3263 if (range_beginning
< low
)
3264 low
= range_beginning
;
3265 if (range_end
> high
)
3271 /* If the first entry is an end-of-list marker, the range
3272 describes an empty scope, i.e. no instructions. */
3278 *high_return
= high
;
3282 /* Get low and high pc attributes from a die. Return 1 if the attributes
3283 are present and valid, otherwise, return 0. Return -1 if the range is
3284 discontinuous, i.e. derived from DW_AT_ranges information. */
3286 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3287 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3289 struct attribute
*attr
;
3294 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3297 high
= DW_ADDR (attr
);
3298 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3300 low
= DW_ADDR (attr
);
3302 /* Found high w/o low attribute. */
3305 /* Found consecutive range of addresses. */
3310 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3313 /* Value of the DW_AT_ranges attribute is the offset in the
3314 .debug_ranges section. */
3315 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3317 /* Found discontinuous range of addresses. */
3325 /* When using the GNU linker, .gnu.linkonce. sections are used to
3326 eliminate duplicate copies of functions and vtables and such.
3327 The linker will arbitrarily choose one and discard the others.
3328 The AT_*_pc values for such functions refer to local labels in
3329 these sections. If the section from that file was discarded, the
3330 labels are not in the output, so the relocs get a value of 0.
3331 If this is a discarded function, mark the pc bounds as invalid,
3332 so that GDB will ignore it. */
3333 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3341 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3342 its low and high PC addresses. Do nothing if these addresses could not
3343 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3344 and HIGHPC to the high address if greater than HIGHPC. */
3347 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3348 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3349 struct dwarf2_cu
*cu
)
3351 CORE_ADDR low
, high
;
3352 struct die_info
*child
= die
->child
;
3354 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3356 *lowpc
= min (*lowpc
, low
);
3357 *highpc
= max (*highpc
, high
);
3360 /* If the language does not allow nested subprograms (either inside
3361 subprograms or lexical blocks), we're done. */
3362 if (cu
->language
!= language_ada
)
3365 /* Check all the children of the given DIE. If it contains nested
3366 subprograms, then check their pc bounds. Likewise, we need to
3367 check lexical blocks as well, as they may also contain subprogram
3369 while (child
&& child
->tag
)
3371 if (child
->tag
== DW_TAG_subprogram
3372 || child
->tag
== DW_TAG_lexical_block
)
3373 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3374 child
= sibling_die (child
);
3378 /* Get the low and high pc's represented by the scope DIE, and store
3379 them in *LOWPC and *HIGHPC. If the correct values can't be
3380 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3383 get_scope_pc_bounds (struct die_info
*die
,
3384 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3385 struct dwarf2_cu
*cu
)
3387 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3388 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3389 CORE_ADDR current_low
, current_high
;
3391 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3393 best_low
= current_low
;
3394 best_high
= current_high
;
3398 struct die_info
*child
= die
->child
;
3400 while (child
&& child
->tag
)
3402 switch (child
->tag
) {
3403 case DW_TAG_subprogram
:
3404 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3406 case DW_TAG_namespace
:
3407 /* FIXME: carlton/2004-01-16: Should we do this for
3408 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3409 that current GCC's always emit the DIEs corresponding
3410 to definitions of methods of classes as children of a
3411 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3412 the DIEs giving the declarations, which could be
3413 anywhere). But I don't see any reason why the
3414 standards says that they have to be there. */
3415 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3417 if (current_low
!= ((CORE_ADDR
) -1))
3419 best_low
= min (best_low
, current_low
);
3420 best_high
= max (best_high
, current_high
);
3428 child
= sibling_die (child
);
3433 *highpc
= best_high
;
3436 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3439 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3440 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3442 struct attribute
*attr
;
3444 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3447 CORE_ADDR high
= DW_ADDR (attr
);
3448 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3451 CORE_ADDR low
= DW_ADDR (attr
);
3452 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3456 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3459 bfd
*obfd
= cu
->objfile
->obfd
;
3461 /* The value of the DW_AT_ranges attribute is the offset of the
3462 address range list in the .debug_ranges section. */
3463 unsigned long offset
= DW_UNSND (attr
);
3464 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3466 /* For some target architectures, but not others, the
3467 read_address function sign-extends the addresses it returns.
3468 To recognize base address selection entries, we need a
3470 unsigned int addr_size
= cu
->header
.addr_size
;
3471 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3473 /* The base address, to which the next pair is relative. Note
3474 that this 'base' is a DWARF concept: most entries in a range
3475 list are relative, to reduce the number of relocs against the
3476 debugging information. This is separate from this function's
3477 'baseaddr' argument, which GDB uses to relocate debugging
3478 information from a shared library based on the address at
3479 which the library was loaded. */
3480 CORE_ADDR base
= cu
->base_address
;
3481 int base_known
= cu
->base_known
;
3483 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3485 complaint (&symfile_complaints
,
3486 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3493 unsigned int bytes_read
;
3494 CORE_ADDR start
, end
;
3496 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3497 buffer
+= bytes_read
;
3498 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3499 buffer
+= bytes_read
;
3501 /* Did we find the end of the range list? */
3502 if (start
== 0 && end
== 0)
3505 /* Did we find a base address selection entry? */
3506 else if ((start
& base_select_mask
) == base_select_mask
)
3512 /* We found an ordinary address range. */
3517 complaint (&symfile_complaints
,
3518 _("Invalid .debug_ranges data (no base address)"));
3522 record_block_range (block
,
3523 baseaddr
+ base
+ start
,
3524 baseaddr
+ base
+ end
- 1);
3530 /* Add an aggregate field to the field list. */
3533 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3534 struct dwarf2_cu
*cu
)
3536 struct objfile
*objfile
= cu
->objfile
;
3537 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3538 struct nextfield
*new_field
;
3539 struct attribute
*attr
;
3541 char *fieldname
= "";
3543 /* Allocate a new field list entry and link it in. */
3544 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3545 make_cleanup (xfree
, new_field
);
3546 memset (new_field
, 0, sizeof (struct nextfield
));
3547 new_field
->next
= fip
->fields
;
3548 fip
->fields
= new_field
;
3551 /* Handle accessibility and virtuality of field.
3552 The default accessibility for members is public, the default
3553 accessibility for inheritance is private. */
3554 if (die
->tag
!= DW_TAG_inheritance
)
3555 new_field
->accessibility
= DW_ACCESS_public
;
3557 new_field
->accessibility
= DW_ACCESS_private
;
3558 new_field
->virtuality
= DW_VIRTUALITY_none
;
3560 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3562 new_field
->accessibility
= DW_UNSND (attr
);
3563 if (new_field
->accessibility
!= DW_ACCESS_public
)
3564 fip
->non_public_fields
= 1;
3565 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3567 new_field
->virtuality
= DW_UNSND (attr
);
3569 fp
= &new_field
->field
;
3571 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3573 /* Data member other than a C++ static data member. */
3575 /* Get type of field. */
3576 fp
->type
= die_type (die
, cu
);
3578 FIELD_STATIC_KIND (*fp
) = 0;
3580 /* Get bit size of field (zero if none). */
3581 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3584 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3588 FIELD_BITSIZE (*fp
) = 0;
3591 /* Get bit offset of field. */
3592 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3597 if (attr_form_is_section_offset (attr
))
3599 dwarf2_complex_location_expr_complaint ();
3602 else if (attr_form_is_constant (attr
))
3603 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3605 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3607 FIELD_BITPOS (*fp
) = byte_offset
* bits_per_byte
;
3610 FIELD_BITPOS (*fp
) = 0;
3611 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3614 if (gdbarch_bits_big_endian (gdbarch
))
3616 /* For big endian bits, the DW_AT_bit_offset gives the
3617 additional bit offset from the MSB of the containing
3618 anonymous object to the MSB of the field. We don't
3619 have to do anything special since we don't need to
3620 know the size of the anonymous object. */
3621 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3625 /* For little endian bits, compute the bit offset to the
3626 MSB of the anonymous object, subtract off the number of
3627 bits from the MSB of the field to the MSB of the
3628 object, and then subtract off the number of bits of
3629 the field itself. The result is the bit offset of
3630 the LSB of the field. */
3632 int bit_offset
= DW_UNSND (attr
);
3634 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3637 /* The size of the anonymous object containing
3638 the bit field is explicit, so use the
3639 indicated size (in bytes). */
3640 anonymous_size
= DW_UNSND (attr
);
3644 /* The size of the anonymous object containing
3645 the bit field must be inferred from the type
3646 attribute of the data member containing the
3648 anonymous_size
= TYPE_LENGTH (fp
->type
);
3650 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3651 - bit_offset
- FIELD_BITSIZE (*fp
);
3655 /* Get name of field. */
3656 fieldname
= dwarf2_name (die
, cu
);
3657 if (fieldname
== NULL
)
3660 /* The name is already allocated along with this objfile, so we don't
3661 need to duplicate it for the type. */
3662 fp
->name
= fieldname
;
3664 /* Change accessibility for artificial fields (e.g. virtual table
3665 pointer or virtual base class pointer) to private. */
3666 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3668 new_field
->accessibility
= DW_ACCESS_private
;
3669 fip
->non_public_fields
= 1;
3672 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3674 /* C++ static member. */
3676 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3677 is a declaration, but all versions of G++ as of this writing
3678 (so through at least 3.2.1) incorrectly generate
3679 DW_TAG_variable tags. */
3683 /* Get name of field. */
3684 fieldname
= dwarf2_name (die
, cu
);
3685 if (fieldname
== NULL
)
3688 /* Get physical name. */
3689 physname
= dwarf2_linkage_name (die
, cu
);
3691 /* The name is already allocated along with this objfile, so we don't
3692 need to duplicate it for the type. */
3693 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3694 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3695 FIELD_NAME (*fp
) = fieldname
;
3697 else if (die
->tag
== DW_TAG_inheritance
)
3699 /* C++ base class field. */
3700 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3702 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3704 FIELD_BITSIZE (*fp
) = 0;
3705 FIELD_STATIC_KIND (*fp
) = 0;
3706 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3707 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3708 fip
->nbaseclasses
++;
3712 /* Create the vector of fields, and attach it to the type. */
3715 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3716 struct dwarf2_cu
*cu
)
3718 int nfields
= fip
->nfields
;
3720 /* Record the field count, allocate space for the array of fields,
3721 and create blank accessibility bitfields if necessary. */
3722 TYPE_NFIELDS (type
) = nfields
;
3723 TYPE_FIELDS (type
) = (struct field
*)
3724 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3725 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3727 if (fip
->non_public_fields
)
3729 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3731 TYPE_FIELD_PRIVATE_BITS (type
) =
3732 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3733 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3735 TYPE_FIELD_PROTECTED_BITS (type
) =
3736 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3737 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3739 TYPE_FIELD_IGNORE_BITS (type
) =
3740 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3741 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3744 /* If the type has baseclasses, allocate and clear a bit vector for
3745 TYPE_FIELD_VIRTUAL_BITS. */
3746 if (fip
->nbaseclasses
)
3748 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3749 unsigned char *pointer
;
3751 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3752 pointer
= TYPE_ALLOC (type
, num_bytes
);
3753 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3754 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3755 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3758 /* Copy the saved-up fields into the field vector. Start from the head
3759 of the list, adding to the tail of the field array, so that they end
3760 up in the same order in the array in which they were added to the list. */
3761 while (nfields
-- > 0)
3763 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3764 switch (fip
->fields
->accessibility
)
3766 case DW_ACCESS_private
:
3767 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3770 case DW_ACCESS_protected
:
3771 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3774 case DW_ACCESS_public
:
3778 /* Unknown accessibility. Complain and treat it as public. */
3780 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3781 fip
->fields
->accessibility
);
3785 if (nfields
< fip
->nbaseclasses
)
3787 switch (fip
->fields
->virtuality
)
3789 case DW_VIRTUALITY_virtual
:
3790 case DW_VIRTUALITY_pure_virtual
:
3791 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3795 fip
->fields
= fip
->fields
->next
;
3799 /* Add a member function to the proper fieldlist. */
3802 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3803 struct type
*type
, struct dwarf2_cu
*cu
)
3805 struct objfile
*objfile
= cu
->objfile
;
3806 struct attribute
*attr
;
3807 struct fnfieldlist
*flp
;
3809 struct fn_field
*fnp
;
3812 struct nextfnfield
*new_fnfield
;
3813 struct type
*this_type
;
3815 /* Get name of member function. */
3816 fieldname
= dwarf2_name (die
, cu
);
3817 if (fieldname
== NULL
)
3820 /* Get the mangled name. */
3821 physname
= dwarf2_linkage_name (die
, cu
);
3823 /* Look up member function name in fieldlist. */
3824 for (i
= 0; i
< fip
->nfnfields
; i
++)
3826 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3830 /* Create new list element if necessary. */
3831 if (i
< fip
->nfnfields
)
3832 flp
= &fip
->fnfieldlists
[i
];
3835 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3837 fip
->fnfieldlists
= (struct fnfieldlist
*)
3838 xrealloc (fip
->fnfieldlists
,
3839 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3840 * sizeof (struct fnfieldlist
));
3841 if (fip
->nfnfields
== 0)
3842 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3844 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3845 flp
->name
= fieldname
;
3851 /* Create a new member function field and chain it to the field list
3853 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3854 make_cleanup (xfree
, new_fnfield
);
3855 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3856 new_fnfield
->next
= flp
->head
;
3857 flp
->head
= new_fnfield
;
3860 /* Fill in the member function field info. */
3861 fnp
= &new_fnfield
->fnfield
;
3862 /* The name is already allocated along with this objfile, so we don't
3863 need to duplicate it for the type. */
3864 fnp
->physname
= physname
? physname
: "";
3865 fnp
->type
= alloc_type (objfile
);
3866 this_type
= read_type_die (die
, cu
);
3867 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
3869 int nparams
= TYPE_NFIELDS (this_type
);
3871 /* TYPE is the domain of this method, and THIS_TYPE is the type
3872 of the method itself (TYPE_CODE_METHOD). */
3873 smash_to_method_type (fnp
->type
, type
,
3874 TYPE_TARGET_TYPE (this_type
),
3875 TYPE_FIELDS (this_type
),
3876 TYPE_NFIELDS (this_type
),
3877 TYPE_VARARGS (this_type
));
3879 /* Handle static member functions.
3880 Dwarf2 has no clean way to discern C++ static and non-static
3881 member functions. G++ helps GDB by marking the first
3882 parameter for non-static member functions (which is the
3883 this pointer) as artificial. We obtain this information
3884 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3885 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
3886 fnp
->voffset
= VOFFSET_STATIC
;
3889 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3892 /* Get fcontext from DW_AT_containing_type if present. */
3893 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3894 fnp
->fcontext
= die_containing_type (die
, cu
);
3896 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3897 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3899 /* Get accessibility. */
3900 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3903 switch (DW_UNSND (attr
))
3905 case DW_ACCESS_private
:
3906 fnp
->is_private
= 1;
3908 case DW_ACCESS_protected
:
3909 fnp
->is_protected
= 1;
3914 /* Check for artificial methods. */
3915 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3916 if (attr
&& DW_UNSND (attr
) != 0)
3917 fnp
->is_artificial
= 1;
3919 /* Get index in virtual function table if it is a virtual member function. */
3920 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3923 /* Support the .debug_loc offsets */
3924 if (attr_form_is_block (attr
))
3926 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3928 else if (attr_form_is_section_offset (attr
))
3930 dwarf2_complex_location_expr_complaint ();
3934 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3940 /* Create the vector of member function fields, and attach it to the type. */
3943 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3944 struct dwarf2_cu
*cu
)
3946 struct fnfieldlist
*flp
;
3947 int total_length
= 0;
3950 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3951 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3952 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3954 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3956 struct nextfnfield
*nfp
= flp
->head
;
3957 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3960 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3961 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3962 fn_flp
->fn_fields
= (struct fn_field
*)
3963 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3964 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3965 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3967 total_length
+= flp
->length
;
3970 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3971 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3974 /* Returns non-zero if NAME is the name of a vtable member in CU's
3975 language, zero otherwise. */
3977 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3979 static const char vptr
[] = "_vptr";
3980 static const char vtable
[] = "vtable";
3982 /* Look for the C++ and Java forms of the vtable. */
3983 if ((cu
->language
== language_java
3984 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3985 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3986 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3992 /* GCC outputs unnamed structures that are really pointers to member
3993 functions, with the ABI-specified layout. If DIE (from CU) describes
3994 such a structure, set its type, and return nonzero. Otherwise return
3997 GCC shouldn't do this; it should just output pointer to member DIEs.
3998 This is GCC PR debug/28767. */
4000 static struct type
*
4001 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4003 struct objfile
*objfile
= cu
->objfile
;
4005 struct die_info
*pfn_die
, *delta_die
;
4006 struct attribute
*pfn_name
, *delta_name
;
4007 struct type
*pfn_type
, *domain_type
;
4009 /* Check for a structure with no name and two children. */
4010 if (die
->tag
!= DW_TAG_structure_type
4011 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4012 || die
->child
== NULL
4013 || die
->child
->sibling
== NULL
4014 || (die
->child
->sibling
->sibling
!= NULL
4015 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4018 /* Check for __pfn and __delta members. */
4019 pfn_die
= die
->child
;
4020 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4021 if (pfn_die
->tag
!= DW_TAG_member
4023 || DW_STRING (pfn_name
) == NULL
4024 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4027 delta_die
= pfn_die
->sibling
;
4028 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4029 if (delta_die
->tag
!= DW_TAG_member
4030 || delta_name
== NULL
4031 || DW_STRING (delta_name
) == NULL
4032 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4035 /* Find the type of the method. */
4036 pfn_type
= die_type (pfn_die
, cu
);
4037 if (pfn_type
== NULL
4038 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4039 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4042 /* Look for the "this" argument. */
4043 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4044 if (TYPE_NFIELDS (pfn_type
) == 0
4045 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4048 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4049 type
= alloc_type (objfile
);
4050 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4051 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4052 TYPE_VARARGS (pfn_type
));
4053 type
= lookup_methodptr_type (type
);
4054 return set_die_type (die
, type
, cu
);
4057 /* Called when we find the DIE that starts a structure or union scope
4058 (definition) to process all dies that define the members of the
4061 NOTE: we need to call struct_type regardless of whether or not the
4062 DIE has an at_name attribute, since it might be an anonymous
4063 structure or union. This gets the type entered into our set of
4066 However, if the structure is incomplete (an opaque struct/union)
4067 then suppress creating a symbol table entry for it since gdb only
4068 wants to find the one with the complete definition. Note that if
4069 it is complete, we just call new_symbol, which does it's own
4070 checking about whether the struct/union is anonymous or not (and
4071 suppresses creating a symbol table entry itself). */
4073 static struct type
*
4074 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4076 struct objfile
*objfile
= cu
->objfile
;
4078 struct attribute
*attr
;
4080 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4082 type
= quirk_gcc_member_function_pointer (die
, cu
);
4086 type
= alloc_type (objfile
);
4087 INIT_CPLUS_SPECIFIC (type
);
4088 name
= dwarf2_name (die
, cu
);
4091 if (cu
->language
== language_cplus
4092 || cu
->language
== language_java
)
4094 const char *new_prefix
= determine_class_name (die
, cu
);
4095 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4099 /* The name is already allocated along with this objfile, so
4100 we don't need to duplicate it for the type. */
4101 TYPE_TAG_NAME (type
) = name
;
4105 if (die
->tag
== DW_TAG_structure_type
)
4107 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4109 else if (die
->tag
== DW_TAG_union_type
)
4111 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4115 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4117 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4120 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4123 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4127 TYPE_LENGTH (type
) = 0;
4130 TYPE_STUB_SUPPORTED (type
) = 1;
4131 if (die_is_declaration (die
, cu
))
4132 TYPE_STUB (type
) = 1;
4134 /* We need to add the type field to the die immediately so we don't
4135 infinitely recurse when dealing with pointers to the structure
4136 type within the structure itself. */
4137 set_die_type (die
, type
, cu
);
4139 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4141 struct field_info fi
;
4142 struct die_info
*child_die
;
4144 memset (&fi
, 0, sizeof (struct field_info
));
4146 child_die
= die
->child
;
4148 while (child_die
&& child_die
->tag
)
4150 if (child_die
->tag
== DW_TAG_member
4151 || child_die
->tag
== DW_TAG_variable
)
4153 /* NOTE: carlton/2002-11-05: A C++ static data member
4154 should be a DW_TAG_member that is a declaration, but
4155 all versions of G++ as of this writing (so through at
4156 least 3.2.1) incorrectly generate DW_TAG_variable
4157 tags for them instead. */
4158 dwarf2_add_field (&fi
, child_die
, cu
);
4160 else if (child_die
->tag
== DW_TAG_subprogram
)
4162 /* C++ member function. */
4163 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
;
4244 do_cleanups (back_to
);
4249 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4251 struct objfile
*objfile
= cu
->objfile
;
4252 struct die_info
*child_die
= die
->child
;
4253 struct type
*this_type
;
4255 this_type
= get_die_type (die
, cu
);
4256 if (this_type
== NULL
)
4257 this_type
= read_structure_type (die
, cu
);
4259 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4260 snapshots) has been known to create a die giving a declaration
4261 for a class that has, as a child, a die giving a definition for a
4262 nested class. So we have to process our children even if the
4263 current die is a declaration. Normally, of course, a declaration
4264 won't have any children at all. */
4266 while (child_die
!= NULL
&& child_die
->tag
)
4268 if (child_die
->tag
== DW_TAG_member
4269 || child_die
->tag
== DW_TAG_variable
4270 || child_die
->tag
== DW_TAG_inheritance
)
4275 process_die (child_die
, cu
);
4277 child_die
= sibling_die (child_die
);
4280 /* Do not consider external references. According to the DWARF standard,
4281 these DIEs are identified by the fact that they have no byte_size
4282 attribute, and a declaration attribute. */
4283 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4284 || !die_is_declaration (die
, cu
))
4285 new_symbol (die
, this_type
, cu
);
4288 /* Given a DW_AT_enumeration_type die, set its type. We do not
4289 complete the type's fields yet, or create any symbols. */
4291 static struct type
*
4292 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4294 struct objfile
*objfile
= cu
->objfile
;
4296 struct attribute
*attr
;
4299 type
= alloc_type (objfile
);
4301 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4302 name
= dwarf2_full_name (die
, cu
);
4304 TYPE_TAG_NAME (type
) = (char *) name
;
4306 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4309 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4313 TYPE_LENGTH (type
) = 0;
4316 /* The enumeration DIE can be incomplete. In Ada, any type can be
4317 declared as private in the package spec, and then defined only
4318 inside the package body. Such types are known as Taft Amendment
4319 Types. When another package uses such a type, an incomplete DIE
4320 may be generated by the compiler. */
4321 if (die_is_declaration (die
, cu
))
4322 TYPE_STUB (type
) = 1;
4324 return set_die_type (die
, type
, cu
);
4327 /* Determine the name of the type represented by DIE, which should be
4328 a named C++ or Java compound type. Return the name in question,
4329 allocated on the objfile obstack. */
4332 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4334 const char *new_prefix
= NULL
;
4336 /* If we don't have namespace debug info, guess the name by trying
4337 to demangle the names of members, just like we did in
4338 guess_structure_name. */
4339 if (!processing_has_namespace_info
)
4341 struct die_info
*child
;
4343 for (child
= die
->child
;
4344 child
!= NULL
&& child
->tag
!= 0;
4345 child
= sibling_die (child
))
4347 if (child
->tag
== DW_TAG_subprogram
)
4350 = language_class_name_from_physname (cu
->language_defn
,
4354 if (phys_prefix
!= NULL
)
4357 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4358 &cu
->objfile
->objfile_obstack
);
4359 xfree (phys_prefix
);
4366 if (new_prefix
== NULL
)
4367 new_prefix
= dwarf2_full_name (die
, cu
);
4372 /* Given a pointer to a die which begins an enumeration, process all
4373 the dies that define the members of the enumeration, and create the
4374 symbol for the enumeration type.
4376 NOTE: We reverse the order of the element list. */
4379 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4381 struct objfile
*objfile
= cu
->objfile
;
4382 struct die_info
*child_die
;
4383 struct field
*fields
;
4386 int unsigned_enum
= 1;
4388 struct type
*this_type
;
4392 this_type
= get_die_type (die
, cu
);
4393 if (this_type
== NULL
)
4394 this_type
= read_enumeration_type (die
, cu
);
4395 if (die
->child
!= NULL
)
4397 child_die
= die
->child
;
4398 while (child_die
&& child_die
->tag
)
4400 if (child_die
->tag
!= DW_TAG_enumerator
)
4402 process_die (child_die
, cu
);
4406 name
= dwarf2_name (child_die
, cu
);
4409 sym
= new_symbol (child_die
, this_type
, cu
);
4410 if (SYMBOL_VALUE (sym
) < 0)
4413 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4415 fields
= (struct field
*)
4417 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4418 * sizeof (struct field
));
4421 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4422 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4423 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4424 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4425 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4431 child_die
= sibling_die (child_die
);
4436 TYPE_NFIELDS (this_type
) = num_fields
;
4437 TYPE_FIELDS (this_type
) = (struct field
*)
4438 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4439 memcpy (TYPE_FIELDS (this_type
), fields
,
4440 sizeof (struct field
) * num_fields
);
4444 TYPE_UNSIGNED (this_type
) = 1;
4447 new_symbol (die
, this_type
, cu
);
4450 /* Extract all information from a DW_TAG_array_type DIE and put it in
4451 the DIE's type field. For now, this only handles one dimensional
4454 static struct type
*
4455 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4457 struct objfile
*objfile
= cu
->objfile
;
4458 struct die_info
*child_die
;
4459 struct type
*type
= NULL
;
4460 struct type
*element_type
, *range_type
, *index_type
;
4461 struct type
**range_types
= NULL
;
4462 struct attribute
*attr
;
4464 struct cleanup
*back_to
;
4467 element_type
= die_type (die
, cu
);
4469 /* Irix 6.2 native cc creates array types without children for
4470 arrays with unspecified length. */
4471 if (die
->child
== NULL
)
4473 index_type
= builtin_type_int32
;
4474 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4475 type
= create_array_type (NULL
, element_type
, range_type
);
4476 return set_die_type (die
, type
, cu
);
4479 back_to
= make_cleanup (null_cleanup
, NULL
);
4480 child_die
= die
->child
;
4481 while (child_die
&& child_die
->tag
)
4483 if (child_die
->tag
== DW_TAG_subrange_type
)
4485 struct type
*child_type
= read_type_die (child_die
, cu
);
4486 if (child_type
!= NULL
)
4488 /* The range type was succesfully read. Save it for
4489 the array type creation. */
4490 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4492 range_types
= (struct type
**)
4493 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4494 * sizeof (struct type
*));
4496 make_cleanup (free_current_contents
, &range_types
);
4498 range_types
[ndim
++] = child_type
;
4501 child_die
= sibling_die (child_die
);
4504 /* Dwarf2 dimensions are output from left to right, create the
4505 necessary array types in backwards order. */
4507 type
= element_type
;
4509 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4513 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4518 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4521 /* Understand Dwarf2 support for vector types (like they occur on
4522 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4523 array type. This is not part of the Dwarf2/3 standard yet, but a
4524 custom vendor extension. The main difference between a regular
4525 array and the vector variant is that vectors are passed by value
4527 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4529 make_vector_type (type
);
4531 name
= dwarf2_name (die
, cu
);
4533 TYPE_NAME (type
) = name
;
4535 do_cleanups (back_to
);
4537 /* Install the type in the die. */
4538 return set_die_type (die
, type
, cu
);
4541 static enum dwarf_array_dim_ordering
4542 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4544 struct attribute
*attr
;
4546 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4548 if (attr
) return DW_SND (attr
);
4551 GNU F77 is a special case, as at 08/2004 array type info is the
4552 opposite order to the dwarf2 specification, but data is still
4553 laid out as per normal fortran.
4555 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4559 if (cu
->language
== language_fortran
&&
4560 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4562 return DW_ORD_row_major
;
4565 switch (cu
->language_defn
->la_array_ordering
)
4567 case array_column_major
:
4568 return DW_ORD_col_major
;
4569 case array_row_major
:
4571 return DW_ORD_row_major
;
4575 /* Extract all information from a DW_TAG_set_type DIE and put it in
4576 the DIE's type field. */
4578 static struct type
*
4579 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4581 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4583 return set_die_type (die
, set_type
, cu
);
4586 /* First cut: install each common block member as a global variable. */
4589 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4591 struct die_info
*child_die
;
4592 struct attribute
*attr
;
4594 CORE_ADDR base
= (CORE_ADDR
) 0;
4596 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4599 /* Support the .debug_loc offsets */
4600 if (attr_form_is_block (attr
))
4602 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4604 else if (attr_form_is_section_offset (attr
))
4606 dwarf2_complex_location_expr_complaint ();
4610 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4611 "common block member");
4614 if (die
->child
!= NULL
)
4616 child_die
= die
->child
;
4617 while (child_die
&& child_die
->tag
)
4619 sym
= new_symbol (child_die
, NULL
, cu
);
4620 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4623 SYMBOL_VALUE_ADDRESS (sym
) =
4624 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4625 add_symbol_to_list (sym
, &global_symbols
);
4627 child_die
= sibling_die (child_die
);
4632 /* Create a type for a C++ namespace. */
4634 static struct type
*
4635 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4637 struct objfile
*objfile
= cu
->objfile
;
4638 const char *previous_prefix
, *name
;
4642 /* For extensions, reuse the type of the original namespace. */
4643 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4645 struct die_info
*ext_die
;
4646 struct dwarf2_cu
*ext_cu
= cu
;
4647 ext_die
= dwarf2_extension (die
, &ext_cu
);
4648 type
= read_type_die (ext_die
, ext_cu
);
4649 return set_die_type (die
, type
, cu
);
4652 name
= namespace_name (die
, &is_anonymous
, cu
);
4654 /* Now build the name of the current namespace. */
4656 previous_prefix
= determine_prefix (die
, cu
);
4657 if (previous_prefix
[0] != '\0')
4658 name
= typename_concat (&objfile
->objfile_obstack
,
4659 previous_prefix
, name
, cu
);
4661 /* Create the type. */
4662 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
4664 TYPE_NAME (type
) = (char *) name
;
4665 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4667 set_die_type (die
, type
, cu
);
4672 /* Read a C++ namespace. */
4675 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4677 struct objfile
*objfile
= cu
->objfile
;
4681 /* Add a symbol associated to this if we haven't seen the namespace
4682 before. Also, add a using directive if it's an anonymous
4685 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
4689 type
= read_type_die (die
, cu
);
4690 new_symbol (die
, type
, cu
);
4692 name
= namespace_name (die
, &is_anonymous
, cu
);
4695 const char *previous_prefix
= determine_prefix (die
, cu
);
4696 cp_add_using_directive (TYPE_NAME (type
),
4697 strlen (previous_prefix
),
4698 strlen (TYPE_NAME (type
)));
4702 if (die
->child
!= NULL
)
4704 struct die_info
*child_die
= die
->child
;
4706 while (child_die
&& child_die
->tag
)
4708 process_die (child_die
, cu
);
4709 child_die
= sibling_die (child_die
);
4714 /* Return the name of the namespace represented by DIE. Set
4715 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4719 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4721 struct die_info
*current_die
;
4722 const char *name
= NULL
;
4724 /* Loop through the extensions until we find a name. */
4726 for (current_die
= die
;
4727 current_die
!= NULL
;
4728 current_die
= dwarf2_extension (die
, &cu
))
4730 name
= dwarf2_name (current_die
, cu
);
4735 /* Is it an anonymous namespace? */
4737 *is_anonymous
= (name
== NULL
);
4739 name
= "(anonymous namespace)";
4744 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4745 the user defined type vector. */
4747 static struct type
*
4748 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4750 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
4751 struct comp_unit_head
*cu_header
= &cu
->header
;
4753 struct attribute
*attr_byte_size
;
4754 struct attribute
*attr_address_class
;
4755 int byte_size
, addr_class
;
4757 type
= lookup_pointer_type (die_type (die
, cu
));
4759 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4761 byte_size
= DW_UNSND (attr_byte_size
);
4763 byte_size
= cu_header
->addr_size
;
4765 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4766 if (attr_address_class
)
4767 addr_class
= DW_UNSND (attr_address_class
);
4769 addr_class
= DW_ADDR_none
;
4771 /* If the pointer size or address class is different than the
4772 default, create a type variant marked as such and set the
4773 length accordingly. */
4774 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4776 if (gdbarch_address_class_type_flags_p (gdbarch
))
4780 type_flags
= gdbarch_address_class_type_flags
4781 (gdbarch
, byte_size
, addr_class
);
4782 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
4784 type
= make_type_with_address_space (type
, type_flags
);
4786 else if (TYPE_LENGTH (type
) != byte_size
)
4788 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4791 /* Should we also complain about unhandled address classes? */
4795 TYPE_LENGTH (type
) = byte_size
;
4796 return set_die_type (die
, type
, cu
);
4799 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4800 the user defined type vector. */
4802 static struct type
*
4803 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4805 struct objfile
*objfile
= cu
->objfile
;
4807 struct type
*to_type
;
4808 struct type
*domain
;
4810 to_type
= die_type (die
, cu
);
4811 domain
= die_containing_type (die
, cu
);
4813 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4814 type
= lookup_methodptr_type (to_type
);
4816 type
= lookup_memberptr_type (to_type
, domain
);
4818 return set_die_type (die
, type
, cu
);
4821 /* Extract all information from a DW_TAG_reference_type DIE and add to
4822 the user defined type vector. */
4824 static struct type
*
4825 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4827 struct comp_unit_head
*cu_header
= &cu
->header
;
4829 struct attribute
*attr
;
4831 type
= lookup_reference_type (die_type (die
, cu
));
4832 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4835 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4839 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4841 return set_die_type (die
, type
, cu
);
4844 static struct type
*
4845 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4847 struct type
*base_type
, *cv_type
;
4849 base_type
= die_type (die
, cu
);
4850 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
4851 return set_die_type (die
, cv_type
, cu
);
4854 static struct type
*
4855 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4857 struct type
*base_type
, *cv_type
;
4859 base_type
= die_type (die
, cu
);
4860 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
4861 return set_die_type (die
, cv_type
, cu
);
4864 /* Extract all information from a DW_TAG_string_type DIE and add to
4865 the user defined type vector. It isn't really a user defined type,
4866 but it behaves like one, with other DIE's using an AT_user_def_type
4867 attribute to reference it. */
4869 static struct type
*
4870 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4872 struct objfile
*objfile
= cu
->objfile
;
4873 struct type
*type
, *range_type
, *index_type
, *char_type
;
4874 struct attribute
*attr
;
4875 unsigned int length
;
4877 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4880 length
= DW_UNSND (attr
);
4884 /* check for the DW_AT_byte_size attribute */
4885 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4888 length
= DW_UNSND (attr
);
4896 index_type
= builtin_type_int32
;
4897 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4898 type
= create_string_type (NULL
, range_type
);
4900 return set_die_type (die
, type
, cu
);
4903 /* Handle DIES due to C code like:
4907 int (*funcp)(int a, long l);
4911 ('funcp' generates a DW_TAG_subroutine_type DIE)
4914 static struct type
*
4915 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4917 struct type
*type
; /* Type that this function returns */
4918 struct type
*ftype
; /* Function that returns above type */
4919 struct attribute
*attr
;
4921 type
= die_type (die
, cu
);
4922 ftype
= make_function_type (type
, (struct type
**) 0);
4924 /* All functions in C++, Pascal and Java have prototypes. */
4925 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4926 if ((attr
&& (DW_UNSND (attr
) != 0))
4927 || cu
->language
== language_cplus
4928 || cu
->language
== language_java
4929 || cu
->language
== language_pascal
)
4930 TYPE_PROTOTYPED (ftype
) = 1;
4932 /* Store the calling convention in the type if it's available in
4933 the subroutine die. Otherwise set the calling convention to
4934 the default value DW_CC_normal. */
4935 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
4936 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
4938 if (die
->child
!= NULL
)
4940 struct die_info
*child_die
;
4944 /* Count the number of parameters.
4945 FIXME: GDB currently ignores vararg functions, but knows about
4946 vararg member functions. */
4947 child_die
= die
->child
;
4948 while (child_die
&& child_die
->tag
)
4950 if (child_die
->tag
== DW_TAG_formal_parameter
)
4952 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4953 TYPE_VARARGS (ftype
) = 1;
4954 child_die
= sibling_die (child_die
);
4957 /* Allocate storage for parameters and fill them in. */
4958 TYPE_NFIELDS (ftype
) = nparams
;
4959 TYPE_FIELDS (ftype
) = (struct field
*)
4960 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4962 child_die
= die
->child
;
4963 while (child_die
&& child_die
->tag
)
4965 if (child_die
->tag
== DW_TAG_formal_parameter
)
4967 /* Dwarf2 has no clean way to discern C++ static and non-static
4968 member functions. G++ helps GDB by marking the first
4969 parameter for non-static member functions (which is the
4970 this pointer) as artificial. We pass this information
4971 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4972 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4974 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4976 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4977 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4980 child_die
= sibling_die (child_die
);
4984 return set_die_type (die
, ftype
, cu
);
4987 static struct type
*
4988 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4990 struct objfile
*objfile
= cu
->objfile
;
4991 struct attribute
*attr
;
4992 const char *name
= NULL
;
4993 struct type
*this_type
;
4995 name
= dwarf2_full_name (die
, cu
);
4996 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
4997 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
4998 TYPE_NAME (this_type
) = (char *) name
;
4999 set_die_type (die
, this_type
, cu
);
5000 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5004 /* Find a representation of a given base type and install
5005 it in the TYPE field of the die. */
5007 static struct type
*
5008 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5010 struct objfile
*objfile
= cu
->objfile
;
5012 struct attribute
*attr
;
5013 int encoding
= 0, size
= 0;
5015 enum type_code code
= TYPE_CODE_INT
;
5017 struct type
*target_type
= NULL
;
5019 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5022 encoding
= DW_UNSND (attr
);
5024 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5027 size
= DW_UNSND (attr
);
5029 name
= dwarf2_name (die
, cu
);
5032 complaint (&symfile_complaints
,
5033 _("DW_AT_name missing from DW_TAG_base_type"));
5038 case DW_ATE_address
:
5039 /* Turn DW_ATE_address into a void * pointer. */
5040 code
= TYPE_CODE_PTR
;
5041 type_flags
|= TYPE_FLAG_UNSIGNED
;
5042 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5044 case DW_ATE_boolean
:
5045 code
= TYPE_CODE_BOOL
;
5046 type_flags
|= TYPE_FLAG_UNSIGNED
;
5048 case DW_ATE_complex_float
:
5049 code
= TYPE_CODE_COMPLEX
;
5050 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5052 case DW_ATE_decimal_float
:
5053 code
= TYPE_CODE_DECFLOAT
;
5056 code
= TYPE_CODE_FLT
;
5060 case DW_ATE_unsigned
:
5061 type_flags
|= TYPE_FLAG_UNSIGNED
;
5063 case DW_ATE_signed_char
:
5064 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5065 code
= TYPE_CODE_CHAR
;
5067 case DW_ATE_unsigned_char
:
5068 if (cu
->language
== language_ada
|| cu
->language
== language_m2
)
5069 code
= TYPE_CODE_CHAR
;
5070 type_flags
|= TYPE_FLAG_UNSIGNED
;
5073 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5074 dwarf_type_encoding_name (encoding
));
5078 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5079 TYPE_NAME (type
) = name
;
5080 TYPE_TARGET_TYPE (type
) = target_type
;
5082 if (name
&& strcmp (name
, "char") == 0)
5083 TYPE_NOSIGN (type
) = 1;
5085 return set_die_type (die
, type
, cu
);
5088 /* Read the given DW_AT_subrange DIE. */
5090 static struct type
*
5091 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5093 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5094 struct type
*base_type
;
5095 struct type
*range_type
;
5096 struct attribute
*attr
;
5101 base_type
= die_type (die
, cu
);
5102 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5104 complaint (&symfile_complaints
,
5105 _("DW_AT_type missing from DW_TAG_subrange_type"));
5107 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5108 0, NULL
, cu
->objfile
);
5111 if (cu
->language
== language_fortran
)
5113 /* FORTRAN implies a lower bound of 1, if not given. */
5117 /* FIXME: For variable sized arrays either of these could be
5118 a variable rather than a constant value. We'll allow it,
5119 but we don't know how to handle it. */
5120 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5122 low
= dwarf2_get_attr_constant_value (attr
, 0);
5124 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5127 if (attr
->form
== DW_FORM_block1
)
5129 /* GCC encodes arrays with unspecified or dynamic length
5130 with a DW_FORM_block1 attribute.
5131 FIXME: GDB does not yet know how to handle dynamic
5132 arrays properly, treat them as arrays with unspecified
5135 FIXME: jimb/2003-09-22: GDB does not really know
5136 how to handle arrays of unspecified length
5137 either; we just represent them as zero-length
5138 arrays. Choose an appropriate upper bound given
5139 the lower bound we've computed above. */
5143 high
= dwarf2_get_attr_constant_value (attr
, 1);
5146 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5148 name
= dwarf2_name (die
, cu
);
5150 TYPE_NAME (range_type
) = name
;
5152 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5154 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5156 return set_die_type (die
, range_type
, cu
);
5159 static struct type
*
5160 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5164 /* For now, we only support the C meaning of an unspecified type: void. */
5166 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5167 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5169 return set_die_type (die
, type
, cu
);
5172 /* Trivial hash function for die_info: the hash value of a DIE
5173 is its offset in .debug_info for this objfile. */
5176 die_hash (const void *item
)
5178 const struct die_info
*die
= item
;
5182 /* Trivial comparison function for die_info structures: two DIEs
5183 are equal if they have the same offset. */
5186 die_eq (const void *item_lhs
, const void *item_rhs
)
5188 const struct die_info
*die_lhs
= item_lhs
;
5189 const struct die_info
*die_rhs
= item_rhs
;
5190 return die_lhs
->offset
== die_rhs
->offset
;
5193 /* Read a whole compilation unit into a linked list of dies. */
5195 static struct die_info
*
5196 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5199 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5203 &cu
->comp_unit_obstack
,
5204 hashtab_obstack_allocate
,
5205 dummy_obstack_deallocate
);
5207 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5210 /* Read a single die and all its descendents. Set the die's sibling
5211 field to NULL; set other fields in the die correctly, and set all
5212 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5213 location of the info_ptr after reading all of those dies. PARENT
5214 is the parent of the die in question. */
5216 static struct die_info
*
5217 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5218 struct dwarf2_cu
*cu
,
5219 gdb_byte
**new_info_ptr
,
5220 struct die_info
*parent
)
5222 struct die_info
*die
;
5226 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5229 *new_info_ptr
= cur_ptr
;
5232 store_in_ref_table (die
, cu
);
5236 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5242 *new_info_ptr
= cur_ptr
;
5245 die
->sibling
= NULL
;
5246 die
->parent
= parent
;
5250 /* Read a die, all of its descendents, and all of its siblings; set
5251 all of the fields of all of the dies correctly. Arguments are as
5252 in read_die_and_children. */
5254 static struct die_info
*
5255 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5256 struct dwarf2_cu
*cu
,
5257 gdb_byte
**new_info_ptr
,
5258 struct die_info
*parent
)
5260 struct die_info
*first_die
, *last_sibling
;
5264 first_die
= last_sibling
= NULL
;
5268 struct die_info
*die
5269 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5273 *new_info_ptr
= cur_ptr
;
5280 last_sibling
->sibling
= die
;
5286 /* Decompress a section that was compressed using zlib. Store the
5287 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5290 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
5291 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
5293 bfd
*abfd
= objfile
->obfd
;
5295 error (_("Support for zlib-compressed DWARF data (from '%s') "
5296 "is disabled in this copy of GDB"),
5297 bfd_get_filename (abfd
));
5299 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
5300 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
5301 bfd_size_type uncompressed_size
;
5302 gdb_byte
*uncompressed_buffer
;
5305 int header_size
= 12;
5307 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5308 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
5309 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5310 bfd_get_filename (abfd
));
5312 /* Read the zlib header. In this case, it should be "ZLIB" followed
5313 by the uncompressed section size, 8 bytes in big-endian order. */
5314 if (compressed_size
< header_size
5315 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
5316 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
5317 bfd_get_filename (abfd
));
5318 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
5319 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
5320 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
5321 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
5322 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
5323 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
5324 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
5325 uncompressed_size
+= compressed_buffer
[11];
5327 /* It is possible the section consists of several compressed
5328 buffers concatenated together, so we uncompress in a loop. */
5332 strm
.avail_in
= compressed_size
- header_size
;
5333 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
5334 strm
.avail_out
= uncompressed_size
;
5335 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
5337 rc
= inflateInit (&strm
);
5338 while (strm
.avail_in
> 0)
5341 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
5342 bfd_get_filename (abfd
), rc
);
5343 strm
.next_out
= ((Bytef
*) uncompressed_buffer
5344 + (uncompressed_size
- strm
.avail_out
));
5345 rc
= inflate (&strm
, Z_FINISH
);
5346 if (rc
!= Z_STREAM_END
)
5347 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
5348 bfd_get_filename (abfd
), rc
);
5349 rc
= inflateReset (&strm
);
5351 rc
= inflateEnd (&strm
);
5353 || strm
.avail_out
!= 0)
5354 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5355 bfd_get_filename (abfd
), rc
);
5357 xfree (compressed_buffer
);
5358 *outbuf
= uncompressed_buffer
;
5359 *outsize
= uncompressed_size
;
5364 /* Read the contents of the section at OFFSET and of size SIZE from the
5365 object file specified by OBJFILE into the objfile_obstack and return it.
5366 If the section is compressed, uncompress it before returning. */
5369 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5371 bfd
*abfd
= objfile
->obfd
;
5372 gdb_byte
*buf
, *retbuf
;
5373 bfd_size_type size
= bfd_get_section_size (sectp
);
5374 unsigned char header
[4];
5379 /* Check if the file has a 4-byte header indicating compression. */
5380 if (size
> sizeof (header
)
5381 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
5382 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
5384 /* Upon decompression, update the buffer and its size. */
5385 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
5387 zlib_decompress_section (objfile
, sectp
, &buf
, &size
);
5388 dwarf2_resize_section (sectp
, size
);
5393 /* If we get here, we are a normal, not-compressed section. */
5394 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5395 /* When debugging .o files, we may need to apply relocations; see
5396 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5397 We never compress sections in .o files, so we only need to
5398 try this when the section is not compressed. */
5399 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5403 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5404 || bfd_bread (buf
, size
, abfd
) != size
)
5405 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5406 bfd_get_filename (abfd
));
5411 /* In DWARF version 2, the description of the debugging information is
5412 stored in a separate .debug_abbrev section. Before we read any
5413 dies from a section we read in all abbreviations and install them
5414 in a hash table. This function also sets flags in CU describing
5415 the data found in the abbrev table. */
5418 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5420 struct comp_unit_head
*cu_header
= &cu
->header
;
5421 gdb_byte
*abbrev_ptr
;
5422 struct abbrev_info
*cur_abbrev
;
5423 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5424 unsigned int abbrev_form
, hash_number
;
5425 struct attr_abbrev
*cur_attrs
;
5426 unsigned int allocated_attrs
;
5428 /* Initialize dwarf2 abbrevs */
5429 obstack_init (&cu
->abbrev_obstack
);
5430 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5432 * sizeof (struct abbrev_info
*)));
5433 memset (cu
->dwarf2_abbrevs
, 0,
5434 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5436 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5437 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5438 abbrev_ptr
+= bytes_read
;
5440 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5441 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5443 /* loop until we reach an abbrev number of 0 */
5444 while (abbrev_number
)
5446 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5448 /* read in abbrev header */
5449 cur_abbrev
->number
= abbrev_number
;
5450 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5451 abbrev_ptr
+= bytes_read
;
5452 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5455 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5456 cu
->has_namespace_info
= 1;
5458 /* now read in declarations */
5459 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5460 abbrev_ptr
+= bytes_read
;
5461 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5462 abbrev_ptr
+= bytes_read
;
5465 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5467 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5469 = xrealloc (cur_attrs
, (allocated_attrs
5470 * sizeof (struct attr_abbrev
)));
5473 /* Record whether this compilation unit might have
5474 inter-compilation-unit references. If we don't know what form
5475 this attribute will have, then it might potentially be a
5476 DW_FORM_ref_addr, so we conservatively expect inter-CU
5479 if (abbrev_form
== DW_FORM_ref_addr
5480 || abbrev_form
== DW_FORM_indirect
)
5481 cu
->has_form_ref_addr
= 1;
5483 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5484 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5485 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5486 abbrev_ptr
+= bytes_read
;
5487 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5488 abbrev_ptr
+= bytes_read
;
5491 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5492 (cur_abbrev
->num_attrs
5493 * sizeof (struct attr_abbrev
)));
5494 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5495 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5497 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5498 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5499 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5501 /* Get next abbreviation.
5502 Under Irix6 the abbreviations for a compilation unit are not
5503 always properly terminated with an abbrev number of 0.
5504 Exit loop if we encounter an abbreviation which we have
5505 already read (which means we are about to read the abbreviations
5506 for the next compile unit) or if the end of the abbreviation
5507 table is reached. */
5508 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5509 >= dwarf2_per_objfile
->abbrev_size
)
5511 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5512 abbrev_ptr
+= bytes_read
;
5513 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5520 /* Release the memory used by the abbrev table for a compilation unit. */
5523 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5525 struct dwarf2_cu
*cu
= ptr_to_cu
;
5527 obstack_free (&cu
->abbrev_obstack
, NULL
);
5528 cu
->dwarf2_abbrevs
= NULL
;
5531 /* Lookup an abbrev_info structure in the abbrev hash table. */
5533 static struct abbrev_info
*
5534 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5536 unsigned int hash_number
;
5537 struct abbrev_info
*abbrev
;
5539 hash_number
= number
% ABBREV_HASH_SIZE
;
5540 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5544 if (abbrev
->number
== number
)
5547 abbrev
= abbrev
->next
;
5552 /* Returns nonzero if TAG represents a type that we might generate a partial
5556 is_type_tag_for_partial (int tag
)
5561 /* Some types that would be reasonable to generate partial symbols for,
5562 that we don't at present. */
5563 case DW_TAG_array_type
:
5564 case DW_TAG_file_type
:
5565 case DW_TAG_ptr_to_member_type
:
5566 case DW_TAG_set_type
:
5567 case DW_TAG_string_type
:
5568 case DW_TAG_subroutine_type
:
5570 case DW_TAG_base_type
:
5571 case DW_TAG_class_type
:
5572 case DW_TAG_interface_type
:
5573 case DW_TAG_enumeration_type
:
5574 case DW_TAG_structure_type
:
5575 case DW_TAG_subrange_type
:
5576 case DW_TAG_typedef
:
5577 case DW_TAG_union_type
:
5584 /* Load all DIEs that are interesting for partial symbols into memory. */
5586 static struct partial_die_info
*
5587 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5588 struct dwarf2_cu
*cu
)
5590 struct partial_die_info
*part_die
;
5591 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5592 struct abbrev_info
*abbrev
;
5593 unsigned int bytes_read
;
5594 unsigned int load_all
= 0;
5596 int nesting_level
= 1;
5601 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5605 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5609 &cu
->comp_unit_obstack
,
5610 hashtab_obstack_allocate
,
5611 dummy_obstack_deallocate
);
5613 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5614 sizeof (struct partial_die_info
));
5618 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5620 /* A NULL abbrev means the end of a series of children. */
5623 if (--nesting_level
== 0)
5625 /* PART_DIE was probably the last thing allocated on the
5626 comp_unit_obstack, so we could call obstack_free
5627 here. We don't do that because the waste is small,
5628 and will be cleaned up when we're done with this
5629 compilation unit. This way, we're also more robust
5630 against other users of the comp_unit_obstack. */
5633 info_ptr
+= bytes_read
;
5634 last_die
= parent_die
;
5635 parent_die
= parent_die
->die_parent
;
5639 /* Check whether this DIE is interesting enough to save. Normally
5640 we would not be interested in members here, but there may be
5641 later variables referencing them via DW_AT_specification (for
5644 && !is_type_tag_for_partial (abbrev
->tag
)
5645 && abbrev
->tag
!= DW_TAG_enumerator
5646 && abbrev
->tag
!= DW_TAG_subprogram
5647 && abbrev
->tag
!= DW_TAG_lexical_block
5648 && abbrev
->tag
!= DW_TAG_variable
5649 && abbrev
->tag
!= DW_TAG_namespace
5650 && abbrev
->tag
!= DW_TAG_member
)
5652 /* Otherwise we skip to the next sibling, if any. */
5653 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5657 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5658 abfd
, info_ptr
, cu
);
5660 /* This two-pass algorithm for processing partial symbols has a
5661 high cost in cache pressure. Thus, handle some simple cases
5662 here which cover the majority of C partial symbols. DIEs
5663 which neither have specification tags in them, nor could have
5664 specification tags elsewhere pointing at them, can simply be
5665 processed and discarded.
5667 This segment is also optional; scan_partial_symbols and
5668 add_partial_symbol will handle these DIEs if we chain
5669 them in normally. When compilers which do not emit large
5670 quantities of duplicate debug information are more common,
5671 this code can probably be removed. */
5673 /* Any complete simple types at the top level (pretty much all
5674 of them, for a language without namespaces), can be processed
5676 if (parent_die
== NULL
5677 && part_die
->has_specification
== 0
5678 && part_die
->is_declaration
== 0
5679 && (part_die
->tag
== DW_TAG_typedef
5680 || part_die
->tag
== DW_TAG_base_type
5681 || part_die
->tag
== DW_TAG_subrange_type
))
5683 if (building_psymtab
&& part_die
->name
!= NULL
)
5684 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5685 VAR_DOMAIN
, LOC_TYPEDEF
,
5686 &cu
->objfile
->static_psymbols
,
5687 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5688 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5692 /* If we're at the second level, and we're an enumerator, and
5693 our parent has no specification (meaning possibly lives in a
5694 namespace elsewhere), then we can add the partial symbol now
5695 instead of queueing it. */
5696 if (part_die
->tag
== DW_TAG_enumerator
5697 && parent_die
!= NULL
5698 && parent_die
->die_parent
== NULL
5699 && parent_die
->tag
== DW_TAG_enumeration_type
5700 && parent_die
->has_specification
== 0)
5702 if (part_die
->name
== NULL
)
5703 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5704 else if (building_psymtab
)
5705 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5706 VAR_DOMAIN
, LOC_CONST
,
5707 (cu
->language
== language_cplus
5708 || cu
->language
== language_java
)
5709 ? &cu
->objfile
->global_psymbols
5710 : &cu
->objfile
->static_psymbols
,
5711 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5713 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5717 /* We'll save this DIE so link it in. */
5718 part_die
->die_parent
= parent_die
;
5719 part_die
->die_sibling
= NULL
;
5720 part_die
->die_child
= NULL
;
5722 if (last_die
&& last_die
== parent_die
)
5723 last_die
->die_child
= part_die
;
5725 last_die
->die_sibling
= part_die
;
5727 last_die
= part_die
;
5729 if (first_die
== NULL
)
5730 first_die
= part_die
;
5732 /* Maybe add the DIE to the hash table. Not all DIEs that we
5733 find interesting need to be in the hash table, because we
5734 also have the parent/sibling/child chains; only those that we
5735 might refer to by offset later during partial symbol reading.
5737 For now this means things that might have be the target of a
5738 DW_AT_specification, DW_AT_abstract_origin, or
5739 DW_AT_extension. DW_AT_extension will refer only to
5740 namespaces; DW_AT_abstract_origin refers to functions (and
5741 many things under the function DIE, but we do not recurse
5742 into function DIEs during partial symbol reading) and
5743 possibly variables as well; DW_AT_specification refers to
5744 declarations. Declarations ought to have the DW_AT_declaration
5745 flag. It happens that GCC forgets to put it in sometimes, but
5746 only for functions, not for types.
5748 Adding more things than necessary to the hash table is harmless
5749 except for the performance cost. Adding too few will result in
5750 wasted time in find_partial_die, when we reread the compilation
5751 unit with load_all_dies set. */
5754 || abbrev
->tag
== DW_TAG_subprogram
5755 || abbrev
->tag
== DW_TAG_variable
5756 || abbrev
->tag
== DW_TAG_namespace
5757 || part_die
->is_declaration
)
5761 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5762 part_die
->offset
, INSERT
);
5766 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5767 sizeof (struct partial_die_info
));
5769 /* For some DIEs we want to follow their children (if any). For C
5770 we have no reason to follow the children of structures; for other
5771 languages we have to, both so that we can get at method physnames
5772 to infer fully qualified class names, and for DW_AT_specification.
5774 For Ada, we need to scan the children of subprograms and lexical
5775 blocks as well because Ada allows the definition of nested
5776 entities that could be interesting for the debugger, such as
5777 nested subprograms for instance. */
5778 if (last_die
->has_children
5780 || last_die
->tag
== DW_TAG_namespace
5781 || last_die
->tag
== DW_TAG_enumeration_type
5782 || (cu
->language
!= language_c
5783 && (last_die
->tag
== DW_TAG_class_type
5784 || last_die
->tag
== DW_TAG_interface_type
5785 || last_die
->tag
== DW_TAG_structure_type
5786 || last_die
->tag
== DW_TAG_union_type
))
5787 || (cu
->language
== language_ada
5788 && (last_die
->tag
== DW_TAG_subprogram
5789 || last_die
->tag
== DW_TAG_lexical_block
))))
5792 parent_die
= last_die
;
5796 /* Otherwise we skip to the next sibling, if any. */
5797 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5799 /* Back to the top, do it again. */
5803 /* Read a minimal amount of information into the minimal die structure. */
5806 read_partial_die (struct partial_die_info
*part_die
,
5807 struct abbrev_info
*abbrev
,
5808 unsigned int abbrev_len
, bfd
*abfd
,
5809 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5811 unsigned int bytes_read
, i
;
5812 struct attribute attr
;
5813 int has_low_pc_attr
= 0;
5814 int has_high_pc_attr
= 0;
5815 CORE_ADDR base_address
= 0;
5819 base_address_low_pc
,
5820 /* Overrides BASE_ADDRESS_LOW_PC. */
5821 base_address_entry_pc
5823 base_address_type
= base_address_none
;
5825 memset (part_die
, 0, sizeof (struct partial_die_info
));
5827 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5829 info_ptr
+= abbrev_len
;
5834 part_die
->tag
= abbrev
->tag
;
5835 part_die
->has_children
= abbrev
->has_children
;
5837 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5839 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5841 /* Store the data if it is of an attribute we want to keep in a
5842 partial symbol table. */
5847 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5848 if (part_die
->name
== NULL
)
5849 part_die
->name
= DW_STRING (&attr
);
5851 case DW_AT_comp_dir
:
5852 if (part_die
->dirname
== NULL
)
5853 part_die
->dirname
= DW_STRING (&attr
);
5855 case DW_AT_MIPS_linkage_name
:
5856 part_die
->name
= DW_STRING (&attr
);
5859 has_low_pc_attr
= 1;
5860 part_die
->lowpc
= DW_ADDR (&attr
);
5861 if (part_die
->tag
== DW_TAG_compile_unit
5862 && base_address_type
< base_address_low_pc
)
5864 base_address
= DW_ADDR (&attr
);
5865 base_address_type
= base_address_low_pc
;
5869 has_high_pc_attr
= 1;
5870 part_die
->highpc
= DW_ADDR (&attr
);
5872 case DW_AT_entry_pc
:
5873 if (part_die
->tag
== DW_TAG_compile_unit
5874 && base_address_type
< base_address_entry_pc
)
5876 base_address
= DW_ADDR (&attr
);
5877 base_address_type
= base_address_entry_pc
;
5881 if (part_die
->tag
== DW_TAG_compile_unit
)
5883 cu
->ranges_offset
= DW_UNSND (&attr
);
5884 cu
->has_ranges_offset
= 1;
5887 case DW_AT_location
:
5888 /* Support the .debug_loc offsets */
5889 if (attr_form_is_block (&attr
))
5891 part_die
->locdesc
= DW_BLOCK (&attr
);
5893 else if (attr_form_is_section_offset (&attr
))
5895 dwarf2_complex_location_expr_complaint ();
5899 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5900 "partial symbol information");
5903 case DW_AT_language
:
5904 part_die
->language
= DW_UNSND (&attr
);
5906 case DW_AT_external
:
5907 part_die
->is_external
= DW_UNSND (&attr
);
5909 case DW_AT_declaration
:
5910 part_die
->is_declaration
= DW_UNSND (&attr
);
5913 part_die
->has_type
= 1;
5915 case DW_AT_abstract_origin
:
5916 case DW_AT_specification
:
5917 case DW_AT_extension
:
5918 part_die
->has_specification
= 1;
5919 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5922 /* Ignore absolute siblings, they might point outside of
5923 the current compile unit. */
5924 if (attr
.form
== DW_FORM_ref_addr
)
5925 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5927 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5928 + dwarf2_get_ref_die_offset (&attr
, cu
);
5930 case DW_AT_stmt_list
:
5931 part_die
->has_stmt_list
= 1;
5932 part_die
->line_offset
= DW_UNSND (&attr
);
5934 case DW_AT_byte_size
:
5935 part_die
->has_byte_size
= 1;
5937 case DW_AT_calling_convention
:
5938 /* DWARF doesn't provide a way to identify a program's source-level
5939 entry point. DW_AT_calling_convention attributes are only meant
5940 to describe functions' calling conventions.
5942 However, because it's a necessary piece of information in
5943 Fortran, and because DW_CC_program is the only piece of debugging
5944 information whose definition refers to a 'main program' at all,
5945 several compilers have begun marking Fortran main programs with
5946 DW_CC_program --- even when those functions use the standard
5947 calling conventions.
5949 So until DWARF specifies a way to provide this information and
5950 compilers pick up the new representation, we'll support this
5952 if (DW_UNSND (&attr
) == DW_CC_program
5953 && cu
->language
== language_fortran
)
5954 set_main_name (part_die
->name
);
5961 /* When using the GNU linker, .gnu.linkonce. sections are used to
5962 eliminate duplicate copies of functions and vtables and such.
5963 The linker will arbitrarily choose one and discard the others.
5964 The AT_*_pc values for such functions refer to local labels in
5965 these sections. If the section from that file was discarded, the
5966 labels are not in the output, so the relocs get a value of 0.
5967 If this is a discarded function, mark the pc bounds as invalid,
5968 so that GDB will ignore it. */
5969 if (has_low_pc_attr
&& has_high_pc_attr
5970 && part_die
->lowpc
< part_die
->highpc
5971 && (part_die
->lowpc
!= 0
5972 || dwarf2_per_objfile
->has_section_at_zero
))
5973 part_die
->has_pc_info
= 1;
5975 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
5977 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
5979 cu
->base_address
= base_address
;
5985 /* Find a cached partial DIE at OFFSET in CU. */
5987 static struct partial_die_info
*
5988 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5990 struct partial_die_info
*lookup_die
= NULL
;
5991 struct partial_die_info part_die
;
5993 part_die
.offset
= offset
;
5994 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5999 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6001 static struct partial_die_info
*
6002 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
6004 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6005 struct partial_die_info
*pd
= NULL
;
6007 if (offset_in_cu_p (&cu
->header
, offset
))
6009 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6014 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6016 if (per_cu
->cu
== NULL
)
6018 load_comp_unit (per_cu
, cu
->objfile
);
6019 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6020 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6023 per_cu
->cu
->last_used
= 0;
6024 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6026 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6028 struct cleanup
*back_to
;
6029 struct partial_die_info comp_unit_die
;
6030 struct abbrev_info
*abbrev
;
6031 unsigned int bytes_read
;
6034 per_cu
->load_all_dies
= 1;
6036 /* Re-read the DIEs. */
6037 back_to
= make_cleanup (null_cleanup
, 0);
6038 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6040 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6041 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6043 info_ptr
= (dwarf2_per_objfile
->info_buffer
6044 + per_cu
->cu
->header
.offset
6045 + per_cu
->cu
->header
.first_die_offset
);
6046 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6047 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6048 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6050 if (comp_unit_die
.has_children
)
6051 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6052 do_cleanups (back_to
);
6054 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6058 internal_error (__FILE__
, __LINE__
,
6059 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
6060 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6064 /* Adjust PART_DIE before generating a symbol for it. This function
6065 may set the is_external flag or change the DIE's name. */
6068 fixup_partial_die (struct partial_die_info
*part_die
,
6069 struct dwarf2_cu
*cu
)
6071 /* If we found a reference attribute and the DIE has no name, try
6072 to find a name in the referred to DIE. */
6074 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6076 struct partial_die_info
*spec_die
;
6078 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6080 fixup_partial_die (spec_die
, cu
);
6084 part_die
->name
= spec_die
->name
;
6086 /* Copy DW_AT_external attribute if it is set. */
6087 if (spec_die
->is_external
)
6088 part_die
->is_external
= spec_die
->is_external
;
6092 /* Set default names for some unnamed DIEs. */
6093 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6094 || part_die
->tag
== DW_TAG_class_type
))
6095 part_die
->name
= "(anonymous class)";
6097 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6098 part_die
->name
= "(anonymous namespace)";
6100 if (part_die
->tag
== DW_TAG_structure_type
6101 || part_die
->tag
== DW_TAG_class_type
6102 || part_die
->tag
== DW_TAG_union_type
)
6103 guess_structure_name (part_die
, cu
);
6106 /* Read the die from the .debug_info section buffer. Set DIEP to
6107 point to a newly allocated die with its information, except for its
6108 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6109 whether the die has children or not. */
6112 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6113 struct dwarf2_cu
*cu
, int *has_children
)
6115 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6116 struct abbrev_info
*abbrev
;
6117 struct die_info
*die
;
6119 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
6120 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6121 info_ptr
+= bytes_read
;
6129 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6132 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6134 bfd_get_filename (abfd
));
6136 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6137 die
->offset
= offset
;
6138 die
->tag
= abbrev
->tag
;
6139 die
->abbrev
= abbrev_number
;
6141 die
->num_attrs
= abbrev
->num_attrs
;
6143 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6144 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6145 abfd
, info_ptr
, cu
);
6148 *has_children
= abbrev
->has_children
;
6152 /* Read an attribute value described by an attribute form. */
6155 read_attribute_value (struct attribute
*attr
, unsigned form
,
6156 bfd
*abfd
, gdb_byte
*info_ptr
,
6157 struct dwarf2_cu
*cu
)
6159 struct comp_unit_head
*cu_header
= &cu
->header
;
6160 unsigned int bytes_read
;
6161 struct dwarf_block
*blk
;
6167 case DW_FORM_ref_addr
:
6168 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6169 info_ptr
+= bytes_read
;
6171 case DW_FORM_block2
:
6172 blk
= dwarf_alloc_block (cu
);
6173 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6175 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6176 info_ptr
+= blk
->size
;
6177 DW_BLOCK (attr
) = blk
;
6179 case DW_FORM_block4
:
6180 blk
= dwarf_alloc_block (cu
);
6181 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6183 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6184 info_ptr
+= blk
->size
;
6185 DW_BLOCK (attr
) = blk
;
6188 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6192 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6196 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6199 case DW_FORM_string
:
6200 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6201 info_ptr
+= bytes_read
;
6204 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6206 info_ptr
+= bytes_read
;
6209 blk
= dwarf_alloc_block (cu
);
6210 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6211 info_ptr
+= bytes_read
;
6212 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6213 info_ptr
+= blk
->size
;
6214 DW_BLOCK (attr
) = blk
;
6216 case DW_FORM_block1
:
6217 blk
= dwarf_alloc_block (cu
);
6218 blk
->size
= read_1_byte (abfd
, info_ptr
);
6220 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6221 info_ptr
+= blk
->size
;
6222 DW_BLOCK (attr
) = blk
;
6225 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6229 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6233 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6234 info_ptr
+= bytes_read
;
6237 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6238 info_ptr
+= bytes_read
;
6241 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6245 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6249 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6253 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6256 case DW_FORM_ref_udata
:
6257 DW_ADDR (attr
) = (cu
->header
.offset
6258 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6259 info_ptr
+= bytes_read
;
6261 case DW_FORM_indirect
:
6262 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6263 info_ptr
+= bytes_read
;
6264 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6267 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6268 dwarf_form_name (form
),
6269 bfd_get_filename (abfd
));
6272 /* We have seen instances where the compiler tried to emit a byte
6273 size attribute of -1 which ended up being encoded as an unsigned
6274 0xffffffff. Although 0xffffffff is technically a valid size value,
6275 an object of this size seems pretty unlikely so we can relatively
6276 safely treat these cases as if the size attribute was invalid and
6277 treat them as zero by default. */
6278 if (attr
->name
== DW_AT_byte_size
6279 && form
== DW_FORM_data4
6280 && DW_UNSND (attr
) >= 0xffffffff)
6283 (&symfile_complaints
,
6284 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6286 DW_UNSND (attr
) = 0;
6292 /* Read an attribute described by an abbreviated attribute. */
6295 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6296 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6298 attr
->name
= abbrev
->name
;
6299 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6302 /* read dwarf information from a buffer */
6305 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6307 return bfd_get_8 (abfd
, buf
);
6311 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6313 return bfd_get_signed_8 (abfd
, buf
);
6317 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6319 return bfd_get_16 (abfd
, buf
);
6323 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6325 return bfd_get_signed_16 (abfd
, buf
);
6329 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6331 return bfd_get_32 (abfd
, buf
);
6335 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6337 return bfd_get_signed_32 (abfd
, buf
);
6340 static unsigned long
6341 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6343 return bfd_get_64 (abfd
, buf
);
6347 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6348 unsigned int *bytes_read
)
6350 struct comp_unit_head
*cu_header
= &cu
->header
;
6351 CORE_ADDR retval
= 0;
6353 if (cu_header
->signed_addr_p
)
6355 switch (cu_header
->addr_size
)
6358 retval
= bfd_get_signed_16 (abfd
, buf
);
6361 retval
= bfd_get_signed_32 (abfd
, buf
);
6364 retval
= bfd_get_signed_64 (abfd
, buf
);
6367 internal_error (__FILE__
, __LINE__
,
6368 _("read_address: bad switch, signed [in module %s]"),
6369 bfd_get_filename (abfd
));
6374 switch (cu_header
->addr_size
)
6377 retval
= bfd_get_16 (abfd
, buf
);
6380 retval
= bfd_get_32 (abfd
, buf
);
6383 retval
= bfd_get_64 (abfd
, buf
);
6386 internal_error (__FILE__
, __LINE__
,
6387 _("read_address: bad switch, unsigned [in module %s]"),
6388 bfd_get_filename (abfd
));
6392 *bytes_read
= cu_header
->addr_size
;
6396 /* Read the initial length from a section. The (draft) DWARF 3
6397 specification allows the initial length to take up either 4 bytes
6398 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6399 bytes describe the length and all offsets will be 8 bytes in length
6402 An older, non-standard 64-bit format is also handled by this
6403 function. The older format in question stores the initial length
6404 as an 8-byte quantity without an escape value. Lengths greater
6405 than 2^32 aren't very common which means that the initial 4 bytes
6406 is almost always zero. Since a length value of zero doesn't make
6407 sense for the 32-bit format, this initial zero can be considered to
6408 be an escape value which indicates the presence of the older 64-bit
6409 format. As written, the code can't detect (old format) lengths
6410 greater than 4GB. If it becomes necessary to handle lengths
6411 somewhat larger than 4GB, we could allow other small values (such
6412 as the non-sensical values of 1, 2, and 3) to also be used as
6413 escape values indicating the presence of the old format.
6415 The value returned via bytes_read should be used to increment the
6416 relevant pointer after calling read_initial_length().
6418 As a side effect, this function sets the fields initial_length_size
6419 and offset_size in cu_header to the values appropriate for the
6420 length field. (The format of the initial length field determines
6421 the width of file offsets to be fetched later with read_offset().)
6423 [ Note: read_initial_length() and read_offset() are based on the
6424 document entitled "DWARF Debugging Information Format", revision
6425 3, draft 8, dated November 19, 2001. This document was obtained
6428 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6430 This document is only a draft and is subject to change. (So beware.)
6432 Details regarding the older, non-standard 64-bit format were
6433 determined empirically by examining 64-bit ELF files produced by
6434 the SGI toolchain on an IRIX 6.5 machine.
6436 - Kevin, July 16, 2002
6440 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6441 unsigned int *bytes_read
)
6443 LONGEST length
= bfd_get_32 (abfd
, buf
);
6445 if (length
== 0xffffffff)
6447 length
= bfd_get_64 (abfd
, buf
+ 4);
6450 else if (length
== 0)
6452 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6453 length
= bfd_get_64 (abfd
, buf
);
6463 gdb_assert (cu_header
->initial_length_size
== 0
6464 || cu_header
->initial_length_size
== 4
6465 || cu_header
->initial_length_size
== 8
6466 || cu_header
->initial_length_size
== 12);
6468 if (cu_header
->initial_length_size
!= 0
6469 && cu_header
->initial_length_size
!= *bytes_read
)
6470 complaint (&symfile_complaints
,
6471 _("intermixed 32-bit and 64-bit DWARF sections"));
6473 cu_header
->initial_length_size
= *bytes_read
;
6474 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6480 /* Read an offset from the data stream. The size of the offset is
6481 given by cu_header->offset_size. */
6484 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6485 unsigned int *bytes_read
)
6489 switch (cu_header
->offset_size
)
6492 retval
= bfd_get_32 (abfd
, buf
);
6496 retval
= bfd_get_64 (abfd
, buf
);
6500 internal_error (__FILE__
, __LINE__
,
6501 _("read_offset: bad switch [in module %s]"),
6502 bfd_get_filename (abfd
));
6509 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6511 /* If the size of a host char is 8 bits, we can return a pointer
6512 to the buffer, otherwise we have to copy the data to a buffer
6513 allocated on the temporary obstack. */
6514 gdb_assert (HOST_CHAR_BIT
== 8);
6519 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6521 /* If the size of a host char is 8 bits, we can return a pointer
6522 to the string, otherwise we have to copy the string to a buffer
6523 allocated on the temporary obstack. */
6524 gdb_assert (HOST_CHAR_BIT
== 8);
6527 *bytes_read_ptr
= 1;
6530 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6531 return (char *) buf
;
6535 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6536 const struct comp_unit_head
*cu_header
,
6537 unsigned int *bytes_read_ptr
)
6539 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6542 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6544 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6545 bfd_get_filename (abfd
));
6548 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6550 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6551 bfd_get_filename (abfd
));
6554 gdb_assert (HOST_CHAR_BIT
== 8);
6555 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6557 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6560 static unsigned long
6561 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6563 unsigned long result
;
6564 unsigned int num_read
;
6574 byte
= bfd_get_8 (abfd
, buf
);
6577 result
|= ((unsigned long)(byte
& 127) << shift
);
6578 if ((byte
& 128) == 0)
6584 *bytes_read_ptr
= num_read
;
6589 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6592 int i
, shift
, num_read
;
6601 byte
= bfd_get_8 (abfd
, buf
);
6604 result
|= ((long)(byte
& 127) << shift
);
6606 if ((byte
& 128) == 0)
6611 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6612 result
|= -(((long)1) << shift
);
6613 *bytes_read_ptr
= num_read
;
6617 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6620 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6626 byte
= bfd_get_8 (abfd
, buf
);
6628 if ((byte
& 128) == 0)
6634 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6640 cu
->language
= language_c
;
6642 case DW_LANG_C_plus_plus
:
6643 cu
->language
= language_cplus
;
6645 case DW_LANG_Fortran77
:
6646 case DW_LANG_Fortran90
:
6647 case DW_LANG_Fortran95
:
6648 cu
->language
= language_fortran
;
6650 case DW_LANG_Mips_Assembler
:
6651 cu
->language
= language_asm
;
6654 cu
->language
= language_java
;
6658 cu
->language
= language_ada
;
6660 case DW_LANG_Modula2
:
6661 cu
->language
= language_m2
;
6663 case DW_LANG_Pascal83
:
6664 cu
->language
= language_pascal
;
6667 cu
->language
= language_objc
;
6669 case DW_LANG_Cobol74
:
6670 case DW_LANG_Cobol85
:
6672 cu
->language
= language_minimal
;
6675 cu
->language_defn
= language_def (cu
->language
);
6678 /* Return the named attribute or NULL if not there. */
6680 static struct attribute
*
6681 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6684 struct attribute
*spec
= NULL
;
6686 for (i
= 0; i
< die
->num_attrs
; ++i
)
6688 if (die
->attrs
[i
].name
== name
)
6689 return &die
->attrs
[i
];
6690 if (die
->attrs
[i
].name
== DW_AT_specification
6691 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6692 spec
= &die
->attrs
[i
];
6697 die
= follow_die_ref (die
, spec
, &cu
);
6698 return dwarf2_attr (die
, name
, cu
);
6704 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6705 and holds a non-zero value. This function should only be used for
6706 DW_FORM_flag attributes. */
6709 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6711 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6713 return (attr
&& DW_UNSND (attr
));
6717 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6719 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6720 which value is non-zero. However, we have to be careful with
6721 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6722 (via dwarf2_flag_true_p) follows this attribute. So we may
6723 end up accidently finding a declaration attribute that belongs
6724 to a different DIE referenced by the specification attribute,
6725 even though the given DIE does not have a declaration attribute. */
6726 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6727 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6730 /* Return the die giving the specification for DIE, if there is
6731 one. *SPEC_CU is the CU containing DIE on input, and the CU
6732 containing the return value on output. */
6734 static struct die_info
*
6735 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
6737 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
6740 if (spec_attr
== NULL
)
6743 return follow_die_ref (die
, spec_attr
, spec_cu
);
6746 /* Free the line_header structure *LH, and any arrays and strings it
6749 free_line_header (struct line_header
*lh
)
6751 if (lh
->standard_opcode_lengths
)
6752 xfree (lh
->standard_opcode_lengths
);
6754 /* Remember that all the lh->file_names[i].name pointers are
6755 pointers into debug_line_buffer, and don't need to be freed. */
6757 xfree (lh
->file_names
);
6759 /* Similarly for the include directory names. */
6760 if (lh
->include_dirs
)
6761 xfree (lh
->include_dirs
);
6767 /* Add an entry to LH's include directory table. */
6769 add_include_dir (struct line_header
*lh
, char *include_dir
)
6771 /* Grow the array if necessary. */
6772 if (lh
->include_dirs_size
== 0)
6774 lh
->include_dirs_size
= 1; /* for testing */
6775 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6776 * sizeof (*lh
->include_dirs
));
6778 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6780 lh
->include_dirs_size
*= 2;
6781 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6782 (lh
->include_dirs_size
6783 * sizeof (*lh
->include_dirs
)));
6786 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6790 /* Add an entry to LH's file name table. */
6792 add_file_name (struct line_header
*lh
,
6794 unsigned int dir_index
,
6795 unsigned int mod_time
,
6796 unsigned int length
)
6798 struct file_entry
*fe
;
6800 /* Grow the array if necessary. */
6801 if (lh
->file_names_size
== 0)
6803 lh
->file_names_size
= 1; /* for testing */
6804 lh
->file_names
= xmalloc (lh
->file_names_size
6805 * sizeof (*lh
->file_names
));
6807 else if (lh
->num_file_names
>= lh
->file_names_size
)
6809 lh
->file_names_size
*= 2;
6810 lh
->file_names
= xrealloc (lh
->file_names
,
6811 (lh
->file_names_size
6812 * sizeof (*lh
->file_names
)));
6815 fe
= &lh
->file_names
[lh
->num_file_names
++];
6817 fe
->dir_index
= dir_index
;
6818 fe
->mod_time
= mod_time
;
6819 fe
->length
= length
;
6825 /* Read the statement program header starting at OFFSET in
6826 .debug_line, according to the endianness of ABFD. Return a pointer
6827 to a struct line_header, allocated using xmalloc.
6829 NOTE: the strings in the include directory and file name tables of
6830 the returned object point into debug_line_buffer, and must not be
6832 static struct line_header
*
6833 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6834 struct dwarf2_cu
*cu
)
6836 struct cleanup
*back_to
;
6837 struct line_header
*lh
;
6839 unsigned int bytes_read
;
6841 char *cur_dir
, *cur_file
;
6843 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6845 complaint (&symfile_complaints
, _("missing .debug_line section"));
6849 /* Make sure that at least there's room for the total_length field.
6850 That could be 12 bytes long, but we're just going to fudge that. */
6851 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6853 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6857 lh
= xmalloc (sizeof (*lh
));
6858 memset (lh
, 0, sizeof (*lh
));
6859 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6862 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6864 /* Read in the header. */
6866 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6867 line_ptr
+= bytes_read
;
6868 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6869 + dwarf2_per_objfile
->line_size
))
6871 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6874 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6875 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6877 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6878 line_ptr
+= bytes_read
;
6879 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6881 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6883 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6885 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6887 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6889 lh
->standard_opcode_lengths
6890 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6892 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6893 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6895 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6899 /* Read directory table. */
6900 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6902 line_ptr
+= bytes_read
;
6903 add_include_dir (lh
, cur_dir
);
6905 line_ptr
+= bytes_read
;
6907 /* Read file name table. */
6908 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6910 unsigned int dir_index
, mod_time
, length
;
6912 line_ptr
+= bytes_read
;
6913 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6914 line_ptr
+= bytes_read
;
6915 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6916 line_ptr
+= bytes_read
;
6917 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6918 line_ptr
+= bytes_read
;
6920 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6922 line_ptr
+= bytes_read
;
6923 lh
->statement_program_start
= line_ptr
;
6925 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6926 + dwarf2_per_objfile
->line_size
))
6927 complaint (&symfile_complaints
,
6928 _("line number info header doesn't fit in `.debug_line' section"));
6930 discard_cleanups (back_to
);
6934 /* This function exists to work around a bug in certain compilers
6935 (particularly GCC 2.95), in which the first line number marker of a
6936 function does not show up until after the prologue, right before
6937 the second line number marker. This function shifts ADDRESS down
6938 to the beginning of the function if necessary, and is called on
6939 addresses passed to record_line. */
6942 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6944 struct function_range
*fn
;
6946 /* Find the function_range containing address. */
6951 cu
->cached_fn
= cu
->first_fn
;
6955 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6961 while (fn
&& fn
!= cu
->cached_fn
)
6962 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6972 if (address
!= fn
->lowpc
)
6973 complaint (&symfile_complaints
,
6974 _("misplaced first line number at 0x%lx for '%s'"),
6975 (unsigned long) address
, fn
->name
);
6980 /* Decode the Line Number Program (LNP) for the given line_header
6981 structure and CU. The actual information extracted and the type
6982 of structures created from the LNP depends on the value of PST.
6984 1. If PST is NULL, then this procedure uses the data from the program
6985 to create all necessary symbol tables, and their linetables.
6986 The compilation directory of the file is passed in COMP_DIR,
6987 and must not be NULL.
6989 2. If PST is not NULL, this procedure reads the program to determine
6990 the list of files included by the unit represented by PST, and
6991 builds all the associated partial symbol tables. In this case,
6992 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6993 is not used to compute the full name of the symtab, and therefore
6994 omitting it when building the partial symtab does not introduce
6995 the potential for inconsistency - a partial symtab and its associated
6996 symbtab having a different fullname -). */
6999 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7000 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7002 gdb_byte
*line_ptr
, *extended_end
;
7004 unsigned int bytes_read
, extended_len
;
7005 unsigned char op_code
, extended_op
, adj_opcode
;
7007 struct objfile
*objfile
= cu
->objfile
;
7008 const int decode_for_pst_p
= (pst
!= NULL
);
7009 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7011 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7013 line_ptr
= lh
->statement_program_start
;
7014 line_end
= lh
->statement_program_end
;
7016 /* Read the statement sequences until there's nothing left. */
7017 while (line_ptr
< line_end
)
7019 /* state machine registers */
7020 CORE_ADDR address
= 0;
7021 unsigned int file
= 1;
7022 unsigned int line
= 1;
7023 unsigned int column
= 0;
7024 int is_stmt
= lh
->default_is_stmt
;
7025 int basic_block
= 0;
7026 int end_sequence
= 0;
7028 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7030 /* Start a subfile for the current file of the state machine. */
7031 /* lh->include_dirs and lh->file_names are 0-based, but the
7032 directory and file name numbers in the statement program
7034 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7038 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7040 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7043 /* Decode the table. */
7044 while (!end_sequence
)
7046 op_code
= read_1_byte (abfd
, line_ptr
);
7049 if (op_code
>= lh
->opcode_base
)
7051 /* Special operand. */
7052 adj_opcode
= op_code
- lh
->opcode_base
;
7053 address
+= (adj_opcode
/ lh
->line_range
)
7054 * lh
->minimum_instruction_length
;
7055 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7056 if (lh
->num_file_names
< file
)
7057 dwarf2_debug_line_missing_file_complaint ();
7060 lh
->file_names
[file
- 1].included_p
= 1;
7061 if (!decode_for_pst_p
)
7063 if (last_subfile
!= current_subfile
)
7066 record_line (last_subfile
, 0, address
);
7067 last_subfile
= current_subfile
;
7069 /* Append row to matrix using current values. */
7070 record_line (current_subfile
, line
,
7071 check_cu_functions (address
, cu
));
7076 else switch (op_code
)
7078 case DW_LNS_extended_op
:
7079 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7080 line_ptr
+= bytes_read
;
7081 extended_end
= line_ptr
+ extended_len
;
7082 extended_op
= read_1_byte (abfd
, line_ptr
);
7084 switch (extended_op
)
7086 case DW_LNE_end_sequence
:
7089 if (lh
->num_file_names
< file
)
7090 dwarf2_debug_line_missing_file_complaint ();
7093 lh
->file_names
[file
- 1].included_p
= 1;
7094 if (!decode_for_pst_p
)
7095 record_line (current_subfile
, 0, address
);
7098 case DW_LNE_set_address
:
7099 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7100 line_ptr
+= bytes_read
;
7101 address
+= baseaddr
;
7103 case DW_LNE_define_file
:
7106 unsigned int dir_index
, mod_time
, length
;
7108 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7109 line_ptr
+= bytes_read
;
7111 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7112 line_ptr
+= bytes_read
;
7114 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7115 line_ptr
+= bytes_read
;
7117 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7118 line_ptr
+= bytes_read
;
7119 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7123 complaint (&symfile_complaints
,
7124 _("mangled .debug_line section"));
7127 /* Make sure that we parsed the extended op correctly. If e.g.
7128 we expected a different address size than the producer used,
7129 we may have read the wrong number of bytes. */
7130 if (line_ptr
!= extended_end
)
7132 complaint (&symfile_complaints
,
7133 _("mangled .debug_line section"));
7138 if (lh
->num_file_names
< file
)
7139 dwarf2_debug_line_missing_file_complaint ();
7142 lh
->file_names
[file
- 1].included_p
= 1;
7143 if (!decode_for_pst_p
)
7145 if (last_subfile
!= current_subfile
)
7148 record_line (last_subfile
, 0, address
);
7149 last_subfile
= current_subfile
;
7151 record_line (current_subfile
, line
,
7152 check_cu_functions (address
, cu
));
7157 case DW_LNS_advance_pc
:
7158 address
+= lh
->minimum_instruction_length
7159 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7160 line_ptr
+= bytes_read
;
7162 case DW_LNS_advance_line
:
7163 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7164 line_ptr
+= bytes_read
;
7166 case DW_LNS_set_file
:
7168 /* The arrays lh->include_dirs and lh->file_names are
7169 0-based, but the directory and file name numbers in
7170 the statement program are 1-based. */
7171 struct file_entry
*fe
;
7174 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7175 line_ptr
+= bytes_read
;
7176 if (lh
->num_file_names
< file
)
7177 dwarf2_debug_line_missing_file_complaint ();
7180 fe
= &lh
->file_names
[file
- 1];
7182 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7183 if (!decode_for_pst_p
)
7185 last_subfile
= current_subfile
;
7186 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7191 case DW_LNS_set_column
:
7192 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7193 line_ptr
+= bytes_read
;
7195 case DW_LNS_negate_stmt
:
7196 is_stmt
= (!is_stmt
);
7198 case DW_LNS_set_basic_block
:
7201 /* Add to the address register of the state machine the
7202 address increment value corresponding to special opcode
7203 255. I.e., this value is scaled by the minimum
7204 instruction length since special opcode 255 would have
7205 scaled the the increment. */
7206 case DW_LNS_const_add_pc
:
7207 address
+= (lh
->minimum_instruction_length
7208 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7210 case DW_LNS_fixed_advance_pc
:
7211 address
+= read_2_bytes (abfd
, line_ptr
);
7216 /* Unknown standard opcode, ignore it. */
7219 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7221 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7222 line_ptr
+= bytes_read
;
7229 if (decode_for_pst_p
)
7233 /* Now that we're done scanning the Line Header Program, we can
7234 create the psymtab of each included file. */
7235 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7236 if (lh
->file_names
[file_index
].included_p
== 1)
7238 const struct file_entry fe
= lh
->file_names
[file_index
];
7239 char *include_name
= fe
.name
;
7240 char *dir_name
= NULL
;
7241 char *pst_filename
= pst
->filename
;
7244 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7246 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7248 include_name
= concat (dir_name
, SLASH_STRING
,
7249 include_name
, (char *)NULL
);
7250 make_cleanup (xfree
, include_name
);
7253 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7255 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7256 pst_filename
, (char *)NULL
);
7257 make_cleanup (xfree
, pst_filename
);
7260 if (strcmp (include_name
, pst_filename
) != 0)
7261 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7266 /* Make sure a symtab is created for every file, even files
7267 which contain only variables (i.e. no code with associated
7271 struct file_entry
*fe
;
7273 for (i
= 0; i
< lh
->num_file_names
; i
++)
7276 fe
= &lh
->file_names
[i
];
7278 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7279 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7281 /* Skip the main file; we don't need it, and it must be
7282 allocated last, so that it will show up before the
7283 non-primary symtabs in the objfile's symtab list. */
7284 if (current_subfile
== first_subfile
)
7287 if (current_subfile
->symtab
== NULL
)
7288 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7290 fe
->symtab
= current_subfile
->symtab
;
7295 /* Start a subfile for DWARF. FILENAME is the name of the file and
7296 DIRNAME the name of the source directory which contains FILENAME
7297 or NULL if not known. COMP_DIR is the compilation directory for the
7298 linetable's compilation unit or NULL if not known.
7299 This routine tries to keep line numbers from identical absolute and
7300 relative file names in a common subfile.
7302 Using the `list' example from the GDB testsuite, which resides in
7303 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7304 of /srcdir/list0.c yields the following debugging information for list0.c:
7306 DW_AT_name: /srcdir/list0.c
7307 DW_AT_comp_dir: /compdir
7308 files.files[0].name: list0.h
7309 files.files[0].dir: /srcdir
7310 files.files[1].name: list0.c
7311 files.files[1].dir: /srcdir
7313 The line number information for list0.c has to end up in a single
7314 subfile, so that `break /srcdir/list0.c:1' works as expected.
7315 start_subfile will ensure that this happens provided that we pass the
7316 concatenation of files.files[1].dir and files.files[1].name as the
7320 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7324 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7325 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7326 second argument to start_subfile. To be consistent, we do the
7327 same here. In order not to lose the line information directory,
7328 we concatenate it to the filename when it makes sense.
7329 Note that the Dwarf3 standard says (speaking of filenames in line
7330 information): ``The directory index is ignored for file names
7331 that represent full path names''. Thus ignoring dirname in the
7332 `else' branch below isn't an issue. */
7334 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7335 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7337 fullname
= filename
;
7339 start_subfile (fullname
, comp_dir
);
7341 if (fullname
!= filename
)
7346 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7347 struct dwarf2_cu
*cu
)
7349 struct objfile
*objfile
= cu
->objfile
;
7350 struct comp_unit_head
*cu_header
= &cu
->header
;
7352 /* NOTE drow/2003-01-30: There used to be a comment and some special
7353 code here to turn a symbol with DW_AT_external and a
7354 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7355 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7356 with some versions of binutils) where shared libraries could have
7357 relocations against symbols in their debug information - the
7358 minimal symbol would have the right address, but the debug info
7359 would not. It's no longer necessary, because we will explicitly
7360 apply relocations when we read in the debug information now. */
7362 /* A DW_AT_location attribute with no contents indicates that a
7363 variable has been optimized away. */
7364 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7366 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7370 /* Handle one degenerate form of location expression specially, to
7371 preserve GDB's previous behavior when section offsets are
7372 specified. If this is just a DW_OP_addr then mark this symbol
7375 if (attr_form_is_block (attr
)
7376 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7377 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7381 SYMBOL_VALUE_ADDRESS (sym
) =
7382 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7383 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7384 fixup_symbol_section (sym
, objfile
);
7385 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7386 SYMBOL_SECTION (sym
));
7390 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7391 expression evaluator, and use LOC_COMPUTED only when necessary
7392 (i.e. when the value of a register or memory location is
7393 referenced, or a thread-local block, etc.). Then again, it might
7394 not be worthwhile. I'm assuming that it isn't unless performance
7395 or memory numbers show me otherwise. */
7397 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7398 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7401 /* Given a pointer to a DWARF information entry, figure out if we need
7402 to make a symbol table entry for it, and if so, create a new entry
7403 and return a pointer to it.
7404 If TYPE is NULL, determine symbol type from the die, otherwise
7405 used the passed type. */
7407 static struct symbol
*
7408 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7410 struct objfile
*objfile
= cu
->objfile
;
7411 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7412 struct symbol
*sym
= NULL
;
7414 struct attribute
*attr
= NULL
;
7415 struct attribute
*attr2
= NULL
;
7418 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7420 if (die
->tag
!= DW_TAG_namespace
)
7421 name
= dwarf2_linkage_name (die
, cu
);
7423 name
= TYPE_NAME (type
);
7427 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7428 sizeof (struct symbol
));
7429 OBJSTAT (objfile
, n_syms
++);
7430 memset (sym
, 0, sizeof (struct symbol
));
7432 /* Cache this symbol's name and the name's demangled form (if any). */
7433 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7434 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7436 /* Default assumptions.
7437 Use the passed type or decode it from the die. */
7438 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7439 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7441 SYMBOL_TYPE (sym
) = type
;
7443 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7444 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7447 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7450 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7453 int file_index
= DW_UNSND (attr
);
7454 if (cu
->line_header
== NULL
7455 || file_index
> cu
->line_header
->num_file_names
)
7456 complaint (&symfile_complaints
,
7457 _("file index out of range"));
7458 else if (file_index
> 0)
7460 struct file_entry
*fe
;
7461 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7462 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7469 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7472 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7474 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7476 case DW_TAG_subprogram
:
7477 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7479 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7480 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7481 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7482 || cu
->language
== language_ada
)
7484 /* Subprograms marked external are stored as a global symbol.
7485 Ada subprograms, whether marked external or not, are always
7486 stored as a global symbol, because we want to be able to
7487 access them globally. For instance, we want to be able
7488 to break on a nested subprogram without having to
7489 specify the context. */
7490 add_symbol_to_list (sym
, &global_symbols
);
7494 add_symbol_to_list (sym
, cu
->list_in_scope
);
7497 case DW_TAG_variable
:
7498 /* Compilation with minimal debug info may result in variables
7499 with missing type entries. Change the misleading `void' type
7500 to something sensible. */
7501 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7503 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7505 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7508 dwarf2_const_value (attr
, sym
, cu
);
7509 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7510 if (attr2
&& (DW_UNSND (attr2
) != 0))
7511 add_symbol_to_list (sym
, &global_symbols
);
7513 add_symbol_to_list (sym
, cu
->list_in_scope
);
7516 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7519 var_decode_location (attr
, sym
, cu
);
7520 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7521 if (attr2
&& (DW_UNSND (attr2
) != 0))
7522 add_symbol_to_list (sym
, &global_symbols
);
7524 add_symbol_to_list (sym
, cu
->list_in_scope
);
7528 /* We do not know the address of this symbol.
7529 If it is an external symbol and we have type information
7530 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7531 The address of the variable will then be determined from
7532 the minimal symbol table whenever the variable is
7534 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7535 if (attr2
&& (DW_UNSND (attr2
) != 0)
7536 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7538 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7539 add_symbol_to_list (sym
, &global_symbols
);
7543 case DW_TAG_formal_parameter
:
7544 SYMBOL_IS_ARGUMENT (sym
) = 1;
7545 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7548 var_decode_location (attr
, sym
, cu
);
7550 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7553 dwarf2_const_value (attr
, sym
, cu
);
7555 add_symbol_to_list (sym
, cu
->list_in_scope
);
7557 case DW_TAG_unspecified_parameters
:
7558 /* From varargs functions; gdb doesn't seem to have any
7559 interest in this information, so just ignore it for now.
7562 case DW_TAG_class_type
:
7563 case DW_TAG_interface_type
:
7564 case DW_TAG_structure_type
:
7565 case DW_TAG_union_type
:
7566 case DW_TAG_set_type
:
7567 case DW_TAG_enumeration_type
:
7568 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7569 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7571 /* Make sure that the symbol includes appropriate enclosing
7572 classes/namespaces in its name. These are calculated in
7573 read_structure_type, and the correct name is saved in
7576 if (cu
->language
== language_cplus
7577 || cu
->language
== language_java
)
7579 struct type
*type
= SYMBOL_TYPE (sym
);
7581 if (TYPE_TAG_NAME (type
) != NULL
)
7583 /* FIXME: carlton/2003-11-10: Should this use
7584 SYMBOL_SET_NAMES instead? (The same problem also
7585 arises further down in this function.) */
7586 /* The type's name is already allocated along with
7587 this objfile, so we don't need to duplicate it
7589 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7594 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7595 really ever be static objects: otherwise, if you try
7596 to, say, break of a class's method and you're in a file
7597 which doesn't mention that class, it won't work unless
7598 the check for all static symbols in lookup_symbol_aux
7599 saves you. See the OtherFileClass tests in
7600 gdb.c++/namespace.exp. */
7602 struct pending
**list_to_add
;
7604 list_to_add
= (cu
->list_in_scope
== &file_symbols
7605 && (cu
->language
== language_cplus
7606 || cu
->language
== language_java
)
7607 ? &global_symbols
: cu
->list_in_scope
);
7609 add_symbol_to_list (sym
, list_to_add
);
7611 /* The semantics of C++ state that "struct foo { ... }" also
7612 defines a typedef for "foo". A Java class declaration also
7613 defines a typedef for the class. */
7614 if (cu
->language
== language_cplus
7615 || cu
->language
== language_java
7616 || cu
->language
== language_ada
)
7618 /* The symbol's name is already allocated along with
7619 this objfile, so we don't need to duplicate it for
7621 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7622 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7626 case DW_TAG_typedef
:
7627 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7628 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7629 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7630 add_symbol_to_list (sym
, cu
->list_in_scope
);
7632 case DW_TAG_base_type
:
7633 case DW_TAG_subrange_type
:
7634 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7635 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7636 add_symbol_to_list (sym
, cu
->list_in_scope
);
7638 case DW_TAG_enumerator
:
7639 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7640 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7643 dwarf2_const_value (attr
, sym
, cu
);
7646 /* NOTE: carlton/2003-11-10: See comment above in the
7647 DW_TAG_class_type, etc. block. */
7649 struct pending
**list_to_add
;
7651 list_to_add
= (cu
->list_in_scope
== &file_symbols
7652 && (cu
->language
== language_cplus
7653 || cu
->language
== language_java
)
7654 ? &global_symbols
: cu
->list_in_scope
);
7656 add_symbol_to_list (sym
, list_to_add
);
7659 case DW_TAG_namespace
:
7660 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7661 add_symbol_to_list (sym
, &global_symbols
);
7664 /* Not a tag we recognize. Hopefully we aren't processing
7665 trash data, but since we must specifically ignore things
7666 we don't recognize, there is nothing else we should do at
7668 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7669 dwarf_tag_name (die
->tag
));
7673 /* For the benefit of old versions of GCC, check for anonymous
7674 namespaces based on the demangled name. */
7675 if (!processing_has_namespace_info
7676 && cu
->language
== language_cplus
7677 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7678 cp_scan_for_anonymous_namespaces (sym
);
7683 /* Copy constant value from an attribute to a symbol. */
7686 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7687 struct dwarf2_cu
*cu
)
7689 struct objfile
*objfile
= cu
->objfile
;
7690 struct comp_unit_head
*cu_header
= &cu
->header
;
7691 struct dwarf_block
*blk
;
7696 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7697 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7698 cu_header
->addr_size
,
7699 TYPE_LENGTH (SYMBOL_TYPE
7701 SYMBOL_VALUE_BYTES (sym
) =
7702 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7703 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7704 it's body - store_unsigned_integer. */
7705 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7707 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7710 /* DW_STRING is already allocated on the obstack, point directly
7712 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
7713 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7715 case DW_FORM_block1
:
7716 case DW_FORM_block2
:
7717 case DW_FORM_block4
:
7719 blk
= DW_BLOCK (attr
);
7720 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7721 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
7723 TYPE_LENGTH (SYMBOL_TYPE
7725 SYMBOL_VALUE_BYTES (sym
) =
7726 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7727 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7728 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7731 /* The DW_AT_const_value attributes are supposed to carry the
7732 symbol's value "represented as it would be on the target
7733 architecture." By the time we get here, it's already been
7734 converted to host endianness, so we just need to sign- or
7735 zero-extend it as appropriate. */
7737 dwarf2_const_value_data (attr
, sym
, 8);
7740 dwarf2_const_value_data (attr
, sym
, 16);
7743 dwarf2_const_value_data (attr
, sym
, 32);
7746 dwarf2_const_value_data (attr
, sym
, 64);
7750 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7751 SYMBOL_CLASS (sym
) = LOC_CONST
;
7755 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7756 SYMBOL_CLASS (sym
) = LOC_CONST
;
7760 complaint (&symfile_complaints
,
7761 _("unsupported const value attribute form: '%s'"),
7762 dwarf_form_name (attr
->form
));
7763 SYMBOL_VALUE (sym
) = 0;
7764 SYMBOL_CLASS (sym
) = LOC_CONST
;
7770 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7771 or zero-extend it as appropriate for the symbol's type. */
7773 dwarf2_const_value_data (struct attribute
*attr
,
7777 LONGEST l
= DW_UNSND (attr
);
7779 if (bits
< sizeof (l
) * 8)
7781 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7782 l
&= ((LONGEST
) 1 << bits
) - 1;
7784 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7787 SYMBOL_VALUE (sym
) = l
;
7788 SYMBOL_CLASS (sym
) = LOC_CONST
;
7792 /* Return the type of the die in question using its DW_AT_type attribute. */
7794 static struct type
*
7795 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7797 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7799 struct attribute
*type_attr
;
7800 struct die_info
*type_die
;
7802 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7805 /* A missing DW_AT_type represents a void type. */
7806 return builtin_type (gdbarch
)->builtin_void
;
7809 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7811 type
= tag_type_to_type (type_die
, cu
);
7814 dump_die (type_die
);
7815 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7821 /* Return the containing type of the die in question using its
7822 DW_AT_containing_type attribute. */
7824 static struct type
*
7825 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7827 struct type
*type
= NULL
;
7828 struct attribute
*type_attr
;
7829 struct die_info
*type_die
= NULL
;
7831 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7834 type_die
= follow_die_ref (die
, type_attr
, &cu
);
7835 type
= tag_type_to_type (type_die
, cu
);
7840 dump_die (type_die
);
7841 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7847 static struct type
*
7848 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7850 struct type
*this_type
;
7852 this_type
= read_type_die (die
, cu
);
7856 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7862 static struct type
*
7863 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7865 struct type
*this_type
;
7867 this_type
= get_die_type (die
, cu
);
7873 case DW_TAG_class_type
:
7874 case DW_TAG_interface_type
:
7875 case DW_TAG_structure_type
:
7876 case DW_TAG_union_type
:
7877 this_type
= read_structure_type (die
, cu
);
7879 case DW_TAG_enumeration_type
:
7880 this_type
= read_enumeration_type (die
, cu
);
7882 case DW_TAG_subprogram
:
7883 case DW_TAG_subroutine_type
:
7884 this_type
= read_subroutine_type (die
, cu
);
7886 case DW_TAG_array_type
:
7887 this_type
= read_array_type (die
, cu
);
7889 case DW_TAG_set_type
:
7890 this_type
= read_set_type (die
, cu
);
7892 case DW_TAG_pointer_type
:
7893 this_type
= read_tag_pointer_type (die
, cu
);
7895 case DW_TAG_ptr_to_member_type
:
7896 this_type
= read_tag_ptr_to_member_type (die
, cu
);
7898 case DW_TAG_reference_type
:
7899 this_type
= read_tag_reference_type (die
, cu
);
7901 case DW_TAG_const_type
:
7902 this_type
= read_tag_const_type (die
, cu
);
7904 case DW_TAG_volatile_type
:
7905 this_type
= read_tag_volatile_type (die
, cu
);
7907 case DW_TAG_string_type
:
7908 this_type
= read_tag_string_type (die
, cu
);
7910 case DW_TAG_typedef
:
7911 this_type
= read_typedef (die
, cu
);
7913 case DW_TAG_subrange_type
:
7914 this_type
= read_subrange_type (die
, cu
);
7916 case DW_TAG_base_type
:
7917 this_type
= read_base_type (die
, cu
);
7919 case DW_TAG_unspecified_type
:
7920 this_type
= read_unspecified_type (die
, cu
);
7922 case DW_TAG_namespace
:
7923 this_type
= read_namespace_type (die
, cu
);
7926 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7927 dwarf_tag_name (die
->tag
));
7934 /* Return the name of the namespace/class that DIE is defined within,
7935 or "" if we can't tell. The caller should not xfree the result.
7937 For example, if we're within the method foo() in the following
7947 then determine_prefix on foo's die will return "N::C". */
7950 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7952 struct die_info
*parent
, *spec_die
;
7953 struct dwarf2_cu
*spec_cu
;
7954 struct type
*parent_type
;
7956 if (cu
->language
!= language_cplus
7957 && cu
->language
!= language_java
)
7960 /* We have to be careful in the presence of DW_AT_specification.
7961 For example, with GCC 3.4, given the code
7965 // Definition of N::foo.
7969 then we'll have a tree of DIEs like this:
7971 1: DW_TAG_compile_unit
7972 2: DW_TAG_namespace // N
7973 3: DW_TAG_subprogram // declaration of N::foo
7974 4: DW_TAG_subprogram // definition of N::foo
7975 DW_AT_specification // refers to die #3
7977 Thus, when processing die #4, we have to pretend that we're in
7978 the context of its DW_AT_specification, namely the contex of die
7981 spec_die
= die_specification (die
, &spec_cu
);
7982 if (spec_die
== NULL
)
7983 parent
= die
->parent
;
7986 parent
= spec_die
->parent
;
7993 switch (parent
->tag
)
7995 case DW_TAG_namespace
:
7996 parent_type
= read_type_die (parent
, cu
);
7997 /* We give a name to even anonymous namespaces. */
7998 return TYPE_TAG_NAME (parent_type
);
7999 case DW_TAG_class_type
:
8000 case DW_TAG_interface_type
:
8001 case DW_TAG_structure_type
:
8002 case DW_TAG_union_type
:
8003 parent_type
= read_type_die (parent
, cu
);
8004 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8005 return TYPE_TAG_NAME (parent_type
);
8007 /* An anonymous structure is only allowed non-static data
8008 members; no typedefs, no member functions, et cetera.
8009 So it does not need a prefix. */
8012 return determine_prefix (parent
, cu
);
8016 /* Return a newly-allocated string formed by concatenating PREFIX and
8017 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8018 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8019 perform an obconcat, otherwise allocate storage for the result. The CU argument
8020 is used to determine the language and hence, the appropriate separator. */
8022 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8025 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8026 struct dwarf2_cu
*cu
)
8030 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8032 else if (cu
->language
== language_java
)
8039 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8044 strcpy (retval
, prefix
);
8045 strcat (retval
, sep
);
8048 strcat (retval
, suffix
);
8054 /* We have an obstack. */
8055 return obconcat (obs
, prefix
, sep
, suffix
);
8059 /* Return sibling of die, NULL if no sibling. */
8061 static struct die_info
*
8062 sibling_die (struct die_info
*die
)
8064 return die
->sibling
;
8067 /* Get linkage name of a die, return NULL if not found. */
8070 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8072 struct attribute
*attr
;
8074 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8075 if (attr
&& DW_STRING (attr
))
8076 return DW_STRING (attr
);
8077 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8078 if (attr
&& DW_STRING (attr
))
8079 return DW_STRING (attr
);
8083 /* Get name of a die, return NULL if not found. */
8086 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8088 struct attribute
*attr
;
8090 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8091 if (attr
&& DW_STRING (attr
))
8092 return DW_STRING (attr
);
8096 /* Return the die that this die in an extension of, or NULL if there
8097 is none. *EXT_CU is the CU containing DIE on input, and the CU
8098 containing the return value on output. */
8100 static struct die_info
*
8101 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8103 struct attribute
*attr
;
8105 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8109 return follow_die_ref (die
, attr
, ext_cu
);
8112 /* Convert a DIE tag into its string name. */
8115 dwarf_tag_name (unsigned tag
)
8119 case DW_TAG_padding
:
8120 return "DW_TAG_padding";
8121 case DW_TAG_array_type
:
8122 return "DW_TAG_array_type";
8123 case DW_TAG_class_type
:
8124 return "DW_TAG_class_type";
8125 case DW_TAG_entry_point
:
8126 return "DW_TAG_entry_point";
8127 case DW_TAG_enumeration_type
:
8128 return "DW_TAG_enumeration_type";
8129 case DW_TAG_formal_parameter
:
8130 return "DW_TAG_formal_parameter";
8131 case DW_TAG_imported_declaration
:
8132 return "DW_TAG_imported_declaration";
8134 return "DW_TAG_label";
8135 case DW_TAG_lexical_block
:
8136 return "DW_TAG_lexical_block";
8138 return "DW_TAG_member";
8139 case DW_TAG_pointer_type
:
8140 return "DW_TAG_pointer_type";
8141 case DW_TAG_reference_type
:
8142 return "DW_TAG_reference_type";
8143 case DW_TAG_compile_unit
:
8144 return "DW_TAG_compile_unit";
8145 case DW_TAG_string_type
:
8146 return "DW_TAG_string_type";
8147 case DW_TAG_structure_type
:
8148 return "DW_TAG_structure_type";
8149 case DW_TAG_subroutine_type
:
8150 return "DW_TAG_subroutine_type";
8151 case DW_TAG_typedef
:
8152 return "DW_TAG_typedef";
8153 case DW_TAG_union_type
:
8154 return "DW_TAG_union_type";
8155 case DW_TAG_unspecified_parameters
:
8156 return "DW_TAG_unspecified_parameters";
8157 case DW_TAG_variant
:
8158 return "DW_TAG_variant";
8159 case DW_TAG_common_block
:
8160 return "DW_TAG_common_block";
8161 case DW_TAG_common_inclusion
:
8162 return "DW_TAG_common_inclusion";
8163 case DW_TAG_inheritance
:
8164 return "DW_TAG_inheritance";
8165 case DW_TAG_inlined_subroutine
:
8166 return "DW_TAG_inlined_subroutine";
8168 return "DW_TAG_module";
8169 case DW_TAG_ptr_to_member_type
:
8170 return "DW_TAG_ptr_to_member_type";
8171 case DW_TAG_set_type
:
8172 return "DW_TAG_set_type";
8173 case DW_TAG_subrange_type
:
8174 return "DW_TAG_subrange_type";
8175 case DW_TAG_with_stmt
:
8176 return "DW_TAG_with_stmt";
8177 case DW_TAG_access_declaration
:
8178 return "DW_TAG_access_declaration";
8179 case DW_TAG_base_type
:
8180 return "DW_TAG_base_type";
8181 case DW_TAG_catch_block
:
8182 return "DW_TAG_catch_block";
8183 case DW_TAG_const_type
:
8184 return "DW_TAG_const_type";
8185 case DW_TAG_constant
:
8186 return "DW_TAG_constant";
8187 case DW_TAG_enumerator
:
8188 return "DW_TAG_enumerator";
8189 case DW_TAG_file_type
:
8190 return "DW_TAG_file_type";
8192 return "DW_TAG_friend";
8193 case DW_TAG_namelist
:
8194 return "DW_TAG_namelist";
8195 case DW_TAG_namelist_item
:
8196 return "DW_TAG_namelist_item";
8197 case DW_TAG_packed_type
:
8198 return "DW_TAG_packed_type";
8199 case DW_TAG_subprogram
:
8200 return "DW_TAG_subprogram";
8201 case DW_TAG_template_type_param
:
8202 return "DW_TAG_template_type_param";
8203 case DW_TAG_template_value_param
:
8204 return "DW_TAG_template_value_param";
8205 case DW_TAG_thrown_type
:
8206 return "DW_TAG_thrown_type";
8207 case DW_TAG_try_block
:
8208 return "DW_TAG_try_block";
8209 case DW_TAG_variant_part
:
8210 return "DW_TAG_variant_part";
8211 case DW_TAG_variable
:
8212 return "DW_TAG_variable";
8213 case DW_TAG_volatile_type
:
8214 return "DW_TAG_volatile_type";
8215 case DW_TAG_dwarf_procedure
:
8216 return "DW_TAG_dwarf_procedure";
8217 case DW_TAG_restrict_type
:
8218 return "DW_TAG_restrict_type";
8219 case DW_TAG_interface_type
:
8220 return "DW_TAG_interface_type";
8221 case DW_TAG_namespace
:
8222 return "DW_TAG_namespace";
8223 case DW_TAG_imported_module
:
8224 return "DW_TAG_imported_module";
8225 case DW_TAG_unspecified_type
:
8226 return "DW_TAG_unspecified_type";
8227 case DW_TAG_partial_unit
:
8228 return "DW_TAG_partial_unit";
8229 case DW_TAG_imported_unit
:
8230 return "DW_TAG_imported_unit";
8231 case DW_TAG_condition
:
8232 return "DW_TAG_condition";
8233 case DW_TAG_shared_type
:
8234 return "DW_TAG_shared_type";
8235 case DW_TAG_MIPS_loop
:
8236 return "DW_TAG_MIPS_loop";
8237 case DW_TAG_HP_array_descriptor
:
8238 return "DW_TAG_HP_array_descriptor";
8239 case DW_TAG_format_label
:
8240 return "DW_TAG_format_label";
8241 case DW_TAG_function_template
:
8242 return "DW_TAG_function_template";
8243 case DW_TAG_class_template
:
8244 return "DW_TAG_class_template";
8245 case DW_TAG_GNU_BINCL
:
8246 return "DW_TAG_GNU_BINCL";
8247 case DW_TAG_GNU_EINCL
:
8248 return "DW_TAG_GNU_EINCL";
8249 case DW_TAG_upc_shared_type
:
8250 return "DW_TAG_upc_shared_type";
8251 case DW_TAG_upc_strict_type
:
8252 return "DW_TAG_upc_strict_type";
8253 case DW_TAG_upc_relaxed_type
:
8254 return "DW_TAG_upc_relaxed_type";
8255 case DW_TAG_PGI_kanji_type
:
8256 return "DW_TAG_PGI_kanji_type";
8257 case DW_TAG_PGI_interface_block
:
8258 return "DW_TAG_PGI_interface_block";
8260 return "DW_TAG_<unknown>";
8264 /* Convert a DWARF attribute code into its string name. */
8267 dwarf_attr_name (unsigned attr
)
8272 return "DW_AT_sibling";
8273 case DW_AT_location
:
8274 return "DW_AT_location";
8276 return "DW_AT_name";
8277 case DW_AT_ordering
:
8278 return "DW_AT_ordering";
8279 case DW_AT_subscr_data
:
8280 return "DW_AT_subscr_data";
8281 case DW_AT_byte_size
:
8282 return "DW_AT_byte_size";
8283 case DW_AT_bit_offset
:
8284 return "DW_AT_bit_offset";
8285 case DW_AT_bit_size
:
8286 return "DW_AT_bit_size";
8287 case DW_AT_element_list
:
8288 return "DW_AT_element_list";
8289 case DW_AT_stmt_list
:
8290 return "DW_AT_stmt_list";
8292 return "DW_AT_low_pc";
8294 return "DW_AT_high_pc";
8295 case DW_AT_language
:
8296 return "DW_AT_language";
8298 return "DW_AT_member";
8300 return "DW_AT_discr";
8301 case DW_AT_discr_value
:
8302 return "DW_AT_discr_value";
8303 case DW_AT_visibility
:
8304 return "DW_AT_visibility";
8306 return "DW_AT_import";
8307 case DW_AT_string_length
:
8308 return "DW_AT_string_length";
8309 case DW_AT_common_reference
:
8310 return "DW_AT_common_reference";
8311 case DW_AT_comp_dir
:
8312 return "DW_AT_comp_dir";
8313 case DW_AT_const_value
:
8314 return "DW_AT_const_value";
8315 case DW_AT_containing_type
:
8316 return "DW_AT_containing_type";
8317 case DW_AT_default_value
:
8318 return "DW_AT_default_value";
8320 return "DW_AT_inline";
8321 case DW_AT_is_optional
:
8322 return "DW_AT_is_optional";
8323 case DW_AT_lower_bound
:
8324 return "DW_AT_lower_bound";
8325 case DW_AT_producer
:
8326 return "DW_AT_producer";
8327 case DW_AT_prototyped
:
8328 return "DW_AT_prototyped";
8329 case DW_AT_return_addr
:
8330 return "DW_AT_return_addr";
8331 case DW_AT_start_scope
:
8332 return "DW_AT_start_scope";
8333 case DW_AT_bit_stride
:
8334 return "DW_AT_bit_stride";
8335 case DW_AT_upper_bound
:
8336 return "DW_AT_upper_bound";
8337 case DW_AT_abstract_origin
:
8338 return "DW_AT_abstract_origin";
8339 case DW_AT_accessibility
:
8340 return "DW_AT_accessibility";
8341 case DW_AT_address_class
:
8342 return "DW_AT_address_class";
8343 case DW_AT_artificial
:
8344 return "DW_AT_artificial";
8345 case DW_AT_base_types
:
8346 return "DW_AT_base_types";
8347 case DW_AT_calling_convention
:
8348 return "DW_AT_calling_convention";
8350 return "DW_AT_count";
8351 case DW_AT_data_member_location
:
8352 return "DW_AT_data_member_location";
8353 case DW_AT_decl_column
:
8354 return "DW_AT_decl_column";
8355 case DW_AT_decl_file
:
8356 return "DW_AT_decl_file";
8357 case DW_AT_decl_line
:
8358 return "DW_AT_decl_line";
8359 case DW_AT_declaration
:
8360 return "DW_AT_declaration";
8361 case DW_AT_discr_list
:
8362 return "DW_AT_discr_list";
8363 case DW_AT_encoding
:
8364 return "DW_AT_encoding";
8365 case DW_AT_external
:
8366 return "DW_AT_external";
8367 case DW_AT_frame_base
:
8368 return "DW_AT_frame_base";
8370 return "DW_AT_friend";
8371 case DW_AT_identifier_case
:
8372 return "DW_AT_identifier_case";
8373 case DW_AT_macro_info
:
8374 return "DW_AT_macro_info";
8375 case DW_AT_namelist_items
:
8376 return "DW_AT_namelist_items";
8377 case DW_AT_priority
:
8378 return "DW_AT_priority";
8380 return "DW_AT_segment";
8381 case DW_AT_specification
:
8382 return "DW_AT_specification";
8383 case DW_AT_static_link
:
8384 return "DW_AT_static_link";
8386 return "DW_AT_type";
8387 case DW_AT_use_location
:
8388 return "DW_AT_use_location";
8389 case DW_AT_variable_parameter
:
8390 return "DW_AT_variable_parameter";
8391 case DW_AT_virtuality
:
8392 return "DW_AT_virtuality";
8393 case DW_AT_vtable_elem_location
:
8394 return "DW_AT_vtable_elem_location";
8395 /* DWARF 3 values. */
8396 case DW_AT_allocated
:
8397 return "DW_AT_allocated";
8398 case DW_AT_associated
:
8399 return "DW_AT_associated";
8400 case DW_AT_data_location
:
8401 return "DW_AT_data_location";
8402 case DW_AT_byte_stride
:
8403 return "DW_AT_byte_stride";
8404 case DW_AT_entry_pc
:
8405 return "DW_AT_entry_pc";
8406 case DW_AT_use_UTF8
:
8407 return "DW_AT_use_UTF8";
8408 case DW_AT_extension
:
8409 return "DW_AT_extension";
8411 return "DW_AT_ranges";
8412 case DW_AT_trampoline
:
8413 return "DW_AT_trampoline";
8414 case DW_AT_call_column
:
8415 return "DW_AT_call_column";
8416 case DW_AT_call_file
:
8417 return "DW_AT_call_file";
8418 case DW_AT_call_line
:
8419 return "DW_AT_call_line";
8420 case DW_AT_description
:
8421 return "DW_AT_description";
8422 case DW_AT_binary_scale
:
8423 return "DW_AT_binary_scale";
8424 case DW_AT_decimal_scale
:
8425 return "DW_AT_decimal_scale";
8427 return "DW_AT_small";
8428 case DW_AT_decimal_sign
:
8429 return "DW_AT_decimal_sign";
8430 case DW_AT_digit_count
:
8431 return "DW_AT_digit_count";
8432 case DW_AT_picture_string
:
8433 return "DW_AT_picture_string";
8435 return "DW_AT_mutable";
8436 case DW_AT_threads_scaled
:
8437 return "DW_AT_threads_scaled";
8438 case DW_AT_explicit
:
8439 return "DW_AT_explicit";
8440 case DW_AT_object_pointer
:
8441 return "DW_AT_object_pointer";
8442 case DW_AT_endianity
:
8443 return "DW_AT_endianity";
8444 case DW_AT_elemental
:
8445 return "DW_AT_elemental";
8447 return "DW_AT_pure";
8448 case DW_AT_recursive
:
8449 return "DW_AT_recursive";
8451 /* SGI/MIPS extensions. */
8452 case DW_AT_MIPS_fde
:
8453 return "DW_AT_MIPS_fde";
8454 case DW_AT_MIPS_loop_begin
:
8455 return "DW_AT_MIPS_loop_begin";
8456 case DW_AT_MIPS_tail_loop_begin
:
8457 return "DW_AT_MIPS_tail_loop_begin";
8458 case DW_AT_MIPS_epilog_begin
:
8459 return "DW_AT_MIPS_epilog_begin";
8460 case DW_AT_MIPS_loop_unroll_factor
:
8461 return "DW_AT_MIPS_loop_unroll_factor";
8462 case DW_AT_MIPS_software_pipeline_depth
:
8463 return "DW_AT_MIPS_software_pipeline_depth";
8464 case DW_AT_MIPS_linkage_name
:
8465 return "DW_AT_MIPS_linkage_name";
8466 case DW_AT_MIPS_stride
:
8467 return "DW_AT_MIPS_stride";
8468 case DW_AT_MIPS_abstract_name
:
8469 return "DW_AT_MIPS_abstract_name";
8470 case DW_AT_MIPS_clone_origin
:
8471 return "DW_AT_MIPS_clone_origin";
8472 case DW_AT_MIPS_has_inlines
:
8473 return "DW_AT_MIPS_has_inlines";
8475 /* HP extensions. */
8476 case DW_AT_HP_block_index
:
8477 return "DW_AT_HP_block_index";
8478 case DW_AT_HP_unmodifiable
:
8479 return "DW_AT_HP_unmodifiable";
8480 case DW_AT_HP_actuals_stmt_list
:
8481 return "DW_AT_HP_actuals_stmt_list";
8482 case DW_AT_HP_proc_per_section
:
8483 return "DW_AT_HP_proc_per_section";
8484 case DW_AT_HP_raw_data_ptr
:
8485 return "DW_AT_HP_raw_data_ptr";
8486 case DW_AT_HP_pass_by_reference
:
8487 return "DW_AT_HP_pass_by_reference";
8488 case DW_AT_HP_opt_level
:
8489 return "DW_AT_HP_opt_level";
8490 case DW_AT_HP_prof_version_id
:
8491 return "DW_AT_HP_prof_version_id";
8492 case DW_AT_HP_opt_flags
:
8493 return "DW_AT_HP_opt_flags";
8494 case DW_AT_HP_cold_region_low_pc
:
8495 return "DW_AT_HP_cold_region_low_pc";
8496 case DW_AT_HP_cold_region_high_pc
:
8497 return "DW_AT_HP_cold_region_high_pc";
8498 case DW_AT_HP_all_variables_modifiable
:
8499 return "DW_AT_HP_all_variables_modifiable";
8500 case DW_AT_HP_linkage_name
:
8501 return "DW_AT_HP_linkage_name";
8502 case DW_AT_HP_prof_flags
:
8503 return "DW_AT_HP_prof_flags";
8504 /* GNU extensions. */
8505 case DW_AT_sf_names
:
8506 return "DW_AT_sf_names";
8507 case DW_AT_src_info
:
8508 return "DW_AT_src_info";
8509 case DW_AT_mac_info
:
8510 return "DW_AT_mac_info";
8511 case DW_AT_src_coords
:
8512 return "DW_AT_src_coords";
8513 case DW_AT_body_begin
:
8514 return "DW_AT_body_begin";
8515 case DW_AT_body_end
:
8516 return "DW_AT_body_end";
8517 case DW_AT_GNU_vector
:
8518 return "DW_AT_GNU_vector";
8519 /* VMS extensions. */
8520 case DW_AT_VMS_rtnbeg_pd_address
:
8521 return "DW_AT_VMS_rtnbeg_pd_address";
8522 /* UPC extension. */
8523 case DW_AT_upc_threads_scaled
:
8524 return "DW_AT_upc_threads_scaled";
8525 /* PGI (STMicroelectronics) extensions. */
8526 case DW_AT_PGI_lbase
:
8527 return "DW_AT_PGI_lbase";
8528 case DW_AT_PGI_soffset
:
8529 return "DW_AT_PGI_soffset";
8530 case DW_AT_PGI_lstride
:
8531 return "DW_AT_PGI_lstride";
8533 return "DW_AT_<unknown>";
8537 /* Convert a DWARF value form code into its string name. */
8540 dwarf_form_name (unsigned form
)
8545 return "DW_FORM_addr";
8546 case DW_FORM_block2
:
8547 return "DW_FORM_block2";
8548 case DW_FORM_block4
:
8549 return "DW_FORM_block4";
8551 return "DW_FORM_data2";
8553 return "DW_FORM_data4";
8555 return "DW_FORM_data8";
8556 case DW_FORM_string
:
8557 return "DW_FORM_string";
8559 return "DW_FORM_block";
8560 case DW_FORM_block1
:
8561 return "DW_FORM_block1";
8563 return "DW_FORM_data1";
8565 return "DW_FORM_flag";
8567 return "DW_FORM_sdata";
8569 return "DW_FORM_strp";
8571 return "DW_FORM_udata";
8572 case DW_FORM_ref_addr
:
8573 return "DW_FORM_ref_addr";
8575 return "DW_FORM_ref1";
8577 return "DW_FORM_ref2";
8579 return "DW_FORM_ref4";
8581 return "DW_FORM_ref8";
8582 case DW_FORM_ref_udata
:
8583 return "DW_FORM_ref_udata";
8584 case DW_FORM_indirect
:
8585 return "DW_FORM_indirect";
8587 return "DW_FORM_<unknown>";
8591 /* Convert a DWARF stack opcode into its string name. */
8594 dwarf_stack_op_name (unsigned op
)
8599 return "DW_OP_addr";
8601 return "DW_OP_deref";
8603 return "DW_OP_const1u";
8605 return "DW_OP_const1s";
8607 return "DW_OP_const2u";
8609 return "DW_OP_const2s";
8611 return "DW_OP_const4u";
8613 return "DW_OP_const4s";
8615 return "DW_OP_const8u";
8617 return "DW_OP_const8s";
8619 return "DW_OP_constu";
8621 return "DW_OP_consts";
8625 return "DW_OP_drop";
8627 return "DW_OP_over";
8629 return "DW_OP_pick";
8631 return "DW_OP_swap";
8635 return "DW_OP_xderef";
8643 return "DW_OP_minus";
8655 return "DW_OP_plus";
8656 case DW_OP_plus_uconst
:
8657 return "DW_OP_plus_uconst";
8663 return "DW_OP_shra";
8681 return "DW_OP_skip";
8683 return "DW_OP_lit0";
8685 return "DW_OP_lit1";
8687 return "DW_OP_lit2";
8689 return "DW_OP_lit3";
8691 return "DW_OP_lit4";
8693 return "DW_OP_lit5";
8695 return "DW_OP_lit6";
8697 return "DW_OP_lit7";
8699 return "DW_OP_lit8";
8701 return "DW_OP_lit9";
8703 return "DW_OP_lit10";
8705 return "DW_OP_lit11";
8707 return "DW_OP_lit12";
8709 return "DW_OP_lit13";
8711 return "DW_OP_lit14";
8713 return "DW_OP_lit15";
8715 return "DW_OP_lit16";
8717 return "DW_OP_lit17";
8719 return "DW_OP_lit18";
8721 return "DW_OP_lit19";
8723 return "DW_OP_lit20";
8725 return "DW_OP_lit21";
8727 return "DW_OP_lit22";
8729 return "DW_OP_lit23";
8731 return "DW_OP_lit24";
8733 return "DW_OP_lit25";
8735 return "DW_OP_lit26";
8737 return "DW_OP_lit27";
8739 return "DW_OP_lit28";
8741 return "DW_OP_lit29";
8743 return "DW_OP_lit30";
8745 return "DW_OP_lit31";
8747 return "DW_OP_reg0";
8749 return "DW_OP_reg1";
8751 return "DW_OP_reg2";
8753 return "DW_OP_reg3";
8755 return "DW_OP_reg4";
8757 return "DW_OP_reg5";
8759 return "DW_OP_reg6";
8761 return "DW_OP_reg7";
8763 return "DW_OP_reg8";
8765 return "DW_OP_reg9";
8767 return "DW_OP_reg10";
8769 return "DW_OP_reg11";
8771 return "DW_OP_reg12";
8773 return "DW_OP_reg13";
8775 return "DW_OP_reg14";
8777 return "DW_OP_reg15";
8779 return "DW_OP_reg16";
8781 return "DW_OP_reg17";
8783 return "DW_OP_reg18";
8785 return "DW_OP_reg19";
8787 return "DW_OP_reg20";
8789 return "DW_OP_reg21";
8791 return "DW_OP_reg22";
8793 return "DW_OP_reg23";
8795 return "DW_OP_reg24";
8797 return "DW_OP_reg25";
8799 return "DW_OP_reg26";
8801 return "DW_OP_reg27";
8803 return "DW_OP_reg28";
8805 return "DW_OP_reg29";
8807 return "DW_OP_reg30";
8809 return "DW_OP_reg31";
8811 return "DW_OP_breg0";
8813 return "DW_OP_breg1";
8815 return "DW_OP_breg2";
8817 return "DW_OP_breg3";
8819 return "DW_OP_breg4";
8821 return "DW_OP_breg5";
8823 return "DW_OP_breg6";
8825 return "DW_OP_breg7";
8827 return "DW_OP_breg8";
8829 return "DW_OP_breg9";
8831 return "DW_OP_breg10";
8833 return "DW_OP_breg11";
8835 return "DW_OP_breg12";
8837 return "DW_OP_breg13";
8839 return "DW_OP_breg14";
8841 return "DW_OP_breg15";
8843 return "DW_OP_breg16";
8845 return "DW_OP_breg17";
8847 return "DW_OP_breg18";
8849 return "DW_OP_breg19";
8851 return "DW_OP_breg20";
8853 return "DW_OP_breg21";
8855 return "DW_OP_breg22";
8857 return "DW_OP_breg23";
8859 return "DW_OP_breg24";
8861 return "DW_OP_breg25";
8863 return "DW_OP_breg26";
8865 return "DW_OP_breg27";
8867 return "DW_OP_breg28";
8869 return "DW_OP_breg29";
8871 return "DW_OP_breg30";
8873 return "DW_OP_breg31";
8875 return "DW_OP_regx";
8877 return "DW_OP_fbreg";
8879 return "DW_OP_bregx";
8881 return "DW_OP_piece";
8882 case DW_OP_deref_size
:
8883 return "DW_OP_deref_size";
8884 case DW_OP_xderef_size
:
8885 return "DW_OP_xderef_size";
8888 /* DWARF 3 extensions. */
8889 case DW_OP_push_object_address
:
8890 return "DW_OP_push_object_address";
8892 return "DW_OP_call2";
8894 return "DW_OP_call4";
8895 case DW_OP_call_ref
:
8896 return "DW_OP_call_ref";
8897 /* GNU extensions. */
8898 case DW_OP_form_tls_address
:
8899 return "DW_OP_form_tls_address";
8900 case DW_OP_call_frame_cfa
:
8901 return "DW_OP_call_frame_cfa";
8902 case DW_OP_bit_piece
:
8903 return "DW_OP_bit_piece";
8904 case DW_OP_GNU_push_tls_address
:
8905 return "DW_OP_GNU_push_tls_address";
8906 case DW_OP_GNU_uninit
:
8907 return "DW_OP_GNU_uninit";
8908 /* HP extensions. */
8909 case DW_OP_HP_is_value
:
8910 return "DW_OP_HP_is_value";
8911 case DW_OP_HP_fltconst4
:
8912 return "DW_OP_HP_fltconst4";
8913 case DW_OP_HP_fltconst8
:
8914 return "DW_OP_HP_fltconst8";
8915 case DW_OP_HP_mod_range
:
8916 return "DW_OP_HP_mod_range";
8917 case DW_OP_HP_unmod_range
:
8918 return "DW_OP_HP_unmod_range";
8920 return "DW_OP_HP_tls";
8922 return "OP_<unknown>";
8927 dwarf_bool_name (unsigned mybool
)
8935 /* Convert a DWARF type code into its string name. */
8938 dwarf_type_encoding_name (unsigned enc
)
8943 return "DW_ATE_void";
8944 case DW_ATE_address
:
8945 return "DW_ATE_address";
8946 case DW_ATE_boolean
:
8947 return "DW_ATE_boolean";
8948 case DW_ATE_complex_float
:
8949 return "DW_ATE_complex_float";
8951 return "DW_ATE_float";
8953 return "DW_ATE_signed";
8954 case DW_ATE_signed_char
:
8955 return "DW_ATE_signed_char";
8956 case DW_ATE_unsigned
:
8957 return "DW_ATE_unsigned";
8958 case DW_ATE_unsigned_char
:
8959 return "DW_ATE_unsigned_char";
8961 case DW_ATE_imaginary_float
:
8962 return "DW_ATE_imaginary_float";
8963 case DW_ATE_packed_decimal
:
8964 return "DW_ATE_packed_decimal";
8965 case DW_ATE_numeric_string
:
8966 return "DW_ATE_numeric_string";
8968 return "DW_ATE_edited";
8969 case DW_ATE_signed_fixed
:
8970 return "DW_ATE_signed_fixed";
8971 case DW_ATE_unsigned_fixed
:
8972 return "DW_ATE_unsigned_fixed";
8973 case DW_ATE_decimal_float
:
8974 return "DW_ATE_decimal_float";
8975 /* HP extensions. */
8976 case DW_ATE_HP_float80
:
8977 return "DW_ATE_HP_float80";
8978 case DW_ATE_HP_complex_float80
:
8979 return "DW_ATE_HP_complex_float80";
8980 case DW_ATE_HP_float128
:
8981 return "DW_ATE_HP_float128";
8982 case DW_ATE_HP_complex_float128
:
8983 return "DW_ATE_HP_complex_float128";
8984 case DW_ATE_HP_floathpintel
:
8985 return "DW_ATE_HP_floathpintel";
8986 case DW_ATE_HP_imaginary_float80
:
8987 return "DW_ATE_HP_imaginary_float80";
8988 case DW_ATE_HP_imaginary_float128
:
8989 return "DW_ATE_HP_imaginary_float128";
8991 return "DW_ATE_<unknown>";
8995 /* Convert a DWARF call frame info operation to its string name. */
8999 dwarf_cfi_name (unsigned cfi_opc
)
9003 case DW_CFA_advance_loc
:
9004 return "DW_CFA_advance_loc";
9006 return "DW_CFA_offset";
9007 case DW_CFA_restore
:
9008 return "DW_CFA_restore";
9010 return "DW_CFA_nop";
9011 case DW_CFA_set_loc
:
9012 return "DW_CFA_set_loc";
9013 case DW_CFA_advance_loc1
:
9014 return "DW_CFA_advance_loc1";
9015 case DW_CFA_advance_loc2
:
9016 return "DW_CFA_advance_loc2";
9017 case DW_CFA_advance_loc4
:
9018 return "DW_CFA_advance_loc4";
9019 case DW_CFA_offset_extended
:
9020 return "DW_CFA_offset_extended";
9021 case DW_CFA_restore_extended
:
9022 return "DW_CFA_restore_extended";
9023 case DW_CFA_undefined
:
9024 return "DW_CFA_undefined";
9025 case DW_CFA_same_value
:
9026 return "DW_CFA_same_value";
9027 case DW_CFA_register
:
9028 return "DW_CFA_register";
9029 case DW_CFA_remember_state
:
9030 return "DW_CFA_remember_state";
9031 case DW_CFA_restore_state
:
9032 return "DW_CFA_restore_state";
9033 case DW_CFA_def_cfa
:
9034 return "DW_CFA_def_cfa";
9035 case DW_CFA_def_cfa_register
:
9036 return "DW_CFA_def_cfa_register";
9037 case DW_CFA_def_cfa_offset
:
9038 return "DW_CFA_def_cfa_offset";
9040 case DW_CFA_def_cfa_expression
:
9041 return "DW_CFA_def_cfa_expression";
9042 case DW_CFA_expression
:
9043 return "DW_CFA_expression";
9044 case DW_CFA_offset_extended_sf
:
9045 return "DW_CFA_offset_extended_sf";
9046 case DW_CFA_def_cfa_sf
:
9047 return "DW_CFA_def_cfa_sf";
9048 case DW_CFA_def_cfa_offset_sf
:
9049 return "DW_CFA_def_cfa_offset_sf";
9050 case DW_CFA_val_offset
:
9051 return "DW_CFA_val_offset";
9052 case DW_CFA_val_offset_sf
:
9053 return "DW_CFA_val_offset_sf";
9054 case DW_CFA_val_expression
:
9055 return "DW_CFA_val_expression";
9056 /* SGI/MIPS specific. */
9057 case DW_CFA_MIPS_advance_loc8
:
9058 return "DW_CFA_MIPS_advance_loc8";
9059 /* GNU extensions. */
9060 case DW_CFA_GNU_window_save
:
9061 return "DW_CFA_GNU_window_save";
9062 case DW_CFA_GNU_args_size
:
9063 return "DW_CFA_GNU_args_size";
9064 case DW_CFA_GNU_negative_offset_extended
:
9065 return "DW_CFA_GNU_negative_offset_extended";
9067 return "DW_CFA_<unknown>";
9073 dump_die (struct die_info
*die
)
9077 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
9078 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9079 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
9080 dwarf_bool_name (die
->child
!= NULL
));
9082 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
9083 for (i
= 0; i
< die
->num_attrs
; ++i
)
9085 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
9086 dwarf_attr_name (die
->attrs
[i
].name
),
9087 dwarf_form_name (die
->attrs
[i
].form
));
9088 switch (die
->attrs
[i
].form
)
9090 case DW_FORM_ref_addr
:
9092 fprintf_unfiltered (gdb_stderr
, "address: ");
9093 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), gdb_stderr
);
9095 case DW_FORM_block2
:
9096 case DW_FORM_block4
:
9098 case DW_FORM_block1
:
9099 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9104 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
9105 (long) (DW_ADDR (&die
->attrs
[i
])));
9113 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9115 case DW_FORM_string
:
9117 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
9118 DW_STRING (&die
->attrs
[i
])
9119 ? DW_STRING (&die
->attrs
[i
]) : "");
9122 if (DW_UNSND (&die
->attrs
[i
]))
9123 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
9125 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
9127 case DW_FORM_indirect
:
9128 /* the reader will have reduced the indirect form to
9129 the "base form" so this form should not occur */
9130 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
9133 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
9134 die
->attrs
[i
].form
);
9136 fprintf_unfiltered (gdb_stderr
, "\n");
9141 dump_die_list (struct die_info
*die
)
9146 if (die
->child
!= NULL
)
9147 dump_die_list (die
->child
);
9148 if (die
->sibling
!= NULL
)
9149 dump_die_list (die
->sibling
);
9154 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9158 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9164 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
9166 unsigned int result
= 0;
9170 case DW_FORM_ref_addr
:
9175 case DW_FORM_ref_udata
:
9176 result
= DW_ADDR (attr
);
9179 complaint (&symfile_complaints
,
9180 _("unsupported die ref attribute form: '%s'"),
9181 dwarf_form_name (attr
->form
));
9186 /* Return the constant value held by the given attribute. Return -1
9187 if the value held by the attribute is not constant. */
9190 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9192 if (attr
->form
== DW_FORM_sdata
)
9193 return DW_SND (attr
);
9194 else if (attr
->form
== DW_FORM_udata
9195 || attr
->form
== DW_FORM_data1
9196 || attr
->form
== DW_FORM_data2
9197 || attr
->form
== DW_FORM_data4
9198 || attr
->form
== DW_FORM_data8
)
9199 return DW_UNSND (attr
);
9202 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9203 dwarf_form_name (attr
->form
));
9204 return default_value
;
9208 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9209 unit and add it to our queue. */
9212 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9213 struct dwarf2_per_cu_data
*per_cu
)
9215 /* Mark the dependence relation so that we don't flush PER_CU
9217 dwarf2_add_dependence (this_cu
, per_cu
);
9219 /* If it's already on the queue, we have nothing to do. */
9223 /* If the compilation unit is already loaded, just mark it as
9225 if (per_cu
->cu
!= NULL
)
9227 per_cu
->cu
->last_used
= 0;
9231 /* Add it to the queue. */
9232 queue_comp_unit (per_cu
, this_cu
->objfile
);
9235 static struct die_info
*
9236 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9237 struct dwarf2_cu
**ref_cu
)
9239 struct die_info
*die
;
9240 unsigned int offset
;
9241 struct die_info temp_die
;
9242 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9244 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
9246 if (! offset_in_cu_p (&cu
->header
, offset
))
9248 struct dwarf2_per_cu_data
*per_cu
;
9249 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9251 /* If necessary, add it to the queue and load its DIEs. */
9252 maybe_queue_comp_unit (cu
, per_cu
);
9254 target_cu
= per_cu
->cu
;
9259 *ref_cu
= target_cu
;
9260 temp_die
.offset
= offset
;
9261 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9265 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9266 "at 0x%lx [in module %s]"),
9267 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9270 /* Decode simple location descriptions.
9271 Given a pointer to a dwarf block that defines a location, compute
9272 the location and return the value.
9274 NOTE drow/2003-11-18: This function is called in two situations
9275 now: for the address of static or global variables (partial symbols
9276 only) and for offsets into structures which are expected to be
9277 (more or less) constant. The partial symbol case should go away,
9278 and only the constant case should remain. That will let this
9279 function complain more accurately. A few special modes are allowed
9280 without complaint for global variables (for instance, global
9281 register values and thread-local values).
9283 A location description containing no operations indicates that the
9284 object is optimized out. The return value is 0 for that case.
9285 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9286 callers will only want a very basic result and this can become a
9289 Note that stack[0] is unused except as a default error return.
9290 Note that stack overflow is not yet handled. */
9293 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9295 struct objfile
*objfile
= cu
->objfile
;
9296 struct comp_unit_head
*cu_header
= &cu
->header
;
9298 int size
= blk
->size
;
9299 gdb_byte
*data
= blk
->data
;
9300 CORE_ADDR stack
[64];
9302 unsigned int bytes_read
, unsnd
;
9346 stack
[++stacki
] = op
- DW_OP_lit0
;
9381 stack
[++stacki
] = op
- DW_OP_reg0
;
9383 dwarf2_complex_location_expr_complaint ();
9387 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9389 stack
[++stacki
] = unsnd
;
9391 dwarf2_complex_location_expr_complaint ();
9395 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9401 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9406 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9411 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9416 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9421 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9426 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9431 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9437 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9442 stack
[stacki
+ 1] = stack
[stacki
];
9447 stack
[stacki
- 1] += stack
[stacki
];
9451 case DW_OP_plus_uconst
:
9452 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9457 stack
[stacki
- 1] -= stack
[stacki
];
9462 /* If we're not the last op, then we definitely can't encode
9463 this using GDB's address_class enum. This is valid for partial
9464 global symbols, although the variable's address will be bogus
9467 dwarf2_complex_location_expr_complaint ();
9470 case DW_OP_GNU_push_tls_address
:
9471 /* The top of the stack has the offset from the beginning
9472 of the thread control block at which the variable is located. */
9473 /* Nothing should follow this operator, so the top of stack would
9475 /* This is valid for partial global symbols, but the variable's
9476 address will be bogus in the psymtab. */
9478 dwarf2_complex_location_expr_complaint ();
9481 case DW_OP_GNU_uninit
:
9485 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9486 dwarf_stack_op_name (op
));
9487 return (stack
[stacki
]);
9490 return (stack
[stacki
]);
9493 /* memory allocation interface */
9495 static struct dwarf_block
*
9496 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9498 struct dwarf_block
*blk
;
9500 blk
= (struct dwarf_block
*)
9501 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9505 static struct abbrev_info
*
9506 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9508 struct abbrev_info
*abbrev
;
9510 abbrev
= (struct abbrev_info
*)
9511 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9512 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9516 static struct die_info
*
9517 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9519 struct die_info
*die
;
9520 size_t size
= sizeof (struct die_info
);
9523 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9525 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9526 memset (die
, 0, sizeof (struct die_info
));
9531 /* Macro support. */
9534 /* Return the full name of file number I in *LH's file name table.
9535 Use COMP_DIR as the name of the current directory of the
9536 compilation. The result is allocated using xmalloc; the caller is
9537 responsible for freeing it. */
9539 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9541 /* Is the file number a valid index into the line header's file name
9542 table? Remember that file numbers start with one, not zero. */
9543 if (1 <= file
&& file
<= lh
->num_file_names
)
9545 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9547 if (IS_ABSOLUTE_PATH (fe
->name
))
9548 return xstrdup (fe
->name
);
9556 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9562 dir_len
= strlen (dir
);
9563 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9564 strcpy (full_name
, dir
);
9565 full_name
[dir_len
] = '/';
9566 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9570 return xstrdup (fe
->name
);
9575 /* The compiler produced a bogus file number. We can at least
9576 record the macro definitions made in the file, even if we
9577 won't be able to find the file by name. */
9579 sprintf (fake_name
, "<bad macro file number %d>", file
);
9581 complaint (&symfile_complaints
,
9582 _("bad file number in macro information (%d)"),
9585 return xstrdup (fake_name
);
9590 static struct macro_source_file
*
9591 macro_start_file (int file
, int line
,
9592 struct macro_source_file
*current_file
,
9593 const char *comp_dir
,
9594 struct line_header
*lh
, struct objfile
*objfile
)
9596 /* The full name of this source file. */
9597 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9599 /* We don't create a macro table for this compilation unit
9600 at all until we actually get a filename. */
9601 if (! pending_macros
)
9602 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9603 objfile
->macro_cache
);
9606 /* If we have no current file, then this must be the start_file
9607 directive for the compilation unit's main source file. */
9608 current_file
= macro_set_main (pending_macros
, full_name
);
9610 current_file
= macro_include (current_file
, line
, full_name
);
9614 return current_file
;
9618 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9619 followed by a null byte. */
9621 copy_string (const char *buf
, int len
)
9623 char *s
= xmalloc (len
+ 1);
9624 memcpy (s
, buf
, len
);
9632 consume_improper_spaces (const char *p
, const char *body
)
9636 complaint (&symfile_complaints
,
9637 _("macro definition contains spaces in formal argument list:\n`%s'"),
9649 parse_macro_definition (struct macro_source_file
*file
, int line
,
9654 /* The body string takes one of two forms. For object-like macro
9655 definitions, it should be:
9657 <macro name> " " <definition>
9659 For function-like macro definitions, it should be:
9661 <macro name> "() " <definition>
9663 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9665 Spaces may appear only where explicitly indicated, and in the
9668 The Dwarf 2 spec says that an object-like macro's name is always
9669 followed by a space, but versions of GCC around March 2002 omit
9670 the space when the macro's definition is the empty string.
9672 The Dwarf 2 spec says that there should be no spaces between the
9673 formal arguments in a function-like macro's formal argument list,
9674 but versions of GCC around March 2002 include spaces after the
9678 /* Find the extent of the macro name. The macro name is terminated
9679 by either a space or null character (for an object-like macro) or
9680 an opening paren (for a function-like macro). */
9681 for (p
= body
; *p
; p
++)
9682 if (*p
== ' ' || *p
== '(')
9685 if (*p
== ' ' || *p
== '\0')
9687 /* It's an object-like macro. */
9688 int name_len
= p
- body
;
9689 char *name
= copy_string (body
, name_len
);
9690 const char *replacement
;
9693 replacement
= body
+ name_len
+ 1;
9696 dwarf2_macro_malformed_definition_complaint (body
);
9697 replacement
= body
+ name_len
;
9700 macro_define_object (file
, line
, name
, replacement
);
9706 /* It's a function-like macro. */
9707 char *name
= copy_string (body
, p
- body
);
9710 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9714 p
= consume_improper_spaces (p
, body
);
9716 /* Parse the formal argument list. */
9717 while (*p
&& *p
!= ')')
9719 /* Find the extent of the current argument name. */
9720 const char *arg_start
= p
;
9722 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9725 if (! *p
|| p
== arg_start
)
9726 dwarf2_macro_malformed_definition_complaint (body
);
9729 /* Make sure argv has room for the new argument. */
9730 if (argc
>= argv_size
)
9733 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9736 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9739 p
= consume_improper_spaces (p
, body
);
9741 /* Consume the comma, if present. */
9746 p
= consume_improper_spaces (p
, body
);
9755 /* Perfectly formed definition, no complaints. */
9756 macro_define_function (file
, line
, name
,
9757 argc
, (const char **) argv
,
9759 else if (*p
== '\0')
9761 /* Complain, but do define it. */
9762 dwarf2_macro_malformed_definition_complaint (body
);
9763 macro_define_function (file
, line
, name
,
9764 argc
, (const char **) argv
,
9768 /* Just complain. */
9769 dwarf2_macro_malformed_definition_complaint (body
);
9772 /* Just complain. */
9773 dwarf2_macro_malformed_definition_complaint (body
);
9779 for (i
= 0; i
< argc
; i
++)
9785 dwarf2_macro_malformed_definition_complaint (body
);
9790 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9791 char *comp_dir
, bfd
*abfd
,
9792 struct dwarf2_cu
*cu
)
9794 gdb_byte
*mac_ptr
, *mac_end
;
9795 struct macro_source_file
*current_file
= 0;
9797 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9799 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9803 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9804 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9805 + dwarf2_per_objfile
->macinfo_size
;
9809 enum dwarf_macinfo_record_type macinfo_type
;
9811 /* Do we at least have room for a macinfo type byte? */
9812 if (mac_ptr
>= mac_end
)
9814 dwarf2_macros_too_long_complaint ();
9818 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9821 switch (macinfo_type
)
9823 /* A zero macinfo type indicates the end of the macro
9828 case DW_MACINFO_define
:
9829 case DW_MACINFO_undef
:
9831 unsigned int bytes_read
;
9835 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9836 mac_ptr
+= bytes_read
;
9837 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9838 mac_ptr
+= bytes_read
;
9841 complaint (&symfile_complaints
,
9842 _("debug info gives macro %s outside of any file: %s"),
9844 DW_MACINFO_define
? "definition" : macinfo_type
==
9845 DW_MACINFO_undef
? "undefinition" :
9846 "something-or-other", body
);
9849 if (macinfo_type
== DW_MACINFO_define
)
9850 parse_macro_definition (current_file
, line
, body
);
9851 else if (macinfo_type
== DW_MACINFO_undef
)
9852 macro_undef (current_file
, line
, body
);
9857 case DW_MACINFO_start_file
:
9859 unsigned int bytes_read
;
9862 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9863 mac_ptr
+= bytes_read
;
9864 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9865 mac_ptr
+= bytes_read
;
9867 current_file
= macro_start_file (file
, line
,
9868 current_file
, comp_dir
,
9873 case DW_MACINFO_end_file
:
9875 complaint (&symfile_complaints
,
9876 _("macro debug info has an unmatched `close_file' directive"));
9879 current_file
= current_file
->included_by
;
9882 enum dwarf_macinfo_record_type next_type
;
9884 /* GCC circa March 2002 doesn't produce the zero
9885 type byte marking the end of the compilation
9886 unit. Complain if it's not there, but exit no
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 /* We don't increment mac_ptr here, so this is just
9898 next_type
= read_1_byte (abfd
, mac_ptr
);
9900 complaint (&symfile_complaints
,
9901 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9908 case DW_MACINFO_vendor_ext
:
9910 unsigned int bytes_read
;
9914 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9915 mac_ptr
+= bytes_read
;
9916 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9917 mac_ptr
+= bytes_read
;
9919 /* We don't recognize any vendor extensions. */
9926 /* Check if the attribute's form is a DW_FORM_block*
9927 if so return true else false. */
9929 attr_form_is_block (struct attribute
*attr
)
9931 return (attr
== NULL
? 0 :
9932 attr
->form
== DW_FORM_block1
9933 || attr
->form
== DW_FORM_block2
9934 || attr
->form
== DW_FORM_block4
9935 || attr
->form
== DW_FORM_block
);
9938 /* Return non-zero if ATTR's value is a section offset --- classes
9939 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
9940 You may use DW_UNSND (attr) to retrieve such offsets.
9942 Section 7.5.4, "Attribute Encodings", explains that no attribute
9943 may have a value that belongs to more than one of these classes; it
9944 would be ambiguous if we did, because we use the same forms for all
9947 attr_form_is_section_offset (struct attribute
*attr
)
9949 return (attr
->form
== DW_FORM_data4
9950 || attr
->form
== DW_FORM_data8
);
9954 /* Return non-zero if ATTR's value falls in the 'constant' class, or
9955 zero otherwise. When this function returns true, you can apply
9956 dwarf2_get_attr_constant_value to it.
9958 However, note that for some attributes you must check
9959 attr_form_is_section_offset before using this test. DW_FORM_data4
9960 and DW_FORM_data8 are members of both the constant class, and of
9961 the classes that contain offsets into other debug sections
9962 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
9963 that, if an attribute's can be either a constant or one of the
9964 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
9965 taken as section offsets, not constants. */
9967 attr_form_is_constant (struct attribute
*attr
)
9984 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9985 struct dwarf2_cu
*cu
)
9987 if (attr_form_is_section_offset (attr
)
9988 /* ".debug_loc" may not exist at all, or the offset may be outside
9989 the section. If so, fall through to the complaint in the
9991 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9993 struct dwarf2_loclist_baton
*baton
;
9995 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9996 sizeof (struct dwarf2_loclist_baton
));
9997 baton
->per_cu
= cu
->per_cu
;
9998 gdb_assert (baton
->per_cu
);
10000 /* We don't know how long the location list is, but make sure we
10001 don't run off the edge of the section. */
10002 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
10003 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
10004 baton
->base_address
= cu
->base_address
;
10005 if (cu
->base_known
== 0)
10006 complaint (&symfile_complaints
,
10007 _("Location list used without specifying the CU base address."));
10009 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
10010 SYMBOL_LOCATION_BATON (sym
) = baton
;
10014 struct dwarf2_locexpr_baton
*baton
;
10016 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10017 sizeof (struct dwarf2_locexpr_baton
));
10018 baton
->per_cu
= cu
->per_cu
;
10019 gdb_assert (baton
->per_cu
);
10021 if (attr_form_is_block (attr
))
10023 /* Note that we're just copying the block's data pointer
10024 here, not the actual data. We're still pointing into the
10025 info_buffer for SYM's objfile; right now we never release
10026 that buffer, but when we do clean up properly this may
10028 baton
->size
= DW_BLOCK (attr
)->size
;
10029 baton
->data
= DW_BLOCK (attr
)->data
;
10033 dwarf2_invalid_attrib_class_complaint ("location description",
10034 SYMBOL_NATURAL_NAME (sym
));
10036 baton
->data
= NULL
;
10039 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
10040 SYMBOL_LOCATION_BATON (sym
) = baton
;
10044 /* Return the OBJFILE associated with the compilation unit CU. */
10047 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10049 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10051 /* Return the master objfile, so that we can report and look up the
10052 correct file containing this variable. */
10053 if (objfile
->separate_debug_objfile_backlink
)
10054 objfile
= objfile
->separate_debug_objfile_backlink
;
10059 /* Return the address size given in the compilation unit header for CU. */
10062 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10065 return per_cu
->cu
->header
.addr_size
;
10068 /* If the CU is not currently read in, we re-read its header. */
10069 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10070 struct dwarf2_per_objfile
*per_objfile
10071 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10072 gdb_byte
*info_ptr
= per_objfile
->info_buffer
+ per_cu
->offset
;
10074 struct comp_unit_head cu_header
;
10075 memset (&cu_header
, 0, sizeof cu_header
);
10076 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10077 return cu_header
.addr_size
;
10081 /* Locate the compilation unit from CU's objfile which contains the
10082 DIE at OFFSET. Raises an error on failure. */
10084 static struct dwarf2_per_cu_data
*
10085 dwarf2_find_containing_comp_unit (unsigned long offset
,
10086 struct objfile
*objfile
)
10088 struct dwarf2_per_cu_data
*this_cu
;
10092 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10095 int mid
= low
+ (high
- low
) / 2;
10096 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10101 gdb_assert (low
== high
);
10102 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10105 error (_("Dwarf Error: could not find partial DIE containing "
10106 "offset 0x%lx [in module %s]"),
10107 (long) offset
, bfd_get_filename (objfile
->obfd
));
10109 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10110 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10114 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10115 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10116 && offset
>= this_cu
->offset
+ this_cu
->length
)
10117 error (_("invalid dwarf2 offset %ld"), offset
);
10118 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10123 /* Locate the compilation unit from OBJFILE which is located at exactly
10124 OFFSET. Raises an error on failure. */
10126 static struct dwarf2_per_cu_data
*
10127 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
10129 struct dwarf2_per_cu_data
*this_cu
;
10130 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10131 if (this_cu
->offset
!= offset
)
10132 error (_("no compilation unit with offset %ld."), offset
);
10136 /* Release one cached compilation unit, CU. We unlink it from the tree
10137 of compilation units, but we don't remove it from the read_in_chain;
10138 the caller is responsible for that. */
10141 free_one_comp_unit (void *data
)
10143 struct dwarf2_cu
*cu
= data
;
10145 if (cu
->per_cu
!= NULL
)
10146 cu
->per_cu
->cu
= NULL
;
10149 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10154 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10155 when we're finished with it. We can't free the pointer itself, but be
10156 sure to unlink it from the cache. Also release any associated storage
10157 and perform cache maintenance.
10159 Only used during partial symbol parsing. */
10162 free_stack_comp_unit (void *data
)
10164 struct dwarf2_cu
*cu
= data
;
10166 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10167 cu
->partial_dies
= NULL
;
10169 if (cu
->per_cu
!= NULL
)
10171 /* This compilation unit is on the stack in our caller, so we
10172 should not xfree it. Just unlink it. */
10173 cu
->per_cu
->cu
= NULL
;
10176 /* If we had a per-cu pointer, then we may have other compilation
10177 units loaded, so age them now. */
10178 age_cached_comp_units ();
10182 /* Free all cached compilation units. */
10185 free_cached_comp_units (void *data
)
10187 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10189 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10190 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10191 while (per_cu
!= NULL
)
10193 struct dwarf2_per_cu_data
*next_cu
;
10195 next_cu
= per_cu
->cu
->read_in_chain
;
10197 free_one_comp_unit (per_cu
->cu
);
10198 *last_chain
= next_cu
;
10204 /* Increase the age counter on each cached compilation unit, and free
10205 any that are too old. */
10208 age_cached_comp_units (void)
10210 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10212 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10213 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10214 while (per_cu
!= NULL
)
10216 per_cu
->cu
->last_used
++;
10217 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10218 dwarf2_mark (per_cu
->cu
);
10219 per_cu
= per_cu
->cu
->read_in_chain
;
10222 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10223 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10224 while (per_cu
!= NULL
)
10226 struct dwarf2_per_cu_data
*next_cu
;
10228 next_cu
= per_cu
->cu
->read_in_chain
;
10230 if (!per_cu
->cu
->mark
)
10232 free_one_comp_unit (per_cu
->cu
);
10233 *last_chain
= next_cu
;
10236 last_chain
= &per_cu
->cu
->read_in_chain
;
10242 /* Remove a single compilation unit from the cache. */
10245 free_one_cached_comp_unit (void *target_cu
)
10247 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10249 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10250 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10251 while (per_cu
!= NULL
)
10253 struct dwarf2_per_cu_data
*next_cu
;
10255 next_cu
= per_cu
->cu
->read_in_chain
;
10257 if (per_cu
->cu
== target_cu
)
10259 free_one_comp_unit (per_cu
->cu
);
10260 *last_chain
= next_cu
;
10264 last_chain
= &per_cu
->cu
->read_in_chain
;
10270 /* Release all extra memory associated with OBJFILE. */
10273 dwarf2_free_objfile (struct objfile
*objfile
)
10275 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10277 if (dwarf2_per_objfile
== NULL
)
10280 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10281 free_cached_comp_units (NULL
);
10283 /* Everything else should be on the objfile obstack. */
10286 /* A pair of DIE offset and GDB type pointer. We store these
10287 in a hash table separate from the DIEs, and preserve them
10288 when the DIEs are flushed out of cache. */
10290 struct dwarf2_offset_and_type
10292 unsigned int offset
;
10296 /* Hash function for a dwarf2_offset_and_type. */
10299 offset_and_type_hash (const void *item
)
10301 const struct dwarf2_offset_and_type
*ofs
= item
;
10302 return ofs
->offset
;
10305 /* Equality function for a dwarf2_offset_and_type. */
10308 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10310 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10311 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10312 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10315 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10316 table if necessary. For convenience, return TYPE. */
10318 static struct type
*
10319 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10321 struct dwarf2_offset_and_type
**slot
, ofs
;
10323 if (cu
->type_hash
== NULL
)
10325 gdb_assert (cu
->per_cu
!= NULL
);
10326 cu
->per_cu
->type_hash
10327 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10328 offset_and_type_hash
,
10329 offset_and_type_eq
,
10331 &cu
->objfile
->objfile_obstack
,
10332 hashtab_obstack_allocate
,
10333 dummy_obstack_deallocate
);
10334 cu
->type_hash
= cu
->per_cu
->type_hash
;
10337 ofs
.offset
= die
->offset
;
10339 slot
= (struct dwarf2_offset_and_type
**)
10340 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10341 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10346 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10347 not have a saved type. */
10349 static struct type
*
10350 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10352 struct dwarf2_offset_and_type
*slot
, ofs
;
10353 htab_t type_hash
= cu
->type_hash
;
10355 if (type_hash
== NULL
)
10358 ofs
.offset
= die
->offset
;
10359 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10366 /* Set the mark field in CU and in every other compilation unit in the
10367 cache that we must keep because we are keeping CU. */
10369 /* Add a dependence relationship from CU to REF_PER_CU. */
10372 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10373 struct dwarf2_per_cu_data
*ref_per_cu
)
10377 if (cu
->dependencies
== NULL
)
10379 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10380 NULL
, &cu
->comp_unit_obstack
,
10381 hashtab_obstack_allocate
,
10382 dummy_obstack_deallocate
);
10384 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10386 *slot
= ref_per_cu
;
10389 /* Set the mark field in CU and in every other compilation unit in the
10390 cache that we must keep because we are keeping CU. */
10393 dwarf2_mark_helper (void **slot
, void *data
)
10395 struct dwarf2_per_cu_data
*per_cu
;
10397 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10398 if (per_cu
->cu
->mark
)
10400 per_cu
->cu
->mark
= 1;
10402 if (per_cu
->cu
->dependencies
!= NULL
)
10403 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10409 dwarf2_mark (struct dwarf2_cu
*cu
)
10414 if (cu
->dependencies
!= NULL
)
10415 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10419 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10423 per_cu
->cu
->mark
= 0;
10424 per_cu
= per_cu
->cu
->read_in_chain
;
10428 /* Trivial hash function for partial_die_info: the hash value of a DIE
10429 is its offset in .debug_info for this objfile. */
10432 partial_die_hash (const void *item
)
10434 const struct partial_die_info
*part_die
= item
;
10435 return part_die
->offset
;
10438 /* Trivial comparison function for partial_die_info structures: two DIEs
10439 are equal if they have the same offset. */
10442 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10444 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10445 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10446 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10449 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10450 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10453 set_dwarf2_cmd (char *args
, int from_tty
)
10455 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10459 show_dwarf2_cmd (char *args
, int from_tty
)
10461 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10464 void _initialize_dwarf2_read (void);
10467 _initialize_dwarf2_read (void)
10469 dwarf2_objfile_data_key
= register_objfile_data ();
10471 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10472 Set DWARF 2 specific variables.\n\
10473 Configure DWARF 2 variables such as the cache size"),
10474 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10475 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10477 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10478 Show DWARF 2 specific variables\n\
10479 Show DWARF 2 variables such as the cache size"),
10480 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10481 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10483 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10484 &dwarf2_max_cache_age
, _("\
10485 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10486 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10487 A higher limit means that cached compilation units will be stored\n\
10488 in memory longer, and more total memory will be used. Zero disables\n\
10489 caching, which can slow down startup."),
10491 show_dwarf2_max_cache_age
,
10492 &set_dwarf2_cmdlist
,
10493 &show_dwarf2_cmdlist
);