1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4 2002, 2003, 2004, 2005, 2006, 2007
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 support in dwarfread.c
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or (at
19 your option) any later version.
21 This program is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA. */
36 #include "elf/dwarf2.h"
39 #include "expression.h"
40 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
45 #include "dwarf2expr.h"
46 #include "dwarf2loc.h"
47 #include "cp-support.h"
53 #include "gdb_string.h"
54 #include "gdb_assert.h"
55 #include <sys/types.h>
57 /* A note on memory usage for this file.
59 At the present time, this code reads the debug info sections into
60 the objfile's objfile_obstack. A definite improvement for startup
61 time, on platforms which do not emit relocations for debug
62 sections, would be to use mmap instead. The object's complete
63 debug information is loaded into memory, partly to simplify
64 absolute DIE references.
66 Whether using obstacks or mmap, the sections should remain loaded
67 until the objfile is released, and pointers into the section data
68 can be used for any other data associated to the objfile (symbol
69 names, type names, location expressions to name a few). */
71 #ifndef DWARF2_REG_TO_REGNUM
72 #define DWARF2_REG_TO_REGNUM(REG) (REG)
76 /* .debug_info header for a compilation unit
77 Because of alignment constraints, this structure has padding and cannot
78 be mapped directly onto the beginning of the .debug_info section. */
79 typedef struct comp_unit_header
81 unsigned int length
; /* length of the .debug_info
83 unsigned short version
; /* version number -- 2 for DWARF
85 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
86 unsigned char addr_size
; /* byte size of an address -- 4 */
89 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
92 /* .debug_pubnames header
93 Because of alignment constraints, this structure has padding and cannot
94 be mapped directly onto the beginning of the .debug_info section. */
95 typedef struct pubnames_header
97 unsigned int length
; /* length of the .debug_pubnames
99 unsigned char version
; /* version number -- 2 for DWARF
101 unsigned int info_offset
; /* offset into .debug_info section */
102 unsigned int info_size
; /* byte size of .debug_info section
106 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
108 /* .debug_pubnames header
109 Because of alignment constraints, this structure has padding and cannot
110 be mapped directly onto the beginning of the .debug_info section. */
111 typedef struct aranges_header
113 unsigned int length
; /* byte len of the .debug_aranges
115 unsigned short version
; /* version number -- 2 for DWARF
117 unsigned int info_offset
; /* offset into .debug_info section */
118 unsigned char addr_size
; /* byte size of an address */
119 unsigned char seg_size
; /* byte size of segment descriptor */
122 #define _ACTUAL_ARANGES_HEADER_SIZE 12
124 /* .debug_line statement program prologue
125 Because of alignment constraints, this structure has padding and cannot
126 be mapped directly onto the beginning of the .debug_info section. */
127 typedef struct statement_prologue
129 unsigned int total_length
; /* byte length of the statement
131 unsigned short version
; /* version number -- 2 for DWARF
133 unsigned int prologue_length
; /* # bytes between prologue &
135 unsigned char minimum_instruction_length
; /* byte size of
137 unsigned char default_is_stmt
; /* initial value of is_stmt
140 unsigned char line_range
;
141 unsigned char opcode_base
; /* number assigned to first special
143 unsigned char *standard_opcode_lengths
;
147 static const struct objfile_data
*dwarf2_objfile_data_key
;
149 struct dwarf2_per_objfile
151 /* Sizes of debugging sections. */
152 unsigned int info_size
;
153 unsigned int abbrev_size
;
154 unsigned int line_size
;
155 unsigned int pubnames_size
;
156 unsigned int aranges_size
;
157 unsigned int loc_size
;
158 unsigned int macinfo_size
;
159 unsigned int str_size
;
160 unsigned int ranges_size
;
161 unsigned int frame_size
;
162 unsigned int eh_frame_size
;
164 /* Loaded data from the sections. */
165 gdb_byte
*info_buffer
;
166 gdb_byte
*abbrev_buffer
;
167 gdb_byte
*line_buffer
;
168 gdb_byte
*str_buffer
;
169 gdb_byte
*macinfo_buffer
;
170 gdb_byte
*ranges_buffer
;
171 gdb_byte
*loc_buffer
;
173 /* A list of all the compilation units. This is used to locate
174 the target compilation unit of a particular reference. */
175 struct dwarf2_per_cu_data
**all_comp_units
;
177 /* The number of compilation units in ALL_COMP_UNITS. */
180 /* A chain of compilation units that are currently read in, so that
181 they can be freed later. */
182 struct dwarf2_per_cu_data
*read_in_chain
;
184 /* A flag indicating wether this objfile has a section loaded at a
186 int has_section_at_zero
;
189 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
191 static asection
*dwarf_info_section
;
192 static asection
*dwarf_abbrev_section
;
193 static asection
*dwarf_line_section
;
194 static asection
*dwarf_pubnames_section
;
195 static asection
*dwarf_aranges_section
;
196 static asection
*dwarf_loc_section
;
197 static asection
*dwarf_macinfo_section
;
198 static asection
*dwarf_str_section
;
199 static asection
*dwarf_ranges_section
;
200 asection
*dwarf_frame_section
;
201 asection
*dwarf_eh_frame_section
;
203 /* names of the debugging sections */
205 #define INFO_SECTION ".debug_info"
206 #define ABBREV_SECTION ".debug_abbrev"
207 #define LINE_SECTION ".debug_line"
208 #define PUBNAMES_SECTION ".debug_pubnames"
209 #define ARANGES_SECTION ".debug_aranges"
210 #define LOC_SECTION ".debug_loc"
211 #define MACINFO_SECTION ".debug_macinfo"
212 #define STR_SECTION ".debug_str"
213 #define RANGES_SECTION ".debug_ranges"
214 #define FRAME_SECTION ".debug_frame"
215 #define EH_FRAME_SECTION ".eh_frame"
217 /* local data types */
219 /* We hold several abbreviation tables in memory at the same time. */
220 #ifndef ABBREV_HASH_SIZE
221 #define ABBREV_HASH_SIZE 121
224 /* The data in a compilation unit header, after target2host
225 translation, looks like this. */
226 struct comp_unit_head
228 unsigned long length
;
230 unsigned int abbrev_offset
;
231 unsigned char addr_size
;
232 unsigned char signed_addr_p
;
234 /* Size of file offsets; either 4 or 8. */
235 unsigned int offset_size
;
237 /* Size of the length field; either 4 or 12. */
238 unsigned int initial_length_size
;
240 /* Offset to the first byte of this compilation unit header in the
241 .debug_info section, for resolving relative reference dies. */
244 /* Pointer to this compilation unit header in the .debug_info
246 gdb_byte
*cu_head_ptr
;
248 /* Pointer to the first die of this compilation unit. This will be
249 the first byte following the compilation unit header. */
250 gdb_byte
*first_die_ptr
;
252 /* Pointer to the next compilation unit header in the program. */
253 struct comp_unit_head
*next
;
255 /* Base address of this compilation unit. */
256 CORE_ADDR base_address
;
258 /* Non-zero if base_address has been set. */
262 /* Fixed size for the DIE hash table. */
263 #ifndef REF_HASH_SIZE
264 #define REF_HASH_SIZE 1021
267 /* Internal state when decoding a particular compilation unit. */
270 /* The objfile containing this compilation unit. */
271 struct objfile
*objfile
;
273 /* The header of the compilation unit.
275 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
276 should logically be moved to the dwarf2_cu structure. */
277 struct comp_unit_head header
;
279 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
281 /* The language we are debugging. */
282 enum language language
;
283 const struct language_defn
*language_defn
;
285 const char *producer
;
287 /* The generic symbol table building routines have separate lists for
288 file scope symbols and all all other scopes (local scopes). So
289 we need to select the right one to pass to add_symbol_to_list().
290 We do it by keeping a pointer to the correct list in list_in_scope.
292 FIXME: The original dwarf code just treated the file scope as the
293 first local scope, and all other local scopes as nested local
294 scopes, and worked fine. Check to see if we really need to
295 distinguish these in buildsym.c. */
296 struct pending
**list_in_scope
;
298 /* Maintain an array of referenced fundamental types for the current
299 compilation unit being read. For DWARF version 1, we have to construct
300 the fundamental types on the fly, since no information about the
301 fundamental types is supplied. Each such fundamental type is created by
302 calling a language dependent routine to create the type, and then a
303 pointer to that type is then placed in the array at the index specified
304 by it's FT_<TYPENAME> value. The array has a fixed size set by the
305 FT_NUM_MEMBERS compile time constant, which is the number of predefined
306 fundamental types gdb knows how to construct. */
307 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
309 /* DWARF abbreviation table associated with this compilation unit. */
310 struct abbrev_info
**dwarf2_abbrevs
;
312 /* Storage for the abbrev table. */
313 struct obstack abbrev_obstack
;
315 /* Hash table holding all the loaded partial DIEs. */
318 /* Storage for things with the same lifetime as this read-in compilation
319 unit, including partial DIEs. */
320 struct obstack comp_unit_obstack
;
322 /* When multiple dwarf2_cu structures are living in memory, this field
323 chains them all together, so that they can be released efficiently.
324 We will probably also want a generation counter so that most-recently-used
325 compilation units are cached... */
326 struct dwarf2_per_cu_data
*read_in_chain
;
328 /* Backchain to our per_cu entry if the tree has been built. */
329 struct dwarf2_per_cu_data
*per_cu
;
331 /* How many compilation units ago was this CU last referenced? */
334 /* A hash table of die offsets for following references. */
335 struct die_info
*die_ref_table
[REF_HASH_SIZE
];
337 /* Full DIEs if read in. */
338 struct die_info
*dies
;
340 /* A set of pointers to dwarf2_per_cu_data objects for compilation
341 units referenced by this one. Only set during full symbol processing;
342 partial symbol tables do not have dependencies. */
345 /* Mark used when releasing cached dies. */
346 unsigned int mark
: 1;
348 /* This flag will be set if this compilation unit might include
349 inter-compilation-unit references. */
350 unsigned int has_form_ref_addr
: 1;
352 /* This flag will be set if this compilation unit includes any
353 DW_TAG_namespace DIEs. If we know that there are explicit
354 DIEs for namespaces, we don't need to try to infer them
355 from mangled names. */
356 unsigned int has_namespace_info
: 1;
359 /* Persistent data held for a compilation unit, even when not
360 processing it. We put a pointer to this structure in the
361 read_symtab_private field of the psymtab. If we encounter
362 inter-compilation-unit references, we also maintain a sorted
363 list of all compilation units. */
365 struct dwarf2_per_cu_data
367 /* The start offset and length of this compilation unit. 2**30-1
368 bytes should suffice to store the length of any compilation unit
369 - if it doesn't, GDB will fall over anyway. */
370 unsigned long offset
;
371 unsigned long length
: 30;
373 /* Flag indicating this compilation unit will be read in before
374 any of the current compilation units are processed. */
375 unsigned long queued
: 1;
377 /* This flag will be set if we need to load absolutely all DIEs
378 for this compilation unit, instead of just the ones we think
379 are interesting. It gets set if we look for a DIE in the
380 hash table and don't find it. */
381 unsigned int load_all_dies
: 1;
383 /* Set iff currently read in. */
384 struct dwarf2_cu
*cu
;
386 /* If full symbols for this CU have been read in, then this field
387 holds a map of DIE offsets to types. It isn't always possible
388 to reconstruct this information later, so we have to preserve
392 /* The partial symbol table associated with this compilation unit,
393 or NULL for partial units (which do not have an associated
395 struct partial_symtab
*psymtab
;
398 /* The line number information for a compilation unit (found in the
399 .debug_line section) begins with a "statement program header",
400 which contains the following information. */
403 unsigned int total_length
;
404 unsigned short version
;
405 unsigned int header_length
;
406 unsigned char minimum_instruction_length
;
407 unsigned char default_is_stmt
;
409 unsigned char line_range
;
410 unsigned char opcode_base
;
412 /* standard_opcode_lengths[i] is the number of operands for the
413 standard opcode whose value is i. This means that
414 standard_opcode_lengths[0] is unused, and the last meaningful
415 element is standard_opcode_lengths[opcode_base - 1]. */
416 unsigned char *standard_opcode_lengths
;
418 /* The include_directories table. NOTE! These strings are not
419 allocated with xmalloc; instead, they are pointers into
420 debug_line_buffer. If you try to free them, `free' will get
422 unsigned int num_include_dirs
, include_dirs_size
;
425 /* The file_names table. NOTE! These strings are not allocated
426 with xmalloc; instead, they are pointers into debug_line_buffer.
427 Don't try to free them directly. */
428 unsigned int num_file_names
, file_names_size
;
432 unsigned int dir_index
;
433 unsigned int mod_time
;
435 int included_p
; /* Non-zero if referenced by the Line Number Program. */
438 /* The start and end of the statement program following this
439 header. These point into dwarf2_per_objfile->line_buffer. */
440 gdb_byte
*statement_program_start
, *statement_program_end
;
443 /* When we construct a partial symbol table entry we only
444 need this much information. */
445 struct partial_die_info
447 /* Offset of this DIE. */
450 /* DWARF-2 tag for this DIE. */
451 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
453 /* Language code associated with this DIE. This is only used
454 for the compilation unit DIE. */
455 unsigned int language
: 8;
457 /* Assorted flags describing the data found in this DIE. */
458 unsigned int has_children
: 1;
459 unsigned int is_external
: 1;
460 unsigned int is_declaration
: 1;
461 unsigned int has_type
: 1;
462 unsigned int has_specification
: 1;
463 unsigned int has_stmt_list
: 1;
464 unsigned int has_pc_info
: 1;
466 /* Flag set if the SCOPE field of this structure has been
468 unsigned int scope_set
: 1;
470 /* Flag set if the DIE has a byte_size attribute. */
471 unsigned int has_byte_size
: 1;
473 /* The name of this DIE. Normally the value of DW_AT_name, but
474 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
479 /* The scope to prepend to our children. This is generally
480 allocated on the comp_unit_obstack, so will disappear
481 when this compilation unit leaves the cache. */
484 /* The location description associated with this DIE, if any. */
485 struct dwarf_block
*locdesc
;
487 /* If HAS_PC_INFO, the PC range associated with this DIE. */
491 /* Pointer into the info_buffer pointing at the target of
492 DW_AT_sibling, if any. */
495 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
496 DW_AT_specification (or DW_AT_abstract_origin or
498 unsigned int spec_offset
;
500 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
501 unsigned int line_offset
;
503 /* Pointers to this DIE's parent, first child, and next sibling,
505 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
508 /* This data structure holds the information of an abbrev. */
511 unsigned int number
; /* number identifying abbrev */
512 enum dwarf_tag tag
; /* dwarf tag */
513 unsigned short has_children
; /* boolean */
514 unsigned short num_attrs
; /* number of attributes */
515 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
516 struct abbrev_info
*next
; /* next in chain */
521 enum dwarf_attribute name
;
522 enum dwarf_form form
;
525 /* This data structure holds a complete die structure. */
528 enum dwarf_tag tag
; /* Tag indicating type of die */
529 unsigned int abbrev
; /* Abbrev number */
530 unsigned int offset
; /* Offset in .debug_info section */
531 unsigned int num_attrs
; /* Number of attributes */
532 struct attribute
*attrs
; /* An array of attributes */
533 struct die_info
*next_ref
; /* Next die in ref hash table */
535 /* The dies in a compilation unit form an n-ary tree. PARENT
536 points to this die's parent; CHILD points to the first child of
537 this node; and all the children of a given node are chained
538 together via their SIBLING fields, terminated by a die whose
540 struct die_info
*child
; /* Its first child, if any. */
541 struct die_info
*sibling
; /* Its next sibling, if any. */
542 struct die_info
*parent
; /* Its parent, if any. */
544 struct type
*type
; /* Cached type information */
547 /* Attributes have a name and a value */
550 enum dwarf_attribute name
;
551 enum dwarf_form form
;
555 struct dwarf_block
*blk
;
563 struct function_range
566 CORE_ADDR lowpc
, highpc
;
568 struct function_range
*next
;
571 /* Get at parts of an attribute structure */
573 #define DW_STRING(attr) ((attr)->u.str)
574 #define DW_UNSND(attr) ((attr)->u.unsnd)
575 #define DW_BLOCK(attr) ((attr)->u.blk)
576 #define DW_SND(attr) ((attr)->u.snd)
577 #define DW_ADDR(attr) ((attr)->u.addr)
579 /* Blocks are a bunch of untyped bytes. */
586 #ifndef ATTR_ALLOC_CHUNK
587 #define ATTR_ALLOC_CHUNK 4
590 /* Allocate fields for structs, unions and enums in this size. */
591 #ifndef DW_FIELD_ALLOC_CHUNK
592 #define DW_FIELD_ALLOC_CHUNK 4
595 /* A zeroed version of a partial die for initialization purposes. */
596 static struct partial_die_info zeroed_partial_die
;
598 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
599 but this would require a corresponding change in unpack_field_as_long
601 static int bits_per_byte
= 8;
603 /* The routines that read and process dies for a C struct or C++ class
604 pass lists of data member fields and lists of member function fields
605 in an instance of a field_info structure, as defined below. */
608 /* List of data member and baseclasses fields. */
611 struct nextfield
*next
;
618 /* Number of fields. */
621 /* Number of baseclasses. */
624 /* Set if the accesibility of one of the fields is not public. */
625 int non_public_fields
;
627 /* Member function fields array, entries are allocated in the order they
628 are encountered in the object file. */
631 struct nextfnfield
*next
;
632 struct fn_field fnfield
;
636 /* Member function fieldlist array, contains name of possibly overloaded
637 member function, number of overloaded member functions and a pointer
638 to the head of the member function field chain. */
643 struct nextfnfield
*head
;
647 /* Number of entries in the fnfieldlists array. */
651 /* One item on the queue of compilation units to read in full symbols
653 struct dwarf2_queue_item
655 struct dwarf2_per_cu_data
*per_cu
;
656 struct dwarf2_queue_item
*next
;
659 /* The current queue. */
660 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
662 /* Loaded secondary compilation units are kept in memory until they
663 have not been referenced for the processing of this many
664 compilation units. Set this to zero to disable caching. Cache
665 sizes of up to at least twenty will improve startup time for
666 typical inter-CU-reference binaries, at an obvious memory cost. */
667 static int dwarf2_max_cache_age
= 5;
669 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
670 struct cmd_list_element
*c
, const char *value
)
672 fprintf_filtered (file
, _("\
673 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
678 /* Various complaints about symbol reading that don't abort the process */
681 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
683 complaint (&symfile_complaints
,
684 _("statement list doesn't fit in .debug_line section"));
688 dwarf2_complex_location_expr_complaint (void)
690 complaint (&symfile_complaints
, _("location expression too complex"));
694 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
697 complaint (&symfile_complaints
,
698 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
703 dwarf2_macros_too_long_complaint (void)
705 complaint (&symfile_complaints
,
706 _("macro info runs off end of `.debug_macinfo' section"));
710 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
712 complaint (&symfile_complaints
,
713 _("macro debug info contains a malformed macro definition:\n`%s'"),
718 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
720 complaint (&symfile_complaints
,
721 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
724 /* local function prototypes */
726 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
729 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
732 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
735 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
736 struct partial_die_info
*,
737 struct partial_symtab
*);
739 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
741 static void scan_partial_symbols (struct partial_die_info
*,
742 CORE_ADDR
*, CORE_ADDR
*,
745 static void add_partial_symbol (struct partial_die_info
*,
748 static int pdi_needs_namespace (enum dwarf_tag tag
);
750 static void add_partial_namespace (struct partial_die_info
*pdi
,
751 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
752 struct dwarf2_cu
*cu
);
754 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
755 struct dwarf2_cu
*cu
);
757 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
760 struct dwarf2_cu
*cu
);
762 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
764 static void psymtab_to_symtab_1 (struct partial_symtab
*);
766 gdb_byte
*dwarf2_read_section (struct objfile
*, asection
*);
768 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
770 static void dwarf2_free_abbrev_table (void *);
772 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
775 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
778 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
781 static gdb_byte
*read_partial_die (struct partial_die_info
*,
782 struct abbrev_info
*abbrev
, unsigned int,
783 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
785 static struct partial_die_info
*find_partial_die (unsigned long,
788 static void fixup_partial_die (struct partial_die_info
*,
791 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
792 struct dwarf2_cu
*, int *);
794 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
795 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
797 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
798 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
800 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
802 static int read_1_signed_byte (bfd
*, gdb_byte
*);
804 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
806 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
808 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
810 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
813 static LONGEST
read_initial_length (bfd
*, gdb_byte
*,
814 struct comp_unit_head
*, unsigned int *);
816 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
819 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
821 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
823 static char *read_indirect_string (bfd
*, gdb_byte
*,
824 const struct comp_unit_head
*,
827 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
829 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
831 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
833 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
835 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
838 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
839 struct dwarf2_cu
*cu
);
841 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
843 static struct die_info
*die_specification (struct die_info
*die
,
846 static void free_line_header (struct line_header
*lh
);
848 static void add_file_name (struct line_header
*, char *, unsigned int,
849 unsigned int, unsigned int);
851 static struct line_header
*(dwarf_decode_line_header
852 (unsigned int offset
,
853 bfd
*abfd
, struct dwarf2_cu
*cu
));
855 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
856 struct dwarf2_cu
*, struct partial_symtab
*);
858 static void dwarf2_start_subfile (char *, char *, char *);
860 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
863 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
866 static void dwarf2_const_value_data (struct attribute
*attr
,
870 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
872 static struct type
*die_containing_type (struct die_info
*,
875 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
877 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
879 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
881 static char *typename_concat (struct obstack
*,
886 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
888 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
890 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
892 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
894 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
896 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
898 static int dwarf2_get_pc_bounds (struct die_info
*,
899 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
901 static void get_scope_pc_bounds (struct die_info
*,
902 CORE_ADDR
*, CORE_ADDR
*,
905 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
908 static void dwarf2_attach_fields_to_type (struct field_info
*,
909 struct type
*, struct dwarf2_cu
*);
911 static void dwarf2_add_member_fn (struct field_info
*,
912 struct die_info
*, struct type
*,
915 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
916 struct type
*, struct dwarf2_cu
*);
918 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
920 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
922 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
924 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
926 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
928 static const char *namespace_name (struct die_info
*die
,
929 int *is_anonymous
, struct dwarf2_cu
*);
931 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
933 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
935 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
937 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
939 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
941 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
944 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
946 static void read_tag_ptr_to_member_type (struct die_info
*,
949 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
951 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
953 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
955 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
957 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
959 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
961 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
963 gdb_byte
**new_info_ptr
,
964 struct die_info
*parent
);
966 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
968 gdb_byte
**new_info_ptr
,
969 struct die_info
*parent
);
971 static void free_die_list (struct die_info
*);
973 static void process_die (struct die_info
*, struct dwarf2_cu
*);
975 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
977 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
979 static struct die_info
*dwarf2_extension (struct die_info
*die
,
982 static char *dwarf_tag_name (unsigned int);
984 static char *dwarf_attr_name (unsigned int);
986 static char *dwarf_form_name (unsigned int);
988 static char *dwarf_stack_op_name (unsigned int);
990 static char *dwarf_bool_name (unsigned int);
992 static char *dwarf_type_encoding_name (unsigned int);
995 static char *dwarf_cfi_name (unsigned int);
997 struct die_info
*copy_die (struct die_info
*);
1000 static struct die_info
*sibling_die (struct die_info
*);
1002 static void dump_die (struct die_info
*);
1004 static void dump_die_list (struct die_info
*);
1006 static void store_in_ref_table (unsigned int, struct die_info
*,
1007 struct dwarf2_cu
*);
1009 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
1010 struct dwarf2_cu
*);
1012 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1014 static struct die_info
*follow_die_ref (struct die_info
*,
1016 struct dwarf2_cu
*);
1018 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
1019 struct dwarf2_cu
*);
1021 /* memory allocation interface */
1023 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1025 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1027 static struct die_info
*dwarf_alloc_die (void);
1029 static void initialize_cu_func_list (struct dwarf2_cu
*);
1031 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1032 struct dwarf2_cu
*);
1034 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1035 char *, bfd
*, struct dwarf2_cu
*);
1037 static int attr_form_is_block (struct attribute
*);
1040 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
1041 struct dwarf2_cu
*cu
);
1043 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1044 struct dwarf2_cu
*cu
);
1046 static void free_stack_comp_unit (void *);
1048 static hashval_t
partial_die_hash (const void *item
);
1050 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1052 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1053 (unsigned long offset
, struct objfile
*objfile
);
1055 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1056 (unsigned long offset
, struct objfile
*objfile
);
1058 static void free_one_comp_unit (void *);
1060 static void free_cached_comp_units (void *);
1062 static void age_cached_comp_units (void);
1064 static void free_one_cached_comp_unit (void *);
1066 static void set_die_type (struct die_info
*, struct type
*,
1067 struct dwarf2_cu
*);
1069 static void reset_die_and_siblings_types (struct die_info
*,
1070 struct dwarf2_cu
*);
1072 static void create_all_comp_units (struct objfile
*);
1074 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1077 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1079 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1080 struct dwarf2_per_cu_data
*);
1082 static void dwarf2_mark (struct dwarf2_cu
*);
1084 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1086 static void read_set_type (struct die_info
*, struct dwarf2_cu
*);
1089 /* Try to locate the sections we need for DWARF 2 debugging
1090 information and return true if we have enough to do something. */
1093 dwarf2_has_info (struct objfile
*objfile
)
1095 struct dwarf2_per_objfile
*data
;
1097 /* Initialize per-objfile state. */
1098 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1099 memset (data
, 0, sizeof (*data
));
1100 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1101 dwarf2_per_objfile
= data
;
1103 dwarf_info_section
= 0;
1104 dwarf_abbrev_section
= 0;
1105 dwarf_line_section
= 0;
1106 dwarf_str_section
= 0;
1107 dwarf_macinfo_section
= 0;
1108 dwarf_frame_section
= 0;
1109 dwarf_eh_frame_section
= 0;
1110 dwarf_ranges_section
= 0;
1111 dwarf_loc_section
= 0;
1113 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1114 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1117 /* This function is mapped across the sections and remembers the
1118 offset and size of each of the debugging sections we are interested
1122 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1124 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
1126 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1127 dwarf_info_section
= sectp
;
1129 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
1131 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1132 dwarf_abbrev_section
= sectp
;
1134 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
1136 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1137 dwarf_line_section
= sectp
;
1139 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
1141 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1142 dwarf_pubnames_section
= sectp
;
1144 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
1146 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1147 dwarf_aranges_section
= sectp
;
1149 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1151 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1152 dwarf_loc_section
= sectp
;
1154 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1156 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1157 dwarf_macinfo_section
= sectp
;
1159 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1161 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1162 dwarf_str_section
= sectp
;
1164 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1166 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1167 dwarf_frame_section
= sectp
;
1169 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1171 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1172 if (aflag
& SEC_HAS_CONTENTS
)
1174 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1175 dwarf_eh_frame_section
= sectp
;
1178 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1180 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1181 dwarf_ranges_section
= sectp
;
1184 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1185 && bfd_section_vma (abfd
, sectp
) == 0)
1186 dwarf2_per_objfile
->has_section_at_zero
= 1;
1189 /* Build a partial symbol table. */
1192 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1194 /* We definitely need the .debug_info and .debug_abbrev sections */
1196 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1197 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1199 if (dwarf_line_section
)
1200 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1202 dwarf2_per_objfile
->line_buffer
= NULL
;
1204 if (dwarf_str_section
)
1205 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1207 dwarf2_per_objfile
->str_buffer
= NULL
;
1209 if (dwarf_macinfo_section
)
1210 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1211 dwarf_macinfo_section
);
1213 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1215 if (dwarf_ranges_section
)
1216 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1218 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1220 if (dwarf_loc_section
)
1221 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1223 dwarf2_per_objfile
->loc_buffer
= NULL
;
1226 || (objfile
->global_psymbols
.size
== 0
1227 && objfile
->static_psymbols
.size
== 0))
1229 init_psymbol_list (objfile
, 1024);
1233 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1235 /* Things are significantly easier if we have .debug_aranges and
1236 .debug_pubnames sections */
1238 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1242 /* only test this case for now */
1244 /* In this case we have to work a bit harder */
1245 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1250 /* Build the partial symbol table from the information in the
1251 .debug_pubnames and .debug_aranges sections. */
1254 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1256 bfd
*abfd
= objfile
->obfd
;
1257 char *aranges_buffer
, *pubnames_buffer
;
1258 char *aranges_ptr
, *pubnames_ptr
;
1259 unsigned int entry_length
, version
, info_offset
, info_size
;
1261 pubnames_buffer
= dwarf2_read_section (objfile
,
1262 dwarf_pubnames_section
);
1263 pubnames_ptr
= pubnames_buffer
;
1264 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1266 struct comp_unit_head cu_header
;
1267 unsigned int bytes_read
;
1269 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1271 pubnames_ptr
+= bytes_read
;
1272 version
= read_1_byte (abfd
, pubnames_ptr
);
1274 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1276 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1280 aranges_buffer
= dwarf2_read_section (objfile
,
1281 dwarf_aranges_section
);
1286 /* Read in the comp unit header information from the debug_info at
1290 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1291 gdb_byte
*info_ptr
, bfd
*abfd
)
1294 unsigned int bytes_read
;
1295 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1297 info_ptr
+= bytes_read
;
1298 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1300 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1302 info_ptr
+= bytes_read
;
1303 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1305 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1306 if (signed_addr
< 0)
1307 internal_error (__FILE__
, __LINE__
,
1308 _("read_comp_unit_head: dwarf from non elf file"));
1309 cu_header
->signed_addr_p
= signed_addr
;
1314 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1317 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1319 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1321 if (header
->version
!= 2 && header
->version
!= 3)
1322 error (_("Dwarf Error: wrong version in compilation unit header "
1323 "(is %d, should be %d) [in module %s]"), header
->version
,
1324 2, bfd_get_filename (abfd
));
1326 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1327 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1328 "(offset 0x%lx + 6) [in module %s]"),
1329 (long) header
->abbrev_offset
,
1330 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1331 bfd_get_filename (abfd
));
1333 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1334 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1335 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1336 "(offset 0x%lx + 0) [in module %s]"),
1337 (long) header
->length
,
1338 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1339 bfd_get_filename (abfd
));
1344 /* Allocate a new partial symtab for file named NAME and mark this new
1345 partial symtab as being an include of PST. */
1348 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1349 struct objfile
*objfile
)
1351 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1353 subpst
->section_offsets
= pst
->section_offsets
;
1354 subpst
->textlow
= 0;
1355 subpst
->texthigh
= 0;
1357 subpst
->dependencies
= (struct partial_symtab
**)
1358 obstack_alloc (&objfile
->objfile_obstack
,
1359 sizeof (struct partial_symtab
*));
1360 subpst
->dependencies
[0] = pst
;
1361 subpst
->number_of_dependencies
= 1;
1363 subpst
->globals_offset
= 0;
1364 subpst
->n_global_syms
= 0;
1365 subpst
->statics_offset
= 0;
1366 subpst
->n_static_syms
= 0;
1367 subpst
->symtab
= NULL
;
1368 subpst
->read_symtab
= pst
->read_symtab
;
1371 /* No private part is necessary for include psymtabs. This property
1372 can be used to differentiate between such include psymtabs and
1373 the regular ones. */
1374 subpst
->read_symtab_private
= NULL
;
1377 /* Read the Line Number Program data and extract the list of files
1378 included by the source file represented by PST. Build an include
1379 partial symtab for each of these included files.
1381 This procedure assumes that there *is* a Line Number Program in
1382 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1383 before calling this procedure. */
1386 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1387 struct partial_die_info
*pdi
,
1388 struct partial_symtab
*pst
)
1390 struct objfile
*objfile
= cu
->objfile
;
1391 bfd
*abfd
= objfile
->obfd
;
1392 struct line_header
*lh
;
1394 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1396 return; /* No linetable, so no includes. */
1398 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1400 free_line_header (lh
);
1404 /* Build the partial symbol table by doing a quick pass through the
1405 .debug_info and .debug_abbrev sections. */
1408 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1410 /* Instead of reading this into a big buffer, we should probably use
1411 mmap() on architectures that support it. (FIXME) */
1412 bfd
*abfd
= objfile
->obfd
;
1414 gdb_byte
*beg_of_comp_unit
;
1415 struct partial_die_info comp_unit_die
;
1416 struct partial_symtab
*pst
;
1417 struct cleanup
*back_to
;
1418 CORE_ADDR lowpc
, highpc
, baseaddr
;
1420 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1422 /* Any cached compilation units will be linked by the per-objfile
1423 read_in_chain. Make sure to free them when we're done. */
1424 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1426 create_all_comp_units (objfile
);
1428 /* Since the objects we're extracting from .debug_info vary in
1429 length, only the individual functions to extract them (like
1430 read_comp_unit_head and load_partial_die) can really know whether
1431 the buffer is large enough to hold another complete object.
1433 At the moment, they don't actually check that. If .debug_info
1434 holds just one extra byte after the last compilation unit's dies,
1435 then read_comp_unit_head will happily read off the end of the
1436 buffer. read_partial_die is similarly casual. Those functions
1439 For this loop condition, simply checking whether there's any data
1440 left at all should be sufficient. */
1441 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1442 + dwarf2_per_objfile
->info_size
))
1444 struct cleanup
*back_to_inner
;
1445 struct dwarf2_cu cu
;
1446 struct abbrev_info
*abbrev
;
1447 unsigned int bytes_read
;
1448 struct dwarf2_per_cu_data
*this_cu
;
1450 beg_of_comp_unit
= info_ptr
;
1452 memset (&cu
, 0, sizeof (cu
));
1454 obstack_init (&cu
.comp_unit_obstack
);
1456 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1458 cu
.objfile
= objfile
;
1459 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1461 /* Complete the cu_header */
1462 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1463 cu
.header
.first_die_ptr
= info_ptr
;
1464 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1466 cu
.list_in_scope
= &file_symbols
;
1468 /* Read the abbrevs for this compilation unit into a table */
1469 dwarf2_read_abbrevs (abfd
, &cu
);
1470 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1472 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1474 /* Read the compilation unit die */
1475 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1476 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1477 abfd
, info_ptr
, &cu
);
1479 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1481 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1482 + cu
.header
.initial_length_size
);
1483 do_cleanups (back_to_inner
);
1487 /* Set the language we're debugging */
1488 set_cu_language (comp_unit_die
.language
, &cu
);
1490 /* Allocate a new partial symbol table structure */
1491 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1492 comp_unit_die
.name
? comp_unit_die
.name
: "",
1493 comp_unit_die
.lowpc
,
1494 objfile
->global_psymbols
.next
,
1495 objfile
->static_psymbols
.next
);
1497 if (comp_unit_die
.dirname
)
1498 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1500 pst
->read_symtab_private
= (char *) this_cu
;
1502 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1504 /* Store the function that reads in the rest of the symbol table */
1505 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1507 /* If this compilation unit was already read in, free the
1508 cached copy in order to read it in again. This is
1509 necessary because we skipped some symbols when we first
1510 read in the compilation unit (see load_partial_dies).
1511 This problem could be avoided, but the benefit is
1513 if (this_cu
->cu
!= NULL
)
1514 free_one_cached_comp_unit (this_cu
->cu
);
1516 cu
.per_cu
= this_cu
;
1518 /* Note that this is a pointer to our stack frame, being
1519 added to a global data structure. It will be cleaned up
1520 in free_stack_comp_unit when we finish with this
1521 compilation unit. */
1524 this_cu
->psymtab
= pst
;
1526 /* Check if comp unit has_children.
1527 If so, read the rest of the partial symbols from this comp unit.
1528 If not, there's no more debug_info for this comp unit. */
1529 if (comp_unit_die
.has_children
)
1531 struct partial_die_info
*first_die
;
1533 lowpc
= ((CORE_ADDR
) -1);
1534 highpc
= ((CORE_ADDR
) 0);
1536 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1538 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1540 /* If we didn't find a lowpc, set it to highpc to avoid
1541 complaints from `maint check'. */
1542 if (lowpc
== ((CORE_ADDR
) -1))
1545 /* If the compilation unit didn't have an explicit address range,
1546 then use the information extracted from its child dies. */
1547 if (! comp_unit_die
.has_pc_info
)
1549 comp_unit_die
.lowpc
= lowpc
;
1550 comp_unit_die
.highpc
= highpc
;
1553 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1554 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1556 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1557 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1558 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1559 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1560 sort_pst_symbols (pst
);
1562 /* If there is already a psymtab or symtab for a file of this
1563 name, remove it. (If there is a symtab, more drastic things
1564 also happen.) This happens in VxWorks. */
1565 free_named_symtabs (pst
->filename
);
1567 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1568 + cu
.header
.initial_length_size
;
1570 if (comp_unit_die
.has_stmt_list
)
1572 /* Get the list of files included in the current compilation unit,
1573 and build a psymtab for each of them. */
1574 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1577 do_cleanups (back_to_inner
);
1579 do_cleanups (back_to
);
1582 /* Load the DIEs for a secondary CU into memory. */
1585 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1587 bfd
*abfd
= objfile
->obfd
;
1588 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1589 struct partial_die_info comp_unit_die
;
1590 struct dwarf2_cu
*cu
;
1591 struct abbrev_info
*abbrev
;
1592 unsigned int bytes_read
;
1593 struct cleanup
*back_to
;
1595 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1596 beg_of_comp_unit
= info_ptr
;
1598 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1599 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1601 obstack_init (&cu
->comp_unit_obstack
);
1603 cu
->objfile
= objfile
;
1604 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1606 /* Complete the cu_header. */
1607 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1608 cu
->header
.first_die_ptr
= info_ptr
;
1609 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1611 /* Read the abbrevs for this compilation unit into a table. */
1612 dwarf2_read_abbrevs (abfd
, cu
);
1613 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1615 /* Read the compilation unit die. */
1616 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1617 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1618 abfd
, info_ptr
, cu
);
1620 /* Set the language we're debugging. */
1621 set_cu_language (comp_unit_die
.language
, cu
);
1623 /* Link this compilation unit into the compilation unit tree. */
1625 cu
->per_cu
= this_cu
;
1627 /* Check if comp unit has_children.
1628 If so, read the rest of the partial symbols from this comp unit.
1629 If not, there's no more debug_info for this comp unit. */
1630 if (comp_unit_die
.has_children
)
1631 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1633 do_cleanups (back_to
);
1636 /* Create a list of all compilation units in OBJFILE. We do this only
1637 if an inter-comp-unit reference is found; presumably if there is one,
1638 there will be many, and one will occur early in the .debug_info section.
1639 So there's no point in building this list incrementally. */
1642 create_all_comp_units (struct objfile
*objfile
)
1646 struct dwarf2_per_cu_data
**all_comp_units
;
1647 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info_buffer
;
1651 all_comp_units
= xmalloc (n_allocated
1652 * sizeof (struct dwarf2_per_cu_data
*));
1654 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1656 struct comp_unit_head cu_header
;
1657 gdb_byte
*beg_of_comp_unit
;
1658 struct dwarf2_per_cu_data
*this_cu
;
1659 unsigned long offset
;
1660 unsigned int bytes_read
;
1662 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1664 /* Read just enough information to find out where the next
1665 compilation unit is. */
1666 cu_header
.initial_length_size
= 0;
1667 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1668 &cu_header
, &bytes_read
);
1670 /* Save the compilation unit for later lookup. */
1671 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1672 sizeof (struct dwarf2_per_cu_data
));
1673 memset (this_cu
, 0, sizeof (*this_cu
));
1674 this_cu
->offset
= offset
;
1675 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1677 if (n_comp_units
== n_allocated
)
1680 all_comp_units
= xrealloc (all_comp_units
,
1682 * sizeof (struct dwarf2_per_cu_data
*));
1684 all_comp_units
[n_comp_units
++] = this_cu
;
1686 info_ptr
= info_ptr
+ this_cu
->length
;
1689 dwarf2_per_objfile
->all_comp_units
1690 = obstack_alloc (&objfile
->objfile_obstack
,
1691 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1692 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1693 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1694 xfree (all_comp_units
);
1695 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1698 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1699 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1703 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1704 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1706 struct objfile
*objfile
= cu
->objfile
;
1707 bfd
*abfd
= objfile
->obfd
;
1708 struct partial_die_info
*pdi
;
1710 /* Now, march along the PDI's, descending into ones which have
1711 interesting children but skipping the children of the other ones,
1712 until we reach the end of the compilation unit. */
1718 fixup_partial_die (pdi
, cu
);
1720 /* Anonymous namespaces have no name but have interesting
1721 children, so we need to look at them. Ditto for anonymous
1724 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1725 || pdi
->tag
== DW_TAG_enumeration_type
)
1729 case DW_TAG_subprogram
:
1730 if (pdi
->has_pc_info
)
1732 if (pdi
->lowpc
< *lowpc
)
1734 *lowpc
= pdi
->lowpc
;
1736 if (pdi
->highpc
> *highpc
)
1738 *highpc
= pdi
->highpc
;
1740 if (!pdi
->is_declaration
)
1742 add_partial_symbol (pdi
, cu
);
1746 case DW_TAG_variable
:
1747 case DW_TAG_typedef
:
1748 case DW_TAG_union_type
:
1749 if (!pdi
->is_declaration
)
1751 add_partial_symbol (pdi
, cu
);
1754 case DW_TAG_class_type
:
1755 case DW_TAG_structure_type
:
1756 if (!pdi
->is_declaration
)
1758 add_partial_symbol (pdi
, cu
);
1761 case DW_TAG_enumeration_type
:
1762 if (!pdi
->is_declaration
)
1763 add_partial_enumeration (pdi
, cu
);
1765 case DW_TAG_base_type
:
1766 case DW_TAG_subrange_type
:
1767 /* File scope base type definitions are added to the partial
1769 add_partial_symbol (pdi
, cu
);
1771 case DW_TAG_namespace
:
1772 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1779 /* If the die has a sibling, skip to the sibling. */
1781 pdi
= pdi
->die_sibling
;
1785 /* Functions used to compute the fully scoped name of a partial DIE.
1787 Normally, this is simple. For C++, the parent DIE's fully scoped
1788 name is concatenated with "::" and the partial DIE's name. For
1789 Java, the same thing occurs except that "." is used instead of "::".
1790 Enumerators are an exception; they use the scope of their parent
1791 enumeration type, i.e. the name of the enumeration type is not
1792 prepended to the enumerator.
1794 There are two complexities. One is DW_AT_specification; in this
1795 case "parent" means the parent of the target of the specification,
1796 instead of the direct parent of the DIE. The other is compilers
1797 which do not emit DW_TAG_namespace; in this case we try to guess
1798 the fully qualified name of structure types from their members'
1799 linkage names. This must be done using the DIE's children rather
1800 than the children of any DW_AT_specification target. We only need
1801 to do this for structures at the top level, i.e. if the target of
1802 any DW_AT_specification (if any; otherwise the DIE itself) does not
1805 /* Compute the scope prefix associated with PDI's parent, in
1806 compilation unit CU. The result will be allocated on CU's
1807 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1808 field. NULL is returned if no prefix is necessary. */
1810 partial_die_parent_scope (struct partial_die_info
*pdi
,
1811 struct dwarf2_cu
*cu
)
1813 char *grandparent_scope
;
1814 struct partial_die_info
*parent
, *real_pdi
;
1816 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1817 then this means the parent of the specification DIE. */
1820 while (real_pdi
->has_specification
)
1821 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
1823 parent
= real_pdi
->die_parent
;
1827 if (parent
->scope_set
)
1828 return parent
->scope
;
1830 fixup_partial_die (parent
, cu
);
1832 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
1834 if (parent
->tag
== DW_TAG_namespace
1835 || parent
->tag
== DW_TAG_structure_type
1836 || parent
->tag
== DW_TAG_class_type
1837 || parent
->tag
== DW_TAG_union_type
)
1839 if (grandparent_scope
== NULL
)
1840 parent
->scope
= parent
->name
;
1842 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1845 else if (parent
->tag
== DW_TAG_enumeration_type
)
1846 /* Enumerators should not get the name of the enumeration as a prefix. */
1847 parent
->scope
= grandparent_scope
;
1850 /* FIXME drow/2004-04-01: What should we be doing with
1851 function-local names? For partial symbols, we should probably be
1853 complaint (&symfile_complaints
,
1854 _("unhandled containing DIE tag %d for DIE at %d"),
1855 parent
->tag
, pdi
->offset
);
1856 parent
->scope
= grandparent_scope
;
1859 parent
->scope_set
= 1;
1860 return parent
->scope
;
1863 /* Return the fully scoped name associated with PDI, from compilation unit
1864 CU. The result will be allocated with malloc. */
1866 partial_die_full_name (struct partial_die_info
*pdi
,
1867 struct dwarf2_cu
*cu
)
1871 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1872 if (parent_scope
== NULL
)
1875 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1879 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1881 struct objfile
*objfile
= cu
->objfile
;
1884 const char *my_prefix
;
1885 const struct partial_symbol
*psym
= NULL
;
1887 int built_actual_name
= 0;
1889 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1893 if (pdi_needs_namespace (pdi
->tag
))
1895 actual_name
= partial_die_full_name (pdi
, cu
);
1897 built_actual_name
= 1;
1900 if (actual_name
== NULL
)
1901 actual_name
= pdi
->name
;
1905 case DW_TAG_subprogram
:
1906 if (pdi
->is_external
)
1908 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1909 mst_text, objfile); */
1910 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1911 VAR_DOMAIN
, LOC_BLOCK
,
1912 &objfile
->global_psymbols
,
1913 0, pdi
->lowpc
+ baseaddr
,
1914 cu
->language
, objfile
);
1918 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1919 mst_file_text, objfile); */
1920 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1921 VAR_DOMAIN
, LOC_BLOCK
,
1922 &objfile
->static_psymbols
,
1923 0, pdi
->lowpc
+ baseaddr
,
1924 cu
->language
, objfile
);
1927 case DW_TAG_variable
:
1928 if (pdi
->is_external
)
1931 Don't enter into the minimal symbol tables as there is
1932 a minimal symbol table entry from the ELF symbols already.
1933 Enter into partial symbol table if it has a location
1934 descriptor or a type.
1935 If the location descriptor is missing, new_symbol will create
1936 a LOC_UNRESOLVED symbol, the address of the variable will then
1937 be determined from the minimal symbol table whenever the variable
1939 The address for the partial symbol table entry is not
1940 used by GDB, but it comes in handy for debugging partial symbol
1944 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1945 if (pdi
->locdesc
|| pdi
->has_type
)
1946 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1947 VAR_DOMAIN
, LOC_STATIC
,
1948 &objfile
->global_psymbols
,
1950 cu
->language
, objfile
);
1954 /* Static Variable. Skip symbols without location descriptors. */
1955 if (pdi
->locdesc
== NULL
)
1957 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1958 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1959 mst_file_data, objfile); */
1960 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1961 VAR_DOMAIN
, LOC_STATIC
,
1962 &objfile
->static_psymbols
,
1964 cu
->language
, objfile
);
1967 case DW_TAG_typedef
:
1968 case DW_TAG_base_type
:
1969 case DW_TAG_subrange_type
:
1970 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1971 VAR_DOMAIN
, LOC_TYPEDEF
,
1972 &objfile
->static_psymbols
,
1973 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1975 case DW_TAG_namespace
:
1976 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1977 VAR_DOMAIN
, LOC_TYPEDEF
,
1978 &objfile
->global_psymbols
,
1979 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1981 case DW_TAG_class_type
:
1982 case DW_TAG_structure_type
:
1983 case DW_TAG_union_type
:
1984 case DW_TAG_enumeration_type
:
1985 /* Skip external references. The DWARF standard says in the section
1986 about "Structure, Union, and Class Type Entries": "An incomplete
1987 structure, union or class type is represented by a structure,
1988 union or class entry that does not have a byte size attribute
1989 and that has a DW_AT_declaration attribute." */
1990 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
1993 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1994 static vs. global. */
1995 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1996 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1997 (cu
->language
== language_cplus
1998 || cu
->language
== language_java
)
1999 ? &objfile
->global_psymbols
2000 : &objfile
->static_psymbols
,
2001 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2003 if (cu
->language
== language_cplus
2004 || cu
->language
== language_java
)
2006 /* For C++ and Java, these implicitly act as typedefs as well. */
2007 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2008 VAR_DOMAIN
, LOC_TYPEDEF
,
2009 &objfile
->global_psymbols
,
2010 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2013 case DW_TAG_enumerator
:
2014 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2015 VAR_DOMAIN
, LOC_CONST
,
2016 (cu
->language
== language_cplus
2017 || cu
->language
== language_java
)
2018 ? &objfile
->global_psymbols
2019 : &objfile
->static_psymbols
,
2020 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2026 /* Check to see if we should scan the name for possible namespace
2027 info. Only do this if this is C++, if we don't have namespace
2028 debugging info in the file, if the psym is of an appropriate type
2029 (otherwise we'll have psym == NULL), and if we actually had a
2030 mangled name to begin with. */
2032 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2033 cases which do not set PSYM above? */
2035 if (cu
->language
== language_cplus
2036 && cu
->has_namespace_info
== 0
2038 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2039 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2042 if (built_actual_name
)
2043 xfree (actual_name
);
2046 /* Determine whether a die of type TAG living in a C++ class or
2047 namespace needs to have the name of the scope prepended to the
2048 name listed in the die. */
2051 pdi_needs_namespace (enum dwarf_tag tag
)
2055 case DW_TAG_namespace
:
2056 case DW_TAG_typedef
:
2057 case DW_TAG_class_type
:
2058 case DW_TAG_structure_type
:
2059 case DW_TAG_union_type
:
2060 case DW_TAG_enumeration_type
:
2061 case DW_TAG_enumerator
:
2068 /* Read a partial die corresponding to a namespace; also, add a symbol
2069 corresponding to that namespace to the symbol table. NAMESPACE is
2070 the name of the enclosing namespace. */
2073 add_partial_namespace (struct partial_die_info
*pdi
,
2074 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2075 struct dwarf2_cu
*cu
)
2077 struct objfile
*objfile
= cu
->objfile
;
2079 /* Add a symbol for the namespace. */
2081 add_partial_symbol (pdi
, cu
);
2083 /* Now scan partial symbols in that namespace. */
2085 if (pdi
->has_children
)
2086 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2089 /* See if we can figure out if the class lives in a namespace. We do
2090 this by looking for a member function; its demangled name will
2091 contain namespace info, if there is any. */
2094 guess_structure_name (struct partial_die_info
*struct_pdi
,
2095 struct dwarf2_cu
*cu
)
2097 if ((cu
->language
== language_cplus
2098 || cu
->language
== language_java
)
2099 && cu
->has_namespace_info
== 0
2100 && struct_pdi
->has_children
)
2102 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2103 what template types look like, because the demangler
2104 frequently doesn't give the same name as the debug info. We
2105 could fix this by only using the demangled name to get the
2106 prefix (but see comment in read_structure_type). */
2108 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2109 struct partial_die_info
*real_pdi
;
2111 /* If this DIE (this DIE's specification, if any) has a parent, then
2112 we should not do this. We'll prepend the parent's fully qualified
2113 name when we create the partial symbol. */
2115 real_pdi
= struct_pdi
;
2116 while (real_pdi
->has_specification
)
2117 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2119 if (real_pdi
->die_parent
!= NULL
)
2122 while (child_pdi
!= NULL
)
2124 if (child_pdi
->tag
== DW_TAG_subprogram
)
2126 char *actual_class_name
2127 = language_class_name_from_physname (cu
->language_defn
,
2129 if (actual_class_name
!= NULL
)
2132 = obsavestring (actual_class_name
,
2133 strlen (actual_class_name
),
2134 &cu
->comp_unit_obstack
);
2135 xfree (actual_class_name
);
2140 child_pdi
= child_pdi
->die_sibling
;
2145 /* Read a partial die corresponding to an enumeration type. */
2148 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2149 struct dwarf2_cu
*cu
)
2151 struct objfile
*objfile
= cu
->objfile
;
2152 bfd
*abfd
= objfile
->obfd
;
2153 struct partial_die_info
*pdi
;
2155 if (enum_pdi
->name
!= NULL
)
2156 add_partial_symbol (enum_pdi
, cu
);
2158 pdi
= enum_pdi
->die_child
;
2161 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2162 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2164 add_partial_symbol (pdi
, cu
);
2165 pdi
= pdi
->die_sibling
;
2169 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2170 Return the corresponding abbrev, or NULL if the number is zero (indicating
2171 an empty DIE). In either case *BYTES_READ will be set to the length of
2172 the initial number. */
2174 static struct abbrev_info
*
2175 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2176 struct dwarf2_cu
*cu
)
2178 bfd
*abfd
= cu
->objfile
->obfd
;
2179 unsigned int abbrev_number
;
2180 struct abbrev_info
*abbrev
;
2182 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2184 if (abbrev_number
== 0)
2187 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2190 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2191 bfd_get_filename (abfd
));
2197 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2198 pointer to the end of a series of DIEs, terminated by an empty
2199 DIE. Any children of the skipped DIEs will also be skipped. */
2202 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2204 struct abbrev_info
*abbrev
;
2205 unsigned int bytes_read
;
2209 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2211 return info_ptr
+ bytes_read
;
2213 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2217 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2218 should point just after the initial uleb128 of a DIE, and the
2219 abbrev corresponding to that skipped uleb128 should be passed in
2220 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2224 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2225 struct dwarf2_cu
*cu
)
2227 unsigned int bytes_read
;
2228 struct attribute attr
;
2229 bfd
*abfd
= cu
->objfile
->obfd
;
2230 unsigned int form
, i
;
2232 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2234 /* The only abbrev we care about is DW_AT_sibling. */
2235 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2237 read_attribute (&attr
, &abbrev
->attrs
[i
],
2238 abfd
, info_ptr
, cu
);
2239 if (attr
.form
== DW_FORM_ref_addr
)
2240 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2242 return dwarf2_per_objfile
->info_buffer
2243 + dwarf2_get_ref_die_offset (&attr
, cu
);
2246 /* If it isn't DW_AT_sibling, skip this attribute. */
2247 form
= abbrev
->attrs
[i
].form
;
2252 case DW_FORM_ref_addr
:
2253 info_ptr
+= cu
->header
.addr_size
;
2272 case DW_FORM_string
:
2273 read_string (abfd
, info_ptr
, &bytes_read
);
2274 info_ptr
+= bytes_read
;
2277 info_ptr
+= cu
->header
.offset_size
;
2280 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2281 info_ptr
+= bytes_read
;
2283 case DW_FORM_block1
:
2284 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2286 case DW_FORM_block2
:
2287 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2289 case DW_FORM_block4
:
2290 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2294 case DW_FORM_ref_udata
:
2295 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2297 case DW_FORM_indirect
:
2298 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2299 info_ptr
+= bytes_read
;
2300 /* We need to continue parsing from here, so just go back to
2302 goto skip_attribute
;
2305 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2306 dwarf_form_name (form
),
2307 bfd_get_filename (abfd
));
2311 if (abbrev
->has_children
)
2312 return skip_children (info_ptr
, cu
);
2317 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2318 the next DIE after ORIG_PDI. */
2321 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2322 bfd
*abfd
, struct dwarf2_cu
*cu
)
2324 /* Do we know the sibling already? */
2326 if (orig_pdi
->sibling
)
2327 return orig_pdi
->sibling
;
2329 /* Are there any children to deal with? */
2331 if (!orig_pdi
->has_children
)
2334 /* Skip the children the long way. */
2336 return skip_children (info_ptr
, cu
);
2339 /* Expand this partial symbol table into a full symbol table. */
2342 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2344 /* FIXME: This is barely more than a stub. */
2349 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2355 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2356 gdb_flush (gdb_stdout
);
2359 /* Restore our global data. */
2360 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2361 dwarf2_objfile_data_key
);
2363 psymtab_to_symtab_1 (pst
);
2365 /* Finish up the debug error message. */
2367 printf_filtered (_("done.\n"));
2372 /* Add PER_CU to the queue. */
2375 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2377 struct dwarf2_queue_item
*item
;
2380 item
= xmalloc (sizeof (*item
));
2381 item
->per_cu
= per_cu
;
2384 if (dwarf2_queue
== NULL
)
2385 dwarf2_queue
= item
;
2387 dwarf2_queue_tail
->next
= item
;
2389 dwarf2_queue_tail
= item
;
2392 /* Process the queue. */
2395 process_queue (struct objfile
*objfile
)
2397 struct dwarf2_queue_item
*item
, *next_item
;
2399 /* Initially, there is just one item on the queue. Load its DIEs,
2400 and the DIEs of any other compilation units it requires,
2403 for (item
= dwarf2_queue
; item
!= NULL
; item
= item
->next
)
2405 /* Read in this compilation unit. This may add new items to
2406 the end of the queue. */
2407 load_full_comp_unit (item
->per_cu
, objfile
);
2409 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2410 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2412 /* If this compilation unit has already had full symbols created,
2413 reset the TYPE fields in each DIE. */
2414 if (item
->per_cu
->type_hash
)
2415 reset_die_and_siblings_types (item
->per_cu
->cu
->dies
,
2419 /* Now everything left on the queue needs to be read in. Process
2420 them, one at a time, removing from the queue as we finish. */
2421 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2423 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2424 process_full_comp_unit (item
->per_cu
);
2426 item
->per_cu
->queued
= 0;
2427 next_item
= item
->next
;
2431 dwarf2_queue_tail
= NULL
;
2434 /* Free all allocated queue entries. This function only releases anything if
2435 an error was thrown; if the queue was processed then it would have been
2436 freed as we went along. */
2439 dwarf2_release_queue (void *dummy
)
2441 struct dwarf2_queue_item
*item
, *last
;
2443 item
= dwarf2_queue
;
2446 /* Anything still marked queued is likely to be in an
2447 inconsistent state, so discard it. */
2448 if (item
->per_cu
->queued
)
2450 if (item
->per_cu
->cu
!= NULL
)
2451 free_one_cached_comp_unit (item
->per_cu
->cu
);
2452 item
->per_cu
->queued
= 0;
2460 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2463 /* Read in full symbols for PST, and anything it depends on. */
2466 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2468 struct dwarf2_per_cu_data
*per_cu
;
2469 struct cleanup
*back_to
;
2472 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2473 if (!pst
->dependencies
[i
]->readin
)
2475 /* Inform about additional files that need to be read in. */
2478 /* FIXME: i18n: Need to make this a single string. */
2479 fputs_filtered (" ", gdb_stdout
);
2481 fputs_filtered ("and ", gdb_stdout
);
2483 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2484 wrap_here (""); /* Flush output */
2485 gdb_flush (gdb_stdout
);
2487 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2490 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2494 /* It's an include file, no symbols to read for it.
2495 Everything is in the parent symtab. */
2500 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2502 queue_comp_unit (per_cu
);
2504 process_queue (pst
->objfile
);
2506 /* Age the cache, releasing compilation units that have not
2507 been used recently. */
2508 age_cached_comp_units ();
2510 do_cleanups (back_to
);
2513 /* Load the DIEs associated with PST and PER_CU into memory. */
2515 static struct dwarf2_cu
*
2516 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2518 bfd
*abfd
= objfile
->obfd
;
2519 struct dwarf2_cu
*cu
;
2520 unsigned long offset
;
2522 struct cleanup
*back_to
, *free_cu_cleanup
;
2523 struct attribute
*attr
;
2526 /* Set local variables from the partial symbol table info. */
2527 offset
= per_cu
->offset
;
2529 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2531 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2532 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2534 /* If an error occurs while loading, release our storage. */
2535 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2537 cu
->objfile
= objfile
;
2539 /* read in the comp_unit header */
2540 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2542 /* Read the abbrevs for this compilation unit */
2543 dwarf2_read_abbrevs (abfd
, cu
);
2544 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2546 cu
->header
.offset
= offset
;
2548 cu
->per_cu
= per_cu
;
2551 /* We use this obstack for block values in dwarf_alloc_block. */
2552 obstack_init (&cu
->comp_unit_obstack
);
2554 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2556 /* We try not to read any attributes in this function, because not
2557 all objfiles needed for references have been loaded yet, and symbol
2558 table processing isn't initialized. But we have to set the CU language,
2559 or we won't be able to build types correctly. */
2560 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2562 set_cu_language (DW_UNSND (attr
), cu
);
2564 set_cu_language (language_minimal
, cu
);
2566 do_cleanups (back_to
);
2568 /* We've successfully allocated this compilation unit. Let our caller
2569 clean it up when finished with it. */
2570 discard_cleanups (free_cu_cleanup
);
2575 /* Generate full symbol information for PST and CU, whose DIEs have
2576 already been loaded into memory. */
2579 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2581 struct partial_symtab
*pst
= per_cu
->psymtab
;
2582 struct dwarf2_cu
*cu
= per_cu
->cu
;
2583 struct objfile
*objfile
= pst
->objfile
;
2584 bfd
*abfd
= objfile
->obfd
;
2585 CORE_ADDR lowpc
, highpc
;
2586 struct symtab
*symtab
;
2587 struct cleanup
*back_to
;
2588 struct attribute
*attr
;
2591 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2593 /* We're in the global namespace. */
2594 processing_current_prefix
= "";
2597 back_to
= make_cleanup (really_free_pendings
, NULL
);
2599 cu
->list_in_scope
= &file_symbols
;
2601 /* Find the base address of the compilation unit for range lists and
2602 location lists. It will normally be specified by DW_AT_low_pc.
2603 In DWARF-3 draft 4, the base address could be overridden by
2604 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2605 compilation units with discontinuous ranges. */
2607 cu
->header
.base_known
= 0;
2608 cu
->header
.base_address
= 0;
2610 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2613 cu
->header
.base_address
= DW_ADDR (attr
);
2614 cu
->header
.base_known
= 1;
2618 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2621 cu
->header
.base_address
= DW_ADDR (attr
);
2622 cu
->header
.base_known
= 1;
2626 /* Do line number decoding in read_file_scope () */
2627 process_die (cu
->dies
, cu
);
2629 /* Some compilers don't define a DW_AT_high_pc attribute for the
2630 compilation unit. If the DW_AT_high_pc is missing, synthesize
2631 it, by scanning the DIE's below the compilation unit. */
2632 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2634 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2636 /* Set symtab language to language from DW_AT_language.
2637 If the compilation is from a C file generated by language preprocessors,
2638 do not set the language if it was already deduced by start_subfile. */
2640 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2642 symtab
->language
= cu
->language
;
2644 pst
->symtab
= symtab
;
2647 do_cleanups (back_to
);
2650 /* Process a die and its children. */
2653 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2657 case DW_TAG_padding
:
2659 case DW_TAG_compile_unit
:
2660 read_file_scope (die
, cu
);
2662 case DW_TAG_subprogram
:
2663 read_subroutine_type (die
, cu
);
2664 read_func_scope (die
, cu
);
2666 case DW_TAG_inlined_subroutine
:
2667 /* FIXME: These are ignored for now.
2668 They could be used to set breakpoints on all inlined instances
2669 of a function and make GDB `next' properly over inlined functions. */
2671 case DW_TAG_lexical_block
:
2672 case DW_TAG_try_block
:
2673 case DW_TAG_catch_block
:
2674 read_lexical_block_scope (die
, cu
);
2676 case DW_TAG_class_type
:
2677 case DW_TAG_structure_type
:
2678 case DW_TAG_union_type
:
2679 read_structure_type (die
, cu
);
2680 process_structure_scope (die
, cu
);
2682 case DW_TAG_enumeration_type
:
2683 read_enumeration_type (die
, cu
);
2684 process_enumeration_scope (die
, cu
);
2687 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2688 a symbol or process any children. Therefore it doesn't do anything
2689 that won't be done on-demand by read_type_die. */
2690 case DW_TAG_subroutine_type
:
2691 read_subroutine_type (die
, cu
);
2693 case DW_TAG_set_type
:
2694 read_set_type (die
, cu
);
2696 case DW_TAG_array_type
:
2697 read_array_type (die
, cu
);
2699 case DW_TAG_pointer_type
:
2700 read_tag_pointer_type (die
, cu
);
2702 case DW_TAG_ptr_to_member_type
:
2703 read_tag_ptr_to_member_type (die
, cu
);
2705 case DW_TAG_reference_type
:
2706 read_tag_reference_type (die
, cu
);
2708 case DW_TAG_string_type
:
2709 read_tag_string_type (die
, cu
);
2713 case DW_TAG_base_type
:
2714 read_base_type (die
, cu
);
2715 /* Add a typedef symbol for the type definition, if it has a
2717 new_symbol (die
, die
->type
, cu
);
2719 case DW_TAG_subrange_type
:
2720 read_subrange_type (die
, cu
);
2721 /* Add a typedef symbol for the type definition, if it has a
2723 new_symbol (die
, die
->type
, cu
);
2725 case DW_TAG_common_block
:
2726 read_common_block (die
, cu
);
2728 case DW_TAG_common_inclusion
:
2730 case DW_TAG_namespace
:
2731 processing_has_namespace_info
= 1;
2732 read_namespace (die
, cu
);
2734 case DW_TAG_imported_declaration
:
2735 case DW_TAG_imported_module
:
2736 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2737 information contained in these. DW_TAG_imported_declaration
2738 dies shouldn't have children; DW_TAG_imported_module dies
2739 shouldn't in the C++ case, but conceivably could in the
2740 Fortran case, so we'll have to replace this gdb_assert if
2741 Fortran compilers start generating that info. */
2742 processing_has_namespace_info
= 1;
2743 gdb_assert (die
->child
== NULL
);
2746 new_symbol (die
, NULL
, cu
);
2752 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2754 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2758 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2760 struct objfile
*objfile
= cu
->objfile
;
2761 struct comp_unit_head
*cu_header
= &cu
->header
;
2762 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2763 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2764 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2765 struct attribute
*attr
;
2766 char *name
= "<unknown>";
2767 char *comp_dir
= NULL
;
2768 struct die_info
*child_die
;
2769 bfd
*abfd
= objfile
->obfd
;
2770 struct line_header
*line_header
= 0;
2773 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2775 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2777 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2778 from finish_block. */
2779 if (lowpc
== ((CORE_ADDR
) -1))
2784 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2787 name
= DW_STRING (attr
);
2789 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2792 comp_dir
= DW_STRING (attr
);
2795 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2796 directory, get rid of it. */
2797 char *cp
= strchr (comp_dir
, ':');
2799 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2804 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2807 set_cu_language (DW_UNSND (attr
), cu
);
2810 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2812 cu
->producer
= DW_STRING (attr
);
2814 /* We assume that we're processing GCC output. */
2815 processing_gcc_compilation
= 2;
2817 /* The compilation unit may be in a different language or objfile,
2818 zero out all remembered fundamental types. */
2819 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2821 start_symtab (name
, comp_dir
, lowpc
);
2822 record_debugformat ("DWARF 2");
2823 record_producer (cu
->producer
);
2825 initialize_cu_func_list (cu
);
2827 /* Process all dies in compilation unit. */
2828 if (die
->child
!= NULL
)
2830 child_die
= die
->child
;
2831 while (child_die
&& child_die
->tag
)
2833 process_die (child_die
, cu
);
2834 child_die
= sibling_die (child_die
);
2838 /* Decode line number information if present. */
2839 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2842 unsigned int line_offset
= DW_UNSND (attr
);
2843 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2846 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2847 (void *) line_header
);
2848 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2852 /* Decode macro information, if present. Dwarf 2 macro information
2853 refers to information in the line number info statement program
2854 header, so we can only read it if we've read the header
2856 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2857 if (attr
&& line_header
)
2859 unsigned int macro_offset
= DW_UNSND (attr
);
2860 dwarf_decode_macros (line_header
, macro_offset
,
2861 comp_dir
, abfd
, cu
);
2863 do_cleanups (back_to
);
2867 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2868 struct dwarf2_cu
*cu
)
2870 struct function_range
*thisfn
;
2872 thisfn
= (struct function_range
*)
2873 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2874 thisfn
->name
= name
;
2875 thisfn
->lowpc
= lowpc
;
2876 thisfn
->highpc
= highpc
;
2877 thisfn
->seen_line
= 0;
2878 thisfn
->next
= NULL
;
2880 if (cu
->last_fn
== NULL
)
2881 cu
->first_fn
= thisfn
;
2883 cu
->last_fn
->next
= thisfn
;
2885 cu
->last_fn
= thisfn
;
2889 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2891 struct objfile
*objfile
= cu
->objfile
;
2892 struct context_stack
*new;
2895 struct die_info
*child_die
;
2896 struct attribute
*attr
;
2898 const char *previous_prefix
= processing_current_prefix
;
2899 struct cleanup
*back_to
= NULL
;
2902 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2904 name
= dwarf2_linkage_name (die
, cu
);
2906 /* Ignore functions with missing or empty names and functions with
2907 missing or invalid low and high pc attributes. */
2908 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2911 if (cu
->language
== language_cplus
2912 || cu
->language
== language_java
)
2914 struct die_info
*spec_die
= die_specification (die
, cu
);
2916 /* NOTE: carlton/2004-01-23: We have to be careful in the
2917 presence of DW_AT_specification. For example, with GCC 3.4,
2922 // Definition of N::foo.
2926 then we'll have a tree of DIEs like this:
2928 1: DW_TAG_compile_unit
2929 2: DW_TAG_namespace // N
2930 3: DW_TAG_subprogram // declaration of N::foo
2931 4: DW_TAG_subprogram // definition of N::foo
2932 DW_AT_specification // refers to die #3
2934 Thus, when processing die #4, we have to pretend that we're
2935 in the context of its DW_AT_specification, namely the contex
2938 if (spec_die
!= NULL
)
2940 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2941 processing_current_prefix
= specification_prefix
;
2942 back_to
= make_cleanup (xfree
, specification_prefix
);
2949 /* Record the function range for dwarf_decode_lines. */
2950 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2952 new = push_context (0, lowpc
);
2953 new->name
= new_symbol (die
, die
->type
, cu
);
2955 /* If there is a location expression for DW_AT_frame_base, record
2957 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2959 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2960 expression is being recorded directly in the function's symbol
2961 and not in a separate frame-base object. I guess this hack is
2962 to avoid adding some sort of frame-base adjunct/annex to the
2963 function's symbol :-(. The problem with doing this is that it
2964 results in a function symbol with a location expression that
2965 has nothing to do with the location of the function, ouch! The
2966 relationship should be: a function's symbol has-a frame base; a
2967 frame-base has-a location expression. */
2968 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2970 cu
->list_in_scope
= &local_symbols
;
2972 if (die
->child
!= NULL
)
2974 child_die
= die
->child
;
2975 while (child_die
&& child_die
->tag
)
2977 process_die (child_die
, cu
);
2978 child_die
= sibling_die (child_die
);
2982 new = pop_context ();
2983 /* Make a block for the local symbols within. */
2984 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2985 lowpc
, highpc
, objfile
);
2987 /* In C++, we can have functions nested inside functions (e.g., when
2988 a function declares a class that has methods). This means that
2989 when we finish processing a function scope, we may need to go
2990 back to building a containing block's symbol lists. */
2991 local_symbols
= new->locals
;
2992 param_symbols
= new->params
;
2994 /* If we've finished processing a top-level function, subsequent
2995 symbols go in the file symbol list. */
2996 if (outermost_context_p ())
2997 cu
->list_in_scope
= &file_symbols
;
2999 processing_current_prefix
= previous_prefix
;
3000 if (back_to
!= NULL
)
3001 do_cleanups (back_to
);
3004 /* Process all the DIES contained within a lexical block scope. Start
3005 a new scope, process the dies, and then close the scope. */
3008 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3010 struct objfile
*objfile
= cu
->objfile
;
3011 struct context_stack
*new;
3012 CORE_ADDR lowpc
, highpc
;
3013 struct die_info
*child_die
;
3016 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3018 /* Ignore blocks with missing or invalid low and high pc attributes. */
3019 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3020 as multiple lexical blocks? Handling children in a sane way would
3021 be nasty. Might be easier to properly extend generic blocks to
3023 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3028 push_context (0, lowpc
);
3029 if (die
->child
!= NULL
)
3031 child_die
= die
->child
;
3032 while (child_die
&& child_die
->tag
)
3034 process_die (child_die
, cu
);
3035 child_die
= sibling_die (child_die
);
3038 new = pop_context ();
3040 if (local_symbols
!= NULL
)
3042 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3045 local_symbols
= new->locals
;
3048 /* Get low and high pc attributes from a die. Return 1 if the attributes
3049 are present and valid, otherwise, return 0. Return -1 if the range is
3050 discontinuous, i.e. derived from DW_AT_ranges information. */
3052 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3053 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3055 struct objfile
*objfile
= cu
->objfile
;
3056 struct comp_unit_head
*cu_header
= &cu
->header
;
3057 struct attribute
*attr
;
3058 bfd
*obfd
= objfile
->obfd
;
3063 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3066 high
= DW_ADDR (attr
);
3067 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3069 low
= DW_ADDR (attr
);
3071 /* Found high w/o low attribute. */
3074 /* Found consecutive range of addresses. */
3079 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3082 unsigned int addr_size
= cu_header
->addr_size
;
3083 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3084 /* Value of the DW_AT_ranges attribute is the offset in the
3085 .debug_ranges section. */
3086 unsigned int offset
= DW_UNSND (attr
);
3087 /* Base address selection entry. */
3095 found_base
= cu_header
->base_known
;
3096 base
= cu_header
->base_address
;
3098 if (offset
>= dwarf2_per_objfile
->ranges_size
)
3100 complaint (&symfile_complaints
,
3101 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3105 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
3107 /* Read in the largest possible address. */
3108 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3109 if ((marker
& mask
) == mask
)
3111 /* If we found the largest possible address, then
3112 read the base address. */
3113 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3114 buffer
+= 2 * addr_size
;
3115 offset
+= 2 * addr_size
;
3123 CORE_ADDR range_beginning
, range_end
;
3125 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3126 buffer
+= addr_size
;
3127 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3128 buffer
+= addr_size
;
3129 offset
+= 2 * addr_size
;
3131 /* An end of list marker is a pair of zero addresses. */
3132 if (range_beginning
== 0 && range_end
== 0)
3133 /* Found the end of list entry. */
3136 /* Each base address selection entry is a pair of 2 values.
3137 The first is the largest possible address, the second is
3138 the base address. Check for a base address here. */
3139 if ((range_beginning
& mask
) == mask
)
3141 /* If we found the largest possible address, then
3142 read the base address. */
3143 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3150 /* We have no valid base address for the ranges
3152 complaint (&symfile_complaints
,
3153 _("Invalid .debug_ranges data (no base address)"));
3157 range_beginning
+= base
;
3160 /* FIXME: This is recording everything as a low-high
3161 segment of consecutive addresses. We should have a
3162 data structure for discontiguous block ranges
3166 low
= range_beginning
;
3172 if (range_beginning
< low
)
3173 low
= range_beginning
;
3174 if (range_end
> high
)
3180 /* If the first entry is an end-of-list marker, the range
3181 describes an empty scope, i.e. no instructions. */
3191 /* When using the GNU linker, .gnu.linkonce. sections are used to
3192 eliminate duplicate copies of functions and vtables and such.
3193 The linker will arbitrarily choose one and discard the others.
3194 The AT_*_pc values for such functions refer to local labels in
3195 these sections. If the section from that file was discarded, the
3196 labels are not in the output, so the relocs get a value of 0.
3197 If this is a discarded function, mark the pc bounds as invalid,
3198 so that GDB will ignore it. */
3199 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3207 /* Get the low and high pc's represented by the scope DIE, and store
3208 them in *LOWPC and *HIGHPC. If the correct values can't be
3209 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3212 get_scope_pc_bounds (struct die_info
*die
,
3213 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3214 struct dwarf2_cu
*cu
)
3216 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3217 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3218 CORE_ADDR current_low
, current_high
;
3220 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3222 best_low
= current_low
;
3223 best_high
= current_high
;
3227 struct die_info
*child
= die
->child
;
3229 while (child
&& child
->tag
)
3231 switch (child
->tag
) {
3232 case DW_TAG_subprogram
:
3233 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3235 best_low
= min (best_low
, current_low
);
3236 best_high
= max (best_high
, current_high
);
3239 case DW_TAG_namespace
:
3240 /* FIXME: carlton/2004-01-16: Should we do this for
3241 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3242 that current GCC's always emit the DIEs corresponding
3243 to definitions of methods of classes as children of a
3244 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3245 the DIEs giving the declarations, which could be
3246 anywhere). But I don't see any reason why the
3247 standards says that they have to be there. */
3248 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3250 if (current_low
!= ((CORE_ADDR
) -1))
3252 best_low
= min (best_low
, current_low
);
3253 best_high
= max (best_high
, current_high
);
3261 child
= sibling_die (child
);
3266 *highpc
= best_high
;
3269 /* Add an aggregate field to the field list. */
3272 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3273 struct dwarf2_cu
*cu
)
3275 struct objfile
*objfile
= cu
->objfile
;
3276 struct nextfield
*new_field
;
3277 struct attribute
*attr
;
3279 char *fieldname
= "";
3281 /* Allocate a new field list entry and link it in. */
3282 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3283 make_cleanup (xfree
, new_field
);
3284 memset (new_field
, 0, sizeof (struct nextfield
));
3285 new_field
->next
= fip
->fields
;
3286 fip
->fields
= new_field
;
3289 /* Handle accessibility and virtuality of field.
3290 The default accessibility for members is public, the default
3291 accessibility for inheritance is private. */
3292 if (die
->tag
!= DW_TAG_inheritance
)
3293 new_field
->accessibility
= DW_ACCESS_public
;
3295 new_field
->accessibility
= DW_ACCESS_private
;
3296 new_field
->virtuality
= DW_VIRTUALITY_none
;
3298 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3300 new_field
->accessibility
= DW_UNSND (attr
);
3301 if (new_field
->accessibility
!= DW_ACCESS_public
)
3302 fip
->non_public_fields
= 1;
3303 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3305 new_field
->virtuality
= DW_UNSND (attr
);
3307 fp
= &new_field
->field
;
3309 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3311 /* Data member other than a C++ static data member. */
3313 /* Get type of field. */
3314 fp
->type
= die_type (die
, cu
);
3316 FIELD_STATIC_KIND (*fp
) = 0;
3318 /* Get bit size of field (zero if none). */
3319 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3322 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3326 FIELD_BITSIZE (*fp
) = 0;
3329 /* Get bit offset of field. */
3330 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3333 FIELD_BITPOS (*fp
) =
3334 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
3337 FIELD_BITPOS (*fp
) = 0;
3338 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3341 if (BITS_BIG_ENDIAN
)
3343 /* For big endian bits, the DW_AT_bit_offset gives the
3344 additional bit offset from the MSB of the containing
3345 anonymous object to the MSB of the field. We don't
3346 have to do anything special since we don't need to
3347 know the size of the anonymous object. */
3348 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3352 /* For little endian bits, compute the bit offset to the
3353 MSB of the anonymous object, subtract off the number of
3354 bits from the MSB of the field to the MSB of the
3355 object, and then subtract off the number of bits of
3356 the field itself. The result is the bit offset of
3357 the LSB of the field. */
3359 int bit_offset
= DW_UNSND (attr
);
3361 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3364 /* The size of the anonymous object containing
3365 the bit field is explicit, so use the
3366 indicated size (in bytes). */
3367 anonymous_size
= DW_UNSND (attr
);
3371 /* The size of the anonymous object containing
3372 the bit field must be inferred from the type
3373 attribute of the data member containing the
3375 anonymous_size
= TYPE_LENGTH (fp
->type
);
3377 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3378 - bit_offset
- FIELD_BITSIZE (*fp
);
3382 /* Get name of field. */
3383 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3384 if (attr
&& DW_STRING (attr
))
3385 fieldname
= DW_STRING (attr
);
3387 /* The name is already allocated along with this objfile, so we don't
3388 need to duplicate it for the type. */
3389 fp
->name
= fieldname
;
3391 /* Change accessibility for artificial fields (e.g. virtual table
3392 pointer or virtual base class pointer) to private. */
3393 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3395 new_field
->accessibility
= DW_ACCESS_private
;
3396 fip
->non_public_fields
= 1;
3399 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3401 /* C++ static member. */
3403 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3404 is a declaration, but all versions of G++ as of this writing
3405 (so through at least 3.2.1) incorrectly generate
3406 DW_TAG_variable tags. */
3410 /* Get name of field. */
3411 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3412 if (attr
&& DW_STRING (attr
))
3413 fieldname
= DW_STRING (attr
);
3417 /* Get physical name. */
3418 physname
= dwarf2_linkage_name (die
, cu
);
3420 /* The name is already allocated along with this objfile, so we don't
3421 need to duplicate it for the type. */
3422 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3423 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3424 FIELD_NAME (*fp
) = fieldname
;
3426 else if (die
->tag
== DW_TAG_inheritance
)
3428 /* C++ base class field. */
3429 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3431 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3433 FIELD_BITSIZE (*fp
) = 0;
3434 FIELD_STATIC_KIND (*fp
) = 0;
3435 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3436 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3437 fip
->nbaseclasses
++;
3441 /* Create the vector of fields, and attach it to the type. */
3444 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3445 struct dwarf2_cu
*cu
)
3447 int nfields
= fip
->nfields
;
3449 /* Record the field count, allocate space for the array of fields,
3450 and create blank accessibility bitfields if necessary. */
3451 TYPE_NFIELDS (type
) = nfields
;
3452 TYPE_FIELDS (type
) = (struct field
*)
3453 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3454 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3456 if (fip
->non_public_fields
)
3458 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3460 TYPE_FIELD_PRIVATE_BITS (type
) =
3461 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3462 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3464 TYPE_FIELD_PROTECTED_BITS (type
) =
3465 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3466 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3468 TYPE_FIELD_IGNORE_BITS (type
) =
3469 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3470 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3473 /* If the type has baseclasses, allocate and clear a bit vector for
3474 TYPE_FIELD_VIRTUAL_BITS. */
3475 if (fip
->nbaseclasses
)
3477 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3478 unsigned char *pointer
;
3480 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3481 pointer
= TYPE_ALLOC (type
, num_bytes
);
3482 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
3483 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3484 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3487 /* Copy the saved-up fields into the field vector. Start from the head
3488 of the list, adding to the tail of the field array, so that they end
3489 up in the same order in the array in which they were added to the list. */
3490 while (nfields
-- > 0)
3492 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3493 switch (fip
->fields
->accessibility
)
3495 case DW_ACCESS_private
:
3496 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3499 case DW_ACCESS_protected
:
3500 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3503 case DW_ACCESS_public
:
3507 /* Unknown accessibility. Complain and treat it as public. */
3509 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
3510 fip
->fields
->accessibility
);
3514 if (nfields
< fip
->nbaseclasses
)
3516 switch (fip
->fields
->virtuality
)
3518 case DW_VIRTUALITY_virtual
:
3519 case DW_VIRTUALITY_pure_virtual
:
3520 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3524 fip
->fields
= fip
->fields
->next
;
3528 /* Add a member function to the proper fieldlist. */
3531 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3532 struct type
*type
, struct dwarf2_cu
*cu
)
3534 struct objfile
*objfile
= cu
->objfile
;
3535 struct attribute
*attr
;
3536 struct fnfieldlist
*flp
;
3538 struct fn_field
*fnp
;
3541 struct nextfnfield
*new_fnfield
;
3543 /* Get name of member function. */
3544 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3545 if (attr
&& DW_STRING (attr
))
3546 fieldname
= DW_STRING (attr
);
3550 /* Get the mangled name. */
3551 physname
= dwarf2_linkage_name (die
, cu
);
3553 /* Look up member function name in fieldlist. */
3554 for (i
= 0; i
< fip
->nfnfields
; i
++)
3556 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3560 /* Create new list element if necessary. */
3561 if (i
< fip
->nfnfields
)
3562 flp
= &fip
->fnfieldlists
[i
];
3565 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3567 fip
->fnfieldlists
= (struct fnfieldlist
*)
3568 xrealloc (fip
->fnfieldlists
,
3569 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3570 * sizeof (struct fnfieldlist
));
3571 if (fip
->nfnfields
== 0)
3572 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3574 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3575 flp
->name
= fieldname
;
3581 /* Create a new member function field and chain it to the field list
3583 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3584 make_cleanup (xfree
, new_fnfield
);
3585 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3586 new_fnfield
->next
= flp
->head
;
3587 flp
->head
= new_fnfield
;
3590 /* Fill in the member function field info. */
3591 fnp
= &new_fnfield
->fnfield
;
3592 /* The name is already allocated along with this objfile, so we don't
3593 need to duplicate it for the type. */
3594 fnp
->physname
= physname
? physname
: "";
3595 fnp
->type
= alloc_type (objfile
);
3596 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3598 int nparams
= TYPE_NFIELDS (die
->type
);
3600 /* TYPE is the domain of this method, and DIE->TYPE is the type
3601 of the method itself (TYPE_CODE_METHOD). */
3602 smash_to_method_type (fnp
->type
, type
,
3603 TYPE_TARGET_TYPE (die
->type
),
3604 TYPE_FIELDS (die
->type
),
3605 TYPE_NFIELDS (die
->type
),
3606 TYPE_VARARGS (die
->type
));
3608 /* Handle static member functions.
3609 Dwarf2 has no clean way to discern C++ static and non-static
3610 member functions. G++ helps GDB by marking the first
3611 parameter for non-static member functions (which is the
3612 this pointer) as artificial. We obtain this information
3613 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3614 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3615 fnp
->voffset
= VOFFSET_STATIC
;
3618 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
3621 /* Get fcontext from DW_AT_containing_type if present. */
3622 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3623 fnp
->fcontext
= die_containing_type (die
, cu
);
3625 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3626 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3628 /* Get accessibility. */
3629 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3632 switch (DW_UNSND (attr
))
3634 case DW_ACCESS_private
:
3635 fnp
->is_private
= 1;
3637 case DW_ACCESS_protected
:
3638 fnp
->is_protected
= 1;
3643 /* Check for artificial methods. */
3644 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3645 if (attr
&& DW_UNSND (attr
) != 0)
3646 fnp
->is_artificial
= 1;
3648 /* Get index in virtual function table if it is a virtual member function. */
3649 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3652 /* Support the .debug_loc offsets */
3653 if (attr_form_is_block (attr
))
3655 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3657 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3659 dwarf2_complex_location_expr_complaint ();
3663 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3669 /* Create the vector of member function fields, and attach it to the type. */
3672 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3673 struct dwarf2_cu
*cu
)
3675 struct fnfieldlist
*flp
;
3676 int total_length
= 0;
3679 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3680 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3681 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3683 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3685 struct nextfnfield
*nfp
= flp
->head
;
3686 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3689 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3690 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3691 fn_flp
->fn_fields
= (struct fn_field
*)
3692 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3693 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3694 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3696 total_length
+= flp
->length
;
3699 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3700 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3703 /* Returns non-zero if NAME is the name of a vtable member in CU's
3704 language, zero otherwise. */
3706 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3708 static const char vptr
[] = "_vptr";
3709 static const char vtable
[] = "vtable";
3711 /* Look for the C++ and Java forms of the vtable. */
3712 if ((cu
->language
== language_java
3713 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3714 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3715 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3721 /* GCC outputs unnamed structures that are really pointers to member
3722 functions, with the ABI-specified layout. If DIE (from CU) describes
3723 such a structure, set its type, and return nonzero. Otherwise return
3726 GCC shouldn't do this; it should just output pointer to member DIEs.
3727 This is GCC PR debug/28767. */
3730 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
3732 struct objfile
*objfile
= cu
->objfile
;
3734 struct die_info
*pfn_die
, *delta_die
;
3735 struct attribute
*pfn_name
, *delta_name
;
3736 struct type
*pfn_type
, *domain_type
;
3738 /* Check for a structure with no name and two children. */
3739 if (die
->tag
!= DW_TAG_structure_type
3740 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
3741 || die
->child
== NULL
3742 || die
->child
->sibling
== NULL
3743 || (die
->child
->sibling
->sibling
!= NULL
3744 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
3747 /* Check for __pfn and __delta members. */
3748 pfn_die
= die
->child
;
3749 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
3750 if (pfn_die
->tag
!= DW_TAG_member
3752 || DW_STRING (pfn_name
) == NULL
3753 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
3756 delta_die
= pfn_die
->sibling
;
3757 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
3758 if (delta_die
->tag
!= DW_TAG_member
3759 || delta_name
== NULL
3760 || DW_STRING (delta_name
) == NULL
3761 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
3764 /* Find the type of the method. */
3765 pfn_type
= die_type (pfn_die
, cu
);
3766 if (pfn_type
== NULL
3767 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
3768 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
3771 /* Look for the "this" argument. */
3772 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
3773 if (TYPE_NFIELDS (pfn_type
) == 0
3774 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
3777 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
3778 type
= alloc_type (objfile
);
3779 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
3780 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
3781 TYPE_VARARGS (pfn_type
));
3782 type
= lookup_methodptr_type (type
);
3783 set_die_type (die
, type
, cu
);
3788 /* Called when we find the DIE that starts a structure or union scope
3789 (definition) to process all dies that define the members of the
3792 NOTE: we need to call struct_type regardless of whether or not the
3793 DIE has an at_name attribute, since it might be an anonymous
3794 structure or union. This gets the type entered into our set of
3797 However, if the structure is incomplete (an opaque struct/union)
3798 then suppress creating a symbol table entry for it since gdb only
3799 wants to find the one with the complete definition. Note that if
3800 it is complete, we just call new_symbol, which does it's own
3801 checking about whether the struct/union is anonymous or not (and
3802 suppresses creating a symbol table entry itself). */
3805 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3807 struct objfile
*objfile
= cu
->objfile
;
3809 struct attribute
*attr
;
3810 const char *previous_prefix
= processing_current_prefix
;
3811 struct cleanup
*back_to
= NULL
;
3816 if (quirk_gcc_member_function_pointer (die
, cu
))
3819 type
= alloc_type (objfile
);
3820 INIT_CPLUS_SPECIFIC (type
);
3821 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3822 if (attr
&& DW_STRING (attr
))
3824 if (cu
->language
== language_cplus
3825 || cu
->language
== language_java
)
3827 char *new_prefix
= determine_class_name (die
, cu
);
3828 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3829 strlen (new_prefix
),
3830 &objfile
->objfile_obstack
);
3831 back_to
= make_cleanup (xfree
, new_prefix
);
3832 processing_current_prefix
= new_prefix
;
3836 /* The name is already allocated along with this objfile, so
3837 we don't need to duplicate it for the type. */
3838 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3842 if (die
->tag
== DW_TAG_structure_type
)
3844 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3846 else if (die
->tag
== DW_TAG_union_type
)
3848 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3852 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3854 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3857 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3860 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3864 TYPE_LENGTH (type
) = 0;
3867 if (die_is_declaration (die
, cu
))
3868 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3870 /* We need to add the type field to the die immediately so we don't
3871 infinitely recurse when dealing with pointers to the structure
3872 type within the structure itself. */
3873 set_die_type (die
, type
, cu
);
3875 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3877 struct field_info fi
;
3878 struct die_info
*child_die
;
3879 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3881 memset (&fi
, 0, sizeof (struct field_info
));
3883 child_die
= die
->child
;
3885 while (child_die
&& child_die
->tag
)
3887 if (child_die
->tag
== DW_TAG_member
3888 || child_die
->tag
== DW_TAG_variable
)
3890 /* NOTE: carlton/2002-11-05: A C++ static data member
3891 should be a DW_TAG_member that is a declaration, but
3892 all versions of G++ as of this writing (so through at
3893 least 3.2.1) incorrectly generate DW_TAG_variable
3894 tags for them instead. */
3895 dwarf2_add_field (&fi
, child_die
, cu
);
3897 else if (child_die
->tag
== DW_TAG_subprogram
)
3899 /* C++ member function. */
3900 read_type_die (child_die
, cu
);
3901 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3903 else if (child_die
->tag
== DW_TAG_inheritance
)
3905 /* C++ base class field. */
3906 dwarf2_add_field (&fi
, child_die
, cu
);
3908 child_die
= sibling_die (child_die
);
3911 /* Attach fields and member functions to the type. */
3913 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3916 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3918 /* Get the type which refers to the base class (possibly this
3919 class itself) which contains the vtable pointer for the current
3920 class from the DW_AT_containing_type attribute. */
3922 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3924 struct type
*t
= die_containing_type (die
, cu
);
3926 TYPE_VPTR_BASETYPE (type
) = t
;
3931 /* Our own class provides vtbl ptr. */
3932 for (i
= TYPE_NFIELDS (t
) - 1;
3933 i
>= TYPE_N_BASECLASSES (t
);
3936 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3938 if (is_vtable_name (fieldname
, cu
))
3940 TYPE_VPTR_FIELDNO (type
) = i
;
3945 /* Complain if virtual function table field not found. */
3946 if (i
< TYPE_N_BASECLASSES (t
))
3947 complaint (&symfile_complaints
,
3948 _("virtual function table pointer not found when defining class '%s'"),
3949 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3954 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3957 else if (cu
->producer
3958 && strncmp (cu
->producer
,
3959 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
3961 /* The IBM XLC compiler does not provide direct indication
3962 of the containing type, but the vtable pointer is
3963 always named __vfp. */
3967 for (i
= TYPE_NFIELDS (type
) - 1;
3968 i
>= TYPE_N_BASECLASSES (type
);
3971 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
3973 TYPE_VPTR_FIELDNO (type
) = i
;
3974 TYPE_VPTR_BASETYPE (type
) = type
;
3981 do_cleanups (back_to
);
3984 processing_current_prefix
= previous_prefix
;
3985 if (back_to
!= NULL
)
3986 do_cleanups (back_to
);
3990 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3992 struct objfile
*objfile
= cu
->objfile
;
3993 const char *previous_prefix
= processing_current_prefix
;
3994 struct die_info
*child_die
= die
->child
;
3996 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3997 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3999 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4000 snapshots) has been known to create a die giving a declaration
4001 for a class that has, as a child, a die giving a definition for a
4002 nested class. So we have to process our children even if the
4003 current die is a declaration. Normally, of course, a declaration
4004 won't have any children at all. */
4006 while (child_die
!= NULL
&& child_die
->tag
)
4008 if (child_die
->tag
== DW_TAG_member
4009 || child_die
->tag
== DW_TAG_variable
4010 || child_die
->tag
== DW_TAG_inheritance
)
4015 process_die (child_die
, cu
);
4017 child_die
= sibling_die (child_die
);
4020 /* Do not consider external references. According to the DWARF standard,
4021 these DIEs are identified by the fact that they have no byte_size
4022 attribute, and a declaration attribute. */
4023 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4024 || !die_is_declaration (die
, cu
))
4025 new_symbol (die
, die
->type
, cu
);
4027 processing_current_prefix
= previous_prefix
;
4030 /* Given a DW_AT_enumeration_type die, set its type. We do not
4031 complete the type's fields yet, or create any symbols. */
4034 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4036 struct objfile
*objfile
= cu
->objfile
;
4038 struct attribute
*attr
;
4043 type
= alloc_type (objfile
);
4045 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4046 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4047 if (attr
&& DW_STRING (attr
))
4049 char *name
= DW_STRING (attr
);
4051 if (processing_has_namespace_info
)
4053 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
4054 processing_current_prefix
,
4059 /* The name is already allocated along with this objfile, so
4060 we don't need to duplicate it for the type. */
4061 TYPE_TAG_NAME (type
) = name
;
4065 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4068 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4072 TYPE_LENGTH (type
) = 0;
4075 set_die_type (die
, type
, cu
);
4078 /* Determine the name of the type represented by DIE, which should be
4079 a named C++ or Java compound type. Return the name in question; the caller
4080 is responsible for xfree()'ing it. */
4083 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4085 struct cleanup
*back_to
= NULL
;
4086 struct die_info
*spec_die
= die_specification (die
, cu
);
4087 char *new_prefix
= NULL
;
4089 /* If this is the definition of a class that is declared by another
4090 die, then processing_current_prefix may not be accurate; see
4091 read_func_scope for a similar example. */
4092 if (spec_die
!= NULL
)
4094 char *specification_prefix
= determine_prefix (spec_die
, cu
);
4095 processing_current_prefix
= specification_prefix
;
4096 back_to
= make_cleanup (xfree
, specification_prefix
);
4099 /* If we don't have namespace debug info, guess the name by trying
4100 to demangle the names of members, just like we did in
4101 guess_structure_name. */
4102 if (!processing_has_namespace_info
)
4104 struct die_info
*child
;
4106 for (child
= die
->child
;
4107 child
!= NULL
&& child
->tag
!= 0;
4108 child
= sibling_die (child
))
4110 if (child
->tag
== DW_TAG_subprogram
)
4113 = language_class_name_from_physname (cu
->language_defn
,
4117 if (new_prefix
!= NULL
)
4123 if (new_prefix
== NULL
)
4125 const char *name
= dwarf2_name (die
, cu
);
4126 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
4127 name
? name
: "<<anonymous>>",
4131 if (back_to
!= NULL
)
4132 do_cleanups (back_to
);
4137 /* Given a pointer to a die which begins an enumeration, process all
4138 the dies that define the members of the enumeration, and create the
4139 symbol for the enumeration type.
4141 NOTE: We reverse the order of the element list. */
4144 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4146 struct objfile
*objfile
= cu
->objfile
;
4147 struct die_info
*child_die
;
4148 struct field
*fields
;
4149 struct attribute
*attr
;
4152 int unsigned_enum
= 1;
4156 if (die
->child
!= NULL
)
4158 child_die
= die
->child
;
4159 while (child_die
&& child_die
->tag
)
4161 if (child_die
->tag
!= DW_TAG_enumerator
)
4163 process_die (child_die
, cu
);
4167 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
4170 sym
= new_symbol (child_die
, die
->type
, cu
);
4171 if (SYMBOL_VALUE (sym
) < 0)
4174 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4176 fields
= (struct field
*)
4178 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4179 * sizeof (struct field
));
4182 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
4183 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4184 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
4185 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4186 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
4192 child_die
= sibling_die (child_die
);
4197 TYPE_NFIELDS (die
->type
) = num_fields
;
4198 TYPE_FIELDS (die
->type
) = (struct field
*)
4199 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
4200 memcpy (TYPE_FIELDS (die
->type
), fields
,
4201 sizeof (struct field
) * num_fields
);
4205 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
4208 new_symbol (die
, die
->type
, cu
);
4211 /* Extract all information from a DW_TAG_array_type DIE and put it in
4212 the DIE's type field. For now, this only handles one dimensional
4216 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4218 struct objfile
*objfile
= cu
->objfile
;
4219 struct die_info
*child_die
;
4220 struct type
*type
= NULL
;
4221 struct type
*element_type
, *range_type
, *index_type
;
4222 struct type
**range_types
= NULL
;
4223 struct attribute
*attr
;
4225 struct cleanup
*back_to
;
4227 /* Return if we've already decoded this type. */
4233 element_type
= die_type (die
, cu
);
4235 /* Irix 6.2 native cc creates array types without children for
4236 arrays with unspecified length. */
4237 if (die
->child
== NULL
)
4239 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4240 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4241 set_die_type (die
, create_array_type (NULL
, element_type
, range_type
),
4246 back_to
= make_cleanup (null_cleanup
, NULL
);
4247 child_die
= die
->child
;
4248 while (child_die
&& child_die
->tag
)
4250 if (child_die
->tag
== DW_TAG_subrange_type
)
4252 read_subrange_type (child_die
, cu
);
4254 if (child_die
->type
!= NULL
)
4256 /* The range type was succesfully read. Save it for
4257 the array type creation. */
4258 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4260 range_types
= (struct type
**)
4261 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4262 * sizeof (struct type
*));
4264 make_cleanup (free_current_contents
, &range_types
);
4266 range_types
[ndim
++] = child_die
->type
;
4269 child_die
= sibling_die (child_die
);
4272 /* Dwarf2 dimensions are output from left to right, create the
4273 necessary array types in backwards order. */
4275 type
= element_type
;
4277 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4281 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4286 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4289 /* Understand Dwarf2 support for vector types (like they occur on
4290 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4291 array type. This is not part of the Dwarf2/3 standard yet, but a
4292 custom vendor extension. The main difference between a regular
4293 array and the vector variant is that vectors are passed by value
4295 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4297 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
4299 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4300 if (attr
&& DW_STRING (attr
))
4301 TYPE_NAME (type
) = DW_STRING (attr
);
4303 do_cleanups (back_to
);
4305 /* Install the type in the die. */
4306 set_die_type (die
, type
, cu
);
4309 static enum dwarf_array_dim_ordering
4310 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4312 struct attribute
*attr
;
4314 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4316 if (attr
) return DW_SND (attr
);
4319 GNU F77 is a special case, as at 08/2004 array type info is the
4320 opposite order to the dwarf2 specification, but data is still
4321 laid out as per normal fortran.
4323 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4327 if (cu
->language
== language_fortran
&&
4328 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4330 return DW_ORD_row_major
;
4333 switch (cu
->language_defn
->la_array_ordering
)
4335 case array_column_major
:
4336 return DW_ORD_col_major
;
4337 case array_row_major
:
4339 return DW_ORD_row_major
;
4343 /* Extract all information from a DW_TAG_set_type DIE and put it in
4344 the DIE's type field. */
4347 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4349 if (die
->type
== NULL
)
4350 die
->type
= create_set_type ((struct type
*) NULL
, die_type (die
, cu
));
4353 /* First cut: install each common block member as a global variable. */
4356 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4358 struct die_info
*child_die
;
4359 struct attribute
*attr
;
4361 CORE_ADDR base
= (CORE_ADDR
) 0;
4363 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4366 /* Support the .debug_loc offsets */
4367 if (attr_form_is_block (attr
))
4369 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4371 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
4373 dwarf2_complex_location_expr_complaint ();
4377 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4378 "common block member");
4381 if (die
->child
!= NULL
)
4383 child_die
= die
->child
;
4384 while (child_die
&& child_die
->tag
)
4386 sym
= new_symbol (child_die
, NULL
, cu
);
4387 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4390 SYMBOL_VALUE_ADDRESS (sym
) =
4391 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4392 add_symbol_to_list (sym
, &global_symbols
);
4394 child_die
= sibling_die (child_die
);
4399 /* Read a C++ namespace. */
4402 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4404 struct objfile
*objfile
= cu
->objfile
;
4405 const char *previous_prefix
= processing_current_prefix
;
4408 struct die_info
*current_die
;
4409 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4411 name
= namespace_name (die
, &is_anonymous
, cu
);
4413 /* Now build the name of the current namespace. */
4415 if (previous_prefix
[0] == '\0')
4417 processing_current_prefix
= name
;
4421 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4422 make_cleanup (xfree
, temp_name
);
4423 processing_current_prefix
= temp_name
;
4426 /* Add a symbol associated to this if we haven't seen the namespace
4427 before. Also, add a using directive if it's an anonymous
4430 if (dwarf2_extension (die
, cu
) == NULL
)
4434 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4435 this cast will hopefully become unnecessary. */
4436 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4437 (char *) processing_current_prefix
,
4439 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4441 new_symbol (die
, type
, cu
);
4442 set_die_type (die
, type
, cu
);
4445 cp_add_using_directive (processing_current_prefix
,
4446 strlen (previous_prefix
),
4447 strlen (processing_current_prefix
));
4450 if (die
->child
!= NULL
)
4452 struct die_info
*child_die
= die
->child
;
4454 while (child_die
&& child_die
->tag
)
4456 process_die (child_die
, cu
);
4457 child_die
= sibling_die (child_die
);
4461 processing_current_prefix
= previous_prefix
;
4462 do_cleanups (back_to
);
4465 /* Return the name of the namespace represented by DIE. Set
4466 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4470 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4472 struct die_info
*current_die
;
4473 const char *name
= NULL
;
4475 /* Loop through the extensions until we find a name. */
4477 for (current_die
= die
;
4478 current_die
!= NULL
;
4479 current_die
= dwarf2_extension (die
, cu
))
4481 name
= dwarf2_name (current_die
, cu
);
4486 /* Is it an anonymous namespace? */
4488 *is_anonymous
= (name
== NULL
);
4490 name
= "(anonymous namespace)";
4495 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4496 the user defined type vector. */
4499 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4501 struct comp_unit_head
*cu_header
= &cu
->header
;
4503 struct attribute
*attr_byte_size
;
4504 struct attribute
*attr_address_class
;
4505 int byte_size
, addr_class
;
4512 type
= lookup_pointer_type (die_type (die
, cu
));
4514 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4516 byte_size
= DW_UNSND (attr_byte_size
);
4518 byte_size
= cu_header
->addr_size
;
4520 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4521 if (attr_address_class
)
4522 addr_class
= DW_UNSND (attr_address_class
);
4524 addr_class
= DW_ADDR_none
;
4526 /* If the pointer size or address class is different than the
4527 default, create a type variant marked as such and set the
4528 length accordingly. */
4529 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4531 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
4535 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
4536 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4537 type
= make_type_with_address_space (type
, type_flags
);
4539 else if (TYPE_LENGTH (type
) != byte_size
)
4541 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
4544 /* Should we also complain about unhandled address classes? */
4548 TYPE_LENGTH (type
) = byte_size
;
4549 set_die_type (die
, type
, cu
);
4552 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4553 the user defined type vector. */
4556 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4558 struct objfile
*objfile
= cu
->objfile
;
4560 struct type
*to_type
;
4561 struct type
*domain
;
4568 to_type
= die_type (die
, cu
);
4569 domain
= die_containing_type (die
, cu
);
4571 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
4572 type
= lookup_methodptr_type (to_type
);
4574 type
= lookup_memberptr_type (to_type
, domain
);
4576 set_die_type (die
, type
, cu
);
4579 /* Extract all information from a DW_TAG_reference_type DIE and add to
4580 the user defined type vector. */
4583 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4585 struct comp_unit_head
*cu_header
= &cu
->header
;
4587 struct attribute
*attr
;
4594 type
= lookup_reference_type (die_type (die
, cu
));
4595 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4598 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4602 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4604 set_die_type (die
, type
, cu
);
4608 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4610 struct type
*base_type
;
4617 base_type
= die_type (die
, cu
);
4618 set_die_type (die
, make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0),
4623 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4625 struct type
*base_type
;
4632 base_type
= die_type (die
, cu
);
4633 set_die_type (die
, make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0),
4637 /* Extract all information from a DW_TAG_string_type DIE and add to
4638 the user defined type vector. It isn't really a user defined type,
4639 but it behaves like one, with other DIE's using an AT_user_def_type
4640 attribute to reference it. */
4643 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4645 struct objfile
*objfile
= cu
->objfile
;
4646 struct type
*type
, *range_type
, *index_type
, *char_type
;
4647 struct attribute
*attr
;
4648 unsigned int length
;
4655 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4658 length
= DW_UNSND (attr
);
4662 /* check for the DW_AT_byte_size attribute */
4663 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4666 length
= DW_UNSND (attr
);
4673 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4674 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4675 if (cu
->language
== language_fortran
)
4677 /* Need to create a unique string type for bounds
4679 type
= create_string_type (0, range_type
);
4683 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
4684 type
= create_string_type (char_type
, range_type
);
4686 set_die_type (die
, type
, cu
);
4689 /* Handle DIES due to C code like:
4693 int (*funcp)(int a, long l);
4697 ('funcp' generates a DW_TAG_subroutine_type DIE)
4701 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4703 struct type
*type
; /* Type that this function returns */
4704 struct type
*ftype
; /* Function that returns above type */
4705 struct attribute
*attr
;
4707 /* Decode the type that this subroutine returns */
4712 type
= die_type (die
, cu
);
4713 ftype
= make_function_type (type
, (struct type
**) 0);
4715 /* All functions in C++ and Java have prototypes. */
4716 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4717 if ((attr
&& (DW_UNSND (attr
) != 0))
4718 || cu
->language
== language_cplus
4719 || cu
->language
== language_java
)
4720 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4722 if (die
->child
!= NULL
)
4724 struct die_info
*child_die
;
4728 /* Count the number of parameters.
4729 FIXME: GDB currently ignores vararg functions, but knows about
4730 vararg member functions. */
4731 child_die
= die
->child
;
4732 while (child_die
&& child_die
->tag
)
4734 if (child_die
->tag
== DW_TAG_formal_parameter
)
4736 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4737 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4738 child_die
= sibling_die (child_die
);
4741 /* Allocate storage for parameters and fill them in. */
4742 TYPE_NFIELDS (ftype
) = nparams
;
4743 TYPE_FIELDS (ftype
) = (struct field
*)
4744 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
4746 child_die
= die
->child
;
4747 while (child_die
&& child_die
->tag
)
4749 if (child_die
->tag
== DW_TAG_formal_parameter
)
4751 /* Dwarf2 has no clean way to discern C++ static and non-static
4752 member functions. G++ helps GDB by marking the first
4753 parameter for non-static member functions (which is the
4754 this pointer) as artificial. We pass this information
4755 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4756 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4758 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4760 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4761 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4764 child_die
= sibling_die (child_die
);
4768 set_die_type (die
, ftype
, cu
);
4772 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4774 struct objfile
*objfile
= cu
->objfile
;
4775 struct attribute
*attr
;
4780 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4781 if (attr
&& DW_STRING (attr
))
4783 name
= DW_STRING (attr
);
4785 set_die_type (die
, init_type (TYPE_CODE_TYPEDEF
, 0,
4786 TYPE_FLAG_TARGET_STUB
, name
, objfile
),
4788 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4792 /* Find a representation of a given base type and install
4793 it in the TYPE field of the die. */
4796 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4798 struct objfile
*objfile
= cu
->objfile
;
4800 struct attribute
*attr
;
4801 int encoding
= 0, size
= 0;
4803 /* If we've already decoded this die, this is a no-op. */
4809 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4812 encoding
= DW_UNSND (attr
);
4814 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4817 size
= DW_UNSND (attr
);
4819 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4820 if (attr
&& DW_STRING (attr
))
4822 enum type_code code
= TYPE_CODE_INT
;
4827 case DW_ATE_address
:
4828 /* Turn DW_ATE_address into a void * pointer. */
4829 code
= TYPE_CODE_PTR
;
4830 type_flags
|= TYPE_FLAG_UNSIGNED
;
4832 case DW_ATE_boolean
:
4833 code
= TYPE_CODE_BOOL
;
4834 type_flags
|= TYPE_FLAG_UNSIGNED
;
4836 case DW_ATE_complex_float
:
4837 code
= TYPE_CODE_COMPLEX
;
4840 code
= TYPE_CODE_FLT
;
4844 case DW_ATE_unsigned
:
4845 type_flags
|= TYPE_FLAG_UNSIGNED
;
4847 case DW_ATE_signed_char
:
4848 if (cu
->language
== language_m2
)
4849 code
= TYPE_CODE_CHAR
;
4851 case DW_ATE_unsigned_char
:
4852 if (cu
->language
== language_m2
)
4853 code
= TYPE_CODE_CHAR
;
4854 type_flags
|= TYPE_FLAG_UNSIGNED
;
4857 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
4858 dwarf_type_encoding_name (encoding
));
4861 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4862 if (encoding
== DW_ATE_address
)
4863 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4865 else if (encoding
== DW_ATE_complex_float
)
4868 TYPE_TARGET_TYPE (type
)
4869 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4870 else if (size
== 16)
4871 TYPE_TARGET_TYPE (type
)
4872 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4874 TYPE_TARGET_TYPE (type
)
4875 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4880 type
= dwarf_base_type (encoding
, size
, cu
);
4882 set_die_type (die
, type
, cu
);
4885 /* Read the given DW_AT_subrange DIE. */
4888 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4890 struct type
*base_type
;
4891 struct type
*range_type
;
4892 struct attribute
*attr
;
4896 /* If we have already decoded this die, then nothing more to do. */
4900 base_type
= die_type (die
, cu
);
4901 if (base_type
== NULL
)
4903 complaint (&symfile_complaints
,
4904 _("DW_AT_type missing from DW_TAG_subrange_type"));
4908 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4909 base_type
= alloc_type (NULL
);
4911 if (cu
->language
== language_fortran
)
4913 /* FORTRAN implies a lower bound of 1, if not given. */
4917 /* FIXME: For variable sized arrays either of these could be
4918 a variable rather than a constant value. We'll allow it,
4919 but we don't know how to handle it. */
4920 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4922 low
= dwarf2_get_attr_constant_value (attr
, 0);
4924 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4927 if (attr
->form
== DW_FORM_block1
)
4929 /* GCC encodes arrays with unspecified or dynamic length
4930 with a DW_FORM_block1 attribute.
4931 FIXME: GDB does not yet know how to handle dynamic
4932 arrays properly, treat them as arrays with unspecified
4935 FIXME: jimb/2003-09-22: GDB does not really know
4936 how to handle arrays of unspecified length
4937 either; we just represent them as zero-length
4938 arrays. Choose an appropriate upper bound given
4939 the lower bound we've computed above. */
4943 high
= dwarf2_get_attr_constant_value (attr
, 1);
4946 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4948 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4949 if (attr
&& DW_STRING (attr
))
4950 TYPE_NAME (range_type
) = DW_STRING (attr
);
4952 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4954 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4956 set_die_type (die
, range_type
, cu
);
4960 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4963 struct attribute
*attr
;
4968 /* For now, we only support the C meaning of an unspecified type: void. */
4970 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4971 type
= init_type (TYPE_CODE_VOID
, 0, 0, attr
? DW_STRING (attr
) : "",
4974 set_die_type (die
, type
, cu
);
4977 /* Read a whole compilation unit into a linked list of dies. */
4979 static struct die_info
*
4980 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4982 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4985 /* Read a single die and all its descendents. Set the die's sibling
4986 field to NULL; set other fields in the die correctly, and set all
4987 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4988 location of the info_ptr after reading all of those dies. PARENT
4989 is the parent of the die in question. */
4991 static struct die_info
*
4992 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
4993 struct dwarf2_cu
*cu
,
4994 gdb_byte
**new_info_ptr
,
4995 struct die_info
*parent
)
4997 struct die_info
*die
;
5001 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5002 store_in_ref_table (die
->offset
, die
, cu
);
5006 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5012 *new_info_ptr
= cur_ptr
;
5015 die
->sibling
= NULL
;
5016 die
->parent
= parent
;
5020 /* Read a die, all of its descendents, and all of its siblings; set
5021 all of the fields of all of the dies correctly. Arguments are as
5022 in read_die_and_children. */
5024 static struct die_info
*
5025 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5026 struct dwarf2_cu
*cu
,
5027 gdb_byte
**new_info_ptr
,
5028 struct die_info
*parent
)
5030 struct die_info
*first_die
, *last_sibling
;
5034 first_die
= last_sibling
= NULL
;
5038 struct die_info
*die
5039 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5047 last_sibling
->sibling
= die
;
5052 *new_info_ptr
= cur_ptr
;
5062 /* Free a linked list of dies. */
5065 free_die_list (struct die_info
*dies
)
5067 struct die_info
*die
, *next
;
5072 if (die
->child
!= NULL
)
5073 free_die_list (die
->child
);
5074 next
= die
->sibling
;
5081 /* Read the contents of the section at OFFSET and of size SIZE from the
5082 object file specified by OBJFILE into the objfile_obstack and return it. */
5085 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
5087 bfd
*abfd
= objfile
->obfd
;
5088 gdb_byte
*buf
, *retbuf
;
5089 bfd_size_type size
= bfd_get_section_size (sectp
);
5094 buf
= obstack_alloc (&objfile
->objfile_obstack
, size
);
5095 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
5099 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
5100 || bfd_bread (buf
, size
, abfd
) != size
)
5101 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5102 bfd_get_filename (abfd
));
5107 /* In DWARF version 2, the description of the debugging information is
5108 stored in a separate .debug_abbrev section. Before we read any
5109 dies from a section we read in all abbreviations and install them
5110 in a hash table. This function also sets flags in CU describing
5111 the data found in the abbrev table. */
5114 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5116 struct comp_unit_head
*cu_header
= &cu
->header
;
5117 gdb_byte
*abbrev_ptr
;
5118 struct abbrev_info
*cur_abbrev
;
5119 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5120 unsigned int abbrev_form
, hash_number
;
5121 struct attr_abbrev
*cur_attrs
;
5122 unsigned int allocated_attrs
;
5124 /* Initialize dwarf2 abbrevs */
5125 obstack_init (&cu
->abbrev_obstack
);
5126 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5128 * sizeof (struct abbrev_info
*)));
5129 memset (cu
->dwarf2_abbrevs
, 0,
5130 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5132 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
5133 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5134 abbrev_ptr
+= bytes_read
;
5136 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5137 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5139 /* loop until we reach an abbrev number of 0 */
5140 while (abbrev_number
)
5142 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5144 /* read in abbrev header */
5145 cur_abbrev
->number
= abbrev_number
;
5146 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5147 abbrev_ptr
+= bytes_read
;
5148 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5151 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5152 cu
->has_namespace_info
= 1;
5154 /* now read in declarations */
5155 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5156 abbrev_ptr
+= bytes_read
;
5157 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5158 abbrev_ptr
+= bytes_read
;
5161 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5163 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5165 = xrealloc (cur_attrs
, (allocated_attrs
5166 * sizeof (struct attr_abbrev
)));
5169 /* Record whether this compilation unit might have
5170 inter-compilation-unit references. If we don't know what form
5171 this attribute will have, then it might potentially be a
5172 DW_FORM_ref_addr, so we conservatively expect inter-CU
5175 if (abbrev_form
== DW_FORM_ref_addr
5176 || abbrev_form
== DW_FORM_indirect
)
5177 cu
->has_form_ref_addr
= 1;
5179 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5180 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5181 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5182 abbrev_ptr
+= bytes_read
;
5183 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5184 abbrev_ptr
+= bytes_read
;
5187 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5188 (cur_abbrev
->num_attrs
5189 * sizeof (struct attr_abbrev
)));
5190 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5191 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5193 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5194 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5195 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5197 /* Get next abbreviation.
5198 Under Irix6 the abbreviations for a compilation unit are not
5199 always properly terminated with an abbrev number of 0.
5200 Exit loop if we encounter an abbreviation which we have
5201 already read (which means we are about to read the abbreviations
5202 for the next compile unit) or if the end of the abbreviation
5203 table is reached. */
5204 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
5205 >= dwarf2_per_objfile
->abbrev_size
)
5207 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5208 abbrev_ptr
+= bytes_read
;
5209 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5216 /* Release the memory used by the abbrev table for a compilation unit. */
5219 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5221 struct dwarf2_cu
*cu
= ptr_to_cu
;
5223 obstack_free (&cu
->abbrev_obstack
, NULL
);
5224 cu
->dwarf2_abbrevs
= NULL
;
5227 /* Lookup an abbrev_info structure in the abbrev hash table. */
5229 static struct abbrev_info
*
5230 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5232 unsigned int hash_number
;
5233 struct abbrev_info
*abbrev
;
5235 hash_number
= number
% ABBREV_HASH_SIZE
;
5236 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5240 if (abbrev
->number
== number
)
5243 abbrev
= abbrev
->next
;
5248 /* Returns nonzero if TAG represents a type that we might generate a partial
5252 is_type_tag_for_partial (int tag
)
5257 /* Some types that would be reasonable to generate partial symbols for,
5258 that we don't at present. */
5259 case DW_TAG_array_type
:
5260 case DW_TAG_file_type
:
5261 case DW_TAG_ptr_to_member_type
:
5262 case DW_TAG_set_type
:
5263 case DW_TAG_string_type
:
5264 case DW_TAG_subroutine_type
:
5266 case DW_TAG_base_type
:
5267 case DW_TAG_class_type
:
5268 case DW_TAG_enumeration_type
:
5269 case DW_TAG_structure_type
:
5270 case DW_TAG_subrange_type
:
5271 case DW_TAG_typedef
:
5272 case DW_TAG_union_type
:
5279 /* Load all DIEs that are interesting for partial symbols into memory. */
5281 static struct partial_die_info
*
5282 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5283 struct dwarf2_cu
*cu
)
5285 struct partial_die_info
*part_die
;
5286 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5287 struct abbrev_info
*abbrev
;
5288 unsigned int bytes_read
;
5289 unsigned int load_all
= 0;
5291 int nesting_level
= 1;
5296 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5300 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5304 &cu
->comp_unit_obstack
,
5305 hashtab_obstack_allocate
,
5306 dummy_obstack_deallocate
);
5308 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5309 sizeof (struct partial_die_info
));
5313 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5315 /* A NULL abbrev means the end of a series of children. */
5318 if (--nesting_level
== 0)
5320 /* PART_DIE was probably the last thing allocated on the
5321 comp_unit_obstack, so we could call obstack_free
5322 here. We don't do that because the waste is small,
5323 and will be cleaned up when we're done with this
5324 compilation unit. This way, we're also more robust
5325 against other users of the comp_unit_obstack. */
5328 info_ptr
+= bytes_read
;
5329 last_die
= parent_die
;
5330 parent_die
= parent_die
->die_parent
;
5334 /* Check whether this DIE is interesting enough to save. Normally
5335 we would not be interested in members here, but there may be
5336 later variables referencing them via DW_AT_specification (for
5339 && !is_type_tag_for_partial (abbrev
->tag
)
5340 && abbrev
->tag
!= DW_TAG_enumerator
5341 && abbrev
->tag
!= DW_TAG_subprogram
5342 && abbrev
->tag
!= DW_TAG_variable
5343 && abbrev
->tag
!= DW_TAG_namespace
5344 && abbrev
->tag
!= DW_TAG_member
)
5346 /* Otherwise we skip to the next sibling, if any. */
5347 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5351 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5352 abfd
, info_ptr
, cu
);
5354 /* This two-pass algorithm for processing partial symbols has a
5355 high cost in cache pressure. Thus, handle some simple cases
5356 here which cover the majority of C partial symbols. DIEs
5357 which neither have specification tags in them, nor could have
5358 specification tags elsewhere pointing at them, can simply be
5359 processed and discarded.
5361 This segment is also optional; scan_partial_symbols and
5362 add_partial_symbol will handle these DIEs if we chain
5363 them in normally. When compilers which do not emit large
5364 quantities of duplicate debug information are more common,
5365 this code can probably be removed. */
5367 /* Any complete simple types at the top level (pretty much all
5368 of them, for a language without namespaces), can be processed
5370 if (parent_die
== NULL
5371 && part_die
->has_specification
== 0
5372 && part_die
->is_declaration
== 0
5373 && (part_die
->tag
== DW_TAG_typedef
5374 || part_die
->tag
== DW_TAG_base_type
5375 || part_die
->tag
== DW_TAG_subrange_type
))
5377 if (building_psymtab
&& part_die
->name
!= NULL
)
5378 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5379 VAR_DOMAIN
, LOC_TYPEDEF
,
5380 &cu
->objfile
->static_psymbols
,
5381 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5382 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5386 /* If we're at the second level, and we're an enumerator, and
5387 our parent has no specification (meaning possibly lives in a
5388 namespace elsewhere), then we can add the partial symbol now
5389 instead of queueing it. */
5390 if (part_die
->tag
== DW_TAG_enumerator
5391 && parent_die
!= NULL
5392 && parent_die
->die_parent
== NULL
5393 && parent_die
->tag
== DW_TAG_enumeration_type
5394 && parent_die
->has_specification
== 0)
5396 if (part_die
->name
== NULL
)
5397 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5398 else if (building_psymtab
)
5399 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5400 VAR_DOMAIN
, LOC_CONST
,
5401 (cu
->language
== language_cplus
5402 || cu
->language
== language_java
)
5403 ? &cu
->objfile
->global_psymbols
5404 : &cu
->objfile
->static_psymbols
,
5405 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5407 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5411 /* We'll save this DIE so link it in. */
5412 part_die
->die_parent
= parent_die
;
5413 part_die
->die_sibling
= NULL
;
5414 part_die
->die_child
= NULL
;
5416 if (last_die
&& last_die
== parent_die
)
5417 last_die
->die_child
= part_die
;
5419 last_die
->die_sibling
= part_die
;
5421 last_die
= part_die
;
5423 if (first_die
== NULL
)
5424 first_die
= part_die
;
5426 /* Maybe add the DIE to the hash table. Not all DIEs that we
5427 find interesting need to be in the hash table, because we
5428 also have the parent/sibling/child chains; only those that we
5429 might refer to by offset later during partial symbol reading.
5431 For now this means things that might have be the target of a
5432 DW_AT_specification, DW_AT_abstract_origin, or
5433 DW_AT_extension. DW_AT_extension will refer only to
5434 namespaces; DW_AT_abstract_origin refers to functions (and
5435 many things under the function DIE, but we do not recurse
5436 into function DIEs during partial symbol reading) and
5437 possibly variables as well; DW_AT_specification refers to
5438 declarations. Declarations ought to have the DW_AT_declaration
5439 flag. It happens that GCC forgets to put it in sometimes, but
5440 only for functions, not for types.
5442 Adding more things than necessary to the hash table is harmless
5443 except for the performance cost. Adding too few will result in
5444 wasted time in find_partial_die, when we reread the compilation
5445 unit with load_all_dies set. */
5448 || abbrev
->tag
== DW_TAG_subprogram
5449 || abbrev
->tag
== DW_TAG_variable
5450 || abbrev
->tag
== DW_TAG_namespace
5451 || part_die
->is_declaration
)
5455 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5456 part_die
->offset
, INSERT
);
5460 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5461 sizeof (struct partial_die_info
));
5463 /* For some DIEs we want to follow their children (if any). For C
5464 we have no reason to follow the children of structures; for other
5465 languages we have to, both so that we can get at method physnames
5466 to infer fully qualified class names, and for DW_AT_specification. */
5467 if (last_die
->has_children
5469 || last_die
->tag
== DW_TAG_namespace
5470 || last_die
->tag
== DW_TAG_enumeration_type
5471 || (cu
->language
!= language_c
5472 && (last_die
->tag
== DW_TAG_class_type
5473 || last_die
->tag
== DW_TAG_structure_type
5474 || last_die
->tag
== DW_TAG_union_type
))))
5477 parent_die
= last_die
;
5481 /* Otherwise we skip to the next sibling, if any. */
5482 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5484 /* Back to the top, do it again. */
5488 /* Read a minimal amount of information into the minimal die structure. */
5491 read_partial_die (struct partial_die_info
*part_die
,
5492 struct abbrev_info
*abbrev
,
5493 unsigned int abbrev_len
, bfd
*abfd
,
5494 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5496 unsigned int bytes_read
, i
;
5497 struct attribute attr
;
5498 int has_low_pc_attr
= 0;
5499 int has_high_pc_attr
= 0;
5501 memset (part_die
, 0, sizeof (struct partial_die_info
));
5503 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5505 info_ptr
+= abbrev_len
;
5510 part_die
->tag
= abbrev
->tag
;
5511 part_die
->has_children
= abbrev
->has_children
;
5513 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5515 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5517 /* Store the data if it is of an attribute we want to keep in a
5518 partial symbol table. */
5523 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5524 if (part_die
->name
== NULL
)
5525 part_die
->name
= DW_STRING (&attr
);
5527 case DW_AT_comp_dir
:
5528 if (part_die
->dirname
== NULL
)
5529 part_die
->dirname
= DW_STRING (&attr
);
5531 case DW_AT_MIPS_linkage_name
:
5532 part_die
->name
= DW_STRING (&attr
);
5535 has_low_pc_attr
= 1;
5536 part_die
->lowpc
= DW_ADDR (&attr
);
5539 has_high_pc_attr
= 1;
5540 part_die
->highpc
= DW_ADDR (&attr
);
5542 case DW_AT_location
:
5543 /* Support the .debug_loc offsets */
5544 if (attr_form_is_block (&attr
))
5546 part_die
->locdesc
= DW_BLOCK (&attr
);
5548 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
5550 dwarf2_complex_location_expr_complaint ();
5554 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5555 "partial symbol information");
5558 case DW_AT_language
:
5559 part_die
->language
= DW_UNSND (&attr
);
5561 case DW_AT_external
:
5562 part_die
->is_external
= DW_UNSND (&attr
);
5564 case DW_AT_declaration
:
5565 part_die
->is_declaration
= DW_UNSND (&attr
);
5568 part_die
->has_type
= 1;
5570 case DW_AT_abstract_origin
:
5571 case DW_AT_specification
:
5572 case DW_AT_extension
:
5573 part_die
->has_specification
= 1;
5574 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5577 /* Ignore absolute siblings, they might point outside of
5578 the current compile unit. */
5579 if (attr
.form
== DW_FORM_ref_addr
)
5580 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
5582 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5583 + dwarf2_get_ref_die_offset (&attr
, cu
);
5585 case DW_AT_stmt_list
:
5586 part_die
->has_stmt_list
= 1;
5587 part_die
->line_offset
= DW_UNSND (&attr
);
5589 case DW_AT_byte_size
:
5590 part_die
->has_byte_size
= 1;
5597 /* When using the GNU linker, .gnu.linkonce. sections are used to
5598 eliminate duplicate copies of functions and vtables and such.
5599 The linker will arbitrarily choose one and discard the others.
5600 The AT_*_pc values for such functions refer to local labels in
5601 these sections. If the section from that file was discarded, the
5602 labels are not in the output, so the relocs get a value of 0.
5603 If this is a discarded function, mark the pc bounds as invalid,
5604 so that GDB will ignore it. */
5605 if (has_low_pc_attr
&& has_high_pc_attr
5606 && part_die
->lowpc
< part_die
->highpc
5607 && (part_die
->lowpc
!= 0
5608 || dwarf2_per_objfile
->has_section_at_zero
))
5609 part_die
->has_pc_info
= 1;
5613 /* Find a cached partial DIE at OFFSET in CU. */
5615 static struct partial_die_info
*
5616 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5618 struct partial_die_info
*lookup_die
= NULL
;
5619 struct partial_die_info part_die
;
5621 part_die
.offset
= offset
;
5622 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5627 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5629 static struct partial_die_info
*
5630 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
)
5632 struct dwarf2_per_cu_data
*per_cu
= NULL
;
5633 struct partial_die_info
*pd
= NULL
;
5635 if (offset
>= cu
->header
.offset
5636 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5638 pd
= find_partial_die_in_comp_unit (offset
, cu
);
5643 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5645 if (per_cu
->cu
== NULL
)
5647 load_comp_unit (per_cu
, cu
->objfile
);
5648 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5649 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5652 per_cu
->cu
->last_used
= 0;
5653 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5655 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
5657 struct cleanup
*back_to
;
5658 struct partial_die_info comp_unit_die
;
5659 struct abbrev_info
*abbrev
;
5660 unsigned int bytes_read
;
5663 per_cu
->load_all_dies
= 1;
5665 /* Re-read the DIEs. */
5666 back_to
= make_cleanup (null_cleanup
, 0);
5667 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
5669 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
5670 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
5672 info_ptr
= per_cu
->cu
->header
.first_die_ptr
;
5673 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
5674 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
5675 per_cu
->cu
->objfile
->obfd
, info_ptr
,
5677 if (comp_unit_die
.has_children
)
5678 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
5679 do_cleanups (back_to
);
5681 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5685 internal_error (__FILE__
, __LINE__
,
5686 _("could not find partial DIE 0x%lx in cache [from module %s]\n"),
5687 offset
, bfd_get_filename (cu
->objfile
->obfd
));
5691 /* Adjust PART_DIE before generating a symbol for it. This function
5692 may set the is_external flag or change the DIE's name. */
5695 fixup_partial_die (struct partial_die_info
*part_die
,
5696 struct dwarf2_cu
*cu
)
5698 /* If we found a reference attribute and the DIE has no name, try
5699 to find a name in the referred to DIE. */
5701 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5703 struct partial_die_info
*spec_die
;
5705 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
5707 fixup_partial_die (spec_die
, cu
);
5711 part_die
->name
= spec_die
->name
;
5713 /* Copy DW_AT_external attribute if it is set. */
5714 if (spec_die
->is_external
)
5715 part_die
->is_external
= spec_die
->is_external
;
5719 /* Set default names for some unnamed DIEs. */
5720 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
5721 || part_die
->tag
== DW_TAG_class_type
))
5722 part_die
->name
= "(anonymous class)";
5724 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
5725 part_die
->name
= "(anonymous namespace)";
5727 if (part_die
->tag
== DW_TAG_structure_type
5728 || part_die
->tag
== DW_TAG_class_type
5729 || part_die
->tag
== DW_TAG_union_type
)
5730 guess_structure_name (part_die
, cu
);
5733 /* Read the die from the .debug_info section buffer. Set DIEP to
5734 point to a newly allocated die with its information, except for its
5735 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5736 whether the die has children or not. */
5739 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
5740 struct dwarf2_cu
*cu
, int *has_children
)
5742 unsigned int abbrev_number
, bytes_read
, i
, offset
;
5743 struct abbrev_info
*abbrev
;
5744 struct die_info
*die
;
5746 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5747 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5748 info_ptr
+= bytes_read
;
5751 die
= dwarf_alloc_die ();
5753 die
->abbrev
= abbrev_number
;
5760 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5763 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
5765 bfd_get_filename (abfd
));
5767 die
= dwarf_alloc_die ();
5768 die
->offset
= offset
;
5769 die
->tag
= abbrev
->tag
;
5770 die
->abbrev
= abbrev_number
;
5773 die
->num_attrs
= abbrev
->num_attrs
;
5774 die
->attrs
= (struct attribute
*)
5775 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
5777 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5779 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
5780 abfd
, info_ptr
, cu
);
5782 /* If this attribute is an absolute reference to a different
5783 compilation unit, make sure that compilation unit is loaded
5785 if (die
->attrs
[i
].form
== DW_FORM_ref_addr
5786 && (DW_ADDR (&die
->attrs
[i
]) < cu
->header
.offset
5787 || (DW_ADDR (&die
->attrs
[i
])
5788 >= cu
->header
.offset
+ cu
->header
.length
)))
5790 struct dwarf2_per_cu_data
*per_cu
;
5791 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (&die
->attrs
[i
]),
5794 /* Mark the dependence relation so that we don't flush PER_CU
5796 dwarf2_add_dependence (cu
, per_cu
);
5798 /* If it's already on the queue, we have nothing to do. */
5802 /* If the compilation unit is already loaded, just mark it as
5804 if (per_cu
->cu
!= NULL
)
5806 per_cu
->cu
->last_used
= 0;
5810 /* Add it to the queue. */
5811 queue_comp_unit (per_cu
);
5816 *has_children
= abbrev
->has_children
;
5820 /* Read an attribute value described by an attribute form. */
5823 read_attribute_value (struct attribute
*attr
, unsigned form
,
5824 bfd
*abfd
, gdb_byte
*info_ptr
,
5825 struct dwarf2_cu
*cu
)
5827 struct comp_unit_head
*cu_header
= &cu
->header
;
5828 unsigned int bytes_read
;
5829 struct dwarf_block
*blk
;
5835 case DW_FORM_ref_addr
:
5836 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5837 info_ptr
+= bytes_read
;
5839 case DW_FORM_block2
:
5840 blk
= dwarf_alloc_block (cu
);
5841 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5843 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5844 info_ptr
+= blk
->size
;
5845 DW_BLOCK (attr
) = blk
;
5847 case DW_FORM_block4
:
5848 blk
= dwarf_alloc_block (cu
);
5849 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5851 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5852 info_ptr
+= blk
->size
;
5853 DW_BLOCK (attr
) = blk
;
5856 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5860 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5864 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5867 case DW_FORM_string
:
5868 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5869 info_ptr
+= bytes_read
;
5872 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5874 info_ptr
+= bytes_read
;
5877 blk
= dwarf_alloc_block (cu
);
5878 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5879 info_ptr
+= bytes_read
;
5880 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5881 info_ptr
+= blk
->size
;
5882 DW_BLOCK (attr
) = blk
;
5884 case DW_FORM_block1
:
5885 blk
= dwarf_alloc_block (cu
);
5886 blk
->size
= read_1_byte (abfd
, info_ptr
);
5888 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5889 info_ptr
+= blk
->size
;
5890 DW_BLOCK (attr
) = blk
;
5893 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5897 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5901 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5902 info_ptr
+= bytes_read
;
5905 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5906 info_ptr
+= bytes_read
;
5909 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
5913 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
5917 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
5921 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
5924 case DW_FORM_ref_udata
:
5925 DW_ADDR (attr
) = (cu
->header
.offset
5926 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
5927 info_ptr
+= bytes_read
;
5929 case DW_FORM_indirect
:
5930 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5931 info_ptr
+= bytes_read
;
5932 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5935 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
5936 dwarf_form_name (form
),
5937 bfd_get_filename (abfd
));
5942 /* Read an attribute described by an abbreviated attribute. */
5945 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5946 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
5948 attr
->name
= abbrev
->name
;
5949 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5952 /* read dwarf information from a buffer */
5955 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
5957 return bfd_get_8 (abfd
, buf
);
5961 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
5963 return bfd_get_signed_8 (abfd
, buf
);
5967 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
5969 return bfd_get_16 (abfd
, buf
);
5973 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
5975 return bfd_get_signed_16 (abfd
, buf
);
5979 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
5981 return bfd_get_32 (abfd
, buf
);
5985 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
5987 return bfd_get_signed_32 (abfd
, buf
);
5990 static unsigned long
5991 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
5993 return bfd_get_64 (abfd
, buf
);
5997 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
5998 unsigned int *bytes_read
)
6000 struct comp_unit_head
*cu_header
= &cu
->header
;
6001 CORE_ADDR retval
= 0;
6003 if (cu_header
->signed_addr_p
)
6005 switch (cu_header
->addr_size
)
6008 retval
= bfd_get_signed_16 (abfd
, buf
);
6011 retval
= bfd_get_signed_32 (abfd
, buf
);
6014 retval
= bfd_get_signed_64 (abfd
, buf
);
6017 internal_error (__FILE__
, __LINE__
,
6018 _("read_address: bad switch, signed [in module %s]"),
6019 bfd_get_filename (abfd
));
6024 switch (cu_header
->addr_size
)
6027 retval
= bfd_get_16 (abfd
, buf
);
6030 retval
= bfd_get_32 (abfd
, buf
);
6033 retval
= bfd_get_64 (abfd
, buf
);
6036 internal_error (__FILE__
, __LINE__
,
6037 _("read_address: bad switch, unsigned [in module %s]"),
6038 bfd_get_filename (abfd
));
6042 *bytes_read
= cu_header
->addr_size
;
6046 /* Read the initial length from a section. The (draft) DWARF 3
6047 specification allows the initial length to take up either 4 bytes
6048 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6049 bytes describe the length and all offsets will be 8 bytes in length
6052 An older, non-standard 64-bit format is also handled by this
6053 function. The older format in question stores the initial length
6054 as an 8-byte quantity without an escape value. Lengths greater
6055 than 2^32 aren't very common which means that the initial 4 bytes
6056 is almost always zero. Since a length value of zero doesn't make
6057 sense for the 32-bit format, this initial zero can be considered to
6058 be an escape value which indicates the presence of the older 64-bit
6059 format. As written, the code can't detect (old format) lengths
6060 greater than 4GB. If it becomes necessary to handle lengths
6061 somewhat larger than 4GB, we could allow other small values (such
6062 as the non-sensical values of 1, 2, and 3) to also be used as
6063 escape values indicating the presence of the old format.
6065 The value returned via bytes_read should be used to increment the
6066 relevant pointer after calling read_initial_length().
6068 As a side effect, this function sets the fields initial_length_size
6069 and offset_size in cu_header to the values appropriate for the
6070 length field. (The format of the initial length field determines
6071 the width of file offsets to be fetched later with read_offset().)
6073 [ Note: read_initial_length() and read_offset() are based on the
6074 document entitled "DWARF Debugging Information Format", revision
6075 3, draft 8, dated November 19, 2001. This document was obtained
6078 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6080 This document is only a draft and is subject to change. (So beware.)
6082 Details regarding the older, non-standard 64-bit format were
6083 determined empirically by examining 64-bit ELF files produced by
6084 the SGI toolchain on an IRIX 6.5 machine.
6086 - Kevin, July 16, 2002
6090 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, struct comp_unit_head
*cu_header
,
6091 unsigned int *bytes_read
)
6093 LONGEST length
= bfd_get_32 (abfd
, buf
);
6095 if (length
== 0xffffffff)
6097 length
= bfd_get_64 (abfd
, buf
+ 4);
6100 else if (length
== 0)
6102 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6103 length
= bfd_get_64 (abfd
, buf
);
6113 gdb_assert (cu_header
->initial_length_size
== 0
6114 || cu_header
->initial_length_size
== 4
6115 || cu_header
->initial_length_size
== 8
6116 || cu_header
->initial_length_size
== 12);
6118 if (cu_header
->initial_length_size
!= 0
6119 && cu_header
->initial_length_size
!= *bytes_read
)
6120 complaint (&symfile_complaints
,
6121 _("intermixed 32-bit and 64-bit DWARF sections"));
6123 cu_header
->initial_length_size
= *bytes_read
;
6124 cu_header
->offset_size
= (*bytes_read
== 4) ? 4 : 8;
6130 /* Read an offset from the data stream. The size of the offset is
6131 given by cu_header->offset_size. */
6134 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6135 unsigned int *bytes_read
)
6139 switch (cu_header
->offset_size
)
6142 retval
= bfd_get_32 (abfd
, buf
);
6146 retval
= bfd_get_64 (abfd
, buf
);
6150 internal_error (__FILE__
, __LINE__
,
6151 _("read_offset: bad switch [in module %s]"),
6152 bfd_get_filename (abfd
));
6159 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6161 /* If the size of a host char is 8 bits, we can return a pointer
6162 to the buffer, otherwise we have to copy the data to a buffer
6163 allocated on the temporary obstack. */
6164 gdb_assert (HOST_CHAR_BIT
== 8);
6169 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6171 /* If the size of a host char is 8 bits, we can return a pointer
6172 to the string, otherwise we have to copy the string to a buffer
6173 allocated on the temporary obstack. */
6174 gdb_assert (HOST_CHAR_BIT
== 8);
6177 *bytes_read_ptr
= 1;
6180 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6181 return (char *) buf
;
6185 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6186 const struct comp_unit_head
*cu_header
,
6187 unsigned int *bytes_read_ptr
)
6189 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
6192 if (dwarf2_per_objfile
->str_buffer
== NULL
)
6194 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6195 bfd_get_filename (abfd
));
6198 if (str_offset
>= dwarf2_per_objfile
->str_size
)
6200 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6201 bfd_get_filename (abfd
));
6204 gdb_assert (HOST_CHAR_BIT
== 8);
6205 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
6207 return (char *) (dwarf2_per_objfile
->str_buffer
+ str_offset
);
6210 static unsigned long
6211 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6213 unsigned long result
;
6214 unsigned int num_read
;
6224 byte
= bfd_get_8 (abfd
, buf
);
6227 result
|= ((unsigned long)(byte
& 127) << shift
);
6228 if ((byte
& 128) == 0)
6234 *bytes_read_ptr
= num_read
;
6239 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6242 int i
, shift
, num_read
;
6251 byte
= bfd_get_8 (abfd
, buf
);
6254 result
|= ((long)(byte
& 127) << shift
);
6256 if ((byte
& 128) == 0)
6261 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6262 result
|= -(((long)1) << shift
);
6263 *bytes_read_ptr
= num_read
;
6267 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6270 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6276 byte
= bfd_get_8 (abfd
, buf
);
6278 if ((byte
& 128) == 0)
6284 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6290 cu
->language
= language_c
;
6292 case DW_LANG_C_plus_plus
:
6293 cu
->language
= language_cplus
;
6295 case DW_LANG_Fortran77
:
6296 case DW_LANG_Fortran90
:
6297 case DW_LANG_Fortran95
:
6298 cu
->language
= language_fortran
;
6300 case DW_LANG_Mips_Assembler
:
6301 cu
->language
= language_asm
;
6304 cu
->language
= language_java
;
6308 cu
->language
= language_ada
;
6310 case DW_LANG_Modula2
:
6311 cu
->language
= language_m2
;
6313 case DW_LANG_Cobol74
:
6314 case DW_LANG_Cobol85
:
6315 case DW_LANG_Pascal83
:
6317 cu
->language
= language_minimal
;
6320 cu
->language_defn
= language_def (cu
->language
);
6323 /* Return the named attribute or NULL if not there. */
6325 static struct attribute
*
6326 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6329 struct attribute
*spec
= NULL
;
6331 for (i
= 0; i
< die
->num_attrs
; ++i
)
6333 if (die
->attrs
[i
].name
== name
)
6334 return &die
->attrs
[i
];
6335 if (die
->attrs
[i
].name
== DW_AT_specification
6336 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6337 spec
= &die
->attrs
[i
];
6341 return dwarf2_attr (follow_die_ref (die
, spec
, cu
), name
, cu
);
6346 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6347 and holds a non-zero value. This function should only be used for
6348 DW_FORM_flag attributes. */
6351 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6353 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
6355 return (attr
&& DW_UNSND (attr
));
6359 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
6361 /* A DIE is a declaration if it has a DW_AT_declaration attribute
6362 which value is non-zero. However, we have to be careful with
6363 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
6364 (via dwarf2_flag_true_p) follows this attribute. So we may
6365 end up accidently finding a declaration attribute that belongs
6366 to a different DIE referenced by the specification attribute,
6367 even though the given DIE does not have a declaration attribute. */
6368 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
6369 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6372 /* Return the die giving the specification for DIE, if there is
6375 static struct die_info
*
6376 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6378 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6380 if (spec_attr
== NULL
)
6383 return follow_die_ref (die
, spec_attr
, cu
);
6386 /* Free the line_header structure *LH, and any arrays and strings it
6389 free_line_header (struct line_header
*lh
)
6391 if (lh
->standard_opcode_lengths
)
6392 xfree (lh
->standard_opcode_lengths
);
6394 /* Remember that all the lh->file_names[i].name pointers are
6395 pointers into debug_line_buffer, and don't need to be freed. */
6397 xfree (lh
->file_names
);
6399 /* Similarly for the include directory names. */
6400 if (lh
->include_dirs
)
6401 xfree (lh
->include_dirs
);
6407 /* Add an entry to LH's include directory table. */
6409 add_include_dir (struct line_header
*lh
, char *include_dir
)
6411 /* Grow the array if necessary. */
6412 if (lh
->include_dirs_size
== 0)
6414 lh
->include_dirs_size
= 1; /* for testing */
6415 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6416 * sizeof (*lh
->include_dirs
));
6418 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6420 lh
->include_dirs_size
*= 2;
6421 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6422 (lh
->include_dirs_size
6423 * sizeof (*lh
->include_dirs
)));
6426 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6430 /* Add an entry to LH's file name table. */
6432 add_file_name (struct line_header
*lh
,
6434 unsigned int dir_index
,
6435 unsigned int mod_time
,
6436 unsigned int length
)
6438 struct file_entry
*fe
;
6440 /* Grow the array if necessary. */
6441 if (lh
->file_names_size
== 0)
6443 lh
->file_names_size
= 1; /* for testing */
6444 lh
->file_names
= xmalloc (lh
->file_names_size
6445 * sizeof (*lh
->file_names
));
6447 else if (lh
->num_file_names
>= lh
->file_names_size
)
6449 lh
->file_names_size
*= 2;
6450 lh
->file_names
= xrealloc (lh
->file_names
,
6451 (lh
->file_names_size
6452 * sizeof (*lh
->file_names
)));
6455 fe
= &lh
->file_names
[lh
->num_file_names
++];
6457 fe
->dir_index
= dir_index
;
6458 fe
->mod_time
= mod_time
;
6459 fe
->length
= length
;
6464 /* Read the statement program header starting at OFFSET in
6465 .debug_line, according to the endianness of ABFD. Return a pointer
6466 to a struct line_header, allocated using xmalloc.
6468 NOTE: the strings in the include directory and file name tables of
6469 the returned object point into debug_line_buffer, and must not be
6471 static struct line_header
*
6472 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6473 struct dwarf2_cu
*cu
)
6475 struct cleanup
*back_to
;
6476 struct line_header
*lh
;
6478 unsigned int bytes_read
;
6480 char *cur_dir
, *cur_file
;
6482 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6484 complaint (&symfile_complaints
, _("missing .debug_line section"));
6488 /* Make sure that at least there's room for the total_length field.
6489 That could be 12 bytes long, but we're just going to fudge that. */
6490 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6492 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6496 lh
= xmalloc (sizeof (*lh
));
6497 memset (lh
, 0, sizeof (*lh
));
6498 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6501 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6503 /* Read in the header. */
6505 read_initial_length (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6506 line_ptr
+= bytes_read
;
6507 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6508 + dwarf2_per_objfile
->line_size
))
6510 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6513 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6514 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6516 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6517 line_ptr
+= bytes_read
;
6518 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6520 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6522 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6524 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6526 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6528 lh
->standard_opcode_lengths
6529 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
6531 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6532 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6534 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6538 /* Read directory table. */
6539 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6541 line_ptr
+= bytes_read
;
6542 add_include_dir (lh
, cur_dir
);
6544 line_ptr
+= bytes_read
;
6546 /* Read file name table. */
6547 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6549 unsigned int dir_index
, mod_time
, length
;
6551 line_ptr
+= bytes_read
;
6552 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6553 line_ptr
+= bytes_read
;
6554 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6555 line_ptr
+= bytes_read
;
6556 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6557 line_ptr
+= bytes_read
;
6559 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6561 line_ptr
+= bytes_read
;
6562 lh
->statement_program_start
= line_ptr
;
6564 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6565 + dwarf2_per_objfile
->line_size
))
6566 complaint (&symfile_complaints
,
6567 _("line number info header doesn't fit in `.debug_line' section"));
6569 discard_cleanups (back_to
);
6573 /* This function exists to work around a bug in certain compilers
6574 (particularly GCC 2.95), in which the first line number marker of a
6575 function does not show up until after the prologue, right before
6576 the second line number marker. This function shifts ADDRESS down
6577 to the beginning of the function if necessary, and is called on
6578 addresses passed to record_line. */
6581 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6583 struct function_range
*fn
;
6585 /* Find the function_range containing address. */
6590 cu
->cached_fn
= cu
->first_fn
;
6594 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6600 while (fn
&& fn
!= cu
->cached_fn
)
6601 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6611 if (address
!= fn
->lowpc
)
6612 complaint (&symfile_complaints
,
6613 _("misplaced first line number at 0x%lx for '%s'"),
6614 (unsigned long) address
, fn
->name
);
6619 /* Decode the Line Number Program (LNP) for the given line_header
6620 structure and CU. The actual information extracted and the type
6621 of structures created from the LNP depends on the value of PST.
6623 1. If PST is NULL, then this procedure uses the data from the program
6624 to create all necessary symbol tables, and their linetables.
6625 The compilation directory of the file is passed in COMP_DIR,
6626 and must not be NULL.
6628 2. If PST is not NULL, this procedure reads the program to determine
6629 the list of files included by the unit represented by PST, and
6630 builds all the associated partial symbol tables. In this case,
6631 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6632 is not used to compute the full name of the symtab, and therefore
6633 omitting it when building the partial symtab does not introduce
6634 the potential for inconsistency - a partial symtab and its associated
6635 symbtab having a different fullname -). */
6638 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6639 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6643 unsigned int bytes_read
;
6644 unsigned char op_code
, extended_op
, adj_opcode
;
6646 struct objfile
*objfile
= cu
->objfile
;
6647 const int decode_for_pst_p
= (pst
!= NULL
);
6648 struct subfile
*last_subfile
= NULL
;
6650 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6652 line_ptr
= lh
->statement_program_start
;
6653 line_end
= lh
->statement_program_end
;
6655 /* Read the statement sequences until there's nothing left. */
6656 while (line_ptr
< line_end
)
6658 /* state machine registers */
6659 CORE_ADDR address
= 0;
6660 unsigned int file
= 1;
6661 unsigned int line
= 1;
6662 unsigned int column
= 0;
6663 int is_stmt
= lh
->default_is_stmt
;
6664 int basic_block
= 0;
6665 int end_sequence
= 0;
6667 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6669 /* Start a subfile for the current file of the state machine. */
6670 /* lh->include_dirs and lh->file_names are 0-based, but the
6671 directory and file name numbers in the statement program
6673 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6677 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6679 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6682 /* Decode the table. */
6683 while (!end_sequence
)
6685 op_code
= read_1_byte (abfd
, line_ptr
);
6688 if (op_code
>= lh
->opcode_base
)
6690 /* Special operand. */
6691 adj_opcode
= op_code
- lh
->opcode_base
;
6692 address
+= (adj_opcode
/ lh
->line_range
)
6693 * lh
->minimum_instruction_length
;
6694 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
6695 lh
->file_names
[file
- 1].included_p
= 1;
6696 if (!decode_for_pst_p
)
6698 if (last_subfile
!= current_subfile
)
6701 record_line (last_subfile
, 0, address
);
6702 last_subfile
= current_subfile
;
6704 /* Append row to matrix using current values. */
6705 record_line (current_subfile
, line
,
6706 check_cu_functions (address
, cu
));
6710 else switch (op_code
)
6712 case DW_LNS_extended_op
:
6713 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6714 line_ptr
+= bytes_read
;
6715 extended_op
= read_1_byte (abfd
, line_ptr
);
6717 switch (extended_op
)
6719 case DW_LNE_end_sequence
:
6721 lh
->file_names
[file
- 1].included_p
= 1;
6722 if (!decode_for_pst_p
)
6723 record_line (current_subfile
, 0, address
);
6725 case DW_LNE_set_address
:
6726 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
6727 line_ptr
+= bytes_read
;
6728 address
+= baseaddr
;
6730 case DW_LNE_define_file
:
6733 unsigned int dir_index
, mod_time
, length
;
6735 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
6736 line_ptr
+= bytes_read
;
6738 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6739 line_ptr
+= bytes_read
;
6741 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6742 line_ptr
+= bytes_read
;
6744 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6745 line_ptr
+= bytes_read
;
6746 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6750 complaint (&symfile_complaints
,
6751 _("mangled .debug_line section"));
6756 lh
->file_names
[file
- 1].included_p
= 1;
6757 if (!decode_for_pst_p
)
6759 if (last_subfile
!= current_subfile
)
6762 record_line (last_subfile
, 0, address
);
6763 last_subfile
= current_subfile
;
6765 record_line (current_subfile
, line
,
6766 check_cu_functions (address
, cu
));
6770 case DW_LNS_advance_pc
:
6771 address
+= lh
->minimum_instruction_length
6772 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6773 line_ptr
+= bytes_read
;
6775 case DW_LNS_advance_line
:
6776 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
6777 line_ptr
+= bytes_read
;
6779 case DW_LNS_set_file
:
6781 /* The arrays lh->include_dirs and lh->file_names are
6782 0-based, but the directory and file name numbers in
6783 the statement program are 1-based. */
6784 struct file_entry
*fe
;
6787 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6788 line_ptr
+= bytes_read
;
6789 fe
= &lh
->file_names
[file
- 1];
6791 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6793 if (!decode_for_pst_p
)
6795 last_subfile
= current_subfile
;
6796 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
6800 case DW_LNS_set_column
:
6801 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6802 line_ptr
+= bytes_read
;
6804 case DW_LNS_negate_stmt
:
6805 is_stmt
= (!is_stmt
);
6807 case DW_LNS_set_basic_block
:
6810 /* Add to the address register of the state machine the
6811 address increment value corresponding to special opcode
6812 255. I.e., this value is scaled by the minimum
6813 instruction length since special opcode 255 would have
6814 scaled the the increment. */
6815 case DW_LNS_const_add_pc
:
6816 address
+= (lh
->minimum_instruction_length
6817 * ((255 - lh
->opcode_base
) / lh
->line_range
));
6819 case DW_LNS_fixed_advance_pc
:
6820 address
+= read_2_bytes (abfd
, line_ptr
);
6825 /* Unknown standard opcode, ignore it. */
6828 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
6830 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6831 line_ptr
+= bytes_read
;
6838 if (decode_for_pst_p
)
6842 /* Now that we're done scanning the Line Header Program, we can
6843 create the psymtab of each included file. */
6844 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
6845 if (lh
->file_names
[file_index
].included_p
== 1)
6847 const struct file_entry fe
= lh
->file_names
[file_index
];
6848 char *include_name
= fe
.name
;
6849 char *dir_name
= NULL
;
6850 char *pst_filename
= pst
->filename
;
6853 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
6855 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
6857 include_name
= concat (dir_name
, SLASH_STRING
,
6858 include_name
, (char *)NULL
);
6859 make_cleanup (xfree
, include_name
);
6862 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
6864 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
6865 pst_filename
, (char *)NULL
);
6866 make_cleanup (xfree
, pst_filename
);
6869 if (strcmp (include_name
, pst_filename
) != 0)
6870 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
6875 /* Start a subfile for DWARF. FILENAME is the name of the file and
6876 DIRNAME the name of the source directory which contains FILENAME
6877 or NULL if not known. COMP_DIR is the compilation directory for the
6878 linetable's compilation unit or NULL if not known.
6879 This routine tries to keep line numbers from identical absolute and
6880 relative file names in a common subfile.
6882 Using the `list' example from the GDB testsuite, which resides in
6883 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6884 of /srcdir/list0.c yields the following debugging information for list0.c:
6886 DW_AT_name: /srcdir/list0.c
6887 DW_AT_comp_dir: /compdir
6888 files.files[0].name: list0.h
6889 files.files[0].dir: /srcdir
6890 files.files[1].name: list0.c
6891 files.files[1].dir: /srcdir
6893 The line number information for list0.c has to end up in a single
6894 subfile, so that `break /srcdir/list0.c:1' works as expected.
6895 start_subfile will ensure that this happens provided that we pass the
6896 concatenation of files.files[1].dir and files.files[1].name as the
6900 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
6904 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
6905 `start_symtab' will always pass the contents of DW_AT_comp_dir as
6906 second argument to start_subfile. To be consistent, we do the
6907 same here. In order not to lose the line information directory,
6908 we concatenate it to the filename when it makes sense.
6909 Note that the Dwarf3 standard says (speaking of filenames in line
6910 information): ``The directory index is ignored for file names
6911 that represent full path names''. Thus ignoring dirname in the
6912 `else' branch below isn't an issue. */
6914 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6915 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
6917 fullname
= filename
;
6919 start_subfile (fullname
, comp_dir
);
6921 if (fullname
!= filename
)
6926 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6927 struct dwarf2_cu
*cu
)
6929 struct objfile
*objfile
= cu
->objfile
;
6930 struct comp_unit_head
*cu_header
= &cu
->header
;
6932 /* NOTE drow/2003-01-30: There used to be a comment and some special
6933 code here to turn a symbol with DW_AT_external and a
6934 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6935 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6936 with some versions of binutils) where shared libraries could have
6937 relocations against symbols in their debug information - the
6938 minimal symbol would have the right address, but the debug info
6939 would not. It's no longer necessary, because we will explicitly
6940 apply relocations when we read in the debug information now. */
6942 /* A DW_AT_location attribute with no contents indicates that a
6943 variable has been optimized away. */
6944 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6946 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6950 /* Handle one degenerate form of location expression specially, to
6951 preserve GDB's previous behavior when section offsets are
6952 specified. If this is just a DW_OP_addr then mark this symbol
6955 if (attr_form_is_block (attr
)
6956 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6957 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6961 SYMBOL_VALUE_ADDRESS (sym
) =
6962 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6963 fixup_symbol_section (sym
, objfile
);
6964 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6965 SYMBOL_SECTION (sym
));
6966 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6970 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6971 expression evaluator, and use LOC_COMPUTED only when necessary
6972 (i.e. when the value of a register or memory location is
6973 referenced, or a thread-local block, etc.). Then again, it might
6974 not be worthwhile. I'm assuming that it isn't unless performance
6975 or memory numbers show me otherwise. */
6977 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6978 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6981 /* Given a pointer to a DWARF information entry, figure out if we need
6982 to make a symbol table entry for it, and if so, create a new entry
6983 and return a pointer to it.
6984 If TYPE is NULL, determine symbol type from the die, otherwise
6985 used the passed type. */
6987 static struct symbol
*
6988 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6990 struct objfile
*objfile
= cu
->objfile
;
6991 struct symbol
*sym
= NULL
;
6993 struct attribute
*attr
= NULL
;
6994 struct attribute
*attr2
= NULL
;
6997 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6999 if (die
->tag
!= DW_TAG_namespace
)
7000 name
= dwarf2_linkage_name (die
, cu
);
7002 name
= TYPE_NAME (type
);
7006 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7007 sizeof (struct symbol
));
7008 OBJSTAT (objfile
, n_syms
++);
7009 memset (sym
, 0, sizeof (struct symbol
));
7011 /* Cache this symbol's name and the name's demangled form (if any). */
7012 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7013 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7015 /* Default assumptions.
7016 Use the passed type or decode it from the die. */
7017 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7018 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7020 SYMBOL_TYPE (sym
) = type
;
7022 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7023 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7026 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7031 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7034 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7036 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7038 case DW_TAG_subprogram
:
7039 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7041 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7042 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7043 if (attr2
&& (DW_UNSND (attr2
) != 0))
7045 add_symbol_to_list (sym
, &global_symbols
);
7049 add_symbol_to_list (sym
, cu
->list_in_scope
);
7052 case DW_TAG_variable
:
7053 /* Compilation with minimal debug info may result in variables
7054 with missing type entries. Change the misleading `void' type
7055 to something sensible. */
7056 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7057 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
7058 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
7059 "<variable, no debug info>",
7061 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7064 dwarf2_const_value (attr
, sym
, cu
);
7065 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7066 if (attr2
&& (DW_UNSND (attr2
) != 0))
7067 add_symbol_to_list (sym
, &global_symbols
);
7069 add_symbol_to_list (sym
, cu
->list_in_scope
);
7072 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7075 var_decode_location (attr
, sym
, cu
);
7076 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7077 if (attr2
&& (DW_UNSND (attr2
) != 0))
7078 add_symbol_to_list (sym
, &global_symbols
);
7080 add_symbol_to_list (sym
, cu
->list_in_scope
);
7084 /* We do not know the address of this symbol.
7085 If it is an external symbol and we have type information
7086 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7087 The address of the variable will then be determined from
7088 the minimal symbol table whenever the variable is
7090 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7091 if (attr2
&& (DW_UNSND (attr2
) != 0)
7092 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7094 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7095 add_symbol_to_list (sym
, &global_symbols
);
7099 case DW_TAG_formal_parameter
:
7100 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7103 var_decode_location (attr
, sym
, cu
);
7104 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
7105 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
7106 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
7108 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7111 dwarf2_const_value (attr
, sym
, cu
);
7113 add_symbol_to_list (sym
, cu
->list_in_scope
);
7115 case DW_TAG_unspecified_parameters
:
7116 /* From varargs functions; gdb doesn't seem to have any
7117 interest in this information, so just ignore it for now.
7120 case DW_TAG_class_type
:
7121 case DW_TAG_structure_type
:
7122 case DW_TAG_union_type
:
7123 case DW_TAG_set_type
:
7124 case DW_TAG_enumeration_type
:
7125 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7126 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7128 /* Make sure that the symbol includes appropriate enclosing
7129 classes/namespaces in its name. These are calculated in
7130 read_structure_type, and the correct name is saved in
7133 if (cu
->language
== language_cplus
7134 || cu
->language
== language_java
)
7136 struct type
*type
= SYMBOL_TYPE (sym
);
7138 if (TYPE_TAG_NAME (type
) != NULL
)
7140 /* FIXME: carlton/2003-11-10: Should this use
7141 SYMBOL_SET_NAMES instead? (The same problem also
7142 arises further down in this function.) */
7143 /* The type's name is already allocated along with
7144 this objfile, so we don't need to duplicate it
7146 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7151 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7152 really ever be static objects: otherwise, if you try
7153 to, say, break of a class's method and you're in a file
7154 which doesn't mention that class, it won't work unless
7155 the check for all static symbols in lookup_symbol_aux
7156 saves you. See the OtherFileClass tests in
7157 gdb.c++/namespace.exp. */
7159 struct pending
**list_to_add
;
7161 list_to_add
= (cu
->list_in_scope
== &file_symbols
7162 && (cu
->language
== language_cplus
7163 || cu
->language
== language_java
)
7164 ? &global_symbols
: cu
->list_in_scope
);
7166 add_symbol_to_list (sym
, list_to_add
);
7168 /* The semantics of C++ state that "struct foo { ... }" also
7169 defines a typedef for "foo". A Java class declaration also
7170 defines a typedef for the class. Synthesize a typedef symbol
7171 so that "ptype foo" works as expected. */
7172 if (cu
->language
== language_cplus
7173 || cu
->language
== language_java
)
7175 struct symbol
*typedef_sym
= (struct symbol
*)
7176 obstack_alloc (&objfile
->objfile_obstack
,
7177 sizeof (struct symbol
));
7178 *typedef_sym
= *sym
;
7179 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
7180 /* The symbol's name is already allocated along with
7181 this objfile, so we don't need to duplicate it for
7183 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7184 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7185 add_symbol_to_list (typedef_sym
, list_to_add
);
7189 case DW_TAG_typedef
:
7190 if (processing_has_namespace_info
7191 && processing_current_prefix
[0] != '\0')
7193 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7194 processing_current_prefix
,
7197 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7198 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7199 add_symbol_to_list (sym
, cu
->list_in_scope
);
7201 case DW_TAG_base_type
:
7202 case DW_TAG_subrange_type
:
7203 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7204 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7205 add_symbol_to_list (sym
, cu
->list_in_scope
);
7207 case DW_TAG_enumerator
:
7208 if (processing_has_namespace_info
7209 && processing_current_prefix
[0] != '\0')
7211 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
7212 processing_current_prefix
,
7215 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7218 dwarf2_const_value (attr
, sym
, cu
);
7221 /* NOTE: carlton/2003-11-10: See comment above in the
7222 DW_TAG_class_type, etc. block. */
7224 struct pending
**list_to_add
;
7226 list_to_add
= (cu
->list_in_scope
== &file_symbols
7227 && (cu
->language
== language_cplus
7228 || cu
->language
== language_java
)
7229 ? &global_symbols
: cu
->list_in_scope
);
7231 add_symbol_to_list (sym
, list_to_add
);
7234 case DW_TAG_namespace
:
7235 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7236 add_symbol_to_list (sym
, &global_symbols
);
7239 /* Not a tag we recognize. Hopefully we aren't processing
7240 trash data, but since we must specifically ignore things
7241 we don't recognize, there is nothing else we should do at
7243 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7244 dwarf_tag_name (die
->tag
));
7251 /* Copy constant value from an attribute to a symbol. */
7254 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7255 struct dwarf2_cu
*cu
)
7257 struct objfile
*objfile
= cu
->objfile
;
7258 struct comp_unit_head
*cu_header
= &cu
->header
;
7259 struct dwarf_block
*blk
;
7264 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
7265 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7266 cu_header
->addr_size
,
7267 TYPE_LENGTH (SYMBOL_TYPE
7269 SYMBOL_VALUE_BYTES (sym
) =
7270 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
7271 /* NOTE: cagney/2003-05-09: In-lined store_address call with
7272 it's body - store_unsigned_integer. */
7273 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
7275 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7277 case DW_FORM_block1
:
7278 case DW_FORM_block2
:
7279 case DW_FORM_block4
:
7281 blk
= DW_BLOCK (attr
);
7282 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
7283 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
7285 TYPE_LENGTH (SYMBOL_TYPE
7287 SYMBOL_VALUE_BYTES (sym
) =
7288 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
7289 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
7290 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
7293 /* The DW_AT_const_value attributes are supposed to carry the
7294 symbol's value "represented as it would be on the target
7295 architecture." By the time we get here, it's already been
7296 converted to host endianness, so we just need to sign- or
7297 zero-extend it as appropriate. */
7299 dwarf2_const_value_data (attr
, sym
, 8);
7302 dwarf2_const_value_data (attr
, sym
, 16);
7305 dwarf2_const_value_data (attr
, sym
, 32);
7308 dwarf2_const_value_data (attr
, sym
, 64);
7312 SYMBOL_VALUE (sym
) = DW_SND (attr
);
7313 SYMBOL_CLASS (sym
) = LOC_CONST
;
7317 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
7318 SYMBOL_CLASS (sym
) = LOC_CONST
;
7322 complaint (&symfile_complaints
,
7323 _("unsupported const value attribute form: '%s'"),
7324 dwarf_form_name (attr
->form
));
7325 SYMBOL_VALUE (sym
) = 0;
7326 SYMBOL_CLASS (sym
) = LOC_CONST
;
7332 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
7333 or zero-extend it as appropriate for the symbol's type. */
7335 dwarf2_const_value_data (struct attribute
*attr
,
7339 LONGEST l
= DW_UNSND (attr
);
7341 if (bits
< sizeof (l
) * 8)
7343 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
7344 l
&= ((LONGEST
) 1 << bits
) - 1;
7346 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
7349 SYMBOL_VALUE (sym
) = l
;
7350 SYMBOL_CLASS (sym
) = LOC_CONST
;
7354 /* Return the type of the die in question using its DW_AT_type attribute. */
7356 static struct type
*
7357 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7360 struct attribute
*type_attr
;
7361 struct die_info
*type_die
;
7363 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
7366 /* A missing DW_AT_type represents a void type. */
7367 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
7370 type_die
= follow_die_ref (die
, type_attr
, cu
);
7372 type
= tag_type_to_type (type_die
, cu
);
7375 dump_die (type_die
);
7376 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
7382 /* Return the containing type of the die in question using its
7383 DW_AT_containing_type attribute. */
7385 static struct type
*
7386 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7388 struct type
*type
= NULL
;
7389 struct attribute
*type_attr
;
7390 struct die_info
*type_die
= NULL
;
7392 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
7395 type_die
= follow_die_ref (die
, type_attr
, cu
);
7396 type
= tag_type_to_type (type_die
, cu
);
7401 dump_die (type_die
);
7402 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
7408 static struct type
*
7409 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7417 read_type_die (die
, cu
);
7421 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
7429 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7431 char *prefix
= determine_prefix (die
, cu
);
7432 const char *old_prefix
= processing_current_prefix
;
7433 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
7434 processing_current_prefix
= prefix
;
7438 case DW_TAG_class_type
:
7439 case DW_TAG_structure_type
:
7440 case DW_TAG_union_type
:
7441 read_structure_type (die
, cu
);
7443 case DW_TAG_enumeration_type
:
7444 read_enumeration_type (die
, cu
);
7446 case DW_TAG_subprogram
:
7447 case DW_TAG_subroutine_type
:
7448 read_subroutine_type (die
, cu
);
7450 case DW_TAG_array_type
:
7451 read_array_type (die
, cu
);
7453 case DW_TAG_set_type
:
7454 read_set_type (die
, cu
);
7456 case DW_TAG_pointer_type
:
7457 read_tag_pointer_type (die
, cu
);
7459 case DW_TAG_ptr_to_member_type
:
7460 read_tag_ptr_to_member_type (die
, cu
);
7462 case DW_TAG_reference_type
:
7463 read_tag_reference_type (die
, cu
);
7465 case DW_TAG_const_type
:
7466 read_tag_const_type (die
, cu
);
7468 case DW_TAG_volatile_type
:
7469 read_tag_volatile_type (die
, cu
);
7471 case DW_TAG_string_type
:
7472 read_tag_string_type (die
, cu
);
7474 case DW_TAG_typedef
:
7475 read_typedef (die
, cu
);
7477 case DW_TAG_subrange_type
:
7478 read_subrange_type (die
, cu
);
7480 case DW_TAG_base_type
:
7481 read_base_type (die
, cu
);
7483 case DW_TAG_unspecified_type
:
7484 read_unspecified_type (die
, cu
);
7487 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
7488 dwarf_tag_name (die
->tag
));
7492 processing_current_prefix
= old_prefix
;
7493 do_cleanups (back_to
);
7496 /* Return the name of the namespace/class that DIE is defined within,
7497 or "" if we can't tell. The caller should xfree the result. */
7499 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7500 therein) for an example of how to use this function to deal with
7501 DW_AT_specification. */
7504 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7506 struct die_info
*parent
;
7508 if (cu
->language
!= language_cplus
7509 && cu
->language
!= language_java
)
7512 parent
= die
->parent
;
7516 return xstrdup ("");
7520 switch (parent
->tag
) {
7521 case DW_TAG_namespace
:
7523 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7524 before doing this check? */
7525 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
7527 return xstrdup (TYPE_TAG_NAME (parent
->type
));
7532 char *parent_prefix
= determine_prefix (parent
, cu
);
7533 char *retval
= typename_concat (NULL
, parent_prefix
,
7534 namespace_name (parent
, &dummy
,
7537 xfree (parent_prefix
);
7542 case DW_TAG_class_type
:
7543 case DW_TAG_structure_type
:
7545 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
7547 return xstrdup (TYPE_TAG_NAME (parent
->type
));
7551 const char *old_prefix
= processing_current_prefix
;
7552 char *new_prefix
= determine_prefix (parent
, cu
);
7555 processing_current_prefix
= new_prefix
;
7556 retval
= determine_class_name (parent
, cu
);
7557 processing_current_prefix
= old_prefix
;
7564 return determine_prefix (parent
, cu
);
7569 /* Return a newly-allocated string formed by concatenating PREFIX and
7570 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7571 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7572 perform an obconcat, otherwise allocate storage for the result. The CU argument
7573 is used to determine the language and hence, the appropriate separator. */
7575 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7578 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7579 struct dwarf2_cu
*cu
)
7583 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7585 else if (cu
->language
== language_java
)
7592 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7597 strcpy (retval
, prefix
);
7598 strcat (retval
, sep
);
7601 strcat (retval
, suffix
);
7607 /* We have an obstack. */
7608 return obconcat (obs
, prefix
, sep
, suffix
);
7612 static struct type
*
7613 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
7615 struct objfile
*objfile
= cu
->objfile
;
7617 /* FIXME - this should not produce a new (struct type *)
7618 every time. It should cache base types. */
7622 case DW_ATE_address
:
7623 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
7625 case DW_ATE_boolean
:
7626 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
7628 case DW_ATE_complex_float
:
7631 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
7635 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
7641 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
7645 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
7652 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
7655 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
7659 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
7663 case DW_ATE_signed_char
:
7664 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
7666 case DW_ATE_unsigned
:
7670 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
7673 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
7677 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
7681 case DW_ATE_unsigned_char
:
7682 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
7685 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
7692 copy_die (struct die_info
*old_die
)
7694 struct die_info
*new_die
;
7697 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7698 memset (new_die
, 0, sizeof (struct die_info
));
7700 new_die
->tag
= old_die
->tag
;
7701 new_die
->has_children
= old_die
->has_children
;
7702 new_die
->abbrev
= old_die
->abbrev
;
7703 new_die
->offset
= old_die
->offset
;
7704 new_die
->type
= NULL
;
7706 num_attrs
= old_die
->num_attrs
;
7707 new_die
->num_attrs
= num_attrs
;
7708 new_die
->attrs
= (struct attribute
*)
7709 xmalloc (num_attrs
* sizeof (struct attribute
));
7711 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
7713 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
7714 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
7715 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
7718 new_die
->next
= NULL
;
7723 /* Return sibling of die, NULL if no sibling. */
7725 static struct die_info
*
7726 sibling_die (struct die_info
*die
)
7728 return die
->sibling
;
7731 /* Get linkage name of a die, return NULL if not found. */
7734 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7736 struct attribute
*attr
;
7738 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7739 if (attr
&& DW_STRING (attr
))
7740 return DW_STRING (attr
);
7741 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7742 if (attr
&& DW_STRING (attr
))
7743 return DW_STRING (attr
);
7747 /* Get name of a die, return NULL if not found. */
7750 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7752 struct attribute
*attr
;
7754 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7755 if (attr
&& DW_STRING (attr
))
7756 return DW_STRING (attr
);
7760 /* Return the die that this die in an extension of, or NULL if there
7763 static struct die_info
*
7764 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
7766 struct attribute
*attr
;
7768 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
7772 return follow_die_ref (die
, attr
, cu
);
7775 /* Convert a DIE tag into its string name. */
7778 dwarf_tag_name (unsigned tag
)
7782 case DW_TAG_padding
:
7783 return "DW_TAG_padding";
7784 case DW_TAG_array_type
:
7785 return "DW_TAG_array_type";
7786 case DW_TAG_class_type
:
7787 return "DW_TAG_class_type";
7788 case DW_TAG_entry_point
:
7789 return "DW_TAG_entry_point";
7790 case DW_TAG_enumeration_type
:
7791 return "DW_TAG_enumeration_type";
7792 case DW_TAG_formal_parameter
:
7793 return "DW_TAG_formal_parameter";
7794 case DW_TAG_imported_declaration
:
7795 return "DW_TAG_imported_declaration";
7797 return "DW_TAG_label";
7798 case DW_TAG_lexical_block
:
7799 return "DW_TAG_lexical_block";
7801 return "DW_TAG_member";
7802 case DW_TAG_pointer_type
:
7803 return "DW_TAG_pointer_type";
7804 case DW_TAG_reference_type
:
7805 return "DW_TAG_reference_type";
7806 case DW_TAG_compile_unit
:
7807 return "DW_TAG_compile_unit";
7808 case DW_TAG_string_type
:
7809 return "DW_TAG_string_type";
7810 case DW_TAG_structure_type
:
7811 return "DW_TAG_structure_type";
7812 case DW_TAG_subroutine_type
:
7813 return "DW_TAG_subroutine_type";
7814 case DW_TAG_typedef
:
7815 return "DW_TAG_typedef";
7816 case DW_TAG_union_type
:
7817 return "DW_TAG_union_type";
7818 case DW_TAG_unspecified_parameters
:
7819 return "DW_TAG_unspecified_parameters";
7820 case DW_TAG_variant
:
7821 return "DW_TAG_variant";
7822 case DW_TAG_common_block
:
7823 return "DW_TAG_common_block";
7824 case DW_TAG_common_inclusion
:
7825 return "DW_TAG_common_inclusion";
7826 case DW_TAG_inheritance
:
7827 return "DW_TAG_inheritance";
7828 case DW_TAG_inlined_subroutine
:
7829 return "DW_TAG_inlined_subroutine";
7831 return "DW_TAG_module";
7832 case DW_TAG_ptr_to_member_type
:
7833 return "DW_TAG_ptr_to_member_type";
7834 case DW_TAG_set_type
:
7835 return "DW_TAG_set_type";
7836 case DW_TAG_subrange_type
:
7837 return "DW_TAG_subrange_type";
7838 case DW_TAG_with_stmt
:
7839 return "DW_TAG_with_stmt";
7840 case DW_TAG_access_declaration
:
7841 return "DW_TAG_access_declaration";
7842 case DW_TAG_base_type
:
7843 return "DW_TAG_base_type";
7844 case DW_TAG_catch_block
:
7845 return "DW_TAG_catch_block";
7846 case DW_TAG_const_type
:
7847 return "DW_TAG_const_type";
7848 case DW_TAG_constant
:
7849 return "DW_TAG_constant";
7850 case DW_TAG_enumerator
:
7851 return "DW_TAG_enumerator";
7852 case DW_TAG_file_type
:
7853 return "DW_TAG_file_type";
7855 return "DW_TAG_friend";
7856 case DW_TAG_namelist
:
7857 return "DW_TAG_namelist";
7858 case DW_TAG_namelist_item
:
7859 return "DW_TAG_namelist_item";
7860 case DW_TAG_packed_type
:
7861 return "DW_TAG_packed_type";
7862 case DW_TAG_subprogram
:
7863 return "DW_TAG_subprogram";
7864 case DW_TAG_template_type_param
:
7865 return "DW_TAG_template_type_param";
7866 case DW_TAG_template_value_param
:
7867 return "DW_TAG_template_value_param";
7868 case DW_TAG_thrown_type
:
7869 return "DW_TAG_thrown_type";
7870 case DW_TAG_try_block
:
7871 return "DW_TAG_try_block";
7872 case DW_TAG_variant_part
:
7873 return "DW_TAG_variant_part";
7874 case DW_TAG_variable
:
7875 return "DW_TAG_variable";
7876 case DW_TAG_volatile_type
:
7877 return "DW_TAG_volatile_type";
7878 case DW_TAG_dwarf_procedure
:
7879 return "DW_TAG_dwarf_procedure";
7880 case DW_TAG_restrict_type
:
7881 return "DW_TAG_restrict_type";
7882 case DW_TAG_interface_type
:
7883 return "DW_TAG_interface_type";
7884 case DW_TAG_namespace
:
7885 return "DW_TAG_namespace";
7886 case DW_TAG_imported_module
:
7887 return "DW_TAG_imported_module";
7888 case DW_TAG_unspecified_type
:
7889 return "DW_TAG_unspecified_type";
7890 case DW_TAG_partial_unit
:
7891 return "DW_TAG_partial_unit";
7892 case DW_TAG_imported_unit
:
7893 return "DW_TAG_imported_unit";
7894 case DW_TAG_condition
:
7895 return "DW_TAG_condition";
7896 case DW_TAG_shared_type
:
7897 return "DW_TAG_shared_type";
7898 case DW_TAG_MIPS_loop
:
7899 return "DW_TAG_MIPS_loop";
7900 case DW_TAG_HP_array_descriptor
:
7901 return "DW_TAG_HP_array_descriptor";
7902 case DW_TAG_format_label
:
7903 return "DW_TAG_format_label";
7904 case DW_TAG_function_template
:
7905 return "DW_TAG_function_template";
7906 case DW_TAG_class_template
:
7907 return "DW_TAG_class_template";
7908 case DW_TAG_GNU_BINCL
:
7909 return "DW_TAG_GNU_BINCL";
7910 case DW_TAG_GNU_EINCL
:
7911 return "DW_TAG_GNU_EINCL";
7912 case DW_TAG_upc_shared_type
:
7913 return "DW_TAG_upc_shared_type";
7914 case DW_TAG_upc_strict_type
:
7915 return "DW_TAG_upc_strict_type";
7916 case DW_TAG_upc_relaxed_type
:
7917 return "DW_TAG_upc_relaxed_type";
7918 case DW_TAG_PGI_kanji_type
:
7919 return "DW_TAG_PGI_kanji_type";
7920 case DW_TAG_PGI_interface_block
:
7921 return "DW_TAG_PGI_interface_block";
7923 return "DW_TAG_<unknown>";
7927 /* Convert a DWARF attribute code into its string name. */
7930 dwarf_attr_name (unsigned attr
)
7935 return "DW_AT_sibling";
7936 case DW_AT_location
:
7937 return "DW_AT_location";
7939 return "DW_AT_name";
7940 case DW_AT_ordering
:
7941 return "DW_AT_ordering";
7942 case DW_AT_subscr_data
:
7943 return "DW_AT_subscr_data";
7944 case DW_AT_byte_size
:
7945 return "DW_AT_byte_size";
7946 case DW_AT_bit_offset
:
7947 return "DW_AT_bit_offset";
7948 case DW_AT_bit_size
:
7949 return "DW_AT_bit_size";
7950 case DW_AT_element_list
:
7951 return "DW_AT_element_list";
7952 case DW_AT_stmt_list
:
7953 return "DW_AT_stmt_list";
7955 return "DW_AT_low_pc";
7957 return "DW_AT_high_pc";
7958 case DW_AT_language
:
7959 return "DW_AT_language";
7961 return "DW_AT_member";
7963 return "DW_AT_discr";
7964 case DW_AT_discr_value
:
7965 return "DW_AT_discr_value";
7966 case DW_AT_visibility
:
7967 return "DW_AT_visibility";
7969 return "DW_AT_import";
7970 case DW_AT_string_length
:
7971 return "DW_AT_string_length";
7972 case DW_AT_common_reference
:
7973 return "DW_AT_common_reference";
7974 case DW_AT_comp_dir
:
7975 return "DW_AT_comp_dir";
7976 case DW_AT_const_value
:
7977 return "DW_AT_const_value";
7978 case DW_AT_containing_type
:
7979 return "DW_AT_containing_type";
7980 case DW_AT_default_value
:
7981 return "DW_AT_default_value";
7983 return "DW_AT_inline";
7984 case DW_AT_is_optional
:
7985 return "DW_AT_is_optional";
7986 case DW_AT_lower_bound
:
7987 return "DW_AT_lower_bound";
7988 case DW_AT_producer
:
7989 return "DW_AT_producer";
7990 case DW_AT_prototyped
:
7991 return "DW_AT_prototyped";
7992 case DW_AT_return_addr
:
7993 return "DW_AT_return_addr";
7994 case DW_AT_start_scope
:
7995 return "DW_AT_start_scope";
7996 case DW_AT_stride_size
:
7997 return "DW_AT_stride_size";
7998 case DW_AT_upper_bound
:
7999 return "DW_AT_upper_bound";
8000 case DW_AT_abstract_origin
:
8001 return "DW_AT_abstract_origin";
8002 case DW_AT_accessibility
:
8003 return "DW_AT_accessibility";
8004 case DW_AT_address_class
:
8005 return "DW_AT_address_class";
8006 case DW_AT_artificial
:
8007 return "DW_AT_artificial";
8008 case DW_AT_base_types
:
8009 return "DW_AT_base_types";
8010 case DW_AT_calling_convention
:
8011 return "DW_AT_calling_convention";
8013 return "DW_AT_count";
8014 case DW_AT_data_member_location
:
8015 return "DW_AT_data_member_location";
8016 case DW_AT_decl_column
:
8017 return "DW_AT_decl_column";
8018 case DW_AT_decl_file
:
8019 return "DW_AT_decl_file";
8020 case DW_AT_decl_line
:
8021 return "DW_AT_decl_line";
8022 case DW_AT_declaration
:
8023 return "DW_AT_declaration";
8024 case DW_AT_discr_list
:
8025 return "DW_AT_discr_list";
8026 case DW_AT_encoding
:
8027 return "DW_AT_encoding";
8028 case DW_AT_external
:
8029 return "DW_AT_external";
8030 case DW_AT_frame_base
:
8031 return "DW_AT_frame_base";
8033 return "DW_AT_friend";
8034 case DW_AT_identifier_case
:
8035 return "DW_AT_identifier_case";
8036 case DW_AT_macro_info
:
8037 return "DW_AT_macro_info";
8038 case DW_AT_namelist_items
:
8039 return "DW_AT_namelist_items";
8040 case DW_AT_priority
:
8041 return "DW_AT_priority";
8043 return "DW_AT_segment";
8044 case DW_AT_specification
:
8045 return "DW_AT_specification";
8046 case DW_AT_static_link
:
8047 return "DW_AT_static_link";
8049 return "DW_AT_type";
8050 case DW_AT_use_location
:
8051 return "DW_AT_use_location";
8052 case DW_AT_variable_parameter
:
8053 return "DW_AT_variable_parameter";
8054 case DW_AT_virtuality
:
8055 return "DW_AT_virtuality";
8056 case DW_AT_vtable_elem_location
:
8057 return "DW_AT_vtable_elem_location";
8058 /* DWARF 3 values. */
8059 case DW_AT_allocated
:
8060 return "DW_AT_allocated";
8061 case DW_AT_associated
:
8062 return "DW_AT_associated";
8063 case DW_AT_data_location
:
8064 return "DW_AT_data_location";
8066 return "DW_AT_stride";
8067 case DW_AT_entry_pc
:
8068 return "DW_AT_entry_pc";
8069 case DW_AT_use_UTF8
:
8070 return "DW_AT_use_UTF8";
8071 case DW_AT_extension
:
8072 return "DW_AT_extension";
8074 return "DW_AT_ranges";
8075 case DW_AT_trampoline
:
8076 return "DW_AT_trampoline";
8077 case DW_AT_call_column
:
8078 return "DW_AT_call_column";
8079 case DW_AT_call_file
:
8080 return "DW_AT_call_file";
8081 case DW_AT_call_line
:
8082 return "DW_AT_call_line";
8083 case DW_AT_description
:
8084 return "DW_AT_description";
8085 case DW_AT_binary_scale
:
8086 return "DW_AT_binary_scale";
8087 case DW_AT_decimal_scale
:
8088 return "DW_AT_decimal_scale";
8090 return "DW_AT_small";
8091 case DW_AT_decimal_sign
:
8092 return "DW_AT_decimal_sign";
8093 case DW_AT_digit_count
:
8094 return "DW_AT_digit_count";
8095 case DW_AT_picture_string
:
8096 return "DW_AT_picture_string";
8098 return "DW_AT_mutable";
8099 case DW_AT_threads_scaled
:
8100 return "DW_AT_threads_scaled";
8101 case DW_AT_explicit
:
8102 return "DW_AT_explicit";
8103 case DW_AT_object_pointer
:
8104 return "DW_AT_object_pointer";
8105 case DW_AT_endianity
:
8106 return "DW_AT_endianity";
8107 case DW_AT_elemental
:
8108 return "DW_AT_elemental";
8110 return "DW_AT_pure";
8111 case DW_AT_recursive
:
8112 return "DW_AT_recursive";
8114 /* SGI/MIPS extensions. */
8115 case DW_AT_MIPS_fde
:
8116 return "DW_AT_MIPS_fde";
8117 case DW_AT_MIPS_loop_begin
:
8118 return "DW_AT_MIPS_loop_begin";
8119 case DW_AT_MIPS_tail_loop_begin
:
8120 return "DW_AT_MIPS_tail_loop_begin";
8121 case DW_AT_MIPS_epilog_begin
:
8122 return "DW_AT_MIPS_epilog_begin";
8123 case DW_AT_MIPS_loop_unroll_factor
:
8124 return "DW_AT_MIPS_loop_unroll_factor";
8125 case DW_AT_MIPS_software_pipeline_depth
:
8126 return "DW_AT_MIPS_software_pipeline_depth";
8127 case DW_AT_MIPS_linkage_name
:
8128 return "DW_AT_MIPS_linkage_name";
8129 case DW_AT_MIPS_stride
:
8130 return "DW_AT_MIPS_stride";
8131 case DW_AT_MIPS_abstract_name
:
8132 return "DW_AT_MIPS_abstract_name";
8133 case DW_AT_MIPS_clone_origin
:
8134 return "DW_AT_MIPS_clone_origin";
8135 case DW_AT_MIPS_has_inlines
:
8136 return "DW_AT_MIPS_has_inlines";
8138 /* HP extensions. */
8139 case DW_AT_HP_block_index
:
8140 return "DW_AT_HP_block_index";
8141 case DW_AT_HP_unmodifiable
:
8142 return "DW_AT_HP_unmodifiable";
8143 case DW_AT_HP_actuals_stmt_list
:
8144 return "DW_AT_HP_actuals_stmt_list";
8145 case DW_AT_HP_proc_per_section
:
8146 return "DW_AT_HP_proc_per_section";
8147 case DW_AT_HP_raw_data_ptr
:
8148 return "DW_AT_HP_raw_data_ptr";
8149 case DW_AT_HP_pass_by_reference
:
8150 return "DW_AT_HP_pass_by_reference";
8151 case DW_AT_HP_opt_level
:
8152 return "DW_AT_HP_opt_level";
8153 case DW_AT_HP_prof_version_id
:
8154 return "DW_AT_HP_prof_version_id";
8155 case DW_AT_HP_opt_flags
:
8156 return "DW_AT_HP_opt_flags";
8157 case DW_AT_HP_cold_region_low_pc
:
8158 return "DW_AT_HP_cold_region_low_pc";
8159 case DW_AT_HP_cold_region_high_pc
:
8160 return "DW_AT_HP_cold_region_high_pc";
8161 case DW_AT_HP_all_variables_modifiable
:
8162 return "DW_AT_HP_all_variables_modifiable";
8163 case DW_AT_HP_linkage_name
:
8164 return "DW_AT_HP_linkage_name";
8165 case DW_AT_HP_prof_flags
:
8166 return "DW_AT_HP_prof_flags";
8167 /* GNU extensions. */
8168 case DW_AT_sf_names
:
8169 return "DW_AT_sf_names";
8170 case DW_AT_src_info
:
8171 return "DW_AT_src_info";
8172 case DW_AT_mac_info
:
8173 return "DW_AT_mac_info";
8174 case DW_AT_src_coords
:
8175 return "DW_AT_src_coords";
8176 case DW_AT_body_begin
:
8177 return "DW_AT_body_begin";
8178 case DW_AT_body_end
:
8179 return "DW_AT_body_end";
8180 case DW_AT_GNU_vector
:
8181 return "DW_AT_GNU_vector";
8182 /* VMS extensions. */
8183 case DW_AT_VMS_rtnbeg_pd_address
:
8184 return "DW_AT_VMS_rtnbeg_pd_address";
8185 /* UPC extension. */
8186 case DW_AT_upc_threads_scaled
:
8187 return "DW_AT_upc_threads_scaled";
8188 /* PGI (STMicroelectronics) extensions. */
8189 case DW_AT_PGI_lbase
:
8190 return "DW_AT_PGI_lbase";
8191 case DW_AT_PGI_soffset
:
8192 return "DW_AT_PGI_soffset";
8193 case DW_AT_PGI_lstride
:
8194 return "DW_AT_PGI_lstride";
8196 return "DW_AT_<unknown>";
8200 /* Convert a DWARF value form code into its string name. */
8203 dwarf_form_name (unsigned form
)
8208 return "DW_FORM_addr";
8209 case DW_FORM_block2
:
8210 return "DW_FORM_block2";
8211 case DW_FORM_block4
:
8212 return "DW_FORM_block4";
8214 return "DW_FORM_data2";
8216 return "DW_FORM_data4";
8218 return "DW_FORM_data8";
8219 case DW_FORM_string
:
8220 return "DW_FORM_string";
8222 return "DW_FORM_block";
8223 case DW_FORM_block1
:
8224 return "DW_FORM_block1";
8226 return "DW_FORM_data1";
8228 return "DW_FORM_flag";
8230 return "DW_FORM_sdata";
8232 return "DW_FORM_strp";
8234 return "DW_FORM_udata";
8235 case DW_FORM_ref_addr
:
8236 return "DW_FORM_ref_addr";
8238 return "DW_FORM_ref1";
8240 return "DW_FORM_ref2";
8242 return "DW_FORM_ref4";
8244 return "DW_FORM_ref8";
8245 case DW_FORM_ref_udata
:
8246 return "DW_FORM_ref_udata";
8247 case DW_FORM_indirect
:
8248 return "DW_FORM_indirect";
8250 return "DW_FORM_<unknown>";
8254 /* Convert a DWARF stack opcode into its string name. */
8257 dwarf_stack_op_name (unsigned op
)
8262 return "DW_OP_addr";
8264 return "DW_OP_deref";
8266 return "DW_OP_const1u";
8268 return "DW_OP_const1s";
8270 return "DW_OP_const2u";
8272 return "DW_OP_const2s";
8274 return "DW_OP_const4u";
8276 return "DW_OP_const4s";
8278 return "DW_OP_const8u";
8280 return "DW_OP_const8s";
8282 return "DW_OP_constu";
8284 return "DW_OP_consts";
8288 return "DW_OP_drop";
8290 return "DW_OP_over";
8292 return "DW_OP_pick";
8294 return "DW_OP_swap";
8298 return "DW_OP_xderef";
8306 return "DW_OP_minus";
8318 return "DW_OP_plus";
8319 case DW_OP_plus_uconst
:
8320 return "DW_OP_plus_uconst";
8326 return "DW_OP_shra";
8344 return "DW_OP_skip";
8346 return "DW_OP_lit0";
8348 return "DW_OP_lit1";
8350 return "DW_OP_lit2";
8352 return "DW_OP_lit3";
8354 return "DW_OP_lit4";
8356 return "DW_OP_lit5";
8358 return "DW_OP_lit6";
8360 return "DW_OP_lit7";
8362 return "DW_OP_lit8";
8364 return "DW_OP_lit9";
8366 return "DW_OP_lit10";
8368 return "DW_OP_lit11";
8370 return "DW_OP_lit12";
8372 return "DW_OP_lit13";
8374 return "DW_OP_lit14";
8376 return "DW_OP_lit15";
8378 return "DW_OP_lit16";
8380 return "DW_OP_lit17";
8382 return "DW_OP_lit18";
8384 return "DW_OP_lit19";
8386 return "DW_OP_lit20";
8388 return "DW_OP_lit21";
8390 return "DW_OP_lit22";
8392 return "DW_OP_lit23";
8394 return "DW_OP_lit24";
8396 return "DW_OP_lit25";
8398 return "DW_OP_lit26";
8400 return "DW_OP_lit27";
8402 return "DW_OP_lit28";
8404 return "DW_OP_lit29";
8406 return "DW_OP_lit30";
8408 return "DW_OP_lit31";
8410 return "DW_OP_reg0";
8412 return "DW_OP_reg1";
8414 return "DW_OP_reg2";
8416 return "DW_OP_reg3";
8418 return "DW_OP_reg4";
8420 return "DW_OP_reg5";
8422 return "DW_OP_reg6";
8424 return "DW_OP_reg7";
8426 return "DW_OP_reg8";
8428 return "DW_OP_reg9";
8430 return "DW_OP_reg10";
8432 return "DW_OP_reg11";
8434 return "DW_OP_reg12";
8436 return "DW_OP_reg13";
8438 return "DW_OP_reg14";
8440 return "DW_OP_reg15";
8442 return "DW_OP_reg16";
8444 return "DW_OP_reg17";
8446 return "DW_OP_reg18";
8448 return "DW_OP_reg19";
8450 return "DW_OP_reg20";
8452 return "DW_OP_reg21";
8454 return "DW_OP_reg22";
8456 return "DW_OP_reg23";
8458 return "DW_OP_reg24";
8460 return "DW_OP_reg25";
8462 return "DW_OP_reg26";
8464 return "DW_OP_reg27";
8466 return "DW_OP_reg28";
8468 return "DW_OP_reg29";
8470 return "DW_OP_reg30";
8472 return "DW_OP_reg31";
8474 return "DW_OP_breg0";
8476 return "DW_OP_breg1";
8478 return "DW_OP_breg2";
8480 return "DW_OP_breg3";
8482 return "DW_OP_breg4";
8484 return "DW_OP_breg5";
8486 return "DW_OP_breg6";
8488 return "DW_OP_breg7";
8490 return "DW_OP_breg8";
8492 return "DW_OP_breg9";
8494 return "DW_OP_breg10";
8496 return "DW_OP_breg11";
8498 return "DW_OP_breg12";
8500 return "DW_OP_breg13";
8502 return "DW_OP_breg14";
8504 return "DW_OP_breg15";
8506 return "DW_OP_breg16";
8508 return "DW_OP_breg17";
8510 return "DW_OP_breg18";
8512 return "DW_OP_breg19";
8514 return "DW_OP_breg20";
8516 return "DW_OP_breg21";
8518 return "DW_OP_breg22";
8520 return "DW_OP_breg23";
8522 return "DW_OP_breg24";
8524 return "DW_OP_breg25";
8526 return "DW_OP_breg26";
8528 return "DW_OP_breg27";
8530 return "DW_OP_breg28";
8532 return "DW_OP_breg29";
8534 return "DW_OP_breg30";
8536 return "DW_OP_breg31";
8538 return "DW_OP_regx";
8540 return "DW_OP_fbreg";
8542 return "DW_OP_bregx";
8544 return "DW_OP_piece";
8545 case DW_OP_deref_size
:
8546 return "DW_OP_deref_size";
8547 case DW_OP_xderef_size
:
8548 return "DW_OP_xderef_size";
8551 /* DWARF 3 extensions. */
8552 case DW_OP_push_object_address
:
8553 return "DW_OP_push_object_address";
8555 return "DW_OP_call2";
8557 return "DW_OP_call4";
8558 case DW_OP_call_ref
:
8559 return "DW_OP_call_ref";
8560 /* GNU extensions. */
8561 case DW_OP_form_tls_address
:
8562 return "DW_OP_form_tls_address";
8563 case DW_OP_call_frame_cfa
:
8564 return "DW_OP_call_frame_cfa";
8565 case DW_OP_bit_piece
:
8566 return "DW_OP_bit_piece";
8567 case DW_OP_GNU_push_tls_address
:
8568 return "DW_OP_GNU_push_tls_address";
8569 /* HP extensions. */
8570 case DW_OP_HP_is_value
:
8571 return "DW_OP_HP_is_value";
8572 case DW_OP_HP_fltconst4
:
8573 return "DW_OP_HP_fltconst4";
8574 case DW_OP_HP_fltconst8
:
8575 return "DW_OP_HP_fltconst8";
8576 case DW_OP_HP_mod_range
:
8577 return "DW_OP_HP_mod_range";
8578 case DW_OP_HP_unmod_range
:
8579 return "DW_OP_HP_unmod_range";
8581 return "DW_OP_HP_tls";
8583 return "OP_<unknown>";
8588 dwarf_bool_name (unsigned mybool
)
8596 /* Convert a DWARF type code into its string name. */
8599 dwarf_type_encoding_name (unsigned enc
)
8604 return "DW_ATE_void";
8605 case DW_ATE_address
:
8606 return "DW_ATE_address";
8607 case DW_ATE_boolean
:
8608 return "DW_ATE_boolean";
8609 case DW_ATE_complex_float
:
8610 return "DW_ATE_complex_float";
8612 return "DW_ATE_float";
8614 return "DW_ATE_signed";
8615 case DW_ATE_signed_char
:
8616 return "DW_ATE_signed_char";
8617 case DW_ATE_unsigned
:
8618 return "DW_ATE_unsigned";
8619 case DW_ATE_unsigned_char
:
8620 return "DW_ATE_unsigned_char";
8622 case DW_ATE_imaginary_float
:
8623 return "DW_ATE_imaginary_float";
8624 case DW_ATE_packed_decimal
:
8625 return "DW_ATE_packed_decimal";
8626 case DW_ATE_numeric_string
:
8627 return "DW_ATE_numeric_string";
8629 return "DW_ATE_edited";
8630 case DW_ATE_signed_fixed
:
8631 return "DW_ATE_signed_fixed";
8632 case DW_ATE_unsigned_fixed
:
8633 return "DW_ATE_unsigned_fixed";
8634 case DW_ATE_decimal_float
:
8635 return "DW_ATE_decimal_float";
8636 /* HP extensions. */
8637 case DW_ATE_HP_float80
:
8638 return "DW_ATE_HP_float80";
8639 case DW_ATE_HP_complex_float80
:
8640 return "DW_ATE_HP_complex_float80";
8641 case DW_ATE_HP_float128
:
8642 return "DW_ATE_HP_float128";
8643 case DW_ATE_HP_complex_float128
:
8644 return "DW_ATE_HP_complex_float128";
8645 case DW_ATE_HP_floathpintel
:
8646 return "DW_ATE_HP_floathpintel";
8647 case DW_ATE_HP_imaginary_float80
:
8648 return "DW_ATE_HP_imaginary_float80";
8649 case DW_ATE_HP_imaginary_float128
:
8650 return "DW_ATE_HP_imaginary_float128";
8652 return "DW_ATE_<unknown>";
8656 /* Convert a DWARF call frame info operation to its string name. */
8660 dwarf_cfi_name (unsigned cfi_opc
)
8664 case DW_CFA_advance_loc
:
8665 return "DW_CFA_advance_loc";
8667 return "DW_CFA_offset";
8668 case DW_CFA_restore
:
8669 return "DW_CFA_restore";
8671 return "DW_CFA_nop";
8672 case DW_CFA_set_loc
:
8673 return "DW_CFA_set_loc";
8674 case DW_CFA_advance_loc1
:
8675 return "DW_CFA_advance_loc1";
8676 case DW_CFA_advance_loc2
:
8677 return "DW_CFA_advance_loc2";
8678 case DW_CFA_advance_loc4
:
8679 return "DW_CFA_advance_loc4";
8680 case DW_CFA_offset_extended
:
8681 return "DW_CFA_offset_extended";
8682 case DW_CFA_restore_extended
:
8683 return "DW_CFA_restore_extended";
8684 case DW_CFA_undefined
:
8685 return "DW_CFA_undefined";
8686 case DW_CFA_same_value
:
8687 return "DW_CFA_same_value";
8688 case DW_CFA_register
:
8689 return "DW_CFA_register";
8690 case DW_CFA_remember_state
:
8691 return "DW_CFA_remember_state";
8692 case DW_CFA_restore_state
:
8693 return "DW_CFA_restore_state";
8694 case DW_CFA_def_cfa
:
8695 return "DW_CFA_def_cfa";
8696 case DW_CFA_def_cfa_register
:
8697 return "DW_CFA_def_cfa_register";
8698 case DW_CFA_def_cfa_offset
:
8699 return "DW_CFA_def_cfa_offset";
8701 case DW_CFA_def_cfa_expression
:
8702 return "DW_CFA_def_cfa_expression";
8703 case DW_CFA_expression
:
8704 return "DW_CFA_expression";
8705 case DW_CFA_offset_extended_sf
:
8706 return "DW_CFA_offset_extended_sf";
8707 case DW_CFA_def_cfa_sf
:
8708 return "DW_CFA_def_cfa_sf";
8709 case DW_CFA_def_cfa_offset_sf
:
8710 return "DW_CFA_def_cfa_offset_sf";
8711 case DW_CFA_val_offset
:
8712 return "DW_CFA_val_offset";
8713 case DW_CFA_val_offset_sf
:
8714 return "DW_CFA_val_offset_sf";
8715 case DW_CFA_val_expression
:
8716 return "DW_CFA_val_expression";
8717 /* SGI/MIPS specific. */
8718 case DW_CFA_MIPS_advance_loc8
:
8719 return "DW_CFA_MIPS_advance_loc8";
8720 /* GNU extensions. */
8721 case DW_CFA_GNU_window_save
:
8722 return "DW_CFA_GNU_window_save";
8723 case DW_CFA_GNU_args_size
:
8724 return "DW_CFA_GNU_args_size";
8725 case DW_CFA_GNU_negative_offset_extended
:
8726 return "DW_CFA_GNU_negative_offset_extended";
8728 return "DW_CFA_<unknown>";
8734 dump_die (struct die_info
*die
)
8738 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
8739 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
8740 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
8741 dwarf_bool_name (die
->child
!= NULL
));
8743 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
8744 for (i
= 0; i
< die
->num_attrs
; ++i
)
8746 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
8747 dwarf_attr_name (die
->attrs
[i
].name
),
8748 dwarf_form_name (die
->attrs
[i
].form
));
8749 switch (die
->attrs
[i
].form
)
8751 case DW_FORM_ref_addr
:
8753 fprintf_unfiltered (gdb_stderr
, "address: ");
8754 deprecated_print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
8756 case DW_FORM_block2
:
8757 case DW_FORM_block4
:
8759 case DW_FORM_block1
:
8760 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
8765 fprintf_unfiltered (gdb_stderr
, "constant ref: %ld (adjusted)",
8766 (long) (DW_ADDR (&die
->attrs
[i
])));
8774 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
8776 case DW_FORM_string
:
8778 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
8779 DW_STRING (&die
->attrs
[i
])
8780 ? DW_STRING (&die
->attrs
[i
]) : "");
8783 if (DW_UNSND (&die
->attrs
[i
]))
8784 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
8786 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
8788 case DW_FORM_indirect
:
8789 /* the reader will have reduced the indirect form to
8790 the "base form" so this form should not occur */
8791 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
8794 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
8795 die
->attrs
[i
].form
);
8797 fprintf_unfiltered (gdb_stderr
, "\n");
8802 dump_die_list (struct die_info
*die
)
8807 if (die
->child
!= NULL
)
8808 dump_die_list (die
->child
);
8809 if (die
->sibling
!= NULL
)
8810 dump_die_list (die
->sibling
);
8815 store_in_ref_table (unsigned int offset
, struct die_info
*die
,
8816 struct dwarf2_cu
*cu
)
8819 struct die_info
*old
;
8821 h
= (offset
% REF_HASH_SIZE
);
8822 old
= cu
->die_ref_table
[h
];
8823 die
->next_ref
= old
;
8824 cu
->die_ref_table
[h
] = die
;
8828 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
8830 unsigned int result
= 0;
8834 case DW_FORM_ref_addr
:
8839 case DW_FORM_ref_udata
:
8840 result
= DW_ADDR (attr
);
8843 complaint (&symfile_complaints
,
8844 _("unsupported die ref attribute form: '%s'"),
8845 dwarf_form_name (attr
->form
));
8850 /* Return the constant value held by the given attribute. Return -1
8851 if the value held by the attribute is not constant. */
8854 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
8856 if (attr
->form
== DW_FORM_sdata
)
8857 return DW_SND (attr
);
8858 else if (attr
->form
== DW_FORM_udata
8859 || attr
->form
== DW_FORM_data1
8860 || attr
->form
== DW_FORM_data2
8861 || attr
->form
== DW_FORM_data4
8862 || attr
->form
== DW_FORM_data8
)
8863 return DW_UNSND (attr
);
8866 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
8867 dwarf_form_name (attr
->form
));
8868 return default_value
;
8872 static struct die_info
*
8873 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
8874 struct dwarf2_cu
*cu
)
8876 struct die_info
*die
;
8877 unsigned int offset
;
8879 struct die_info temp_die
;
8880 struct dwarf2_cu
*target_cu
;
8882 offset
= dwarf2_get_ref_die_offset (attr
, cu
);
8884 if (DW_ADDR (attr
) < cu
->header
.offset
8885 || DW_ADDR (attr
) >= cu
->header
.offset
+ cu
->header
.length
)
8887 struct dwarf2_per_cu_data
*per_cu
;
8888 per_cu
= dwarf2_find_containing_comp_unit (DW_ADDR (attr
),
8890 target_cu
= per_cu
->cu
;
8895 h
= (offset
% REF_HASH_SIZE
);
8896 die
= target_cu
->die_ref_table
[h
];
8899 if (die
->offset
== offset
)
8901 die
= die
->next_ref
;
8904 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
8905 "at 0x%lx [in module %s]"),
8906 (long) src_die
->offset
, (long) offset
, cu
->objfile
->name
);
8911 static struct type
*
8912 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
8913 struct dwarf2_cu
*cu
)
8915 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
8917 error (_("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]"),
8918 typeid, objfile
->name
);
8921 /* Look for this particular type in the fundamental type vector. If
8922 one is not found, create and install one appropriate for the
8923 current language and the current target machine. */
8925 if (cu
->ftypes
[typeid] == NULL
)
8927 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
8930 return (cu
->ftypes
[typeid]);
8933 /* Decode simple location descriptions.
8934 Given a pointer to a dwarf block that defines a location, compute
8935 the location and return the value.
8937 NOTE drow/2003-11-18: This function is called in two situations
8938 now: for the address of static or global variables (partial symbols
8939 only) and for offsets into structures which are expected to be
8940 (more or less) constant. The partial symbol case should go away,
8941 and only the constant case should remain. That will let this
8942 function complain more accurately. A few special modes are allowed
8943 without complaint for global variables (for instance, global
8944 register values and thread-local values).
8946 A location description containing no operations indicates that the
8947 object is optimized out. The return value is 0 for that case.
8948 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8949 callers will only want a very basic result and this can become a
8952 Note that stack[0] is unused except as a default error return.
8953 Note that stack overflow is not yet handled. */
8956 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
8958 struct objfile
*objfile
= cu
->objfile
;
8959 struct comp_unit_head
*cu_header
= &cu
->header
;
8961 int size
= blk
->size
;
8962 gdb_byte
*data
= blk
->data
;
8963 CORE_ADDR stack
[64];
8965 unsigned int bytes_read
, unsnd
;
9009 stack
[++stacki
] = op
- DW_OP_lit0
;
9044 stack
[++stacki
] = op
- DW_OP_reg0
;
9046 dwarf2_complex_location_expr_complaint ();
9050 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9052 stack
[++stacki
] = unsnd
;
9054 dwarf2_complex_location_expr_complaint ();
9058 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9064 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9069 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9074 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9079 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9084 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9089 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9094 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9100 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9105 stack
[stacki
+ 1] = stack
[stacki
];
9110 stack
[stacki
- 1] += stack
[stacki
];
9114 case DW_OP_plus_uconst
:
9115 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9120 stack
[stacki
- 1] -= stack
[stacki
];
9125 /* If we're not the last op, then we definitely can't encode
9126 this using GDB's address_class enum. This is valid for partial
9127 global symbols, although the variable's address will be bogus
9130 dwarf2_complex_location_expr_complaint ();
9133 case DW_OP_GNU_push_tls_address
:
9134 /* The top of the stack has the offset from the beginning
9135 of the thread control block at which the variable is located. */
9136 /* Nothing should follow this operator, so the top of stack would
9138 /* This is valid for partial global symbols, but the variable's
9139 address will be bogus in the psymtab. */
9141 dwarf2_complex_location_expr_complaint ();
9145 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9146 dwarf_stack_op_name (op
));
9147 return (stack
[stacki
]);
9150 return (stack
[stacki
]);
9153 /* memory allocation interface */
9155 static struct dwarf_block
*
9156 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9158 struct dwarf_block
*blk
;
9160 blk
= (struct dwarf_block
*)
9161 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9165 static struct abbrev_info
*
9166 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9168 struct abbrev_info
*abbrev
;
9170 abbrev
= (struct abbrev_info
*)
9171 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9172 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9176 static struct die_info
*
9177 dwarf_alloc_die (void)
9179 struct die_info
*die
;
9181 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
9182 memset (die
, 0, sizeof (struct die_info
));
9187 /* Macro support. */
9190 /* Return the full name of file number I in *LH's file name table.
9191 Use COMP_DIR as the name of the current directory of the
9192 compilation. The result is allocated using xmalloc; the caller is
9193 responsible for freeing it. */
9195 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9197 /* Is the file number a valid index into the line header's file name
9198 table? Remember that file numbers start with one, not zero. */
9199 if (1 <= file
&& file
<= lh
->num_file_names
)
9201 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9203 if (IS_ABSOLUTE_PATH (fe
->name
))
9204 return xstrdup (fe
->name
);
9212 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9218 dir_len
= strlen (dir
);
9219 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9220 strcpy (full_name
, dir
);
9221 full_name
[dir_len
] = '/';
9222 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9226 return xstrdup (fe
->name
);
9231 /* The compiler produced a bogus file number. We can at least
9232 record the macro definitions made in the file, even if we
9233 won't be able to find the file by name. */
9235 sprintf (fake_name
, "<bad macro file number %d>", file
);
9237 complaint (&symfile_complaints
,
9238 _("bad file number in macro information (%d)"),
9241 return xstrdup (fake_name
);
9246 static struct macro_source_file
*
9247 macro_start_file (int file
, int line
,
9248 struct macro_source_file
*current_file
,
9249 const char *comp_dir
,
9250 struct line_header
*lh
, struct objfile
*objfile
)
9252 /* The full name of this source file. */
9253 char *full_name
= file_full_name (file
, lh
, comp_dir
);
9255 /* We don't create a macro table for this compilation unit
9256 at all until we actually get a filename. */
9257 if (! pending_macros
)
9258 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
9259 objfile
->macro_cache
);
9262 /* If we have no current file, then this must be the start_file
9263 directive for the compilation unit's main source file. */
9264 current_file
= macro_set_main (pending_macros
, full_name
);
9266 current_file
= macro_include (current_file
, line
, full_name
);
9270 return current_file
;
9274 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
9275 followed by a null byte. */
9277 copy_string (const char *buf
, int len
)
9279 char *s
= xmalloc (len
+ 1);
9280 memcpy (s
, buf
, len
);
9288 consume_improper_spaces (const char *p
, const char *body
)
9292 complaint (&symfile_complaints
,
9293 _("macro definition contains spaces in formal argument list:\n`%s'"),
9305 parse_macro_definition (struct macro_source_file
*file
, int line
,
9310 /* The body string takes one of two forms. For object-like macro
9311 definitions, it should be:
9313 <macro name> " " <definition>
9315 For function-like macro definitions, it should be:
9317 <macro name> "() " <definition>
9319 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
9321 Spaces may appear only where explicitly indicated, and in the
9324 The Dwarf 2 spec says that an object-like macro's name is always
9325 followed by a space, but versions of GCC around March 2002 omit
9326 the space when the macro's definition is the empty string.
9328 The Dwarf 2 spec says that there should be no spaces between the
9329 formal arguments in a function-like macro's formal argument list,
9330 but versions of GCC around March 2002 include spaces after the
9334 /* Find the extent of the macro name. The macro name is terminated
9335 by either a space or null character (for an object-like macro) or
9336 an opening paren (for a function-like macro). */
9337 for (p
= body
; *p
; p
++)
9338 if (*p
== ' ' || *p
== '(')
9341 if (*p
== ' ' || *p
== '\0')
9343 /* It's an object-like macro. */
9344 int name_len
= p
- body
;
9345 char *name
= copy_string (body
, name_len
);
9346 const char *replacement
;
9349 replacement
= body
+ name_len
+ 1;
9352 dwarf2_macro_malformed_definition_complaint (body
);
9353 replacement
= body
+ name_len
;
9356 macro_define_object (file
, line
, name
, replacement
);
9362 /* It's a function-like macro. */
9363 char *name
= copy_string (body
, p
- body
);
9366 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
9370 p
= consume_improper_spaces (p
, body
);
9372 /* Parse the formal argument list. */
9373 while (*p
&& *p
!= ')')
9375 /* Find the extent of the current argument name. */
9376 const char *arg_start
= p
;
9378 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
9381 if (! *p
|| p
== arg_start
)
9382 dwarf2_macro_malformed_definition_complaint (body
);
9385 /* Make sure argv has room for the new argument. */
9386 if (argc
>= argv_size
)
9389 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
9392 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
9395 p
= consume_improper_spaces (p
, body
);
9397 /* Consume the comma, if present. */
9402 p
= consume_improper_spaces (p
, body
);
9411 /* Perfectly formed definition, no complaints. */
9412 macro_define_function (file
, line
, name
,
9413 argc
, (const char **) argv
,
9415 else if (*p
== '\0')
9417 /* Complain, but do define it. */
9418 dwarf2_macro_malformed_definition_complaint (body
);
9419 macro_define_function (file
, line
, name
,
9420 argc
, (const char **) argv
,
9424 /* Just complain. */
9425 dwarf2_macro_malformed_definition_complaint (body
);
9428 /* Just complain. */
9429 dwarf2_macro_malformed_definition_complaint (body
);
9435 for (i
= 0; i
< argc
; i
++)
9441 dwarf2_macro_malformed_definition_complaint (body
);
9446 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
9447 char *comp_dir
, bfd
*abfd
,
9448 struct dwarf2_cu
*cu
)
9450 gdb_byte
*mac_ptr
, *mac_end
;
9451 struct macro_source_file
*current_file
= 0;
9453 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
9455 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
9459 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
9460 mac_end
= dwarf2_per_objfile
->macinfo_buffer
9461 + dwarf2_per_objfile
->macinfo_size
;
9465 enum dwarf_macinfo_record_type macinfo_type
;
9467 /* Do we at least have room for a macinfo type byte? */
9468 if (mac_ptr
>= mac_end
)
9470 dwarf2_macros_too_long_complaint ();
9474 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
9477 switch (macinfo_type
)
9479 /* A zero macinfo type indicates the end of the macro
9484 case DW_MACINFO_define
:
9485 case DW_MACINFO_undef
:
9487 unsigned int bytes_read
;
9491 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9492 mac_ptr
+= bytes_read
;
9493 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
9494 mac_ptr
+= bytes_read
;
9497 complaint (&symfile_complaints
,
9498 _("debug info gives macro %s outside of any file: %s"),
9500 DW_MACINFO_define
? "definition" : macinfo_type
==
9501 DW_MACINFO_undef
? "undefinition" :
9502 "something-or-other", body
);
9505 if (macinfo_type
== DW_MACINFO_define
)
9506 parse_macro_definition (current_file
, line
, body
);
9507 else if (macinfo_type
== DW_MACINFO_undef
)
9508 macro_undef (current_file
, line
, body
);
9513 case DW_MACINFO_start_file
:
9515 unsigned int bytes_read
;
9518 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9519 mac_ptr
+= bytes_read
;
9520 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9521 mac_ptr
+= bytes_read
;
9523 current_file
= macro_start_file (file
, line
,
9524 current_file
, comp_dir
,
9529 case DW_MACINFO_end_file
:
9531 complaint (&symfile_complaints
,
9532 _("macro debug info has an unmatched `close_file' directive"));
9535 current_file
= current_file
->included_by
;
9538 enum dwarf_macinfo_record_type next_type
;
9540 /* GCC circa March 2002 doesn't produce the zero
9541 type byte marking the end of the compilation
9542 unit. Complain if it's not there, but exit no
9545 /* Do we at least have room for a macinfo type byte? */
9546 if (mac_ptr
>= mac_end
)
9548 dwarf2_macros_too_long_complaint ();
9552 /* We don't increment mac_ptr here, so this is just
9554 next_type
= read_1_byte (abfd
, mac_ptr
);
9556 complaint (&symfile_complaints
,
9557 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
9564 case DW_MACINFO_vendor_ext
:
9566 unsigned int bytes_read
;
9570 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9571 mac_ptr
+= bytes_read
;
9572 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9573 mac_ptr
+= bytes_read
;
9575 /* We don't recognize any vendor extensions. */
9582 /* Check if the attribute's form is a DW_FORM_block*
9583 if so return true else false. */
9585 attr_form_is_block (struct attribute
*attr
)
9587 return (attr
== NULL
? 0 :
9588 attr
->form
== DW_FORM_block1
9589 || attr
->form
== DW_FORM_block2
9590 || attr
->form
== DW_FORM_block4
9591 || attr
->form
== DW_FORM_block
);
9595 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9596 struct dwarf2_cu
*cu
)
9598 if ((attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
9599 /* ".debug_loc" may not exist at all, or the offset may be outside
9600 the section. If so, fall through to the complaint in the
9602 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc_size
)
9604 struct dwarf2_loclist_baton
*baton
;
9606 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9607 sizeof (struct dwarf2_loclist_baton
));
9608 baton
->objfile
= cu
->objfile
;
9610 /* We don't know how long the location list is, but make sure we
9611 don't run off the edge of the section. */
9612 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9613 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9614 baton
->base_address
= cu
->header
.base_address
;
9615 if (cu
->header
.base_known
== 0)
9616 complaint (&symfile_complaints
,
9617 _("Location list used without specifying the CU base address."));
9619 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9620 SYMBOL_LOCATION_BATON (sym
) = baton
;
9624 struct dwarf2_locexpr_baton
*baton
;
9626 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9627 sizeof (struct dwarf2_locexpr_baton
));
9628 baton
->objfile
= cu
->objfile
;
9630 if (attr_form_is_block (attr
))
9632 /* Note that we're just copying the block's data pointer
9633 here, not the actual data. We're still pointing into the
9634 info_buffer for SYM's objfile; right now we never release
9635 that buffer, but when we do clean up properly this may
9637 baton
->size
= DW_BLOCK (attr
)->size
;
9638 baton
->data
= DW_BLOCK (attr
)->data
;
9642 dwarf2_invalid_attrib_class_complaint ("location description",
9643 SYMBOL_NATURAL_NAME (sym
));
9648 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9649 SYMBOL_LOCATION_BATON (sym
) = baton
;
9653 /* Locate the compilation unit from CU's objfile which contains the
9654 DIE at OFFSET. Raises an error on failure. */
9656 static struct dwarf2_per_cu_data
*
9657 dwarf2_find_containing_comp_unit (unsigned long offset
,
9658 struct objfile
*objfile
)
9660 struct dwarf2_per_cu_data
*this_cu
;
9664 high
= dwarf2_per_objfile
->n_comp_units
- 1;
9667 int mid
= low
+ (high
- low
) / 2;
9668 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
9673 gdb_assert (low
== high
);
9674 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
9677 error (_("Dwarf Error: could not find partial DIE containing "
9678 "offset 0x%lx [in module %s]"),
9679 (long) offset
, bfd_get_filename (objfile
->obfd
));
9681 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
9682 return dwarf2_per_objfile
->all_comp_units
[low
-1];
9686 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
9687 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
9688 && offset
>= this_cu
->offset
+ this_cu
->length
)
9689 error (_("invalid dwarf2 offset %ld"), offset
);
9690 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
9695 /* Locate the compilation unit from OBJFILE which is located at exactly
9696 OFFSET. Raises an error on failure. */
9698 static struct dwarf2_per_cu_data
*
9699 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
9701 struct dwarf2_per_cu_data
*this_cu
;
9702 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
9703 if (this_cu
->offset
!= offset
)
9704 error (_("no compilation unit with offset %ld."), offset
);
9708 /* Release one cached compilation unit, CU. We unlink it from the tree
9709 of compilation units, but we don't remove it from the read_in_chain;
9710 the caller is responsible for that. */
9713 free_one_comp_unit (void *data
)
9715 struct dwarf2_cu
*cu
= data
;
9717 if (cu
->per_cu
!= NULL
)
9718 cu
->per_cu
->cu
= NULL
;
9721 obstack_free (&cu
->comp_unit_obstack
, NULL
);
9723 free_die_list (cu
->dies
);
9728 /* This cleanup function is passed the address of a dwarf2_cu on the stack
9729 when we're finished with it. We can't free the pointer itself, but be
9730 sure to unlink it from the cache. Also release any associated storage
9731 and perform cache maintenance.
9733 Only used during partial symbol parsing. */
9736 free_stack_comp_unit (void *data
)
9738 struct dwarf2_cu
*cu
= data
;
9740 obstack_free (&cu
->comp_unit_obstack
, NULL
);
9741 cu
->partial_dies
= NULL
;
9743 if (cu
->per_cu
!= NULL
)
9745 /* This compilation unit is on the stack in our caller, so we
9746 should not xfree it. Just unlink it. */
9747 cu
->per_cu
->cu
= NULL
;
9750 /* If we had a per-cu pointer, then we may have other compilation
9751 units loaded, so age them now. */
9752 age_cached_comp_units ();
9756 /* Free all cached compilation units. */
9759 free_cached_comp_units (void *data
)
9761 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9763 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9764 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9765 while (per_cu
!= NULL
)
9767 struct dwarf2_per_cu_data
*next_cu
;
9769 next_cu
= per_cu
->cu
->read_in_chain
;
9771 free_one_comp_unit (per_cu
->cu
);
9772 *last_chain
= next_cu
;
9778 /* Increase the age counter on each cached compilation unit, and free
9779 any that are too old. */
9782 age_cached_comp_units (void)
9784 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9786 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
9787 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9788 while (per_cu
!= NULL
)
9790 per_cu
->cu
->last_used
++;
9791 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
9792 dwarf2_mark (per_cu
->cu
);
9793 per_cu
= per_cu
->cu
->read_in_chain
;
9796 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9797 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9798 while (per_cu
!= NULL
)
9800 struct dwarf2_per_cu_data
*next_cu
;
9802 next_cu
= per_cu
->cu
->read_in_chain
;
9804 if (!per_cu
->cu
->mark
)
9806 free_one_comp_unit (per_cu
->cu
);
9807 *last_chain
= next_cu
;
9810 last_chain
= &per_cu
->cu
->read_in_chain
;
9816 /* Remove a single compilation unit from the cache. */
9819 free_one_cached_comp_unit (void *target_cu
)
9821 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9823 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9824 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9825 while (per_cu
!= NULL
)
9827 struct dwarf2_per_cu_data
*next_cu
;
9829 next_cu
= per_cu
->cu
->read_in_chain
;
9831 if (per_cu
->cu
== target_cu
)
9833 free_one_comp_unit (per_cu
->cu
);
9834 *last_chain
= next_cu
;
9838 last_chain
= &per_cu
->cu
->read_in_chain
;
9844 /* A pair of DIE offset and GDB type pointer. We store these
9845 in a hash table separate from the DIEs, and preserve them
9846 when the DIEs are flushed out of cache. */
9848 struct dwarf2_offset_and_type
9850 unsigned int offset
;
9854 /* Hash function for a dwarf2_offset_and_type. */
9857 offset_and_type_hash (const void *item
)
9859 const struct dwarf2_offset_and_type
*ofs
= item
;
9863 /* Equality function for a dwarf2_offset_and_type. */
9866 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
9868 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
9869 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
9870 return ofs_lhs
->offset
== ofs_rhs
->offset
;
9873 /* Set the type associated with DIE to TYPE. Save it in CU's hash
9874 table if necessary. */
9877 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
9879 struct dwarf2_offset_and_type
**slot
, ofs
;
9883 if (cu
->per_cu
== NULL
)
9886 if (cu
->per_cu
->type_hash
== NULL
)
9887 cu
->per_cu
->type_hash
9888 = htab_create_alloc_ex (cu
->header
.length
/ 24,
9889 offset_and_type_hash
,
9892 &cu
->objfile
->objfile_obstack
,
9893 hashtab_obstack_allocate
,
9894 dummy_obstack_deallocate
);
9896 ofs
.offset
= die
->offset
;
9898 slot
= (struct dwarf2_offset_and_type
**)
9899 htab_find_slot_with_hash (cu
->per_cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
9900 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
9904 /* Find the type for DIE in TYPE_HASH, or return NULL if DIE does not
9905 have a saved type. */
9907 static struct type
*
9908 get_die_type (struct die_info
*die
, htab_t type_hash
)
9910 struct dwarf2_offset_and_type
*slot
, ofs
;
9912 ofs
.offset
= die
->offset
;
9913 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
9920 /* Restore the types of the DIE tree starting at START_DIE from the hash
9921 table saved in CU. */
9924 reset_die_and_siblings_types (struct die_info
*start_die
, struct dwarf2_cu
*cu
)
9926 struct die_info
*die
;
9928 if (cu
->per_cu
->type_hash
== NULL
)
9931 for (die
= start_die
; die
!= NULL
; die
= die
->sibling
)
9933 die
->type
= get_die_type (die
, cu
->per_cu
->type_hash
);
9934 if (die
->child
!= NULL
)
9935 reset_die_and_siblings_types (die
->child
, cu
);
9939 /* Set the mark field in CU and in every other compilation unit in the
9940 cache that we must keep because we are keeping CU. */
9942 /* Add a dependence relationship from CU to REF_PER_CU. */
9945 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
9946 struct dwarf2_per_cu_data
*ref_per_cu
)
9950 if (cu
->dependencies
== NULL
)
9952 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
9953 NULL
, &cu
->comp_unit_obstack
,
9954 hashtab_obstack_allocate
,
9955 dummy_obstack_deallocate
);
9957 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
9962 /* Set the mark field in CU and in every other compilation unit in the
9963 cache that we must keep because we are keeping CU. */
9966 dwarf2_mark_helper (void **slot
, void *data
)
9968 struct dwarf2_per_cu_data
*per_cu
;
9970 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
9971 if (per_cu
->cu
->mark
)
9973 per_cu
->cu
->mark
= 1;
9975 if (per_cu
->cu
->dependencies
!= NULL
)
9976 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
9982 dwarf2_mark (struct dwarf2_cu
*cu
)
9987 if (cu
->dependencies
!= NULL
)
9988 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
9992 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
9996 per_cu
->cu
->mark
= 0;
9997 per_cu
= per_cu
->cu
->read_in_chain
;
10001 /* Trivial hash function for partial_die_info: the hash value of a DIE
10002 is its offset in .debug_info for this objfile. */
10005 partial_die_hash (const void *item
)
10007 const struct partial_die_info
*part_die
= item
;
10008 return part_die
->offset
;
10011 /* Trivial comparison function for partial_die_info structures: two DIEs
10012 are equal if they have the same offset. */
10015 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10017 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10018 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10019 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10022 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10023 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10026 set_dwarf2_cmd (char *args
, int from_tty
)
10028 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10032 show_dwarf2_cmd (char *args
, int from_tty
)
10034 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10037 void _initialize_dwarf2_read (void);
10040 _initialize_dwarf2_read (void)
10042 dwarf2_objfile_data_key
= register_objfile_data ();
10044 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
10045 Set DWARF 2 specific variables.\n\
10046 Configure DWARF 2 variables such as the cache size"),
10047 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
10048 0/*allow-unknown*/, &maintenance_set_cmdlist
);
10050 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
10051 Show DWARF 2 specific variables\n\
10052 Show DWARF 2 variables such as the cache size"),
10053 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
10054 0/*allow-unknown*/, &maintenance_show_cmdlist
);
10056 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
10057 &dwarf2_max_cache_age
, _("\
10058 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
10059 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
10060 A higher limit means that cached compilation units will be stored\n\
10061 in memory longer, and more total memory will be used. Zero disables\n\
10062 caching, which can slow down startup."),
10064 show_dwarf2_max_cache_age
,
10065 &set_dwarf2_cmdlist
,
10066 &show_dwarf2_cmdlist
);