1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
71 #define MAP_FAILED ((void *) -1)
75 typedef struct symbol
*symbolp
;
79 /* .debug_info header for a compilation unit
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct comp_unit_header
84 unsigned int length
; /* length of the .debug_info
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
89 unsigned char addr_size
; /* byte size of an address -- 4 */
92 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* When non-zero, dump DIEs after they are read in. */
119 static int dwarf2_die_debug
= 0;
123 /* When set, the file that we're processing is known to have debugging
124 info for C++ namespaces. GCC 3.3.x did not produce this information,
125 but later versions do. */
127 static int processing_has_namespace_info
;
129 static const struct objfile_data
*dwarf2_objfile_data_key
;
131 struct dwarf2_section_info
137 /* True if we have tried to read this section. */
141 /* All offsets in the index are of this type. It must be
142 architecture-independent. */
143 typedef uint32_t offset_type
;
145 DEF_VEC_I (offset_type
);
147 /* A description of the mapped index. The file format is described in
148 a comment by the code that writes the index. */
151 /* The total length of the buffer. */
153 /* A pointer to the address table data. */
154 const gdb_byte
*address_table
;
155 /* Size of the address table data in bytes. */
156 offset_type address_table_size
;
157 /* The symbol table, implemented as a hash table. */
158 const offset_type
*symbol_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_table_slots
;
161 /* A pointer to the constant pool. */
162 const char *constant_pool
;
165 struct dwarf2_per_objfile
167 struct dwarf2_section_info info
;
168 struct dwarf2_section_info abbrev
;
169 struct dwarf2_section_info line
;
170 struct dwarf2_section_info loc
;
171 struct dwarf2_section_info macinfo
;
172 struct dwarf2_section_info str
;
173 struct dwarf2_section_info ranges
;
174 struct dwarf2_section_info types
;
175 struct dwarf2_section_info frame
;
176 struct dwarf2_section_info eh_frame
;
177 struct dwarf2_section_info gdb_index
;
180 struct objfile
*objfile
;
182 /* A list of all the compilation units. This is used to locate
183 the target compilation unit of a particular reference. */
184 struct dwarf2_per_cu_data
**all_comp_units
;
186 /* The number of compilation units in ALL_COMP_UNITS. */
189 /* The number of .debug_types-related CUs. */
190 int n_type_comp_units
;
192 /* The .debug_types-related CUs. */
193 struct dwarf2_per_cu_data
**type_comp_units
;
195 /* A chain of compilation units that are currently read in, so that
196 they can be freed later. */
197 struct dwarf2_per_cu_data
*read_in_chain
;
199 /* A table mapping .debug_types signatures to its signatured_type entry.
200 This is NULL if the .debug_types section hasn't been read in yet. */
201 htab_t signatured_types
;
203 /* A flag indicating wether this objfile has a section loaded at a
205 int has_section_at_zero
;
207 /* True if we are using the mapped index,
208 or we are faking it for OBJF_READNOW's sake. */
209 unsigned char using_index
;
211 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
212 struct mapped_index
*index_table
;
214 /* Set during partial symbol reading, to prevent queueing of full
216 int reading_partial_symbols
;
218 /* Table mapping type .debug_info DIE offsets to types.
219 This is NULL if not allocated yet.
220 It (currently) makes sense to allocate debug_types_type_hash lazily.
221 To keep things simple we allocate both lazily. */
222 htab_t debug_info_type_hash
;
224 /* Table mapping type .debug_types DIE offsets to types.
225 This is NULL if not allocated yet. */
226 htab_t debug_types_type_hash
;
229 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
231 /* names of the debugging sections */
233 /* Note that if the debugging section has been compressed, it might
234 have a name like .zdebug_info. */
236 #define INFO_SECTION "debug_info"
237 #define ABBREV_SECTION "debug_abbrev"
238 #define LINE_SECTION "debug_line"
239 #define LOC_SECTION "debug_loc"
240 #define MACINFO_SECTION "debug_macinfo"
241 #define STR_SECTION "debug_str"
242 #define RANGES_SECTION "debug_ranges"
243 #define TYPES_SECTION "debug_types"
244 #define FRAME_SECTION "debug_frame"
245 #define EH_FRAME_SECTION "eh_frame"
246 #define GDB_INDEX_SECTION "gdb_index"
248 /* local data types */
250 /* We hold several abbreviation tables in memory at the same time. */
251 #ifndef ABBREV_HASH_SIZE
252 #define ABBREV_HASH_SIZE 121
255 /* The data in a compilation unit header, after target2host
256 translation, looks like this. */
257 struct comp_unit_head
261 unsigned char addr_size
;
262 unsigned char signed_addr_p
;
263 unsigned int abbrev_offset
;
265 /* Size of file offsets; either 4 or 8. */
266 unsigned int offset_size
;
268 /* Size of the length field; either 4 or 12. */
269 unsigned int initial_length_size
;
271 /* Offset to the first byte of this compilation unit header in the
272 .debug_info section, for resolving relative reference dies. */
275 /* Offset to first die in this cu from the start of the cu.
276 This will be the first byte following the compilation unit header. */
277 unsigned int first_die_offset
;
280 /* Type used for delaying computation of method physnames.
281 See comments for compute_delayed_physnames. */
282 struct delayed_method_info
284 /* The type to which the method is attached, i.e., its parent class. */
287 /* The index of the method in the type's function fieldlists. */
290 /* The index of the method in the fieldlist. */
293 /* The name of the DIE. */
296 /* The DIE associated with this method. */
297 struct die_info
*die
;
300 typedef struct delayed_method_info delayed_method_info
;
301 DEF_VEC_O (delayed_method_info
);
303 /* Internal state when decoding a particular compilation unit. */
306 /* The objfile containing this compilation unit. */
307 struct objfile
*objfile
;
309 /* The header of the compilation unit. */
310 struct comp_unit_head header
;
312 /* Base address of this compilation unit. */
313 CORE_ADDR base_address
;
315 /* Non-zero if base_address has been set. */
318 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
320 /* The language we are debugging. */
321 enum language language
;
322 const struct language_defn
*language_defn
;
324 const char *producer
;
326 /* The generic symbol table building routines have separate lists for
327 file scope symbols and all all other scopes (local scopes). So
328 we need to select the right one to pass to add_symbol_to_list().
329 We do it by keeping a pointer to the correct list in list_in_scope.
331 FIXME: The original dwarf code just treated the file scope as the
332 first local scope, and all other local scopes as nested local
333 scopes, and worked fine. Check to see if we really need to
334 distinguish these in buildsym.c. */
335 struct pending
**list_in_scope
;
337 /* DWARF abbreviation table associated with this compilation unit. */
338 struct abbrev_info
**dwarf2_abbrevs
;
340 /* Storage for the abbrev table. */
341 struct obstack abbrev_obstack
;
343 /* Hash table holding all the loaded partial DIEs. */
346 /* Storage for things with the same lifetime as this read-in compilation
347 unit, including partial DIEs. */
348 struct obstack comp_unit_obstack
;
350 /* When multiple dwarf2_cu structures are living in memory, this field
351 chains them all together, so that they can be released efficiently.
352 We will probably also want a generation counter so that most-recently-used
353 compilation units are cached... */
354 struct dwarf2_per_cu_data
*read_in_chain
;
356 /* Backchain to our per_cu entry if the tree has been built. */
357 struct dwarf2_per_cu_data
*per_cu
;
359 /* How many compilation units ago was this CU last referenced? */
362 /* A hash table of die offsets for following references. */
365 /* Full DIEs if read in. */
366 struct die_info
*dies
;
368 /* A set of pointers to dwarf2_per_cu_data objects for compilation
369 units referenced by this one. Only set during full symbol processing;
370 partial symbol tables do not have dependencies. */
373 /* Header data from the line table, during full symbol processing. */
374 struct line_header
*line_header
;
376 /* A list of methods which need to have physnames computed
377 after all type information has been read. */
378 VEC (delayed_method_info
) *method_list
;
380 /* Mark used when releasing cached dies. */
381 unsigned int mark
: 1;
383 /* This flag will be set if this compilation unit might include
384 inter-compilation-unit references. */
385 unsigned int has_form_ref_addr
: 1;
387 /* This flag will be set if this compilation unit includes any
388 DW_TAG_namespace DIEs. If we know that there are explicit
389 DIEs for namespaces, we don't need to try to infer them
390 from mangled names. */
391 unsigned int has_namespace_info
: 1;
394 /* When using the index (and thus not using psymtabs), each CU has an
395 object of this type. This is used to hold information needed by
396 the various "quick" methods. */
397 struct dwarf2_per_cu_quick_data
399 /* The line table. This can be NULL if there was no line table. */
400 struct line_header
*lines
;
402 /* The file names from the line table. */
403 const char **file_names
;
404 /* The file names from the line table after being run through
406 const char **full_names
;
408 /* The corresponding symbol table. This is NULL if symbols for this
409 CU have not yet been read. */
410 struct symtab
*symtab
;
412 /* A temporary mark bit used when iterating over all CUs in
413 expand_symtabs_matching. */
414 unsigned int mark
: 1;
416 /* True if we've tried to read the line table. */
417 unsigned int read_lines
: 1;
420 /* Persistent data held for a compilation unit, even when not
421 processing it. We put a pointer to this structure in the
422 read_symtab_private field of the psymtab. If we encounter
423 inter-compilation-unit references, we also maintain a sorted
424 list of all compilation units. */
426 struct dwarf2_per_cu_data
428 /* The start offset and length of this compilation unit. 2**29-1
429 bytes should suffice to store the length of any compilation unit
430 - if it doesn't, GDB will fall over anyway.
431 NOTE: Unlike comp_unit_head.length, this length includes
432 initial_length_size. */
434 unsigned int length
: 29;
436 /* Flag indicating this compilation unit will be read in before
437 any of the current compilation units are processed. */
438 unsigned int queued
: 1;
440 /* This flag will be set if we need to load absolutely all DIEs
441 for this compilation unit, instead of just the ones we think
442 are interesting. It gets set if we look for a DIE in the
443 hash table and don't find it. */
444 unsigned int load_all_dies
: 1;
446 /* Non-zero if this CU is from .debug_types.
447 Otherwise it's from .debug_info. */
448 unsigned int from_debug_types
: 1;
450 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
451 of the CU cache it gets reset to NULL again. */
452 struct dwarf2_cu
*cu
;
454 /* The corresponding objfile. */
455 struct objfile
*objfile
;
457 /* When using partial symbol tables, the 'psymtab' field is active.
458 Otherwise the 'quick' field is active. */
461 /* The partial symbol table associated with this compilation unit,
462 or NULL for partial units (which do not have an associated
464 struct partial_symtab
*psymtab
;
466 /* Data needed by the "quick" functions. */
467 struct dwarf2_per_cu_quick_data
*quick
;
471 /* Entry in the signatured_types hash table. */
473 struct signatured_type
477 /* Offset in .debug_types of the TU (type_unit) for this type. */
480 /* Offset in .debug_types of the type defined by this TU. */
481 unsigned int type_offset
;
483 /* The CU(/TU) of this type. */
484 struct dwarf2_per_cu_data per_cu
;
487 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
488 which are used for both .debug_info and .debug_types dies.
489 All parameters here are unchanging for the life of the call.
490 This struct exists to abstract away the constant parameters of
493 struct die_reader_specs
495 /* The bfd of this objfile. */
498 /* The CU of the DIE we are parsing. */
499 struct dwarf2_cu
*cu
;
501 /* Pointer to start of section buffer.
502 This is either the start of .debug_info or .debug_types. */
503 const gdb_byte
*buffer
;
506 /* The line number information for a compilation unit (found in the
507 .debug_line section) begins with a "statement program header",
508 which contains the following information. */
511 unsigned int total_length
;
512 unsigned short version
;
513 unsigned int header_length
;
514 unsigned char minimum_instruction_length
;
515 unsigned char maximum_ops_per_instruction
;
516 unsigned char default_is_stmt
;
518 unsigned char line_range
;
519 unsigned char opcode_base
;
521 /* standard_opcode_lengths[i] is the number of operands for the
522 standard opcode whose value is i. This means that
523 standard_opcode_lengths[0] is unused, and the last meaningful
524 element is standard_opcode_lengths[opcode_base - 1]. */
525 unsigned char *standard_opcode_lengths
;
527 /* The include_directories table. NOTE! These strings are not
528 allocated with xmalloc; instead, they are pointers into
529 debug_line_buffer. If you try to free them, `free' will get
531 unsigned int num_include_dirs
, include_dirs_size
;
534 /* The file_names table. NOTE! These strings are not allocated
535 with xmalloc; instead, they are pointers into debug_line_buffer.
536 Don't try to free them directly. */
537 unsigned int num_file_names
, file_names_size
;
541 unsigned int dir_index
;
542 unsigned int mod_time
;
544 int included_p
; /* Non-zero if referenced by the Line Number Program. */
545 struct symtab
*symtab
; /* The associated symbol table, if any. */
548 /* The start and end of the statement program following this
549 header. These point into dwarf2_per_objfile->line_buffer. */
550 gdb_byte
*statement_program_start
, *statement_program_end
;
553 /* When we construct a partial symbol table entry we only
554 need this much information. */
555 struct partial_die_info
557 /* Offset of this DIE. */
560 /* DWARF-2 tag for this DIE. */
561 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
563 /* Assorted flags describing the data found in this DIE. */
564 unsigned int has_children
: 1;
565 unsigned int is_external
: 1;
566 unsigned int is_declaration
: 1;
567 unsigned int has_type
: 1;
568 unsigned int has_specification
: 1;
569 unsigned int has_pc_info
: 1;
571 /* Flag set if the SCOPE field of this structure has been
573 unsigned int scope_set
: 1;
575 /* Flag set if the DIE has a byte_size attribute. */
576 unsigned int has_byte_size
: 1;
578 /* Flag set if any of the DIE's children are template arguments. */
579 unsigned int has_template_arguments
: 1;
581 /* Flag set if fixup_partial_die has been called on this die. */
582 unsigned int fixup_called
: 1;
584 /* The name of this DIE. Normally the value of DW_AT_name, but
585 sometimes a default name for unnamed DIEs. */
588 /* The linkage name, if present. */
589 const char *linkage_name
;
591 /* The scope to prepend to our children. This is generally
592 allocated on the comp_unit_obstack, so will disappear
593 when this compilation unit leaves the cache. */
596 /* The location description associated with this DIE, if any. */
597 struct dwarf_block
*locdesc
;
599 /* If HAS_PC_INFO, the PC range associated with this DIE. */
603 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
604 DW_AT_sibling, if any. */
605 /* NOTE: This member isn't strictly necessary, read_partial_die could
606 return DW_AT_sibling values to its caller load_partial_dies. */
609 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
610 DW_AT_specification (or DW_AT_abstract_origin or
612 unsigned int spec_offset
;
614 /* Pointers to this DIE's parent, first child, and next sibling,
616 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
619 /* This data structure holds the information of an abbrev. */
622 unsigned int number
; /* number identifying abbrev */
623 enum dwarf_tag tag
; /* dwarf tag */
624 unsigned short has_children
; /* boolean */
625 unsigned short num_attrs
; /* number of attributes */
626 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
627 struct abbrev_info
*next
; /* next in chain */
632 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
633 ENUM_BITFIELD(dwarf_form
) form
: 16;
636 /* Attributes have a name and a value */
639 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
640 ENUM_BITFIELD(dwarf_form
) form
: 15;
642 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
643 field should be in u.str (existing only for DW_STRING) but it is kept
644 here for better struct attribute alignment. */
645 unsigned int string_is_canonical
: 1;
650 struct dwarf_block
*blk
;
654 struct signatured_type
*signatured_type
;
659 /* This data structure holds a complete die structure. */
662 /* DWARF-2 tag for this DIE. */
663 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
665 /* Number of attributes */
666 unsigned char num_attrs
;
668 /* True if we're presently building the full type name for the
669 type derived from this DIE. */
670 unsigned char building_fullname
: 1;
675 /* Offset in .debug_info or .debug_types section. */
678 /* The dies in a compilation unit form an n-ary tree. PARENT
679 points to this die's parent; CHILD points to the first child of
680 this node; and all the children of a given node are chained
681 together via their SIBLING fields. */
682 struct die_info
*child
; /* Its first child, if any. */
683 struct die_info
*sibling
; /* Its next sibling, if any. */
684 struct die_info
*parent
; /* Its parent, if any. */
686 /* An array of attributes, with NUM_ATTRS elements. There may be
687 zero, but it's not common and zero-sized arrays are not
688 sufficiently portable C. */
689 struct attribute attrs
[1];
692 struct function_range
695 CORE_ADDR lowpc
, highpc
;
697 struct function_range
*next
;
700 /* Get at parts of an attribute structure */
702 #define DW_STRING(attr) ((attr)->u.str)
703 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
704 #define DW_UNSND(attr) ((attr)->u.unsnd)
705 #define DW_BLOCK(attr) ((attr)->u.blk)
706 #define DW_SND(attr) ((attr)->u.snd)
707 #define DW_ADDR(attr) ((attr)->u.addr)
708 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
710 /* Blocks are a bunch of untyped bytes. */
717 #ifndef ATTR_ALLOC_CHUNK
718 #define ATTR_ALLOC_CHUNK 4
721 /* Allocate fields for structs, unions and enums in this size. */
722 #ifndef DW_FIELD_ALLOC_CHUNK
723 #define DW_FIELD_ALLOC_CHUNK 4
726 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
727 but this would require a corresponding change in unpack_field_as_long
729 static int bits_per_byte
= 8;
731 /* The routines that read and process dies for a C struct or C++ class
732 pass lists of data member fields and lists of member function fields
733 in an instance of a field_info structure, as defined below. */
736 /* List of data member and baseclasses fields. */
739 struct nextfield
*next
;
744 *fields
, *baseclasses
;
746 /* Number of fields (including baseclasses). */
749 /* Number of baseclasses. */
752 /* Set if the accesibility of one of the fields is not public. */
753 int non_public_fields
;
755 /* Member function fields array, entries are allocated in the order they
756 are encountered in the object file. */
759 struct nextfnfield
*next
;
760 struct fn_field fnfield
;
764 /* Member function fieldlist array, contains name of possibly overloaded
765 member function, number of overloaded member functions and a pointer
766 to the head of the member function field chain. */
771 struct nextfnfield
*head
;
775 /* Number of entries in the fnfieldlists array. */
778 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
779 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
780 struct typedef_field_list
782 struct typedef_field field
;
783 struct typedef_field_list
*next
;
786 unsigned typedef_field_list_count
;
789 /* One item on the queue of compilation units to read in full symbols
791 struct dwarf2_queue_item
793 struct dwarf2_per_cu_data
*per_cu
;
794 struct dwarf2_queue_item
*next
;
797 /* The current queue. */
798 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
800 /* Loaded secondary compilation units are kept in memory until they
801 have not been referenced for the processing of this many
802 compilation units. Set this to zero to disable caching. Cache
803 sizes of up to at least twenty will improve startup time for
804 typical inter-CU-reference binaries, at an obvious memory cost. */
805 static int dwarf2_max_cache_age
= 5;
807 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
808 struct cmd_list_element
*c
, const char *value
)
810 fprintf_filtered (file
, _("\
811 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
816 /* Various complaints about symbol reading that don't abort the process */
819 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
821 complaint (&symfile_complaints
,
822 _("statement list doesn't fit in .debug_line section"));
826 dwarf2_debug_line_missing_file_complaint (void)
828 complaint (&symfile_complaints
,
829 _(".debug_line section has line data without a file"));
833 dwarf2_debug_line_missing_end_sequence_complaint (void)
835 complaint (&symfile_complaints
,
836 _(".debug_line section has line program sequence without an end"));
840 dwarf2_complex_location_expr_complaint (void)
842 complaint (&symfile_complaints
, _("location expression too complex"));
846 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
849 complaint (&symfile_complaints
,
850 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
855 dwarf2_macros_too_long_complaint (void)
857 complaint (&symfile_complaints
,
858 _("macro info runs off end of `.debug_macinfo' section"));
862 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
864 complaint (&symfile_complaints
,
865 _("macro debug info contains a malformed macro definition:\n`%s'"),
870 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
872 complaint (&symfile_complaints
,
873 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
876 /* local function prototypes */
878 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
880 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
883 static void dwarf2_build_psymtabs_hard (struct objfile
*);
885 static void scan_partial_symbols (struct partial_die_info
*,
886 CORE_ADDR
*, CORE_ADDR
*,
887 int, struct dwarf2_cu
*);
889 static void add_partial_symbol (struct partial_die_info
*,
892 static void add_partial_namespace (struct partial_die_info
*pdi
,
893 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
894 int need_pc
, struct dwarf2_cu
*cu
);
896 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
897 CORE_ADDR
*highpc
, int need_pc
,
898 struct dwarf2_cu
*cu
);
900 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
901 struct dwarf2_cu
*cu
);
903 static void add_partial_subprogram (struct partial_die_info
*pdi
,
904 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
905 int need_pc
, struct dwarf2_cu
*cu
);
907 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
908 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
909 bfd
*abfd
, struct dwarf2_cu
*cu
);
911 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
913 static void psymtab_to_symtab_1 (struct partial_symtab
*);
915 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
917 static void dwarf2_free_abbrev_table (void *);
919 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
922 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
925 static struct partial_die_info
*load_partial_dies (bfd
*,
926 gdb_byte
*, gdb_byte
*,
927 int, struct dwarf2_cu
*);
929 static gdb_byte
*read_partial_die (struct partial_die_info
*,
930 struct abbrev_info
*abbrev
,
932 gdb_byte
*, gdb_byte
*,
935 static struct partial_die_info
*find_partial_die (unsigned int,
938 static void fixup_partial_die (struct partial_die_info
*,
941 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
942 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
944 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
945 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
947 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
949 static int read_1_signed_byte (bfd
*, gdb_byte
*);
951 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
953 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
955 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
957 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
960 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
962 static LONGEST read_checked_initial_length_and_offset
963 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
964 unsigned int *, unsigned int *);
966 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
969 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
971 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
973 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
975 static char *read_indirect_string (bfd
*, gdb_byte
*,
976 const struct comp_unit_head
*,
979 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
981 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
983 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
985 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
987 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
990 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
994 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
995 struct dwarf2_cu
*cu
);
997 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
999 static struct die_info
*die_specification (struct die_info
*die
,
1000 struct dwarf2_cu
**);
1002 static void free_line_header (struct line_header
*lh
);
1004 static void add_file_name (struct line_header
*, char *, unsigned int,
1005 unsigned int, unsigned int);
1007 static struct line_header
*(dwarf_decode_line_header
1008 (unsigned int offset
,
1009 bfd
*abfd
, struct dwarf2_cu
*cu
));
1011 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1012 struct dwarf2_cu
*, struct partial_symtab
*);
1014 static void dwarf2_start_subfile (char *, const char *, const char *);
1016 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1017 struct dwarf2_cu
*);
1019 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1020 struct dwarf2_cu
*, struct symbol
*);
1022 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1023 struct dwarf2_cu
*);
1025 static void dwarf2_const_value_attr (struct attribute
*attr
,
1028 struct obstack
*obstack
,
1029 struct dwarf2_cu
*cu
, long *value
,
1031 struct dwarf2_locexpr_baton
**baton
);
1033 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1035 static int need_gnat_info (struct dwarf2_cu
*);
1037 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
1039 static void set_descriptive_type (struct type
*, struct die_info
*,
1040 struct dwarf2_cu
*);
1042 static struct type
*die_containing_type (struct die_info
*,
1043 struct dwarf2_cu
*);
1045 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1046 struct dwarf2_cu
*);
1048 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1050 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1052 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1054 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1055 const char *suffix
, int physname
,
1056 struct dwarf2_cu
*cu
);
1058 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1060 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1062 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1064 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1066 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1067 struct dwarf2_cu
*, struct partial_symtab
*);
1069 static int dwarf2_get_pc_bounds (struct die_info
*,
1070 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1071 struct partial_symtab
*);
1073 static void get_scope_pc_bounds (struct die_info
*,
1074 CORE_ADDR
*, CORE_ADDR
*,
1075 struct dwarf2_cu
*);
1077 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1078 CORE_ADDR
, struct dwarf2_cu
*);
1080 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1081 struct dwarf2_cu
*);
1083 static void dwarf2_attach_fields_to_type (struct field_info
*,
1084 struct type
*, struct dwarf2_cu
*);
1086 static void dwarf2_add_member_fn (struct field_info
*,
1087 struct die_info
*, struct type
*,
1088 struct dwarf2_cu
*);
1090 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1091 struct type
*, struct dwarf2_cu
*);
1093 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1095 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1097 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1099 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1101 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1103 static struct type
*read_module_type (struct die_info
*die
,
1104 struct dwarf2_cu
*cu
);
1106 static const char *namespace_name (struct die_info
*die
,
1107 int *is_anonymous
, struct dwarf2_cu
*);
1109 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1111 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1113 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1114 struct dwarf2_cu
*);
1116 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1118 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1120 gdb_byte
**new_info_ptr
,
1121 struct die_info
*parent
);
1123 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1125 gdb_byte
**new_info_ptr
,
1126 struct die_info
*parent
);
1128 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1130 gdb_byte
**new_info_ptr
,
1131 struct die_info
*parent
);
1133 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1134 struct die_info
**, gdb_byte
*,
1137 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1139 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1142 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1144 static const char *dwarf2_full_name (char *name
,
1145 struct die_info
*die
,
1146 struct dwarf2_cu
*cu
);
1148 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1149 struct dwarf2_cu
**);
1151 static char *dwarf_tag_name (unsigned int);
1153 static char *dwarf_attr_name (unsigned int);
1155 static char *dwarf_form_name (unsigned int);
1157 static char *dwarf_bool_name (unsigned int);
1159 static char *dwarf_type_encoding_name (unsigned int);
1162 static char *dwarf_cfi_name (unsigned int);
1165 static struct die_info
*sibling_die (struct die_info
*);
1167 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1169 static void dump_die_for_error (struct die_info
*);
1171 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1174 /*static*/ void dump_die (struct die_info
*, int max_level
);
1176 static void store_in_ref_table (struct die_info
*,
1177 struct dwarf2_cu
*);
1179 static int is_ref_attr (struct attribute
*);
1181 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1183 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1185 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1187 struct dwarf2_cu
**);
1189 static struct die_info
*follow_die_ref (struct die_info
*,
1191 struct dwarf2_cu
**);
1193 static struct die_info
*follow_die_sig (struct die_info
*,
1195 struct dwarf2_cu
**);
1197 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1198 unsigned int offset
);
1200 static void read_signatured_type (struct objfile
*,
1201 struct signatured_type
*type_sig
);
1203 /* memory allocation interface */
1205 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1207 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1209 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1211 static void initialize_cu_func_list (struct dwarf2_cu
*);
1213 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1214 struct dwarf2_cu
*);
1216 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1217 char *, bfd
*, struct dwarf2_cu
*);
1219 static int attr_form_is_block (struct attribute
*);
1221 static int attr_form_is_section_offset (struct attribute
*);
1223 static int attr_form_is_constant (struct attribute
*);
1225 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1226 struct dwarf2_loclist_baton
*baton
,
1227 struct attribute
*attr
);
1229 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1231 struct dwarf2_cu
*cu
);
1233 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1234 struct abbrev_info
*abbrev
,
1235 struct dwarf2_cu
*cu
);
1237 static void free_stack_comp_unit (void *);
1239 static hashval_t
partial_die_hash (const void *item
);
1241 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1243 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1244 (unsigned int offset
, struct objfile
*objfile
);
1246 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1247 (unsigned int offset
, struct objfile
*objfile
);
1249 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1250 struct objfile
*objfile
);
1252 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1253 struct die_info
*comp_unit_die
);
1255 static void free_one_comp_unit (void *);
1257 static void free_cached_comp_units (void *);
1259 static void age_cached_comp_units (void);
1261 static void free_one_cached_comp_unit (void *);
1263 static struct type
*set_die_type (struct die_info
*, struct type
*,
1264 struct dwarf2_cu
*);
1266 static void create_all_comp_units (struct objfile
*);
1268 static int create_debug_types_hash_table (struct objfile
*objfile
);
1270 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1273 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1275 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1276 struct dwarf2_per_cu_data
*);
1278 static void dwarf2_mark (struct dwarf2_cu
*);
1280 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1282 static struct type
*get_die_type_at_offset (unsigned int,
1283 struct dwarf2_per_cu_data
*per_cu
);
1285 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1287 static void dwarf2_release_queue (void *dummy
);
1289 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1290 struct objfile
*objfile
);
1292 static void process_queue (struct objfile
*objfile
);
1294 static void find_file_and_directory (struct die_info
*die
,
1295 struct dwarf2_cu
*cu
,
1296 char **name
, char **comp_dir
);
1298 static char *file_full_name (int file
, struct line_header
*lh
,
1299 const char *comp_dir
);
1301 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1304 unsigned int buffer_size
,
1307 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1308 struct dwarf2_cu
*cu
);
1310 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1314 /* Convert VALUE between big- and little-endian. */
1316 byte_swap (offset_type value
)
1320 result
= (value
& 0xff) << 24;
1321 result
|= (value
& 0xff00) << 8;
1322 result
|= (value
& 0xff0000) >> 8;
1323 result
|= (value
& 0xff000000) >> 24;
1327 #define MAYBE_SWAP(V) byte_swap (V)
1330 #define MAYBE_SWAP(V) (V)
1331 #endif /* WORDS_BIGENDIAN */
1333 /* The suffix for an index file. */
1334 #define INDEX_SUFFIX ".gdb-index"
1336 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1337 struct dwarf2_cu
*cu
);
1339 /* Try to locate the sections we need for DWARF 2 debugging
1340 information and return true if we have enough to do something. */
1343 dwarf2_has_info (struct objfile
*objfile
)
1345 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1346 if (!dwarf2_per_objfile
)
1348 /* Initialize per-objfile state. */
1349 struct dwarf2_per_objfile
*data
1350 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1352 memset (data
, 0, sizeof (*data
));
1353 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1354 dwarf2_per_objfile
= data
;
1356 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1357 dwarf2_per_objfile
->objfile
= objfile
;
1359 return (dwarf2_per_objfile
->info
.asection
!= NULL
1360 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1363 /* When loading sections, we can either look for ".<name>", or for
1364 * ".z<name>", which indicates a compressed section. */
1367 section_is_p (const char *section_name
, const char *name
)
1369 return (section_name
[0] == '.'
1370 && (strcmp (section_name
+ 1, name
) == 0
1371 || (section_name
[1] == 'z'
1372 && strcmp (section_name
+ 2, name
) == 0)));
1375 /* This function is mapped across the sections and remembers the
1376 offset and size of each of the debugging sections we are interested
1380 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1382 if (section_is_p (sectp
->name
, INFO_SECTION
))
1384 dwarf2_per_objfile
->info
.asection
= sectp
;
1385 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1387 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1389 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1390 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1392 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1394 dwarf2_per_objfile
->line
.asection
= sectp
;
1395 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1397 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1399 dwarf2_per_objfile
->loc
.asection
= sectp
;
1400 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1402 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1404 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1405 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1407 else if (section_is_p (sectp
->name
, STR_SECTION
))
1409 dwarf2_per_objfile
->str
.asection
= sectp
;
1410 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1412 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1414 dwarf2_per_objfile
->frame
.asection
= sectp
;
1415 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1417 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1419 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1421 if (aflag
& SEC_HAS_CONTENTS
)
1423 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1424 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1427 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1429 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1430 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1432 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1434 dwarf2_per_objfile
->types
.asection
= sectp
;
1435 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1437 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1439 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1440 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1443 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1444 && bfd_section_vma (abfd
, sectp
) == 0)
1445 dwarf2_per_objfile
->has_section_at_zero
= 1;
1448 /* Decompress a section that was compressed using zlib. Store the
1449 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1452 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1453 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1455 bfd
*abfd
= objfile
->obfd
;
1457 error (_("Support for zlib-compressed DWARF data (from '%s') "
1458 "is disabled in this copy of GDB"),
1459 bfd_get_filename (abfd
));
1461 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1462 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1463 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1464 bfd_size_type uncompressed_size
;
1465 gdb_byte
*uncompressed_buffer
;
1468 int header_size
= 12;
1470 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1471 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1472 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1473 bfd_get_filename (abfd
));
1475 /* Read the zlib header. In this case, it should be "ZLIB" followed
1476 by the uncompressed section size, 8 bytes in big-endian order. */
1477 if (compressed_size
< header_size
1478 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1479 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1480 bfd_get_filename (abfd
));
1481 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1482 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1483 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1484 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1485 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1486 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1487 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1488 uncompressed_size
+= compressed_buffer
[11];
1490 /* It is possible the section consists of several compressed
1491 buffers concatenated together, so we uncompress in a loop. */
1495 strm
.avail_in
= compressed_size
- header_size
;
1496 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1497 strm
.avail_out
= uncompressed_size
;
1498 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1500 rc
= inflateInit (&strm
);
1501 while (strm
.avail_in
> 0)
1504 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1505 bfd_get_filename (abfd
), rc
);
1506 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1507 + (uncompressed_size
- strm
.avail_out
));
1508 rc
= inflate (&strm
, Z_FINISH
);
1509 if (rc
!= Z_STREAM_END
)
1510 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1511 bfd_get_filename (abfd
), rc
);
1512 rc
= inflateReset (&strm
);
1514 rc
= inflateEnd (&strm
);
1516 || strm
.avail_out
!= 0)
1517 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1518 bfd_get_filename (abfd
), rc
);
1520 do_cleanups (cleanup
);
1521 *outbuf
= uncompressed_buffer
;
1522 *outsize
= uncompressed_size
;
1526 /* Read the contents of the section SECTP from object file specified by
1527 OBJFILE, store info about the section into INFO.
1528 If the section is compressed, uncompress it before returning. */
1531 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1533 bfd
*abfd
= objfile
->obfd
;
1534 asection
*sectp
= info
->asection
;
1535 gdb_byte
*buf
, *retbuf
;
1536 unsigned char header
[4];
1540 info
->buffer
= NULL
;
1541 info
->was_mmapped
= 0;
1544 if (info
->asection
== NULL
|| info
->size
== 0)
1547 /* Check if the file has a 4-byte header indicating compression. */
1548 if (info
->size
> sizeof (header
)
1549 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1550 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1552 /* Upon decompression, update the buffer and its size. */
1553 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1555 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1563 pagesize
= getpagesize ();
1565 /* Only try to mmap sections which are large enough: we don't want to
1566 waste space due to fragmentation. Also, only try mmap for sections
1567 without relocations. */
1569 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1571 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1572 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1573 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1574 MAP_PRIVATE
, pg_offset
);
1576 if (retbuf
!= MAP_FAILED
)
1578 info
->was_mmapped
= 1;
1579 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1580 #if HAVE_POSIX_MADVISE
1581 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1588 /* If we get here, we are a normal, not-compressed section. */
1590 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1592 /* When debugging .o files, we may need to apply relocations; see
1593 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1594 We never compress sections in .o files, so we only need to
1595 try this when the section is not compressed. */
1596 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1599 info
->buffer
= retbuf
;
1603 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1604 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1605 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1606 bfd_get_filename (abfd
));
1609 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1613 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1614 asection
**sectp
, gdb_byte
**bufp
,
1615 bfd_size_type
*sizep
)
1617 struct dwarf2_per_objfile
*data
1618 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1619 struct dwarf2_section_info
*info
;
1621 /* We may see an objfile without any DWARF, in which case we just
1630 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1631 info
= &data
->eh_frame
;
1632 else if (section_is_p (section_name
, FRAME_SECTION
))
1633 info
= &data
->frame
;
1635 gdb_assert_not_reached ("unexpected section");
1637 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1638 /* We haven't read this section in yet. Do it now. */
1639 dwarf2_read_section (objfile
, info
);
1641 *sectp
= info
->asection
;
1642 *bufp
= info
->buffer
;
1643 *sizep
= info
->size
;
1648 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1652 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1653 struct dwarf2_per_cu_data
*per_cu
)
1655 struct cleanup
*back_to
;
1657 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1659 queue_comp_unit (per_cu
, objfile
);
1661 if (per_cu
->from_debug_types
)
1662 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1664 load_full_comp_unit (per_cu
, objfile
);
1666 process_queue (objfile
);
1668 /* Age the cache, releasing compilation units that have not
1669 been used recently. */
1670 age_cached_comp_units ();
1672 do_cleanups (back_to
);
1675 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1676 the objfile from which this CU came. Returns the resulting symbol
1679 static struct symtab
*
1680 dw2_instantiate_symtab (struct objfile
*objfile
,
1681 struct dwarf2_per_cu_data
*per_cu
)
1683 if (!per_cu
->v
.quick
->symtab
)
1685 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1686 increment_reading_symtab ();
1687 dw2_do_instantiate_symtab (objfile
, per_cu
);
1688 do_cleanups (back_to
);
1690 return per_cu
->v
.quick
->symtab
;
1693 /* Return the CU given its index. */
1695 static struct dwarf2_per_cu_data
*
1696 dw2_get_cu (int index
)
1698 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1700 index
-= dwarf2_per_objfile
->n_comp_units
;
1701 return dwarf2_per_objfile
->type_comp_units
[index
];
1703 return dwarf2_per_objfile
->all_comp_units
[index
];
1706 /* A helper function that knows how to read a 64-bit value in a way
1707 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1711 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1713 if (sizeof (ULONGEST
) < 8)
1717 /* Ignore the upper 4 bytes if they are all zero. */
1718 for (i
= 0; i
< 4; ++i
)
1719 if (bytes
[i
+ 4] != 0)
1722 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1725 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1729 /* Read the CU list from the mapped index, and use it to create all
1730 the CU objects for this objfile. Return 0 if something went wrong,
1731 1 if everything went ok. */
1734 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1735 offset_type cu_list_elements
)
1739 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1740 dwarf2_per_objfile
->all_comp_units
1741 = obstack_alloc (&objfile
->objfile_obstack
,
1742 dwarf2_per_objfile
->n_comp_units
1743 * sizeof (struct dwarf2_per_cu_data
*));
1745 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1747 struct dwarf2_per_cu_data
*the_cu
;
1748 ULONGEST offset
, length
;
1750 if (!extract_cu_value (cu_list
, &offset
)
1751 || !extract_cu_value (cu_list
+ 8, &length
))
1755 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1756 struct dwarf2_per_cu_data
);
1757 the_cu
->offset
= offset
;
1758 the_cu
->length
= length
;
1759 the_cu
->objfile
= objfile
;
1760 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1761 struct dwarf2_per_cu_quick_data
);
1762 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1768 /* Create the signatured type hash table from the index. */
1771 create_signatured_type_table_from_index (struct objfile
*objfile
,
1772 const gdb_byte
*bytes
,
1773 offset_type elements
)
1776 htab_t sig_types_hash
;
1778 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1779 dwarf2_per_objfile
->type_comp_units
1780 = obstack_alloc (&objfile
->objfile_obstack
,
1781 dwarf2_per_objfile
->n_type_comp_units
1782 * sizeof (struct dwarf2_per_cu_data
*));
1784 sig_types_hash
= allocate_signatured_type_table (objfile
);
1786 for (i
= 0; i
< elements
; i
+= 3)
1788 struct signatured_type
*type_sig
;
1789 ULONGEST offset
, type_offset
, signature
;
1792 if (!extract_cu_value (bytes
, &offset
)
1793 || !extract_cu_value (bytes
+ 8, &type_offset
))
1795 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1798 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1799 struct signatured_type
);
1800 type_sig
->signature
= signature
;
1801 type_sig
->offset
= offset
;
1802 type_sig
->type_offset
= type_offset
;
1803 type_sig
->per_cu
.from_debug_types
= 1;
1804 type_sig
->per_cu
.offset
= offset
;
1805 type_sig
->per_cu
.objfile
= objfile
;
1806 type_sig
->per_cu
.v
.quick
1807 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1808 struct dwarf2_per_cu_quick_data
);
1810 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1813 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1816 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1821 /* Read the address map data from the mapped index, and use it to
1822 populate the objfile's psymtabs_addrmap. */
1825 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1827 const gdb_byte
*iter
, *end
;
1828 struct obstack temp_obstack
;
1829 struct addrmap
*mutable_map
;
1830 struct cleanup
*cleanup
;
1833 obstack_init (&temp_obstack
);
1834 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1835 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1837 iter
= index
->address_table
;
1838 end
= iter
+ index
->address_table_size
;
1840 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1844 ULONGEST hi
, lo
, cu_index
;
1845 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1847 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1849 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1852 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1853 dw2_get_cu (cu_index
));
1856 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1857 &objfile
->objfile_obstack
);
1858 do_cleanups (cleanup
);
1861 /* The hash function for strings in the mapped index. This is the
1862 same as the hashtab.c hash function, but we keep a separate copy to
1863 maintain control over the implementation. This is necessary
1864 because the hash function is tied to the format of the mapped index
1868 mapped_index_string_hash (const void *p
)
1870 const unsigned char *str
= (const unsigned char *) p
;
1874 while ((c
= *str
++) != 0)
1875 r
= r
* 67 + c
- 113;
1880 /* Find a slot in the mapped index INDEX for the object named NAME.
1881 If NAME is found, set *VEC_OUT to point to the CU vector in the
1882 constant pool and return 1. If NAME cannot be found, return 0. */
1885 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1886 offset_type
**vec_out
)
1888 offset_type hash
= mapped_index_string_hash (name
);
1889 offset_type slot
, step
;
1891 slot
= hash
& (index
->symbol_table_slots
- 1);
1892 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
1896 /* Convert a slot number to an offset into the table. */
1897 offset_type i
= 2 * slot
;
1899 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
1902 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
1903 if (!strcmp (name
, str
))
1905 *vec_out
= (offset_type
*) (index
->constant_pool
1906 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
1910 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
1914 /* Read the index file. If everything went ok, initialize the "quick"
1915 elements of all the CUs and return 1. Otherwise, return 0. */
1918 dwarf2_read_index (struct objfile
*objfile
)
1921 struct mapped_index
*map
;
1922 offset_type
*metadata
;
1923 const gdb_byte
*cu_list
;
1924 const gdb_byte
*types_list
= NULL
;
1925 offset_type version
, cu_list_elements
;
1926 offset_type types_list_elements
= 0;
1929 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1930 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1933 /* Older elfutils strip versions could keep the section in the main
1934 executable while splitting it for the separate debug info file. */
1935 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
1936 & SEC_HAS_CONTENTS
) == 0)
1939 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1941 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1942 /* Version check. */
1943 version
= MAYBE_SWAP (*(offset_type
*) addr
);
1944 /* Versions earlier than 3 emitted every copy of a psymbol. This
1945 causes the index to behave very poorly for certain requests. So,
1946 it seems better to just ignore such indices. */
1949 /* Indexes with higher version than the one supported by GDB may be no
1950 longer backward compatible. */
1954 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1955 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
1957 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1960 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1961 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
1965 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1966 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
1967 - MAYBE_SWAP (metadata
[i
]))
1971 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
1972 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
1973 - MAYBE_SWAP (metadata
[i
]));
1976 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
1977 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
1978 - MAYBE_SWAP (metadata
[i
]))
1979 / (2 * sizeof (offset_type
)));
1982 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
1984 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
1987 if (types_list_elements
1988 && !create_signatured_type_table_from_index (objfile
, types_list
,
1989 types_list_elements
))
1992 create_addrmap_from_index (objfile
, map
);
1994 dwarf2_per_objfile
->index_table
= map
;
1995 dwarf2_per_objfile
->using_index
= 1;
2000 /* A helper for the "quick" functions which sets the global
2001 dwarf2_per_objfile according to OBJFILE. */
2004 dw2_setup (struct objfile
*objfile
)
2006 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2007 gdb_assert (dwarf2_per_objfile
);
2010 /* A helper for the "quick" functions which attempts to read the line
2011 table for THIS_CU. */
2014 dw2_require_line_header (struct objfile
*objfile
,
2015 struct dwarf2_per_cu_data
*this_cu
)
2017 bfd
*abfd
= objfile
->obfd
;
2018 struct line_header
*lh
= NULL
;
2019 struct attribute
*attr
;
2020 struct cleanup
*cleanups
;
2021 struct die_info
*comp_unit_die
;
2022 struct dwarf2_section_info
* sec
;
2023 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2024 int has_children
, i
;
2025 struct dwarf2_cu cu
;
2026 unsigned int bytes_read
, buffer_size
;
2027 struct die_reader_specs reader_specs
;
2028 char *name
, *comp_dir
;
2030 if (this_cu
->v
.quick
->read_lines
)
2032 this_cu
->v
.quick
->read_lines
= 1;
2034 init_one_comp_unit (&cu
, objfile
);
2035 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2037 if (this_cu
->from_debug_types
)
2038 sec
= &dwarf2_per_objfile
->types
;
2040 sec
= &dwarf2_per_objfile
->info
;
2041 dwarf2_read_section (objfile
, sec
);
2042 buffer_size
= sec
->size
;
2043 buffer
= sec
->buffer
;
2044 info_ptr
= buffer
+ this_cu
->offset
;
2045 beg_of_comp_unit
= info_ptr
;
2047 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2048 buffer
, buffer_size
,
2051 /* Complete the cu_header. */
2052 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2053 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2056 cu
.per_cu
= this_cu
;
2058 dwarf2_read_abbrevs (abfd
, &cu
);
2059 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2061 if (this_cu
->from_debug_types
)
2062 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2063 init_cu_die_reader (&reader_specs
, &cu
);
2064 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2067 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2070 unsigned int line_offset
= DW_UNSND (attr
);
2071 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2075 do_cleanups (cleanups
);
2079 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2081 this_cu
->v
.quick
->lines
= lh
;
2083 this_cu
->v
.quick
->file_names
2084 = obstack_alloc (&objfile
->objfile_obstack
,
2085 lh
->num_file_names
* sizeof (char *));
2086 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2087 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2089 do_cleanups (cleanups
);
2092 /* A helper for the "quick" functions which computes and caches the
2093 real path for a given file name from the line table.
2094 dw2_require_line_header must have been called before this is
2098 dw2_require_full_path (struct objfile
*objfile
,
2099 struct dwarf2_per_cu_data
*per_cu
,
2102 if (!per_cu
->v
.quick
->full_names
)
2103 per_cu
->v
.quick
->full_names
2104 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2105 per_cu
->v
.quick
->lines
->num_file_names
,
2108 if (!per_cu
->v
.quick
->full_names
[index
])
2109 per_cu
->v
.quick
->full_names
[index
]
2110 = gdb_realpath (per_cu
->v
.quick
->file_names
[index
]);
2112 return per_cu
->v
.quick
->full_names
[index
];
2115 static struct symtab
*
2116 dw2_find_last_source_symtab (struct objfile
*objfile
)
2120 dw2_setup (objfile
);
2121 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2122 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2126 dw2_forget_cached_source_info (struct objfile
*objfile
)
2130 dw2_setup (objfile
);
2131 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2132 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2134 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2136 if (per_cu
->v
.quick
->full_names
)
2140 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2142 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
2143 per_cu
->v
.quick
->full_names
[j
] = NULL
;
2150 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2151 const char *full_path
, const char *real_path
,
2152 struct symtab
**result
)
2155 int check_basename
= lbasename (name
) == name
;
2156 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2158 dw2_setup (objfile
);
2160 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2161 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2164 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2166 if (per_cu
->v
.quick
->symtab
)
2169 dw2_require_line_header (objfile
, per_cu
);
2170 if (!per_cu
->v
.quick
->lines
)
2173 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2175 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2177 if (FILENAME_CMP (name
, this_name
) == 0)
2179 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2183 if (check_basename
&& ! base_cu
2184 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2187 if (full_path
!= NULL
)
2189 const char *this_full_name
= dw2_require_full_path (objfile
,
2193 && FILENAME_CMP (full_path
, this_full_name
) == 0)
2195 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2200 if (real_path
!= NULL
)
2202 const char *this_full_name
= dw2_require_full_path (objfile
,
2205 if (this_full_name
!= NULL
2206 && FILENAME_CMP (real_path
, this_full_name
) == 0)
2208 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2217 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2224 static struct symtab
*
2225 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2226 const char *name
, domain_enum domain
)
2228 /* We do all the work in the pre_expand_symtabs_matching hook
2233 /* A helper function that expands all symtabs that hold an object
2237 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2239 dw2_setup (objfile
);
2241 /* index_table is NULL if OBJF_READNOW. */
2242 if (dwarf2_per_objfile
->index_table
)
2246 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2249 offset_type i
, len
= MAYBE_SWAP (*vec
);
2250 for (i
= 0; i
< len
; ++i
)
2252 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2253 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2255 dw2_instantiate_symtab (objfile
, per_cu
);
2262 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2263 int kind
, const char *name
,
2266 dw2_do_expand_symtabs_matching (objfile
, name
);
2270 dw2_print_stats (struct objfile
*objfile
)
2274 dw2_setup (objfile
);
2276 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2277 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2279 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2281 if (!per_cu
->v
.quick
->symtab
)
2284 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2288 dw2_dump (struct objfile
*objfile
)
2290 /* Nothing worth printing. */
2294 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2295 struct section_offsets
*delta
)
2297 /* There's nothing to relocate here. */
2301 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2302 const char *func_name
)
2304 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2308 dw2_expand_all_symtabs (struct objfile
*objfile
)
2312 dw2_setup (objfile
);
2314 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2315 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2317 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2319 dw2_instantiate_symtab (objfile
, per_cu
);
2324 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2325 const char *filename
)
2329 dw2_setup (objfile
);
2331 /* We don't need to consider type units here.
2332 This is only called for examining code, e.g. expand_line_sal.
2333 There can be an order of magnitude (or more) more type units
2334 than comp units, and we avoid them if we can. */
2336 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2339 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2341 if (per_cu
->v
.quick
->symtab
)
2344 dw2_require_line_header (objfile
, per_cu
);
2345 if (!per_cu
->v
.quick
->lines
)
2348 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2350 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2351 if (FILENAME_CMP (this_name
, filename
) == 0)
2353 dw2_instantiate_symtab (objfile
, per_cu
);
2361 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2363 struct dwarf2_per_cu_data
*per_cu
;
2366 dw2_setup (objfile
);
2368 /* index_table is NULL if OBJF_READNOW. */
2369 if (!dwarf2_per_objfile
->index_table
)
2372 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2376 /* Note that this just looks at the very first one named NAME -- but
2377 actually we are looking for a function. find_main_filename
2378 should be rewritten so that it doesn't require a custom hook. It
2379 could just use the ordinary symbol tables. */
2380 /* vec[0] is the length, which must always be >0. */
2381 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2383 dw2_require_line_header (objfile
, per_cu
);
2384 if (!per_cu
->v
.quick
->lines
)
2387 return per_cu
->v
.quick
->file_names
[per_cu
->v
.quick
->lines
->num_file_names
- 1];
2391 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2392 struct objfile
*objfile
, int global
,
2393 int (*callback
) (struct block
*,
2394 struct symbol
*, void *),
2395 void *data
, symbol_compare_ftype
*match
,
2396 symbol_compare_ftype
*ordered_compare
)
2398 /* Currently unimplemented; used for Ada. The function can be called if the
2399 current language is Ada for a non-Ada objfile using GNU index. As Ada
2400 does not look for non-Ada symbols this function should just return. */
2404 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2405 int (*file_matcher
) (const char *, void *),
2406 int (*name_matcher
) (const char *, void *),
2412 struct mapped_index
*index
;
2414 dw2_setup (objfile
);
2416 /* index_table is NULL if OBJF_READNOW. */
2417 if (!dwarf2_per_objfile
->index_table
)
2419 index
= dwarf2_per_objfile
->index_table
;
2421 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2422 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2425 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2427 per_cu
->v
.quick
->mark
= 0;
2428 if (per_cu
->v
.quick
->symtab
)
2431 dw2_require_line_header (objfile
, per_cu
);
2432 if (!per_cu
->v
.quick
->lines
)
2435 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2437 if (file_matcher (per_cu
->v
.quick
->file_names
[j
], data
))
2439 per_cu
->v
.quick
->mark
= 1;
2445 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2447 offset_type idx
= 2 * iter
;
2449 offset_type
*vec
, vec_len
, vec_idx
;
2451 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2454 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2456 if (! (*name_matcher
) (name
, data
))
2459 /* The name was matched, now expand corresponding CUs that were
2461 vec
= (offset_type
*) (index
->constant_pool
2462 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2463 vec_len
= MAYBE_SWAP (vec
[0]);
2464 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2466 struct dwarf2_per_cu_data
*per_cu
;
2468 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2469 if (per_cu
->v
.quick
->mark
)
2470 dw2_instantiate_symtab (objfile
, per_cu
);
2475 static struct symtab
*
2476 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2477 struct minimal_symbol
*msymbol
,
2479 struct obj_section
*section
,
2482 struct dwarf2_per_cu_data
*data
;
2484 dw2_setup (objfile
);
2486 if (!objfile
->psymtabs_addrmap
)
2489 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2493 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2494 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2495 paddress (get_objfile_arch (objfile
), pc
));
2497 return dw2_instantiate_symtab (objfile
, data
);
2501 dw2_map_symbol_names (struct objfile
*objfile
,
2502 void (*fun
) (const char *, void *),
2506 struct mapped_index
*index
;
2508 dw2_setup (objfile
);
2510 /* index_table is NULL if OBJF_READNOW. */
2511 if (!dwarf2_per_objfile
->index_table
)
2513 index
= dwarf2_per_objfile
->index_table
;
2515 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2517 offset_type idx
= 2 * iter
;
2519 offset_type
*vec
, vec_len
, vec_idx
;
2521 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2524 name
= (index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]));
2526 (*fun
) (name
, data
);
2531 dw2_map_symbol_filenames (struct objfile
*objfile
,
2532 void (*fun
) (const char *, const char *, void *),
2537 dw2_setup (objfile
);
2539 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2540 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2543 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2545 if (per_cu
->v
.quick
->symtab
)
2548 dw2_require_line_header (objfile
, per_cu
);
2549 if (!per_cu
->v
.quick
->lines
)
2552 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2554 const char *this_full_name
= dw2_require_full_path (objfile
, per_cu
,
2556 (*fun
) (per_cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2562 dw2_has_symbols (struct objfile
*objfile
)
2567 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2570 dw2_find_last_source_symtab
,
2571 dw2_forget_cached_source_info
,
2574 dw2_pre_expand_symtabs_matching
,
2578 dw2_expand_symtabs_for_function
,
2579 dw2_expand_all_symtabs
,
2580 dw2_expand_symtabs_with_filename
,
2581 dw2_find_symbol_file
,
2582 dw2_map_matching_symbols
,
2583 dw2_expand_symtabs_matching
,
2584 dw2_find_pc_sect_symtab
,
2585 dw2_map_symbol_names
,
2586 dw2_map_symbol_filenames
2589 /* Initialize for reading DWARF for this objfile. Return 0 if this
2590 file will use psymtabs, or 1 if using the GNU index. */
2593 dwarf2_initialize_objfile (struct objfile
*objfile
)
2595 /* If we're about to read full symbols, don't bother with the
2596 indices. In this case we also don't care if some other debug
2597 format is making psymtabs, because they are all about to be
2599 if ((objfile
->flags
& OBJF_READNOW
))
2603 dwarf2_per_objfile
->using_index
= 1;
2604 create_all_comp_units (objfile
);
2605 create_debug_types_hash_table (objfile
);
2607 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2608 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2610 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2612 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2613 struct dwarf2_per_cu_quick_data
);
2616 /* Return 1 so that gdb sees the "quick" functions. However,
2617 these functions will be no-ops because we will have expanded
2622 if (dwarf2_read_index (objfile
))
2625 dwarf2_build_psymtabs (objfile
);
2631 /* Build a partial symbol table. */
2634 dwarf2_build_psymtabs (struct objfile
*objfile
)
2636 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2638 init_psymbol_list (objfile
, 1024);
2641 dwarf2_build_psymtabs_hard (objfile
);
2644 /* Return TRUE if OFFSET is within CU_HEADER. */
2647 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2649 unsigned int bottom
= cu_header
->offset
;
2650 unsigned int top
= (cu_header
->offset
2652 + cu_header
->initial_length_size
);
2654 return (offset
>= bottom
&& offset
< top
);
2657 /* Read in the comp unit header information from the debug_info at info_ptr.
2658 NOTE: This leaves members offset, first_die_offset to be filled in
2662 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2663 gdb_byte
*info_ptr
, bfd
*abfd
)
2666 unsigned int bytes_read
;
2668 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2669 cu_header
->initial_length_size
= bytes_read
;
2670 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2671 info_ptr
+= bytes_read
;
2672 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2674 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2676 info_ptr
+= bytes_read
;
2677 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2679 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2680 if (signed_addr
< 0)
2681 internal_error (__FILE__
, __LINE__
,
2682 _("read_comp_unit_head: dwarf from non elf file"));
2683 cu_header
->signed_addr_p
= signed_addr
;
2689 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2690 gdb_byte
*buffer
, unsigned int buffer_size
,
2693 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2695 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2697 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2698 error (_("Dwarf Error: wrong version in compilation unit header "
2699 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2700 bfd_get_filename (abfd
));
2702 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2703 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2704 "(offset 0x%lx + 6) [in module %s]"),
2705 (long) header
->abbrev_offset
,
2706 (long) (beg_of_comp_unit
- buffer
),
2707 bfd_get_filename (abfd
));
2709 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2710 > buffer
+ buffer_size
)
2711 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2712 "(offset 0x%lx + 0) [in module %s]"),
2713 (long) header
->length
,
2714 (long) (beg_of_comp_unit
- buffer
),
2715 bfd_get_filename (abfd
));
2720 /* Read in the types comp unit header information from .debug_types entry at
2721 types_ptr. The result is a pointer to one past the end of the header. */
2724 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2725 ULONGEST
*signature
,
2726 gdb_byte
*types_ptr
, bfd
*abfd
)
2728 gdb_byte
*initial_types_ptr
= types_ptr
;
2730 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2731 &dwarf2_per_objfile
->types
);
2732 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2734 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2736 *signature
= read_8_bytes (abfd
, types_ptr
);
2738 types_ptr
+= cu_header
->offset_size
;
2739 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2744 /* Allocate a new partial symtab for file named NAME and mark this new
2745 partial symtab as being an include of PST. */
2748 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2749 struct objfile
*objfile
)
2751 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2753 subpst
->section_offsets
= pst
->section_offsets
;
2754 subpst
->textlow
= 0;
2755 subpst
->texthigh
= 0;
2757 subpst
->dependencies
= (struct partial_symtab
**)
2758 obstack_alloc (&objfile
->objfile_obstack
,
2759 sizeof (struct partial_symtab
*));
2760 subpst
->dependencies
[0] = pst
;
2761 subpst
->number_of_dependencies
= 1;
2763 subpst
->globals_offset
= 0;
2764 subpst
->n_global_syms
= 0;
2765 subpst
->statics_offset
= 0;
2766 subpst
->n_static_syms
= 0;
2767 subpst
->symtab
= NULL
;
2768 subpst
->read_symtab
= pst
->read_symtab
;
2771 /* No private part is necessary for include psymtabs. This property
2772 can be used to differentiate between such include psymtabs and
2773 the regular ones. */
2774 subpst
->read_symtab_private
= NULL
;
2777 /* Read the Line Number Program data and extract the list of files
2778 included by the source file represented by PST. Build an include
2779 partial symtab for each of these included files. */
2782 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2783 struct die_info
*die
,
2784 struct partial_symtab
*pst
)
2786 struct objfile
*objfile
= cu
->objfile
;
2787 bfd
*abfd
= objfile
->obfd
;
2788 struct line_header
*lh
= NULL
;
2789 struct attribute
*attr
;
2791 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2794 unsigned int line_offset
= DW_UNSND (attr
);
2796 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2799 return; /* No linetable, so no includes. */
2801 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2802 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2804 free_line_header (lh
);
2808 hash_type_signature (const void *item
)
2810 const struct signatured_type
*type_sig
= item
;
2812 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2813 return type_sig
->signature
;
2817 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2819 const struct signatured_type
*lhs
= item_lhs
;
2820 const struct signatured_type
*rhs
= item_rhs
;
2822 return lhs
->signature
== rhs
->signature
;
2825 /* Allocate a hash table for signatured types. */
2828 allocate_signatured_type_table (struct objfile
*objfile
)
2830 return htab_create_alloc_ex (41,
2831 hash_type_signature
,
2834 &objfile
->objfile_obstack
,
2835 hashtab_obstack_allocate
,
2836 dummy_obstack_deallocate
);
2839 /* A helper function to add a signatured type CU to a list. */
2842 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2844 struct signatured_type
*sigt
= *slot
;
2845 struct dwarf2_per_cu_data
***datap
= datum
;
2847 **datap
= &sigt
->per_cu
;
2853 /* Create the hash table of all entries in the .debug_types section.
2854 The result is zero if there is an error (e.g. missing .debug_types section),
2855 otherwise non-zero. */
2858 create_debug_types_hash_table (struct objfile
*objfile
)
2862 struct dwarf2_per_cu_data
**iter
;
2864 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2865 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2867 if (info_ptr
== NULL
)
2869 dwarf2_per_objfile
->signatured_types
= NULL
;
2873 types_htab
= allocate_signatured_type_table (objfile
);
2875 if (dwarf2_die_debug
)
2876 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2878 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2880 unsigned int offset
;
2881 unsigned int offset_size
;
2882 unsigned int type_offset
;
2883 unsigned int length
, initial_length_size
;
2884 unsigned short version
;
2886 struct signatured_type
*type_sig
;
2888 gdb_byte
*ptr
= info_ptr
;
2890 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2892 /* We need to read the type's signature in order to build the hash
2893 table, but we don't need to read anything else just yet. */
2895 /* Sanity check to ensure entire cu is present. */
2896 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2897 if (ptr
+ length
+ initial_length_size
2898 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2900 complaint (&symfile_complaints
,
2901 _("debug type entry runs off end of `.debug_types' section, ignored"));
2905 offset_size
= initial_length_size
== 4 ? 4 : 8;
2906 ptr
+= initial_length_size
;
2907 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2909 ptr
+= offset_size
; /* abbrev offset */
2910 ptr
+= 1; /* address size */
2911 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2913 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2915 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2916 memset (type_sig
, 0, sizeof (*type_sig
));
2917 type_sig
->signature
= signature
;
2918 type_sig
->offset
= offset
;
2919 type_sig
->type_offset
= type_offset
;
2920 type_sig
->per_cu
.objfile
= objfile
;
2921 type_sig
->per_cu
.from_debug_types
= 1;
2923 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2924 gdb_assert (slot
!= NULL
);
2927 if (dwarf2_die_debug
)
2928 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2929 offset
, phex (signature
, sizeof (signature
)));
2931 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2934 dwarf2_per_objfile
->signatured_types
= types_htab
;
2936 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
2937 dwarf2_per_objfile
->type_comp_units
2938 = obstack_alloc (&objfile
->objfile_obstack
,
2939 dwarf2_per_objfile
->n_type_comp_units
2940 * sizeof (struct dwarf2_per_cu_data
*));
2941 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
2942 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
2943 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
2944 == dwarf2_per_objfile
->n_type_comp_units
);
2949 /* Lookup a signature based type.
2950 Returns NULL if SIG is not present in the table. */
2952 static struct signatured_type
*
2953 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2955 struct signatured_type find_entry
, *entry
;
2957 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2959 complaint (&symfile_complaints
,
2960 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2964 find_entry
.signature
= sig
;
2965 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2969 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2972 init_cu_die_reader (struct die_reader_specs
*reader
,
2973 struct dwarf2_cu
*cu
)
2975 reader
->abfd
= cu
->objfile
->obfd
;
2977 if (cu
->per_cu
->from_debug_types
)
2979 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2980 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2984 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2985 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2989 /* Find the base address of the compilation unit for range lists and
2990 location lists. It will normally be specified by DW_AT_low_pc.
2991 In DWARF-3 draft 4, the base address could be overridden by
2992 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2993 compilation units with discontinuous ranges. */
2996 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2998 struct attribute
*attr
;
3001 cu
->base_address
= 0;
3003 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3006 cu
->base_address
= DW_ADDR (attr
);
3011 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3014 cu
->base_address
= DW_ADDR (attr
);
3020 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3021 to combine the common parts.
3022 Process a compilation unit for a psymtab.
3023 BUFFER is a pointer to the beginning of the dwarf section buffer,
3024 either .debug_info or debug_types.
3025 INFO_PTR is a pointer to the start of the CU.
3026 Returns a pointer to the next CU. */
3029 process_psymtab_comp_unit (struct objfile
*objfile
,
3030 struct dwarf2_per_cu_data
*this_cu
,
3031 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3032 unsigned int buffer_size
)
3034 bfd
*abfd
= objfile
->obfd
;
3035 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3036 struct die_info
*comp_unit_die
;
3037 struct partial_symtab
*pst
;
3039 struct cleanup
*back_to_inner
;
3040 struct dwarf2_cu cu
;
3041 int has_children
, has_pc_info
;
3042 struct attribute
*attr
;
3043 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3044 struct die_reader_specs reader_specs
;
3046 init_one_comp_unit (&cu
, objfile
);
3047 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3049 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3050 buffer
, buffer_size
,
3053 /* Complete the cu_header. */
3054 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3055 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3057 cu
.list_in_scope
= &file_symbols
;
3059 /* If this compilation unit was already read in, free the
3060 cached copy in order to read it in again. This is
3061 necessary because we skipped some symbols when we first
3062 read in the compilation unit (see load_partial_dies).
3063 This problem could be avoided, but the benefit is
3065 if (this_cu
->cu
!= NULL
)
3066 free_one_cached_comp_unit (this_cu
->cu
);
3068 /* Note that this is a pointer to our stack frame, being
3069 added to a global data structure. It will be cleaned up
3070 in free_stack_comp_unit when we finish with this
3071 compilation unit. */
3073 cu
.per_cu
= this_cu
;
3075 /* Read the abbrevs for this compilation unit into a table. */
3076 dwarf2_read_abbrevs (abfd
, &cu
);
3077 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3079 /* Read the compilation unit die. */
3080 if (this_cu
->from_debug_types
)
3081 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3082 init_cu_die_reader (&reader_specs
, &cu
);
3083 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3086 if (this_cu
->from_debug_types
)
3088 /* offset,length haven't been set yet for type units. */
3089 this_cu
->offset
= cu
.header
.offset
;
3090 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3092 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3094 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3095 + cu
.header
.initial_length_size
);
3096 do_cleanups (back_to_inner
);
3100 prepare_one_comp_unit (&cu
, comp_unit_die
);
3102 /* Allocate a new partial symbol table structure. */
3103 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3104 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3105 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3106 /* TEXTLOW and TEXTHIGH are set below. */
3108 objfile
->global_psymbols
.next
,
3109 objfile
->static_psymbols
.next
);
3111 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3113 pst
->dirname
= DW_STRING (attr
);
3115 pst
->read_symtab_private
= this_cu
;
3117 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3119 /* Store the function that reads in the rest of the symbol table */
3120 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3122 this_cu
->v
.psymtab
= pst
;
3124 dwarf2_find_base_address (comp_unit_die
, &cu
);
3126 /* Possibly set the default values of LOWPC and HIGHPC from
3128 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3129 &best_highpc
, &cu
, pst
);
3130 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3131 /* Store the contiguous range if it is not empty; it can be empty for
3132 CUs with no code. */
3133 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3134 best_lowpc
+ baseaddr
,
3135 best_highpc
+ baseaddr
- 1, pst
);
3137 /* Check if comp unit has_children.
3138 If so, read the rest of the partial symbols from this comp unit.
3139 If not, there's no more debug_info for this comp unit. */
3142 struct partial_die_info
*first_die
;
3143 CORE_ADDR lowpc
, highpc
;
3145 lowpc
= ((CORE_ADDR
) -1);
3146 highpc
= ((CORE_ADDR
) 0);
3148 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3150 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3151 ! has_pc_info
, &cu
);
3153 /* If we didn't find a lowpc, set it to highpc to avoid
3154 complaints from `maint check'. */
3155 if (lowpc
== ((CORE_ADDR
) -1))
3158 /* If the compilation unit didn't have an explicit address range,
3159 then use the information extracted from its child dies. */
3163 best_highpc
= highpc
;
3166 pst
->textlow
= best_lowpc
+ baseaddr
;
3167 pst
->texthigh
= best_highpc
+ baseaddr
;
3169 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3170 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3171 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3172 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3173 sort_pst_symbols (pst
);
3175 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3176 + cu
.header
.initial_length_size
);
3178 if (this_cu
->from_debug_types
)
3180 /* It's not clear we want to do anything with stmt lists here.
3181 Waiting to see what gcc ultimately does. */
3185 /* Get the list of files included in the current compilation unit,
3186 and build a psymtab for each of them. */
3187 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3190 do_cleanups (back_to_inner
);
3195 /* Traversal function for htab_traverse_noresize.
3196 Process one .debug_types comp-unit. */
3199 process_type_comp_unit (void **slot
, void *info
)
3201 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3202 struct objfile
*objfile
= (struct objfile
*) info
;
3203 struct dwarf2_per_cu_data
*this_cu
;
3205 this_cu
= &entry
->per_cu
;
3207 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3208 process_psymtab_comp_unit (objfile
, this_cu
,
3209 dwarf2_per_objfile
->types
.buffer
,
3210 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3211 dwarf2_per_objfile
->types
.size
);
3216 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3217 Build partial symbol tables for the .debug_types comp-units. */
3220 build_type_psymtabs (struct objfile
*objfile
)
3222 if (! create_debug_types_hash_table (objfile
))
3225 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3226 process_type_comp_unit
, objfile
);
3229 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3232 psymtabs_addrmap_cleanup (void *o
)
3234 struct objfile
*objfile
= o
;
3236 objfile
->psymtabs_addrmap
= NULL
;
3239 /* Build the partial symbol table by doing a quick pass through the
3240 .debug_info and .debug_abbrev sections. */
3243 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3246 struct cleanup
*back_to
, *addrmap_cleanup
;
3247 struct obstack temp_obstack
;
3249 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3251 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3252 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3254 /* Any cached compilation units will be linked by the per-objfile
3255 read_in_chain. Make sure to free them when we're done. */
3256 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3258 build_type_psymtabs (objfile
);
3260 create_all_comp_units (objfile
);
3262 /* Create a temporary address map on a temporary obstack. We later
3263 copy this to the final obstack. */
3264 obstack_init (&temp_obstack
);
3265 make_cleanup_obstack_free (&temp_obstack
);
3266 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3267 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3269 /* Since the objects we're extracting from .debug_info vary in
3270 length, only the individual functions to extract them (like
3271 read_comp_unit_head and load_partial_die) can really know whether
3272 the buffer is large enough to hold another complete object.
3274 At the moment, they don't actually check that. If .debug_info
3275 holds just one extra byte after the last compilation unit's dies,
3276 then read_comp_unit_head will happily read off the end of the
3277 buffer. read_partial_die is similarly casual. Those functions
3280 For this loop condition, simply checking whether there's any data
3281 left at all should be sufficient. */
3283 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3284 + dwarf2_per_objfile
->info
.size
))
3286 struct dwarf2_per_cu_data
*this_cu
;
3288 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3291 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3292 dwarf2_per_objfile
->info
.buffer
,
3294 dwarf2_per_objfile
->info
.size
);
3297 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3298 &objfile
->objfile_obstack
);
3299 discard_cleanups (addrmap_cleanup
);
3301 do_cleanups (back_to
);
3304 /* Load the partial DIEs for a secondary CU into memory. */
3307 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3308 struct objfile
*objfile
)
3310 bfd
*abfd
= objfile
->obfd
;
3311 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3312 struct die_info
*comp_unit_die
;
3313 struct dwarf2_cu
*cu
;
3314 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3316 struct die_reader_specs reader_specs
;
3319 gdb_assert (! this_cu
->from_debug_types
);
3321 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3322 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3323 beg_of_comp_unit
= info_ptr
;
3325 if (this_cu
->cu
== NULL
)
3327 cu
= xmalloc (sizeof (*cu
));
3328 init_one_comp_unit (cu
, objfile
);
3332 /* If an error occurs while loading, release our storage. */
3333 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3335 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3336 dwarf2_per_objfile
->info
.buffer
,
3337 dwarf2_per_objfile
->info
.size
,
3340 /* Complete the cu_header. */
3341 cu
->header
.offset
= this_cu
->offset
;
3342 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3344 /* Link this compilation unit into the compilation unit tree. */
3346 cu
->per_cu
= this_cu
;
3348 /* Link this CU into read_in_chain. */
3349 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3350 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3355 info_ptr
+= cu
->header
.first_die_offset
;
3358 /* Read the abbrevs for this compilation unit into a table. */
3359 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3360 dwarf2_read_abbrevs (abfd
, cu
);
3361 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3363 /* Read the compilation unit die. */
3364 init_cu_die_reader (&reader_specs
, cu
);
3365 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3368 prepare_one_comp_unit (cu
, comp_unit_die
);
3370 /* Check if comp unit has_children.
3371 If so, read the rest of the partial symbols from this comp unit.
3372 If not, there's no more debug_info for this comp unit. */
3374 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3376 do_cleanups (free_abbrevs_cleanup
);
3380 /* We've successfully allocated this compilation unit. Let our
3381 caller clean it up when finished with it. */
3382 discard_cleanups (free_cu_cleanup
);
3386 /* Create a list of all compilation units in OBJFILE. We do this only
3387 if an inter-comp-unit reference is found; presumably if there is one,
3388 there will be many, and one will occur early in the .debug_info section.
3389 So there's no point in building this list incrementally. */
3392 create_all_comp_units (struct objfile
*objfile
)
3396 struct dwarf2_per_cu_data
**all_comp_units
;
3399 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3400 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3404 all_comp_units
= xmalloc (n_allocated
3405 * sizeof (struct dwarf2_per_cu_data
*));
3407 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3409 unsigned int length
, initial_length_size
;
3410 struct dwarf2_per_cu_data
*this_cu
;
3411 unsigned int offset
;
3413 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3415 /* Read just enough information to find out where the next
3416 compilation unit is. */
3417 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3418 &initial_length_size
);
3420 /* Save the compilation unit for later lookup. */
3421 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3422 sizeof (struct dwarf2_per_cu_data
));
3423 memset (this_cu
, 0, sizeof (*this_cu
));
3424 this_cu
->offset
= offset
;
3425 this_cu
->length
= length
+ initial_length_size
;
3426 this_cu
->objfile
= objfile
;
3428 if (n_comp_units
== n_allocated
)
3431 all_comp_units
= xrealloc (all_comp_units
,
3433 * sizeof (struct dwarf2_per_cu_data
*));
3435 all_comp_units
[n_comp_units
++] = this_cu
;
3437 info_ptr
= info_ptr
+ this_cu
->length
;
3440 dwarf2_per_objfile
->all_comp_units
3441 = obstack_alloc (&objfile
->objfile_obstack
,
3442 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3443 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3444 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3445 xfree (all_comp_units
);
3446 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3449 /* Process all loaded DIEs for compilation unit CU, starting at
3450 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3451 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3452 DW_AT_ranges). If NEED_PC is set, then this function will set
3453 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3454 and record the covered ranges in the addrmap. */
3457 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3458 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3460 struct partial_die_info
*pdi
;
3462 /* Now, march along the PDI's, descending into ones which have
3463 interesting children but skipping the children of the other ones,
3464 until we reach the end of the compilation unit. */
3470 fixup_partial_die (pdi
, cu
);
3472 /* Anonymous namespaces or modules have no name but have interesting
3473 children, so we need to look at them. Ditto for anonymous
3476 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3477 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3481 case DW_TAG_subprogram
:
3482 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3484 case DW_TAG_constant
:
3485 case DW_TAG_variable
:
3486 case DW_TAG_typedef
:
3487 case DW_TAG_union_type
:
3488 if (!pdi
->is_declaration
)
3490 add_partial_symbol (pdi
, cu
);
3493 case DW_TAG_class_type
:
3494 case DW_TAG_interface_type
:
3495 case DW_TAG_structure_type
:
3496 if (!pdi
->is_declaration
)
3498 add_partial_symbol (pdi
, cu
);
3501 case DW_TAG_enumeration_type
:
3502 if (!pdi
->is_declaration
)
3503 add_partial_enumeration (pdi
, cu
);
3505 case DW_TAG_base_type
:
3506 case DW_TAG_subrange_type
:
3507 /* File scope base type definitions are added to the partial
3509 add_partial_symbol (pdi
, cu
);
3511 case DW_TAG_namespace
:
3512 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3515 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3522 /* If the die has a sibling, skip to the sibling. */
3524 pdi
= pdi
->die_sibling
;
3528 /* Functions used to compute the fully scoped name of a partial DIE.
3530 Normally, this is simple. For C++, the parent DIE's fully scoped
3531 name is concatenated with "::" and the partial DIE's name. For
3532 Java, the same thing occurs except that "." is used instead of "::".
3533 Enumerators are an exception; they use the scope of their parent
3534 enumeration type, i.e. the name of the enumeration type is not
3535 prepended to the enumerator.
3537 There are two complexities. One is DW_AT_specification; in this
3538 case "parent" means the parent of the target of the specification,
3539 instead of the direct parent of the DIE. The other is compilers
3540 which do not emit DW_TAG_namespace; in this case we try to guess
3541 the fully qualified name of structure types from their members'
3542 linkage names. This must be done using the DIE's children rather
3543 than the children of any DW_AT_specification target. We only need
3544 to do this for structures at the top level, i.e. if the target of
3545 any DW_AT_specification (if any; otherwise the DIE itself) does not
3548 /* Compute the scope prefix associated with PDI's parent, in
3549 compilation unit CU. The result will be allocated on CU's
3550 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3551 field. NULL is returned if no prefix is necessary. */
3553 partial_die_parent_scope (struct partial_die_info
*pdi
,
3554 struct dwarf2_cu
*cu
)
3556 char *grandparent_scope
;
3557 struct partial_die_info
*parent
, *real_pdi
;
3559 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3560 then this means the parent of the specification DIE. */
3563 while (real_pdi
->has_specification
)
3564 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3566 parent
= real_pdi
->die_parent
;
3570 if (parent
->scope_set
)
3571 return parent
->scope
;
3573 fixup_partial_die (parent
, cu
);
3575 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3577 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3578 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3579 Work around this problem here. */
3580 if (cu
->language
== language_cplus
3581 && parent
->tag
== DW_TAG_namespace
3582 && strcmp (parent
->name
, "::") == 0
3583 && grandparent_scope
== NULL
)
3585 parent
->scope
= NULL
;
3586 parent
->scope_set
= 1;
3590 if (parent
->tag
== DW_TAG_namespace
3591 || parent
->tag
== DW_TAG_module
3592 || parent
->tag
== DW_TAG_structure_type
3593 || parent
->tag
== DW_TAG_class_type
3594 || parent
->tag
== DW_TAG_interface_type
3595 || parent
->tag
== DW_TAG_union_type
3596 || parent
->tag
== DW_TAG_enumeration_type
)
3598 if (grandparent_scope
== NULL
)
3599 parent
->scope
= parent
->name
;
3601 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3602 parent
->name
, 0, cu
);
3604 else if (parent
->tag
== DW_TAG_enumerator
)
3605 /* Enumerators should not get the name of the enumeration as a prefix. */
3606 parent
->scope
= grandparent_scope
;
3609 /* FIXME drow/2004-04-01: What should we be doing with
3610 function-local names? For partial symbols, we should probably be
3612 complaint (&symfile_complaints
,
3613 _("unhandled containing DIE tag %d for DIE at %d"),
3614 parent
->tag
, pdi
->offset
);
3615 parent
->scope
= grandparent_scope
;
3618 parent
->scope_set
= 1;
3619 return parent
->scope
;
3622 /* Return the fully scoped name associated with PDI, from compilation unit
3623 CU. The result will be allocated with malloc. */
3625 partial_die_full_name (struct partial_die_info
*pdi
,
3626 struct dwarf2_cu
*cu
)
3630 /* If this is a template instantiation, we can not work out the
3631 template arguments from partial DIEs. So, unfortunately, we have
3632 to go through the full DIEs. At least any work we do building
3633 types here will be reused if full symbols are loaded later. */
3634 if (pdi
->has_template_arguments
)
3636 fixup_partial_die (pdi
, cu
);
3638 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3640 struct die_info
*die
;
3641 struct attribute attr
;
3642 struct dwarf2_cu
*ref_cu
= cu
;
3645 attr
.form
= DW_FORM_ref_addr
;
3646 attr
.u
.addr
= pdi
->offset
;
3647 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3649 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3653 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3654 if (parent_scope
== NULL
)
3657 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3661 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3663 struct objfile
*objfile
= cu
->objfile
;
3665 char *actual_name
= NULL
;
3666 const struct partial_symbol
*psym
= NULL
;
3668 int built_actual_name
= 0;
3670 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3672 actual_name
= partial_die_full_name (pdi
, cu
);
3674 built_actual_name
= 1;
3676 if (actual_name
== NULL
)
3677 actual_name
= pdi
->name
;
3681 case DW_TAG_subprogram
:
3682 if (pdi
->is_external
|| cu
->language
== language_ada
)
3684 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3685 of the global scope. But in Ada, we want to be able to access
3686 nested procedures globally. So all Ada subprograms are stored
3687 in the global scope. */
3688 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3689 mst_text, objfile); */
3690 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3692 VAR_DOMAIN
, LOC_BLOCK
,
3693 &objfile
->global_psymbols
,
3694 0, pdi
->lowpc
+ baseaddr
,
3695 cu
->language
, objfile
);
3699 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3700 mst_file_text, objfile); */
3701 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3703 VAR_DOMAIN
, LOC_BLOCK
,
3704 &objfile
->static_psymbols
,
3705 0, pdi
->lowpc
+ baseaddr
,
3706 cu
->language
, objfile
);
3709 case DW_TAG_constant
:
3711 struct psymbol_allocation_list
*list
;
3713 if (pdi
->is_external
)
3714 list
= &objfile
->global_psymbols
;
3716 list
= &objfile
->static_psymbols
;
3717 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3718 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3719 list
, 0, 0, cu
->language
, objfile
);
3723 case DW_TAG_variable
:
3725 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3729 && !dwarf2_per_objfile
->has_section_at_zero
)
3731 /* A global or static variable may also have been stripped
3732 out by the linker if unused, in which case its address
3733 will be nullified; do not add such variables into partial
3734 symbol table then. */
3736 else if (pdi
->is_external
)
3739 Don't enter into the minimal symbol tables as there is
3740 a minimal symbol table entry from the ELF symbols already.
3741 Enter into partial symbol table if it has a location
3742 descriptor or a type.
3743 If the location descriptor is missing, new_symbol will create
3744 a LOC_UNRESOLVED symbol, the address of the variable will then
3745 be determined from the minimal symbol table whenever the variable
3747 The address for the partial symbol table entry is not
3748 used by GDB, but it comes in handy for debugging partial symbol
3751 if (pdi
->locdesc
|| pdi
->has_type
)
3752 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3754 VAR_DOMAIN
, LOC_STATIC
,
3755 &objfile
->global_psymbols
,
3757 cu
->language
, objfile
);
3761 /* Static Variable. Skip symbols without location descriptors. */
3762 if (pdi
->locdesc
== NULL
)
3764 if (built_actual_name
)
3765 xfree (actual_name
);
3768 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3769 mst_file_data, objfile); */
3770 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3772 VAR_DOMAIN
, LOC_STATIC
,
3773 &objfile
->static_psymbols
,
3775 cu
->language
, objfile
);
3778 case DW_TAG_typedef
:
3779 case DW_TAG_base_type
:
3780 case DW_TAG_subrange_type
:
3781 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3783 VAR_DOMAIN
, LOC_TYPEDEF
,
3784 &objfile
->static_psymbols
,
3785 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3787 case DW_TAG_namespace
:
3788 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3790 VAR_DOMAIN
, LOC_TYPEDEF
,
3791 &objfile
->global_psymbols
,
3792 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3794 case DW_TAG_class_type
:
3795 case DW_TAG_interface_type
:
3796 case DW_TAG_structure_type
:
3797 case DW_TAG_union_type
:
3798 case DW_TAG_enumeration_type
:
3799 /* Skip external references. The DWARF standard says in the section
3800 about "Structure, Union, and Class Type Entries": "An incomplete
3801 structure, union or class type is represented by a structure,
3802 union or class entry that does not have a byte size attribute
3803 and that has a DW_AT_declaration attribute." */
3804 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3806 if (built_actual_name
)
3807 xfree (actual_name
);
3811 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3812 static vs. global. */
3813 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3815 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3816 (cu
->language
== language_cplus
3817 || cu
->language
== language_java
)
3818 ? &objfile
->global_psymbols
3819 : &objfile
->static_psymbols
,
3820 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3823 case DW_TAG_enumerator
:
3824 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3826 VAR_DOMAIN
, LOC_CONST
,
3827 (cu
->language
== language_cplus
3828 || cu
->language
== language_java
)
3829 ? &objfile
->global_psymbols
3830 : &objfile
->static_psymbols
,
3831 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3837 if (built_actual_name
)
3838 xfree (actual_name
);
3841 /* Read a partial die corresponding to a namespace; also, add a symbol
3842 corresponding to that namespace to the symbol table. NAMESPACE is
3843 the name of the enclosing namespace. */
3846 add_partial_namespace (struct partial_die_info
*pdi
,
3847 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3848 int need_pc
, struct dwarf2_cu
*cu
)
3850 /* Add a symbol for the namespace. */
3852 add_partial_symbol (pdi
, cu
);
3854 /* Now scan partial symbols in that namespace. */
3856 if (pdi
->has_children
)
3857 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3860 /* Read a partial die corresponding to a Fortran module. */
3863 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3864 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3866 /* Now scan partial symbols in that module. */
3868 if (pdi
->has_children
)
3869 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3872 /* Read a partial die corresponding to a subprogram and create a partial
3873 symbol for that subprogram. When the CU language allows it, this
3874 routine also defines a partial symbol for each nested subprogram
3875 that this subprogram contains.
3877 DIE my also be a lexical block, in which case we simply search
3878 recursively for suprograms defined inside that lexical block.
3879 Again, this is only performed when the CU language allows this
3880 type of definitions. */
3883 add_partial_subprogram (struct partial_die_info
*pdi
,
3884 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3885 int need_pc
, struct dwarf2_cu
*cu
)
3887 if (pdi
->tag
== DW_TAG_subprogram
)
3889 if (pdi
->has_pc_info
)
3891 if (pdi
->lowpc
< *lowpc
)
3892 *lowpc
= pdi
->lowpc
;
3893 if (pdi
->highpc
> *highpc
)
3894 *highpc
= pdi
->highpc
;
3898 struct objfile
*objfile
= cu
->objfile
;
3900 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3901 SECT_OFF_TEXT (objfile
));
3902 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3903 pdi
->lowpc
+ baseaddr
,
3904 pdi
->highpc
- 1 + baseaddr
,
3905 cu
->per_cu
->v
.psymtab
);
3907 if (!pdi
->is_declaration
)
3908 /* Ignore subprogram DIEs that do not have a name, they are
3909 illegal. Do not emit a complaint at this point, we will
3910 do so when we convert this psymtab into a symtab. */
3912 add_partial_symbol (pdi
, cu
);
3916 if (! pdi
->has_children
)
3919 if (cu
->language
== language_ada
)
3921 pdi
= pdi
->die_child
;
3924 fixup_partial_die (pdi
, cu
);
3925 if (pdi
->tag
== DW_TAG_subprogram
3926 || pdi
->tag
== DW_TAG_lexical_block
)
3927 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3928 pdi
= pdi
->die_sibling
;
3933 /* Read a partial die corresponding to an enumeration type. */
3936 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3937 struct dwarf2_cu
*cu
)
3939 struct partial_die_info
*pdi
;
3941 if (enum_pdi
->name
!= NULL
)
3942 add_partial_symbol (enum_pdi
, cu
);
3944 pdi
= enum_pdi
->die_child
;
3947 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3948 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3950 add_partial_symbol (pdi
, cu
);
3951 pdi
= pdi
->die_sibling
;
3955 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3956 Return the corresponding abbrev, or NULL if the number is zero (indicating
3957 an empty DIE). In either case *BYTES_READ will be set to the length of
3958 the initial number. */
3960 static struct abbrev_info
*
3961 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3962 struct dwarf2_cu
*cu
)
3964 bfd
*abfd
= cu
->objfile
->obfd
;
3965 unsigned int abbrev_number
;
3966 struct abbrev_info
*abbrev
;
3968 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3970 if (abbrev_number
== 0)
3973 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3976 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3977 bfd_get_filename (abfd
));
3983 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3984 Returns a pointer to the end of a series of DIEs, terminated by an empty
3985 DIE. Any children of the skipped DIEs will also be skipped. */
3988 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
3990 struct abbrev_info
*abbrev
;
3991 unsigned int bytes_read
;
3995 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
3997 return info_ptr
+ bytes_read
;
3999 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4003 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4004 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4005 abbrev corresponding to that skipped uleb128 should be passed in
4006 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4010 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4011 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4013 unsigned int bytes_read
;
4014 struct attribute attr
;
4015 bfd
*abfd
= cu
->objfile
->obfd
;
4016 unsigned int form
, i
;
4018 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4020 /* The only abbrev we care about is DW_AT_sibling. */
4021 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4023 read_attribute (&attr
, &abbrev
->attrs
[i
],
4024 abfd
, info_ptr
, cu
);
4025 if (attr
.form
== DW_FORM_ref_addr
)
4026 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
4028 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4031 /* If it isn't DW_AT_sibling, skip this attribute. */
4032 form
= abbrev
->attrs
[i
].form
;
4036 case DW_FORM_ref_addr
:
4037 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4038 and later it is offset sized. */
4039 if (cu
->header
.version
== 2)
4040 info_ptr
+= cu
->header
.addr_size
;
4042 info_ptr
+= cu
->header
.offset_size
;
4045 info_ptr
+= cu
->header
.addr_size
;
4052 case DW_FORM_flag_present
:
4067 case DW_FORM_string
:
4068 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4069 info_ptr
+= bytes_read
;
4071 case DW_FORM_sec_offset
:
4073 info_ptr
+= cu
->header
.offset_size
;
4075 case DW_FORM_exprloc
:
4077 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4078 info_ptr
+= bytes_read
;
4080 case DW_FORM_block1
:
4081 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4083 case DW_FORM_block2
:
4084 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4086 case DW_FORM_block4
:
4087 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4091 case DW_FORM_ref_udata
:
4092 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4094 case DW_FORM_indirect
:
4095 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4096 info_ptr
+= bytes_read
;
4097 /* We need to continue parsing from here, so just go back to
4099 goto skip_attribute
;
4102 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4103 dwarf_form_name (form
),
4104 bfd_get_filename (abfd
));
4108 if (abbrev
->has_children
)
4109 return skip_children (buffer
, info_ptr
, cu
);
4114 /* Locate ORIG_PDI's sibling.
4115 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4119 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4120 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4121 bfd
*abfd
, struct dwarf2_cu
*cu
)
4123 /* Do we know the sibling already? */
4125 if (orig_pdi
->sibling
)
4126 return orig_pdi
->sibling
;
4128 /* Are there any children to deal with? */
4130 if (!orig_pdi
->has_children
)
4133 /* Skip the children the long way. */
4135 return skip_children (buffer
, info_ptr
, cu
);
4138 /* Expand this partial symbol table into a full symbol table. */
4141 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4147 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
4153 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
4154 gdb_flush (gdb_stdout
);
4157 /* Restore our global data. */
4158 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4159 dwarf2_objfile_data_key
);
4161 /* If this psymtab is constructed from a debug-only objfile, the
4162 has_section_at_zero flag will not necessarily be correct. We
4163 can get the correct value for this flag by looking at the data
4164 associated with the (presumably stripped) associated objfile. */
4165 if (pst
->objfile
->separate_debug_objfile_backlink
)
4167 struct dwarf2_per_objfile
*dpo_backlink
4168 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4169 dwarf2_objfile_data_key
);
4171 dwarf2_per_objfile
->has_section_at_zero
4172 = dpo_backlink
->has_section_at_zero
;
4175 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4177 psymtab_to_symtab_1 (pst
);
4179 /* Finish up the debug error message. */
4181 printf_filtered (_("done.\n"));
4186 /* Add PER_CU to the queue. */
4189 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4191 struct dwarf2_queue_item
*item
;
4194 item
= xmalloc (sizeof (*item
));
4195 item
->per_cu
= per_cu
;
4198 if (dwarf2_queue
== NULL
)
4199 dwarf2_queue
= item
;
4201 dwarf2_queue_tail
->next
= item
;
4203 dwarf2_queue_tail
= item
;
4206 /* Process the queue. */
4209 process_queue (struct objfile
*objfile
)
4211 struct dwarf2_queue_item
*item
, *next_item
;
4213 /* The queue starts out with one item, but following a DIE reference
4214 may load a new CU, adding it to the end of the queue. */
4215 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4217 if (dwarf2_per_objfile
->using_index
4218 ? !item
->per_cu
->v
.quick
->symtab
4219 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4220 process_full_comp_unit (item
->per_cu
);
4222 item
->per_cu
->queued
= 0;
4223 next_item
= item
->next
;
4227 dwarf2_queue_tail
= NULL
;
4230 /* Free all allocated queue entries. This function only releases anything if
4231 an error was thrown; if the queue was processed then it would have been
4232 freed as we went along. */
4235 dwarf2_release_queue (void *dummy
)
4237 struct dwarf2_queue_item
*item
, *last
;
4239 item
= dwarf2_queue
;
4242 /* Anything still marked queued is likely to be in an
4243 inconsistent state, so discard it. */
4244 if (item
->per_cu
->queued
)
4246 if (item
->per_cu
->cu
!= NULL
)
4247 free_one_cached_comp_unit (item
->per_cu
->cu
);
4248 item
->per_cu
->queued
= 0;
4256 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4259 /* Read in full symbols for PST, and anything it depends on. */
4262 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4264 struct dwarf2_per_cu_data
*per_cu
;
4265 struct cleanup
*back_to
;
4268 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4269 if (!pst
->dependencies
[i
]->readin
)
4271 /* Inform about additional files that need to be read in. */
4274 /* FIXME: i18n: Need to make this a single string. */
4275 fputs_filtered (" ", gdb_stdout
);
4277 fputs_filtered ("and ", gdb_stdout
);
4279 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4280 wrap_here (""); /* Flush output */
4281 gdb_flush (gdb_stdout
);
4283 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4286 per_cu
= pst
->read_symtab_private
;
4290 /* It's an include file, no symbols to read for it.
4291 Everything is in the parent symtab. */
4296 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4299 /* Load the DIEs associated with PER_CU into memory. */
4302 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4304 bfd
*abfd
= objfile
->obfd
;
4305 struct dwarf2_cu
*cu
;
4306 unsigned int offset
;
4307 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4308 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4309 struct attribute
*attr
;
4312 gdb_assert (! per_cu
->from_debug_types
);
4314 /* Set local variables from the partial symbol table info. */
4315 offset
= per_cu
->offset
;
4317 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4318 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4319 beg_of_comp_unit
= info_ptr
;
4321 if (per_cu
->cu
== NULL
)
4323 cu
= xmalloc (sizeof (*cu
));
4324 init_one_comp_unit (cu
, objfile
);
4328 /* If an error occurs while loading, release our storage. */
4329 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4331 /* Read in the comp_unit header. */
4332 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4334 /* Complete the cu_header. */
4335 cu
->header
.offset
= offset
;
4336 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4338 /* Read the abbrevs for this compilation unit. */
4339 dwarf2_read_abbrevs (abfd
, cu
);
4340 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4342 /* Link this compilation unit into the compilation unit tree. */
4344 cu
->per_cu
= per_cu
;
4346 /* Link this CU into read_in_chain. */
4347 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4348 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4353 info_ptr
+= cu
->header
.first_die_offset
;
4356 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4358 /* We try not to read any attributes in this function, because not
4359 all objfiles needed for references have been loaded yet, and symbol
4360 table processing isn't initialized. But we have to set the CU language,
4361 or we won't be able to build types correctly. */
4362 prepare_one_comp_unit (cu
, cu
->dies
);
4364 /* Similarly, if we do not read the producer, we can not apply
4365 producer-specific interpretation. */
4366 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4368 cu
->producer
= DW_STRING (attr
);
4372 do_cleanups (free_abbrevs_cleanup
);
4374 /* We've successfully allocated this compilation unit. Let our
4375 caller clean it up when finished with it. */
4376 discard_cleanups (free_cu_cleanup
);
4380 /* Add a DIE to the delayed physname list. */
4383 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4384 const char *name
, struct die_info
*die
,
4385 struct dwarf2_cu
*cu
)
4387 struct delayed_method_info mi
;
4389 mi
.fnfield_index
= fnfield_index
;
4393 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4396 /* A cleanup for freeing the delayed method list. */
4399 free_delayed_list (void *ptr
)
4401 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4402 if (cu
->method_list
!= NULL
)
4404 VEC_free (delayed_method_info
, cu
->method_list
);
4405 cu
->method_list
= NULL
;
4409 /* Compute the physnames of any methods on the CU's method list.
4411 The computation of method physnames is delayed in order to avoid the
4412 (bad) condition that one of the method's formal parameters is of an as yet
4416 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4419 struct delayed_method_info
*mi
;
4420 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4423 struct fn_fieldlist
*fn_flp
4424 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4425 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4426 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4430 /* Generate full symbol information for PST and CU, whose DIEs have
4431 already been loaded into memory. */
4434 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4436 struct dwarf2_cu
*cu
= per_cu
->cu
;
4437 struct objfile
*objfile
= per_cu
->objfile
;
4438 CORE_ADDR lowpc
, highpc
;
4439 struct symtab
*symtab
;
4440 struct cleanup
*back_to
, *delayed_list_cleanup
;
4443 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4446 back_to
= make_cleanup (really_free_pendings
, NULL
);
4447 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4449 cu
->list_in_scope
= &file_symbols
;
4451 dwarf2_find_base_address (cu
->dies
, cu
);
4453 /* Do line number decoding in read_file_scope () */
4454 process_die (cu
->dies
, cu
);
4456 /* Now that we have processed all the DIEs in the CU, all the types
4457 should be complete, and it should now be safe to compute all of the
4459 compute_delayed_physnames (cu
);
4460 do_cleanups (delayed_list_cleanup
);
4462 /* Some compilers don't define a DW_AT_high_pc attribute for the
4463 compilation unit. If the DW_AT_high_pc is missing, synthesize
4464 it, by scanning the DIE's below the compilation unit. */
4465 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4467 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4469 /* Set symtab language to language from DW_AT_language.
4470 If the compilation is from a C file generated by language preprocessors,
4471 do not set the language if it was already deduced by start_subfile. */
4473 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4475 symtab
->language
= cu
->language
;
4478 if (dwarf2_per_objfile
->using_index
)
4479 per_cu
->v
.quick
->symtab
= symtab
;
4482 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4483 pst
->symtab
= symtab
;
4487 do_cleanups (back_to
);
4490 /* Process a die and its children. */
4493 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4497 case DW_TAG_padding
:
4499 case DW_TAG_compile_unit
:
4500 read_file_scope (die
, cu
);
4502 case DW_TAG_type_unit
:
4503 read_type_unit_scope (die
, cu
);
4505 case DW_TAG_subprogram
:
4506 case DW_TAG_inlined_subroutine
:
4507 read_func_scope (die
, cu
);
4509 case DW_TAG_lexical_block
:
4510 case DW_TAG_try_block
:
4511 case DW_TAG_catch_block
:
4512 read_lexical_block_scope (die
, cu
);
4514 case DW_TAG_class_type
:
4515 case DW_TAG_interface_type
:
4516 case DW_TAG_structure_type
:
4517 case DW_TAG_union_type
:
4518 process_structure_scope (die
, cu
);
4520 case DW_TAG_enumeration_type
:
4521 process_enumeration_scope (die
, cu
);
4524 /* These dies have a type, but processing them does not create
4525 a symbol or recurse to process the children. Therefore we can
4526 read them on-demand through read_type_die. */
4527 case DW_TAG_subroutine_type
:
4528 case DW_TAG_set_type
:
4529 case DW_TAG_array_type
:
4530 case DW_TAG_pointer_type
:
4531 case DW_TAG_ptr_to_member_type
:
4532 case DW_TAG_reference_type
:
4533 case DW_TAG_string_type
:
4536 case DW_TAG_base_type
:
4537 case DW_TAG_subrange_type
:
4538 case DW_TAG_typedef
:
4539 /* Add a typedef symbol for the type definition, if it has a
4541 new_symbol (die
, read_type_die (die
, cu
), cu
);
4543 case DW_TAG_common_block
:
4544 read_common_block (die
, cu
);
4546 case DW_TAG_common_inclusion
:
4548 case DW_TAG_namespace
:
4549 processing_has_namespace_info
= 1;
4550 read_namespace (die
, cu
);
4553 processing_has_namespace_info
= 1;
4554 read_module (die
, cu
);
4556 case DW_TAG_imported_declaration
:
4557 case DW_TAG_imported_module
:
4558 processing_has_namespace_info
= 1;
4559 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4560 || cu
->language
!= language_fortran
))
4561 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4562 dwarf_tag_name (die
->tag
));
4563 read_import_statement (die
, cu
);
4566 new_symbol (die
, NULL
, cu
);
4571 /* A helper function for dwarf2_compute_name which determines whether DIE
4572 needs to have the name of the scope prepended to the name listed in the
4576 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4578 struct attribute
*attr
;
4582 case DW_TAG_namespace
:
4583 case DW_TAG_typedef
:
4584 case DW_TAG_class_type
:
4585 case DW_TAG_interface_type
:
4586 case DW_TAG_structure_type
:
4587 case DW_TAG_union_type
:
4588 case DW_TAG_enumeration_type
:
4589 case DW_TAG_enumerator
:
4590 case DW_TAG_subprogram
:
4594 case DW_TAG_variable
:
4595 case DW_TAG_constant
:
4596 /* We only need to prefix "globally" visible variables. These include
4597 any variable marked with DW_AT_external or any variable that
4598 lives in a namespace. [Variables in anonymous namespaces
4599 require prefixing, but they are not DW_AT_external.] */
4601 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4603 struct dwarf2_cu
*spec_cu
= cu
;
4605 return die_needs_namespace (die_specification (die
, &spec_cu
),
4609 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4610 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4611 && die
->parent
->tag
!= DW_TAG_module
)
4613 /* A variable in a lexical block of some kind does not need a
4614 namespace, even though in C++ such variables may be external
4615 and have a mangled name. */
4616 if (die
->parent
->tag
== DW_TAG_lexical_block
4617 || die
->parent
->tag
== DW_TAG_try_block
4618 || die
->parent
->tag
== DW_TAG_catch_block
4619 || die
->parent
->tag
== DW_TAG_subprogram
)
4628 /* Retrieve the last character from a mem_file. */
4631 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4633 char *last_char_p
= (char *) object
;
4636 *last_char_p
= buffer
[length
- 1];
4639 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4640 compute the physname for the object, which include a method's
4641 formal parameters (C++/Java) and return type (Java).
4643 For Ada, return the DIE's linkage name rather than the fully qualified
4644 name. PHYSNAME is ignored..
4646 The result is allocated on the objfile_obstack and canonicalized. */
4649 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4653 name
= dwarf2_name (die
, cu
);
4655 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4656 compute it by typename_concat inside GDB. */
4657 if (cu
->language
== language_ada
4658 || (cu
->language
== language_fortran
&& physname
))
4660 /* For Ada unit, we prefer the linkage name over the name, as
4661 the former contains the exported name, which the user expects
4662 to be able to reference. Ideally, we want the user to be able
4663 to reference this entity using either natural or linkage name,
4664 but we haven't started looking at this enhancement yet. */
4665 struct attribute
*attr
;
4667 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4669 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4670 if (attr
&& DW_STRING (attr
))
4671 return DW_STRING (attr
);
4674 /* These are the only languages we know how to qualify names in. */
4676 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4677 || cu
->language
== language_fortran
))
4679 if (die_needs_namespace (die
, cu
))
4683 struct ui_file
*buf
;
4685 prefix
= determine_prefix (die
, cu
);
4686 buf
= mem_fileopen ();
4687 if (*prefix
!= '\0')
4689 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4692 fputs_unfiltered (prefixed_name
, buf
);
4693 xfree (prefixed_name
);
4696 fputs_unfiltered (name
? name
: "", buf
);
4698 /* Template parameters may be specified in the DIE's DW_AT_name, or
4699 as children with DW_TAG_template_type_param or
4700 DW_TAG_value_type_param. If the latter, add them to the name
4701 here. If the name already has template parameters, then
4702 skip this step; some versions of GCC emit both, and
4703 it is more efficient to use the pre-computed name.
4705 Something to keep in mind about this process: it is very
4706 unlikely, or in some cases downright impossible, to produce
4707 something that will match the mangled name of a function.
4708 If the definition of the function has the same debug info,
4709 we should be able to match up with it anyway. But fallbacks
4710 using the minimal symbol, for instance to find a method
4711 implemented in a stripped copy of libstdc++, will not work.
4712 If we do not have debug info for the definition, we will have to
4713 match them up some other way.
4715 When we do name matching there is a related problem with function
4716 templates; two instantiated function templates are allowed to
4717 differ only by their return types, which we do not add here. */
4719 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4721 struct attribute
*attr
;
4722 struct die_info
*child
;
4725 die
->building_fullname
= 1;
4727 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4732 struct dwarf2_locexpr_baton
*baton
;
4735 if (child
->tag
!= DW_TAG_template_type_param
4736 && child
->tag
!= DW_TAG_template_value_param
)
4741 fputs_unfiltered ("<", buf
);
4745 fputs_unfiltered (", ", buf
);
4747 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4750 complaint (&symfile_complaints
,
4751 _("template parameter missing DW_AT_type"));
4752 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4755 type
= die_type (child
, cu
);
4757 if (child
->tag
== DW_TAG_template_type_param
)
4759 c_print_type (type
, "", buf
, -1, 0);
4763 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4766 complaint (&symfile_complaints
,
4767 _("template parameter missing DW_AT_const_value"));
4768 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4772 dwarf2_const_value_attr (attr
, type
, name
,
4773 &cu
->comp_unit_obstack
, cu
,
4774 &value
, &bytes
, &baton
);
4776 if (TYPE_NOSIGN (type
))
4777 /* GDB prints characters as NUMBER 'CHAR'. If that's
4778 changed, this can use value_print instead. */
4779 c_printchar (value
, type
, buf
);
4782 struct value_print_options opts
;
4785 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4789 else if (bytes
!= NULL
)
4791 v
= allocate_value (type
);
4792 memcpy (value_contents_writeable (v
), bytes
,
4793 TYPE_LENGTH (type
));
4796 v
= value_from_longest (type
, value
);
4798 /* Specify decimal so that we do not depend on the radix. */
4799 get_formatted_print_options (&opts
, 'd');
4801 value_print (v
, buf
, &opts
);
4807 die
->building_fullname
= 0;
4811 /* Close the argument list, with a space if necessary
4812 (nested templates). */
4813 char last_char
= '\0';
4814 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4815 if (last_char
== '>')
4816 fputs_unfiltered (" >", buf
);
4818 fputs_unfiltered (">", buf
);
4822 /* For Java and C++ methods, append formal parameter type
4823 information, if PHYSNAME. */
4825 if (physname
&& die
->tag
== DW_TAG_subprogram
4826 && (cu
->language
== language_cplus
4827 || cu
->language
== language_java
))
4829 struct type
*type
= read_type_die (die
, cu
);
4831 c_type_print_args (type
, buf
, 0, cu
->language
);
4833 if (cu
->language
== language_java
)
4835 /* For java, we must append the return type to method
4837 if (die
->tag
== DW_TAG_subprogram
)
4838 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4841 else if (cu
->language
== language_cplus
)
4843 /* Assume that an artificial first parameter is
4844 "this", but do not crash if it is not. RealView
4845 marks unnamed (and thus unused) parameters as
4846 artificial; there is no way to differentiate
4848 if (TYPE_NFIELDS (type
) > 0
4849 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4850 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
4851 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4852 fputs_unfiltered (" const", buf
);
4856 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4858 ui_file_delete (buf
);
4860 if (cu
->language
== language_cplus
)
4863 = dwarf2_canonicalize_name (name
, cu
,
4864 &cu
->objfile
->objfile_obstack
);
4875 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4876 If scope qualifiers are appropriate they will be added. The result
4877 will be allocated on the objfile_obstack, or NULL if the DIE does
4878 not have a name. NAME may either be from a previous call to
4879 dwarf2_name or NULL.
4881 The output string will be canonicalized (if C++/Java). */
4884 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4886 return dwarf2_compute_name (name
, die
, cu
, 0);
4889 /* Construct a physname for the given DIE in CU. NAME may either be
4890 from a previous call to dwarf2_name or NULL. The result will be
4891 allocated on the objfile_objstack or NULL if the DIE does not have a
4894 The output string will be canonicalized (if C++/Java). */
4897 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4899 return dwarf2_compute_name (name
, die
, cu
, 1);
4902 /* Read the import statement specified by the given die and record it. */
4905 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4907 struct attribute
*import_attr
;
4908 struct die_info
*imported_die
;
4909 struct dwarf2_cu
*imported_cu
;
4910 const char *imported_name
;
4911 const char *imported_name_prefix
;
4912 const char *canonical_name
;
4913 const char *import_alias
;
4914 const char *imported_declaration
= NULL
;
4915 const char *import_prefix
;
4919 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4920 if (import_attr
== NULL
)
4922 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4923 dwarf_tag_name (die
->tag
));
4928 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4929 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4930 if (imported_name
== NULL
)
4932 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4934 The import in the following code:
4948 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4949 <52> DW_AT_decl_file : 1
4950 <53> DW_AT_decl_line : 6
4951 <54> DW_AT_import : <0x75>
4952 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4954 <5b> DW_AT_decl_file : 1
4955 <5c> DW_AT_decl_line : 2
4956 <5d> DW_AT_type : <0x6e>
4958 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4959 <76> DW_AT_byte_size : 4
4960 <77> DW_AT_encoding : 5 (signed)
4962 imports the wrong die ( 0x75 instead of 0x58 ).
4963 This case will be ignored until the gcc bug is fixed. */
4967 /* Figure out the local name after import. */
4968 import_alias
= dwarf2_name (die
, cu
);
4970 /* Figure out where the statement is being imported to. */
4971 import_prefix
= determine_prefix (die
, cu
);
4973 /* Figure out what the scope of the imported die is and prepend it
4974 to the name of the imported die. */
4975 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4977 if (imported_die
->tag
!= DW_TAG_namespace
4978 && imported_die
->tag
!= DW_TAG_module
)
4980 imported_declaration
= imported_name
;
4981 canonical_name
= imported_name_prefix
;
4983 else if (strlen (imported_name_prefix
) > 0)
4985 temp
= alloca (strlen (imported_name_prefix
)
4986 + 2 + strlen (imported_name
) + 1);
4987 strcpy (temp
, imported_name_prefix
);
4988 strcat (temp
, "::");
4989 strcat (temp
, imported_name
);
4990 canonical_name
= temp
;
4993 canonical_name
= imported_name
;
4995 cp_add_using_directive (import_prefix
,
4998 imported_declaration
,
4999 &cu
->objfile
->objfile_obstack
);
5003 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5005 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5008 /* Cleanup function for read_file_scope. */
5011 free_cu_line_header (void *arg
)
5013 struct dwarf2_cu
*cu
= arg
;
5015 free_line_header (cu
->line_header
);
5016 cu
->line_header
= NULL
;
5020 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5021 char **name
, char **comp_dir
)
5023 struct attribute
*attr
;
5028 /* Find the filename. Do not use dwarf2_name here, since the filename
5029 is not a source language identifier. */
5030 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5033 *name
= DW_STRING (attr
);
5036 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5038 *comp_dir
= DW_STRING (attr
);
5039 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5041 *comp_dir
= ldirname (*name
);
5042 if (*comp_dir
!= NULL
)
5043 make_cleanup (xfree
, *comp_dir
);
5045 if (*comp_dir
!= NULL
)
5047 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5048 directory, get rid of it. */
5049 char *cp
= strchr (*comp_dir
, ':');
5051 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5056 *name
= "<unknown>";
5059 /* Process DW_TAG_compile_unit. */
5062 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5064 struct objfile
*objfile
= cu
->objfile
;
5065 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5066 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5067 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5068 struct attribute
*attr
;
5070 char *comp_dir
= NULL
;
5071 struct die_info
*child_die
;
5072 bfd
*abfd
= objfile
->obfd
;
5073 struct line_header
*line_header
= 0;
5076 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5078 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5080 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5081 from finish_block. */
5082 if (lowpc
== ((CORE_ADDR
) -1))
5087 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5089 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5092 set_cu_language (DW_UNSND (attr
), cu
);
5095 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5097 cu
->producer
= DW_STRING (attr
);
5099 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5100 standardised yet. As a workaround for the language detection we fall
5101 back to the DW_AT_producer string. */
5102 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5103 cu
->language
= language_opencl
;
5105 /* We assume that we're processing GCC output. */
5106 processing_gcc_compilation
= 2;
5108 processing_has_namespace_info
= 0;
5110 start_symtab (name
, comp_dir
, lowpc
);
5111 record_debugformat ("DWARF 2");
5112 record_producer (cu
->producer
);
5114 initialize_cu_func_list (cu
);
5116 /* Decode line number information if present. We do this before
5117 processing child DIEs, so that the line header table is available
5118 for DW_AT_decl_file. */
5119 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5122 unsigned int line_offset
= DW_UNSND (attr
);
5123 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5126 cu
->line_header
= line_header
;
5127 make_cleanup (free_cu_line_header
, cu
);
5128 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5132 /* Process all dies in compilation unit. */
5133 if (die
->child
!= NULL
)
5135 child_die
= die
->child
;
5136 while (child_die
&& child_die
->tag
)
5138 process_die (child_die
, cu
);
5139 child_die
= sibling_die (child_die
);
5143 /* Decode macro information, if present. Dwarf 2 macro information
5144 refers to information in the line number info statement program
5145 header, so we can only read it if we've read the header
5147 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5148 if (attr
&& line_header
)
5150 unsigned int macro_offset
= DW_UNSND (attr
);
5152 dwarf_decode_macros (line_header
, macro_offset
,
5153 comp_dir
, abfd
, cu
);
5155 do_cleanups (back_to
);
5158 /* Process DW_TAG_type_unit.
5159 For TUs we want to skip the first top level sibling if it's not the
5160 actual type being defined by this TU. In this case the first top
5161 level sibling is there to provide context only. */
5164 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5166 struct objfile
*objfile
= cu
->objfile
;
5167 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5169 struct attribute
*attr
;
5171 char *comp_dir
= NULL
;
5172 struct die_info
*child_die
;
5173 bfd
*abfd
= objfile
->obfd
;
5175 /* start_symtab needs a low pc, but we don't really have one.
5176 Do what read_file_scope would do in the absence of such info. */
5177 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5179 /* Find the filename. Do not use dwarf2_name here, since the filename
5180 is not a source language identifier. */
5181 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5183 name
= DW_STRING (attr
);
5185 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5187 comp_dir
= DW_STRING (attr
);
5188 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5190 comp_dir
= ldirname (name
);
5191 if (comp_dir
!= NULL
)
5192 make_cleanup (xfree
, comp_dir
);
5198 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5200 set_cu_language (DW_UNSND (attr
), cu
);
5202 /* This isn't technically needed today. It is done for symmetry
5203 with read_file_scope. */
5204 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5206 cu
->producer
= DW_STRING (attr
);
5208 /* We assume that we're processing GCC output. */
5209 processing_gcc_compilation
= 2;
5211 processing_has_namespace_info
= 0;
5213 start_symtab (name
, comp_dir
, lowpc
);
5214 record_debugformat ("DWARF 2");
5215 record_producer (cu
->producer
);
5217 /* Process the dies in the type unit. */
5218 if (die
->child
== NULL
)
5220 dump_die_for_error (die
);
5221 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5222 bfd_get_filename (abfd
));
5225 child_die
= die
->child
;
5227 while (child_die
&& child_die
->tag
)
5229 process_die (child_die
, cu
);
5231 child_die
= sibling_die (child_die
);
5234 do_cleanups (back_to
);
5238 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5239 struct dwarf2_cu
*cu
)
5241 struct function_range
*thisfn
;
5243 thisfn
= (struct function_range
*)
5244 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5245 thisfn
->name
= name
;
5246 thisfn
->lowpc
= lowpc
;
5247 thisfn
->highpc
= highpc
;
5248 thisfn
->seen_line
= 0;
5249 thisfn
->next
= NULL
;
5251 if (cu
->last_fn
== NULL
)
5252 cu
->first_fn
= thisfn
;
5254 cu
->last_fn
->next
= thisfn
;
5256 cu
->last_fn
= thisfn
;
5259 /* qsort helper for inherit_abstract_dies. */
5262 unsigned_int_compar (const void *ap
, const void *bp
)
5264 unsigned int a
= *(unsigned int *) ap
;
5265 unsigned int b
= *(unsigned int *) bp
;
5267 return (a
> b
) - (b
> a
);
5270 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5271 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5272 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5275 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5277 struct die_info
*child_die
;
5278 unsigned die_children_count
;
5279 /* CU offsets which were referenced by children of the current DIE. */
5281 unsigned *offsets_end
, *offsetp
;
5282 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5283 struct die_info
*origin_die
;
5284 /* Iterator of the ORIGIN_DIE children. */
5285 struct die_info
*origin_child_die
;
5286 struct cleanup
*cleanups
;
5287 struct attribute
*attr
;
5288 struct dwarf2_cu
*origin_cu
;
5289 struct pending
**origin_previous_list_in_scope
;
5291 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5295 /* Note that following die references may follow to a die in a
5299 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5301 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5303 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5304 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5306 if (die
->tag
!= origin_die
->tag
5307 && !(die
->tag
== DW_TAG_inlined_subroutine
5308 && origin_die
->tag
== DW_TAG_subprogram
))
5309 complaint (&symfile_complaints
,
5310 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5311 die
->offset
, origin_die
->offset
);
5313 child_die
= die
->child
;
5314 die_children_count
= 0;
5315 while (child_die
&& child_die
->tag
)
5317 child_die
= sibling_die (child_die
);
5318 die_children_count
++;
5320 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5321 cleanups
= make_cleanup (xfree
, offsets
);
5323 offsets_end
= offsets
;
5324 child_die
= die
->child
;
5325 while (child_die
&& child_die
->tag
)
5327 /* For each CHILD_DIE, find the corresponding child of
5328 ORIGIN_DIE. If there is more than one layer of
5329 DW_AT_abstract_origin, follow them all; there shouldn't be,
5330 but GCC versions at least through 4.4 generate this (GCC PR
5332 struct die_info
*child_origin_die
= child_die
;
5333 struct dwarf2_cu
*child_origin_cu
= cu
;
5337 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5341 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5345 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5346 counterpart may exist. */
5347 if (child_origin_die
!= child_die
)
5349 if (child_die
->tag
!= child_origin_die
->tag
5350 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5351 && child_origin_die
->tag
== DW_TAG_subprogram
))
5352 complaint (&symfile_complaints
,
5353 _("Child DIE 0x%x and its abstract origin 0x%x have "
5354 "different tags"), child_die
->offset
,
5355 child_origin_die
->offset
);
5356 if (child_origin_die
->parent
!= origin_die
)
5357 complaint (&symfile_complaints
,
5358 _("Child DIE 0x%x and its abstract origin 0x%x have "
5359 "different parents"), child_die
->offset
,
5360 child_origin_die
->offset
);
5362 *offsets_end
++ = child_origin_die
->offset
;
5364 child_die
= sibling_die (child_die
);
5366 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5367 unsigned_int_compar
);
5368 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5369 if (offsetp
[-1] == *offsetp
)
5370 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
5371 "to DIE 0x%x as their abstract origin"),
5372 die
->offset
, *offsetp
);
5375 origin_child_die
= origin_die
->child
;
5376 while (origin_child_die
&& origin_child_die
->tag
)
5378 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5379 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5381 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5383 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5384 process_die (origin_child_die
, origin_cu
);
5386 origin_child_die
= sibling_die (origin_child_die
);
5388 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5390 do_cleanups (cleanups
);
5394 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5396 struct objfile
*objfile
= cu
->objfile
;
5397 struct context_stack
*new;
5400 struct die_info
*child_die
;
5401 struct attribute
*attr
, *call_line
, *call_file
;
5404 struct block
*block
;
5405 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5406 VEC (symbolp
) *template_args
= NULL
;
5407 struct template_symbol
*templ_func
= NULL
;
5411 /* If we do not have call site information, we can't show the
5412 caller of this inlined function. That's too confusing, so
5413 only use the scope for local variables. */
5414 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5415 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5416 if (call_line
== NULL
|| call_file
== NULL
)
5418 read_lexical_block_scope (die
, cu
);
5423 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5425 name
= dwarf2_name (die
, cu
);
5427 /* Ignore functions with missing or empty names. These are actually
5428 illegal according to the DWARF standard. */
5431 complaint (&symfile_complaints
,
5432 _("missing name for subprogram DIE at %d"), die
->offset
);
5436 /* Ignore functions with missing or invalid low and high pc attributes. */
5437 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5439 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5440 if (!attr
|| !DW_UNSND (attr
))
5441 complaint (&symfile_complaints
,
5442 _("cannot get low and high bounds for subprogram DIE at %d"),
5450 /* Record the function range for dwarf_decode_lines. */
5451 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5453 /* If we have any template arguments, then we must allocate a
5454 different sort of symbol. */
5455 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5457 if (child_die
->tag
== DW_TAG_template_type_param
5458 || child_die
->tag
== DW_TAG_template_value_param
)
5460 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5461 struct template_symbol
);
5462 templ_func
->base
.is_cplus_template_function
= 1;
5467 new = push_context (0, lowpc
);
5468 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5469 (struct symbol
*) templ_func
);
5471 /* If there is a location expression for DW_AT_frame_base, record
5473 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5475 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5476 expression is being recorded directly in the function's symbol
5477 and not in a separate frame-base object. I guess this hack is
5478 to avoid adding some sort of frame-base adjunct/annex to the
5479 function's symbol :-(. The problem with doing this is that it
5480 results in a function symbol with a location expression that
5481 has nothing to do with the location of the function, ouch! The
5482 relationship should be: a function's symbol has-a frame base; a
5483 frame-base has-a location expression. */
5484 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5486 cu
->list_in_scope
= &local_symbols
;
5488 if (die
->child
!= NULL
)
5490 child_die
= die
->child
;
5491 while (child_die
&& child_die
->tag
)
5493 if (child_die
->tag
== DW_TAG_template_type_param
5494 || child_die
->tag
== DW_TAG_template_value_param
)
5496 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5499 VEC_safe_push (symbolp
, template_args
, arg
);
5502 process_die (child_die
, cu
);
5503 child_die
= sibling_die (child_die
);
5507 inherit_abstract_dies (die
, cu
);
5509 /* If we have a DW_AT_specification, we might need to import using
5510 directives from the context of the specification DIE. See the
5511 comment in determine_prefix. */
5512 if (cu
->language
== language_cplus
5513 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5515 struct dwarf2_cu
*spec_cu
= cu
;
5516 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5520 child_die
= spec_die
->child
;
5521 while (child_die
&& child_die
->tag
)
5523 if (child_die
->tag
== DW_TAG_imported_module
)
5524 process_die (child_die
, spec_cu
);
5525 child_die
= sibling_die (child_die
);
5528 /* In some cases, GCC generates specification DIEs that
5529 themselves contain DW_AT_specification attributes. */
5530 spec_die
= die_specification (spec_die
, &spec_cu
);
5534 new = pop_context ();
5535 /* Make a block for the local symbols within. */
5536 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5537 lowpc
, highpc
, objfile
);
5539 /* For C++, set the block's scope. */
5540 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5541 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5542 determine_prefix (die
, cu
),
5543 processing_has_namespace_info
);
5545 /* If we have address ranges, record them. */
5546 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5548 /* Attach template arguments to function. */
5549 if (! VEC_empty (symbolp
, template_args
))
5551 gdb_assert (templ_func
!= NULL
);
5553 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5554 templ_func
->template_arguments
5555 = obstack_alloc (&objfile
->objfile_obstack
,
5556 (templ_func
->n_template_arguments
5557 * sizeof (struct symbol
*)));
5558 memcpy (templ_func
->template_arguments
,
5559 VEC_address (symbolp
, template_args
),
5560 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5561 VEC_free (symbolp
, template_args
);
5564 /* In C++, we can have functions nested inside functions (e.g., when
5565 a function declares a class that has methods). This means that
5566 when we finish processing a function scope, we may need to go
5567 back to building a containing block's symbol lists. */
5568 local_symbols
= new->locals
;
5569 param_symbols
= new->params
;
5570 using_directives
= new->using_directives
;
5572 /* If we've finished processing a top-level function, subsequent
5573 symbols go in the file symbol list. */
5574 if (outermost_context_p ())
5575 cu
->list_in_scope
= &file_symbols
;
5578 /* Process all the DIES contained within a lexical block scope. Start
5579 a new scope, process the dies, and then close the scope. */
5582 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5584 struct objfile
*objfile
= cu
->objfile
;
5585 struct context_stack
*new;
5586 CORE_ADDR lowpc
, highpc
;
5587 struct die_info
*child_die
;
5590 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5592 /* Ignore blocks with missing or invalid low and high pc attributes. */
5593 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5594 as multiple lexical blocks? Handling children in a sane way would
5595 be nasty. Might be easier to properly extend generic blocks to
5597 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5602 push_context (0, lowpc
);
5603 if (die
->child
!= NULL
)
5605 child_die
= die
->child
;
5606 while (child_die
&& child_die
->tag
)
5608 process_die (child_die
, cu
);
5609 child_die
= sibling_die (child_die
);
5612 new = pop_context ();
5614 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5617 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5620 /* Note that recording ranges after traversing children, as we
5621 do here, means that recording a parent's ranges entails
5622 walking across all its children's ranges as they appear in
5623 the address map, which is quadratic behavior.
5625 It would be nicer to record the parent's ranges before
5626 traversing its children, simply overriding whatever you find
5627 there. But since we don't even decide whether to create a
5628 block until after we've traversed its children, that's hard
5630 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5632 local_symbols
= new->locals
;
5633 using_directives
= new->using_directives
;
5636 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5637 Return 1 if the attributes are present and valid, otherwise, return 0.
5638 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5641 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5642 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5643 struct partial_symtab
*ranges_pst
)
5645 struct objfile
*objfile
= cu
->objfile
;
5646 struct comp_unit_head
*cu_header
= &cu
->header
;
5647 bfd
*obfd
= objfile
->obfd
;
5648 unsigned int addr_size
= cu_header
->addr_size
;
5649 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5650 /* Base address selection entry. */
5661 found_base
= cu
->base_known
;
5662 base
= cu
->base_address
;
5664 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5665 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5667 complaint (&symfile_complaints
,
5668 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5672 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5674 /* Read in the largest possible address. */
5675 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5676 if ((marker
& mask
) == mask
)
5678 /* If we found the largest possible address, then
5679 read the base address. */
5680 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5681 buffer
+= 2 * addr_size
;
5682 offset
+= 2 * addr_size
;
5688 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5692 CORE_ADDR range_beginning
, range_end
;
5694 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5695 buffer
+= addr_size
;
5696 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5697 buffer
+= addr_size
;
5698 offset
+= 2 * addr_size
;
5700 /* An end of list marker is a pair of zero addresses. */
5701 if (range_beginning
== 0 && range_end
== 0)
5702 /* Found the end of list entry. */
5705 /* Each base address selection entry is a pair of 2 values.
5706 The first is the largest possible address, the second is
5707 the base address. Check for a base address here. */
5708 if ((range_beginning
& mask
) == mask
)
5710 /* If we found the largest possible address, then
5711 read the base address. */
5712 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5719 /* We have no valid base address for the ranges
5721 complaint (&symfile_complaints
,
5722 _("Invalid .debug_ranges data (no base address)"));
5726 range_beginning
+= base
;
5729 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5730 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5731 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5734 /* FIXME: This is recording everything as a low-high
5735 segment of consecutive addresses. We should have a
5736 data structure for discontiguous block ranges
5740 low
= range_beginning
;
5746 if (range_beginning
< low
)
5747 low
= range_beginning
;
5748 if (range_end
> high
)
5754 /* If the first entry is an end-of-list marker, the range
5755 describes an empty scope, i.e. no instructions. */
5761 *high_return
= high
;
5765 /* Get low and high pc attributes from a die. Return 1 if the attributes
5766 are present and valid, otherwise, return 0. Return -1 if the range is
5767 discontinuous, i.e. derived from DW_AT_ranges information. */
5769 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5770 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5771 struct partial_symtab
*pst
)
5773 struct attribute
*attr
;
5778 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5781 high
= DW_ADDR (attr
);
5782 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5784 low
= DW_ADDR (attr
);
5786 /* Found high w/o low attribute. */
5789 /* Found consecutive range of addresses. */
5794 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5797 /* Value of the DW_AT_ranges attribute is the offset in the
5798 .debug_ranges section. */
5799 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5801 /* Found discontinuous range of addresses. */
5809 /* When using the GNU linker, .gnu.linkonce. sections are used to
5810 eliminate duplicate copies of functions and vtables and such.
5811 The linker will arbitrarily choose one and discard the others.
5812 The AT_*_pc values for such functions refer to local labels in
5813 these sections. If the section from that file was discarded, the
5814 labels are not in the output, so the relocs get a value of 0.
5815 If this is a discarded function, mark the pc bounds as invalid,
5816 so that GDB will ignore it. */
5817 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5825 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5826 its low and high PC addresses. Do nothing if these addresses could not
5827 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5828 and HIGHPC to the high address if greater than HIGHPC. */
5831 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5832 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5833 struct dwarf2_cu
*cu
)
5835 CORE_ADDR low
, high
;
5836 struct die_info
*child
= die
->child
;
5838 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5840 *lowpc
= min (*lowpc
, low
);
5841 *highpc
= max (*highpc
, high
);
5844 /* If the language does not allow nested subprograms (either inside
5845 subprograms or lexical blocks), we're done. */
5846 if (cu
->language
!= language_ada
)
5849 /* Check all the children of the given DIE. If it contains nested
5850 subprograms, then check their pc bounds. Likewise, we need to
5851 check lexical blocks as well, as they may also contain subprogram
5853 while (child
&& child
->tag
)
5855 if (child
->tag
== DW_TAG_subprogram
5856 || child
->tag
== DW_TAG_lexical_block
)
5857 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5858 child
= sibling_die (child
);
5862 /* Get the low and high pc's represented by the scope DIE, and store
5863 them in *LOWPC and *HIGHPC. If the correct values can't be
5864 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5867 get_scope_pc_bounds (struct die_info
*die
,
5868 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5869 struct dwarf2_cu
*cu
)
5871 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5872 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5873 CORE_ADDR current_low
, current_high
;
5875 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5877 best_low
= current_low
;
5878 best_high
= current_high
;
5882 struct die_info
*child
= die
->child
;
5884 while (child
&& child
->tag
)
5886 switch (child
->tag
) {
5887 case DW_TAG_subprogram
:
5888 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5890 case DW_TAG_namespace
:
5892 /* FIXME: carlton/2004-01-16: Should we do this for
5893 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5894 that current GCC's always emit the DIEs corresponding
5895 to definitions of methods of classes as children of a
5896 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5897 the DIEs giving the declarations, which could be
5898 anywhere). But I don't see any reason why the
5899 standards says that they have to be there. */
5900 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5902 if (current_low
!= ((CORE_ADDR
) -1))
5904 best_low
= min (best_low
, current_low
);
5905 best_high
= max (best_high
, current_high
);
5913 child
= sibling_die (child
);
5918 *highpc
= best_high
;
5921 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5924 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5925 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5927 struct attribute
*attr
;
5929 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5932 CORE_ADDR high
= DW_ADDR (attr
);
5934 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5937 CORE_ADDR low
= DW_ADDR (attr
);
5939 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5943 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5946 bfd
*obfd
= cu
->objfile
->obfd
;
5948 /* The value of the DW_AT_ranges attribute is the offset of the
5949 address range list in the .debug_ranges section. */
5950 unsigned long offset
= DW_UNSND (attr
);
5951 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5953 /* For some target architectures, but not others, the
5954 read_address function sign-extends the addresses it returns.
5955 To recognize base address selection entries, we need a
5957 unsigned int addr_size
= cu
->header
.addr_size
;
5958 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5960 /* The base address, to which the next pair is relative. Note
5961 that this 'base' is a DWARF concept: most entries in a range
5962 list are relative, to reduce the number of relocs against the
5963 debugging information. This is separate from this function's
5964 'baseaddr' argument, which GDB uses to relocate debugging
5965 information from a shared library based on the address at
5966 which the library was loaded. */
5967 CORE_ADDR base
= cu
->base_address
;
5968 int base_known
= cu
->base_known
;
5970 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5971 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5973 complaint (&symfile_complaints
,
5974 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5981 unsigned int bytes_read
;
5982 CORE_ADDR start
, end
;
5984 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5985 buffer
+= bytes_read
;
5986 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5987 buffer
+= bytes_read
;
5989 /* Did we find the end of the range list? */
5990 if (start
== 0 && end
== 0)
5993 /* Did we find a base address selection entry? */
5994 else if ((start
& base_select_mask
) == base_select_mask
)
6000 /* We found an ordinary address range. */
6005 complaint (&symfile_complaints
,
6006 _("Invalid .debug_ranges data (no base address)"));
6010 record_block_range (block
,
6011 baseaddr
+ base
+ start
,
6012 baseaddr
+ base
+ end
- 1);
6018 /* Add an aggregate field to the field list. */
6021 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6022 struct dwarf2_cu
*cu
)
6024 struct objfile
*objfile
= cu
->objfile
;
6025 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6026 struct nextfield
*new_field
;
6027 struct attribute
*attr
;
6029 char *fieldname
= "";
6031 /* Allocate a new field list entry and link it in. */
6032 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6033 make_cleanup (xfree
, new_field
);
6034 memset (new_field
, 0, sizeof (struct nextfield
));
6036 if (die
->tag
== DW_TAG_inheritance
)
6038 new_field
->next
= fip
->baseclasses
;
6039 fip
->baseclasses
= new_field
;
6043 new_field
->next
= fip
->fields
;
6044 fip
->fields
= new_field
;
6048 /* Handle accessibility and virtuality of field.
6049 The default accessibility for members is public, the default
6050 accessibility for inheritance is private. */
6051 if (die
->tag
!= DW_TAG_inheritance
)
6052 new_field
->accessibility
= DW_ACCESS_public
;
6054 new_field
->accessibility
= DW_ACCESS_private
;
6055 new_field
->virtuality
= DW_VIRTUALITY_none
;
6057 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6059 new_field
->accessibility
= DW_UNSND (attr
);
6060 if (new_field
->accessibility
!= DW_ACCESS_public
)
6061 fip
->non_public_fields
= 1;
6062 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6064 new_field
->virtuality
= DW_UNSND (attr
);
6066 fp
= &new_field
->field
;
6068 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6070 /* Data member other than a C++ static data member. */
6072 /* Get type of field. */
6073 fp
->type
= die_type (die
, cu
);
6075 SET_FIELD_BITPOS (*fp
, 0);
6077 /* Get bit size of field (zero if none). */
6078 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6081 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6085 FIELD_BITSIZE (*fp
) = 0;
6088 /* Get bit offset of field. */
6089 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6092 int byte_offset
= 0;
6094 if (attr_form_is_section_offset (attr
))
6095 dwarf2_complex_location_expr_complaint ();
6096 else if (attr_form_is_constant (attr
))
6097 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6098 else if (attr_form_is_block (attr
))
6099 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6101 dwarf2_complex_location_expr_complaint ();
6103 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6105 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6108 if (gdbarch_bits_big_endian (gdbarch
))
6110 /* For big endian bits, the DW_AT_bit_offset gives the
6111 additional bit offset from the MSB of the containing
6112 anonymous object to the MSB of the field. We don't
6113 have to do anything special since we don't need to
6114 know the size of the anonymous object. */
6115 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6119 /* For little endian bits, compute the bit offset to the
6120 MSB of the anonymous object, subtract off the number of
6121 bits from the MSB of the field to the MSB of the
6122 object, and then subtract off the number of bits of
6123 the field itself. The result is the bit offset of
6124 the LSB of the field. */
6126 int bit_offset
= DW_UNSND (attr
);
6128 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6131 /* The size of the anonymous object containing
6132 the bit field is explicit, so use the
6133 indicated size (in bytes). */
6134 anonymous_size
= DW_UNSND (attr
);
6138 /* The size of the anonymous object containing
6139 the bit field must be inferred from the type
6140 attribute of the data member containing the
6142 anonymous_size
= TYPE_LENGTH (fp
->type
);
6144 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6145 - bit_offset
- FIELD_BITSIZE (*fp
);
6149 /* Get name of field. */
6150 fieldname
= dwarf2_name (die
, cu
);
6151 if (fieldname
== NULL
)
6154 /* The name is already allocated along with this objfile, so we don't
6155 need to duplicate it for the type. */
6156 fp
->name
= fieldname
;
6158 /* Change accessibility for artificial fields (e.g. virtual table
6159 pointer or virtual base class pointer) to private. */
6160 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6162 FIELD_ARTIFICIAL (*fp
) = 1;
6163 new_field
->accessibility
= DW_ACCESS_private
;
6164 fip
->non_public_fields
= 1;
6167 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6169 /* C++ static member. */
6171 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6172 is a declaration, but all versions of G++ as of this writing
6173 (so through at least 3.2.1) incorrectly generate
6174 DW_TAG_variable tags. */
6178 /* Get name of field. */
6179 fieldname
= dwarf2_name (die
, cu
);
6180 if (fieldname
== NULL
)
6183 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6185 /* Only create a symbol if this is an external value.
6186 new_symbol checks this and puts the value in the global symbol
6187 table, which we want. If it is not external, new_symbol
6188 will try to put the value in cu->list_in_scope which is wrong. */
6189 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6191 /* A static const member, not much different than an enum as far as
6192 we're concerned, except that we can support more types. */
6193 new_symbol (die
, NULL
, cu
);
6196 /* Get physical name. */
6197 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6199 /* The name is already allocated along with this objfile, so we don't
6200 need to duplicate it for the type. */
6201 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6202 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6203 FIELD_NAME (*fp
) = fieldname
;
6205 else if (die
->tag
== DW_TAG_inheritance
)
6207 /* C++ base class field. */
6208 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6211 int byte_offset
= 0;
6213 if (attr_form_is_section_offset (attr
))
6214 dwarf2_complex_location_expr_complaint ();
6215 else if (attr_form_is_constant (attr
))
6216 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6217 else if (attr_form_is_block (attr
))
6218 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6220 dwarf2_complex_location_expr_complaint ();
6222 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6224 FIELD_BITSIZE (*fp
) = 0;
6225 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6226 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6227 fip
->nbaseclasses
++;
6231 /* Add a typedef defined in the scope of the FIP's class. */
6234 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6235 struct dwarf2_cu
*cu
)
6237 struct objfile
*objfile
= cu
->objfile
;
6238 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6239 struct typedef_field_list
*new_field
;
6240 struct attribute
*attr
;
6241 struct typedef_field
*fp
;
6242 char *fieldname
= "";
6244 /* Allocate a new field list entry and link it in. */
6245 new_field
= xzalloc (sizeof (*new_field
));
6246 make_cleanup (xfree
, new_field
);
6248 gdb_assert (die
->tag
== DW_TAG_typedef
);
6250 fp
= &new_field
->field
;
6252 /* Get name of field. */
6253 fp
->name
= dwarf2_name (die
, cu
);
6254 if (fp
->name
== NULL
)
6257 fp
->type
= read_type_die (die
, cu
);
6259 new_field
->next
= fip
->typedef_field_list
;
6260 fip
->typedef_field_list
= new_field
;
6261 fip
->typedef_field_list_count
++;
6264 /* Create the vector of fields, and attach it to the type. */
6267 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6268 struct dwarf2_cu
*cu
)
6270 int nfields
= fip
->nfields
;
6272 /* Record the field count, allocate space for the array of fields,
6273 and create blank accessibility bitfields if necessary. */
6274 TYPE_NFIELDS (type
) = nfields
;
6275 TYPE_FIELDS (type
) = (struct field
*)
6276 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6277 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6279 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6281 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6283 TYPE_FIELD_PRIVATE_BITS (type
) =
6284 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6285 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6287 TYPE_FIELD_PROTECTED_BITS (type
) =
6288 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6289 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6291 TYPE_FIELD_IGNORE_BITS (type
) =
6292 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6293 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6296 /* If the type has baseclasses, allocate and clear a bit vector for
6297 TYPE_FIELD_VIRTUAL_BITS. */
6298 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6300 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6301 unsigned char *pointer
;
6303 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6304 pointer
= TYPE_ALLOC (type
, num_bytes
);
6305 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6306 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6307 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6310 /* Copy the saved-up fields into the field vector. Start from the head
6311 of the list, adding to the tail of the field array, so that they end
6312 up in the same order in the array in which they were added to the list. */
6313 while (nfields
-- > 0)
6315 struct nextfield
*fieldp
;
6319 fieldp
= fip
->fields
;
6320 fip
->fields
= fieldp
->next
;
6324 fieldp
= fip
->baseclasses
;
6325 fip
->baseclasses
= fieldp
->next
;
6328 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6329 switch (fieldp
->accessibility
)
6331 case DW_ACCESS_private
:
6332 if (cu
->language
!= language_ada
)
6333 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6336 case DW_ACCESS_protected
:
6337 if (cu
->language
!= language_ada
)
6338 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6341 case DW_ACCESS_public
:
6345 /* Unknown accessibility. Complain and treat it as public. */
6347 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6348 fieldp
->accessibility
);
6352 if (nfields
< fip
->nbaseclasses
)
6354 switch (fieldp
->virtuality
)
6356 case DW_VIRTUALITY_virtual
:
6357 case DW_VIRTUALITY_pure_virtual
:
6358 if (cu
->language
== language_ada
)
6359 error ("unexpected virtuality in component of Ada type");
6360 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6367 /* Add a member function to the proper fieldlist. */
6370 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6371 struct type
*type
, struct dwarf2_cu
*cu
)
6373 struct objfile
*objfile
= cu
->objfile
;
6374 struct attribute
*attr
;
6375 struct fnfieldlist
*flp
;
6377 struct fn_field
*fnp
;
6379 struct nextfnfield
*new_fnfield
;
6380 struct type
*this_type
;
6382 if (cu
->language
== language_ada
)
6383 error ("unexpected member function in Ada type");
6385 /* Get name of member function. */
6386 fieldname
= dwarf2_name (die
, cu
);
6387 if (fieldname
== NULL
)
6390 /* Look up member function name in fieldlist. */
6391 for (i
= 0; i
< fip
->nfnfields
; i
++)
6393 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6397 /* Create new list element if necessary. */
6398 if (i
< fip
->nfnfields
)
6399 flp
= &fip
->fnfieldlists
[i
];
6402 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6404 fip
->fnfieldlists
= (struct fnfieldlist
*)
6405 xrealloc (fip
->fnfieldlists
,
6406 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6407 * sizeof (struct fnfieldlist
));
6408 if (fip
->nfnfields
== 0)
6409 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6411 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6412 flp
->name
= fieldname
;
6415 i
= fip
->nfnfields
++;
6418 /* Create a new member function field and chain it to the field list
6420 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6421 make_cleanup (xfree
, new_fnfield
);
6422 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6423 new_fnfield
->next
= flp
->head
;
6424 flp
->head
= new_fnfield
;
6427 /* Fill in the member function field info. */
6428 fnp
= &new_fnfield
->fnfield
;
6430 /* Delay processing of the physname until later. */
6431 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6433 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6438 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6439 fnp
->physname
= physname
? physname
: "";
6442 fnp
->type
= alloc_type (objfile
);
6443 this_type
= read_type_die (die
, cu
);
6444 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6446 int nparams
= TYPE_NFIELDS (this_type
);
6448 /* TYPE is the domain of this method, and THIS_TYPE is the type
6449 of the method itself (TYPE_CODE_METHOD). */
6450 smash_to_method_type (fnp
->type
, type
,
6451 TYPE_TARGET_TYPE (this_type
),
6452 TYPE_FIELDS (this_type
),
6453 TYPE_NFIELDS (this_type
),
6454 TYPE_VARARGS (this_type
));
6456 /* Handle static member functions.
6457 Dwarf2 has no clean way to discern C++ static and non-static
6458 member functions. G++ helps GDB by marking the first
6459 parameter for non-static member functions (which is the
6460 this pointer) as artificial. We obtain this information
6461 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6462 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6463 fnp
->voffset
= VOFFSET_STATIC
;
6466 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6467 dwarf2_full_name (fieldname
, die
, cu
));
6469 /* Get fcontext from DW_AT_containing_type if present. */
6470 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6471 fnp
->fcontext
= die_containing_type (die
, cu
);
6473 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6474 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6476 /* Get accessibility. */
6477 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6480 switch (DW_UNSND (attr
))
6482 case DW_ACCESS_private
:
6483 fnp
->is_private
= 1;
6485 case DW_ACCESS_protected
:
6486 fnp
->is_protected
= 1;
6491 /* Check for artificial methods. */
6492 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6493 if (attr
&& DW_UNSND (attr
) != 0)
6494 fnp
->is_artificial
= 1;
6496 /* Get index in virtual function table if it is a virtual member
6497 function. For older versions of GCC, this is an offset in the
6498 appropriate virtual table, as specified by DW_AT_containing_type.
6499 For everyone else, it is an expression to be evaluated relative
6500 to the object address. */
6502 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6505 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6507 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6509 /* Old-style GCC. */
6510 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6512 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6513 || (DW_BLOCK (attr
)->size
> 1
6514 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6515 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6517 struct dwarf_block blk
;
6520 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6522 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6523 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6524 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6525 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6526 dwarf2_complex_location_expr_complaint ();
6528 fnp
->voffset
/= cu
->header
.addr_size
;
6532 dwarf2_complex_location_expr_complaint ();
6535 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6537 else if (attr_form_is_section_offset (attr
))
6539 dwarf2_complex_location_expr_complaint ();
6543 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6549 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6550 if (attr
&& DW_UNSND (attr
))
6552 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6553 complaint (&symfile_complaints
,
6554 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6555 fieldname
, die
->offset
);
6556 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6557 TYPE_CPLUS_DYNAMIC (type
) = 1;
6562 /* Create the vector of member function fields, and attach it to the type. */
6565 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6566 struct dwarf2_cu
*cu
)
6568 struct fnfieldlist
*flp
;
6569 int total_length
= 0;
6572 if (cu
->language
== language_ada
)
6573 error ("unexpected member functions in Ada type");
6575 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6576 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6577 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6579 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6581 struct nextfnfield
*nfp
= flp
->head
;
6582 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6585 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6586 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6587 fn_flp
->fn_fields
= (struct fn_field
*)
6588 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6589 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6590 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6592 total_length
+= flp
->length
;
6595 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6596 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6599 /* Returns non-zero if NAME is the name of a vtable member in CU's
6600 language, zero otherwise. */
6602 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6604 static const char vptr
[] = "_vptr";
6605 static const char vtable
[] = "vtable";
6607 /* Look for the C++ and Java forms of the vtable. */
6608 if ((cu
->language
== language_java
6609 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6610 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6611 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6617 /* GCC outputs unnamed structures that are really pointers to member
6618 functions, with the ABI-specified layout. If TYPE describes
6619 such a structure, smash it into a member function type.
6621 GCC shouldn't do this; it should just output pointer to member DIEs.
6622 This is GCC PR debug/28767. */
6625 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6627 struct type
*pfn_type
, *domain_type
, *new_type
;
6629 /* Check for a structure with no name and two children. */
6630 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6633 /* Check for __pfn and __delta members. */
6634 if (TYPE_FIELD_NAME (type
, 0) == NULL
6635 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6636 || TYPE_FIELD_NAME (type
, 1) == NULL
6637 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6640 /* Find the type of the method. */
6641 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6642 if (pfn_type
== NULL
6643 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6644 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6647 /* Look for the "this" argument. */
6648 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6649 if (TYPE_NFIELDS (pfn_type
) == 0
6650 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6651 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6654 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6655 new_type
= alloc_type (objfile
);
6656 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6657 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6658 TYPE_VARARGS (pfn_type
));
6659 smash_to_methodptr_type (type
, new_type
);
6662 /* Called when we find the DIE that starts a structure or union scope
6663 (definition) to create a type for the structure or union. Fill in
6664 the type's name and general properties; the members will not be
6665 processed until process_structure_type.
6667 NOTE: we need to call these functions regardless of whether or not the
6668 DIE has a DW_AT_name attribute, since it might be an anonymous
6669 structure or union. This gets the type entered into our set of
6672 However, if the structure is incomplete (an opaque struct/union)
6673 then suppress creating a symbol table entry for it since gdb only
6674 wants to find the one with the complete definition. Note that if
6675 it is complete, we just call new_symbol, which does it's own
6676 checking about whether the struct/union is anonymous or not (and
6677 suppresses creating a symbol table entry itself). */
6679 static struct type
*
6680 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6682 struct objfile
*objfile
= cu
->objfile
;
6684 struct attribute
*attr
;
6687 /* If the definition of this type lives in .debug_types, read that type.
6688 Don't follow DW_AT_specification though, that will take us back up
6689 the chain and we want to go down. */
6690 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6693 struct dwarf2_cu
*type_cu
= cu
;
6694 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6696 /* We could just recurse on read_structure_type, but we need to call
6697 get_die_type to ensure only one type for this DIE is created.
6698 This is important, for example, because for c++ classes we need
6699 TYPE_NAME set which is only done by new_symbol. Blech. */
6700 type
= read_type_die (type_die
, type_cu
);
6702 /* TYPE_CU may not be the same as CU.
6703 Ensure TYPE is recorded in CU's type_hash table. */
6704 return set_die_type (die
, type
, cu
);
6707 type
= alloc_type (objfile
);
6708 INIT_CPLUS_SPECIFIC (type
);
6710 name
= dwarf2_name (die
, cu
);
6713 if (cu
->language
== language_cplus
6714 || cu
->language
== language_java
)
6716 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6718 /* dwarf2_full_name might have already finished building the DIE's
6719 type. If so, there is no need to continue. */
6720 if (get_die_type (die
, cu
) != NULL
)
6721 return get_die_type (die
, cu
);
6723 TYPE_TAG_NAME (type
) = full_name
;
6724 if (die
->tag
== DW_TAG_structure_type
6725 || die
->tag
== DW_TAG_class_type
)
6726 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6730 /* The name is already allocated along with this objfile, so
6731 we don't need to duplicate it for the type. */
6732 TYPE_TAG_NAME (type
) = (char *) name
;
6733 if (die
->tag
== DW_TAG_class_type
)
6734 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6738 if (die
->tag
== DW_TAG_structure_type
)
6740 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6742 else if (die
->tag
== DW_TAG_union_type
)
6744 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6748 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6751 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6752 TYPE_DECLARED_CLASS (type
) = 1;
6754 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6757 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6761 TYPE_LENGTH (type
) = 0;
6764 TYPE_STUB_SUPPORTED (type
) = 1;
6765 if (die_is_declaration (die
, cu
))
6766 TYPE_STUB (type
) = 1;
6767 else if (attr
== NULL
&& die
->child
== NULL
6768 && producer_is_realview (cu
->producer
))
6769 /* RealView does not output the required DW_AT_declaration
6770 on incomplete types. */
6771 TYPE_STUB (type
) = 1;
6773 /* We need to add the type field to the die immediately so we don't
6774 infinitely recurse when dealing with pointers to the structure
6775 type within the structure itself. */
6776 set_die_type (die
, type
, cu
);
6778 /* set_die_type should be already done. */
6779 set_descriptive_type (type
, die
, cu
);
6784 /* Finish creating a structure or union type, including filling in
6785 its members and creating a symbol for it. */
6788 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6790 struct objfile
*objfile
= cu
->objfile
;
6791 struct die_info
*child_die
= die
->child
;
6794 type
= get_die_type (die
, cu
);
6796 type
= read_structure_type (die
, cu
);
6798 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6800 struct field_info fi
;
6801 struct die_info
*child_die
;
6802 VEC (symbolp
) *template_args
= NULL
;
6803 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6805 memset (&fi
, 0, sizeof (struct field_info
));
6807 child_die
= die
->child
;
6809 while (child_die
&& child_die
->tag
)
6811 if (child_die
->tag
== DW_TAG_member
6812 || child_die
->tag
== DW_TAG_variable
)
6814 /* NOTE: carlton/2002-11-05: A C++ static data member
6815 should be a DW_TAG_member that is a declaration, but
6816 all versions of G++ as of this writing (so through at
6817 least 3.2.1) incorrectly generate DW_TAG_variable
6818 tags for them instead. */
6819 dwarf2_add_field (&fi
, child_die
, cu
);
6821 else if (child_die
->tag
== DW_TAG_subprogram
)
6823 /* C++ member function. */
6824 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6826 else if (child_die
->tag
== DW_TAG_inheritance
)
6828 /* C++ base class field. */
6829 dwarf2_add_field (&fi
, child_die
, cu
);
6831 else if (child_die
->tag
== DW_TAG_typedef
)
6832 dwarf2_add_typedef (&fi
, child_die
, cu
);
6833 else if (child_die
->tag
== DW_TAG_template_type_param
6834 || child_die
->tag
== DW_TAG_template_value_param
)
6836 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6839 VEC_safe_push (symbolp
, template_args
, arg
);
6842 child_die
= sibling_die (child_die
);
6845 /* Attach template arguments to type. */
6846 if (! VEC_empty (symbolp
, template_args
))
6848 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6849 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6850 = VEC_length (symbolp
, template_args
);
6851 TYPE_TEMPLATE_ARGUMENTS (type
)
6852 = obstack_alloc (&objfile
->objfile_obstack
,
6853 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6854 * sizeof (struct symbol
*)));
6855 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6856 VEC_address (symbolp
, template_args
),
6857 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6858 * sizeof (struct symbol
*)));
6859 VEC_free (symbolp
, template_args
);
6862 /* Attach fields and member functions to the type. */
6864 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6867 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6869 /* Get the type which refers to the base class (possibly this
6870 class itself) which contains the vtable pointer for the current
6871 class from the DW_AT_containing_type attribute. This use of
6872 DW_AT_containing_type is a GNU extension. */
6874 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6876 struct type
*t
= die_containing_type (die
, cu
);
6878 TYPE_VPTR_BASETYPE (type
) = t
;
6883 /* Our own class provides vtbl ptr. */
6884 for (i
= TYPE_NFIELDS (t
) - 1;
6885 i
>= TYPE_N_BASECLASSES (t
);
6888 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6890 if (is_vtable_name (fieldname
, cu
))
6892 TYPE_VPTR_FIELDNO (type
) = i
;
6897 /* Complain if virtual function table field not found. */
6898 if (i
< TYPE_N_BASECLASSES (t
))
6899 complaint (&symfile_complaints
,
6900 _("virtual function table pointer not found when defining class '%s'"),
6901 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6906 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6909 else if (cu
->producer
6910 && strncmp (cu
->producer
,
6911 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6913 /* The IBM XLC compiler does not provide direct indication
6914 of the containing type, but the vtable pointer is
6915 always named __vfp. */
6919 for (i
= TYPE_NFIELDS (type
) - 1;
6920 i
>= TYPE_N_BASECLASSES (type
);
6923 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6925 TYPE_VPTR_FIELDNO (type
) = i
;
6926 TYPE_VPTR_BASETYPE (type
) = type
;
6933 /* Copy fi.typedef_field_list linked list elements content into the
6934 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6935 if (fi
.typedef_field_list
)
6937 int i
= fi
.typedef_field_list_count
;
6939 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6940 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6941 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6942 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6944 /* Reverse the list order to keep the debug info elements order. */
6947 struct typedef_field
*dest
, *src
;
6949 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6950 src
= &fi
.typedef_field_list
->field
;
6951 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6956 do_cleanups (back_to
);
6959 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6961 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6962 snapshots) has been known to create a die giving a declaration
6963 for a class that has, as a child, a die giving a definition for a
6964 nested class. So we have to process our children even if the
6965 current die is a declaration. Normally, of course, a declaration
6966 won't have any children at all. */
6968 while (child_die
!= NULL
&& child_die
->tag
)
6970 if (child_die
->tag
== DW_TAG_member
6971 || child_die
->tag
== DW_TAG_variable
6972 || child_die
->tag
== DW_TAG_inheritance
6973 || child_die
->tag
== DW_TAG_template_value_param
6974 || child_die
->tag
== DW_TAG_template_type_param
)
6979 process_die (child_die
, cu
);
6981 child_die
= sibling_die (child_die
);
6984 /* Do not consider external references. According to the DWARF standard,
6985 these DIEs are identified by the fact that they have no byte_size
6986 attribute, and a declaration attribute. */
6987 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6988 || !die_is_declaration (die
, cu
))
6989 new_symbol (die
, type
, cu
);
6992 /* Given a DW_AT_enumeration_type die, set its type. We do not
6993 complete the type's fields yet, or create any symbols. */
6995 static struct type
*
6996 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6998 struct objfile
*objfile
= cu
->objfile
;
7000 struct attribute
*attr
;
7003 /* If the definition of this type lives in .debug_types, read that type.
7004 Don't follow DW_AT_specification though, that will take us back up
7005 the chain and we want to go down. */
7006 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7009 struct dwarf2_cu
*type_cu
= cu
;
7010 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7012 type
= read_type_die (type_die
, type_cu
);
7014 /* TYPE_CU may not be the same as CU.
7015 Ensure TYPE is recorded in CU's type_hash table. */
7016 return set_die_type (die
, type
, cu
);
7019 type
= alloc_type (objfile
);
7021 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7022 name
= dwarf2_full_name (NULL
, die
, cu
);
7024 TYPE_TAG_NAME (type
) = (char *) name
;
7026 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7029 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7033 TYPE_LENGTH (type
) = 0;
7036 /* The enumeration DIE can be incomplete. In Ada, any type can be
7037 declared as private in the package spec, and then defined only
7038 inside the package body. Such types are known as Taft Amendment
7039 Types. When another package uses such a type, an incomplete DIE
7040 may be generated by the compiler. */
7041 if (die_is_declaration (die
, cu
))
7042 TYPE_STUB (type
) = 1;
7044 return set_die_type (die
, type
, cu
);
7047 /* Given a pointer to a die which begins an enumeration, process all
7048 the dies that define the members of the enumeration, and create the
7049 symbol for the enumeration type.
7051 NOTE: We reverse the order of the element list. */
7054 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7056 struct type
*this_type
;
7058 this_type
= get_die_type (die
, cu
);
7059 if (this_type
== NULL
)
7060 this_type
= read_enumeration_type (die
, cu
);
7062 if (die
->child
!= NULL
)
7064 struct die_info
*child_die
;
7066 struct field
*fields
= NULL
;
7068 int unsigned_enum
= 1;
7071 child_die
= die
->child
;
7072 while (child_die
&& child_die
->tag
)
7074 if (child_die
->tag
!= DW_TAG_enumerator
)
7076 process_die (child_die
, cu
);
7080 name
= dwarf2_name (child_die
, cu
);
7083 sym
= new_symbol (child_die
, this_type
, cu
);
7084 if (SYMBOL_VALUE (sym
) < 0)
7087 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7089 fields
= (struct field
*)
7091 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7092 * sizeof (struct field
));
7095 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7096 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7097 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7098 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7104 child_die
= sibling_die (child_die
);
7109 TYPE_NFIELDS (this_type
) = num_fields
;
7110 TYPE_FIELDS (this_type
) = (struct field
*)
7111 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7112 memcpy (TYPE_FIELDS (this_type
), fields
,
7113 sizeof (struct field
) * num_fields
);
7117 TYPE_UNSIGNED (this_type
) = 1;
7120 new_symbol (die
, this_type
, cu
);
7123 /* Extract all information from a DW_TAG_array_type DIE and put it in
7124 the DIE's type field. For now, this only handles one dimensional
7127 static struct type
*
7128 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7130 struct objfile
*objfile
= cu
->objfile
;
7131 struct die_info
*child_die
;
7133 struct type
*element_type
, *range_type
, *index_type
;
7134 struct type
**range_types
= NULL
;
7135 struct attribute
*attr
;
7137 struct cleanup
*back_to
;
7140 element_type
= die_type (die
, cu
);
7142 /* The die_type call above may have already set the type for this DIE. */
7143 type
= get_die_type (die
, cu
);
7147 /* Irix 6.2 native cc creates array types without children for
7148 arrays with unspecified length. */
7149 if (die
->child
== NULL
)
7151 index_type
= objfile_type (objfile
)->builtin_int
;
7152 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7153 type
= create_array_type (NULL
, element_type
, range_type
);
7154 return set_die_type (die
, type
, cu
);
7157 back_to
= make_cleanup (null_cleanup
, NULL
);
7158 child_die
= die
->child
;
7159 while (child_die
&& child_die
->tag
)
7161 if (child_die
->tag
== DW_TAG_subrange_type
)
7163 struct type
*child_type
= read_type_die (child_die
, cu
);
7165 if (child_type
!= NULL
)
7167 /* The range type was succesfully read. Save it for
7168 the array type creation. */
7169 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7171 range_types
= (struct type
**)
7172 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7173 * sizeof (struct type
*));
7175 make_cleanup (free_current_contents
, &range_types
);
7177 range_types
[ndim
++] = child_type
;
7180 child_die
= sibling_die (child_die
);
7183 /* Dwarf2 dimensions are output from left to right, create the
7184 necessary array types in backwards order. */
7186 type
= element_type
;
7188 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7193 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7198 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7201 /* Understand Dwarf2 support for vector types (like they occur on
7202 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7203 array type. This is not part of the Dwarf2/3 standard yet, but a
7204 custom vendor extension. The main difference between a regular
7205 array and the vector variant is that vectors are passed by value
7207 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7209 make_vector_type (type
);
7211 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7212 implementation may choose to implement triple vectors using this
7214 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7217 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7218 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7220 complaint (&symfile_complaints
, _("\
7221 DW_AT_byte_size for array type smaller than the total size of elements"));
7224 name
= dwarf2_name (die
, cu
);
7226 TYPE_NAME (type
) = name
;
7228 /* Install the type in the die. */
7229 set_die_type (die
, type
, cu
);
7231 /* set_die_type should be already done. */
7232 set_descriptive_type (type
, die
, cu
);
7234 do_cleanups (back_to
);
7239 static enum dwarf_array_dim_ordering
7240 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7242 struct attribute
*attr
;
7244 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7246 if (attr
) return DW_SND (attr
);
7249 GNU F77 is a special case, as at 08/2004 array type info is the
7250 opposite order to the dwarf2 specification, but data is still
7251 laid out as per normal fortran.
7253 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7257 if (cu
->language
== language_fortran
7258 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7260 return DW_ORD_row_major
;
7263 switch (cu
->language_defn
->la_array_ordering
)
7265 case array_column_major
:
7266 return DW_ORD_col_major
;
7267 case array_row_major
:
7269 return DW_ORD_row_major
;
7273 /* Extract all information from a DW_TAG_set_type DIE and put it in
7274 the DIE's type field. */
7276 static struct type
*
7277 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7279 struct type
*domain_type
, *set_type
;
7280 struct attribute
*attr
;
7282 domain_type
= die_type (die
, cu
);
7284 /* The die_type call above may have already set the type for this DIE. */
7285 set_type
= get_die_type (die
, cu
);
7289 set_type
= create_set_type (NULL
, domain_type
);
7291 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7293 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7295 return set_die_type (die
, set_type
, cu
);
7298 /* First cut: install each common block member as a global variable. */
7301 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7303 struct die_info
*child_die
;
7304 struct attribute
*attr
;
7306 CORE_ADDR base
= (CORE_ADDR
) 0;
7308 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7311 /* Support the .debug_loc offsets */
7312 if (attr_form_is_block (attr
))
7314 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7316 else if (attr_form_is_section_offset (attr
))
7318 dwarf2_complex_location_expr_complaint ();
7322 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7323 "common block member");
7326 if (die
->child
!= NULL
)
7328 child_die
= die
->child
;
7329 while (child_die
&& child_die
->tag
)
7331 sym
= new_symbol (child_die
, NULL
, cu
);
7332 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7333 if (sym
!= NULL
&& attr
!= NULL
)
7335 CORE_ADDR byte_offset
= 0;
7337 if (attr_form_is_section_offset (attr
))
7338 dwarf2_complex_location_expr_complaint ();
7339 else if (attr_form_is_constant (attr
))
7340 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7341 else if (attr_form_is_block (attr
))
7342 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7344 dwarf2_complex_location_expr_complaint ();
7346 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7347 add_symbol_to_list (sym
, &global_symbols
);
7349 child_die
= sibling_die (child_die
);
7354 /* Create a type for a C++ namespace. */
7356 static struct type
*
7357 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7359 struct objfile
*objfile
= cu
->objfile
;
7360 const char *previous_prefix
, *name
;
7364 /* For extensions, reuse the type of the original namespace. */
7365 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7367 struct die_info
*ext_die
;
7368 struct dwarf2_cu
*ext_cu
= cu
;
7370 ext_die
= dwarf2_extension (die
, &ext_cu
);
7371 type
= read_type_die (ext_die
, ext_cu
);
7373 /* EXT_CU may not be the same as CU.
7374 Ensure TYPE is recorded in CU's type_hash table. */
7375 return set_die_type (die
, type
, cu
);
7378 name
= namespace_name (die
, &is_anonymous
, cu
);
7380 /* Now build the name of the current namespace. */
7382 previous_prefix
= determine_prefix (die
, cu
);
7383 if (previous_prefix
[0] != '\0')
7384 name
= typename_concat (&objfile
->objfile_obstack
,
7385 previous_prefix
, name
, 0, cu
);
7387 /* Create the type. */
7388 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7390 TYPE_NAME (type
) = (char *) name
;
7391 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7393 return set_die_type (die
, type
, cu
);
7396 /* Read a C++ namespace. */
7399 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7401 struct objfile
*objfile
= cu
->objfile
;
7405 /* Add a symbol associated to this if we haven't seen the namespace
7406 before. Also, add a using directive if it's an anonymous
7409 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7413 type
= read_type_die (die
, cu
);
7414 new_symbol (die
, type
, cu
);
7416 name
= namespace_name (die
, &is_anonymous
, cu
);
7419 const char *previous_prefix
= determine_prefix (die
, cu
);
7421 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7422 NULL
, &objfile
->objfile_obstack
);
7426 if (die
->child
!= NULL
)
7428 struct die_info
*child_die
= die
->child
;
7430 while (child_die
&& child_die
->tag
)
7432 process_die (child_die
, cu
);
7433 child_die
= sibling_die (child_die
);
7438 /* Read a Fortran module as type. This DIE can be only a declaration used for
7439 imported module. Still we need that type as local Fortran "use ... only"
7440 declaration imports depend on the created type in determine_prefix. */
7442 static struct type
*
7443 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7445 struct objfile
*objfile
= cu
->objfile
;
7449 module_name
= dwarf2_name (die
, cu
);
7451 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
7453 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7455 /* determine_prefix uses TYPE_TAG_NAME. */
7456 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7458 return set_die_type (die
, type
, cu
);
7461 /* Read a Fortran module. */
7464 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7466 struct die_info
*child_die
= die
->child
;
7468 while (child_die
&& child_die
->tag
)
7470 process_die (child_die
, cu
);
7471 child_die
= sibling_die (child_die
);
7475 /* Return the name of the namespace represented by DIE. Set
7476 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7480 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7482 struct die_info
*current_die
;
7483 const char *name
= NULL
;
7485 /* Loop through the extensions until we find a name. */
7487 for (current_die
= die
;
7488 current_die
!= NULL
;
7489 current_die
= dwarf2_extension (die
, &cu
))
7491 name
= dwarf2_name (current_die
, cu
);
7496 /* Is it an anonymous namespace? */
7498 *is_anonymous
= (name
== NULL
);
7500 name
= "(anonymous namespace)";
7505 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7506 the user defined type vector. */
7508 static struct type
*
7509 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7511 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7512 struct comp_unit_head
*cu_header
= &cu
->header
;
7514 struct attribute
*attr_byte_size
;
7515 struct attribute
*attr_address_class
;
7516 int byte_size
, addr_class
;
7517 struct type
*target_type
;
7519 target_type
= die_type (die
, cu
);
7521 /* The die_type call above may have already set the type for this DIE. */
7522 type
= get_die_type (die
, cu
);
7526 type
= lookup_pointer_type (target_type
);
7528 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7530 byte_size
= DW_UNSND (attr_byte_size
);
7532 byte_size
= cu_header
->addr_size
;
7534 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7535 if (attr_address_class
)
7536 addr_class
= DW_UNSND (attr_address_class
);
7538 addr_class
= DW_ADDR_none
;
7540 /* If the pointer size or address class is different than the
7541 default, create a type variant marked as such and set the
7542 length accordingly. */
7543 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7545 if (gdbarch_address_class_type_flags_p (gdbarch
))
7549 type_flags
= gdbarch_address_class_type_flags
7550 (gdbarch
, byte_size
, addr_class
);
7551 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7553 type
= make_type_with_address_space (type
, type_flags
);
7555 else if (TYPE_LENGTH (type
) != byte_size
)
7557 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
7561 /* Should we also complain about unhandled address classes? */
7565 TYPE_LENGTH (type
) = byte_size
;
7566 return set_die_type (die
, type
, cu
);
7569 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7570 the user defined type vector. */
7572 static struct type
*
7573 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7576 struct type
*to_type
;
7577 struct type
*domain
;
7579 to_type
= die_type (die
, cu
);
7580 domain
= die_containing_type (die
, cu
);
7582 /* The calls above may have already set the type for this DIE. */
7583 type
= get_die_type (die
, cu
);
7587 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7588 type
= lookup_methodptr_type (to_type
);
7590 type
= lookup_memberptr_type (to_type
, domain
);
7592 return set_die_type (die
, type
, cu
);
7595 /* Extract all information from a DW_TAG_reference_type DIE and add to
7596 the user defined type vector. */
7598 static struct type
*
7599 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7601 struct comp_unit_head
*cu_header
= &cu
->header
;
7602 struct type
*type
, *target_type
;
7603 struct attribute
*attr
;
7605 target_type
= die_type (die
, cu
);
7607 /* The die_type call above may have already set the type for this DIE. */
7608 type
= get_die_type (die
, cu
);
7612 type
= lookup_reference_type (target_type
);
7613 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7616 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7620 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7622 return set_die_type (die
, type
, cu
);
7625 static struct type
*
7626 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7628 struct type
*base_type
, *cv_type
;
7630 base_type
= die_type (die
, cu
);
7632 /* The die_type call above may have already set the type for this DIE. */
7633 cv_type
= get_die_type (die
, cu
);
7637 /* In case the const qualifier is applied to an array type, the element type
7638 is so qualified, not the array type (section 6.7.3 of C99). */
7639 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7641 struct type
*el_type
, *inner_array
;
7643 base_type
= copy_type (base_type
);
7644 inner_array
= base_type
;
7646 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7648 TYPE_TARGET_TYPE (inner_array
) =
7649 copy_type (TYPE_TARGET_TYPE (inner_array
));
7650 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7653 el_type
= TYPE_TARGET_TYPE (inner_array
);
7654 TYPE_TARGET_TYPE (inner_array
) =
7655 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7657 return set_die_type (die
, base_type
, cu
);
7660 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7661 return set_die_type (die
, cv_type
, cu
);
7664 static struct type
*
7665 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7667 struct type
*base_type
, *cv_type
;
7669 base_type
= die_type (die
, cu
);
7671 /* The die_type call above may have already set the type for this DIE. */
7672 cv_type
= get_die_type (die
, cu
);
7676 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7677 return set_die_type (die
, cv_type
, cu
);
7680 /* Extract all information from a DW_TAG_string_type DIE and add to
7681 the user defined type vector. It isn't really a user defined type,
7682 but it behaves like one, with other DIE's using an AT_user_def_type
7683 attribute to reference it. */
7685 static struct type
*
7686 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7688 struct objfile
*objfile
= cu
->objfile
;
7689 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7690 struct type
*type
, *range_type
, *index_type
, *char_type
;
7691 struct attribute
*attr
;
7692 unsigned int length
;
7694 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7697 length
= DW_UNSND (attr
);
7701 /* check for the DW_AT_byte_size attribute */
7702 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7705 length
= DW_UNSND (attr
);
7713 index_type
= objfile_type (objfile
)->builtin_int
;
7714 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7715 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7716 type
= create_string_type (NULL
, char_type
, range_type
);
7718 return set_die_type (die
, type
, cu
);
7721 /* Handle DIES due to C code like:
7725 int (*funcp)(int a, long l);
7729 ('funcp' generates a DW_TAG_subroutine_type DIE)
7732 static struct type
*
7733 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7735 struct type
*type
; /* Type that this function returns */
7736 struct type
*ftype
; /* Function that returns above type */
7737 struct attribute
*attr
;
7739 type
= die_type (die
, cu
);
7741 /* The die_type call above may have already set the type for this DIE. */
7742 ftype
= get_die_type (die
, cu
);
7746 ftype
= lookup_function_type (type
);
7748 /* All functions in C++, Pascal and Java have prototypes. */
7749 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7750 if ((attr
&& (DW_UNSND (attr
) != 0))
7751 || cu
->language
== language_cplus
7752 || cu
->language
== language_java
7753 || cu
->language
== language_pascal
)
7754 TYPE_PROTOTYPED (ftype
) = 1;
7755 else if (producer_is_realview (cu
->producer
))
7756 /* RealView does not emit DW_AT_prototyped. We can not
7757 distinguish prototyped and unprototyped functions; default to
7758 prototyped, since that is more common in modern code (and
7759 RealView warns about unprototyped functions). */
7760 TYPE_PROTOTYPED (ftype
) = 1;
7762 /* Store the calling convention in the type if it's available in
7763 the subroutine die. Otherwise set the calling convention to
7764 the default value DW_CC_normal. */
7765 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7766 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7768 /* We need to add the subroutine type to the die immediately so
7769 we don't infinitely recurse when dealing with parameters
7770 declared as the same subroutine type. */
7771 set_die_type (die
, ftype
, cu
);
7773 if (die
->child
!= NULL
)
7775 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7776 struct die_info
*child_die
;
7777 int nparams
, iparams
;
7779 /* Count the number of parameters.
7780 FIXME: GDB currently ignores vararg functions, but knows about
7781 vararg member functions. */
7783 child_die
= die
->child
;
7784 while (child_die
&& child_die
->tag
)
7786 if (child_die
->tag
== DW_TAG_formal_parameter
)
7788 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7789 TYPE_VARARGS (ftype
) = 1;
7790 child_die
= sibling_die (child_die
);
7793 /* Allocate storage for parameters and fill them in. */
7794 TYPE_NFIELDS (ftype
) = nparams
;
7795 TYPE_FIELDS (ftype
) = (struct field
*)
7796 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7798 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7799 even if we error out during the parameters reading below. */
7800 for (iparams
= 0; iparams
< nparams
; iparams
++)
7801 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7804 child_die
= die
->child
;
7805 while (child_die
&& child_die
->tag
)
7807 if (child_die
->tag
== DW_TAG_formal_parameter
)
7809 struct type
*arg_type
;
7811 /* DWARF version 2 has no clean way to discern C++
7812 static and non-static member functions. G++ helps
7813 GDB by marking the first parameter for non-static
7814 member functions (which is the this pointer) as
7815 artificial. We pass this information to
7816 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7818 DWARF version 3 added DW_AT_object_pointer, which GCC
7819 4.5 does not yet generate. */
7820 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7822 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7825 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7827 /* GCC/43521: In java, the formal parameter
7828 "this" is sometimes not marked with DW_AT_artificial. */
7829 if (cu
->language
== language_java
)
7831 const char *name
= dwarf2_name (child_die
, cu
);
7833 if (name
&& !strcmp (name
, "this"))
7834 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7837 arg_type
= die_type (child_die
, cu
);
7839 /* RealView does not mark THIS as const, which the testsuite
7840 expects. GCC marks THIS as const in method definitions,
7841 but not in the class specifications (GCC PR 43053). */
7842 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7843 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7846 struct dwarf2_cu
*arg_cu
= cu
;
7847 const char *name
= dwarf2_name (child_die
, cu
);
7849 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7852 /* If the compiler emits this, use it. */
7853 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
7856 else if (name
&& strcmp (name
, "this") == 0)
7857 /* Function definitions will have the argument names. */
7859 else if (name
== NULL
&& iparams
== 0)
7860 /* Declarations may not have the names, so like
7861 elsewhere in GDB, assume an artificial first
7862 argument is "this". */
7866 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
7870 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
7873 child_die
= sibling_die (child_die
);
7880 static struct type
*
7881 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7883 struct objfile
*objfile
= cu
->objfile
;
7884 const char *name
= NULL
;
7885 struct type
*this_type
;
7887 name
= dwarf2_full_name (NULL
, die
, cu
);
7888 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7889 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7890 TYPE_NAME (this_type
) = (char *) name
;
7891 set_die_type (die
, this_type
, cu
);
7892 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7896 /* Find a representation of a given base type and install
7897 it in the TYPE field of the die. */
7899 static struct type
*
7900 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7902 struct objfile
*objfile
= cu
->objfile
;
7904 struct attribute
*attr
;
7905 int encoding
= 0, size
= 0;
7907 enum type_code code
= TYPE_CODE_INT
;
7909 struct type
*target_type
= NULL
;
7911 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7914 encoding
= DW_UNSND (attr
);
7916 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7919 size
= DW_UNSND (attr
);
7921 name
= dwarf2_name (die
, cu
);
7924 complaint (&symfile_complaints
,
7925 _("DW_AT_name missing from DW_TAG_base_type"));
7930 case DW_ATE_address
:
7931 /* Turn DW_ATE_address into a void * pointer. */
7932 code
= TYPE_CODE_PTR
;
7933 type_flags
|= TYPE_FLAG_UNSIGNED
;
7934 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7936 case DW_ATE_boolean
:
7937 code
= TYPE_CODE_BOOL
;
7938 type_flags
|= TYPE_FLAG_UNSIGNED
;
7940 case DW_ATE_complex_float
:
7941 code
= TYPE_CODE_COMPLEX
;
7942 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7944 case DW_ATE_decimal_float
:
7945 code
= TYPE_CODE_DECFLOAT
;
7948 code
= TYPE_CODE_FLT
;
7952 case DW_ATE_unsigned
:
7953 type_flags
|= TYPE_FLAG_UNSIGNED
;
7955 case DW_ATE_signed_char
:
7956 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7957 || cu
->language
== language_pascal
)
7958 code
= TYPE_CODE_CHAR
;
7960 case DW_ATE_unsigned_char
:
7961 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7962 || cu
->language
== language_pascal
)
7963 code
= TYPE_CODE_CHAR
;
7964 type_flags
|= TYPE_FLAG_UNSIGNED
;
7967 /* We just treat this as an integer and then recognize the
7968 type by name elsewhere. */
7972 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7973 dwarf_type_encoding_name (encoding
));
7977 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7978 TYPE_NAME (type
) = name
;
7979 TYPE_TARGET_TYPE (type
) = target_type
;
7981 if (name
&& strcmp (name
, "char") == 0)
7982 TYPE_NOSIGN (type
) = 1;
7984 return set_die_type (die
, type
, cu
);
7987 /* Read the given DW_AT_subrange DIE. */
7989 static struct type
*
7990 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7992 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7993 struct type
*base_type
;
7994 struct type
*range_type
;
7995 struct attribute
*attr
;
7999 LONGEST negative_mask
;
8001 base_type
= die_type (die
, cu
);
8002 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8003 check_typedef (base_type
);
8005 /* The die_type call above may have already set the type for this DIE. */
8006 range_type
= get_die_type (die
, cu
);
8010 if (cu
->language
== language_fortran
)
8012 /* FORTRAN implies a lower bound of 1, if not given. */
8016 /* FIXME: For variable sized arrays either of these could be
8017 a variable rather than a constant value. We'll allow it,
8018 but we don't know how to handle it. */
8019 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8021 low
= dwarf2_get_attr_constant_value (attr
, 0);
8023 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8026 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8028 /* GCC encodes arrays with unspecified or dynamic length
8029 with a DW_FORM_block1 attribute or a reference attribute.
8030 FIXME: GDB does not yet know how to handle dynamic
8031 arrays properly, treat them as arrays with unspecified
8034 FIXME: jimb/2003-09-22: GDB does not really know
8035 how to handle arrays of unspecified length
8036 either; we just represent them as zero-length
8037 arrays. Choose an appropriate upper bound given
8038 the lower bound we've computed above. */
8042 high
= dwarf2_get_attr_constant_value (attr
, 1);
8046 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8049 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8050 high
= low
+ count
- 1;
8054 /* Dwarf-2 specifications explicitly allows to create subrange types
8055 without specifying a base type.
8056 In that case, the base type must be set to the type of
8057 the lower bound, upper bound or count, in that order, if any of these
8058 three attributes references an object that has a type.
8059 If no base type is found, the Dwarf-2 specifications say that
8060 a signed integer type of size equal to the size of an address should
8062 For the following C code: `extern char gdb_int [];'
8063 GCC produces an empty range DIE.
8064 FIXME: muller/2010-05-28: Possible references to object for low bound,
8065 high bound or count are not yet handled by this code.
8067 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8069 struct objfile
*objfile
= cu
->objfile
;
8070 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8071 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8072 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8074 /* Test "int", "long int", and "long long int" objfile types,
8075 and select the first one having a size above or equal to the
8076 architecture address size. */
8077 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8078 base_type
= int_type
;
8081 int_type
= objfile_type (objfile
)->builtin_long
;
8082 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8083 base_type
= int_type
;
8086 int_type
= objfile_type (objfile
)->builtin_long_long
;
8087 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8088 base_type
= int_type
;
8094 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8095 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8096 low
|= negative_mask
;
8097 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8098 high
|= negative_mask
;
8100 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8102 /* Mark arrays with dynamic length at least as an array of unspecified
8103 length. GDB could check the boundary but before it gets implemented at
8104 least allow accessing the array elements. */
8105 if (attr
&& attr
->form
== DW_FORM_block1
)
8106 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8108 name
= dwarf2_name (die
, cu
);
8110 TYPE_NAME (range_type
) = name
;
8112 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8114 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8116 set_die_type (die
, range_type
, cu
);
8118 /* set_die_type should be already done. */
8119 set_descriptive_type (range_type
, die
, cu
);
8124 static struct type
*
8125 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8129 /* For now, we only support the C meaning of an unspecified type: void. */
8131 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8132 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8134 return set_die_type (die
, type
, cu
);
8137 /* Trivial hash function for die_info: the hash value of a DIE
8138 is its offset in .debug_info for this objfile. */
8141 die_hash (const void *item
)
8143 const struct die_info
*die
= item
;
8148 /* Trivial comparison function for die_info structures: two DIEs
8149 are equal if they have the same offset. */
8152 die_eq (const void *item_lhs
, const void *item_rhs
)
8154 const struct die_info
*die_lhs
= item_lhs
;
8155 const struct die_info
*die_rhs
= item_rhs
;
8157 return die_lhs
->offset
== die_rhs
->offset
;
8160 /* Read a whole compilation unit into a linked list of dies. */
8162 static struct die_info
*
8163 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8165 struct die_reader_specs reader_specs
;
8166 int read_abbrevs
= 0;
8167 struct cleanup
*back_to
= NULL
;
8168 struct die_info
*die
;
8170 if (cu
->dwarf2_abbrevs
== NULL
)
8172 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8173 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8177 gdb_assert (cu
->die_hash
== NULL
);
8179 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8183 &cu
->comp_unit_obstack
,
8184 hashtab_obstack_allocate
,
8185 dummy_obstack_deallocate
);
8187 init_cu_die_reader (&reader_specs
, cu
);
8189 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8192 do_cleanups (back_to
);
8197 /* Main entry point for reading a DIE and all children.
8198 Read the DIE and dump it if requested. */
8200 static struct die_info
*
8201 read_die_and_children (const struct die_reader_specs
*reader
,
8203 gdb_byte
**new_info_ptr
,
8204 struct die_info
*parent
)
8206 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8207 new_info_ptr
, parent
);
8209 if (dwarf2_die_debug
)
8211 fprintf_unfiltered (gdb_stdlog
,
8212 "\nRead die from %s of %s:\n",
8213 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8215 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8217 : "unknown section",
8218 reader
->abfd
->filename
);
8219 dump_die (result
, dwarf2_die_debug
);
8225 /* Read a single die and all its descendents. Set the die's sibling
8226 field to NULL; set other fields in the die correctly, and set all
8227 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8228 location of the info_ptr after reading all of those dies. PARENT
8229 is the parent of the die in question. */
8231 static struct die_info
*
8232 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8234 gdb_byte
**new_info_ptr
,
8235 struct die_info
*parent
)
8237 struct die_info
*die
;
8241 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8244 *new_info_ptr
= cur_ptr
;
8247 store_in_ref_table (die
, reader
->cu
);
8250 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8254 *new_info_ptr
= cur_ptr
;
8257 die
->sibling
= NULL
;
8258 die
->parent
= parent
;
8262 /* Read a die, all of its descendents, and all of its siblings; set
8263 all of the fields of all of the dies correctly. Arguments are as
8264 in read_die_and_children. */
8266 static struct die_info
*
8267 read_die_and_siblings (const struct die_reader_specs
*reader
,
8269 gdb_byte
**new_info_ptr
,
8270 struct die_info
*parent
)
8272 struct die_info
*first_die
, *last_sibling
;
8276 first_die
= last_sibling
= NULL
;
8280 struct die_info
*die
8281 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8285 *new_info_ptr
= cur_ptr
;
8292 last_sibling
->sibling
= die
;
8298 /* Read the die from the .debug_info section buffer. Set DIEP to
8299 point to a newly allocated die with its information, except for its
8300 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8301 whether the die has children or not. */
8304 read_full_die (const struct die_reader_specs
*reader
,
8305 struct die_info
**diep
, gdb_byte
*info_ptr
,
8308 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8309 struct abbrev_info
*abbrev
;
8310 struct die_info
*die
;
8311 struct dwarf2_cu
*cu
= reader
->cu
;
8312 bfd
*abfd
= reader
->abfd
;
8314 offset
= info_ptr
- reader
->buffer
;
8315 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8316 info_ptr
+= bytes_read
;
8324 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8326 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8328 bfd_get_filename (abfd
));
8330 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8331 die
->offset
= offset
;
8332 die
->tag
= abbrev
->tag
;
8333 die
->abbrev
= abbrev_number
;
8335 die
->num_attrs
= abbrev
->num_attrs
;
8337 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8338 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8339 abfd
, info_ptr
, cu
);
8342 *has_children
= abbrev
->has_children
;
8346 /* In DWARF version 2, the description of the debugging information is
8347 stored in a separate .debug_abbrev section. Before we read any
8348 dies from a section we read in all abbreviations and install them
8349 in a hash table. This function also sets flags in CU describing
8350 the data found in the abbrev table. */
8353 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8355 struct comp_unit_head
*cu_header
= &cu
->header
;
8356 gdb_byte
*abbrev_ptr
;
8357 struct abbrev_info
*cur_abbrev
;
8358 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8359 unsigned int abbrev_form
, hash_number
;
8360 struct attr_abbrev
*cur_attrs
;
8361 unsigned int allocated_attrs
;
8363 /* Initialize dwarf2 abbrevs */
8364 obstack_init (&cu
->abbrev_obstack
);
8365 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8367 * sizeof (struct abbrev_info
*)));
8368 memset (cu
->dwarf2_abbrevs
, 0,
8369 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8371 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8372 &dwarf2_per_objfile
->abbrev
);
8373 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8374 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8375 abbrev_ptr
+= bytes_read
;
8377 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8378 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8380 /* loop until we reach an abbrev number of 0 */
8381 while (abbrev_number
)
8383 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8385 /* read in abbrev header */
8386 cur_abbrev
->number
= abbrev_number
;
8387 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8388 abbrev_ptr
+= bytes_read
;
8389 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8392 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8393 cu
->has_namespace_info
= 1;
8395 /* now read in declarations */
8396 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8397 abbrev_ptr
+= bytes_read
;
8398 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8399 abbrev_ptr
+= bytes_read
;
8402 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8404 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8406 = xrealloc (cur_attrs
, (allocated_attrs
8407 * sizeof (struct attr_abbrev
)));
8410 /* Record whether this compilation unit might have
8411 inter-compilation-unit references. If we don't know what form
8412 this attribute will have, then it might potentially be a
8413 DW_FORM_ref_addr, so we conservatively expect inter-CU
8416 if (abbrev_form
== DW_FORM_ref_addr
8417 || abbrev_form
== DW_FORM_indirect
)
8418 cu
->has_form_ref_addr
= 1;
8420 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8421 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8422 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8423 abbrev_ptr
+= bytes_read
;
8424 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8425 abbrev_ptr
+= bytes_read
;
8428 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8429 (cur_abbrev
->num_attrs
8430 * sizeof (struct attr_abbrev
)));
8431 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8432 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8434 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8435 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8436 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8438 /* Get next abbreviation.
8439 Under Irix6 the abbreviations for a compilation unit are not
8440 always properly terminated with an abbrev number of 0.
8441 Exit loop if we encounter an abbreviation which we have
8442 already read (which means we are about to read the abbreviations
8443 for the next compile unit) or if the end of the abbreviation
8444 table is reached. */
8445 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8446 >= dwarf2_per_objfile
->abbrev
.size
)
8448 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8449 abbrev_ptr
+= bytes_read
;
8450 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8457 /* Release the memory used by the abbrev table for a compilation unit. */
8460 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8462 struct dwarf2_cu
*cu
= ptr_to_cu
;
8464 obstack_free (&cu
->abbrev_obstack
, NULL
);
8465 cu
->dwarf2_abbrevs
= NULL
;
8468 /* Lookup an abbrev_info structure in the abbrev hash table. */
8470 static struct abbrev_info
*
8471 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8473 unsigned int hash_number
;
8474 struct abbrev_info
*abbrev
;
8476 hash_number
= number
% ABBREV_HASH_SIZE
;
8477 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8481 if (abbrev
->number
== number
)
8484 abbrev
= abbrev
->next
;
8489 /* Returns nonzero if TAG represents a type that we might generate a partial
8493 is_type_tag_for_partial (int tag
)
8498 /* Some types that would be reasonable to generate partial symbols for,
8499 that we don't at present. */
8500 case DW_TAG_array_type
:
8501 case DW_TAG_file_type
:
8502 case DW_TAG_ptr_to_member_type
:
8503 case DW_TAG_set_type
:
8504 case DW_TAG_string_type
:
8505 case DW_TAG_subroutine_type
:
8507 case DW_TAG_base_type
:
8508 case DW_TAG_class_type
:
8509 case DW_TAG_interface_type
:
8510 case DW_TAG_enumeration_type
:
8511 case DW_TAG_structure_type
:
8512 case DW_TAG_subrange_type
:
8513 case DW_TAG_typedef
:
8514 case DW_TAG_union_type
:
8521 /* Load all DIEs that are interesting for partial symbols into memory. */
8523 static struct partial_die_info
*
8524 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8525 int building_psymtab
, struct dwarf2_cu
*cu
)
8527 struct partial_die_info
*part_die
;
8528 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8529 struct abbrev_info
*abbrev
;
8530 unsigned int bytes_read
;
8531 unsigned int load_all
= 0;
8533 int nesting_level
= 1;
8538 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8542 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8546 &cu
->comp_unit_obstack
,
8547 hashtab_obstack_allocate
,
8548 dummy_obstack_deallocate
);
8550 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8551 sizeof (struct partial_die_info
));
8555 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8557 /* A NULL abbrev means the end of a series of children. */
8560 if (--nesting_level
== 0)
8562 /* PART_DIE was probably the last thing allocated on the
8563 comp_unit_obstack, so we could call obstack_free
8564 here. We don't do that because the waste is small,
8565 and will be cleaned up when we're done with this
8566 compilation unit. This way, we're also more robust
8567 against other users of the comp_unit_obstack. */
8570 info_ptr
+= bytes_read
;
8571 last_die
= parent_die
;
8572 parent_die
= parent_die
->die_parent
;
8576 /* Check for template arguments. We never save these; if
8577 they're seen, we just mark the parent, and go on our way. */
8578 if (parent_die
!= NULL
8579 && cu
->language
== language_cplus
8580 && (abbrev
->tag
== DW_TAG_template_type_param
8581 || abbrev
->tag
== DW_TAG_template_value_param
))
8583 parent_die
->has_template_arguments
= 1;
8587 /* We don't need a partial DIE for the template argument. */
8588 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8594 /* We only recurse into subprograms looking for template arguments.
8595 Skip their other children. */
8597 && cu
->language
== language_cplus
8598 && parent_die
!= NULL
8599 && parent_die
->tag
== DW_TAG_subprogram
)
8601 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8605 /* Check whether this DIE is interesting enough to save. Normally
8606 we would not be interested in members here, but there may be
8607 later variables referencing them via DW_AT_specification (for
8610 && !is_type_tag_for_partial (abbrev
->tag
)
8611 && abbrev
->tag
!= DW_TAG_constant
8612 && abbrev
->tag
!= DW_TAG_enumerator
8613 && abbrev
->tag
!= DW_TAG_subprogram
8614 && abbrev
->tag
!= DW_TAG_lexical_block
8615 && abbrev
->tag
!= DW_TAG_variable
8616 && abbrev
->tag
!= DW_TAG_namespace
8617 && abbrev
->tag
!= DW_TAG_module
8618 && abbrev
->tag
!= DW_TAG_member
)
8620 /* Otherwise we skip to the next sibling, if any. */
8621 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8625 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8626 buffer
, info_ptr
, cu
);
8628 /* This two-pass algorithm for processing partial symbols has a
8629 high cost in cache pressure. Thus, handle some simple cases
8630 here which cover the majority of C partial symbols. DIEs
8631 which neither have specification tags in them, nor could have
8632 specification tags elsewhere pointing at them, can simply be
8633 processed and discarded.
8635 This segment is also optional; scan_partial_symbols and
8636 add_partial_symbol will handle these DIEs if we chain
8637 them in normally. When compilers which do not emit large
8638 quantities of duplicate debug information are more common,
8639 this code can probably be removed. */
8641 /* Any complete simple types at the top level (pretty much all
8642 of them, for a language without namespaces), can be processed
8644 if (parent_die
== NULL
8645 && part_die
->has_specification
== 0
8646 && part_die
->is_declaration
== 0
8647 && (part_die
->tag
== DW_TAG_typedef
8648 || part_die
->tag
== DW_TAG_base_type
8649 || part_die
->tag
== DW_TAG_subrange_type
))
8651 if (building_psymtab
&& part_die
->name
!= NULL
)
8652 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8653 VAR_DOMAIN
, LOC_TYPEDEF
,
8654 &cu
->objfile
->static_psymbols
,
8655 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8656 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8660 /* If we're at the second level, and we're an enumerator, and
8661 our parent has no specification (meaning possibly lives in a
8662 namespace elsewhere), then we can add the partial symbol now
8663 instead of queueing it. */
8664 if (part_die
->tag
== DW_TAG_enumerator
8665 && parent_die
!= NULL
8666 && parent_die
->die_parent
== NULL
8667 && parent_die
->tag
== DW_TAG_enumeration_type
8668 && parent_die
->has_specification
== 0)
8670 if (part_die
->name
== NULL
)
8671 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8672 else if (building_psymtab
)
8673 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8674 VAR_DOMAIN
, LOC_CONST
,
8675 (cu
->language
== language_cplus
8676 || cu
->language
== language_java
)
8677 ? &cu
->objfile
->global_psymbols
8678 : &cu
->objfile
->static_psymbols
,
8679 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8681 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8685 /* We'll save this DIE so link it in. */
8686 part_die
->die_parent
= parent_die
;
8687 part_die
->die_sibling
= NULL
;
8688 part_die
->die_child
= NULL
;
8690 if (last_die
&& last_die
== parent_die
)
8691 last_die
->die_child
= part_die
;
8693 last_die
->die_sibling
= part_die
;
8695 last_die
= part_die
;
8697 if (first_die
== NULL
)
8698 first_die
= part_die
;
8700 /* Maybe add the DIE to the hash table. Not all DIEs that we
8701 find interesting need to be in the hash table, because we
8702 also have the parent/sibling/child chains; only those that we
8703 might refer to by offset later during partial symbol reading.
8705 For now this means things that might have be the target of a
8706 DW_AT_specification, DW_AT_abstract_origin, or
8707 DW_AT_extension. DW_AT_extension will refer only to
8708 namespaces; DW_AT_abstract_origin refers to functions (and
8709 many things under the function DIE, but we do not recurse
8710 into function DIEs during partial symbol reading) and
8711 possibly variables as well; DW_AT_specification refers to
8712 declarations. Declarations ought to have the DW_AT_declaration
8713 flag. It happens that GCC forgets to put it in sometimes, but
8714 only for functions, not for types.
8716 Adding more things than necessary to the hash table is harmless
8717 except for the performance cost. Adding too few will result in
8718 wasted time in find_partial_die, when we reread the compilation
8719 unit with load_all_dies set. */
8722 || abbrev
->tag
== DW_TAG_constant
8723 || abbrev
->tag
== DW_TAG_subprogram
8724 || abbrev
->tag
== DW_TAG_variable
8725 || abbrev
->tag
== DW_TAG_namespace
8726 || part_die
->is_declaration
)
8730 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8731 part_die
->offset
, INSERT
);
8735 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8736 sizeof (struct partial_die_info
));
8738 /* For some DIEs we want to follow their children (if any). For C
8739 we have no reason to follow the children of structures; for other
8740 languages we have to, so that we can get at method physnames
8741 to infer fully qualified class names, for DW_AT_specification,
8742 and for C++ template arguments. For C++, we also look one level
8743 inside functions to find template arguments (if the name of the
8744 function does not already contain the template arguments).
8746 For Ada, we need to scan the children of subprograms and lexical
8747 blocks as well because Ada allows the definition of nested
8748 entities that could be interesting for the debugger, such as
8749 nested subprograms for instance. */
8750 if (last_die
->has_children
8752 || last_die
->tag
== DW_TAG_namespace
8753 || last_die
->tag
== DW_TAG_module
8754 || last_die
->tag
== DW_TAG_enumeration_type
8755 || (cu
->language
== language_cplus
8756 && last_die
->tag
== DW_TAG_subprogram
8757 && (last_die
->name
== NULL
8758 || strchr (last_die
->name
, '<') == NULL
))
8759 || (cu
->language
!= language_c
8760 && (last_die
->tag
== DW_TAG_class_type
8761 || last_die
->tag
== DW_TAG_interface_type
8762 || last_die
->tag
== DW_TAG_structure_type
8763 || last_die
->tag
== DW_TAG_union_type
))
8764 || (cu
->language
== language_ada
8765 && (last_die
->tag
== DW_TAG_subprogram
8766 || last_die
->tag
== DW_TAG_lexical_block
))))
8769 parent_die
= last_die
;
8773 /* Otherwise we skip to the next sibling, if any. */
8774 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8776 /* Back to the top, do it again. */
8780 /* Read a minimal amount of information into the minimal die structure. */
8783 read_partial_die (struct partial_die_info
*part_die
,
8784 struct abbrev_info
*abbrev
,
8785 unsigned int abbrev_len
, bfd
*abfd
,
8786 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8787 struct dwarf2_cu
*cu
)
8790 struct attribute attr
;
8791 int has_low_pc_attr
= 0;
8792 int has_high_pc_attr
= 0;
8794 memset (part_die
, 0, sizeof (struct partial_die_info
));
8796 part_die
->offset
= info_ptr
- buffer
;
8798 info_ptr
+= abbrev_len
;
8803 part_die
->tag
= abbrev
->tag
;
8804 part_die
->has_children
= abbrev
->has_children
;
8806 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8808 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8810 /* Store the data if it is of an attribute we want to keep in a
8811 partial symbol table. */
8815 switch (part_die
->tag
)
8817 case DW_TAG_compile_unit
:
8818 case DW_TAG_type_unit
:
8819 /* Compilation units have a DW_AT_name that is a filename, not
8820 a source language identifier. */
8821 case DW_TAG_enumeration_type
:
8822 case DW_TAG_enumerator
:
8823 /* These tags always have simple identifiers already; no need
8824 to canonicalize them. */
8825 part_die
->name
= DW_STRING (&attr
);
8829 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8830 &cu
->objfile
->objfile_obstack
);
8834 case DW_AT_linkage_name
:
8835 case DW_AT_MIPS_linkage_name
:
8836 /* Note that both forms of linkage name might appear. We
8837 assume they will be the same, and we only store the last
8839 if (cu
->language
== language_ada
)
8840 part_die
->name
= DW_STRING (&attr
);
8841 part_die
->linkage_name
= DW_STRING (&attr
);
8844 has_low_pc_attr
= 1;
8845 part_die
->lowpc
= DW_ADDR (&attr
);
8848 has_high_pc_attr
= 1;
8849 part_die
->highpc
= DW_ADDR (&attr
);
8851 case DW_AT_location
:
8852 /* Support the .debug_loc offsets */
8853 if (attr_form_is_block (&attr
))
8855 part_die
->locdesc
= DW_BLOCK (&attr
);
8857 else if (attr_form_is_section_offset (&attr
))
8859 dwarf2_complex_location_expr_complaint ();
8863 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8864 "partial symbol information");
8867 case DW_AT_external
:
8868 part_die
->is_external
= DW_UNSND (&attr
);
8870 case DW_AT_declaration
:
8871 part_die
->is_declaration
= DW_UNSND (&attr
);
8874 part_die
->has_type
= 1;
8876 case DW_AT_abstract_origin
:
8877 case DW_AT_specification
:
8878 case DW_AT_extension
:
8879 part_die
->has_specification
= 1;
8880 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8883 /* Ignore absolute siblings, they might point outside of
8884 the current compile unit. */
8885 if (attr
.form
== DW_FORM_ref_addr
)
8886 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8888 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8890 case DW_AT_byte_size
:
8891 part_die
->has_byte_size
= 1;
8893 case DW_AT_calling_convention
:
8894 /* DWARF doesn't provide a way to identify a program's source-level
8895 entry point. DW_AT_calling_convention attributes are only meant
8896 to describe functions' calling conventions.
8898 However, because it's a necessary piece of information in
8899 Fortran, and because DW_CC_program is the only piece of debugging
8900 information whose definition refers to a 'main program' at all,
8901 several compilers have begun marking Fortran main programs with
8902 DW_CC_program --- even when those functions use the standard
8903 calling conventions.
8905 So until DWARF specifies a way to provide this information and
8906 compilers pick up the new representation, we'll support this
8908 if (DW_UNSND (&attr
) == DW_CC_program
8909 && cu
->language
== language_fortran
)
8911 set_main_name (part_die
->name
);
8913 /* As this DIE has a static linkage the name would be difficult
8914 to look up later. */
8915 language_of_main
= language_fortran
;
8923 /* When using the GNU linker, .gnu.linkonce. sections are used to
8924 eliminate duplicate copies of functions and vtables and such.
8925 The linker will arbitrarily choose one and discard the others.
8926 The AT_*_pc values for such functions refer to local labels in
8927 these sections. If the section from that file was discarded, the
8928 labels are not in the output, so the relocs get a value of 0.
8929 If this is a discarded function, mark the pc bounds as invalid,
8930 so that GDB will ignore it. */
8931 if (has_low_pc_attr
&& has_high_pc_attr
8932 && part_die
->lowpc
< part_die
->highpc
8933 && (part_die
->lowpc
!= 0
8934 || dwarf2_per_objfile
->has_section_at_zero
))
8935 part_die
->has_pc_info
= 1;
8940 /* Find a cached partial DIE at OFFSET in CU. */
8942 static struct partial_die_info
*
8943 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8945 struct partial_die_info
*lookup_die
= NULL
;
8946 struct partial_die_info part_die
;
8948 part_die
.offset
= offset
;
8949 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8954 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8955 except in the case of .debug_types DIEs which do not reference
8956 outside their CU (they do however referencing other types via
8959 static struct partial_die_info
*
8960 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8962 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8963 struct partial_die_info
*pd
= NULL
;
8965 if (cu
->per_cu
->from_debug_types
)
8967 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8973 if (offset_in_cu_p (&cu
->header
, offset
))
8975 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8980 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8982 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
8983 load_partial_comp_unit (per_cu
, cu
->objfile
);
8985 per_cu
->cu
->last_used
= 0;
8986 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8988 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8990 struct cleanup
*back_to
;
8991 struct partial_die_info comp_unit_die
;
8992 struct abbrev_info
*abbrev
;
8993 unsigned int bytes_read
;
8996 per_cu
->load_all_dies
= 1;
8998 /* Re-read the DIEs. */
8999 back_to
= make_cleanup (null_cleanup
, 0);
9000 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9002 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9003 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9005 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9006 + per_cu
->cu
->header
.offset
9007 + per_cu
->cu
->header
.first_die_offset
);
9008 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9009 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9010 per_cu
->cu
->objfile
->obfd
,
9011 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9013 if (comp_unit_die
.has_children
)
9014 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9015 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9017 do_cleanups (back_to
);
9019 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9025 internal_error (__FILE__
, __LINE__
,
9026 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
9027 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9031 /* See if we can figure out if the class lives in a namespace. We do
9032 this by looking for a member function; its demangled name will
9033 contain namespace info, if there is any. */
9036 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9037 struct dwarf2_cu
*cu
)
9039 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9040 what template types look like, because the demangler
9041 frequently doesn't give the same name as the debug info. We
9042 could fix this by only using the demangled name to get the
9043 prefix (but see comment in read_structure_type). */
9045 struct partial_die_info
*real_pdi
;
9046 struct partial_die_info
*child_pdi
;
9048 /* If this DIE (this DIE's specification, if any) has a parent, then
9049 we should not do this. We'll prepend the parent's fully qualified
9050 name when we create the partial symbol. */
9052 real_pdi
= struct_pdi
;
9053 while (real_pdi
->has_specification
)
9054 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9056 if (real_pdi
->die_parent
!= NULL
)
9059 for (child_pdi
= struct_pdi
->die_child
;
9061 child_pdi
= child_pdi
->die_sibling
)
9063 if (child_pdi
->tag
== DW_TAG_subprogram
9064 && child_pdi
->linkage_name
!= NULL
)
9066 char *actual_class_name
9067 = language_class_name_from_physname (cu
->language_defn
,
9068 child_pdi
->linkage_name
);
9069 if (actual_class_name
!= NULL
)
9072 = obsavestring (actual_class_name
,
9073 strlen (actual_class_name
),
9074 &cu
->objfile
->objfile_obstack
);
9075 xfree (actual_class_name
);
9082 /* Adjust PART_DIE before generating a symbol for it. This function
9083 may set the is_external flag or change the DIE's name. */
9086 fixup_partial_die (struct partial_die_info
*part_die
,
9087 struct dwarf2_cu
*cu
)
9089 /* Once we've fixed up a die, there's no point in doing so again.
9090 This also avoids a memory leak if we were to call
9091 guess_partial_die_structure_name multiple times. */
9092 if (part_die
->fixup_called
)
9095 /* If we found a reference attribute and the DIE has no name, try
9096 to find a name in the referred to DIE. */
9098 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9100 struct partial_die_info
*spec_die
;
9102 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9104 fixup_partial_die (spec_die
, cu
);
9108 part_die
->name
= spec_die
->name
;
9110 /* Copy DW_AT_external attribute if it is set. */
9111 if (spec_die
->is_external
)
9112 part_die
->is_external
= spec_die
->is_external
;
9116 /* Set default names for some unnamed DIEs. */
9118 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9119 part_die
->name
= "(anonymous namespace)";
9121 /* If there is no parent die to provide a namespace, and there are
9122 children, see if we can determine the namespace from their linkage
9124 NOTE: We need to do this even if cu->has_namespace_info != 0.
9125 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9126 if (cu
->language
== language_cplus
9127 && dwarf2_per_objfile
->types
.asection
!= NULL
9128 && part_die
->die_parent
== NULL
9129 && part_die
->has_children
9130 && (part_die
->tag
== DW_TAG_class_type
9131 || part_die
->tag
== DW_TAG_structure_type
9132 || part_die
->tag
== DW_TAG_union_type
))
9133 guess_partial_die_structure_name (part_die
, cu
);
9135 part_die
->fixup_called
= 1;
9138 /* Read an attribute value described by an attribute form. */
9141 read_attribute_value (struct attribute
*attr
, unsigned form
,
9142 bfd
*abfd
, gdb_byte
*info_ptr
,
9143 struct dwarf2_cu
*cu
)
9145 struct comp_unit_head
*cu_header
= &cu
->header
;
9146 unsigned int bytes_read
;
9147 struct dwarf_block
*blk
;
9152 case DW_FORM_ref_addr
:
9153 if (cu
->header
.version
== 2)
9154 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9156 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9157 info_ptr
+= bytes_read
;
9160 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9161 info_ptr
+= bytes_read
;
9163 case DW_FORM_block2
:
9164 blk
= dwarf_alloc_block (cu
);
9165 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9167 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9168 info_ptr
+= blk
->size
;
9169 DW_BLOCK (attr
) = blk
;
9171 case DW_FORM_block4
:
9172 blk
= dwarf_alloc_block (cu
);
9173 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9175 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9176 info_ptr
+= blk
->size
;
9177 DW_BLOCK (attr
) = blk
;
9180 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9184 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9188 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9191 case DW_FORM_sec_offset
:
9192 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9193 info_ptr
+= bytes_read
;
9195 case DW_FORM_string
:
9196 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9197 DW_STRING_IS_CANONICAL (attr
) = 0;
9198 info_ptr
+= bytes_read
;
9201 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9203 DW_STRING_IS_CANONICAL (attr
) = 0;
9204 info_ptr
+= bytes_read
;
9206 case DW_FORM_exprloc
:
9208 blk
= dwarf_alloc_block (cu
);
9209 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9210 info_ptr
+= bytes_read
;
9211 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9212 info_ptr
+= blk
->size
;
9213 DW_BLOCK (attr
) = blk
;
9215 case DW_FORM_block1
:
9216 blk
= dwarf_alloc_block (cu
);
9217 blk
->size
= read_1_byte (abfd
, info_ptr
);
9219 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9220 info_ptr
+= blk
->size
;
9221 DW_BLOCK (attr
) = blk
;
9224 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9228 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9231 case DW_FORM_flag_present
:
9232 DW_UNSND (attr
) = 1;
9235 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9236 info_ptr
+= bytes_read
;
9239 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9240 info_ptr
+= bytes_read
;
9243 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9247 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9251 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9255 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9259 /* Convert the signature to something we can record in DW_UNSND
9261 NOTE: This is NULL if the type wasn't found. */
9262 DW_SIGNATURED_TYPE (attr
) =
9263 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9266 case DW_FORM_ref_udata
:
9267 DW_ADDR (attr
) = (cu
->header
.offset
9268 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9269 info_ptr
+= bytes_read
;
9271 case DW_FORM_indirect
:
9272 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9273 info_ptr
+= bytes_read
;
9274 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9277 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9278 dwarf_form_name (form
),
9279 bfd_get_filename (abfd
));
9282 /* We have seen instances where the compiler tried to emit a byte
9283 size attribute of -1 which ended up being encoded as an unsigned
9284 0xffffffff. Although 0xffffffff is technically a valid size value,
9285 an object of this size seems pretty unlikely so we can relatively
9286 safely treat these cases as if the size attribute was invalid and
9287 treat them as zero by default. */
9288 if (attr
->name
== DW_AT_byte_size
9289 && form
== DW_FORM_data4
9290 && DW_UNSND (attr
) >= 0xffffffff)
9293 (&symfile_complaints
,
9294 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9295 hex_string (DW_UNSND (attr
)));
9296 DW_UNSND (attr
) = 0;
9302 /* Read an attribute described by an abbreviated attribute. */
9305 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9306 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9308 attr
->name
= abbrev
->name
;
9309 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9312 /* read dwarf information from a buffer */
9315 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9317 return bfd_get_8 (abfd
, buf
);
9321 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9323 return bfd_get_signed_8 (abfd
, buf
);
9327 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9329 return bfd_get_16 (abfd
, buf
);
9333 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9335 return bfd_get_signed_16 (abfd
, buf
);
9339 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9341 return bfd_get_32 (abfd
, buf
);
9345 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9347 return bfd_get_signed_32 (abfd
, buf
);
9351 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9353 return bfd_get_64 (abfd
, buf
);
9357 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9358 unsigned int *bytes_read
)
9360 struct comp_unit_head
*cu_header
= &cu
->header
;
9361 CORE_ADDR retval
= 0;
9363 if (cu_header
->signed_addr_p
)
9365 switch (cu_header
->addr_size
)
9368 retval
= bfd_get_signed_16 (abfd
, buf
);
9371 retval
= bfd_get_signed_32 (abfd
, buf
);
9374 retval
= bfd_get_signed_64 (abfd
, buf
);
9377 internal_error (__FILE__
, __LINE__
,
9378 _("read_address: bad switch, signed [in module %s]"),
9379 bfd_get_filename (abfd
));
9384 switch (cu_header
->addr_size
)
9387 retval
= bfd_get_16 (abfd
, buf
);
9390 retval
= bfd_get_32 (abfd
, buf
);
9393 retval
= bfd_get_64 (abfd
, buf
);
9396 internal_error (__FILE__
, __LINE__
,
9397 _("read_address: bad switch, unsigned [in module %s]"),
9398 bfd_get_filename (abfd
));
9402 *bytes_read
= cu_header
->addr_size
;
9406 /* Read the initial length from a section. The (draft) DWARF 3
9407 specification allows the initial length to take up either 4 bytes
9408 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9409 bytes describe the length and all offsets will be 8 bytes in length
9412 An older, non-standard 64-bit format is also handled by this
9413 function. The older format in question stores the initial length
9414 as an 8-byte quantity without an escape value. Lengths greater
9415 than 2^32 aren't very common which means that the initial 4 bytes
9416 is almost always zero. Since a length value of zero doesn't make
9417 sense for the 32-bit format, this initial zero can be considered to
9418 be an escape value which indicates the presence of the older 64-bit
9419 format. As written, the code can't detect (old format) lengths
9420 greater than 4GB. If it becomes necessary to handle lengths
9421 somewhat larger than 4GB, we could allow other small values (such
9422 as the non-sensical values of 1, 2, and 3) to also be used as
9423 escape values indicating the presence of the old format.
9425 The value returned via bytes_read should be used to increment the
9426 relevant pointer after calling read_initial_length().
9428 [ Note: read_initial_length() and read_offset() are based on the
9429 document entitled "DWARF Debugging Information Format", revision
9430 3, draft 8, dated November 19, 2001. This document was obtained
9433 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9435 This document is only a draft and is subject to change. (So beware.)
9437 Details regarding the older, non-standard 64-bit format were
9438 determined empirically by examining 64-bit ELF files produced by
9439 the SGI toolchain on an IRIX 6.5 machine.
9441 - Kevin, July 16, 2002
9445 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9447 LONGEST length
= bfd_get_32 (abfd
, buf
);
9449 if (length
== 0xffffffff)
9451 length
= bfd_get_64 (abfd
, buf
+ 4);
9454 else if (length
== 0)
9456 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9457 length
= bfd_get_64 (abfd
, buf
);
9468 /* Cover function for read_initial_length.
9469 Returns the length of the object at BUF, and stores the size of the
9470 initial length in *BYTES_READ and stores the size that offsets will be in
9472 If the initial length size is not equivalent to that specified in
9473 CU_HEADER then issue a complaint.
9474 This is useful when reading non-comp-unit headers. */
9477 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9478 const struct comp_unit_head
*cu_header
,
9479 unsigned int *bytes_read
,
9480 unsigned int *offset_size
)
9482 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9484 gdb_assert (cu_header
->initial_length_size
== 4
9485 || cu_header
->initial_length_size
== 8
9486 || cu_header
->initial_length_size
== 12);
9488 if (cu_header
->initial_length_size
!= *bytes_read
)
9489 complaint (&symfile_complaints
,
9490 _("intermixed 32-bit and 64-bit DWARF sections"));
9492 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9496 /* Read an offset from the data stream. The size of the offset is
9497 given by cu_header->offset_size. */
9500 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9501 unsigned int *bytes_read
)
9503 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9505 *bytes_read
= cu_header
->offset_size
;
9509 /* Read an offset from the data stream. */
9512 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9516 switch (offset_size
)
9519 retval
= bfd_get_32 (abfd
, buf
);
9522 retval
= bfd_get_64 (abfd
, buf
);
9525 internal_error (__FILE__
, __LINE__
,
9526 _("read_offset_1: bad switch [in module %s]"),
9527 bfd_get_filename (abfd
));
9534 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9536 /* If the size of a host char is 8 bits, we can return a pointer
9537 to the buffer, otherwise we have to copy the data to a buffer
9538 allocated on the temporary obstack. */
9539 gdb_assert (HOST_CHAR_BIT
== 8);
9544 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9546 /* If the size of a host char is 8 bits, we can return a pointer
9547 to the string, otherwise we have to copy the string to a buffer
9548 allocated on the temporary obstack. */
9549 gdb_assert (HOST_CHAR_BIT
== 8);
9552 *bytes_read_ptr
= 1;
9555 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9556 return (char *) buf
;
9560 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9561 const struct comp_unit_head
*cu_header
,
9562 unsigned int *bytes_read_ptr
)
9564 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9566 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9567 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9569 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9570 bfd_get_filename (abfd
));
9573 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9575 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9576 bfd_get_filename (abfd
));
9579 gdb_assert (HOST_CHAR_BIT
== 8);
9580 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9582 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9585 static unsigned long
9586 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9588 unsigned long result
;
9589 unsigned int num_read
;
9599 byte
= bfd_get_8 (abfd
, buf
);
9602 result
|= ((unsigned long)(byte
& 127) << shift
);
9603 if ((byte
& 128) == 0)
9609 *bytes_read_ptr
= num_read
;
9614 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9617 int i
, shift
, num_read
;
9626 byte
= bfd_get_8 (abfd
, buf
);
9629 result
|= ((long)(byte
& 127) << shift
);
9631 if ((byte
& 128) == 0)
9636 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9637 result
|= -(((long)1) << shift
);
9638 *bytes_read_ptr
= num_read
;
9642 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9645 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9651 byte
= bfd_get_8 (abfd
, buf
);
9653 if ((byte
& 128) == 0)
9659 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9666 cu
->language
= language_c
;
9668 case DW_LANG_C_plus_plus
:
9669 cu
->language
= language_cplus
;
9672 cu
->language
= language_d
;
9674 case DW_LANG_Fortran77
:
9675 case DW_LANG_Fortran90
:
9676 case DW_LANG_Fortran95
:
9677 cu
->language
= language_fortran
;
9679 case DW_LANG_Mips_Assembler
:
9680 cu
->language
= language_asm
;
9683 cu
->language
= language_java
;
9687 cu
->language
= language_ada
;
9689 case DW_LANG_Modula2
:
9690 cu
->language
= language_m2
;
9692 case DW_LANG_Pascal83
:
9693 cu
->language
= language_pascal
;
9696 cu
->language
= language_objc
;
9698 case DW_LANG_Cobol74
:
9699 case DW_LANG_Cobol85
:
9701 cu
->language
= language_minimal
;
9704 cu
->language_defn
= language_def (cu
->language
);
9707 /* Return the named attribute or NULL if not there. */
9709 static struct attribute
*
9710 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9713 struct attribute
*spec
= NULL
;
9715 for (i
= 0; i
< die
->num_attrs
; ++i
)
9717 if (die
->attrs
[i
].name
== name
)
9718 return &die
->attrs
[i
];
9719 if (die
->attrs
[i
].name
== DW_AT_specification
9720 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9721 spec
= &die
->attrs
[i
];
9726 die
= follow_die_ref (die
, spec
, &cu
);
9727 return dwarf2_attr (die
, name
, cu
);
9733 /* Return the named attribute or NULL if not there,
9734 but do not follow DW_AT_specification, etc.
9735 This is for use in contexts where we're reading .debug_types dies.
9736 Following DW_AT_specification, DW_AT_abstract_origin will take us
9737 back up the chain, and we want to go down. */
9739 static struct attribute
*
9740 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9741 struct dwarf2_cu
*cu
)
9745 for (i
= 0; i
< die
->num_attrs
; ++i
)
9746 if (die
->attrs
[i
].name
== name
)
9747 return &die
->attrs
[i
];
9752 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9753 and holds a non-zero value. This function should only be used for
9754 DW_FORM_flag or DW_FORM_flag_present attributes. */
9757 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9759 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9761 return (attr
&& DW_UNSND (attr
));
9765 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9767 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9768 which value is non-zero. However, we have to be careful with
9769 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9770 (via dwarf2_flag_true_p) follows this attribute. So we may
9771 end up accidently finding a declaration attribute that belongs
9772 to a different DIE referenced by the specification attribute,
9773 even though the given DIE does not have a declaration attribute. */
9774 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9775 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9778 /* Return the die giving the specification for DIE, if there is
9779 one. *SPEC_CU is the CU containing DIE on input, and the CU
9780 containing the return value on output. If there is no
9781 specification, but there is an abstract origin, that is
9784 static struct die_info
*
9785 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9787 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9790 if (spec_attr
== NULL
)
9791 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9793 if (spec_attr
== NULL
)
9796 return follow_die_ref (die
, spec_attr
, spec_cu
);
9799 /* Free the line_header structure *LH, and any arrays and strings it
9801 NOTE: This is also used as a "cleanup" function. */
9804 free_line_header (struct line_header
*lh
)
9806 if (lh
->standard_opcode_lengths
)
9807 xfree (lh
->standard_opcode_lengths
);
9809 /* Remember that all the lh->file_names[i].name pointers are
9810 pointers into debug_line_buffer, and don't need to be freed. */
9812 xfree (lh
->file_names
);
9814 /* Similarly for the include directory names. */
9815 if (lh
->include_dirs
)
9816 xfree (lh
->include_dirs
);
9821 /* Add an entry to LH's include directory table. */
9824 add_include_dir (struct line_header
*lh
, char *include_dir
)
9826 /* Grow the array if necessary. */
9827 if (lh
->include_dirs_size
== 0)
9829 lh
->include_dirs_size
= 1; /* for testing */
9830 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9831 * sizeof (*lh
->include_dirs
));
9833 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9835 lh
->include_dirs_size
*= 2;
9836 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9837 (lh
->include_dirs_size
9838 * sizeof (*lh
->include_dirs
)));
9841 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9844 /* Add an entry to LH's file name table. */
9847 add_file_name (struct line_header
*lh
,
9849 unsigned int dir_index
,
9850 unsigned int mod_time
,
9851 unsigned int length
)
9853 struct file_entry
*fe
;
9855 /* Grow the array if necessary. */
9856 if (lh
->file_names_size
== 0)
9858 lh
->file_names_size
= 1; /* for testing */
9859 lh
->file_names
= xmalloc (lh
->file_names_size
9860 * sizeof (*lh
->file_names
));
9862 else if (lh
->num_file_names
>= lh
->file_names_size
)
9864 lh
->file_names_size
*= 2;
9865 lh
->file_names
= xrealloc (lh
->file_names
,
9866 (lh
->file_names_size
9867 * sizeof (*lh
->file_names
)));
9870 fe
= &lh
->file_names
[lh
->num_file_names
++];
9872 fe
->dir_index
= dir_index
;
9873 fe
->mod_time
= mod_time
;
9874 fe
->length
= length
;
9879 /* Read the statement program header starting at OFFSET in
9880 .debug_line, according to the endianness of ABFD. Return a pointer
9881 to a struct line_header, allocated using xmalloc.
9883 NOTE: the strings in the include directory and file name tables of
9884 the returned object point into debug_line_buffer, and must not be
9887 static struct line_header
*
9888 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9889 struct dwarf2_cu
*cu
)
9891 struct cleanup
*back_to
;
9892 struct line_header
*lh
;
9894 unsigned int bytes_read
, offset_size
;
9896 char *cur_dir
, *cur_file
;
9898 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9899 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9901 complaint (&symfile_complaints
, _("missing .debug_line section"));
9905 /* Make sure that at least there's room for the total_length field.
9906 That could be 12 bytes long, but we're just going to fudge that. */
9907 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9909 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9913 lh
= xmalloc (sizeof (*lh
));
9914 memset (lh
, 0, sizeof (*lh
));
9915 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9918 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9920 /* Read in the header. */
9922 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9923 &bytes_read
, &offset_size
);
9924 line_ptr
+= bytes_read
;
9925 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9926 + dwarf2_per_objfile
->line
.size
))
9928 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9931 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9932 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9934 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9935 line_ptr
+= offset_size
;
9936 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9938 if (lh
->version
>= 4)
9940 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9944 lh
->maximum_ops_per_instruction
= 1;
9946 if (lh
->maximum_ops_per_instruction
== 0)
9948 lh
->maximum_ops_per_instruction
= 1;
9949 complaint (&symfile_complaints
,
9950 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9953 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9955 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9957 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9959 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9961 lh
->standard_opcode_lengths
9962 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9964 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9965 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9967 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9971 /* Read directory table. */
9972 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9974 line_ptr
+= bytes_read
;
9975 add_include_dir (lh
, cur_dir
);
9977 line_ptr
+= bytes_read
;
9979 /* Read file name table. */
9980 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9982 unsigned int dir_index
, mod_time
, length
;
9984 line_ptr
+= bytes_read
;
9985 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9986 line_ptr
+= bytes_read
;
9987 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9988 line_ptr
+= bytes_read
;
9989 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9990 line_ptr
+= bytes_read
;
9992 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9994 line_ptr
+= bytes_read
;
9995 lh
->statement_program_start
= line_ptr
;
9997 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9998 + dwarf2_per_objfile
->line
.size
))
9999 complaint (&symfile_complaints
,
10000 _("line number info header doesn't fit in `.debug_line' section"));
10002 discard_cleanups (back_to
);
10006 /* This function exists to work around a bug in certain compilers
10007 (particularly GCC 2.95), in which the first line number marker of a
10008 function does not show up until after the prologue, right before
10009 the second line number marker. This function shifts ADDRESS down
10010 to the beginning of the function if necessary, and is called on
10011 addresses passed to record_line. */
10014 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10016 struct function_range
*fn
;
10018 /* Find the function_range containing address. */
10022 if (!cu
->cached_fn
)
10023 cu
->cached_fn
= cu
->first_fn
;
10025 fn
= cu
->cached_fn
;
10027 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10033 while (fn
&& fn
!= cu
->cached_fn
)
10034 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10044 if (address
!= fn
->lowpc
)
10045 complaint (&symfile_complaints
,
10046 _("misplaced first line number at 0x%lx for '%s'"),
10047 (unsigned long) address
, fn
->name
);
10052 /* Subroutine of dwarf_decode_lines to simplify it.
10053 Return the file name of the psymtab for included file FILE_INDEX
10054 in line header LH of PST.
10055 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10056 If space for the result is malloc'd, it will be freed by a cleanup.
10057 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10060 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10061 const struct partial_symtab
*pst
,
10062 const char *comp_dir
)
10064 const struct file_entry fe
= lh
->file_names
[file_index
];
10065 char *include_name
= fe
.name
;
10066 char *include_name_to_compare
= include_name
;
10067 char *dir_name
= NULL
;
10068 const char *pst_filename
;
10069 char *copied_name
= NULL
;
10073 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10075 if (!IS_ABSOLUTE_PATH (include_name
)
10076 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10078 /* Avoid creating a duplicate psymtab for PST.
10079 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10080 Before we do the comparison, however, we need to account
10081 for DIR_NAME and COMP_DIR.
10082 First prepend dir_name (if non-NULL). If we still don't
10083 have an absolute path prepend comp_dir (if non-NULL).
10084 However, the directory we record in the include-file's
10085 psymtab does not contain COMP_DIR (to match the
10086 corresponding symtab(s)).
10091 bash$ gcc -g ./hello.c
10092 include_name = "hello.c"
10094 DW_AT_comp_dir = comp_dir = "/tmp"
10095 DW_AT_name = "./hello.c" */
10097 if (dir_name
!= NULL
)
10099 include_name
= concat (dir_name
, SLASH_STRING
,
10100 include_name
, (char *)NULL
);
10101 include_name_to_compare
= include_name
;
10102 make_cleanup (xfree
, include_name
);
10104 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10106 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10107 include_name
, (char *)NULL
);
10111 pst_filename
= pst
->filename
;
10112 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10114 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10115 pst_filename
, (char *)NULL
);
10116 pst_filename
= copied_name
;
10119 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10121 if (include_name_to_compare
!= include_name
)
10122 xfree (include_name_to_compare
);
10123 if (copied_name
!= NULL
)
10124 xfree (copied_name
);
10128 return include_name
;
10131 /* Decode the Line Number Program (LNP) for the given line_header
10132 structure and CU. The actual information extracted and the type
10133 of structures created from the LNP depends on the value of PST.
10135 1. If PST is NULL, then this procedure uses the data from the program
10136 to create all necessary symbol tables, and their linetables.
10138 2. If PST is not NULL, this procedure reads the program to determine
10139 the list of files included by the unit represented by PST, and
10140 builds all the associated partial symbol tables.
10142 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10143 It is used for relative paths in the line table.
10144 NOTE: When processing partial symtabs (pst != NULL),
10145 comp_dir == pst->dirname.
10147 NOTE: It is important that psymtabs have the same file name (via strcmp)
10148 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10149 symtab we don't use it in the name of the psymtabs we create.
10150 E.g. expand_line_sal requires this when finding psymtabs to expand.
10151 A good testcase for this is mb-inline.exp. */
10154 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10155 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10157 gdb_byte
*line_ptr
, *extended_end
;
10158 gdb_byte
*line_end
;
10159 unsigned int bytes_read
, extended_len
;
10160 unsigned char op_code
, extended_op
, adj_opcode
;
10161 CORE_ADDR baseaddr
;
10162 struct objfile
*objfile
= cu
->objfile
;
10163 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10164 const int decode_for_pst_p
= (pst
!= NULL
);
10165 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10167 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10169 line_ptr
= lh
->statement_program_start
;
10170 line_end
= lh
->statement_program_end
;
10172 /* Read the statement sequences until there's nothing left. */
10173 while (line_ptr
< line_end
)
10175 /* state machine registers */
10176 CORE_ADDR address
= 0;
10177 unsigned int file
= 1;
10178 unsigned int line
= 1;
10179 unsigned int column
= 0;
10180 int is_stmt
= lh
->default_is_stmt
;
10181 int basic_block
= 0;
10182 int end_sequence
= 0;
10184 unsigned char op_index
= 0;
10186 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10188 /* Start a subfile for the current file of the state machine. */
10189 /* lh->include_dirs and lh->file_names are 0-based, but the
10190 directory and file name numbers in the statement program
10192 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10196 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10198 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10201 /* Decode the table. */
10202 while (!end_sequence
)
10204 op_code
= read_1_byte (abfd
, line_ptr
);
10206 if (line_ptr
> line_end
)
10208 dwarf2_debug_line_missing_end_sequence_complaint ();
10212 if (op_code
>= lh
->opcode_base
)
10214 /* Special operand. */
10215 adj_opcode
= op_code
- lh
->opcode_base
;
10216 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10217 / lh
->maximum_ops_per_instruction
)
10218 * lh
->minimum_instruction_length
);
10219 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10220 % lh
->maximum_ops_per_instruction
);
10221 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10222 if (lh
->num_file_names
< file
|| file
== 0)
10223 dwarf2_debug_line_missing_file_complaint ();
10224 /* For now we ignore lines not starting on an
10225 instruction boundary. */
10226 else if (op_index
== 0)
10228 lh
->file_names
[file
- 1].included_p
= 1;
10229 if (!decode_for_pst_p
&& is_stmt
)
10231 if (last_subfile
!= current_subfile
)
10233 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10235 record_line (last_subfile
, 0, addr
);
10236 last_subfile
= current_subfile
;
10238 /* Append row to matrix using current values. */
10239 addr
= check_cu_functions (address
, cu
);
10240 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10241 record_line (current_subfile
, line
, addr
);
10246 else switch (op_code
)
10248 case DW_LNS_extended_op
:
10249 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10250 line_ptr
+= bytes_read
;
10251 extended_end
= line_ptr
+ extended_len
;
10252 extended_op
= read_1_byte (abfd
, line_ptr
);
10254 switch (extended_op
)
10256 case DW_LNE_end_sequence
:
10259 case DW_LNE_set_address
:
10260 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10262 line_ptr
+= bytes_read
;
10263 address
+= baseaddr
;
10265 case DW_LNE_define_file
:
10268 unsigned int dir_index
, mod_time
, length
;
10270 cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
);
10271 line_ptr
+= bytes_read
;
10273 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10274 line_ptr
+= bytes_read
;
10276 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10277 line_ptr
+= bytes_read
;
10279 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10280 line_ptr
+= bytes_read
;
10281 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10284 case DW_LNE_set_discriminator
:
10285 /* The discriminator is not interesting to the debugger;
10287 line_ptr
= extended_end
;
10290 complaint (&symfile_complaints
,
10291 _("mangled .debug_line section"));
10294 /* Make sure that we parsed the extended op correctly. If e.g.
10295 we expected a different address size than the producer used,
10296 we may have read the wrong number of bytes. */
10297 if (line_ptr
!= extended_end
)
10299 complaint (&symfile_complaints
,
10300 _("mangled .debug_line section"));
10305 if (lh
->num_file_names
< file
|| file
== 0)
10306 dwarf2_debug_line_missing_file_complaint ();
10309 lh
->file_names
[file
- 1].included_p
= 1;
10310 if (!decode_for_pst_p
&& is_stmt
)
10312 if (last_subfile
!= current_subfile
)
10314 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10316 record_line (last_subfile
, 0, addr
);
10317 last_subfile
= current_subfile
;
10319 addr
= check_cu_functions (address
, cu
);
10320 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10321 record_line (current_subfile
, line
, addr
);
10326 case DW_LNS_advance_pc
:
10329 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10331 address
+= (((op_index
+ adjust
)
10332 / lh
->maximum_ops_per_instruction
)
10333 * lh
->minimum_instruction_length
);
10334 op_index
= ((op_index
+ adjust
)
10335 % lh
->maximum_ops_per_instruction
);
10336 line_ptr
+= bytes_read
;
10339 case DW_LNS_advance_line
:
10340 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10341 line_ptr
+= bytes_read
;
10343 case DW_LNS_set_file
:
10345 /* The arrays lh->include_dirs and lh->file_names are
10346 0-based, but the directory and file name numbers in
10347 the statement program are 1-based. */
10348 struct file_entry
*fe
;
10351 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10352 line_ptr
+= bytes_read
;
10353 if (lh
->num_file_names
< file
|| file
== 0)
10354 dwarf2_debug_line_missing_file_complaint ();
10357 fe
= &lh
->file_names
[file
- 1];
10359 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10360 if (!decode_for_pst_p
)
10362 last_subfile
= current_subfile
;
10363 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10368 case DW_LNS_set_column
:
10369 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10370 line_ptr
+= bytes_read
;
10372 case DW_LNS_negate_stmt
:
10373 is_stmt
= (!is_stmt
);
10375 case DW_LNS_set_basic_block
:
10378 /* Add to the address register of the state machine the
10379 address increment value corresponding to special opcode
10380 255. I.e., this value is scaled by the minimum
10381 instruction length since special opcode 255 would have
10382 scaled the the increment. */
10383 case DW_LNS_const_add_pc
:
10385 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10387 address
+= (((op_index
+ adjust
)
10388 / lh
->maximum_ops_per_instruction
)
10389 * lh
->minimum_instruction_length
);
10390 op_index
= ((op_index
+ adjust
)
10391 % lh
->maximum_ops_per_instruction
);
10394 case DW_LNS_fixed_advance_pc
:
10395 address
+= read_2_bytes (abfd
, line_ptr
);
10401 /* Unknown standard opcode, ignore it. */
10404 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10406 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10407 line_ptr
+= bytes_read
;
10412 if (lh
->num_file_names
< file
|| file
== 0)
10413 dwarf2_debug_line_missing_file_complaint ();
10416 lh
->file_names
[file
- 1].included_p
= 1;
10417 if (!decode_for_pst_p
)
10419 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10420 record_line (current_subfile
, 0, addr
);
10425 if (decode_for_pst_p
)
10429 /* Now that we're done scanning the Line Header Program, we can
10430 create the psymtab of each included file. */
10431 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10432 if (lh
->file_names
[file_index
].included_p
== 1)
10434 char *include_name
=
10435 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10436 if (include_name
!= NULL
)
10437 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10442 /* Make sure a symtab is created for every file, even files
10443 which contain only variables (i.e. no code with associated
10447 struct file_entry
*fe
;
10449 for (i
= 0; i
< lh
->num_file_names
; i
++)
10453 fe
= &lh
->file_names
[i
];
10455 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10456 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10458 /* Skip the main file; we don't need it, and it must be
10459 allocated last, so that it will show up before the
10460 non-primary symtabs in the objfile's symtab list. */
10461 if (current_subfile
== first_subfile
)
10464 if (current_subfile
->symtab
== NULL
)
10465 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10467 fe
->symtab
= current_subfile
->symtab
;
10472 /* Start a subfile for DWARF. FILENAME is the name of the file and
10473 DIRNAME the name of the source directory which contains FILENAME
10474 or NULL if not known. COMP_DIR is the compilation directory for the
10475 linetable's compilation unit or NULL if not known.
10476 This routine tries to keep line numbers from identical absolute and
10477 relative file names in a common subfile.
10479 Using the `list' example from the GDB testsuite, which resides in
10480 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10481 of /srcdir/list0.c yields the following debugging information for list0.c:
10483 DW_AT_name: /srcdir/list0.c
10484 DW_AT_comp_dir: /compdir
10485 files.files[0].name: list0.h
10486 files.files[0].dir: /srcdir
10487 files.files[1].name: list0.c
10488 files.files[1].dir: /srcdir
10490 The line number information for list0.c has to end up in a single
10491 subfile, so that `break /srcdir/list0.c:1' works as expected.
10492 start_subfile will ensure that this happens provided that we pass the
10493 concatenation of files.files[1].dir and files.files[1].name as the
10497 dwarf2_start_subfile (char *filename
, const char *dirname
, const char *comp_dir
)
10501 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10502 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10503 second argument to start_subfile. To be consistent, we do the
10504 same here. In order not to lose the line information directory,
10505 we concatenate it to the filename when it makes sense.
10506 Note that the Dwarf3 standard says (speaking of filenames in line
10507 information): ``The directory index is ignored for file names
10508 that represent full path names''. Thus ignoring dirname in the
10509 `else' branch below isn't an issue. */
10511 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10512 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10514 fullname
= filename
;
10516 start_subfile (fullname
, comp_dir
);
10518 if (fullname
!= filename
)
10523 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10524 struct dwarf2_cu
*cu
)
10526 struct objfile
*objfile
= cu
->objfile
;
10527 struct comp_unit_head
*cu_header
= &cu
->header
;
10529 /* NOTE drow/2003-01-30: There used to be a comment and some special
10530 code here to turn a symbol with DW_AT_external and a
10531 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10532 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10533 with some versions of binutils) where shared libraries could have
10534 relocations against symbols in their debug information - the
10535 minimal symbol would have the right address, but the debug info
10536 would not. It's no longer necessary, because we will explicitly
10537 apply relocations when we read in the debug information now. */
10539 /* A DW_AT_location attribute with no contents indicates that a
10540 variable has been optimized away. */
10541 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10543 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10547 /* Handle one degenerate form of location expression specially, to
10548 preserve GDB's previous behavior when section offsets are
10549 specified. If this is just a DW_OP_addr then mark this symbol
10552 if (attr_form_is_block (attr
)
10553 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10554 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10556 unsigned int dummy
;
10558 SYMBOL_VALUE_ADDRESS (sym
) =
10559 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10560 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10561 fixup_symbol_section (sym
, objfile
);
10562 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10563 SYMBOL_SECTION (sym
));
10567 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10568 expression evaluator, and use LOC_COMPUTED only when necessary
10569 (i.e. when the value of a register or memory location is
10570 referenced, or a thread-local block, etc.). Then again, it might
10571 not be worthwhile. I'm assuming that it isn't unless performance
10572 or memory numbers show me otherwise. */
10574 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10575 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10578 /* Given a pointer to a DWARF information entry, figure out if we need
10579 to make a symbol table entry for it, and if so, create a new entry
10580 and return a pointer to it.
10581 If TYPE is NULL, determine symbol type from the die, otherwise
10582 used the passed type.
10583 If SPACE is not NULL, use it to hold the new symbol. If it is
10584 NULL, allocate a new symbol on the objfile's obstack. */
10586 static struct symbol
*
10587 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10588 struct symbol
*space
)
10590 struct objfile
*objfile
= cu
->objfile
;
10591 struct symbol
*sym
= NULL
;
10593 struct attribute
*attr
= NULL
;
10594 struct attribute
*attr2
= NULL
;
10595 CORE_ADDR baseaddr
;
10596 struct pending
**list_to_add
= NULL
;
10598 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10600 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10602 name
= dwarf2_name (die
, cu
);
10605 const char *linkagename
;
10606 int suppress_add
= 0;
10611 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10612 OBJSTAT (objfile
, n_syms
++);
10614 /* Cache this symbol's name and the name's demangled form (if any). */
10615 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10616 linkagename
= dwarf2_physname (name
, die
, cu
);
10617 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10619 /* Fortran does not have mangling standard and the mangling does differ
10620 between gfortran, iFort etc. */
10621 if (cu
->language
== language_fortran
10622 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10623 symbol_set_demangled_name (&(sym
->ginfo
),
10624 (char *) dwarf2_full_name (name
, die
, cu
),
10627 /* Default assumptions.
10628 Use the passed type or decode it from the die. */
10629 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10630 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10632 SYMBOL_TYPE (sym
) = type
;
10634 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10635 attr
= dwarf2_attr (die
,
10636 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10640 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10643 attr
= dwarf2_attr (die
,
10644 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10648 int file_index
= DW_UNSND (attr
);
10650 if (cu
->line_header
== NULL
10651 || file_index
> cu
->line_header
->num_file_names
)
10652 complaint (&symfile_complaints
,
10653 _("file index out of range"));
10654 else if (file_index
> 0)
10656 struct file_entry
*fe
;
10658 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10659 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10666 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10669 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10671 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10672 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10673 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10674 add_symbol_to_list (sym
, cu
->list_in_scope
);
10676 case DW_TAG_subprogram
:
10677 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10679 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10680 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10681 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10682 || cu
->language
== language_ada
)
10684 /* Subprograms marked external are stored as a global symbol.
10685 Ada subprograms, whether marked external or not, are always
10686 stored as a global symbol, because we want to be able to
10687 access them globally. For instance, we want to be able
10688 to break on a nested subprogram without having to
10689 specify the context. */
10690 list_to_add
= &global_symbols
;
10694 list_to_add
= cu
->list_in_scope
;
10697 case DW_TAG_inlined_subroutine
:
10698 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10700 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10701 SYMBOL_INLINED (sym
) = 1;
10702 /* Do not add the symbol to any lists. It will be found via
10703 BLOCK_FUNCTION from the blockvector. */
10705 case DW_TAG_template_value_param
:
10707 /* Fall through. */
10708 case DW_TAG_constant
:
10709 case DW_TAG_variable
:
10710 case DW_TAG_member
:
10711 /* Compilation with minimal debug info may result in variables
10712 with missing type entries. Change the misleading `void' type
10713 to something sensible. */
10714 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10716 = objfile_type (objfile
)->nodebug_data_symbol
;
10718 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10719 /* In the case of DW_TAG_member, we should only be called for
10720 static const members. */
10721 if (die
->tag
== DW_TAG_member
)
10723 /* dwarf2_add_field uses die_is_declaration,
10724 so we do the same. */
10725 gdb_assert (die_is_declaration (die
, cu
));
10730 dwarf2_const_value (attr
, sym
, cu
);
10731 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10734 if (attr2
&& (DW_UNSND (attr2
) != 0))
10735 list_to_add
= &global_symbols
;
10737 list_to_add
= cu
->list_in_scope
;
10741 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10744 var_decode_location (attr
, sym
, cu
);
10745 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10746 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10747 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10748 && !dwarf2_per_objfile
->has_section_at_zero
)
10750 /* When a static variable is eliminated by the linker,
10751 the corresponding debug information is not stripped
10752 out, but the variable address is set to null;
10753 do not add such variables into symbol table. */
10755 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10757 /* Workaround gfortran PR debug/40040 - it uses
10758 DW_AT_location for variables in -fPIC libraries which may
10759 get overriden by other libraries/executable and get
10760 a different address. Resolve it by the minimal symbol
10761 which may come from inferior's executable using copy
10762 relocation. Make this workaround only for gfortran as for
10763 other compilers GDB cannot guess the minimal symbol
10764 Fortran mangling kind. */
10765 if (cu
->language
== language_fortran
&& die
->parent
10766 && die
->parent
->tag
== DW_TAG_module
10768 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10769 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10771 /* A variable with DW_AT_external is never static,
10772 but it may be block-scoped. */
10773 list_to_add
= (cu
->list_in_scope
== &file_symbols
10774 ? &global_symbols
: cu
->list_in_scope
);
10777 list_to_add
= cu
->list_in_scope
;
10781 /* We do not know the address of this symbol.
10782 If it is an external symbol and we have type information
10783 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10784 The address of the variable will then be determined from
10785 the minimal symbol table whenever the variable is
10787 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10788 if (attr2
&& (DW_UNSND (attr2
) != 0)
10789 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10791 /* A variable with DW_AT_external is never static, but it
10792 may be block-scoped. */
10793 list_to_add
= (cu
->list_in_scope
== &file_symbols
10794 ? &global_symbols
: cu
->list_in_scope
);
10796 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10798 else if (!die_is_declaration (die
, cu
))
10800 /* Use the default LOC_OPTIMIZED_OUT class. */
10801 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10803 list_to_add
= cu
->list_in_scope
;
10807 case DW_TAG_formal_parameter
:
10808 /* If we are inside a function, mark this as an argument. If
10809 not, we might be looking at an argument to an inlined function
10810 when we do not have enough information to show inlined frames;
10811 pretend it's a local variable in that case so that the user can
10813 if (context_stack_depth
> 0
10814 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10815 SYMBOL_IS_ARGUMENT (sym
) = 1;
10816 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10819 var_decode_location (attr
, sym
, cu
);
10821 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10824 dwarf2_const_value (attr
, sym
, cu
);
10826 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10827 if (attr
&& DW_UNSND (attr
))
10829 struct type
*ref_type
;
10831 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10832 SYMBOL_TYPE (sym
) = ref_type
;
10835 list_to_add
= cu
->list_in_scope
;
10837 case DW_TAG_unspecified_parameters
:
10838 /* From varargs functions; gdb doesn't seem to have any
10839 interest in this information, so just ignore it for now.
10842 case DW_TAG_template_type_param
:
10844 /* Fall through. */
10845 case DW_TAG_class_type
:
10846 case DW_TAG_interface_type
:
10847 case DW_TAG_structure_type
:
10848 case DW_TAG_union_type
:
10849 case DW_TAG_set_type
:
10850 case DW_TAG_enumeration_type
:
10851 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10852 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10855 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10856 really ever be static objects: otherwise, if you try
10857 to, say, break of a class's method and you're in a file
10858 which doesn't mention that class, it won't work unless
10859 the check for all static symbols in lookup_symbol_aux
10860 saves you. See the OtherFileClass tests in
10861 gdb.c++/namespace.exp. */
10865 list_to_add
= (cu
->list_in_scope
== &file_symbols
10866 && (cu
->language
== language_cplus
10867 || cu
->language
== language_java
)
10868 ? &global_symbols
: cu
->list_in_scope
);
10870 /* The semantics of C++ state that "struct foo {
10871 ... }" also defines a typedef for "foo". A Java
10872 class declaration also defines a typedef for the
10874 if (cu
->language
== language_cplus
10875 || cu
->language
== language_java
10876 || cu
->language
== language_ada
)
10878 /* The symbol's name is already allocated along
10879 with this objfile, so we don't need to
10880 duplicate it for the type. */
10881 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
10882 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
10887 case DW_TAG_typedef
:
10888 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10889 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10890 list_to_add
= cu
->list_in_scope
;
10892 case DW_TAG_base_type
:
10893 case DW_TAG_subrange_type
:
10894 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10895 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10896 list_to_add
= cu
->list_in_scope
;
10898 case DW_TAG_enumerator
:
10899 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10902 dwarf2_const_value (attr
, sym
, cu
);
10905 /* NOTE: carlton/2003-11-10: See comment above in the
10906 DW_TAG_class_type, etc. block. */
10908 list_to_add
= (cu
->list_in_scope
== &file_symbols
10909 && (cu
->language
== language_cplus
10910 || cu
->language
== language_java
)
10911 ? &global_symbols
: cu
->list_in_scope
);
10914 case DW_TAG_namespace
:
10915 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10916 list_to_add
= &global_symbols
;
10919 /* Not a tag we recognize. Hopefully we aren't processing
10920 trash data, but since we must specifically ignore things
10921 we don't recognize, there is nothing else we should do at
10923 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10924 dwarf_tag_name (die
->tag
));
10930 sym
->hash_next
= objfile
->template_symbols
;
10931 objfile
->template_symbols
= sym
;
10932 list_to_add
= NULL
;
10935 if (list_to_add
!= NULL
)
10936 add_symbol_to_list (sym
, list_to_add
);
10938 /* For the benefit of old versions of GCC, check for anonymous
10939 namespaces based on the demangled name. */
10940 if (!processing_has_namespace_info
10941 && cu
->language
== language_cplus
)
10942 cp_scan_for_anonymous_namespaces (sym
);
10947 /* A wrapper for new_symbol_full that always allocates a new symbol. */
10949 static struct symbol
*
10950 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10952 return new_symbol_full (die
, type
, cu
, NULL
);
10955 /* Given an attr with a DW_FORM_dataN value in host byte order,
10956 zero-extend it as appropriate for the symbol's type. The DWARF
10957 standard (v4) is not entirely clear about the meaning of using
10958 DW_FORM_dataN for a constant with a signed type, where the type is
10959 wider than the data. The conclusion of a discussion on the DWARF
10960 list was that this is unspecified. We choose to always zero-extend
10961 because that is the interpretation long in use by GCC. */
10964 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
10965 const char *name
, struct obstack
*obstack
,
10966 struct dwarf2_cu
*cu
, long *value
, int bits
)
10968 struct objfile
*objfile
= cu
->objfile
;
10969 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10970 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10971 LONGEST l
= DW_UNSND (attr
);
10973 if (bits
< sizeof (*value
) * 8)
10975 l
&= ((LONGEST
) 1 << bits
) - 1;
10978 else if (bits
== sizeof (*value
) * 8)
10982 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
10983 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
10990 /* Read a constant value from an attribute. Either set *VALUE, or if
10991 the value does not fit in *VALUE, set *BYTES - either already
10992 allocated on the objfile obstack, or newly allocated on OBSTACK,
10993 or, set *BATON, if we translated the constant to a location
10997 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
10998 const char *name
, struct obstack
*obstack
,
10999 struct dwarf2_cu
*cu
,
11000 long *value
, gdb_byte
**bytes
,
11001 struct dwarf2_locexpr_baton
**baton
)
11003 struct objfile
*objfile
= cu
->objfile
;
11004 struct comp_unit_head
*cu_header
= &cu
->header
;
11005 struct dwarf_block
*blk
;
11006 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11007 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11013 switch (attr
->form
)
11019 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11020 dwarf2_const_value_length_mismatch_complaint (name
,
11021 cu_header
->addr_size
,
11022 TYPE_LENGTH (type
));
11023 /* Symbols of this form are reasonably rare, so we just
11024 piggyback on the existing location code rather than writing
11025 a new implementation of symbol_computed_ops. */
11026 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11027 sizeof (struct dwarf2_locexpr_baton
));
11028 (*baton
)->per_cu
= cu
->per_cu
;
11029 gdb_assert ((*baton
)->per_cu
);
11031 (*baton
)->size
= 2 + cu_header
->addr_size
;
11032 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11033 (*baton
)->data
= data
;
11035 data
[0] = DW_OP_addr
;
11036 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11037 byte_order
, DW_ADDR (attr
));
11038 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11041 case DW_FORM_string
:
11043 /* DW_STRING is already allocated on the objfile obstack, point
11045 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11047 case DW_FORM_block1
:
11048 case DW_FORM_block2
:
11049 case DW_FORM_block4
:
11050 case DW_FORM_block
:
11051 case DW_FORM_exprloc
:
11052 blk
= DW_BLOCK (attr
);
11053 if (TYPE_LENGTH (type
) != blk
->size
)
11054 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11055 TYPE_LENGTH (type
));
11056 *bytes
= blk
->data
;
11059 /* The DW_AT_const_value attributes are supposed to carry the
11060 symbol's value "represented as it would be on the target
11061 architecture." By the time we get here, it's already been
11062 converted to host endianness, so we just need to sign- or
11063 zero-extend it as appropriate. */
11064 case DW_FORM_data1
:
11065 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 8);
11067 case DW_FORM_data2
:
11068 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 16);
11070 case DW_FORM_data4
:
11071 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 32);
11073 case DW_FORM_data8
:
11074 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 64);
11077 case DW_FORM_sdata
:
11078 *value
= DW_SND (attr
);
11081 case DW_FORM_udata
:
11082 *value
= DW_UNSND (attr
);
11086 complaint (&symfile_complaints
,
11087 _("unsupported const value attribute form: '%s'"),
11088 dwarf_form_name (attr
->form
));
11095 /* Copy constant value from an attribute to a symbol. */
11098 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11099 struct dwarf2_cu
*cu
)
11101 struct objfile
*objfile
= cu
->objfile
;
11102 struct comp_unit_head
*cu_header
= &cu
->header
;
11105 struct dwarf2_locexpr_baton
*baton
;
11107 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11108 SYMBOL_PRINT_NAME (sym
),
11109 &objfile
->objfile_obstack
, cu
,
11110 &value
, &bytes
, &baton
);
11114 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11115 SYMBOL_LOCATION_BATON (sym
) = baton
;
11116 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11118 else if (bytes
!= NULL
)
11120 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11121 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11125 SYMBOL_VALUE (sym
) = value
;
11126 SYMBOL_CLASS (sym
) = LOC_CONST
;
11130 /* Return the type of the die in question using its DW_AT_type attribute. */
11132 static struct type
*
11133 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11135 struct attribute
*type_attr
;
11137 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11140 /* A missing DW_AT_type represents a void type. */
11141 return objfile_type (cu
->objfile
)->builtin_void
;
11144 return lookup_die_type (die
, type_attr
, cu
);
11147 /* True iff CU's producer generates GNAT Ada auxiliary information
11148 that allows to find parallel types through that information instead
11149 of having to do expensive parallel lookups by type name. */
11152 need_gnat_info (struct dwarf2_cu
*cu
)
11154 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11155 of GNAT produces this auxiliary information, without any indication
11156 that it is produced. Part of enhancing the FSF version of GNAT
11157 to produce that information will be to put in place an indicator
11158 that we can use in order to determine whether the descriptive type
11159 info is available or not. One suggestion that has been made is
11160 to use a new attribute, attached to the CU die. For now, assume
11161 that the descriptive type info is not available. */
11165 /* Return the auxiliary type of the die in question using its
11166 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11167 attribute is not present. */
11169 static struct type
*
11170 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11172 struct attribute
*type_attr
;
11174 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11178 return lookup_die_type (die
, type_attr
, cu
);
11181 /* If DIE has a descriptive_type attribute, then set the TYPE's
11182 descriptive type accordingly. */
11185 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11186 struct dwarf2_cu
*cu
)
11188 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11190 if (descriptive_type
)
11192 ALLOCATE_GNAT_AUX_TYPE (type
);
11193 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11197 /* Return the containing type of the die in question using its
11198 DW_AT_containing_type attribute. */
11200 static struct type
*
11201 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11203 struct attribute
*type_attr
;
11205 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11207 error (_("Dwarf Error: Problem turning containing type into gdb type "
11208 "[in module %s]"), cu
->objfile
->name
);
11210 return lookup_die_type (die
, type_attr
, cu
);
11213 /* Look up the type of DIE in CU using its type attribute ATTR.
11214 If there is no type substitute an error marker. */
11216 static struct type
*
11217 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11218 struct dwarf2_cu
*cu
)
11220 struct type
*this_type
;
11222 /* First see if we have it cached. */
11224 if (is_ref_attr (attr
))
11226 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11228 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11230 else if (attr
->form
== DW_FORM_sig8
)
11232 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11233 struct dwarf2_cu
*sig_cu
;
11234 unsigned int offset
;
11236 /* sig_type will be NULL if the signatured type is missing from
11238 if (sig_type
== NULL
)
11239 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11240 "at 0x%x [in module %s]"),
11241 die
->offset
, cu
->objfile
->name
);
11243 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11244 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11245 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11249 dump_die_for_error (die
);
11250 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11251 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11254 /* If not cached we need to read it in. */
11256 if (this_type
== NULL
)
11258 struct die_info
*type_die
;
11259 struct dwarf2_cu
*type_cu
= cu
;
11261 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11262 /* If the type is cached, we should have found it above. */
11263 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11264 this_type
= read_type_die_1 (type_die
, type_cu
);
11267 /* If we still don't have a type use an error marker. */
11269 if (this_type
== NULL
)
11271 char *message
, *saved
;
11273 /* read_type_die already issued a complaint. */
11274 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11278 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11279 message
, strlen (message
));
11282 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11288 /* Return the type in DIE, CU.
11289 Returns NULL for invalid types.
11291 This first does a lookup in the appropriate type_hash table,
11292 and only reads the die in if necessary.
11294 NOTE: This can be called when reading in partial or full symbols. */
11296 static struct type
*
11297 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11299 struct type
*this_type
;
11301 this_type
= get_die_type (die
, cu
);
11305 return read_type_die_1 (die
, cu
);
11308 /* Read the type in DIE, CU.
11309 Returns NULL for invalid types. */
11311 static struct type
*
11312 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11314 struct type
*this_type
= NULL
;
11318 case DW_TAG_class_type
:
11319 case DW_TAG_interface_type
:
11320 case DW_TAG_structure_type
:
11321 case DW_TAG_union_type
:
11322 this_type
= read_structure_type (die
, cu
);
11324 case DW_TAG_enumeration_type
:
11325 this_type
= read_enumeration_type (die
, cu
);
11327 case DW_TAG_subprogram
:
11328 case DW_TAG_subroutine_type
:
11329 case DW_TAG_inlined_subroutine
:
11330 this_type
= read_subroutine_type (die
, cu
);
11332 case DW_TAG_array_type
:
11333 this_type
= read_array_type (die
, cu
);
11335 case DW_TAG_set_type
:
11336 this_type
= read_set_type (die
, cu
);
11338 case DW_TAG_pointer_type
:
11339 this_type
= read_tag_pointer_type (die
, cu
);
11341 case DW_TAG_ptr_to_member_type
:
11342 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11344 case DW_TAG_reference_type
:
11345 this_type
= read_tag_reference_type (die
, cu
);
11347 case DW_TAG_const_type
:
11348 this_type
= read_tag_const_type (die
, cu
);
11350 case DW_TAG_volatile_type
:
11351 this_type
= read_tag_volatile_type (die
, cu
);
11353 case DW_TAG_string_type
:
11354 this_type
= read_tag_string_type (die
, cu
);
11356 case DW_TAG_typedef
:
11357 this_type
= read_typedef (die
, cu
);
11359 case DW_TAG_subrange_type
:
11360 this_type
= read_subrange_type (die
, cu
);
11362 case DW_TAG_base_type
:
11363 this_type
= read_base_type (die
, cu
);
11365 case DW_TAG_unspecified_type
:
11366 this_type
= read_unspecified_type (die
, cu
);
11368 case DW_TAG_namespace
:
11369 this_type
= read_namespace_type (die
, cu
);
11371 case DW_TAG_module
:
11372 this_type
= read_module_type (die
, cu
);
11375 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
11376 dwarf_tag_name (die
->tag
));
11383 /* See if we can figure out if the class lives in a namespace. We do
11384 this by looking for a member function; its demangled name will
11385 contain namespace info, if there is any.
11386 Return the computed name or NULL.
11387 Space for the result is allocated on the objfile's obstack.
11388 This is the full-die version of guess_partial_die_structure_name.
11389 In this case we know DIE has no useful parent. */
11392 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11394 struct die_info
*spec_die
;
11395 struct dwarf2_cu
*spec_cu
;
11396 struct die_info
*child
;
11399 spec_die
= die_specification (die
, &spec_cu
);
11400 if (spec_die
!= NULL
)
11406 for (child
= die
->child
;
11408 child
= child
->sibling
)
11410 if (child
->tag
== DW_TAG_subprogram
)
11412 struct attribute
*attr
;
11414 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11416 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11420 = language_class_name_from_physname (cu
->language_defn
,
11424 if (actual_name
!= NULL
)
11426 char *die_name
= dwarf2_name (die
, cu
);
11428 if (die_name
!= NULL
11429 && strcmp (die_name
, actual_name
) != 0)
11431 /* Strip off the class name from the full name.
11432 We want the prefix. */
11433 int die_name_len
= strlen (die_name
);
11434 int actual_name_len
= strlen (actual_name
);
11436 /* Test for '::' as a sanity check. */
11437 if (actual_name_len
> die_name_len
+ 2
11438 && actual_name
[actual_name_len
- die_name_len
- 1] == ':')
11440 obsavestring (actual_name
,
11441 actual_name_len
- die_name_len
- 2,
11442 &cu
->objfile
->objfile_obstack
);
11445 xfree (actual_name
);
11454 /* Return the name of the namespace/class that DIE is defined within,
11455 or "" if we can't tell. The caller should not xfree the result.
11457 For example, if we're within the method foo() in the following
11467 then determine_prefix on foo's die will return "N::C". */
11470 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11472 struct die_info
*parent
, *spec_die
;
11473 struct dwarf2_cu
*spec_cu
;
11474 struct type
*parent_type
;
11476 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11477 && cu
->language
!= language_fortran
)
11480 /* We have to be careful in the presence of DW_AT_specification.
11481 For example, with GCC 3.4, given the code
11485 // Definition of N::foo.
11489 then we'll have a tree of DIEs like this:
11491 1: DW_TAG_compile_unit
11492 2: DW_TAG_namespace // N
11493 3: DW_TAG_subprogram // declaration of N::foo
11494 4: DW_TAG_subprogram // definition of N::foo
11495 DW_AT_specification // refers to die #3
11497 Thus, when processing die #4, we have to pretend that we're in
11498 the context of its DW_AT_specification, namely the contex of die
11501 spec_die
= die_specification (die
, &spec_cu
);
11502 if (spec_die
== NULL
)
11503 parent
= die
->parent
;
11506 parent
= spec_die
->parent
;
11510 if (parent
== NULL
)
11512 else if (parent
->building_fullname
)
11515 const char *parent_name
;
11517 /* It has been seen on RealView 2.2 built binaries,
11518 DW_TAG_template_type_param types actually _defined_ as
11519 children of the parent class:
11522 template class <class Enum> Class{};
11523 Class<enum E> class_e;
11525 1: DW_TAG_class_type (Class)
11526 2: DW_TAG_enumeration_type (E)
11527 3: DW_TAG_enumerator (enum1:0)
11528 3: DW_TAG_enumerator (enum2:1)
11530 2: DW_TAG_template_type_param
11531 DW_AT_type DW_FORM_ref_udata (E)
11533 Besides being broken debug info, it can put GDB into an
11534 infinite loop. Consider:
11536 When we're building the full name for Class<E>, we'll start
11537 at Class, and go look over its template type parameters,
11538 finding E. We'll then try to build the full name of E, and
11539 reach here. We're now trying to build the full name of E,
11540 and look over the parent DIE for containing scope. In the
11541 broken case, if we followed the parent DIE of E, we'd again
11542 find Class, and once again go look at its template type
11543 arguments, etc., etc. Simply don't consider such parent die
11544 as source-level parent of this die (it can't be, the language
11545 doesn't allow it), and break the loop here. */
11546 name
= dwarf2_name (die
, cu
);
11547 parent_name
= dwarf2_name (parent
, cu
);
11548 complaint (&symfile_complaints
,
11549 _("template param type '%s' defined within parent '%s'"),
11550 name
? name
: "<unknown>",
11551 parent_name
? parent_name
: "<unknown>");
11555 switch (parent
->tag
)
11557 case DW_TAG_namespace
:
11558 parent_type
= read_type_die (parent
, cu
);
11559 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11560 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11561 Work around this problem here. */
11562 if (cu
->language
== language_cplus
11563 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11565 /* We give a name to even anonymous namespaces. */
11566 return TYPE_TAG_NAME (parent_type
);
11567 case DW_TAG_class_type
:
11568 case DW_TAG_interface_type
:
11569 case DW_TAG_structure_type
:
11570 case DW_TAG_union_type
:
11571 case DW_TAG_module
:
11572 parent_type
= read_type_die (parent
, cu
);
11573 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11574 return TYPE_TAG_NAME (parent_type
);
11576 /* An anonymous structure is only allowed non-static data
11577 members; no typedefs, no member functions, et cetera.
11578 So it does not need a prefix. */
11580 case DW_TAG_compile_unit
:
11581 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11582 if (cu
->language
== language_cplus
11583 && dwarf2_per_objfile
->types
.asection
!= NULL
11584 && die
->child
!= NULL
11585 && (die
->tag
== DW_TAG_class_type
11586 || die
->tag
== DW_TAG_structure_type
11587 || die
->tag
== DW_TAG_union_type
))
11589 char *name
= guess_full_die_structure_name (die
, cu
);
11595 return determine_prefix (parent
, cu
);
11599 /* Return a newly-allocated string formed by concatenating PREFIX and
11600 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11601 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11602 perform an obconcat, otherwise allocate storage for the result. The CU argument
11603 is used to determine the language and hence, the appropriate separator. */
11605 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11608 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11609 int physname
, struct dwarf2_cu
*cu
)
11611 const char *lead
= "";
11614 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
11616 else if (cu
->language
== language_java
)
11618 else if (cu
->language
== language_fortran
&& physname
)
11620 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11621 DW_AT_MIPS_linkage_name is preferred and used instead. */
11629 if (prefix
== NULL
)
11631 if (suffix
== NULL
)
11636 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11638 strcpy (retval
, lead
);
11639 strcat (retval
, prefix
);
11640 strcat (retval
, sep
);
11641 strcat (retval
, suffix
);
11646 /* We have an obstack. */
11647 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11651 /* Return sibling of die, NULL if no sibling. */
11653 static struct die_info
*
11654 sibling_die (struct die_info
*die
)
11656 return die
->sibling
;
11659 /* Get name of a die, return NULL if not found. */
11662 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11663 struct obstack
*obstack
)
11665 if (name
&& cu
->language
== language_cplus
)
11667 char *canon_name
= cp_canonicalize_string (name
);
11669 if (canon_name
!= NULL
)
11671 if (strcmp (canon_name
, name
) != 0)
11672 name
= obsavestring (canon_name
, strlen (canon_name
),
11674 xfree (canon_name
);
11681 /* Get name of a die, return NULL if not found. */
11684 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11686 struct attribute
*attr
;
11688 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11689 if (!attr
|| !DW_STRING (attr
))
11694 case DW_TAG_compile_unit
:
11695 /* Compilation units have a DW_AT_name that is a filename, not
11696 a source language identifier. */
11697 case DW_TAG_enumeration_type
:
11698 case DW_TAG_enumerator
:
11699 /* These tags always have simple identifiers already; no need
11700 to canonicalize them. */
11701 return DW_STRING (attr
);
11703 case DW_TAG_subprogram
:
11704 /* Java constructors will all be named "<init>", so return
11705 the class name when we see this special case. */
11706 if (cu
->language
== language_java
11707 && DW_STRING (attr
) != NULL
11708 && strcmp (DW_STRING (attr
), "<init>") == 0)
11710 struct dwarf2_cu
*spec_cu
= cu
;
11711 struct die_info
*spec_die
;
11713 /* GCJ will output '<init>' for Java constructor names.
11714 For this special case, return the name of the parent class. */
11716 /* GCJ may output suprogram DIEs with AT_specification set.
11717 If so, use the name of the specified DIE. */
11718 spec_die
= die_specification (die
, &spec_cu
);
11719 if (spec_die
!= NULL
)
11720 return dwarf2_name (spec_die
, spec_cu
);
11725 if (die
->tag
== DW_TAG_class_type
)
11726 return dwarf2_name (die
, cu
);
11728 while (die
->tag
!= DW_TAG_compile_unit
);
11732 case DW_TAG_class_type
:
11733 case DW_TAG_interface_type
:
11734 case DW_TAG_structure_type
:
11735 case DW_TAG_union_type
:
11736 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11737 structures or unions. These were of the form "._%d" in GCC 4.1,
11738 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11739 and GCC 4.4. We work around this problem by ignoring these. */
11740 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11741 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11749 if (!DW_STRING_IS_CANONICAL (attr
))
11752 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11753 &cu
->objfile
->objfile_obstack
);
11754 DW_STRING_IS_CANONICAL (attr
) = 1;
11756 return DW_STRING (attr
);
11759 /* Return the die that this die in an extension of, or NULL if there
11760 is none. *EXT_CU is the CU containing DIE on input, and the CU
11761 containing the return value on output. */
11763 static struct die_info
*
11764 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11766 struct attribute
*attr
;
11768 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11772 return follow_die_ref (die
, attr
, ext_cu
);
11775 /* Convert a DIE tag into its string name. */
11778 dwarf_tag_name (unsigned tag
)
11782 case DW_TAG_padding
:
11783 return "DW_TAG_padding";
11784 case DW_TAG_array_type
:
11785 return "DW_TAG_array_type";
11786 case DW_TAG_class_type
:
11787 return "DW_TAG_class_type";
11788 case DW_TAG_entry_point
:
11789 return "DW_TAG_entry_point";
11790 case DW_TAG_enumeration_type
:
11791 return "DW_TAG_enumeration_type";
11792 case DW_TAG_formal_parameter
:
11793 return "DW_TAG_formal_parameter";
11794 case DW_TAG_imported_declaration
:
11795 return "DW_TAG_imported_declaration";
11797 return "DW_TAG_label";
11798 case DW_TAG_lexical_block
:
11799 return "DW_TAG_lexical_block";
11800 case DW_TAG_member
:
11801 return "DW_TAG_member";
11802 case DW_TAG_pointer_type
:
11803 return "DW_TAG_pointer_type";
11804 case DW_TAG_reference_type
:
11805 return "DW_TAG_reference_type";
11806 case DW_TAG_compile_unit
:
11807 return "DW_TAG_compile_unit";
11808 case DW_TAG_string_type
:
11809 return "DW_TAG_string_type";
11810 case DW_TAG_structure_type
:
11811 return "DW_TAG_structure_type";
11812 case DW_TAG_subroutine_type
:
11813 return "DW_TAG_subroutine_type";
11814 case DW_TAG_typedef
:
11815 return "DW_TAG_typedef";
11816 case DW_TAG_union_type
:
11817 return "DW_TAG_union_type";
11818 case DW_TAG_unspecified_parameters
:
11819 return "DW_TAG_unspecified_parameters";
11820 case DW_TAG_variant
:
11821 return "DW_TAG_variant";
11822 case DW_TAG_common_block
:
11823 return "DW_TAG_common_block";
11824 case DW_TAG_common_inclusion
:
11825 return "DW_TAG_common_inclusion";
11826 case DW_TAG_inheritance
:
11827 return "DW_TAG_inheritance";
11828 case DW_TAG_inlined_subroutine
:
11829 return "DW_TAG_inlined_subroutine";
11830 case DW_TAG_module
:
11831 return "DW_TAG_module";
11832 case DW_TAG_ptr_to_member_type
:
11833 return "DW_TAG_ptr_to_member_type";
11834 case DW_TAG_set_type
:
11835 return "DW_TAG_set_type";
11836 case DW_TAG_subrange_type
:
11837 return "DW_TAG_subrange_type";
11838 case DW_TAG_with_stmt
:
11839 return "DW_TAG_with_stmt";
11840 case DW_TAG_access_declaration
:
11841 return "DW_TAG_access_declaration";
11842 case DW_TAG_base_type
:
11843 return "DW_TAG_base_type";
11844 case DW_TAG_catch_block
:
11845 return "DW_TAG_catch_block";
11846 case DW_TAG_const_type
:
11847 return "DW_TAG_const_type";
11848 case DW_TAG_constant
:
11849 return "DW_TAG_constant";
11850 case DW_TAG_enumerator
:
11851 return "DW_TAG_enumerator";
11852 case DW_TAG_file_type
:
11853 return "DW_TAG_file_type";
11854 case DW_TAG_friend
:
11855 return "DW_TAG_friend";
11856 case DW_TAG_namelist
:
11857 return "DW_TAG_namelist";
11858 case DW_TAG_namelist_item
:
11859 return "DW_TAG_namelist_item";
11860 case DW_TAG_packed_type
:
11861 return "DW_TAG_packed_type";
11862 case DW_TAG_subprogram
:
11863 return "DW_TAG_subprogram";
11864 case DW_TAG_template_type_param
:
11865 return "DW_TAG_template_type_param";
11866 case DW_TAG_template_value_param
:
11867 return "DW_TAG_template_value_param";
11868 case DW_TAG_thrown_type
:
11869 return "DW_TAG_thrown_type";
11870 case DW_TAG_try_block
:
11871 return "DW_TAG_try_block";
11872 case DW_TAG_variant_part
:
11873 return "DW_TAG_variant_part";
11874 case DW_TAG_variable
:
11875 return "DW_TAG_variable";
11876 case DW_TAG_volatile_type
:
11877 return "DW_TAG_volatile_type";
11878 case DW_TAG_dwarf_procedure
:
11879 return "DW_TAG_dwarf_procedure";
11880 case DW_TAG_restrict_type
:
11881 return "DW_TAG_restrict_type";
11882 case DW_TAG_interface_type
:
11883 return "DW_TAG_interface_type";
11884 case DW_TAG_namespace
:
11885 return "DW_TAG_namespace";
11886 case DW_TAG_imported_module
:
11887 return "DW_TAG_imported_module";
11888 case DW_TAG_unspecified_type
:
11889 return "DW_TAG_unspecified_type";
11890 case DW_TAG_partial_unit
:
11891 return "DW_TAG_partial_unit";
11892 case DW_TAG_imported_unit
:
11893 return "DW_TAG_imported_unit";
11894 case DW_TAG_condition
:
11895 return "DW_TAG_condition";
11896 case DW_TAG_shared_type
:
11897 return "DW_TAG_shared_type";
11898 case DW_TAG_type_unit
:
11899 return "DW_TAG_type_unit";
11900 case DW_TAG_MIPS_loop
:
11901 return "DW_TAG_MIPS_loop";
11902 case DW_TAG_HP_array_descriptor
:
11903 return "DW_TAG_HP_array_descriptor";
11904 case DW_TAG_format_label
:
11905 return "DW_TAG_format_label";
11906 case DW_TAG_function_template
:
11907 return "DW_TAG_function_template";
11908 case DW_TAG_class_template
:
11909 return "DW_TAG_class_template";
11910 case DW_TAG_GNU_BINCL
:
11911 return "DW_TAG_GNU_BINCL";
11912 case DW_TAG_GNU_EINCL
:
11913 return "DW_TAG_GNU_EINCL";
11914 case DW_TAG_upc_shared_type
:
11915 return "DW_TAG_upc_shared_type";
11916 case DW_TAG_upc_strict_type
:
11917 return "DW_TAG_upc_strict_type";
11918 case DW_TAG_upc_relaxed_type
:
11919 return "DW_TAG_upc_relaxed_type";
11920 case DW_TAG_PGI_kanji_type
:
11921 return "DW_TAG_PGI_kanji_type";
11922 case DW_TAG_PGI_interface_block
:
11923 return "DW_TAG_PGI_interface_block";
11925 return "DW_TAG_<unknown>";
11929 /* Convert a DWARF attribute code into its string name. */
11932 dwarf_attr_name (unsigned attr
)
11936 case DW_AT_sibling
:
11937 return "DW_AT_sibling";
11938 case DW_AT_location
:
11939 return "DW_AT_location";
11941 return "DW_AT_name";
11942 case DW_AT_ordering
:
11943 return "DW_AT_ordering";
11944 case DW_AT_subscr_data
:
11945 return "DW_AT_subscr_data";
11946 case DW_AT_byte_size
:
11947 return "DW_AT_byte_size";
11948 case DW_AT_bit_offset
:
11949 return "DW_AT_bit_offset";
11950 case DW_AT_bit_size
:
11951 return "DW_AT_bit_size";
11952 case DW_AT_element_list
:
11953 return "DW_AT_element_list";
11954 case DW_AT_stmt_list
:
11955 return "DW_AT_stmt_list";
11957 return "DW_AT_low_pc";
11958 case DW_AT_high_pc
:
11959 return "DW_AT_high_pc";
11960 case DW_AT_language
:
11961 return "DW_AT_language";
11963 return "DW_AT_member";
11965 return "DW_AT_discr";
11966 case DW_AT_discr_value
:
11967 return "DW_AT_discr_value";
11968 case DW_AT_visibility
:
11969 return "DW_AT_visibility";
11971 return "DW_AT_import";
11972 case DW_AT_string_length
:
11973 return "DW_AT_string_length";
11974 case DW_AT_common_reference
:
11975 return "DW_AT_common_reference";
11976 case DW_AT_comp_dir
:
11977 return "DW_AT_comp_dir";
11978 case DW_AT_const_value
:
11979 return "DW_AT_const_value";
11980 case DW_AT_containing_type
:
11981 return "DW_AT_containing_type";
11982 case DW_AT_default_value
:
11983 return "DW_AT_default_value";
11985 return "DW_AT_inline";
11986 case DW_AT_is_optional
:
11987 return "DW_AT_is_optional";
11988 case DW_AT_lower_bound
:
11989 return "DW_AT_lower_bound";
11990 case DW_AT_producer
:
11991 return "DW_AT_producer";
11992 case DW_AT_prototyped
:
11993 return "DW_AT_prototyped";
11994 case DW_AT_return_addr
:
11995 return "DW_AT_return_addr";
11996 case DW_AT_start_scope
:
11997 return "DW_AT_start_scope";
11998 case DW_AT_bit_stride
:
11999 return "DW_AT_bit_stride";
12000 case DW_AT_upper_bound
:
12001 return "DW_AT_upper_bound";
12002 case DW_AT_abstract_origin
:
12003 return "DW_AT_abstract_origin";
12004 case DW_AT_accessibility
:
12005 return "DW_AT_accessibility";
12006 case DW_AT_address_class
:
12007 return "DW_AT_address_class";
12008 case DW_AT_artificial
:
12009 return "DW_AT_artificial";
12010 case DW_AT_base_types
:
12011 return "DW_AT_base_types";
12012 case DW_AT_calling_convention
:
12013 return "DW_AT_calling_convention";
12015 return "DW_AT_count";
12016 case DW_AT_data_member_location
:
12017 return "DW_AT_data_member_location";
12018 case DW_AT_decl_column
:
12019 return "DW_AT_decl_column";
12020 case DW_AT_decl_file
:
12021 return "DW_AT_decl_file";
12022 case DW_AT_decl_line
:
12023 return "DW_AT_decl_line";
12024 case DW_AT_declaration
:
12025 return "DW_AT_declaration";
12026 case DW_AT_discr_list
:
12027 return "DW_AT_discr_list";
12028 case DW_AT_encoding
:
12029 return "DW_AT_encoding";
12030 case DW_AT_external
:
12031 return "DW_AT_external";
12032 case DW_AT_frame_base
:
12033 return "DW_AT_frame_base";
12035 return "DW_AT_friend";
12036 case DW_AT_identifier_case
:
12037 return "DW_AT_identifier_case";
12038 case DW_AT_macro_info
:
12039 return "DW_AT_macro_info";
12040 case DW_AT_namelist_items
:
12041 return "DW_AT_namelist_items";
12042 case DW_AT_priority
:
12043 return "DW_AT_priority";
12044 case DW_AT_segment
:
12045 return "DW_AT_segment";
12046 case DW_AT_specification
:
12047 return "DW_AT_specification";
12048 case DW_AT_static_link
:
12049 return "DW_AT_static_link";
12051 return "DW_AT_type";
12052 case DW_AT_use_location
:
12053 return "DW_AT_use_location";
12054 case DW_AT_variable_parameter
:
12055 return "DW_AT_variable_parameter";
12056 case DW_AT_virtuality
:
12057 return "DW_AT_virtuality";
12058 case DW_AT_vtable_elem_location
:
12059 return "DW_AT_vtable_elem_location";
12060 /* DWARF 3 values. */
12061 case DW_AT_allocated
:
12062 return "DW_AT_allocated";
12063 case DW_AT_associated
:
12064 return "DW_AT_associated";
12065 case DW_AT_data_location
:
12066 return "DW_AT_data_location";
12067 case DW_AT_byte_stride
:
12068 return "DW_AT_byte_stride";
12069 case DW_AT_entry_pc
:
12070 return "DW_AT_entry_pc";
12071 case DW_AT_use_UTF8
:
12072 return "DW_AT_use_UTF8";
12073 case DW_AT_extension
:
12074 return "DW_AT_extension";
12076 return "DW_AT_ranges";
12077 case DW_AT_trampoline
:
12078 return "DW_AT_trampoline";
12079 case DW_AT_call_column
:
12080 return "DW_AT_call_column";
12081 case DW_AT_call_file
:
12082 return "DW_AT_call_file";
12083 case DW_AT_call_line
:
12084 return "DW_AT_call_line";
12085 case DW_AT_description
:
12086 return "DW_AT_description";
12087 case DW_AT_binary_scale
:
12088 return "DW_AT_binary_scale";
12089 case DW_AT_decimal_scale
:
12090 return "DW_AT_decimal_scale";
12092 return "DW_AT_small";
12093 case DW_AT_decimal_sign
:
12094 return "DW_AT_decimal_sign";
12095 case DW_AT_digit_count
:
12096 return "DW_AT_digit_count";
12097 case DW_AT_picture_string
:
12098 return "DW_AT_picture_string";
12099 case DW_AT_mutable
:
12100 return "DW_AT_mutable";
12101 case DW_AT_threads_scaled
:
12102 return "DW_AT_threads_scaled";
12103 case DW_AT_explicit
:
12104 return "DW_AT_explicit";
12105 case DW_AT_object_pointer
:
12106 return "DW_AT_object_pointer";
12107 case DW_AT_endianity
:
12108 return "DW_AT_endianity";
12109 case DW_AT_elemental
:
12110 return "DW_AT_elemental";
12112 return "DW_AT_pure";
12113 case DW_AT_recursive
:
12114 return "DW_AT_recursive";
12115 /* DWARF 4 values. */
12116 case DW_AT_signature
:
12117 return "DW_AT_signature";
12118 case DW_AT_linkage_name
:
12119 return "DW_AT_linkage_name";
12120 /* SGI/MIPS extensions. */
12121 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12122 case DW_AT_MIPS_fde
:
12123 return "DW_AT_MIPS_fde";
12125 case DW_AT_MIPS_loop_begin
:
12126 return "DW_AT_MIPS_loop_begin";
12127 case DW_AT_MIPS_tail_loop_begin
:
12128 return "DW_AT_MIPS_tail_loop_begin";
12129 case DW_AT_MIPS_epilog_begin
:
12130 return "DW_AT_MIPS_epilog_begin";
12131 case DW_AT_MIPS_loop_unroll_factor
:
12132 return "DW_AT_MIPS_loop_unroll_factor";
12133 case DW_AT_MIPS_software_pipeline_depth
:
12134 return "DW_AT_MIPS_software_pipeline_depth";
12135 case DW_AT_MIPS_linkage_name
:
12136 return "DW_AT_MIPS_linkage_name";
12137 case DW_AT_MIPS_stride
:
12138 return "DW_AT_MIPS_stride";
12139 case DW_AT_MIPS_abstract_name
:
12140 return "DW_AT_MIPS_abstract_name";
12141 case DW_AT_MIPS_clone_origin
:
12142 return "DW_AT_MIPS_clone_origin";
12143 case DW_AT_MIPS_has_inlines
:
12144 return "DW_AT_MIPS_has_inlines";
12145 /* HP extensions. */
12146 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12147 case DW_AT_HP_block_index
:
12148 return "DW_AT_HP_block_index";
12150 case DW_AT_HP_unmodifiable
:
12151 return "DW_AT_HP_unmodifiable";
12152 case DW_AT_HP_actuals_stmt_list
:
12153 return "DW_AT_HP_actuals_stmt_list";
12154 case DW_AT_HP_proc_per_section
:
12155 return "DW_AT_HP_proc_per_section";
12156 case DW_AT_HP_raw_data_ptr
:
12157 return "DW_AT_HP_raw_data_ptr";
12158 case DW_AT_HP_pass_by_reference
:
12159 return "DW_AT_HP_pass_by_reference";
12160 case DW_AT_HP_opt_level
:
12161 return "DW_AT_HP_opt_level";
12162 case DW_AT_HP_prof_version_id
:
12163 return "DW_AT_HP_prof_version_id";
12164 case DW_AT_HP_opt_flags
:
12165 return "DW_AT_HP_opt_flags";
12166 case DW_AT_HP_cold_region_low_pc
:
12167 return "DW_AT_HP_cold_region_low_pc";
12168 case DW_AT_HP_cold_region_high_pc
:
12169 return "DW_AT_HP_cold_region_high_pc";
12170 case DW_AT_HP_all_variables_modifiable
:
12171 return "DW_AT_HP_all_variables_modifiable";
12172 case DW_AT_HP_linkage_name
:
12173 return "DW_AT_HP_linkage_name";
12174 case DW_AT_HP_prof_flags
:
12175 return "DW_AT_HP_prof_flags";
12176 /* GNU extensions. */
12177 case DW_AT_sf_names
:
12178 return "DW_AT_sf_names";
12179 case DW_AT_src_info
:
12180 return "DW_AT_src_info";
12181 case DW_AT_mac_info
:
12182 return "DW_AT_mac_info";
12183 case DW_AT_src_coords
:
12184 return "DW_AT_src_coords";
12185 case DW_AT_body_begin
:
12186 return "DW_AT_body_begin";
12187 case DW_AT_body_end
:
12188 return "DW_AT_body_end";
12189 case DW_AT_GNU_vector
:
12190 return "DW_AT_GNU_vector";
12191 case DW_AT_GNU_odr_signature
:
12192 return "DW_AT_GNU_odr_signature";
12193 /* VMS extensions. */
12194 case DW_AT_VMS_rtnbeg_pd_address
:
12195 return "DW_AT_VMS_rtnbeg_pd_address";
12196 /* UPC extension. */
12197 case DW_AT_upc_threads_scaled
:
12198 return "DW_AT_upc_threads_scaled";
12199 /* PGI (STMicroelectronics) extensions. */
12200 case DW_AT_PGI_lbase
:
12201 return "DW_AT_PGI_lbase";
12202 case DW_AT_PGI_soffset
:
12203 return "DW_AT_PGI_soffset";
12204 case DW_AT_PGI_lstride
:
12205 return "DW_AT_PGI_lstride";
12207 return "DW_AT_<unknown>";
12211 /* Convert a DWARF value form code into its string name. */
12214 dwarf_form_name (unsigned form
)
12219 return "DW_FORM_addr";
12220 case DW_FORM_block2
:
12221 return "DW_FORM_block2";
12222 case DW_FORM_block4
:
12223 return "DW_FORM_block4";
12224 case DW_FORM_data2
:
12225 return "DW_FORM_data2";
12226 case DW_FORM_data4
:
12227 return "DW_FORM_data4";
12228 case DW_FORM_data8
:
12229 return "DW_FORM_data8";
12230 case DW_FORM_string
:
12231 return "DW_FORM_string";
12232 case DW_FORM_block
:
12233 return "DW_FORM_block";
12234 case DW_FORM_block1
:
12235 return "DW_FORM_block1";
12236 case DW_FORM_data1
:
12237 return "DW_FORM_data1";
12239 return "DW_FORM_flag";
12240 case DW_FORM_sdata
:
12241 return "DW_FORM_sdata";
12243 return "DW_FORM_strp";
12244 case DW_FORM_udata
:
12245 return "DW_FORM_udata";
12246 case DW_FORM_ref_addr
:
12247 return "DW_FORM_ref_addr";
12249 return "DW_FORM_ref1";
12251 return "DW_FORM_ref2";
12253 return "DW_FORM_ref4";
12255 return "DW_FORM_ref8";
12256 case DW_FORM_ref_udata
:
12257 return "DW_FORM_ref_udata";
12258 case DW_FORM_indirect
:
12259 return "DW_FORM_indirect";
12260 case DW_FORM_sec_offset
:
12261 return "DW_FORM_sec_offset";
12262 case DW_FORM_exprloc
:
12263 return "DW_FORM_exprloc";
12264 case DW_FORM_flag_present
:
12265 return "DW_FORM_flag_present";
12267 return "DW_FORM_sig8";
12269 return "DW_FORM_<unknown>";
12273 /* Convert a DWARF stack opcode into its string name. */
12276 dwarf_stack_op_name (unsigned op
, int def
)
12281 return "DW_OP_addr";
12283 return "DW_OP_deref";
12284 case DW_OP_const1u
:
12285 return "DW_OP_const1u";
12286 case DW_OP_const1s
:
12287 return "DW_OP_const1s";
12288 case DW_OP_const2u
:
12289 return "DW_OP_const2u";
12290 case DW_OP_const2s
:
12291 return "DW_OP_const2s";
12292 case DW_OP_const4u
:
12293 return "DW_OP_const4u";
12294 case DW_OP_const4s
:
12295 return "DW_OP_const4s";
12296 case DW_OP_const8u
:
12297 return "DW_OP_const8u";
12298 case DW_OP_const8s
:
12299 return "DW_OP_const8s";
12301 return "DW_OP_constu";
12303 return "DW_OP_consts";
12305 return "DW_OP_dup";
12307 return "DW_OP_drop";
12309 return "DW_OP_over";
12311 return "DW_OP_pick";
12313 return "DW_OP_swap";
12315 return "DW_OP_rot";
12317 return "DW_OP_xderef";
12319 return "DW_OP_abs";
12321 return "DW_OP_and";
12323 return "DW_OP_div";
12325 return "DW_OP_minus";
12327 return "DW_OP_mod";
12329 return "DW_OP_mul";
12331 return "DW_OP_neg";
12333 return "DW_OP_not";
12337 return "DW_OP_plus";
12338 case DW_OP_plus_uconst
:
12339 return "DW_OP_plus_uconst";
12341 return "DW_OP_shl";
12343 return "DW_OP_shr";
12345 return "DW_OP_shra";
12347 return "DW_OP_xor";
12349 return "DW_OP_bra";
12363 return "DW_OP_skip";
12365 return "DW_OP_lit0";
12367 return "DW_OP_lit1";
12369 return "DW_OP_lit2";
12371 return "DW_OP_lit3";
12373 return "DW_OP_lit4";
12375 return "DW_OP_lit5";
12377 return "DW_OP_lit6";
12379 return "DW_OP_lit7";
12381 return "DW_OP_lit8";
12383 return "DW_OP_lit9";
12385 return "DW_OP_lit10";
12387 return "DW_OP_lit11";
12389 return "DW_OP_lit12";
12391 return "DW_OP_lit13";
12393 return "DW_OP_lit14";
12395 return "DW_OP_lit15";
12397 return "DW_OP_lit16";
12399 return "DW_OP_lit17";
12401 return "DW_OP_lit18";
12403 return "DW_OP_lit19";
12405 return "DW_OP_lit20";
12407 return "DW_OP_lit21";
12409 return "DW_OP_lit22";
12411 return "DW_OP_lit23";
12413 return "DW_OP_lit24";
12415 return "DW_OP_lit25";
12417 return "DW_OP_lit26";
12419 return "DW_OP_lit27";
12421 return "DW_OP_lit28";
12423 return "DW_OP_lit29";
12425 return "DW_OP_lit30";
12427 return "DW_OP_lit31";
12429 return "DW_OP_reg0";
12431 return "DW_OP_reg1";
12433 return "DW_OP_reg2";
12435 return "DW_OP_reg3";
12437 return "DW_OP_reg4";
12439 return "DW_OP_reg5";
12441 return "DW_OP_reg6";
12443 return "DW_OP_reg7";
12445 return "DW_OP_reg8";
12447 return "DW_OP_reg9";
12449 return "DW_OP_reg10";
12451 return "DW_OP_reg11";
12453 return "DW_OP_reg12";
12455 return "DW_OP_reg13";
12457 return "DW_OP_reg14";
12459 return "DW_OP_reg15";
12461 return "DW_OP_reg16";
12463 return "DW_OP_reg17";
12465 return "DW_OP_reg18";
12467 return "DW_OP_reg19";
12469 return "DW_OP_reg20";
12471 return "DW_OP_reg21";
12473 return "DW_OP_reg22";
12475 return "DW_OP_reg23";
12477 return "DW_OP_reg24";
12479 return "DW_OP_reg25";
12481 return "DW_OP_reg26";
12483 return "DW_OP_reg27";
12485 return "DW_OP_reg28";
12487 return "DW_OP_reg29";
12489 return "DW_OP_reg30";
12491 return "DW_OP_reg31";
12493 return "DW_OP_breg0";
12495 return "DW_OP_breg1";
12497 return "DW_OP_breg2";
12499 return "DW_OP_breg3";
12501 return "DW_OP_breg4";
12503 return "DW_OP_breg5";
12505 return "DW_OP_breg6";
12507 return "DW_OP_breg7";
12509 return "DW_OP_breg8";
12511 return "DW_OP_breg9";
12513 return "DW_OP_breg10";
12515 return "DW_OP_breg11";
12517 return "DW_OP_breg12";
12519 return "DW_OP_breg13";
12521 return "DW_OP_breg14";
12523 return "DW_OP_breg15";
12525 return "DW_OP_breg16";
12527 return "DW_OP_breg17";
12529 return "DW_OP_breg18";
12531 return "DW_OP_breg19";
12533 return "DW_OP_breg20";
12535 return "DW_OP_breg21";
12537 return "DW_OP_breg22";
12539 return "DW_OP_breg23";
12541 return "DW_OP_breg24";
12543 return "DW_OP_breg25";
12545 return "DW_OP_breg26";
12547 return "DW_OP_breg27";
12549 return "DW_OP_breg28";
12551 return "DW_OP_breg29";
12553 return "DW_OP_breg30";
12555 return "DW_OP_breg31";
12557 return "DW_OP_regx";
12559 return "DW_OP_fbreg";
12561 return "DW_OP_bregx";
12563 return "DW_OP_piece";
12564 case DW_OP_deref_size
:
12565 return "DW_OP_deref_size";
12566 case DW_OP_xderef_size
:
12567 return "DW_OP_xderef_size";
12569 return "DW_OP_nop";
12570 /* DWARF 3 extensions. */
12571 case DW_OP_push_object_address
:
12572 return "DW_OP_push_object_address";
12574 return "DW_OP_call2";
12576 return "DW_OP_call4";
12577 case DW_OP_call_ref
:
12578 return "DW_OP_call_ref";
12579 case DW_OP_form_tls_address
:
12580 return "DW_OP_form_tls_address";
12581 case DW_OP_call_frame_cfa
:
12582 return "DW_OP_call_frame_cfa";
12583 case DW_OP_bit_piece
:
12584 return "DW_OP_bit_piece";
12585 /* DWARF 4 extensions. */
12586 case DW_OP_implicit_value
:
12587 return "DW_OP_implicit_value";
12588 case DW_OP_stack_value
:
12589 return "DW_OP_stack_value";
12590 /* GNU extensions. */
12591 case DW_OP_GNU_push_tls_address
:
12592 return "DW_OP_GNU_push_tls_address";
12593 case DW_OP_GNU_uninit
:
12594 return "DW_OP_GNU_uninit";
12595 case DW_OP_GNU_implicit_pointer
:
12596 return "DW_OP_GNU_implicit_pointer";
12598 return def
? "OP_<unknown>" : NULL
;
12603 dwarf_bool_name (unsigned mybool
)
12611 /* Convert a DWARF type code into its string name. */
12614 dwarf_type_encoding_name (unsigned enc
)
12619 return "DW_ATE_void";
12620 case DW_ATE_address
:
12621 return "DW_ATE_address";
12622 case DW_ATE_boolean
:
12623 return "DW_ATE_boolean";
12624 case DW_ATE_complex_float
:
12625 return "DW_ATE_complex_float";
12627 return "DW_ATE_float";
12628 case DW_ATE_signed
:
12629 return "DW_ATE_signed";
12630 case DW_ATE_signed_char
:
12631 return "DW_ATE_signed_char";
12632 case DW_ATE_unsigned
:
12633 return "DW_ATE_unsigned";
12634 case DW_ATE_unsigned_char
:
12635 return "DW_ATE_unsigned_char";
12637 case DW_ATE_imaginary_float
:
12638 return "DW_ATE_imaginary_float";
12639 case DW_ATE_packed_decimal
:
12640 return "DW_ATE_packed_decimal";
12641 case DW_ATE_numeric_string
:
12642 return "DW_ATE_numeric_string";
12643 case DW_ATE_edited
:
12644 return "DW_ATE_edited";
12645 case DW_ATE_signed_fixed
:
12646 return "DW_ATE_signed_fixed";
12647 case DW_ATE_unsigned_fixed
:
12648 return "DW_ATE_unsigned_fixed";
12649 case DW_ATE_decimal_float
:
12650 return "DW_ATE_decimal_float";
12653 return "DW_ATE_UTF";
12654 /* HP extensions. */
12655 case DW_ATE_HP_float80
:
12656 return "DW_ATE_HP_float80";
12657 case DW_ATE_HP_complex_float80
:
12658 return "DW_ATE_HP_complex_float80";
12659 case DW_ATE_HP_float128
:
12660 return "DW_ATE_HP_float128";
12661 case DW_ATE_HP_complex_float128
:
12662 return "DW_ATE_HP_complex_float128";
12663 case DW_ATE_HP_floathpintel
:
12664 return "DW_ATE_HP_floathpintel";
12665 case DW_ATE_HP_imaginary_float80
:
12666 return "DW_ATE_HP_imaginary_float80";
12667 case DW_ATE_HP_imaginary_float128
:
12668 return "DW_ATE_HP_imaginary_float128";
12670 return "DW_ATE_<unknown>";
12674 /* Convert a DWARF call frame info operation to its string name. */
12678 dwarf_cfi_name (unsigned cfi_opc
)
12682 case DW_CFA_advance_loc
:
12683 return "DW_CFA_advance_loc";
12684 case DW_CFA_offset
:
12685 return "DW_CFA_offset";
12686 case DW_CFA_restore
:
12687 return "DW_CFA_restore";
12689 return "DW_CFA_nop";
12690 case DW_CFA_set_loc
:
12691 return "DW_CFA_set_loc";
12692 case DW_CFA_advance_loc1
:
12693 return "DW_CFA_advance_loc1";
12694 case DW_CFA_advance_loc2
:
12695 return "DW_CFA_advance_loc2";
12696 case DW_CFA_advance_loc4
:
12697 return "DW_CFA_advance_loc4";
12698 case DW_CFA_offset_extended
:
12699 return "DW_CFA_offset_extended";
12700 case DW_CFA_restore_extended
:
12701 return "DW_CFA_restore_extended";
12702 case DW_CFA_undefined
:
12703 return "DW_CFA_undefined";
12704 case DW_CFA_same_value
:
12705 return "DW_CFA_same_value";
12706 case DW_CFA_register
:
12707 return "DW_CFA_register";
12708 case DW_CFA_remember_state
:
12709 return "DW_CFA_remember_state";
12710 case DW_CFA_restore_state
:
12711 return "DW_CFA_restore_state";
12712 case DW_CFA_def_cfa
:
12713 return "DW_CFA_def_cfa";
12714 case DW_CFA_def_cfa_register
:
12715 return "DW_CFA_def_cfa_register";
12716 case DW_CFA_def_cfa_offset
:
12717 return "DW_CFA_def_cfa_offset";
12719 case DW_CFA_def_cfa_expression
:
12720 return "DW_CFA_def_cfa_expression";
12721 case DW_CFA_expression
:
12722 return "DW_CFA_expression";
12723 case DW_CFA_offset_extended_sf
:
12724 return "DW_CFA_offset_extended_sf";
12725 case DW_CFA_def_cfa_sf
:
12726 return "DW_CFA_def_cfa_sf";
12727 case DW_CFA_def_cfa_offset_sf
:
12728 return "DW_CFA_def_cfa_offset_sf";
12729 case DW_CFA_val_offset
:
12730 return "DW_CFA_val_offset";
12731 case DW_CFA_val_offset_sf
:
12732 return "DW_CFA_val_offset_sf";
12733 case DW_CFA_val_expression
:
12734 return "DW_CFA_val_expression";
12735 /* SGI/MIPS specific. */
12736 case DW_CFA_MIPS_advance_loc8
:
12737 return "DW_CFA_MIPS_advance_loc8";
12738 /* GNU extensions. */
12739 case DW_CFA_GNU_window_save
:
12740 return "DW_CFA_GNU_window_save";
12741 case DW_CFA_GNU_args_size
:
12742 return "DW_CFA_GNU_args_size";
12743 case DW_CFA_GNU_negative_offset_extended
:
12744 return "DW_CFA_GNU_negative_offset_extended";
12746 return "DW_CFA_<unknown>";
12752 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12756 print_spaces (indent
, f
);
12757 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12758 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12760 if (die
->parent
!= NULL
)
12762 print_spaces (indent
, f
);
12763 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12764 die
->parent
->offset
);
12767 print_spaces (indent
, f
);
12768 fprintf_unfiltered (f
, " has children: %s\n",
12769 dwarf_bool_name (die
->child
!= NULL
));
12771 print_spaces (indent
, f
);
12772 fprintf_unfiltered (f
, " attributes:\n");
12774 for (i
= 0; i
< die
->num_attrs
; ++i
)
12776 print_spaces (indent
, f
);
12777 fprintf_unfiltered (f
, " %s (%s) ",
12778 dwarf_attr_name (die
->attrs
[i
].name
),
12779 dwarf_form_name (die
->attrs
[i
].form
));
12781 switch (die
->attrs
[i
].form
)
12783 case DW_FORM_ref_addr
:
12785 fprintf_unfiltered (f
, "address: ");
12786 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12788 case DW_FORM_block2
:
12789 case DW_FORM_block4
:
12790 case DW_FORM_block
:
12791 case DW_FORM_block1
:
12792 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
12794 case DW_FORM_exprloc
:
12795 fprintf_unfiltered (f
, "expression: size %u",
12796 DW_BLOCK (&die
->attrs
[i
])->size
);
12801 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12802 (long) (DW_ADDR (&die
->attrs
[i
])));
12804 case DW_FORM_data1
:
12805 case DW_FORM_data2
:
12806 case DW_FORM_data4
:
12807 case DW_FORM_data8
:
12808 case DW_FORM_udata
:
12809 case DW_FORM_sdata
:
12810 fprintf_unfiltered (f
, "constant: %s",
12811 pulongest (DW_UNSND (&die
->attrs
[i
])));
12813 case DW_FORM_sec_offset
:
12814 fprintf_unfiltered (f
, "section offset: %s",
12815 pulongest (DW_UNSND (&die
->attrs
[i
])));
12818 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12819 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12820 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12822 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12824 case DW_FORM_string
:
12826 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12827 DW_STRING (&die
->attrs
[i
])
12828 ? DW_STRING (&die
->attrs
[i
]) : "",
12829 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12832 if (DW_UNSND (&die
->attrs
[i
]))
12833 fprintf_unfiltered (f
, "flag: TRUE");
12835 fprintf_unfiltered (f
, "flag: FALSE");
12837 case DW_FORM_flag_present
:
12838 fprintf_unfiltered (f
, "flag: TRUE");
12840 case DW_FORM_indirect
:
12841 /* the reader will have reduced the indirect form to
12842 the "base form" so this form should not occur */
12843 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
12846 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
12847 die
->attrs
[i
].form
);
12850 fprintf_unfiltered (f
, "\n");
12855 dump_die_for_error (struct die_info
*die
)
12857 dump_die_shallow (gdb_stderr
, 0, die
);
12861 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
12863 int indent
= level
* 4;
12865 gdb_assert (die
!= NULL
);
12867 if (level
>= max_level
)
12870 dump_die_shallow (f
, indent
, die
);
12872 if (die
->child
!= NULL
)
12874 print_spaces (indent
, f
);
12875 fprintf_unfiltered (f
, " Children:");
12876 if (level
+ 1 < max_level
)
12878 fprintf_unfiltered (f
, "\n");
12879 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
12883 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
12887 if (die
->sibling
!= NULL
&& level
> 0)
12889 dump_die_1 (f
, level
, max_level
, die
->sibling
);
12893 /* This is called from the pdie macro in gdbinit.in.
12894 It's not static so gcc will keep a copy callable from gdb. */
12897 dump_die (struct die_info
*die
, int max_level
)
12899 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
12903 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
12907 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
12913 is_ref_attr (struct attribute
*attr
)
12915 switch (attr
->form
)
12917 case DW_FORM_ref_addr
:
12922 case DW_FORM_ref_udata
:
12929 static unsigned int
12930 dwarf2_get_ref_die_offset (struct attribute
*attr
)
12932 if (is_ref_attr (attr
))
12933 return DW_ADDR (attr
);
12935 complaint (&symfile_complaints
,
12936 _("unsupported die ref attribute form: '%s'"),
12937 dwarf_form_name (attr
->form
));
12941 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
12942 * the value held by the attribute is not constant. */
12945 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
12947 if (attr
->form
== DW_FORM_sdata
)
12948 return DW_SND (attr
);
12949 else if (attr
->form
== DW_FORM_udata
12950 || attr
->form
== DW_FORM_data1
12951 || attr
->form
== DW_FORM_data2
12952 || attr
->form
== DW_FORM_data4
12953 || attr
->form
== DW_FORM_data8
)
12954 return DW_UNSND (attr
);
12957 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
12958 dwarf_form_name (attr
->form
));
12959 return default_value
;
12963 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
12964 unit and add it to our queue.
12965 The result is non-zero if PER_CU was queued, otherwise the result is zero
12966 meaning either PER_CU is already queued or it is already loaded. */
12969 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
12970 struct dwarf2_per_cu_data
*per_cu
)
12972 /* We may arrive here during partial symbol reading, if we need full
12973 DIEs to process an unusual case (e.g. template arguments). Do
12974 not queue PER_CU, just tell our caller to load its DIEs. */
12975 if (dwarf2_per_objfile
->reading_partial_symbols
)
12977 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
12982 /* Mark the dependence relation so that we don't flush PER_CU
12984 dwarf2_add_dependence (this_cu
, per_cu
);
12986 /* If it's already on the queue, we have nothing to do. */
12987 if (per_cu
->queued
)
12990 /* If the compilation unit is already loaded, just mark it as
12992 if (per_cu
->cu
!= NULL
)
12994 per_cu
->cu
->last_used
= 0;
12998 /* Add it to the queue. */
12999 queue_comp_unit (per_cu
, this_cu
->objfile
);
13004 /* Follow reference or signature attribute ATTR of SRC_DIE.
13005 On entry *REF_CU is the CU of SRC_DIE.
13006 On exit *REF_CU is the CU of the result. */
13008 static struct die_info
*
13009 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13010 struct dwarf2_cu
**ref_cu
)
13012 struct die_info
*die
;
13014 if (is_ref_attr (attr
))
13015 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13016 else if (attr
->form
== DW_FORM_sig8
)
13017 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13020 dump_die_for_error (src_die
);
13021 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13022 (*ref_cu
)->objfile
->name
);
13028 /* Follow reference OFFSET.
13029 On entry *REF_CU is the CU of the source die referencing OFFSET.
13030 On exit *REF_CU is the CU of the result.
13031 Returns NULL if OFFSET is invalid. */
13033 static struct die_info
*
13034 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13036 struct die_info temp_die
;
13037 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13039 gdb_assert (cu
->per_cu
!= NULL
);
13043 if (cu
->per_cu
->from_debug_types
)
13045 /* .debug_types CUs cannot reference anything outside their CU.
13046 If they need to, they have to reference a signatured type via
13048 if (! offset_in_cu_p (&cu
->header
, offset
))
13051 else if (! offset_in_cu_p (&cu
->header
, offset
))
13053 struct dwarf2_per_cu_data
*per_cu
;
13055 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13057 /* If necessary, add it to the queue and load its DIEs. */
13058 if (maybe_queue_comp_unit (cu
, per_cu
))
13059 load_full_comp_unit (per_cu
, cu
->objfile
);
13061 target_cu
= per_cu
->cu
;
13063 else if (cu
->dies
== NULL
)
13065 /* We're loading full DIEs during partial symbol reading. */
13066 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13067 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13070 *ref_cu
= target_cu
;
13071 temp_die
.offset
= offset
;
13072 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13075 /* Follow reference attribute ATTR of SRC_DIE.
13076 On entry *REF_CU is the CU of SRC_DIE.
13077 On exit *REF_CU is the CU of the result. */
13079 static struct die_info
*
13080 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13081 struct dwarf2_cu
**ref_cu
)
13083 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13084 struct dwarf2_cu
*cu
= *ref_cu
;
13085 struct die_info
*die
;
13087 die
= follow_die_offset (offset
, ref_cu
);
13089 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13090 "at 0x%x [in module %s]"),
13091 offset
, src_die
->offset
, cu
->objfile
->name
);
13096 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13097 value is intended for DW_OP_call*. */
13099 struct dwarf2_locexpr_baton
13100 dwarf2_fetch_die_location_block (unsigned int offset
,
13101 struct dwarf2_per_cu_data
*per_cu
,
13102 CORE_ADDR (*get_frame_pc
) (void *baton
),
13105 struct dwarf2_cu
*cu
= per_cu
->cu
;
13106 struct die_info
*die
;
13107 struct attribute
*attr
;
13108 struct dwarf2_locexpr_baton retval
;
13110 dw2_setup (per_cu
->objfile
);
13112 die
= follow_die_offset (offset
, &cu
);
13114 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13115 offset
, per_cu
->cu
->objfile
->name
);
13117 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13120 /* DWARF: "If there is no such attribute, then there is no effect.". */
13122 retval
.data
= NULL
;
13125 else if (attr_form_is_section_offset (attr
))
13127 struct dwarf2_loclist_baton loclist_baton
;
13128 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13131 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13133 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13135 retval
.size
= size
;
13139 if (!attr_form_is_block (attr
))
13140 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13141 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13142 offset
, per_cu
->cu
->objfile
->name
);
13144 retval
.data
= DW_BLOCK (attr
)->data
;
13145 retval
.size
= DW_BLOCK (attr
)->size
;
13147 retval
.per_cu
= cu
->per_cu
;
13151 /* Follow the signature attribute ATTR in SRC_DIE.
13152 On entry *REF_CU is the CU of SRC_DIE.
13153 On exit *REF_CU is the CU of the result. */
13155 static struct die_info
*
13156 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13157 struct dwarf2_cu
**ref_cu
)
13159 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13160 struct die_info temp_die
;
13161 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13162 struct dwarf2_cu
*sig_cu
;
13163 struct die_info
*die
;
13165 /* sig_type will be NULL if the signatured type is missing from
13167 if (sig_type
== NULL
)
13168 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13169 "at 0x%x [in module %s]"),
13170 src_die
->offset
, objfile
->name
);
13172 /* If necessary, add it to the queue and load its DIEs. */
13174 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13175 read_signatured_type (objfile
, sig_type
);
13177 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13179 sig_cu
= sig_type
->per_cu
.cu
;
13180 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13181 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13188 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
13189 "at 0x%x [in module %s]"),
13190 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13193 /* Given an offset of a signatured type, return its signatured_type. */
13195 static struct signatured_type
*
13196 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13198 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13199 unsigned int length
, initial_length_size
;
13200 unsigned int sig_offset
;
13201 struct signatured_type find_entry
, *type_sig
;
13203 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13204 sig_offset
= (initial_length_size
13206 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13207 + 1 /*address_size*/);
13208 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13209 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13211 /* This is only used to lookup previously recorded types.
13212 If we didn't find it, it's our bug. */
13213 gdb_assert (type_sig
!= NULL
);
13214 gdb_assert (offset
== type_sig
->offset
);
13219 /* Read in signatured type at OFFSET and build its CU and die(s). */
13222 read_signatured_type_at_offset (struct objfile
*objfile
,
13223 unsigned int offset
)
13225 struct signatured_type
*type_sig
;
13227 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13229 /* We have the section offset, but we need the signature to do the
13230 hash table lookup. */
13231 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13233 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13235 read_signatured_type (objfile
, type_sig
);
13237 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13240 /* Read in a signatured type and build its CU and DIEs. */
13243 read_signatured_type (struct objfile
*objfile
,
13244 struct signatured_type
*type_sig
)
13246 gdb_byte
*types_ptr
;
13247 struct die_reader_specs reader_specs
;
13248 struct dwarf2_cu
*cu
;
13249 ULONGEST signature
;
13250 struct cleanup
*back_to
, *free_cu_cleanup
;
13252 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13253 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13255 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13257 cu
= xmalloc (sizeof (*cu
));
13258 init_one_comp_unit (cu
, objfile
);
13260 type_sig
->per_cu
.cu
= cu
;
13261 cu
->per_cu
= &type_sig
->per_cu
;
13263 /* If an error occurs while loading, release our storage. */
13264 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13266 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13267 types_ptr
, objfile
->obfd
);
13268 gdb_assert (signature
== type_sig
->signature
);
13271 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13275 &cu
->comp_unit_obstack
,
13276 hashtab_obstack_allocate
,
13277 dummy_obstack_deallocate
);
13279 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13280 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13282 init_cu_die_reader (&reader_specs
, cu
);
13284 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13287 /* We try not to read any attributes in this function, because not
13288 all objfiles needed for references have been loaded yet, and symbol
13289 table processing isn't initialized. But we have to set the CU language,
13290 or we won't be able to build types correctly. */
13291 prepare_one_comp_unit (cu
, cu
->dies
);
13293 do_cleanups (back_to
);
13295 /* We've successfully allocated this compilation unit. Let our caller
13296 clean it up when finished with it. */
13297 discard_cleanups (free_cu_cleanup
);
13299 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13300 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13303 /* Decode simple location descriptions.
13304 Given a pointer to a dwarf block that defines a location, compute
13305 the location and return the value.
13307 NOTE drow/2003-11-18: This function is called in two situations
13308 now: for the address of static or global variables (partial symbols
13309 only) and for offsets into structures which are expected to be
13310 (more or less) constant. The partial symbol case should go away,
13311 and only the constant case should remain. That will let this
13312 function complain more accurately. A few special modes are allowed
13313 without complaint for global variables (for instance, global
13314 register values and thread-local values).
13316 A location description containing no operations indicates that the
13317 object is optimized out. The return value is 0 for that case.
13318 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13319 callers will only want a very basic result and this can become a
13322 Note that stack[0] is unused except as a default error return. */
13325 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13327 struct objfile
*objfile
= cu
->objfile
;
13329 int size
= blk
->size
;
13330 gdb_byte
*data
= blk
->data
;
13331 CORE_ADDR stack
[64];
13333 unsigned int bytes_read
, unsnd
;
13339 stack
[++stacki
] = 0;
13378 stack
[++stacki
] = op
- DW_OP_lit0
;
13413 stack
[++stacki
] = op
- DW_OP_reg0
;
13415 dwarf2_complex_location_expr_complaint ();
13419 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13421 stack
[++stacki
] = unsnd
;
13423 dwarf2_complex_location_expr_complaint ();
13427 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13432 case DW_OP_const1u
:
13433 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13437 case DW_OP_const1s
:
13438 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13442 case DW_OP_const2u
:
13443 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13447 case DW_OP_const2s
:
13448 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13452 case DW_OP_const4u
:
13453 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13457 case DW_OP_const4s
:
13458 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13463 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13469 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13474 stack
[stacki
+ 1] = stack
[stacki
];
13479 stack
[stacki
- 1] += stack
[stacki
];
13483 case DW_OP_plus_uconst
:
13484 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13489 stack
[stacki
- 1] -= stack
[stacki
];
13494 /* If we're not the last op, then we definitely can't encode
13495 this using GDB's address_class enum. This is valid for partial
13496 global symbols, although the variable's address will be bogus
13499 dwarf2_complex_location_expr_complaint ();
13502 case DW_OP_GNU_push_tls_address
:
13503 /* The top of the stack has the offset from the beginning
13504 of the thread control block at which the variable is located. */
13505 /* Nothing should follow this operator, so the top of stack would
13507 /* This is valid for partial global symbols, but the variable's
13508 address will be bogus in the psymtab. */
13510 dwarf2_complex_location_expr_complaint ();
13513 case DW_OP_GNU_uninit
:
13517 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13518 dwarf_stack_op_name (op
, 1));
13519 return (stack
[stacki
]);
13522 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13523 outside of the allocated space. Also enforce minimum>0. */
13524 if (stacki
>= ARRAY_SIZE (stack
) - 1)
13526 complaint (&symfile_complaints
,
13527 _("location description stack overflow"));
13533 complaint (&symfile_complaints
,
13534 _("location description stack underflow"));
13538 return (stack
[stacki
]);
13541 /* memory allocation interface */
13543 static struct dwarf_block
*
13544 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13546 struct dwarf_block
*blk
;
13548 blk
= (struct dwarf_block
*)
13549 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13553 static struct abbrev_info
*
13554 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13556 struct abbrev_info
*abbrev
;
13558 abbrev
= (struct abbrev_info
*)
13559 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13560 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13564 static struct die_info
*
13565 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13567 struct die_info
*die
;
13568 size_t size
= sizeof (struct die_info
);
13571 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13573 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13574 memset (die
, 0, sizeof (struct die_info
));
13579 /* Macro support. */
13581 /* Return the full name of file number I in *LH's file name table.
13582 Use COMP_DIR as the name of the current directory of the
13583 compilation. The result is allocated using xmalloc; the caller is
13584 responsible for freeing it. */
13586 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13588 /* Is the file number a valid index into the line header's file name
13589 table? Remember that file numbers start with one, not zero. */
13590 if (1 <= file
&& file
<= lh
->num_file_names
)
13592 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13594 if (IS_ABSOLUTE_PATH (fe
->name
))
13595 return xstrdup (fe
->name
);
13603 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13609 dir_len
= strlen (dir
);
13610 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13611 strcpy (full_name
, dir
);
13612 full_name
[dir_len
] = '/';
13613 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13617 return xstrdup (fe
->name
);
13622 /* The compiler produced a bogus file number. We can at least
13623 record the macro definitions made in the file, even if we
13624 won't be able to find the file by name. */
13625 char fake_name
[80];
13627 sprintf (fake_name
, "<bad macro file number %d>", file
);
13629 complaint (&symfile_complaints
,
13630 _("bad file number in macro information (%d)"),
13633 return xstrdup (fake_name
);
13638 static struct macro_source_file
*
13639 macro_start_file (int file
, int line
,
13640 struct macro_source_file
*current_file
,
13641 const char *comp_dir
,
13642 struct line_header
*lh
, struct objfile
*objfile
)
13644 /* The full name of this source file. */
13645 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13647 /* We don't create a macro table for this compilation unit
13648 at all until we actually get a filename. */
13649 if (! pending_macros
)
13650 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13651 objfile
->macro_cache
);
13653 if (! current_file
)
13654 /* If we have no current file, then this must be the start_file
13655 directive for the compilation unit's main source file. */
13656 current_file
= macro_set_main (pending_macros
, full_name
);
13658 current_file
= macro_include (current_file
, line
, full_name
);
13662 return current_file
;
13666 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13667 followed by a null byte. */
13669 copy_string (const char *buf
, int len
)
13671 char *s
= xmalloc (len
+ 1);
13673 memcpy (s
, buf
, len
);
13679 static const char *
13680 consume_improper_spaces (const char *p
, const char *body
)
13684 complaint (&symfile_complaints
,
13685 _("macro definition contains spaces in formal argument list:\n`%s'"),
13697 parse_macro_definition (struct macro_source_file
*file
, int line
,
13702 /* The body string takes one of two forms. For object-like macro
13703 definitions, it should be:
13705 <macro name> " " <definition>
13707 For function-like macro definitions, it should be:
13709 <macro name> "() " <definition>
13711 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13713 Spaces may appear only where explicitly indicated, and in the
13716 The Dwarf 2 spec says that an object-like macro's name is always
13717 followed by a space, but versions of GCC around March 2002 omit
13718 the space when the macro's definition is the empty string.
13720 The Dwarf 2 spec says that there should be no spaces between the
13721 formal arguments in a function-like macro's formal argument list,
13722 but versions of GCC around March 2002 include spaces after the
13726 /* Find the extent of the macro name. The macro name is terminated
13727 by either a space or null character (for an object-like macro) or
13728 an opening paren (for a function-like macro). */
13729 for (p
= body
; *p
; p
++)
13730 if (*p
== ' ' || *p
== '(')
13733 if (*p
== ' ' || *p
== '\0')
13735 /* It's an object-like macro. */
13736 int name_len
= p
- body
;
13737 char *name
= copy_string (body
, name_len
);
13738 const char *replacement
;
13741 replacement
= body
+ name_len
+ 1;
13744 dwarf2_macro_malformed_definition_complaint (body
);
13745 replacement
= body
+ name_len
;
13748 macro_define_object (file
, line
, name
, replacement
);
13752 else if (*p
== '(')
13754 /* It's a function-like macro. */
13755 char *name
= copy_string (body
, p
- body
);
13758 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13762 p
= consume_improper_spaces (p
, body
);
13764 /* Parse the formal argument list. */
13765 while (*p
&& *p
!= ')')
13767 /* Find the extent of the current argument name. */
13768 const char *arg_start
= p
;
13770 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13773 if (! *p
|| p
== arg_start
)
13774 dwarf2_macro_malformed_definition_complaint (body
);
13777 /* Make sure argv has room for the new argument. */
13778 if (argc
>= argv_size
)
13781 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13784 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13787 p
= consume_improper_spaces (p
, body
);
13789 /* Consume the comma, if present. */
13794 p
= consume_improper_spaces (p
, body
);
13803 /* Perfectly formed definition, no complaints. */
13804 macro_define_function (file
, line
, name
,
13805 argc
, (const char **) argv
,
13807 else if (*p
== '\0')
13809 /* Complain, but do define it. */
13810 dwarf2_macro_malformed_definition_complaint (body
);
13811 macro_define_function (file
, line
, name
,
13812 argc
, (const char **) argv
,
13816 /* Just complain. */
13817 dwarf2_macro_malformed_definition_complaint (body
);
13820 /* Just complain. */
13821 dwarf2_macro_malformed_definition_complaint (body
);
13827 for (i
= 0; i
< argc
; i
++)
13833 dwarf2_macro_malformed_definition_complaint (body
);
13838 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
13839 char *comp_dir
, bfd
*abfd
,
13840 struct dwarf2_cu
*cu
)
13842 gdb_byte
*mac_ptr
, *mac_end
;
13843 struct macro_source_file
*current_file
= 0;
13844 enum dwarf_macinfo_record_type macinfo_type
;
13845 int at_commandline
;
13847 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13848 &dwarf2_per_objfile
->macinfo
);
13849 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
13851 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
13855 /* First pass: Find the name of the base filename.
13856 This filename is needed in order to process all macros whose definition
13857 (or undefinition) comes from the command line. These macros are defined
13858 before the first DW_MACINFO_start_file entry, and yet still need to be
13859 associated to the base file.
13861 To determine the base file name, we scan the macro definitions until we
13862 reach the first DW_MACINFO_start_file entry. We then initialize
13863 CURRENT_FILE accordingly so that any macro definition found before the
13864 first DW_MACINFO_start_file can still be associated to the base file. */
13866 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13867 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
13868 + dwarf2_per_objfile
->macinfo
.size
;
13872 /* Do we at least have room for a macinfo type byte? */
13873 if (mac_ptr
>= mac_end
)
13875 /* Complaint is printed during the second pass as GDB will probably
13876 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13880 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13883 switch (macinfo_type
)
13885 /* A zero macinfo type indicates the end of the macro
13890 case DW_MACINFO_define
:
13891 case DW_MACINFO_undef
:
13892 /* Only skip the data by MAC_PTR. */
13894 unsigned int bytes_read
;
13896 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13897 mac_ptr
+= bytes_read
;
13898 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13899 mac_ptr
+= bytes_read
;
13903 case DW_MACINFO_start_file
:
13905 unsigned int bytes_read
;
13908 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13909 mac_ptr
+= bytes_read
;
13910 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13911 mac_ptr
+= bytes_read
;
13913 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
13918 case DW_MACINFO_end_file
:
13919 /* No data to skip by MAC_PTR. */
13922 case DW_MACINFO_vendor_ext
:
13923 /* Only skip the data by MAC_PTR. */
13925 unsigned int bytes_read
;
13927 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13928 mac_ptr
+= bytes_read
;
13929 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13930 mac_ptr
+= bytes_read
;
13937 } while (macinfo_type
!= 0 && current_file
== NULL
);
13939 /* Second pass: Process all entries.
13941 Use the AT_COMMAND_LINE flag to determine whether we are still processing
13942 command-line macro definitions/undefinitions. This flag is unset when we
13943 reach the first DW_MACINFO_start_file entry. */
13945 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13947 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
13948 GDB is still reading the definitions from command line. First
13949 DW_MACINFO_start_file will need to be ignored as it was already executed
13950 to create CURRENT_FILE for the main source holding also the command line
13951 definitions. On first met DW_MACINFO_start_file this flag is reset to
13952 normally execute all the remaining DW_MACINFO_start_file macinfos. */
13954 at_commandline
= 1;
13958 /* Do we at least have room for a macinfo type byte? */
13959 if (mac_ptr
>= mac_end
)
13961 dwarf2_macros_too_long_complaint ();
13965 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13968 switch (macinfo_type
)
13970 /* A zero macinfo type indicates the end of the macro
13975 case DW_MACINFO_define
:
13976 case DW_MACINFO_undef
:
13978 unsigned int bytes_read
;
13982 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13983 mac_ptr
+= bytes_read
;
13984 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13985 mac_ptr
+= bytes_read
;
13987 if (! current_file
)
13989 /* DWARF violation as no main source is present. */
13990 complaint (&symfile_complaints
,
13991 _("debug info with no main source gives macro %s "
13993 macinfo_type
== DW_MACINFO_define
?
13995 macinfo_type
== DW_MACINFO_undef
?
13996 _("undefinition") :
13997 _("something-or-other"), line
, body
);
14000 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
14001 complaint (&symfile_complaints
,
14002 _("debug info gives %s macro %s with %s line %d: %s"),
14003 at_commandline
? _("command-line") : _("in-file"),
14004 macinfo_type
== DW_MACINFO_define
?
14006 macinfo_type
== DW_MACINFO_undef
?
14007 _("undefinition") :
14008 _("something-or-other"),
14009 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14011 if (macinfo_type
== DW_MACINFO_define
)
14012 parse_macro_definition (current_file
, line
, body
);
14013 else if (macinfo_type
== DW_MACINFO_undef
)
14014 macro_undef (current_file
, line
, body
);
14018 case DW_MACINFO_start_file
:
14020 unsigned int bytes_read
;
14023 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14024 mac_ptr
+= bytes_read
;
14025 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14026 mac_ptr
+= bytes_read
;
14028 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
14029 complaint (&symfile_complaints
,
14030 _("debug info gives source %d included "
14031 "from %s at %s line %d"),
14032 file
, at_commandline
? _("command-line") : _("file"),
14033 line
== 0 ? _("zero") : _("non-zero"), line
);
14035 if (at_commandline
)
14037 /* This DW_MACINFO_start_file was executed in the pass one. */
14038 at_commandline
= 0;
14041 current_file
= macro_start_file (file
, line
,
14042 current_file
, comp_dir
,
14047 case DW_MACINFO_end_file
:
14048 if (! current_file
)
14049 complaint (&symfile_complaints
,
14050 _("macro debug info has an unmatched `close_file' directive"));
14053 current_file
= current_file
->included_by
;
14054 if (! current_file
)
14056 enum dwarf_macinfo_record_type next_type
;
14058 /* GCC circa March 2002 doesn't produce the zero
14059 type byte marking the end of the compilation
14060 unit. Complain if it's not there, but exit no
14063 /* Do we at least have room for a macinfo type byte? */
14064 if (mac_ptr
>= mac_end
)
14066 dwarf2_macros_too_long_complaint ();
14070 /* We don't increment mac_ptr here, so this is just
14072 next_type
= read_1_byte (abfd
, mac_ptr
);
14073 if (next_type
!= 0)
14074 complaint (&symfile_complaints
,
14075 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
14082 case DW_MACINFO_vendor_ext
:
14084 unsigned int bytes_read
;
14088 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14089 mac_ptr
+= bytes_read
;
14090 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14091 mac_ptr
+= bytes_read
;
14093 /* We don't recognize any vendor extensions. */
14097 } while (macinfo_type
!= 0);
14100 /* Check if the attribute's form is a DW_FORM_block*
14101 if so return true else false. */
14103 attr_form_is_block (struct attribute
*attr
)
14105 return (attr
== NULL
? 0 :
14106 attr
->form
== DW_FORM_block1
14107 || attr
->form
== DW_FORM_block2
14108 || attr
->form
== DW_FORM_block4
14109 || attr
->form
== DW_FORM_block
14110 || attr
->form
== DW_FORM_exprloc
);
14113 /* Return non-zero if ATTR's value is a section offset --- classes
14114 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14115 You may use DW_UNSND (attr) to retrieve such offsets.
14117 Section 7.5.4, "Attribute Encodings", explains that no attribute
14118 may have a value that belongs to more than one of these classes; it
14119 would be ambiguous if we did, because we use the same forms for all
14122 attr_form_is_section_offset (struct attribute
*attr
)
14124 return (attr
->form
== DW_FORM_data4
14125 || attr
->form
== DW_FORM_data8
14126 || attr
->form
== DW_FORM_sec_offset
);
14130 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14131 zero otherwise. When this function returns true, you can apply
14132 dwarf2_get_attr_constant_value to it.
14134 However, note that for some attributes you must check
14135 attr_form_is_section_offset before using this test. DW_FORM_data4
14136 and DW_FORM_data8 are members of both the constant class, and of
14137 the classes that contain offsets into other debug sections
14138 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14139 that, if an attribute's can be either a constant or one of the
14140 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14141 taken as section offsets, not constants. */
14143 attr_form_is_constant (struct attribute
*attr
)
14145 switch (attr
->form
)
14147 case DW_FORM_sdata
:
14148 case DW_FORM_udata
:
14149 case DW_FORM_data1
:
14150 case DW_FORM_data2
:
14151 case DW_FORM_data4
:
14152 case DW_FORM_data8
:
14159 /* A helper function that fills in a dwarf2_loclist_baton. */
14162 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14163 struct dwarf2_loclist_baton
*baton
,
14164 struct attribute
*attr
)
14166 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14167 &dwarf2_per_objfile
->loc
);
14169 baton
->per_cu
= cu
->per_cu
;
14170 gdb_assert (baton
->per_cu
);
14171 /* We don't know how long the location list is, but make sure we
14172 don't run off the edge of the section. */
14173 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14174 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14175 baton
->base_address
= cu
->base_address
;
14179 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14180 struct dwarf2_cu
*cu
)
14182 if (attr_form_is_section_offset (attr
)
14183 /* ".debug_loc" may not exist at all, or the offset may be outside
14184 the section. If so, fall through to the complaint in the
14186 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
14188 struct dwarf2_loclist_baton
*baton
;
14190 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14191 sizeof (struct dwarf2_loclist_baton
));
14193 fill_in_loclist_baton (cu
, baton
, attr
);
14195 if (cu
->base_known
== 0)
14196 complaint (&symfile_complaints
,
14197 _("Location list used without specifying the CU base address."));
14199 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14200 SYMBOL_LOCATION_BATON (sym
) = baton
;
14204 struct dwarf2_locexpr_baton
*baton
;
14206 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14207 sizeof (struct dwarf2_locexpr_baton
));
14208 baton
->per_cu
= cu
->per_cu
;
14209 gdb_assert (baton
->per_cu
);
14211 if (attr_form_is_block (attr
))
14213 /* Note that we're just copying the block's data pointer
14214 here, not the actual data. We're still pointing into the
14215 info_buffer for SYM's objfile; right now we never release
14216 that buffer, but when we do clean up properly this may
14218 baton
->size
= DW_BLOCK (attr
)->size
;
14219 baton
->data
= DW_BLOCK (attr
)->data
;
14223 dwarf2_invalid_attrib_class_complaint ("location description",
14224 SYMBOL_NATURAL_NAME (sym
));
14226 baton
->data
= NULL
;
14229 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14230 SYMBOL_LOCATION_BATON (sym
) = baton
;
14234 /* Return the OBJFILE associated with the compilation unit CU. If CU
14235 came from a separate debuginfo file, then the master objfile is
14239 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14241 struct objfile
*objfile
= per_cu
->objfile
;
14243 /* Return the master objfile, so that we can report and look up the
14244 correct file containing this variable. */
14245 if (objfile
->separate_debug_objfile_backlink
)
14246 objfile
= objfile
->separate_debug_objfile_backlink
;
14251 /* Return the address size given in the compilation unit header for CU. */
14254 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14257 return per_cu
->cu
->header
.addr_size
;
14260 /* If the CU is not currently read in, we re-read its header. */
14261 struct objfile
*objfile
= per_cu
->objfile
;
14262 struct dwarf2_per_objfile
*per_objfile
14263 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14264 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14265 struct comp_unit_head cu_header
;
14267 memset (&cu_header
, 0, sizeof cu_header
);
14268 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14269 return cu_header
.addr_size
;
14273 /* Return the offset size given in the compilation unit header for CU. */
14276 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14279 return per_cu
->cu
->header
.offset_size
;
14282 /* If the CU is not currently read in, we re-read its header. */
14283 struct objfile
*objfile
= per_cu
->objfile
;
14284 struct dwarf2_per_objfile
*per_objfile
14285 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14286 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14287 struct comp_unit_head cu_header
;
14289 memset (&cu_header
, 0, sizeof cu_header
);
14290 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14291 return cu_header
.offset_size
;
14295 /* Return the text offset of the CU. The returned offset comes from
14296 this CU's objfile. If this objfile came from a separate debuginfo
14297 file, then the offset may be different from the corresponding
14298 offset in the parent objfile. */
14301 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14303 struct objfile
*objfile
= per_cu
->objfile
;
14305 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14308 /* Locate the .debug_info compilation unit from CU's objfile which contains
14309 the DIE at OFFSET. Raises an error on failure. */
14311 static struct dwarf2_per_cu_data
*
14312 dwarf2_find_containing_comp_unit (unsigned int offset
,
14313 struct objfile
*objfile
)
14315 struct dwarf2_per_cu_data
*this_cu
;
14319 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14322 int mid
= low
+ (high
- low
) / 2;
14324 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14329 gdb_assert (low
== high
);
14330 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14333 error (_("Dwarf Error: could not find partial DIE containing "
14334 "offset 0x%lx [in module %s]"),
14335 (long) offset
, bfd_get_filename (objfile
->obfd
));
14337 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14338 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14342 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14343 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14344 && offset
>= this_cu
->offset
+ this_cu
->length
)
14345 error (_("invalid dwarf2 offset %u"), offset
);
14346 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14351 /* Locate the compilation unit from OBJFILE which is located at exactly
14352 OFFSET. Raises an error on failure. */
14354 static struct dwarf2_per_cu_data
*
14355 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14357 struct dwarf2_per_cu_data
*this_cu
;
14359 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14360 if (this_cu
->offset
!= offset
)
14361 error (_("no compilation unit with offset %u."), offset
);
14365 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14368 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14370 memset (cu
, 0, sizeof (*cu
));
14371 cu
->objfile
= objfile
;
14372 obstack_init (&cu
->comp_unit_obstack
);
14375 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14378 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14380 struct attribute
*attr
;
14382 /* Set the language we're debugging. */
14383 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14385 set_cu_language (DW_UNSND (attr
), cu
);
14387 set_cu_language (language_minimal
, cu
);
14390 /* Release one cached compilation unit, CU. We unlink it from the tree
14391 of compilation units, but we don't remove it from the read_in_chain;
14392 the caller is responsible for that.
14393 NOTE: DATA is a void * because this function is also used as a
14394 cleanup routine. */
14397 free_one_comp_unit (void *data
)
14399 struct dwarf2_cu
*cu
= data
;
14401 if (cu
->per_cu
!= NULL
)
14402 cu
->per_cu
->cu
= NULL
;
14405 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14410 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14411 when we're finished with it. We can't free the pointer itself, but be
14412 sure to unlink it from the cache. Also release any associated storage
14413 and perform cache maintenance.
14415 Only used during partial symbol parsing. */
14418 free_stack_comp_unit (void *data
)
14420 struct dwarf2_cu
*cu
= data
;
14422 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14423 cu
->partial_dies
= NULL
;
14425 if (cu
->per_cu
!= NULL
)
14427 /* This compilation unit is on the stack in our caller, so we
14428 should not xfree it. Just unlink it. */
14429 cu
->per_cu
->cu
= NULL
;
14432 /* If we had a per-cu pointer, then we may have other compilation
14433 units loaded, so age them now. */
14434 age_cached_comp_units ();
14438 /* Free all cached compilation units. */
14441 free_cached_comp_units (void *data
)
14443 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14445 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14446 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14447 while (per_cu
!= NULL
)
14449 struct dwarf2_per_cu_data
*next_cu
;
14451 next_cu
= per_cu
->cu
->read_in_chain
;
14453 free_one_comp_unit (per_cu
->cu
);
14454 *last_chain
= next_cu
;
14460 /* Increase the age counter on each cached compilation unit, and free
14461 any that are too old. */
14464 age_cached_comp_units (void)
14466 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14468 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14469 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14470 while (per_cu
!= NULL
)
14472 per_cu
->cu
->last_used
++;
14473 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14474 dwarf2_mark (per_cu
->cu
);
14475 per_cu
= per_cu
->cu
->read_in_chain
;
14478 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14479 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14480 while (per_cu
!= NULL
)
14482 struct dwarf2_per_cu_data
*next_cu
;
14484 next_cu
= per_cu
->cu
->read_in_chain
;
14486 if (!per_cu
->cu
->mark
)
14488 free_one_comp_unit (per_cu
->cu
);
14489 *last_chain
= next_cu
;
14492 last_chain
= &per_cu
->cu
->read_in_chain
;
14498 /* Remove a single compilation unit from the cache. */
14501 free_one_cached_comp_unit (void *target_cu
)
14503 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14505 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14506 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14507 while (per_cu
!= NULL
)
14509 struct dwarf2_per_cu_data
*next_cu
;
14511 next_cu
= per_cu
->cu
->read_in_chain
;
14513 if (per_cu
->cu
== target_cu
)
14515 free_one_comp_unit (per_cu
->cu
);
14516 *last_chain
= next_cu
;
14520 last_chain
= &per_cu
->cu
->read_in_chain
;
14526 /* Release all extra memory associated with OBJFILE. */
14529 dwarf2_free_objfile (struct objfile
*objfile
)
14531 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14533 if (dwarf2_per_objfile
== NULL
)
14536 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14537 free_cached_comp_units (NULL
);
14539 if (dwarf2_per_objfile
->using_index
)
14543 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14546 struct dwarf2_per_cu_data
*per_cu
=
14547 dwarf2_per_objfile
->all_comp_units
[i
];
14549 if (!per_cu
->v
.quick
->lines
)
14552 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
14554 if (per_cu
->v
.quick
->file_names
)
14555 xfree ((void *) per_cu
->v
.quick
->file_names
[j
]);
14556 if (per_cu
->v
.quick
->full_names
)
14557 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
14560 free_line_header (per_cu
->v
.quick
->lines
);
14564 /* Everything else should be on the objfile obstack. */
14567 /* A pair of DIE offset and GDB type pointer. We store these
14568 in a hash table separate from the DIEs, and preserve them
14569 when the DIEs are flushed out of cache. */
14571 struct dwarf2_offset_and_type
14573 unsigned int offset
;
14577 /* Hash function for a dwarf2_offset_and_type. */
14580 offset_and_type_hash (const void *item
)
14582 const struct dwarf2_offset_and_type
*ofs
= item
;
14584 return ofs
->offset
;
14587 /* Equality function for a dwarf2_offset_and_type. */
14590 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14592 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14593 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14595 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14598 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14599 table if necessary. For convenience, return TYPE.
14601 The DIEs reading must have careful ordering to:
14602 * Not cause infite loops trying to read in DIEs as a prerequisite for
14603 reading current DIE.
14604 * Not trying to dereference contents of still incompletely read in types
14605 while reading in other DIEs.
14606 * Enable referencing still incompletely read in types just by a pointer to
14607 the type without accessing its fields.
14609 Therefore caller should follow these rules:
14610 * Try to fetch any prerequisite types we may need to build this DIE type
14611 before building the type and calling set_die_type.
14612 * After building type call set_die_type for current DIE as soon as
14613 possible before fetching more types to complete the current type.
14614 * Make the type as complete as possible before fetching more types. */
14616 static struct type
*
14617 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14619 struct dwarf2_offset_and_type
**slot
, ofs
;
14620 struct objfile
*objfile
= cu
->objfile
;
14621 htab_t
*type_hash_ptr
;
14623 /* For Ada types, make sure that the gnat-specific data is always
14624 initialized (if not already set). There are a few types where
14625 we should not be doing so, because the type-specific area is
14626 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14627 where the type-specific area is used to store the floatformat).
14628 But this is not a problem, because the gnat-specific information
14629 is actually not needed for these types. */
14630 if (need_gnat_info (cu
)
14631 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14632 && TYPE_CODE (type
) != TYPE_CODE_FLT
14633 && !HAVE_GNAT_AUX_INFO (type
))
14634 INIT_GNAT_SPECIFIC (type
);
14636 if (cu
->per_cu
->from_debug_types
)
14637 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14639 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14641 if (*type_hash_ptr
== NULL
)
14644 = htab_create_alloc_ex (127,
14645 offset_and_type_hash
,
14646 offset_and_type_eq
,
14648 &objfile
->objfile_obstack
,
14649 hashtab_obstack_allocate
,
14650 dummy_obstack_deallocate
);
14653 ofs
.offset
= die
->offset
;
14655 slot
= (struct dwarf2_offset_and_type
**)
14656 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14658 complaint (&symfile_complaints
,
14659 _("A problem internal to GDB: DIE 0x%x has type already set"),
14661 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14666 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14667 table, or return NULL if the die does not have a saved type. */
14669 static struct type
*
14670 get_die_type_at_offset (unsigned int offset
,
14671 struct dwarf2_per_cu_data
*per_cu
)
14673 struct dwarf2_offset_and_type
*slot
, ofs
;
14676 if (per_cu
->from_debug_types
)
14677 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
14679 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
14680 if (type_hash
== NULL
)
14683 ofs
.offset
= offset
;
14684 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14691 /* Look up the type for DIE in the appropriate type_hash table,
14692 or return NULL if DIE does not have a saved type. */
14694 static struct type
*
14695 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14697 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
14700 /* Add a dependence relationship from CU to REF_PER_CU. */
14703 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14704 struct dwarf2_per_cu_data
*ref_per_cu
)
14708 if (cu
->dependencies
== NULL
)
14710 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14711 NULL
, &cu
->comp_unit_obstack
,
14712 hashtab_obstack_allocate
,
14713 dummy_obstack_deallocate
);
14715 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14717 *slot
= ref_per_cu
;
14720 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14721 Set the mark field in every compilation unit in the
14722 cache that we must keep because we are keeping CU. */
14725 dwarf2_mark_helper (void **slot
, void *data
)
14727 struct dwarf2_per_cu_data
*per_cu
;
14729 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14730 if (per_cu
->cu
->mark
)
14732 per_cu
->cu
->mark
= 1;
14734 if (per_cu
->cu
->dependencies
!= NULL
)
14735 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14740 /* Set the mark field in CU and in every other compilation unit in the
14741 cache that we must keep because we are keeping CU. */
14744 dwarf2_mark (struct dwarf2_cu
*cu
)
14749 if (cu
->dependencies
!= NULL
)
14750 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14754 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14758 per_cu
->cu
->mark
= 0;
14759 per_cu
= per_cu
->cu
->read_in_chain
;
14763 /* Trivial hash function for partial_die_info: the hash value of a DIE
14764 is its offset in .debug_info for this objfile. */
14767 partial_die_hash (const void *item
)
14769 const struct partial_die_info
*part_die
= item
;
14771 return part_die
->offset
;
14774 /* Trivial comparison function for partial_die_info structures: two DIEs
14775 are equal if they have the same offset. */
14778 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14780 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14781 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14783 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14786 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14787 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14790 set_dwarf2_cmd (char *args
, int from_tty
)
14792 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14796 show_dwarf2_cmd (char *args
, int from_tty
)
14798 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14801 /* If section described by INFO was mmapped, munmap it now. */
14804 munmap_section_buffer (struct dwarf2_section_info
*info
)
14806 if (info
->was_mmapped
)
14809 intptr_t begin
= (intptr_t) info
->buffer
;
14810 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14811 size_t map_length
= info
->size
+ begin
- map_begin
;
14813 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14815 /* Without HAVE_MMAP, we should never be here to begin with. */
14816 gdb_assert_not_reached ("no mmap support");
14821 /* munmap debug sections for OBJFILE, if necessary. */
14824 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14826 struct dwarf2_per_objfile
*data
= d
;
14828 /* This is sorted according to the order they're defined in to make it easier
14829 to keep in sync. */
14830 munmap_section_buffer (&data
->info
);
14831 munmap_section_buffer (&data
->abbrev
);
14832 munmap_section_buffer (&data
->line
);
14833 munmap_section_buffer (&data
->loc
);
14834 munmap_section_buffer (&data
->macinfo
);
14835 munmap_section_buffer (&data
->str
);
14836 munmap_section_buffer (&data
->ranges
);
14837 munmap_section_buffer (&data
->types
);
14838 munmap_section_buffer (&data
->frame
);
14839 munmap_section_buffer (&data
->eh_frame
);
14840 munmap_section_buffer (&data
->gdb_index
);
14844 /* The "save gdb-index" command. */
14846 /* The contents of the hash table we create when building the string
14848 struct strtab_entry
14850 offset_type offset
;
14854 /* Hash function for a strtab_entry. */
14857 hash_strtab_entry (const void *e
)
14859 const struct strtab_entry
*entry
= e
;
14860 return mapped_index_string_hash (entry
->str
);
14863 /* Equality function for a strtab_entry. */
14866 eq_strtab_entry (const void *a
, const void *b
)
14868 const struct strtab_entry
*ea
= a
;
14869 const struct strtab_entry
*eb
= b
;
14870 return !strcmp (ea
->str
, eb
->str
);
14873 /* Create a strtab_entry hash table. */
14876 create_strtab (void)
14878 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
14879 xfree
, xcalloc
, xfree
);
14882 /* Add a string to the constant pool. Return the string's offset in
14886 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
14889 struct strtab_entry entry
;
14890 struct strtab_entry
*result
;
14893 slot
= htab_find_slot (table
, &entry
, INSERT
);
14898 result
= XNEW (struct strtab_entry
);
14899 result
->offset
= obstack_object_size (cpool
);
14901 obstack_grow_str0 (cpool
, str
);
14904 return result
->offset
;
14907 /* An entry in the symbol table. */
14908 struct symtab_index_entry
14910 /* The name of the symbol. */
14912 /* The offset of the name in the constant pool. */
14913 offset_type index_offset
;
14914 /* A sorted vector of the indices of all the CUs that hold an object
14916 VEC (offset_type
) *cu_indices
;
14919 /* The symbol table. This is a power-of-2-sized hash table. */
14920 struct mapped_symtab
14922 offset_type n_elements
;
14924 struct symtab_index_entry
**data
;
14927 /* Hash function for a symtab_index_entry. */
14930 hash_symtab_entry (const void *e
)
14932 const struct symtab_index_entry
*entry
= e
;
14933 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
14934 sizeof (offset_type
) * VEC_length (offset_type
,
14935 entry
->cu_indices
),
14939 /* Equality function for a symtab_index_entry. */
14942 eq_symtab_entry (const void *a
, const void *b
)
14944 const struct symtab_index_entry
*ea
= a
;
14945 const struct symtab_index_entry
*eb
= b
;
14946 int len
= VEC_length (offset_type
, ea
->cu_indices
);
14947 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
14949 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
14950 VEC_address (offset_type
, eb
->cu_indices
),
14951 sizeof (offset_type
) * len
);
14954 /* Destroy a symtab_index_entry. */
14957 delete_symtab_entry (void *p
)
14959 struct symtab_index_entry
*entry
= p
;
14960 VEC_free (offset_type
, entry
->cu_indices
);
14964 /* Create a hash table holding symtab_index_entry objects. */
14967 create_symbol_hash_table (void)
14969 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
14970 delete_symtab_entry
, xcalloc
, xfree
);
14973 /* Create a new mapped symtab object. */
14975 static struct mapped_symtab
*
14976 create_mapped_symtab (void)
14978 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
14979 symtab
->n_elements
= 0;
14980 symtab
->size
= 1024;
14981 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14985 /* Destroy a mapped_symtab. */
14988 cleanup_mapped_symtab (void *p
)
14990 struct mapped_symtab
*symtab
= p
;
14991 /* The contents of the array are freed when the other hash table is
14993 xfree (symtab
->data
);
14997 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15000 static struct symtab_index_entry
**
15001 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15003 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
15005 index
= hash
& (symtab
->size
- 1);
15006 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15010 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15011 return &symtab
->data
[index
];
15012 index
= (index
+ step
) & (symtab
->size
- 1);
15016 /* Expand SYMTAB's hash table. */
15019 hash_expand (struct mapped_symtab
*symtab
)
15021 offset_type old_size
= symtab
->size
;
15023 struct symtab_index_entry
**old_entries
= symtab
->data
;
15026 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15028 for (i
= 0; i
< old_size
; ++i
)
15030 if (old_entries
[i
])
15032 struct symtab_index_entry
**slot
= find_slot (symtab
,
15033 old_entries
[i
]->name
);
15034 *slot
= old_entries
[i
];
15038 xfree (old_entries
);
15041 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15042 is the index of the CU in which the symbol appears. */
15045 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15046 offset_type cu_index
)
15048 struct symtab_index_entry
**slot
;
15050 ++symtab
->n_elements
;
15051 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15052 hash_expand (symtab
);
15054 slot
= find_slot (symtab
, name
);
15057 *slot
= XNEW (struct symtab_index_entry
);
15058 (*slot
)->name
= name
;
15059 (*slot
)->cu_indices
= NULL
;
15061 /* Don't push an index twice. Due to how we add entries we only
15062 have to check the last one. */
15063 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15064 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15065 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15068 /* Add a vector of indices to the constant pool. */
15071 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15072 struct symtab_index_entry
*entry
)
15076 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15079 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15080 offset_type val
= MAYBE_SWAP (len
);
15085 entry
->index_offset
= obstack_object_size (cpool
);
15087 obstack_grow (cpool
, &val
, sizeof (val
));
15089 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15092 val
= MAYBE_SWAP (iter
);
15093 obstack_grow (cpool
, &val
, sizeof (val
));
15098 struct symtab_index_entry
*old_entry
= *slot
;
15099 entry
->index_offset
= old_entry
->index_offset
;
15102 return entry
->index_offset
;
15105 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15106 constant pool entries going into the obstack CPOOL. */
15109 write_hash_table (struct mapped_symtab
*symtab
,
15110 struct obstack
*output
, struct obstack
*cpool
)
15113 htab_t symbol_hash_table
;
15116 symbol_hash_table
= create_symbol_hash_table ();
15117 str_table
= create_strtab ();
15119 /* We add all the index vectors to the constant pool first, to
15120 ensure alignment is ok. */
15121 for (i
= 0; i
< symtab
->size
; ++i
)
15123 if (symtab
->data
[i
])
15124 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15127 /* Now write out the hash table. */
15128 for (i
= 0; i
< symtab
->size
; ++i
)
15130 offset_type str_off
, vec_off
;
15132 if (symtab
->data
[i
])
15134 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15135 vec_off
= symtab
->data
[i
]->index_offset
;
15139 /* While 0 is a valid constant pool index, it is not valid
15140 to have 0 for both offsets. */
15145 str_off
= MAYBE_SWAP (str_off
);
15146 vec_off
= MAYBE_SWAP (vec_off
);
15148 obstack_grow (output
, &str_off
, sizeof (str_off
));
15149 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15152 htab_delete (str_table
);
15153 htab_delete (symbol_hash_table
);
15156 /* Struct to map psymtab to CU index in the index file. */
15157 struct psymtab_cu_index_map
15159 struct partial_symtab
*psymtab
;
15160 unsigned int cu_index
;
15164 hash_psymtab_cu_index (const void *item
)
15166 const struct psymtab_cu_index_map
*map
= item
;
15168 return htab_hash_pointer (map
->psymtab
);
15172 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15174 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15175 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15177 return lhs
->psymtab
== rhs
->psymtab
;
15180 /* Helper struct for building the address table. */
15181 struct addrmap_index_data
15183 struct objfile
*objfile
;
15184 struct obstack
*addr_obstack
;
15185 htab_t cu_index_htab
;
15187 /* Non-zero if the previous_* fields are valid.
15188 We can't write an entry until we see the next entry (since it is only then
15189 that we know the end of the entry). */
15190 int previous_valid
;
15191 /* Index of the CU in the table of all CUs in the index file. */
15192 unsigned int previous_cu_index
;
15193 /* Start address of the CU. */
15194 CORE_ADDR previous_cu_start
;
15197 /* Write an address entry to OBSTACK. */
15200 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15201 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15203 offset_type cu_index_to_write
;
15205 CORE_ADDR baseaddr
;
15207 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15209 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15210 obstack_grow (obstack
, addr
, 8);
15211 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15212 obstack_grow (obstack
, addr
, 8);
15213 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15214 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15217 /* Worker function for traversing an addrmap to build the address table. */
15220 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15222 struct addrmap_index_data
*data
= datap
;
15223 struct partial_symtab
*pst
= obj
;
15224 offset_type cu_index
;
15227 if (data
->previous_valid
)
15228 add_address_entry (data
->objfile
, data
->addr_obstack
,
15229 data
->previous_cu_start
, start_addr
,
15230 data
->previous_cu_index
);
15232 data
->previous_cu_start
= start_addr
;
15235 struct psymtab_cu_index_map find_map
, *map
;
15236 find_map
.psymtab
= pst
;
15237 map
= htab_find (data
->cu_index_htab
, &find_map
);
15238 gdb_assert (map
!= NULL
);
15239 data
->previous_cu_index
= map
->cu_index
;
15240 data
->previous_valid
= 1;
15243 data
->previous_valid
= 0;
15248 /* Write OBJFILE's address map to OBSTACK.
15249 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15250 in the index file. */
15253 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15254 htab_t cu_index_htab
)
15256 struct addrmap_index_data addrmap_index_data
;
15258 /* When writing the address table, we have to cope with the fact that
15259 the addrmap iterator only provides the start of a region; we have to
15260 wait until the next invocation to get the start of the next region. */
15262 addrmap_index_data
.objfile
= objfile
;
15263 addrmap_index_data
.addr_obstack
= obstack
;
15264 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15265 addrmap_index_data
.previous_valid
= 0;
15267 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15268 &addrmap_index_data
);
15270 /* It's highly unlikely the last entry (end address = 0xff...ff)
15271 is valid, but we should still handle it.
15272 The end address is recorded as the start of the next region, but that
15273 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15275 if (addrmap_index_data
.previous_valid
)
15276 add_address_entry (objfile
, obstack
,
15277 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15278 addrmap_index_data
.previous_cu_index
);
15281 /* Add a list of partial symbols to SYMTAB. */
15284 write_psymbols (struct mapped_symtab
*symtab
,
15286 struct partial_symbol
**psymp
,
15288 offset_type cu_index
,
15291 for (; count
-- > 0; ++psymp
)
15293 void **slot
, *lookup
;
15295 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15296 error (_("Ada is not currently supported by the index"));
15298 /* We only want to add a given psymbol once. However, we also
15299 want to account for whether it is global or static. So, we
15300 may add it twice, using slightly different values. */
15303 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15305 lookup
= (void *) val
;
15310 /* Only add a given psymbol once. */
15311 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15315 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15320 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15321 exception if there is an error. */
15324 write_obstack (FILE *file
, struct obstack
*obstack
)
15326 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15328 != obstack_object_size (obstack
))
15329 error (_("couldn't data write to file"));
15332 /* Unlink a file if the argument is not NULL. */
15335 unlink_if_set (void *p
)
15337 char **filename
= p
;
15339 unlink (*filename
);
15342 /* A helper struct used when iterating over debug_types. */
15343 struct signatured_type_index_data
15345 struct objfile
*objfile
;
15346 struct mapped_symtab
*symtab
;
15347 struct obstack
*types_list
;
15352 /* A helper function that writes a single signatured_type to an
15356 write_one_signatured_type (void **slot
, void *d
)
15358 struct signatured_type_index_data
*info
= d
;
15359 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15360 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15361 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15364 write_psymbols (info
->symtab
,
15366 info
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15367 psymtab
->n_global_syms
, info
->cu_index
,
15369 write_psymbols (info
->symtab
,
15371 info
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15372 psymtab
->n_static_syms
, info
->cu_index
,
15375 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15376 obstack_grow (info
->types_list
, val
, 8);
15377 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15378 obstack_grow (info
->types_list
, val
, 8);
15379 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15380 obstack_grow (info
->types_list
, val
, 8);
15387 /* A cleanup function for an htab_t. */
15390 cleanup_htab (void *arg
)
15395 /* Create an index file for OBJFILE in the directory DIR. */
15398 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15400 struct cleanup
*cleanup
;
15401 char *filename
, *cleanup_filename
;
15402 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15403 struct obstack cu_list
, types_cu_list
;
15406 struct mapped_symtab
*symtab
;
15407 offset_type val
, size_of_contents
, total_len
;
15411 htab_t cu_index_htab
;
15412 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
15414 if (!objfile
->psymtabs
)
15416 if (dwarf2_per_objfile
->using_index
)
15417 error (_("Cannot use an index to create the index"));
15419 if (stat (objfile
->name
, &st
) < 0)
15420 perror_with_name (objfile
->name
);
15422 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15423 INDEX_SUFFIX
, (char *) NULL
);
15424 cleanup
= make_cleanup (xfree
, filename
);
15426 out_file
= fopen (filename
, "wb");
15428 error (_("Can't open `%s' for writing"), filename
);
15430 cleanup_filename
= filename
;
15431 make_cleanup (unlink_if_set
, &cleanup_filename
);
15433 symtab
= create_mapped_symtab ();
15434 make_cleanup (cleanup_mapped_symtab
, symtab
);
15436 obstack_init (&addr_obstack
);
15437 make_cleanup_obstack_free (&addr_obstack
);
15439 obstack_init (&cu_list
);
15440 make_cleanup_obstack_free (&cu_list
);
15442 obstack_init (&types_cu_list
);
15443 make_cleanup_obstack_free (&types_cu_list
);
15445 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15446 NULL
, xcalloc
, xfree
);
15447 make_cleanup (cleanup_htab
, psyms_seen
);
15449 /* While we're scanning CU's create a table that maps a psymtab pointer
15450 (which is what addrmap records) to its index (which is what is recorded
15451 in the index file). This will later be needed to write the address
15453 cu_index_htab
= htab_create_alloc (100,
15454 hash_psymtab_cu_index
,
15455 eq_psymtab_cu_index
,
15456 NULL
, xcalloc
, xfree
);
15457 make_cleanup (cleanup_htab
, cu_index_htab
);
15458 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
15459 xmalloc (sizeof (struct psymtab_cu_index_map
)
15460 * dwarf2_per_objfile
->n_comp_units
);
15461 make_cleanup (xfree
, psymtab_cu_index_map
);
15463 /* The CU list is already sorted, so we don't need to do additional
15464 work here. Also, the debug_types entries do not appear in
15465 all_comp_units, but only in their own hash table. */
15466 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15468 struct dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
15469 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15471 struct psymtab_cu_index_map
*map
;
15474 write_psymbols (symtab
,
15476 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15477 psymtab
->n_global_syms
, i
,
15479 write_psymbols (symtab
,
15481 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15482 psymtab
->n_static_syms
, i
,
15485 map
= &psymtab_cu_index_map
[i
];
15486 map
->psymtab
= psymtab
;
15488 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
15489 gdb_assert (slot
!= NULL
);
15490 gdb_assert (*slot
== NULL
);
15493 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15494 obstack_grow (&cu_list
, val
, 8);
15495 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15496 obstack_grow (&cu_list
, val
, 8);
15499 /* Dump the address map. */
15500 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
15502 /* Write out the .debug_type entries, if any. */
15503 if (dwarf2_per_objfile
->signatured_types
)
15505 struct signatured_type_index_data sig_data
;
15507 sig_data
.objfile
= objfile
;
15508 sig_data
.symtab
= symtab
;
15509 sig_data
.types_list
= &types_cu_list
;
15510 sig_data
.psyms_seen
= psyms_seen
;
15511 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15512 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15513 write_one_signatured_type
, &sig_data
);
15516 obstack_init (&constant_pool
);
15517 make_cleanup_obstack_free (&constant_pool
);
15518 obstack_init (&symtab_obstack
);
15519 make_cleanup_obstack_free (&symtab_obstack
);
15520 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15522 obstack_init (&contents
);
15523 make_cleanup_obstack_free (&contents
);
15524 size_of_contents
= 6 * sizeof (offset_type
);
15525 total_len
= size_of_contents
;
15527 /* The version number. */
15528 val
= MAYBE_SWAP (3);
15529 obstack_grow (&contents
, &val
, sizeof (val
));
15531 /* The offset of the CU list from the start of the file. */
15532 val
= MAYBE_SWAP (total_len
);
15533 obstack_grow (&contents
, &val
, sizeof (val
));
15534 total_len
+= obstack_object_size (&cu_list
);
15536 /* The offset of the types CU list from the start of the file. */
15537 val
= MAYBE_SWAP (total_len
);
15538 obstack_grow (&contents
, &val
, sizeof (val
));
15539 total_len
+= obstack_object_size (&types_cu_list
);
15541 /* The offset of the address table from the start of the file. */
15542 val
= MAYBE_SWAP (total_len
);
15543 obstack_grow (&contents
, &val
, sizeof (val
));
15544 total_len
+= obstack_object_size (&addr_obstack
);
15546 /* The offset of the symbol table from the start of the file. */
15547 val
= MAYBE_SWAP (total_len
);
15548 obstack_grow (&contents
, &val
, sizeof (val
));
15549 total_len
+= obstack_object_size (&symtab_obstack
);
15551 /* The offset of the constant pool from the start of the file. */
15552 val
= MAYBE_SWAP (total_len
);
15553 obstack_grow (&contents
, &val
, sizeof (val
));
15554 total_len
+= obstack_object_size (&constant_pool
);
15556 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15558 write_obstack (out_file
, &contents
);
15559 write_obstack (out_file
, &cu_list
);
15560 write_obstack (out_file
, &types_cu_list
);
15561 write_obstack (out_file
, &addr_obstack
);
15562 write_obstack (out_file
, &symtab_obstack
);
15563 write_obstack (out_file
, &constant_pool
);
15567 /* We want to keep the file, so we set cleanup_filename to NULL
15568 here. See unlink_if_set. */
15569 cleanup_filename
= NULL
;
15571 do_cleanups (cleanup
);
15574 /* The mapped index file format is designed to be directly mmap()able
15575 on any architecture. In most cases, a datum is represented using a
15576 little-endian 32-bit integer value, called an offset_type. Big
15577 endian machines must byte-swap the values before using them.
15578 Exceptions to this rule are noted. The data is laid out such that
15579 alignment is always respected.
15581 A mapped index consists of several sections.
15583 1. The file header. This is a sequence of values, of offset_type
15584 unless otherwise noted:
15586 [0] The version number, currently 3. Versions 1 and 2 are
15588 [1] The offset, from the start of the file, of the CU list.
15589 [2] The offset, from the start of the file, of the types CU list.
15590 Note that this section can be empty, in which case this offset will
15591 be equal to the next offset.
15592 [3] The offset, from the start of the file, of the address section.
15593 [4] The offset, from the start of the file, of the symbol table.
15594 [5] The offset, from the start of the file, of the constant pool.
15596 2. The CU list. This is a sequence of pairs of 64-bit
15597 little-endian values, sorted by the CU offset. The first element
15598 in each pair is the offset of a CU in the .debug_info section. The
15599 second element in each pair is the length of that CU. References
15600 to a CU elsewhere in the map are done using a CU index, which is
15601 just the 0-based index into this table. Note that if there are
15602 type CUs, then conceptually CUs and type CUs form a single list for
15603 the purposes of CU indices.
15605 3. The types CU list. This is a sequence of triplets of 64-bit
15606 little-endian values. In a triplet, the first value is the CU
15607 offset, the second value is the type offset in the CU, and the
15608 third value is the type signature. The types CU list is not
15611 4. The address section. The address section consists of a sequence
15612 of address entries. Each address entry has three elements.
15613 [0] The low address. This is a 64-bit little-endian value.
15614 [1] The high address. This is a 64-bit little-endian value.
15615 Like DW_AT_high_pc, the value is one byte beyond the end.
15616 [2] The CU index. This is an offset_type value.
15618 5. The symbol table. This is a hash table. The size of the hash
15619 table is always a power of 2. The initial hash and the step are
15620 currently defined by the `find_slot' function.
15622 Each slot in the hash table consists of a pair of offset_type
15623 values. The first value is the offset of the symbol's name in the
15624 constant pool. The second value is the offset of the CU vector in
15627 If both values are 0, then this slot in the hash table is empty.
15628 This is ok because while 0 is a valid constant pool index, it
15629 cannot be a valid index for both a string and a CU vector.
15631 A string in the constant pool is stored as a \0-terminated string,
15634 A CU vector in the constant pool is a sequence of offset_type
15635 values. The first value is the number of CU indices in the vector.
15636 Each subsequent value is the index of a CU in the CU list. This
15637 element in the hash table is used to indicate which CUs define the
15640 6. The constant pool. This is simply a bunch of bytes. It is
15641 organized so that alignment is correct: CU vectors are stored
15642 first, followed by strings. */
15645 save_gdb_index_command (char *arg
, int from_tty
)
15647 struct objfile
*objfile
;
15650 error (_("usage: save gdb-index DIRECTORY"));
15652 ALL_OBJFILES (objfile
)
15656 /* If the objfile does not correspond to an actual file, skip it. */
15657 if (stat (objfile
->name
, &st
) < 0)
15660 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15661 if (dwarf2_per_objfile
)
15663 volatile struct gdb_exception except
;
15665 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15667 write_psymtabs_to_index (objfile
, arg
);
15669 if (except
.reason
< 0)
15670 exception_fprintf (gdb_stderr
, except
,
15671 _("Error while writing index for `%s': "),
15679 int dwarf2_always_disassemble
;
15682 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15683 struct cmd_list_element
*c
, const char *value
)
15685 fprintf_filtered (file
, _("\
15686 Whether to always disassemble DWARF expressions is %s.\n"),
15690 void _initialize_dwarf2_read (void);
15693 _initialize_dwarf2_read (void)
15695 struct cmd_list_element
*c
;
15697 dwarf2_objfile_data_key
15698 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15700 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15701 Set DWARF 2 specific variables.\n\
15702 Configure DWARF 2 variables such as the cache size"),
15703 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15704 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15706 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15707 Show DWARF 2 specific variables\n\
15708 Show DWARF 2 variables such as the cache size"),
15709 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15710 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15712 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15713 &dwarf2_max_cache_age
, _("\
15714 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15715 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15716 A higher limit means that cached compilation units will be stored\n\
15717 in memory longer, and more total memory will be used. Zero disables\n\
15718 caching, which can slow down startup."),
15720 show_dwarf2_max_cache_age
,
15721 &set_dwarf2_cmdlist
,
15722 &show_dwarf2_cmdlist
);
15724 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15725 &dwarf2_always_disassemble
, _("\
15726 Set whether `info address' always disassembles DWARF expressions."), _("\
15727 Show whether `info address' always disassembles DWARF expressions."), _("\
15728 When enabled, DWARF expressions are always printed in an assembly-like\n\
15729 syntax. When disabled, expressions will be printed in a more\n\
15730 conversational style, when possible."),
15732 show_dwarf2_always_disassemble
,
15733 &set_dwarf2_cmdlist
,
15734 &show_dwarf2_cmdlist
);
15736 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15737 Set debugging of the dwarf2 DIE reader."), _("\
15738 Show debugging of the dwarf2 DIE reader."), _("\
15739 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15740 The value is the maximum depth to print."),
15743 &setdebuglist
, &showdebuglist
);
15745 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15747 Save a .gdb-index file.\n\
15748 Usage: save gdb-index DIRECTORY"),
15750 set_cmd_completer (c
, filename_completer
);