1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
65 #include "gdb/gdb-index.h"
69 #include "gdb_string.h"
70 #include "gdb_assert.h"
71 #include <sys/types.h>
78 #define MAP_FAILED ((void *) -1)
82 typedef struct symbol
*symbolp
;
85 /* When non-zero, print basic high level tracing messages.
86 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
87 static int dwarf2_read_debug
= 0;
89 /* When non-zero, dump DIEs after they are read in. */
90 static int dwarf2_die_debug
= 0;
92 /* When non-zero, cross-check physname against demangler. */
93 static int check_physname
= 0;
95 /* When non-zero, do not reject deprecated .gdb_index sections. */
96 int use_deprecated_index_sections
= 0;
100 /* When set, the file that we're processing is known to have debugging
101 info for C++ namespaces. GCC 3.3.x did not produce this information,
102 but later versions do. */
104 static int processing_has_namespace_info
;
106 static const struct objfile_data
*dwarf2_objfile_data_key
;
108 struct dwarf2_section_info
113 /* Not NULL if the section was actually mmapped. */
115 /* Page aligned size of mmapped area. */
116 bfd_size_type map_len
;
117 /* True if we have tried to read this section. */
121 typedef struct dwarf2_section_info dwarf2_section_info_def
;
122 DEF_VEC_O (dwarf2_section_info_def
);
124 /* All offsets in the index are of this type. It must be
125 architecture-independent. */
126 typedef uint32_t offset_type
;
128 DEF_VEC_I (offset_type
);
130 /* Ensure only legit values are used. */
131 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
133 gdb_assert ((unsigned int) (value) <= 1); \
134 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
137 /* Ensure only legit values are used. */
138 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
140 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
141 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
142 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
145 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
146 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
148 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
149 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
152 /* A description of the mapped index. The file format is described in
153 a comment by the code that writes the index. */
156 /* Index data format version. */
159 /* The total length of the buffer. */
162 /* A pointer to the address table data. */
163 const gdb_byte
*address_table
;
165 /* Size of the address table data in bytes. */
166 offset_type address_table_size
;
168 /* The symbol table, implemented as a hash table. */
169 const offset_type
*symbol_table
;
171 /* Size in slots, each slot is 2 offset_types. */
172 offset_type symbol_table_slots
;
174 /* A pointer to the constant pool. */
175 const char *constant_pool
;
178 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
179 DEF_VEC_P (dwarf2_per_cu_ptr
);
181 /* Collection of data recorded per objfile.
182 This hangs off of dwarf2_objfile_data_key. */
184 struct dwarf2_per_objfile
186 struct dwarf2_section_info info
;
187 struct dwarf2_section_info abbrev
;
188 struct dwarf2_section_info line
;
189 struct dwarf2_section_info loc
;
190 struct dwarf2_section_info macinfo
;
191 struct dwarf2_section_info macro
;
192 struct dwarf2_section_info str
;
193 struct dwarf2_section_info ranges
;
194 struct dwarf2_section_info addr
;
195 struct dwarf2_section_info frame
;
196 struct dwarf2_section_info eh_frame
;
197 struct dwarf2_section_info gdb_index
;
199 VEC (dwarf2_section_info_def
) *types
;
202 struct objfile
*objfile
;
204 /* Table of all the compilation units. This is used to locate
205 the target compilation unit of a particular reference. */
206 struct dwarf2_per_cu_data
**all_comp_units
;
208 /* The number of compilation units in ALL_COMP_UNITS. */
211 /* The number of .debug_types-related CUs. */
214 /* The .debug_types-related CUs (TUs). */
215 struct signatured_type
**all_type_units
;
217 /* The number of entries in all_type_unit_groups. */
218 int n_type_unit_groups
;
220 /* Table of type unit groups.
221 This exists to make it easy to iterate over all CUs and TU groups. */
222 struct type_unit_group
**all_type_unit_groups
;
224 /* Table of struct type_unit_group objects.
225 The hash key is the DW_AT_stmt_list value. */
226 htab_t type_unit_groups
;
228 /* A table mapping .debug_types signatures to its signatured_type entry.
229 This is NULL if the .debug_types section hasn't been read in yet. */
230 htab_t signatured_types
;
232 /* Type unit statistics, to see how well the scaling improvements
236 int nr_uniq_abbrev_tables
;
238 int nr_symtab_sharers
;
239 int nr_stmt_less_type_units
;
242 /* A chain of compilation units that are currently read in, so that
243 they can be freed later. */
244 struct dwarf2_per_cu_data
*read_in_chain
;
246 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
247 This is NULL if the table hasn't been allocated yet. */
250 /* A flag indicating wether this objfile has a section loaded at a
252 int has_section_at_zero
;
254 /* True if we are using the mapped index,
255 or we are faking it for OBJF_READNOW's sake. */
256 unsigned char using_index
;
258 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
259 struct mapped_index
*index_table
;
261 /* When using index_table, this keeps track of all quick_file_names entries.
262 TUs can share line table entries with CUs or other TUs, and there can be
263 a lot more TUs than unique line tables, so we maintain a separate table
264 of all line table entries to support the sharing. */
265 htab_t quick_file_names_table
;
267 /* Set during partial symbol reading, to prevent queueing of full
269 int reading_partial_symbols
;
271 /* Table mapping type DIEs to their struct type *.
272 This is NULL if not allocated yet.
273 The mapping is done via (CU/TU signature + DIE offset) -> type. */
274 htab_t die_type_hash
;
276 /* The CUs we recently read. */
277 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
280 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
282 /* Default names of the debugging sections. */
284 /* Note that if the debugging section has been compressed, it might
285 have a name like .zdebug_info. */
287 static const struct dwarf2_debug_sections dwarf2_elf_names
=
289 { ".debug_info", ".zdebug_info" },
290 { ".debug_abbrev", ".zdebug_abbrev" },
291 { ".debug_line", ".zdebug_line" },
292 { ".debug_loc", ".zdebug_loc" },
293 { ".debug_macinfo", ".zdebug_macinfo" },
294 { ".debug_macro", ".zdebug_macro" },
295 { ".debug_str", ".zdebug_str" },
296 { ".debug_ranges", ".zdebug_ranges" },
297 { ".debug_types", ".zdebug_types" },
298 { ".debug_addr", ".zdebug_addr" },
299 { ".debug_frame", ".zdebug_frame" },
300 { ".eh_frame", NULL
},
301 { ".gdb_index", ".zgdb_index" },
305 /* List of DWO sections. */
307 static const struct dwo_section_names
309 struct dwarf2_section_names abbrev_dwo
;
310 struct dwarf2_section_names info_dwo
;
311 struct dwarf2_section_names line_dwo
;
312 struct dwarf2_section_names loc_dwo
;
313 struct dwarf2_section_names macinfo_dwo
;
314 struct dwarf2_section_names macro_dwo
;
315 struct dwarf2_section_names str_dwo
;
316 struct dwarf2_section_names str_offsets_dwo
;
317 struct dwarf2_section_names types_dwo
;
321 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
322 { ".debug_info.dwo", ".zdebug_info.dwo" },
323 { ".debug_line.dwo", ".zdebug_line.dwo" },
324 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
325 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
326 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
327 { ".debug_str.dwo", ".zdebug_str.dwo" },
328 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
329 { ".debug_types.dwo", ".zdebug_types.dwo" },
332 /* local data types */
334 /* The data in a compilation unit header, after target2host
335 translation, looks like this. */
336 struct comp_unit_head
340 unsigned char addr_size
;
341 unsigned char signed_addr_p
;
342 sect_offset abbrev_offset
;
344 /* Size of file offsets; either 4 or 8. */
345 unsigned int offset_size
;
347 /* Size of the length field; either 4 or 12. */
348 unsigned int initial_length_size
;
350 /* Offset to the first byte of this compilation unit header in the
351 .debug_info section, for resolving relative reference dies. */
354 /* Offset to first die in this cu from the start of the cu.
355 This will be the first byte following the compilation unit header. */
356 cu_offset first_die_offset
;
359 /* Type used for delaying computation of method physnames.
360 See comments for compute_delayed_physnames. */
361 struct delayed_method_info
363 /* The type to which the method is attached, i.e., its parent class. */
366 /* The index of the method in the type's function fieldlists. */
369 /* The index of the method in the fieldlist. */
372 /* The name of the DIE. */
375 /* The DIE associated with this method. */
376 struct die_info
*die
;
379 typedef struct delayed_method_info delayed_method_info
;
380 DEF_VEC_O (delayed_method_info
);
382 /* Internal state when decoding a particular compilation unit. */
385 /* The objfile containing this compilation unit. */
386 struct objfile
*objfile
;
388 /* The header of the compilation unit. */
389 struct comp_unit_head header
;
391 /* Base address of this compilation unit. */
392 CORE_ADDR base_address
;
394 /* Non-zero if base_address has been set. */
397 /* The language we are debugging. */
398 enum language language
;
399 const struct language_defn
*language_defn
;
401 const char *producer
;
403 /* The generic symbol table building routines have separate lists for
404 file scope symbols and all all other scopes (local scopes). So
405 we need to select the right one to pass to add_symbol_to_list().
406 We do it by keeping a pointer to the correct list in list_in_scope.
408 FIXME: The original dwarf code just treated the file scope as the
409 first local scope, and all other local scopes as nested local
410 scopes, and worked fine. Check to see if we really need to
411 distinguish these in buildsym.c. */
412 struct pending
**list_in_scope
;
414 /* The abbrev table for this CU.
415 Normally this points to the abbrev table in the objfile.
416 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
417 struct abbrev_table
*abbrev_table
;
419 /* Hash table holding all the loaded partial DIEs
420 with partial_die->offset.SECT_OFF as hash. */
423 /* Storage for things with the same lifetime as this read-in compilation
424 unit, including partial DIEs. */
425 struct obstack comp_unit_obstack
;
427 /* When multiple dwarf2_cu structures are living in memory, this field
428 chains them all together, so that they can be released efficiently.
429 We will probably also want a generation counter so that most-recently-used
430 compilation units are cached... */
431 struct dwarf2_per_cu_data
*read_in_chain
;
433 /* Backchain to our per_cu entry if the tree has been built. */
434 struct dwarf2_per_cu_data
*per_cu
;
436 /* How many compilation units ago was this CU last referenced? */
439 /* A hash table of DIE cu_offset for following references with
440 die_info->offset.sect_off as hash. */
443 /* Full DIEs if read in. */
444 struct die_info
*dies
;
446 /* A set of pointers to dwarf2_per_cu_data objects for compilation
447 units referenced by this one. Only set during full symbol processing;
448 partial symbol tables do not have dependencies. */
451 /* Header data from the line table, during full symbol processing. */
452 struct line_header
*line_header
;
454 /* A list of methods which need to have physnames computed
455 after all type information has been read. */
456 VEC (delayed_method_info
) *method_list
;
458 /* To be copied to symtab->call_site_htab. */
459 htab_t call_site_htab
;
461 /* Non-NULL if this CU came from a DWO file.
462 There is an invariant here that is important to remember:
463 Except for attributes copied from the top level DIE in the "main"
464 (or "stub") file in preparation for reading the DWO file
465 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
466 Either there isn't a DWO file (in which case this is NULL and the point
467 is moot), or there is and either we're not going to read it (in which
468 case this is NULL) or there is and we are reading it (in which case this
470 struct dwo_unit
*dwo_unit
;
472 /* The DW_AT_addr_base attribute if present, zero otherwise
473 (zero is a valid value though).
474 Note this value comes from the stub CU/TU's DIE. */
477 /* The DW_AT_ranges_base attribute if present, zero otherwise
478 (zero is a valid value though).
479 Note this value comes from the stub CU/TU's DIE.
480 Also note that the value is zero in the non-DWO case so this value can
481 be used without needing to know whether DWO files are in use or not. */
482 ULONGEST ranges_base
;
484 /* Mark used when releasing cached dies. */
485 unsigned int mark
: 1;
487 /* This CU references .debug_loc. See the symtab->locations_valid field.
488 This test is imperfect as there may exist optimized debug code not using
489 any location list and still facing inlining issues if handled as
490 unoptimized code. For a future better test see GCC PR other/32998. */
491 unsigned int has_loclist
: 1;
493 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
494 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
495 are valid. This information is cached because profiling CU expansion
496 showed excessive time spent in producer_is_gxx_lt_4_6. */
497 unsigned int checked_producer
: 1;
498 unsigned int producer_is_gxx_lt_4_6
: 1;
499 unsigned int producer_is_icc
: 1;
502 /* Persistent data held for a compilation unit, even when not
503 processing it. We put a pointer to this structure in the
504 read_symtab_private field of the psymtab. */
506 struct dwarf2_per_cu_data
508 /* The start offset and length of this compilation unit. 2**29-1
509 bytes should suffice to store the length of any compilation unit
510 - if it doesn't, GDB will fall over anyway.
511 NOTE: Unlike comp_unit_head.length, this length includes
513 If the DIE refers to a DWO file, this is always of the original die,
516 unsigned int length
: 29;
518 /* Flag indicating this compilation unit will be read in before
519 any of the current compilation units are processed. */
520 unsigned int queued
: 1;
522 /* This flag will be set when reading partial DIEs if we need to load
523 absolutely all DIEs for this compilation unit, instead of just the ones
524 we think are interesting. It gets set if we look for a DIE in the
525 hash table and don't find it. */
526 unsigned int load_all_dies
: 1;
528 /* Non-zero if this CU is from .debug_types. */
529 unsigned int is_debug_types
: 1;
531 /* The section this CU/TU lives in.
532 If the DIE refers to a DWO file, this is always the original die,
534 struct dwarf2_section_info
*info_or_types_section
;
536 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
537 of the CU cache it gets reset to NULL again. */
538 struct dwarf2_cu
*cu
;
540 /* The corresponding objfile.
541 Normally we can get the objfile from dwarf2_per_objfile.
542 However we can enter this file with just a "per_cu" handle. */
543 struct objfile
*objfile
;
545 /* When using partial symbol tables, the 'psymtab' field is active.
546 Otherwise the 'quick' field is active. */
549 /* The partial symbol table associated with this compilation unit,
550 or NULL for unread partial units. */
551 struct partial_symtab
*psymtab
;
553 /* Data needed by the "quick" functions. */
554 struct dwarf2_per_cu_quick_data
*quick
;
559 /* The CUs we import using DW_TAG_imported_unit. This is filled in
560 while reading psymtabs, used to compute the psymtab dependencies,
561 and then cleared. Then it is filled in again while reading full
562 symbols, and only deleted when the objfile is destroyed. */
563 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
565 /* Type units are grouped by their DW_AT_stmt_list entry so that they
566 can share them. If this is a TU, this points to the containing
568 struct type_unit_group
*type_unit_group
;
572 /* Entry in the signatured_types hash table. */
574 struct signatured_type
576 /* The "per_cu" object of this type.
577 N.B.: This is the first member so that it's easy to convert pointers
579 struct dwarf2_per_cu_data per_cu
;
581 /* The type's signature. */
584 /* Offset in the TU of the type's DIE, as read from the TU header.
585 If the definition lives in a DWO file, this value is unusable. */
586 cu_offset type_offset_in_tu
;
588 /* Offset in the section of the type's DIE.
589 If the definition lives in a DWO file, this is the offset in the
590 .debug_types.dwo section.
591 The value is zero until the actual value is known.
592 Zero is otherwise not a valid section offset. */
593 sect_offset type_offset_in_section
;
596 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
597 an object of this type. */
599 struct type_unit_group
601 /* dwarf2read.c's main "handle" on the symtab.
602 To simplify things we create an artificial CU that "includes" all the
603 type units using this stmt_list so that the rest of the code still has
604 a "per_cu" handle on the symtab.
605 This PER_CU is recognized by having no section. */
606 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
607 struct dwarf2_per_cu_data
*per_cu
;
609 /* The TUs that share this DW_AT_stmt_list entry.
610 This is added to while parsing type units to build partial symtabs,
611 and is deleted afterwards and not used again. */
612 VEC (dwarf2_per_cu_ptr
) *tus
;
614 /* The primary symtab.
615 Type units don't have DW_AT_name so we create an essentially
616 anonymous symtab as the primary symtab. */
617 struct symtab
*primary_symtab
;
619 /* Offset in .debug_line. This is the hash key. */
620 sect_offset line_offset
;
622 /* The number of symtabs from the line header.
623 The value here must match line_header.num_file_names. */
624 unsigned int num_symtabs
;
626 /* The symbol tables for this TU (obtained from the files listed in
628 WARNING: The order of entries here must match the order of entries
629 in the line header. After the first TU using this type_unit_group, the
630 line header for the subsequent TUs is recreated from this. This is done
631 because we need to use the same symtabs for each TU using the same
632 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
633 there's no guarantee the line header doesn't have duplicate entries. */
634 struct symtab
**symtabs
;
637 /* These sections are what may appear in a "dwo" file. */
641 struct dwarf2_section_info abbrev
;
642 struct dwarf2_section_info info
;
643 struct dwarf2_section_info line
;
644 struct dwarf2_section_info loc
;
645 struct dwarf2_section_info macinfo
;
646 struct dwarf2_section_info macro
;
647 struct dwarf2_section_info str
;
648 struct dwarf2_section_info str_offsets
;
649 VEC (dwarf2_section_info_def
) *types
;
652 /* Common bits of DWO CUs/TUs. */
656 /* Backlink to the containing struct dwo_file. */
657 struct dwo_file
*dwo_file
;
659 /* The "id" that distinguishes this CU/TU.
660 .debug_info calls this "dwo_id", .debug_types calls this "signature".
661 Since signatures came first, we stick with it for consistency. */
664 /* The section this CU/TU lives in, in the DWO file. */
665 struct dwarf2_section_info
*info_or_types_section
;
667 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
671 /* For types, offset in the type's DIE of the type defined by this TU. */
672 cu_offset type_offset_in_tu
;
675 /* Data for one DWO file. */
679 /* The DW_AT_GNU_dwo_name attribute.
680 We don't manage space for this, it's an attribute. */
681 const char *dwo_name
;
683 /* The bfd, when the file is open. Otherwise this is NULL. */
686 /* Section info for this file. */
687 struct dwo_sections sections
;
689 /* Table of CUs in the file.
690 Each element is a struct dwo_unit. */
693 /* Table of TUs in the file.
694 Each element is a struct dwo_unit. */
698 /* Struct used to pass misc. parameters to read_die_and_children, et
699 al. which are used for both .debug_info and .debug_types dies.
700 All parameters here are unchanging for the life of the call. This
701 struct exists to abstract away the constant parameters of die reading. */
703 struct die_reader_specs
705 /* die_section->asection->owner. */
708 /* The CU of the DIE we are parsing. */
709 struct dwarf2_cu
*cu
;
711 /* Non-NULL if reading a DWO file. */
712 struct dwo_file
*dwo_file
;
714 /* The section the die comes from.
715 This is either .debug_info or .debug_types, or the .dwo variants. */
716 struct dwarf2_section_info
*die_section
;
718 /* die_section->buffer. */
721 /* The end of the buffer. */
722 const gdb_byte
*buffer_end
;
725 /* Type of function passed to init_cutu_and_read_dies, et.al. */
726 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
728 struct die_info
*comp_unit_die
,
732 /* The line number information for a compilation unit (found in the
733 .debug_line section) begins with a "statement program header",
734 which contains the following information. */
737 unsigned int total_length
;
738 unsigned short version
;
739 unsigned int header_length
;
740 unsigned char minimum_instruction_length
;
741 unsigned char maximum_ops_per_instruction
;
742 unsigned char default_is_stmt
;
744 unsigned char line_range
;
745 unsigned char opcode_base
;
747 /* standard_opcode_lengths[i] is the number of operands for the
748 standard opcode whose value is i. This means that
749 standard_opcode_lengths[0] is unused, and the last meaningful
750 element is standard_opcode_lengths[opcode_base - 1]. */
751 unsigned char *standard_opcode_lengths
;
753 /* The include_directories table. NOTE! These strings are not
754 allocated with xmalloc; instead, they are pointers into
755 debug_line_buffer. If you try to free them, `free' will get
757 unsigned int num_include_dirs
, include_dirs_size
;
760 /* The file_names table. NOTE! These strings are not allocated
761 with xmalloc; instead, they are pointers into debug_line_buffer.
762 Don't try to free them directly. */
763 unsigned int num_file_names
, file_names_size
;
767 unsigned int dir_index
;
768 unsigned int mod_time
;
770 int included_p
; /* Non-zero if referenced by the Line Number Program. */
771 struct symtab
*symtab
; /* The associated symbol table, if any. */
774 /* The start and end of the statement program following this
775 header. These point into dwarf2_per_objfile->line_buffer. */
776 gdb_byte
*statement_program_start
, *statement_program_end
;
779 /* When we construct a partial symbol table entry we only
780 need this much information. */
781 struct partial_die_info
783 /* Offset of this DIE. */
786 /* DWARF-2 tag for this DIE. */
787 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
789 /* Assorted flags describing the data found in this DIE. */
790 unsigned int has_children
: 1;
791 unsigned int is_external
: 1;
792 unsigned int is_declaration
: 1;
793 unsigned int has_type
: 1;
794 unsigned int has_specification
: 1;
795 unsigned int has_pc_info
: 1;
796 unsigned int may_be_inlined
: 1;
798 /* Flag set if the SCOPE field of this structure has been
800 unsigned int scope_set
: 1;
802 /* Flag set if the DIE has a byte_size attribute. */
803 unsigned int has_byte_size
: 1;
805 /* Flag set if any of the DIE's children are template arguments. */
806 unsigned int has_template_arguments
: 1;
808 /* Flag set if fixup_partial_die has been called on this die. */
809 unsigned int fixup_called
: 1;
811 /* The name of this DIE. Normally the value of DW_AT_name, but
812 sometimes a default name for unnamed DIEs. */
815 /* The linkage name, if present. */
816 const char *linkage_name
;
818 /* The scope to prepend to our children. This is generally
819 allocated on the comp_unit_obstack, so will disappear
820 when this compilation unit leaves the cache. */
823 /* Some data associated with the partial DIE. The tag determines
824 which field is live. */
827 /* The location description associated with this DIE, if any. */
828 struct dwarf_block
*locdesc
;
829 /* The offset of an import, for DW_TAG_imported_unit. */
833 /* If HAS_PC_INFO, the PC range associated with this DIE. */
837 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
838 DW_AT_sibling, if any. */
839 /* NOTE: This member isn't strictly necessary, read_partial_die could
840 return DW_AT_sibling values to its caller load_partial_dies. */
843 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
844 DW_AT_specification (or DW_AT_abstract_origin or
846 sect_offset spec_offset
;
848 /* Pointers to this DIE's parent, first child, and next sibling,
850 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
853 /* This data structure holds the information of an abbrev. */
856 unsigned int number
; /* number identifying abbrev */
857 enum dwarf_tag tag
; /* dwarf tag */
858 unsigned short has_children
; /* boolean */
859 unsigned short num_attrs
; /* number of attributes */
860 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
861 struct abbrev_info
*next
; /* next in chain */
866 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
867 ENUM_BITFIELD(dwarf_form
) form
: 16;
870 /* Size of abbrev_table.abbrev_hash_table. */
871 #define ABBREV_HASH_SIZE 121
873 /* Top level data structure to contain an abbreviation table. */
877 /* Where the abbrev table came from.
878 This is used as a sanity check when the table is used. */
881 /* Storage for the abbrev table. */
882 struct obstack abbrev_obstack
;
884 /* Hash table of abbrevs.
885 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
886 It could be statically allocated, but the previous code didn't so we
888 struct abbrev_info
**abbrevs
;
891 /* Attributes have a name and a value. */
894 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
895 ENUM_BITFIELD(dwarf_form
) form
: 15;
897 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
898 field should be in u.str (existing only for DW_STRING) but it is kept
899 here for better struct attribute alignment. */
900 unsigned int string_is_canonical
: 1;
905 struct dwarf_block
*blk
;
909 struct signatured_type
*signatured_type
;
914 /* This data structure holds a complete die structure. */
917 /* DWARF-2 tag for this DIE. */
918 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
920 /* Number of attributes */
921 unsigned char num_attrs
;
923 /* True if we're presently building the full type name for the
924 type derived from this DIE. */
925 unsigned char building_fullname
: 1;
930 /* Offset in .debug_info or .debug_types section. */
933 /* The dies in a compilation unit form an n-ary tree. PARENT
934 points to this die's parent; CHILD points to the first child of
935 this node; and all the children of a given node are chained
936 together via their SIBLING fields. */
937 struct die_info
*child
; /* Its first child, if any. */
938 struct die_info
*sibling
; /* Its next sibling, if any. */
939 struct die_info
*parent
; /* Its parent, if any. */
941 /* An array of attributes, with NUM_ATTRS elements. There may be
942 zero, but it's not common and zero-sized arrays are not
943 sufficiently portable C. */
944 struct attribute attrs
[1];
947 /* Get at parts of an attribute structure. */
949 #define DW_STRING(attr) ((attr)->u.str)
950 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
951 #define DW_UNSND(attr) ((attr)->u.unsnd)
952 #define DW_BLOCK(attr) ((attr)->u.blk)
953 #define DW_SND(attr) ((attr)->u.snd)
954 #define DW_ADDR(attr) ((attr)->u.addr)
955 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
957 /* Blocks are a bunch of untyped bytes. */
962 /* Valid only if SIZE is not zero. */
966 #ifndef ATTR_ALLOC_CHUNK
967 #define ATTR_ALLOC_CHUNK 4
970 /* Allocate fields for structs, unions and enums in this size. */
971 #ifndef DW_FIELD_ALLOC_CHUNK
972 #define DW_FIELD_ALLOC_CHUNK 4
975 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
976 but this would require a corresponding change in unpack_field_as_long
978 static int bits_per_byte
= 8;
980 /* The routines that read and process dies for a C struct or C++ class
981 pass lists of data member fields and lists of member function fields
982 in an instance of a field_info structure, as defined below. */
985 /* List of data member and baseclasses fields. */
988 struct nextfield
*next
;
993 *fields
, *baseclasses
;
995 /* Number of fields (including baseclasses). */
998 /* Number of baseclasses. */
1001 /* Set if the accesibility of one of the fields is not public. */
1002 int non_public_fields
;
1004 /* Member function fields array, entries are allocated in the order they
1005 are encountered in the object file. */
1008 struct nextfnfield
*next
;
1009 struct fn_field fnfield
;
1013 /* Member function fieldlist array, contains name of possibly overloaded
1014 member function, number of overloaded member functions and a pointer
1015 to the head of the member function field chain. */
1020 struct nextfnfield
*head
;
1024 /* Number of entries in the fnfieldlists array. */
1027 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1028 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1029 struct typedef_field_list
1031 struct typedef_field field
;
1032 struct typedef_field_list
*next
;
1034 *typedef_field_list
;
1035 unsigned typedef_field_list_count
;
1038 /* One item on the queue of compilation units to read in full symbols
1040 struct dwarf2_queue_item
1042 struct dwarf2_per_cu_data
*per_cu
;
1043 enum language pretend_language
;
1044 struct dwarf2_queue_item
*next
;
1047 /* The current queue. */
1048 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1050 /* Loaded secondary compilation units are kept in memory until they
1051 have not been referenced for the processing of this many
1052 compilation units. Set this to zero to disable caching. Cache
1053 sizes of up to at least twenty will improve startup time for
1054 typical inter-CU-reference binaries, at an obvious memory cost. */
1055 static int dwarf2_max_cache_age
= 5;
1057 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1058 struct cmd_list_element
*c
, const char *value
)
1060 fprintf_filtered (file
, _("The upper bound on the age of cached "
1061 "dwarf2 compilation units is %s.\n"),
1066 /* Various complaints about symbol reading that don't abort the process. */
1069 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1071 complaint (&symfile_complaints
,
1072 _("statement list doesn't fit in .debug_line section"));
1076 dwarf2_debug_line_missing_file_complaint (void)
1078 complaint (&symfile_complaints
,
1079 _(".debug_line section has line data without a file"));
1083 dwarf2_debug_line_missing_end_sequence_complaint (void)
1085 complaint (&symfile_complaints
,
1086 _(".debug_line section has line "
1087 "program sequence without an end"));
1091 dwarf2_complex_location_expr_complaint (void)
1093 complaint (&symfile_complaints
, _("location expression too complex"));
1097 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1100 complaint (&symfile_complaints
,
1101 _("const value length mismatch for '%s', got %d, expected %d"),
1106 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1108 complaint (&symfile_complaints
,
1109 _("debug info runs off end of %s section"
1111 section
->asection
->name
,
1112 bfd_get_filename (section
->asection
->owner
));
1116 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1118 complaint (&symfile_complaints
,
1119 _("macro debug info contains a "
1120 "malformed macro definition:\n`%s'"),
1125 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1127 complaint (&symfile_complaints
,
1128 _("invalid attribute class or form for '%s' in '%s'"),
1132 /* local function prototypes */
1134 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1136 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1139 static void dwarf2_find_base_address (struct die_info
*die
,
1140 struct dwarf2_cu
*cu
);
1142 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1144 static void scan_partial_symbols (struct partial_die_info
*,
1145 CORE_ADDR
*, CORE_ADDR
*,
1146 int, struct dwarf2_cu
*);
1148 static void add_partial_symbol (struct partial_die_info
*,
1149 struct dwarf2_cu
*);
1151 static void add_partial_namespace (struct partial_die_info
*pdi
,
1152 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1153 int need_pc
, struct dwarf2_cu
*cu
);
1155 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1156 CORE_ADDR
*highpc
, int need_pc
,
1157 struct dwarf2_cu
*cu
);
1159 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1160 struct dwarf2_cu
*cu
);
1162 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1163 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1164 int need_pc
, struct dwarf2_cu
*cu
);
1166 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1168 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1170 static struct abbrev_info
*abbrev_table_lookup_abbrev
1171 (const struct abbrev_table
*, unsigned int);
1173 static struct abbrev_table
*abbrev_table_read_table
1174 (struct dwarf2_section_info
*, sect_offset
);
1176 static void abbrev_table_free (struct abbrev_table
*);
1178 static void abbrev_table_free_cleanup (void *);
1180 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1181 struct dwarf2_section_info
*);
1183 static void dwarf2_free_abbrev_table (void *);
1185 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1187 static struct partial_die_info
*load_partial_dies
1188 (const struct die_reader_specs
*, gdb_byte
*, int);
1190 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1191 struct partial_die_info
*,
1192 struct abbrev_info
*,
1196 static struct partial_die_info
*find_partial_die (sect_offset
,
1197 struct dwarf2_cu
*);
1199 static void fixup_partial_die (struct partial_die_info
*,
1200 struct dwarf2_cu
*);
1202 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1203 struct attribute
*, struct attr_abbrev
*,
1206 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1208 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1210 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1212 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1214 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1216 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1219 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1221 static LONGEST read_checked_initial_length_and_offset
1222 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1223 unsigned int *, unsigned int *);
1225 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1228 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1230 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1233 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1235 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1237 static char *read_indirect_string (bfd
*, gdb_byte
*,
1238 const struct comp_unit_head
*,
1241 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1243 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1245 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1248 static char *read_str_index (const struct die_reader_specs
*reader
,
1249 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1251 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1253 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1254 struct dwarf2_cu
*);
1256 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1259 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1260 struct dwarf2_cu
*cu
);
1262 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1264 static struct die_info
*die_specification (struct die_info
*die
,
1265 struct dwarf2_cu
**);
1267 static void free_line_header (struct line_header
*lh
);
1269 static void add_file_name (struct line_header
*, char *, unsigned int,
1270 unsigned int, unsigned int);
1272 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1273 struct dwarf2_cu
*cu
);
1275 static void dwarf_decode_lines (struct line_header
*, const char *,
1276 struct dwarf2_cu
*, struct partial_symtab
*,
1279 static void dwarf2_start_subfile (char *, const char *, const char *);
1281 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1282 char *, char *, CORE_ADDR
);
1284 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1285 struct dwarf2_cu
*);
1287 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1288 struct dwarf2_cu
*, struct symbol
*);
1290 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1291 struct dwarf2_cu
*);
1293 static void dwarf2_const_value_attr (struct attribute
*attr
,
1296 struct obstack
*obstack
,
1297 struct dwarf2_cu
*cu
, LONGEST
*value
,
1299 struct dwarf2_locexpr_baton
**baton
);
1301 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1303 static int need_gnat_info (struct dwarf2_cu
*);
1305 static struct type
*die_descriptive_type (struct die_info
*,
1306 struct dwarf2_cu
*);
1308 static void set_descriptive_type (struct type
*, struct die_info
*,
1309 struct dwarf2_cu
*);
1311 static struct type
*die_containing_type (struct die_info
*,
1312 struct dwarf2_cu
*);
1314 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1315 struct dwarf2_cu
*);
1317 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1319 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1321 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1323 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1324 const char *suffix
, int physname
,
1325 struct dwarf2_cu
*cu
);
1327 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1329 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1331 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1333 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1335 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1337 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1338 struct dwarf2_cu
*, struct partial_symtab
*);
1340 static int dwarf2_get_pc_bounds (struct die_info
*,
1341 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1342 struct partial_symtab
*);
1344 static void get_scope_pc_bounds (struct die_info
*,
1345 CORE_ADDR
*, CORE_ADDR
*,
1346 struct dwarf2_cu
*);
1348 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1349 CORE_ADDR
, struct dwarf2_cu
*);
1351 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1352 struct dwarf2_cu
*);
1354 static void dwarf2_attach_fields_to_type (struct field_info
*,
1355 struct type
*, struct dwarf2_cu
*);
1357 static void dwarf2_add_member_fn (struct field_info
*,
1358 struct die_info
*, struct type
*,
1359 struct dwarf2_cu
*);
1361 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1363 struct dwarf2_cu
*);
1365 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1367 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1369 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1371 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1373 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1375 static struct type
*read_module_type (struct die_info
*die
,
1376 struct dwarf2_cu
*cu
);
1378 static const char *namespace_name (struct die_info
*die
,
1379 int *is_anonymous
, struct dwarf2_cu
*);
1381 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1383 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1385 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1386 struct dwarf2_cu
*);
1388 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1390 gdb_byte
**new_info_ptr
,
1391 struct die_info
*parent
);
1393 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1395 gdb_byte
**new_info_ptr
,
1396 struct die_info
*parent
);
1398 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1399 struct die_info
**, gdb_byte
*, int *, int);
1401 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1402 struct die_info
**, gdb_byte
*, int *);
1404 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1406 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1409 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1411 static const char *dwarf2_full_name (char *name
,
1412 struct die_info
*die
,
1413 struct dwarf2_cu
*cu
);
1415 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1416 struct dwarf2_cu
**);
1418 static const char *dwarf_tag_name (unsigned int);
1420 static const char *dwarf_attr_name (unsigned int);
1422 static const char *dwarf_form_name (unsigned int);
1424 static char *dwarf_bool_name (unsigned int);
1426 static const char *dwarf_type_encoding_name (unsigned int);
1428 static struct die_info
*sibling_die (struct die_info
*);
1430 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1432 static void dump_die_for_error (struct die_info
*);
1434 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1437 /*static*/ void dump_die (struct die_info
*, int max_level
);
1439 static void store_in_ref_table (struct die_info
*,
1440 struct dwarf2_cu
*);
1442 static int is_ref_attr (struct attribute
*);
1444 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1446 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1448 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1450 struct dwarf2_cu
**);
1452 static struct die_info
*follow_die_ref (struct die_info
*,
1454 struct dwarf2_cu
**);
1456 static struct die_info
*follow_die_sig (struct die_info
*,
1458 struct dwarf2_cu
**);
1460 static struct signatured_type
*lookup_signatured_type_at_offset
1461 (struct objfile
*objfile
,
1462 struct dwarf2_section_info
*section
, sect_offset offset
);
1464 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1466 static void read_signatured_type (struct signatured_type
*);
1468 static struct type_unit_group
*get_type_unit_group
1469 (struct dwarf2_per_cu_data
*, struct attribute
*);
1471 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1473 /* memory allocation interface */
1475 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1477 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1479 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1482 static int attr_form_is_block (struct attribute
*);
1484 static int attr_form_is_section_offset (struct attribute
*);
1486 static int attr_form_is_constant (struct attribute
*);
1488 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1489 struct dwarf2_loclist_baton
*baton
,
1490 struct attribute
*attr
);
1492 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1494 struct dwarf2_cu
*cu
);
1496 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1498 struct abbrev_info
*abbrev
);
1500 static void free_stack_comp_unit (void *);
1502 static hashval_t
partial_die_hash (const void *item
);
1504 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1506 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1507 (sect_offset offset
, struct objfile
*objfile
);
1509 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1510 struct dwarf2_per_cu_data
*per_cu
);
1512 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1513 struct die_info
*comp_unit_die
,
1514 enum language pretend_language
);
1516 static void free_heap_comp_unit (void *);
1518 static void free_cached_comp_units (void *);
1520 static void age_cached_comp_units (void);
1522 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1524 static struct type
*set_die_type (struct die_info
*, struct type
*,
1525 struct dwarf2_cu
*);
1527 static void create_all_comp_units (struct objfile
*);
1529 static int create_all_type_units (struct objfile
*);
1531 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1534 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1537 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1540 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1541 struct dwarf2_per_cu_data
*);
1543 static void dwarf2_mark (struct dwarf2_cu
*);
1545 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1547 static struct type
*get_die_type_at_offset (sect_offset
,
1548 struct dwarf2_per_cu_data
*per_cu
);
1550 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1552 static void dwarf2_release_queue (void *dummy
);
1554 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1555 enum language pretend_language
);
1557 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1558 struct dwarf2_per_cu_data
*per_cu
,
1559 enum language pretend_language
);
1561 static void process_queue (void);
1563 static void find_file_and_directory (struct die_info
*die
,
1564 struct dwarf2_cu
*cu
,
1565 char **name
, char **comp_dir
);
1567 static char *file_full_name (int file
, struct line_header
*lh
,
1568 const char *comp_dir
);
1570 static void init_cutu_and_read_dies
1571 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1572 int use_existing_cu
, int keep
,
1573 die_reader_func_ftype
*die_reader_func
, void *data
);
1575 static void init_cutu_and_read_dies_simple
1576 (struct dwarf2_per_cu_data
*this_cu
,
1577 die_reader_func_ftype
*die_reader_func
, void *data
);
1579 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1581 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1583 static struct dwo_unit
*lookup_dwo_comp_unit
1584 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1586 static struct dwo_unit
*lookup_dwo_type_unit
1587 (struct signatured_type
*, char *, const char *);
1589 static void free_dwo_file_cleanup (void *);
1591 static void munmap_section_buffer (struct dwarf2_section_info
*);
1593 static void process_cu_includes (void);
1597 /* Convert VALUE between big- and little-endian. */
1599 byte_swap (offset_type value
)
1603 result
= (value
& 0xff) << 24;
1604 result
|= (value
& 0xff00) << 8;
1605 result
|= (value
& 0xff0000) >> 8;
1606 result
|= (value
& 0xff000000) >> 24;
1610 #define MAYBE_SWAP(V) byte_swap (V)
1613 #define MAYBE_SWAP(V) (V)
1614 #endif /* WORDS_BIGENDIAN */
1616 /* The suffix for an index file. */
1617 #define INDEX_SUFFIX ".gdb-index"
1619 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1620 struct dwarf2_cu
*cu
);
1622 /* Try to locate the sections we need for DWARF 2 debugging
1623 information and return true if we have enough to do something.
1624 NAMES points to the dwarf2 section names, or is NULL if the standard
1625 ELF names are used. */
1628 dwarf2_has_info (struct objfile
*objfile
,
1629 const struct dwarf2_debug_sections
*names
)
1631 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1632 if (!dwarf2_per_objfile
)
1634 /* Initialize per-objfile state. */
1635 struct dwarf2_per_objfile
*data
1636 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1638 memset (data
, 0, sizeof (*data
));
1639 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1640 dwarf2_per_objfile
= data
;
1642 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1644 dwarf2_per_objfile
->objfile
= objfile
;
1646 return (dwarf2_per_objfile
->info
.asection
!= NULL
1647 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1650 /* When loading sections, we look either for uncompressed section or for
1651 compressed section names. */
1654 section_is_p (const char *section_name
,
1655 const struct dwarf2_section_names
*names
)
1657 if (names
->normal
!= NULL
1658 && strcmp (section_name
, names
->normal
) == 0)
1660 if (names
->compressed
!= NULL
1661 && strcmp (section_name
, names
->compressed
) == 0)
1666 /* This function is mapped across the sections and remembers the
1667 offset and size of each of the debugging sections we are interested
1671 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1673 const struct dwarf2_debug_sections
*names
;
1676 names
= &dwarf2_elf_names
;
1678 names
= (const struct dwarf2_debug_sections
*) vnames
;
1680 if (section_is_p (sectp
->name
, &names
->info
))
1682 dwarf2_per_objfile
->info
.asection
= sectp
;
1683 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1685 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1687 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1688 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1690 else if (section_is_p (sectp
->name
, &names
->line
))
1692 dwarf2_per_objfile
->line
.asection
= sectp
;
1693 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1695 else if (section_is_p (sectp
->name
, &names
->loc
))
1697 dwarf2_per_objfile
->loc
.asection
= sectp
;
1698 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1700 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1702 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1703 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1705 else if (section_is_p (sectp
->name
, &names
->macro
))
1707 dwarf2_per_objfile
->macro
.asection
= sectp
;
1708 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1710 else if (section_is_p (sectp
->name
, &names
->str
))
1712 dwarf2_per_objfile
->str
.asection
= sectp
;
1713 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1715 else if (section_is_p (sectp
->name
, &names
->addr
))
1717 dwarf2_per_objfile
->addr
.asection
= sectp
;
1718 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1720 else if (section_is_p (sectp
->name
, &names
->frame
))
1722 dwarf2_per_objfile
->frame
.asection
= sectp
;
1723 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1725 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1727 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1729 if (aflag
& SEC_HAS_CONTENTS
)
1731 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1732 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1735 else if (section_is_p (sectp
->name
, &names
->ranges
))
1737 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1738 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1740 else if (section_is_p (sectp
->name
, &names
->types
))
1742 struct dwarf2_section_info type_section
;
1744 memset (&type_section
, 0, sizeof (type_section
));
1745 type_section
.asection
= sectp
;
1746 type_section
.size
= bfd_get_section_size (sectp
);
1748 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1751 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1753 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1754 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1757 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1758 && bfd_section_vma (abfd
, sectp
) == 0)
1759 dwarf2_per_objfile
->has_section_at_zero
= 1;
1762 /* Decompress a section that was compressed using zlib. Store the
1763 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1766 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1767 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1769 bfd
*abfd
= sectp
->owner
;
1771 error (_("Support for zlib-compressed DWARF data (from '%s') "
1772 "is disabled in this copy of GDB"),
1773 bfd_get_filename (abfd
));
1775 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1776 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1777 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1778 bfd_size_type uncompressed_size
;
1779 gdb_byte
*uncompressed_buffer
;
1782 int header_size
= 12;
1784 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1785 || bfd_bread (compressed_buffer
,
1786 compressed_size
, abfd
) != compressed_size
)
1787 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1788 bfd_get_filename (abfd
));
1790 /* Read the zlib header. In this case, it should be "ZLIB" followed
1791 by the uncompressed section size, 8 bytes in big-endian order. */
1792 if (compressed_size
< header_size
1793 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1794 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1795 bfd_get_filename (abfd
));
1796 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1797 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1798 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1799 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1800 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1801 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1802 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1803 uncompressed_size
+= compressed_buffer
[11];
1805 /* It is possible the section consists of several compressed
1806 buffers concatenated together, so we uncompress in a loop. */
1810 strm
.avail_in
= compressed_size
- header_size
;
1811 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1812 strm
.avail_out
= uncompressed_size
;
1813 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1815 rc
= inflateInit (&strm
);
1816 while (strm
.avail_in
> 0)
1819 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1820 bfd_get_filename (abfd
), rc
);
1821 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1822 + (uncompressed_size
- strm
.avail_out
));
1823 rc
= inflate (&strm
, Z_FINISH
);
1824 if (rc
!= Z_STREAM_END
)
1825 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1826 bfd_get_filename (abfd
), rc
);
1827 rc
= inflateReset (&strm
);
1829 rc
= inflateEnd (&strm
);
1831 || strm
.avail_out
!= 0)
1832 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1833 bfd_get_filename (abfd
), rc
);
1835 do_cleanups (cleanup
);
1836 *outbuf
= uncompressed_buffer
;
1837 *outsize
= uncompressed_size
;
1841 /* A helper function that decides whether a section is empty,
1845 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1847 return info
->asection
== NULL
|| info
->size
== 0;
1850 /* Read the contents of the section INFO.
1851 OBJFILE is the main object file, but not necessarily the file where
1852 the section comes from. E.g., for DWO files INFO->asection->owner
1853 is the bfd of the DWO file.
1854 If the section is compressed, uncompress it before returning. */
1857 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1859 asection
*sectp
= info
->asection
;
1861 gdb_byte
*buf
, *retbuf
;
1862 unsigned char header
[4];
1866 info
->buffer
= NULL
;
1867 info
->map_addr
= NULL
;
1870 if (dwarf2_section_empty_p (info
))
1873 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1874 abfd
= sectp
->owner
;
1876 /* Check if the file has a 4-byte header indicating compression. */
1877 if (info
->size
> sizeof (header
)
1878 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1879 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1881 /* Upon decompression, update the buffer and its size. */
1882 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1884 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1892 pagesize
= getpagesize ();
1894 /* Only try to mmap sections which are large enough: we don't want to
1895 waste space due to fragmentation. Also, only try mmap for sections
1896 without relocations. */
1898 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1900 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1901 MAP_PRIVATE
, sectp
->filepos
,
1902 &info
->map_addr
, &info
->map_len
);
1904 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1906 #if HAVE_POSIX_MADVISE
1907 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1914 /* If we get here, we are a normal, not-compressed section. */
1916 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1918 /* When debugging .o files, we may need to apply relocations; see
1919 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1920 We never compress sections in .o files, so we only need to
1921 try this when the section is not compressed. */
1922 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1925 info
->buffer
= retbuf
;
1929 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1930 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1931 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1932 bfd_get_filename (abfd
));
1935 /* A helper function that returns the size of a section in a safe way.
1936 If you are positive that the section has been read before using the
1937 size, then it is safe to refer to the dwarf2_section_info object's
1938 "size" field directly. In other cases, you must call this
1939 function, because for compressed sections the size field is not set
1940 correctly until the section has been read. */
1942 static bfd_size_type
1943 dwarf2_section_size (struct objfile
*objfile
,
1944 struct dwarf2_section_info
*info
)
1947 dwarf2_read_section (objfile
, info
);
1951 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1955 dwarf2_get_section_info (struct objfile
*objfile
,
1956 enum dwarf2_section_enum sect
,
1957 asection
**sectp
, gdb_byte
**bufp
,
1958 bfd_size_type
*sizep
)
1960 struct dwarf2_per_objfile
*data
1961 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1962 struct dwarf2_section_info
*info
;
1964 /* We may see an objfile without any DWARF, in which case we just
1975 case DWARF2_DEBUG_FRAME
:
1976 info
= &data
->frame
;
1978 case DWARF2_EH_FRAME
:
1979 info
= &data
->eh_frame
;
1982 gdb_assert_not_reached ("unexpected section");
1985 dwarf2_read_section (objfile
, info
);
1987 *sectp
= info
->asection
;
1988 *bufp
= info
->buffer
;
1989 *sizep
= info
->size
;
1993 /* DWARF quick_symbols_functions support. */
1995 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1996 unique line tables, so we maintain a separate table of all .debug_line
1997 derived entries to support the sharing.
1998 All the quick functions need is the list of file names. We discard the
1999 line_header when we're done and don't need to record it here. */
2000 struct quick_file_names
2002 /* The offset in .debug_line of the line table. We hash on this. */
2003 unsigned int offset
;
2005 /* The number of entries in file_names, real_names. */
2006 unsigned int num_file_names
;
2008 /* The file names from the line table, after being run through
2010 const char **file_names
;
2012 /* The file names from the line table after being run through
2013 gdb_realpath. These are computed lazily. */
2014 const char **real_names
;
2017 /* When using the index (and thus not using psymtabs), each CU has an
2018 object of this type. This is used to hold information needed by
2019 the various "quick" methods. */
2020 struct dwarf2_per_cu_quick_data
2022 /* The file table. This can be NULL if there was no file table
2023 or it's currently not read in.
2024 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2025 struct quick_file_names
*file_names
;
2027 /* The corresponding symbol table. This is NULL if symbols for this
2028 CU have not yet been read. */
2029 struct symtab
*symtab
;
2031 /* A temporary mark bit used when iterating over all CUs in
2032 expand_symtabs_matching. */
2033 unsigned int mark
: 1;
2035 /* True if we've tried to read the file table and found there isn't one.
2036 There will be no point in trying to read it again next time. */
2037 unsigned int no_file_data
: 1;
2040 /* Hash function for a quick_file_names. */
2043 hash_file_name_entry (const void *e
)
2045 const struct quick_file_names
*file_data
= e
;
2047 return file_data
->offset
;
2050 /* Equality function for a quick_file_names. */
2053 eq_file_name_entry (const void *a
, const void *b
)
2055 const struct quick_file_names
*ea
= a
;
2056 const struct quick_file_names
*eb
= b
;
2058 return ea
->offset
== eb
->offset
;
2061 /* Delete function for a quick_file_names. */
2064 delete_file_name_entry (void *e
)
2066 struct quick_file_names
*file_data
= e
;
2069 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2071 xfree ((void*) file_data
->file_names
[i
]);
2072 if (file_data
->real_names
)
2073 xfree ((void*) file_data
->real_names
[i
]);
2076 /* The space for the struct itself lives on objfile_obstack,
2077 so we don't free it here. */
2080 /* Create a quick_file_names hash table. */
2083 create_quick_file_names_table (unsigned int nr_initial_entries
)
2085 return htab_create_alloc (nr_initial_entries
,
2086 hash_file_name_entry
, eq_file_name_entry
,
2087 delete_file_name_entry
, xcalloc
, xfree
);
2090 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2091 have to be created afterwards. You should call age_cached_comp_units after
2092 processing PER_CU->CU. dw2_setup must have been already called. */
2095 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2097 if (per_cu
->is_debug_types
)
2098 load_full_type_unit (per_cu
);
2100 load_full_comp_unit (per_cu
, language_minimal
);
2102 gdb_assert (per_cu
->cu
!= NULL
);
2104 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2107 /* Read in the symbols for PER_CU. */
2110 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2112 struct cleanup
*back_to
;
2114 /* Skip type_unit_groups, reading the type units they contain
2115 is handled elsewhere. */
2116 if (IS_TYPE_UNIT_GROUP (per_cu
))
2119 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2121 if (dwarf2_per_objfile
->using_index
2122 ? per_cu
->v
.quick
->symtab
== NULL
2123 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2125 queue_comp_unit (per_cu
, language_minimal
);
2131 /* Age the cache, releasing compilation units that have not
2132 been used recently. */
2133 age_cached_comp_units ();
2135 do_cleanups (back_to
);
2138 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2139 the objfile from which this CU came. Returns the resulting symbol
2142 static struct symtab
*
2143 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2145 gdb_assert (dwarf2_per_objfile
->using_index
);
2146 if (!per_cu
->v
.quick
->symtab
)
2148 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2149 increment_reading_symtab ();
2150 dw2_do_instantiate_symtab (per_cu
);
2151 process_cu_includes ();
2152 do_cleanups (back_to
);
2154 return per_cu
->v
.quick
->symtab
;
2157 /* Return the CU given its index.
2159 This is intended for loops like:
2161 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2162 + dwarf2_per_objfile->n_type_units); ++i)
2164 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2170 static struct dwarf2_per_cu_data
*
2171 dw2_get_cu (int index
)
2173 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2175 struct dwarf2_per_cu_data
*per_cu
;
2177 index
-= dwarf2_per_objfile
->n_comp_units
;
2178 per_cu
= &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2179 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
2183 return dwarf2_per_objfile
->all_comp_units
[index
];
2186 /* Return the primary CU given its index.
2187 The difference between this function and dw2_get_cu is in the handling
2188 of type units (TUs). Here we return the type_unit_group object.
2190 This is intended for loops like:
2192 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2193 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2195 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2201 static struct dwarf2_per_cu_data
*
2202 dw2_get_primary_cu (int index
)
2204 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2206 struct dwarf2_per_cu_data
*per_cu
;
2208 index
-= dwarf2_per_objfile
->n_comp_units
;
2209 per_cu
= dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2210 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
2214 return dwarf2_per_objfile
->all_comp_units
[index
];
2217 /* A helper function that knows how to read a 64-bit value in a way
2218 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2222 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2224 if (sizeof (ULONGEST
) < 8)
2228 /* Ignore the upper 4 bytes if they are all zero. */
2229 for (i
= 0; i
< 4; ++i
)
2230 if (bytes
[i
+ 4] != 0)
2233 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2236 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2240 /* Read the CU list from the mapped index, and use it to create all
2241 the CU objects for this objfile. Return 0 if something went wrong,
2242 1 if everything went ok. */
2245 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2246 offset_type cu_list_elements
)
2250 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2251 dwarf2_per_objfile
->all_comp_units
2252 = obstack_alloc (&objfile
->objfile_obstack
,
2253 dwarf2_per_objfile
->n_comp_units
2254 * sizeof (struct dwarf2_per_cu_data
*));
2256 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2258 struct dwarf2_per_cu_data
*the_cu
;
2259 ULONGEST offset
, length
;
2261 if (!extract_cu_value (cu_list
, &offset
)
2262 || !extract_cu_value (cu_list
+ 8, &length
))
2266 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2267 struct dwarf2_per_cu_data
);
2268 the_cu
->offset
.sect_off
= offset
;
2269 the_cu
->length
= length
;
2270 the_cu
->objfile
= objfile
;
2271 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2272 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2273 struct dwarf2_per_cu_quick_data
);
2274 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2280 /* Create the signatured type hash table from the index. */
2283 create_signatured_type_table_from_index (struct objfile
*objfile
,
2284 struct dwarf2_section_info
*section
,
2285 const gdb_byte
*bytes
,
2286 offset_type elements
)
2289 htab_t sig_types_hash
;
2291 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2292 dwarf2_per_objfile
->all_type_units
2293 = obstack_alloc (&objfile
->objfile_obstack
,
2294 dwarf2_per_objfile
->n_type_units
2295 * sizeof (struct signatured_type
*));
2297 sig_types_hash
= allocate_signatured_type_table (objfile
);
2299 for (i
= 0; i
< elements
; i
+= 3)
2301 struct signatured_type
*sig_type
;
2302 ULONGEST offset
, type_offset_in_tu
, signature
;
2305 if (!extract_cu_value (bytes
, &offset
)
2306 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2308 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2311 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2312 struct signatured_type
);
2313 sig_type
->signature
= signature
;
2314 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2315 sig_type
->per_cu
.is_debug_types
= 1;
2316 sig_type
->per_cu
.info_or_types_section
= section
;
2317 sig_type
->per_cu
.offset
.sect_off
= offset
;
2318 sig_type
->per_cu
.objfile
= objfile
;
2319 sig_type
->per_cu
.v
.quick
2320 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2321 struct dwarf2_per_cu_quick_data
);
2323 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2326 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2329 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2334 /* Read the address map data from the mapped index, and use it to
2335 populate the objfile's psymtabs_addrmap. */
2338 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2340 const gdb_byte
*iter
, *end
;
2341 struct obstack temp_obstack
;
2342 struct addrmap
*mutable_map
;
2343 struct cleanup
*cleanup
;
2346 obstack_init (&temp_obstack
);
2347 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2348 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2350 iter
= index
->address_table
;
2351 end
= iter
+ index
->address_table_size
;
2353 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2357 ULONGEST hi
, lo
, cu_index
;
2358 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2360 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2362 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2365 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2366 dw2_get_cu (cu_index
));
2369 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2370 &objfile
->objfile_obstack
);
2371 do_cleanups (cleanup
);
2374 /* The hash function for strings in the mapped index. This is the same as
2375 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2376 implementation. This is necessary because the hash function is tied to the
2377 format of the mapped index file. The hash values do not have to match with
2380 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2383 mapped_index_string_hash (int index_version
, const void *p
)
2385 const unsigned char *str
= (const unsigned char *) p
;
2389 while ((c
= *str
++) != 0)
2391 if (index_version
>= 5)
2393 r
= r
* 67 + c
- 113;
2399 /* Find a slot in the mapped index INDEX for the object named NAME.
2400 If NAME is found, set *VEC_OUT to point to the CU vector in the
2401 constant pool and return 1. If NAME cannot be found, return 0. */
2404 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2405 offset_type
**vec_out
)
2407 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2409 offset_type slot
, step
;
2410 int (*cmp
) (const char *, const char *);
2412 if (current_language
->la_language
== language_cplus
2413 || current_language
->la_language
== language_java
2414 || current_language
->la_language
== language_fortran
)
2416 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2418 const char *paren
= strchr (name
, '(');
2424 dup
= xmalloc (paren
- name
+ 1);
2425 memcpy (dup
, name
, paren
- name
);
2426 dup
[paren
- name
] = 0;
2428 make_cleanup (xfree
, dup
);
2433 /* Index version 4 did not support case insensitive searches. But the
2434 indices for case insensitive languages are built in lowercase, therefore
2435 simulate our NAME being searched is also lowercased. */
2436 hash
= mapped_index_string_hash ((index
->version
== 4
2437 && case_sensitivity
== case_sensitive_off
2438 ? 5 : index
->version
),
2441 slot
= hash
& (index
->symbol_table_slots
- 1);
2442 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2443 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2447 /* Convert a slot number to an offset into the table. */
2448 offset_type i
= 2 * slot
;
2450 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2452 do_cleanups (back_to
);
2456 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2457 if (!cmp (name
, str
))
2459 *vec_out
= (offset_type
*) (index
->constant_pool
2460 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2461 do_cleanups (back_to
);
2465 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2469 /* Read the index file. If everything went ok, initialize the "quick"
2470 elements of all the CUs and return 1. Otherwise, return 0. */
2473 dwarf2_read_index (struct objfile
*objfile
)
2476 struct mapped_index
*map
;
2477 offset_type
*metadata
;
2478 const gdb_byte
*cu_list
;
2479 const gdb_byte
*types_list
= NULL
;
2480 offset_type version
, cu_list_elements
;
2481 offset_type types_list_elements
= 0;
2484 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2487 /* Older elfutils strip versions could keep the section in the main
2488 executable while splitting it for the separate debug info file. */
2489 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2490 & SEC_HAS_CONTENTS
) == 0)
2493 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2495 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2496 /* Version check. */
2497 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2498 /* Versions earlier than 3 emitted every copy of a psymbol. This
2499 causes the index to behave very poorly for certain requests. Version 3
2500 contained incomplete addrmap. So, it seems better to just ignore such
2504 static int warning_printed
= 0;
2505 if (!warning_printed
)
2507 warning (_("Skipping obsolete .gdb_index section in %s."),
2509 warning_printed
= 1;
2513 /* Index version 4 uses a different hash function than index version
2516 Versions earlier than 6 did not emit psymbols for inlined
2517 functions. Using these files will cause GDB not to be able to
2518 set breakpoints on inlined functions by name, so we ignore these
2519 indices unless the --use-deprecated-index-sections command line
2520 option was supplied. */
2521 if (version
< 6 && !use_deprecated_index_sections
)
2523 static int warning_printed
= 0;
2524 if (!warning_printed
)
2526 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2527 "--use-deprecated-index-sections to use them anyway"),
2529 warning_printed
= 1;
2533 /* Indexes with higher version than the one supported by GDB may be no
2534 longer backward compatible. */
2538 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2539 map
->version
= version
;
2540 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2542 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2545 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2546 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2550 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2551 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2552 - MAYBE_SWAP (metadata
[i
]))
2556 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2557 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2558 - MAYBE_SWAP (metadata
[i
]));
2561 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2562 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2563 - MAYBE_SWAP (metadata
[i
]))
2564 / (2 * sizeof (offset_type
)));
2567 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2569 /* Don't use the index if it's empty. */
2570 if (map
->symbol_table_slots
== 0)
2573 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2576 if (types_list_elements
)
2578 struct dwarf2_section_info
*section
;
2580 /* We can only handle a single .debug_types when we have an
2582 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2585 section
= VEC_index (dwarf2_section_info_def
,
2586 dwarf2_per_objfile
->types
, 0);
2588 if (!create_signatured_type_table_from_index (objfile
, section
,
2590 types_list_elements
))
2594 create_addrmap_from_index (objfile
, map
);
2596 dwarf2_per_objfile
->index_table
= map
;
2597 dwarf2_per_objfile
->using_index
= 1;
2598 dwarf2_per_objfile
->quick_file_names_table
=
2599 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2604 /* A helper for the "quick" functions which sets the global
2605 dwarf2_per_objfile according to OBJFILE. */
2608 dw2_setup (struct objfile
*objfile
)
2610 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2611 gdb_assert (dwarf2_per_objfile
);
2614 /* Reader function for dw2_build_type_unit_groups. */
2617 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2619 struct die_info
*type_unit_die
,
2623 struct dwarf2_cu
*cu
= reader
->cu
;
2624 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
2625 struct attribute
*attr
;
2626 struct type_unit_group
*tu_group
;
2628 gdb_assert (data
== NULL
);
2633 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2634 /* Call this for its side-effect of creating the associated
2635 struct type_unit_group if it doesn't already exist. */
2636 tu_group
= get_type_unit_group (per_cu
, attr
);
2639 /* Build dwarf2_per_objfile->type_unit_groups.
2640 This function may be called multiple times. */
2643 dw2_build_type_unit_groups (void)
2645 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2646 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2649 /* die_reader_func for dw2_get_file_names. */
2652 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2654 struct die_info
*comp_unit_die
,
2658 struct dwarf2_cu
*cu
= reader
->cu
;
2659 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2661 struct line_header
*lh
;
2662 struct attribute
*attr
;
2664 char *name
, *comp_dir
;
2666 struct quick_file_names
*qfn
;
2667 unsigned int line_offset
;
2669 /* Our callers never want to match partial units -- instead they
2670 will match the enclosing full CU. */
2671 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2673 this_cu
->v
.quick
->no_file_data
= 1;
2681 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2684 struct quick_file_names find_entry
;
2686 line_offset
= DW_UNSND (attr
);
2688 /* We may have already read in this line header (TU line header sharing).
2689 If we have we're done. */
2690 find_entry
.offset
= line_offset
;
2691 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2692 &find_entry
, INSERT
);
2695 this_cu
->v
.quick
->file_names
= *slot
;
2699 lh
= dwarf_decode_line_header (line_offset
, cu
);
2703 this_cu
->v
.quick
->no_file_data
= 1;
2707 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2708 qfn
->offset
= line_offset
;
2709 gdb_assert (slot
!= NULL
);
2712 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2714 qfn
->num_file_names
= lh
->num_file_names
;
2715 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2716 lh
->num_file_names
* sizeof (char *));
2717 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2718 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2719 qfn
->real_names
= NULL
;
2721 free_line_header (lh
);
2723 this_cu
->v
.quick
->file_names
= qfn
;
2726 /* A helper for the "quick" functions which attempts to read the line
2727 table for THIS_CU. */
2729 static struct quick_file_names
*
2730 dw2_get_file_names (struct objfile
*objfile
,
2731 struct dwarf2_per_cu_data
*this_cu
)
2733 /* For TUs this should only be called on the parent group. */
2734 if (this_cu
->is_debug_types
)
2735 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2737 if (this_cu
->v
.quick
->file_names
!= NULL
)
2738 return this_cu
->v
.quick
->file_names
;
2739 /* If we know there is no line data, no point in looking again. */
2740 if (this_cu
->v
.quick
->no_file_data
)
2743 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2744 in the stub for CUs, there's is no need to lookup the DWO file.
2745 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2747 if (this_cu
->is_debug_types
)
2748 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
2749 dw2_get_file_names_reader
, NULL
);
2751 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2753 if (this_cu
->v
.quick
->no_file_data
)
2755 return this_cu
->v
.quick
->file_names
;
2758 /* A helper for the "quick" functions which computes and caches the
2759 real path for a given file name from the line table. */
2762 dw2_get_real_path (struct objfile
*objfile
,
2763 struct quick_file_names
*qfn
, int index
)
2765 if (qfn
->real_names
== NULL
)
2766 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2767 qfn
->num_file_names
, sizeof (char *));
2769 if (qfn
->real_names
[index
] == NULL
)
2770 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2772 return qfn
->real_names
[index
];
2775 static struct symtab
*
2776 dw2_find_last_source_symtab (struct objfile
*objfile
)
2780 dw2_setup (objfile
);
2781 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2782 return dw2_instantiate_symtab (dw2_get_cu (index
));
2785 /* Traversal function for dw2_forget_cached_source_info. */
2788 dw2_free_cached_file_names (void **slot
, void *info
)
2790 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2792 if (file_data
->real_names
)
2796 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2798 xfree ((void*) file_data
->real_names
[i
]);
2799 file_data
->real_names
[i
] = NULL
;
2807 dw2_forget_cached_source_info (struct objfile
*objfile
)
2809 dw2_setup (objfile
);
2811 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2812 dw2_free_cached_file_names
, NULL
);
2815 /* Helper function for dw2_map_symtabs_matching_filename that expands
2816 the symtabs and calls the iterator. */
2819 dw2_map_expand_apply (struct objfile
*objfile
,
2820 struct dwarf2_per_cu_data
*per_cu
,
2822 const char *full_path
, const char *real_path
,
2823 int (*callback
) (struct symtab
*, void *),
2826 struct symtab
*last_made
= objfile
->symtabs
;
2828 /* Don't visit already-expanded CUs. */
2829 if (per_cu
->v
.quick
->symtab
)
2832 /* This may expand more than one symtab, and we want to iterate over
2834 dw2_instantiate_symtab (per_cu
);
2836 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2837 objfile
->symtabs
, last_made
);
2840 /* Implementation of the map_symtabs_matching_filename method. */
2843 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2844 const char *full_path
, const char *real_path
,
2845 int (*callback
) (struct symtab
*, void *),
2849 const char *name_basename
= lbasename (name
);
2850 int name_len
= strlen (name
);
2851 int is_abs
= IS_ABSOLUTE_PATH (name
);
2853 dw2_setup (objfile
);
2855 dw2_build_type_unit_groups ();
2857 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2858 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
2861 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
2862 struct quick_file_names
*file_data
;
2864 /* We only need to look at symtabs not already expanded. */
2865 if (per_cu
->v
.quick
->symtab
)
2868 file_data
= dw2_get_file_names (objfile
, per_cu
);
2869 if (file_data
== NULL
)
2872 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2874 const char *this_name
= file_data
->file_names
[j
];
2876 if (FILENAME_CMP (name
, this_name
) == 0
2877 || (!is_abs
&& compare_filenames_for_search (this_name
,
2880 if (dw2_map_expand_apply (objfile
, per_cu
,
2881 name
, full_path
, real_path
,
2886 /* Before we invoke realpath, which can get expensive when many
2887 files are involved, do a quick comparison of the basenames. */
2888 if (! basenames_may_differ
2889 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2892 if (full_path
!= NULL
)
2894 const char *this_real_name
= dw2_get_real_path (objfile
,
2897 if (this_real_name
!= NULL
2898 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2900 && compare_filenames_for_search (this_real_name
,
2903 if (dw2_map_expand_apply (objfile
, per_cu
,
2904 name
, full_path
, real_path
,
2910 if (real_path
!= NULL
)
2912 const char *this_real_name
= dw2_get_real_path (objfile
,
2915 if (this_real_name
!= NULL
2916 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2918 && compare_filenames_for_search (this_real_name
,
2921 if (dw2_map_expand_apply (objfile
, per_cu
,
2922 name
, full_path
, real_path
,
2933 static struct symtab
*
2934 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2935 const char *name
, domain_enum domain
)
2937 /* We do all the work in the pre_expand_symtabs_matching hook
2942 /* A helper function that expands all symtabs that hold an object
2943 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
2944 symbols in block BLOCK_KIND. */
2947 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
2948 int want_specific_block
,
2949 enum block_enum block_kind
,
2950 const char *name
, domain_enum domain
)
2952 struct mapped_index
*index
;
2954 dw2_setup (objfile
);
2956 index
= dwarf2_per_objfile
->index_table
;
2958 /* index_table is NULL if OBJF_READNOW. */
2963 if (find_slot_in_mapped_hash (index
, name
, &vec
))
2965 offset_type i
, len
= MAYBE_SWAP (*vec
);
2966 for (i
= 0; i
< len
; ++i
)
2968 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
2969 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
2970 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2971 int want_static
= block_kind
!= GLOBAL_BLOCK
;
2972 /* This value is only valid for index versions >= 7. */
2973 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
2974 gdb_index_symbol_kind symbol_kind
=
2975 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
2977 if (want_specific_block
2978 && index
->version
>= 7
2979 && want_static
!= is_static
)
2982 /* Only check the symbol's kind if it has one.
2983 Indices prior to version 7 don't record it. */
2984 if (index
->version
>= 7)
2989 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
2990 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
2991 /* Some types are also in VAR_DOMAIN. */
2992 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2996 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3000 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3008 dw2_instantiate_symtab (per_cu
);
3015 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
3016 enum block_enum block_kind
, const char *name
,
3019 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
3023 dw2_print_stats (struct objfile
*objfile
)
3027 dw2_setup (objfile
);
3029 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3030 + dwarf2_per_objfile
->n_type_units
); ++i
)
3032 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3034 if (!per_cu
->v
.quick
->symtab
)
3037 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3041 dw2_dump (struct objfile
*objfile
)
3043 /* Nothing worth printing. */
3047 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3048 struct section_offsets
*delta
)
3050 /* There's nothing to relocate here. */
3054 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3055 const char *func_name
)
3057 /* Note: It doesn't matter what we pass for block_kind here. */
3058 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
3063 dw2_expand_all_symtabs (struct objfile
*objfile
)
3067 dw2_setup (objfile
);
3069 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3070 + dwarf2_per_objfile
->n_type_units
); ++i
)
3072 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3074 dw2_instantiate_symtab (per_cu
);
3079 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3080 const char *filename
)
3084 dw2_setup (objfile
);
3086 /* We don't need to consider type units here.
3087 This is only called for examining code, e.g. expand_line_sal.
3088 There can be an order of magnitude (or more) more type units
3089 than comp units, and we avoid them if we can. */
3091 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3094 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3095 struct quick_file_names
*file_data
;
3097 /* We only need to look at symtabs not already expanded. */
3098 if (per_cu
->v
.quick
->symtab
)
3101 file_data
= dw2_get_file_names (objfile
, per_cu
);
3102 if (file_data
== NULL
)
3105 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3107 const char *this_name
= file_data
->file_names
[j
];
3108 if (FILENAME_CMP (this_name
, filename
) == 0)
3110 dw2_instantiate_symtab (per_cu
);
3117 /* A helper function for dw2_find_symbol_file that finds the primary
3118 file name for a given CU. This is a die_reader_func. */
3121 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3123 struct die_info
*comp_unit_die
,
3127 const char **result_ptr
= data
;
3128 struct dwarf2_cu
*cu
= reader
->cu
;
3129 struct attribute
*attr
;
3131 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3135 *result_ptr
= DW_STRING (attr
);
3139 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3141 struct dwarf2_per_cu_data
*per_cu
;
3143 struct quick_file_names
*file_data
;
3144 const char *filename
;
3146 dw2_setup (objfile
);
3148 /* index_table is NULL if OBJF_READNOW. */
3149 if (!dwarf2_per_objfile
->index_table
)
3153 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3155 struct blockvector
*bv
= BLOCKVECTOR (s
);
3156 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3157 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3160 return sym
->symtab
->filename
;
3165 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3169 /* Note that this just looks at the very first one named NAME -- but
3170 actually we are looking for a function. find_main_filename
3171 should be rewritten so that it doesn't require a custom hook. It
3172 could just use the ordinary symbol tables. */
3173 /* vec[0] is the length, which must always be >0. */
3174 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3176 if (per_cu
->v
.quick
->symtab
!= NULL
)
3177 return per_cu
->v
.quick
->symtab
->filename
;
3179 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3180 dw2_get_primary_filename_reader
, &filename
);
3186 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3187 struct objfile
*objfile
, int global
,
3188 int (*callback
) (struct block
*,
3189 struct symbol
*, void *),
3190 void *data
, symbol_compare_ftype
*match
,
3191 symbol_compare_ftype
*ordered_compare
)
3193 /* Currently unimplemented; used for Ada. The function can be called if the
3194 current language is Ada for a non-Ada objfile using GNU index. As Ada
3195 does not look for non-Ada symbols this function should just return. */
3199 dw2_expand_symtabs_matching
3200 (struct objfile
*objfile
,
3201 int (*file_matcher
) (const char *, void *),
3202 int (*name_matcher
) (const char *, void *),
3203 enum search_domain kind
,
3208 struct mapped_index
*index
;
3210 dw2_setup (objfile
);
3212 /* index_table is NULL if OBJF_READNOW. */
3213 if (!dwarf2_per_objfile
->index_table
)
3215 index
= dwarf2_per_objfile
->index_table
;
3217 if (file_matcher
!= NULL
)
3219 struct cleanup
*cleanup
;
3220 htab_t visited_found
, visited_not_found
;
3222 dw2_build_type_unit_groups ();
3224 visited_found
= htab_create_alloc (10,
3225 htab_hash_pointer
, htab_eq_pointer
,
3226 NULL
, xcalloc
, xfree
);
3227 cleanup
= make_cleanup_htab_delete (visited_found
);
3228 visited_not_found
= htab_create_alloc (10,
3229 htab_hash_pointer
, htab_eq_pointer
,
3230 NULL
, xcalloc
, xfree
);
3231 make_cleanup_htab_delete (visited_not_found
);
3233 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3234 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3237 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3238 struct quick_file_names
*file_data
;
3241 per_cu
->v
.quick
->mark
= 0;
3243 /* We only need to look at symtabs not already expanded. */
3244 if (per_cu
->v
.quick
->symtab
)
3247 file_data
= dw2_get_file_names (objfile
, per_cu
);
3248 if (file_data
== NULL
)
3251 if (htab_find (visited_not_found
, file_data
) != NULL
)
3253 else if (htab_find (visited_found
, file_data
) != NULL
)
3255 per_cu
->v
.quick
->mark
= 1;
3259 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3261 if (file_matcher (file_data
->file_names
[j
], data
))
3263 per_cu
->v
.quick
->mark
= 1;
3268 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3270 : visited_not_found
,
3275 do_cleanups (cleanup
);
3278 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3280 offset_type idx
= 2 * iter
;
3282 offset_type
*vec
, vec_len
, vec_idx
;
3284 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3287 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3289 if (! (*name_matcher
) (name
, data
))
3292 /* The name was matched, now expand corresponding CUs that were
3294 vec
= (offset_type
*) (index
->constant_pool
3295 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3296 vec_len
= MAYBE_SWAP (vec
[0]);
3297 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3299 struct dwarf2_per_cu_data
*per_cu
;
3300 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3301 gdb_index_symbol_kind symbol_kind
=
3302 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3303 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3305 /* Don't crash on bad data. */
3306 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3307 + dwarf2_per_objfile
->n_type_units
))
3310 /* Only check the symbol's kind if it has one.
3311 Indices prior to version 7 don't record it. */
3312 if (index
->version
>= 7)
3316 case VARIABLES_DOMAIN
:
3317 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3320 case FUNCTIONS_DOMAIN
:
3321 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3325 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3333 per_cu
= dw2_get_cu (cu_index
);
3334 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3335 dw2_instantiate_symtab (per_cu
);
3340 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3343 static struct symtab
*
3344 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3348 if (BLOCKVECTOR (symtab
) != NULL
3349 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3352 if (symtab
->includes
== NULL
)
3355 for (i
= 0; symtab
->includes
[i
]; ++i
)
3357 struct symtab
*s
= symtab
->includes
[i
];
3359 s
= recursively_find_pc_sect_symtab (s
, pc
);
3367 static struct symtab
*
3368 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3369 struct minimal_symbol
*msymbol
,
3371 struct obj_section
*section
,
3374 struct dwarf2_per_cu_data
*data
;
3375 struct symtab
*result
;
3377 dw2_setup (objfile
);
3379 if (!objfile
->psymtabs_addrmap
)
3382 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3386 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3387 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3388 paddress (get_objfile_arch (objfile
), pc
));
3390 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3391 gdb_assert (result
!= NULL
);
3396 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3397 void *data
, int need_fullname
)
3400 struct cleanup
*cleanup
;
3401 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3402 NULL
, xcalloc
, xfree
);
3404 cleanup
= make_cleanup_htab_delete (visited
);
3405 dw2_setup (objfile
);
3407 dw2_build_type_unit_groups ();
3409 /* We can ignore file names coming from already-expanded CUs. */
3410 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3411 + dwarf2_per_objfile
->n_type_units
); ++i
)
3413 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3415 if (per_cu
->v
.quick
->symtab
)
3417 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3420 *slot
= per_cu
->v
.quick
->file_names
;
3424 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3425 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3428 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3429 struct quick_file_names
*file_data
;
3432 /* We only need to look at symtabs not already expanded. */
3433 if (per_cu
->v
.quick
->symtab
)
3436 file_data
= dw2_get_file_names (objfile
, per_cu
);
3437 if (file_data
== NULL
)
3440 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3443 /* Already visited. */
3448 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3450 const char *this_real_name
;
3453 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3455 this_real_name
= NULL
;
3456 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3460 do_cleanups (cleanup
);
3464 dw2_has_symbols (struct objfile
*objfile
)
3469 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3472 dw2_find_last_source_symtab
,
3473 dw2_forget_cached_source_info
,
3474 dw2_map_symtabs_matching_filename
,
3476 dw2_pre_expand_symtabs_matching
,
3480 dw2_expand_symtabs_for_function
,
3481 dw2_expand_all_symtabs
,
3482 dw2_expand_symtabs_with_filename
,
3483 dw2_find_symbol_file
,
3484 dw2_map_matching_symbols
,
3485 dw2_expand_symtabs_matching
,
3486 dw2_find_pc_sect_symtab
,
3487 dw2_map_symbol_filenames
3490 /* Initialize for reading DWARF for this objfile. Return 0 if this
3491 file will use psymtabs, or 1 if using the GNU index. */
3494 dwarf2_initialize_objfile (struct objfile
*objfile
)
3496 /* If we're about to read full symbols, don't bother with the
3497 indices. In this case we also don't care if some other debug
3498 format is making psymtabs, because they are all about to be
3500 if ((objfile
->flags
& OBJF_READNOW
))
3504 dwarf2_per_objfile
->using_index
= 1;
3505 create_all_comp_units (objfile
);
3506 create_all_type_units (objfile
);
3507 dwarf2_per_objfile
->quick_file_names_table
=
3508 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3510 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3511 + dwarf2_per_objfile
->n_type_units
); ++i
)
3513 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3515 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3516 struct dwarf2_per_cu_quick_data
);
3519 /* Return 1 so that gdb sees the "quick" functions. However,
3520 these functions will be no-ops because we will have expanded
3525 if (dwarf2_read_index (objfile
))
3533 /* Build a partial symbol table. */
3536 dwarf2_build_psymtabs (struct objfile
*objfile
)
3538 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3540 init_psymbol_list (objfile
, 1024);
3543 dwarf2_build_psymtabs_hard (objfile
);
3546 /* Return the total length of the CU described by HEADER. */
3549 get_cu_length (const struct comp_unit_head
*header
)
3551 return header
->initial_length_size
+ header
->length
;
3554 /* Return TRUE if OFFSET is within CU_HEADER. */
3557 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3559 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3560 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3562 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3565 /* Find the base address of the compilation unit for range lists and
3566 location lists. It will normally be specified by DW_AT_low_pc.
3567 In DWARF-3 draft 4, the base address could be overridden by
3568 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3569 compilation units with discontinuous ranges. */
3572 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3574 struct attribute
*attr
;
3577 cu
->base_address
= 0;
3579 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3582 cu
->base_address
= DW_ADDR (attr
);
3587 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3590 cu
->base_address
= DW_ADDR (attr
);
3596 /* Read in the comp unit header information from the debug_info at info_ptr.
3597 NOTE: This leaves members offset, first_die_offset to be filled in
3601 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3602 gdb_byte
*info_ptr
, bfd
*abfd
)
3605 unsigned int bytes_read
;
3607 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3608 cu_header
->initial_length_size
= bytes_read
;
3609 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3610 info_ptr
+= bytes_read
;
3611 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3613 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3615 info_ptr
+= bytes_read
;
3616 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3618 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3619 if (signed_addr
< 0)
3620 internal_error (__FILE__
, __LINE__
,
3621 _("read_comp_unit_head: dwarf from non elf file"));
3622 cu_header
->signed_addr_p
= signed_addr
;
3627 /* Subroutine of read_and_check_comp_unit_head and
3628 read_and_check_type_unit_head to simplify them.
3629 Perform various error checking on the header. */
3632 error_check_comp_unit_head (struct comp_unit_head
*header
,
3633 struct dwarf2_section_info
*section
,
3634 struct dwarf2_section_info
*abbrev_section
)
3636 bfd
*abfd
= section
->asection
->owner
;
3637 const char *filename
= bfd_get_filename (abfd
);
3639 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3640 error (_("Dwarf Error: wrong version in compilation unit header "
3641 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3644 if (header
->abbrev_offset
.sect_off
3645 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3646 &dwarf2_per_objfile
->abbrev
))
3647 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3648 "(offset 0x%lx + 6) [in module %s]"),
3649 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3652 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3653 avoid potential 32-bit overflow. */
3654 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3656 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3657 "(offset 0x%lx + 0) [in module %s]"),
3658 (long) header
->length
, (long) header
->offset
.sect_off
,
3662 /* Read in a CU/TU header and perform some basic error checking.
3663 The contents of the header are stored in HEADER.
3664 The result is a pointer to the start of the first DIE. */
3667 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3668 struct dwarf2_section_info
*section
,
3669 struct dwarf2_section_info
*abbrev_section
,
3671 int is_debug_types_section
)
3673 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3674 bfd
*abfd
= section
->asection
->owner
;
3676 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3678 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3680 /* If we're reading a type unit, skip over the signature and
3681 type_offset fields. */
3682 if (is_debug_types_section
)
3683 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3685 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3687 error_check_comp_unit_head (header
, section
, abbrev_section
);
3692 /* Read in the types comp unit header information from .debug_types entry at
3693 types_ptr. The result is a pointer to one past the end of the header. */
3696 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3697 struct dwarf2_section_info
*section
,
3698 struct dwarf2_section_info
*abbrev_section
,
3700 ULONGEST
*signature
,
3701 cu_offset
*type_offset_in_tu
)
3703 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3704 bfd
*abfd
= section
->asection
->owner
;
3706 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3708 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3710 /* If we're reading a type unit, skip over the signature and
3711 type_offset fields. */
3712 if (signature
!= NULL
)
3713 *signature
= read_8_bytes (abfd
, info_ptr
);
3715 if (type_offset_in_tu
!= NULL
)
3716 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3717 header
->offset_size
);
3718 info_ptr
+= header
->offset_size
;
3720 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3722 error_check_comp_unit_head (header
, section
, abbrev_section
);
3727 /* Fetch the abbreviation table offset from a comp or type unit header. */
3730 read_abbrev_offset (struct dwarf2_section_info
*section
,
3733 bfd
*abfd
= section
->asection
->owner
;
3735 unsigned int length
, initial_length_size
, offset_size
;
3736 sect_offset abbrev_offset
;
3738 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3739 info_ptr
= section
->buffer
+ offset
.sect_off
;
3740 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3741 offset_size
= initial_length_size
== 4 ? 4 : 8;
3742 info_ptr
+= initial_length_size
+ 2 /*version*/;
3743 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
3744 return abbrev_offset
;
3747 /* Allocate a new partial symtab for file named NAME and mark this new
3748 partial symtab as being an include of PST. */
3751 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3752 struct objfile
*objfile
)
3754 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3756 subpst
->section_offsets
= pst
->section_offsets
;
3757 subpst
->textlow
= 0;
3758 subpst
->texthigh
= 0;
3760 subpst
->dependencies
= (struct partial_symtab
**)
3761 obstack_alloc (&objfile
->objfile_obstack
,
3762 sizeof (struct partial_symtab
*));
3763 subpst
->dependencies
[0] = pst
;
3764 subpst
->number_of_dependencies
= 1;
3766 subpst
->globals_offset
= 0;
3767 subpst
->n_global_syms
= 0;
3768 subpst
->statics_offset
= 0;
3769 subpst
->n_static_syms
= 0;
3770 subpst
->symtab
= NULL
;
3771 subpst
->read_symtab
= pst
->read_symtab
;
3774 /* No private part is necessary for include psymtabs. This property
3775 can be used to differentiate between such include psymtabs and
3776 the regular ones. */
3777 subpst
->read_symtab_private
= NULL
;
3780 /* Read the Line Number Program data and extract the list of files
3781 included by the source file represented by PST. Build an include
3782 partial symtab for each of these included files. */
3785 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3786 struct die_info
*die
,
3787 struct partial_symtab
*pst
)
3789 struct line_header
*lh
= NULL
;
3790 struct attribute
*attr
;
3792 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3794 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3796 return; /* No linetable, so no includes. */
3798 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3799 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3801 free_line_header (lh
);
3805 hash_signatured_type (const void *item
)
3807 const struct signatured_type
*sig_type
= item
;
3809 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3810 return sig_type
->signature
;
3814 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3816 const struct signatured_type
*lhs
= item_lhs
;
3817 const struct signatured_type
*rhs
= item_rhs
;
3819 return lhs
->signature
== rhs
->signature
;
3822 /* Allocate a hash table for signatured types. */
3825 allocate_signatured_type_table (struct objfile
*objfile
)
3827 return htab_create_alloc_ex (41,
3828 hash_signatured_type
,
3831 &objfile
->objfile_obstack
,
3832 hashtab_obstack_allocate
,
3833 dummy_obstack_deallocate
);
3836 /* A helper function to add a signatured type CU to a table. */
3839 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3841 struct signatured_type
*sigt
= *slot
;
3842 struct signatured_type
***datap
= datum
;
3850 /* Create the hash table of all entries in the .debug_types section.
3851 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3852 The result is a pointer to the hash table or NULL if there are
3856 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3857 VEC (dwarf2_section_info_def
) *types
)
3859 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3860 htab_t types_htab
= NULL
;
3862 struct dwarf2_section_info
*section
;
3863 struct dwarf2_section_info
*abbrev_section
;
3865 if (VEC_empty (dwarf2_section_info_def
, types
))
3868 abbrev_section
= (dwo_file
!= NULL
3869 ? &dwo_file
->sections
.abbrev
3870 : &dwarf2_per_objfile
->abbrev
);
3872 if (dwarf2_read_debug
)
3873 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
3874 dwo_file
? ".dwo" : "",
3875 bfd_get_filename (abbrev_section
->asection
->owner
));
3878 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3882 gdb_byte
*info_ptr
, *end_ptr
;
3884 dwarf2_read_section (objfile
, section
);
3885 info_ptr
= section
->buffer
;
3887 if (info_ptr
== NULL
)
3890 /* We can't set abfd until now because the section may be empty or
3891 not present, in which case section->asection will be NULL. */
3892 abfd
= section
->asection
->owner
;
3894 if (types_htab
== NULL
)
3897 types_htab
= allocate_dwo_unit_table (objfile
);
3899 types_htab
= allocate_signatured_type_table (objfile
);
3902 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3903 because we don't need to read any dies: the signature is in the
3906 end_ptr
= info_ptr
+ section
->size
;
3907 while (info_ptr
< end_ptr
)
3910 cu_offset type_offset_in_tu
;
3912 struct signatured_type
*sig_type
;
3913 struct dwo_unit
*dwo_tu
;
3915 gdb_byte
*ptr
= info_ptr
;
3916 struct comp_unit_head header
;
3917 unsigned int length
;
3919 offset
.sect_off
= ptr
- section
->buffer
;
3921 /* We need to read the type's signature in order to build the hash
3922 table, but we don't need anything else just yet. */
3924 ptr
= read_and_check_type_unit_head (&header
, section
,
3925 abbrev_section
, ptr
,
3926 &signature
, &type_offset_in_tu
);
3928 length
= get_cu_length (&header
);
3930 /* Skip dummy type units. */
3931 if (ptr
>= info_ptr
+ length
3932 || peek_abbrev_code (abfd
, ptr
) == 0)
3941 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3943 dwo_tu
->dwo_file
= dwo_file
;
3944 dwo_tu
->signature
= signature
;
3945 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3946 dwo_tu
->info_or_types_section
= section
;
3947 dwo_tu
->offset
= offset
;
3948 dwo_tu
->length
= length
;
3952 /* N.B.: type_offset is not usable if this type uses a DWO file.
3953 The real type_offset is in the DWO file. */
3955 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3956 struct signatured_type
);
3957 sig_type
->signature
= signature
;
3958 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3959 sig_type
->per_cu
.objfile
= objfile
;
3960 sig_type
->per_cu
.is_debug_types
= 1;
3961 sig_type
->per_cu
.info_or_types_section
= section
;
3962 sig_type
->per_cu
.offset
= offset
;
3963 sig_type
->per_cu
.length
= length
;
3966 slot
= htab_find_slot (types_htab
,
3967 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3969 gdb_assert (slot
!= NULL
);
3972 sect_offset dup_offset
;
3976 const struct dwo_unit
*dup_tu
= *slot
;
3978 dup_offset
= dup_tu
->offset
;
3982 const struct signatured_type
*dup_tu
= *slot
;
3984 dup_offset
= dup_tu
->per_cu
.offset
;
3987 complaint (&symfile_complaints
,
3988 _("debug type entry at offset 0x%x is duplicate to the "
3989 "entry at offset 0x%x, signature 0x%s"),
3990 offset
.sect_off
, dup_offset
.sect_off
,
3991 phex (signature
, sizeof (signature
)));
3993 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3995 if (dwarf2_read_debug
)
3996 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3998 phex (signature
, sizeof (signature
)));
4007 /* Create the hash table of all entries in the .debug_types section,
4008 and initialize all_type_units.
4009 The result is zero if there is an error (e.g. missing .debug_types section),
4010 otherwise non-zero. */
4013 create_all_type_units (struct objfile
*objfile
)
4016 struct signatured_type
**iter
;
4018 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4019 if (types_htab
== NULL
)
4021 dwarf2_per_objfile
->signatured_types
= NULL
;
4025 dwarf2_per_objfile
->signatured_types
= types_htab
;
4027 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4028 dwarf2_per_objfile
->all_type_units
4029 = obstack_alloc (&objfile
->objfile_obstack
,
4030 dwarf2_per_objfile
->n_type_units
4031 * sizeof (struct signatured_type
*));
4032 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4033 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4034 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4035 == dwarf2_per_objfile
->n_type_units
);
4040 /* Lookup a signature based type for DW_FORM_ref_sig8.
4041 Returns NULL if signature SIG is not present in the table. */
4043 static struct signatured_type
*
4044 lookup_signatured_type (ULONGEST sig
)
4046 struct signatured_type find_entry
, *entry
;
4048 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4050 complaint (&symfile_complaints
,
4051 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4055 find_entry
.signature
= sig
;
4056 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4060 /* Low level DIE reading support. */
4062 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4065 init_cu_die_reader (struct die_reader_specs
*reader
,
4066 struct dwarf2_cu
*cu
,
4067 struct dwarf2_section_info
*section
,
4068 struct dwo_file
*dwo_file
)
4070 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4071 reader
->abfd
= section
->asection
->owner
;
4073 reader
->dwo_file
= dwo_file
;
4074 reader
->die_section
= section
;
4075 reader
->buffer
= section
->buffer
;
4076 reader
->buffer_end
= section
->buffer
+ section
->size
;
4079 /* Initialize a CU (or TU) and read its DIEs.
4080 If the CU defers to a DWO file, read the DWO file as well.
4082 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4083 Otherwise the table specified in the comp unit header is read in and used.
4084 This is an optimization for when we already have the abbrev table.
4086 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4087 Otherwise, a new CU is allocated with xmalloc.
4089 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4090 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4092 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4093 linker) then DIE_READER_FUNC will not get called. */
4096 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4097 struct abbrev_table
*abbrev_table
,
4098 int use_existing_cu
, int keep
,
4099 die_reader_func_ftype
*die_reader_func
,
4102 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4103 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4104 bfd
*abfd
= section
->asection
->owner
;
4105 struct dwarf2_cu
*cu
;
4106 gdb_byte
*begin_info_ptr
, *info_ptr
;
4107 struct die_reader_specs reader
;
4108 struct die_info
*comp_unit_die
;
4110 struct attribute
*attr
;
4111 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4112 struct signatured_type
*sig_type
= NULL
;
4113 struct dwarf2_section_info
*abbrev_section
;
4114 /* Non-zero if CU currently points to a DWO file and we need to
4115 reread it. When this happens we need to reread the skeleton die
4116 before we can reread the DWO file. */
4117 int rereading_dwo_cu
= 0;
4119 if (dwarf2_die_debug
)
4120 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4121 this_cu
->is_debug_types
? "type" : "comp",
4122 this_cu
->offset
.sect_off
);
4124 if (use_existing_cu
)
4127 cleanups
= make_cleanup (null_cleanup
, NULL
);
4129 /* This is cheap if the section is already read in. */
4130 dwarf2_read_section (objfile
, section
);
4132 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4133 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4135 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4139 /* If this CU is from a DWO file we need to start over, we need to
4140 refetch the attributes from the skeleton CU.
4141 This could be optimized by retrieving those attributes from when we
4142 were here the first time: the previous comp_unit_die was stored in
4143 comp_unit_obstack. But there's no data yet that we need this
4145 if (cu
->dwo_unit
!= NULL
)
4146 rereading_dwo_cu
= 1;
4150 /* If !use_existing_cu, this_cu->cu must be NULL. */
4151 gdb_assert (this_cu
->cu
== NULL
);
4153 cu
= xmalloc (sizeof (*cu
));
4154 init_one_comp_unit (cu
, this_cu
);
4156 /* If an error occurs while loading, release our storage. */
4157 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4160 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4162 /* We already have the header, there's no need to read it in again. */
4163 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4167 if (this_cu
->is_debug_types
)
4170 cu_offset type_offset_in_tu
;
4172 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4173 abbrev_section
, info_ptr
,
4175 &type_offset_in_tu
);
4177 /* Since per_cu is the first member of struct signatured_type,
4178 we can go from a pointer to one to a pointer to the other. */
4179 sig_type
= (struct signatured_type
*) this_cu
;
4180 gdb_assert (sig_type
->signature
== signature
);
4181 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4182 == type_offset_in_tu
.cu_off
);
4183 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4185 /* LENGTH has not been set yet for type units if we're
4186 using .gdb_index. */
4187 this_cu
->length
= get_cu_length (&cu
->header
);
4189 /* Establish the type offset that can be used to lookup the type. */
4190 sig_type
->type_offset_in_section
.sect_off
=
4191 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4195 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4199 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4200 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4204 /* Skip dummy compilation units. */
4205 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4206 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4208 do_cleanups (cleanups
);
4212 /* If we don't have them yet, read the abbrevs for this compilation unit.
4213 And if we need to read them now, make sure they're freed when we're
4214 done. Note that it's important that if the CU had an abbrev table
4215 on entry we don't free it when we're done: Somewhere up the call stack
4216 it may be in use. */
4217 if (abbrev_table
!= NULL
)
4219 gdb_assert (cu
->abbrev_table
== NULL
);
4220 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4221 == abbrev_table
->offset
.sect_off
);
4222 cu
->abbrev_table
= abbrev_table
;
4224 else if (cu
->abbrev_table
== NULL
)
4226 dwarf2_read_abbrevs (cu
, abbrev_section
);
4227 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4229 else if (rereading_dwo_cu
)
4231 dwarf2_free_abbrev_table (cu
);
4232 dwarf2_read_abbrevs (cu
, abbrev_section
);
4235 /* Read the top level CU/TU die. */
4236 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4237 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4239 /* If we have a DWO stub, process it and then read in the DWO file.
4240 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4241 a DWO CU, that this test will fail. */
4242 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4245 char *dwo_name
= DW_STRING (attr
);
4246 const char *comp_dir_string
;
4247 struct dwo_unit
*dwo_unit
;
4248 ULONGEST signature
; /* Or dwo_id. */
4249 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4250 int i
,num_extra_attrs
;
4251 struct dwarf2_section_info
*dwo_abbrev_section
;
4254 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4255 " has children (offset 0x%x) [in module %s]"),
4256 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4258 /* These attributes aren't processed until later:
4259 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4260 However, the attribute is found in the stub which we won't have later.
4261 In order to not impose this complication on the rest of the code,
4262 we read them here and copy them to the DWO CU/TU die. */
4264 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4267 if (! this_cu
->is_debug_types
)
4268 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4269 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4270 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4271 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4272 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4274 /* There should be a DW_AT_addr_base attribute here (if needed).
4275 We need the value before we can process DW_FORM_GNU_addr_index. */
4277 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4279 cu
->addr_base
= DW_UNSND (attr
);
4281 /* There should be a DW_AT_ranges_base attribute here (if needed).
4282 We need the value before we can process DW_AT_ranges. */
4283 cu
->ranges_base
= 0;
4284 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4286 cu
->ranges_base
= DW_UNSND (attr
);
4288 if (this_cu
->is_debug_types
)
4290 gdb_assert (sig_type
!= NULL
);
4291 signature
= sig_type
->signature
;
4295 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4297 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4299 signature
= DW_UNSND (attr
);
4302 /* We may need the comp_dir in order to find the DWO file. */
4303 comp_dir_string
= NULL
;
4305 comp_dir_string
= DW_STRING (comp_dir
);
4307 if (this_cu
->is_debug_types
)
4308 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4310 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4313 if (dwo_unit
== NULL
)
4315 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4316 " with ID %s [in module %s]"),
4317 this_cu
->offset
.sect_off
,
4318 phex (signature
, sizeof (signature
)),
4322 /* Set up for reading the DWO CU/TU. */
4323 cu
->dwo_unit
= dwo_unit
;
4324 section
= dwo_unit
->info_or_types_section
;
4325 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4326 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4327 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4329 if (this_cu
->is_debug_types
)
4333 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4337 gdb_assert (sig_type
->signature
== signature
);
4338 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4339 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4341 /* Establish the type offset that can be used to lookup the type.
4342 For DWO files, we don't know it until now. */
4343 sig_type
->type_offset_in_section
.sect_off
=
4344 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4348 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4351 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4352 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4355 /* Discard the original CU's abbrev table, and read the DWO's. */
4356 if (abbrev_table
== NULL
)
4358 dwarf2_free_abbrev_table (cu
);
4359 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4363 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4364 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4367 /* Read in the die, but leave space to copy over the attributes
4368 from the stub. This has the benefit of simplifying the rest of
4369 the code - all the real work is done here. */
4370 num_extra_attrs
= ((stmt_list
!= NULL
)
4374 + (comp_dir
!= NULL
));
4375 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4376 &has_children
, num_extra_attrs
);
4378 /* Copy over the attributes from the stub to the DWO die. */
4379 i
= comp_unit_die
->num_attrs
;
4380 if (stmt_list
!= NULL
)
4381 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4383 comp_unit_die
->attrs
[i
++] = *low_pc
;
4384 if (high_pc
!= NULL
)
4385 comp_unit_die
->attrs
[i
++] = *high_pc
;
4387 comp_unit_die
->attrs
[i
++] = *ranges
;
4388 if (comp_dir
!= NULL
)
4389 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4390 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4392 /* Skip dummy compilation units. */
4393 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4394 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4396 do_cleanups (cleanups
);
4401 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4403 if (free_cu_cleanup
!= NULL
)
4407 /* We've successfully allocated this compilation unit. Let our
4408 caller clean it up when finished with it. */
4409 discard_cleanups (free_cu_cleanup
);
4411 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4412 So we have to manually free the abbrev table. */
4413 dwarf2_free_abbrev_table (cu
);
4415 /* Link this CU into read_in_chain. */
4416 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4417 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4420 do_cleanups (free_cu_cleanup
);
4423 do_cleanups (cleanups
);
4426 /* Read CU/TU THIS_CU in section SECTION,
4427 but do not follow DW_AT_GNU_dwo_name if present.
4428 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4429 have already done the lookup to find the DWO file).
4431 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4432 THIS_CU->is_debug_types, but nothing else.
4434 We fill in THIS_CU->length.
4436 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4437 linker) then DIE_READER_FUNC will not get called.
4439 THIS_CU->cu is always freed when done.
4440 This is done in order to not leave THIS_CU->cu in a state where we have
4441 to care whether it refers to the "main" CU or the DWO CU. */
4444 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4445 struct dwarf2_section_info
*abbrev_section
,
4446 struct dwo_file
*dwo_file
,
4447 die_reader_func_ftype
*die_reader_func
,
4450 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4451 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4452 bfd
*abfd
= section
->asection
->owner
;
4453 struct dwarf2_cu cu
;
4454 gdb_byte
*begin_info_ptr
, *info_ptr
;
4455 struct die_reader_specs reader
;
4456 struct cleanup
*cleanups
;
4457 struct die_info
*comp_unit_die
;
4460 if (dwarf2_die_debug
)
4461 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4462 this_cu
->is_debug_types
? "type" : "comp",
4463 this_cu
->offset
.sect_off
);
4465 gdb_assert (this_cu
->cu
== NULL
);
4467 /* This is cheap if the section is already read in. */
4468 dwarf2_read_section (objfile
, section
);
4470 init_one_comp_unit (&cu
, this_cu
);
4472 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4474 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4475 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4476 abbrev_section
, info_ptr
,
4477 this_cu
->is_debug_types
);
4479 this_cu
->length
= get_cu_length (&cu
.header
);
4481 /* Skip dummy compilation units. */
4482 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4483 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4485 do_cleanups (cleanups
);
4489 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4490 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4492 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4493 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4495 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4497 do_cleanups (cleanups
);
4500 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4501 does not lookup the specified DWO file.
4502 This cannot be used to read DWO files.
4504 THIS_CU->cu is always freed when done.
4505 This is done in order to not leave THIS_CU->cu in a state where we have
4506 to care whether it refers to the "main" CU or the DWO CU.
4507 We can revisit this if the data shows there's a performance issue. */
4510 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4511 die_reader_func_ftype
*die_reader_func
,
4514 init_cutu_and_read_dies_no_follow (this_cu
,
4515 &dwarf2_per_objfile
->abbrev
,
4517 die_reader_func
, data
);
4520 /* Create a psymtab named NAME and assign it to PER_CU.
4522 The caller must fill in the following details:
4523 dirname, textlow, texthigh. */
4525 static struct partial_symtab
*
4526 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4528 struct objfile
*objfile
= per_cu
->objfile
;
4529 struct partial_symtab
*pst
;
4531 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4533 objfile
->global_psymbols
.next
,
4534 objfile
->static_psymbols
.next
);
4536 pst
->psymtabs_addrmap_supported
= 1;
4538 /* This is the glue that links PST into GDB's symbol API. */
4539 pst
->read_symtab_private
= per_cu
;
4540 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4541 per_cu
->v
.psymtab
= pst
;
4546 /* die_reader_func for process_psymtab_comp_unit. */
4549 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4551 struct die_info
*comp_unit_die
,
4555 struct dwarf2_cu
*cu
= reader
->cu
;
4556 struct objfile
*objfile
= cu
->objfile
;
4557 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4558 struct attribute
*attr
;
4560 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4561 struct partial_symtab
*pst
;
4563 const char *filename
;
4564 int *want_partial_unit_ptr
= data
;
4566 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4567 && (want_partial_unit_ptr
== NULL
4568 || !*want_partial_unit_ptr
))
4571 gdb_assert (! per_cu
->is_debug_types
);
4573 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4575 cu
->list_in_scope
= &file_symbols
;
4577 /* Allocate a new partial symbol table structure. */
4578 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4579 if (attr
== NULL
|| !DW_STRING (attr
))
4582 filename
= DW_STRING (attr
);
4584 pst
= create_partial_symtab (per_cu
, filename
);
4586 /* This must be done before calling dwarf2_build_include_psymtabs. */
4587 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4589 pst
->dirname
= DW_STRING (attr
);
4591 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4593 dwarf2_find_base_address (comp_unit_die
, cu
);
4595 /* Possibly set the default values of LOWPC and HIGHPC from
4597 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4598 &best_highpc
, cu
, pst
);
4599 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4600 /* Store the contiguous range if it is not empty; it can be empty for
4601 CUs with no code. */
4602 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4603 best_lowpc
+ baseaddr
,
4604 best_highpc
+ baseaddr
- 1, pst
);
4606 /* Check if comp unit has_children.
4607 If so, read the rest of the partial symbols from this comp unit.
4608 If not, there's no more debug_info for this comp unit. */
4611 struct partial_die_info
*first_die
;
4612 CORE_ADDR lowpc
, highpc
;
4614 lowpc
= ((CORE_ADDR
) -1);
4615 highpc
= ((CORE_ADDR
) 0);
4617 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4619 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4622 /* If we didn't find a lowpc, set it to highpc to avoid
4623 complaints from `maint check'. */
4624 if (lowpc
== ((CORE_ADDR
) -1))
4627 /* If the compilation unit didn't have an explicit address range,
4628 then use the information extracted from its child dies. */
4632 best_highpc
= highpc
;
4635 pst
->textlow
= best_lowpc
+ baseaddr
;
4636 pst
->texthigh
= best_highpc
+ baseaddr
;
4638 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4639 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4640 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4641 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4642 sort_pst_symbols (pst
);
4644 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4647 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4648 struct dwarf2_per_cu_data
*iter
;
4650 /* Fill in 'dependencies' here; we fill in 'users' in a
4652 pst
->number_of_dependencies
= len
;
4653 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4654 len
* sizeof (struct symtab
*));
4656 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4659 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4661 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4664 /* Get the list of files included in the current compilation unit,
4665 and build a psymtab for each of them. */
4666 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4668 if (dwarf2_read_debug
)
4670 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4672 fprintf_unfiltered (gdb_stdlog
,
4673 "Psymtab for %s unit @0x%x: 0x%s - 0x%s"
4674 ", %d global, %d static syms\n",
4675 per_cu
->is_debug_types
? "type" : "comp",
4676 per_cu
->offset
.sect_off
,
4677 paddress (gdbarch
, pst
->textlow
),
4678 paddress (gdbarch
, pst
->texthigh
),
4679 pst
->n_global_syms
, pst
->n_static_syms
);
4683 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4684 Process compilation unit THIS_CU for a psymtab. */
4687 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4688 int want_partial_unit
)
4690 /* If this compilation unit was already read in, free the
4691 cached copy in order to read it in again. This is
4692 necessary because we skipped some symbols when we first
4693 read in the compilation unit (see load_partial_dies).
4694 This problem could be avoided, but the benefit is unclear. */
4695 if (this_cu
->cu
!= NULL
)
4696 free_one_cached_comp_unit (this_cu
);
4698 gdb_assert (! this_cu
->is_debug_types
);
4699 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4700 process_psymtab_comp_unit_reader
,
4701 &want_partial_unit
);
4703 /* Age out any secondary CUs. */
4704 age_cached_comp_units ();
4708 hash_type_unit_group (const void *item
)
4710 const struct type_unit_group
*symtab
= item
;
4712 return symtab
->line_offset
.sect_off
;
4716 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4718 const struct type_unit_group
*lhs
= item_lhs
;
4719 const struct type_unit_group
*rhs
= item_rhs
;
4721 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
4724 /* Allocate a hash table for type unit groups. */
4727 allocate_type_unit_groups_table (void)
4729 return htab_create_alloc_ex (3,
4730 hash_type_unit_group
,
4733 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
4734 hashtab_obstack_allocate
,
4735 dummy_obstack_deallocate
);
4738 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4739 partial symtabs. We combine several TUs per psymtab to not let the size
4740 of any one psymtab grow too big. */
4741 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4742 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4744 /* Helper routine for build_type_psymtabs_reader.
4745 Create the type_unit_group object used to hold one or more TUs. */
4747 static struct type_unit_group
*
4748 create_type_unit_group (struct dwarf2_per_cu_data
*per_cu
,
4749 sect_offset line_offset_struct
)
4751 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4752 struct type_unit_group
*tu_group
;
4753 struct partial_symtab
*pst
;
4754 unsigned int line_offset
;
4757 line_offset
= line_offset_struct
.sect_off
;
4759 /* Give the symtab a useful name for debug purposes. */
4760 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
4761 name
= xstrprintf ("<type_units_%d>",
4762 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
4764 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
4766 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4767 struct type_unit_group
);
4769 per_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4770 struct dwarf2_per_cu_data
);
4771 per_cu
->objfile
= objfile
;
4772 per_cu
->is_debug_types
= 1;
4773 per_cu
->s
.type_unit_group
= tu_group
;
4775 pst
= create_partial_symtab (per_cu
, name
);
4780 tu_group
->per_cu
= per_cu
;
4781 tu_group
->line_offset
.sect_off
= line_offset
;
4786 /* Look up the type_unit_group for PER_CU, and create it if necessary.
4787 STMT_LIST is an DW_AT_stmt_list attribute. */
4789 static struct type_unit_group
*
4790 get_type_unit_group (struct dwarf2_per_cu_data
*per_cu
,
4791 struct attribute
*stmt_list
)
4793 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4794 struct type_unit_group
*tu_group
;
4796 unsigned int line_offset
;
4797 struct type_unit_group type_unit_group_for_lookup
;
4799 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
4801 dwarf2_per_objfile
->type_unit_groups
=
4802 allocate_type_unit_groups_table ();
4805 /* Do we need to create a new group, or can we use an existing one? */
4809 line_offset
= DW_UNSND (stmt_list
);
4810 ++tu_stats
->nr_symtab_sharers
;
4814 /* Ugh, no stmt_list. Rare, but we have to handle it.
4815 We can do various things here like create one group per TU or
4816 spread them over multiple groups to split up the expansion work.
4817 To avoid worst case scenarios (too many groups or too large groups)
4818 we, umm, group them in bunches. */
4819 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
4820 | (tu_stats
->nr_stmt_less_type_units
4821 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
4822 ++tu_stats
->nr_stmt_less_type_units
;
4825 type_unit_group_for_lookup
.line_offset
.sect_off
= line_offset
;
4826 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
4827 &type_unit_group_for_lookup
, INSERT
);
4831 gdb_assert (tu_group
!= NULL
);
4835 sect_offset line_offset_struct
;
4837 line_offset_struct
.sect_off
= line_offset
;
4838 tu_group
= create_type_unit_group (per_cu
, line_offset_struct
);
4840 ++tu_stats
->nr_symtabs
;
4846 /* Struct used to sort TUs by their abbreviation table offset. */
4848 struct tu_abbrev_offset
4850 struct signatured_type
*sig_type
;
4851 sect_offset abbrev_offset
;
4854 /* Helper routine for build_type_unit_groups, passed to qsort. */
4857 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
4859 const struct tu_abbrev_offset
* const *a
= ap
;
4860 const struct tu_abbrev_offset
* const *b
= bp
;
4861 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
4862 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
4864 return (aoff
> boff
) - (aoff
< boff
);
4867 /* A helper function to add a type_unit_group to a table. */
4870 add_type_unit_group_to_table (void **slot
, void *datum
)
4872 struct type_unit_group
*tu_group
= *slot
;
4873 struct type_unit_group
***datap
= datum
;
4881 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
4882 each one passing FUNC,DATA.
4884 The efficiency is because we sort TUs by the abbrev table they use and
4885 only read each abbrev table once. In one program there are 200K TUs
4886 sharing 8K abbrev tables.
4888 The main purpose of this function is to support building the
4889 dwarf2_per_objfile->type_unit_groups table.
4890 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
4891 can collapse the search space by grouping them by stmt_list.
4892 The savings can be significant, in the same program from above the 200K TUs
4893 share 8K stmt_list tables.
4895 FUNC is expected to call get_type_unit_group, which will create the
4896 struct type_unit_group if necessary and add it to
4897 dwarf2_per_objfile->type_unit_groups. */
4900 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
4902 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4903 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4904 struct cleanup
*cleanups
;
4905 struct abbrev_table
*abbrev_table
;
4906 sect_offset abbrev_offset
;
4907 struct tu_abbrev_offset
*sorted_by_abbrev
;
4908 struct type_unit_group
**iter
;
4911 /* It's up to the caller to not call us multiple times. */
4912 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
4914 if (dwarf2_per_objfile
->n_type_units
== 0)
4917 /* TUs typically share abbrev tables, and there can be way more TUs than
4918 abbrev tables. Sort by abbrev table to reduce the number of times we
4919 read each abbrev table in.
4920 Alternatives are to punt or to maintain a cache of abbrev tables.
4921 This is simpler and efficient enough for now.
4923 Later we group TUs by their DW_AT_stmt_list value (as this defines the
4924 symtab to use). Typically TUs with the same abbrev offset have the same
4925 stmt_list value too so in practice this should work well.
4927 The basic algorithm here is:
4929 sort TUs by abbrev table
4930 for each TU with same abbrev table:
4931 read abbrev table if first user
4932 read TU top level DIE
4933 [IWBN if DWO skeletons had DW_AT_stmt_list]
4936 if (dwarf2_read_debug
)
4937 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
4939 /* Sort in a separate table to maintain the order of all_type_units
4940 for .gdb_index: TU indices directly index all_type_units. */
4941 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
4942 dwarf2_per_objfile
->n_type_units
);
4943 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
4945 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
4947 sorted_by_abbrev
[i
].sig_type
= sig_type
;
4948 sorted_by_abbrev
[i
].abbrev_offset
=
4949 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
4950 sig_type
->per_cu
.offset
);
4952 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
4953 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
4954 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
4956 memset (tu_stats
, 0, sizeof (*tu_stats
));
4957 abbrev_offset
.sect_off
= ~(unsigned) 0;
4958 abbrev_table
= NULL
;
4959 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
4961 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
4963 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
4965 /* Switch to the next abbrev table if necessary. */
4966 if (abbrev_table
== NULL
4967 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
4969 if (abbrev_table
!= NULL
)
4971 abbrev_table_free (abbrev_table
);
4972 /* Reset to NULL in case abbrev_table_read_table throws
4973 an error: abbrev_table_free_cleanup will get called. */
4974 abbrev_table
= NULL
;
4976 abbrev_offset
= tu
->abbrev_offset
;
4978 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
4980 ++tu_stats
->nr_uniq_abbrev_tables
;
4983 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
4987 /* Create a vector of pointers to primary type units to make it easy to
4988 iterate over them and CUs. See dw2_get_primary_cu. */
4989 dwarf2_per_objfile
->n_type_unit_groups
=
4990 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
4991 dwarf2_per_objfile
->all_type_unit_groups
=
4992 obstack_alloc (&objfile
->objfile_obstack
,
4993 dwarf2_per_objfile
->n_type_unit_groups
4994 * sizeof (struct type_unit_group
*));
4995 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
4996 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
4997 add_type_unit_group_to_table
, &iter
);
4998 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
4999 == dwarf2_per_objfile
->n_type_unit_groups
);
5001 do_cleanups (cleanups
);
5003 if (dwarf2_read_debug
)
5005 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5006 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5007 dwarf2_per_objfile
->n_type_units
);
5008 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5009 tu_stats
->nr_uniq_abbrev_tables
);
5010 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5011 tu_stats
->nr_symtabs
);
5012 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5013 tu_stats
->nr_symtab_sharers
);
5014 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5015 tu_stats
->nr_stmt_less_type_units
);
5019 /* Reader function for build_type_psymtabs. */
5022 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5024 struct die_info
*type_unit_die
,
5028 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5029 struct dwarf2_cu
*cu
= reader
->cu
;
5030 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5031 struct type_unit_group
*tu_group
;
5032 struct attribute
*attr
;
5033 struct partial_die_info
*first_die
;
5034 CORE_ADDR lowpc
, highpc
;
5035 struct partial_symtab
*pst
;
5037 gdb_assert (data
== NULL
);
5042 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5043 tu_group
= get_type_unit_group (per_cu
, attr
);
5045 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->tus
, per_cu
);
5047 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5048 cu
->list_in_scope
= &file_symbols
;
5049 pst
= create_partial_symtab (per_cu
, "");
5052 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5054 lowpc
= (CORE_ADDR
) -1;
5055 highpc
= (CORE_ADDR
) 0;
5056 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5058 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5059 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5060 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5061 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5062 sort_pst_symbols (pst
);
5065 /* Traversal function for build_type_psymtabs. */
5068 build_type_psymtab_dependencies (void **slot
, void *info
)
5070 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5071 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5072 struct dwarf2_per_cu_data
*per_cu
= tu_group
->per_cu
;
5073 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5074 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->tus
);
5075 struct dwarf2_per_cu_data
*iter
;
5078 gdb_assert (len
> 0);
5080 pst
->number_of_dependencies
= len
;
5081 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5082 len
* sizeof (struct psymtab
*));
5084 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->tus
, i
, iter
);
5087 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5088 iter
->s
.type_unit_group
= tu_group
;
5091 VEC_free (dwarf2_per_cu_ptr
, tu_group
->tus
);
5096 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5097 Build partial symbol tables for the .debug_types comp-units. */
5100 build_type_psymtabs (struct objfile
*objfile
)
5102 if (! create_all_type_units (objfile
))
5105 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5107 /* Now that all TUs have been processed we can fill in the dependencies. */
5108 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5109 build_type_psymtab_dependencies
, NULL
);
5112 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5115 psymtabs_addrmap_cleanup (void *o
)
5117 struct objfile
*objfile
= o
;
5119 objfile
->psymtabs_addrmap
= NULL
;
5122 /* Compute the 'user' field for each psymtab in OBJFILE. */
5125 set_partial_user (struct objfile
*objfile
)
5129 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5131 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5132 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5135 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5137 /* Set the 'user' field only if it is not already set. */
5138 if (pst
->dependencies
[j
]->user
== NULL
)
5139 pst
->dependencies
[j
]->user
= pst
;
5144 /* Build the partial symbol table by doing a quick pass through the
5145 .debug_info and .debug_abbrev sections. */
5148 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5150 struct cleanup
*back_to
, *addrmap_cleanup
;
5151 struct obstack temp_obstack
;
5154 if (dwarf2_read_debug
)
5156 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5160 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5162 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5164 /* Any cached compilation units will be linked by the per-objfile
5165 read_in_chain. Make sure to free them when we're done. */
5166 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5168 build_type_psymtabs (objfile
);
5170 create_all_comp_units (objfile
);
5172 /* Create a temporary address map on a temporary obstack. We later
5173 copy this to the final obstack. */
5174 obstack_init (&temp_obstack
);
5175 make_cleanup_obstack_free (&temp_obstack
);
5176 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5177 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5179 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5181 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5183 process_psymtab_comp_unit (per_cu
, 0);
5186 set_partial_user (objfile
);
5188 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5189 &objfile
->objfile_obstack
);
5190 discard_cleanups (addrmap_cleanup
);
5192 do_cleanups (back_to
);
5194 if (dwarf2_read_debug
)
5195 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5199 /* die_reader_func for load_partial_comp_unit. */
5202 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5204 struct die_info
*comp_unit_die
,
5208 struct dwarf2_cu
*cu
= reader
->cu
;
5210 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5212 /* Check if comp unit has_children.
5213 If so, read the rest of the partial symbols from this comp unit.
5214 If not, there's no more debug_info for this comp unit. */
5216 load_partial_dies (reader
, info_ptr
, 0);
5219 /* Load the partial DIEs for a secondary CU into memory.
5220 This is also used when rereading a primary CU with load_all_dies. */
5223 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5225 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5226 load_partial_comp_unit_reader
, NULL
);
5229 /* Create a list of all compilation units in OBJFILE.
5230 This is only done for -readnow and building partial symtabs. */
5233 create_all_comp_units (struct objfile
*objfile
)
5237 struct dwarf2_per_cu_data
**all_comp_units
;
5240 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5241 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
5245 all_comp_units
= xmalloc (n_allocated
5246 * sizeof (struct dwarf2_per_cu_data
*));
5248 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
5249 + dwarf2_per_objfile
->info
.size
)
5251 unsigned int length
, initial_length_size
;
5252 struct dwarf2_per_cu_data
*this_cu
;
5255 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
5257 /* Read just enough information to find out where the next
5258 compilation unit is. */
5259 length
= read_initial_length (objfile
->obfd
, info_ptr
,
5260 &initial_length_size
);
5262 /* Save the compilation unit for later lookup. */
5263 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5264 sizeof (struct dwarf2_per_cu_data
));
5265 memset (this_cu
, 0, sizeof (*this_cu
));
5266 this_cu
->offset
= offset
;
5267 this_cu
->length
= length
+ initial_length_size
;
5268 this_cu
->objfile
= objfile
;
5269 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
5271 if (n_comp_units
== n_allocated
)
5274 all_comp_units
= xrealloc (all_comp_units
,
5276 * sizeof (struct dwarf2_per_cu_data
*));
5278 all_comp_units
[n_comp_units
++] = this_cu
;
5280 info_ptr
= info_ptr
+ this_cu
->length
;
5283 dwarf2_per_objfile
->all_comp_units
5284 = obstack_alloc (&objfile
->objfile_obstack
,
5285 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5286 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5287 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5288 xfree (all_comp_units
);
5289 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5292 /* Process all loaded DIEs for compilation unit CU, starting at
5293 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5294 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5295 DW_AT_ranges). If NEED_PC is set, then this function will set
5296 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5297 and record the covered ranges in the addrmap. */
5300 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5301 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5303 struct partial_die_info
*pdi
;
5305 /* Now, march along the PDI's, descending into ones which have
5306 interesting children but skipping the children of the other ones,
5307 until we reach the end of the compilation unit. */
5313 fixup_partial_die (pdi
, cu
);
5315 /* Anonymous namespaces or modules have no name but have interesting
5316 children, so we need to look at them. Ditto for anonymous
5319 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5320 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5321 || pdi
->tag
== DW_TAG_imported_unit
)
5325 case DW_TAG_subprogram
:
5326 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5328 case DW_TAG_constant
:
5329 case DW_TAG_variable
:
5330 case DW_TAG_typedef
:
5331 case DW_TAG_union_type
:
5332 if (!pdi
->is_declaration
)
5334 add_partial_symbol (pdi
, cu
);
5337 case DW_TAG_class_type
:
5338 case DW_TAG_interface_type
:
5339 case DW_TAG_structure_type
:
5340 if (!pdi
->is_declaration
)
5342 add_partial_symbol (pdi
, cu
);
5345 case DW_TAG_enumeration_type
:
5346 if (!pdi
->is_declaration
)
5347 add_partial_enumeration (pdi
, cu
);
5349 case DW_TAG_base_type
:
5350 case DW_TAG_subrange_type
:
5351 /* File scope base type definitions are added to the partial
5353 add_partial_symbol (pdi
, cu
);
5355 case DW_TAG_namespace
:
5356 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5359 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5361 case DW_TAG_imported_unit
:
5363 struct dwarf2_per_cu_data
*per_cu
;
5365 /* For now we don't handle imported units in type units. */
5366 if (cu
->per_cu
->is_debug_types
)
5368 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5369 " supported in type units [in module %s]"),
5373 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5376 /* Go read the partial unit, if needed. */
5377 if (per_cu
->v
.psymtab
== NULL
)
5378 process_psymtab_comp_unit (per_cu
, 1);
5380 VEC_safe_push (dwarf2_per_cu_ptr
,
5381 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5389 /* If the die has a sibling, skip to the sibling. */
5391 pdi
= pdi
->die_sibling
;
5395 /* Functions used to compute the fully scoped name of a partial DIE.
5397 Normally, this is simple. For C++, the parent DIE's fully scoped
5398 name is concatenated with "::" and the partial DIE's name. For
5399 Java, the same thing occurs except that "." is used instead of "::".
5400 Enumerators are an exception; they use the scope of their parent
5401 enumeration type, i.e. the name of the enumeration type is not
5402 prepended to the enumerator.
5404 There are two complexities. One is DW_AT_specification; in this
5405 case "parent" means the parent of the target of the specification,
5406 instead of the direct parent of the DIE. The other is compilers
5407 which do not emit DW_TAG_namespace; in this case we try to guess
5408 the fully qualified name of structure types from their members'
5409 linkage names. This must be done using the DIE's children rather
5410 than the children of any DW_AT_specification target. We only need
5411 to do this for structures at the top level, i.e. if the target of
5412 any DW_AT_specification (if any; otherwise the DIE itself) does not
5415 /* Compute the scope prefix associated with PDI's parent, in
5416 compilation unit CU. The result will be allocated on CU's
5417 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5418 field. NULL is returned if no prefix is necessary. */
5420 partial_die_parent_scope (struct partial_die_info
*pdi
,
5421 struct dwarf2_cu
*cu
)
5423 char *grandparent_scope
;
5424 struct partial_die_info
*parent
, *real_pdi
;
5426 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5427 then this means the parent of the specification DIE. */
5430 while (real_pdi
->has_specification
)
5431 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
5433 parent
= real_pdi
->die_parent
;
5437 if (parent
->scope_set
)
5438 return parent
->scope
;
5440 fixup_partial_die (parent
, cu
);
5442 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5444 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5445 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5446 Work around this problem here. */
5447 if (cu
->language
== language_cplus
5448 && parent
->tag
== DW_TAG_namespace
5449 && strcmp (parent
->name
, "::") == 0
5450 && grandparent_scope
== NULL
)
5452 parent
->scope
= NULL
;
5453 parent
->scope_set
= 1;
5457 if (pdi
->tag
== DW_TAG_enumerator
)
5458 /* Enumerators should not get the name of the enumeration as a prefix. */
5459 parent
->scope
= grandparent_scope
;
5460 else if (parent
->tag
== DW_TAG_namespace
5461 || parent
->tag
== DW_TAG_module
5462 || parent
->tag
== DW_TAG_structure_type
5463 || parent
->tag
== DW_TAG_class_type
5464 || parent
->tag
== DW_TAG_interface_type
5465 || parent
->tag
== DW_TAG_union_type
5466 || parent
->tag
== DW_TAG_enumeration_type
)
5468 if (grandparent_scope
== NULL
)
5469 parent
->scope
= parent
->name
;
5471 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5473 parent
->name
, 0, cu
);
5477 /* FIXME drow/2004-04-01: What should we be doing with
5478 function-local names? For partial symbols, we should probably be
5480 complaint (&symfile_complaints
,
5481 _("unhandled containing DIE tag %d for DIE at %d"),
5482 parent
->tag
, pdi
->offset
.sect_off
);
5483 parent
->scope
= grandparent_scope
;
5486 parent
->scope_set
= 1;
5487 return parent
->scope
;
5490 /* Return the fully scoped name associated with PDI, from compilation unit
5491 CU. The result will be allocated with malloc. */
5494 partial_die_full_name (struct partial_die_info
*pdi
,
5495 struct dwarf2_cu
*cu
)
5499 /* If this is a template instantiation, we can not work out the
5500 template arguments from partial DIEs. So, unfortunately, we have
5501 to go through the full DIEs. At least any work we do building
5502 types here will be reused if full symbols are loaded later. */
5503 if (pdi
->has_template_arguments
)
5505 fixup_partial_die (pdi
, cu
);
5507 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5509 struct die_info
*die
;
5510 struct attribute attr
;
5511 struct dwarf2_cu
*ref_cu
= cu
;
5513 /* DW_FORM_ref_addr is using section offset. */
5515 attr
.form
= DW_FORM_ref_addr
;
5516 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5517 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5519 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5523 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5524 if (parent_scope
== NULL
)
5527 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5531 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5533 struct objfile
*objfile
= cu
->objfile
;
5535 char *actual_name
= NULL
;
5537 int built_actual_name
= 0;
5539 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5541 actual_name
= partial_die_full_name (pdi
, cu
);
5543 built_actual_name
= 1;
5545 if (actual_name
== NULL
)
5546 actual_name
= pdi
->name
;
5550 case DW_TAG_subprogram
:
5551 if (pdi
->is_external
|| cu
->language
== language_ada
)
5553 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5554 of the global scope. But in Ada, we want to be able to access
5555 nested procedures globally. So all Ada subprograms are stored
5556 in the global scope. */
5557 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5558 mst_text, objfile); */
5559 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5561 VAR_DOMAIN
, LOC_BLOCK
,
5562 &objfile
->global_psymbols
,
5563 0, pdi
->lowpc
+ baseaddr
,
5564 cu
->language
, objfile
);
5568 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5569 mst_file_text, objfile); */
5570 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5572 VAR_DOMAIN
, LOC_BLOCK
,
5573 &objfile
->static_psymbols
,
5574 0, pdi
->lowpc
+ baseaddr
,
5575 cu
->language
, objfile
);
5578 case DW_TAG_constant
:
5580 struct psymbol_allocation_list
*list
;
5582 if (pdi
->is_external
)
5583 list
= &objfile
->global_psymbols
;
5585 list
= &objfile
->static_psymbols
;
5586 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5587 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5588 list
, 0, 0, cu
->language
, objfile
);
5591 case DW_TAG_variable
:
5593 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5597 && !dwarf2_per_objfile
->has_section_at_zero
)
5599 /* A global or static variable may also have been stripped
5600 out by the linker if unused, in which case its address
5601 will be nullified; do not add such variables into partial
5602 symbol table then. */
5604 else if (pdi
->is_external
)
5607 Don't enter into the minimal symbol tables as there is
5608 a minimal symbol table entry from the ELF symbols already.
5609 Enter into partial symbol table if it has a location
5610 descriptor or a type.
5611 If the location descriptor is missing, new_symbol will create
5612 a LOC_UNRESOLVED symbol, the address of the variable will then
5613 be determined from the minimal symbol table whenever the variable
5615 The address for the partial symbol table entry is not
5616 used by GDB, but it comes in handy for debugging partial symbol
5619 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5620 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5622 VAR_DOMAIN
, LOC_STATIC
,
5623 &objfile
->global_psymbols
,
5625 cu
->language
, objfile
);
5629 /* Static Variable. Skip symbols without location descriptors. */
5630 if (pdi
->d
.locdesc
== NULL
)
5632 if (built_actual_name
)
5633 xfree (actual_name
);
5636 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5637 mst_file_data, objfile); */
5638 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5640 VAR_DOMAIN
, LOC_STATIC
,
5641 &objfile
->static_psymbols
,
5643 cu
->language
, objfile
);
5646 case DW_TAG_typedef
:
5647 case DW_TAG_base_type
:
5648 case DW_TAG_subrange_type
:
5649 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5651 VAR_DOMAIN
, LOC_TYPEDEF
,
5652 &objfile
->static_psymbols
,
5653 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5655 case DW_TAG_namespace
:
5656 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5658 VAR_DOMAIN
, LOC_TYPEDEF
,
5659 &objfile
->global_psymbols
,
5660 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5662 case DW_TAG_class_type
:
5663 case DW_TAG_interface_type
:
5664 case DW_TAG_structure_type
:
5665 case DW_TAG_union_type
:
5666 case DW_TAG_enumeration_type
:
5667 /* Skip external references. The DWARF standard says in the section
5668 about "Structure, Union, and Class Type Entries": "An incomplete
5669 structure, union or class type is represented by a structure,
5670 union or class entry that does not have a byte size attribute
5671 and that has a DW_AT_declaration attribute." */
5672 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5674 if (built_actual_name
)
5675 xfree (actual_name
);
5679 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5680 static vs. global. */
5681 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5683 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5684 (cu
->language
== language_cplus
5685 || cu
->language
== language_java
)
5686 ? &objfile
->global_psymbols
5687 : &objfile
->static_psymbols
,
5688 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5691 case DW_TAG_enumerator
:
5692 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5694 VAR_DOMAIN
, LOC_CONST
,
5695 (cu
->language
== language_cplus
5696 || cu
->language
== language_java
)
5697 ? &objfile
->global_psymbols
5698 : &objfile
->static_psymbols
,
5699 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5705 if (built_actual_name
)
5706 xfree (actual_name
);
5709 /* Read a partial die corresponding to a namespace; also, add a symbol
5710 corresponding to that namespace to the symbol table. NAMESPACE is
5711 the name of the enclosing namespace. */
5714 add_partial_namespace (struct partial_die_info
*pdi
,
5715 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5716 int need_pc
, struct dwarf2_cu
*cu
)
5718 /* Add a symbol for the namespace. */
5720 add_partial_symbol (pdi
, cu
);
5722 /* Now scan partial symbols in that namespace. */
5724 if (pdi
->has_children
)
5725 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5728 /* Read a partial die corresponding to a Fortran module. */
5731 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5732 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5734 /* Now scan partial symbols in that module. */
5736 if (pdi
->has_children
)
5737 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5740 /* Read a partial die corresponding to a subprogram and create a partial
5741 symbol for that subprogram. When the CU language allows it, this
5742 routine also defines a partial symbol for each nested subprogram
5743 that this subprogram contains.
5745 DIE my also be a lexical block, in which case we simply search
5746 recursively for suprograms defined inside that lexical block.
5747 Again, this is only performed when the CU language allows this
5748 type of definitions. */
5751 add_partial_subprogram (struct partial_die_info
*pdi
,
5752 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5753 int need_pc
, struct dwarf2_cu
*cu
)
5755 if (pdi
->tag
== DW_TAG_subprogram
)
5757 if (pdi
->has_pc_info
)
5759 if (pdi
->lowpc
< *lowpc
)
5760 *lowpc
= pdi
->lowpc
;
5761 if (pdi
->highpc
> *highpc
)
5762 *highpc
= pdi
->highpc
;
5766 struct objfile
*objfile
= cu
->objfile
;
5768 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5769 SECT_OFF_TEXT (objfile
));
5770 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5771 pdi
->lowpc
+ baseaddr
,
5772 pdi
->highpc
- 1 + baseaddr
,
5773 cu
->per_cu
->v
.psymtab
);
5777 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5779 if (!pdi
->is_declaration
)
5780 /* Ignore subprogram DIEs that do not have a name, they are
5781 illegal. Do not emit a complaint at this point, we will
5782 do so when we convert this psymtab into a symtab. */
5784 add_partial_symbol (pdi
, cu
);
5788 if (! pdi
->has_children
)
5791 if (cu
->language
== language_ada
)
5793 pdi
= pdi
->die_child
;
5796 fixup_partial_die (pdi
, cu
);
5797 if (pdi
->tag
== DW_TAG_subprogram
5798 || pdi
->tag
== DW_TAG_lexical_block
)
5799 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5800 pdi
= pdi
->die_sibling
;
5805 /* Read a partial die corresponding to an enumeration type. */
5808 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
5809 struct dwarf2_cu
*cu
)
5811 struct partial_die_info
*pdi
;
5813 if (enum_pdi
->name
!= NULL
)
5814 add_partial_symbol (enum_pdi
, cu
);
5816 pdi
= enum_pdi
->die_child
;
5819 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
5820 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5822 add_partial_symbol (pdi
, cu
);
5823 pdi
= pdi
->die_sibling
;
5827 /* Return the initial uleb128 in the die at INFO_PTR. */
5830 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
5832 unsigned int bytes_read
;
5834 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5837 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
5838 Return the corresponding abbrev, or NULL if the number is zero (indicating
5839 an empty DIE). In either case *BYTES_READ will be set to the length of
5840 the initial number. */
5842 static struct abbrev_info
*
5843 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
5844 struct dwarf2_cu
*cu
)
5846 bfd
*abfd
= cu
->objfile
->obfd
;
5847 unsigned int abbrev_number
;
5848 struct abbrev_info
*abbrev
;
5850 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5852 if (abbrev_number
== 0)
5855 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
5858 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
5859 abbrev_number
, bfd_get_filename (abfd
));
5865 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5866 Returns a pointer to the end of a series of DIEs, terminated by an empty
5867 DIE. Any children of the skipped DIEs will also be skipped. */
5870 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5872 struct dwarf2_cu
*cu
= reader
->cu
;
5873 struct abbrev_info
*abbrev
;
5874 unsigned int bytes_read
;
5878 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5880 return info_ptr
+ bytes_read
;
5882 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5886 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5887 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5888 abbrev corresponding to that skipped uleb128 should be passed in
5889 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5893 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5894 struct abbrev_info
*abbrev
)
5896 unsigned int bytes_read
;
5897 struct attribute attr
;
5898 bfd
*abfd
= reader
->abfd
;
5899 struct dwarf2_cu
*cu
= reader
->cu
;
5900 gdb_byte
*buffer
= reader
->buffer
;
5901 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5902 gdb_byte
*start_info_ptr
= info_ptr
;
5903 unsigned int form
, i
;
5905 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5907 /* The only abbrev we care about is DW_AT_sibling. */
5908 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5910 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5911 if (attr
.form
== DW_FORM_ref_addr
)
5912 complaint (&symfile_complaints
,
5913 _("ignoring absolute DW_AT_sibling"));
5915 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5918 /* If it isn't DW_AT_sibling, skip this attribute. */
5919 form
= abbrev
->attrs
[i
].form
;
5923 case DW_FORM_ref_addr
:
5924 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5925 and later it is offset sized. */
5926 if (cu
->header
.version
== 2)
5927 info_ptr
+= cu
->header
.addr_size
;
5929 info_ptr
+= cu
->header
.offset_size
;
5932 info_ptr
+= cu
->header
.addr_size
;
5939 case DW_FORM_flag_present
:
5951 case DW_FORM_ref_sig8
:
5954 case DW_FORM_string
:
5955 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5956 info_ptr
+= bytes_read
;
5958 case DW_FORM_sec_offset
:
5960 info_ptr
+= cu
->header
.offset_size
;
5962 case DW_FORM_exprloc
:
5964 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5965 info_ptr
+= bytes_read
;
5967 case DW_FORM_block1
:
5968 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5970 case DW_FORM_block2
:
5971 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5973 case DW_FORM_block4
:
5974 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5978 case DW_FORM_ref_udata
:
5979 case DW_FORM_GNU_addr_index
:
5980 case DW_FORM_GNU_str_index
:
5981 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
5983 case DW_FORM_indirect
:
5984 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5985 info_ptr
+= bytes_read
;
5986 /* We need to continue parsing from here, so just go back to
5988 goto skip_attribute
;
5991 error (_("Dwarf Error: Cannot handle %s "
5992 "in DWARF reader [in module %s]"),
5993 dwarf_form_name (form
),
5994 bfd_get_filename (abfd
));
5998 if (abbrev
->has_children
)
5999 return skip_children (reader
, info_ptr
);
6004 /* Locate ORIG_PDI's sibling.
6005 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6008 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6009 struct partial_die_info
*orig_pdi
,
6012 /* Do we know the sibling already? */
6014 if (orig_pdi
->sibling
)
6015 return orig_pdi
->sibling
;
6017 /* Are there any children to deal with? */
6019 if (!orig_pdi
->has_children
)
6022 /* Skip the children the long way. */
6024 return skip_children (reader
, info_ptr
);
6027 /* Expand this partial symbol table into a full symbol table. */
6030 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
6036 warning (_("bug: psymtab for %s is already read in."),
6043 printf_filtered (_("Reading in symbols for %s..."),
6045 gdb_flush (gdb_stdout
);
6048 /* Restore our global data. */
6049 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
6050 dwarf2_objfile_data_key
);
6052 /* If this psymtab is constructed from a debug-only objfile, the
6053 has_section_at_zero flag will not necessarily be correct. We
6054 can get the correct value for this flag by looking at the data
6055 associated with the (presumably stripped) associated objfile. */
6056 if (pst
->objfile
->separate_debug_objfile_backlink
)
6058 struct dwarf2_per_objfile
*dpo_backlink
6059 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6060 dwarf2_objfile_data_key
);
6062 dwarf2_per_objfile
->has_section_at_zero
6063 = dpo_backlink
->has_section_at_zero
;
6066 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6068 psymtab_to_symtab_1 (pst
);
6070 /* Finish up the debug error message. */
6072 printf_filtered (_("done.\n"));
6076 process_cu_includes ();
6079 /* Reading in full CUs. */
6081 /* Add PER_CU to the queue. */
6084 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6085 enum language pretend_language
)
6087 struct dwarf2_queue_item
*item
;
6090 item
= xmalloc (sizeof (*item
));
6091 item
->per_cu
= per_cu
;
6092 item
->pretend_language
= pretend_language
;
6095 if (dwarf2_queue
== NULL
)
6096 dwarf2_queue
= item
;
6098 dwarf2_queue_tail
->next
= item
;
6100 dwarf2_queue_tail
= item
;
6103 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6104 unit and add it to our queue.
6105 The result is non-zero if PER_CU was queued, otherwise the result is zero
6106 meaning either PER_CU is already queued or it is already loaded. */
6109 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6110 struct dwarf2_per_cu_data
*per_cu
,
6111 enum language pretend_language
)
6113 /* We may arrive here during partial symbol reading, if we need full
6114 DIEs to process an unusual case (e.g. template arguments). Do
6115 not queue PER_CU, just tell our caller to load its DIEs. */
6116 if (dwarf2_per_objfile
->reading_partial_symbols
)
6118 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6123 /* Mark the dependence relation so that we don't flush PER_CU
6125 dwarf2_add_dependence (this_cu
, per_cu
);
6127 /* If it's already on the queue, we have nothing to do. */
6131 /* If the compilation unit is already loaded, just mark it as
6133 if (per_cu
->cu
!= NULL
)
6135 per_cu
->cu
->last_used
= 0;
6139 /* Add it to the queue. */
6140 queue_comp_unit (per_cu
, pretend_language
);
6145 /* Process the queue. */
6148 process_queue (void)
6150 struct dwarf2_queue_item
*item
, *next_item
;
6152 if (dwarf2_read_debug
)
6154 fprintf_unfiltered (gdb_stdlog
,
6155 "Expanding one or more symtabs of objfile %s ...\n",
6156 dwarf2_per_objfile
->objfile
->name
);
6159 /* The queue starts out with one item, but following a DIE reference
6160 may load a new CU, adding it to the end of the queue. */
6161 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6163 if (dwarf2_per_objfile
->using_index
6164 ? !item
->per_cu
->v
.quick
->symtab
6165 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6167 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6169 if (dwarf2_read_debug
)
6171 fprintf_unfiltered (gdb_stdlog
,
6172 "Expanding symtab of %s at offset 0x%x\n",
6173 per_cu
->is_debug_types
? "TU" : "CU",
6174 per_cu
->offset
.sect_off
);
6177 if (per_cu
->is_debug_types
)
6178 process_full_type_unit (per_cu
, item
->pretend_language
);
6180 process_full_comp_unit (per_cu
, item
->pretend_language
);
6182 if (dwarf2_read_debug
)
6184 fprintf_unfiltered (gdb_stdlog
,
6185 "Done expanding %s at offset 0x%x\n",
6186 per_cu
->is_debug_types
? "TU" : "CU",
6187 per_cu
->offset
.sect_off
);
6191 item
->per_cu
->queued
= 0;
6192 next_item
= item
->next
;
6196 dwarf2_queue_tail
= NULL
;
6198 if (dwarf2_read_debug
)
6200 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6201 dwarf2_per_objfile
->objfile
->name
);
6205 /* Free all allocated queue entries. This function only releases anything if
6206 an error was thrown; if the queue was processed then it would have been
6207 freed as we went along. */
6210 dwarf2_release_queue (void *dummy
)
6212 struct dwarf2_queue_item
*item
, *last
;
6214 item
= dwarf2_queue
;
6217 /* Anything still marked queued is likely to be in an
6218 inconsistent state, so discard it. */
6219 if (item
->per_cu
->queued
)
6221 if (item
->per_cu
->cu
!= NULL
)
6222 free_one_cached_comp_unit (item
->per_cu
);
6223 item
->per_cu
->queued
= 0;
6231 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6234 /* Read in full symbols for PST, and anything it depends on. */
6237 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6239 struct dwarf2_per_cu_data
*per_cu
;
6245 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6246 if (!pst
->dependencies
[i
]->readin
6247 && pst
->dependencies
[i
]->user
== NULL
)
6249 /* Inform about additional files that need to be read in. */
6252 /* FIXME: i18n: Need to make this a single string. */
6253 fputs_filtered (" ", gdb_stdout
);
6255 fputs_filtered ("and ", gdb_stdout
);
6257 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6258 wrap_here (""); /* Flush output. */
6259 gdb_flush (gdb_stdout
);
6261 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6264 per_cu
= pst
->read_symtab_private
;
6268 /* It's an include file, no symbols to read for it.
6269 Everything is in the parent symtab. */
6274 dw2_do_instantiate_symtab (per_cu
);
6277 /* Trivial hash function for die_info: the hash value of a DIE
6278 is its offset in .debug_info for this objfile. */
6281 die_hash (const void *item
)
6283 const struct die_info
*die
= item
;
6285 return die
->offset
.sect_off
;
6288 /* Trivial comparison function for die_info structures: two DIEs
6289 are equal if they have the same offset. */
6292 die_eq (const void *item_lhs
, const void *item_rhs
)
6294 const struct die_info
*die_lhs
= item_lhs
;
6295 const struct die_info
*die_rhs
= item_rhs
;
6297 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6300 /* die_reader_func for load_full_comp_unit.
6301 This is identical to read_signatured_type_reader,
6302 but is kept separate for now. */
6305 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6307 struct die_info
*comp_unit_die
,
6311 struct dwarf2_cu
*cu
= reader
->cu
;
6312 enum language
*language_ptr
= data
;
6314 gdb_assert (cu
->die_hash
== NULL
);
6316 htab_create_alloc_ex (cu
->header
.length
/ 12,
6320 &cu
->comp_unit_obstack
,
6321 hashtab_obstack_allocate
,
6322 dummy_obstack_deallocate
);
6325 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6326 &info_ptr
, comp_unit_die
);
6327 cu
->dies
= comp_unit_die
;
6328 /* comp_unit_die is not stored in die_hash, no need. */
6330 /* We try not to read any attributes in this function, because not
6331 all CUs needed for references have been loaded yet, and symbol
6332 table processing isn't initialized. But we have to set the CU language,
6333 or we won't be able to build types correctly.
6334 Similarly, if we do not read the producer, we can not apply
6335 producer-specific interpretation. */
6336 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6339 /* Load the DIEs associated with PER_CU into memory. */
6342 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6343 enum language pretend_language
)
6345 gdb_assert (! this_cu
->is_debug_types
);
6347 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6348 load_full_comp_unit_reader
, &pretend_language
);
6351 /* Add a DIE to the delayed physname list. */
6354 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6355 const char *name
, struct die_info
*die
,
6356 struct dwarf2_cu
*cu
)
6358 struct delayed_method_info mi
;
6360 mi
.fnfield_index
= fnfield_index
;
6364 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6367 /* A cleanup for freeing the delayed method list. */
6370 free_delayed_list (void *ptr
)
6372 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6373 if (cu
->method_list
!= NULL
)
6375 VEC_free (delayed_method_info
, cu
->method_list
);
6376 cu
->method_list
= NULL
;
6380 /* Compute the physnames of any methods on the CU's method list.
6382 The computation of method physnames is delayed in order to avoid the
6383 (bad) condition that one of the method's formal parameters is of an as yet
6387 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6390 struct delayed_method_info
*mi
;
6391 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6393 const char *physname
;
6394 struct fn_fieldlist
*fn_flp
6395 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6396 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6397 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6401 /* Go objects should be embedded in a DW_TAG_module DIE,
6402 and it's not clear if/how imported objects will appear.
6403 To keep Go support simple until that's worked out,
6404 go back through what we've read and create something usable.
6405 We could do this while processing each DIE, and feels kinda cleaner,
6406 but that way is more invasive.
6407 This is to, for example, allow the user to type "p var" or "b main"
6408 without having to specify the package name, and allow lookups
6409 of module.object to work in contexts that use the expression
6413 fixup_go_packaging (struct dwarf2_cu
*cu
)
6415 char *package_name
= NULL
;
6416 struct pending
*list
;
6419 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6421 for (i
= 0; i
< list
->nsyms
; ++i
)
6423 struct symbol
*sym
= list
->symbol
[i
];
6425 if (SYMBOL_LANGUAGE (sym
) == language_go
6426 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6428 char *this_package_name
= go_symbol_package_name (sym
);
6430 if (this_package_name
== NULL
)
6432 if (package_name
== NULL
)
6433 package_name
= this_package_name
;
6436 if (strcmp (package_name
, this_package_name
) != 0)
6437 complaint (&symfile_complaints
,
6438 _("Symtab %s has objects from two different Go packages: %s and %s"),
6439 (sym
->symtab
&& sym
->symtab
->filename
6440 ? sym
->symtab
->filename
6441 : cu
->objfile
->name
),
6442 this_package_name
, package_name
);
6443 xfree (this_package_name
);
6449 if (package_name
!= NULL
)
6451 struct objfile
*objfile
= cu
->objfile
;
6452 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6453 package_name
, objfile
);
6456 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6458 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6459 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6460 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6461 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6462 e.g., "main" finds the "main" module and not C's main(). */
6463 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6464 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6465 SYMBOL_TYPE (sym
) = type
;
6467 add_symbol_to_list (sym
, &global_symbols
);
6469 xfree (package_name
);
6473 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6475 /* Return the symtab for PER_CU. This works properly regardless of
6476 whether we're using the index or psymtabs. */
6478 static struct symtab
*
6479 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6481 return (dwarf2_per_objfile
->using_index
6482 ? per_cu
->v
.quick
->symtab
6483 : per_cu
->v
.psymtab
->symtab
);
6486 /* A helper function for computing the list of all symbol tables
6487 included by PER_CU. */
6490 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6491 htab_t all_children
,
6492 struct dwarf2_per_cu_data
*per_cu
)
6496 struct dwarf2_per_cu_data
*iter
;
6498 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6501 /* This inclusion and its children have been processed. */
6506 /* Only add a CU if it has a symbol table. */
6507 if (get_symtab (per_cu
) != NULL
)
6508 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6511 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6513 recursively_compute_inclusions (result
, all_children
, iter
);
6516 /* Compute the symtab 'includes' fields for the symtab related to
6520 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6522 gdb_assert (! per_cu
->is_debug_types
);
6524 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6527 struct dwarf2_per_cu_data
*iter
;
6528 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6529 htab_t all_children
;
6530 struct symtab
*symtab
= get_symtab (per_cu
);
6532 /* If we don't have a symtab, we can just skip this case. */
6536 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6537 NULL
, xcalloc
, xfree
);
6540 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6543 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6545 /* Now we have a transitive closure of all the included CUs, so
6546 we can convert it to a list of symtabs. */
6547 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6549 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6550 (len
+ 1) * sizeof (struct symtab
*));
6552 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6554 symtab
->includes
[ix
] = get_symtab (iter
);
6555 symtab
->includes
[len
] = NULL
;
6557 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6558 htab_delete (all_children
);
6562 /* Compute the 'includes' field for the symtabs of all the CUs we just
6566 process_cu_includes (void)
6569 struct dwarf2_per_cu_data
*iter
;
6572 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6576 if (! iter
->is_debug_types
)
6577 compute_symtab_includes (iter
);
6580 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6583 /* Generate full symbol information for PER_CU, whose DIEs have
6584 already been loaded into memory. */
6587 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6588 enum language pretend_language
)
6590 struct dwarf2_cu
*cu
= per_cu
->cu
;
6591 struct objfile
*objfile
= per_cu
->objfile
;
6592 CORE_ADDR lowpc
, highpc
;
6593 struct symtab
*symtab
;
6594 struct cleanup
*back_to
, *delayed_list_cleanup
;
6596 struct block
*static_block
;
6598 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6601 back_to
= make_cleanup (really_free_pendings
, NULL
);
6602 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6604 cu
->list_in_scope
= &file_symbols
;
6606 cu
->language
= pretend_language
;
6607 cu
->language_defn
= language_def (cu
->language
);
6609 /* Do line number decoding in read_file_scope () */
6610 process_die (cu
->dies
, cu
);
6612 /* For now fudge the Go package. */
6613 if (cu
->language
== language_go
)
6614 fixup_go_packaging (cu
);
6616 /* Now that we have processed all the DIEs in the CU, all the types
6617 should be complete, and it should now be safe to compute all of the
6619 compute_delayed_physnames (cu
);
6620 do_cleanups (delayed_list_cleanup
);
6622 /* Some compilers don't define a DW_AT_high_pc attribute for the
6623 compilation unit. If the DW_AT_high_pc is missing, synthesize
6624 it, by scanning the DIE's below the compilation unit. */
6625 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6627 static_block
= end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0);
6629 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6630 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6631 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6632 addrmap to help ensure it has an accurate map of pc values belonging to
6634 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6636 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6637 SECT_OFF_TEXT (objfile
), 0);
6641 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6643 /* Set symtab language to language from DW_AT_language. If the
6644 compilation is from a C file generated by language preprocessors, do
6645 not set the language if it was already deduced by start_subfile. */
6646 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6647 symtab
->language
= cu
->language
;
6649 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6650 produce DW_AT_location with location lists but it can be possibly
6651 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6652 there were bugs in prologue debug info, fixed later in GCC-4.5
6653 by "unwind info for epilogues" patch (which is not directly related).
6655 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6656 needed, it would be wrong due to missing DW_AT_producer there.
6658 Still one can confuse GDB by using non-standard GCC compilation
6659 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6661 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6662 symtab
->locations_valid
= 1;
6664 if (gcc_4_minor
>= 5)
6665 symtab
->epilogue_unwind_valid
= 1;
6667 symtab
->call_site_htab
= cu
->call_site_htab
;
6670 if (dwarf2_per_objfile
->using_index
)
6671 per_cu
->v
.quick
->symtab
= symtab
;
6674 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6675 pst
->symtab
= symtab
;
6679 /* Push it for inclusion processing later. */
6680 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
6682 do_cleanups (back_to
);
6685 /* Generate full symbol information for type unit PER_CU, whose DIEs have
6686 already been loaded into memory. */
6689 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
6690 enum language pretend_language
)
6692 struct dwarf2_cu
*cu
= per_cu
->cu
;
6693 struct objfile
*objfile
= per_cu
->objfile
;
6694 struct symtab
*symtab
;
6695 struct cleanup
*back_to
, *delayed_list_cleanup
;
6698 back_to
= make_cleanup (really_free_pendings
, NULL
);
6699 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6701 cu
->list_in_scope
= &file_symbols
;
6703 cu
->language
= pretend_language
;
6704 cu
->language_defn
= language_def (cu
->language
);
6706 /* The symbol tables are set up in read_type_unit_scope. */
6707 process_die (cu
->dies
, cu
);
6709 /* For now fudge the Go package. */
6710 if (cu
->language
== language_go
)
6711 fixup_go_packaging (cu
);
6713 /* Now that we have processed all the DIEs in the CU, all the types
6714 should be complete, and it should now be safe to compute all of the
6716 compute_delayed_physnames (cu
);
6717 do_cleanups (delayed_list_cleanup
);
6719 /* TUs share symbol tables.
6720 If this is the first TU to use this symtab, complete the construction
6721 of it with end_symtab. Otherwise, complete the addition of this TU's
6722 symbols to the existing symtab. */
6723 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
6725 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
6726 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
6730 /* Set symtab language to language from DW_AT_language. If the
6731 compilation is from a C file generated by language preprocessors,
6732 do not set the language if it was already deduced by
6734 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6735 symtab
->language
= cu
->language
;
6740 augment_type_symtab (objfile
,
6741 per_cu
->s
.type_unit_group
->primary_symtab
);
6742 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
6745 if (dwarf2_per_objfile
->using_index
)
6746 per_cu
->v
.quick
->symtab
= symtab
;
6749 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6750 pst
->symtab
= symtab
;
6754 do_cleanups (back_to
);
6757 /* Process an imported unit DIE. */
6760 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6762 struct attribute
*attr
;
6764 /* For now we don't handle imported units in type units. */
6765 if (cu
->per_cu
->is_debug_types
)
6767 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6768 " supported in type units [in module %s]"),
6772 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6775 struct dwarf2_per_cu_data
*per_cu
;
6776 struct symtab
*imported_symtab
;
6779 offset
= dwarf2_get_ref_die_offset (attr
);
6780 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6782 /* Queue the unit, if needed. */
6783 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
6784 load_full_comp_unit (per_cu
, cu
->language
);
6786 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
6791 /* Process a die and its children. */
6794 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6798 case DW_TAG_padding
:
6800 case DW_TAG_compile_unit
:
6801 case DW_TAG_partial_unit
:
6802 read_file_scope (die
, cu
);
6804 case DW_TAG_type_unit
:
6805 read_type_unit_scope (die
, cu
);
6807 case DW_TAG_subprogram
:
6808 case DW_TAG_inlined_subroutine
:
6809 read_func_scope (die
, cu
);
6811 case DW_TAG_lexical_block
:
6812 case DW_TAG_try_block
:
6813 case DW_TAG_catch_block
:
6814 read_lexical_block_scope (die
, cu
);
6816 case DW_TAG_GNU_call_site
:
6817 read_call_site_scope (die
, cu
);
6819 case DW_TAG_class_type
:
6820 case DW_TAG_interface_type
:
6821 case DW_TAG_structure_type
:
6822 case DW_TAG_union_type
:
6823 process_structure_scope (die
, cu
);
6825 case DW_TAG_enumeration_type
:
6826 process_enumeration_scope (die
, cu
);
6829 /* These dies have a type, but processing them does not create
6830 a symbol or recurse to process the children. Therefore we can
6831 read them on-demand through read_type_die. */
6832 case DW_TAG_subroutine_type
:
6833 case DW_TAG_set_type
:
6834 case DW_TAG_array_type
:
6835 case DW_TAG_pointer_type
:
6836 case DW_TAG_ptr_to_member_type
:
6837 case DW_TAG_reference_type
:
6838 case DW_TAG_string_type
:
6841 case DW_TAG_base_type
:
6842 case DW_TAG_subrange_type
:
6843 case DW_TAG_typedef
:
6844 /* Add a typedef symbol for the type definition, if it has a
6846 new_symbol (die
, read_type_die (die
, cu
), cu
);
6848 case DW_TAG_common_block
:
6849 read_common_block (die
, cu
);
6851 case DW_TAG_common_inclusion
:
6853 case DW_TAG_namespace
:
6854 processing_has_namespace_info
= 1;
6855 read_namespace (die
, cu
);
6858 processing_has_namespace_info
= 1;
6859 read_module (die
, cu
);
6861 case DW_TAG_imported_declaration
:
6862 case DW_TAG_imported_module
:
6863 processing_has_namespace_info
= 1;
6864 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6865 || cu
->language
!= language_fortran
))
6866 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
6867 dwarf_tag_name (die
->tag
));
6868 read_import_statement (die
, cu
);
6871 case DW_TAG_imported_unit
:
6872 process_imported_unit_die (die
, cu
);
6876 new_symbol (die
, NULL
, cu
);
6881 /* A helper function for dwarf2_compute_name which determines whether DIE
6882 needs to have the name of the scope prepended to the name listed in the
6886 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6888 struct attribute
*attr
;
6892 case DW_TAG_namespace
:
6893 case DW_TAG_typedef
:
6894 case DW_TAG_class_type
:
6895 case DW_TAG_interface_type
:
6896 case DW_TAG_structure_type
:
6897 case DW_TAG_union_type
:
6898 case DW_TAG_enumeration_type
:
6899 case DW_TAG_enumerator
:
6900 case DW_TAG_subprogram
:
6904 case DW_TAG_variable
:
6905 case DW_TAG_constant
:
6906 /* We only need to prefix "globally" visible variables. These include
6907 any variable marked with DW_AT_external or any variable that
6908 lives in a namespace. [Variables in anonymous namespaces
6909 require prefixing, but they are not DW_AT_external.] */
6911 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6913 struct dwarf2_cu
*spec_cu
= cu
;
6915 return die_needs_namespace (die_specification (die
, &spec_cu
),
6919 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6920 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6921 && die
->parent
->tag
!= DW_TAG_module
)
6923 /* A variable in a lexical block of some kind does not need a
6924 namespace, even though in C++ such variables may be external
6925 and have a mangled name. */
6926 if (die
->parent
->tag
== DW_TAG_lexical_block
6927 || die
->parent
->tag
== DW_TAG_try_block
6928 || die
->parent
->tag
== DW_TAG_catch_block
6929 || die
->parent
->tag
== DW_TAG_subprogram
)
6938 /* Retrieve the last character from a mem_file. */
6941 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
6943 char *last_char_p
= (char *) object
;
6946 *last_char_p
= buffer
[length
- 1];
6949 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6950 compute the physname for the object, which include a method's:
6951 - formal parameters (C++/Java),
6952 - receiver type (Go),
6953 - return type (Java).
6955 The term "physname" is a bit confusing.
6956 For C++, for example, it is the demangled name.
6957 For Go, for example, it's the mangled name.
6959 For Ada, return the DIE's linkage name rather than the fully qualified
6960 name. PHYSNAME is ignored..
6962 The result is allocated on the objfile_obstack and canonicalized. */
6965 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
6968 struct objfile
*objfile
= cu
->objfile
;
6971 name
= dwarf2_name (die
, cu
);
6973 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
6974 compute it by typename_concat inside GDB. */
6975 if (cu
->language
== language_ada
6976 || (cu
->language
== language_fortran
&& physname
))
6978 /* For Ada unit, we prefer the linkage name over the name, as
6979 the former contains the exported name, which the user expects
6980 to be able to reference. Ideally, we want the user to be able
6981 to reference this entity using either natural or linkage name,
6982 but we haven't started looking at this enhancement yet. */
6983 struct attribute
*attr
;
6985 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6987 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6988 if (attr
&& DW_STRING (attr
))
6989 return DW_STRING (attr
);
6992 /* These are the only languages we know how to qualify names in. */
6994 && (cu
->language
== language_cplus
|| cu
->language
== language_java
6995 || cu
->language
== language_fortran
))
6997 if (die_needs_namespace (die
, cu
))
7001 struct ui_file
*buf
;
7003 prefix
= determine_prefix (die
, cu
);
7004 buf
= mem_fileopen ();
7005 if (*prefix
!= '\0')
7007 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7010 fputs_unfiltered (prefixed_name
, buf
);
7011 xfree (prefixed_name
);
7014 fputs_unfiltered (name
, buf
);
7016 /* Template parameters may be specified in the DIE's DW_AT_name, or
7017 as children with DW_TAG_template_type_param or
7018 DW_TAG_value_type_param. If the latter, add them to the name
7019 here. If the name already has template parameters, then
7020 skip this step; some versions of GCC emit both, and
7021 it is more efficient to use the pre-computed name.
7023 Something to keep in mind about this process: it is very
7024 unlikely, or in some cases downright impossible, to produce
7025 something that will match the mangled name of a function.
7026 If the definition of the function has the same debug info,
7027 we should be able to match up with it anyway. But fallbacks
7028 using the minimal symbol, for instance to find a method
7029 implemented in a stripped copy of libstdc++, will not work.
7030 If we do not have debug info for the definition, we will have to
7031 match them up some other way.
7033 When we do name matching there is a related problem with function
7034 templates; two instantiated function templates are allowed to
7035 differ only by their return types, which we do not add here. */
7037 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7039 struct attribute
*attr
;
7040 struct die_info
*child
;
7043 die
->building_fullname
= 1;
7045 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7050 struct dwarf2_locexpr_baton
*baton
;
7053 if (child
->tag
!= DW_TAG_template_type_param
7054 && child
->tag
!= DW_TAG_template_value_param
)
7059 fputs_unfiltered ("<", buf
);
7063 fputs_unfiltered (", ", buf
);
7065 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7068 complaint (&symfile_complaints
,
7069 _("template parameter missing DW_AT_type"));
7070 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7073 type
= die_type (child
, cu
);
7075 if (child
->tag
== DW_TAG_template_type_param
)
7077 c_print_type (type
, "", buf
, -1, 0);
7081 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7084 complaint (&symfile_complaints
,
7085 _("template parameter missing "
7086 "DW_AT_const_value"));
7087 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7091 dwarf2_const_value_attr (attr
, type
, name
,
7092 &cu
->comp_unit_obstack
, cu
,
7093 &value
, &bytes
, &baton
);
7095 if (TYPE_NOSIGN (type
))
7096 /* GDB prints characters as NUMBER 'CHAR'. If that's
7097 changed, this can use value_print instead. */
7098 c_printchar (value
, type
, buf
);
7101 struct value_print_options opts
;
7104 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7108 else if (bytes
!= NULL
)
7110 v
= allocate_value (type
);
7111 memcpy (value_contents_writeable (v
), bytes
,
7112 TYPE_LENGTH (type
));
7115 v
= value_from_longest (type
, value
);
7117 /* Specify decimal so that we do not depend on
7119 get_formatted_print_options (&opts
, 'd');
7121 value_print (v
, buf
, &opts
);
7127 die
->building_fullname
= 0;
7131 /* Close the argument list, with a space if necessary
7132 (nested templates). */
7133 char last_char
= '\0';
7134 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7135 if (last_char
== '>')
7136 fputs_unfiltered (" >", buf
);
7138 fputs_unfiltered (">", buf
);
7142 /* For Java and C++ methods, append formal parameter type
7143 information, if PHYSNAME. */
7145 if (physname
&& die
->tag
== DW_TAG_subprogram
7146 && (cu
->language
== language_cplus
7147 || cu
->language
== language_java
))
7149 struct type
*type
= read_type_die (die
, cu
);
7151 c_type_print_args (type
, buf
, 1, cu
->language
);
7153 if (cu
->language
== language_java
)
7155 /* For java, we must append the return type to method
7157 if (die
->tag
== DW_TAG_subprogram
)
7158 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7161 else if (cu
->language
== language_cplus
)
7163 /* Assume that an artificial first parameter is
7164 "this", but do not crash if it is not. RealView
7165 marks unnamed (and thus unused) parameters as
7166 artificial; there is no way to differentiate
7168 if (TYPE_NFIELDS (type
) > 0
7169 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7170 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7171 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7173 fputs_unfiltered (" const", buf
);
7177 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7179 ui_file_delete (buf
);
7181 if (cu
->language
== language_cplus
)
7184 = dwarf2_canonicalize_name (name
, cu
,
7185 &objfile
->objfile_obstack
);
7196 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7197 If scope qualifiers are appropriate they will be added. The result
7198 will be allocated on the objfile_obstack, or NULL if the DIE does
7199 not have a name. NAME may either be from a previous call to
7200 dwarf2_name or NULL.
7202 The output string will be canonicalized (if C++/Java). */
7205 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7207 return dwarf2_compute_name (name
, die
, cu
, 0);
7210 /* Construct a physname for the given DIE in CU. NAME may either be
7211 from a previous call to dwarf2_name or NULL. The result will be
7212 allocated on the objfile_objstack or NULL if the DIE does not have a
7215 The output string will be canonicalized (if C++/Java). */
7218 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7220 struct objfile
*objfile
= cu
->objfile
;
7221 struct attribute
*attr
;
7222 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7223 struct cleanup
*back_to
;
7226 /* In this case dwarf2_compute_name is just a shortcut not building anything
7228 if (!die_needs_namespace (die
, cu
))
7229 return dwarf2_compute_name (name
, die
, cu
, 1);
7231 back_to
= make_cleanup (null_cleanup
, NULL
);
7233 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7235 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7237 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7239 if (attr
&& DW_STRING (attr
))
7243 mangled
= DW_STRING (attr
);
7245 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7246 type. It is easier for GDB users to search for such functions as
7247 `name(params)' than `long name(params)'. In such case the minimal
7248 symbol names do not match the full symbol names but for template
7249 functions there is never a need to look up their definition from their
7250 declaration so the only disadvantage remains the minimal symbol
7251 variant `long name(params)' does not have the proper inferior type.
7254 if (cu
->language
== language_go
)
7256 /* This is a lie, but we already lie to the caller new_symbol_full.
7257 new_symbol_full assumes we return the mangled name.
7258 This just undoes that lie until things are cleaned up. */
7263 demangled
= cplus_demangle (mangled
,
7264 (DMGL_PARAMS
| DMGL_ANSI
7265 | (cu
->language
== language_java
7266 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7271 make_cleanup (xfree
, demangled
);
7281 if (canon
== NULL
|| check_physname
)
7283 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7285 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7287 /* It may not mean a bug in GDB. The compiler could also
7288 compute DW_AT_linkage_name incorrectly. But in such case
7289 GDB would need to be bug-to-bug compatible. */
7291 complaint (&symfile_complaints
,
7292 _("Computed physname <%s> does not match demangled <%s> "
7293 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7294 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7296 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7297 is available here - over computed PHYSNAME. It is safer
7298 against both buggy GDB and buggy compilers. */
7312 retval
= obsavestring (retval
, strlen (retval
),
7313 &objfile
->objfile_obstack
);
7315 do_cleanups (back_to
);
7319 /* Read the import statement specified by the given die and record it. */
7322 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7324 struct objfile
*objfile
= cu
->objfile
;
7325 struct attribute
*import_attr
;
7326 struct die_info
*imported_die
, *child_die
;
7327 struct dwarf2_cu
*imported_cu
;
7328 const char *imported_name
;
7329 const char *imported_name_prefix
;
7330 const char *canonical_name
;
7331 const char *import_alias
;
7332 const char *imported_declaration
= NULL
;
7333 const char *import_prefix
;
7334 VEC (const_char_ptr
) *excludes
= NULL
;
7335 struct cleanup
*cleanups
;
7339 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7340 if (import_attr
== NULL
)
7342 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7343 dwarf_tag_name (die
->tag
));
7348 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7349 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7350 if (imported_name
== NULL
)
7352 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7354 The import in the following code:
7368 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7369 <52> DW_AT_decl_file : 1
7370 <53> DW_AT_decl_line : 6
7371 <54> DW_AT_import : <0x75>
7372 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7374 <5b> DW_AT_decl_file : 1
7375 <5c> DW_AT_decl_line : 2
7376 <5d> DW_AT_type : <0x6e>
7378 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7379 <76> DW_AT_byte_size : 4
7380 <77> DW_AT_encoding : 5 (signed)
7382 imports the wrong die ( 0x75 instead of 0x58 ).
7383 This case will be ignored until the gcc bug is fixed. */
7387 /* Figure out the local name after import. */
7388 import_alias
= dwarf2_name (die
, cu
);
7390 /* Figure out where the statement is being imported to. */
7391 import_prefix
= determine_prefix (die
, cu
);
7393 /* Figure out what the scope of the imported die is and prepend it
7394 to the name of the imported die. */
7395 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7397 if (imported_die
->tag
!= DW_TAG_namespace
7398 && imported_die
->tag
!= DW_TAG_module
)
7400 imported_declaration
= imported_name
;
7401 canonical_name
= imported_name_prefix
;
7403 else if (strlen (imported_name_prefix
) > 0)
7405 temp
= alloca (strlen (imported_name_prefix
)
7406 + 2 + strlen (imported_name
) + 1);
7407 strcpy (temp
, imported_name_prefix
);
7408 strcat (temp
, "::");
7409 strcat (temp
, imported_name
);
7410 canonical_name
= temp
;
7413 canonical_name
= imported_name
;
7415 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7417 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7418 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7419 child_die
= sibling_die (child_die
))
7421 /* DWARF-4: A Fortran use statement with a “rename list” may be
7422 represented by an imported module entry with an import attribute
7423 referring to the module and owned entries corresponding to those
7424 entities that are renamed as part of being imported. */
7426 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7428 complaint (&symfile_complaints
,
7429 _("child DW_TAG_imported_declaration expected "
7430 "- DIE at 0x%x [in module %s]"),
7431 child_die
->offset
.sect_off
, objfile
->name
);
7435 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7436 if (import_attr
== NULL
)
7438 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7439 dwarf_tag_name (child_die
->tag
));
7444 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7446 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7447 if (imported_name
== NULL
)
7449 complaint (&symfile_complaints
,
7450 _("child DW_TAG_imported_declaration has unknown "
7451 "imported name - DIE at 0x%x [in module %s]"),
7452 child_die
->offset
.sect_off
, objfile
->name
);
7456 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7458 process_die (child_die
, cu
);
7461 cp_add_using_directive (import_prefix
,
7464 imported_declaration
,
7466 &objfile
->objfile_obstack
);
7468 do_cleanups (cleanups
);
7471 /* Cleanup function for handle_DW_AT_stmt_list. */
7474 free_cu_line_header (void *arg
)
7476 struct dwarf2_cu
*cu
= arg
;
7478 free_line_header (cu
->line_header
);
7479 cu
->line_header
= NULL
;
7483 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7484 char **name
, char **comp_dir
)
7486 struct attribute
*attr
;
7491 /* Find the filename. Do not use dwarf2_name here, since the filename
7492 is not a source language identifier. */
7493 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7496 *name
= DW_STRING (attr
);
7499 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7501 *comp_dir
= DW_STRING (attr
);
7502 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
7504 *comp_dir
= ldirname (*name
);
7505 if (*comp_dir
!= NULL
)
7506 make_cleanup (xfree
, *comp_dir
);
7508 if (*comp_dir
!= NULL
)
7510 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7511 directory, get rid of it. */
7512 char *cp
= strchr (*comp_dir
, ':');
7514 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7519 *name
= "<unknown>";
7522 /* Handle DW_AT_stmt_list for a compilation unit.
7523 DIE is the DW_TAG_compile_unit die for CU.
7524 COMP_DIR is the compilation directory.
7525 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7528 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7529 const char *comp_dir
)
7531 struct attribute
*attr
;
7533 gdb_assert (! cu
->per_cu
->is_debug_types
);
7535 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7538 unsigned int line_offset
= DW_UNSND (attr
);
7539 struct line_header
*line_header
7540 = dwarf_decode_line_header (line_offset
, cu
);
7544 cu
->line_header
= line_header
;
7545 make_cleanup (free_cu_line_header
, cu
);
7546 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7551 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7554 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7556 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7557 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7558 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7559 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7560 struct attribute
*attr
;
7562 char *comp_dir
= NULL
;
7563 struct die_info
*child_die
;
7564 bfd
*abfd
= objfile
->obfd
;
7567 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7569 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7571 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7572 from finish_block. */
7573 if (lowpc
== ((CORE_ADDR
) -1))
7578 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7580 prepare_one_comp_unit (cu
, die
, cu
->language
);
7582 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7583 standardised yet. As a workaround for the language detection we fall
7584 back to the DW_AT_producer string. */
7585 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7586 cu
->language
= language_opencl
;
7588 /* Similar hack for Go. */
7589 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7590 set_cu_language (DW_LANG_Go
, cu
);
7592 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7594 /* Decode line number information if present. We do this before
7595 processing child DIEs, so that the line header table is available
7596 for DW_AT_decl_file. */
7597 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7599 /* Process all dies in compilation unit. */
7600 if (die
->child
!= NULL
)
7602 child_die
= die
->child
;
7603 while (child_die
&& child_die
->tag
)
7605 process_die (child_die
, cu
);
7606 child_die
= sibling_die (child_die
);
7610 /* Decode macro information, if present. Dwarf 2 macro information
7611 refers to information in the line number info statement program
7612 header, so we can only read it if we've read the header
7614 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7615 if (attr
&& cu
->line_header
)
7617 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7618 complaint (&symfile_complaints
,
7619 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7621 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7625 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7626 if (attr
&& cu
->line_header
)
7628 unsigned int macro_offset
= DW_UNSND (attr
);
7630 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7634 do_cleanups (back_to
);
7637 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7638 Create the set of symtabs used by this TU, or if this TU is sharing
7639 symtabs with another TU and the symtabs have already been created
7640 then restore those symtabs in the line header.
7641 We don't need the pc/line-number mapping for type units. */
7644 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7646 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7647 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7648 struct type_unit_group
*tu_group
;
7650 struct line_header
*lh
;
7651 struct attribute
*attr
;
7652 unsigned int i
, line_offset
;
7654 gdb_assert (per_cu
->is_debug_types
);
7656 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7658 /* If we're using .gdb_index (includes -readnow) then
7659 per_cu->s.type_unit_group may not have been set up yet. */
7660 if (per_cu
->s
.type_unit_group
== NULL
)
7661 per_cu
->s
.type_unit_group
= get_type_unit_group (per_cu
, attr
);
7662 tu_group
= per_cu
->s
.type_unit_group
;
7664 /* If we've already processed this stmt_list there's no real need to
7665 do it again, we could fake it and just recreate the part we need
7666 (file name,index -> symtab mapping). If data shows this optimization
7667 is useful we can do it then. */
7668 first_time
= tu_group
->primary_symtab
== NULL
;
7670 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7675 line_offset
= DW_UNSND (attr
);
7676 lh
= dwarf_decode_line_header (line_offset
, cu
);
7681 dwarf2_start_symtab (cu
, "", NULL
, 0);
7684 gdb_assert (tu_group
->symtabs
== NULL
);
7687 /* Note: The primary symtab will get allocated at the end. */
7691 cu
->line_header
= lh
;
7692 make_cleanup (free_cu_line_header
, cu
);
7696 dwarf2_start_symtab (cu
, "", NULL
, 0);
7698 tu_group
->num_symtabs
= lh
->num_file_names
;
7699 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
7701 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7704 struct file_entry
*fe
= &lh
->file_names
[i
];
7707 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7708 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
7710 /* Note: We don't have to watch for the main subfile here, type units
7711 don't have DW_AT_name. */
7713 if (current_subfile
->symtab
== NULL
)
7715 /* NOTE: start_subfile will recognize when it's been passed
7716 a file it has already seen. So we can't assume there's a
7717 simple mapping from lh->file_names to subfiles,
7718 lh->file_names may contain dups. */
7719 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7723 fe
->symtab
= current_subfile
->symtab
;
7724 tu_group
->symtabs
[i
] = fe
->symtab
;
7731 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7733 struct file_entry
*fe
= &lh
->file_names
[i
];
7735 fe
->symtab
= tu_group
->symtabs
[i
];
7739 /* The main symtab is allocated last. Type units don't have DW_AT_name
7740 so they don't have a "real" (so to speak) symtab anyway.
7741 There is later code that will assign the main symtab to all symbols
7742 that don't have one. We need to handle the case of a symbol with a
7743 missing symtab (DW_AT_decl_file) anyway. */
7746 /* Process DW_TAG_type_unit.
7747 For TUs we want to skip the first top level sibling if it's not the
7748 actual type being defined by this TU. In this case the first top
7749 level sibling is there to provide context only. */
7752 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7754 struct die_info
*child_die
;
7756 prepare_one_comp_unit (cu
, die
, language_minimal
);
7758 /* Initialize (or reinitialize) the machinery for building symtabs.
7759 We do this before processing child DIEs, so that the line header table
7760 is available for DW_AT_decl_file. */
7761 setup_type_unit_groups (die
, cu
);
7763 if (die
->child
!= NULL
)
7765 child_die
= die
->child
;
7766 while (child_die
&& child_die
->tag
)
7768 process_die (child_die
, cu
);
7769 child_die
= sibling_die (child_die
);
7777 hash_dwo_file (const void *item
)
7779 const struct dwo_file
*dwo_file
= item
;
7781 return htab_hash_string (dwo_file
->dwo_name
);
7785 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
7787 const struct dwo_file
*lhs
= item_lhs
;
7788 const struct dwo_file
*rhs
= item_rhs
;
7790 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
7793 /* Allocate a hash table for DWO files. */
7796 allocate_dwo_file_hash_table (void)
7798 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7800 return htab_create_alloc_ex (41,
7804 &objfile
->objfile_obstack
,
7805 hashtab_obstack_allocate
,
7806 dummy_obstack_deallocate
);
7810 hash_dwo_unit (const void *item
)
7812 const struct dwo_unit
*dwo_unit
= item
;
7814 /* This drops the top 32 bits of the id, but is ok for a hash. */
7815 return dwo_unit
->signature
;
7819 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
7821 const struct dwo_unit
*lhs
= item_lhs
;
7822 const struct dwo_unit
*rhs
= item_rhs
;
7824 /* The signature is assumed to be unique within the DWO file.
7825 So while object file CU dwo_id's always have the value zero,
7826 that's OK, assuming each object file DWO file has only one CU,
7827 and that's the rule for now. */
7828 return lhs
->signature
== rhs
->signature
;
7831 /* Allocate a hash table for DWO CUs,TUs.
7832 There is one of these tables for each of CUs,TUs for each DWO file. */
7835 allocate_dwo_unit_table (struct objfile
*objfile
)
7837 /* Start out with a pretty small number.
7838 Generally DWO files contain only one CU and maybe some TUs. */
7839 return htab_create_alloc_ex (3,
7843 &objfile
->objfile_obstack
,
7844 hashtab_obstack_allocate
,
7845 dummy_obstack_deallocate
);
7848 /* This function is mapped across the sections and remembers the offset and
7849 size of each of the DWO debugging sections we are interested in. */
7852 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
7854 struct dwo_file
*dwo_file
= dwo_file_ptr
;
7855 const struct dwo_section_names
*names
= &dwo_section_names
;
7857 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
7859 dwo_file
->sections
.abbrev
.asection
= sectp
;
7860 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
7862 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
7864 dwo_file
->sections
.info
.asection
= sectp
;
7865 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
7867 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
7869 dwo_file
->sections
.line
.asection
= sectp
;
7870 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
7872 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
7874 dwo_file
->sections
.loc
.asection
= sectp
;
7875 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
7877 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
7879 dwo_file
->sections
.macinfo
.asection
= sectp
;
7880 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
7882 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
7884 dwo_file
->sections
.macro
.asection
= sectp
;
7885 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
7887 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
7889 dwo_file
->sections
.str
.asection
= sectp
;
7890 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
7892 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
7894 dwo_file
->sections
.str_offsets
.asection
= sectp
;
7895 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
7897 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
7899 struct dwarf2_section_info type_section
;
7901 memset (&type_section
, 0, sizeof (type_section
));
7902 type_section
.asection
= sectp
;
7903 type_section
.size
= bfd_get_section_size (sectp
);
7904 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7909 /* Structure used to pass data to create_debug_info_hash_table_reader. */
7911 struct create_dwo_info_table_data
7913 struct dwo_file
*dwo_file
;
7917 /* die_reader_func for create_debug_info_hash_table. */
7920 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
7922 struct die_info
*comp_unit_die
,
7926 struct dwarf2_cu
*cu
= reader
->cu
;
7927 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7928 sect_offset offset
= cu
->per_cu
->offset
;
7929 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
7930 struct create_dwo_info_table_data
*data
= datap
;
7931 struct dwo_file
*dwo_file
= data
->dwo_file
;
7932 htab_t cu_htab
= data
->cu_htab
;
7934 struct attribute
*attr
;
7935 struct dwo_unit
*dwo_unit
;
7937 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7940 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
7941 " its dwo_id [in module %s]"),
7942 offset
.sect_off
, dwo_file
->dwo_name
);
7946 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
7947 dwo_unit
->dwo_file
= dwo_file
;
7948 dwo_unit
->signature
= DW_UNSND (attr
);
7949 dwo_unit
->info_or_types_section
= section
;
7950 dwo_unit
->offset
= offset
;
7951 dwo_unit
->length
= cu
->per_cu
->length
;
7953 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
7954 gdb_assert (slot
!= NULL
);
7957 const struct dwo_unit
*dup_dwo_unit
= *slot
;
7959 complaint (&symfile_complaints
,
7960 _("debug entry at offset 0x%x is duplicate to the entry at"
7961 " offset 0x%x, dwo_id 0x%s [in module %s]"),
7962 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
7963 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
7964 dwo_file
->dwo_name
);
7969 if (dwarf2_read_debug
)
7970 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
7972 phex (dwo_unit
->signature
,
7973 sizeof (dwo_unit
->signature
)));
7976 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
7979 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
7981 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7982 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
7985 gdb_byte
*info_ptr
, *end_ptr
;
7986 struct create_dwo_info_table_data create_dwo_info_table_data
;
7988 dwarf2_read_section (objfile
, section
);
7989 info_ptr
= section
->buffer
;
7991 if (info_ptr
== NULL
)
7994 /* We can't set abfd until now because the section may be empty or
7995 not present, in which case section->asection will be NULL. */
7996 abfd
= section
->asection
->owner
;
7998 if (dwarf2_read_debug
)
7999 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8000 bfd_get_filename (abfd
));
8002 cu_htab
= allocate_dwo_unit_table (objfile
);
8004 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8005 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8007 end_ptr
= info_ptr
+ section
->size
;
8008 while (info_ptr
< end_ptr
)
8010 struct dwarf2_per_cu_data per_cu
;
8012 memset (&per_cu
, 0, sizeof (per_cu
));
8013 per_cu
.objfile
= objfile
;
8014 per_cu
.is_debug_types
= 0;
8015 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8016 per_cu
.info_or_types_section
= section
;
8018 init_cutu_and_read_dies_no_follow (&per_cu
,
8019 &dwo_file
->sections
.abbrev
,
8021 create_debug_info_hash_table_reader
,
8022 &create_dwo_info_table_data
);
8024 info_ptr
+= per_cu
.length
;
8030 /* Subroutine of open_dwo_file to simplify it.
8031 Open the file specified by FILE_NAME and hand it off to BFD for
8032 preliminary analysis. Return a newly initialized bfd *, which
8033 includes a canonicalized copy of FILE_NAME.
8034 In case of trouble, return NULL.
8035 NOTE: This function is derived from symfile_bfd_open. */
8038 try_open_dwo_file (const char *file_name
)
8042 char *absolute_name
;
8044 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
8045 O_RDONLY
| O_BINARY
, &absolute_name
);
8049 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
8052 xfree (absolute_name
);
8055 bfd_set_cacheable (sym_bfd
, 1);
8057 if (!bfd_check_format (sym_bfd
, bfd_object
))
8059 bfd_close (sym_bfd
); /* This also closes desc. */
8060 xfree (absolute_name
);
8064 /* bfd_usrdata exists for applications and libbfd must not touch it. */
8065 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
8070 /* Try to open DWO file DWO_NAME.
8071 COMP_DIR is the DW_AT_comp_dir attribute.
8072 The result is the bfd handle of the file.
8073 If there is a problem finding or opening the file, return NULL.
8074 Upon success, the canonicalized path of the file is stored in the bfd,
8075 same as symfile_bfd_open. */
8078 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
8082 if (IS_ABSOLUTE_PATH (dwo_name
))
8083 return try_open_dwo_file (dwo_name
);
8085 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8087 if (comp_dir
!= NULL
)
8089 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
8091 /* NOTE: If comp_dir is a relative path, this will also try the
8092 search path, which seems useful. */
8093 abfd
= try_open_dwo_file (path_to_try
);
8094 xfree (path_to_try
);
8099 /* That didn't work, try debug-file-directory, which, despite its name,
8100 is a list of paths. */
8102 if (*debug_file_directory
== '\0')
8105 return try_open_dwo_file (dwo_name
);
8108 /* Initialize the use of the DWO file specified by DWO_NAME. */
8110 static struct dwo_file
*
8111 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8113 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8114 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8117 struct cleanup
*cleanups
;
8119 if (dwarf2_read_debug
)
8120 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
8122 abfd
= open_dwo_file (dwo_name
, comp_dir
);
8125 dwo_file
->dwo_name
= dwo_name
;
8126 dwo_file
->dwo_bfd
= abfd
;
8128 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8130 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
8132 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
8134 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8135 dwo_file
->sections
.types
);
8137 discard_cleanups (cleanups
);
8142 /* Lookup DWO file DWO_NAME. */
8144 static struct dwo_file
*
8145 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
8147 struct dwo_file
*dwo_file
;
8148 struct dwo_file find_entry
;
8151 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8152 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8154 /* Have we already seen this DWO file? */
8155 find_entry
.dwo_name
= dwo_name
;
8156 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8158 /* If not, read it in and build a table of the DWOs it contains. */
8160 *slot
= init_dwo_file (dwo_name
, comp_dir
);
8162 /* NOTE: This will be NULL if unable to open the file. */
8168 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
8169 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8170 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
8171 nomenclature as TUs).
8172 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8173 (dwo_id mismatch or couldn't find the DWO file). */
8175 static struct dwo_unit
*
8176 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8177 char *dwo_name
, const char *comp_dir
,
8180 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8181 struct dwo_file
*dwo_file
;
8183 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8184 if (dwo_file
== NULL
)
8187 /* Look up the DWO using its signature(dwo_id). */
8189 if (dwo_file
->cus
!= NULL
)
8191 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8193 find_dwo_cu
.signature
= signature
;
8194 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
8200 /* We didn't find it. This must mean a dwo_id mismatch. */
8202 complaint (&symfile_complaints
,
8203 _("Could not find DWO CU referenced by CU at offset 0x%x"
8205 this_cu
->offset
.sect_off
, objfile
->name
);
8209 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
8210 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8211 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8212 (dwo_id mismatch or couldn't find the DWO file). */
8214 static struct dwo_unit
*
8215 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
8216 char *dwo_name
, const char *comp_dir
)
8218 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8219 struct dwo_file
*dwo_file
;
8221 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8222 if (dwo_file
== NULL
)
8225 /* Look up the DWO using its signature(dwo_id). */
8227 if (dwo_file
->tus
!= NULL
)
8229 struct dwo_unit find_dwo_tu
, *dwo_tu
;
8231 find_dwo_tu
.signature
= this_tu
->signature
;
8232 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
8238 /* We didn't find it. This must mean a dwo_id mismatch. */
8240 complaint (&symfile_complaints
,
8241 _("Could not find DWO TU referenced by TU at offset 0x%x"
8243 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
8247 /* Free all resources associated with DWO_FILE.
8248 Close the DWO file and munmap the sections.
8249 All memory should be on the objfile obstack. */
8252 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
8255 struct dwarf2_section_info
*section
;
8257 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
8258 bfd_close (dwo_file
->dwo_bfd
);
8260 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
8261 munmap_section_buffer (&dwo_file
->sections
.info
);
8262 munmap_section_buffer (&dwo_file
->sections
.line
);
8263 munmap_section_buffer (&dwo_file
->sections
.loc
);
8264 munmap_section_buffer (&dwo_file
->sections
.str
);
8265 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
8268 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
8271 munmap_section_buffer (section
);
8273 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
8276 /* Wrapper for free_dwo_file for use in cleanups. */
8279 free_dwo_file_cleanup (void *arg
)
8281 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
8282 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8284 free_dwo_file (dwo_file
, objfile
);
8287 /* Traversal function for free_dwo_files. */
8290 free_dwo_file_from_slot (void **slot
, void *info
)
8292 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8293 struct objfile
*objfile
= (struct objfile
*) info
;
8295 free_dwo_file (dwo_file
, objfile
);
8300 /* Free all resources associated with DWO_FILES. */
8303 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
8305 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
8308 /* Read in various DIEs. */
8310 /* qsort helper for inherit_abstract_dies. */
8313 unsigned_int_compar (const void *ap
, const void *bp
)
8315 unsigned int a
= *(unsigned int *) ap
;
8316 unsigned int b
= *(unsigned int *) bp
;
8318 return (a
> b
) - (b
> a
);
8321 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
8322 Inherit only the children of the DW_AT_abstract_origin DIE not being
8323 already referenced by DW_AT_abstract_origin from the children of the
8327 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
8329 struct die_info
*child_die
;
8330 unsigned die_children_count
;
8331 /* CU offsets which were referenced by children of the current DIE. */
8332 sect_offset
*offsets
;
8333 sect_offset
*offsets_end
, *offsetp
;
8334 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
8335 struct die_info
*origin_die
;
8336 /* Iterator of the ORIGIN_DIE children. */
8337 struct die_info
*origin_child_die
;
8338 struct cleanup
*cleanups
;
8339 struct attribute
*attr
;
8340 struct dwarf2_cu
*origin_cu
;
8341 struct pending
**origin_previous_list_in_scope
;
8343 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8347 /* Note that following die references may follow to a die in a
8351 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
8353 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
8355 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
8356 origin_cu
->list_in_scope
= cu
->list_in_scope
;
8358 if (die
->tag
!= origin_die
->tag
8359 && !(die
->tag
== DW_TAG_inlined_subroutine
8360 && origin_die
->tag
== DW_TAG_subprogram
))
8361 complaint (&symfile_complaints
,
8362 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
8363 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
8365 child_die
= die
->child
;
8366 die_children_count
= 0;
8367 while (child_die
&& child_die
->tag
)
8369 child_die
= sibling_die (child_die
);
8370 die_children_count
++;
8372 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
8373 cleanups
= make_cleanup (xfree
, offsets
);
8375 offsets_end
= offsets
;
8376 child_die
= die
->child
;
8377 while (child_die
&& child_die
->tag
)
8379 /* For each CHILD_DIE, find the corresponding child of
8380 ORIGIN_DIE. If there is more than one layer of
8381 DW_AT_abstract_origin, follow them all; there shouldn't be,
8382 but GCC versions at least through 4.4 generate this (GCC PR
8384 struct die_info
*child_origin_die
= child_die
;
8385 struct dwarf2_cu
*child_origin_cu
= cu
;
8389 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
8393 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
8397 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
8398 counterpart may exist. */
8399 if (child_origin_die
!= child_die
)
8401 if (child_die
->tag
!= child_origin_die
->tag
8402 && !(child_die
->tag
== DW_TAG_inlined_subroutine
8403 && child_origin_die
->tag
== DW_TAG_subprogram
))
8404 complaint (&symfile_complaints
,
8405 _("Child DIE 0x%x and its abstract origin 0x%x have "
8406 "different tags"), child_die
->offset
.sect_off
,
8407 child_origin_die
->offset
.sect_off
);
8408 if (child_origin_die
->parent
!= origin_die
)
8409 complaint (&symfile_complaints
,
8410 _("Child DIE 0x%x and its abstract origin 0x%x have "
8411 "different parents"), child_die
->offset
.sect_off
,
8412 child_origin_die
->offset
.sect_off
);
8414 *offsets_end
++ = child_origin_die
->offset
;
8416 child_die
= sibling_die (child_die
);
8418 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
8419 unsigned_int_compar
);
8420 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
8421 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
8422 complaint (&symfile_complaints
,
8423 _("Multiple children of DIE 0x%x refer "
8424 "to DIE 0x%x as their abstract origin"),
8425 die
->offset
.sect_off
, offsetp
->sect_off
);
8428 origin_child_die
= origin_die
->child
;
8429 while (origin_child_die
&& origin_child_die
->tag
)
8431 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
8432 while (offsetp
< offsets_end
8433 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
8435 if (offsetp
>= offsets_end
8436 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
8438 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
8439 process_die (origin_child_die
, origin_cu
);
8441 origin_child_die
= sibling_die (origin_child_die
);
8443 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
8445 do_cleanups (cleanups
);
8449 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8451 struct objfile
*objfile
= cu
->objfile
;
8452 struct context_stack
*new;
8455 struct die_info
*child_die
;
8456 struct attribute
*attr
, *call_line
, *call_file
;
8459 struct block
*block
;
8460 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8461 VEC (symbolp
) *template_args
= NULL
;
8462 struct template_symbol
*templ_func
= NULL
;
8466 /* If we do not have call site information, we can't show the
8467 caller of this inlined function. That's too confusing, so
8468 only use the scope for local variables. */
8469 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
8470 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
8471 if (call_line
== NULL
|| call_file
== NULL
)
8473 read_lexical_block_scope (die
, cu
);
8478 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8480 name
= dwarf2_name (die
, cu
);
8482 /* Ignore functions with missing or empty names. These are actually
8483 illegal according to the DWARF standard. */
8486 complaint (&symfile_complaints
,
8487 _("missing name for subprogram DIE at %d"),
8488 die
->offset
.sect_off
);
8492 /* Ignore functions with missing or invalid low and high pc attributes. */
8493 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8495 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8496 if (!attr
|| !DW_UNSND (attr
))
8497 complaint (&symfile_complaints
,
8498 _("cannot get low and high bounds "
8499 "for subprogram DIE at %d"),
8500 die
->offset
.sect_off
);
8507 /* If we have any template arguments, then we must allocate a
8508 different sort of symbol. */
8509 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
8511 if (child_die
->tag
== DW_TAG_template_type_param
8512 || child_die
->tag
== DW_TAG_template_value_param
)
8514 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8515 struct template_symbol
);
8516 templ_func
->base
.is_cplus_template_function
= 1;
8521 new = push_context (0, lowpc
);
8522 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
8523 (struct symbol
*) templ_func
);
8525 /* If there is a location expression for DW_AT_frame_base, record
8527 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
8529 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
8530 expression is being recorded directly in the function's symbol
8531 and not in a separate frame-base object. I guess this hack is
8532 to avoid adding some sort of frame-base adjunct/annex to the
8533 function's symbol :-(. The problem with doing this is that it
8534 results in a function symbol with a location expression that
8535 has nothing to do with the location of the function, ouch! The
8536 relationship should be: a function's symbol has-a frame base; a
8537 frame-base has-a location expression. */
8538 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
8540 cu
->list_in_scope
= &local_symbols
;
8542 if (die
->child
!= NULL
)
8544 child_die
= die
->child
;
8545 while (child_die
&& child_die
->tag
)
8547 if (child_die
->tag
== DW_TAG_template_type_param
8548 || child_die
->tag
== DW_TAG_template_value_param
)
8550 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8553 VEC_safe_push (symbolp
, template_args
, arg
);
8556 process_die (child_die
, cu
);
8557 child_die
= sibling_die (child_die
);
8561 inherit_abstract_dies (die
, cu
);
8563 /* If we have a DW_AT_specification, we might need to import using
8564 directives from the context of the specification DIE. See the
8565 comment in determine_prefix. */
8566 if (cu
->language
== language_cplus
8567 && dwarf2_attr (die
, DW_AT_specification
, cu
))
8569 struct dwarf2_cu
*spec_cu
= cu
;
8570 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
8574 child_die
= spec_die
->child
;
8575 while (child_die
&& child_die
->tag
)
8577 if (child_die
->tag
== DW_TAG_imported_module
)
8578 process_die (child_die
, spec_cu
);
8579 child_die
= sibling_die (child_die
);
8582 /* In some cases, GCC generates specification DIEs that
8583 themselves contain DW_AT_specification attributes. */
8584 spec_die
= die_specification (spec_die
, &spec_cu
);
8588 new = pop_context ();
8589 /* Make a block for the local symbols within. */
8590 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
8591 lowpc
, highpc
, objfile
);
8593 /* For C++, set the block's scope. */
8594 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
8595 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
8596 determine_prefix (die
, cu
),
8597 processing_has_namespace_info
);
8599 /* If we have address ranges, record them. */
8600 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8602 /* Attach template arguments to function. */
8603 if (! VEC_empty (symbolp
, template_args
))
8605 gdb_assert (templ_func
!= NULL
);
8607 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
8608 templ_func
->template_arguments
8609 = obstack_alloc (&objfile
->objfile_obstack
,
8610 (templ_func
->n_template_arguments
8611 * sizeof (struct symbol
*)));
8612 memcpy (templ_func
->template_arguments
,
8613 VEC_address (symbolp
, template_args
),
8614 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
8615 VEC_free (symbolp
, template_args
);
8618 /* In C++, we can have functions nested inside functions (e.g., when
8619 a function declares a class that has methods). This means that
8620 when we finish processing a function scope, we may need to go
8621 back to building a containing block's symbol lists. */
8622 local_symbols
= new->locals
;
8623 param_symbols
= new->params
;
8624 using_directives
= new->using_directives
;
8626 /* If we've finished processing a top-level function, subsequent
8627 symbols go in the file symbol list. */
8628 if (outermost_context_p ())
8629 cu
->list_in_scope
= &file_symbols
;
8632 /* Process all the DIES contained within a lexical block scope. Start
8633 a new scope, process the dies, and then close the scope. */
8636 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8638 struct objfile
*objfile
= cu
->objfile
;
8639 struct context_stack
*new;
8640 CORE_ADDR lowpc
, highpc
;
8641 struct die_info
*child_die
;
8644 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8646 /* Ignore blocks with missing or invalid low and high pc attributes. */
8647 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
8648 as multiple lexical blocks? Handling children in a sane way would
8649 be nasty. Might be easier to properly extend generic blocks to
8651 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8656 push_context (0, lowpc
);
8657 if (die
->child
!= NULL
)
8659 child_die
= die
->child
;
8660 while (child_die
&& child_die
->tag
)
8662 process_die (child_die
, cu
);
8663 child_die
= sibling_die (child_die
);
8666 new = pop_context ();
8668 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
8671 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
8674 /* Note that recording ranges after traversing children, as we
8675 do here, means that recording a parent's ranges entails
8676 walking across all its children's ranges as they appear in
8677 the address map, which is quadratic behavior.
8679 It would be nicer to record the parent's ranges before
8680 traversing its children, simply overriding whatever you find
8681 there. But since we don't even decide whether to create a
8682 block until after we've traversed its children, that's hard
8684 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8686 local_symbols
= new->locals
;
8687 using_directives
= new->using_directives
;
8690 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
8693 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8695 struct objfile
*objfile
= cu
->objfile
;
8696 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8697 CORE_ADDR pc
, baseaddr
;
8698 struct attribute
*attr
;
8699 struct call_site
*call_site
, call_site_local
;
8702 struct die_info
*child_die
;
8704 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8706 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8709 complaint (&symfile_complaints
,
8710 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
8711 "DIE 0x%x [in module %s]"),
8712 die
->offset
.sect_off
, objfile
->name
);
8715 pc
= DW_ADDR (attr
) + baseaddr
;
8717 if (cu
->call_site_htab
== NULL
)
8718 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
8719 NULL
, &objfile
->objfile_obstack
,
8720 hashtab_obstack_allocate
, NULL
);
8721 call_site_local
.pc
= pc
;
8722 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
8725 complaint (&symfile_complaints
,
8726 _("Duplicate PC %s for DW_TAG_GNU_call_site "
8727 "DIE 0x%x [in module %s]"),
8728 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
8732 /* Count parameters at the caller. */
8735 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8736 child_die
= sibling_die (child_die
))
8738 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8740 complaint (&symfile_complaints
,
8741 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
8742 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8743 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
8750 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
8751 (sizeof (*call_site
)
8752 + (sizeof (*call_site
->parameter
)
8755 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
8758 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
8760 struct die_info
*func_die
;
8762 /* Skip also over DW_TAG_inlined_subroutine. */
8763 for (func_die
= die
->parent
;
8764 func_die
&& func_die
->tag
!= DW_TAG_subprogram
8765 && func_die
->tag
!= DW_TAG_subroutine_type
;
8766 func_die
= func_die
->parent
);
8768 /* DW_AT_GNU_all_call_sites is a superset
8769 of DW_AT_GNU_all_tail_call_sites. */
8771 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
8772 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
8774 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
8775 not complete. But keep CALL_SITE for look ups via call_site_htab,
8776 both the initial caller containing the real return address PC and
8777 the final callee containing the current PC of a chain of tail
8778 calls do not need to have the tail call list complete. But any
8779 function candidate for a virtual tail call frame searched via
8780 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
8781 determined unambiguously. */
8785 struct type
*func_type
= NULL
;
8788 func_type
= get_die_type (func_die
, cu
);
8789 if (func_type
!= NULL
)
8791 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
8793 /* Enlist this call site to the function. */
8794 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
8795 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
8798 complaint (&symfile_complaints
,
8799 _("Cannot find function owning DW_TAG_GNU_call_site "
8800 "DIE 0x%x [in module %s]"),
8801 die
->offset
.sect_off
, objfile
->name
);
8805 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
8807 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8808 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
8809 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
8810 /* Keep NULL DWARF_BLOCK. */;
8811 else if (attr_form_is_block (attr
))
8813 struct dwarf2_locexpr_baton
*dlbaton
;
8815 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
8816 dlbaton
->data
= DW_BLOCK (attr
)->data
;
8817 dlbaton
->size
= DW_BLOCK (attr
)->size
;
8818 dlbaton
->per_cu
= cu
->per_cu
;
8820 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
8822 else if (is_ref_attr (attr
))
8824 struct dwarf2_cu
*target_cu
= cu
;
8825 struct die_info
*target_die
;
8827 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
8828 gdb_assert (target_cu
->objfile
== objfile
);
8829 if (die_is_declaration (target_die
, target_cu
))
8831 const char *target_physname
;
8833 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
8834 if (target_physname
== NULL
)
8835 complaint (&symfile_complaints
,
8836 _("DW_AT_GNU_call_site_target target DIE has invalid "
8837 "physname, for referencing DIE 0x%x [in module %s]"),
8838 die
->offset
.sect_off
, objfile
->name
);
8840 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
8846 /* DW_AT_entry_pc should be preferred. */
8847 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
8848 complaint (&symfile_complaints
,
8849 _("DW_AT_GNU_call_site_target target DIE has invalid "
8850 "low pc, for referencing DIE 0x%x [in module %s]"),
8851 die
->offset
.sect_off
, objfile
->name
);
8853 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
8857 complaint (&symfile_complaints
,
8858 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
8859 "block nor reference, for DIE 0x%x [in module %s]"),
8860 die
->offset
.sect_off
, objfile
->name
);
8862 call_site
->per_cu
= cu
->per_cu
;
8864 for (child_die
= die
->child
;
8865 child_die
&& child_die
->tag
;
8866 child_die
= sibling_die (child_die
))
8868 struct call_site_parameter
*parameter
;
8869 struct attribute
*loc
, *origin
;
8871 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8873 /* Already printed the complaint above. */
8877 gdb_assert (call_site
->parameter_count
< nparams
);
8878 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
8880 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
8881 specifies DW_TAG_formal_parameter. Value of the data assumed for the
8882 register is contained in DW_AT_GNU_call_site_value. */
8884 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
8885 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
8886 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
8890 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
8891 offset
= dwarf2_get_ref_die_offset (origin
);
8892 if (!offset_in_cu_p (&cu
->header
, offset
))
8894 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
8895 binding can be done only inside one CU. Such referenced DIE
8896 therefore cannot be even moved to DW_TAG_partial_unit. */
8897 complaint (&symfile_complaints
,
8898 _("DW_AT_abstract_origin offset is not in CU for "
8899 "DW_TAG_GNU_call_site child DIE 0x%x "
8901 child_die
->offset
.sect_off
, objfile
->name
);
8904 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
8905 - cu
->header
.offset
.sect_off
);
8907 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
8909 complaint (&symfile_complaints
,
8910 _("No DW_FORM_block* DW_AT_location for "
8911 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8912 child_die
->offset
.sect_off
, objfile
->name
);
8917 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
8918 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
8919 if (parameter
->u
.dwarf_reg
!= -1)
8920 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
8921 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
8922 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
8923 ¶meter
->u
.fb_offset
))
8924 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
8927 complaint (&symfile_complaints
,
8928 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
8929 "for DW_FORM_block* DW_AT_location is supported for "
8930 "DW_TAG_GNU_call_site child DIE 0x%x "
8932 child_die
->offset
.sect_off
, objfile
->name
);
8937 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
8938 if (!attr_form_is_block (attr
))
8940 complaint (&symfile_complaints
,
8941 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
8942 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8943 child_die
->offset
.sect_off
, objfile
->name
);
8946 parameter
->value
= DW_BLOCK (attr
)->data
;
8947 parameter
->value_size
= DW_BLOCK (attr
)->size
;
8949 /* Parameters are not pre-cleared by memset above. */
8950 parameter
->data_value
= NULL
;
8951 parameter
->data_value_size
= 0;
8952 call_site
->parameter_count
++;
8954 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
8957 if (!attr_form_is_block (attr
))
8958 complaint (&symfile_complaints
,
8959 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
8960 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8961 child_die
->offset
.sect_off
, objfile
->name
);
8964 parameter
->data_value
= DW_BLOCK (attr
)->data
;
8965 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
8971 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
8972 Return 1 if the attributes are present and valid, otherwise, return 0.
8973 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
8976 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
8977 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
8978 struct partial_symtab
*ranges_pst
)
8980 struct objfile
*objfile
= cu
->objfile
;
8981 struct comp_unit_head
*cu_header
= &cu
->header
;
8982 bfd
*obfd
= objfile
->obfd
;
8983 unsigned int addr_size
= cu_header
->addr_size
;
8984 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8985 /* Base address selection entry. */
8996 found_base
= cu
->base_known
;
8997 base
= cu
->base_address
;
8999 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9000 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9002 complaint (&symfile_complaints
,
9003 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9007 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9009 /* Read in the largest possible address. */
9010 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9011 if ((marker
& mask
) == mask
)
9013 /* If we found the largest possible address, then
9014 read the base address. */
9015 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9016 buffer
+= 2 * addr_size
;
9017 offset
+= 2 * addr_size
;
9023 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9027 CORE_ADDR range_beginning
, range_end
;
9029 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9030 buffer
+= addr_size
;
9031 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9032 buffer
+= addr_size
;
9033 offset
+= 2 * addr_size
;
9035 /* An end of list marker is a pair of zero addresses. */
9036 if (range_beginning
== 0 && range_end
== 0)
9037 /* Found the end of list entry. */
9040 /* Each base address selection entry is a pair of 2 values.
9041 The first is the largest possible address, the second is
9042 the base address. Check for a base address here. */
9043 if ((range_beginning
& mask
) == mask
)
9045 /* If we found the largest possible address, then
9046 read the base address. */
9047 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9054 /* We have no valid base address for the ranges
9056 complaint (&symfile_complaints
,
9057 _("Invalid .debug_ranges data (no base address)"));
9061 if (range_beginning
> range_end
)
9063 /* Inverted range entries are invalid. */
9064 complaint (&symfile_complaints
,
9065 _("Invalid .debug_ranges data (inverted range)"));
9069 /* Empty range entries have no effect. */
9070 if (range_beginning
== range_end
)
9073 range_beginning
+= base
;
9076 if (ranges_pst
!= NULL
)
9077 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9078 range_beginning
+ baseaddr
,
9079 range_end
- 1 + baseaddr
,
9082 /* FIXME: This is recording everything as a low-high
9083 segment of consecutive addresses. We should have a
9084 data structure for discontiguous block ranges
9088 low
= range_beginning
;
9094 if (range_beginning
< low
)
9095 low
= range_beginning
;
9096 if (range_end
> high
)
9102 /* If the first entry is an end-of-list marker, the range
9103 describes an empty scope, i.e. no instructions. */
9109 *high_return
= high
;
9113 /* Get low and high pc attributes from a die. Return 1 if the attributes
9114 are present and valid, otherwise, return 0. Return -1 if the range is
9115 discontinuous, i.e. derived from DW_AT_ranges information. */
9118 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
9119 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
9120 struct partial_symtab
*pst
)
9122 struct attribute
*attr
;
9123 struct attribute
*attr_high
;
9128 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9131 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9134 low
= DW_ADDR (attr
);
9135 if (attr_high
->form
== DW_FORM_addr
9136 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9137 high
= DW_ADDR (attr_high
);
9139 high
= low
+ DW_UNSND (attr_high
);
9142 /* Found high w/o low attribute. */
9145 /* Found consecutive range of addresses. */
9150 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9153 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9155 /* Value of the DW_AT_ranges attribute is the offset in the
9156 .debug_ranges section. */
9157 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
9159 /* Found discontinuous range of addresses. */
9164 /* read_partial_die has also the strict LOW < HIGH requirement. */
9168 /* When using the GNU linker, .gnu.linkonce. sections are used to
9169 eliminate duplicate copies of functions and vtables and such.
9170 The linker will arbitrarily choose one and discard the others.
9171 The AT_*_pc values for such functions refer to local labels in
9172 these sections. If the section from that file was discarded, the
9173 labels are not in the output, so the relocs get a value of 0.
9174 If this is a discarded function, mark the pc bounds as invalid,
9175 so that GDB will ignore it. */
9176 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9185 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
9186 its low and high PC addresses. Do nothing if these addresses could not
9187 be determined. Otherwise, set LOWPC to the low address if it is smaller,
9188 and HIGHPC to the high address if greater than HIGHPC. */
9191 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
9192 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9193 struct dwarf2_cu
*cu
)
9195 CORE_ADDR low
, high
;
9196 struct die_info
*child
= die
->child
;
9198 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
9200 *lowpc
= min (*lowpc
, low
);
9201 *highpc
= max (*highpc
, high
);
9204 /* If the language does not allow nested subprograms (either inside
9205 subprograms or lexical blocks), we're done. */
9206 if (cu
->language
!= language_ada
)
9209 /* Check all the children of the given DIE. If it contains nested
9210 subprograms, then check their pc bounds. Likewise, we need to
9211 check lexical blocks as well, as they may also contain subprogram
9213 while (child
&& child
->tag
)
9215 if (child
->tag
== DW_TAG_subprogram
9216 || child
->tag
== DW_TAG_lexical_block
)
9217 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
9218 child
= sibling_die (child
);
9222 /* Get the low and high pc's represented by the scope DIE, and store
9223 them in *LOWPC and *HIGHPC. If the correct values can't be
9224 determined, set *LOWPC to -1 and *HIGHPC to 0. */
9227 get_scope_pc_bounds (struct die_info
*die
,
9228 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9229 struct dwarf2_cu
*cu
)
9231 CORE_ADDR best_low
= (CORE_ADDR
) -1;
9232 CORE_ADDR best_high
= (CORE_ADDR
) 0;
9233 CORE_ADDR current_low
, current_high
;
9235 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
9237 best_low
= current_low
;
9238 best_high
= current_high
;
9242 struct die_info
*child
= die
->child
;
9244 while (child
&& child
->tag
)
9246 switch (child
->tag
) {
9247 case DW_TAG_subprogram
:
9248 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
9250 case DW_TAG_namespace
:
9252 /* FIXME: carlton/2004-01-16: Should we do this for
9253 DW_TAG_class_type/DW_TAG_structure_type, too? I think
9254 that current GCC's always emit the DIEs corresponding
9255 to definitions of methods of classes as children of a
9256 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
9257 the DIEs giving the declarations, which could be
9258 anywhere). But I don't see any reason why the
9259 standards says that they have to be there. */
9260 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
9262 if (current_low
!= ((CORE_ADDR
) -1))
9264 best_low
= min (best_low
, current_low
);
9265 best_high
= max (best_high
, current_high
);
9273 child
= sibling_die (child
);
9278 *highpc
= best_high
;
9281 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
9285 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
9286 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
9288 struct objfile
*objfile
= cu
->objfile
;
9289 struct attribute
*attr
;
9290 struct attribute
*attr_high
;
9292 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9295 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9298 CORE_ADDR low
= DW_ADDR (attr
);
9300 if (attr_high
->form
== DW_FORM_addr
9301 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9302 high
= DW_ADDR (attr_high
);
9304 high
= low
+ DW_UNSND (attr_high
);
9306 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
9310 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9313 bfd
*obfd
= objfile
->obfd
;
9315 /* The value of the DW_AT_ranges attribute is the offset of the
9316 address range list in the .debug_ranges section. */
9317 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9318 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9320 /* For some target architectures, but not others, the
9321 read_address function sign-extends the addresses it returns.
9322 To recognize base address selection entries, we need a
9324 unsigned int addr_size
= cu
->header
.addr_size
;
9325 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9327 /* The base address, to which the next pair is relative. Note
9328 that this 'base' is a DWARF concept: most entries in a range
9329 list are relative, to reduce the number of relocs against the
9330 debugging information. This is separate from this function's
9331 'baseaddr' argument, which GDB uses to relocate debugging
9332 information from a shared library based on the address at
9333 which the library was loaded. */
9334 CORE_ADDR base
= cu
->base_address
;
9335 int base_known
= cu
->base_known
;
9337 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
9338 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9340 complaint (&symfile_complaints
,
9341 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
9348 unsigned int bytes_read
;
9349 CORE_ADDR start
, end
;
9351 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9352 buffer
+= bytes_read
;
9353 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9354 buffer
+= bytes_read
;
9356 /* Did we find the end of the range list? */
9357 if (start
== 0 && end
== 0)
9360 /* Did we find a base address selection entry? */
9361 else if ((start
& base_select_mask
) == base_select_mask
)
9367 /* We found an ordinary address range. */
9372 complaint (&symfile_complaints
,
9373 _("Invalid .debug_ranges data "
9374 "(no base address)"));
9380 /* Inverted range entries are invalid. */
9381 complaint (&symfile_complaints
,
9382 _("Invalid .debug_ranges data "
9383 "(inverted range)"));
9387 /* Empty range entries have no effect. */
9391 record_block_range (block
,
9392 baseaddr
+ base
+ start
,
9393 baseaddr
+ base
+ end
- 1);
9399 /* Check whether the producer field indicates either of GCC < 4.6, or the
9400 Intel C/C++ compiler, and cache the result in CU. */
9403 check_producer (struct dwarf2_cu
*cu
)
9406 int major
, minor
, release
;
9408 if (cu
->producer
== NULL
)
9410 /* For unknown compilers expect their behavior is DWARF version
9413 GCC started to support .debug_types sections by -gdwarf-4 since
9414 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
9415 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
9416 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
9417 interpreted incorrectly by GDB now - GCC PR debug/48229. */
9419 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
9421 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
9423 cs
= &cu
->producer
[strlen ("GNU ")];
9424 while (*cs
&& !isdigit (*cs
))
9426 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
9428 /* Not recognized as GCC. */
9431 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
9433 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
9434 cu
->producer_is_icc
= 1;
9437 /* For other non-GCC compilers, expect their behavior is DWARF version
9441 cu
->checked_producer
= 1;
9444 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
9445 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
9446 during 4.6.0 experimental. */
9449 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
9451 if (!cu
->checked_producer
)
9452 check_producer (cu
);
9454 return cu
->producer_is_gxx_lt_4_6
;
9457 /* Return the default accessibility type if it is not overriden by
9458 DW_AT_accessibility. */
9460 static enum dwarf_access_attribute
9461 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
9463 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
9465 /* The default DWARF 2 accessibility for members is public, the default
9466 accessibility for inheritance is private. */
9468 if (die
->tag
!= DW_TAG_inheritance
)
9469 return DW_ACCESS_public
;
9471 return DW_ACCESS_private
;
9475 /* DWARF 3+ defines the default accessibility a different way. The same
9476 rules apply now for DW_TAG_inheritance as for the members and it only
9477 depends on the container kind. */
9479 if (die
->parent
->tag
== DW_TAG_class_type
)
9480 return DW_ACCESS_private
;
9482 return DW_ACCESS_public
;
9486 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
9487 offset. If the attribute was not found return 0, otherwise return
9488 1. If it was found but could not properly be handled, set *OFFSET
9492 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
9495 struct attribute
*attr
;
9497 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
9502 /* Note that we do not check for a section offset first here.
9503 This is because DW_AT_data_member_location is new in DWARF 4,
9504 so if we see it, we can assume that a constant form is really
9505 a constant and not a section offset. */
9506 if (attr_form_is_constant (attr
))
9507 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
9508 else if (attr_form_is_section_offset (attr
))
9509 dwarf2_complex_location_expr_complaint ();
9510 else if (attr_form_is_block (attr
))
9511 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9513 dwarf2_complex_location_expr_complaint ();
9521 /* Add an aggregate field to the field list. */
9524 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
9525 struct dwarf2_cu
*cu
)
9527 struct objfile
*objfile
= cu
->objfile
;
9528 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9529 struct nextfield
*new_field
;
9530 struct attribute
*attr
;
9532 char *fieldname
= "";
9534 /* Allocate a new field list entry and link it in. */
9535 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
9536 make_cleanup (xfree
, new_field
);
9537 memset (new_field
, 0, sizeof (struct nextfield
));
9539 if (die
->tag
== DW_TAG_inheritance
)
9541 new_field
->next
= fip
->baseclasses
;
9542 fip
->baseclasses
= new_field
;
9546 new_field
->next
= fip
->fields
;
9547 fip
->fields
= new_field
;
9551 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9553 new_field
->accessibility
= DW_UNSND (attr
);
9555 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
9556 if (new_field
->accessibility
!= DW_ACCESS_public
)
9557 fip
->non_public_fields
= 1;
9559 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9561 new_field
->virtuality
= DW_UNSND (attr
);
9563 new_field
->virtuality
= DW_VIRTUALITY_none
;
9565 fp
= &new_field
->field
;
9567 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
9571 /* Data member other than a C++ static data member. */
9573 /* Get type of field. */
9574 fp
->type
= die_type (die
, cu
);
9576 SET_FIELD_BITPOS (*fp
, 0);
9578 /* Get bit size of field (zero if none). */
9579 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
9582 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
9586 FIELD_BITSIZE (*fp
) = 0;
9589 /* Get bit offset of field. */
9590 if (handle_data_member_location (die
, cu
, &offset
))
9591 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9592 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
9595 if (gdbarch_bits_big_endian (gdbarch
))
9597 /* For big endian bits, the DW_AT_bit_offset gives the
9598 additional bit offset from the MSB of the containing
9599 anonymous object to the MSB of the field. We don't
9600 have to do anything special since we don't need to
9601 know the size of the anonymous object. */
9602 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
9606 /* For little endian bits, compute the bit offset to the
9607 MSB of the anonymous object, subtract off the number of
9608 bits from the MSB of the field to the MSB of the
9609 object, and then subtract off the number of bits of
9610 the field itself. The result is the bit offset of
9611 the LSB of the field. */
9613 int bit_offset
= DW_UNSND (attr
);
9615 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9618 /* The size of the anonymous object containing
9619 the bit field is explicit, so use the
9620 indicated size (in bytes). */
9621 anonymous_size
= DW_UNSND (attr
);
9625 /* The size of the anonymous object containing
9626 the bit field must be inferred from the type
9627 attribute of the data member containing the
9629 anonymous_size
= TYPE_LENGTH (fp
->type
);
9631 SET_FIELD_BITPOS (*fp
,
9633 + anonymous_size
* bits_per_byte
9634 - bit_offset
- FIELD_BITSIZE (*fp
)));
9638 /* Get name of field. */
9639 fieldname
= dwarf2_name (die
, cu
);
9640 if (fieldname
== NULL
)
9643 /* The name is already allocated along with this objfile, so we don't
9644 need to duplicate it for the type. */
9645 fp
->name
= fieldname
;
9647 /* Change accessibility for artificial fields (e.g. virtual table
9648 pointer or virtual base class pointer) to private. */
9649 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
9651 FIELD_ARTIFICIAL (*fp
) = 1;
9652 new_field
->accessibility
= DW_ACCESS_private
;
9653 fip
->non_public_fields
= 1;
9656 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
9658 /* C++ static member. */
9660 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
9661 is a declaration, but all versions of G++ as of this writing
9662 (so through at least 3.2.1) incorrectly generate
9663 DW_TAG_variable tags. */
9665 const char *physname
;
9667 /* Get name of field. */
9668 fieldname
= dwarf2_name (die
, cu
);
9669 if (fieldname
== NULL
)
9672 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9674 /* Only create a symbol if this is an external value.
9675 new_symbol checks this and puts the value in the global symbol
9676 table, which we want. If it is not external, new_symbol
9677 will try to put the value in cu->list_in_scope which is wrong. */
9678 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
9680 /* A static const member, not much different than an enum as far as
9681 we're concerned, except that we can support more types. */
9682 new_symbol (die
, NULL
, cu
);
9685 /* Get physical name. */
9686 physname
= dwarf2_physname (fieldname
, die
, cu
);
9688 /* The name is already allocated along with this objfile, so we don't
9689 need to duplicate it for the type. */
9690 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
9691 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9692 FIELD_NAME (*fp
) = fieldname
;
9694 else if (die
->tag
== DW_TAG_inheritance
)
9698 /* C++ base class field. */
9699 if (handle_data_member_location (die
, cu
, &offset
))
9700 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9701 FIELD_BITSIZE (*fp
) = 0;
9702 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9703 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
9704 fip
->nbaseclasses
++;
9708 /* Add a typedef defined in the scope of the FIP's class. */
9711 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
9712 struct dwarf2_cu
*cu
)
9714 struct objfile
*objfile
= cu
->objfile
;
9715 struct typedef_field_list
*new_field
;
9716 struct attribute
*attr
;
9717 struct typedef_field
*fp
;
9718 char *fieldname
= "";
9720 /* Allocate a new field list entry and link it in. */
9721 new_field
= xzalloc (sizeof (*new_field
));
9722 make_cleanup (xfree
, new_field
);
9724 gdb_assert (die
->tag
== DW_TAG_typedef
);
9726 fp
= &new_field
->field
;
9728 /* Get name of field. */
9729 fp
->name
= dwarf2_name (die
, cu
);
9730 if (fp
->name
== NULL
)
9733 fp
->type
= read_type_die (die
, cu
);
9735 new_field
->next
= fip
->typedef_field_list
;
9736 fip
->typedef_field_list
= new_field
;
9737 fip
->typedef_field_list_count
++;
9740 /* Create the vector of fields, and attach it to the type. */
9743 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
9744 struct dwarf2_cu
*cu
)
9746 int nfields
= fip
->nfields
;
9748 /* Record the field count, allocate space for the array of fields,
9749 and create blank accessibility bitfields if necessary. */
9750 TYPE_NFIELDS (type
) = nfields
;
9751 TYPE_FIELDS (type
) = (struct field
*)
9752 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
9753 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
9755 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
9757 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9759 TYPE_FIELD_PRIVATE_BITS (type
) =
9760 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9761 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
9763 TYPE_FIELD_PROTECTED_BITS (type
) =
9764 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9765 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
9767 TYPE_FIELD_IGNORE_BITS (type
) =
9768 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9769 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
9772 /* If the type has baseclasses, allocate and clear a bit vector for
9773 TYPE_FIELD_VIRTUAL_BITS. */
9774 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
9776 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
9777 unsigned char *pointer
;
9779 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9780 pointer
= TYPE_ALLOC (type
, num_bytes
);
9781 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
9782 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
9783 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
9786 /* Copy the saved-up fields into the field vector. Start from the head of
9787 the list, adding to the tail of the field array, so that they end up in
9788 the same order in the array in which they were added to the list. */
9789 while (nfields
-- > 0)
9791 struct nextfield
*fieldp
;
9795 fieldp
= fip
->fields
;
9796 fip
->fields
= fieldp
->next
;
9800 fieldp
= fip
->baseclasses
;
9801 fip
->baseclasses
= fieldp
->next
;
9804 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
9805 switch (fieldp
->accessibility
)
9807 case DW_ACCESS_private
:
9808 if (cu
->language
!= language_ada
)
9809 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
9812 case DW_ACCESS_protected
:
9813 if (cu
->language
!= language_ada
)
9814 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
9817 case DW_ACCESS_public
:
9821 /* Unknown accessibility. Complain and treat it as public. */
9823 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
9824 fieldp
->accessibility
);
9828 if (nfields
< fip
->nbaseclasses
)
9830 switch (fieldp
->virtuality
)
9832 case DW_VIRTUALITY_virtual
:
9833 case DW_VIRTUALITY_pure_virtual
:
9834 if (cu
->language
== language_ada
)
9835 error (_("unexpected virtuality in component of Ada type"));
9836 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
9843 /* Add a member function to the proper fieldlist. */
9846 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
9847 struct type
*type
, struct dwarf2_cu
*cu
)
9849 struct objfile
*objfile
= cu
->objfile
;
9850 struct attribute
*attr
;
9851 struct fnfieldlist
*flp
;
9853 struct fn_field
*fnp
;
9855 struct nextfnfield
*new_fnfield
;
9856 struct type
*this_type
;
9857 enum dwarf_access_attribute accessibility
;
9859 if (cu
->language
== language_ada
)
9860 error (_("unexpected member function in Ada type"));
9862 /* Get name of member function. */
9863 fieldname
= dwarf2_name (die
, cu
);
9864 if (fieldname
== NULL
)
9867 /* Look up member function name in fieldlist. */
9868 for (i
= 0; i
< fip
->nfnfields
; i
++)
9870 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
9874 /* Create new list element if necessary. */
9875 if (i
< fip
->nfnfields
)
9876 flp
= &fip
->fnfieldlists
[i
];
9879 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9881 fip
->fnfieldlists
= (struct fnfieldlist
*)
9882 xrealloc (fip
->fnfieldlists
,
9883 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
9884 * sizeof (struct fnfieldlist
));
9885 if (fip
->nfnfields
== 0)
9886 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
9888 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
9889 flp
->name
= fieldname
;
9892 i
= fip
->nfnfields
++;
9895 /* Create a new member function field and chain it to the field list
9897 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
9898 make_cleanup (xfree
, new_fnfield
);
9899 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
9900 new_fnfield
->next
= flp
->head
;
9901 flp
->head
= new_fnfield
;
9904 /* Fill in the member function field info. */
9905 fnp
= &new_fnfield
->fnfield
;
9907 /* Delay processing of the physname until later. */
9908 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
9910 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
9915 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
9916 fnp
->physname
= physname
? physname
: "";
9919 fnp
->type
= alloc_type (objfile
);
9920 this_type
= read_type_die (die
, cu
);
9921 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
9923 int nparams
= TYPE_NFIELDS (this_type
);
9925 /* TYPE is the domain of this method, and THIS_TYPE is the type
9926 of the method itself (TYPE_CODE_METHOD). */
9927 smash_to_method_type (fnp
->type
, type
,
9928 TYPE_TARGET_TYPE (this_type
),
9929 TYPE_FIELDS (this_type
),
9930 TYPE_NFIELDS (this_type
),
9931 TYPE_VARARGS (this_type
));
9933 /* Handle static member functions.
9934 Dwarf2 has no clean way to discern C++ static and non-static
9935 member functions. G++ helps GDB by marking the first
9936 parameter for non-static member functions (which is the this
9937 pointer) as artificial. We obtain this information from
9938 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
9939 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
9940 fnp
->voffset
= VOFFSET_STATIC
;
9943 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
9944 dwarf2_full_name (fieldname
, die
, cu
));
9946 /* Get fcontext from DW_AT_containing_type if present. */
9947 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9948 fnp
->fcontext
= die_containing_type (die
, cu
);
9950 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
9951 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
9953 /* Get accessibility. */
9954 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9956 accessibility
= DW_UNSND (attr
);
9958 accessibility
= dwarf2_default_access_attribute (die
, cu
);
9959 switch (accessibility
)
9961 case DW_ACCESS_private
:
9962 fnp
->is_private
= 1;
9964 case DW_ACCESS_protected
:
9965 fnp
->is_protected
= 1;
9969 /* Check for artificial methods. */
9970 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
9971 if (attr
&& DW_UNSND (attr
) != 0)
9972 fnp
->is_artificial
= 1;
9974 /* Get index in virtual function table if it is a virtual member
9975 function. For older versions of GCC, this is an offset in the
9976 appropriate virtual table, as specified by DW_AT_containing_type.
9977 For everyone else, it is an expression to be evaluated relative
9978 to the object address. */
9980 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
9983 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
9985 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
9987 /* Old-style GCC. */
9988 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
9990 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9991 || (DW_BLOCK (attr
)->size
> 1
9992 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
9993 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
9995 struct dwarf_block blk
;
9998 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10000 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10001 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10002 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10003 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10004 dwarf2_complex_location_expr_complaint ();
10006 fnp
->voffset
/= cu
->header
.addr_size
;
10010 dwarf2_complex_location_expr_complaint ();
10012 if (!fnp
->fcontext
)
10013 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10015 else if (attr_form_is_section_offset (attr
))
10017 dwarf2_complex_location_expr_complaint ();
10021 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10027 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10028 if (attr
&& DW_UNSND (attr
))
10030 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10031 complaint (&symfile_complaints
,
10032 _("Member function \"%s\" (offset %d) is virtual "
10033 "but the vtable offset is not specified"),
10034 fieldname
, die
->offset
.sect_off
);
10035 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10036 TYPE_CPLUS_DYNAMIC (type
) = 1;
10041 /* Create the vector of member function fields, and attach it to the type. */
10044 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10045 struct dwarf2_cu
*cu
)
10047 struct fnfieldlist
*flp
;
10050 if (cu
->language
== language_ada
)
10051 error (_("unexpected member functions in Ada type"));
10053 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10054 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
10055 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
10057 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
10059 struct nextfnfield
*nfp
= flp
->head
;
10060 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
10063 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
10064 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
10065 fn_flp
->fn_fields
= (struct fn_field
*)
10066 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
10067 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
10068 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
10071 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
10074 /* Returns non-zero if NAME is the name of a vtable member in CU's
10075 language, zero otherwise. */
10077 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
10079 static const char vptr
[] = "_vptr";
10080 static const char vtable
[] = "vtable";
10082 /* Look for the C++ and Java forms of the vtable. */
10083 if ((cu
->language
== language_java
10084 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
10085 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
10086 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
10092 /* GCC outputs unnamed structures that are really pointers to member
10093 functions, with the ABI-specified layout. If TYPE describes
10094 such a structure, smash it into a member function type.
10096 GCC shouldn't do this; it should just output pointer to member DIEs.
10097 This is GCC PR debug/28767. */
10100 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
10102 struct type
*pfn_type
, *domain_type
, *new_type
;
10104 /* Check for a structure with no name and two children. */
10105 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
10108 /* Check for __pfn and __delta members. */
10109 if (TYPE_FIELD_NAME (type
, 0) == NULL
10110 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
10111 || TYPE_FIELD_NAME (type
, 1) == NULL
10112 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
10115 /* Find the type of the method. */
10116 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
10117 if (pfn_type
== NULL
10118 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
10119 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
10122 /* Look for the "this" argument. */
10123 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
10124 if (TYPE_NFIELDS (pfn_type
) == 0
10125 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
10126 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
10129 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
10130 new_type
= alloc_type (objfile
);
10131 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
10132 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
10133 TYPE_VARARGS (pfn_type
));
10134 smash_to_methodptr_type (type
, new_type
);
10137 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
10141 producer_is_icc (struct dwarf2_cu
*cu
)
10143 if (!cu
->checked_producer
)
10144 check_producer (cu
);
10146 return cu
->producer_is_icc
;
10149 /* Called when we find the DIE that starts a structure or union scope
10150 (definition) to create a type for the structure or union. Fill in
10151 the type's name and general properties; the members will not be
10152 processed until process_structure_type.
10154 NOTE: we need to call these functions regardless of whether or not the
10155 DIE has a DW_AT_name attribute, since it might be an anonymous
10156 structure or union. This gets the type entered into our set of
10157 user defined types.
10159 However, if the structure is incomplete (an opaque struct/union)
10160 then suppress creating a symbol table entry for it since gdb only
10161 wants to find the one with the complete definition. Note that if
10162 it is complete, we just call new_symbol, which does it's own
10163 checking about whether the struct/union is anonymous or not (and
10164 suppresses creating a symbol table entry itself). */
10166 static struct type
*
10167 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10169 struct objfile
*objfile
= cu
->objfile
;
10171 struct attribute
*attr
;
10174 /* If the definition of this type lives in .debug_types, read that type.
10175 Don't follow DW_AT_specification though, that will take us back up
10176 the chain and we want to go down. */
10177 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10180 struct dwarf2_cu
*type_cu
= cu
;
10181 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10183 /* We could just recurse on read_structure_type, but we need to call
10184 get_die_type to ensure only one type for this DIE is created.
10185 This is important, for example, because for c++ classes we need
10186 TYPE_NAME set which is only done by new_symbol. Blech. */
10187 type
= read_type_die (type_die
, type_cu
);
10189 /* TYPE_CU may not be the same as CU.
10190 Ensure TYPE is recorded in CU's type_hash table. */
10191 return set_die_type (die
, type
, cu
);
10194 type
= alloc_type (objfile
);
10195 INIT_CPLUS_SPECIFIC (type
);
10197 name
= dwarf2_name (die
, cu
);
10200 if (cu
->language
== language_cplus
10201 || cu
->language
== language_java
)
10203 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
10205 /* dwarf2_full_name might have already finished building the DIE's
10206 type. If so, there is no need to continue. */
10207 if (get_die_type (die
, cu
) != NULL
)
10208 return get_die_type (die
, cu
);
10210 TYPE_TAG_NAME (type
) = full_name
;
10211 if (die
->tag
== DW_TAG_structure_type
10212 || die
->tag
== DW_TAG_class_type
)
10213 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10217 /* The name is already allocated along with this objfile, so
10218 we don't need to duplicate it for the type. */
10219 TYPE_TAG_NAME (type
) = (char *) name
;
10220 if (die
->tag
== DW_TAG_class_type
)
10221 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10225 if (die
->tag
== DW_TAG_structure_type
)
10227 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10229 else if (die
->tag
== DW_TAG_union_type
)
10231 TYPE_CODE (type
) = TYPE_CODE_UNION
;
10235 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
10238 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
10239 TYPE_DECLARED_CLASS (type
) = 1;
10241 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10244 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10248 TYPE_LENGTH (type
) = 0;
10251 if (producer_is_icc (cu
))
10253 /* ICC does not output the required DW_AT_declaration
10254 on incomplete types, but gives them a size of zero. */
10257 TYPE_STUB_SUPPORTED (type
) = 1;
10259 if (die_is_declaration (die
, cu
))
10260 TYPE_STUB (type
) = 1;
10261 else if (attr
== NULL
&& die
->child
== NULL
10262 && producer_is_realview (cu
->producer
))
10263 /* RealView does not output the required DW_AT_declaration
10264 on incomplete types. */
10265 TYPE_STUB (type
) = 1;
10267 /* We need to add the type field to the die immediately so we don't
10268 infinitely recurse when dealing with pointers to the structure
10269 type within the structure itself. */
10270 set_die_type (die
, type
, cu
);
10272 /* set_die_type should be already done. */
10273 set_descriptive_type (type
, die
, cu
);
10278 /* Finish creating a structure or union type, including filling in
10279 its members and creating a symbol for it. */
10282 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10284 struct objfile
*objfile
= cu
->objfile
;
10285 struct die_info
*child_die
= die
->child
;
10288 type
= get_die_type (die
, cu
);
10290 type
= read_structure_type (die
, cu
);
10292 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
10294 struct field_info fi
;
10295 struct die_info
*child_die
;
10296 VEC (symbolp
) *template_args
= NULL
;
10297 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
10299 memset (&fi
, 0, sizeof (struct field_info
));
10301 child_die
= die
->child
;
10303 while (child_die
&& child_die
->tag
)
10305 if (child_die
->tag
== DW_TAG_member
10306 || child_die
->tag
== DW_TAG_variable
)
10308 /* NOTE: carlton/2002-11-05: A C++ static data member
10309 should be a DW_TAG_member that is a declaration, but
10310 all versions of G++ as of this writing (so through at
10311 least 3.2.1) incorrectly generate DW_TAG_variable
10312 tags for them instead. */
10313 dwarf2_add_field (&fi
, child_die
, cu
);
10315 else if (child_die
->tag
== DW_TAG_subprogram
)
10317 /* C++ member function. */
10318 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
10320 else if (child_die
->tag
== DW_TAG_inheritance
)
10322 /* C++ base class field. */
10323 dwarf2_add_field (&fi
, child_die
, cu
);
10325 else if (child_die
->tag
== DW_TAG_typedef
)
10326 dwarf2_add_typedef (&fi
, child_die
, cu
);
10327 else if (child_die
->tag
== DW_TAG_template_type_param
10328 || child_die
->tag
== DW_TAG_template_value_param
)
10330 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10333 VEC_safe_push (symbolp
, template_args
, arg
);
10336 child_die
= sibling_die (child_die
);
10339 /* Attach template arguments to type. */
10340 if (! VEC_empty (symbolp
, template_args
))
10342 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10343 TYPE_N_TEMPLATE_ARGUMENTS (type
)
10344 = VEC_length (symbolp
, template_args
);
10345 TYPE_TEMPLATE_ARGUMENTS (type
)
10346 = obstack_alloc (&objfile
->objfile_obstack
,
10347 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10348 * sizeof (struct symbol
*)));
10349 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
10350 VEC_address (symbolp
, template_args
),
10351 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10352 * sizeof (struct symbol
*)));
10353 VEC_free (symbolp
, template_args
);
10356 /* Attach fields and member functions to the type. */
10358 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
10361 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
10363 /* Get the type which refers to the base class (possibly this
10364 class itself) which contains the vtable pointer for the current
10365 class from the DW_AT_containing_type attribute. This use of
10366 DW_AT_containing_type is a GNU extension. */
10368 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10370 struct type
*t
= die_containing_type (die
, cu
);
10372 TYPE_VPTR_BASETYPE (type
) = t
;
10377 /* Our own class provides vtbl ptr. */
10378 for (i
= TYPE_NFIELDS (t
) - 1;
10379 i
>= TYPE_N_BASECLASSES (t
);
10382 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
10384 if (is_vtable_name (fieldname
, cu
))
10386 TYPE_VPTR_FIELDNO (type
) = i
;
10391 /* Complain if virtual function table field not found. */
10392 if (i
< TYPE_N_BASECLASSES (t
))
10393 complaint (&symfile_complaints
,
10394 _("virtual function table pointer "
10395 "not found when defining class '%s'"),
10396 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
10401 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
10404 else if (cu
->producer
10405 && strncmp (cu
->producer
,
10406 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
10408 /* The IBM XLC compiler does not provide direct indication
10409 of the containing type, but the vtable pointer is
10410 always named __vfp. */
10414 for (i
= TYPE_NFIELDS (type
) - 1;
10415 i
>= TYPE_N_BASECLASSES (type
);
10418 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
10420 TYPE_VPTR_FIELDNO (type
) = i
;
10421 TYPE_VPTR_BASETYPE (type
) = type
;
10428 /* Copy fi.typedef_field_list linked list elements content into the
10429 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
10430 if (fi
.typedef_field_list
)
10432 int i
= fi
.typedef_field_list_count
;
10434 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10435 TYPE_TYPEDEF_FIELD_ARRAY (type
)
10436 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
10437 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
10439 /* Reverse the list order to keep the debug info elements order. */
10442 struct typedef_field
*dest
, *src
;
10444 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
10445 src
= &fi
.typedef_field_list
->field
;
10446 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
10451 do_cleanups (back_to
);
10453 if (HAVE_CPLUS_STRUCT (type
))
10454 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
10457 quirk_gcc_member_function_pointer (type
, objfile
);
10459 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
10460 snapshots) has been known to create a die giving a declaration
10461 for a class that has, as a child, a die giving a definition for a
10462 nested class. So we have to process our children even if the
10463 current die is a declaration. Normally, of course, a declaration
10464 won't have any children at all. */
10466 while (child_die
!= NULL
&& child_die
->tag
)
10468 if (child_die
->tag
== DW_TAG_member
10469 || child_die
->tag
== DW_TAG_variable
10470 || child_die
->tag
== DW_TAG_inheritance
10471 || child_die
->tag
== DW_TAG_template_value_param
10472 || child_die
->tag
== DW_TAG_template_type_param
)
10477 process_die (child_die
, cu
);
10479 child_die
= sibling_die (child_die
);
10482 /* Do not consider external references. According to the DWARF standard,
10483 these DIEs are identified by the fact that they have no byte_size
10484 attribute, and a declaration attribute. */
10485 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
10486 || !die_is_declaration (die
, cu
))
10487 new_symbol (die
, type
, cu
);
10490 /* Given a DW_AT_enumeration_type die, set its type. We do not
10491 complete the type's fields yet, or create any symbols. */
10493 static struct type
*
10494 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10496 struct objfile
*objfile
= cu
->objfile
;
10498 struct attribute
*attr
;
10501 /* If the definition of this type lives in .debug_types, read that type.
10502 Don't follow DW_AT_specification though, that will take us back up
10503 the chain and we want to go down. */
10504 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10507 struct dwarf2_cu
*type_cu
= cu
;
10508 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10510 type
= read_type_die (type_die
, type_cu
);
10512 /* TYPE_CU may not be the same as CU.
10513 Ensure TYPE is recorded in CU's type_hash table. */
10514 return set_die_type (die
, type
, cu
);
10517 type
= alloc_type (objfile
);
10519 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
10520 name
= dwarf2_full_name (NULL
, die
, cu
);
10522 TYPE_TAG_NAME (type
) = (char *) name
;
10524 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10527 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10531 TYPE_LENGTH (type
) = 0;
10534 /* The enumeration DIE can be incomplete. In Ada, any type can be
10535 declared as private in the package spec, and then defined only
10536 inside the package body. Such types are known as Taft Amendment
10537 Types. When another package uses such a type, an incomplete DIE
10538 may be generated by the compiler. */
10539 if (die_is_declaration (die
, cu
))
10540 TYPE_STUB (type
) = 1;
10542 return set_die_type (die
, type
, cu
);
10545 /* Given a pointer to a die which begins an enumeration, process all
10546 the dies that define the members of the enumeration, and create the
10547 symbol for the enumeration type.
10549 NOTE: We reverse the order of the element list. */
10552 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10554 struct type
*this_type
;
10556 this_type
= get_die_type (die
, cu
);
10557 if (this_type
== NULL
)
10558 this_type
= read_enumeration_type (die
, cu
);
10560 if (die
->child
!= NULL
)
10562 struct die_info
*child_die
;
10563 struct symbol
*sym
;
10564 struct field
*fields
= NULL
;
10565 int num_fields
= 0;
10566 int unsigned_enum
= 1;
10571 child_die
= die
->child
;
10572 while (child_die
&& child_die
->tag
)
10574 if (child_die
->tag
!= DW_TAG_enumerator
)
10576 process_die (child_die
, cu
);
10580 name
= dwarf2_name (child_die
, cu
);
10583 sym
= new_symbol (child_die
, this_type
, cu
);
10584 if (SYMBOL_VALUE (sym
) < 0)
10589 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
10592 mask
|= SYMBOL_VALUE (sym
);
10594 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10596 fields
= (struct field
*)
10598 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
10599 * sizeof (struct field
));
10602 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
10603 FIELD_TYPE (fields
[num_fields
]) = NULL
;
10604 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
10605 FIELD_BITSIZE (fields
[num_fields
]) = 0;
10611 child_die
= sibling_die (child_die
);
10616 TYPE_NFIELDS (this_type
) = num_fields
;
10617 TYPE_FIELDS (this_type
) = (struct field
*)
10618 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
10619 memcpy (TYPE_FIELDS (this_type
), fields
,
10620 sizeof (struct field
) * num_fields
);
10624 TYPE_UNSIGNED (this_type
) = 1;
10626 TYPE_FLAG_ENUM (this_type
) = 1;
10629 /* If we are reading an enum from a .debug_types unit, and the enum
10630 is a declaration, and the enum is not the signatured type in the
10631 unit, then we do not want to add a symbol for it. Adding a
10632 symbol would in some cases obscure the true definition of the
10633 enum, giving users an incomplete type when the definition is
10634 actually available. Note that we do not want to do this for all
10635 enums which are just declarations, because C++0x allows forward
10636 enum declarations. */
10637 if (cu
->per_cu
->is_debug_types
10638 && die_is_declaration (die
, cu
))
10640 struct signatured_type
*sig_type
;
10643 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
10644 cu
->per_cu
->info_or_types_section
,
10645 cu
->per_cu
->offset
);
10646 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
10647 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
10651 new_symbol (die
, this_type
, cu
);
10654 /* Extract all information from a DW_TAG_array_type DIE and put it in
10655 the DIE's type field. For now, this only handles one dimensional
10658 static struct type
*
10659 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10661 struct objfile
*objfile
= cu
->objfile
;
10662 struct die_info
*child_die
;
10664 struct type
*element_type
, *range_type
, *index_type
;
10665 struct type
**range_types
= NULL
;
10666 struct attribute
*attr
;
10668 struct cleanup
*back_to
;
10671 element_type
= die_type (die
, cu
);
10673 /* The die_type call above may have already set the type for this DIE. */
10674 type
= get_die_type (die
, cu
);
10678 /* Irix 6.2 native cc creates array types without children for
10679 arrays with unspecified length. */
10680 if (die
->child
== NULL
)
10682 index_type
= objfile_type (objfile
)->builtin_int
;
10683 range_type
= create_range_type (NULL
, index_type
, 0, -1);
10684 type
= create_array_type (NULL
, element_type
, range_type
);
10685 return set_die_type (die
, type
, cu
);
10688 back_to
= make_cleanup (null_cleanup
, NULL
);
10689 child_die
= die
->child
;
10690 while (child_die
&& child_die
->tag
)
10692 if (child_die
->tag
== DW_TAG_subrange_type
)
10694 struct type
*child_type
= read_type_die (child_die
, cu
);
10696 if (child_type
!= NULL
)
10698 /* The range type was succesfully read. Save it for the
10699 array type creation. */
10700 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
10702 range_types
= (struct type
**)
10703 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
10704 * sizeof (struct type
*));
10706 make_cleanup (free_current_contents
, &range_types
);
10708 range_types
[ndim
++] = child_type
;
10711 child_die
= sibling_die (child_die
);
10714 /* Dwarf2 dimensions are output from left to right, create the
10715 necessary array types in backwards order. */
10717 type
= element_type
;
10719 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
10724 type
= create_array_type (NULL
, type
, range_types
[i
++]);
10729 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
10732 /* Understand Dwarf2 support for vector types (like they occur on
10733 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
10734 array type. This is not part of the Dwarf2/3 standard yet, but a
10735 custom vendor extension. The main difference between a regular
10736 array and the vector variant is that vectors are passed by value
10738 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
10740 make_vector_type (type
);
10742 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
10743 implementation may choose to implement triple vectors using this
10745 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10748 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
10749 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10751 complaint (&symfile_complaints
,
10752 _("DW_AT_byte_size for array type smaller "
10753 "than the total size of elements"));
10756 name
= dwarf2_name (die
, cu
);
10758 TYPE_NAME (type
) = name
;
10760 /* Install the type in the die. */
10761 set_die_type (die
, type
, cu
);
10763 /* set_die_type should be already done. */
10764 set_descriptive_type (type
, die
, cu
);
10766 do_cleanups (back_to
);
10771 static enum dwarf_array_dim_ordering
10772 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
10774 struct attribute
*attr
;
10776 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
10778 if (attr
) return DW_SND (attr
);
10780 /* GNU F77 is a special case, as at 08/2004 array type info is the
10781 opposite order to the dwarf2 specification, but data is still
10782 laid out as per normal fortran.
10784 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
10785 version checking. */
10787 if (cu
->language
== language_fortran
10788 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
10790 return DW_ORD_row_major
;
10793 switch (cu
->language_defn
->la_array_ordering
)
10795 case array_column_major
:
10796 return DW_ORD_col_major
;
10797 case array_row_major
:
10799 return DW_ORD_row_major
;
10803 /* Extract all information from a DW_TAG_set_type DIE and put it in
10804 the DIE's type field. */
10806 static struct type
*
10807 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10809 struct type
*domain_type
, *set_type
;
10810 struct attribute
*attr
;
10812 domain_type
= die_type (die
, cu
);
10814 /* The die_type call above may have already set the type for this DIE. */
10815 set_type
= get_die_type (die
, cu
);
10819 set_type
= create_set_type (NULL
, domain_type
);
10821 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10823 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
10825 return set_die_type (die
, set_type
, cu
);
10828 /* First cut: install each common block member as a global variable. */
10831 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
10833 struct die_info
*child_die
;
10834 struct attribute
*attr
;
10835 struct symbol
*sym
;
10836 CORE_ADDR base
= (CORE_ADDR
) 0;
10838 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10841 /* Support the .debug_loc offsets. */
10842 if (attr_form_is_block (attr
))
10844 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
10846 else if (attr_form_is_section_offset (attr
))
10848 dwarf2_complex_location_expr_complaint ();
10852 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10853 "common block member");
10856 if (die
->child
!= NULL
)
10858 child_die
= die
->child
;
10859 while (child_die
&& child_die
->tag
)
10863 sym
= new_symbol (child_die
, NULL
, cu
);
10865 && handle_data_member_location (child_die
, cu
, &offset
))
10867 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
10868 add_symbol_to_list (sym
, &global_symbols
);
10870 child_die
= sibling_die (child_die
);
10875 /* Create a type for a C++ namespace. */
10877 static struct type
*
10878 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10880 struct objfile
*objfile
= cu
->objfile
;
10881 const char *previous_prefix
, *name
;
10885 /* For extensions, reuse the type of the original namespace. */
10886 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
10888 struct die_info
*ext_die
;
10889 struct dwarf2_cu
*ext_cu
= cu
;
10891 ext_die
= dwarf2_extension (die
, &ext_cu
);
10892 type
= read_type_die (ext_die
, ext_cu
);
10894 /* EXT_CU may not be the same as CU.
10895 Ensure TYPE is recorded in CU's type_hash table. */
10896 return set_die_type (die
, type
, cu
);
10899 name
= namespace_name (die
, &is_anonymous
, cu
);
10901 /* Now build the name of the current namespace. */
10903 previous_prefix
= determine_prefix (die
, cu
);
10904 if (previous_prefix
[0] != '\0')
10905 name
= typename_concat (&objfile
->objfile_obstack
,
10906 previous_prefix
, name
, 0, cu
);
10908 /* Create the type. */
10909 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
10911 TYPE_NAME (type
) = (char *) name
;
10912 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10914 return set_die_type (die
, type
, cu
);
10917 /* Read a C++ namespace. */
10920 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10922 struct objfile
*objfile
= cu
->objfile
;
10925 /* Add a symbol associated to this if we haven't seen the namespace
10926 before. Also, add a using directive if it's an anonymous
10929 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
10933 type
= read_type_die (die
, cu
);
10934 new_symbol (die
, type
, cu
);
10936 namespace_name (die
, &is_anonymous
, cu
);
10939 const char *previous_prefix
= determine_prefix (die
, cu
);
10941 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
10942 NULL
, NULL
, &objfile
->objfile_obstack
);
10946 if (die
->child
!= NULL
)
10948 struct die_info
*child_die
= die
->child
;
10950 while (child_die
&& child_die
->tag
)
10952 process_die (child_die
, cu
);
10953 child_die
= sibling_die (child_die
);
10958 /* Read a Fortran module as type. This DIE can be only a declaration used for
10959 imported module. Still we need that type as local Fortran "use ... only"
10960 declaration imports depend on the created type in determine_prefix. */
10962 static struct type
*
10963 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10965 struct objfile
*objfile
= cu
->objfile
;
10969 module_name
= dwarf2_name (die
, cu
);
10971 complaint (&symfile_complaints
,
10972 _("DW_TAG_module has no name, offset 0x%x"),
10973 die
->offset
.sect_off
);
10974 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
10976 /* determine_prefix uses TYPE_TAG_NAME. */
10977 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10979 return set_die_type (die
, type
, cu
);
10982 /* Read a Fortran module. */
10985 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
10987 struct die_info
*child_die
= die
->child
;
10989 while (child_die
&& child_die
->tag
)
10991 process_die (child_die
, cu
);
10992 child_die
= sibling_die (child_die
);
10996 /* Return the name of the namespace represented by DIE. Set
10997 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
11000 static const char *
11001 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
11003 struct die_info
*current_die
;
11004 const char *name
= NULL
;
11006 /* Loop through the extensions until we find a name. */
11008 for (current_die
= die
;
11009 current_die
!= NULL
;
11010 current_die
= dwarf2_extension (die
, &cu
))
11012 name
= dwarf2_name (current_die
, cu
);
11017 /* Is it an anonymous namespace? */
11019 *is_anonymous
= (name
== NULL
);
11021 name
= CP_ANONYMOUS_NAMESPACE_STR
;
11026 /* Extract all information from a DW_TAG_pointer_type DIE and add to
11027 the user defined type vector. */
11029 static struct type
*
11030 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11032 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
11033 struct comp_unit_head
*cu_header
= &cu
->header
;
11035 struct attribute
*attr_byte_size
;
11036 struct attribute
*attr_address_class
;
11037 int byte_size
, addr_class
;
11038 struct type
*target_type
;
11040 target_type
= die_type (die
, cu
);
11042 /* The die_type call above may have already set the type for this DIE. */
11043 type
= get_die_type (die
, cu
);
11047 type
= lookup_pointer_type (target_type
);
11049 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11050 if (attr_byte_size
)
11051 byte_size
= DW_UNSND (attr_byte_size
);
11053 byte_size
= cu_header
->addr_size
;
11055 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
11056 if (attr_address_class
)
11057 addr_class
= DW_UNSND (attr_address_class
);
11059 addr_class
= DW_ADDR_none
;
11061 /* If the pointer size or address class is different than the
11062 default, create a type variant marked as such and set the
11063 length accordingly. */
11064 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
11066 if (gdbarch_address_class_type_flags_p (gdbarch
))
11070 type_flags
= gdbarch_address_class_type_flags
11071 (gdbarch
, byte_size
, addr_class
);
11072 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
11074 type
= make_type_with_address_space (type
, type_flags
);
11076 else if (TYPE_LENGTH (type
) != byte_size
)
11078 complaint (&symfile_complaints
,
11079 _("invalid pointer size %d"), byte_size
);
11083 /* Should we also complain about unhandled address classes? */
11087 TYPE_LENGTH (type
) = byte_size
;
11088 return set_die_type (die
, type
, cu
);
11091 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
11092 the user defined type vector. */
11094 static struct type
*
11095 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11098 struct type
*to_type
;
11099 struct type
*domain
;
11101 to_type
= die_type (die
, cu
);
11102 domain
= die_containing_type (die
, cu
);
11104 /* The calls above may have already set the type for this DIE. */
11105 type
= get_die_type (die
, cu
);
11109 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
11110 type
= lookup_methodptr_type (to_type
);
11112 type
= lookup_memberptr_type (to_type
, domain
);
11114 return set_die_type (die
, type
, cu
);
11117 /* Extract all information from a DW_TAG_reference_type DIE and add to
11118 the user defined type vector. */
11120 static struct type
*
11121 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11123 struct comp_unit_head
*cu_header
= &cu
->header
;
11124 struct type
*type
, *target_type
;
11125 struct attribute
*attr
;
11127 target_type
= die_type (die
, cu
);
11129 /* The die_type call above may have already set the type for this DIE. */
11130 type
= get_die_type (die
, cu
);
11134 type
= lookup_reference_type (target_type
);
11135 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11138 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11142 TYPE_LENGTH (type
) = cu_header
->addr_size
;
11144 return set_die_type (die
, type
, cu
);
11147 static struct type
*
11148 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11150 struct type
*base_type
, *cv_type
;
11152 base_type
= die_type (die
, cu
);
11154 /* The die_type call above may have already set the type for this DIE. */
11155 cv_type
= get_die_type (die
, cu
);
11159 /* In case the const qualifier is applied to an array type, the element type
11160 is so qualified, not the array type (section 6.7.3 of C99). */
11161 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
11163 struct type
*el_type
, *inner_array
;
11165 base_type
= copy_type (base_type
);
11166 inner_array
= base_type
;
11168 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
11170 TYPE_TARGET_TYPE (inner_array
) =
11171 copy_type (TYPE_TARGET_TYPE (inner_array
));
11172 inner_array
= TYPE_TARGET_TYPE (inner_array
);
11175 el_type
= TYPE_TARGET_TYPE (inner_array
);
11176 TYPE_TARGET_TYPE (inner_array
) =
11177 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
11179 return set_die_type (die
, base_type
, cu
);
11182 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
11183 return set_die_type (die
, cv_type
, cu
);
11186 static struct type
*
11187 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11189 struct type
*base_type
, *cv_type
;
11191 base_type
= die_type (die
, cu
);
11193 /* The die_type call above may have already set the type for this DIE. */
11194 cv_type
= get_die_type (die
, cu
);
11198 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
11199 return set_die_type (die
, cv_type
, cu
);
11202 /* Extract all information from a DW_TAG_string_type DIE and add to
11203 the user defined type vector. It isn't really a user defined type,
11204 but it behaves like one, with other DIE's using an AT_user_def_type
11205 attribute to reference it. */
11207 static struct type
*
11208 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11210 struct objfile
*objfile
= cu
->objfile
;
11211 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11212 struct type
*type
, *range_type
, *index_type
, *char_type
;
11213 struct attribute
*attr
;
11214 unsigned int length
;
11216 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
11219 length
= DW_UNSND (attr
);
11223 /* Check for the DW_AT_byte_size attribute. */
11224 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11227 length
= DW_UNSND (attr
);
11235 index_type
= objfile_type (objfile
)->builtin_int
;
11236 range_type
= create_range_type (NULL
, index_type
, 1, length
);
11237 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
11238 type
= create_string_type (NULL
, char_type
, range_type
);
11240 return set_die_type (die
, type
, cu
);
11243 /* Handle DIES due to C code like:
11247 int (*funcp)(int a, long l);
11251 ('funcp' generates a DW_TAG_subroutine_type DIE). */
11253 static struct type
*
11254 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11256 struct objfile
*objfile
= cu
->objfile
;
11257 struct type
*type
; /* Type that this function returns. */
11258 struct type
*ftype
; /* Function that returns above type. */
11259 struct attribute
*attr
;
11261 type
= die_type (die
, cu
);
11263 /* The die_type call above may have already set the type for this DIE. */
11264 ftype
= get_die_type (die
, cu
);
11268 ftype
= lookup_function_type (type
);
11270 /* All functions in C++, Pascal and Java have prototypes. */
11271 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
11272 if ((attr
&& (DW_UNSND (attr
) != 0))
11273 || cu
->language
== language_cplus
11274 || cu
->language
== language_java
11275 || cu
->language
== language_pascal
)
11276 TYPE_PROTOTYPED (ftype
) = 1;
11277 else if (producer_is_realview (cu
->producer
))
11278 /* RealView does not emit DW_AT_prototyped. We can not
11279 distinguish prototyped and unprototyped functions; default to
11280 prototyped, since that is more common in modern code (and
11281 RealView warns about unprototyped functions). */
11282 TYPE_PROTOTYPED (ftype
) = 1;
11284 /* Store the calling convention in the type if it's available in
11285 the subroutine die. Otherwise set the calling convention to
11286 the default value DW_CC_normal. */
11287 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
11289 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
11290 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
11291 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
11293 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
11295 /* We need to add the subroutine type to the die immediately so
11296 we don't infinitely recurse when dealing with parameters
11297 declared as the same subroutine type. */
11298 set_die_type (die
, ftype
, cu
);
11300 if (die
->child
!= NULL
)
11302 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
11303 struct die_info
*child_die
;
11304 int nparams
, iparams
;
11306 /* Count the number of parameters.
11307 FIXME: GDB currently ignores vararg functions, but knows about
11308 vararg member functions. */
11310 child_die
= die
->child
;
11311 while (child_die
&& child_die
->tag
)
11313 if (child_die
->tag
== DW_TAG_formal_parameter
)
11315 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
11316 TYPE_VARARGS (ftype
) = 1;
11317 child_die
= sibling_die (child_die
);
11320 /* Allocate storage for parameters and fill them in. */
11321 TYPE_NFIELDS (ftype
) = nparams
;
11322 TYPE_FIELDS (ftype
) = (struct field
*)
11323 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
11325 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
11326 even if we error out during the parameters reading below. */
11327 for (iparams
= 0; iparams
< nparams
; iparams
++)
11328 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
11331 child_die
= die
->child
;
11332 while (child_die
&& child_die
->tag
)
11334 if (child_die
->tag
== DW_TAG_formal_parameter
)
11336 struct type
*arg_type
;
11338 /* DWARF version 2 has no clean way to discern C++
11339 static and non-static member functions. G++ helps
11340 GDB by marking the first parameter for non-static
11341 member functions (which is the this pointer) as
11342 artificial. We pass this information to
11343 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
11345 DWARF version 3 added DW_AT_object_pointer, which GCC
11346 4.5 does not yet generate. */
11347 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
11349 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
11352 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
11354 /* GCC/43521: In java, the formal parameter
11355 "this" is sometimes not marked with DW_AT_artificial. */
11356 if (cu
->language
== language_java
)
11358 const char *name
= dwarf2_name (child_die
, cu
);
11360 if (name
&& !strcmp (name
, "this"))
11361 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
11364 arg_type
= die_type (child_die
, cu
);
11366 /* RealView does not mark THIS as const, which the testsuite
11367 expects. GCC marks THIS as const in method definitions,
11368 but not in the class specifications (GCC PR 43053). */
11369 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
11370 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
11373 struct dwarf2_cu
*arg_cu
= cu
;
11374 const char *name
= dwarf2_name (child_die
, cu
);
11376 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
11379 /* If the compiler emits this, use it. */
11380 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
11383 else if (name
&& strcmp (name
, "this") == 0)
11384 /* Function definitions will have the argument names. */
11386 else if (name
== NULL
&& iparams
== 0)
11387 /* Declarations may not have the names, so like
11388 elsewhere in GDB, assume an artificial first
11389 argument is "this". */
11393 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
11397 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
11400 child_die
= sibling_die (child_die
);
11407 static struct type
*
11408 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
11410 struct objfile
*objfile
= cu
->objfile
;
11411 const char *name
= NULL
;
11412 struct type
*this_type
, *target_type
;
11414 name
= dwarf2_full_name (NULL
, die
, cu
);
11415 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
11416 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
11417 TYPE_NAME (this_type
) = (char *) name
;
11418 set_die_type (die
, this_type
, cu
);
11419 target_type
= die_type (die
, cu
);
11420 if (target_type
!= this_type
)
11421 TYPE_TARGET_TYPE (this_type
) = target_type
;
11424 /* Self-referential typedefs are, it seems, not allowed by the DWARF
11425 spec and cause infinite loops in GDB. */
11426 complaint (&symfile_complaints
,
11427 _("Self-referential DW_TAG_typedef "
11428 "- DIE at 0x%x [in module %s]"),
11429 die
->offset
.sect_off
, objfile
->name
);
11430 TYPE_TARGET_TYPE (this_type
) = NULL
;
11435 /* Find a representation of a given base type and install
11436 it in the TYPE field of the die. */
11438 static struct type
*
11439 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11441 struct objfile
*objfile
= cu
->objfile
;
11443 struct attribute
*attr
;
11444 int encoding
= 0, size
= 0;
11446 enum type_code code
= TYPE_CODE_INT
;
11447 int type_flags
= 0;
11448 struct type
*target_type
= NULL
;
11450 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
11453 encoding
= DW_UNSND (attr
);
11455 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11458 size
= DW_UNSND (attr
);
11460 name
= dwarf2_name (die
, cu
);
11463 complaint (&symfile_complaints
,
11464 _("DW_AT_name missing from DW_TAG_base_type"));
11469 case DW_ATE_address
:
11470 /* Turn DW_ATE_address into a void * pointer. */
11471 code
= TYPE_CODE_PTR
;
11472 type_flags
|= TYPE_FLAG_UNSIGNED
;
11473 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
11475 case DW_ATE_boolean
:
11476 code
= TYPE_CODE_BOOL
;
11477 type_flags
|= TYPE_FLAG_UNSIGNED
;
11479 case DW_ATE_complex_float
:
11480 code
= TYPE_CODE_COMPLEX
;
11481 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
11483 case DW_ATE_decimal_float
:
11484 code
= TYPE_CODE_DECFLOAT
;
11487 code
= TYPE_CODE_FLT
;
11489 case DW_ATE_signed
:
11491 case DW_ATE_unsigned
:
11492 type_flags
|= TYPE_FLAG_UNSIGNED
;
11493 if (cu
->language
== language_fortran
11495 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
11496 code
= TYPE_CODE_CHAR
;
11498 case DW_ATE_signed_char
:
11499 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11500 || cu
->language
== language_pascal
11501 || cu
->language
== language_fortran
)
11502 code
= TYPE_CODE_CHAR
;
11504 case DW_ATE_unsigned_char
:
11505 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11506 || cu
->language
== language_pascal
11507 || cu
->language
== language_fortran
)
11508 code
= TYPE_CODE_CHAR
;
11509 type_flags
|= TYPE_FLAG_UNSIGNED
;
11512 /* We just treat this as an integer and then recognize the
11513 type by name elsewhere. */
11517 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
11518 dwarf_type_encoding_name (encoding
));
11522 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
11523 TYPE_NAME (type
) = name
;
11524 TYPE_TARGET_TYPE (type
) = target_type
;
11526 if (name
&& strcmp (name
, "char") == 0)
11527 TYPE_NOSIGN (type
) = 1;
11529 return set_die_type (die
, type
, cu
);
11532 /* Read the given DW_AT_subrange DIE. */
11534 static struct type
*
11535 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11537 struct type
*base_type
;
11538 struct type
*range_type
;
11539 struct attribute
*attr
;
11541 int low_default_is_valid
;
11543 LONGEST negative_mask
;
11545 base_type
= die_type (die
, cu
);
11546 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
11547 check_typedef (base_type
);
11549 /* The die_type call above may have already set the type for this DIE. */
11550 range_type
= get_die_type (die
, cu
);
11554 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
11555 omitting DW_AT_lower_bound. */
11556 switch (cu
->language
)
11559 case language_cplus
:
11561 low_default_is_valid
= 1;
11563 case language_fortran
:
11565 low_default_is_valid
= 1;
11568 case language_java
:
11569 case language_objc
:
11571 low_default_is_valid
= (cu
->header
.version
>= 4);
11575 case language_pascal
:
11577 low_default_is_valid
= (cu
->header
.version
>= 4);
11581 low_default_is_valid
= 0;
11585 /* FIXME: For variable sized arrays either of these could be
11586 a variable rather than a constant value. We'll allow it,
11587 but we don't know how to handle it. */
11588 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
11590 low
= dwarf2_get_attr_constant_value (attr
, low
);
11591 else if (!low_default_is_valid
)
11592 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
11593 "- DIE at 0x%x [in module %s]"),
11594 die
->offset
.sect_off
, cu
->objfile
->name
);
11596 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
11599 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
11601 /* GCC encodes arrays with unspecified or dynamic length
11602 with a DW_FORM_block1 attribute or a reference attribute.
11603 FIXME: GDB does not yet know how to handle dynamic
11604 arrays properly, treat them as arrays with unspecified
11607 FIXME: jimb/2003-09-22: GDB does not really know
11608 how to handle arrays of unspecified length
11609 either; we just represent them as zero-length
11610 arrays. Choose an appropriate upper bound given
11611 the lower bound we've computed above. */
11615 high
= dwarf2_get_attr_constant_value (attr
, 1);
11619 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
11622 int count
= dwarf2_get_attr_constant_value (attr
, 1);
11623 high
= low
+ count
- 1;
11627 /* Unspecified array length. */
11632 /* Dwarf-2 specifications explicitly allows to create subrange types
11633 without specifying a base type.
11634 In that case, the base type must be set to the type of
11635 the lower bound, upper bound or count, in that order, if any of these
11636 three attributes references an object that has a type.
11637 If no base type is found, the Dwarf-2 specifications say that
11638 a signed integer type of size equal to the size of an address should
11640 For the following C code: `extern char gdb_int [];'
11641 GCC produces an empty range DIE.
11642 FIXME: muller/2010-05-28: Possible references to object for low bound,
11643 high bound or count are not yet handled by this code. */
11644 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
11646 struct objfile
*objfile
= cu
->objfile
;
11647 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11648 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
11649 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
11651 /* Test "int", "long int", and "long long int" objfile types,
11652 and select the first one having a size above or equal to the
11653 architecture address size. */
11654 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11655 base_type
= int_type
;
11658 int_type
= objfile_type (objfile
)->builtin_long
;
11659 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11660 base_type
= int_type
;
11663 int_type
= objfile_type (objfile
)->builtin_long_long
;
11664 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11665 base_type
= int_type
;
11671 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
11672 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
11673 low
|= negative_mask
;
11674 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
11675 high
|= negative_mask
;
11677 range_type
= create_range_type (NULL
, base_type
, low
, high
);
11679 /* Mark arrays with dynamic length at least as an array of unspecified
11680 length. GDB could check the boundary but before it gets implemented at
11681 least allow accessing the array elements. */
11682 if (attr
&& attr_form_is_block (attr
))
11683 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11685 /* Ada expects an empty array on no boundary attributes. */
11686 if (attr
== NULL
&& cu
->language
!= language_ada
)
11687 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11689 name
= dwarf2_name (die
, cu
);
11691 TYPE_NAME (range_type
) = name
;
11693 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11695 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
11697 set_die_type (die
, range_type
, cu
);
11699 /* set_die_type should be already done. */
11700 set_descriptive_type (range_type
, die
, cu
);
11705 static struct type
*
11706 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11710 /* For now, we only support the C meaning of an unspecified type: void. */
11712 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
11713 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
11715 return set_die_type (die
, type
, cu
);
11718 /* Read a single die and all its descendents. Set the die's sibling
11719 field to NULL; set other fields in the die correctly, and set all
11720 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
11721 location of the info_ptr after reading all of those dies. PARENT
11722 is the parent of the die in question. */
11724 static struct die_info
*
11725 read_die_and_children (const struct die_reader_specs
*reader
,
11726 gdb_byte
*info_ptr
,
11727 gdb_byte
**new_info_ptr
,
11728 struct die_info
*parent
)
11730 struct die_info
*die
;
11734 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
11737 *new_info_ptr
= cur_ptr
;
11740 store_in_ref_table (die
, reader
->cu
);
11743 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
11747 *new_info_ptr
= cur_ptr
;
11750 die
->sibling
= NULL
;
11751 die
->parent
= parent
;
11755 /* Read a die, all of its descendents, and all of its siblings; set
11756 all of the fields of all of the dies correctly. Arguments are as
11757 in read_die_and_children. */
11759 static struct die_info
*
11760 read_die_and_siblings (const struct die_reader_specs
*reader
,
11761 gdb_byte
*info_ptr
,
11762 gdb_byte
**new_info_ptr
,
11763 struct die_info
*parent
)
11765 struct die_info
*first_die
, *last_sibling
;
11768 cur_ptr
= info_ptr
;
11769 first_die
= last_sibling
= NULL
;
11773 struct die_info
*die
11774 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
11778 *new_info_ptr
= cur_ptr
;
11785 last_sibling
->sibling
= die
;
11787 last_sibling
= die
;
11791 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
11793 The caller is responsible for filling in the extra attributes
11794 and updating (*DIEP)->num_attrs.
11795 Set DIEP to point to a newly allocated die with its information,
11796 except for its child, sibling, and parent fields.
11797 Set HAS_CHILDREN to tell whether the die has children or not. */
11800 read_full_die_1 (const struct die_reader_specs
*reader
,
11801 struct die_info
**diep
, gdb_byte
*info_ptr
,
11802 int *has_children
, int num_extra_attrs
)
11804 unsigned int abbrev_number
, bytes_read
, i
;
11805 sect_offset offset
;
11806 struct abbrev_info
*abbrev
;
11807 struct die_info
*die
;
11808 struct dwarf2_cu
*cu
= reader
->cu
;
11809 bfd
*abfd
= reader
->abfd
;
11811 offset
.sect_off
= info_ptr
- reader
->buffer
;
11812 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11813 info_ptr
+= bytes_read
;
11814 if (!abbrev_number
)
11821 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
11823 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
11825 bfd_get_filename (abfd
));
11827 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
11828 die
->offset
= offset
;
11829 die
->tag
= abbrev
->tag
;
11830 die
->abbrev
= abbrev_number
;
11832 /* Make the result usable.
11833 The caller needs to update num_attrs after adding the extra
11835 die
->num_attrs
= abbrev
->num_attrs
;
11837 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11838 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
11842 *has_children
= abbrev
->has_children
;
11846 /* Read a die and all its attributes.
11847 Set DIEP to point to a newly allocated die with its information,
11848 except for its child, sibling, and parent fields.
11849 Set HAS_CHILDREN to tell whether the die has children or not. */
11852 read_full_die (const struct die_reader_specs
*reader
,
11853 struct die_info
**diep
, gdb_byte
*info_ptr
,
11856 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
11859 /* Abbreviation tables.
11861 In DWARF version 2, the description of the debugging information is
11862 stored in a separate .debug_abbrev section. Before we read any
11863 dies from a section we read in all abbreviations and install them
11864 in a hash table. */
11866 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
11868 static struct abbrev_info
*
11869 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
11871 struct abbrev_info
*abbrev
;
11873 abbrev
= (struct abbrev_info
*)
11874 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
11875 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11879 /* Add an abbreviation to the table. */
11882 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
11883 unsigned int abbrev_number
,
11884 struct abbrev_info
*abbrev
)
11886 unsigned int hash_number
;
11888 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11889 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
11890 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
11893 /* Look up an abbrev in the table.
11894 Returns NULL if the abbrev is not found. */
11896 static struct abbrev_info
*
11897 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
11898 unsigned int abbrev_number
)
11900 unsigned int hash_number
;
11901 struct abbrev_info
*abbrev
;
11903 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11904 abbrev
= abbrev_table
->abbrevs
[hash_number
];
11908 if (abbrev
->number
== abbrev_number
)
11910 abbrev
= abbrev
->next
;
11915 /* Read in an abbrev table. */
11917 static struct abbrev_table
*
11918 abbrev_table_read_table (struct dwarf2_section_info
*section
,
11919 sect_offset offset
)
11921 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11922 bfd
*abfd
= section
->asection
->owner
;
11923 struct abbrev_table
*abbrev_table
;
11924 gdb_byte
*abbrev_ptr
;
11925 struct abbrev_info
*cur_abbrev
;
11926 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
11927 unsigned int abbrev_form
;
11928 struct attr_abbrev
*cur_attrs
;
11929 unsigned int allocated_attrs
;
11931 abbrev_table
= XMALLOC (struct abbrev_table
);
11932 abbrev_table
->offset
= offset
;
11933 obstack_init (&abbrev_table
->abbrev_obstack
);
11934 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
11936 * sizeof (struct abbrev_info
*)));
11937 memset (abbrev_table
->abbrevs
, 0,
11938 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
11940 dwarf2_read_section (objfile
, section
);
11941 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
11942 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11943 abbrev_ptr
+= bytes_read
;
11945 allocated_attrs
= ATTR_ALLOC_CHUNK
;
11946 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
11948 /* Loop until we reach an abbrev number of 0. */
11949 while (abbrev_number
)
11951 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
11953 /* read in abbrev header */
11954 cur_abbrev
->number
= abbrev_number
;
11955 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11956 abbrev_ptr
+= bytes_read
;
11957 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
11960 /* now read in declarations */
11961 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11962 abbrev_ptr
+= bytes_read
;
11963 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11964 abbrev_ptr
+= bytes_read
;
11965 while (abbrev_name
)
11967 if (cur_abbrev
->num_attrs
== allocated_attrs
)
11969 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
11971 = xrealloc (cur_attrs
, (allocated_attrs
11972 * sizeof (struct attr_abbrev
)));
11975 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
11976 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
11977 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11978 abbrev_ptr
+= bytes_read
;
11979 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11980 abbrev_ptr
+= bytes_read
;
11983 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
11984 (cur_abbrev
->num_attrs
11985 * sizeof (struct attr_abbrev
)));
11986 memcpy (cur_abbrev
->attrs
, cur_attrs
,
11987 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
11989 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
11991 /* Get next abbreviation.
11992 Under Irix6 the abbreviations for a compilation unit are not
11993 always properly terminated with an abbrev number of 0.
11994 Exit loop if we encounter an abbreviation which we have
11995 already read (which means we are about to read the abbreviations
11996 for the next compile unit) or if the end of the abbreviation
11997 table is reached. */
11998 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
12000 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12001 abbrev_ptr
+= bytes_read
;
12002 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
12007 return abbrev_table
;
12010 /* Free the resources held by ABBREV_TABLE. */
12013 abbrev_table_free (struct abbrev_table
*abbrev_table
)
12015 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
12016 xfree (abbrev_table
);
12019 /* Same as abbrev_table_free but as a cleanup.
12020 We pass in a pointer to the pointer to the table so that we can
12021 set the pointer to NULL when we're done. It also simplifies
12022 build_type_unit_groups. */
12025 abbrev_table_free_cleanup (void *table_ptr
)
12027 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
12029 if (*abbrev_table_ptr
!= NULL
)
12030 abbrev_table_free (*abbrev_table_ptr
);
12031 *abbrev_table_ptr
= NULL
;
12034 /* Read the abbrev table for CU from ABBREV_SECTION. */
12037 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
12038 struct dwarf2_section_info
*abbrev_section
)
12041 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
12044 /* Release the memory used by the abbrev table for a compilation unit. */
12047 dwarf2_free_abbrev_table (void *ptr_to_cu
)
12049 struct dwarf2_cu
*cu
= ptr_to_cu
;
12051 abbrev_table_free (cu
->abbrev_table
);
12052 /* Set this to NULL so that we SEGV if we try to read it later,
12053 and also because free_comp_unit verifies this is NULL. */
12054 cu
->abbrev_table
= NULL
;
12057 /* Returns nonzero if TAG represents a type that we might generate a partial
12061 is_type_tag_for_partial (int tag
)
12066 /* Some types that would be reasonable to generate partial symbols for,
12067 that we don't at present. */
12068 case DW_TAG_array_type
:
12069 case DW_TAG_file_type
:
12070 case DW_TAG_ptr_to_member_type
:
12071 case DW_TAG_set_type
:
12072 case DW_TAG_string_type
:
12073 case DW_TAG_subroutine_type
:
12075 case DW_TAG_base_type
:
12076 case DW_TAG_class_type
:
12077 case DW_TAG_interface_type
:
12078 case DW_TAG_enumeration_type
:
12079 case DW_TAG_structure_type
:
12080 case DW_TAG_subrange_type
:
12081 case DW_TAG_typedef
:
12082 case DW_TAG_union_type
:
12089 /* Load all DIEs that are interesting for partial symbols into memory. */
12091 static struct partial_die_info
*
12092 load_partial_dies (const struct die_reader_specs
*reader
,
12093 gdb_byte
*info_ptr
, int building_psymtab
)
12095 struct dwarf2_cu
*cu
= reader
->cu
;
12096 struct objfile
*objfile
= cu
->objfile
;
12097 struct partial_die_info
*part_die
;
12098 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
12099 struct abbrev_info
*abbrev
;
12100 unsigned int bytes_read
;
12101 unsigned int load_all
= 0;
12102 int nesting_level
= 1;
12107 gdb_assert (cu
->per_cu
!= NULL
);
12108 if (cu
->per_cu
->load_all_dies
)
12112 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12116 &cu
->comp_unit_obstack
,
12117 hashtab_obstack_allocate
,
12118 dummy_obstack_deallocate
);
12120 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12121 sizeof (struct partial_die_info
));
12125 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
12127 /* A NULL abbrev means the end of a series of children. */
12128 if (abbrev
== NULL
)
12130 if (--nesting_level
== 0)
12132 /* PART_DIE was probably the last thing allocated on the
12133 comp_unit_obstack, so we could call obstack_free
12134 here. We don't do that because the waste is small,
12135 and will be cleaned up when we're done with this
12136 compilation unit. This way, we're also more robust
12137 against other users of the comp_unit_obstack. */
12140 info_ptr
+= bytes_read
;
12141 last_die
= parent_die
;
12142 parent_die
= parent_die
->die_parent
;
12146 /* Check for template arguments. We never save these; if
12147 they're seen, we just mark the parent, and go on our way. */
12148 if (parent_die
!= NULL
12149 && cu
->language
== language_cplus
12150 && (abbrev
->tag
== DW_TAG_template_type_param
12151 || abbrev
->tag
== DW_TAG_template_value_param
))
12153 parent_die
->has_template_arguments
= 1;
12157 /* We don't need a partial DIE for the template argument. */
12158 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12163 /* We only recurse into c++ subprograms looking for template arguments.
12164 Skip their other children. */
12166 && cu
->language
== language_cplus
12167 && parent_die
!= NULL
12168 && parent_die
->tag
== DW_TAG_subprogram
)
12170 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12174 /* Check whether this DIE is interesting enough to save. Normally
12175 we would not be interested in members here, but there may be
12176 later variables referencing them via DW_AT_specification (for
12177 static members). */
12179 && !is_type_tag_for_partial (abbrev
->tag
)
12180 && abbrev
->tag
!= DW_TAG_constant
12181 && abbrev
->tag
!= DW_TAG_enumerator
12182 && abbrev
->tag
!= DW_TAG_subprogram
12183 && abbrev
->tag
!= DW_TAG_lexical_block
12184 && abbrev
->tag
!= DW_TAG_variable
12185 && abbrev
->tag
!= DW_TAG_namespace
12186 && abbrev
->tag
!= DW_TAG_module
12187 && abbrev
->tag
!= DW_TAG_member
12188 && abbrev
->tag
!= DW_TAG_imported_unit
)
12190 /* Otherwise we skip to the next sibling, if any. */
12191 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12195 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
12198 /* This two-pass algorithm for processing partial symbols has a
12199 high cost in cache pressure. Thus, handle some simple cases
12200 here which cover the majority of C partial symbols. DIEs
12201 which neither have specification tags in them, nor could have
12202 specification tags elsewhere pointing at them, can simply be
12203 processed and discarded.
12205 This segment is also optional; scan_partial_symbols and
12206 add_partial_symbol will handle these DIEs if we chain
12207 them in normally. When compilers which do not emit large
12208 quantities of duplicate debug information are more common,
12209 this code can probably be removed. */
12211 /* Any complete simple types at the top level (pretty much all
12212 of them, for a language without namespaces), can be processed
12214 if (parent_die
== NULL
12215 && part_die
->has_specification
== 0
12216 && part_die
->is_declaration
== 0
12217 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
12218 || part_die
->tag
== DW_TAG_base_type
12219 || part_die
->tag
== DW_TAG_subrange_type
))
12221 if (building_psymtab
&& part_die
->name
!= NULL
)
12222 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12223 VAR_DOMAIN
, LOC_TYPEDEF
,
12224 &objfile
->static_psymbols
,
12225 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12226 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12230 /* The exception for DW_TAG_typedef with has_children above is
12231 a workaround of GCC PR debug/47510. In the case of this complaint
12232 type_name_no_tag_or_error will error on such types later.
12234 GDB skipped children of DW_TAG_typedef by the shortcut above and then
12235 it could not find the child DIEs referenced later, this is checked
12236 above. In correct DWARF DW_TAG_typedef should have no children. */
12238 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
12239 complaint (&symfile_complaints
,
12240 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
12241 "- DIE at 0x%x [in module %s]"),
12242 part_die
->offset
.sect_off
, objfile
->name
);
12244 /* If we're at the second level, and we're an enumerator, and
12245 our parent has no specification (meaning possibly lives in a
12246 namespace elsewhere), then we can add the partial symbol now
12247 instead of queueing it. */
12248 if (part_die
->tag
== DW_TAG_enumerator
12249 && parent_die
!= NULL
12250 && parent_die
->die_parent
== NULL
12251 && parent_die
->tag
== DW_TAG_enumeration_type
12252 && parent_die
->has_specification
== 0)
12254 if (part_die
->name
== NULL
)
12255 complaint (&symfile_complaints
,
12256 _("malformed enumerator DIE ignored"));
12257 else if (building_psymtab
)
12258 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12259 VAR_DOMAIN
, LOC_CONST
,
12260 (cu
->language
== language_cplus
12261 || cu
->language
== language_java
)
12262 ? &objfile
->global_psymbols
12263 : &objfile
->static_psymbols
,
12264 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12266 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12270 /* We'll save this DIE so link it in. */
12271 part_die
->die_parent
= parent_die
;
12272 part_die
->die_sibling
= NULL
;
12273 part_die
->die_child
= NULL
;
12275 if (last_die
&& last_die
== parent_die
)
12276 last_die
->die_child
= part_die
;
12278 last_die
->die_sibling
= part_die
;
12280 last_die
= part_die
;
12282 if (first_die
== NULL
)
12283 first_die
= part_die
;
12285 /* Maybe add the DIE to the hash table. Not all DIEs that we
12286 find interesting need to be in the hash table, because we
12287 also have the parent/sibling/child chains; only those that we
12288 might refer to by offset later during partial symbol reading.
12290 For now this means things that might have be the target of a
12291 DW_AT_specification, DW_AT_abstract_origin, or
12292 DW_AT_extension. DW_AT_extension will refer only to
12293 namespaces; DW_AT_abstract_origin refers to functions (and
12294 many things under the function DIE, but we do not recurse
12295 into function DIEs during partial symbol reading) and
12296 possibly variables as well; DW_AT_specification refers to
12297 declarations. Declarations ought to have the DW_AT_declaration
12298 flag. It happens that GCC forgets to put it in sometimes, but
12299 only for functions, not for types.
12301 Adding more things than necessary to the hash table is harmless
12302 except for the performance cost. Adding too few will result in
12303 wasted time in find_partial_die, when we reread the compilation
12304 unit with load_all_dies set. */
12307 || abbrev
->tag
== DW_TAG_constant
12308 || abbrev
->tag
== DW_TAG_subprogram
12309 || abbrev
->tag
== DW_TAG_variable
12310 || abbrev
->tag
== DW_TAG_namespace
12311 || part_die
->is_declaration
)
12315 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
12316 part_die
->offset
.sect_off
, INSERT
);
12320 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12321 sizeof (struct partial_die_info
));
12323 /* For some DIEs we want to follow their children (if any). For C
12324 we have no reason to follow the children of structures; for other
12325 languages we have to, so that we can get at method physnames
12326 to infer fully qualified class names, for DW_AT_specification,
12327 and for C++ template arguments. For C++, we also look one level
12328 inside functions to find template arguments (if the name of the
12329 function does not already contain the template arguments).
12331 For Ada, we need to scan the children of subprograms and lexical
12332 blocks as well because Ada allows the definition of nested
12333 entities that could be interesting for the debugger, such as
12334 nested subprograms for instance. */
12335 if (last_die
->has_children
12337 || last_die
->tag
== DW_TAG_namespace
12338 || last_die
->tag
== DW_TAG_module
12339 || last_die
->tag
== DW_TAG_enumeration_type
12340 || (cu
->language
== language_cplus
12341 && last_die
->tag
== DW_TAG_subprogram
12342 && (last_die
->name
== NULL
12343 || strchr (last_die
->name
, '<') == NULL
))
12344 || (cu
->language
!= language_c
12345 && (last_die
->tag
== DW_TAG_class_type
12346 || last_die
->tag
== DW_TAG_interface_type
12347 || last_die
->tag
== DW_TAG_structure_type
12348 || last_die
->tag
== DW_TAG_union_type
))
12349 || (cu
->language
== language_ada
12350 && (last_die
->tag
== DW_TAG_subprogram
12351 || last_die
->tag
== DW_TAG_lexical_block
))))
12354 parent_die
= last_die
;
12358 /* Otherwise we skip to the next sibling, if any. */
12359 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
12361 /* Back to the top, do it again. */
12365 /* Read a minimal amount of information into the minimal die structure. */
12368 read_partial_die (const struct die_reader_specs
*reader
,
12369 struct partial_die_info
*part_die
,
12370 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
12371 gdb_byte
*info_ptr
)
12373 struct dwarf2_cu
*cu
= reader
->cu
;
12374 struct objfile
*objfile
= cu
->objfile
;
12375 gdb_byte
*buffer
= reader
->buffer
;
12377 struct attribute attr
;
12378 int has_low_pc_attr
= 0;
12379 int has_high_pc_attr
= 0;
12380 int high_pc_relative
= 0;
12382 memset (part_die
, 0, sizeof (struct partial_die_info
));
12384 part_die
->offset
.sect_off
= info_ptr
- buffer
;
12386 info_ptr
+= abbrev_len
;
12388 if (abbrev
== NULL
)
12391 part_die
->tag
= abbrev
->tag
;
12392 part_die
->has_children
= abbrev
->has_children
;
12394 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12396 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
12398 /* Store the data if it is of an attribute we want to keep in a
12399 partial symbol table. */
12403 switch (part_die
->tag
)
12405 case DW_TAG_compile_unit
:
12406 case DW_TAG_partial_unit
:
12407 case DW_TAG_type_unit
:
12408 /* Compilation units have a DW_AT_name that is a filename, not
12409 a source language identifier. */
12410 case DW_TAG_enumeration_type
:
12411 case DW_TAG_enumerator
:
12412 /* These tags always have simple identifiers already; no need
12413 to canonicalize them. */
12414 part_die
->name
= DW_STRING (&attr
);
12418 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
12419 &objfile
->objfile_obstack
);
12423 case DW_AT_linkage_name
:
12424 case DW_AT_MIPS_linkage_name
:
12425 /* Note that both forms of linkage name might appear. We
12426 assume they will be the same, and we only store the last
12428 if (cu
->language
== language_ada
)
12429 part_die
->name
= DW_STRING (&attr
);
12430 part_die
->linkage_name
= DW_STRING (&attr
);
12433 has_low_pc_attr
= 1;
12434 part_die
->lowpc
= DW_ADDR (&attr
);
12436 case DW_AT_high_pc
:
12437 has_high_pc_attr
= 1;
12438 if (attr
.form
== DW_FORM_addr
12439 || attr
.form
== DW_FORM_GNU_addr_index
)
12440 part_die
->highpc
= DW_ADDR (&attr
);
12443 high_pc_relative
= 1;
12444 part_die
->highpc
= DW_UNSND (&attr
);
12447 case DW_AT_location
:
12448 /* Support the .debug_loc offsets. */
12449 if (attr_form_is_block (&attr
))
12451 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
12453 else if (attr_form_is_section_offset (&attr
))
12455 dwarf2_complex_location_expr_complaint ();
12459 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12460 "partial symbol information");
12463 case DW_AT_external
:
12464 part_die
->is_external
= DW_UNSND (&attr
);
12466 case DW_AT_declaration
:
12467 part_die
->is_declaration
= DW_UNSND (&attr
);
12470 part_die
->has_type
= 1;
12472 case DW_AT_abstract_origin
:
12473 case DW_AT_specification
:
12474 case DW_AT_extension
:
12475 part_die
->has_specification
= 1;
12476 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
12478 case DW_AT_sibling
:
12479 /* Ignore absolute siblings, they might point outside of
12480 the current compile unit. */
12481 if (attr
.form
== DW_FORM_ref_addr
)
12482 complaint (&symfile_complaints
,
12483 _("ignoring absolute DW_AT_sibling"));
12485 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
12487 case DW_AT_byte_size
:
12488 part_die
->has_byte_size
= 1;
12490 case DW_AT_calling_convention
:
12491 /* DWARF doesn't provide a way to identify a program's source-level
12492 entry point. DW_AT_calling_convention attributes are only meant
12493 to describe functions' calling conventions.
12495 However, because it's a necessary piece of information in
12496 Fortran, and because DW_CC_program is the only piece of debugging
12497 information whose definition refers to a 'main program' at all,
12498 several compilers have begun marking Fortran main programs with
12499 DW_CC_program --- even when those functions use the standard
12500 calling conventions.
12502 So until DWARF specifies a way to provide this information and
12503 compilers pick up the new representation, we'll support this
12505 if (DW_UNSND (&attr
) == DW_CC_program
12506 && cu
->language
== language_fortran
)
12508 set_main_name (part_die
->name
);
12510 /* As this DIE has a static linkage the name would be difficult
12511 to look up later. */
12512 language_of_main
= language_fortran
;
12516 if (DW_UNSND (&attr
) == DW_INL_inlined
12517 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
12518 part_die
->may_be_inlined
= 1;
12522 if (part_die
->tag
== DW_TAG_imported_unit
)
12523 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
12531 if (high_pc_relative
)
12532 part_die
->highpc
+= part_die
->lowpc
;
12534 if (has_low_pc_attr
&& has_high_pc_attr
)
12536 /* When using the GNU linker, .gnu.linkonce. sections are used to
12537 eliminate duplicate copies of functions and vtables and such.
12538 The linker will arbitrarily choose one and discard the others.
12539 The AT_*_pc values for such functions refer to local labels in
12540 these sections. If the section from that file was discarded, the
12541 labels are not in the output, so the relocs get a value of 0.
12542 If this is a discarded function, mark the pc bounds as invalid,
12543 so that GDB will ignore it. */
12544 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12546 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12548 complaint (&symfile_complaints
,
12549 _("DW_AT_low_pc %s is zero "
12550 "for DIE at 0x%x [in module %s]"),
12551 paddress (gdbarch
, part_die
->lowpc
),
12552 part_die
->offset
.sect_off
, objfile
->name
);
12554 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
12555 else if (part_die
->lowpc
>= part_die
->highpc
)
12557 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12559 complaint (&symfile_complaints
,
12560 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
12561 "for DIE at 0x%x [in module %s]"),
12562 paddress (gdbarch
, part_die
->lowpc
),
12563 paddress (gdbarch
, part_die
->highpc
),
12564 part_die
->offset
.sect_off
, objfile
->name
);
12567 part_die
->has_pc_info
= 1;
12573 /* Find a cached partial DIE at OFFSET in CU. */
12575 static struct partial_die_info
*
12576 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
12578 struct partial_die_info
*lookup_die
= NULL
;
12579 struct partial_die_info part_die
;
12581 part_die
.offset
= offset
;
12582 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
12588 /* Find a partial DIE at OFFSET, which may or may not be in CU,
12589 except in the case of .debug_types DIEs which do not reference
12590 outside their CU (they do however referencing other types via
12591 DW_FORM_ref_sig8). */
12593 static struct partial_die_info
*
12594 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
12596 struct objfile
*objfile
= cu
->objfile
;
12597 struct dwarf2_per_cu_data
*per_cu
= NULL
;
12598 struct partial_die_info
*pd
= NULL
;
12600 if (offset_in_cu_p (&cu
->header
, offset
))
12602 pd
= find_partial_die_in_comp_unit (offset
, cu
);
12605 /* We missed recording what we needed.
12606 Load all dies and try again. */
12607 per_cu
= cu
->per_cu
;
12611 /* TUs don't reference other CUs/TUs (except via type signatures). */
12612 if (cu
->per_cu
->is_debug_types
)
12614 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
12615 " external reference to offset 0x%lx [in module %s].\n"),
12616 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
12617 bfd_get_filename (objfile
->obfd
));
12619 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
12621 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
12622 load_partial_comp_unit (per_cu
);
12624 per_cu
->cu
->last_used
= 0;
12625 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12628 /* If we didn't find it, and not all dies have been loaded,
12629 load them all and try again. */
12631 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
12633 per_cu
->load_all_dies
= 1;
12635 /* This is nasty. When we reread the DIEs, somewhere up the call chain
12636 THIS_CU->cu may already be in use. So we can't just free it and
12637 replace its DIEs with the ones we read in. Instead, we leave those
12638 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
12639 and clobber THIS_CU->cu->partial_dies with the hash table for the new
12641 load_partial_comp_unit (per_cu
);
12643 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12647 internal_error (__FILE__
, __LINE__
,
12648 _("could not find partial DIE 0x%x "
12649 "in cache [from module %s]\n"),
12650 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
12654 /* See if we can figure out if the class lives in a namespace. We do
12655 this by looking for a member function; its demangled name will
12656 contain namespace info, if there is any. */
12659 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
12660 struct dwarf2_cu
*cu
)
12662 /* NOTE: carlton/2003-10-07: Getting the info this way changes
12663 what template types look like, because the demangler
12664 frequently doesn't give the same name as the debug info. We
12665 could fix this by only using the demangled name to get the
12666 prefix (but see comment in read_structure_type). */
12668 struct partial_die_info
*real_pdi
;
12669 struct partial_die_info
*child_pdi
;
12671 /* If this DIE (this DIE's specification, if any) has a parent, then
12672 we should not do this. We'll prepend the parent's fully qualified
12673 name when we create the partial symbol. */
12675 real_pdi
= struct_pdi
;
12676 while (real_pdi
->has_specification
)
12677 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
12679 if (real_pdi
->die_parent
!= NULL
)
12682 for (child_pdi
= struct_pdi
->die_child
;
12684 child_pdi
= child_pdi
->die_sibling
)
12686 if (child_pdi
->tag
== DW_TAG_subprogram
12687 && child_pdi
->linkage_name
!= NULL
)
12689 char *actual_class_name
12690 = language_class_name_from_physname (cu
->language_defn
,
12691 child_pdi
->linkage_name
);
12692 if (actual_class_name
!= NULL
)
12695 = obsavestring (actual_class_name
,
12696 strlen (actual_class_name
),
12697 &cu
->objfile
->objfile_obstack
);
12698 xfree (actual_class_name
);
12705 /* Adjust PART_DIE before generating a symbol for it. This function
12706 may set the is_external flag or change the DIE's name. */
12709 fixup_partial_die (struct partial_die_info
*part_die
,
12710 struct dwarf2_cu
*cu
)
12712 /* Once we've fixed up a die, there's no point in doing so again.
12713 This also avoids a memory leak if we were to call
12714 guess_partial_die_structure_name multiple times. */
12715 if (part_die
->fixup_called
)
12718 /* If we found a reference attribute and the DIE has no name, try
12719 to find a name in the referred to DIE. */
12721 if (part_die
->name
== NULL
&& part_die
->has_specification
)
12723 struct partial_die_info
*spec_die
;
12725 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
12727 fixup_partial_die (spec_die
, cu
);
12729 if (spec_die
->name
)
12731 part_die
->name
= spec_die
->name
;
12733 /* Copy DW_AT_external attribute if it is set. */
12734 if (spec_die
->is_external
)
12735 part_die
->is_external
= spec_die
->is_external
;
12739 /* Set default names for some unnamed DIEs. */
12741 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
12742 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
12744 /* If there is no parent die to provide a namespace, and there are
12745 children, see if we can determine the namespace from their linkage
12747 if (cu
->language
== language_cplus
12748 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12749 && part_die
->die_parent
== NULL
12750 && part_die
->has_children
12751 && (part_die
->tag
== DW_TAG_class_type
12752 || part_die
->tag
== DW_TAG_structure_type
12753 || part_die
->tag
== DW_TAG_union_type
))
12754 guess_partial_die_structure_name (part_die
, cu
);
12756 /* GCC might emit a nameless struct or union that has a linkage
12757 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12758 if (part_die
->name
== NULL
12759 && (part_die
->tag
== DW_TAG_class_type
12760 || part_die
->tag
== DW_TAG_interface_type
12761 || part_die
->tag
== DW_TAG_structure_type
12762 || part_die
->tag
== DW_TAG_union_type
)
12763 && part_die
->linkage_name
!= NULL
)
12767 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
12772 /* Strip any leading namespaces/classes, keep only the base name.
12773 DW_AT_name for named DIEs does not contain the prefixes. */
12774 base
= strrchr (demangled
, ':');
12775 if (base
&& base
> demangled
&& base
[-1] == ':')
12780 part_die
->name
= obsavestring (base
, strlen (base
),
12781 &cu
->objfile
->objfile_obstack
);
12786 part_die
->fixup_called
= 1;
12789 /* Read an attribute value described by an attribute form. */
12792 read_attribute_value (const struct die_reader_specs
*reader
,
12793 struct attribute
*attr
, unsigned form
,
12794 gdb_byte
*info_ptr
)
12796 struct dwarf2_cu
*cu
= reader
->cu
;
12797 bfd
*abfd
= reader
->abfd
;
12798 struct comp_unit_head
*cu_header
= &cu
->header
;
12799 unsigned int bytes_read
;
12800 struct dwarf_block
*blk
;
12805 case DW_FORM_ref_addr
:
12806 if (cu
->header
.version
== 2)
12807 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12809 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
12810 &cu
->header
, &bytes_read
);
12811 info_ptr
+= bytes_read
;
12814 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12815 info_ptr
+= bytes_read
;
12817 case DW_FORM_block2
:
12818 blk
= dwarf_alloc_block (cu
);
12819 blk
->size
= read_2_bytes (abfd
, info_ptr
);
12821 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12822 info_ptr
+= blk
->size
;
12823 DW_BLOCK (attr
) = blk
;
12825 case DW_FORM_block4
:
12826 blk
= dwarf_alloc_block (cu
);
12827 blk
->size
= read_4_bytes (abfd
, info_ptr
);
12829 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12830 info_ptr
+= blk
->size
;
12831 DW_BLOCK (attr
) = blk
;
12833 case DW_FORM_data2
:
12834 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
12837 case DW_FORM_data4
:
12838 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
12841 case DW_FORM_data8
:
12842 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
12845 case DW_FORM_sec_offset
:
12846 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
12847 info_ptr
+= bytes_read
;
12849 case DW_FORM_string
:
12850 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
12851 DW_STRING_IS_CANONICAL (attr
) = 0;
12852 info_ptr
+= bytes_read
;
12855 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
12857 DW_STRING_IS_CANONICAL (attr
) = 0;
12858 info_ptr
+= bytes_read
;
12860 case DW_FORM_exprloc
:
12861 case DW_FORM_block
:
12862 blk
= dwarf_alloc_block (cu
);
12863 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12864 info_ptr
+= bytes_read
;
12865 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12866 info_ptr
+= blk
->size
;
12867 DW_BLOCK (attr
) = blk
;
12869 case DW_FORM_block1
:
12870 blk
= dwarf_alloc_block (cu
);
12871 blk
->size
= read_1_byte (abfd
, info_ptr
);
12873 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12874 info_ptr
+= blk
->size
;
12875 DW_BLOCK (attr
) = blk
;
12877 case DW_FORM_data1
:
12878 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12882 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12885 case DW_FORM_flag_present
:
12886 DW_UNSND (attr
) = 1;
12888 case DW_FORM_sdata
:
12889 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
12890 info_ptr
+= bytes_read
;
12892 case DW_FORM_udata
:
12893 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12894 info_ptr
+= bytes_read
;
12897 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12898 + read_1_byte (abfd
, info_ptr
));
12902 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12903 + read_2_bytes (abfd
, info_ptr
));
12907 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12908 + read_4_bytes (abfd
, info_ptr
));
12912 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12913 + read_8_bytes (abfd
, info_ptr
));
12916 case DW_FORM_ref_sig8
:
12917 /* Convert the signature to something we can record in DW_UNSND
12919 NOTE: This is NULL if the type wasn't found. */
12920 DW_SIGNATURED_TYPE (attr
) =
12921 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
12924 case DW_FORM_ref_udata
:
12925 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12926 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
12927 info_ptr
+= bytes_read
;
12929 case DW_FORM_indirect
:
12930 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12931 info_ptr
+= bytes_read
;
12932 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
12934 case DW_FORM_GNU_addr_index
:
12935 if (reader
->dwo_file
== NULL
)
12937 /* For now flag a hard error.
12938 Later we can turn this into a complaint. */
12939 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12940 dwarf_form_name (form
),
12941 bfd_get_filename (abfd
));
12943 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
12944 info_ptr
+= bytes_read
;
12946 case DW_FORM_GNU_str_index
:
12947 if (reader
->dwo_file
== NULL
)
12949 /* For now flag a hard error.
12950 Later we can turn this into a complaint if warranted. */
12951 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12952 dwarf_form_name (form
),
12953 bfd_get_filename (abfd
));
12956 ULONGEST str_index
=
12957 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12959 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
12960 DW_STRING_IS_CANONICAL (attr
) = 0;
12961 info_ptr
+= bytes_read
;
12965 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
12966 dwarf_form_name (form
),
12967 bfd_get_filename (abfd
));
12970 /* We have seen instances where the compiler tried to emit a byte
12971 size attribute of -1 which ended up being encoded as an unsigned
12972 0xffffffff. Although 0xffffffff is technically a valid size value,
12973 an object of this size seems pretty unlikely so we can relatively
12974 safely treat these cases as if the size attribute was invalid and
12975 treat them as zero by default. */
12976 if (attr
->name
== DW_AT_byte_size
12977 && form
== DW_FORM_data4
12978 && DW_UNSND (attr
) >= 0xffffffff)
12981 (&symfile_complaints
,
12982 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
12983 hex_string (DW_UNSND (attr
)));
12984 DW_UNSND (attr
) = 0;
12990 /* Read an attribute described by an abbreviated attribute. */
12993 read_attribute (const struct die_reader_specs
*reader
,
12994 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
12995 gdb_byte
*info_ptr
)
12997 attr
->name
= abbrev
->name
;
12998 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
13001 /* Read dwarf information from a buffer. */
13003 static unsigned int
13004 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
13006 return bfd_get_8 (abfd
, buf
);
13010 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
13012 return bfd_get_signed_8 (abfd
, buf
);
13015 static unsigned int
13016 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
13018 return bfd_get_16 (abfd
, buf
);
13022 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13024 return bfd_get_signed_16 (abfd
, buf
);
13027 static unsigned int
13028 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
13030 return bfd_get_32 (abfd
, buf
);
13034 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13036 return bfd_get_signed_32 (abfd
, buf
);
13040 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
13042 return bfd_get_64 (abfd
, buf
);
13046 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
13047 unsigned int *bytes_read
)
13049 struct comp_unit_head
*cu_header
= &cu
->header
;
13050 CORE_ADDR retval
= 0;
13052 if (cu_header
->signed_addr_p
)
13054 switch (cu_header
->addr_size
)
13057 retval
= bfd_get_signed_16 (abfd
, buf
);
13060 retval
= bfd_get_signed_32 (abfd
, buf
);
13063 retval
= bfd_get_signed_64 (abfd
, buf
);
13066 internal_error (__FILE__
, __LINE__
,
13067 _("read_address: bad switch, signed [in module %s]"),
13068 bfd_get_filename (abfd
));
13073 switch (cu_header
->addr_size
)
13076 retval
= bfd_get_16 (abfd
, buf
);
13079 retval
= bfd_get_32 (abfd
, buf
);
13082 retval
= bfd_get_64 (abfd
, buf
);
13085 internal_error (__FILE__
, __LINE__
,
13086 _("read_address: bad switch, "
13087 "unsigned [in module %s]"),
13088 bfd_get_filename (abfd
));
13092 *bytes_read
= cu_header
->addr_size
;
13096 /* Read the initial length from a section. The (draft) DWARF 3
13097 specification allows the initial length to take up either 4 bytes
13098 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
13099 bytes describe the length and all offsets will be 8 bytes in length
13102 An older, non-standard 64-bit format is also handled by this
13103 function. The older format in question stores the initial length
13104 as an 8-byte quantity without an escape value. Lengths greater
13105 than 2^32 aren't very common which means that the initial 4 bytes
13106 is almost always zero. Since a length value of zero doesn't make
13107 sense for the 32-bit format, this initial zero can be considered to
13108 be an escape value which indicates the presence of the older 64-bit
13109 format. As written, the code can't detect (old format) lengths
13110 greater than 4GB. If it becomes necessary to handle lengths
13111 somewhat larger than 4GB, we could allow other small values (such
13112 as the non-sensical values of 1, 2, and 3) to also be used as
13113 escape values indicating the presence of the old format.
13115 The value returned via bytes_read should be used to increment the
13116 relevant pointer after calling read_initial_length().
13118 [ Note: read_initial_length() and read_offset() are based on the
13119 document entitled "DWARF Debugging Information Format", revision
13120 3, draft 8, dated November 19, 2001. This document was obtained
13123 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
13125 This document is only a draft and is subject to change. (So beware.)
13127 Details regarding the older, non-standard 64-bit format were
13128 determined empirically by examining 64-bit ELF files produced by
13129 the SGI toolchain on an IRIX 6.5 machine.
13131 - Kevin, July 16, 2002
13135 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
13137 LONGEST length
= bfd_get_32 (abfd
, buf
);
13139 if (length
== 0xffffffff)
13141 length
= bfd_get_64 (abfd
, buf
+ 4);
13144 else if (length
== 0)
13146 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
13147 length
= bfd_get_64 (abfd
, buf
);
13158 /* Cover function for read_initial_length.
13159 Returns the length of the object at BUF, and stores the size of the
13160 initial length in *BYTES_READ and stores the size that offsets will be in
13162 If the initial length size is not equivalent to that specified in
13163 CU_HEADER then issue a complaint.
13164 This is useful when reading non-comp-unit headers. */
13167 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
13168 const struct comp_unit_head
*cu_header
,
13169 unsigned int *bytes_read
,
13170 unsigned int *offset_size
)
13172 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
13174 gdb_assert (cu_header
->initial_length_size
== 4
13175 || cu_header
->initial_length_size
== 8
13176 || cu_header
->initial_length_size
== 12);
13178 if (cu_header
->initial_length_size
!= *bytes_read
)
13179 complaint (&symfile_complaints
,
13180 _("intermixed 32-bit and 64-bit DWARF sections"));
13182 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
13186 /* Read an offset from the data stream. The size of the offset is
13187 given by cu_header->offset_size. */
13190 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
13191 unsigned int *bytes_read
)
13193 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
13195 *bytes_read
= cu_header
->offset_size
;
13199 /* Read an offset from the data stream. */
13202 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
13204 LONGEST retval
= 0;
13206 switch (offset_size
)
13209 retval
= bfd_get_32 (abfd
, buf
);
13212 retval
= bfd_get_64 (abfd
, buf
);
13215 internal_error (__FILE__
, __LINE__
,
13216 _("read_offset_1: bad switch [in module %s]"),
13217 bfd_get_filename (abfd
));
13224 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
13226 /* If the size of a host char is 8 bits, we can return a pointer
13227 to the buffer, otherwise we have to copy the data to a buffer
13228 allocated on the temporary obstack. */
13229 gdb_assert (HOST_CHAR_BIT
== 8);
13234 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13236 /* If the size of a host char is 8 bits, we can return a pointer
13237 to the string, otherwise we have to copy the string to a buffer
13238 allocated on the temporary obstack. */
13239 gdb_assert (HOST_CHAR_BIT
== 8);
13242 *bytes_read_ptr
= 1;
13245 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
13246 return (char *) buf
;
13250 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
13252 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
13253 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
13254 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
13255 bfd_get_filename (abfd
));
13256 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
13257 error (_("DW_FORM_strp pointing outside of "
13258 ".debug_str section [in module %s]"),
13259 bfd_get_filename (abfd
));
13260 gdb_assert (HOST_CHAR_BIT
== 8);
13261 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
13263 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
13267 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
13268 const struct comp_unit_head
*cu_header
,
13269 unsigned int *bytes_read_ptr
)
13271 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
13273 return read_indirect_string_at_offset (abfd
, str_offset
);
13277 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13280 unsigned int num_read
;
13282 unsigned char byte
;
13290 byte
= bfd_get_8 (abfd
, buf
);
13293 result
|= ((ULONGEST
) (byte
& 127) << shift
);
13294 if ((byte
& 128) == 0)
13300 *bytes_read_ptr
= num_read
;
13305 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13308 int i
, shift
, num_read
;
13309 unsigned char byte
;
13317 byte
= bfd_get_8 (abfd
, buf
);
13320 result
|= ((LONGEST
) (byte
& 127) << shift
);
13322 if ((byte
& 128) == 0)
13327 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
13328 result
|= -(((LONGEST
) 1) << shift
);
13329 *bytes_read_ptr
= num_read
;
13333 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
13334 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
13335 ADDR_SIZE is the size of addresses from the CU header. */
13338 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
13340 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13341 bfd
*abfd
= objfile
->obfd
;
13342 const gdb_byte
*info_ptr
;
13344 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
13345 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
13346 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
13348 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
13349 error (_("DW_FORM_addr_index pointing outside of "
13350 ".debug_addr section [in module %s]"),
13352 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
13353 + addr_base
+ addr_index
* addr_size
);
13354 if (addr_size
== 4)
13355 return bfd_get_32 (abfd
, info_ptr
);
13357 return bfd_get_64 (abfd
, info_ptr
);
13360 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
13363 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
13365 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
13368 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
13371 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
13372 unsigned int *bytes_read
)
13374 bfd
*abfd
= cu
->objfile
->obfd
;
13375 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
13377 return read_addr_index (cu
, addr_index
);
13380 /* Data structure to pass results from dwarf2_read_addr_index_reader
13381 back to dwarf2_read_addr_index. */
13383 struct dwarf2_read_addr_index_data
13385 ULONGEST addr_base
;
13389 /* die_reader_func for dwarf2_read_addr_index. */
13392 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
13393 gdb_byte
*info_ptr
,
13394 struct die_info
*comp_unit_die
,
13398 struct dwarf2_cu
*cu
= reader
->cu
;
13399 struct dwarf2_read_addr_index_data
*aidata
=
13400 (struct dwarf2_read_addr_index_data
*) data
;
13402 aidata
->addr_base
= cu
->addr_base
;
13403 aidata
->addr_size
= cu
->header
.addr_size
;
13406 /* Given an index in .debug_addr, fetch the value.
13407 NOTE: This can be called during dwarf expression evaluation,
13408 long after the debug information has been read, and thus per_cu->cu
13409 may no longer exist. */
13412 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
13413 unsigned int addr_index
)
13415 struct objfile
*objfile
= per_cu
->objfile
;
13416 struct dwarf2_cu
*cu
= per_cu
->cu
;
13417 ULONGEST addr_base
;
13420 /* This is intended to be called from outside this file. */
13421 dw2_setup (objfile
);
13423 /* We need addr_base and addr_size.
13424 If we don't have PER_CU->cu, we have to get it.
13425 Nasty, but the alternative is storing the needed info in PER_CU,
13426 which at this point doesn't seem justified: it's not clear how frequently
13427 it would get used and it would increase the size of every PER_CU.
13428 Entry points like dwarf2_per_cu_addr_size do a similar thing
13429 so we're not in uncharted territory here.
13430 Alas we need to be a bit more complicated as addr_base is contained
13433 We don't need to read the entire CU(/TU).
13434 We just need the header and top level die.
13435 IWBN to use the aging mechanism to let us lazily later discard the CU.
13436 See however init_cutu_and_read_dies_simple. */
13440 addr_base
= cu
->addr_base
;
13441 addr_size
= cu
->header
.addr_size
;
13445 struct dwarf2_read_addr_index_data aidata
;
13447 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
13449 addr_base
= aidata
.addr_base
;
13450 addr_size
= aidata
.addr_size
;
13453 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
13456 /* Given a DW_AT_str_index, fetch the string. */
13459 read_str_index (const struct die_reader_specs
*reader
,
13460 struct dwarf2_cu
*cu
, ULONGEST str_index
)
13462 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13463 const char *dwo_name
= objfile
->name
;
13464 bfd
*abfd
= objfile
->obfd
;
13465 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
13466 gdb_byte
*info_ptr
;
13467 ULONGEST str_offset
;
13469 dwarf2_read_section (objfile
, §ions
->str
);
13470 dwarf2_read_section (objfile
, §ions
->str_offsets
);
13471 if (sections
->str
.buffer
== NULL
)
13472 error (_("DW_FORM_str_index used without .debug_str.dwo section"
13473 " in CU at offset 0x%lx [in module %s]"),
13474 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13475 if (sections
->str_offsets
.buffer
== NULL
)
13476 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
13477 " in CU at offset 0x%lx [in module %s]"),
13478 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13479 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
13480 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
13481 " section in CU at offset 0x%lx [in module %s]"),
13482 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13483 info_ptr
= (sections
->str_offsets
.buffer
13484 + str_index
* cu
->header
.offset_size
);
13485 if (cu
->header
.offset_size
== 4)
13486 str_offset
= bfd_get_32 (abfd
, info_ptr
);
13488 str_offset
= bfd_get_64 (abfd
, info_ptr
);
13489 if (str_offset
>= sections
->str
.size
)
13490 error (_("Offset from DW_FORM_str_index pointing outside of"
13491 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
13492 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13493 return (char *) (sections
->str
.buffer
+ str_offset
);
13496 /* Return the length of an LEB128 number in BUF. */
13499 leb128_size (const gdb_byte
*buf
)
13501 const gdb_byte
*begin
= buf
;
13507 if ((byte
& 128) == 0)
13508 return buf
- begin
;
13513 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
13520 cu
->language
= language_c
;
13522 case DW_LANG_C_plus_plus
:
13523 cu
->language
= language_cplus
;
13526 cu
->language
= language_d
;
13528 case DW_LANG_Fortran77
:
13529 case DW_LANG_Fortran90
:
13530 case DW_LANG_Fortran95
:
13531 cu
->language
= language_fortran
;
13534 cu
->language
= language_go
;
13536 case DW_LANG_Mips_Assembler
:
13537 cu
->language
= language_asm
;
13540 cu
->language
= language_java
;
13542 case DW_LANG_Ada83
:
13543 case DW_LANG_Ada95
:
13544 cu
->language
= language_ada
;
13546 case DW_LANG_Modula2
:
13547 cu
->language
= language_m2
;
13549 case DW_LANG_Pascal83
:
13550 cu
->language
= language_pascal
;
13553 cu
->language
= language_objc
;
13555 case DW_LANG_Cobol74
:
13556 case DW_LANG_Cobol85
:
13558 cu
->language
= language_minimal
;
13561 cu
->language_defn
= language_def (cu
->language
);
13564 /* Return the named attribute or NULL if not there. */
13566 static struct attribute
*
13567 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
13572 struct attribute
*spec
= NULL
;
13574 for (i
= 0; i
< die
->num_attrs
; ++i
)
13576 if (die
->attrs
[i
].name
== name
)
13577 return &die
->attrs
[i
];
13578 if (die
->attrs
[i
].name
== DW_AT_specification
13579 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
13580 spec
= &die
->attrs
[i
];
13586 die
= follow_die_ref (die
, spec
, &cu
);
13592 /* Return the named attribute or NULL if not there,
13593 but do not follow DW_AT_specification, etc.
13594 This is for use in contexts where we're reading .debug_types dies.
13595 Following DW_AT_specification, DW_AT_abstract_origin will take us
13596 back up the chain, and we want to go down. */
13598 static struct attribute
*
13599 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
13603 for (i
= 0; i
< die
->num_attrs
; ++i
)
13604 if (die
->attrs
[i
].name
== name
)
13605 return &die
->attrs
[i
];
13610 /* Return non-zero iff the attribute NAME is defined for the given DIE,
13611 and holds a non-zero value. This function should only be used for
13612 DW_FORM_flag or DW_FORM_flag_present attributes. */
13615 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
13617 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
13619 return (attr
&& DW_UNSND (attr
));
13623 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
13625 /* A DIE is a declaration if it has a DW_AT_declaration attribute
13626 which value is non-zero. However, we have to be careful with
13627 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
13628 (via dwarf2_flag_true_p) follows this attribute. So we may
13629 end up accidently finding a declaration attribute that belongs
13630 to a different DIE referenced by the specification attribute,
13631 even though the given DIE does not have a declaration attribute. */
13632 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
13633 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
13636 /* Return the die giving the specification for DIE, if there is
13637 one. *SPEC_CU is the CU containing DIE on input, and the CU
13638 containing the return value on output. If there is no
13639 specification, but there is an abstract origin, that is
13642 static struct die_info
*
13643 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
13645 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
13648 if (spec_attr
== NULL
)
13649 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
13651 if (spec_attr
== NULL
)
13654 return follow_die_ref (die
, spec_attr
, spec_cu
);
13657 /* Free the line_header structure *LH, and any arrays and strings it
13659 NOTE: This is also used as a "cleanup" function. */
13662 free_line_header (struct line_header
*lh
)
13664 if (lh
->standard_opcode_lengths
)
13665 xfree (lh
->standard_opcode_lengths
);
13667 /* Remember that all the lh->file_names[i].name pointers are
13668 pointers into debug_line_buffer, and don't need to be freed. */
13669 if (lh
->file_names
)
13670 xfree (lh
->file_names
);
13672 /* Similarly for the include directory names. */
13673 if (lh
->include_dirs
)
13674 xfree (lh
->include_dirs
);
13679 /* Add an entry to LH's include directory table. */
13682 add_include_dir (struct line_header
*lh
, char *include_dir
)
13684 /* Grow the array if necessary. */
13685 if (lh
->include_dirs_size
== 0)
13687 lh
->include_dirs_size
= 1; /* for testing */
13688 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
13689 * sizeof (*lh
->include_dirs
));
13691 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
13693 lh
->include_dirs_size
*= 2;
13694 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
13695 (lh
->include_dirs_size
13696 * sizeof (*lh
->include_dirs
)));
13699 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
13702 /* Add an entry to LH's file name table. */
13705 add_file_name (struct line_header
*lh
,
13707 unsigned int dir_index
,
13708 unsigned int mod_time
,
13709 unsigned int length
)
13711 struct file_entry
*fe
;
13713 /* Grow the array if necessary. */
13714 if (lh
->file_names_size
== 0)
13716 lh
->file_names_size
= 1; /* for testing */
13717 lh
->file_names
= xmalloc (lh
->file_names_size
13718 * sizeof (*lh
->file_names
));
13720 else if (lh
->num_file_names
>= lh
->file_names_size
)
13722 lh
->file_names_size
*= 2;
13723 lh
->file_names
= xrealloc (lh
->file_names
,
13724 (lh
->file_names_size
13725 * sizeof (*lh
->file_names
)));
13728 fe
= &lh
->file_names
[lh
->num_file_names
++];
13730 fe
->dir_index
= dir_index
;
13731 fe
->mod_time
= mod_time
;
13732 fe
->length
= length
;
13733 fe
->included_p
= 0;
13737 /* Read the statement program header starting at OFFSET in
13738 .debug_line, or .debug_line.dwo. Return a pointer
13739 to a struct line_header, allocated using xmalloc.
13741 NOTE: the strings in the include directory and file name tables of
13742 the returned object point into the dwarf line section buffer,
13743 and must not be freed. */
13745 static struct line_header
*
13746 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
13748 struct cleanup
*back_to
;
13749 struct line_header
*lh
;
13750 gdb_byte
*line_ptr
;
13751 unsigned int bytes_read
, offset_size
;
13753 char *cur_dir
, *cur_file
;
13754 struct dwarf2_section_info
*section
;
13757 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
13759 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13760 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
13762 section
= &dwarf2_per_objfile
->line
;
13764 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
13765 if (section
->buffer
== NULL
)
13767 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13768 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
13770 complaint (&symfile_complaints
, _("missing .debug_line section"));
13774 /* We can't do this until we know the section is non-empty.
13775 Only then do we know we have such a section. */
13776 abfd
= section
->asection
->owner
;
13778 /* Make sure that at least there's room for the total_length field.
13779 That could be 12 bytes long, but we're just going to fudge that. */
13780 if (offset
+ 4 >= section
->size
)
13782 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13786 lh
= xmalloc (sizeof (*lh
));
13787 memset (lh
, 0, sizeof (*lh
));
13788 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
13791 line_ptr
= section
->buffer
+ offset
;
13793 /* Read in the header. */
13795 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
13796 &bytes_read
, &offset_size
);
13797 line_ptr
+= bytes_read
;
13798 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
13800 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13803 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
13804 lh
->version
= read_2_bytes (abfd
, line_ptr
);
13806 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
13807 line_ptr
+= offset_size
;
13808 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
13810 if (lh
->version
>= 4)
13812 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
13816 lh
->maximum_ops_per_instruction
= 1;
13818 if (lh
->maximum_ops_per_instruction
== 0)
13820 lh
->maximum_ops_per_instruction
= 1;
13821 complaint (&symfile_complaints
,
13822 _("invalid maximum_ops_per_instruction "
13823 "in `.debug_line' section"));
13826 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
13828 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
13830 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
13832 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
13834 lh
->standard_opcode_lengths
13835 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
13837 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
13838 for (i
= 1; i
< lh
->opcode_base
; ++i
)
13840 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
13844 /* Read directory table. */
13845 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13847 line_ptr
+= bytes_read
;
13848 add_include_dir (lh
, cur_dir
);
13850 line_ptr
+= bytes_read
;
13852 /* Read file name table. */
13853 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13855 unsigned int dir_index
, mod_time
, length
;
13857 line_ptr
+= bytes_read
;
13858 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13859 line_ptr
+= bytes_read
;
13860 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13861 line_ptr
+= bytes_read
;
13862 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13863 line_ptr
+= bytes_read
;
13865 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13867 line_ptr
+= bytes_read
;
13868 lh
->statement_program_start
= line_ptr
;
13870 if (line_ptr
> (section
->buffer
+ section
->size
))
13871 complaint (&symfile_complaints
,
13872 _("line number info header doesn't "
13873 "fit in `.debug_line' section"));
13875 discard_cleanups (back_to
);
13879 /* Subroutine of dwarf_decode_lines to simplify it.
13880 Return the file name of the psymtab for included file FILE_INDEX
13881 in line header LH of PST.
13882 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13883 If space for the result is malloc'd, it will be freed by a cleanup.
13884 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
13887 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
13888 const struct partial_symtab
*pst
,
13889 const char *comp_dir
)
13891 const struct file_entry fe
= lh
->file_names
[file_index
];
13892 char *include_name
= fe
.name
;
13893 char *include_name_to_compare
= include_name
;
13894 char *dir_name
= NULL
;
13895 const char *pst_filename
;
13896 char *copied_name
= NULL
;
13900 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
13902 if (!IS_ABSOLUTE_PATH (include_name
)
13903 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
13905 /* Avoid creating a duplicate psymtab for PST.
13906 We do this by comparing INCLUDE_NAME and PST_FILENAME.
13907 Before we do the comparison, however, we need to account
13908 for DIR_NAME and COMP_DIR.
13909 First prepend dir_name (if non-NULL). If we still don't
13910 have an absolute path prepend comp_dir (if non-NULL).
13911 However, the directory we record in the include-file's
13912 psymtab does not contain COMP_DIR (to match the
13913 corresponding symtab(s)).
13918 bash$ gcc -g ./hello.c
13919 include_name = "hello.c"
13921 DW_AT_comp_dir = comp_dir = "/tmp"
13922 DW_AT_name = "./hello.c" */
13924 if (dir_name
!= NULL
)
13926 include_name
= concat (dir_name
, SLASH_STRING
,
13927 include_name
, (char *)NULL
);
13928 include_name_to_compare
= include_name
;
13929 make_cleanup (xfree
, include_name
);
13931 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
13933 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
13934 include_name
, (char *)NULL
);
13938 pst_filename
= pst
->filename
;
13939 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
13941 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
13942 pst_filename
, (char *)NULL
);
13943 pst_filename
= copied_name
;
13946 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
13948 if (include_name_to_compare
!= include_name
)
13949 xfree (include_name_to_compare
);
13950 if (copied_name
!= NULL
)
13951 xfree (copied_name
);
13955 return include_name
;
13958 /* Ignore this record_line request. */
13961 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13966 /* Subroutine of dwarf_decode_lines to simplify it.
13967 Process the line number information in LH. */
13970 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
13971 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
13973 gdb_byte
*line_ptr
, *extended_end
;
13974 gdb_byte
*line_end
;
13975 unsigned int bytes_read
, extended_len
;
13976 unsigned char op_code
, extended_op
, adj_opcode
;
13977 CORE_ADDR baseaddr
;
13978 struct objfile
*objfile
= cu
->objfile
;
13979 bfd
*abfd
= objfile
->obfd
;
13980 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13981 const int decode_for_pst_p
= (pst
!= NULL
);
13982 struct subfile
*last_subfile
= NULL
;
13983 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13986 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13988 line_ptr
= lh
->statement_program_start
;
13989 line_end
= lh
->statement_program_end
;
13991 /* Read the statement sequences until there's nothing left. */
13992 while (line_ptr
< line_end
)
13994 /* state machine registers */
13995 CORE_ADDR address
= 0;
13996 unsigned int file
= 1;
13997 unsigned int line
= 1;
13998 unsigned int column
= 0;
13999 int is_stmt
= lh
->default_is_stmt
;
14000 int basic_block
= 0;
14001 int end_sequence
= 0;
14003 unsigned char op_index
= 0;
14005 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
14007 /* Start a subfile for the current file of the state machine. */
14008 /* lh->include_dirs and lh->file_names are 0-based, but the
14009 directory and file name numbers in the statement program
14011 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14015 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14017 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14020 /* Decode the table. */
14021 while (!end_sequence
)
14023 op_code
= read_1_byte (abfd
, line_ptr
);
14025 if (line_ptr
> line_end
)
14027 dwarf2_debug_line_missing_end_sequence_complaint ();
14031 if (op_code
>= lh
->opcode_base
)
14033 /* Special operand. */
14034 adj_opcode
= op_code
- lh
->opcode_base
;
14035 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
14036 / lh
->maximum_ops_per_instruction
)
14037 * lh
->minimum_instruction_length
);
14038 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
14039 % lh
->maximum_ops_per_instruction
);
14040 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
14041 if (lh
->num_file_names
< file
|| file
== 0)
14042 dwarf2_debug_line_missing_file_complaint ();
14043 /* For now we ignore lines not starting on an
14044 instruction boundary. */
14045 else if (op_index
== 0)
14047 lh
->file_names
[file
- 1].included_p
= 1;
14048 if (!decode_for_pst_p
&& is_stmt
)
14050 if (last_subfile
!= current_subfile
)
14052 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14054 (*p_record_line
) (last_subfile
, 0, addr
);
14055 last_subfile
= current_subfile
;
14057 /* Append row to matrix using current values. */
14058 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14059 (*p_record_line
) (current_subfile
, line
, addr
);
14064 else switch (op_code
)
14066 case DW_LNS_extended_op
:
14067 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
14069 line_ptr
+= bytes_read
;
14070 extended_end
= line_ptr
+ extended_len
;
14071 extended_op
= read_1_byte (abfd
, line_ptr
);
14073 switch (extended_op
)
14075 case DW_LNE_end_sequence
:
14076 p_record_line
= record_line
;
14079 case DW_LNE_set_address
:
14080 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
14082 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14084 /* This line table is for a function which has been
14085 GCd by the linker. Ignore it. PR gdb/12528 */
14088 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
14090 complaint (&symfile_complaints
,
14091 _(".debug_line address at offset 0x%lx is 0 "
14093 line_offset
, objfile
->name
);
14094 p_record_line
= noop_record_line
;
14098 line_ptr
+= bytes_read
;
14099 address
+= baseaddr
;
14101 case DW_LNE_define_file
:
14104 unsigned int dir_index
, mod_time
, length
;
14106 cur_file
= read_direct_string (abfd
, line_ptr
,
14108 line_ptr
+= bytes_read
;
14110 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14111 line_ptr
+= bytes_read
;
14113 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14114 line_ptr
+= bytes_read
;
14116 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14117 line_ptr
+= bytes_read
;
14118 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14121 case DW_LNE_set_discriminator
:
14122 /* The discriminator is not interesting to the debugger;
14124 line_ptr
= extended_end
;
14127 complaint (&symfile_complaints
,
14128 _("mangled .debug_line section"));
14131 /* Make sure that we parsed the extended op correctly. If e.g.
14132 we expected a different address size than the producer used,
14133 we may have read the wrong number of bytes. */
14134 if (line_ptr
!= extended_end
)
14136 complaint (&symfile_complaints
,
14137 _("mangled .debug_line section"));
14142 if (lh
->num_file_names
< file
|| file
== 0)
14143 dwarf2_debug_line_missing_file_complaint ();
14146 lh
->file_names
[file
- 1].included_p
= 1;
14147 if (!decode_for_pst_p
&& is_stmt
)
14149 if (last_subfile
!= current_subfile
)
14151 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14153 (*p_record_line
) (last_subfile
, 0, addr
);
14154 last_subfile
= current_subfile
;
14156 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14157 (*p_record_line
) (current_subfile
, line
, addr
);
14162 case DW_LNS_advance_pc
:
14165 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14167 address
+= (((op_index
+ adjust
)
14168 / lh
->maximum_ops_per_instruction
)
14169 * lh
->minimum_instruction_length
);
14170 op_index
= ((op_index
+ adjust
)
14171 % lh
->maximum_ops_per_instruction
);
14172 line_ptr
+= bytes_read
;
14175 case DW_LNS_advance_line
:
14176 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
14177 line_ptr
+= bytes_read
;
14179 case DW_LNS_set_file
:
14181 /* The arrays lh->include_dirs and lh->file_names are
14182 0-based, but the directory and file name numbers in
14183 the statement program are 1-based. */
14184 struct file_entry
*fe
;
14187 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14188 line_ptr
+= bytes_read
;
14189 if (lh
->num_file_names
< file
|| file
== 0)
14190 dwarf2_debug_line_missing_file_complaint ();
14193 fe
= &lh
->file_names
[file
- 1];
14195 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14196 if (!decode_for_pst_p
)
14198 last_subfile
= current_subfile
;
14199 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14204 case DW_LNS_set_column
:
14205 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14206 line_ptr
+= bytes_read
;
14208 case DW_LNS_negate_stmt
:
14209 is_stmt
= (!is_stmt
);
14211 case DW_LNS_set_basic_block
:
14214 /* Add to the address register of the state machine the
14215 address increment value corresponding to special opcode
14216 255. I.e., this value is scaled by the minimum
14217 instruction length since special opcode 255 would have
14218 scaled the increment. */
14219 case DW_LNS_const_add_pc
:
14221 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
14223 address
+= (((op_index
+ adjust
)
14224 / lh
->maximum_ops_per_instruction
)
14225 * lh
->minimum_instruction_length
);
14226 op_index
= ((op_index
+ adjust
)
14227 % lh
->maximum_ops_per_instruction
);
14230 case DW_LNS_fixed_advance_pc
:
14231 address
+= read_2_bytes (abfd
, line_ptr
);
14237 /* Unknown standard opcode, ignore it. */
14240 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
14242 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14243 line_ptr
+= bytes_read
;
14248 if (lh
->num_file_names
< file
|| file
== 0)
14249 dwarf2_debug_line_missing_file_complaint ();
14252 lh
->file_names
[file
- 1].included_p
= 1;
14253 if (!decode_for_pst_p
)
14255 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14256 (*p_record_line
) (current_subfile
, 0, addr
);
14262 /* Decode the Line Number Program (LNP) for the given line_header
14263 structure and CU. The actual information extracted and the type
14264 of structures created from the LNP depends on the value of PST.
14266 1. If PST is NULL, then this procedure uses the data from the program
14267 to create all necessary symbol tables, and their linetables.
14269 2. If PST is not NULL, this procedure reads the program to determine
14270 the list of files included by the unit represented by PST, and
14271 builds all the associated partial symbol tables.
14273 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
14274 It is used for relative paths in the line table.
14275 NOTE: When processing partial symtabs (pst != NULL),
14276 comp_dir == pst->dirname.
14278 NOTE: It is important that psymtabs have the same file name (via strcmp)
14279 as the corresponding symtab. Since COMP_DIR is not used in the name of the
14280 symtab we don't use it in the name of the psymtabs we create.
14281 E.g. expand_line_sal requires this when finding psymtabs to expand.
14282 A good testcase for this is mb-inline.exp. */
14285 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
14286 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
14287 int want_line_info
)
14289 struct objfile
*objfile
= cu
->objfile
;
14290 const int decode_for_pst_p
= (pst
!= NULL
);
14291 struct subfile
*first_subfile
= current_subfile
;
14293 if (want_line_info
)
14294 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
14296 if (decode_for_pst_p
)
14300 /* Now that we're done scanning the Line Header Program, we can
14301 create the psymtab of each included file. */
14302 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
14303 if (lh
->file_names
[file_index
].included_p
== 1)
14305 char *include_name
=
14306 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
14307 if (include_name
!= NULL
)
14308 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
14313 /* Make sure a symtab is created for every file, even files
14314 which contain only variables (i.e. no code with associated
14318 for (i
= 0; i
< lh
->num_file_names
; i
++)
14321 struct file_entry
*fe
;
14323 fe
= &lh
->file_names
[i
];
14325 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14326 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14328 /* Skip the main file; we don't need it, and it must be
14329 allocated last, so that it will show up before the
14330 non-primary symtabs in the objfile's symtab list. */
14331 if (current_subfile
== first_subfile
)
14334 if (current_subfile
->symtab
== NULL
)
14335 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
14337 fe
->symtab
= current_subfile
->symtab
;
14342 /* Start a subfile for DWARF. FILENAME is the name of the file and
14343 DIRNAME the name of the source directory which contains FILENAME
14344 or NULL if not known. COMP_DIR is the compilation directory for the
14345 linetable's compilation unit or NULL if not known.
14346 This routine tries to keep line numbers from identical absolute and
14347 relative file names in a common subfile.
14349 Using the `list' example from the GDB testsuite, which resides in
14350 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
14351 of /srcdir/list0.c yields the following debugging information for list0.c:
14353 DW_AT_name: /srcdir/list0.c
14354 DW_AT_comp_dir: /compdir
14355 files.files[0].name: list0.h
14356 files.files[0].dir: /srcdir
14357 files.files[1].name: list0.c
14358 files.files[1].dir: /srcdir
14360 The line number information for list0.c has to end up in a single
14361 subfile, so that `break /srcdir/list0.c:1' works as expected.
14362 start_subfile will ensure that this happens provided that we pass the
14363 concatenation of files.files[1].dir and files.files[1].name as the
14367 dwarf2_start_subfile (char *filename
, const char *dirname
,
14368 const char *comp_dir
)
14372 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
14373 `start_symtab' will always pass the contents of DW_AT_comp_dir as
14374 second argument to start_subfile. To be consistent, we do the
14375 same here. In order not to lose the line information directory,
14376 we concatenate it to the filename when it makes sense.
14377 Note that the Dwarf3 standard says (speaking of filenames in line
14378 information): ``The directory index is ignored for file names
14379 that represent full path names''. Thus ignoring dirname in the
14380 `else' branch below isn't an issue. */
14382 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
14383 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
14385 fullname
= filename
;
14387 start_subfile (fullname
, comp_dir
);
14389 if (fullname
!= filename
)
14393 /* Start a symtab for DWARF.
14394 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
14397 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
14398 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
14400 start_symtab (name
, comp_dir
, low_pc
);
14401 record_debugformat ("DWARF 2");
14402 record_producer (cu
->producer
);
14404 /* We assume that we're processing GCC output. */
14405 processing_gcc_compilation
= 2;
14407 processing_has_namespace_info
= 0;
14411 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
14412 struct dwarf2_cu
*cu
)
14414 struct objfile
*objfile
= cu
->objfile
;
14415 struct comp_unit_head
*cu_header
= &cu
->header
;
14417 /* NOTE drow/2003-01-30: There used to be a comment and some special
14418 code here to turn a symbol with DW_AT_external and a
14419 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
14420 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
14421 with some versions of binutils) where shared libraries could have
14422 relocations against symbols in their debug information - the
14423 minimal symbol would have the right address, but the debug info
14424 would not. It's no longer necessary, because we will explicitly
14425 apply relocations when we read in the debug information now. */
14427 /* A DW_AT_location attribute with no contents indicates that a
14428 variable has been optimized away. */
14429 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
14431 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14435 /* Handle one degenerate form of location expression specially, to
14436 preserve GDB's previous behavior when section offsets are
14437 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
14438 then mark this symbol as LOC_STATIC. */
14440 if (attr_form_is_block (attr
)
14441 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
14442 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
14443 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
14444 && (DW_BLOCK (attr
)->size
14445 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
14447 unsigned int dummy
;
14449 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
14450 SYMBOL_VALUE_ADDRESS (sym
) =
14451 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
14453 SYMBOL_VALUE_ADDRESS (sym
) =
14454 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
14455 SYMBOL_CLASS (sym
) = LOC_STATIC
;
14456 fixup_symbol_section (sym
, objfile
);
14457 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
14458 SYMBOL_SECTION (sym
));
14462 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
14463 expression evaluator, and use LOC_COMPUTED only when necessary
14464 (i.e. when the value of a register or memory location is
14465 referenced, or a thread-local block, etc.). Then again, it might
14466 not be worthwhile. I'm assuming that it isn't unless performance
14467 or memory numbers show me otherwise. */
14469 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
14470 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14472 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
14473 cu
->has_loclist
= 1;
14476 /* Given a pointer to a DWARF information entry, figure out if we need
14477 to make a symbol table entry for it, and if so, create a new entry
14478 and return a pointer to it.
14479 If TYPE is NULL, determine symbol type from the die, otherwise
14480 used the passed type.
14481 If SPACE is not NULL, use it to hold the new symbol. If it is
14482 NULL, allocate a new symbol on the objfile's obstack. */
14484 static struct symbol
*
14485 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
14486 struct symbol
*space
)
14488 struct objfile
*objfile
= cu
->objfile
;
14489 struct symbol
*sym
= NULL
;
14491 struct attribute
*attr
= NULL
;
14492 struct attribute
*attr2
= NULL
;
14493 CORE_ADDR baseaddr
;
14494 struct pending
**list_to_add
= NULL
;
14496 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14498 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14500 name
= dwarf2_name (die
, cu
);
14503 const char *linkagename
;
14504 int suppress_add
= 0;
14509 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
14510 OBJSTAT (objfile
, n_syms
++);
14512 /* Cache this symbol's name and the name's demangled form (if any). */
14513 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
14514 linkagename
= dwarf2_physname (name
, die
, cu
);
14515 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
14517 /* Fortran does not have mangling standard and the mangling does differ
14518 between gfortran, iFort etc. */
14519 if (cu
->language
== language_fortran
14520 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
14521 symbol_set_demangled_name (&(sym
->ginfo
),
14522 (char *) dwarf2_full_name (name
, die
, cu
),
14525 /* Default assumptions.
14526 Use the passed type or decode it from the die. */
14527 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14528 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14530 SYMBOL_TYPE (sym
) = type
;
14532 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
14533 attr
= dwarf2_attr (die
,
14534 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
14538 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
14541 attr
= dwarf2_attr (die
,
14542 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
14546 int file_index
= DW_UNSND (attr
);
14548 if (cu
->line_header
== NULL
14549 || file_index
> cu
->line_header
->num_file_names
)
14550 complaint (&symfile_complaints
,
14551 _("file index out of range"));
14552 else if (file_index
> 0)
14554 struct file_entry
*fe
;
14556 fe
= &cu
->line_header
->file_names
[file_index
- 1];
14557 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
14564 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14567 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
14569 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
14570 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
14571 SYMBOL_CLASS (sym
) = LOC_LABEL
;
14572 add_symbol_to_list (sym
, cu
->list_in_scope
);
14574 case DW_TAG_subprogram
:
14575 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14577 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14578 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14579 if ((attr2
&& (DW_UNSND (attr2
) != 0))
14580 || cu
->language
== language_ada
)
14582 /* Subprograms marked external are stored as a global symbol.
14583 Ada subprograms, whether marked external or not, are always
14584 stored as a global symbol, because we want to be able to
14585 access them globally. For instance, we want to be able
14586 to break on a nested subprogram without having to
14587 specify the context. */
14588 list_to_add
= &global_symbols
;
14592 list_to_add
= cu
->list_in_scope
;
14595 case DW_TAG_inlined_subroutine
:
14596 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14598 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14599 SYMBOL_INLINED (sym
) = 1;
14600 list_to_add
= cu
->list_in_scope
;
14602 case DW_TAG_template_value_param
:
14604 /* Fall through. */
14605 case DW_TAG_constant
:
14606 case DW_TAG_variable
:
14607 case DW_TAG_member
:
14608 /* Compilation with minimal debug info may result in
14609 variables with missing type entries. Change the
14610 misleading `void' type to something sensible. */
14611 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
14613 = objfile_type (objfile
)->nodebug_data_symbol
;
14615 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14616 /* In the case of DW_TAG_member, we should only be called for
14617 static const members. */
14618 if (die
->tag
== DW_TAG_member
)
14620 /* dwarf2_add_field uses die_is_declaration,
14621 so we do the same. */
14622 gdb_assert (die_is_declaration (die
, cu
));
14627 dwarf2_const_value (attr
, sym
, cu
);
14628 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14631 if (attr2
&& (DW_UNSND (attr2
) != 0))
14632 list_to_add
= &global_symbols
;
14634 list_to_add
= cu
->list_in_scope
;
14638 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14641 var_decode_location (attr
, sym
, cu
);
14642 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14643 if (SYMBOL_CLASS (sym
) == LOC_STATIC
14644 && SYMBOL_VALUE_ADDRESS (sym
) == 0
14645 && !dwarf2_per_objfile
->has_section_at_zero
)
14647 /* When a static variable is eliminated by the linker,
14648 the corresponding debug information is not stripped
14649 out, but the variable address is set to null;
14650 do not add such variables into symbol table. */
14652 else if (attr2
&& (DW_UNSND (attr2
) != 0))
14654 /* Workaround gfortran PR debug/40040 - it uses
14655 DW_AT_location for variables in -fPIC libraries which may
14656 get overriden by other libraries/executable and get
14657 a different address. Resolve it by the minimal symbol
14658 which may come from inferior's executable using copy
14659 relocation. Make this workaround only for gfortran as for
14660 other compilers GDB cannot guess the minimal symbol
14661 Fortran mangling kind. */
14662 if (cu
->language
== language_fortran
&& die
->parent
14663 && die
->parent
->tag
== DW_TAG_module
14665 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
14666 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14668 /* A variable with DW_AT_external is never static,
14669 but it may be block-scoped. */
14670 list_to_add
= (cu
->list_in_scope
== &file_symbols
14671 ? &global_symbols
: cu
->list_in_scope
);
14674 list_to_add
= cu
->list_in_scope
;
14678 /* We do not know the address of this symbol.
14679 If it is an external symbol and we have type information
14680 for it, enter the symbol as a LOC_UNRESOLVED symbol.
14681 The address of the variable will then be determined from
14682 the minimal symbol table whenever the variable is
14684 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14685 if (attr2
&& (DW_UNSND (attr2
) != 0)
14686 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
14688 /* A variable with DW_AT_external is never static, but it
14689 may be block-scoped. */
14690 list_to_add
= (cu
->list_in_scope
== &file_symbols
14691 ? &global_symbols
: cu
->list_in_scope
);
14693 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14695 else if (!die_is_declaration (die
, cu
))
14697 /* Use the default LOC_OPTIMIZED_OUT class. */
14698 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
14700 list_to_add
= cu
->list_in_scope
;
14704 case DW_TAG_formal_parameter
:
14705 /* If we are inside a function, mark this as an argument. If
14706 not, we might be looking at an argument to an inlined function
14707 when we do not have enough information to show inlined frames;
14708 pretend it's a local variable in that case so that the user can
14710 if (context_stack_depth
> 0
14711 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
14712 SYMBOL_IS_ARGUMENT (sym
) = 1;
14713 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14716 var_decode_location (attr
, sym
, cu
);
14718 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14721 dwarf2_const_value (attr
, sym
, cu
);
14724 list_to_add
= cu
->list_in_scope
;
14726 case DW_TAG_unspecified_parameters
:
14727 /* From varargs functions; gdb doesn't seem to have any
14728 interest in this information, so just ignore it for now.
14731 case DW_TAG_template_type_param
:
14733 /* Fall through. */
14734 case DW_TAG_class_type
:
14735 case DW_TAG_interface_type
:
14736 case DW_TAG_structure_type
:
14737 case DW_TAG_union_type
:
14738 case DW_TAG_set_type
:
14739 case DW_TAG_enumeration_type
:
14740 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14741 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
14744 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
14745 really ever be static objects: otherwise, if you try
14746 to, say, break of a class's method and you're in a file
14747 which doesn't mention that class, it won't work unless
14748 the check for all static symbols in lookup_symbol_aux
14749 saves you. See the OtherFileClass tests in
14750 gdb.c++/namespace.exp. */
14754 list_to_add
= (cu
->list_in_scope
== &file_symbols
14755 && (cu
->language
== language_cplus
14756 || cu
->language
== language_java
)
14757 ? &global_symbols
: cu
->list_in_scope
);
14759 /* The semantics of C++ state that "struct foo {
14760 ... }" also defines a typedef for "foo". A Java
14761 class declaration also defines a typedef for the
14763 if (cu
->language
== language_cplus
14764 || cu
->language
== language_java
14765 || cu
->language
== language_ada
)
14767 /* The symbol's name is already allocated along
14768 with this objfile, so we don't need to
14769 duplicate it for the type. */
14770 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
14771 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
14776 case DW_TAG_typedef
:
14777 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14778 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14779 list_to_add
= cu
->list_in_scope
;
14781 case DW_TAG_base_type
:
14782 case DW_TAG_subrange_type
:
14783 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14784 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14785 list_to_add
= cu
->list_in_scope
;
14787 case DW_TAG_enumerator
:
14788 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14791 dwarf2_const_value (attr
, sym
, cu
);
14794 /* NOTE: carlton/2003-11-10: See comment above in the
14795 DW_TAG_class_type, etc. block. */
14797 list_to_add
= (cu
->list_in_scope
== &file_symbols
14798 && (cu
->language
== language_cplus
14799 || cu
->language
== language_java
)
14800 ? &global_symbols
: cu
->list_in_scope
);
14803 case DW_TAG_namespace
:
14804 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14805 list_to_add
= &global_symbols
;
14808 /* Not a tag we recognize. Hopefully we aren't processing
14809 trash data, but since we must specifically ignore things
14810 we don't recognize, there is nothing else we should do at
14812 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
14813 dwarf_tag_name (die
->tag
));
14819 sym
->hash_next
= objfile
->template_symbols
;
14820 objfile
->template_symbols
= sym
;
14821 list_to_add
= NULL
;
14824 if (list_to_add
!= NULL
)
14825 add_symbol_to_list (sym
, list_to_add
);
14827 /* For the benefit of old versions of GCC, check for anonymous
14828 namespaces based on the demangled name. */
14829 if (!processing_has_namespace_info
14830 && cu
->language
== language_cplus
)
14831 cp_scan_for_anonymous_namespaces (sym
, objfile
);
14836 /* A wrapper for new_symbol_full that always allocates a new symbol. */
14838 static struct symbol
*
14839 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14841 return new_symbol_full (die
, type
, cu
, NULL
);
14844 /* Given an attr with a DW_FORM_dataN value in host byte order,
14845 zero-extend it as appropriate for the symbol's type. The DWARF
14846 standard (v4) is not entirely clear about the meaning of using
14847 DW_FORM_dataN for a constant with a signed type, where the type is
14848 wider than the data. The conclusion of a discussion on the DWARF
14849 list was that this is unspecified. We choose to always zero-extend
14850 because that is the interpretation long in use by GCC. */
14853 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
14854 const char *name
, struct obstack
*obstack
,
14855 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
14857 struct objfile
*objfile
= cu
->objfile
;
14858 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
14859 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
14860 LONGEST l
= DW_UNSND (attr
);
14862 if (bits
< sizeof (*value
) * 8)
14864 l
&= ((LONGEST
) 1 << bits
) - 1;
14867 else if (bits
== sizeof (*value
) * 8)
14871 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
14872 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
14879 /* Read a constant value from an attribute. Either set *VALUE, or if
14880 the value does not fit in *VALUE, set *BYTES - either already
14881 allocated on the objfile obstack, or newly allocated on OBSTACK,
14882 or, set *BATON, if we translated the constant to a location
14886 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
14887 const char *name
, struct obstack
*obstack
,
14888 struct dwarf2_cu
*cu
,
14889 LONGEST
*value
, gdb_byte
**bytes
,
14890 struct dwarf2_locexpr_baton
**baton
)
14892 struct objfile
*objfile
= cu
->objfile
;
14893 struct comp_unit_head
*cu_header
= &cu
->header
;
14894 struct dwarf_block
*blk
;
14895 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
14896 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
14902 switch (attr
->form
)
14905 case DW_FORM_GNU_addr_index
:
14909 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
14910 dwarf2_const_value_length_mismatch_complaint (name
,
14911 cu_header
->addr_size
,
14912 TYPE_LENGTH (type
));
14913 /* Symbols of this form are reasonably rare, so we just
14914 piggyback on the existing location code rather than writing
14915 a new implementation of symbol_computed_ops. */
14916 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
14917 sizeof (struct dwarf2_locexpr_baton
));
14918 (*baton
)->per_cu
= cu
->per_cu
;
14919 gdb_assert ((*baton
)->per_cu
);
14921 (*baton
)->size
= 2 + cu_header
->addr_size
;
14922 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
14923 (*baton
)->data
= data
;
14925 data
[0] = DW_OP_addr
;
14926 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
14927 byte_order
, DW_ADDR (attr
));
14928 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
14931 case DW_FORM_string
:
14933 case DW_FORM_GNU_str_index
:
14934 /* DW_STRING is already allocated on the objfile obstack, point
14936 *bytes
= (gdb_byte
*) DW_STRING (attr
);
14938 case DW_FORM_block1
:
14939 case DW_FORM_block2
:
14940 case DW_FORM_block4
:
14941 case DW_FORM_block
:
14942 case DW_FORM_exprloc
:
14943 blk
= DW_BLOCK (attr
);
14944 if (TYPE_LENGTH (type
) != blk
->size
)
14945 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
14946 TYPE_LENGTH (type
));
14947 *bytes
= blk
->data
;
14950 /* The DW_AT_const_value attributes are supposed to carry the
14951 symbol's value "represented as it would be on the target
14952 architecture." By the time we get here, it's already been
14953 converted to host endianness, so we just need to sign- or
14954 zero-extend it as appropriate. */
14955 case DW_FORM_data1
:
14956 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14957 obstack
, cu
, value
, 8);
14959 case DW_FORM_data2
:
14960 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14961 obstack
, cu
, value
, 16);
14963 case DW_FORM_data4
:
14964 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14965 obstack
, cu
, value
, 32);
14967 case DW_FORM_data8
:
14968 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14969 obstack
, cu
, value
, 64);
14972 case DW_FORM_sdata
:
14973 *value
= DW_SND (attr
);
14976 case DW_FORM_udata
:
14977 *value
= DW_UNSND (attr
);
14981 complaint (&symfile_complaints
,
14982 _("unsupported const value attribute form: '%s'"),
14983 dwarf_form_name (attr
->form
));
14990 /* Copy constant value from an attribute to a symbol. */
14993 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
14994 struct dwarf2_cu
*cu
)
14996 struct objfile
*objfile
= cu
->objfile
;
14997 struct comp_unit_head
*cu_header
= &cu
->header
;
15000 struct dwarf2_locexpr_baton
*baton
;
15002 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
15003 SYMBOL_PRINT_NAME (sym
),
15004 &objfile
->objfile_obstack
, cu
,
15005 &value
, &bytes
, &baton
);
15009 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15010 SYMBOL_LOCATION_BATON (sym
) = baton
;
15011 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15013 else if (bytes
!= NULL
)
15015 SYMBOL_VALUE_BYTES (sym
) = bytes
;
15016 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
15020 SYMBOL_VALUE (sym
) = value
;
15021 SYMBOL_CLASS (sym
) = LOC_CONST
;
15025 /* Return the type of the die in question using its DW_AT_type attribute. */
15027 static struct type
*
15028 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15030 struct attribute
*type_attr
;
15032 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15035 /* A missing DW_AT_type represents a void type. */
15036 return objfile_type (cu
->objfile
)->builtin_void
;
15039 return lookup_die_type (die
, type_attr
, cu
);
15042 /* True iff CU's producer generates GNAT Ada auxiliary information
15043 that allows to find parallel types through that information instead
15044 of having to do expensive parallel lookups by type name. */
15047 need_gnat_info (struct dwarf2_cu
*cu
)
15049 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
15050 of GNAT produces this auxiliary information, without any indication
15051 that it is produced. Part of enhancing the FSF version of GNAT
15052 to produce that information will be to put in place an indicator
15053 that we can use in order to determine whether the descriptive type
15054 info is available or not. One suggestion that has been made is
15055 to use a new attribute, attached to the CU die. For now, assume
15056 that the descriptive type info is not available. */
15060 /* Return the auxiliary type of the die in question using its
15061 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
15062 attribute is not present. */
15064 static struct type
*
15065 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15067 struct attribute
*type_attr
;
15069 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
15073 return lookup_die_type (die
, type_attr
, cu
);
15076 /* If DIE has a descriptive_type attribute, then set the TYPE's
15077 descriptive type accordingly. */
15080 set_descriptive_type (struct type
*type
, struct die_info
*die
,
15081 struct dwarf2_cu
*cu
)
15083 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
15085 if (descriptive_type
)
15087 ALLOCATE_GNAT_AUX_TYPE (type
);
15088 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
15092 /* Return the containing type of the die in question using its
15093 DW_AT_containing_type attribute. */
15095 static struct type
*
15096 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15098 struct attribute
*type_attr
;
15100 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
15102 error (_("Dwarf Error: Problem turning containing type into gdb type "
15103 "[in module %s]"), cu
->objfile
->name
);
15105 return lookup_die_type (die
, type_attr
, cu
);
15108 /* Look up the type of DIE in CU using its type attribute ATTR.
15109 If there is no type substitute an error marker. */
15111 static struct type
*
15112 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
15113 struct dwarf2_cu
*cu
)
15115 struct objfile
*objfile
= cu
->objfile
;
15116 struct type
*this_type
;
15118 /* First see if we have it cached. */
15120 if (is_ref_attr (attr
))
15122 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15124 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
15126 else if (attr
->form
== DW_FORM_ref_sig8
)
15128 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15130 /* sig_type will be NULL if the signatured type is missing from
15132 if (sig_type
== NULL
)
15133 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15134 "at 0x%x [in module %s]"),
15135 die
->offset
.sect_off
, objfile
->name
);
15137 gdb_assert (sig_type
->per_cu
.is_debug_types
);
15138 /* If we haven't filled in type_offset_in_section yet, then we
15139 haven't read the type in yet. */
15141 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
15144 get_die_type_at_offset (sig_type
->type_offset_in_section
,
15145 &sig_type
->per_cu
);
15150 dump_die_for_error (die
);
15151 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
15152 dwarf_attr_name (attr
->name
), objfile
->name
);
15155 /* If not cached we need to read it in. */
15157 if (this_type
== NULL
)
15159 struct die_info
*type_die
;
15160 struct dwarf2_cu
*type_cu
= cu
;
15162 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
15163 /* If we found the type now, it's probably because the type came
15164 from an inter-CU reference and the type's CU got expanded before
15166 this_type
= get_die_type (type_die
, type_cu
);
15167 if (this_type
== NULL
)
15168 this_type
= read_type_die_1 (type_die
, type_cu
);
15171 /* If we still don't have a type use an error marker. */
15173 if (this_type
== NULL
)
15175 char *message
, *saved
;
15177 /* read_type_die already issued a complaint. */
15178 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
15180 cu
->header
.offset
.sect_off
,
15181 die
->offset
.sect_off
);
15182 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
15183 message
, strlen (message
));
15186 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
15192 /* Return the type in DIE, CU.
15193 Returns NULL for invalid types.
15195 This first does a lookup in the appropriate type_hash table,
15196 and only reads the die in if necessary.
15198 NOTE: This can be called when reading in partial or full symbols. */
15200 static struct type
*
15201 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
15203 struct type
*this_type
;
15205 this_type
= get_die_type (die
, cu
);
15209 return read_type_die_1 (die
, cu
);
15212 /* Read the type in DIE, CU.
15213 Returns NULL for invalid types. */
15215 static struct type
*
15216 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
15218 struct type
*this_type
= NULL
;
15222 case DW_TAG_class_type
:
15223 case DW_TAG_interface_type
:
15224 case DW_TAG_structure_type
:
15225 case DW_TAG_union_type
:
15226 this_type
= read_structure_type (die
, cu
);
15228 case DW_TAG_enumeration_type
:
15229 this_type
= read_enumeration_type (die
, cu
);
15231 case DW_TAG_subprogram
:
15232 case DW_TAG_subroutine_type
:
15233 case DW_TAG_inlined_subroutine
:
15234 this_type
= read_subroutine_type (die
, cu
);
15236 case DW_TAG_array_type
:
15237 this_type
= read_array_type (die
, cu
);
15239 case DW_TAG_set_type
:
15240 this_type
= read_set_type (die
, cu
);
15242 case DW_TAG_pointer_type
:
15243 this_type
= read_tag_pointer_type (die
, cu
);
15245 case DW_TAG_ptr_to_member_type
:
15246 this_type
= read_tag_ptr_to_member_type (die
, cu
);
15248 case DW_TAG_reference_type
:
15249 this_type
= read_tag_reference_type (die
, cu
);
15251 case DW_TAG_const_type
:
15252 this_type
= read_tag_const_type (die
, cu
);
15254 case DW_TAG_volatile_type
:
15255 this_type
= read_tag_volatile_type (die
, cu
);
15257 case DW_TAG_string_type
:
15258 this_type
= read_tag_string_type (die
, cu
);
15260 case DW_TAG_typedef
:
15261 this_type
= read_typedef (die
, cu
);
15263 case DW_TAG_subrange_type
:
15264 this_type
= read_subrange_type (die
, cu
);
15266 case DW_TAG_base_type
:
15267 this_type
= read_base_type (die
, cu
);
15269 case DW_TAG_unspecified_type
:
15270 this_type
= read_unspecified_type (die
, cu
);
15272 case DW_TAG_namespace
:
15273 this_type
= read_namespace_type (die
, cu
);
15275 case DW_TAG_module
:
15276 this_type
= read_module_type (die
, cu
);
15279 complaint (&symfile_complaints
,
15280 _("unexpected tag in read_type_die: '%s'"),
15281 dwarf_tag_name (die
->tag
));
15288 /* See if we can figure out if the class lives in a namespace. We do
15289 this by looking for a member function; its demangled name will
15290 contain namespace info, if there is any.
15291 Return the computed name or NULL.
15292 Space for the result is allocated on the objfile's obstack.
15293 This is the full-die version of guess_partial_die_structure_name.
15294 In this case we know DIE has no useful parent. */
15297 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15299 struct die_info
*spec_die
;
15300 struct dwarf2_cu
*spec_cu
;
15301 struct die_info
*child
;
15304 spec_die
= die_specification (die
, &spec_cu
);
15305 if (spec_die
!= NULL
)
15311 for (child
= die
->child
;
15313 child
= child
->sibling
)
15315 if (child
->tag
== DW_TAG_subprogram
)
15317 struct attribute
*attr
;
15319 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
15321 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
15325 = language_class_name_from_physname (cu
->language_defn
,
15329 if (actual_name
!= NULL
)
15331 char *die_name
= dwarf2_name (die
, cu
);
15333 if (die_name
!= NULL
15334 && strcmp (die_name
, actual_name
) != 0)
15336 /* Strip off the class name from the full name.
15337 We want the prefix. */
15338 int die_name_len
= strlen (die_name
);
15339 int actual_name_len
= strlen (actual_name
);
15341 /* Test for '::' as a sanity check. */
15342 if (actual_name_len
> die_name_len
+ 2
15343 && actual_name
[actual_name_len
15344 - die_name_len
- 1] == ':')
15346 obsavestring (actual_name
,
15347 actual_name_len
- die_name_len
- 2,
15348 &cu
->objfile
->objfile_obstack
);
15351 xfree (actual_name
);
15360 /* GCC might emit a nameless typedef that has a linkage name. Determine the
15361 prefix part in such case. See
15362 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15365 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15367 struct attribute
*attr
;
15370 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
15371 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
15374 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15375 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
15378 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15380 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15381 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15384 /* dwarf2_name had to be already called. */
15385 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
15387 /* Strip the base name, keep any leading namespaces/classes. */
15388 base
= strrchr (DW_STRING (attr
), ':');
15389 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
15392 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
15393 &cu
->objfile
->objfile_obstack
);
15396 /* Return the name of the namespace/class that DIE is defined within,
15397 or "" if we can't tell. The caller should not xfree the result.
15399 For example, if we're within the method foo() in the following
15409 then determine_prefix on foo's die will return "N::C". */
15411 static const char *
15412 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15414 struct die_info
*parent
, *spec_die
;
15415 struct dwarf2_cu
*spec_cu
;
15416 struct type
*parent_type
;
15419 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
15420 && cu
->language
!= language_fortran
)
15423 retval
= anonymous_struct_prefix (die
, cu
);
15427 /* We have to be careful in the presence of DW_AT_specification.
15428 For example, with GCC 3.4, given the code
15432 // Definition of N::foo.
15436 then we'll have a tree of DIEs like this:
15438 1: DW_TAG_compile_unit
15439 2: DW_TAG_namespace // N
15440 3: DW_TAG_subprogram // declaration of N::foo
15441 4: DW_TAG_subprogram // definition of N::foo
15442 DW_AT_specification // refers to die #3
15444 Thus, when processing die #4, we have to pretend that we're in
15445 the context of its DW_AT_specification, namely the contex of die
15448 spec_die
= die_specification (die
, &spec_cu
);
15449 if (spec_die
== NULL
)
15450 parent
= die
->parent
;
15453 parent
= spec_die
->parent
;
15457 if (parent
== NULL
)
15459 else if (parent
->building_fullname
)
15462 const char *parent_name
;
15464 /* It has been seen on RealView 2.2 built binaries,
15465 DW_TAG_template_type_param types actually _defined_ as
15466 children of the parent class:
15469 template class <class Enum> Class{};
15470 Class<enum E> class_e;
15472 1: DW_TAG_class_type (Class)
15473 2: DW_TAG_enumeration_type (E)
15474 3: DW_TAG_enumerator (enum1:0)
15475 3: DW_TAG_enumerator (enum2:1)
15477 2: DW_TAG_template_type_param
15478 DW_AT_type DW_FORM_ref_udata (E)
15480 Besides being broken debug info, it can put GDB into an
15481 infinite loop. Consider:
15483 When we're building the full name for Class<E>, we'll start
15484 at Class, and go look over its template type parameters,
15485 finding E. We'll then try to build the full name of E, and
15486 reach here. We're now trying to build the full name of E,
15487 and look over the parent DIE for containing scope. In the
15488 broken case, if we followed the parent DIE of E, we'd again
15489 find Class, and once again go look at its template type
15490 arguments, etc., etc. Simply don't consider such parent die
15491 as source-level parent of this die (it can't be, the language
15492 doesn't allow it), and break the loop here. */
15493 name
= dwarf2_name (die
, cu
);
15494 parent_name
= dwarf2_name (parent
, cu
);
15495 complaint (&symfile_complaints
,
15496 _("template param type '%s' defined within parent '%s'"),
15497 name
? name
: "<unknown>",
15498 parent_name
? parent_name
: "<unknown>");
15502 switch (parent
->tag
)
15504 case DW_TAG_namespace
:
15505 parent_type
= read_type_die (parent
, cu
);
15506 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
15507 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
15508 Work around this problem here. */
15509 if (cu
->language
== language_cplus
15510 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
15512 /* We give a name to even anonymous namespaces. */
15513 return TYPE_TAG_NAME (parent_type
);
15514 case DW_TAG_class_type
:
15515 case DW_TAG_interface_type
:
15516 case DW_TAG_structure_type
:
15517 case DW_TAG_union_type
:
15518 case DW_TAG_module
:
15519 parent_type
= read_type_die (parent
, cu
);
15520 if (TYPE_TAG_NAME (parent_type
) != NULL
)
15521 return TYPE_TAG_NAME (parent_type
);
15523 /* An anonymous structure is only allowed non-static data
15524 members; no typedefs, no member functions, et cetera.
15525 So it does not need a prefix. */
15527 case DW_TAG_compile_unit
:
15528 case DW_TAG_partial_unit
:
15529 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
15530 if (cu
->language
== language_cplus
15531 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
15532 && die
->child
!= NULL
15533 && (die
->tag
== DW_TAG_class_type
15534 || die
->tag
== DW_TAG_structure_type
15535 || die
->tag
== DW_TAG_union_type
))
15537 char *name
= guess_full_die_structure_name (die
, cu
);
15543 return determine_prefix (parent
, cu
);
15547 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
15548 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
15549 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
15550 an obconcat, otherwise allocate storage for the result. The CU argument is
15551 used to determine the language and hence, the appropriate separator. */
15553 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
15556 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
15557 int physname
, struct dwarf2_cu
*cu
)
15559 const char *lead
= "";
15562 if (suffix
== NULL
|| suffix
[0] == '\0'
15563 || prefix
== NULL
|| prefix
[0] == '\0')
15565 else if (cu
->language
== language_java
)
15567 else if (cu
->language
== language_fortran
&& physname
)
15569 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
15570 DW_AT_MIPS_linkage_name is preferred and used instead. */
15578 if (prefix
== NULL
)
15580 if (suffix
== NULL
)
15586 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
15588 strcpy (retval
, lead
);
15589 strcat (retval
, prefix
);
15590 strcat (retval
, sep
);
15591 strcat (retval
, suffix
);
15596 /* We have an obstack. */
15597 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
15601 /* Return sibling of die, NULL if no sibling. */
15603 static struct die_info
*
15604 sibling_die (struct die_info
*die
)
15606 return die
->sibling
;
15609 /* Get name of a die, return NULL if not found. */
15612 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
15613 struct obstack
*obstack
)
15615 if (name
&& cu
->language
== language_cplus
)
15617 char *canon_name
= cp_canonicalize_string (name
);
15619 if (canon_name
!= NULL
)
15621 if (strcmp (canon_name
, name
) != 0)
15622 name
= obsavestring (canon_name
, strlen (canon_name
),
15624 xfree (canon_name
);
15631 /* Get name of a die, return NULL if not found. */
15634 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15636 struct attribute
*attr
;
15638 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15639 if ((!attr
|| !DW_STRING (attr
))
15640 && die
->tag
!= DW_TAG_class_type
15641 && die
->tag
!= DW_TAG_interface_type
15642 && die
->tag
!= DW_TAG_structure_type
15643 && die
->tag
!= DW_TAG_union_type
)
15648 case DW_TAG_compile_unit
:
15649 case DW_TAG_partial_unit
:
15650 /* Compilation units have a DW_AT_name that is a filename, not
15651 a source language identifier. */
15652 case DW_TAG_enumeration_type
:
15653 case DW_TAG_enumerator
:
15654 /* These tags always have simple identifiers already; no need
15655 to canonicalize them. */
15656 return DW_STRING (attr
);
15658 case DW_TAG_subprogram
:
15659 /* Java constructors will all be named "<init>", so return
15660 the class name when we see this special case. */
15661 if (cu
->language
== language_java
15662 && DW_STRING (attr
) != NULL
15663 && strcmp (DW_STRING (attr
), "<init>") == 0)
15665 struct dwarf2_cu
*spec_cu
= cu
;
15666 struct die_info
*spec_die
;
15668 /* GCJ will output '<init>' for Java constructor names.
15669 For this special case, return the name of the parent class. */
15671 /* GCJ may output suprogram DIEs with AT_specification set.
15672 If so, use the name of the specified DIE. */
15673 spec_die
= die_specification (die
, &spec_cu
);
15674 if (spec_die
!= NULL
)
15675 return dwarf2_name (spec_die
, spec_cu
);
15680 if (die
->tag
== DW_TAG_class_type
)
15681 return dwarf2_name (die
, cu
);
15683 while (die
->tag
!= DW_TAG_compile_unit
15684 && die
->tag
!= DW_TAG_partial_unit
);
15688 case DW_TAG_class_type
:
15689 case DW_TAG_interface_type
:
15690 case DW_TAG_structure_type
:
15691 case DW_TAG_union_type
:
15692 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
15693 structures or unions. These were of the form "._%d" in GCC 4.1,
15694 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
15695 and GCC 4.4. We work around this problem by ignoring these. */
15696 if (attr
&& DW_STRING (attr
)
15697 && (strncmp (DW_STRING (attr
), "._", 2) == 0
15698 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
15701 /* GCC might emit a nameless typedef that has a linkage name. See
15702 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15703 if (!attr
|| DW_STRING (attr
) == NULL
)
15705 char *demangled
= NULL
;
15707 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15709 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15711 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15714 /* Avoid demangling DW_STRING (attr) the second time on a second
15715 call for the same DIE. */
15716 if (!DW_STRING_IS_CANONICAL (attr
))
15717 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
15723 /* FIXME: we already did this for the partial symbol... */
15724 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
15725 &cu
->objfile
->objfile_obstack
);
15726 DW_STRING_IS_CANONICAL (attr
) = 1;
15729 /* Strip any leading namespaces/classes, keep only the base name.
15730 DW_AT_name for named DIEs does not contain the prefixes. */
15731 base
= strrchr (DW_STRING (attr
), ':');
15732 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
15735 return DW_STRING (attr
);
15744 if (!DW_STRING_IS_CANONICAL (attr
))
15747 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
15748 &cu
->objfile
->objfile_obstack
);
15749 DW_STRING_IS_CANONICAL (attr
) = 1;
15751 return DW_STRING (attr
);
15754 /* Return the die that this die in an extension of, or NULL if there
15755 is none. *EXT_CU is the CU containing DIE on input, and the CU
15756 containing the return value on output. */
15758 static struct die_info
*
15759 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
15761 struct attribute
*attr
;
15763 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
15767 return follow_die_ref (die
, attr
, ext_cu
);
15770 /* Convert a DIE tag into its string name. */
15772 static const char *
15773 dwarf_tag_name (unsigned tag
)
15775 const char *name
= get_DW_TAG_name (tag
);
15778 return "DW_TAG_<unknown>";
15783 /* Convert a DWARF attribute code into its string name. */
15785 static const char *
15786 dwarf_attr_name (unsigned attr
)
15790 #ifdef MIPS /* collides with DW_AT_HP_block_index */
15791 if (attr
== DW_AT_MIPS_fde
)
15792 return "DW_AT_MIPS_fde";
15794 if (attr
== DW_AT_HP_block_index
)
15795 return "DW_AT_HP_block_index";
15798 name
= get_DW_AT_name (attr
);
15801 return "DW_AT_<unknown>";
15806 /* Convert a DWARF value form code into its string name. */
15808 static const char *
15809 dwarf_form_name (unsigned form
)
15811 const char *name
= get_DW_FORM_name (form
);
15814 return "DW_FORM_<unknown>";
15820 dwarf_bool_name (unsigned mybool
)
15828 /* Convert a DWARF type code into its string name. */
15830 static const char *
15831 dwarf_type_encoding_name (unsigned enc
)
15833 const char *name
= get_DW_ATE_name (enc
);
15836 return "DW_ATE_<unknown>";
15842 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
15846 print_spaces (indent
, f
);
15847 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
15848 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
15850 if (die
->parent
!= NULL
)
15852 print_spaces (indent
, f
);
15853 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
15854 die
->parent
->offset
.sect_off
);
15857 print_spaces (indent
, f
);
15858 fprintf_unfiltered (f
, " has children: %s\n",
15859 dwarf_bool_name (die
->child
!= NULL
));
15861 print_spaces (indent
, f
);
15862 fprintf_unfiltered (f
, " attributes:\n");
15864 for (i
= 0; i
< die
->num_attrs
; ++i
)
15866 print_spaces (indent
, f
);
15867 fprintf_unfiltered (f
, " %s (%s) ",
15868 dwarf_attr_name (die
->attrs
[i
].name
),
15869 dwarf_form_name (die
->attrs
[i
].form
));
15871 switch (die
->attrs
[i
].form
)
15874 case DW_FORM_GNU_addr_index
:
15875 fprintf_unfiltered (f
, "address: ");
15876 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
15878 case DW_FORM_block2
:
15879 case DW_FORM_block4
:
15880 case DW_FORM_block
:
15881 case DW_FORM_block1
:
15882 fprintf_unfiltered (f
, "block: size %d",
15883 DW_BLOCK (&die
->attrs
[i
])->size
);
15885 case DW_FORM_exprloc
:
15886 fprintf_unfiltered (f
, "expression: size %u",
15887 DW_BLOCK (&die
->attrs
[i
])->size
);
15889 case DW_FORM_ref_addr
:
15890 fprintf_unfiltered (f
, "ref address: ");
15891 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
15897 case DW_FORM_ref_udata
:
15898 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
15899 (long) (DW_UNSND (&die
->attrs
[i
])));
15901 case DW_FORM_data1
:
15902 case DW_FORM_data2
:
15903 case DW_FORM_data4
:
15904 case DW_FORM_data8
:
15905 case DW_FORM_udata
:
15906 case DW_FORM_sdata
:
15907 fprintf_unfiltered (f
, "constant: %s",
15908 pulongest (DW_UNSND (&die
->attrs
[i
])));
15910 case DW_FORM_sec_offset
:
15911 fprintf_unfiltered (f
, "section offset: %s",
15912 pulongest (DW_UNSND (&die
->attrs
[i
])));
15914 case DW_FORM_ref_sig8
:
15915 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15916 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15917 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15919 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15921 case DW_FORM_string
:
15923 case DW_FORM_GNU_str_index
:
15924 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15925 DW_STRING (&die
->attrs
[i
])
15926 ? DW_STRING (&die
->attrs
[i
]) : "",
15927 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15930 if (DW_UNSND (&die
->attrs
[i
]))
15931 fprintf_unfiltered (f
, "flag: TRUE");
15933 fprintf_unfiltered (f
, "flag: FALSE");
15935 case DW_FORM_flag_present
:
15936 fprintf_unfiltered (f
, "flag: TRUE");
15938 case DW_FORM_indirect
:
15939 /* The reader will have reduced the indirect form to
15940 the "base form" so this form should not occur. */
15941 fprintf_unfiltered (f
,
15942 "unexpected attribute form: DW_FORM_indirect");
15945 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
15946 die
->attrs
[i
].form
);
15949 fprintf_unfiltered (f
, "\n");
15954 dump_die_for_error (struct die_info
*die
)
15956 dump_die_shallow (gdb_stderr
, 0, die
);
15960 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
15962 int indent
= level
* 4;
15964 gdb_assert (die
!= NULL
);
15966 if (level
>= max_level
)
15969 dump_die_shallow (f
, indent
, die
);
15971 if (die
->child
!= NULL
)
15973 print_spaces (indent
, f
);
15974 fprintf_unfiltered (f
, " Children:");
15975 if (level
+ 1 < max_level
)
15977 fprintf_unfiltered (f
, "\n");
15978 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
15982 fprintf_unfiltered (f
,
15983 " [not printed, max nesting level reached]\n");
15987 if (die
->sibling
!= NULL
&& level
> 0)
15989 dump_die_1 (f
, level
, max_level
, die
->sibling
);
15993 /* This is called from the pdie macro in gdbinit.in.
15994 It's not static so gcc will keep a copy callable from gdb. */
15997 dump_die (struct die_info
*die
, int max_level
)
15999 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
16003 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
16007 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
16013 /* DW_ADDR is always stored already as sect_offset; despite for the forms
16014 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
16017 is_ref_attr (struct attribute
*attr
)
16019 switch (attr
->form
)
16021 case DW_FORM_ref_addr
:
16026 case DW_FORM_ref_udata
:
16033 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
16037 dwarf2_get_ref_die_offset (struct attribute
*attr
)
16039 sect_offset retval
= { DW_UNSND (attr
) };
16041 if (is_ref_attr (attr
))
16044 retval
.sect_off
= 0;
16045 complaint (&symfile_complaints
,
16046 _("unsupported die ref attribute form: '%s'"),
16047 dwarf_form_name (attr
->form
));
16051 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
16052 * the value held by the attribute is not constant. */
16055 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
16057 if (attr
->form
== DW_FORM_sdata
)
16058 return DW_SND (attr
);
16059 else if (attr
->form
== DW_FORM_udata
16060 || attr
->form
== DW_FORM_data1
16061 || attr
->form
== DW_FORM_data2
16062 || attr
->form
== DW_FORM_data4
16063 || attr
->form
== DW_FORM_data8
)
16064 return DW_UNSND (attr
);
16067 complaint (&symfile_complaints
,
16068 _("Attribute value is not a constant (%s)"),
16069 dwarf_form_name (attr
->form
));
16070 return default_value
;
16074 /* Follow reference or signature attribute ATTR of SRC_DIE.
16075 On entry *REF_CU is the CU of SRC_DIE.
16076 On exit *REF_CU is the CU of the result. */
16078 static struct die_info
*
16079 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
16080 struct dwarf2_cu
**ref_cu
)
16082 struct die_info
*die
;
16084 if (is_ref_attr (attr
))
16085 die
= follow_die_ref (src_die
, attr
, ref_cu
);
16086 else if (attr
->form
== DW_FORM_ref_sig8
)
16087 die
= follow_die_sig (src_die
, attr
, ref_cu
);
16090 dump_die_for_error (src_die
);
16091 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
16092 (*ref_cu
)->objfile
->name
);
16098 /* Follow reference OFFSET.
16099 On entry *REF_CU is the CU of the source die referencing OFFSET.
16100 On exit *REF_CU is the CU of the result.
16101 Returns NULL if OFFSET is invalid. */
16103 static struct die_info
*
16104 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
16106 struct die_info temp_die
;
16107 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
16109 gdb_assert (cu
->per_cu
!= NULL
);
16113 if (cu
->per_cu
->is_debug_types
)
16115 /* .debug_types CUs cannot reference anything outside their CU.
16116 If they need to, they have to reference a signatured type via
16117 DW_FORM_ref_sig8. */
16118 if (! offset_in_cu_p (&cu
->header
, offset
))
16121 else if (! offset_in_cu_p (&cu
->header
, offset
))
16123 struct dwarf2_per_cu_data
*per_cu
;
16125 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
16127 /* If necessary, add it to the queue and load its DIEs. */
16128 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
16129 load_full_comp_unit (per_cu
, cu
->language
);
16131 target_cu
= per_cu
->cu
;
16133 else if (cu
->dies
== NULL
)
16135 /* We're loading full DIEs during partial symbol reading. */
16136 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
16137 load_full_comp_unit (cu
->per_cu
, language_minimal
);
16140 *ref_cu
= target_cu
;
16141 temp_die
.offset
= offset
;
16142 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
16145 /* Follow reference attribute ATTR of SRC_DIE.
16146 On entry *REF_CU is the CU of SRC_DIE.
16147 On exit *REF_CU is the CU of the result. */
16149 static struct die_info
*
16150 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
16151 struct dwarf2_cu
**ref_cu
)
16153 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16154 struct dwarf2_cu
*cu
= *ref_cu
;
16155 struct die_info
*die
;
16157 die
= follow_die_offset (offset
, ref_cu
);
16159 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
16160 "at 0x%x [in module %s]"),
16161 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
16166 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
16167 Returned value is intended for DW_OP_call*. Returned
16168 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
16170 struct dwarf2_locexpr_baton
16171 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
16172 struct dwarf2_per_cu_data
*per_cu
,
16173 CORE_ADDR (*get_frame_pc
) (void *baton
),
16176 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
16177 struct dwarf2_cu
*cu
;
16178 struct die_info
*die
;
16179 struct attribute
*attr
;
16180 struct dwarf2_locexpr_baton retval
;
16182 dw2_setup (per_cu
->objfile
);
16184 if (per_cu
->cu
== NULL
)
16188 die
= follow_die_offset (offset
, &cu
);
16190 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
16191 offset
.sect_off
, per_cu
->objfile
->name
);
16193 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16196 /* DWARF: "If there is no such attribute, then there is no effect.".
16197 DATA is ignored if SIZE is 0. */
16199 retval
.data
= NULL
;
16202 else if (attr_form_is_section_offset (attr
))
16204 struct dwarf2_loclist_baton loclist_baton
;
16205 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
16208 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
16210 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
16212 retval
.size
= size
;
16216 if (!attr_form_is_block (attr
))
16217 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
16218 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
16219 offset
.sect_off
, per_cu
->objfile
->name
);
16221 retval
.data
= DW_BLOCK (attr
)->data
;
16222 retval
.size
= DW_BLOCK (attr
)->size
;
16224 retval
.per_cu
= cu
->per_cu
;
16226 age_cached_comp_units ();
16231 /* Return the type of the DIE at DIE_OFFSET in the CU named by
16235 dwarf2_get_die_type (cu_offset die_offset
,
16236 struct dwarf2_per_cu_data
*per_cu
)
16238 sect_offset die_offset_sect
;
16240 dw2_setup (per_cu
->objfile
);
16242 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
16243 return get_die_type_at_offset (die_offset_sect
, per_cu
);
16246 /* Follow the signature attribute ATTR in SRC_DIE.
16247 On entry *REF_CU is the CU of SRC_DIE.
16248 On exit *REF_CU is the CU of the result. */
16250 static struct die_info
*
16251 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
16252 struct dwarf2_cu
**ref_cu
)
16254 struct objfile
*objfile
= (*ref_cu
)->objfile
;
16255 struct die_info temp_die
;
16256 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16257 struct dwarf2_cu
*sig_cu
;
16258 struct die_info
*die
;
16260 /* sig_type will be NULL if the signatured type is missing from
16262 if (sig_type
== NULL
)
16263 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16264 "at 0x%x [in module %s]"),
16265 src_die
->offset
.sect_off
, objfile
->name
);
16267 /* If necessary, add it to the queue and load its DIEs. */
16269 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
16270 read_signatured_type (sig_type
);
16272 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
16274 sig_cu
= sig_type
->per_cu
.cu
;
16275 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
16276 temp_die
.offset
= sig_type
->type_offset_in_section
;
16277 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
16278 temp_die
.offset
.sect_off
);
16285 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
16286 "from DIE at 0x%x [in module %s]"),
16287 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
16290 /* Given an offset of a signatured type, return its signatured_type. */
16292 static struct signatured_type
*
16293 lookup_signatured_type_at_offset (struct objfile
*objfile
,
16294 struct dwarf2_section_info
*section
,
16295 sect_offset offset
)
16297 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
16298 unsigned int length
, initial_length_size
;
16299 unsigned int sig_offset
;
16300 struct signatured_type find_entry
, *sig_type
;
16302 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
16303 sig_offset
= (initial_length_size
16305 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
16306 + 1 /*address_size*/);
16307 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
16308 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
16310 /* This is only used to lookup previously recorded types.
16311 If we didn't find it, it's our bug. */
16312 gdb_assert (sig_type
!= NULL
);
16313 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
16318 /* Load the DIEs associated with type unit PER_CU into memory. */
16321 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
16323 struct signatured_type
*sig_type
;
16325 /* Caller is responsible for ensuring type_unit_groups don't get here. */
16326 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
16328 /* We have the per_cu, but we need the signatured_type.
16329 Fortunately this is an easy translation. */
16330 gdb_assert (per_cu
->is_debug_types
);
16331 sig_type
= (struct signatured_type
*) per_cu
;
16333 gdb_assert (per_cu
->cu
== NULL
);
16335 read_signatured_type (sig_type
);
16337 gdb_assert (per_cu
->cu
!= NULL
);
16340 /* die_reader_func for read_signatured_type.
16341 This is identical to load_full_comp_unit_reader,
16342 but is kept separate for now. */
16345 read_signatured_type_reader (const struct die_reader_specs
*reader
,
16346 gdb_byte
*info_ptr
,
16347 struct die_info
*comp_unit_die
,
16351 struct dwarf2_cu
*cu
= reader
->cu
;
16353 gdb_assert (cu
->die_hash
== NULL
);
16355 htab_create_alloc_ex (cu
->header
.length
/ 12,
16359 &cu
->comp_unit_obstack
,
16360 hashtab_obstack_allocate
,
16361 dummy_obstack_deallocate
);
16364 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
16365 &info_ptr
, comp_unit_die
);
16366 cu
->dies
= comp_unit_die
;
16367 /* comp_unit_die is not stored in die_hash, no need. */
16369 /* We try not to read any attributes in this function, because not
16370 all CUs needed for references have been loaded yet, and symbol
16371 table processing isn't initialized. But we have to set the CU language,
16372 or we won't be able to build types correctly.
16373 Similarly, if we do not read the producer, we can not apply
16374 producer-specific interpretation. */
16375 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
16378 /* Read in a signatured type and build its CU and DIEs.
16379 If the type is a stub for the real type in a DWO file,
16380 read in the real type from the DWO file as well. */
16383 read_signatured_type (struct signatured_type
*sig_type
)
16385 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
16387 gdb_assert (per_cu
->is_debug_types
);
16388 gdb_assert (per_cu
->cu
== NULL
);
16390 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
16391 read_signatured_type_reader
, NULL
);
16394 /* Decode simple location descriptions.
16395 Given a pointer to a dwarf block that defines a location, compute
16396 the location and return the value.
16398 NOTE drow/2003-11-18: This function is called in two situations
16399 now: for the address of static or global variables (partial symbols
16400 only) and for offsets into structures which are expected to be
16401 (more or less) constant. The partial symbol case should go away,
16402 and only the constant case should remain. That will let this
16403 function complain more accurately. A few special modes are allowed
16404 without complaint for global variables (for instance, global
16405 register values and thread-local values).
16407 A location description containing no operations indicates that the
16408 object is optimized out. The return value is 0 for that case.
16409 FIXME drow/2003-11-16: No callers check for this case any more; soon all
16410 callers will only want a very basic result and this can become a
16413 Note that stack[0] is unused except as a default error return. */
16416 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
16418 struct objfile
*objfile
= cu
->objfile
;
16420 int size
= blk
->size
;
16421 gdb_byte
*data
= blk
->data
;
16422 CORE_ADDR stack
[64];
16424 unsigned int bytes_read
, unsnd
;
16430 stack
[++stacki
] = 0;
16469 stack
[++stacki
] = op
- DW_OP_lit0
;
16504 stack
[++stacki
] = op
- DW_OP_reg0
;
16506 dwarf2_complex_location_expr_complaint ();
16510 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
16512 stack
[++stacki
] = unsnd
;
16514 dwarf2_complex_location_expr_complaint ();
16518 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
16523 case DW_OP_const1u
:
16524 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
16528 case DW_OP_const1s
:
16529 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
16533 case DW_OP_const2u
:
16534 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
16538 case DW_OP_const2s
:
16539 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
16543 case DW_OP_const4u
:
16544 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
16548 case DW_OP_const4s
:
16549 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
16553 case DW_OP_const8u
:
16554 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
16559 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
16565 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
16570 stack
[stacki
+ 1] = stack
[stacki
];
16575 stack
[stacki
- 1] += stack
[stacki
];
16579 case DW_OP_plus_uconst
:
16580 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
16586 stack
[stacki
- 1] -= stack
[stacki
];
16591 /* If we're not the last op, then we definitely can't encode
16592 this using GDB's address_class enum. This is valid for partial
16593 global symbols, although the variable's address will be bogus
16596 dwarf2_complex_location_expr_complaint ();
16599 case DW_OP_GNU_push_tls_address
:
16600 /* The top of the stack has the offset from the beginning
16601 of the thread control block at which the variable is located. */
16602 /* Nothing should follow this operator, so the top of stack would
16604 /* This is valid for partial global symbols, but the variable's
16605 address will be bogus in the psymtab. Make it always at least
16606 non-zero to not look as a variable garbage collected by linker
16607 which have DW_OP_addr 0. */
16609 dwarf2_complex_location_expr_complaint ();
16613 case DW_OP_GNU_uninit
:
16616 case DW_OP_GNU_addr_index
:
16617 case DW_OP_GNU_const_index
:
16618 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
16625 const char *name
= get_DW_OP_name (op
);
16628 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
16631 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
16635 return (stack
[stacki
]);
16638 /* Enforce maximum stack depth of SIZE-1 to avoid writing
16639 outside of the allocated space. Also enforce minimum>0. */
16640 if (stacki
>= ARRAY_SIZE (stack
) - 1)
16642 complaint (&symfile_complaints
,
16643 _("location description stack overflow"));
16649 complaint (&symfile_complaints
,
16650 _("location description stack underflow"));
16654 return (stack
[stacki
]);
16657 /* memory allocation interface */
16659 static struct dwarf_block
*
16660 dwarf_alloc_block (struct dwarf2_cu
*cu
)
16662 struct dwarf_block
*blk
;
16664 blk
= (struct dwarf_block
*)
16665 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
16669 static struct die_info
*
16670 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
16672 struct die_info
*die
;
16673 size_t size
= sizeof (struct die_info
);
16676 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
16678 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
16679 memset (die
, 0, sizeof (struct die_info
));
16684 /* Macro support. */
16686 /* Return the full name of file number I in *LH's file name table.
16687 Use COMP_DIR as the name of the current directory of the
16688 compilation. The result is allocated using xmalloc; the caller is
16689 responsible for freeing it. */
16691 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
16693 /* Is the file number a valid index into the line header's file name
16694 table? Remember that file numbers start with one, not zero. */
16695 if (1 <= file
&& file
<= lh
->num_file_names
)
16697 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
16699 if (IS_ABSOLUTE_PATH (fe
->name
))
16700 return xstrdup (fe
->name
);
16708 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16714 dir_len
= strlen (dir
);
16715 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
16716 strcpy (full_name
, dir
);
16717 full_name
[dir_len
] = '/';
16718 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
16722 return xstrdup (fe
->name
);
16727 /* The compiler produced a bogus file number. We can at least
16728 record the macro definitions made in the file, even if we
16729 won't be able to find the file by name. */
16730 char fake_name
[80];
16732 sprintf (fake_name
, "<bad macro file number %d>", file
);
16734 complaint (&symfile_complaints
,
16735 _("bad file number in macro information (%d)"),
16738 return xstrdup (fake_name
);
16743 static struct macro_source_file
*
16744 macro_start_file (int file
, int line
,
16745 struct macro_source_file
*current_file
,
16746 const char *comp_dir
,
16747 struct line_header
*lh
, struct objfile
*objfile
)
16749 /* The full name of this source file. */
16750 char *full_name
= file_full_name (file
, lh
, comp_dir
);
16752 /* We don't create a macro table for this compilation unit
16753 at all until we actually get a filename. */
16754 if (! pending_macros
)
16755 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
16756 objfile
->macro_cache
);
16758 if (! current_file
)
16760 /* If we have no current file, then this must be the start_file
16761 directive for the compilation unit's main source file. */
16762 current_file
= macro_set_main (pending_macros
, full_name
);
16763 macro_define_special (pending_macros
);
16766 current_file
= macro_include (current_file
, line
, full_name
);
16770 return current_file
;
16774 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
16775 followed by a null byte. */
16777 copy_string (const char *buf
, int len
)
16779 char *s
= xmalloc (len
+ 1);
16781 memcpy (s
, buf
, len
);
16787 static const char *
16788 consume_improper_spaces (const char *p
, const char *body
)
16792 complaint (&symfile_complaints
,
16793 _("macro definition contains spaces "
16794 "in formal argument list:\n`%s'"),
16806 parse_macro_definition (struct macro_source_file
*file
, int line
,
16811 /* The body string takes one of two forms. For object-like macro
16812 definitions, it should be:
16814 <macro name> " " <definition>
16816 For function-like macro definitions, it should be:
16818 <macro name> "() " <definition>
16820 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
16822 Spaces may appear only where explicitly indicated, and in the
16825 The Dwarf 2 spec says that an object-like macro's name is always
16826 followed by a space, but versions of GCC around March 2002 omit
16827 the space when the macro's definition is the empty string.
16829 The Dwarf 2 spec says that there should be no spaces between the
16830 formal arguments in a function-like macro's formal argument list,
16831 but versions of GCC around March 2002 include spaces after the
16835 /* Find the extent of the macro name. The macro name is terminated
16836 by either a space or null character (for an object-like macro) or
16837 an opening paren (for a function-like macro). */
16838 for (p
= body
; *p
; p
++)
16839 if (*p
== ' ' || *p
== '(')
16842 if (*p
== ' ' || *p
== '\0')
16844 /* It's an object-like macro. */
16845 int name_len
= p
- body
;
16846 char *name
= copy_string (body
, name_len
);
16847 const char *replacement
;
16850 replacement
= body
+ name_len
+ 1;
16853 dwarf2_macro_malformed_definition_complaint (body
);
16854 replacement
= body
+ name_len
;
16857 macro_define_object (file
, line
, name
, replacement
);
16861 else if (*p
== '(')
16863 /* It's a function-like macro. */
16864 char *name
= copy_string (body
, p
- body
);
16867 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16871 p
= consume_improper_spaces (p
, body
);
16873 /* Parse the formal argument list. */
16874 while (*p
&& *p
!= ')')
16876 /* Find the extent of the current argument name. */
16877 const char *arg_start
= p
;
16879 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16882 if (! *p
|| p
== arg_start
)
16883 dwarf2_macro_malformed_definition_complaint (body
);
16886 /* Make sure argv has room for the new argument. */
16887 if (argc
>= argv_size
)
16890 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16893 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16896 p
= consume_improper_spaces (p
, body
);
16898 /* Consume the comma, if present. */
16903 p
= consume_improper_spaces (p
, body
);
16912 /* Perfectly formed definition, no complaints. */
16913 macro_define_function (file
, line
, name
,
16914 argc
, (const char **) argv
,
16916 else if (*p
== '\0')
16918 /* Complain, but do define it. */
16919 dwarf2_macro_malformed_definition_complaint (body
);
16920 macro_define_function (file
, line
, name
,
16921 argc
, (const char **) argv
,
16925 /* Just complain. */
16926 dwarf2_macro_malformed_definition_complaint (body
);
16929 /* Just complain. */
16930 dwarf2_macro_malformed_definition_complaint (body
);
16936 for (i
= 0; i
< argc
; i
++)
16942 dwarf2_macro_malformed_definition_complaint (body
);
16945 /* Skip some bytes from BYTES according to the form given in FORM.
16946 Returns the new pointer. */
16949 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
16950 enum dwarf_form form
,
16951 unsigned int offset_size
,
16952 struct dwarf2_section_info
*section
)
16954 unsigned int bytes_read
;
16958 case DW_FORM_data1
:
16963 case DW_FORM_data2
:
16967 case DW_FORM_data4
:
16971 case DW_FORM_data8
:
16975 case DW_FORM_string
:
16976 read_direct_string (abfd
, bytes
, &bytes_read
);
16977 bytes
+= bytes_read
;
16980 case DW_FORM_sec_offset
:
16982 bytes
+= offset_size
;
16985 case DW_FORM_block
:
16986 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
16987 bytes
+= bytes_read
;
16990 case DW_FORM_block1
:
16991 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16993 case DW_FORM_block2
:
16994 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16996 case DW_FORM_block4
:
16997 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
17000 case DW_FORM_sdata
:
17001 case DW_FORM_udata
:
17002 case DW_FORM_GNU_addr_index
:
17003 case DW_FORM_GNU_str_index
:
17004 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
17007 dwarf2_section_buffer_overflow_complaint (section
);
17015 complaint (&symfile_complaints
,
17016 _("invalid form 0x%x in `%s'"),
17018 section
->asection
->name
);
17026 /* A helper for dwarf_decode_macros that handles skipping an unknown
17027 opcode. Returns an updated pointer to the macro data buffer; or,
17028 on error, issues a complaint and returns NULL. */
17031 skip_unknown_opcode (unsigned int opcode
,
17032 gdb_byte
**opcode_definitions
,
17033 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17035 unsigned int offset_size
,
17036 struct dwarf2_section_info
*section
)
17038 unsigned int bytes_read
, i
;
17042 if (opcode_definitions
[opcode
] == NULL
)
17044 complaint (&symfile_complaints
,
17045 _("unrecognized DW_MACFINO opcode 0x%x"),
17050 defn
= opcode_definitions
[opcode
];
17051 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
17052 defn
+= bytes_read
;
17054 for (i
= 0; i
< arg
; ++i
)
17056 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
17058 if (mac_ptr
== NULL
)
17060 /* skip_form_bytes already issued the complaint. */
17068 /* A helper function which parses the header of a macro section.
17069 If the macro section is the extended (for now called "GNU") type,
17070 then this updates *OFFSET_SIZE. Returns a pointer to just after
17071 the header, or issues a complaint and returns NULL on error. */
17074 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
17077 unsigned int *offset_size
,
17078 int section_is_gnu
)
17080 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
17082 if (section_is_gnu
)
17084 unsigned int version
, flags
;
17086 version
= read_2_bytes (abfd
, mac_ptr
);
17089 complaint (&symfile_complaints
,
17090 _("unrecognized version `%d' in .debug_macro section"),
17096 flags
= read_1_byte (abfd
, mac_ptr
);
17098 *offset_size
= (flags
& 1) ? 8 : 4;
17100 if ((flags
& 2) != 0)
17101 /* We don't need the line table offset. */
17102 mac_ptr
+= *offset_size
;
17104 /* Vendor opcode descriptions. */
17105 if ((flags
& 4) != 0)
17107 unsigned int i
, count
;
17109 count
= read_1_byte (abfd
, mac_ptr
);
17111 for (i
= 0; i
< count
; ++i
)
17113 unsigned int opcode
, bytes_read
;
17116 opcode
= read_1_byte (abfd
, mac_ptr
);
17118 opcode_definitions
[opcode
] = mac_ptr
;
17119 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17120 mac_ptr
+= bytes_read
;
17129 /* A helper for dwarf_decode_macros that handles the GNU extensions,
17130 including DW_MACRO_GNU_transparent_include. */
17133 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17134 struct macro_source_file
*current_file
,
17135 struct line_header
*lh
, char *comp_dir
,
17136 struct dwarf2_section_info
*section
,
17137 int section_is_gnu
,
17138 unsigned int offset_size
,
17139 struct objfile
*objfile
,
17140 htab_t include_hash
)
17142 enum dwarf_macro_record_type macinfo_type
;
17143 int at_commandline
;
17144 gdb_byte
*opcode_definitions
[256];
17146 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17147 &offset_size
, section_is_gnu
);
17148 if (mac_ptr
== NULL
)
17150 /* We already issued a complaint. */
17154 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
17155 GDB is still reading the definitions from command line. First
17156 DW_MACINFO_start_file will need to be ignored as it was already executed
17157 to create CURRENT_FILE for the main source holding also the command line
17158 definitions. On first met DW_MACINFO_start_file this flag is reset to
17159 normally execute all the remaining DW_MACINFO_start_file macinfos. */
17161 at_commandline
= 1;
17165 /* Do we at least have room for a macinfo type byte? */
17166 if (mac_ptr
>= mac_end
)
17168 dwarf2_section_buffer_overflow_complaint (section
);
17172 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17175 /* Note that we rely on the fact that the corresponding GNU and
17176 DWARF constants are the same. */
17177 switch (macinfo_type
)
17179 /* A zero macinfo type indicates the end of the macro
17184 case DW_MACRO_GNU_define
:
17185 case DW_MACRO_GNU_undef
:
17186 case DW_MACRO_GNU_define_indirect
:
17187 case DW_MACRO_GNU_undef_indirect
:
17189 unsigned int bytes_read
;
17194 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17195 mac_ptr
+= bytes_read
;
17197 if (macinfo_type
== DW_MACRO_GNU_define
17198 || macinfo_type
== DW_MACRO_GNU_undef
)
17200 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17201 mac_ptr
+= bytes_read
;
17205 LONGEST str_offset
;
17207 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17208 mac_ptr
+= offset_size
;
17210 body
= read_indirect_string_at_offset (abfd
, str_offset
);
17213 is_define
= (macinfo_type
== DW_MACRO_GNU_define
17214 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
17215 if (! current_file
)
17217 /* DWARF violation as no main source is present. */
17218 complaint (&symfile_complaints
,
17219 _("debug info with no main source gives macro %s "
17221 is_define
? _("definition") : _("undefinition"),
17225 if ((line
== 0 && !at_commandline
)
17226 || (line
!= 0 && at_commandline
))
17227 complaint (&symfile_complaints
,
17228 _("debug info gives %s macro %s with %s line %d: %s"),
17229 at_commandline
? _("command-line") : _("in-file"),
17230 is_define
? _("definition") : _("undefinition"),
17231 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
17234 parse_macro_definition (current_file
, line
, body
);
17237 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
17238 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
17239 macro_undef (current_file
, line
, body
);
17244 case DW_MACRO_GNU_start_file
:
17246 unsigned int bytes_read
;
17249 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17250 mac_ptr
+= bytes_read
;
17251 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17252 mac_ptr
+= bytes_read
;
17254 if ((line
== 0 && !at_commandline
)
17255 || (line
!= 0 && at_commandline
))
17256 complaint (&symfile_complaints
,
17257 _("debug info gives source %d included "
17258 "from %s at %s line %d"),
17259 file
, at_commandline
? _("command-line") : _("file"),
17260 line
== 0 ? _("zero") : _("non-zero"), line
);
17262 if (at_commandline
)
17264 /* This DW_MACRO_GNU_start_file was executed in the
17266 at_commandline
= 0;
17269 current_file
= macro_start_file (file
, line
,
17270 current_file
, comp_dir
,
17275 case DW_MACRO_GNU_end_file
:
17276 if (! current_file
)
17277 complaint (&symfile_complaints
,
17278 _("macro debug info has an unmatched "
17279 "`close_file' directive"));
17282 current_file
= current_file
->included_by
;
17283 if (! current_file
)
17285 enum dwarf_macro_record_type next_type
;
17287 /* GCC circa March 2002 doesn't produce the zero
17288 type byte marking the end of the compilation
17289 unit. Complain if it's not there, but exit no
17292 /* Do we at least have room for a macinfo type byte? */
17293 if (mac_ptr
>= mac_end
)
17295 dwarf2_section_buffer_overflow_complaint (section
);
17299 /* We don't increment mac_ptr here, so this is just
17301 next_type
= read_1_byte (abfd
, mac_ptr
);
17302 if (next_type
!= 0)
17303 complaint (&symfile_complaints
,
17304 _("no terminating 0-type entry for "
17305 "macros in `.debug_macinfo' section"));
17312 case DW_MACRO_GNU_transparent_include
:
17317 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17318 mac_ptr
+= offset_size
;
17320 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17323 /* This has actually happened; see
17324 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
17325 complaint (&symfile_complaints
,
17326 _("recursive DW_MACRO_GNU_transparent_include in "
17327 ".debug_macro section"));
17333 dwarf_decode_macro_bytes (abfd
,
17334 section
->buffer
+ offset
,
17335 mac_end
, current_file
,
17337 section
, section_is_gnu
,
17338 offset_size
, objfile
, include_hash
);
17340 htab_remove_elt (include_hash
, mac_ptr
);
17345 case DW_MACINFO_vendor_ext
:
17346 if (!section_is_gnu
)
17348 unsigned int bytes_read
;
17351 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17352 mac_ptr
+= bytes_read
;
17353 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17354 mac_ptr
+= bytes_read
;
17356 /* We don't recognize any vendor extensions. */
17362 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17363 mac_ptr
, mac_end
, abfd
, offset_size
,
17365 if (mac_ptr
== NULL
)
17369 } while (macinfo_type
!= 0);
17373 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
17374 char *comp_dir
, int section_is_gnu
)
17376 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17377 struct line_header
*lh
= cu
->line_header
;
17379 gdb_byte
*mac_ptr
, *mac_end
;
17380 struct macro_source_file
*current_file
= 0;
17381 enum dwarf_macro_record_type macinfo_type
;
17382 unsigned int offset_size
= cu
->header
.offset_size
;
17383 gdb_byte
*opcode_definitions
[256];
17384 struct cleanup
*cleanup
;
17385 htab_t include_hash
;
17387 struct dwarf2_section_info
*section
;
17388 const char *section_name
;
17390 if (cu
->dwo_unit
!= NULL
)
17392 if (section_is_gnu
)
17394 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
17395 section_name
= ".debug_macro.dwo";
17399 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
17400 section_name
= ".debug_macinfo.dwo";
17405 if (section_is_gnu
)
17407 section
= &dwarf2_per_objfile
->macro
;
17408 section_name
= ".debug_macro";
17412 section
= &dwarf2_per_objfile
->macinfo
;
17413 section_name
= ".debug_macinfo";
17417 dwarf2_read_section (objfile
, section
);
17418 if (section
->buffer
== NULL
)
17420 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
17423 abfd
= section
->asection
->owner
;
17425 /* First pass: Find the name of the base filename.
17426 This filename is needed in order to process all macros whose definition
17427 (or undefinition) comes from the command line. These macros are defined
17428 before the first DW_MACINFO_start_file entry, and yet still need to be
17429 associated to the base file.
17431 To determine the base file name, we scan the macro definitions until we
17432 reach the first DW_MACINFO_start_file entry. We then initialize
17433 CURRENT_FILE accordingly so that any macro definition found before the
17434 first DW_MACINFO_start_file can still be associated to the base file. */
17436 mac_ptr
= section
->buffer
+ offset
;
17437 mac_end
= section
->buffer
+ section
->size
;
17439 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17440 &offset_size
, section_is_gnu
);
17441 if (mac_ptr
== NULL
)
17443 /* We already issued a complaint. */
17449 /* Do we at least have room for a macinfo type byte? */
17450 if (mac_ptr
>= mac_end
)
17452 /* Complaint is printed during the second pass as GDB will probably
17453 stop the first pass earlier upon finding
17454 DW_MACINFO_start_file. */
17458 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17461 /* Note that we rely on the fact that the corresponding GNU and
17462 DWARF constants are the same. */
17463 switch (macinfo_type
)
17465 /* A zero macinfo type indicates the end of the macro
17470 case DW_MACRO_GNU_define
:
17471 case DW_MACRO_GNU_undef
:
17472 /* Only skip the data by MAC_PTR. */
17474 unsigned int bytes_read
;
17476 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17477 mac_ptr
+= bytes_read
;
17478 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17479 mac_ptr
+= bytes_read
;
17483 case DW_MACRO_GNU_start_file
:
17485 unsigned int bytes_read
;
17488 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17489 mac_ptr
+= bytes_read
;
17490 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17491 mac_ptr
+= bytes_read
;
17493 current_file
= macro_start_file (file
, line
, current_file
,
17494 comp_dir
, lh
, objfile
);
17498 case DW_MACRO_GNU_end_file
:
17499 /* No data to skip by MAC_PTR. */
17502 case DW_MACRO_GNU_define_indirect
:
17503 case DW_MACRO_GNU_undef_indirect
:
17505 unsigned int bytes_read
;
17507 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17508 mac_ptr
+= bytes_read
;
17509 mac_ptr
+= offset_size
;
17513 case DW_MACRO_GNU_transparent_include
:
17514 /* Note that, according to the spec, a transparent include
17515 chain cannot call DW_MACRO_GNU_start_file. So, we can just
17516 skip this opcode. */
17517 mac_ptr
+= offset_size
;
17520 case DW_MACINFO_vendor_ext
:
17521 /* Only skip the data by MAC_PTR. */
17522 if (!section_is_gnu
)
17524 unsigned int bytes_read
;
17526 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17527 mac_ptr
+= bytes_read
;
17528 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17529 mac_ptr
+= bytes_read
;
17534 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17535 mac_ptr
, mac_end
, abfd
, offset_size
,
17537 if (mac_ptr
== NULL
)
17541 } while (macinfo_type
!= 0 && current_file
== NULL
);
17543 /* Second pass: Process all entries.
17545 Use the AT_COMMAND_LINE flag to determine whether we are still processing
17546 command-line macro definitions/undefinitions. This flag is unset when we
17547 reach the first DW_MACINFO_start_file entry. */
17549 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
17550 NULL
, xcalloc
, xfree
);
17551 cleanup
= make_cleanup_htab_delete (include_hash
);
17552 mac_ptr
= section
->buffer
+ offset
;
17553 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17555 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
17556 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
17557 offset_size
, objfile
, include_hash
);
17558 do_cleanups (cleanup
);
17561 /* Check if the attribute's form is a DW_FORM_block*
17562 if so return true else false. */
17565 attr_form_is_block (struct attribute
*attr
)
17567 return (attr
== NULL
? 0 :
17568 attr
->form
== DW_FORM_block1
17569 || attr
->form
== DW_FORM_block2
17570 || attr
->form
== DW_FORM_block4
17571 || attr
->form
== DW_FORM_block
17572 || attr
->form
== DW_FORM_exprloc
);
17575 /* Return non-zero if ATTR's value is a section offset --- classes
17576 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
17577 You may use DW_UNSND (attr) to retrieve such offsets.
17579 Section 7.5.4, "Attribute Encodings", explains that no attribute
17580 may have a value that belongs to more than one of these classes; it
17581 would be ambiguous if we did, because we use the same forms for all
17585 attr_form_is_section_offset (struct attribute
*attr
)
17587 return (attr
->form
== DW_FORM_data4
17588 || attr
->form
== DW_FORM_data8
17589 || attr
->form
== DW_FORM_sec_offset
);
17592 /* Return non-zero if ATTR's value falls in the 'constant' class, or
17593 zero otherwise. When this function returns true, you can apply
17594 dwarf2_get_attr_constant_value to it.
17596 However, note that for some attributes you must check
17597 attr_form_is_section_offset before using this test. DW_FORM_data4
17598 and DW_FORM_data8 are members of both the constant class, and of
17599 the classes that contain offsets into other debug sections
17600 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
17601 that, if an attribute's can be either a constant or one of the
17602 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
17603 taken as section offsets, not constants. */
17606 attr_form_is_constant (struct attribute
*attr
)
17608 switch (attr
->form
)
17610 case DW_FORM_sdata
:
17611 case DW_FORM_udata
:
17612 case DW_FORM_data1
:
17613 case DW_FORM_data2
:
17614 case DW_FORM_data4
:
17615 case DW_FORM_data8
:
17622 /* Return the .debug_loc section to use for CU.
17623 For DWO files use .debug_loc.dwo. */
17625 static struct dwarf2_section_info
*
17626 cu_debug_loc_section (struct dwarf2_cu
*cu
)
17629 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
17630 return &dwarf2_per_objfile
->loc
;
17633 /* A helper function that fills in a dwarf2_loclist_baton. */
17636 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
17637 struct dwarf2_loclist_baton
*baton
,
17638 struct attribute
*attr
)
17640 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17642 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17644 baton
->per_cu
= cu
->per_cu
;
17645 gdb_assert (baton
->per_cu
);
17646 /* We don't know how long the location list is, but make sure we
17647 don't run off the edge of the section. */
17648 baton
->size
= section
->size
- DW_UNSND (attr
);
17649 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
17650 baton
->base_address
= cu
->base_address
;
17651 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
17655 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
17656 struct dwarf2_cu
*cu
)
17658 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17659 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17661 if (attr_form_is_section_offset (attr
)
17662 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
17663 the section. If so, fall through to the complaint in the
17665 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
17667 struct dwarf2_loclist_baton
*baton
;
17669 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17670 sizeof (struct dwarf2_loclist_baton
));
17672 fill_in_loclist_baton (cu
, baton
, attr
);
17674 if (cu
->base_known
== 0)
17675 complaint (&symfile_complaints
,
17676 _("Location list used without "
17677 "specifying the CU base address."));
17679 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
17680 SYMBOL_LOCATION_BATON (sym
) = baton
;
17684 struct dwarf2_locexpr_baton
*baton
;
17686 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17687 sizeof (struct dwarf2_locexpr_baton
));
17688 baton
->per_cu
= cu
->per_cu
;
17689 gdb_assert (baton
->per_cu
);
17691 if (attr_form_is_block (attr
))
17693 /* Note that we're just copying the block's data pointer
17694 here, not the actual data. We're still pointing into the
17695 info_buffer for SYM's objfile; right now we never release
17696 that buffer, but when we do clean up properly this may
17698 baton
->size
= DW_BLOCK (attr
)->size
;
17699 baton
->data
= DW_BLOCK (attr
)->data
;
17703 dwarf2_invalid_attrib_class_complaint ("location description",
17704 SYMBOL_NATURAL_NAME (sym
));
17708 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
17709 SYMBOL_LOCATION_BATON (sym
) = baton
;
17713 /* Return the OBJFILE associated with the compilation unit CU. If CU
17714 came from a separate debuginfo file, then the master objfile is
17718 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
17720 struct objfile
*objfile
= per_cu
->objfile
;
17722 /* Return the master objfile, so that we can report and look up the
17723 correct file containing this variable. */
17724 if (objfile
->separate_debug_objfile_backlink
)
17725 objfile
= objfile
->separate_debug_objfile_backlink
;
17730 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
17731 (CU_HEADERP is unused in such case) or prepare a temporary copy at
17732 CU_HEADERP first. */
17734 static const struct comp_unit_head
*
17735 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
17736 struct dwarf2_per_cu_data
*per_cu
)
17738 gdb_byte
*info_ptr
;
17741 return &per_cu
->cu
->header
;
17743 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
17745 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
17746 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
17751 /* Return the address size given in the compilation unit header for CU. */
17754 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17756 struct comp_unit_head cu_header_local
;
17757 const struct comp_unit_head
*cu_headerp
;
17759 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17761 return cu_headerp
->addr_size
;
17764 /* Return the offset size given in the compilation unit header for CU. */
17767 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
17769 struct comp_unit_head cu_header_local
;
17770 const struct comp_unit_head
*cu_headerp
;
17772 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17774 return cu_headerp
->offset_size
;
17777 /* See its dwarf2loc.h declaration. */
17780 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17782 struct comp_unit_head cu_header_local
;
17783 const struct comp_unit_head
*cu_headerp
;
17785 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17787 if (cu_headerp
->version
== 2)
17788 return cu_headerp
->addr_size
;
17790 return cu_headerp
->offset_size
;
17793 /* Return the text offset of the CU. The returned offset comes from
17794 this CU's objfile. If this objfile came from a separate debuginfo
17795 file, then the offset may be different from the corresponding
17796 offset in the parent objfile. */
17799 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
17801 struct objfile
*objfile
= per_cu
->objfile
;
17803 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17806 /* Locate the .debug_info compilation unit from CU's objfile which contains
17807 the DIE at OFFSET. Raises an error on failure. */
17809 static struct dwarf2_per_cu_data
*
17810 dwarf2_find_containing_comp_unit (sect_offset offset
,
17811 struct objfile
*objfile
)
17813 struct dwarf2_per_cu_data
*this_cu
;
17817 high
= dwarf2_per_objfile
->n_comp_units
- 1;
17820 int mid
= low
+ (high
- low
) / 2;
17822 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
17823 >= offset
.sect_off
)
17828 gdb_assert (low
== high
);
17829 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
17833 error (_("Dwarf Error: could not find partial DIE containing "
17834 "offset 0x%lx [in module %s]"),
17835 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
17837 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
17838 <= offset
.sect_off
);
17839 return dwarf2_per_objfile
->all_comp_units
[low
-1];
17843 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
17844 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
17845 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
17846 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
17847 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
17852 /* Initialize dwarf2_cu CU, owned by PER_CU. */
17855 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
17857 memset (cu
, 0, sizeof (*cu
));
17859 cu
->per_cu
= per_cu
;
17860 cu
->objfile
= per_cu
->objfile
;
17861 obstack_init (&cu
->comp_unit_obstack
);
17864 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17867 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
17868 enum language pretend_language
)
17870 struct attribute
*attr
;
17872 /* Set the language we're debugging. */
17873 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17875 set_cu_language (DW_UNSND (attr
), cu
);
17878 cu
->language
= pretend_language
;
17879 cu
->language_defn
= language_def (cu
->language
);
17882 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17884 cu
->producer
= DW_STRING (attr
);
17887 /* Release one cached compilation unit, CU. We unlink it from the tree
17888 of compilation units, but we don't remove it from the read_in_chain;
17889 the caller is responsible for that.
17890 NOTE: DATA is a void * because this function is also used as a
17891 cleanup routine. */
17894 free_heap_comp_unit (void *data
)
17896 struct dwarf2_cu
*cu
= data
;
17898 gdb_assert (cu
->per_cu
!= NULL
);
17899 cu
->per_cu
->cu
= NULL
;
17902 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17907 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17908 when we're finished with it. We can't free the pointer itself, but be
17909 sure to unlink it from the cache. Also release any associated storage. */
17912 free_stack_comp_unit (void *data
)
17914 struct dwarf2_cu
*cu
= data
;
17916 gdb_assert (cu
->per_cu
!= NULL
);
17917 cu
->per_cu
->cu
= NULL
;
17920 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17921 cu
->partial_dies
= NULL
;
17924 /* Free all cached compilation units. */
17927 free_cached_comp_units (void *data
)
17929 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17931 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17932 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17933 while (per_cu
!= NULL
)
17935 struct dwarf2_per_cu_data
*next_cu
;
17937 next_cu
= per_cu
->cu
->read_in_chain
;
17939 free_heap_comp_unit (per_cu
->cu
);
17940 *last_chain
= next_cu
;
17946 /* Increase the age counter on each cached compilation unit, and free
17947 any that are too old. */
17950 age_cached_comp_units (void)
17952 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17954 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
17955 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17956 while (per_cu
!= NULL
)
17958 per_cu
->cu
->last_used
++;
17959 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
17960 dwarf2_mark (per_cu
->cu
);
17961 per_cu
= per_cu
->cu
->read_in_chain
;
17964 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17965 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17966 while (per_cu
!= NULL
)
17968 struct dwarf2_per_cu_data
*next_cu
;
17970 next_cu
= per_cu
->cu
->read_in_chain
;
17972 if (!per_cu
->cu
->mark
)
17974 free_heap_comp_unit (per_cu
->cu
);
17975 *last_chain
= next_cu
;
17978 last_chain
= &per_cu
->cu
->read_in_chain
;
17984 /* Remove a single compilation unit from the cache. */
17987 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
17989 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17991 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17992 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17993 while (per_cu
!= NULL
)
17995 struct dwarf2_per_cu_data
*next_cu
;
17997 next_cu
= per_cu
->cu
->read_in_chain
;
17999 if (per_cu
== target_per_cu
)
18001 free_heap_comp_unit (per_cu
->cu
);
18003 *last_chain
= next_cu
;
18007 last_chain
= &per_cu
->cu
->read_in_chain
;
18013 /* Release all extra memory associated with OBJFILE. */
18016 dwarf2_free_objfile (struct objfile
*objfile
)
18018 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18020 if (dwarf2_per_objfile
== NULL
)
18023 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
18024 free_cached_comp_units (NULL
);
18026 if (dwarf2_per_objfile
->quick_file_names_table
)
18027 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
18029 /* Everything else should be on the objfile obstack. */
18032 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
18033 We store these in a hash table separate from the DIEs, and preserve them
18034 when the DIEs are flushed out of cache.
18036 The CU "per_cu" pointer is needed because offset alone is not enough to
18037 uniquely identify the type. A file may have multiple .debug_types sections,
18038 or the type may come from a DWO file. We have to use something in
18039 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
18040 routine, get_die_type_at_offset, from outside this file, and thus won't
18041 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
18044 struct dwarf2_per_cu_offset_and_type
18046 const struct dwarf2_per_cu_data
*per_cu
;
18047 sect_offset offset
;
18051 /* Hash function for a dwarf2_per_cu_offset_and_type. */
18054 per_cu_offset_and_type_hash (const void *item
)
18056 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
18058 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
18061 /* Equality function for a dwarf2_per_cu_offset_and_type. */
18064 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
18066 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
18067 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
18069 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
18070 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
18073 /* Set the type associated with DIE to TYPE. Save it in CU's hash
18074 table if necessary. For convenience, return TYPE.
18076 The DIEs reading must have careful ordering to:
18077 * Not cause infite loops trying to read in DIEs as a prerequisite for
18078 reading current DIE.
18079 * Not trying to dereference contents of still incompletely read in types
18080 while reading in other DIEs.
18081 * Enable referencing still incompletely read in types just by a pointer to
18082 the type without accessing its fields.
18084 Therefore caller should follow these rules:
18085 * Try to fetch any prerequisite types we may need to build this DIE type
18086 before building the type and calling set_die_type.
18087 * After building type call set_die_type for current DIE as soon as
18088 possible before fetching more types to complete the current type.
18089 * Make the type as complete as possible before fetching more types. */
18091 static struct type
*
18092 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18094 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
18095 struct objfile
*objfile
= cu
->objfile
;
18097 /* For Ada types, make sure that the gnat-specific data is always
18098 initialized (if not already set). There are a few types where
18099 we should not be doing so, because the type-specific area is
18100 already used to hold some other piece of info (eg: TYPE_CODE_FLT
18101 where the type-specific area is used to store the floatformat).
18102 But this is not a problem, because the gnat-specific information
18103 is actually not needed for these types. */
18104 if (need_gnat_info (cu
)
18105 && TYPE_CODE (type
) != TYPE_CODE_FUNC
18106 && TYPE_CODE (type
) != TYPE_CODE_FLT
18107 && !HAVE_GNAT_AUX_INFO (type
))
18108 INIT_GNAT_SPECIFIC (type
);
18110 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18112 dwarf2_per_objfile
->die_type_hash
=
18113 htab_create_alloc_ex (127,
18114 per_cu_offset_and_type_hash
,
18115 per_cu_offset_and_type_eq
,
18117 &objfile
->objfile_obstack
,
18118 hashtab_obstack_allocate
,
18119 dummy_obstack_deallocate
);
18122 ofs
.per_cu
= cu
->per_cu
;
18123 ofs
.offset
= die
->offset
;
18125 slot
= (struct dwarf2_per_cu_offset_and_type
**)
18126 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
18128 complaint (&symfile_complaints
,
18129 _("A problem internal to GDB: DIE 0x%x has type already set"),
18130 die
->offset
.sect_off
);
18131 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
18136 /* Look up the type for the die at OFFSET in the appropriate type_hash
18137 table, or return NULL if the die does not have a saved type. */
18139 static struct type
*
18140 get_die_type_at_offset (sect_offset offset
,
18141 struct dwarf2_per_cu_data
*per_cu
)
18143 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
18145 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18148 ofs
.per_cu
= per_cu
;
18149 ofs
.offset
= offset
;
18150 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
18157 /* Look up the type for DIE in the appropriate type_hash table,
18158 or return NULL if DIE does not have a saved type. */
18160 static struct type
*
18161 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18163 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
18166 /* Add a dependence relationship from CU to REF_PER_CU. */
18169 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
18170 struct dwarf2_per_cu_data
*ref_per_cu
)
18174 if (cu
->dependencies
== NULL
)
18176 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
18177 NULL
, &cu
->comp_unit_obstack
,
18178 hashtab_obstack_allocate
,
18179 dummy_obstack_deallocate
);
18181 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
18183 *slot
= ref_per_cu
;
18186 /* Subroutine of dwarf2_mark to pass to htab_traverse.
18187 Set the mark field in every compilation unit in the
18188 cache that we must keep because we are keeping CU. */
18191 dwarf2_mark_helper (void **slot
, void *data
)
18193 struct dwarf2_per_cu_data
*per_cu
;
18195 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
18197 /* cu->dependencies references may not yet have been ever read if QUIT aborts
18198 reading of the chain. As such dependencies remain valid it is not much
18199 useful to track and undo them during QUIT cleanups. */
18200 if (per_cu
->cu
== NULL
)
18203 if (per_cu
->cu
->mark
)
18205 per_cu
->cu
->mark
= 1;
18207 if (per_cu
->cu
->dependencies
!= NULL
)
18208 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18213 /* Set the mark field in CU and in every other compilation unit in the
18214 cache that we must keep because we are keeping CU. */
18217 dwarf2_mark (struct dwarf2_cu
*cu
)
18222 if (cu
->dependencies
!= NULL
)
18223 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18227 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
18231 per_cu
->cu
->mark
= 0;
18232 per_cu
= per_cu
->cu
->read_in_chain
;
18236 /* Trivial hash function for partial_die_info: the hash value of a DIE
18237 is its offset in .debug_info for this objfile. */
18240 partial_die_hash (const void *item
)
18242 const struct partial_die_info
*part_die
= item
;
18244 return part_die
->offset
.sect_off
;
18247 /* Trivial comparison function for partial_die_info structures: two DIEs
18248 are equal if they have the same offset. */
18251 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
18253 const struct partial_die_info
*part_die_lhs
= item_lhs
;
18254 const struct partial_die_info
*part_die_rhs
= item_rhs
;
18256 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
18259 static struct cmd_list_element
*set_dwarf2_cmdlist
;
18260 static struct cmd_list_element
*show_dwarf2_cmdlist
;
18263 set_dwarf2_cmd (char *args
, int from_tty
)
18265 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
18269 show_dwarf2_cmd (char *args
, int from_tty
)
18271 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
18274 /* If section described by INFO was mmapped, munmap it now. */
18277 munmap_section_buffer (struct dwarf2_section_info
*info
)
18279 if (info
->map_addr
!= NULL
)
18284 res
= munmap (info
->map_addr
, info
->map_len
);
18285 gdb_assert (res
== 0);
18287 /* Without HAVE_MMAP, we should never be here to begin with. */
18288 gdb_assert_not_reached ("no mmap support");
18293 /* munmap debug sections for OBJFILE, if necessary. */
18296 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
18298 struct dwarf2_per_objfile
*data
= d
;
18300 struct dwarf2_section_info
*section
;
18302 /* This is sorted according to the order they're defined in to make it easier
18303 to keep in sync. */
18304 munmap_section_buffer (&data
->info
);
18305 munmap_section_buffer (&data
->abbrev
);
18306 munmap_section_buffer (&data
->line
);
18307 munmap_section_buffer (&data
->loc
);
18308 munmap_section_buffer (&data
->macinfo
);
18309 munmap_section_buffer (&data
->macro
);
18310 munmap_section_buffer (&data
->str
);
18311 munmap_section_buffer (&data
->ranges
);
18312 munmap_section_buffer (&data
->addr
);
18313 munmap_section_buffer (&data
->frame
);
18314 munmap_section_buffer (&data
->eh_frame
);
18315 munmap_section_buffer (&data
->gdb_index
);
18318 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
18320 munmap_section_buffer (section
);
18322 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
18323 VEC_free (dwarf2_per_cu_ptr
,
18324 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
18326 VEC_free (dwarf2_section_info_def
, data
->types
);
18328 if (data
->dwo_files
)
18329 free_dwo_files (data
->dwo_files
, objfile
);
18333 /* The "save gdb-index" command. */
18335 /* The contents of the hash table we create when building the string
18337 struct strtab_entry
18339 offset_type offset
;
18343 /* Hash function for a strtab_entry.
18345 Function is used only during write_hash_table so no index format backward
18346 compatibility is needed. */
18349 hash_strtab_entry (const void *e
)
18351 const struct strtab_entry
*entry
= e
;
18352 return mapped_index_string_hash (INT_MAX
, entry
->str
);
18355 /* Equality function for a strtab_entry. */
18358 eq_strtab_entry (const void *a
, const void *b
)
18360 const struct strtab_entry
*ea
= a
;
18361 const struct strtab_entry
*eb
= b
;
18362 return !strcmp (ea
->str
, eb
->str
);
18365 /* Create a strtab_entry hash table. */
18368 create_strtab (void)
18370 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
18371 xfree
, xcalloc
, xfree
);
18374 /* Add a string to the constant pool. Return the string's offset in
18378 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
18381 struct strtab_entry entry
;
18382 struct strtab_entry
*result
;
18385 slot
= htab_find_slot (table
, &entry
, INSERT
);
18390 result
= XNEW (struct strtab_entry
);
18391 result
->offset
= obstack_object_size (cpool
);
18393 obstack_grow_str0 (cpool
, str
);
18396 return result
->offset
;
18399 /* An entry in the symbol table. */
18400 struct symtab_index_entry
18402 /* The name of the symbol. */
18404 /* The offset of the name in the constant pool. */
18405 offset_type index_offset
;
18406 /* A sorted vector of the indices of all the CUs that hold an object
18408 VEC (offset_type
) *cu_indices
;
18411 /* The symbol table. This is a power-of-2-sized hash table. */
18412 struct mapped_symtab
18414 offset_type n_elements
;
18416 struct symtab_index_entry
**data
;
18419 /* Hash function for a symtab_index_entry. */
18422 hash_symtab_entry (const void *e
)
18424 const struct symtab_index_entry
*entry
= e
;
18425 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
18426 sizeof (offset_type
) * VEC_length (offset_type
,
18427 entry
->cu_indices
),
18431 /* Equality function for a symtab_index_entry. */
18434 eq_symtab_entry (const void *a
, const void *b
)
18436 const struct symtab_index_entry
*ea
= a
;
18437 const struct symtab_index_entry
*eb
= b
;
18438 int len
= VEC_length (offset_type
, ea
->cu_indices
);
18439 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
18441 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
18442 VEC_address (offset_type
, eb
->cu_indices
),
18443 sizeof (offset_type
) * len
);
18446 /* Destroy a symtab_index_entry. */
18449 delete_symtab_entry (void *p
)
18451 struct symtab_index_entry
*entry
= p
;
18452 VEC_free (offset_type
, entry
->cu_indices
);
18456 /* Create a hash table holding symtab_index_entry objects. */
18459 create_symbol_hash_table (void)
18461 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
18462 delete_symtab_entry
, xcalloc
, xfree
);
18465 /* Create a new mapped symtab object. */
18467 static struct mapped_symtab
*
18468 create_mapped_symtab (void)
18470 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
18471 symtab
->n_elements
= 0;
18472 symtab
->size
= 1024;
18473 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18477 /* Destroy a mapped_symtab. */
18480 cleanup_mapped_symtab (void *p
)
18482 struct mapped_symtab
*symtab
= p
;
18483 /* The contents of the array are freed when the other hash table is
18485 xfree (symtab
->data
);
18489 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
18492 Function is used only during write_hash_table so no index format backward
18493 compatibility is needed. */
18495 static struct symtab_index_entry
**
18496 find_slot (struct mapped_symtab
*symtab
, const char *name
)
18498 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
18500 index
= hash
& (symtab
->size
- 1);
18501 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
18505 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
18506 return &symtab
->data
[index
];
18507 index
= (index
+ step
) & (symtab
->size
- 1);
18511 /* Expand SYMTAB's hash table. */
18514 hash_expand (struct mapped_symtab
*symtab
)
18516 offset_type old_size
= symtab
->size
;
18518 struct symtab_index_entry
**old_entries
= symtab
->data
;
18521 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18523 for (i
= 0; i
< old_size
; ++i
)
18525 if (old_entries
[i
])
18527 struct symtab_index_entry
**slot
= find_slot (symtab
,
18528 old_entries
[i
]->name
);
18529 *slot
= old_entries
[i
];
18533 xfree (old_entries
);
18536 /* Add an entry to SYMTAB. NAME is the name of the symbol.
18537 CU_INDEX is the index of the CU in which the symbol appears.
18538 IS_STATIC is one if the symbol is static, otherwise zero (global). */
18541 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
18542 int is_static
, gdb_index_symbol_kind kind
,
18543 offset_type cu_index
)
18545 struct symtab_index_entry
**slot
;
18546 offset_type cu_index_and_attrs
;
18548 ++symtab
->n_elements
;
18549 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
18550 hash_expand (symtab
);
18552 slot
= find_slot (symtab
, name
);
18555 *slot
= XNEW (struct symtab_index_entry
);
18556 (*slot
)->name
= name
;
18557 /* index_offset is set later. */
18558 (*slot
)->cu_indices
= NULL
;
18561 cu_index_and_attrs
= 0;
18562 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
18563 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
18564 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
18566 /* We don't want to record an index value twice as we want to avoid the
18568 We process all global symbols and then all static symbols
18569 (which would allow us to avoid the duplication by only having to check
18570 the last entry pushed), but a symbol could have multiple kinds in one CU.
18571 To keep things simple we don't worry about the duplication here and
18572 sort and uniqufy the list after we've processed all symbols. */
18573 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
18576 /* qsort helper routine for uniquify_cu_indices. */
18579 offset_type_compare (const void *ap
, const void *bp
)
18581 offset_type a
= *(offset_type
*) ap
;
18582 offset_type b
= *(offset_type
*) bp
;
18584 return (a
> b
) - (b
> a
);
18587 /* Sort and remove duplicates of all symbols' cu_indices lists. */
18590 uniquify_cu_indices (struct mapped_symtab
*symtab
)
18594 for (i
= 0; i
< symtab
->size
; ++i
)
18596 struct symtab_index_entry
*entry
= symtab
->data
[i
];
18599 && entry
->cu_indices
!= NULL
)
18601 unsigned int next_to_insert
, next_to_check
;
18602 offset_type last_value
;
18604 qsort (VEC_address (offset_type
, entry
->cu_indices
),
18605 VEC_length (offset_type
, entry
->cu_indices
),
18606 sizeof (offset_type
), offset_type_compare
);
18608 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
18609 next_to_insert
= 1;
18610 for (next_to_check
= 1;
18611 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
18614 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
18617 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
18619 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
18624 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
18629 /* Add a vector of indices to the constant pool. */
18632 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
18633 struct symtab_index_entry
*entry
)
18637 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
18640 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
18641 offset_type val
= MAYBE_SWAP (len
);
18646 entry
->index_offset
= obstack_object_size (cpool
);
18648 obstack_grow (cpool
, &val
, sizeof (val
));
18650 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
18653 val
= MAYBE_SWAP (iter
);
18654 obstack_grow (cpool
, &val
, sizeof (val
));
18659 struct symtab_index_entry
*old_entry
= *slot
;
18660 entry
->index_offset
= old_entry
->index_offset
;
18663 return entry
->index_offset
;
18666 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
18667 constant pool entries going into the obstack CPOOL. */
18670 write_hash_table (struct mapped_symtab
*symtab
,
18671 struct obstack
*output
, struct obstack
*cpool
)
18674 htab_t symbol_hash_table
;
18677 symbol_hash_table
= create_symbol_hash_table ();
18678 str_table
= create_strtab ();
18680 /* We add all the index vectors to the constant pool first, to
18681 ensure alignment is ok. */
18682 for (i
= 0; i
< symtab
->size
; ++i
)
18684 if (symtab
->data
[i
])
18685 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
18688 /* Now write out the hash table. */
18689 for (i
= 0; i
< symtab
->size
; ++i
)
18691 offset_type str_off
, vec_off
;
18693 if (symtab
->data
[i
])
18695 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
18696 vec_off
= symtab
->data
[i
]->index_offset
;
18700 /* While 0 is a valid constant pool index, it is not valid
18701 to have 0 for both offsets. */
18706 str_off
= MAYBE_SWAP (str_off
);
18707 vec_off
= MAYBE_SWAP (vec_off
);
18709 obstack_grow (output
, &str_off
, sizeof (str_off
));
18710 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
18713 htab_delete (str_table
);
18714 htab_delete (symbol_hash_table
);
18717 /* Struct to map psymtab to CU index in the index file. */
18718 struct psymtab_cu_index_map
18720 struct partial_symtab
*psymtab
;
18721 unsigned int cu_index
;
18725 hash_psymtab_cu_index (const void *item
)
18727 const struct psymtab_cu_index_map
*map
= item
;
18729 return htab_hash_pointer (map
->psymtab
);
18733 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
18735 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
18736 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
18738 return lhs
->psymtab
== rhs
->psymtab
;
18741 /* Helper struct for building the address table. */
18742 struct addrmap_index_data
18744 struct objfile
*objfile
;
18745 struct obstack
*addr_obstack
;
18746 htab_t cu_index_htab
;
18748 /* Non-zero if the previous_* fields are valid.
18749 We can't write an entry until we see the next entry (since it is only then
18750 that we know the end of the entry). */
18751 int previous_valid
;
18752 /* Index of the CU in the table of all CUs in the index file. */
18753 unsigned int previous_cu_index
;
18754 /* Start address of the CU. */
18755 CORE_ADDR previous_cu_start
;
18758 /* Write an address entry to OBSTACK. */
18761 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
18762 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
18764 offset_type cu_index_to_write
;
18766 CORE_ADDR baseaddr
;
18768 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18770 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
18771 obstack_grow (obstack
, addr
, 8);
18772 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
18773 obstack_grow (obstack
, addr
, 8);
18774 cu_index_to_write
= MAYBE_SWAP (cu_index
);
18775 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
18778 /* Worker function for traversing an addrmap to build the address table. */
18781 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
18783 struct addrmap_index_data
*data
= datap
;
18784 struct partial_symtab
*pst
= obj
;
18786 if (data
->previous_valid
)
18787 add_address_entry (data
->objfile
, data
->addr_obstack
,
18788 data
->previous_cu_start
, start_addr
,
18789 data
->previous_cu_index
);
18791 data
->previous_cu_start
= start_addr
;
18794 struct psymtab_cu_index_map find_map
, *map
;
18795 find_map
.psymtab
= pst
;
18796 map
= htab_find (data
->cu_index_htab
, &find_map
);
18797 gdb_assert (map
!= NULL
);
18798 data
->previous_cu_index
= map
->cu_index
;
18799 data
->previous_valid
= 1;
18802 data
->previous_valid
= 0;
18807 /* Write OBJFILE's address map to OBSTACK.
18808 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
18809 in the index file. */
18812 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
18813 htab_t cu_index_htab
)
18815 struct addrmap_index_data addrmap_index_data
;
18817 /* When writing the address table, we have to cope with the fact that
18818 the addrmap iterator only provides the start of a region; we have to
18819 wait until the next invocation to get the start of the next region. */
18821 addrmap_index_data
.objfile
= objfile
;
18822 addrmap_index_data
.addr_obstack
= obstack
;
18823 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
18824 addrmap_index_data
.previous_valid
= 0;
18826 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
18827 &addrmap_index_data
);
18829 /* It's highly unlikely the last entry (end address = 0xff...ff)
18830 is valid, but we should still handle it.
18831 The end address is recorded as the start of the next region, but that
18832 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
18834 if (addrmap_index_data
.previous_valid
)
18835 add_address_entry (objfile
, obstack
,
18836 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
18837 addrmap_index_data
.previous_cu_index
);
18840 /* Return the symbol kind of PSYM. */
18842 static gdb_index_symbol_kind
18843 symbol_kind (struct partial_symbol
*psym
)
18845 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
18846 enum address_class aclass
= PSYMBOL_CLASS (psym
);
18854 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
18856 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18858 case LOC_CONST_BYTES
:
18859 case LOC_OPTIMIZED_OUT
:
18861 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18863 /* Note: It's currently impossible to recognize psyms as enum values
18864 short of reading the type info. For now punt. */
18865 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18867 /* There are other LOC_FOO values that one might want to classify
18868 as variables, but dwarf2read.c doesn't currently use them. */
18869 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18871 case STRUCT_DOMAIN
:
18872 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18874 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18878 /* Add a list of partial symbols to SYMTAB. */
18881 write_psymbols (struct mapped_symtab
*symtab
,
18883 struct partial_symbol
**psymp
,
18885 offset_type cu_index
,
18888 for (; count
-- > 0; ++psymp
)
18890 struct partial_symbol
*psym
= *psymp
;
18893 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
18894 error (_("Ada is not currently supported by the index"));
18896 /* Only add a given psymbol once. */
18897 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
18900 gdb_index_symbol_kind kind
= symbol_kind (psym
);
18903 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
18904 is_static
, kind
, cu_index
);
18909 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18910 exception if there is an error. */
18913 write_obstack (FILE *file
, struct obstack
*obstack
)
18915 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18917 != obstack_object_size (obstack
))
18918 error (_("couldn't data write to file"));
18921 /* Unlink a file if the argument is not NULL. */
18924 unlink_if_set (void *p
)
18926 char **filename
= p
;
18928 unlink (*filename
);
18931 /* A helper struct used when iterating over debug_types. */
18932 struct signatured_type_index_data
18934 struct objfile
*objfile
;
18935 struct mapped_symtab
*symtab
;
18936 struct obstack
*types_list
;
18941 /* A helper function that writes a single signatured_type to an
18945 write_one_signatured_type (void **slot
, void *d
)
18947 struct signatured_type_index_data
*info
= d
;
18948 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
18949 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
18950 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18953 write_psymbols (info
->symtab
,
18955 info
->objfile
->global_psymbols
.list
18956 + psymtab
->globals_offset
,
18957 psymtab
->n_global_syms
, info
->cu_index
,
18959 write_psymbols (info
->symtab
,
18961 info
->objfile
->static_psymbols
.list
18962 + psymtab
->statics_offset
,
18963 psymtab
->n_static_syms
, info
->cu_index
,
18966 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18967 entry
->per_cu
.offset
.sect_off
);
18968 obstack_grow (info
->types_list
, val
, 8);
18969 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18970 entry
->type_offset_in_tu
.cu_off
);
18971 obstack_grow (info
->types_list
, val
, 8);
18972 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
18973 obstack_grow (info
->types_list
, val
, 8);
18980 /* Recurse into all "included" dependencies and write their symbols as
18981 if they appeared in this psymtab. */
18984 recursively_write_psymbols (struct objfile
*objfile
,
18985 struct partial_symtab
*psymtab
,
18986 struct mapped_symtab
*symtab
,
18988 offset_type cu_index
)
18992 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
18993 if (psymtab
->dependencies
[i
]->user
!= NULL
)
18994 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
18995 symtab
, psyms_seen
, cu_index
);
18997 write_psymbols (symtab
,
18999 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
19000 psymtab
->n_global_syms
, cu_index
,
19002 write_psymbols (symtab
,
19004 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
19005 psymtab
->n_static_syms
, cu_index
,
19009 /* Create an index file for OBJFILE in the directory DIR. */
19012 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
19014 struct cleanup
*cleanup
;
19015 char *filename
, *cleanup_filename
;
19016 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
19017 struct obstack cu_list
, types_cu_list
;
19020 struct mapped_symtab
*symtab
;
19021 offset_type val
, size_of_contents
, total_len
;
19024 htab_t cu_index_htab
;
19025 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
19027 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
19030 if (dwarf2_per_objfile
->using_index
)
19031 error (_("Cannot use an index to create the index"));
19033 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
19034 error (_("Cannot make an index when the file has multiple .debug_types sections"));
19036 if (stat (objfile
->name
, &st
) < 0)
19037 perror_with_name (objfile
->name
);
19039 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
19040 INDEX_SUFFIX
, (char *) NULL
);
19041 cleanup
= make_cleanup (xfree
, filename
);
19043 out_file
= fopen (filename
, "wb");
19045 error (_("Can't open `%s' for writing"), filename
);
19047 cleanup_filename
= filename
;
19048 make_cleanup (unlink_if_set
, &cleanup_filename
);
19050 symtab
= create_mapped_symtab ();
19051 make_cleanup (cleanup_mapped_symtab
, symtab
);
19053 obstack_init (&addr_obstack
);
19054 make_cleanup_obstack_free (&addr_obstack
);
19056 obstack_init (&cu_list
);
19057 make_cleanup_obstack_free (&cu_list
);
19059 obstack_init (&types_cu_list
);
19060 make_cleanup_obstack_free (&types_cu_list
);
19062 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
19063 NULL
, xcalloc
, xfree
);
19064 make_cleanup_htab_delete (psyms_seen
);
19066 /* While we're scanning CU's create a table that maps a psymtab pointer
19067 (which is what addrmap records) to its index (which is what is recorded
19068 in the index file). This will later be needed to write the address
19070 cu_index_htab
= htab_create_alloc (100,
19071 hash_psymtab_cu_index
,
19072 eq_psymtab_cu_index
,
19073 NULL
, xcalloc
, xfree
);
19074 make_cleanup_htab_delete (cu_index_htab
);
19075 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
19076 xmalloc (sizeof (struct psymtab_cu_index_map
)
19077 * dwarf2_per_objfile
->n_comp_units
);
19078 make_cleanup (xfree
, psymtab_cu_index_map
);
19080 /* The CU list is already sorted, so we don't need to do additional
19081 work here. Also, the debug_types entries do not appear in
19082 all_comp_units, but only in their own hash table. */
19083 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
19085 struct dwarf2_per_cu_data
*per_cu
19086 = dwarf2_per_objfile
->all_comp_units
[i
];
19087 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19089 struct psymtab_cu_index_map
*map
;
19092 if (psymtab
->user
== NULL
)
19093 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
19095 map
= &psymtab_cu_index_map
[i
];
19096 map
->psymtab
= psymtab
;
19098 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
19099 gdb_assert (slot
!= NULL
);
19100 gdb_assert (*slot
== NULL
);
19103 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19104 per_cu
->offset
.sect_off
);
19105 obstack_grow (&cu_list
, val
, 8);
19106 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
19107 obstack_grow (&cu_list
, val
, 8);
19110 /* Dump the address map. */
19111 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
19113 /* Write out the .debug_type entries, if any. */
19114 if (dwarf2_per_objfile
->signatured_types
)
19116 struct signatured_type_index_data sig_data
;
19118 sig_data
.objfile
= objfile
;
19119 sig_data
.symtab
= symtab
;
19120 sig_data
.types_list
= &types_cu_list
;
19121 sig_data
.psyms_seen
= psyms_seen
;
19122 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
19123 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
19124 write_one_signatured_type
, &sig_data
);
19127 /* Now that we've processed all symbols we can shrink their cu_indices
19129 uniquify_cu_indices (symtab
);
19131 obstack_init (&constant_pool
);
19132 make_cleanup_obstack_free (&constant_pool
);
19133 obstack_init (&symtab_obstack
);
19134 make_cleanup_obstack_free (&symtab_obstack
);
19135 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
19137 obstack_init (&contents
);
19138 make_cleanup_obstack_free (&contents
);
19139 size_of_contents
= 6 * sizeof (offset_type
);
19140 total_len
= size_of_contents
;
19142 /* The version number. */
19143 val
= MAYBE_SWAP (7);
19144 obstack_grow (&contents
, &val
, sizeof (val
));
19146 /* The offset of the CU list from the start of the file. */
19147 val
= MAYBE_SWAP (total_len
);
19148 obstack_grow (&contents
, &val
, sizeof (val
));
19149 total_len
+= obstack_object_size (&cu_list
);
19151 /* The offset of the types CU list from the start of the file. */
19152 val
= MAYBE_SWAP (total_len
);
19153 obstack_grow (&contents
, &val
, sizeof (val
));
19154 total_len
+= obstack_object_size (&types_cu_list
);
19156 /* The offset of the address table from the start of the file. */
19157 val
= MAYBE_SWAP (total_len
);
19158 obstack_grow (&contents
, &val
, sizeof (val
));
19159 total_len
+= obstack_object_size (&addr_obstack
);
19161 /* The offset of the symbol table from the start of the file. */
19162 val
= MAYBE_SWAP (total_len
);
19163 obstack_grow (&contents
, &val
, sizeof (val
));
19164 total_len
+= obstack_object_size (&symtab_obstack
);
19166 /* The offset of the constant pool from the start of the file. */
19167 val
= MAYBE_SWAP (total_len
);
19168 obstack_grow (&contents
, &val
, sizeof (val
));
19169 total_len
+= obstack_object_size (&constant_pool
);
19171 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
19173 write_obstack (out_file
, &contents
);
19174 write_obstack (out_file
, &cu_list
);
19175 write_obstack (out_file
, &types_cu_list
);
19176 write_obstack (out_file
, &addr_obstack
);
19177 write_obstack (out_file
, &symtab_obstack
);
19178 write_obstack (out_file
, &constant_pool
);
19182 /* We want to keep the file, so we set cleanup_filename to NULL
19183 here. See unlink_if_set. */
19184 cleanup_filename
= NULL
;
19186 do_cleanups (cleanup
);
19189 /* Implementation of the `save gdb-index' command.
19191 Note that the file format used by this command is documented in the
19192 GDB manual. Any changes here must be documented there. */
19195 save_gdb_index_command (char *arg
, int from_tty
)
19197 struct objfile
*objfile
;
19200 error (_("usage: save gdb-index DIRECTORY"));
19202 ALL_OBJFILES (objfile
)
19206 /* If the objfile does not correspond to an actual file, skip it. */
19207 if (stat (objfile
->name
, &st
) < 0)
19210 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19211 if (dwarf2_per_objfile
)
19213 volatile struct gdb_exception except
;
19215 TRY_CATCH (except
, RETURN_MASK_ERROR
)
19217 write_psymtabs_to_index (objfile
, arg
);
19219 if (except
.reason
< 0)
19220 exception_fprintf (gdb_stderr
, except
,
19221 _("Error while writing index for `%s': "),
19229 int dwarf2_always_disassemble
;
19232 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
19233 struct cmd_list_element
*c
, const char *value
)
19235 fprintf_filtered (file
,
19236 _("Whether to always disassemble "
19237 "DWARF expressions is %s.\n"),
19242 show_check_physname (struct ui_file
*file
, int from_tty
,
19243 struct cmd_list_element
*c
, const char *value
)
19245 fprintf_filtered (file
,
19246 _("Whether to check \"physname\" is %s.\n"),
19250 void _initialize_dwarf2_read (void);
19253 _initialize_dwarf2_read (void)
19255 struct cmd_list_element
*c
;
19257 dwarf2_objfile_data_key
19258 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
19260 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
19261 Set DWARF 2 specific variables.\n\
19262 Configure DWARF 2 variables such as the cache size"),
19263 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
19264 0/*allow-unknown*/, &maintenance_set_cmdlist
);
19266 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
19267 Show DWARF 2 specific variables\n\
19268 Show DWARF 2 variables such as the cache size"),
19269 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
19270 0/*allow-unknown*/, &maintenance_show_cmdlist
);
19272 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
19273 &dwarf2_max_cache_age
, _("\
19274 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
19275 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
19276 A higher limit means that cached compilation units will be stored\n\
19277 in memory longer, and more total memory will be used. Zero disables\n\
19278 caching, which can slow down startup."),
19280 show_dwarf2_max_cache_age
,
19281 &set_dwarf2_cmdlist
,
19282 &show_dwarf2_cmdlist
);
19284 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
19285 &dwarf2_always_disassemble
, _("\
19286 Set whether `info address' always disassembles DWARF expressions."), _("\
19287 Show whether `info address' always disassembles DWARF expressions."), _("\
19288 When enabled, DWARF expressions are always printed in an assembly-like\n\
19289 syntax. When disabled, expressions will be printed in a more\n\
19290 conversational style, when possible."),
19292 show_dwarf2_always_disassemble
,
19293 &set_dwarf2_cmdlist
,
19294 &show_dwarf2_cmdlist
);
19296 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
19297 Set debugging of the dwarf2 reader."), _("\
19298 Show debugging of the dwarf2 reader."), _("\
19299 When enabled, debugging messages are printed during dwarf2 reading\n\
19300 and symtab expansion."),
19303 &setdebuglist
, &showdebuglist
);
19305 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
19306 Set debugging of the dwarf2 DIE reader."), _("\
19307 Show debugging of the dwarf2 DIE reader."), _("\
19308 When enabled (non-zero), DIEs are dumped after they are read in.\n\
19309 The value is the maximum depth to print."),
19312 &setdebuglist
, &showdebuglist
);
19314 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
19315 Set cross-checking of \"physname\" code against demangler."), _("\
19316 Show cross-checking of \"physname\" code against demangler."), _("\
19317 When enabled, GDB's internal \"physname\" code is checked against\n\
19319 NULL
, show_check_physname
,
19320 &setdebuglist
, &showdebuglist
);
19322 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
19324 Save a gdb-index file.\n\
19325 Usage: save gdb-index DIRECTORY"),
19327 set_cmd_completer (c
, filename_completer
);