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 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
597 This includes type_unit_group and quick_file_names. */
599 struct stmt_list_hash
601 /* The DWO unit this table is from or NULL if there is none. */
602 struct dwo_unit
*dwo_unit
;
604 /* Offset in .debug_line or .debug_line.dwo. */
605 sect_offset line_offset
;
608 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
609 an object of this type. */
611 struct type_unit_group
613 /* dwarf2read.c's main "handle" on the symtab.
614 To simplify things we create an artificial CU that "includes" all the
615 type units using this stmt_list so that the rest of the code still has
616 a "per_cu" handle on the symtab.
617 This PER_CU is recognized by having no section. */
618 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
619 struct dwarf2_per_cu_data per_cu
;
623 /* The TUs that share this DW_AT_stmt_list entry.
624 This is added to while parsing type units to build partial symtabs,
625 and is deleted afterwards and not used again. */
626 VEC (dwarf2_per_cu_ptr
) *tus
;
628 /* When reading the line table in "quick" functions, we need a real TU.
629 Any will do, we know they all share the same DW_AT_stmt_list entry.
630 For simplicity's sake, we pick the first one. */
631 struct dwarf2_per_cu_data
*first_tu
;
634 /* The primary symtab.
635 Type units in a group needn't all be defined in the same source file,
636 so we create an essentially anonymous symtab as the primary symtab. */
637 struct symtab
*primary_symtab
;
639 /* The data used to construct the hash key. */
640 struct stmt_list_hash hash
;
642 /* The number of symtabs from the line header.
643 The value here must match line_header.num_file_names. */
644 unsigned int num_symtabs
;
646 /* The symbol tables for this TU (obtained from the files listed in
648 WARNING: The order of entries here must match the order of entries
649 in the line header. After the first TU using this type_unit_group, the
650 line header for the subsequent TUs is recreated from this. This is done
651 because we need to use the same symtabs for each TU using the same
652 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
653 there's no guarantee the line header doesn't have duplicate entries. */
654 struct symtab
**symtabs
;
657 /* These sections are what may appear in a "dwo" file. */
661 struct dwarf2_section_info abbrev
;
662 struct dwarf2_section_info info
;
663 struct dwarf2_section_info line
;
664 struct dwarf2_section_info loc
;
665 struct dwarf2_section_info macinfo
;
666 struct dwarf2_section_info macro
;
667 struct dwarf2_section_info str
;
668 struct dwarf2_section_info str_offsets
;
669 VEC (dwarf2_section_info_def
) *types
;
672 /* Common bits of DWO CUs/TUs. */
676 /* Backlink to the containing struct dwo_file. */
677 struct dwo_file
*dwo_file
;
679 /* The "id" that distinguishes this CU/TU.
680 .debug_info calls this "dwo_id", .debug_types calls this "signature".
681 Since signatures came first, we stick with it for consistency. */
684 /* The section this CU/TU lives in, in the DWO file. */
685 struct dwarf2_section_info
*info_or_types_section
;
687 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
691 /* For types, offset in the type's DIE of the type defined by this TU. */
692 cu_offset type_offset_in_tu
;
695 /* Data for one DWO file. */
699 /* The DW_AT_GNU_dwo_name attribute.
700 We don't manage space for this, it's an attribute. */
701 const char *dwo_name
;
703 /* The bfd, when the file is open. Otherwise this is NULL. */
706 /* Section info for this file. */
707 struct dwo_sections sections
;
709 /* Table of CUs in the file.
710 Each element is a struct dwo_unit. */
713 /* Table of TUs in the file.
714 Each element is a struct dwo_unit. */
718 /* Struct used to pass misc. parameters to read_die_and_children, et
719 al. which are used for both .debug_info and .debug_types dies.
720 All parameters here are unchanging for the life of the call. This
721 struct exists to abstract away the constant parameters of die reading. */
723 struct die_reader_specs
725 /* die_section->asection->owner. */
728 /* The CU of the DIE we are parsing. */
729 struct dwarf2_cu
*cu
;
731 /* Non-NULL if reading a DWO file. */
732 struct dwo_file
*dwo_file
;
734 /* The section the die comes from.
735 This is either .debug_info or .debug_types, or the .dwo variants. */
736 struct dwarf2_section_info
*die_section
;
738 /* die_section->buffer. */
741 /* The end of the buffer. */
742 const gdb_byte
*buffer_end
;
745 /* Type of function passed to init_cutu_and_read_dies, et.al. */
746 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
748 struct die_info
*comp_unit_die
,
752 /* The line number information for a compilation unit (found in the
753 .debug_line section) begins with a "statement program header",
754 which contains the following information. */
757 unsigned int total_length
;
758 unsigned short version
;
759 unsigned int header_length
;
760 unsigned char minimum_instruction_length
;
761 unsigned char maximum_ops_per_instruction
;
762 unsigned char default_is_stmt
;
764 unsigned char line_range
;
765 unsigned char opcode_base
;
767 /* standard_opcode_lengths[i] is the number of operands for the
768 standard opcode whose value is i. This means that
769 standard_opcode_lengths[0] is unused, and the last meaningful
770 element is standard_opcode_lengths[opcode_base - 1]. */
771 unsigned char *standard_opcode_lengths
;
773 /* The include_directories table. NOTE! These strings are not
774 allocated with xmalloc; instead, they are pointers into
775 debug_line_buffer. If you try to free them, `free' will get
777 unsigned int num_include_dirs
, include_dirs_size
;
780 /* The file_names table. NOTE! These strings are not allocated
781 with xmalloc; instead, they are pointers into debug_line_buffer.
782 Don't try to free them directly. */
783 unsigned int num_file_names
, file_names_size
;
787 unsigned int dir_index
;
788 unsigned int mod_time
;
790 int included_p
; /* Non-zero if referenced by the Line Number Program. */
791 struct symtab
*symtab
; /* The associated symbol table, if any. */
794 /* The start and end of the statement program following this
795 header. These point into dwarf2_per_objfile->line_buffer. */
796 gdb_byte
*statement_program_start
, *statement_program_end
;
799 /* When we construct a partial symbol table entry we only
800 need this much information. */
801 struct partial_die_info
803 /* Offset of this DIE. */
806 /* DWARF-2 tag for this DIE. */
807 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
809 /* Assorted flags describing the data found in this DIE. */
810 unsigned int has_children
: 1;
811 unsigned int is_external
: 1;
812 unsigned int is_declaration
: 1;
813 unsigned int has_type
: 1;
814 unsigned int has_specification
: 1;
815 unsigned int has_pc_info
: 1;
816 unsigned int may_be_inlined
: 1;
818 /* Flag set if the SCOPE field of this structure has been
820 unsigned int scope_set
: 1;
822 /* Flag set if the DIE has a byte_size attribute. */
823 unsigned int has_byte_size
: 1;
825 /* Flag set if any of the DIE's children are template arguments. */
826 unsigned int has_template_arguments
: 1;
828 /* Flag set if fixup_partial_die has been called on this die. */
829 unsigned int fixup_called
: 1;
831 /* The name of this DIE. Normally the value of DW_AT_name, but
832 sometimes a default name for unnamed DIEs. */
835 /* The linkage name, if present. */
836 const char *linkage_name
;
838 /* The scope to prepend to our children. This is generally
839 allocated on the comp_unit_obstack, so will disappear
840 when this compilation unit leaves the cache. */
843 /* Some data associated with the partial DIE. The tag determines
844 which field is live. */
847 /* The location description associated with this DIE, if any. */
848 struct dwarf_block
*locdesc
;
849 /* The offset of an import, for DW_TAG_imported_unit. */
853 /* If HAS_PC_INFO, the PC range associated with this DIE. */
857 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
858 DW_AT_sibling, if any. */
859 /* NOTE: This member isn't strictly necessary, read_partial_die could
860 return DW_AT_sibling values to its caller load_partial_dies. */
863 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
864 DW_AT_specification (or DW_AT_abstract_origin or
866 sect_offset spec_offset
;
868 /* Pointers to this DIE's parent, first child, and next sibling,
870 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
873 /* This data structure holds the information of an abbrev. */
876 unsigned int number
; /* number identifying abbrev */
877 enum dwarf_tag tag
; /* dwarf tag */
878 unsigned short has_children
; /* boolean */
879 unsigned short num_attrs
; /* number of attributes */
880 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
881 struct abbrev_info
*next
; /* next in chain */
886 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
887 ENUM_BITFIELD(dwarf_form
) form
: 16;
890 /* Size of abbrev_table.abbrev_hash_table. */
891 #define ABBREV_HASH_SIZE 121
893 /* Top level data structure to contain an abbreviation table. */
897 /* Where the abbrev table came from.
898 This is used as a sanity check when the table is used. */
901 /* Storage for the abbrev table. */
902 struct obstack abbrev_obstack
;
904 /* Hash table of abbrevs.
905 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
906 It could be statically allocated, but the previous code didn't so we
908 struct abbrev_info
**abbrevs
;
911 /* Attributes have a name and a value. */
914 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
915 ENUM_BITFIELD(dwarf_form
) form
: 15;
917 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
918 field should be in u.str (existing only for DW_STRING) but it is kept
919 here for better struct attribute alignment. */
920 unsigned int string_is_canonical
: 1;
925 struct dwarf_block
*blk
;
929 struct signatured_type
*signatured_type
;
934 /* This data structure holds a complete die structure. */
937 /* DWARF-2 tag for this DIE. */
938 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
940 /* Number of attributes */
941 unsigned char num_attrs
;
943 /* True if we're presently building the full type name for the
944 type derived from this DIE. */
945 unsigned char building_fullname
: 1;
950 /* Offset in .debug_info or .debug_types section. */
953 /* The dies in a compilation unit form an n-ary tree. PARENT
954 points to this die's parent; CHILD points to the first child of
955 this node; and all the children of a given node are chained
956 together via their SIBLING fields. */
957 struct die_info
*child
; /* Its first child, if any. */
958 struct die_info
*sibling
; /* Its next sibling, if any. */
959 struct die_info
*parent
; /* Its parent, if any. */
961 /* An array of attributes, with NUM_ATTRS elements. There may be
962 zero, but it's not common and zero-sized arrays are not
963 sufficiently portable C. */
964 struct attribute attrs
[1];
967 /* Get at parts of an attribute structure. */
969 #define DW_STRING(attr) ((attr)->u.str)
970 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
971 #define DW_UNSND(attr) ((attr)->u.unsnd)
972 #define DW_BLOCK(attr) ((attr)->u.blk)
973 #define DW_SND(attr) ((attr)->u.snd)
974 #define DW_ADDR(attr) ((attr)->u.addr)
975 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
977 /* Blocks are a bunch of untyped bytes. */
982 /* Valid only if SIZE is not zero. */
986 #ifndef ATTR_ALLOC_CHUNK
987 #define ATTR_ALLOC_CHUNK 4
990 /* Allocate fields for structs, unions and enums in this size. */
991 #ifndef DW_FIELD_ALLOC_CHUNK
992 #define DW_FIELD_ALLOC_CHUNK 4
995 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
996 but this would require a corresponding change in unpack_field_as_long
998 static int bits_per_byte
= 8;
1000 /* The routines that read and process dies for a C struct or C++ class
1001 pass lists of data member fields and lists of member function fields
1002 in an instance of a field_info structure, as defined below. */
1005 /* List of data member and baseclasses fields. */
1008 struct nextfield
*next
;
1013 *fields
, *baseclasses
;
1015 /* Number of fields (including baseclasses). */
1018 /* Number of baseclasses. */
1021 /* Set if the accesibility of one of the fields is not public. */
1022 int non_public_fields
;
1024 /* Member function fields array, entries are allocated in the order they
1025 are encountered in the object file. */
1028 struct nextfnfield
*next
;
1029 struct fn_field fnfield
;
1033 /* Member function fieldlist array, contains name of possibly overloaded
1034 member function, number of overloaded member functions and a pointer
1035 to the head of the member function field chain. */
1040 struct nextfnfield
*head
;
1044 /* Number of entries in the fnfieldlists array. */
1047 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1048 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1049 struct typedef_field_list
1051 struct typedef_field field
;
1052 struct typedef_field_list
*next
;
1054 *typedef_field_list
;
1055 unsigned typedef_field_list_count
;
1058 /* One item on the queue of compilation units to read in full symbols
1060 struct dwarf2_queue_item
1062 struct dwarf2_per_cu_data
*per_cu
;
1063 enum language pretend_language
;
1064 struct dwarf2_queue_item
*next
;
1067 /* The current queue. */
1068 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1070 /* Loaded secondary compilation units are kept in memory until they
1071 have not been referenced for the processing of this many
1072 compilation units. Set this to zero to disable caching. Cache
1073 sizes of up to at least twenty will improve startup time for
1074 typical inter-CU-reference binaries, at an obvious memory cost. */
1075 static int dwarf2_max_cache_age
= 5;
1077 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1078 struct cmd_list_element
*c
, const char *value
)
1080 fprintf_filtered (file
, _("The upper bound on the age of cached "
1081 "dwarf2 compilation units is %s.\n"),
1086 /* Various complaints about symbol reading that don't abort the process. */
1089 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1091 complaint (&symfile_complaints
,
1092 _("statement list doesn't fit in .debug_line section"));
1096 dwarf2_debug_line_missing_file_complaint (void)
1098 complaint (&symfile_complaints
,
1099 _(".debug_line section has line data without a file"));
1103 dwarf2_debug_line_missing_end_sequence_complaint (void)
1105 complaint (&symfile_complaints
,
1106 _(".debug_line section has line "
1107 "program sequence without an end"));
1111 dwarf2_complex_location_expr_complaint (void)
1113 complaint (&symfile_complaints
, _("location expression too complex"));
1117 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1120 complaint (&symfile_complaints
,
1121 _("const value length mismatch for '%s', got %d, expected %d"),
1126 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1128 complaint (&symfile_complaints
,
1129 _("debug info runs off end of %s section"
1131 section
->asection
->name
,
1132 bfd_get_filename (section
->asection
->owner
));
1136 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1138 complaint (&symfile_complaints
,
1139 _("macro debug info contains a "
1140 "malformed macro definition:\n`%s'"),
1145 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1147 complaint (&symfile_complaints
,
1148 _("invalid attribute class or form for '%s' in '%s'"),
1152 /* local function prototypes */
1154 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1156 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1159 static void dwarf2_find_base_address (struct die_info
*die
,
1160 struct dwarf2_cu
*cu
);
1162 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1164 static void scan_partial_symbols (struct partial_die_info
*,
1165 CORE_ADDR
*, CORE_ADDR
*,
1166 int, struct dwarf2_cu
*);
1168 static void add_partial_symbol (struct partial_die_info
*,
1169 struct dwarf2_cu
*);
1171 static void add_partial_namespace (struct partial_die_info
*pdi
,
1172 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1173 int need_pc
, struct dwarf2_cu
*cu
);
1175 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1176 CORE_ADDR
*highpc
, int need_pc
,
1177 struct dwarf2_cu
*cu
);
1179 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1180 struct dwarf2_cu
*cu
);
1182 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1183 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1184 int need_pc
, struct dwarf2_cu
*cu
);
1186 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1188 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1190 static struct abbrev_info
*abbrev_table_lookup_abbrev
1191 (const struct abbrev_table
*, unsigned int);
1193 static struct abbrev_table
*abbrev_table_read_table
1194 (struct dwarf2_section_info
*, sect_offset
);
1196 static void abbrev_table_free (struct abbrev_table
*);
1198 static void abbrev_table_free_cleanup (void *);
1200 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1201 struct dwarf2_section_info
*);
1203 static void dwarf2_free_abbrev_table (void *);
1205 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1207 static struct partial_die_info
*load_partial_dies
1208 (const struct die_reader_specs
*, gdb_byte
*, int);
1210 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1211 struct partial_die_info
*,
1212 struct abbrev_info
*,
1216 static struct partial_die_info
*find_partial_die (sect_offset
,
1217 struct dwarf2_cu
*);
1219 static void fixup_partial_die (struct partial_die_info
*,
1220 struct dwarf2_cu
*);
1222 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1223 struct attribute
*, struct attr_abbrev
*,
1226 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1228 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1230 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1232 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1234 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1236 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1239 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1241 static LONGEST read_checked_initial_length_and_offset
1242 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1243 unsigned int *, unsigned int *);
1245 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1248 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1250 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1253 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1255 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1257 static char *read_indirect_string (bfd
*, gdb_byte
*,
1258 const struct comp_unit_head
*,
1261 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1263 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1265 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1268 static char *read_str_index (const struct die_reader_specs
*reader
,
1269 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1271 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1273 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1274 struct dwarf2_cu
*);
1276 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1279 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1280 struct dwarf2_cu
*cu
);
1282 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1284 static struct die_info
*die_specification (struct die_info
*die
,
1285 struct dwarf2_cu
**);
1287 static void free_line_header (struct line_header
*lh
);
1289 static void add_file_name (struct line_header
*, char *, unsigned int,
1290 unsigned int, unsigned int);
1292 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1293 struct dwarf2_cu
*cu
);
1295 static void dwarf_decode_lines (struct line_header
*, const char *,
1296 struct dwarf2_cu
*, struct partial_symtab
*,
1299 static void dwarf2_start_subfile (char *, const char *, const char *);
1301 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1302 char *, char *, CORE_ADDR
);
1304 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1305 struct dwarf2_cu
*);
1307 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1308 struct dwarf2_cu
*, struct symbol
*);
1310 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1311 struct dwarf2_cu
*);
1313 static void dwarf2_const_value_attr (struct attribute
*attr
,
1316 struct obstack
*obstack
,
1317 struct dwarf2_cu
*cu
, LONGEST
*value
,
1319 struct dwarf2_locexpr_baton
**baton
);
1321 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1323 static int need_gnat_info (struct dwarf2_cu
*);
1325 static struct type
*die_descriptive_type (struct die_info
*,
1326 struct dwarf2_cu
*);
1328 static void set_descriptive_type (struct type
*, struct die_info
*,
1329 struct dwarf2_cu
*);
1331 static struct type
*die_containing_type (struct die_info
*,
1332 struct dwarf2_cu
*);
1334 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1335 struct dwarf2_cu
*);
1337 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1339 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1341 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1343 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1344 const char *suffix
, int physname
,
1345 struct dwarf2_cu
*cu
);
1347 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1349 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1351 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1353 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1355 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1357 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1358 struct dwarf2_cu
*, struct partial_symtab
*);
1360 static int dwarf2_get_pc_bounds (struct die_info
*,
1361 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1362 struct partial_symtab
*);
1364 static void get_scope_pc_bounds (struct die_info
*,
1365 CORE_ADDR
*, CORE_ADDR
*,
1366 struct dwarf2_cu
*);
1368 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1369 CORE_ADDR
, struct dwarf2_cu
*);
1371 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1372 struct dwarf2_cu
*);
1374 static void dwarf2_attach_fields_to_type (struct field_info
*,
1375 struct type
*, struct dwarf2_cu
*);
1377 static void dwarf2_add_member_fn (struct field_info
*,
1378 struct die_info
*, struct type
*,
1379 struct dwarf2_cu
*);
1381 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1383 struct dwarf2_cu
*);
1385 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1387 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1389 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1391 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1393 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1395 static struct type
*read_module_type (struct die_info
*die
,
1396 struct dwarf2_cu
*cu
);
1398 static const char *namespace_name (struct die_info
*die
,
1399 int *is_anonymous
, struct dwarf2_cu
*);
1401 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1403 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1405 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1406 struct dwarf2_cu
*);
1408 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1410 gdb_byte
**new_info_ptr
,
1411 struct die_info
*parent
);
1413 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1415 gdb_byte
**new_info_ptr
,
1416 struct die_info
*parent
);
1418 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1419 struct die_info
**, gdb_byte
*, int *, int);
1421 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1422 struct die_info
**, gdb_byte
*, int *);
1424 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1426 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1429 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1431 static const char *dwarf2_full_name (char *name
,
1432 struct die_info
*die
,
1433 struct dwarf2_cu
*cu
);
1435 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1436 struct dwarf2_cu
**);
1438 static const char *dwarf_tag_name (unsigned int);
1440 static const char *dwarf_attr_name (unsigned int);
1442 static const char *dwarf_form_name (unsigned int);
1444 static char *dwarf_bool_name (unsigned int);
1446 static const char *dwarf_type_encoding_name (unsigned int);
1448 static struct die_info
*sibling_die (struct die_info
*);
1450 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1452 static void dump_die_for_error (struct die_info
*);
1454 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1457 /*static*/ void dump_die (struct die_info
*, int max_level
);
1459 static void store_in_ref_table (struct die_info
*,
1460 struct dwarf2_cu
*);
1462 static int is_ref_attr (struct attribute
*);
1464 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1466 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1468 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1470 struct dwarf2_cu
**);
1472 static struct die_info
*follow_die_ref (struct die_info
*,
1474 struct dwarf2_cu
**);
1476 static struct die_info
*follow_die_sig (struct die_info
*,
1478 struct dwarf2_cu
**);
1480 static struct signatured_type
*lookup_signatured_type_at_offset
1481 (struct objfile
*objfile
,
1482 struct dwarf2_section_info
*section
, sect_offset offset
);
1484 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1486 static void read_signatured_type (struct signatured_type
*);
1488 static struct type_unit_group
*get_type_unit_group
1489 (struct dwarf2_cu
*, struct attribute
*);
1491 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1493 /* memory allocation interface */
1495 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1497 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1499 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1502 static int attr_form_is_block (struct attribute
*);
1504 static int attr_form_is_section_offset (struct attribute
*);
1506 static int attr_form_is_constant (struct attribute
*);
1508 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1509 struct dwarf2_loclist_baton
*baton
,
1510 struct attribute
*attr
);
1512 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1514 struct dwarf2_cu
*cu
);
1516 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1518 struct abbrev_info
*abbrev
);
1520 static void free_stack_comp_unit (void *);
1522 static hashval_t
partial_die_hash (const void *item
);
1524 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1526 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1527 (sect_offset offset
, struct objfile
*objfile
);
1529 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1530 struct dwarf2_per_cu_data
*per_cu
);
1532 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1533 struct die_info
*comp_unit_die
,
1534 enum language pretend_language
);
1536 static void free_heap_comp_unit (void *);
1538 static void free_cached_comp_units (void *);
1540 static void age_cached_comp_units (void);
1542 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1544 static struct type
*set_die_type (struct die_info
*, struct type
*,
1545 struct dwarf2_cu
*);
1547 static void create_all_comp_units (struct objfile
*);
1549 static int create_all_type_units (struct objfile
*);
1551 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1554 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1557 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1560 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1561 struct dwarf2_per_cu_data
*);
1563 static void dwarf2_mark (struct dwarf2_cu
*);
1565 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1567 static struct type
*get_die_type_at_offset (sect_offset
,
1568 struct dwarf2_per_cu_data
*per_cu
);
1570 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1572 static void dwarf2_release_queue (void *dummy
);
1574 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1575 enum language pretend_language
);
1577 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1578 struct dwarf2_per_cu_data
*per_cu
,
1579 enum language pretend_language
);
1581 static void process_queue (void);
1583 static void find_file_and_directory (struct die_info
*die
,
1584 struct dwarf2_cu
*cu
,
1585 char **name
, char **comp_dir
);
1587 static char *file_full_name (int file
, struct line_header
*lh
,
1588 const char *comp_dir
);
1590 static void init_cutu_and_read_dies
1591 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1592 int use_existing_cu
, int keep
,
1593 die_reader_func_ftype
*die_reader_func
, void *data
);
1595 static void init_cutu_and_read_dies_simple
1596 (struct dwarf2_per_cu_data
*this_cu
,
1597 die_reader_func_ftype
*die_reader_func
, void *data
);
1599 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1601 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1603 static struct dwo_unit
*lookup_dwo_comp_unit
1604 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1606 static struct dwo_unit
*lookup_dwo_type_unit
1607 (struct signatured_type
*, char *, const char *);
1609 static void free_dwo_file_cleanup (void *);
1611 static void munmap_section_buffer (struct dwarf2_section_info
*);
1613 static void process_cu_includes (void);
1617 /* Convert VALUE between big- and little-endian. */
1619 byte_swap (offset_type value
)
1623 result
= (value
& 0xff) << 24;
1624 result
|= (value
& 0xff00) << 8;
1625 result
|= (value
& 0xff0000) >> 8;
1626 result
|= (value
& 0xff000000) >> 24;
1630 #define MAYBE_SWAP(V) byte_swap (V)
1633 #define MAYBE_SWAP(V) (V)
1634 #endif /* WORDS_BIGENDIAN */
1636 /* The suffix for an index file. */
1637 #define INDEX_SUFFIX ".gdb-index"
1639 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1640 struct dwarf2_cu
*cu
);
1642 /* Try to locate the sections we need for DWARF 2 debugging
1643 information and return true if we have enough to do something.
1644 NAMES points to the dwarf2 section names, or is NULL if the standard
1645 ELF names are used. */
1648 dwarf2_has_info (struct objfile
*objfile
,
1649 const struct dwarf2_debug_sections
*names
)
1651 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1652 if (!dwarf2_per_objfile
)
1654 /* Initialize per-objfile state. */
1655 struct dwarf2_per_objfile
*data
1656 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1658 memset (data
, 0, sizeof (*data
));
1659 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1660 dwarf2_per_objfile
= data
;
1662 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1664 dwarf2_per_objfile
->objfile
= objfile
;
1666 return (dwarf2_per_objfile
->info
.asection
!= NULL
1667 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1670 /* When loading sections, we look either for uncompressed section or for
1671 compressed section names. */
1674 section_is_p (const char *section_name
,
1675 const struct dwarf2_section_names
*names
)
1677 if (names
->normal
!= NULL
1678 && strcmp (section_name
, names
->normal
) == 0)
1680 if (names
->compressed
!= NULL
1681 && strcmp (section_name
, names
->compressed
) == 0)
1686 /* This function is mapped across the sections and remembers the
1687 offset and size of each of the debugging sections we are interested
1691 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1693 const struct dwarf2_debug_sections
*names
;
1696 names
= &dwarf2_elf_names
;
1698 names
= (const struct dwarf2_debug_sections
*) vnames
;
1700 if (section_is_p (sectp
->name
, &names
->info
))
1702 dwarf2_per_objfile
->info
.asection
= sectp
;
1703 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1705 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1707 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1708 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1710 else if (section_is_p (sectp
->name
, &names
->line
))
1712 dwarf2_per_objfile
->line
.asection
= sectp
;
1713 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1715 else if (section_is_p (sectp
->name
, &names
->loc
))
1717 dwarf2_per_objfile
->loc
.asection
= sectp
;
1718 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1720 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1722 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1723 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1725 else if (section_is_p (sectp
->name
, &names
->macro
))
1727 dwarf2_per_objfile
->macro
.asection
= sectp
;
1728 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1730 else if (section_is_p (sectp
->name
, &names
->str
))
1732 dwarf2_per_objfile
->str
.asection
= sectp
;
1733 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1735 else if (section_is_p (sectp
->name
, &names
->addr
))
1737 dwarf2_per_objfile
->addr
.asection
= sectp
;
1738 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1740 else if (section_is_p (sectp
->name
, &names
->frame
))
1742 dwarf2_per_objfile
->frame
.asection
= sectp
;
1743 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1745 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1747 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1749 if (aflag
& SEC_HAS_CONTENTS
)
1751 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1752 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1755 else if (section_is_p (sectp
->name
, &names
->ranges
))
1757 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1758 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1760 else if (section_is_p (sectp
->name
, &names
->types
))
1762 struct dwarf2_section_info type_section
;
1764 memset (&type_section
, 0, sizeof (type_section
));
1765 type_section
.asection
= sectp
;
1766 type_section
.size
= bfd_get_section_size (sectp
);
1768 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1771 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1773 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1774 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1777 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1778 && bfd_section_vma (abfd
, sectp
) == 0)
1779 dwarf2_per_objfile
->has_section_at_zero
= 1;
1782 /* Decompress a section that was compressed using zlib. Store the
1783 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1786 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1787 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1789 bfd
*abfd
= sectp
->owner
;
1791 error (_("Support for zlib-compressed DWARF data (from '%s') "
1792 "is disabled in this copy of GDB"),
1793 bfd_get_filename (abfd
));
1795 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1796 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1797 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1798 bfd_size_type uncompressed_size
;
1799 gdb_byte
*uncompressed_buffer
;
1802 int header_size
= 12;
1804 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1805 || bfd_bread (compressed_buffer
,
1806 compressed_size
, abfd
) != compressed_size
)
1807 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1808 bfd_get_filename (abfd
));
1810 /* Read the zlib header. In this case, it should be "ZLIB" followed
1811 by the uncompressed section size, 8 bytes in big-endian order. */
1812 if (compressed_size
< header_size
1813 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1814 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1815 bfd_get_filename (abfd
));
1816 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1817 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1818 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1819 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1820 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1821 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1822 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1823 uncompressed_size
+= compressed_buffer
[11];
1825 /* It is possible the section consists of several compressed
1826 buffers concatenated together, so we uncompress in a loop. */
1830 strm
.avail_in
= compressed_size
- header_size
;
1831 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1832 strm
.avail_out
= uncompressed_size
;
1833 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1835 rc
= inflateInit (&strm
);
1836 while (strm
.avail_in
> 0)
1839 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1840 bfd_get_filename (abfd
), rc
);
1841 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1842 + (uncompressed_size
- strm
.avail_out
));
1843 rc
= inflate (&strm
, Z_FINISH
);
1844 if (rc
!= Z_STREAM_END
)
1845 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1846 bfd_get_filename (abfd
), rc
);
1847 rc
= inflateReset (&strm
);
1849 rc
= inflateEnd (&strm
);
1851 || strm
.avail_out
!= 0)
1852 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1853 bfd_get_filename (abfd
), rc
);
1855 do_cleanups (cleanup
);
1856 *outbuf
= uncompressed_buffer
;
1857 *outsize
= uncompressed_size
;
1861 /* A helper function that decides whether a section is empty,
1865 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1867 return info
->asection
== NULL
|| info
->size
== 0;
1870 /* Read the contents of the section INFO.
1871 OBJFILE is the main object file, but not necessarily the file where
1872 the section comes from. E.g., for DWO files INFO->asection->owner
1873 is the bfd of the DWO file.
1874 If the section is compressed, uncompress it before returning. */
1877 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1879 asection
*sectp
= info
->asection
;
1881 gdb_byte
*buf
, *retbuf
;
1882 unsigned char header
[4];
1886 info
->buffer
= NULL
;
1887 info
->map_addr
= NULL
;
1890 if (dwarf2_section_empty_p (info
))
1893 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1894 abfd
= sectp
->owner
;
1896 /* Check if the file has a 4-byte header indicating compression. */
1897 if (info
->size
> sizeof (header
)
1898 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1899 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1901 /* Upon decompression, update the buffer and its size. */
1902 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1904 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1912 pagesize
= getpagesize ();
1914 /* Only try to mmap sections which are large enough: we don't want to
1915 waste space due to fragmentation. Also, only try mmap for sections
1916 without relocations. */
1918 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1920 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1921 MAP_PRIVATE
, sectp
->filepos
,
1922 &info
->map_addr
, &info
->map_len
);
1924 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1926 #if HAVE_POSIX_MADVISE
1927 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1934 /* If we get here, we are a normal, not-compressed section. */
1936 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1938 /* When debugging .o files, we may need to apply relocations; see
1939 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1940 We never compress sections in .o files, so we only need to
1941 try this when the section is not compressed. */
1942 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1945 info
->buffer
= retbuf
;
1949 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1950 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1951 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1952 bfd_get_filename (abfd
));
1955 /* A helper function that returns the size of a section in a safe way.
1956 If you are positive that the section has been read before using the
1957 size, then it is safe to refer to the dwarf2_section_info object's
1958 "size" field directly. In other cases, you must call this
1959 function, because for compressed sections the size field is not set
1960 correctly until the section has been read. */
1962 static bfd_size_type
1963 dwarf2_section_size (struct objfile
*objfile
,
1964 struct dwarf2_section_info
*info
)
1967 dwarf2_read_section (objfile
, info
);
1971 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1975 dwarf2_get_section_info (struct objfile
*objfile
,
1976 enum dwarf2_section_enum sect
,
1977 asection
**sectp
, gdb_byte
**bufp
,
1978 bfd_size_type
*sizep
)
1980 struct dwarf2_per_objfile
*data
1981 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1982 struct dwarf2_section_info
*info
;
1984 /* We may see an objfile without any DWARF, in which case we just
1995 case DWARF2_DEBUG_FRAME
:
1996 info
= &data
->frame
;
1998 case DWARF2_EH_FRAME
:
1999 info
= &data
->eh_frame
;
2002 gdb_assert_not_reached ("unexpected section");
2005 dwarf2_read_section (objfile
, info
);
2007 *sectp
= info
->asection
;
2008 *bufp
= info
->buffer
;
2009 *sizep
= info
->size
;
2013 /* DWARF quick_symbols_functions support. */
2015 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2016 unique line tables, so we maintain a separate table of all .debug_line
2017 derived entries to support the sharing.
2018 All the quick functions need is the list of file names. We discard the
2019 line_header when we're done and don't need to record it here. */
2020 struct quick_file_names
2022 /* The data used to construct the hash key. */
2023 struct stmt_list_hash hash
;
2025 /* The number of entries in file_names, real_names. */
2026 unsigned int num_file_names
;
2028 /* The file names from the line table, after being run through
2030 const char **file_names
;
2032 /* The file names from the line table after being run through
2033 gdb_realpath. These are computed lazily. */
2034 const char **real_names
;
2037 /* When using the index (and thus not using psymtabs), each CU has an
2038 object of this type. This is used to hold information needed by
2039 the various "quick" methods. */
2040 struct dwarf2_per_cu_quick_data
2042 /* The file table. This can be NULL if there was no file table
2043 or it's currently not read in.
2044 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2045 struct quick_file_names
*file_names
;
2047 /* The corresponding symbol table. This is NULL if symbols for this
2048 CU have not yet been read. */
2049 struct symtab
*symtab
;
2051 /* A temporary mark bit used when iterating over all CUs in
2052 expand_symtabs_matching. */
2053 unsigned int mark
: 1;
2055 /* True if we've tried to read the file table and found there isn't one.
2056 There will be no point in trying to read it again next time. */
2057 unsigned int no_file_data
: 1;
2060 /* Utility hash function for a stmt_list_hash. */
2063 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2067 if (stmt_list_hash
->dwo_unit
!= NULL
)
2068 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2069 v
+= stmt_list_hash
->line_offset
.sect_off
;
2073 /* Utility equality function for a stmt_list_hash. */
2076 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2077 const struct stmt_list_hash
*rhs
)
2079 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2081 if (lhs
->dwo_unit
!= NULL
2082 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2085 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2088 /* Hash function for a quick_file_names. */
2091 hash_file_name_entry (const void *e
)
2093 const struct quick_file_names
*file_data
= e
;
2095 return hash_stmt_list_entry (&file_data
->hash
);
2098 /* Equality function for a quick_file_names. */
2101 eq_file_name_entry (const void *a
, const void *b
)
2103 const struct quick_file_names
*ea
= a
;
2104 const struct quick_file_names
*eb
= b
;
2106 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2109 /* Delete function for a quick_file_names. */
2112 delete_file_name_entry (void *e
)
2114 struct quick_file_names
*file_data
= e
;
2117 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2119 xfree ((void*) file_data
->file_names
[i
]);
2120 if (file_data
->real_names
)
2121 xfree ((void*) file_data
->real_names
[i
]);
2124 /* The space for the struct itself lives on objfile_obstack,
2125 so we don't free it here. */
2128 /* Create a quick_file_names hash table. */
2131 create_quick_file_names_table (unsigned int nr_initial_entries
)
2133 return htab_create_alloc (nr_initial_entries
,
2134 hash_file_name_entry
, eq_file_name_entry
,
2135 delete_file_name_entry
, xcalloc
, xfree
);
2138 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2139 have to be created afterwards. You should call age_cached_comp_units after
2140 processing PER_CU->CU. dw2_setup must have been already called. */
2143 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2145 if (per_cu
->is_debug_types
)
2146 load_full_type_unit (per_cu
);
2148 load_full_comp_unit (per_cu
, language_minimal
);
2150 gdb_assert (per_cu
->cu
!= NULL
);
2152 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2155 /* Read in the symbols for PER_CU. */
2158 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2160 struct cleanup
*back_to
;
2162 /* Skip type_unit_groups, reading the type units they contain
2163 is handled elsewhere. */
2164 if (IS_TYPE_UNIT_GROUP (per_cu
))
2167 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2169 if (dwarf2_per_objfile
->using_index
2170 ? per_cu
->v
.quick
->symtab
== NULL
2171 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2173 queue_comp_unit (per_cu
, language_minimal
);
2179 /* Age the cache, releasing compilation units that have not
2180 been used recently. */
2181 age_cached_comp_units ();
2183 do_cleanups (back_to
);
2186 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2187 the objfile from which this CU came. Returns the resulting symbol
2190 static struct symtab
*
2191 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2193 gdb_assert (dwarf2_per_objfile
->using_index
);
2194 if (!per_cu
->v
.quick
->symtab
)
2196 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2197 increment_reading_symtab ();
2198 dw2_do_instantiate_symtab (per_cu
);
2199 process_cu_includes ();
2200 do_cleanups (back_to
);
2202 return per_cu
->v
.quick
->symtab
;
2205 /* Return the CU given its index.
2207 This is intended for loops like:
2209 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2210 + dwarf2_per_objfile->n_type_units); ++i)
2212 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2218 static struct dwarf2_per_cu_data
*
2219 dw2_get_cu (int index
)
2221 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2223 index
-= dwarf2_per_objfile
->n_comp_units
;
2224 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2225 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2228 return dwarf2_per_objfile
->all_comp_units
[index
];
2231 /* Return the primary CU given its index.
2232 The difference between this function and dw2_get_cu is in the handling
2233 of type units (TUs). Here we return the type_unit_group object.
2235 This is intended for loops like:
2237 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2238 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2240 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2246 static struct dwarf2_per_cu_data
*
2247 dw2_get_primary_cu (int index
)
2249 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2251 index
-= dwarf2_per_objfile
->n_comp_units
;
2252 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2253 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2256 return dwarf2_per_objfile
->all_comp_units
[index
];
2259 /* A helper function that knows how to read a 64-bit value in a way
2260 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2264 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2266 if (sizeof (ULONGEST
) < 8)
2270 /* Ignore the upper 4 bytes if they are all zero. */
2271 for (i
= 0; i
< 4; ++i
)
2272 if (bytes
[i
+ 4] != 0)
2275 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2278 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2282 /* Read the CU list from the mapped index, and use it to create all
2283 the CU objects for this objfile. Return 0 if something went wrong,
2284 1 if everything went ok. */
2287 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2288 offset_type cu_list_elements
)
2292 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2293 dwarf2_per_objfile
->all_comp_units
2294 = obstack_alloc (&objfile
->objfile_obstack
,
2295 dwarf2_per_objfile
->n_comp_units
2296 * sizeof (struct dwarf2_per_cu_data
*));
2298 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2300 struct dwarf2_per_cu_data
*the_cu
;
2301 ULONGEST offset
, length
;
2303 if (!extract_cu_value (cu_list
, &offset
)
2304 || !extract_cu_value (cu_list
+ 8, &length
))
2308 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2309 struct dwarf2_per_cu_data
);
2310 the_cu
->offset
.sect_off
= offset
;
2311 the_cu
->length
= length
;
2312 the_cu
->objfile
= objfile
;
2313 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2314 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2315 struct dwarf2_per_cu_quick_data
);
2316 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2322 /* Create the signatured type hash table from the index. */
2325 create_signatured_type_table_from_index (struct objfile
*objfile
,
2326 struct dwarf2_section_info
*section
,
2327 const gdb_byte
*bytes
,
2328 offset_type elements
)
2331 htab_t sig_types_hash
;
2333 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2334 dwarf2_per_objfile
->all_type_units
2335 = obstack_alloc (&objfile
->objfile_obstack
,
2336 dwarf2_per_objfile
->n_type_units
2337 * sizeof (struct signatured_type
*));
2339 sig_types_hash
= allocate_signatured_type_table (objfile
);
2341 for (i
= 0; i
< elements
; i
+= 3)
2343 struct signatured_type
*sig_type
;
2344 ULONGEST offset
, type_offset_in_tu
, signature
;
2347 if (!extract_cu_value (bytes
, &offset
)
2348 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2350 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2353 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2354 struct signatured_type
);
2355 sig_type
->signature
= signature
;
2356 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2357 sig_type
->per_cu
.is_debug_types
= 1;
2358 sig_type
->per_cu
.info_or_types_section
= section
;
2359 sig_type
->per_cu
.offset
.sect_off
= offset
;
2360 sig_type
->per_cu
.objfile
= objfile
;
2361 sig_type
->per_cu
.v
.quick
2362 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2363 struct dwarf2_per_cu_quick_data
);
2365 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2368 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2371 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2376 /* Read the address map data from the mapped index, and use it to
2377 populate the objfile's psymtabs_addrmap. */
2380 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2382 const gdb_byte
*iter
, *end
;
2383 struct obstack temp_obstack
;
2384 struct addrmap
*mutable_map
;
2385 struct cleanup
*cleanup
;
2388 obstack_init (&temp_obstack
);
2389 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2390 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2392 iter
= index
->address_table
;
2393 end
= iter
+ index
->address_table_size
;
2395 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2399 ULONGEST hi
, lo
, cu_index
;
2400 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2402 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2404 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2407 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2408 dw2_get_cu (cu_index
));
2411 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2412 &objfile
->objfile_obstack
);
2413 do_cleanups (cleanup
);
2416 /* The hash function for strings in the mapped index. This is the same as
2417 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2418 implementation. This is necessary because the hash function is tied to the
2419 format of the mapped index file. The hash values do not have to match with
2422 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2425 mapped_index_string_hash (int index_version
, const void *p
)
2427 const unsigned char *str
= (const unsigned char *) p
;
2431 while ((c
= *str
++) != 0)
2433 if (index_version
>= 5)
2435 r
= r
* 67 + c
- 113;
2441 /* Find a slot in the mapped index INDEX for the object named NAME.
2442 If NAME is found, set *VEC_OUT to point to the CU vector in the
2443 constant pool and return 1. If NAME cannot be found, return 0. */
2446 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2447 offset_type
**vec_out
)
2449 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2451 offset_type slot
, step
;
2452 int (*cmp
) (const char *, const char *);
2454 if (current_language
->la_language
== language_cplus
2455 || current_language
->la_language
== language_java
2456 || current_language
->la_language
== language_fortran
)
2458 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2460 const char *paren
= strchr (name
, '(');
2466 dup
= xmalloc (paren
- name
+ 1);
2467 memcpy (dup
, name
, paren
- name
);
2468 dup
[paren
- name
] = 0;
2470 make_cleanup (xfree
, dup
);
2475 /* Index version 4 did not support case insensitive searches. But the
2476 indices for case insensitive languages are built in lowercase, therefore
2477 simulate our NAME being searched is also lowercased. */
2478 hash
= mapped_index_string_hash ((index
->version
== 4
2479 && case_sensitivity
== case_sensitive_off
2480 ? 5 : index
->version
),
2483 slot
= hash
& (index
->symbol_table_slots
- 1);
2484 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2485 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2489 /* Convert a slot number to an offset into the table. */
2490 offset_type i
= 2 * slot
;
2492 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2494 do_cleanups (back_to
);
2498 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2499 if (!cmp (name
, str
))
2501 *vec_out
= (offset_type
*) (index
->constant_pool
2502 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2503 do_cleanups (back_to
);
2507 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2511 /* Read the index file. If everything went ok, initialize the "quick"
2512 elements of all the CUs and return 1. Otherwise, return 0. */
2515 dwarf2_read_index (struct objfile
*objfile
)
2518 struct mapped_index
*map
;
2519 offset_type
*metadata
;
2520 const gdb_byte
*cu_list
;
2521 const gdb_byte
*types_list
= NULL
;
2522 offset_type version
, cu_list_elements
;
2523 offset_type types_list_elements
= 0;
2526 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2529 /* Older elfutils strip versions could keep the section in the main
2530 executable while splitting it for the separate debug info file. */
2531 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2532 & SEC_HAS_CONTENTS
) == 0)
2535 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2537 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2538 /* Version check. */
2539 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2540 /* Versions earlier than 3 emitted every copy of a psymbol. This
2541 causes the index to behave very poorly for certain requests. Version 3
2542 contained incomplete addrmap. So, it seems better to just ignore such
2546 static int warning_printed
= 0;
2547 if (!warning_printed
)
2549 warning (_("Skipping obsolete .gdb_index section in %s."),
2551 warning_printed
= 1;
2555 /* Index version 4 uses a different hash function than index version
2558 Versions earlier than 6 did not emit psymbols for inlined
2559 functions. Using these files will cause GDB not to be able to
2560 set breakpoints on inlined functions by name, so we ignore these
2561 indices unless the --use-deprecated-index-sections command line
2562 option was supplied. */
2563 if (version
< 6 && !use_deprecated_index_sections
)
2565 static int warning_printed
= 0;
2566 if (!warning_printed
)
2568 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2569 "--use-deprecated-index-sections to use them anyway"),
2571 warning_printed
= 1;
2575 /* Indexes with higher version than the one supported by GDB may be no
2576 longer backward compatible. */
2580 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2581 map
->version
= version
;
2582 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2584 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2587 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2588 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2592 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2593 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2594 - MAYBE_SWAP (metadata
[i
]))
2598 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2599 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2600 - MAYBE_SWAP (metadata
[i
]));
2603 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2604 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2605 - MAYBE_SWAP (metadata
[i
]))
2606 / (2 * sizeof (offset_type
)));
2609 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2611 /* Don't use the index if it's empty. */
2612 if (map
->symbol_table_slots
== 0)
2615 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2618 if (types_list_elements
)
2620 struct dwarf2_section_info
*section
;
2622 /* We can only handle a single .debug_types when we have an
2624 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2627 section
= VEC_index (dwarf2_section_info_def
,
2628 dwarf2_per_objfile
->types
, 0);
2630 if (!create_signatured_type_table_from_index (objfile
, section
,
2632 types_list_elements
))
2636 create_addrmap_from_index (objfile
, map
);
2638 dwarf2_per_objfile
->index_table
= map
;
2639 dwarf2_per_objfile
->using_index
= 1;
2640 dwarf2_per_objfile
->quick_file_names_table
=
2641 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2646 /* A helper for the "quick" functions which sets the global
2647 dwarf2_per_objfile according to OBJFILE. */
2650 dw2_setup (struct objfile
*objfile
)
2652 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2653 gdb_assert (dwarf2_per_objfile
);
2656 /* Reader function for dw2_build_type_unit_groups. */
2659 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2661 struct die_info
*type_unit_die
,
2665 struct dwarf2_cu
*cu
= reader
->cu
;
2666 struct attribute
*attr
;
2667 struct type_unit_group
*tu_group
;
2669 gdb_assert (data
== NULL
);
2674 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2675 /* Call this for its side-effect of creating the associated
2676 struct type_unit_group if it doesn't already exist. */
2677 tu_group
= get_type_unit_group (cu
, attr
);
2680 /* Build dwarf2_per_objfile->type_unit_groups.
2681 This function may be called multiple times. */
2684 dw2_build_type_unit_groups (void)
2686 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2687 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2690 /* die_reader_func for dw2_get_file_names. */
2693 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2695 struct die_info
*comp_unit_die
,
2699 struct dwarf2_cu
*cu
= reader
->cu
;
2700 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2701 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2702 struct dwarf2_per_cu_data
*lh_cu
;
2703 struct line_header
*lh
;
2704 struct attribute
*attr
;
2706 char *name
, *comp_dir
;
2708 struct quick_file_names
*qfn
;
2709 unsigned int line_offset
;
2711 /* Our callers never want to match partial units -- instead they
2712 will match the enclosing full CU. */
2713 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2715 this_cu
->v
.quick
->no_file_data
= 1;
2719 /* If we're reading the line header for TUs, store it in the "per_cu"
2721 if (this_cu
->is_debug_types
)
2723 struct type_unit_group
*tu_group
= data
;
2725 gdb_assert (tu_group
!= NULL
);
2726 lh_cu
= &tu_group
->per_cu
;
2735 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2738 struct quick_file_names find_entry
;
2740 line_offset
= DW_UNSND (attr
);
2742 /* We may have already read in this line header (TU line header sharing).
2743 If we have we're done. */
2744 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2745 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2746 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2747 &find_entry
, INSERT
);
2750 lh_cu
->v
.quick
->file_names
= *slot
;
2754 lh
= dwarf_decode_line_header (line_offset
, cu
);
2758 lh_cu
->v
.quick
->no_file_data
= 1;
2762 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2763 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2764 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2765 gdb_assert (slot
!= NULL
);
2768 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2770 qfn
->num_file_names
= lh
->num_file_names
;
2771 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2772 lh
->num_file_names
* sizeof (char *));
2773 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2774 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2775 qfn
->real_names
= NULL
;
2777 free_line_header (lh
);
2779 lh_cu
->v
.quick
->file_names
= qfn
;
2782 /* A helper for the "quick" functions which attempts to read the line
2783 table for THIS_CU. */
2785 static struct quick_file_names
*
2786 dw2_get_file_names (struct objfile
*objfile
,
2787 struct dwarf2_per_cu_data
*this_cu
)
2789 /* For TUs this should only be called on the parent group. */
2790 if (this_cu
->is_debug_types
)
2791 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2793 if (this_cu
->v
.quick
->file_names
!= NULL
)
2794 return this_cu
->v
.quick
->file_names
;
2795 /* If we know there is no line data, no point in looking again. */
2796 if (this_cu
->v
.quick
->no_file_data
)
2799 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2800 in the stub for CUs, there's is no need to lookup the DWO file.
2801 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2803 if (this_cu
->is_debug_types
)
2805 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2807 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2808 dw2_get_file_names_reader
, tu_group
);
2811 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2813 if (this_cu
->v
.quick
->no_file_data
)
2815 return this_cu
->v
.quick
->file_names
;
2818 /* A helper for the "quick" functions which computes and caches the
2819 real path for a given file name from the line table. */
2822 dw2_get_real_path (struct objfile
*objfile
,
2823 struct quick_file_names
*qfn
, int index
)
2825 if (qfn
->real_names
== NULL
)
2826 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2827 qfn
->num_file_names
, sizeof (char *));
2829 if (qfn
->real_names
[index
] == NULL
)
2830 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2832 return qfn
->real_names
[index
];
2835 static struct symtab
*
2836 dw2_find_last_source_symtab (struct objfile
*objfile
)
2840 dw2_setup (objfile
);
2841 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2842 return dw2_instantiate_symtab (dw2_get_cu (index
));
2845 /* Traversal function for dw2_forget_cached_source_info. */
2848 dw2_free_cached_file_names (void **slot
, void *info
)
2850 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2852 if (file_data
->real_names
)
2856 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2858 xfree ((void*) file_data
->real_names
[i
]);
2859 file_data
->real_names
[i
] = NULL
;
2867 dw2_forget_cached_source_info (struct objfile
*objfile
)
2869 dw2_setup (objfile
);
2871 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2872 dw2_free_cached_file_names
, NULL
);
2875 /* Helper function for dw2_map_symtabs_matching_filename that expands
2876 the symtabs and calls the iterator. */
2879 dw2_map_expand_apply (struct objfile
*objfile
,
2880 struct dwarf2_per_cu_data
*per_cu
,
2882 const char *full_path
, const char *real_path
,
2883 int (*callback
) (struct symtab
*, void *),
2886 struct symtab
*last_made
= objfile
->symtabs
;
2888 /* Don't visit already-expanded CUs. */
2889 if (per_cu
->v
.quick
->symtab
)
2892 /* This may expand more than one symtab, and we want to iterate over
2894 dw2_instantiate_symtab (per_cu
);
2896 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2897 objfile
->symtabs
, last_made
);
2900 /* Implementation of the map_symtabs_matching_filename method. */
2903 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2904 const char *full_path
, const char *real_path
,
2905 int (*callback
) (struct symtab
*, void *),
2909 const char *name_basename
= lbasename (name
);
2910 int name_len
= strlen (name
);
2911 int is_abs
= IS_ABSOLUTE_PATH (name
);
2913 dw2_setup (objfile
);
2915 dw2_build_type_unit_groups ();
2917 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2918 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
2921 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
2922 struct quick_file_names
*file_data
;
2924 /* We only need to look at symtabs not already expanded. */
2925 if (per_cu
->v
.quick
->symtab
)
2928 file_data
= dw2_get_file_names (objfile
, per_cu
);
2929 if (file_data
== NULL
)
2932 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2934 const char *this_name
= file_data
->file_names
[j
];
2936 if (FILENAME_CMP (name
, this_name
) == 0
2937 || (!is_abs
&& compare_filenames_for_search (this_name
,
2940 if (dw2_map_expand_apply (objfile
, per_cu
,
2941 name
, full_path
, real_path
,
2946 /* Before we invoke realpath, which can get expensive when many
2947 files are involved, do a quick comparison of the basenames. */
2948 if (! basenames_may_differ
2949 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2952 if (full_path
!= NULL
)
2954 const char *this_real_name
= dw2_get_real_path (objfile
,
2957 if (this_real_name
!= NULL
2958 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2960 && compare_filenames_for_search (this_real_name
,
2963 if (dw2_map_expand_apply (objfile
, per_cu
,
2964 name
, full_path
, real_path
,
2970 if (real_path
!= NULL
)
2972 const char *this_real_name
= dw2_get_real_path (objfile
,
2975 if (this_real_name
!= NULL
2976 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2978 && compare_filenames_for_search (this_real_name
,
2981 if (dw2_map_expand_apply (objfile
, per_cu
,
2982 name
, full_path
, real_path
,
2993 static struct symtab
*
2994 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2995 const char *name
, domain_enum domain
)
2997 /* We do all the work in the pre_expand_symtabs_matching hook
3002 /* A helper function that expands all symtabs that hold an object
3003 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
3004 symbols in block BLOCK_KIND. */
3007 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
3008 int want_specific_block
,
3009 enum block_enum block_kind
,
3010 const char *name
, domain_enum domain
)
3012 struct mapped_index
*index
;
3014 dw2_setup (objfile
);
3016 index
= dwarf2_per_objfile
->index_table
;
3018 /* index_table is NULL if OBJF_READNOW. */
3023 if (find_slot_in_mapped_hash (index
, name
, &vec
))
3025 offset_type i
, len
= MAYBE_SWAP (*vec
);
3026 for (i
= 0; i
< len
; ++i
)
3028 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
3029 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3030 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3031 int want_static
= block_kind
!= GLOBAL_BLOCK
;
3032 /* This value is only valid for index versions >= 7. */
3033 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3034 gdb_index_symbol_kind symbol_kind
=
3035 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3037 if (want_specific_block
3038 && index
->version
>= 7
3039 && want_static
!= is_static
)
3042 /* Only check the symbol's kind if it has one.
3043 Indices prior to version 7 don't record it. */
3044 if (index
->version
>= 7)
3049 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3050 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3051 /* Some types are also in VAR_DOMAIN. */
3052 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3056 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3060 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3068 dw2_instantiate_symtab (per_cu
);
3075 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
3076 enum block_enum block_kind
, const char *name
,
3079 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
3083 dw2_print_stats (struct objfile
*objfile
)
3087 dw2_setup (objfile
);
3089 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3090 + dwarf2_per_objfile
->n_type_units
); ++i
)
3092 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3094 if (!per_cu
->v
.quick
->symtab
)
3097 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3101 dw2_dump (struct objfile
*objfile
)
3103 /* Nothing worth printing. */
3107 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3108 struct section_offsets
*delta
)
3110 /* There's nothing to relocate here. */
3114 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3115 const char *func_name
)
3117 /* Note: It doesn't matter what we pass for block_kind here. */
3118 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
3123 dw2_expand_all_symtabs (struct objfile
*objfile
)
3127 dw2_setup (objfile
);
3129 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3130 + dwarf2_per_objfile
->n_type_units
); ++i
)
3132 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3134 dw2_instantiate_symtab (per_cu
);
3139 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3140 const char *filename
)
3144 dw2_setup (objfile
);
3146 /* We don't need to consider type units here.
3147 This is only called for examining code, e.g. expand_line_sal.
3148 There can be an order of magnitude (or more) more type units
3149 than comp units, and we avoid them if we can. */
3151 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3154 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3155 struct quick_file_names
*file_data
;
3157 /* We only need to look at symtabs not already expanded. */
3158 if (per_cu
->v
.quick
->symtab
)
3161 file_data
= dw2_get_file_names (objfile
, per_cu
);
3162 if (file_data
== NULL
)
3165 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3167 const char *this_name
= file_data
->file_names
[j
];
3168 if (FILENAME_CMP (this_name
, filename
) == 0)
3170 dw2_instantiate_symtab (per_cu
);
3177 /* A helper function for dw2_find_symbol_file that finds the primary
3178 file name for a given CU. This is a die_reader_func. */
3181 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3183 struct die_info
*comp_unit_die
,
3187 const char **result_ptr
= data
;
3188 struct dwarf2_cu
*cu
= reader
->cu
;
3189 struct attribute
*attr
;
3191 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3195 *result_ptr
= DW_STRING (attr
);
3199 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3201 struct dwarf2_per_cu_data
*per_cu
;
3203 struct quick_file_names
*file_data
;
3204 const char *filename
;
3206 dw2_setup (objfile
);
3208 /* index_table is NULL if OBJF_READNOW. */
3209 if (!dwarf2_per_objfile
->index_table
)
3213 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3215 struct blockvector
*bv
= BLOCKVECTOR (s
);
3216 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3217 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3220 return sym
->symtab
->filename
;
3225 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3229 /* Note that this just looks at the very first one named NAME -- but
3230 actually we are looking for a function. find_main_filename
3231 should be rewritten so that it doesn't require a custom hook. It
3232 could just use the ordinary symbol tables. */
3233 /* vec[0] is the length, which must always be >0. */
3234 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3236 if (per_cu
->v
.quick
->symtab
!= NULL
)
3237 return per_cu
->v
.quick
->symtab
->filename
;
3239 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3240 dw2_get_primary_filename_reader
, &filename
);
3246 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3247 struct objfile
*objfile
, int global
,
3248 int (*callback
) (struct block
*,
3249 struct symbol
*, void *),
3250 void *data
, symbol_compare_ftype
*match
,
3251 symbol_compare_ftype
*ordered_compare
)
3253 /* Currently unimplemented; used for Ada. The function can be called if the
3254 current language is Ada for a non-Ada objfile using GNU index. As Ada
3255 does not look for non-Ada symbols this function should just return. */
3259 dw2_expand_symtabs_matching
3260 (struct objfile
*objfile
,
3261 int (*file_matcher
) (const char *, void *),
3262 int (*name_matcher
) (const char *, void *),
3263 enum search_domain kind
,
3268 struct mapped_index
*index
;
3270 dw2_setup (objfile
);
3272 /* index_table is NULL if OBJF_READNOW. */
3273 if (!dwarf2_per_objfile
->index_table
)
3275 index
= dwarf2_per_objfile
->index_table
;
3277 if (file_matcher
!= NULL
)
3279 struct cleanup
*cleanup
;
3280 htab_t visited_found
, visited_not_found
;
3282 dw2_build_type_unit_groups ();
3284 visited_found
= htab_create_alloc (10,
3285 htab_hash_pointer
, htab_eq_pointer
,
3286 NULL
, xcalloc
, xfree
);
3287 cleanup
= make_cleanup_htab_delete (visited_found
);
3288 visited_not_found
= htab_create_alloc (10,
3289 htab_hash_pointer
, htab_eq_pointer
,
3290 NULL
, xcalloc
, xfree
);
3291 make_cleanup_htab_delete (visited_not_found
);
3293 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3294 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3297 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3298 struct quick_file_names
*file_data
;
3301 per_cu
->v
.quick
->mark
= 0;
3303 /* We only need to look at symtabs not already expanded. */
3304 if (per_cu
->v
.quick
->symtab
)
3307 file_data
= dw2_get_file_names (objfile
, per_cu
);
3308 if (file_data
== NULL
)
3311 if (htab_find (visited_not_found
, file_data
) != NULL
)
3313 else if (htab_find (visited_found
, file_data
) != NULL
)
3315 per_cu
->v
.quick
->mark
= 1;
3319 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3321 if (file_matcher (file_data
->file_names
[j
], data
))
3323 per_cu
->v
.quick
->mark
= 1;
3328 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3330 : visited_not_found
,
3335 do_cleanups (cleanup
);
3338 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3340 offset_type idx
= 2 * iter
;
3342 offset_type
*vec
, vec_len
, vec_idx
;
3344 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3347 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3349 if (! (*name_matcher
) (name
, data
))
3352 /* The name was matched, now expand corresponding CUs that were
3354 vec
= (offset_type
*) (index
->constant_pool
3355 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3356 vec_len
= MAYBE_SWAP (vec
[0]);
3357 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3359 struct dwarf2_per_cu_data
*per_cu
;
3360 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3361 gdb_index_symbol_kind symbol_kind
=
3362 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3363 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3365 /* Don't crash on bad data. */
3366 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3367 + dwarf2_per_objfile
->n_type_units
))
3370 /* Only check the symbol's kind if it has one.
3371 Indices prior to version 7 don't record it. */
3372 if (index
->version
>= 7)
3376 case VARIABLES_DOMAIN
:
3377 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3380 case FUNCTIONS_DOMAIN
:
3381 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3385 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3393 per_cu
= dw2_get_cu (cu_index
);
3394 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3395 dw2_instantiate_symtab (per_cu
);
3400 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3403 static struct symtab
*
3404 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3408 if (BLOCKVECTOR (symtab
) != NULL
3409 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3412 if (symtab
->includes
== NULL
)
3415 for (i
= 0; symtab
->includes
[i
]; ++i
)
3417 struct symtab
*s
= symtab
->includes
[i
];
3419 s
= recursively_find_pc_sect_symtab (s
, pc
);
3427 static struct symtab
*
3428 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3429 struct minimal_symbol
*msymbol
,
3431 struct obj_section
*section
,
3434 struct dwarf2_per_cu_data
*data
;
3435 struct symtab
*result
;
3437 dw2_setup (objfile
);
3439 if (!objfile
->psymtabs_addrmap
)
3442 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3446 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3447 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3448 paddress (get_objfile_arch (objfile
), pc
));
3450 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3451 gdb_assert (result
!= NULL
);
3456 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3457 void *data
, int need_fullname
)
3460 struct cleanup
*cleanup
;
3461 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3462 NULL
, xcalloc
, xfree
);
3464 cleanup
= make_cleanup_htab_delete (visited
);
3465 dw2_setup (objfile
);
3467 dw2_build_type_unit_groups ();
3469 /* We can ignore file names coming from already-expanded CUs. */
3470 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3471 + dwarf2_per_objfile
->n_type_units
); ++i
)
3473 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3475 if (per_cu
->v
.quick
->symtab
)
3477 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3480 *slot
= per_cu
->v
.quick
->file_names
;
3484 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3485 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3488 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3489 struct quick_file_names
*file_data
;
3492 /* We only need to look at symtabs not already expanded. */
3493 if (per_cu
->v
.quick
->symtab
)
3496 file_data
= dw2_get_file_names (objfile
, per_cu
);
3497 if (file_data
== NULL
)
3500 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3503 /* Already visited. */
3508 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3510 const char *this_real_name
;
3513 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3515 this_real_name
= NULL
;
3516 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3520 do_cleanups (cleanup
);
3524 dw2_has_symbols (struct objfile
*objfile
)
3529 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3532 dw2_find_last_source_symtab
,
3533 dw2_forget_cached_source_info
,
3534 dw2_map_symtabs_matching_filename
,
3536 dw2_pre_expand_symtabs_matching
,
3540 dw2_expand_symtabs_for_function
,
3541 dw2_expand_all_symtabs
,
3542 dw2_expand_symtabs_with_filename
,
3543 dw2_find_symbol_file
,
3544 dw2_map_matching_symbols
,
3545 dw2_expand_symtabs_matching
,
3546 dw2_find_pc_sect_symtab
,
3547 dw2_map_symbol_filenames
3550 /* Initialize for reading DWARF for this objfile. Return 0 if this
3551 file will use psymtabs, or 1 if using the GNU index. */
3554 dwarf2_initialize_objfile (struct objfile
*objfile
)
3556 /* If we're about to read full symbols, don't bother with the
3557 indices. In this case we also don't care if some other debug
3558 format is making psymtabs, because they are all about to be
3560 if ((objfile
->flags
& OBJF_READNOW
))
3564 dwarf2_per_objfile
->using_index
= 1;
3565 create_all_comp_units (objfile
);
3566 create_all_type_units (objfile
);
3567 dwarf2_per_objfile
->quick_file_names_table
=
3568 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3570 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3571 + dwarf2_per_objfile
->n_type_units
); ++i
)
3573 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3575 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3576 struct dwarf2_per_cu_quick_data
);
3579 /* Return 1 so that gdb sees the "quick" functions. However,
3580 these functions will be no-ops because we will have expanded
3585 if (dwarf2_read_index (objfile
))
3593 /* Build a partial symbol table. */
3596 dwarf2_build_psymtabs (struct objfile
*objfile
)
3598 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3600 init_psymbol_list (objfile
, 1024);
3603 dwarf2_build_psymtabs_hard (objfile
);
3606 /* Return the total length of the CU described by HEADER. */
3609 get_cu_length (const struct comp_unit_head
*header
)
3611 return header
->initial_length_size
+ header
->length
;
3614 /* Return TRUE if OFFSET is within CU_HEADER. */
3617 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3619 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3620 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3622 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3625 /* Find the base address of the compilation unit for range lists and
3626 location lists. It will normally be specified by DW_AT_low_pc.
3627 In DWARF-3 draft 4, the base address could be overridden by
3628 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3629 compilation units with discontinuous ranges. */
3632 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3634 struct attribute
*attr
;
3637 cu
->base_address
= 0;
3639 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3642 cu
->base_address
= DW_ADDR (attr
);
3647 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3650 cu
->base_address
= DW_ADDR (attr
);
3656 /* Read in the comp unit header information from the debug_info at info_ptr.
3657 NOTE: This leaves members offset, first_die_offset to be filled in
3661 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3662 gdb_byte
*info_ptr
, bfd
*abfd
)
3665 unsigned int bytes_read
;
3667 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3668 cu_header
->initial_length_size
= bytes_read
;
3669 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3670 info_ptr
+= bytes_read
;
3671 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3673 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3675 info_ptr
+= bytes_read
;
3676 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3678 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3679 if (signed_addr
< 0)
3680 internal_error (__FILE__
, __LINE__
,
3681 _("read_comp_unit_head: dwarf from non elf file"));
3682 cu_header
->signed_addr_p
= signed_addr
;
3687 /* Subroutine of read_and_check_comp_unit_head and
3688 read_and_check_type_unit_head to simplify them.
3689 Perform various error checking on the header. */
3692 error_check_comp_unit_head (struct comp_unit_head
*header
,
3693 struct dwarf2_section_info
*section
,
3694 struct dwarf2_section_info
*abbrev_section
)
3696 bfd
*abfd
= section
->asection
->owner
;
3697 const char *filename
= bfd_get_filename (abfd
);
3699 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3700 error (_("Dwarf Error: wrong version in compilation unit header "
3701 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3704 if (header
->abbrev_offset
.sect_off
3705 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3706 &dwarf2_per_objfile
->abbrev
))
3707 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3708 "(offset 0x%lx + 6) [in module %s]"),
3709 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3712 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3713 avoid potential 32-bit overflow. */
3714 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3716 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3717 "(offset 0x%lx + 0) [in module %s]"),
3718 (long) header
->length
, (long) header
->offset
.sect_off
,
3722 /* Read in a CU/TU header and perform some basic error checking.
3723 The contents of the header are stored in HEADER.
3724 The result is a pointer to the start of the first DIE. */
3727 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3728 struct dwarf2_section_info
*section
,
3729 struct dwarf2_section_info
*abbrev_section
,
3731 int is_debug_types_section
)
3733 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3734 bfd
*abfd
= section
->asection
->owner
;
3736 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3738 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3740 /* If we're reading a type unit, skip over the signature and
3741 type_offset fields. */
3742 if (is_debug_types_section
)
3743 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3745 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3747 error_check_comp_unit_head (header
, section
, abbrev_section
);
3752 /* Read in the types comp unit header information from .debug_types entry at
3753 types_ptr. The result is a pointer to one past the end of the header. */
3756 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3757 struct dwarf2_section_info
*section
,
3758 struct dwarf2_section_info
*abbrev_section
,
3760 ULONGEST
*signature
,
3761 cu_offset
*type_offset_in_tu
)
3763 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3764 bfd
*abfd
= section
->asection
->owner
;
3766 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3768 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3770 /* If we're reading a type unit, skip over the signature and
3771 type_offset fields. */
3772 if (signature
!= NULL
)
3773 *signature
= read_8_bytes (abfd
, info_ptr
);
3775 if (type_offset_in_tu
!= NULL
)
3776 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3777 header
->offset_size
);
3778 info_ptr
+= header
->offset_size
;
3780 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3782 error_check_comp_unit_head (header
, section
, abbrev_section
);
3787 /* Fetch the abbreviation table offset from a comp or type unit header. */
3790 read_abbrev_offset (struct dwarf2_section_info
*section
,
3793 bfd
*abfd
= section
->asection
->owner
;
3795 unsigned int length
, initial_length_size
, offset_size
;
3796 sect_offset abbrev_offset
;
3798 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3799 info_ptr
= section
->buffer
+ offset
.sect_off
;
3800 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3801 offset_size
= initial_length_size
== 4 ? 4 : 8;
3802 info_ptr
+= initial_length_size
+ 2 /*version*/;
3803 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
3804 return abbrev_offset
;
3807 /* Allocate a new partial symtab for file named NAME and mark this new
3808 partial symtab as being an include of PST. */
3811 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3812 struct objfile
*objfile
)
3814 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3816 subpst
->section_offsets
= pst
->section_offsets
;
3817 subpst
->textlow
= 0;
3818 subpst
->texthigh
= 0;
3820 subpst
->dependencies
= (struct partial_symtab
**)
3821 obstack_alloc (&objfile
->objfile_obstack
,
3822 sizeof (struct partial_symtab
*));
3823 subpst
->dependencies
[0] = pst
;
3824 subpst
->number_of_dependencies
= 1;
3826 subpst
->globals_offset
= 0;
3827 subpst
->n_global_syms
= 0;
3828 subpst
->statics_offset
= 0;
3829 subpst
->n_static_syms
= 0;
3830 subpst
->symtab
= NULL
;
3831 subpst
->read_symtab
= pst
->read_symtab
;
3834 /* No private part is necessary for include psymtabs. This property
3835 can be used to differentiate between such include psymtabs and
3836 the regular ones. */
3837 subpst
->read_symtab_private
= NULL
;
3840 /* Read the Line Number Program data and extract the list of files
3841 included by the source file represented by PST. Build an include
3842 partial symtab for each of these included files. */
3845 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3846 struct die_info
*die
,
3847 struct partial_symtab
*pst
)
3849 struct line_header
*lh
= NULL
;
3850 struct attribute
*attr
;
3852 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3854 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3856 return; /* No linetable, so no includes. */
3858 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3859 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3861 free_line_header (lh
);
3865 hash_signatured_type (const void *item
)
3867 const struct signatured_type
*sig_type
= item
;
3869 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3870 return sig_type
->signature
;
3874 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3876 const struct signatured_type
*lhs
= item_lhs
;
3877 const struct signatured_type
*rhs
= item_rhs
;
3879 return lhs
->signature
== rhs
->signature
;
3882 /* Allocate a hash table for signatured types. */
3885 allocate_signatured_type_table (struct objfile
*objfile
)
3887 return htab_create_alloc_ex (41,
3888 hash_signatured_type
,
3891 &objfile
->objfile_obstack
,
3892 hashtab_obstack_allocate
,
3893 dummy_obstack_deallocate
);
3896 /* A helper function to add a signatured type CU to a table. */
3899 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3901 struct signatured_type
*sigt
= *slot
;
3902 struct signatured_type
***datap
= datum
;
3910 /* Create the hash table of all entries in the .debug_types section.
3911 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3912 The result is a pointer to the hash table or NULL if there are
3916 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3917 VEC (dwarf2_section_info_def
) *types
)
3919 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3920 htab_t types_htab
= NULL
;
3922 struct dwarf2_section_info
*section
;
3923 struct dwarf2_section_info
*abbrev_section
;
3925 if (VEC_empty (dwarf2_section_info_def
, types
))
3928 abbrev_section
= (dwo_file
!= NULL
3929 ? &dwo_file
->sections
.abbrev
3930 : &dwarf2_per_objfile
->abbrev
);
3932 if (dwarf2_read_debug
)
3933 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
3934 dwo_file
? ".dwo" : "",
3935 bfd_get_filename (abbrev_section
->asection
->owner
));
3938 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3942 gdb_byte
*info_ptr
, *end_ptr
;
3944 dwarf2_read_section (objfile
, section
);
3945 info_ptr
= section
->buffer
;
3947 if (info_ptr
== NULL
)
3950 /* We can't set abfd until now because the section may be empty or
3951 not present, in which case section->asection will be NULL. */
3952 abfd
= section
->asection
->owner
;
3954 if (types_htab
== NULL
)
3957 types_htab
= allocate_dwo_unit_table (objfile
);
3959 types_htab
= allocate_signatured_type_table (objfile
);
3962 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3963 because we don't need to read any dies: the signature is in the
3966 end_ptr
= info_ptr
+ section
->size
;
3967 while (info_ptr
< end_ptr
)
3970 cu_offset type_offset_in_tu
;
3972 struct signatured_type
*sig_type
;
3973 struct dwo_unit
*dwo_tu
;
3975 gdb_byte
*ptr
= info_ptr
;
3976 struct comp_unit_head header
;
3977 unsigned int length
;
3979 offset
.sect_off
= ptr
- section
->buffer
;
3981 /* We need to read the type's signature in order to build the hash
3982 table, but we don't need anything else just yet. */
3984 ptr
= read_and_check_type_unit_head (&header
, section
,
3985 abbrev_section
, ptr
,
3986 &signature
, &type_offset_in_tu
);
3988 length
= get_cu_length (&header
);
3990 /* Skip dummy type units. */
3991 if (ptr
>= info_ptr
+ length
3992 || peek_abbrev_code (abfd
, ptr
) == 0)
4001 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4003 dwo_tu
->dwo_file
= dwo_file
;
4004 dwo_tu
->signature
= signature
;
4005 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4006 dwo_tu
->info_or_types_section
= section
;
4007 dwo_tu
->offset
= offset
;
4008 dwo_tu
->length
= length
;
4012 /* N.B.: type_offset is not usable if this type uses a DWO file.
4013 The real type_offset is in the DWO file. */
4015 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4016 struct signatured_type
);
4017 sig_type
->signature
= signature
;
4018 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4019 sig_type
->per_cu
.objfile
= objfile
;
4020 sig_type
->per_cu
.is_debug_types
= 1;
4021 sig_type
->per_cu
.info_or_types_section
= section
;
4022 sig_type
->per_cu
.offset
= offset
;
4023 sig_type
->per_cu
.length
= length
;
4026 slot
= htab_find_slot (types_htab
,
4027 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4029 gdb_assert (slot
!= NULL
);
4032 sect_offset dup_offset
;
4036 const struct dwo_unit
*dup_tu
= *slot
;
4038 dup_offset
= dup_tu
->offset
;
4042 const struct signatured_type
*dup_tu
= *slot
;
4044 dup_offset
= dup_tu
->per_cu
.offset
;
4047 complaint (&symfile_complaints
,
4048 _("debug type entry at offset 0x%x is duplicate to the "
4049 "entry at offset 0x%x, signature 0x%s"),
4050 offset
.sect_off
, dup_offset
.sect_off
,
4051 phex (signature
, sizeof (signature
)));
4053 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4055 if (dwarf2_read_debug
)
4056 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4058 phex (signature
, sizeof (signature
)));
4067 /* Create the hash table of all entries in the .debug_types section,
4068 and initialize all_type_units.
4069 The result is zero if there is an error (e.g. missing .debug_types section),
4070 otherwise non-zero. */
4073 create_all_type_units (struct objfile
*objfile
)
4076 struct signatured_type
**iter
;
4078 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4079 if (types_htab
== NULL
)
4081 dwarf2_per_objfile
->signatured_types
= NULL
;
4085 dwarf2_per_objfile
->signatured_types
= types_htab
;
4087 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4088 dwarf2_per_objfile
->all_type_units
4089 = obstack_alloc (&objfile
->objfile_obstack
,
4090 dwarf2_per_objfile
->n_type_units
4091 * sizeof (struct signatured_type
*));
4092 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4093 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4094 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4095 == dwarf2_per_objfile
->n_type_units
);
4100 /* Lookup a signature based type for DW_FORM_ref_sig8.
4101 Returns NULL if signature SIG is not present in the table. */
4103 static struct signatured_type
*
4104 lookup_signatured_type (ULONGEST sig
)
4106 struct signatured_type find_entry
, *entry
;
4108 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4110 complaint (&symfile_complaints
,
4111 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4115 find_entry
.signature
= sig
;
4116 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4120 /* Low level DIE reading support. */
4122 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4125 init_cu_die_reader (struct die_reader_specs
*reader
,
4126 struct dwarf2_cu
*cu
,
4127 struct dwarf2_section_info
*section
,
4128 struct dwo_file
*dwo_file
)
4130 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4131 reader
->abfd
= section
->asection
->owner
;
4133 reader
->dwo_file
= dwo_file
;
4134 reader
->die_section
= section
;
4135 reader
->buffer
= section
->buffer
;
4136 reader
->buffer_end
= section
->buffer
+ section
->size
;
4139 /* Initialize a CU (or TU) and read its DIEs.
4140 If the CU defers to a DWO file, read the DWO file as well.
4142 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4143 Otherwise the table specified in the comp unit header is read in and used.
4144 This is an optimization for when we already have the abbrev table.
4146 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4147 Otherwise, a new CU is allocated with xmalloc.
4149 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4150 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4152 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4153 linker) then DIE_READER_FUNC will not get called. */
4156 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4157 struct abbrev_table
*abbrev_table
,
4158 int use_existing_cu
, int keep
,
4159 die_reader_func_ftype
*die_reader_func
,
4162 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4163 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4164 bfd
*abfd
= section
->asection
->owner
;
4165 struct dwarf2_cu
*cu
;
4166 gdb_byte
*begin_info_ptr
, *info_ptr
;
4167 struct die_reader_specs reader
;
4168 struct die_info
*comp_unit_die
;
4170 struct attribute
*attr
;
4171 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4172 struct signatured_type
*sig_type
= NULL
;
4173 struct dwarf2_section_info
*abbrev_section
;
4174 /* Non-zero if CU currently points to a DWO file and we need to
4175 reread it. When this happens we need to reread the skeleton die
4176 before we can reread the DWO file. */
4177 int rereading_dwo_cu
= 0;
4179 if (dwarf2_die_debug
)
4180 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4181 this_cu
->is_debug_types
? "type" : "comp",
4182 this_cu
->offset
.sect_off
);
4184 if (use_existing_cu
)
4187 cleanups
= make_cleanup (null_cleanup
, NULL
);
4189 /* This is cheap if the section is already read in. */
4190 dwarf2_read_section (objfile
, section
);
4192 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4193 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4195 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4199 /* If this CU is from a DWO file we need to start over, we need to
4200 refetch the attributes from the skeleton CU.
4201 This could be optimized by retrieving those attributes from when we
4202 were here the first time: the previous comp_unit_die was stored in
4203 comp_unit_obstack. But there's no data yet that we need this
4205 if (cu
->dwo_unit
!= NULL
)
4206 rereading_dwo_cu
= 1;
4210 /* If !use_existing_cu, this_cu->cu must be NULL. */
4211 gdb_assert (this_cu
->cu
== NULL
);
4213 cu
= xmalloc (sizeof (*cu
));
4214 init_one_comp_unit (cu
, this_cu
);
4216 /* If an error occurs while loading, release our storage. */
4217 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4220 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4222 /* We already have the header, there's no need to read it in again. */
4223 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4227 if (this_cu
->is_debug_types
)
4230 cu_offset type_offset_in_tu
;
4232 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4233 abbrev_section
, info_ptr
,
4235 &type_offset_in_tu
);
4237 /* Since per_cu is the first member of struct signatured_type,
4238 we can go from a pointer to one to a pointer to the other. */
4239 sig_type
= (struct signatured_type
*) this_cu
;
4240 gdb_assert (sig_type
->signature
== signature
);
4241 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4242 == type_offset_in_tu
.cu_off
);
4243 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4245 /* LENGTH has not been set yet for type units if we're
4246 using .gdb_index. */
4247 this_cu
->length
= get_cu_length (&cu
->header
);
4249 /* Establish the type offset that can be used to lookup the type. */
4250 sig_type
->type_offset_in_section
.sect_off
=
4251 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4255 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4259 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4260 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4264 /* Skip dummy compilation units. */
4265 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4266 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4268 do_cleanups (cleanups
);
4272 /* If we don't have them yet, read the abbrevs for this compilation unit.
4273 And if we need to read them now, make sure they're freed when we're
4274 done. Note that it's important that if the CU had an abbrev table
4275 on entry we don't free it when we're done: Somewhere up the call stack
4276 it may be in use. */
4277 if (abbrev_table
!= NULL
)
4279 gdb_assert (cu
->abbrev_table
== NULL
);
4280 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4281 == abbrev_table
->offset
.sect_off
);
4282 cu
->abbrev_table
= abbrev_table
;
4284 else if (cu
->abbrev_table
== NULL
)
4286 dwarf2_read_abbrevs (cu
, abbrev_section
);
4287 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4289 else if (rereading_dwo_cu
)
4291 dwarf2_free_abbrev_table (cu
);
4292 dwarf2_read_abbrevs (cu
, abbrev_section
);
4295 /* Read the top level CU/TU die. */
4296 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4297 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4299 /* If we have a DWO stub, process it and then read in the DWO file.
4300 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4301 a DWO CU, that this test will fail. */
4302 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4305 char *dwo_name
= DW_STRING (attr
);
4306 const char *comp_dir_string
;
4307 struct dwo_unit
*dwo_unit
;
4308 ULONGEST signature
; /* Or dwo_id. */
4309 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4310 int i
,num_extra_attrs
;
4311 struct dwarf2_section_info
*dwo_abbrev_section
;
4314 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4315 " has children (offset 0x%x) [in module %s]"),
4316 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4318 /* These attributes aren't processed until later:
4319 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4320 However, the attribute is found in the stub which we won't have later.
4321 In order to not impose this complication on the rest of the code,
4322 we read them here and copy them to the DWO CU/TU die. */
4324 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4327 if (! this_cu
->is_debug_types
)
4328 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4329 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4330 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4331 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4332 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4334 /* There should be a DW_AT_addr_base attribute here (if needed).
4335 We need the value before we can process DW_FORM_GNU_addr_index. */
4337 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4339 cu
->addr_base
= DW_UNSND (attr
);
4341 /* There should be a DW_AT_ranges_base attribute here (if needed).
4342 We need the value before we can process DW_AT_ranges. */
4343 cu
->ranges_base
= 0;
4344 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4346 cu
->ranges_base
= DW_UNSND (attr
);
4348 if (this_cu
->is_debug_types
)
4350 gdb_assert (sig_type
!= NULL
);
4351 signature
= sig_type
->signature
;
4355 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4357 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4359 signature
= DW_UNSND (attr
);
4362 /* We may need the comp_dir in order to find the DWO file. */
4363 comp_dir_string
= NULL
;
4365 comp_dir_string
= DW_STRING (comp_dir
);
4367 if (this_cu
->is_debug_types
)
4368 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4370 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4373 if (dwo_unit
== NULL
)
4375 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4376 " with ID %s [in module %s]"),
4377 this_cu
->offset
.sect_off
,
4378 phex (signature
, sizeof (signature
)),
4382 /* Set up for reading the DWO CU/TU. */
4383 cu
->dwo_unit
= dwo_unit
;
4384 section
= dwo_unit
->info_or_types_section
;
4385 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4386 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4387 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4389 if (this_cu
->is_debug_types
)
4393 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4397 gdb_assert (sig_type
->signature
== signature
);
4398 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4399 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4401 /* Establish the type offset that can be used to lookup the type.
4402 For DWO files, we don't know it until now. */
4403 sig_type
->type_offset_in_section
.sect_off
=
4404 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4408 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4411 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4412 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4415 /* Discard the original CU's abbrev table, and read the DWO's. */
4416 if (abbrev_table
== NULL
)
4418 dwarf2_free_abbrev_table (cu
);
4419 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4423 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4424 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4427 /* Read in the die, but leave space to copy over the attributes
4428 from the stub. This has the benefit of simplifying the rest of
4429 the code - all the real work is done here. */
4430 num_extra_attrs
= ((stmt_list
!= NULL
)
4434 + (comp_dir
!= NULL
));
4435 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4436 &has_children
, num_extra_attrs
);
4438 /* Copy over the attributes from the stub to the DWO die. */
4439 i
= comp_unit_die
->num_attrs
;
4440 if (stmt_list
!= NULL
)
4441 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4443 comp_unit_die
->attrs
[i
++] = *low_pc
;
4444 if (high_pc
!= NULL
)
4445 comp_unit_die
->attrs
[i
++] = *high_pc
;
4447 comp_unit_die
->attrs
[i
++] = *ranges
;
4448 if (comp_dir
!= NULL
)
4449 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4450 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4452 /* Skip dummy compilation units. */
4453 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4454 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4456 do_cleanups (cleanups
);
4461 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4463 if (free_cu_cleanup
!= NULL
)
4467 /* We've successfully allocated this compilation unit. Let our
4468 caller clean it up when finished with it. */
4469 discard_cleanups (free_cu_cleanup
);
4471 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4472 So we have to manually free the abbrev table. */
4473 dwarf2_free_abbrev_table (cu
);
4475 /* Link this CU into read_in_chain. */
4476 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4477 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4480 do_cleanups (free_cu_cleanup
);
4483 do_cleanups (cleanups
);
4486 /* Read CU/TU THIS_CU in section SECTION,
4487 but do not follow DW_AT_GNU_dwo_name if present.
4488 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4489 have already done the lookup to find the DWO file).
4491 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4492 THIS_CU->is_debug_types, but nothing else.
4494 We fill in THIS_CU->length.
4496 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4497 linker) then DIE_READER_FUNC will not get called.
4499 THIS_CU->cu is always freed when done.
4500 This is done in order to not leave THIS_CU->cu in a state where we have
4501 to care whether it refers to the "main" CU or the DWO CU. */
4504 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4505 struct dwarf2_section_info
*abbrev_section
,
4506 struct dwo_file
*dwo_file
,
4507 die_reader_func_ftype
*die_reader_func
,
4510 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4511 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4512 bfd
*abfd
= section
->asection
->owner
;
4513 struct dwarf2_cu cu
;
4514 gdb_byte
*begin_info_ptr
, *info_ptr
;
4515 struct die_reader_specs reader
;
4516 struct cleanup
*cleanups
;
4517 struct die_info
*comp_unit_die
;
4520 if (dwarf2_die_debug
)
4521 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4522 this_cu
->is_debug_types
? "type" : "comp",
4523 this_cu
->offset
.sect_off
);
4525 gdb_assert (this_cu
->cu
== NULL
);
4527 /* This is cheap if the section is already read in. */
4528 dwarf2_read_section (objfile
, section
);
4530 init_one_comp_unit (&cu
, this_cu
);
4532 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4534 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4535 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4536 abbrev_section
, info_ptr
,
4537 this_cu
->is_debug_types
);
4539 this_cu
->length
= get_cu_length (&cu
.header
);
4541 /* Skip dummy compilation units. */
4542 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4543 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4545 do_cleanups (cleanups
);
4549 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4550 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4552 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4553 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4555 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4557 do_cleanups (cleanups
);
4560 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4561 does not lookup the specified DWO file.
4562 This cannot be used to read DWO files.
4564 THIS_CU->cu is always freed when done.
4565 This is done in order to not leave THIS_CU->cu in a state where we have
4566 to care whether it refers to the "main" CU or the DWO CU.
4567 We can revisit this if the data shows there's a performance issue. */
4570 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4571 die_reader_func_ftype
*die_reader_func
,
4574 init_cutu_and_read_dies_no_follow (this_cu
,
4575 &dwarf2_per_objfile
->abbrev
,
4577 die_reader_func
, data
);
4580 /* Create a psymtab named NAME and assign it to PER_CU.
4582 The caller must fill in the following details:
4583 dirname, textlow, texthigh. */
4585 static struct partial_symtab
*
4586 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4588 struct objfile
*objfile
= per_cu
->objfile
;
4589 struct partial_symtab
*pst
;
4591 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4593 objfile
->global_psymbols
.next
,
4594 objfile
->static_psymbols
.next
);
4596 pst
->psymtabs_addrmap_supported
= 1;
4598 /* This is the glue that links PST into GDB's symbol API. */
4599 pst
->read_symtab_private
= per_cu
;
4600 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4601 per_cu
->v
.psymtab
= pst
;
4606 /* die_reader_func for process_psymtab_comp_unit. */
4609 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4611 struct die_info
*comp_unit_die
,
4615 struct dwarf2_cu
*cu
= reader
->cu
;
4616 struct objfile
*objfile
= cu
->objfile
;
4617 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4618 struct attribute
*attr
;
4620 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4621 struct partial_symtab
*pst
;
4623 const char *filename
;
4624 int *want_partial_unit_ptr
= data
;
4626 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4627 && (want_partial_unit_ptr
== NULL
4628 || !*want_partial_unit_ptr
))
4631 gdb_assert (! per_cu
->is_debug_types
);
4633 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4635 cu
->list_in_scope
= &file_symbols
;
4637 /* Allocate a new partial symbol table structure. */
4638 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4639 if (attr
== NULL
|| !DW_STRING (attr
))
4642 filename
= DW_STRING (attr
);
4644 pst
= create_partial_symtab (per_cu
, filename
);
4646 /* This must be done before calling dwarf2_build_include_psymtabs. */
4647 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4649 pst
->dirname
= DW_STRING (attr
);
4651 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4653 dwarf2_find_base_address (comp_unit_die
, cu
);
4655 /* Possibly set the default values of LOWPC and HIGHPC from
4657 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4658 &best_highpc
, cu
, pst
);
4659 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4660 /* Store the contiguous range if it is not empty; it can be empty for
4661 CUs with no code. */
4662 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4663 best_lowpc
+ baseaddr
,
4664 best_highpc
+ baseaddr
- 1, pst
);
4666 /* Check if comp unit has_children.
4667 If so, read the rest of the partial symbols from this comp unit.
4668 If not, there's no more debug_info for this comp unit. */
4671 struct partial_die_info
*first_die
;
4672 CORE_ADDR lowpc
, highpc
;
4674 lowpc
= ((CORE_ADDR
) -1);
4675 highpc
= ((CORE_ADDR
) 0);
4677 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4679 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4682 /* If we didn't find a lowpc, set it to highpc to avoid
4683 complaints from `maint check'. */
4684 if (lowpc
== ((CORE_ADDR
) -1))
4687 /* If the compilation unit didn't have an explicit address range,
4688 then use the information extracted from its child dies. */
4692 best_highpc
= highpc
;
4695 pst
->textlow
= best_lowpc
+ baseaddr
;
4696 pst
->texthigh
= best_highpc
+ baseaddr
;
4698 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4699 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4700 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4701 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4702 sort_pst_symbols (pst
);
4704 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4707 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4708 struct dwarf2_per_cu_data
*iter
;
4710 /* Fill in 'dependencies' here; we fill in 'users' in a
4712 pst
->number_of_dependencies
= len
;
4713 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4714 len
* sizeof (struct symtab
*));
4716 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4719 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4721 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4724 /* Get the list of files included in the current compilation unit,
4725 and build a psymtab for each of them. */
4726 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4728 if (dwarf2_read_debug
)
4730 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4732 fprintf_unfiltered (gdb_stdlog
,
4733 "Psymtab for %s unit @0x%x: 0x%s - 0x%s"
4734 ", %d global, %d static syms\n",
4735 per_cu
->is_debug_types
? "type" : "comp",
4736 per_cu
->offset
.sect_off
,
4737 paddress (gdbarch
, pst
->textlow
),
4738 paddress (gdbarch
, pst
->texthigh
),
4739 pst
->n_global_syms
, pst
->n_static_syms
);
4743 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4744 Process compilation unit THIS_CU for a psymtab. */
4747 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4748 int want_partial_unit
)
4750 /* If this compilation unit was already read in, free the
4751 cached copy in order to read it in again. This is
4752 necessary because we skipped some symbols when we first
4753 read in the compilation unit (see load_partial_dies).
4754 This problem could be avoided, but the benefit is unclear. */
4755 if (this_cu
->cu
!= NULL
)
4756 free_one_cached_comp_unit (this_cu
);
4758 gdb_assert (! this_cu
->is_debug_types
);
4759 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4760 process_psymtab_comp_unit_reader
,
4761 &want_partial_unit
);
4763 /* Age out any secondary CUs. */
4764 age_cached_comp_units ();
4768 hash_type_unit_group (const void *item
)
4770 const struct type_unit_group
*tu_group
= item
;
4772 return hash_stmt_list_entry (&tu_group
->hash
);
4776 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4778 const struct type_unit_group
*lhs
= item_lhs
;
4779 const struct type_unit_group
*rhs
= item_rhs
;
4781 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
4784 /* Allocate a hash table for type unit groups. */
4787 allocate_type_unit_groups_table (void)
4789 return htab_create_alloc_ex (3,
4790 hash_type_unit_group
,
4793 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
4794 hashtab_obstack_allocate
,
4795 dummy_obstack_deallocate
);
4798 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4799 partial symtabs. We combine several TUs per psymtab to not let the size
4800 of any one psymtab grow too big. */
4801 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4802 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4804 /* Helper routine for get_type_unit_group.
4805 Create the type_unit_group object used to hold one or more TUs. */
4807 static struct type_unit_group
*
4808 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
4810 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4811 struct dwarf2_per_cu_data
*per_cu
;
4812 struct type_unit_group
*tu_group
;
4814 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4815 struct type_unit_group
);
4816 per_cu
= &tu_group
->per_cu
;
4817 per_cu
->objfile
= objfile
;
4818 per_cu
->is_debug_types
= 1;
4819 per_cu
->s
.type_unit_group
= tu_group
;
4821 if (dwarf2_per_objfile
->using_index
)
4823 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4824 struct dwarf2_per_cu_quick_data
);
4825 tu_group
->t
.first_tu
= cu
->per_cu
;
4829 unsigned int line_offset
= line_offset_struct
.sect_off
;
4830 struct partial_symtab
*pst
;
4833 /* Give the symtab a useful name for debug purposes. */
4834 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
4835 name
= xstrprintf ("<type_units_%d>",
4836 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
4838 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
4840 pst
= create_partial_symtab (per_cu
, name
);
4846 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
4847 tu_group
->hash
.line_offset
= line_offset_struct
;
4852 /* Look up the type_unit_group for type unit CU, and create it if necessary.
4853 STMT_LIST is a DW_AT_stmt_list attribute. */
4855 static struct type_unit_group
*
4856 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
4858 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4859 struct type_unit_group
*tu_group
;
4861 unsigned int line_offset
;
4862 struct type_unit_group type_unit_group_for_lookup
;
4864 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
4866 dwarf2_per_objfile
->type_unit_groups
=
4867 allocate_type_unit_groups_table ();
4870 /* Do we need to create a new group, or can we use an existing one? */
4874 line_offset
= DW_UNSND (stmt_list
);
4875 ++tu_stats
->nr_symtab_sharers
;
4879 /* Ugh, no stmt_list. Rare, but we have to handle it.
4880 We can do various things here like create one group per TU or
4881 spread them over multiple groups to split up the expansion work.
4882 To avoid worst case scenarios (too many groups or too large groups)
4883 we, umm, group them in bunches. */
4884 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
4885 | (tu_stats
->nr_stmt_less_type_units
4886 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
4887 ++tu_stats
->nr_stmt_less_type_units
;
4890 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
4891 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
4892 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
4893 &type_unit_group_for_lookup
, INSERT
);
4897 gdb_assert (tu_group
!= NULL
);
4901 sect_offset line_offset_struct
;
4903 line_offset_struct
.sect_off
= line_offset
;
4904 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
4906 ++tu_stats
->nr_symtabs
;
4912 /* Struct used to sort TUs by their abbreviation table offset. */
4914 struct tu_abbrev_offset
4916 struct signatured_type
*sig_type
;
4917 sect_offset abbrev_offset
;
4920 /* Helper routine for build_type_unit_groups, passed to qsort. */
4923 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
4925 const struct tu_abbrev_offset
* const *a
= ap
;
4926 const struct tu_abbrev_offset
* const *b
= bp
;
4927 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
4928 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
4930 return (aoff
> boff
) - (aoff
< boff
);
4933 /* A helper function to add a type_unit_group to a table. */
4936 add_type_unit_group_to_table (void **slot
, void *datum
)
4938 struct type_unit_group
*tu_group
= *slot
;
4939 struct type_unit_group
***datap
= datum
;
4947 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
4948 each one passing FUNC,DATA.
4950 The efficiency is because we sort TUs by the abbrev table they use and
4951 only read each abbrev table once. In one program there are 200K TUs
4952 sharing 8K abbrev tables.
4954 The main purpose of this function is to support building the
4955 dwarf2_per_objfile->type_unit_groups table.
4956 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
4957 can collapse the search space by grouping them by stmt_list.
4958 The savings can be significant, in the same program from above the 200K TUs
4959 share 8K stmt_list tables.
4961 FUNC is expected to call get_type_unit_group, which will create the
4962 struct type_unit_group if necessary and add it to
4963 dwarf2_per_objfile->type_unit_groups. */
4966 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
4968 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4969 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4970 struct cleanup
*cleanups
;
4971 struct abbrev_table
*abbrev_table
;
4972 sect_offset abbrev_offset
;
4973 struct tu_abbrev_offset
*sorted_by_abbrev
;
4974 struct type_unit_group
**iter
;
4977 /* It's up to the caller to not call us multiple times. */
4978 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
4980 if (dwarf2_per_objfile
->n_type_units
== 0)
4983 /* TUs typically share abbrev tables, and there can be way more TUs than
4984 abbrev tables. Sort by abbrev table to reduce the number of times we
4985 read each abbrev table in.
4986 Alternatives are to punt or to maintain a cache of abbrev tables.
4987 This is simpler and efficient enough for now.
4989 Later we group TUs by their DW_AT_stmt_list value (as this defines the
4990 symtab to use). Typically TUs with the same abbrev offset have the same
4991 stmt_list value too so in practice this should work well.
4993 The basic algorithm here is:
4995 sort TUs by abbrev table
4996 for each TU with same abbrev table:
4997 read abbrev table if first user
4998 read TU top level DIE
4999 [IWBN if DWO skeletons had DW_AT_stmt_list]
5002 if (dwarf2_read_debug
)
5003 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5005 /* Sort in a separate table to maintain the order of all_type_units
5006 for .gdb_index: TU indices directly index all_type_units. */
5007 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5008 dwarf2_per_objfile
->n_type_units
);
5009 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5011 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5013 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5014 sorted_by_abbrev
[i
].abbrev_offset
=
5015 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5016 sig_type
->per_cu
.offset
);
5018 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5019 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5020 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5022 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5023 called any number of times, so we don't reset tu_stats here. */
5025 abbrev_offset
.sect_off
= ~(unsigned) 0;
5026 abbrev_table
= NULL
;
5027 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5029 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5031 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5033 /* Switch to the next abbrev table if necessary. */
5034 if (abbrev_table
== NULL
5035 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5037 if (abbrev_table
!= NULL
)
5039 abbrev_table_free (abbrev_table
);
5040 /* Reset to NULL in case abbrev_table_read_table throws
5041 an error: abbrev_table_free_cleanup will get called. */
5042 abbrev_table
= NULL
;
5044 abbrev_offset
= tu
->abbrev_offset
;
5046 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5048 ++tu_stats
->nr_uniq_abbrev_tables
;
5051 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5055 /* Create a vector of pointers to primary type units to make it easy to
5056 iterate over them and CUs. See dw2_get_primary_cu. */
5057 dwarf2_per_objfile
->n_type_unit_groups
=
5058 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5059 dwarf2_per_objfile
->all_type_unit_groups
=
5060 obstack_alloc (&objfile
->objfile_obstack
,
5061 dwarf2_per_objfile
->n_type_unit_groups
5062 * sizeof (struct type_unit_group
*));
5063 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5064 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5065 add_type_unit_group_to_table
, &iter
);
5066 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5067 == dwarf2_per_objfile
->n_type_unit_groups
);
5069 do_cleanups (cleanups
);
5071 if (dwarf2_read_debug
)
5073 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5074 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5075 dwarf2_per_objfile
->n_type_units
);
5076 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5077 tu_stats
->nr_uniq_abbrev_tables
);
5078 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5079 tu_stats
->nr_symtabs
);
5080 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5081 tu_stats
->nr_symtab_sharers
);
5082 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5083 tu_stats
->nr_stmt_less_type_units
);
5087 /* Reader function for build_type_psymtabs. */
5090 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5092 struct die_info
*type_unit_die
,
5096 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5097 struct dwarf2_cu
*cu
= reader
->cu
;
5098 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5099 struct type_unit_group
*tu_group
;
5100 struct attribute
*attr
;
5101 struct partial_die_info
*first_die
;
5102 CORE_ADDR lowpc
, highpc
;
5103 struct partial_symtab
*pst
;
5105 gdb_assert (data
== NULL
);
5110 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5111 tu_group
= get_type_unit_group (cu
, attr
);
5113 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5115 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5116 cu
->list_in_scope
= &file_symbols
;
5117 pst
= create_partial_symtab (per_cu
, "");
5120 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5122 lowpc
= (CORE_ADDR
) -1;
5123 highpc
= (CORE_ADDR
) 0;
5124 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5126 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5127 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5128 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5129 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5130 sort_pst_symbols (pst
);
5133 /* Traversal function for build_type_psymtabs. */
5136 build_type_psymtab_dependencies (void **slot
, void *info
)
5138 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5139 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5140 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5141 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5142 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5143 struct dwarf2_per_cu_data
*iter
;
5146 gdb_assert (len
> 0);
5148 pst
->number_of_dependencies
= len
;
5149 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5150 len
* sizeof (struct psymtab
*));
5152 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5155 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5156 iter
->s
.type_unit_group
= tu_group
;
5159 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5164 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5165 Build partial symbol tables for the .debug_types comp-units. */
5168 build_type_psymtabs (struct objfile
*objfile
)
5170 if (! create_all_type_units (objfile
))
5173 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5175 /* Now that all TUs have been processed we can fill in the dependencies. */
5176 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5177 build_type_psymtab_dependencies
, NULL
);
5180 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5183 psymtabs_addrmap_cleanup (void *o
)
5185 struct objfile
*objfile
= o
;
5187 objfile
->psymtabs_addrmap
= NULL
;
5190 /* Compute the 'user' field for each psymtab in OBJFILE. */
5193 set_partial_user (struct objfile
*objfile
)
5197 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5199 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5200 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5203 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5205 /* Set the 'user' field only if it is not already set. */
5206 if (pst
->dependencies
[j
]->user
== NULL
)
5207 pst
->dependencies
[j
]->user
= pst
;
5212 /* Build the partial symbol table by doing a quick pass through the
5213 .debug_info and .debug_abbrev sections. */
5216 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5218 struct cleanup
*back_to
, *addrmap_cleanup
;
5219 struct obstack temp_obstack
;
5222 if (dwarf2_read_debug
)
5224 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5228 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5230 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5232 /* Any cached compilation units will be linked by the per-objfile
5233 read_in_chain. Make sure to free them when we're done. */
5234 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5236 build_type_psymtabs (objfile
);
5238 create_all_comp_units (objfile
);
5240 /* Create a temporary address map on a temporary obstack. We later
5241 copy this to the final obstack. */
5242 obstack_init (&temp_obstack
);
5243 make_cleanup_obstack_free (&temp_obstack
);
5244 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5245 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5247 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5249 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5251 process_psymtab_comp_unit (per_cu
, 0);
5254 set_partial_user (objfile
);
5256 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5257 &objfile
->objfile_obstack
);
5258 discard_cleanups (addrmap_cleanup
);
5260 do_cleanups (back_to
);
5262 if (dwarf2_read_debug
)
5263 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5267 /* die_reader_func for load_partial_comp_unit. */
5270 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5272 struct die_info
*comp_unit_die
,
5276 struct dwarf2_cu
*cu
= reader
->cu
;
5278 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5280 /* Check if comp unit has_children.
5281 If so, read the rest of the partial symbols from this comp unit.
5282 If not, there's no more debug_info for this comp unit. */
5284 load_partial_dies (reader
, info_ptr
, 0);
5287 /* Load the partial DIEs for a secondary CU into memory.
5288 This is also used when rereading a primary CU with load_all_dies. */
5291 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5293 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5294 load_partial_comp_unit_reader
, NULL
);
5297 /* Create a list of all compilation units in OBJFILE.
5298 This is only done for -readnow and building partial symtabs. */
5301 create_all_comp_units (struct objfile
*objfile
)
5305 struct dwarf2_per_cu_data
**all_comp_units
;
5308 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5309 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
5313 all_comp_units
= xmalloc (n_allocated
5314 * sizeof (struct dwarf2_per_cu_data
*));
5316 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
5317 + dwarf2_per_objfile
->info
.size
)
5319 unsigned int length
, initial_length_size
;
5320 struct dwarf2_per_cu_data
*this_cu
;
5323 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
5325 /* Read just enough information to find out where the next
5326 compilation unit is. */
5327 length
= read_initial_length (objfile
->obfd
, info_ptr
,
5328 &initial_length_size
);
5330 /* Save the compilation unit for later lookup. */
5331 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5332 sizeof (struct dwarf2_per_cu_data
));
5333 memset (this_cu
, 0, sizeof (*this_cu
));
5334 this_cu
->offset
= offset
;
5335 this_cu
->length
= length
+ initial_length_size
;
5336 this_cu
->objfile
= objfile
;
5337 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
5339 if (n_comp_units
== n_allocated
)
5342 all_comp_units
= xrealloc (all_comp_units
,
5344 * sizeof (struct dwarf2_per_cu_data
*));
5346 all_comp_units
[n_comp_units
++] = this_cu
;
5348 info_ptr
= info_ptr
+ this_cu
->length
;
5351 dwarf2_per_objfile
->all_comp_units
5352 = obstack_alloc (&objfile
->objfile_obstack
,
5353 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5354 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5355 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5356 xfree (all_comp_units
);
5357 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5360 /* Process all loaded DIEs for compilation unit CU, starting at
5361 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5362 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5363 DW_AT_ranges). If NEED_PC is set, then this function will set
5364 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5365 and record the covered ranges in the addrmap. */
5368 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5369 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5371 struct partial_die_info
*pdi
;
5373 /* Now, march along the PDI's, descending into ones which have
5374 interesting children but skipping the children of the other ones,
5375 until we reach the end of the compilation unit. */
5381 fixup_partial_die (pdi
, cu
);
5383 /* Anonymous namespaces or modules have no name but have interesting
5384 children, so we need to look at them. Ditto for anonymous
5387 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5388 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5389 || pdi
->tag
== DW_TAG_imported_unit
)
5393 case DW_TAG_subprogram
:
5394 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5396 case DW_TAG_constant
:
5397 case DW_TAG_variable
:
5398 case DW_TAG_typedef
:
5399 case DW_TAG_union_type
:
5400 if (!pdi
->is_declaration
)
5402 add_partial_symbol (pdi
, cu
);
5405 case DW_TAG_class_type
:
5406 case DW_TAG_interface_type
:
5407 case DW_TAG_structure_type
:
5408 if (!pdi
->is_declaration
)
5410 add_partial_symbol (pdi
, cu
);
5413 case DW_TAG_enumeration_type
:
5414 if (!pdi
->is_declaration
)
5415 add_partial_enumeration (pdi
, cu
);
5417 case DW_TAG_base_type
:
5418 case DW_TAG_subrange_type
:
5419 /* File scope base type definitions are added to the partial
5421 add_partial_symbol (pdi
, cu
);
5423 case DW_TAG_namespace
:
5424 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5427 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5429 case DW_TAG_imported_unit
:
5431 struct dwarf2_per_cu_data
*per_cu
;
5433 /* For now we don't handle imported units in type units. */
5434 if (cu
->per_cu
->is_debug_types
)
5436 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5437 " supported in type units [in module %s]"),
5441 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5444 /* Go read the partial unit, if needed. */
5445 if (per_cu
->v
.psymtab
== NULL
)
5446 process_psymtab_comp_unit (per_cu
, 1);
5448 VEC_safe_push (dwarf2_per_cu_ptr
,
5449 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5457 /* If the die has a sibling, skip to the sibling. */
5459 pdi
= pdi
->die_sibling
;
5463 /* Functions used to compute the fully scoped name of a partial DIE.
5465 Normally, this is simple. For C++, the parent DIE's fully scoped
5466 name is concatenated with "::" and the partial DIE's name. For
5467 Java, the same thing occurs except that "." is used instead of "::".
5468 Enumerators are an exception; they use the scope of their parent
5469 enumeration type, i.e. the name of the enumeration type is not
5470 prepended to the enumerator.
5472 There are two complexities. One is DW_AT_specification; in this
5473 case "parent" means the parent of the target of the specification,
5474 instead of the direct parent of the DIE. The other is compilers
5475 which do not emit DW_TAG_namespace; in this case we try to guess
5476 the fully qualified name of structure types from their members'
5477 linkage names. This must be done using the DIE's children rather
5478 than the children of any DW_AT_specification target. We only need
5479 to do this for structures at the top level, i.e. if the target of
5480 any DW_AT_specification (if any; otherwise the DIE itself) does not
5483 /* Compute the scope prefix associated with PDI's parent, in
5484 compilation unit CU. The result will be allocated on CU's
5485 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5486 field. NULL is returned if no prefix is necessary. */
5488 partial_die_parent_scope (struct partial_die_info
*pdi
,
5489 struct dwarf2_cu
*cu
)
5491 char *grandparent_scope
;
5492 struct partial_die_info
*parent
, *real_pdi
;
5494 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5495 then this means the parent of the specification DIE. */
5498 while (real_pdi
->has_specification
)
5499 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
5501 parent
= real_pdi
->die_parent
;
5505 if (parent
->scope_set
)
5506 return parent
->scope
;
5508 fixup_partial_die (parent
, cu
);
5510 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5512 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5513 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5514 Work around this problem here. */
5515 if (cu
->language
== language_cplus
5516 && parent
->tag
== DW_TAG_namespace
5517 && strcmp (parent
->name
, "::") == 0
5518 && grandparent_scope
== NULL
)
5520 parent
->scope
= NULL
;
5521 parent
->scope_set
= 1;
5525 if (pdi
->tag
== DW_TAG_enumerator
)
5526 /* Enumerators should not get the name of the enumeration as a prefix. */
5527 parent
->scope
= grandparent_scope
;
5528 else if (parent
->tag
== DW_TAG_namespace
5529 || parent
->tag
== DW_TAG_module
5530 || parent
->tag
== DW_TAG_structure_type
5531 || parent
->tag
== DW_TAG_class_type
5532 || parent
->tag
== DW_TAG_interface_type
5533 || parent
->tag
== DW_TAG_union_type
5534 || parent
->tag
== DW_TAG_enumeration_type
)
5536 if (grandparent_scope
== NULL
)
5537 parent
->scope
= parent
->name
;
5539 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5541 parent
->name
, 0, cu
);
5545 /* FIXME drow/2004-04-01: What should we be doing with
5546 function-local names? For partial symbols, we should probably be
5548 complaint (&symfile_complaints
,
5549 _("unhandled containing DIE tag %d for DIE at %d"),
5550 parent
->tag
, pdi
->offset
.sect_off
);
5551 parent
->scope
= grandparent_scope
;
5554 parent
->scope_set
= 1;
5555 return parent
->scope
;
5558 /* Return the fully scoped name associated with PDI, from compilation unit
5559 CU. The result will be allocated with malloc. */
5562 partial_die_full_name (struct partial_die_info
*pdi
,
5563 struct dwarf2_cu
*cu
)
5567 /* If this is a template instantiation, we can not work out the
5568 template arguments from partial DIEs. So, unfortunately, we have
5569 to go through the full DIEs. At least any work we do building
5570 types here will be reused if full symbols are loaded later. */
5571 if (pdi
->has_template_arguments
)
5573 fixup_partial_die (pdi
, cu
);
5575 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5577 struct die_info
*die
;
5578 struct attribute attr
;
5579 struct dwarf2_cu
*ref_cu
= cu
;
5581 /* DW_FORM_ref_addr is using section offset. */
5583 attr
.form
= DW_FORM_ref_addr
;
5584 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5585 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5587 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5591 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5592 if (parent_scope
== NULL
)
5595 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5599 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5601 struct objfile
*objfile
= cu
->objfile
;
5603 char *actual_name
= NULL
;
5605 int built_actual_name
= 0;
5607 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5609 actual_name
= partial_die_full_name (pdi
, cu
);
5611 built_actual_name
= 1;
5613 if (actual_name
== NULL
)
5614 actual_name
= pdi
->name
;
5618 case DW_TAG_subprogram
:
5619 if (pdi
->is_external
|| cu
->language
== language_ada
)
5621 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5622 of the global scope. But in Ada, we want to be able to access
5623 nested procedures globally. So all Ada subprograms are stored
5624 in the global scope. */
5625 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5626 mst_text, objfile); */
5627 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5629 VAR_DOMAIN
, LOC_BLOCK
,
5630 &objfile
->global_psymbols
,
5631 0, pdi
->lowpc
+ baseaddr
,
5632 cu
->language
, objfile
);
5636 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5637 mst_file_text, objfile); */
5638 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5640 VAR_DOMAIN
, LOC_BLOCK
,
5641 &objfile
->static_psymbols
,
5642 0, pdi
->lowpc
+ baseaddr
,
5643 cu
->language
, objfile
);
5646 case DW_TAG_constant
:
5648 struct psymbol_allocation_list
*list
;
5650 if (pdi
->is_external
)
5651 list
= &objfile
->global_psymbols
;
5653 list
= &objfile
->static_psymbols
;
5654 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5655 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5656 list
, 0, 0, cu
->language
, objfile
);
5659 case DW_TAG_variable
:
5661 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5665 && !dwarf2_per_objfile
->has_section_at_zero
)
5667 /* A global or static variable may also have been stripped
5668 out by the linker if unused, in which case its address
5669 will be nullified; do not add such variables into partial
5670 symbol table then. */
5672 else if (pdi
->is_external
)
5675 Don't enter into the minimal symbol tables as there is
5676 a minimal symbol table entry from the ELF symbols already.
5677 Enter into partial symbol table if it has a location
5678 descriptor or a type.
5679 If the location descriptor is missing, new_symbol will create
5680 a LOC_UNRESOLVED symbol, the address of the variable will then
5681 be determined from the minimal symbol table whenever the variable
5683 The address for the partial symbol table entry is not
5684 used by GDB, but it comes in handy for debugging partial symbol
5687 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5688 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5690 VAR_DOMAIN
, LOC_STATIC
,
5691 &objfile
->global_psymbols
,
5693 cu
->language
, objfile
);
5697 /* Static Variable. Skip symbols without location descriptors. */
5698 if (pdi
->d
.locdesc
== NULL
)
5700 if (built_actual_name
)
5701 xfree (actual_name
);
5704 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5705 mst_file_data, objfile); */
5706 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5708 VAR_DOMAIN
, LOC_STATIC
,
5709 &objfile
->static_psymbols
,
5711 cu
->language
, objfile
);
5714 case DW_TAG_typedef
:
5715 case DW_TAG_base_type
:
5716 case DW_TAG_subrange_type
:
5717 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5719 VAR_DOMAIN
, LOC_TYPEDEF
,
5720 &objfile
->static_psymbols
,
5721 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5723 case DW_TAG_namespace
:
5724 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5726 VAR_DOMAIN
, LOC_TYPEDEF
,
5727 &objfile
->global_psymbols
,
5728 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5730 case DW_TAG_class_type
:
5731 case DW_TAG_interface_type
:
5732 case DW_TAG_structure_type
:
5733 case DW_TAG_union_type
:
5734 case DW_TAG_enumeration_type
:
5735 /* Skip external references. The DWARF standard says in the section
5736 about "Structure, Union, and Class Type Entries": "An incomplete
5737 structure, union or class type is represented by a structure,
5738 union or class entry that does not have a byte size attribute
5739 and that has a DW_AT_declaration attribute." */
5740 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5742 if (built_actual_name
)
5743 xfree (actual_name
);
5747 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5748 static vs. global. */
5749 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5751 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5752 (cu
->language
== language_cplus
5753 || cu
->language
== language_java
)
5754 ? &objfile
->global_psymbols
5755 : &objfile
->static_psymbols
,
5756 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5759 case DW_TAG_enumerator
:
5760 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5762 VAR_DOMAIN
, LOC_CONST
,
5763 (cu
->language
== language_cplus
5764 || cu
->language
== language_java
)
5765 ? &objfile
->global_psymbols
5766 : &objfile
->static_psymbols
,
5767 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5773 if (built_actual_name
)
5774 xfree (actual_name
);
5777 /* Read a partial die corresponding to a namespace; also, add a symbol
5778 corresponding to that namespace to the symbol table. NAMESPACE is
5779 the name of the enclosing namespace. */
5782 add_partial_namespace (struct partial_die_info
*pdi
,
5783 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5784 int need_pc
, struct dwarf2_cu
*cu
)
5786 /* Add a symbol for the namespace. */
5788 add_partial_symbol (pdi
, cu
);
5790 /* Now scan partial symbols in that namespace. */
5792 if (pdi
->has_children
)
5793 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5796 /* Read a partial die corresponding to a Fortran module. */
5799 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5800 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5802 /* Now scan partial symbols in that module. */
5804 if (pdi
->has_children
)
5805 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5808 /* Read a partial die corresponding to a subprogram and create a partial
5809 symbol for that subprogram. When the CU language allows it, this
5810 routine also defines a partial symbol for each nested subprogram
5811 that this subprogram contains.
5813 DIE my also be a lexical block, in which case we simply search
5814 recursively for suprograms defined inside that lexical block.
5815 Again, this is only performed when the CU language allows this
5816 type of definitions. */
5819 add_partial_subprogram (struct partial_die_info
*pdi
,
5820 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5821 int need_pc
, struct dwarf2_cu
*cu
)
5823 if (pdi
->tag
== DW_TAG_subprogram
)
5825 if (pdi
->has_pc_info
)
5827 if (pdi
->lowpc
< *lowpc
)
5828 *lowpc
= pdi
->lowpc
;
5829 if (pdi
->highpc
> *highpc
)
5830 *highpc
= pdi
->highpc
;
5834 struct objfile
*objfile
= cu
->objfile
;
5836 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5837 SECT_OFF_TEXT (objfile
));
5838 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5839 pdi
->lowpc
+ baseaddr
,
5840 pdi
->highpc
- 1 + baseaddr
,
5841 cu
->per_cu
->v
.psymtab
);
5845 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5847 if (!pdi
->is_declaration
)
5848 /* Ignore subprogram DIEs that do not have a name, they are
5849 illegal. Do not emit a complaint at this point, we will
5850 do so when we convert this psymtab into a symtab. */
5852 add_partial_symbol (pdi
, cu
);
5856 if (! pdi
->has_children
)
5859 if (cu
->language
== language_ada
)
5861 pdi
= pdi
->die_child
;
5864 fixup_partial_die (pdi
, cu
);
5865 if (pdi
->tag
== DW_TAG_subprogram
5866 || pdi
->tag
== DW_TAG_lexical_block
)
5867 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5868 pdi
= pdi
->die_sibling
;
5873 /* Read a partial die corresponding to an enumeration type. */
5876 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
5877 struct dwarf2_cu
*cu
)
5879 struct partial_die_info
*pdi
;
5881 if (enum_pdi
->name
!= NULL
)
5882 add_partial_symbol (enum_pdi
, cu
);
5884 pdi
= enum_pdi
->die_child
;
5887 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
5888 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5890 add_partial_symbol (pdi
, cu
);
5891 pdi
= pdi
->die_sibling
;
5895 /* Return the initial uleb128 in the die at INFO_PTR. */
5898 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
5900 unsigned int bytes_read
;
5902 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5905 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
5906 Return the corresponding abbrev, or NULL if the number is zero (indicating
5907 an empty DIE). In either case *BYTES_READ will be set to the length of
5908 the initial number. */
5910 static struct abbrev_info
*
5911 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
5912 struct dwarf2_cu
*cu
)
5914 bfd
*abfd
= cu
->objfile
->obfd
;
5915 unsigned int abbrev_number
;
5916 struct abbrev_info
*abbrev
;
5918 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5920 if (abbrev_number
== 0)
5923 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
5926 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
5927 abbrev_number
, bfd_get_filename (abfd
));
5933 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5934 Returns a pointer to the end of a series of DIEs, terminated by an empty
5935 DIE. Any children of the skipped DIEs will also be skipped. */
5938 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5940 struct dwarf2_cu
*cu
= reader
->cu
;
5941 struct abbrev_info
*abbrev
;
5942 unsigned int bytes_read
;
5946 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5948 return info_ptr
+ bytes_read
;
5950 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5954 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5955 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5956 abbrev corresponding to that skipped uleb128 should be passed in
5957 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5961 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5962 struct abbrev_info
*abbrev
)
5964 unsigned int bytes_read
;
5965 struct attribute attr
;
5966 bfd
*abfd
= reader
->abfd
;
5967 struct dwarf2_cu
*cu
= reader
->cu
;
5968 gdb_byte
*buffer
= reader
->buffer
;
5969 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5970 gdb_byte
*start_info_ptr
= info_ptr
;
5971 unsigned int form
, i
;
5973 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5975 /* The only abbrev we care about is DW_AT_sibling. */
5976 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5978 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5979 if (attr
.form
== DW_FORM_ref_addr
)
5980 complaint (&symfile_complaints
,
5981 _("ignoring absolute DW_AT_sibling"));
5983 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5986 /* If it isn't DW_AT_sibling, skip this attribute. */
5987 form
= abbrev
->attrs
[i
].form
;
5991 case DW_FORM_ref_addr
:
5992 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5993 and later it is offset sized. */
5994 if (cu
->header
.version
== 2)
5995 info_ptr
+= cu
->header
.addr_size
;
5997 info_ptr
+= cu
->header
.offset_size
;
6000 info_ptr
+= cu
->header
.addr_size
;
6007 case DW_FORM_flag_present
:
6019 case DW_FORM_ref_sig8
:
6022 case DW_FORM_string
:
6023 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6024 info_ptr
+= bytes_read
;
6026 case DW_FORM_sec_offset
:
6028 info_ptr
+= cu
->header
.offset_size
;
6030 case DW_FORM_exprloc
:
6032 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6033 info_ptr
+= bytes_read
;
6035 case DW_FORM_block1
:
6036 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6038 case DW_FORM_block2
:
6039 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6041 case DW_FORM_block4
:
6042 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6046 case DW_FORM_ref_udata
:
6047 case DW_FORM_GNU_addr_index
:
6048 case DW_FORM_GNU_str_index
:
6049 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6051 case DW_FORM_indirect
:
6052 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6053 info_ptr
+= bytes_read
;
6054 /* We need to continue parsing from here, so just go back to
6056 goto skip_attribute
;
6059 error (_("Dwarf Error: Cannot handle %s "
6060 "in DWARF reader [in module %s]"),
6061 dwarf_form_name (form
),
6062 bfd_get_filename (abfd
));
6066 if (abbrev
->has_children
)
6067 return skip_children (reader
, info_ptr
);
6072 /* Locate ORIG_PDI's sibling.
6073 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6076 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6077 struct partial_die_info
*orig_pdi
,
6080 /* Do we know the sibling already? */
6082 if (orig_pdi
->sibling
)
6083 return orig_pdi
->sibling
;
6085 /* Are there any children to deal with? */
6087 if (!orig_pdi
->has_children
)
6090 /* Skip the children the long way. */
6092 return skip_children (reader
, info_ptr
);
6095 /* Expand this partial symbol table into a full symbol table. */
6098 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
6104 warning (_("bug: psymtab for %s is already read in."),
6111 printf_filtered (_("Reading in symbols for %s..."),
6113 gdb_flush (gdb_stdout
);
6116 /* Restore our global data. */
6117 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
6118 dwarf2_objfile_data_key
);
6120 /* If this psymtab is constructed from a debug-only objfile, the
6121 has_section_at_zero flag will not necessarily be correct. We
6122 can get the correct value for this flag by looking at the data
6123 associated with the (presumably stripped) associated objfile. */
6124 if (pst
->objfile
->separate_debug_objfile_backlink
)
6126 struct dwarf2_per_objfile
*dpo_backlink
6127 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6128 dwarf2_objfile_data_key
);
6130 dwarf2_per_objfile
->has_section_at_zero
6131 = dpo_backlink
->has_section_at_zero
;
6134 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6136 psymtab_to_symtab_1 (pst
);
6138 /* Finish up the debug error message. */
6140 printf_filtered (_("done.\n"));
6144 process_cu_includes ();
6147 /* Reading in full CUs. */
6149 /* Add PER_CU to the queue. */
6152 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6153 enum language pretend_language
)
6155 struct dwarf2_queue_item
*item
;
6158 item
= xmalloc (sizeof (*item
));
6159 item
->per_cu
= per_cu
;
6160 item
->pretend_language
= pretend_language
;
6163 if (dwarf2_queue
== NULL
)
6164 dwarf2_queue
= item
;
6166 dwarf2_queue_tail
->next
= item
;
6168 dwarf2_queue_tail
= item
;
6171 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6172 unit and add it to our queue.
6173 The result is non-zero if PER_CU was queued, otherwise the result is zero
6174 meaning either PER_CU is already queued or it is already loaded. */
6177 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6178 struct dwarf2_per_cu_data
*per_cu
,
6179 enum language pretend_language
)
6181 /* We may arrive here during partial symbol reading, if we need full
6182 DIEs to process an unusual case (e.g. template arguments). Do
6183 not queue PER_CU, just tell our caller to load its DIEs. */
6184 if (dwarf2_per_objfile
->reading_partial_symbols
)
6186 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6191 /* Mark the dependence relation so that we don't flush PER_CU
6193 dwarf2_add_dependence (this_cu
, per_cu
);
6195 /* If it's already on the queue, we have nothing to do. */
6199 /* If the compilation unit is already loaded, just mark it as
6201 if (per_cu
->cu
!= NULL
)
6203 per_cu
->cu
->last_used
= 0;
6207 /* Add it to the queue. */
6208 queue_comp_unit (per_cu
, pretend_language
);
6213 /* Process the queue. */
6216 process_queue (void)
6218 struct dwarf2_queue_item
*item
, *next_item
;
6220 if (dwarf2_read_debug
)
6222 fprintf_unfiltered (gdb_stdlog
,
6223 "Expanding one or more symtabs of objfile %s ...\n",
6224 dwarf2_per_objfile
->objfile
->name
);
6227 /* The queue starts out with one item, but following a DIE reference
6228 may load a new CU, adding it to the end of the queue. */
6229 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6231 if (dwarf2_per_objfile
->using_index
6232 ? !item
->per_cu
->v
.quick
->symtab
6233 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6235 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6237 if (dwarf2_read_debug
)
6239 fprintf_unfiltered (gdb_stdlog
,
6240 "Expanding symtab of %s at offset 0x%x\n",
6241 per_cu
->is_debug_types
? "TU" : "CU",
6242 per_cu
->offset
.sect_off
);
6245 if (per_cu
->is_debug_types
)
6246 process_full_type_unit (per_cu
, item
->pretend_language
);
6248 process_full_comp_unit (per_cu
, item
->pretend_language
);
6250 if (dwarf2_read_debug
)
6252 fprintf_unfiltered (gdb_stdlog
,
6253 "Done expanding %s at offset 0x%x\n",
6254 per_cu
->is_debug_types
? "TU" : "CU",
6255 per_cu
->offset
.sect_off
);
6259 item
->per_cu
->queued
= 0;
6260 next_item
= item
->next
;
6264 dwarf2_queue_tail
= NULL
;
6266 if (dwarf2_read_debug
)
6268 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6269 dwarf2_per_objfile
->objfile
->name
);
6273 /* Free all allocated queue entries. This function only releases anything if
6274 an error was thrown; if the queue was processed then it would have been
6275 freed as we went along. */
6278 dwarf2_release_queue (void *dummy
)
6280 struct dwarf2_queue_item
*item
, *last
;
6282 item
= dwarf2_queue
;
6285 /* Anything still marked queued is likely to be in an
6286 inconsistent state, so discard it. */
6287 if (item
->per_cu
->queued
)
6289 if (item
->per_cu
->cu
!= NULL
)
6290 free_one_cached_comp_unit (item
->per_cu
);
6291 item
->per_cu
->queued
= 0;
6299 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6302 /* Read in full symbols for PST, and anything it depends on. */
6305 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6307 struct dwarf2_per_cu_data
*per_cu
;
6313 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6314 if (!pst
->dependencies
[i
]->readin
6315 && pst
->dependencies
[i
]->user
== NULL
)
6317 /* Inform about additional files that need to be read in. */
6320 /* FIXME: i18n: Need to make this a single string. */
6321 fputs_filtered (" ", gdb_stdout
);
6323 fputs_filtered ("and ", gdb_stdout
);
6325 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6326 wrap_here (""); /* Flush output. */
6327 gdb_flush (gdb_stdout
);
6329 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6332 per_cu
= pst
->read_symtab_private
;
6336 /* It's an include file, no symbols to read for it.
6337 Everything is in the parent symtab. */
6342 dw2_do_instantiate_symtab (per_cu
);
6345 /* Trivial hash function for die_info: the hash value of a DIE
6346 is its offset in .debug_info for this objfile. */
6349 die_hash (const void *item
)
6351 const struct die_info
*die
= item
;
6353 return die
->offset
.sect_off
;
6356 /* Trivial comparison function for die_info structures: two DIEs
6357 are equal if they have the same offset. */
6360 die_eq (const void *item_lhs
, const void *item_rhs
)
6362 const struct die_info
*die_lhs
= item_lhs
;
6363 const struct die_info
*die_rhs
= item_rhs
;
6365 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6368 /* die_reader_func for load_full_comp_unit.
6369 This is identical to read_signatured_type_reader,
6370 but is kept separate for now. */
6373 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6375 struct die_info
*comp_unit_die
,
6379 struct dwarf2_cu
*cu
= reader
->cu
;
6380 enum language
*language_ptr
= data
;
6382 gdb_assert (cu
->die_hash
== NULL
);
6384 htab_create_alloc_ex (cu
->header
.length
/ 12,
6388 &cu
->comp_unit_obstack
,
6389 hashtab_obstack_allocate
,
6390 dummy_obstack_deallocate
);
6393 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6394 &info_ptr
, comp_unit_die
);
6395 cu
->dies
= comp_unit_die
;
6396 /* comp_unit_die is not stored in die_hash, no need. */
6398 /* We try not to read any attributes in this function, because not
6399 all CUs needed for references have been loaded yet, and symbol
6400 table processing isn't initialized. But we have to set the CU language,
6401 or we won't be able to build types correctly.
6402 Similarly, if we do not read the producer, we can not apply
6403 producer-specific interpretation. */
6404 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6407 /* Load the DIEs associated with PER_CU into memory. */
6410 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6411 enum language pretend_language
)
6413 gdb_assert (! this_cu
->is_debug_types
);
6415 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6416 load_full_comp_unit_reader
, &pretend_language
);
6419 /* Add a DIE to the delayed physname list. */
6422 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6423 const char *name
, struct die_info
*die
,
6424 struct dwarf2_cu
*cu
)
6426 struct delayed_method_info mi
;
6428 mi
.fnfield_index
= fnfield_index
;
6432 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6435 /* A cleanup for freeing the delayed method list. */
6438 free_delayed_list (void *ptr
)
6440 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6441 if (cu
->method_list
!= NULL
)
6443 VEC_free (delayed_method_info
, cu
->method_list
);
6444 cu
->method_list
= NULL
;
6448 /* Compute the physnames of any methods on the CU's method list.
6450 The computation of method physnames is delayed in order to avoid the
6451 (bad) condition that one of the method's formal parameters is of an as yet
6455 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6458 struct delayed_method_info
*mi
;
6459 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6461 const char *physname
;
6462 struct fn_fieldlist
*fn_flp
6463 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6464 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6465 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6469 /* Go objects should be embedded in a DW_TAG_module DIE,
6470 and it's not clear if/how imported objects will appear.
6471 To keep Go support simple until that's worked out,
6472 go back through what we've read and create something usable.
6473 We could do this while processing each DIE, and feels kinda cleaner,
6474 but that way is more invasive.
6475 This is to, for example, allow the user to type "p var" or "b main"
6476 without having to specify the package name, and allow lookups
6477 of module.object to work in contexts that use the expression
6481 fixup_go_packaging (struct dwarf2_cu
*cu
)
6483 char *package_name
= NULL
;
6484 struct pending
*list
;
6487 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6489 for (i
= 0; i
< list
->nsyms
; ++i
)
6491 struct symbol
*sym
= list
->symbol
[i
];
6493 if (SYMBOL_LANGUAGE (sym
) == language_go
6494 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6496 char *this_package_name
= go_symbol_package_name (sym
);
6498 if (this_package_name
== NULL
)
6500 if (package_name
== NULL
)
6501 package_name
= this_package_name
;
6504 if (strcmp (package_name
, this_package_name
) != 0)
6505 complaint (&symfile_complaints
,
6506 _("Symtab %s has objects from two different Go packages: %s and %s"),
6507 (sym
->symtab
&& sym
->symtab
->filename
6508 ? sym
->symtab
->filename
6509 : cu
->objfile
->name
),
6510 this_package_name
, package_name
);
6511 xfree (this_package_name
);
6517 if (package_name
!= NULL
)
6519 struct objfile
*objfile
= cu
->objfile
;
6520 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6521 package_name
, objfile
);
6524 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6526 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6527 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6528 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6529 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6530 e.g., "main" finds the "main" module and not C's main(). */
6531 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6532 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6533 SYMBOL_TYPE (sym
) = type
;
6535 add_symbol_to_list (sym
, &global_symbols
);
6537 xfree (package_name
);
6541 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6543 /* Return the symtab for PER_CU. This works properly regardless of
6544 whether we're using the index or psymtabs. */
6546 static struct symtab
*
6547 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6549 return (dwarf2_per_objfile
->using_index
6550 ? per_cu
->v
.quick
->symtab
6551 : per_cu
->v
.psymtab
->symtab
);
6554 /* A helper function for computing the list of all symbol tables
6555 included by PER_CU. */
6558 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6559 htab_t all_children
,
6560 struct dwarf2_per_cu_data
*per_cu
)
6564 struct dwarf2_per_cu_data
*iter
;
6566 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6569 /* This inclusion and its children have been processed. */
6574 /* Only add a CU if it has a symbol table. */
6575 if (get_symtab (per_cu
) != NULL
)
6576 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6579 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6581 recursively_compute_inclusions (result
, all_children
, iter
);
6584 /* Compute the symtab 'includes' fields for the symtab related to
6588 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6590 gdb_assert (! per_cu
->is_debug_types
);
6592 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6595 struct dwarf2_per_cu_data
*iter
;
6596 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6597 htab_t all_children
;
6598 struct symtab
*symtab
= get_symtab (per_cu
);
6600 /* If we don't have a symtab, we can just skip this case. */
6604 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6605 NULL
, xcalloc
, xfree
);
6608 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6611 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6613 /* Now we have a transitive closure of all the included CUs, so
6614 we can convert it to a list of symtabs. */
6615 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6617 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6618 (len
+ 1) * sizeof (struct symtab
*));
6620 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6622 symtab
->includes
[ix
] = get_symtab (iter
);
6623 symtab
->includes
[len
] = NULL
;
6625 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6626 htab_delete (all_children
);
6630 /* Compute the 'includes' field for the symtabs of all the CUs we just
6634 process_cu_includes (void)
6637 struct dwarf2_per_cu_data
*iter
;
6640 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6644 if (! iter
->is_debug_types
)
6645 compute_symtab_includes (iter
);
6648 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6651 /* Generate full symbol information for PER_CU, whose DIEs have
6652 already been loaded into memory. */
6655 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6656 enum language pretend_language
)
6658 struct dwarf2_cu
*cu
= per_cu
->cu
;
6659 struct objfile
*objfile
= per_cu
->objfile
;
6660 CORE_ADDR lowpc
, highpc
;
6661 struct symtab
*symtab
;
6662 struct cleanup
*back_to
, *delayed_list_cleanup
;
6664 struct block
*static_block
;
6666 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6669 back_to
= make_cleanup (really_free_pendings
, NULL
);
6670 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6672 cu
->list_in_scope
= &file_symbols
;
6674 cu
->language
= pretend_language
;
6675 cu
->language_defn
= language_def (cu
->language
);
6677 /* Do line number decoding in read_file_scope () */
6678 process_die (cu
->dies
, cu
);
6680 /* For now fudge the Go package. */
6681 if (cu
->language
== language_go
)
6682 fixup_go_packaging (cu
);
6684 /* Now that we have processed all the DIEs in the CU, all the types
6685 should be complete, and it should now be safe to compute all of the
6687 compute_delayed_physnames (cu
);
6688 do_cleanups (delayed_list_cleanup
);
6690 /* Some compilers don't define a DW_AT_high_pc attribute for the
6691 compilation unit. If the DW_AT_high_pc is missing, synthesize
6692 it, by scanning the DIE's below the compilation unit. */
6693 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6695 static_block
= end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0);
6697 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6698 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6699 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6700 addrmap to help ensure it has an accurate map of pc values belonging to
6702 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6704 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6705 SECT_OFF_TEXT (objfile
), 0);
6709 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6711 /* Set symtab language to language from DW_AT_language. If the
6712 compilation is from a C file generated by language preprocessors, do
6713 not set the language if it was already deduced by start_subfile. */
6714 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6715 symtab
->language
= cu
->language
;
6717 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6718 produce DW_AT_location with location lists but it can be possibly
6719 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6720 there were bugs in prologue debug info, fixed later in GCC-4.5
6721 by "unwind info for epilogues" patch (which is not directly related).
6723 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6724 needed, it would be wrong due to missing DW_AT_producer there.
6726 Still one can confuse GDB by using non-standard GCC compilation
6727 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6729 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6730 symtab
->locations_valid
= 1;
6732 if (gcc_4_minor
>= 5)
6733 symtab
->epilogue_unwind_valid
= 1;
6735 symtab
->call_site_htab
= cu
->call_site_htab
;
6738 if (dwarf2_per_objfile
->using_index
)
6739 per_cu
->v
.quick
->symtab
= symtab
;
6742 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6743 pst
->symtab
= symtab
;
6747 /* Push it for inclusion processing later. */
6748 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
6750 do_cleanups (back_to
);
6753 /* Generate full symbol information for type unit PER_CU, whose DIEs have
6754 already been loaded into memory. */
6757 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
6758 enum language pretend_language
)
6760 struct dwarf2_cu
*cu
= per_cu
->cu
;
6761 struct objfile
*objfile
= per_cu
->objfile
;
6762 struct symtab
*symtab
;
6763 struct cleanup
*back_to
, *delayed_list_cleanup
;
6766 back_to
= make_cleanup (really_free_pendings
, NULL
);
6767 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6769 cu
->list_in_scope
= &file_symbols
;
6771 cu
->language
= pretend_language
;
6772 cu
->language_defn
= language_def (cu
->language
);
6774 /* The symbol tables are set up in read_type_unit_scope. */
6775 process_die (cu
->dies
, cu
);
6777 /* For now fudge the Go package. */
6778 if (cu
->language
== language_go
)
6779 fixup_go_packaging (cu
);
6781 /* Now that we have processed all the DIEs in the CU, all the types
6782 should be complete, and it should now be safe to compute all of the
6784 compute_delayed_physnames (cu
);
6785 do_cleanups (delayed_list_cleanup
);
6787 /* TUs share symbol tables.
6788 If this is the first TU to use this symtab, complete the construction
6789 of it with end_expandable_symtab. Otherwise, complete the addition of
6790 this TU's symbols to the existing symtab. */
6791 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
6793 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
6794 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
6798 /* Set symtab language to language from DW_AT_language. If the
6799 compilation is from a C file generated by language preprocessors,
6800 do not set the language if it was already deduced by
6802 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6803 symtab
->language
= cu
->language
;
6808 augment_type_symtab (objfile
,
6809 per_cu
->s
.type_unit_group
->primary_symtab
);
6810 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
6813 if (dwarf2_per_objfile
->using_index
)
6814 per_cu
->v
.quick
->symtab
= symtab
;
6817 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6818 pst
->symtab
= symtab
;
6822 do_cleanups (back_to
);
6825 /* Process an imported unit DIE. */
6828 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6830 struct attribute
*attr
;
6832 /* For now we don't handle imported units in type units. */
6833 if (cu
->per_cu
->is_debug_types
)
6835 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6836 " supported in type units [in module %s]"),
6840 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6843 struct dwarf2_per_cu_data
*per_cu
;
6844 struct symtab
*imported_symtab
;
6847 offset
= dwarf2_get_ref_die_offset (attr
);
6848 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6850 /* Queue the unit, if needed. */
6851 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
6852 load_full_comp_unit (per_cu
, cu
->language
);
6854 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
6859 /* Process a die and its children. */
6862 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6866 case DW_TAG_padding
:
6868 case DW_TAG_compile_unit
:
6869 case DW_TAG_partial_unit
:
6870 read_file_scope (die
, cu
);
6872 case DW_TAG_type_unit
:
6873 read_type_unit_scope (die
, cu
);
6875 case DW_TAG_subprogram
:
6876 case DW_TAG_inlined_subroutine
:
6877 read_func_scope (die
, cu
);
6879 case DW_TAG_lexical_block
:
6880 case DW_TAG_try_block
:
6881 case DW_TAG_catch_block
:
6882 read_lexical_block_scope (die
, cu
);
6884 case DW_TAG_GNU_call_site
:
6885 read_call_site_scope (die
, cu
);
6887 case DW_TAG_class_type
:
6888 case DW_TAG_interface_type
:
6889 case DW_TAG_structure_type
:
6890 case DW_TAG_union_type
:
6891 process_structure_scope (die
, cu
);
6893 case DW_TAG_enumeration_type
:
6894 process_enumeration_scope (die
, cu
);
6897 /* These dies have a type, but processing them does not create
6898 a symbol or recurse to process the children. Therefore we can
6899 read them on-demand through read_type_die. */
6900 case DW_TAG_subroutine_type
:
6901 case DW_TAG_set_type
:
6902 case DW_TAG_array_type
:
6903 case DW_TAG_pointer_type
:
6904 case DW_TAG_ptr_to_member_type
:
6905 case DW_TAG_reference_type
:
6906 case DW_TAG_string_type
:
6909 case DW_TAG_base_type
:
6910 case DW_TAG_subrange_type
:
6911 case DW_TAG_typedef
:
6912 /* Add a typedef symbol for the type definition, if it has a
6914 new_symbol (die
, read_type_die (die
, cu
), cu
);
6916 case DW_TAG_common_block
:
6917 read_common_block (die
, cu
);
6919 case DW_TAG_common_inclusion
:
6921 case DW_TAG_namespace
:
6922 processing_has_namespace_info
= 1;
6923 read_namespace (die
, cu
);
6926 processing_has_namespace_info
= 1;
6927 read_module (die
, cu
);
6929 case DW_TAG_imported_declaration
:
6930 case DW_TAG_imported_module
:
6931 processing_has_namespace_info
= 1;
6932 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6933 || cu
->language
!= language_fortran
))
6934 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
6935 dwarf_tag_name (die
->tag
));
6936 read_import_statement (die
, cu
);
6939 case DW_TAG_imported_unit
:
6940 process_imported_unit_die (die
, cu
);
6944 new_symbol (die
, NULL
, cu
);
6949 /* A helper function for dwarf2_compute_name which determines whether DIE
6950 needs to have the name of the scope prepended to the name listed in the
6954 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6956 struct attribute
*attr
;
6960 case DW_TAG_namespace
:
6961 case DW_TAG_typedef
:
6962 case DW_TAG_class_type
:
6963 case DW_TAG_interface_type
:
6964 case DW_TAG_structure_type
:
6965 case DW_TAG_union_type
:
6966 case DW_TAG_enumeration_type
:
6967 case DW_TAG_enumerator
:
6968 case DW_TAG_subprogram
:
6972 case DW_TAG_variable
:
6973 case DW_TAG_constant
:
6974 /* We only need to prefix "globally" visible variables. These include
6975 any variable marked with DW_AT_external or any variable that
6976 lives in a namespace. [Variables in anonymous namespaces
6977 require prefixing, but they are not DW_AT_external.] */
6979 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6981 struct dwarf2_cu
*spec_cu
= cu
;
6983 return die_needs_namespace (die_specification (die
, &spec_cu
),
6987 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6988 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6989 && die
->parent
->tag
!= DW_TAG_module
)
6991 /* A variable in a lexical block of some kind does not need a
6992 namespace, even though in C++ such variables may be external
6993 and have a mangled name. */
6994 if (die
->parent
->tag
== DW_TAG_lexical_block
6995 || die
->parent
->tag
== DW_TAG_try_block
6996 || die
->parent
->tag
== DW_TAG_catch_block
6997 || die
->parent
->tag
== DW_TAG_subprogram
)
7006 /* Retrieve the last character from a mem_file. */
7009 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7011 char *last_char_p
= (char *) object
;
7014 *last_char_p
= buffer
[length
- 1];
7017 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7018 compute the physname for the object, which include a method's:
7019 - formal parameters (C++/Java),
7020 - receiver type (Go),
7021 - return type (Java).
7023 The term "physname" is a bit confusing.
7024 For C++, for example, it is the demangled name.
7025 For Go, for example, it's the mangled name.
7027 For Ada, return the DIE's linkage name rather than the fully qualified
7028 name. PHYSNAME is ignored..
7030 The result is allocated on the objfile_obstack and canonicalized. */
7033 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7036 struct objfile
*objfile
= cu
->objfile
;
7039 name
= dwarf2_name (die
, cu
);
7041 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7042 compute it by typename_concat inside GDB. */
7043 if (cu
->language
== language_ada
7044 || (cu
->language
== language_fortran
&& physname
))
7046 /* For Ada unit, we prefer the linkage name over the name, as
7047 the former contains the exported name, which the user expects
7048 to be able to reference. Ideally, we want the user to be able
7049 to reference this entity using either natural or linkage name,
7050 but we haven't started looking at this enhancement yet. */
7051 struct attribute
*attr
;
7053 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7055 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7056 if (attr
&& DW_STRING (attr
))
7057 return DW_STRING (attr
);
7060 /* These are the only languages we know how to qualify names in. */
7062 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7063 || cu
->language
== language_fortran
))
7065 if (die_needs_namespace (die
, cu
))
7069 struct ui_file
*buf
;
7071 prefix
= determine_prefix (die
, cu
);
7072 buf
= mem_fileopen ();
7073 if (*prefix
!= '\0')
7075 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7078 fputs_unfiltered (prefixed_name
, buf
);
7079 xfree (prefixed_name
);
7082 fputs_unfiltered (name
, buf
);
7084 /* Template parameters may be specified in the DIE's DW_AT_name, or
7085 as children with DW_TAG_template_type_param or
7086 DW_TAG_value_type_param. If the latter, add them to the name
7087 here. If the name already has template parameters, then
7088 skip this step; some versions of GCC emit both, and
7089 it is more efficient to use the pre-computed name.
7091 Something to keep in mind about this process: it is very
7092 unlikely, or in some cases downright impossible, to produce
7093 something that will match the mangled name of a function.
7094 If the definition of the function has the same debug info,
7095 we should be able to match up with it anyway. But fallbacks
7096 using the minimal symbol, for instance to find a method
7097 implemented in a stripped copy of libstdc++, will not work.
7098 If we do not have debug info for the definition, we will have to
7099 match them up some other way.
7101 When we do name matching there is a related problem with function
7102 templates; two instantiated function templates are allowed to
7103 differ only by their return types, which we do not add here. */
7105 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7107 struct attribute
*attr
;
7108 struct die_info
*child
;
7111 die
->building_fullname
= 1;
7113 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7118 struct dwarf2_locexpr_baton
*baton
;
7121 if (child
->tag
!= DW_TAG_template_type_param
7122 && child
->tag
!= DW_TAG_template_value_param
)
7127 fputs_unfiltered ("<", buf
);
7131 fputs_unfiltered (", ", buf
);
7133 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7136 complaint (&symfile_complaints
,
7137 _("template parameter missing DW_AT_type"));
7138 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7141 type
= die_type (child
, cu
);
7143 if (child
->tag
== DW_TAG_template_type_param
)
7145 c_print_type (type
, "", buf
, -1, 0);
7149 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7152 complaint (&symfile_complaints
,
7153 _("template parameter missing "
7154 "DW_AT_const_value"));
7155 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7159 dwarf2_const_value_attr (attr
, type
, name
,
7160 &cu
->comp_unit_obstack
, cu
,
7161 &value
, &bytes
, &baton
);
7163 if (TYPE_NOSIGN (type
))
7164 /* GDB prints characters as NUMBER 'CHAR'. If that's
7165 changed, this can use value_print instead. */
7166 c_printchar (value
, type
, buf
);
7169 struct value_print_options opts
;
7172 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7176 else if (bytes
!= NULL
)
7178 v
= allocate_value (type
);
7179 memcpy (value_contents_writeable (v
), bytes
,
7180 TYPE_LENGTH (type
));
7183 v
= value_from_longest (type
, value
);
7185 /* Specify decimal so that we do not depend on
7187 get_formatted_print_options (&opts
, 'd');
7189 value_print (v
, buf
, &opts
);
7195 die
->building_fullname
= 0;
7199 /* Close the argument list, with a space if necessary
7200 (nested templates). */
7201 char last_char
= '\0';
7202 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7203 if (last_char
== '>')
7204 fputs_unfiltered (" >", buf
);
7206 fputs_unfiltered (">", buf
);
7210 /* For Java and C++ methods, append formal parameter type
7211 information, if PHYSNAME. */
7213 if (physname
&& die
->tag
== DW_TAG_subprogram
7214 && (cu
->language
== language_cplus
7215 || cu
->language
== language_java
))
7217 struct type
*type
= read_type_die (die
, cu
);
7219 c_type_print_args (type
, buf
, 1, cu
->language
);
7221 if (cu
->language
== language_java
)
7223 /* For java, we must append the return type to method
7225 if (die
->tag
== DW_TAG_subprogram
)
7226 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7229 else if (cu
->language
== language_cplus
)
7231 /* Assume that an artificial first parameter is
7232 "this", but do not crash if it is not. RealView
7233 marks unnamed (and thus unused) parameters as
7234 artificial; there is no way to differentiate
7236 if (TYPE_NFIELDS (type
) > 0
7237 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7238 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7239 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7241 fputs_unfiltered (" const", buf
);
7245 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7247 ui_file_delete (buf
);
7249 if (cu
->language
== language_cplus
)
7252 = dwarf2_canonicalize_name (name
, cu
,
7253 &objfile
->objfile_obstack
);
7264 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7265 If scope qualifiers are appropriate they will be added. The result
7266 will be allocated on the objfile_obstack, or NULL if the DIE does
7267 not have a name. NAME may either be from a previous call to
7268 dwarf2_name or NULL.
7270 The output string will be canonicalized (if C++/Java). */
7273 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7275 return dwarf2_compute_name (name
, die
, cu
, 0);
7278 /* Construct a physname for the given DIE in CU. NAME may either be
7279 from a previous call to dwarf2_name or NULL. The result will be
7280 allocated on the objfile_objstack or NULL if the DIE does not have a
7283 The output string will be canonicalized (if C++/Java). */
7286 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7288 struct objfile
*objfile
= cu
->objfile
;
7289 struct attribute
*attr
;
7290 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7291 struct cleanup
*back_to
;
7294 /* In this case dwarf2_compute_name is just a shortcut not building anything
7296 if (!die_needs_namespace (die
, cu
))
7297 return dwarf2_compute_name (name
, die
, cu
, 1);
7299 back_to
= make_cleanup (null_cleanup
, NULL
);
7301 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7303 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7305 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7307 if (attr
&& DW_STRING (attr
))
7311 mangled
= DW_STRING (attr
);
7313 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7314 type. It is easier for GDB users to search for such functions as
7315 `name(params)' than `long name(params)'. In such case the minimal
7316 symbol names do not match the full symbol names but for template
7317 functions there is never a need to look up their definition from their
7318 declaration so the only disadvantage remains the minimal symbol
7319 variant `long name(params)' does not have the proper inferior type.
7322 if (cu
->language
== language_go
)
7324 /* This is a lie, but we already lie to the caller new_symbol_full.
7325 new_symbol_full assumes we return the mangled name.
7326 This just undoes that lie until things are cleaned up. */
7331 demangled
= cplus_demangle (mangled
,
7332 (DMGL_PARAMS
| DMGL_ANSI
7333 | (cu
->language
== language_java
7334 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7339 make_cleanup (xfree
, demangled
);
7349 if (canon
== NULL
|| check_physname
)
7351 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7353 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7355 /* It may not mean a bug in GDB. The compiler could also
7356 compute DW_AT_linkage_name incorrectly. But in such case
7357 GDB would need to be bug-to-bug compatible. */
7359 complaint (&symfile_complaints
,
7360 _("Computed physname <%s> does not match demangled <%s> "
7361 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7362 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7364 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7365 is available here - over computed PHYSNAME. It is safer
7366 against both buggy GDB and buggy compilers. */
7380 retval
= obsavestring (retval
, strlen (retval
),
7381 &objfile
->objfile_obstack
);
7383 do_cleanups (back_to
);
7387 /* Read the import statement specified by the given die and record it. */
7390 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7392 struct objfile
*objfile
= cu
->objfile
;
7393 struct attribute
*import_attr
;
7394 struct die_info
*imported_die
, *child_die
;
7395 struct dwarf2_cu
*imported_cu
;
7396 const char *imported_name
;
7397 const char *imported_name_prefix
;
7398 const char *canonical_name
;
7399 const char *import_alias
;
7400 const char *imported_declaration
= NULL
;
7401 const char *import_prefix
;
7402 VEC (const_char_ptr
) *excludes
= NULL
;
7403 struct cleanup
*cleanups
;
7407 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7408 if (import_attr
== NULL
)
7410 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7411 dwarf_tag_name (die
->tag
));
7416 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7417 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7418 if (imported_name
== NULL
)
7420 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7422 The import in the following code:
7436 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7437 <52> DW_AT_decl_file : 1
7438 <53> DW_AT_decl_line : 6
7439 <54> DW_AT_import : <0x75>
7440 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7442 <5b> DW_AT_decl_file : 1
7443 <5c> DW_AT_decl_line : 2
7444 <5d> DW_AT_type : <0x6e>
7446 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7447 <76> DW_AT_byte_size : 4
7448 <77> DW_AT_encoding : 5 (signed)
7450 imports the wrong die ( 0x75 instead of 0x58 ).
7451 This case will be ignored until the gcc bug is fixed. */
7455 /* Figure out the local name after import. */
7456 import_alias
= dwarf2_name (die
, cu
);
7458 /* Figure out where the statement is being imported to. */
7459 import_prefix
= determine_prefix (die
, cu
);
7461 /* Figure out what the scope of the imported die is and prepend it
7462 to the name of the imported die. */
7463 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7465 if (imported_die
->tag
!= DW_TAG_namespace
7466 && imported_die
->tag
!= DW_TAG_module
)
7468 imported_declaration
= imported_name
;
7469 canonical_name
= imported_name_prefix
;
7471 else if (strlen (imported_name_prefix
) > 0)
7473 temp
= alloca (strlen (imported_name_prefix
)
7474 + 2 + strlen (imported_name
) + 1);
7475 strcpy (temp
, imported_name_prefix
);
7476 strcat (temp
, "::");
7477 strcat (temp
, imported_name
);
7478 canonical_name
= temp
;
7481 canonical_name
= imported_name
;
7483 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7485 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7486 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7487 child_die
= sibling_die (child_die
))
7489 /* DWARF-4: A Fortran use statement with a “rename list” may be
7490 represented by an imported module entry with an import attribute
7491 referring to the module and owned entries corresponding to those
7492 entities that are renamed as part of being imported. */
7494 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7496 complaint (&symfile_complaints
,
7497 _("child DW_TAG_imported_declaration expected "
7498 "- DIE at 0x%x [in module %s]"),
7499 child_die
->offset
.sect_off
, objfile
->name
);
7503 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7504 if (import_attr
== NULL
)
7506 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7507 dwarf_tag_name (child_die
->tag
));
7512 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7514 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7515 if (imported_name
== NULL
)
7517 complaint (&symfile_complaints
,
7518 _("child DW_TAG_imported_declaration has unknown "
7519 "imported name - DIE at 0x%x [in module %s]"),
7520 child_die
->offset
.sect_off
, objfile
->name
);
7524 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7526 process_die (child_die
, cu
);
7529 cp_add_using_directive (import_prefix
,
7532 imported_declaration
,
7534 &objfile
->objfile_obstack
);
7536 do_cleanups (cleanups
);
7539 /* Cleanup function for handle_DW_AT_stmt_list. */
7542 free_cu_line_header (void *arg
)
7544 struct dwarf2_cu
*cu
= arg
;
7546 free_line_header (cu
->line_header
);
7547 cu
->line_header
= NULL
;
7551 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7552 char **name
, char **comp_dir
)
7554 struct attribute
*attr
;
7559 /* Find the filename. Do not use dwarf2_name here, since the filename
7560 is not a source language identifier. */
7561 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7564 *name
= DW_STRING (attr
);
7567 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7569 *comp_dir
= DW_STRING (attr
);
7570 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
7572 *comp_dir
= ldirname (*name
);
7573 if (*comp_dir
!= NULL
)
7574 make_cleanup (xfree
, *comp_dir
);
7576 if (*comp_dir
!= NULL
)
7578 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7579 directory, get rid of it. */
7580 char *cp
= strchr (*comp_dir
, ':');
7582 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7587 *name
= "<unknown>";
7590 /* Handle DW_AT_stmt_list for a compilation unit.
7591 DIE is the DW_TAG_compile_unit die for CU.
7592 COMP_DIR is the compilation directory.
7593 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7596 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7597 const char *comp_dir
)
7599 struct attribute
*attr
;
7601 gdb_assert (! cu
->per_cu
->is_debug_types
);
7603 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7606 unsigned int line_offset
= DW_UNSND (attr
);
7607 struct line_header
*line_header
7608 = dwarf_decode_line_header (line_offset
, cu
);
7612 cu
->line_header
= line_header
;
7613 make_cleanup (free_cu_line_header
, cu
);
7614 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7619 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7622 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7624 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7625 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7626 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7627 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7628 struct attribute
*attr
;
7630 char *comp_dir
= NULL
;
7631 struct die_info
*child_die
;
7632 bfd
*abfd
= objfile
->obfd
;
7635 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7637 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7639 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7640 from finish_block. */
7641 if (lowpc
== ((CORE_ADDR
) -1))
7646 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7648 prepare_one_comp_unit (cu
, die
, cu
->language
);
7650 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7651 standardised yet. As a workaround for the language detection we fall
7652 back to the DW_AT_producer string. */
7653 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7654 cu
->language
= language_opencl
;
7656 /* Similar hack for Go. */
7657 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7658 set_cu_language (DW_LANG_Go
, cu
);
7660 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7662 /* Decode line number information if present. We do this before
7663 processing child DIEs, so that the line header table is available
7664 for DW_AT_decl_file. */
7665 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7667 /* Process all dies in compilation unit. */
7668 if (die
->child
!= NULL
)
7670 child_die
= die
->child
;
7671 while (child_die
&& child_die
->tag
)
7673 process_die (child_die
, cu
);
7674 child_die
= sibling_die (child_die
);
7678 /* Decode macro information, if present. Dwarf 2 macro information
7679 refers to information in the line number info statement program
7680 header, so we can only read it if we've read the header
7682 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7683 if (attr
&& cu
->line_header
)
7685 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7686 complaint (&symfile_complaints
,
7687 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7689 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7693 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7694 if (attr
&& cu
->line_header
)
7696 unsigned int macro_offset
= DW_UNSND (attr
);
7698 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7702 do_cleanups (back_to
);
7705 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7706 Create the set of symtabs used by this TU, or if this TU is sharing
7707 symtabs with another TU and the symtabs have already been created
7708 then restore those symtabs in the line header.
7709 We don't need the pc/line-number mapping for type units. */
7712 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7714 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7715 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7716 struct type_unit_group
*tu_group
;
7718 struct line_header
*lh
;
7719 struct attribute
*attr
;
7720 unsigned int i
, line_offset
;
7722 gdb_assert (per_cu
->is_debug_types
);
7724 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7726 /* If we're using .gdb_index (includes -readnow) then
7727 per_cu->s.type_unit_group may not have been set up yet. */
7728 if (per_cu
->s
.type_unit_group
== NULL
)
7729 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
7730 tu_group
= per_cu
->s
.type_unit_group
;
7732 /* If we've already processed this stmt_list there's no real need to
7733 do it again, we could fake it and just recreate the part we need
7734 (file name,index -> symtab mapping). If data shows this optimization
7735 is useful we can do it then. */
7736 first_time
= tu_group
->primary_symtab
== NULL
;
7738 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7743 line_offset
= DW_UNSND (attr
);
7744 lh
= dwarf_decode_line_header (line_offset
, cu
);
7749 dwarf2_start_symtab (cu
, "", NULL
, 0);
7752 gdb_assert (tu_group
->symtabs
== NULL
);
7755 /* Note: The primary symtab will get allocated at the end. */
7759 cu
->line_header
= lh
;
7760 make_cleanup (free_cu_line_header
, cu
);
7764 dwarf2_start_symtab (cu
, "", NULL
, 0);
7766 tu_group
->num_symtabs
= lh
->num_file_names
;
7767 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
7769 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7772 struct file_entry
*fe
= &lh
->file_names
[i
];
7775 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7776 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
7778 /* Note: We don't have to watch for the main subfile here, type units
7779 don't have DW_AT_name. */
7781 if (current_subfile
->symtab
== NULL
)
7783 /* NOTE: start_subfile will recognize when it's been passed
7784 a file it has already seen. So we can't assume there's a
7785 simple mapping from lh->file_names to subfiles,
7786 lh->file_names may contain dups. */
7787 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7791 fe
->symtab
= current_subfile
->symtab
;
7792 tu_group
->symtabs
[i
] = fe
->symtab
;
7799 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7801 struct file_entry
*fe
= &lh
->file_names
[i
];
7803 fe
->symtab
= tu_group
->symtabs
[i
];
7807 /* The main symtab is allocated last. Type units don't have DW_AT_name
7808 so they don't have a "real" (so to speak) symtab anyway.
7809 There is later code that will assign the main symtab to all symbols
7810 that don't have one. We need to handle the case of a symbol with a
7811 missing symtab (DW_AT_decl_file) anyway. */
7814 /* Process DW_TAG_type_unit.
7815 For TUs we want to skip the first top level sibling if it's not the
7816 actual type being defined by this TU. In this case the first top
7817 level sibling is there to provide context only. */
7820 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7822 struct die_info
*child_die
;
7824 prepare_one_comp_unit (cu
, die
, language_minimal
);
7826 /* Initialize (or reinitialize) the machinery for building symtabs.
7827 We do this before processing child DIEs, so that the line header table
7828 is available for DW_AT_decl_file. */
7829 setup_type_unit_groups (die
, cu
);
7831 if (die
->child
!= NULL
)
7833 child_die
= die
->child
;
7834 while (child_die
&& child_die
->tag
)
7836 process_die (child_die
, cu
);
7837 child_die
= sibling_die (child_die
);
7845 hash_dwo_file (const void *item
)
7847 const struct dwo_file
*dwo_file
= item
;
7849 return htab_hash_string (dwo_file
->dwo_name
);
7853 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
7855 const struct dwo_file
*lhs
= item_lhs
;
7856 const struct dwo_file
*rhs
= item_rhs
;
7858 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
7861 /* Allocate a hash table for DWO files. */
7864 allocate_dwo_file_hash_table (void)
7866 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7868 return htab_create_alloc_ex (41,
7872 &objfile
->objfile_obstack
,
7873 hashtab_obstack_allocate
,
7874 dummy_obstack_deallocate
);
7878 hash_dwo_unit (const void *item
)
7880 const struct dwo_unit
*dwo_unit
= item
;
7882 /* This drops the top 32 bits of the id, but is ok for a hash. */
7883 return dwo_unit
->signature
;
7887 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
7889 const struct dwo_unit
*lhs
= item_lhs
;
7890 const struct dwo_unit
*rhs
= item_rhs
;
7892 /* The signature is assumed to be unique within the DWO file.
7893 So while object file CU dwo_id's always have the value zero,
7894 that's OK, assuming each object file DWO file has only one CU,
7895 and that's the rule for now. */
7896 return lhs
->signature
== rhs
->signature
;
7899 /* Allocate a hash table for DWO CUs,TUs.
7900 There is one of these tables for each of CUs,TUs for each DWO file. */
7903 allocate_dwo_unit_table (struct objfile
*objfile
)
7905 /* Start out with a pretty small number.
7906 Generally DWO files contain only one CU and maybe some TUs. */
7907 return htab_create_alloc_ex (3,
7911 &objfile
->objfile_obstack
,
7912 hashtab_obstack_allocate
,
7913 dummy_obstack_deallocate
);
7916 /* This function is mapped across the sections and remembers the offset and
7917 size of each of the DWO debugging sections we are interested in. */
7920 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
7922 struct dwo_file
*dwo_file
= dwo_file_ptr
;
7923 const struct dwo_section_names
*names
= &dwo_section_names
;
7925 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
7927 dwo_file
->sections
.abbrev
.asection
= sectp
;
7928 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
7930 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
7932 dwo_file
->sections
.info
.asection
= sectp
;
7933 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
7935 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
7937 dwo_file
->sections
.line
.asection
= sectp
;
7938 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
7940 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
7942 dwo_file
->sections
.loc
.asection
= sectp
;
7943 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
7945 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
7947 dwo_file
->sections
.macinfo
.asection
= sectp
;
7948 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
7950 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
7952 dwo_file
->sections
.macro
.asection
= sectp
;
7953 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
7955 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
7957 dwo_file
->sections
.str
.asection
= sectp
;
7958 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
7960 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
7962 dwo_file
->sections
.str_offsets
.asection
= sectp
;
7963 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
7965 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
7967 struct dwarf2_section_info type_section
;
7969 memset (&type_section
, 0, sizeof (type_section
));
7970 type_section
.asection
= sectp
;
7971 type_section
.size
= bfd_get_section_size (sectp
);
7972 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7977 /* Structure used to pass data to create_debug_info_hash_table_reader. */
7979 struct create_dwo_info_table_data
7981 struct dwo_file
*dwo_file
;
7985 /* die_reader_func for create_debug_info_hash_table. */
7988 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
7990 struct die_info
*comp_unit_die
,
7994 struct dwarf2_cu
*cu
= reader
->cu
;
7995 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7996 sect_offset offset
= cu
->per_cu
->offset
;
7997 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
7998 struct create_dwo_info_table_data
*data
= datap
;
7999 struct dwo_file
*dwo_file
= data
->dwo_file
;
8000 htab_t cu_htab
= data
->cu_htab
;
8002 struct attribute
*attr
;
8003 struct dwo_unit
*dwo_unit
;
8005 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8008 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8009 " its dwo_id [in module %s]"),
8010 offset
.sect_off
, dwo_file
->dwo_name
);
8014 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8015 dwo_unit
->dwo_file
= dwo_file
;
8016 dwo_unit
->signature
= DW_UNSND (attr
);
8017 dwo_unit
->info_or_types_section
= section
;
8018 dwo_unit
->offset
= offset
;
8019 dwo_unit
->length
= cu
->per_cu
->length
;
8021 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8022 gdb_assert (slot
!= NULL
);
8025 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8027 complaint (&symfile_complaints
,
8028 _("debug entry at offset 0x%x is duplicate to the entry at"
8029 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8030 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8031 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8032 dwo_file
->dwo_name
);
8037 if (dwarf2_read_debug
)
8038 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8040 phex (dwo_unit
->signature
,
8041 sizeof (dwo_unit
->signature
)));
8044 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
8047 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
8049 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8050 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8053 gdb_byte
*info_ptr
, *end_ptr
;
8054 struct create_dwo_info_table_data create_dwo_info_table_data
;
8056 dwarf2_read_section (objfile
, section
);
8057 info_ptr
= section
->buffer
;
8059 if (info_ptr
== NULL
)
8062 /* We can't set abfd until now because the section may be empty or
8063 not present, in which case section->asection will be NULL. */
8064 abfd
= section
->asection
->owner
;
8066 if (dwarf2_read_debug
)
8067 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8068 bfd_get_filename (abfd
));
8070 cu_htab
= allocate_dwo_unit_table (objfile
);
8072 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8073 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8075 end_ptr
= info_ptr
+ section
->size
;
8076 while (info_ptr
< end_ptr
)
8078 struct dwarf2_per_cu_data per_cu
;
8080 memset (&per_cu
, 0, sizeof (per_cu
));
8081 per_cu
.objfile
= objfile
;
8082 per_cu
.is_debug_types
= 0;
8083 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8084 per_cu
.info_or_types_section
= section
;
8086 init_cutu_and_read_dies_no_follow (&per_cu
,
8087 &dwo_file
->sections
.abbrev
,
8089 create_debug_info_hash_table_reader
,
8090 &create_dwo_info_table_data
);
8092 info_ptr
+= per_cu
.length
;
8098 /* Subroutine of open_dwo_file to simplify it.
8099 Open the file specified by FILE_NAME and hand it off to BFD for
8100 preliminary analysis. Return a newly initialized bfd *, which
8101 includes a canonicalized copy of FILE_NAME.
8102 In case of trouble, return NULL.
8103 NOTE: This function is derived from symfile_bfd_open. */
8106 try_open_dwo_file (const char *file_name
)
8110 char *absolute_name
;
8112 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
8113 O_RDONLY
| O_BINARY
, &absolute_name
);
8117 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
8120 xfree (absolute_name
);
8123 bfd_set_cacheable (sym_bfd
, 1);
8125 if (!bfd_check_format (sym_bfd
, bfd_object
))
8127 bfd_close (sym_bfd
); /* This also closes desc. */
8128 xfree (absolute_name
);
8132 /* bfd_usrdata exists for applications and libbfd must not touch it. */
8133 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
8138 /* Try to open DWO file DWO_NAME.
8139 COMP_DIR is the DW_AT_comp_dir attribute.
8140 The result is the bfd handle of the file.
8141 If there is a problem finding or opening the file, return NULL.
8142 Upon success, the canonicalized path of the file is stored in the bfd,
8143 same as symfile_bfd_open. */
8146 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
8150 if (IS_ABSOLUTE_PATH (dwo_name
))
8151 return try_open_dwo_file (dwo_name
);
8153 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8155 if (comp_dir
!= NULL
)
8157 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
8159 /* NOTE: If comp_dir is a relative path, this will also try the
8160 search path, which seems useful. */
8161 abfd
= try_open_dwo_file (path_to_try
);
8162 xfree (path_to_try
);
8167 /* That didn't work, try debug-file-directory, which, despite its name,
8168 is a list of paths. */
8170 if (*debug_file_directory
== '\0')
8173 return try_open_dwo_file (dwo_name
);
8176 /* Initialize the use of the DWO file specified by DWO_NAME. */
8178 static struct dwo_file
*
8179 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8181 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8182 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8185 struct cleanup
*cleanups
;
8187 if (dwarf2_read_debug
)
8188 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
8190 abfd
= open_dwo_file (dwo_name
, comp_dir
);
8193 dwo_file
->dwo_name
= dwo_name
;
8194 dwo_file
->dwo_bfd
= abfd
;
8196 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8198 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
8200 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
8202 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8203 dwo_file
->sections
.types
);
8205 discard_cleanups (cleanups
);
8210 /* Lookup DWO file DWO_NAME. */
8212 static struct dwo_file
*
8213 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
8215 struct dwo_file
*dwo_file
;
8216 struct dwo_file find_entry
;
8219 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8220 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8222 /* Have we already seen this DWO file? */
8223 find_entry
.dwo_name
= dwo_name
;
8224 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8226 /* If not, read it in and build a table of the DWOs it contains. */
8228 *slot
= init_dwo_file (dwo_name
, comp_dir
);
8230 /* NOTE: This will be NULL if unable to open the file. */
8236 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
8237 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8238 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
8239 nomenclature as TUs).
8240 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8241 (dwo_id mismatch or couldn't find the DWO file). */
8243 static struct dwo_unit
*
8244 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8245 char *dwo_name
, const char *comp_dir
,
8248 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8249 struct dwo_file
*dwo_file
;
8251 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8252 if (dwo_file
== NULL
)
8255 /* Look up the DWO using its signature(dwo_id). */
8257 if (dwo_file
->cus
!= NULL
)
8259 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8261 find_dwo_cu
.signature
= signature
;
8262 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
8268 /* We didn't find it. This must mean a dwo_id mismatch. */
8270 complaint (&symfile_complaints
,
8271 _("Could not find DWO CU referenced by CU at offset 0x%x"
8273 this_cu
->offset
.sect_off
, objfile
->name
);
8277 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
8278 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8279 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8280 (dwo_id mismatch or couldn't find the DWO file). */
8282 static struct dwo_unit
*
8283 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
8284 char *dwo_name
, const char *comp_dir
)
8286 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8287 struct dwo_file
*dwo_file
;
8289 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8290 if (dwo_file
== NULL
)
8293 /* Look up the DWO using its signature(dwo_id). */
8295 if (dwo_file
->tus
!= NULL
)
8297 struct dwo_unit find_dwo_tu
, *dwo_tu
;
8299 find_dwo_tu
.signature
= this_tu
->signature
;
8300 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
8306 /* We didn't find it. This must mean a dwo_id mismatch. */
8308 complaint (&symfile_complaints
,
8309 _("Could not find DWO TU referenced by TU at offset 0x%x"
8311 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
8315 /* Free all resources associated with DWO_FILE.
8316 Close the DWO file and munmap the sections.
8317 All memory should be on the objfile obstack. */
8320 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
8323 struct dwarf2_section_info
*section
;
8325 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
8326 bfd_close (dwo_file
->dwo_bfd
);
8328 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
8329 munmap_section_buffer (&dwo_file
->sections
.info
);
8330 munmap_section_buffer (&dwo_file
->sections
.line
);
8331 munmap_section_buffer (&dwo_file
->sections
.loc
);
8332 munmap_section_buffer (&dwo_file
->sections
.str
);
8333 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
8336 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
8339 munmap_section_buffer (section
);
8341 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
8344 /* Wrapper for free_dwo_file for use in cleanups. */
8347 free_dwo_file_cleanup (void *arg
)
8349 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
8350 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8352 free_dwo_file (dwo_file
, objfile
);
8355 /* Traversal function for free_dwo_files. */
8358 free_dwo_file_from_slot (void **slot
, void *info
)
8360 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8361 struct objfile
*objfile
= (struct objfile
*) info
;
8363 free_dwo_file (dwo_file
, objfile
);
8368 /* Free all resources associated with DWO_FILES. */
8371 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
8373 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
8376 /* Read in various DIEs. */
8378 /* qsort helper for inherit_abstract_dies. */
8381 unsigned_int_compar (const void *ap
, const void *bp
)
8383 unsigned int a
= *(unsigned int *) ap
;
8384 unsigned int b
= *(unsigned int *) bp
;
8386 return (a
> b
) - (b
> a
);
8389 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
8390 Inherit only the children of the DW_AT_abstract_origin DIE not being
8391 already referenced by DW_AT_abstract_origin from the children of the
8395 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
8397 struct die_info
*child_die
;
8398 unsigned die_children_count
;
8399 /* CU offsets which were referenced by children of the current DIE. */
8400 sect_offset
*offsets
;
8401 sect_offset
*offsets_end
, *offsetp
;
8402 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
8403 struct die_info
*origin_die
;
8404 /* Iterator of the ORIGIN_DIE children. */
8405 struct die_info
*origin_child_die
;
8406 struct cleanup
*cleanups
;
8407 struct attribute
*attr
;
8408 struct dwarf2_cu
*origin_cu
;
8409 struct pending
**origin_previous_list_in_scope
;
8411 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8415 /* Note that following die references may follow to a die in a
8419 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
8421 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
8423 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
8424 origin_cu
->list_in_scope
= cu
->list_in_scope
;
8426 if (die
->tag
!= origin_die
->tag
8427 && !(die
->tag
== DW_TAG_inlined_subroutine
8428 && origin_die
->tag
== DW_TAG_subprogram
))
8429 complaint (&symfile_complaints
,
8430 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
8431 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
8433 child_die
= die
->child
;
8434 die_children_count
= 0;
8435 while (child_die
&& child_die
->tag
)
8437 child_die
= sibling_die (child_die
);
8438 die_children_count
++;
8440 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
8441 cleanups
= make_cleanup (xfree
, offsets
);
8443 offsets_end
= offsets
;
8444 child_die
= die
->child
;
8445 while (child_die
&& child_die
->tag
)
8447 /* For each CHILD_DIE, find the corresponding child of
8448 ORIGIN_DIE. If there is more than one layer of
8449 DW_AT_abstract_origin, follow them all; there shouldn't be,
8450 but GCC versions at least through 4.4 generate this (GCC PR
8452 struct die_info
*child_origin_die
= child_die
;
8453 struct dwarf2_cu
*child_origin_cu
= cu
;
8457 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
8461 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
8465 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
8466 counterpart may exist. */
8467 if (child_origin_die
!= child_die
)
8469 if (child_die
->tag
!= child_origin_die
->tag
8470 && !(child_die
->tag
== DW_TAG_inlined_subroutine
8471 && child_origin_die
->tag
== DW_TAG_subprogram
))
8472 complaint (&symfile_complaints
,
8473 _("Child DIE 0x%x and its abstract origin 0x%x have "
8474 "different tags"), child_die
->offset
.sect_off
,
8475 child_origin_die
->offset
.sect_off
);
8476 if (child_origin_die
->parent
!= origin_die
)
8477 complaint (&symfile_complaints
,
8478 _("Child DIE 0x%x and its abstract origin 0x%x have "
8479 "different parents"), child_die
->offset
.sect_off
,
8480 child_origin_die
->offset
.sect_off
);
8482 *offsets_end
++ = child_origin_die
->offset
;
8484 child_die
= sibling_die (child_die
);
8486 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
8487 unsigned_int_compar
);
8488 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
8489 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
8490 complaint (&symfile_complaints
,
8491 _("Multiple children of DIE 0x%x refer "
8492 "to DIE 0x%x as their abstract origin"),
8493 die
->offset
.sect_off
, offsetp
->sect_off
);
8496 origin_child_die
= origin_die
->child
;
8497 while (origin_child_die
&& origin_child_die
->tag
)
8499 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
8500 while (offsetp
< offsets_end
8501 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
8503 if (offsetp
>= offsets_end
8504 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
8506 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
8507 process_die (origin_child_die
, origin_cu
);
8509 origin_child_die
= sibling_die (origin_child_die
);
8511 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
8513 do_cleanups (cleanups
);
8517 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8519 struct objfile
*objfile
= cu
->objfile
;
8520 struct context_stack
*new;
8523 struct die_info
*child_die
;
8524 struct attribute
*attr
, *call_line
, *call_file
;
8527 struct block
*block
;
8528 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8529 VEC (symbolp
) *template_args
= NULL
;
8530 struct template_symbol
*templ_func
= NULL
;
8534 /* If we do not have call site information, we can't show the
8535 caller of this inlined function. That's too confusing, so
8536 only use the scope for local variables. */
8537 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
8538 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
8539 if (call_line
== NULL
|| call_file
== NULL
)
8541 read_lexical_block_scope (die
, cu
);
8546 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8548 name
= dwarf2_name (die
, cu
);
8550 /* Ignore functions with missing or empty names. These are actually
8551 illegal according to the DWARF standard. */
8554 complaint (&symfile_complaints
,
8555 _("missing name for subprogram DIE at %d"),
8556 die
->offset
.sect_off
);
8560 /* Ignore functions with missing or invalid low and high pc attributes. */
8561 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8563 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8564 if (!attr
|| !DW_UNSND (attr
))
8565 complaint (&symfile_complaints
,
8566 _("cannot get low and high bounds "
8567 "for subprogram DIE at %d"),
8568 die
->offset
.sect_off
);
8575 /* If we have any template arguments, then we must allocate a
8576 different sort of symbol. */
8577 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
8579 if (child_die
->tag
== DW_TAG_template_type_param
8580 || child_die
->tag
== DW_TAG_template_value_param
)
8582 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8583 struct template_symbol
);
8584 templ_func
->base
.is_cplus_template_function
= 1;
8589 new = push_context (0, lowpc
);
8590 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
8591 (struct symbol
*) templ_func
);
8593 /* If there is a location expression for DW_AT_frame_base, record
8595 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
8597 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
8598 expression is being recorded directly in the function's symbol
8599 and not in a separate frame-base object. I guess this hack is
8600 to avoid adding some sort of frame-base adjunct/annex to the
8601 function's symbol :-(. The problem with doing this is that it
8602 results in a function symbol with a location expression that
8603 has nothing to do with the location of the function, ouch! The
8604 relationship should be: a function's symbol has-a frame base; a
8605 frame-base has-a location expression. */
8606 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
8608 cu
->list_in_scope
= &local_symbols
;
8610 if (die
->child
!= NULL
)
8612 child_die
= die
->child
;
8613 while (child_die
&& child_die
->tag
)
8615 if (child_die
->tag
== DW_TAG_template_type_param
8616 || child_die
->tag
== DW_TAG_template_value_param
)
8618 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8621 VEC_safe_push (symbolp
, template_args
, arg
);
8624 process_die (child_die
, cu
);
8625 child_die
= sibling_die (child_die
);
8629 inherit_abstract_dies (die
, cu
);
8631 /* If we have a DW_AT_specification, we might need to import using
8632 directives from the context of the specification DIE. See the
8633 comment in determine_prefix. */
8634 if (cu
->language
== language_cplus
8635 && dwarf2_attr (die
, DW_AT_specification
, cu
))
8637 struct dwarf2_cu
*spec_cu
= cu
;
8638 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
8642 child_die
= spec_die
->child
;
8643 while (child_die
&& child_die
->tag
)
8645 if (child_die
->tag
== DW_TAG_imported_module
)
8646 process_die (child_die
, spec_cu
);
8647 child_die
= sibling_die (child_die
);
8650 /* In some cases, GCC generates specification DIEs that
8651 themselves contain DW_AT_specification attributes. */
8652 spec_die
= die_specification (spec_die
, &spec_cu
);
8656 new = pop_context ();
8657 /* Make a block for the local symbols within. */
8658 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
8659 lowpc
, highpc
, objfile
);
8661 /* For C++, set the block's scope. */
8662 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
8663 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
8664 determine_prefix (die
, cu
),
8665 processing_has_namespace_info
);
8667 /* If we have address ranges, record them. */
8668 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8670 /* Attach template arguments to function. */
8671 if (! VEC_empty (symbolp
, template_args
))
8673 gdb_assert (templ_func
!= NULL
);
8675 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
8676 templ_func
->template_arguments
8677 = obstack_alloc (&objfile
->objfile_obstack
,
8678 (templ_func
->n_template_arguments
8679 * sizeof (struct symbol
*)));
8680 memcpy (templ_func
->template_arguments
,
8681 VEC_address (symbolp
, template_args
),
8682 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
8683 VEC_free (symbolp
, template_args
);
8686 /* In C++, we can have functions nested inside functions (e.g., when
8687 a function declares a class that has methods). This means that
8688 when we finish processing a function scope, we may need to go
8689 back to building a containing block's symbol lists. */
8690 local_symbols
= new->locals
;
8691 param_symbols
= new->params
;
8692 using_directives
= new->using_directives
;
8694 /* If we've finished processing a top-level function, subsequent
8695 symbols go in the file symbol list. */
8696 if (outermost_context_p ())
8697 cu
->list_in_scope
= &file_symbols
;
8700 /* Process all the DIES contained within a lexical block scope. Start
8701 a new scope, process the dies, and then close the scope. */
8704 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8706 struct objfile
*objfile
= cu
->objfile
;
8707 struct context_stack
*new;
8708 CORE_ADDR lowpc
, highpc
;
8709 struct die_info
*child_die
;
8712 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8714 /* Ignore blocks with missing or invalid low and high pc attributes. */
8715 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
8716 as multiple lexical blocks? Handling children in a sane way would
8717 be nasty. Might be easier to properly extend generic blocks to
8719 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8724 push_context (0, lowpc
);
8725 if (die
->child
!= NULL
)
8727 child_die
= die
->child
;
8728 while (child_die
&& child_die
->tag
)
8730 process_die (child_die
, cu
);
8731 child_die
= sibling_die (child_die
);
8734 new = pop_context ();
8736 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
8739 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
8742 /* Note that recording ranges after traversing children, as we
8743 do here, means that recording a parent's ranges entails
8744 walking across all its children's ranges as they appear in
8745 the address map, which is quadratic behavior.
8747 It would be nicer to record the parent's ranges before
8748 traversing its children, simply overriding whatever you find
8749 there. But since we don't even decide whether to create a
8750 block until after we've traversed its children, that's hard
8752 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8754 local_symbols
= new->locals
;
8755 using_directives
= new->using_directives
;
8758 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
8761 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8763 struct objfile
*objfile
= cu
->objfile
;
8764 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8765 CORE_ADDR pc
, baseaddr
;
8766 struct attribute
*attr
;
8767 struct call_site
*call_site
, call_site_local
;
8770 struct die_info
*child_die
;
8772 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8774 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8777 complaint (&symfile_complaints
,
8778 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
8779 "DIE 0x%x [in module %s]"),
8780 die
->offset
.sect_off
, objfile
->name
);
8783 pc
= DW_ADDR (attr
) + baseaddr
;
8785 if (cu
->call_site_htab
== NULL
)
8786 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
8787 NULL
, &objfile
->objfile_obstack
,
8788 hashtab_obstack_allocate
, NULL
);
8789 call_site_local
.pc
= pc
;
8790 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
8793 complaint (&symfile_complaints
,
8794 _("Duplicate PC %s for DW_TAG_GNU_call_site "
8795 "DIE 0x%x [in module %s]"),
8796 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
8800 /* Count parameters at the caller. */
8803 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8804 child_die
= sibling_die (child_die
))
8806 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8808 complaint (&symfile_complaints
,
8809 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
8810 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8811 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
8818 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
8819 (sizeof (*call_site
)
8820 + (sizeof (*call_site
->parameter
)
8823 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
8826 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
8828 struct die_info
*func_die
;
8830 /* Skip also over DW_TAG_inlined_subroutine. */
8831 for (func_die
= die
->parent
;
8832 func_die
&& func_die
->tag
!= DW_TAG_subprogram
8833 && func_die
->tag
!= DW_TAG_subroutine_type
;
8834 func_die
= func_die
->parent
);
8836 /* DW_AT_GNU_all_call_sites is a superset
8837 of DW_AT_GNU_all_tail_call_sites. */
8839 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
8840 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
8842 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
8843 not complete. But keep CALL_SITE for look ups via call_site_htab,
8844 both the initial caller containing the real return address PC and
8845 the final callee containing the current PC of a chain of tail
8846 calls do not need to have the tail call list complete. But any
8847 function candidate for a virtual tail call frame searched via
8848 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
8849 determined unambiguously. */
8853 struct type
*func_type
= NULL
;
8856 func_type
= get_die_type (func_die
, cu
);
8857 if (func_type
!= NULL
)
8859 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
8861 /* Enlist this call site to the function. */
8862 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
8863 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
8866 complaint (&symfile_complaints
,
8867 _("Cannot find function owning DW_TAG_GNU_call_site "
8868 "DIE 0x%x [in module %s]"),
8869 die
->offset
.sect_off
, objfile
->name
);
8873 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
8875 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8876 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
8877 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
8878 /* Keep NULL DWARF_BLOCK. */;
8879 else if (attr_form_is_block (attr
))
8881 struct dwarf2_locexpr_baton
*dlbaton
;
8883 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
8884 dlbaton
->data
= DW_BLOCK (attr
)->data
;
8885 dlbaton
->size
= DW_BLOCK (attr
)->size
;
8886 dlbaton
->per_cu
= cu
->per_cu
;
8888 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
8890 else if (is_ref_attr (attr
))
8892 struct dwarf2_cu
*target_cu
= cu
;
8893 struct die_info
*target_die
;
8895 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
8896 gdb_assert (target_cu
->objfile
== objfile
);
8897 if (die_is_declaration (target_die
, target_cu
))
8899 const char *target_physname
;
8901 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
8902 if (target_physname
== NULL
)
8903 complaint (&symfile_complaints
,
8904 _("DW_AT_GNU_call_site_target target DIE has invalid "
8905 "physname, for referencing DIE 0x%x [in module %s]"),
8906 die
->offset
.sect_off
, objfile
->name
);
8908 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
8914 /* DW_AT_entry_pc should be preferred. */
8915 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
8916 complaint (&symfile_complaints
,
8917 _("DW_AT_GNU_call_site_target target DIE has invalid "
8918 "low pc, for referencing DIE 0x%x [in module %s]"),
8919 die
->offset
.sect_off
, objfile
->name
);
8921 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
8925 complaint (&symfile_complaints
,
8926 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
8927 "block nor reference, for DIE 0x%x [in module %s]"),
8928 die
->offset
.sect_off
, objfile
->name
);
8930 call_site
->per_cu
= cu
->per_cu
;
8932 for (child_die
= die
->child
;
8933 child_die
&& child_die
->tag
;
8934 child_die
= sibling_die (child_die
))
8936 struct call_site_parameter
*parameter
;
8937 struct attribute
*loc
, *origin
;
8939 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8941 /* Already printed the complaint above. */
8945 gdb_assert (call_site
->parameter_count
< nparams
);
8946 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
8948 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
8949 specifies DW_TAG_formal_parameter. Value of the data assumed for the
8950 register is contained in DW_AT_GNU_call_site_value. */
8952 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
8953 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
8954 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
8958 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
8959 offset
= dwarf2_get_ref_die_offset (origin
);
8960 if (!offset_in_cu_p (&cu
->header
, offset
))
8962 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
8963 binding can be done only inside one CU. Such referenced DIE
8964 therefore cannot be even moved to DW_TAG_partial_unit. */
8965 complaint (&symfile_complaints
,
8966 _("DW_AT_abstract_origin offset is not in CU for "
8967 "DW_TAG_GNU_call_site child DIE 0x%x "
8969 child_die
->offset
.sect_off
, objfile
->name
);
8972 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
8973 - cu
->header
.offset
.sect_off
);
8975 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
8977 complaint (&symfile_complaints
,
8978 _("No DW_FORM_block* DW_AT_location for "
8979 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8980 child_die
->offset
.sect_off
, objfile
->name
);
8985 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
8986 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
8987 if (parameter
->u
.dwarf_reg
!= -1)
8988 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
8989 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
8990 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
8991 ¶meter
->u
.fb_offset
))
8992 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
8995 complaint (&symfile_complaints
,
8996 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
8997 "for DW_FORM_block* DW_AT_location is supported for "
8998 "DW_TAG_GNU_call_site child DIE 0x%x "
9000 child_die
->offset
.sect_off
, objfile
->name
);
9005 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9006 if (!attr_form_is_block (attr
))
9008 complaint (&symfile_complaints
,
9009 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9010 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9011 child_die
->offset
.sect_off
, objfile
->name
);
9014 parameter
->value
= DW_BLOCK (attr
)->data
;
9015 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9017 /* Parameters are not pre-cleared by memset above. */
9018 parameter
->data_value
= NULL
;
9019 parameter
->data_value_size
= 0;
9020 call_site
->parameter_count
++;
9022 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9025 if (!attr_form_is_block (attr
))
9026 complaint (&symfile_complaints
,
9027 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9028 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9029 child_die
->offset
.sect_off
, objfile
->name
);
9032 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9033 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9039 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9040 Return 1 if the attributes are present and valid, otherwise, return 0.
9041 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9044 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9045 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9046 struct partial_symtab
*ranges_pst
)
9048 struct objfile
*objfile
= cu
->objfile
;
9049 struct comp_unit_head
*cu_header
= &cu
->header
;
9050 bfd
*obfd
= objfile
->obfd
;
9051 unsigned int addr_size
= cu_header
->addr_size
;
9052 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9053 /* Base address selection entry. */
9064 found_base
= cu
->base_known
;
9065 base
= cu
->base_address
;
9067 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9068 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9070 complaint (&symfile_complaints
,
9071 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9075 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9077 /* Read in the largest possible address. */
9078 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9079 if ((marker
& mask
) == mask
)
9081 /* If we found the largest possible address, then
9082 read the base address. */
9083 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9084 buffer
+= 2 * addr_size
;
9085 offset
+= 2 * addr_size
;
9091 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9095 CORE_ADDR range_beginning
, range_end
;
9097 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9098 buffer
+= addr_size
;
9099 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9100 buffer
+= addr_size
;
9101 offset
+= 2 * addr_size
;
9103 /* An end of list marker is a pair of zero addresses. */
9104 if (range_beginning
== 0 && range_end
== 0)
9105 /* Found the end of list entry. */
9108 /* Each base address selection entry is a pair of 2 values.
9109 The first is the largest possible address, the second is
9110 the base address. Check for a base address here. */
9111 if ((range_beginning
& mask
) == mask
)
9113 /* If we found the largest possible address, then
9114 read the base address. */
9115 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9122 /* We have no valid base address for the ranges
9124 complaint (&symfile_complaints
,
9125 _("Invalid .debug_ranges data (no base address)"));
9129 if (range_beginning
> range_end
)
9131 /* Inverted range entries are invalid. */
9132 complaint (&symfile_complaints
,
9133 _("Invalid .debug_ranges data (inverted range)"));
9137 /* Empty range entries have no effect. */
9138 if (range_beginning
== range_end
)
9141 range_beginning
+= base
;
9144 if (ranges_pst
!= NULL
)
9145 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9146 range_beginning
+ baseaddr
,
9147 range_end
- 1 + baseaddr
,
9150 /* FIXME: This is recording everything as a low-high
9151 segment of consecutive addresses. We should have a
9152 data structure for discontiguous block ranges
9156 low
= range_beginning
;
9162 if (range_beginning
< low
)
9163 low
= range_beginning
;
9164 if (range_end
> high
)
9170 /* If the first entry is an end-of-list marker, the range
9171 describes an empty scope, i.e. no instructions. */
9177 *high_return
= high
;
9181 /* Get low and high pc attributes from a die. Return 1 if the attributes
9182 are present and valid, otherwise, return 0. Return -1 if the range is
9183 discontinuous, i.e. derived from DW_AT_ranges information. */
9186 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
9187 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
9188 struct partial_symtab
*pst
)
9190 struct attribute
*attr
;
9191 struct attribute
*attr_high
;
9196 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9199 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9202 low
= DW_ADDR (attr
);
9203 if (attr_high
->form
== DW_FORM_addr
9204 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9205 high
= DW_ADDR (attr_high
);
9207 high
= low
+ DW_UNSND (attr_high
);
9210 /* Found high w/o low attribute. */
9213 /* Found consecutive range of addresses. */
9218 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9221 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9223 /* Value of the DW_AT_ranges attribute is the offset in the
9224 .debug_ranges section. */
9225 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
9227 /* Found discontinuous range of addresses. */
9232 /* read_partial_die has also the strict LOW < HIGH requirement. */
9236 /* When using the GNU linker, .gnu.linkonce. sections are used to
9237 eliminate duplicate copies of functions and vtables and such.
9238 The linker will arbitrarily choose one and discard the others.
9239 The AT_*_pc values for such functions refer to local labels in
9240 these sections. If the section from that file was discarded, the
9241 labels are not in the output, so the relocs get a value of 0.
9242 If this is a discarded function, mark the pc bounds as invalid,
9243 so that GDB will ignore it. */
9244 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9253 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
9254 its low and high PC addresses. Do nothing if these addresses could not
9255 be determined. Otherwise, set LOWPC to the low address if it is smaller,
9256 and HIGHPC to the high address if greater than HIGHPC. */
9259 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
9260 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9261 struct dwarf2_cu
*cu
)
9263 CORE_ADDR low
, high
;
9264 struct die_info
*child
= die
->child
;
9266 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
9268 *lowpc
= min (*lowpc
, low
);
9269 *highpc
= max (*highpc
, high
);
9272 /* If the language does not allow nested subprograms (either inside
9273 subprograms or lexical blocks), we're done. */
9274 if (cu
->language
!= language_ada
)
9277 /* Check all the children of the given DIE. If it contains nested
9278 subprograms, then check their pc bounds. Likewise, we need to
9279 check lexical blocks as well, as they may also contain subprogram
9281 while (child
&& child
->tag
)
9283 if (child
->tag
== DW_TAG_subprogram
9284 || child
->tag
== DW_TAG_lexical_block
)
9285 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
9286 child
= sibling_die (child
);
9290 /* Get the low and high pc's represented by the scope DIE, and store
9291 them in *LOWPC and *HIGHPC. If the correct values can't be
9292 determined, set *LOWPC to -1 and *HIGHPC to 0. */
9295 get_scope_pc_bounds (struct die_info
*die
,
9296 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9297 struct dwarf2_cu
*cu
)
9299 CORE_ADDR best_low
= (CORE_ADDR
) -1;
9300 CORE_ADDR best_high
= (CORE_ADDR
) 0;
9301 CORE_ADDR current_low
, current_high
;
9303 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
9305 best_low
= current_low
;
9306 best_high
= current_high
;
9310 struct die_info
*child
= die
->child
;
9312 while (child
&& child
->tag
)
9314 switch (child
->tag
) {
9315 case DW_TAG_subprogram
:
9316 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
9318 case DW_TAG_namespace
:
9320 /* FIXME: carlton/2004-01-16: Should we do this for
9321 DW_TAG_class_type/DW_TAG_structure_type, too? I think
9322 that current GCC's always emit the DIEs corresponding
9323 to definitions of methods of classes as children of a
9324 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
9325 the DIEs giving the declarations, which could be
9326 anywhere). But I don't see any reason why the
9327 standards says that they have to be there. */
9328 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
9330 if (current_low
!= ((CORE_ADDR
) -1))
9332 best_low
= min (best_low
, current_low
);
9333 best_high
= max (best_high
, current_high
);
9341 child
= sibling_die (child
);
9346 *highpc
= best_high
;
9349 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
9353 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
9354 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
9356 struct objfile
*objfile
= cu
->objfile
;
9357 struct attribute
*attr
;
9358 struct attribute
*attr_high
;
9360 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9363 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9366 CORE_ADDR low
= DW_ADDR (attr
);
9368 if (attr_high
->form
== DW_FORM_addr
9369 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9370 high
= DW_ADDR (attr_high
);
9372 high
= low
+ DW_UNSND (attr_high
);
9374 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
9378 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9381 bfd
*obfd
= objfile
->obfd
;
9383 /* The value of the DW_AT_ranges attribute is the offset of the
9384 address range list in the .debug_ranges section. */
9385 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9386 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9388 /* For some target architectures, but not others, the
9389 read_address function sign-extends the addresses it returns.
9390 To recognize base address selection entries, we need a
9392 unsigned int addr_size
= cu
->header
.addr_size
;
9393 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9395 /* The base address, to which the next pair is relative. Note
9396 that this 'base' is a DWARF concept: most entries in a range
9397 list are relative, to reduce the number of relocs against the
9398 debugging information. This is separate from this function's
9399 'baseaddr' argument, which GDB uses to relocate debugging
9400 information from a shared library based on the address at
9401 which the library was loaded. */
9402 CORE_ADDR base
= cu
->base_address
;
9403 int base_known
= cu
->base_known
;
9405 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
9406 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9408 complaint (&symfile_complaints
,
9409 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
9416 unsigned int bytes_read
;
9417 CORE_ADDR start
, end
;
9419 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9420 buffer
+= bytes_read
;
9421 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9422 buffer
+= bytes_read
;
9424 /* Did we find the end of the range list? */
9425 if (start
== 0 && end
== 0)
9428 /* Did we find a base address selection entry? */
9429 else if ((start
& base_select_mask
) == base_select_mask
)
9435 /* We found an ordinary address range. */
9440 complaint (&symfile_complaints
,
9441 _("Invalid .debug_ranges data "
9442 "(no base address)"));
9448 /* Inverted range entries are invalid. */
9449 complaint (&symfile_complaints
,
9450 _("Invalid .debug_ranges data "
9451 "(inverted range)"));
9455 /* Empty range entries have no effect. */
9459 record_block_range (block
,
9460 baseaddr
+ base
+ start
,
9461 baseaddr
+ base
+ end
- 1);
9467 /* Check whether the producer field indicates either of GCC < 4.6, or the
9468 Intel C/C++ compiler, and cache the result in CU. */
9471 check_producer (struct dwarf2_cu
*cu
)
9474 int major
, minor
, release
;
9476 if (cu
->producer
== NULL
)
9478 /* For unknown compilers expect their behavior is DWARF version
9481 GCC started to support .debug_types sections by -gdwarf-4 since
9482 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
9483 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
9484 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
9485 interpreted incorrectly by GDB now - GCC PR debug/48229. */
9487 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
9489 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
9491 cs
= &cu
->producer
[strlen ("GNU ")];
9492 while (*cs
&& !isdigit (*cs
))
9494 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
9496 /* Not recognized as GCC. */
9499 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
9501 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
9502 cu
->producer_is_icc
= 1;
9505 /* For other non-GCC compilers, expect their behavior is DWARF version
9509 cu
->checked_producer
= 1;
9512 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
9513 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
9514 during 4.6.0 experimental. */
9517 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
9519 if (!cu
->checked_producer
)
9520 check_producer (cu
);
9522 return cu
->producer_is_gxx_lt_4_6
;
9525 /* Return the default accessibility type if it is not overriden by
9526 DW_AT_accessibility. */
9528 static enum dwarf_access_attribute
9529 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
9531 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
9533 /* The default DWARF 2 accessibility for members is public, the default
9534 accessibility for inheritance is private. */
9536 if (die
->tag
!= DW_TAG_inheritance
)
9537 return DW_ACCESS_public
;
9539 return DW_ACCESS_private
;
9543 /* DWARF 3+ defines the default accessibility a different way. The same
9544 rules apply now for DW_TAG_inheritance as for the members and it only
9545 depends on the container kind. */
9547 if (die
->parent
->tag
== DW_TAG_class_type
)
9548 return DW_ACCESS_private
;
9550 return DW_ACCESS_public
;
9554 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
9555 offset. If the attribute was not found return 0, otherwise return
9556 1. If it was found but could not properly be handled, set *OFFSET
9560 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
9563 struct attribute
*attr
;
9565 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
9570 /* Note that we do not check for a section offset first here.
9571 This is because DW_AT_data_member_location is new in DWARF 4,
9572 so if we see it, we can assume that a constant form is really
9573 a constant and not a section offset. */
9574 if (attr_form_is_constant (attr
))
9575 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
9576 else if (attr_form_is_section_offset (attr
))
9577 dwarf2_complex_location_expr_complaint ();
9578 else if (attr_form_is_block (attr
))
9579 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9581 dwarf2_complex_location_expr_complaint ();
9589 /* Add an aggregate field to the field list. */
9592 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
9593 struct dwarf2_cu
*cu
)
9595 struct objfile
*objfile
= cu
->objfile
;
9596 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9597 struct nextfield
*new_field
;
9598 struct attribute
*attr
;
9600 char *fieldname
= "";
9602 /* Allocate a new field list entry and link it in. */
9603 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
9604 make_cleanup (xfree
, new_field
);
9605 memset (new_field
, 0, sizeof (struct nextfield
));
9607 if (die
->tag
== DW_TAG_inheritance
)
9609 new_field
->next
= fip
->baseclasses
;
9610 fip
->baseclasses
= new_field
;
9614 new_field
->next
= fip
->fields
;
9615 fip
->fields
= new_field
;
9619 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9621 new_field
->accessibility
= DW_UNSND (attr
);
9623 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
9624 if (new_field
->accessibility
!= DW_ACCESS_public
)
9625 fip
->non_public_fields
= 1;
9627 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9629 new_field
->virtuality
= DW_UNSND (attr
);
9631 new_field
->virtuality
= DW_VIRTUALITY_none
;
9633 fp
= &new_field
->field
;
9635 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
9639 /* Data member other than a C++ static data member. */
9641 /* Get type of field. */
9642 fp
->type
= die_type (die
, cu
);
9644 SET_FIELD_BITPOS (*fp
, 0);
9646 /* Get bit size of field (zero if none). */
9647 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
9650 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
9654 FIELD_BITSIZE (*fp
) = 0;
9657 /* Get bit offset of field. */
9658 if (handle_data_member_location (die
, cu
, &offset
))
9659 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9660 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
9663 if (gdbarch_bits_big_endian (gdbarch
))
9665 /* For big endian bits, the DW_AT_bit_offset gives the
9666 additional bit offset from the MSB of the containing
9667 anonymous object to the MSB of the field. We don't
9668 have to do anything special since we don't need to
9669 know the size of the anonymous object. */
9670 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
9674 /* For little endian bits, compute the bit offset to the
9675 MSB of the anonymous object, subtract off the number of
9676 bits from the MSB of the field to the MSB of the
9677 object, and then subtract off the number of bits of
9678 the field itself. The result is the bit offset of
9679 the LSB of the field. */
9681 int bit_offset
= DW_UNSND (attr
);
9683 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9686 /* The size of the anonymous object containing
9687 the bit field is explicit, so use the
9688 indicated size (in bytes). */
9689 anonymous_size
= DW_UNSND (attr
);
9693 /* The size of the anonymous object containing
9694 the bit field must be inferred from the type
9695 attribute of the data member containing the
9697 anonymous_size
= TYPE_LENGTH (fp
->type
);
9699 SET_FIELD_BITPOS (*fp
,
9701 + anonymous_size
* bits_per_byte
9702 - bit_offset
- FIELD_BITSIZE (*fp
)));
9706 /* Get name of field. */
9707 fieldname
= dwarf2_name (die
, cu
);
9708 if (fieldname
== NULL
)
9711 /* The name is already allocated along with this objfile, so we don't
9712 need to duplicate it for the type. */
9713 fp
->name
= fieldname
;
9715 /* Change accessibility for artificial fields (e.g. virtual table
9716 pointer or virtual base class pointer) to private. */
9717 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
9719 FIELD_ARTIFICIAL (*fp
) = 1;
9720 new_field
->accessibility
= DW_ACCESS_private
;
9721 fip
->non_public_fields
= 1;
9724 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
9726 /* C++ static member. */
9728 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
9729 is a declaration, but all versions of G++ as of this writing
9730 (so through at least 3.2.1) incorrectly generate
9731 DW_TAG_variable tags. */
9733 const char *physname
;
9735 /* Get name of field. */
9736 fieldname
= dwarf2_name (die
, cu
);
9737 if (fieldname
== NULL
)
9740 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9742 /* Only create a symbol if this is an external value.
9743 new_symbol checks this and puts the value in the global symbol
9744 table, which we want. If it is not external, new_symbol
9745 will try to put the value in cu->list_in_scope which is wrong. */
9746 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
9748 /* A static const member, not much different than an enum as far as
9749 we're concerned, except that we can support more types. */
9750 new_symbol (die
, NULL
, cu
);
9753 /* Get physical name. */
9754 physname
= dwarf2_physname (fieldname
, die
, cu
);
9756 /* The name is already allocated along with this objfile, so we don't
9757 need to duplicate it for the type. */
9758 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
9759 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9760 FIELD_NAME (*fp
) = fieldname
;
9762 else if (die
->tag
== DW_TAG_inheritance
)
9766 /* C++ base class field. */
9767 if (handle_data_member_location (die
, cu
, &offset
))
9768 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9769 FIELD_BITSIZE (*fp
) = 0;
9770 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9771 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
9772 fip
->nbaseclasses
++;
9776 /* Add a typedef defined in the scope of the FIP's class. */
9779 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
9780 struct dwarf2_cu
*cu
)
9782 struct objfile
*objfile
= cu
->objfile
;
9783 struct typedef_field_list
*new_field
;
9784 struct attribute
*attr
;
9785 struct typedef_field
*fp
;
9786 char *fieldname
= "";
9788 /* Allocate a new field list entry and link it in. */
9789 new_field
= xzalloc (sizeof (*new_field
));
9790 make_cleanup (xfree
, new_field
);
9792 gdb_assert (die
->tag
== DW_TAG_typedef
);
9794 fp
= &new_field
->field
;
9796 /* Get name of field. */
9797 fp
->name
= dwarf2_name (die
, cu
);
9798 if (fp
->name
== NULL
)
9801 fp
->type
= read_type_die (die
, cu
);
9803 new_field
->next
= fip
->typedef_field_list
;
9804 fip
->typedef_field_list
= new_field
;
9805 fip
->typedef_field_list_count
++;
9808 /* Create the vector of fields, and attach it to the type. */
9811 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
9812 struct dwarf2_cu
*cu
)
9814 int nfields
= fip
->nfields
;
9816 /* Record the field count, allocate space for the array of fields,
9817 and create blank accessibility bitfields if necessary. */
9818 TYPE_NFIELDS (type
) = nfields
;
9819 TYPE_FIELDS (type
) = (struct field
*)
9820 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
9821 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
9823 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
9825 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9827 TYPE_FIELD_PRIVATE_BITS (type
) =
9828 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9829 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
9831 TYPE_FIELD_PROTECTED_BITS (type
) =
9832 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9833 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
9835 TYPE_FIELD_IGNORE_BITS (type
) =
9836 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9837 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
9840 /* If the type has baseclasses, allocate and clear a bit vector for
9841 TYPE_FIELD_VIRTUAL_BITS. */
9842 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
9844 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
9845 unsigned char *pointer
;
9847 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9848 pointer
= TYPE_ALLOC (type
, num_bytes
);
9849 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
9850 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
9851 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
9854 /* Copy the saved-up fields into the field vector. Start from the head of
9855 the list, adding to the tail of the field array, so that they end up in
9856 the same order in the array in which they were added to the list. */
9857 while (nfields
-- > 0)
9859 struct nextfield
*fieldp
;
9863 fieldp
= fip
->fields
;
9864 fip
->fields
= fieldp
->next
;
9868 fieldp
= fip
->baseclasses
;
9869 fip
->baseclasses
= fieldp
->next
;
9872 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
9873 switch (fieldp
->accessibility
)
9875 case DW_ACCESS_private
:
9876 if (cu
->language
!= language_ada
)
9877 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
9880 case DW_ACCESS_protected
:
9881 if (cu
->language
!= language_ada
)
9882 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
9885 case DW_ACCESS_public
:
9889 /* Unknown accessibility. Complain and treat it as public. */
9891 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
9892 fieldp
->accessibility
);
9896 if (nfields
< fip
->nbaseclasses
)
9898 switch (fieldp
->virtuality
)
9900 case DW_VIRTUALITY_virtual
:
9901 case DW_VIRTUALITY_pure_virtual
:
9902 if (cu
->language
== language_ada
)
9903 error (_("unexpected virtuality in component of Ada type"));
9904 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
9911 /* Add a member function to the proper fieldlist. */
9914 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
9915 struct type
*type
, struct dwarf2_cu
*cu
)
9917 struct objfile
*objfile
= cu
->objfile
;
9918 struct attribute
*attr
;
9919 struct fnfieldlist
*flp
;
9921 struct fn_field
*fnp
;
9923 struct nextfnfield
*new_fnfield
;
9924 struct type
*this_type
;
9925 enum dwarf_access_attribute accessibility
;
9927 if (cu
->language
== language_ada
)
9928 error (_("unexpected member function in Ada type"));
9930 /* Get name of member function. */
9931 fieldname
= dwarf2_name (die
, cu
);
9932 if (fieldname
== NULL
)
9935 /* Look up member function name in fieldlist. */
9936 for (i
= 0; i
< fip
->nfnfields
; i
++)
9938 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
9942 /* Create new list element if necessary. */
9943 if (i
< fip
->nfnfields
)
9944 flp
= &fip
->fnfieldlists
[i
];
9947 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9949 fip
->fnfieldlists
= (struct fnfieldlist
*)
9950 xrealloc (fip
->fnfieldlists
,
9951 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
9952 * sizeof (struct fnfieldlist
));
9953 if (fip
->nfnfields
== 0)
9954 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
9956 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
9957 flp
->name
= fieldname
;
9960 i
= fip
->nfnfields
++;
9963 /* Create a new member function field and chain it to the field list
9965 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
9966 make_cleanup (xfree
, new_fnfield
);
9967 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
9968 new_fnfield
->next
= flp
->head
;
9969 flp
->head
= new_fnfield
;
9972 /* Fill in the member function field info. */
9973 fnp
= &new_fnfield
->fnfield
;
9975 /* Delay processing of the physname until later. */
9976 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
9978 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
9983 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
9984 fnp
->physname
= physname
? physname
: "";
9987 fnp
->type
= alloc_type (objfile
);
9988 this_type
= read_type_die (die
, cu
);
9989 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
9991 int nparams
= TYPE_NFIELDS (this_type
);
9993 /* TYPE is the domain of this method, and THIS_TYPE is the type
9994 of the method itself (TYPE_CODE_METHOD). */
9995 smash_to_method_type (fnp
->type
, type
,
9996 TYPE_TARGET_TYPE (this_type
),
9997 TYPE_FIELDS (this_type
),
9998 TYPE_NFIELDS (this_type
),
9999 TYPE_VARARGS (this_type
));
10001 /* Handle static member functions.
10002 Dwarf2 has no clean way to discern C++ static and non-static
10003 member functions. G++ helps GDB by marking the first
10004 parameter for non-static member functions (which is the this
10005 pointer) as artificial. We obtain this information from
10006 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10007 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10008 fnp
->voffset
= VOFFSET_STATIC
;
10011 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10012 dwarf2_full_name (fieldname
, die
, cu
));
10014 /* Get fcontext from DW_AT_containing_type if present. */
10015 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10016 fnp
->fcontext
= die_containing_type (die
, cu
);
10018 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10019 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10021 /* Get accessibility. */
10022 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10024 accessibility
= DW_UNSND (attr
);
10026 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10027 switch (accessibility
)
10029 case DW_ACCESS_private
:
10030 fnp
->is_private
= 1;
10032 case DW_ACCESS_protected
:
10033 fnp
->is_protected
= 1;
10037 /* Check for artificial methods. */
10038 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
10039 if (attr
&& DW_UNSND (attr
) != 0)
10040 fnp
->is_artificial
= 1;
10042 /* Get index in virtual function table if it is a virtual member
10043 function. For older versions of GCC, this is an offset in the
10044 appropriate virtual table, as specified by DW_AT_containing_type.
10045 For everyone else, it is an expression to be evaluated relative
10046 to the object address. */
10048 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
10051 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
10053 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
10055 /* Old-style GCC. */
10056 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
10058 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10059 || (DW_BLOCK (attr
)->size
> 1
10060 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
10061 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
10063 struct dwarf_block blk
;
10066 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10068 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10069 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10070 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10071 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10072 dwarf2_complex_location_expr_complaint ();
10074 fnp
->voffset
/= cu
->header
.addr_size
;
10078 dwarf2_complex_location_expr_complaint ();
10080 if (!fnp
->fcontext
)
10081 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10083 else if (attr_form_is_section_offset (attr
))
10085 dwarf2_complex_location_expr_complaint ();
10089 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10095 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10096 if (attr
&& DW_UNSND (attr
))
10098 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10099 complaint (&symfile_complaints
,
10100 _("Member function \"%s\" (offset %d) is virtual "
10101 "but the vtable offset is not specified"),
10102 fieldname
, die
->offset
.sect_off
);
10103 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10104 TYPE_CPLUS_DYNAMIC (type
) = 1;
10109 /* Create the vector of member function fields, and attach it to the type. */
10112 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10113 struct dwarf2_cu
*cu
)
10115 struct fnfieldlist
*flp
;
10118 if (cu
->language
== language_ada
)
10119 error (_("unexpected member functions in Ada type"));
10121 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10122 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
10123 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
10125 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
10127 struct nextfnfield
*nfp
= flp
->head
;
10128 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
10131 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
10132 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
10133 fn_flp
->fn_fields
= (struct fn_field
*)
10134 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
10135 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
10136 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
10139 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
10142 /* Returns non-zero if NAME is the name of a vtable member in CU's
10143 language, zero otherwise. */
10145 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
10147 static const char vptr
[] = "_vptr";
10148 static const char vtable
[] = "vtable";
10150 /* Look for the C++ and Java forms of the vtable. */
10151 if ((cu
->language
== language_java
10152 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
10153 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
10154 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
10160 /* GCC outputs unnamed structures that are really pointers to member
10161 functions, with the ABI-specified layout. If TYPE describes
10162 such a structure, smash it into a member function type.
10164 GCC shouldn't do this; it should just output pointer to member DIEs.
10165 This is GCC PR debug/28767. */
10168 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
10170 struct type
*pfn_type
, *domain_type
, *new_type
;
10172 /* Check for a structure with no name and two children. */
10173 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
10176 /* Check for __pfn and __delta members. */
10177 if (TYPE_FIELD_NAME (type
, 0) == NULL
10178 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
10179 || TYPE_FIELD_NAME (type
, 1) == NULL
10180 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
10183 /* Find the type of the method. */
10184 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
10185 if (pfn_type
== NULL
10186 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
10187 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
10190 /* Look for the "this" argument. */
10191 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
10192 if (TYPE_NFIELDS (pfn_type
) == 0
10193 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
10194 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
10197 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
10198 new_type
= alloc_type (objfile
);
10199 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
10200 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
10201 TYPE_VARARGS (pfn_type
));
10202 smash_to_methodptr_type (type
, new_type
);
10205 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
10209 producer_is_icc (struct dwarf2_cu
*cu
)
10211 if (!cu
->checked_producer
)
10212 check_producer (cu
);
10214 return cu
->producer_is_icc
;
10217 /* Called when we find the DIE that starts a structure or union scope
10218 (definition) to create a type for the structure or union. Fill in
10219 the type's name and general properties; the members will not be
10220 processed until process_structure_type.
10222 NOTE: we need to call these functions regardless of whether or not the
10223 DIE has a DW_AT_name attribute, since it might be an anonymous
10224 structure or union. This gets the type entered into our set of
10225 user defined types.
10227 However, if the structure is incomplete (an opaque struct/union)
10228 then suppress creating a symbol table entry for it since gdb only
10229 wants to find the one with the complete definition. Note that if
10230 it is complete, we just call new_symbol, which does it's own
10231 checking about whether the struct/union is anonymous or not (and
10232 suppresses creating a symbol table entry itself). */
10234 static struct type
*
10235 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10237 struct objfile
*objfile
= cu
->objfile
;
10239 struct attribute
*attr
;
10242 /* If the definition of this type lives in .debug_types, read that type.
10243 Don't follow DW_AT_specification though, that will take us back up
10244 the chain and we want to go down. */
10245 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10248 struct dwarf2_cu
*type_cu
= cu
;
10249 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10251 /* We could just recurse on read_structure_type, but we need to call
10252 get_die_type to ensure only one type for this DIE is created.
10253 This is important, for example, because for c++ classes we need
10254 TYPE_NAME set which is only done by new_symbol. Blech. */
10255 type
= read_type_die (type_die
, type_cu
);
10257 /* TYPE_CU may not be the same as CU.
10258 Ensure TYPE is recorded in CU's type_hash table. */
10259 return set_die_type (die
, type
, cu
);
10262 type
= alloc_type (objfile
);
10263 INIT_CPLUS_SPECIFIC (type
);
10265 name
= dwarf2_name (die
, cu
);
10268 if (cu
->language
== language_cplus
10269 || cu
->language
== language_java
)
10271 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
10273 /* dwarf2_full_name might have already finished building the DIE's
10274 type. If so, there is no need to continue. */
10275 if (get_die_type (die
, cu
) != NULL
)
10276 return get_die_type (die
, cu
);
10278 TYPE_TAG_NAME (type
) = full_name
;
10279 if (die
->tag
== DW_TAG_structure_type
10280 || die
->tag
== DW_TAG_class_type
)
10281 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10285 /* The name is already allocated along with this objfile, so
10286 we don't need to duplicate it for the type. */
10287 TYPE_TAG_NAME (type
) = (char *) name
;
10288 if (die
->tag
== DW_TAG_class_type
)
10289 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10293 if (die
->tag
== DW_TAG_structure_type
)
10295 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10297 else if (die
->tag
== DW_TAG_union_type
)
10299 TYPE_CODE (type
) = TYPE_CODE_UNION
;
10303 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
10306 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
10307 TYPE_DECLARED_CLASS (type
) = 1;
10309 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10312 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10316 TYPE_LENGTH (type
) = 0;
10319 if (producer_is_icc (cu
))
10321 /* ICC does not output the required DW_AT_declaration
10322 on incomplete types, but gives them a size of zero. */
10325 TYPE_STUB_SUPPORTED (type
) = 1;
10327 if (die_is_declaration (die
, cu
))
10328 TYPE_STUB (type
) = 1;
10329 else if (attr
== NULL
&& die
->child
== NULL
10330 && producer_is_realview (cu
->producer
))
10331 /* RealView does not output the required DW_AT_declaration
10332 on incomplete types. */
10333 TYPE_STUB (type
) = 1;
10335 /* We need to add the type field to the die immediately so we don't
10336 infinitely recurse when dealing with pointers to the structure
10337 type within the structure itself. */
10338 set_die_type (die
, type
, cu
);
10340 /* set_die_type should be already done. */
10341 set_descriptive_type (type
, die
, cu
);
10346 /* Finish creating a structure or union type, including filling in
10347 its members and creating a symbol for it. */
10350 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10352 struct objfile
*objfile
= cu
->objfile
;
10353 struct die_info
*child_die
= die
->child
;
10356 type
= get_die_type (die
, cu
);
10358 type
= read_structure_type (die
, cu
);
10360 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
10362 struct field_info fi
;
10363 struct die_info
*child_die
;
10364 VEC (symbolp
) *template_args
= NULL
;
10365 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
10367 memset (&fi
, 0, sizeof (struct field_info
));
10369 child_die
= die
->child
;
10371 while (child_die
&& child_die
->tag
)
10373 if (child_die
->tag
== DW_TAG_member
10374 || child_die
->tag
== DW_TAG_variable
)
10376 /* NOTE: carlton/2002-11-05: A C++ static data member
10377 should be a DW_TAG_member that is a declaration, but
10378 all versions of G++ as of this writing (so through at
10379 least 3.2.1) incorrectly generate DW_TAG_variable
10380 tags for them instead. */
10381 dwarf2_add_field (&fi
, child_die
, cu
);
10383 else if (child_die
->tag
== DW_TAG_subprogram
)
10385 /* C++ member function. */
10386 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
10388 else if (child_die
->tag
== DW_TAG_inheritance
)
10390 /* C++ base class field. */
10391 dwarf2_add_field (&fi
, child_die
, cu
);
10393 else if (child_die
->tag
== DW_TAG_typedef
)
10394 dwarf2_add_typedef (&fi
, child_die
, cu
);
10395 else if (child_die
->tag
== DW_TAG_template_type_param
10396 || child_die
->tag
== DW_TAG_template_value_param
)
10398 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10401 VEC_safe_push (symbolp
, template_args
, arg
);
10404 child_die
= sibling_die (child_die
);
10407 /* Attach template arguments to type. */
10408 if (! VEC_empty (symbolp
, template_args
))
10410 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10411 TYPE_N_TEMPLATE_ARGUMENTS (type
)
10412 = VEC_length (symbolp
, template_args
);
10413 TYPE_TEMPLATE_ARGUMENTS (type
)
10414 = obstack_alloc (&objfile
->objfile_obstack
,
10415 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10416 * sizeof (struct symbol
*)));
10417 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
10418 VEC_address (symbolp
, template_args
),
10419 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10420 * sizeof (struct symbol
*)));
10421 VEC_free (symbolp
, template_args
);
10424 /* Attach fields and member functions to the type. */
10426 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
10429 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
10431 /* Get the type which refers to the base class (possibly this
10432 class itself) which contains the vtable pointer for the current
10433 class from the DW_AT_containing_type attribute. This use of
10434 DW_AT_containing_type is a GNU extension. */
10436 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10438 struct type
*t
= die_containing_type (die
, cu
);
10440 TYPE_VPTR_BASETYPE (type
) = t
;
10445 /* Our own class provides vtbl ptr. */
10446 for (i
= TYPE_NFIELDS (t
) - 1;
10447 i
>= TYPE_N_BASECLASSES (t
);
10450 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
10452 if (is_vtable_name (fieldname
, cu
))
10454 TYPE_VPTR_FIELDNO (type
) = i
;
10459 /* Complain if virtual function table field not found. */
10460 if (i
< TYPE_N_BASECLASSES (t
))
10461 complaint (&symfile_complaints
,
10462 _("virtual function table pointer "
10463 "not found when defining class '%s'"),
10464 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
10469 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
10472 else if (cu
->producer
10473 && strncmp (cu
->producer
,
10474 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
10476 /* The IBM XLC compiler does not provide direct indication
10477 of the containing type, but the vtable pointer is
10478 always named __vfp. */
10482 for (i
= TYPE_NFIELDS (type
) - 1;
10483 i
>= TYPE_N_BASECLASSES (type
);
10486 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
10488 TYPE_VPTR_FIELDNO (type
) = i
;
10489 TYPE_VPTR_BASETYPE (type
) = type
;
10496 /* Copy fi.typedef_field_list linked list elements content into the
10497 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
10498 if (fi
.typedef_field_list
)
10500 int i
= fi
.typedef_field_list_count
;
10502 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10503 TYPE_TYPEDEF_FIELD_ARRAY (type
)
10504 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
10505 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
10507 /* Reverse the list order to keep the debug info elements order. */
10510 struct typedef_field
*dest
, *src
;
10512 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
10513 src
= &fi
.typedef_field_list
->field
;
10514 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
10519 do_cleanups (back_to
);
10521 if (HAVE_CPLUS_STRUCT (type
))
10522 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
10525 quirk_gcc_member_function_pointer (type
, objfile
);
10527 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
10528 snapshots) has been known to create a die giving a declaration
10529 for a class that has, as a child, a die giving a definition for a
10530 nested class. So we have to process our children even if the
10531 current die is a declaration. Normally, of course, a declaration
10532 won't have any children at all. */
10534 while (child_die
!= NULL
&& child_die
->tag
)
10536 if (child_die
->tag
== DW_TAG_member
10537 || child_die
->tag
== DW_TAG_variable
10538 || child_die
->tag
== DW_TAG_inheritance
10539 || child_die
->tag
== DW_TAG_template_value_param
10540 || child_die
->tag
== DW_TAG_template_type_param
)
10545 process_die (child_die
, cu
);
10547 child_die
= sibling_die (child_die
);
10550 /* Do not consider external references. According to the DWARF standard,
10551 these DIEs are identified by the fact that they have no byte_size
10552 attribute, and a declaration attribute. */
10553 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
10554 || !die_is_declaration (die
, cu
))
10555 new_symbol (die
, type
, cu
);
10558 /* Given a DW_AT_enumeration_type die, set its type. We do not
10559 complete the type's fields yet, or create any symbols. */
10561 static struct type
*
10562 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10564 struct objfile
*objfile
= cu
->objfile
;
10566 struct attribute
*attr
;
10569 /* If the definition of this type lives in .debug_types, read that type.
10570 Don't follow DW_AT_specification though, that will take us back up
10571 the chain and we want to go down. */
10572 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10575 struct dwarf2_cu
*type_cu
= cu
;
10576 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10578 type
= read_type_die (type_die
, type_cu
);
10580 /* TYPE_CU may not be the same as CU.
10581 Ensure TYPE is recorded in CU's type_hash table. */
10582 return set_die_type (die
, type
, cu
);
10585 type
= alloc_type (objfile
);
10587 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
10588 name
= dwarf2_full_name (NULL
, die
, cu
);
10590 TYPE_TAG_NAME (type
) = (char *) name
;
10592 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10595 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10599 TYPE_LENGTH (type
) = 0;
10602 /* The enumeration DIE can be incomplete. In Ada, any type can be
10603 declared as private in the package spec, and then defined only
10604 inside the package body. Such types are known as Taft Amendment
10605 Types. When another package uses such a type, an incomplete DIE
10606 may be generated by the compiler. */
10607 if (die_is_declaration (die
, cu
))
10608 TYPE_STUB (type
) = 1;
10610 return set_die_type (die
, type
, cu
);
10613 /* Given a pointer to a die which begins an enumeration, process all
10614 the dies that define the members of the enumeration, and create the
10615 symbol for the enumeration type.
10617 NOTE: We reverse the order of the element list. */
10620 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10622 struct type
*this_type
;
10624 this_type
= get_die_type (die
, cu
);
10625 if (this_type
== NULL
)
10626 this_type
= read_enumeration_type (die
, cu
);
10628 if (die
->child
!= NULL
)
10630 struct die_info
*child_die
;
10631 struct symbol
*sym
;
10632 struct field
*fields
= NULL
;
10633 int num_fields
= 0;
10634 int unsigned_enum
= 1;
10639 child_die
= die
->child
;
10640 while (child_die
&& child_die
->tag
)
10642 if (child_die
->tag
!= DW_TAG_enumerator
)
10644 process_die (child_die
, cu
);
10648 name
= dwarf2_name (child_die
, cu
);
10651 sym
= new_symbol (child_die
, this_type
, cu
);
10652 if (SYMBOL_VALUE (sym
) < 0)
10657 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
10660 mask
|= SYMBOL_VALUE (sym
);
10662 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10664 fields
= (struct field
*)
10666 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
10667 * sizeof (struct field
));
10670 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
10671 FIELD_TYPE (fields
[num_fields
]) = NULL
;
10672 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
10673 FIELD_BITSIZE (fields
[num_fields
]) = 0;
10679 child_die
= sibling_die (child_die
);
10684 TYPE_NFIELDS (this_type
) = num_fields
;
10685 TYPE_FIELDS (this_type
) = (struct field
*)
10686 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
10687 memcpy (TYPE_FIELDS (this_type
), fields
,
10688 sizeof (struct field
) * num_fields
);
10692 TYPE_UNSIGNED (this_type
) = 1;
10694 TYPE_FLAG_ENUM (this_type
) = 1;
10697 /* If we are reading an enum from a .debug_types unit, and the enum
10698 is a declaration, and the enum is not the signatured type in the
10699 unit, then we do not want to add a symbol for it. Adding a
10700 symbol would in some cases obscure the true definition of the
10701 enum, giving users an incomplete type when the definition is
10702 actually available. Note that we do not want to do this for all
10703 enums which are just declarations, because C++0x allows forward
10704 enum declarations. */
10705 if (cu
->per_cu
->is_debug_types
10706 && die_is_declaration (die
, cu
))
10708 struct signatured_type
*sig_type
;
10711 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
10712 cu
->per_cu
->info_or_types_section
,
10713 cu
->per_cu
->offset
);
10714 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
10715 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
10719 new_symbol (die
, this_type
, cu
);
10722 /* Extract all information from a DW_TAG_array_type DIE and put it in
10723 the DIE's type field. For now, this only handles one dimensional
10726 static struct type
*
10727 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10729 struct objfile
*objfile
= cu
->objfile
;
10730 struct die_info
*child_die
;
10732 struct type
*element_type
, *range_type
, *index_type
;
10733 struct type
**range_types
= NULL
;
10734 struct attribute
*attr
;
10736 struct cleanup
*back_to
;
10739 element_type
= die_type (die
, cu
);
10741 /* The die_type call above may have already set the type for this DIE. */
10742 type
= get_die_type (die
, cu
);
10746 /* Irix 6.2 native cc creates array types without children for
10747 arrays with unspecified length. */
10748 if (die
->child
== NULL
)
10750 index_type
= objfile_type (objfile
)->builtin_int
;
10751 range_type
= create_range_type (NULL
, index_type
, 0, -1);
10752 type
= create_array_type (NULL
, element_type
, range_type
);
10753 return set_die_type (die
, type
, cu
);
10756 back_to
= make_cleanup (null_cleanup
, NULL
);
10757 child_die
= die
->child
;
10758 while (child_die
&& child_die
->tag
)
10760 if (child_die
->tag
== DW_TAG_subrange_type
)
10762 struct type
*child_type
= read_type_die (child_die
, cu
);
10764 if (child_type
!= NULL
)
10766 /* The range type was succesfully read. Save it for the
10767 array type creation. */
10768 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
10770 range_types
= (struct type
**)
10771 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
10772 * sizeof (struct type
*));
10774 make_cleanup (free_current_contents
, &range_types
);
10776 range_types
[ndim
++] = child_type
;
10779 child_die
= sibling_die (child_die
);
10782 /* Dwarf2 dimensions are output from left to right, create the
10783 necessary array types in backwards order. */
10785 type
= element_type
;
10787 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
10792 type
= create_array_type (NULL
, type
, range_types
[i
++]);
10797 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
10800 /* Understand Dwarf2 support for vector types (like they occur on
10801 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
10802 array type. This is not part of the Dwarf2/3 standard yet, but a
10803 custom vendor extension. The main difference between a regular
10804 array and the vector variant is that vectors are passed by value
10806 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
10808 make_vector_type (type
);
10810 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
10811 implementation may choose to implement triple vectors using this
10813 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10816 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
10817 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10819 complaint (&symfile_complaints
,
10820 _("DW_AT_byte_size for array type smaller "
10821 "than the total size of elements"));
10824 name
= dwarf2_name (die
, cu
);
10826 TYPE_NAME (type
) = name
;
10828 /* Install the type in the die. */
10829 set_die_type (die
, type
, cu
);
10831 /* set_die_type should be already done. */
10832 set_descriptive_type (type
, die
, cu
);
10834 do_cleanups (back_to
);
10839 static enum dwarf_array_dim_ordering
10840 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
10842 struct attribute
*attr
;
10844 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
10846 if (attr
) return DW_SND (attr
);
10848 /* GNU F77 is a special case, as at 08/2004 array type info is the
10849 opposite order to the dwarf2 specification, but data is still
10850 laid out as per normal fortran.
10852 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
10853 version checking. */
10855 if (cu
->language
== language_fortran
10856 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
10858 return DW_ORD_row_major
;
10861 switch (cu
->language_defn
->la_array_ordering
)
10863 case array_column_major
:
10864 return DW_ORD_col_major
;
10865 case array_row_major
:
10867 return DW_ORD_row_major
;
10871 /* Extract all information from a DW_TAG_set_type DIE and put it in
10872 the DIE's type field. */
10874 static struct type
*
10875 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10877 struct type
*domain_type
, *set_type
;
10878 struct attribute
*attr
;
10880 domain_type
= die_type (die
, cu
);
10882 /* The die_type call above may have already set the type for this DIE. */
10883 set_type
= get_die_type (die
, cu
);
10887 set_type
= create_set_type (NULL
, domain_type
);
10889 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10891 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
10893 return set_die_type (die
, set_type
, cu
);
10896 /* First cut: install each common block member as a global variable. */
10899 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
10901 struct die_info
*child_die
;
10902 struct attribute
*attr
;
10903 struct symbol
*sym
;
10904 CORE_ADDR base
= (CORE_ADDR
) 0;
10906 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10909 /* Support the .debug_loc offsets. */
10910 if (attr_form_is_block (attr
))
10912 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
10914 else if (attr_form_is_section_offset (attr
))
10916 dwarf2_complex_location_expr_complaint ();
10920 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10921 "common block member");
10924 if (die
->child
!= NULL
)
10926 child_die
= die
->child
;
10927 while (child_die
&& child_die
->tag
)
10931 sym
= new_symbol (child_die
, NULL
, cu
);
10933 && handle_data_member_location (child_die
, cu
, &offset
))
10935 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
10936 add_symbol_to_list (sym
, &global_symbols
);
10938 child_die
= sibling_die (child_die
);
10943 /* Create a type for a C++ namespace. */
10945 static struct type
*
10946 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10948 struct objfile
*objfile
= cu
->objfile
;
10949 const char *previous_prefix
, *name
;
10953 /* For extensions, reuse the type of the original namespace. */
10954 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
10956 struct die_info
*ext_die
;
10957 struct dwarf2_cu
*ext_cu
= cu
;
10959 ext_die
= dwarf2_extension (die
, &ext_cu
);
10960 type
= read_type_die (ext_die
, ext_cu
);
10962 /* EXT_CU may not be the same as CU.
10963 Ensure TYPE is recorded in CU's type_hash table. */
10964 return set_die_type (die
, type
, cu
);
10967 name
= namespace_name (die
, &is_anonymous
, cu
);
10969 /* Now build the name of the current namespace. */
10971 previous_prefix
= determine_prefix (die
, cu
);
10972 if (previous_prefix
[0] != '\0')
10973 name
= typename_concat (&objfile
->objfile_obstack
,
10974 previous_prefix
, name
, 0, cu
);
10976 /* Create the type. */
10977 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
10979 TYPE_NAME (type
) = (char *) name
;
10980 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10982 return set_die_type (die
, type
, cu
);
10985 /* Read a C++ namespace. */
10988 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10990 struct objfile
*objfile
= cu
->objfile
;
10993 /* Add a symbol associated to this if we haven't seen the namespace
10994 before. Also, add a using directive if it's an anonymous
10997 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
11001 type
= read_type_die (die
, cu
);
11002 new_symbol (die
, type
, cu
);
11004 namespace_name (die
, &is_anonymous
, cu
);
11007 const char *previous_prefix
= determine_prefix (die
, cu
);
11009 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
11010 NULL
, NULL
, &objfile
->objfile_obstack
);
11014 if (die
->child
!= NULL
)
11016 struct die_info
*child_die
= die
->child
;
11018 while (child_die
&& child_die
->tag
)
11020 process_die (child_die
, cu
);
11021 child_die
= sibling_die (child_die
);
11026 /* Read a Fortran module as type. This DIE can be only a declaration used for
11027 imported module. Still we need that type as local Fortran "use ... only"
11028 declaration imports depend on the created type in determine_prefix. */
11030 static struct type
*
11031 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11033 struct objfile
*objfile
= cu
->objfile
;
11037 module_name
= dwarf2_name (die
, cu
);
11039 complaint (&symfile_complaints
,
11040 _("DW_TAG_module has no name, offset 0x%x"),
11041 die
->offset
.sect_off
);
11042 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
11044 /* determine_prefix uses TYPE_TAG_NAME. */
11045 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11047 return set_die_type (die
, type
, cu
);
11050 /* Read a Fortran module. */
11053 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
11055 struct die_info
*child_die
= die
->child
;
11057 while (child_die
&& child_die
->tag
)
11059 process_die (child_die
, cu
);
11060 child_die
= sibling_die (child_die
);
11064 /* Return the name of the namespace represented by DIE. Set
11065 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
11068 static const char *
11069 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
11071 struct die_info
*current_die
;
11072 const char *name
= NULL
;
11074 /* Loop through the extensions until we find a name. */
11076 for (current_die
= die
;
11077 current_die
!= NULL
;
11078 current_die
= dwarf2_extension (die
, &cu
))
11080 name
= dwarf2_name (current_die
, cu
);
11085 /* Is it an anonymous namespace? */
11087 *is_anonymous
= (name
== NULL
);
11089 name
= CP_ANONYMOUS_NAMESPACE_STR
;
11094 /* Extract all information from a DW_TAG_pointer_type DIE and add to
11095 the user defined type vector. */
11097 static struct type
*
11098 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11100 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
11101 struct comp_unit_head
*cu_header
= &cu
->header
;
11103 struct attribute
*attr_byte_size
;
11104 struct attribute
*attr_address_class
;
11105 int byte_size
, addr_class
;
11106 struct type
*target_type
;
11108 target_type
= die_type (die
, cu
);
11110 /* The die_type call above may have already set the type for this DIE. */
11111 type
= get_die_type (die
, cu
);
11115 type
= lookup_pointer_type (target_type
);
11117 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11118 if (attr_byte_size
)
11119 byte_size
= DW_UNSND (attr_byte_size
);
11121 byte_size
= cu_header
->addr_size
;
11123 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
11124 if (attr_address_class
)
11125 addr_class
= DW_UNSND (attr_address_class
);
11127 addr_class
= DW_ADDR_none
;
11129 /* If the pointer size or address class is different than the
11130 default, create a type variant marked as such and set the
11131 length accordingly. */
11132 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
11134 if (gdbarch_address_class_type_flags_p (gdbarch
))
11138 type_flags
= gdbarch_address_class_type_flags
11139 (gdbarch
, byte_size
, addr_class
);
11140 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
11142 type
= make_type_with_address_space (type
, type_flags
);
11144 else if (TYPE_LENGTH (type
) != byte_size
)
11146 complaint (&symfile_complaints
,
11147 _("invalid pointer size %d"), byte_size
);
11151 /* Should we also complain about unhandled address classes? */
11155 TYPE_LENGTH (type
) = byte_size
;
11156 return set_die_type (die
, type
, cu
);
11159 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
11160 the user defined type vector. */
11162 static struct type
*
11163 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11166 struct type
*to_type
;
11167 struct type
*domain
;
11169 to_type
= die_type (die
, cu
);
11170 domain
= die_containing_type (die
, cu
);
11172 /* The calls above may have already set the type for this DIE. */
11173 type
= get_die_type (die
, cu
);
11177 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
11178 type
= lookup_methodptr_type (to_type
);
11180 type
= lookup_memberptr_type (to_type
, domain
);
11182 return set_die_type (die
, type
, cu
);
11185 /* Extract all information from a DW_TAG_reference_type DIE and add to
11186 the user defined type vector. */
11188 static struct type
*
11189 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11191 struct comp_unit_head
*cu_header
= &cu
->header
;
11192 struct type
*type
, *target_type
;
11193 struct attribute
*attr
;
11195 target_type
= die_type (die
, cu
);
11197 /* The die_type call above may have already set the type for this DIE. */
11198 type
= get_die_type (die
, cu
);
11202 type
= lookup_reference_type (target_type
);
11203 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11206 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11210 TYPE_LENGTH (type
) = cu_header
->addr_size
;
11212 return set_die_type (die
, type
, cu
);
11215 static struct type
*
11216 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11218 struct type
*base_type
, *cv_type
;
11220 base_type
= die_type (die
, cu
);
11222 /* The die_type call above may have already set the type for this DIE. */
11223 cv_type
= get_die_type (die
, cu
);
11227 /* In case the const qualifier is applied to an array type, the element type
11228 is so qualified, not the array type (section 6.7.3 of C99). */
11229 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
11231 struct type
*el_type
, *inner_array
;
11233 base_type
= copy_type (base_type
);
11234 inner_array
= base_type
;
11236 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
11238 TYPE_TARGET_TYPE (inner_array
) =
11239 copy_type (TYPE_TARGET_TYPE (inner_array
));
11240 inner_array
= TYPE_TARGET_TYPE (inner_array
);
11243 el_type
= TYPE_TARGET_TYPE (inner_array
);
11244 TYPE_TARGET_TYPE (inner_array
) =
11245 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
11247 return set_die_type (die
, base_type
, cu
);
11250 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
11251 return set_die_type (die
, cv_type
, cu
);
11254 static struct type
*
11255 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11257 struct type
*base_type
, *cv_type
;
11259 base_type
= die_type (die
, cu
);
11261 /* The die_type call above may have already set the type for this DIE. */
11262 cv_type
= get_die_type (die
, cu
);
11266 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
11267 return set_die_type (die
, cv_type
, cu
);
11270 /* Extract all information from a DW_TAG_string_type DIE and add to
11271 the user defined type vector. It isn't really a user defined type,
11272 but it behaves like one, with other DIE's using an AT_user_def_type
11273 attribute to reference it. */
11275 static struct type
*
11276 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11278 struct objfile
*objfile
= cu
->objfile
;
11279 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11280 struct type
*type
, *range_type
, *index_type
, *char_type
;
11281 struct attribute
*attr
;
11282 unsigned int length
;
11284 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
11287 length
= DW_UNSND (attr
);
11291 /* Check for the DW_AT_byte_size attribute. */
11292 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11295 length
= DW_UNSND (attr
);
11303 index_type
= objfile_type (objfile
)->builtin_int
;
11304 range_type
= create_range_type (NULL
, index_type
, 1, length
);
11305 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
11306 type
= create_string_type (NULL
, char_type
, range_type
);
11308 return set_die_type (die
, type
, cu
);
11311 /* Handle DIES due to C code like:
11315 int (*funcp)(int a, long l);
11319 ('funcp' generates a DW_TAG_subroutine_type DIE). */
11321 static struct type
*
11322 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11324 struct objfile
*objfile
= cu
->objfile
;
11325 struct type
*type
; /* Type that this function returns. */
11326 struct type
*ftype
; /* Function that returns above type. */
11327 struct attribute
*attr
;
11329 type
= die_type (die
, cu
);
11331 /* The die_type call above may have already set the type for this DIE. */
11332 ftype
= get_die_type (die
, cu
);
11336 ftype
= lookup_function_type (type
);
11338 /* All functions in C++, Pascal and Java have prototypes. */
11339 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
11340 if ((attr
&& (DW_UNSND (attr
) != 0))
11341 || cu
->language
== language_cplus
11342 || cu
->language
== language_java
11343 || cu
->language
== language_pascal
)
11344 TYPE_PROTOTYPED (ftype
) = 1;
11345 else if (producer_is_realview (cu
->producer
))
11346 /* RealView does not emit DW_AT_prototyped. We can not
11347 distinguish prototyped and unprototyped functions; default to
11348 prototyped, since that is more common in modern code (and
11349 RealView warns about unprototyped functions). */
11350 TYPE_PROTOTYPED (ftype
) = 1;
11352 /* Store the calling convention in the type if it's available in
11353 the subroutine die. Otherwise set the calling convention to
11354 the default value DW_CC_normal. */
11355 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
11357 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
11358 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
11359 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
11361 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
11363 /* We need to add the subroutine type to the die immediately so
11364 we don't infinitely recurse when dealing with parameters
11365 declared as the same subroutine type. */
11366 set_die_type (die
, ftype
, cu
);
11368 if (die
->child
!= NULL
)
11370 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
11371 struct die_info
*child_die
;
11372 int nparams
, iparams
;
11374 /* Count the number of parameters.
11375 FIXME: GDB currently ignores vararg functions, but knows about
11376 vararg member functions. */
11378 child_die
= die
->child
;
11379 while (child_die
&& child_die
->tag
)
11381 if (child_die
->tag
== DW_TAG_formal_parameter
)
11383 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
11384 TYPE_VARARGS (ftype
) = 1;
11385 child_die
= sibling_die (child_die
);
11388 /* Allocate storage for parameters and fill them in. */
11389 TYPE_NFIELDS (ftype
) = nparams
;
11390 TYPE_FIELDS (ftype
) = (struct field
*)
11391 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
11393 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
11394 even if we error out during the parameters reading below. */
11395 for (iparams
= 0; iparams
< nparams
; iparams
++)
11396 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
11399 child_die
= die
->child
;
11400 while (child_die
&& child_die
->tag
)
11402 if (child_die
->tag
== DW_TAG_formal_parameter
)
11404 struct type
*arg_type
;
11406 /* DWARF version 2 has no clean way to discern C++
11407 static and non-static member functions. G++ helps
11408 GDB by marking the first parameter for non-static
11409 member functions (which is the this pointer) as
11410 artificial. We pass this information to
11411 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
11413 DWARF version 3 added DW_AT_object_pointer, which GCC
11414 4.5 does not yet generate. */
11415 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
11417 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
11420 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
11422 /* GCC/43521: In java, the formal parameter
11423 "this" is sometimes not marked with DW_AT_artificial. */
11424 if (cu
->language
== language_java
)
11426 const char *name
= dwarf2_name (child_die
, cu
);
11428 if (name
&& !strcmp (name
, "this"))
11429 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
11432 arg_type
= die_type (child_die
, cu
);
11434 /* RealView does not mark THIS as const, which the testsuite
11435 expects. GCC marks THIS as const in method definitions,
11436 but not in the class specifications (GCC PR 43053). */
11437 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
11438 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
11441 struct dwarf2_cu
*arg_cu
= cu
;
11442 const char *name
= dwarf2_name (child_die
, cu
);
11444 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
11447 /* If the compiler emits this, use it. */
11448 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
11451 else if (name
&& strcmp (name
, "this") == 0)
11452 /* Function definitions will have the argument names. */
11454 else if (name
== NULL
&& iparams
== 0)
11455 /* Declarations may not have the names, so like
11456 elsewhere in GDB, assume an artificial first
11457 argument is "this". */
11461 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
11465 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
11468 child_die
= sibling_die (child_die
);
11475 static struct type
*
11476 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
11478 struct objfile
*objfile
= cu
->objfile
;
11479 const char *name
= NULL
;
11480 struct type
*this_type
, *target_type
;
11482 name
= dwarf2_full_name (NULL
, die
, cu
);
11483 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
11484 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
11485 TYPE_NAME (this_type
) = (char *) name
;
11486 set_die_type (die
, this_type
, cu
);
11487 target_type
= die_type (die
, cu
);
11488 if (target_type
!= this_type
)
11489 TYPE_TARGET_TYPE (this_type
) = target_type
;
11492 /* Self-referential typedefs are, it seems, not allowed by the DWARF
11493 spec and cause infinite loops in GDB. */
11494 complaint (&symfile_complaints
,
11495 _("Self-referential DW_TAG_typedef "
11496 "- DIE at 0x%x [in module %s]"),
11497 die
->offset
.sect_off
, objfile
->name
);
11498 TYPE_TARGET_TYPE (this_type
) = NULL
;
11503 /* Find a representation of a given base type and install
11504 it in the TYPE field of the die. */
11506 static struct type
*
11507 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11509 struct objfile
*objfile
= cu
->objfile
;
11511 struct attribute
*attr
;
11512 int encoding
= 0, size
= 0;
11514 enum type_code code
= TYPE_CODE_INT
;
11515 int type_flags
= 0;
11516 struct type
*target_type
= NULL
;
11518 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
11521 encoding
= DW_UNSND (attr
);
11523 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11526 size
= DW_UNSND (attr
);
11528 name
= dwarf2_name (die
, cu
);
11531 complaint (&symfile_complaints
,
11532 _("DW_AT_name missing from DW_TAG_base_type"));
11537 case DW_ATE_address
:
11538 /* Turn DW_ATE_address into a void * pointer. */
11539 code
= TYPE_CODE_PTR
;
11540 type_flags
|= TYPE_FLAG_UNSIGNED
;
11541 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
11543 case DW_ATE_boolean
:
11544 code
= TYPE_CODE_BOOL
;
11545 type_flags
|= TYPE_FLAG_UNSIGNED
;
11547 case DW_ATE_complex_float
:
11548 code
= TYPE_CODE_COMPLEX
;
11549 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
11551 case DW_ATE_decimal_float
:
11552 code
= TYPE_CODE_DECFLOAT
;
11555 code
= TYPE_CODE_FLT
;
11557 case DW_ATE_signed
:
11559 case DW_ATE_unsigned
:
11560 type_flags
|= TYPE_FLAG_UNSIGNED
;
11561 if (cu
->language
== language_fortran
11563 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
11564 code
= TYPE_CODE_CHAR
;
11566 case DW_ATE_signed_char
:
11567 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11568 || cu
->language
== language_pascal
11569 || cu
->language
== language_fortran
)
11570 code
= TYPE_CODE_CHAR
;
11572 case DW_ATE_unsigned_char
:
11573 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11574 || cu
->language
== language_pascal
11575 || cu
->language
== language_fortran
)
11576 code
= TYPE_CODE_CHAR
;
11577 type_flags
|= TYPE_FLAG_UNSIGNED
;
11580 /* We just treat this as an integer and then recognize the
11581 type by name elsewhere. */
11585 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
11586 dwarf_type_encoding_name (encoding
));
11590 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
11591 TYPE_NAME (type
) = name
;
11592 TYPE_TARGET_TYPE (type
) = target_type
;
11594 if (name
&& strcmp (name
, "char") == 0)
11595 TYPE_NOSIGN (type
) = 1;
11597 return set_die_type (die
, type
, cu
);
11600 /* Read the given DW_AT_subrange DIE. */
11602 static struct type
*
11603 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11605 struct type
*base_type
;
11606 struct type
*range_type
;
11607 struct attribute
*attr
;
11609 int low_default_is_valid
;
11611 LONGEST negative_mask
;
11613 base_type
= die_type (die
, cu
);
11614 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
11615 check_typedef (base_type
);
11617 /* The die_type call above may have already set the type for this DIE. */
11618 range_type
= get_die_type (die
, cu
);
11622 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
11623 omitting DW_AT_lower_bound. */
11624 switch (cu
->language
)
11627 case language_cplus
:
11629 low_default_is_valid
= 1;
11631 case language_fortran
:
11633 low_default_is_valid
= 1;
11636 case language_java
:
11637 case language_objc
:
11639 low_default_is_valid
= (cu
->header
.version
>= 4);
11643 case language_pascal
:
11645 low_default_is_valid
= (cu
->header
.version
>= 4);
11649 low_default_is_valid
= 0;
11653 /* FIXME: For variable sized arrays either of these could be
11654 a variable rather than a constant value. We'll allow it,
11655 but we don't know how to handle it. */
11656 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
11658 low
= dwarf2_get_attr_constant_value (attr
, low
);
11659 else if (!low_default_is_valid
)
11660 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
11661 "- DIE at 0x%x [in module %s]"),
11662 die
->offset
.sect_off
, cu
->objfile
->name
);
11664 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
11667 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
11669 /* GCC encodes arrays with unspecified or dynamic length
11670 with a DW_FORM_block1 attribute or a reference attribute.
11671 FIXME: GDB does not yet know how to handle dynamic
11672 arrays properly, treat them as arrays with unspecified
11675 FIXME: jimb/2003-09-22: GDB does not really know
11676 how to handle arrays of unspecified length
11677 either; we just represent them as zero-length
11678 arrays. Choose an appropriate upper bound given
11679 the lower bound we've computed above. */
11683 high
= dwarf2_get_attr_constant_value (attr
, 1);
11687 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
11690 int count
= dwarf2_get_attr_constant_value (attr
, 1);
11691 high
= low
+ count
- 1;
11695 /* Unspecified array length. */
11700 /* Dwarf-2 specifications explicitly allows to create subrange types
11701 without specifying a base type.
11702 In that case, the base type must be set to the type of
11703 the lower bound, upper bound or count, in that order, if any of these
11704 three attributes references an object that has a type.
11705 If no base type is found, the Dwarf-2 specifications say that
11706 a signed integer type of size equal to the size of an address should
11708 For the following C code: `extern char gdb_int [];'
11709 GCC produces an empty range DIE.
11710 FIXME: muller/2010-05-28: Possible references to object for low bound,
11711 high bound or count are not yet handled by this code. */
11712 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
11714 struct objfile
*objfile
= cu
->objfile
;
11715 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11716 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
11717 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
11719 /* Test "int", "long int", and "long long int" objfile types,
11720 and select the first one having a size above or equal to the
11721 architecture address size. */
11722 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11723 base_type
= int_type
;
11726 int_type
= objfile_type (objfile
)->builtin_long
;
11727 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11728 base_type
= int_type
;
11731 int_type
= objfile_type (objfile
)->builtin_long_long
;
11732 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11733 base_type
= int_type
;
11739 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
11740 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
11741 low
|= negative_mask
;
11742 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
11743 high
|= negative_mask
;
11745 range_type
= create_range_type (NULL
, base_type
, low
, high
);
11747 /* Mark arrays with dynamic length at least as an array of unspecified
11748 length. GDB could check the boundary but before it gets implemented at
11749 least allow accessing the array elements. */
11750 if (attr
&& attr_form_is_block (attr
))
11751 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11753 /* Ada expects an empty array on no boundary attributes. */
11754 if (attr
== NULL
&& cu
->language
!= language_ada
)
11755 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11757 name
= dwarf2_name (die
, cu
);
11759 TYPE_NAME (range_type
) = name
;
11761 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11763 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
11765 set_die_type (die
, range_type
, cu
);
11767 /* set_die_type should be already done. */
11768 set_descriptive_type (range_type
, die
, cu
);
11773 static struct type
*
11774 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11778 /* For now, we only support the C meaning of an unspecified type: void. */
11780 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
11781 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
11783 return set_die_type (die
, type
, cu
);
11786 /* Read a single die and all its descendents. Set the die's sibling
11787 field to NULL; set other fields in the die correctly, and set all
11788 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
11789 location of the info_ptr after reading all of those dies. PARENT
11790 is the parent of the die in question. */
11792 static struct die_info
*
11793 read_die_and_children (const struct die_reader_specs
*reader
,
11794 gdb_byte
*info_ptr
,
11795 gdb_byte
**new_info_ptr
,
11796 struct die_info
*parent
)
11798 struct die_info
*die
;
11802 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
11805 *new_info_ptr
= cur_ptr
;
11808 store_in_ref_table (die
, reader
->cu
);
11811 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
11815 *new_info_ptr
= cur_ptr
;
11818 die
->sibling
= NULL
;
11819 die
->parent
= parent
;
11823 /* Read a die, all of its descendents, and all of its siblings; set
11824 all of the fields of all of the dies correctly. Arguments are as
11825 in read_die_and_children. */
11827 static struct die_info
*
11828 read_die_and_siblings (const struct die_reader_specs
*reader
,
11829 gdb_byte
*info_ptr
,
11830 gdb_byte
**new_info_ptr
,
11831 struct die_info
*parent
)
11833 struct die_info
*first_die
, *last_sibling
;
11836 cur_ptr
= info_ptr
;
11837 first_die
= last_sibling
= NULL
;
11841 struct die_info
*die
11842 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
11846 *new_info_ptr
= cur_ptr
;
11853 last_sibling
->sibling
= die
;
11855 last_sibling
= die
;
11859 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
11861 The caller is responsible for filling in the extra attributes
11862 and updating (*DIEP)->num_attrs.
11863 Set DIEP to point to a newly allocated die with its information,
11864 except for its child, sibling, and parent fields.
11865 Set HAS_CHILDREN to tell whether the die has children or not. */
11868 read_full_die_1 (const struct die_reader_specs
*reader
,
11869 struct die_info
**diep
, gdb_byte
*info_ptr
,
11870 int *has_children
, int num_extra_attrs
)
11872 unsigned int abbrev_number
, bytes_read
, i
;
11873 sect_offset offset
;
11874 struct abbrev_info
*abbrev
;
11875 struct die_info
*die
;
11876 struct dwarf2_cu
*cu
= reader
->cu
;
11877 bfd
*abfd
= reader
->abfd
;
11879 offset
.sect_off
= info_ptr
- reader
->buffer
;
11880 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11881 info_ptr
+= bytes_read
;
11882 if (!abbrev_number
)
11889 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
11891 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
11893 bfd_get_filename (abfd
));
11895 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
11896 die
->offset
= offset
;
11897 die
->tag
= abbrev
->tag
;
11898 die
->abbrev
= abbrev_number
;
11900 /* Make the result usable.
11901 The caller needs to update num_attrs after adding the extra
11903 die
->num_attrs
= abbrev
->num_attrs
;
11905 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11906 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
11910 *has_children
= abbrev
->has_children
;
11914 /* Read a die and all its attributes.
11915 Set DIEP to point to a newly allocated die with its information,
11916 except for its child, sibling, and parent fields.
11917 Set HAS_CHILDREN to tell whether the die has children or not. */
11920 read_full_die (const struct die_reader_specs
*reader
,
11921 struct die_info
**diep
, gdb_byte
*info_ptr
,
11924 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
11927 /* Abbreviation tables.
11929 In DWARF version 2, the description of the debugging information is
11930 stored in a separate .debug_abbrev section. Before we read any
11931 dies from a section we read in all abbreviations and install them
11932 in a hash table. */
11934 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
11936 static struct abbrev_info
*
11937 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
11939 struct abbrev_info
*abbrev
;
11941 abbrev
= (struct abbrev_info
*)
11942 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
11943 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11947 /* Add an abbreviation to the table. */
11950 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
11951 unsigned int abbrev_number
,
11952 struct abbrev_info
*abbrev
)
11954 unsigned int hash_number
;
11956 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11957 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
11958 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
11961 /* Look up an abbrev in the table.
11962 Returns NULL if the abbrev is not found. */
11964 static struct abbrev_info
*
11965 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
11966 unsigned int abbrev_number
)
11968 unsigned int hash_number
;
11969 struct abbrev_info
*abbrev
;
11971 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11972 abbrev
= abbrev_table
->abbrevs
[hash_number
];
11976 if (abbrev
->number
== abbrev_number
)
11978 abbrev
= abbrev
->next
;
11983 /* Read in an abbrev table. */
11985 static struct abbrev_table
*
11986 abbrev_table_read_table (struct dwarf2_section_info
*section
,
11987 sect_offset offset
)
11989 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11990 bfd
*abfd
= section
->asection
->owner
;
11991 struct abbrev_table
*abbrev_table
;
11992 gdb_byte
*abbrev_ptr
;
11993 struct abbrev_info
*cur_abbrev
;
11994 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
11995 unsigned int abbrev_form
;
11996 struct attr_abbrev
*cur_attrs
;
11997 unsigned int allocated_attrs
;
11999 abbrev_table
= XMALLOC (struct abbrev_table
);
12000 abbrev_table
->offset
= offset
;
12001 obstack_init (&abbrev_table
->abbrev_obstack
);
12002 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12004 * sizeof (struct abbrev_info
*)));
12005 memset (abbrev_table
->abbrevs
, 0,
12006 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
12008 dwarf2_read_section (objfile
, section
);
12009 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
12010 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12011 abbrev_ptr
+= bytes_read
;
12013 allocated_attrs
= ATTR_ALLOC_CHUNK
;
12014 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
12016 /* Loop until we reach an abbrev number of 0. */
12017 while (abbrev_number
)
12019 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
12021 /* read in abbrev header */
12022 cur_abbrev
->number
= abbrev_number
;
12023 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12024 abbrev_ptr
+= bytes_read
;
12025 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
12028 /* now read in declarations */
12029 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12030 abbrev_ptr
+= bytes_read
;
12031 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12032 abbrev_ptr
+= bytes_read
;
12033 while (abbrev_name
)
12035 if (cur_abbrev
->num_attrs
== allocated_attrs
)
12037 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
12039 = xrealloc (cur_attrs
, (allocated_attrs
12040 * sizeof (struct attr_abbrev
)));
12043 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
12044 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
12045 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12046 abbrev_ptr
+= bytes_read
;
12047 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12048 abbrev_ptr
+= bytes_read
;
12051 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12052 (cur_abbrev
->num_attrs
12053 * sizeof (struct attr_abbrev
)));
12054 memcpy (cur_abbrev
->attrs
, cur_attrs
,
12055 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
12057 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
12059 /* Get next abbreviation.
12060 Under Irix6 the abbreviations for a compilation unit are not
12061 always properly terminated with an abbrev number of 0.
12062 Exit loop if we encounter an abbreviation which we have
12063 already read (which means we are about to read the abbreviations
12064 for the next compile unit) or if the end of the abbreviation
12065 table is reached. */
12066 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
12068 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12069 abbrev_ptr
+= bytes_read
;
12070 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
12075 return abbrev_table
;
12078 /* Free the resources held by ABBREV_TABLE. */
12081 abbrev_table_free (struct abbrev_table
*abbrev_table
)
12083 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
12084 xfree (abbrev_table
);
12087 /* Same as abbrev_table_free but as a cleanup.
12088 We pass in a pointer to the pointer to the table so that we can
12089 set the pointer to NULL when we're done. It also simplifies
12090 build_type_unit_groups. */
12093 abbrev_table_free_cleanup (void *table_ptr
)
12095 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
12097 if (*abbrev_table_ptr
!= NULL
)
12098 abbrev_table_free (*abbrev_table_ptr
);
12099 *abbrev_table_ptr
= NULL
;
12102 /* Read the abbrev table for CU from ABBREV_SECTION. */
12105 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
12106 struct dwarf2_section_info
*abbrev_section
)
12109 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
12112 /* Release the memory used by the abbrev table for a compilation unit. */
12115 dwarf2_free_abbrev_table (void *ptr_to_cu
)
12117 struct dwarf2_cu
*cu
= ptr_to_cu
;
12119 abbrev_table_free (cu
->abbrev_table
);
12120 /* Set this to NULL so that we SEGV if we try to read it later,
12121 and also because free_comp_unit verifies this is NULL. */
12122 cu
->abbrev_table
= NULL
;
12125 /* Returns nonzero if TAG represents a type that we might generate a partial
12129 is_type_tag_for_partial (int tag
)
12134 /* Some types that would be reasonable to generate partial symbols for,
12135 that we don't at present. */
12136 case DW_TAG_array_type
:
12137 case DW_TAG_file_type
:
12138 case DW_TAG_ptr_to_member_type
:
12139 case DW_TAG_set_type
:
12140 case DW_TAG_string_type
:
12141 case DW_TAG_subroutine_type
:
12143 case DW_TAG_base_type
:
12144 case DW_TAG_class_type
:
12145 case DW_TAG_interface_type
:
12146 case DW_TAG_enumeration_type
:
12147 case DW_TAG_structure_type
:
12148 case DW_TAG_subrange_type
:
12149 case DW_TAG_typedef
:
12150 case DW_TAG_union_type
:
12157 /* Load all DIEs that are interesting for partial symbols into memory. */
12159 static struct partial_die_info
*
12160 load_partial_dies (const struct die_reader_specs
*reader
,
12161 gdb_byte
*info_ptr
, int building_psymtab
)
12163 struct dwarf2_cu
*cu
= reader
->cu
;
12164 struct objfile
*objfile
= cu
->objfile
;
12165 struct partial_die_info
*part_die
;
12166 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
12167 struct abbrev_info
*abbrev
;
12168 unsigned int bytes_read
;
12169 unsigned int load_all
= 0;
12170 int nesting_level
= 1;
12175 gdb_assert (cu
->per_cu
!= NULL
);
12176 if (cu
->per_cu
->load_all_dies
)
12180 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12184 &cu
->comp_unit_obstack
,
12185 hashtab_obstack_allocate
,
12186 dummy_obstack_deallocate
);
12188 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12189 sizeof (struct partial_die_info
));
12193 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
12195 /* A NULL abbrev means the end of a series of children. */
12196 if (abbrev
== NULL
)
12198 if (--nesting_level
== 0)
12200 /* PART_DIE was probably the last thing allocated on the
12201 comp_unit_obstack, so we could call obstack_free
12202 here. We don't do that because the waste is small,
12203 and will be cleaned up when we're done with this
12204 compilation unit. This way, we're also more robust
12205 against other users of the comp_unit_obstack. */
12208 info_ptr
+= bytes_read
;
12209 last_die
= parent_die
;
12210 parent_die
= parent_die
->die_parent
;
12214 /* Check for template arguments. We never save these; if
12215 they're seen, we just mark the parent, and go on our way. */
12216 if (parent_die
!= NULL
12217 && cu
->language
== language_cplus
12218 && (abbrev
->tag
== DW_TAG_template_type_param
12219 || abbrev
->tag
== DW_TAG_template_value_param
))
12221 parent_die
->has_template_arguments
= 1;
12225 /* We don't need a partial DIE for the template argument. */
12226 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12231 /* We only recurse into c++ subprograms looking for template arguments.
12232 Skip their other children. */
12234 && cu
->language
== language_cplus
12235 && parent_die
!= NULL
12236 && parent_die
->tag
== DW_TAG_subprogram
)
12238 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12242 /* Check whether this DIE is interesting enough to save. Normally
12243 we would not be interested in members here, but there may be
12244 later variables referencing them via DW_AT_specification (for
12245 static members). */
12247 && !is_type_tag_for_partial (abbrev
->tag
)
12248 && abbrev
->tag
!= DW_TAG_constant
12249 && abbrev
->tag
!= DW_TAG_enumerator
12250 && abbrev
->tag
!= DW_TAG_subprogram
12251 && abbrev
->tag
!= DW_TAG_lexical_block
12252 && abbrev
->tag
!= DW_TAG_variable
12253 && abbrev
->tag
!= DW_TAG_namespace
12254 && abbrev
->tag
!= DW_TAG_module
12255 && abbrev
->tag
!= DW_TAG_member
12256 && abbrev
->tag
!= DW_TAG_imported_unit
)
12258 /* Otherwise we skip to the next sibling, if any. */
12259 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12263 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
12266 /* This two-pass algorithm for processing partial symbols has a
12267 high cost in cache pressure. Thus, handle some simple cases
12268 here which cover the majority of C partial symbols. DIEs
12269 which neither have specification tags in them, nor could have
12270 specification tags elsewhere pointing at them, can simply be
12271 processed and discarded.
12273 This segment is also optional; scan_partial_symbols and
12274 add_partial_symbol will handle these DIEs if we chain
12275 them in normally. When compilers which do not emit large
12276 quantities of duplicate debug information are more common,
12277 this code can probably be removed. */
12279 /* Any complete simple types at the top level (pretty much all
12280 of them, for a language without namespaces), can be processed
12282 if (parent_die
== NULL
12283 && part_die
->has_specification
== 0
12284 && part_die
->is_declaration
== 0
12285 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
12286 || part_die
->tag
== DW_TAG_base_type
12287 || part_die
->tag
== DW_TAG_subrange_type
))
12289 if (building_psymtab
&& part_die
->name
!= NULL
)
12290 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12291 VAR_DOMAIN
, LOC_TYPEDEF
,
12292 &objfile
->static_psymbols
,
12293 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12294 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12298 /* The exception for DW_TAG_typedef with has_children above is
12299 a workaround of GCC PR debug/47510. In the case of this complaint
12300 type_name_no_tag_or_error will error on such types later.
12302 GDB skipped children of DW_TAG_typedef by the shortcut above and then
12303 it could not find the child DIEs referenced later, this is checked
12304 above. In correct DWARF DW_TAG_typedef should have no children. */
12306 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
12307 complaint (&symfile_complaints
,
12308 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
12309 "- DIE at 0x%x [in module %s]"),
12310 part_die
->offset
.sect_off
, objfile
->name
);
12312 /* If we're at the second level, and we're an enumerator, and
12313 our parent has no specification (meaning possibly lives in a
12314 namespace elsewhere), then we can add the partial symbol now
12315 instead of queueing it. */
12316 if (part_die
->tag
== DW_TAG_enumerator
12317 && parent_die
!= NULL
12318 && parent_die
->die_parent
== NULL
12319 && parent_die
->tag
== DW_TAG_enumeration_type
12320 && parent_die
->has_specification
== 0)
12322 if (part_die
->name
== NULL
)
12323 complaint (&symfile_complaints
,
12324 _("malformed enumerator DIE ignored"));
12325 else if (building_psymtab
)
12326 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12327 VAR_DOMAIN
, LOC_CONST
,
12328 (cu
->language
== language_cplus
12329 || cu
->language
== language_java
)
12330 ? &objfile
->global_psymbols
12331 : &objfile
->static_psymbols
,
12332 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12334 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12338 /* We'll save this DIE so link it in. */
12339 part_die
->die_parent
= parent_die
;
12340 part_die
->die_sibling
= NULL
;
12341 part_die
->die_child
= NULL
;
12343 if (last_die
&& last_die
== parent_die
)
12344 last_die
->die_child
= part_die
;
12346 last_die
->die_sibling
= part_die
;
12348 last_die
= part_die
;
12350 if (first_die
== NULL
)
12351 first_die
= part_die
;
12353 /* Maybe add the DIE to the hash table. Not all DIEs that we
12354 find interesting need to be in the hash table, because we
12355 also have the parent/sibling/child chains; only those that we
12356 might refer to by offset later during partial symbol reading.
12358 For now this means things that might have be the target of a
12359 DW_AT_specification, DW_AT_abstract_origin, or
12360 DW_AT_extension. DW_AT_extension will refer only to
12361 namespaces; DW_AT_abstract_origin refers to functions (and
12362 many things under the function DIE, but we do not recurse
12363 into function DIEs during partial symbol reading) and
12364 possibly variables as well; DW_AT_specification refers to
12365 declarations. Declarations ought to have the DW_AT_declaration
12366 flag. It happens that GCC forgets to put it in sometimes, but
12367 only for functions, not for types.
12369 Adding more things than necessary to the hash table is harmless
12370 except for the performance cost. Adding too few will result in
12371 wasted time in find_partial_die, when we reread the compilation
12372 unit with load_all_dies set. */
12375 || abbrev
->tag
== DW_TAG_constant
12376 || abbrev
->tag
== DW_TAG_subprogram
12377 || abbrev
->tag
== DW_TAG_variable
12378 || abbrev
->tag
== DW_TAG_namespace
12379 || part_die
->is_declaration
)
12383 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
12384 part_die
->offset
.sect_off
, INSERT
);
12388 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12389 sizeof (struct partial_die_info
));
12391 /* For some DIEs we want to follow their children (if any). For C
12392 we have no reason to follow the children of structures; for other
12393 languages we have to, so that we can get at method physnames
12394 to infer fully qualified class names, for DW_AT_specification,
12395 and for C++ template arguments. For C++, we also look one level
12396 inside functions to find template arguments (if the name of the
12397 function does not already contain the template arguments).
12399 For Ada, we need to scan the children of subprograms and lexical
12400 blocks as well because Ada allows the definition of nested
12401 entities that could be interesting for the debugger, such as
12402 nested subprograms for instance. */
12403 if (last_die
->has_children
12405 || last_die
->tag
== DW_TAG_namespace
12406 || last_die
->tag
== DW_TAG_module
12407 || last_die
->tag
== DW_TAG_enumeration_type
12408 || (cu
->language
== language_cplus
12409 && last_die
->tag
== DW_TAG_subprogram
12410 && (last_die
->name
== NULL
12411 || strchr (last_die
->name
, '<') == NULL
))
12412 || (cu
->language
!= language_c
12413 && (last_die
->tag
== DW_TAG_class_type
12414 || last_die
->tag
== DW_TAG_interface_type
12415 || last_die
->tag
== DW_TAG_structure_type
12416 || last_die
->tag
== DW_TAG_union_type
))
12417 || (cu
->language
== language_ada
12418 && (last_die
->tag
== DW_TAG_subprogram
12419 || last_die
->tag
== DW_TAG_lexical_block
))))
12422 parent_die
= last_die
;
12426 /* Otherwise we skip to the next sibling, if any. */
12427 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
12429 /* Back to the top, do it again. */
12433 /* Read a minimal amount of information into the minimal die structure. */
12436 read_partial_die (const struct die_reader_specs
*reader
,
12437 struct partial_die_info
*part_die
,
12438 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
12439 gdb_byte
*info_ptr
)
12441 struct dwarf2_cu
*cu
= reader
->cu
;
12442 struct objfile
*objfile
= cu
->objfile
;
12443 gdb_byte
*buffer
= reader
->buffer
;
12445 struct attribute attr
;
12446 int has_low_pc_attr
= 0;
12447 int has_high_pc_attr
= 0;
12448 int high_pc_relative
= 0;
12450 memset (part_die
, 0, sizeof (struct partial_die_info
));
12452 part_die
->offset
.sect_off
= info_ptr
- buffer
;
12454 info_ptr
+= abbrev_len
;
12456 if (abbrev
== NULL
)
12459 part_die
->tag
= abbrev
->tag
;
12460 part_die
->has_children
= abbrev
->has_children
;
12462 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12464 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
12466 /* Store the data if it is of an attribute we want to keep in a
12467 partial symbol table. */
12471 switch (part_die
->tag
)
12473 case DW_TAG_compile_unit
:
12474 case DW_TAG_partial_unit
:
12475 case DW_TAG_type_unit
:
12476 /* Compilation units have a DW_AT_name that is a filename, not
12477 a source language identifier. */
12478 case DW_TAG_enumeration_type
:
12479 case DW_TAG_enumerator
:
12480 /* These tags always have simple identifiers already; no need
12481 to canonicalize them. */
12482 part_die
->name
= DW_STRING (&attr
);
12486 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
12487 &objfile
->objfile_obstack
);
12491 case DW_AT_linkage_name
:
12492 case DW_AT_MIPS_linkage_name
:
12493 /* Note that both forms of linkage name might appear. We
12494 assume they will be the same, and we only store the last
12496 if (cu
->language
== language_ada
)
12497 part_die
->name
= DW_STRING (&attr
);
12498 part_die
->linkage_name
= DW_STRING (&attr
);
12501 has_low_pc_attr
= 1;
12502 part_die
->lowpc
= DW_ADDR (&attr
);
12504 case DW_AT_high_pc
:
12505 has_high_pc_attr
= 1;
12506 if (attr
.form
== DW_FORM_addr
12507 || attr
.form
== DW_FORM_GNU_addr_index
)
12508 part_die
->highpc
= DW_ADDR (&attr
);
12511 high_pc_relative
= 1;
12512 part_die
->highpc
= DW_UNSND (&attr
);
12515 case DW_AT_location
:
12516 /* Support the .debug_loc offsets. */
12517 if (attr_form_is_block (&attr
))
12519 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
12521 else if (attr_form_is_section_offset (&attr
))
12523 dwarf2_complex_location_expr_complaint ();
12527 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12528 "partial symbol information");
12531 case DW_AT_external
:
12532 part_die
->is_external
= DW_UNSND (&attr
);
12534 case DW_AT_declaration
:
12535 part_die
->is_declaration
= DW_UNSND (&attr
);
12538 part_die
->has_type
= 1;
12540 case DW_AT_abstract_origin
:
12541 case DW_AT_specification
:
12542 case DW_AT_extension
:
12543 part_die
->has_specification
= 1;
12544 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
12546 case DW_AT_sibling
:
12547 /* Ignore absolute siblings, they might point outside of
12548 the current compile unit. */
12549 if (attr
.form
== DW_FORM_ref_addr
)
12550 complaint (&symfile_complaints
,
12551 _("ignoring absolute DW_AT_sibling"));
12553 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
12555 case DW_AT_byte_size
:
12556 part_die
->has_byte_size
= 1;
12558 case DW_AT_calling_convention
:
12559 /* DWARF doesn't provide a way to identify a program's source-level
12560 entry point. DW_AT_calling_convention attributes are only meant
12561 to describe functions' calling conventions.
12563 However, because it's a necessary piece of information in
12564 Fortran, and because DW_CC_program is the only piece of debugging
12565 information whose definition refers to a 'main program' at all,
12566 several compilers have begun marking Fortran main programs with
12567 DW_CC_program --- even when those functions use the standard
12568 calling conventions.
12570 So until DWARF specifies a way to provide this information and
12571 compilers pick up the new representation, we'll support this
12573 if (DW_UNSND (&attr
) == DW_CC_program
12574 && cu
->language
== language_fortran
)
12576 set_main_name (part_die
->name
);
12578 /* As this DIE has a static linkage the name would be difficult
12579 to look up later. */
12580 language_of_main
= language_fortran
;
12584 if (DW_UNSND (&attr
) == DW_INL_inlined
12585 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
12586 part_die
->may_be_inlined
= 1;
12590 if (part_die
->tag
== DW_TAG_imported_unit
)
12591 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
12599 if (high_pc_relative
)
12600 part_die
->highpc
+= part_die
->lowpc
;
12602 if (has_low_pc_attr
&& has_high_pc_attr
)
12604 /* When using the GNU linker, .gnu.linkonce. sections are used to
12605 eliminate duplicate copies of functions and vtables and such.
12606 The linker will arbitrarily choose one and discard the others.
12607 The AT_*_pc values for such functions refer to local labels in
12608 these sections. If the section from that file was discarded, the
12609 labels are not in the output, so the relocs get a value of 0.
12610 If this is a discarded function, mark the pc bounds as invalid,
12611 so that GDB will ignore it. */
12612 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12614 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12616 complaint (&symfile_complaints
,
12617 _("DW_AT_low_pc %s is zero "
12618 "for DIE at 0x%x [in module %s]"),
12619 paddress (gdbarch
, part_die
->lowpc
),
12620 part_die
->offset
.sect_off
, objfile
->name
);
12622 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
12623 else if (part_die
->lowpc
>= part_die
->highpc
)
12625 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12627 complaint (&symfile_complaints
,
12628 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
12629 "for DIE at 0x%x [in module %s]"),
12630 paddress (gdbarch
, part_die
->lowpc
),
12631 paddress (gdbarch
, part_die
->highpc
),
12632 part_die
->offset
.sect_off
, objfile
->name
);
12635 part_die
->has_pc_info
= 1;
12641 /* Find a cached partial DIE at OFFSET in CU. */
12643 static struct partial_die_info
*
12644 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
12646 struct partial_die_info
*lookup_die
= NULL
;
12647 struct partial_die_info part_die
;
12649 part_die
.offset
= offset
;
12650 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
12656 /* Find a partial DIE at OFFSET, which may or may not be in CU,
12657 except in the case of .debug_types DIEs which do not reference
12658 outside their CU (they do however referencing other types via
12659 DW_FORM_ref_sig8). */
12661 static struct partial_die_info
*
12662 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
12664 struct objfile
*objfile
= cu
->objfile
;
12665 struct dwarf2_per_cu_data
*per_cu
= NULL
;
12666 struct partial_die_info
*pd
= NULL
;
12668 if (offset_in_cu_p (&cu
->header
, offset
))
12670 pd
= find_partial_die_in_comp_unit (offset
, cu
);
12673 /* We missed recording what we needed.
12674 Load all dies and try again. */
12675 per_cu
= cu
->per_cu
;
12679 /* TUs don't reference other CUs/TUs (except via type signatures). */
12680 if (cu
->per_cu
->is_debug_types
)
12682 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
12683 " external reference to offset 0x%lx [in module %s].\n"),
12684 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
12685 bfd_get_filename (objfile
->obfd
));
12687 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
12689 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
12690 load_partial_comp_unit (per_cu
);
12692 per_cu
->cu
->last_used
= 0;
12693 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12696 /* If we didn't find it, and not all dies have been loaded,
12697 load them all and try again. */
12699 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
12701 per_cu
->load_all_dies
= 1;
12703 /* This is nasty. When we reread the DIEs, somewhere up the call chain
12704 THIS_CU->cu may already be in use. So we can't just free it and
12705 replace its DIEs with the ones we read in. Instead, we leave those
12706 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
12707 and clobber THIS_CU->cu->partial_dies with the hash table for the new
12709 load_partial_comp_unit (per_cu
);
12711 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12715 internal_error (__FILE__
, __LINE__
,
12716 _("could not find partial DIE 0x%x "
12717 "in cache [from module %s]\n"),
12718 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
12722 /* See if we can figure out if the class lives in a namespace. We do
12723 this by looking for a member function; its demangled name will
12724 contain namespace info, if there is any. */
12727 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
12728 struct dwarf2_cu
*cu
)
12730 /* NOTE: carlton/2003-10-07: Getting the info this way changes
12731 what template types look like, because the demangler
12732 frequently doesn't give the same name as the debug info. We
12733 could fix this by only using the demangled name to get the
12734 prefix (but see comment in read_structure_type). */
12736 struct partial_die_info
*real_pdi
;
12737 struct partial_die_info
*child_pdi
;
12739 /* If this DIE (this DIE's specification, if any) has a parent, then
12740 we should not do this. We'll prepend the parent's fully qualified
12741 name when we create the partial symbol. */
12743 real_pdi
= struct_pdi
;
12744 while (real_pdi
->has_specification
)
12745 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
12747 if (real_pdi
->die_parent
!= NULL
)
12750 for (child_pdi
= struct_pdi
->die_child
;
12752 child_pdi
= child_pdi
->die_sibling
)
12754 if (child_pdi
->tag
== DW_TAG_subprogram
12755 && child_pdi
->linkage_name
!= NULL
)
12757 char *actual_class_name
12758 = language_class_name_from_physname (cu
->language_defn
,
12759 child_pdi
->linkage_name
);
12760 if (actual_class_name
!= NULL
)
12763 = obsavestring (actual_class_name
,
12764 strlen (actual_class_name
),
12765 &cu
->objfile
->objfile_obstack
);
12766 xfree (actual_class_name
);
12773 /* Adjust PART_DIE before generating a symbol for it. This function
12774 may set the is_external flag or change the DIE's name. */
12777 fixup_partial_die (struct partial_die_info
*part_die
,
12778 struct dwarf2_cu
*cu
)
12780 /* Once we've fixed up a die, there's no point in doing so again.
12781 This also avoids a memory leak if we were to call
12782 guess_partial_die_structure_name multiple times. */
12783 if (part_die
->fixup_called
)
12786 /* If we found a reference attribute and the DIE has no name, try
12787 to find a name in the referred to DIE. */
12789 if (part_die
->name
== NULL
&& part_die
->has_specification
)
12791 struct partial_die_info
*spec_die
;
12793 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
12795 fixup_partial_die (spec_die
, cu
);
12797 if (spec_die
->name
)
12799 part_die
->name
= spec_die
->name
;
12801 /* Copy DW_AT_external attribute if it is set. */
12802 if (spec_die
->is_external
)
12803 part_die
->is_external
= spec_die
->is_external
;
12807 /* Set default names for some unnamed DIEs. */
12809 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
12810 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
12812 /* If there is no parent die to provide a namespace, and there are
12813 children, see if we can determine the namespace from their linkage
12815 if (cu
->language
== language_cplus
12816 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12817 && part_die
->die_parent
== NULL
12818 && part_die
->has_children
12819 && (part_die
->tag
== DW_TAG_class_type
12820 || part_die
->tag
== DW_TAG_structure_type
12821 || part_die
->tag
== DW_TAG_union_type
))
12822 guess_partial_die_structure_name (part_die
, cu
);
12824 /* GCC might emit a nameless struct or union that has a linkage
12825 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12826 if (part_die
->name
== NULL
12827 && (part_die
->tag
== DW_TAG_class_type
12828 || part_die
->tag
== DW_TAG_interface_type
12829 || part_die
->tag
== DW_TAG_structure_type
12830 || part_die
->tag
== DW_TAG_union_type
)
12831 && part_die
->linkage_name
!= NULL
)
12835 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
12840 /* Strip any leading namespaces/classes, keep only the base name.
12841 DW_AT_name for named DIEs does not contain the prefixes. */
12842 base
= strrchr (demangled
, ':');
12843 if (base
&& base
> demangled
&& base
[-1] == ':')
12848 part_die
->name
= obsavestring (base
, strlen (base
),
12849 &cu
->objfile
->objfile_obstack
);
12854 part_die
->fixup_called
= 1;
12857 /* Read an attribute value described by an attribute form. */
12860 read_attribute_value (const struct die_reader_specs
*reader
,
12861 struct attribute
*attr
, unsigned form
,
12862 gdb_byte
*info_ptr
)
12864 struct dwarf2_cu
*cu
= reader
->cu
;
12865 bfd
*abfd
= reader
->abfd
;
12866 struct comp_unit_head
*cu_header
= &cu
->header
;
12867 unsigned int bytes_read
;
12868 struct dwarf_block
*blk
;
12873 case DW_FORM_ref_addr
:
12874 if (cu
->header
.version
== 2)
12875 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12877 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
12878 &cu
->header
, &bytes_read
);
12879 info_ptr
+= bytes_read
;
12882 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12883 info_ptr
+= bytes_read
;
12885 case DW_FORM_block2
:
12886 blk
= dwarf_alloc_block (cu
);
12887 blk
->size
= read_2_bytes (abfd
, info_ptr
);
12889 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12890 info_ptr
+= blk
->size
;
12891 DW_BLOCK (attr
) = blk
;
12893 case DW_FORM_block4
:
12894 blk
= dwarf_alloc_block (cu
);
12895 blk
->size
= read_4_bytes (abfd
, info_ptr
);
12897 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12898 info_ptr
+= blk
->size
;
12899 DW_BLOCK (attr
) = blk
;
12901 case DW_FORM_data2
:
12902 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
12905 case DW_FORM_data4
:
12906 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
12909 case DW_FORM_data8
:
12910 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
12913 case DW_FORM_sec_offset
:
12914 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
12915 info_ptr
+= bytes_read
;
12917 case DW_FORM_string
:
12918 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
12919 DW_STRING_IS_CANONICAL (attr
) = 0;
12920 info_ptr
+= bytes_read
;
12923 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
12925 DW_STRING_IS_CANONICAL (attr
) = 0;
12926 info_ptr
+= bytes_read
;
12928 case DW_FORM_exprloc
:
12929 case DW_FORM_block
:
12930 blk
= dwarf_alloc_block (cu
);
12931 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12932 info_ptr
+= bytes_read
;
12933 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12934 info_ptr
+= blk
->size
;
12935 DW_BLOCK (attr
) = blk
;
12937 case DW_FORM_block1
:
12938 blk
= dwarf_alloc_block (cu
);
12939 blk
->size
= read_1_byte (abfd
, info_ptr
);
12941 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12942 info_ptr
+= blk
->size
;
12943 DW_BLOCK (attr
) = blk
;
12945 case DW_FORM_data1
:
12946 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12950 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12953 case DW_FORM_flag_present
:
12954 DW_UNSND (attr
) = 1;
12956 case DW_FORM_sdata
:
12957 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
12958 info_ptr
+= bytes_read
;
12960 case DW_FORM_udata
:
12961 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12962 info_ptr
+= bytes_read
;
12965 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12966 + read_1_byte (abfd
, info_ptr
));
12970 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12971 + read_2_bytes (abfd
, info_ptr
));
12975 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12976 + read_4_bytes (abfd
, info_ptr
));
12980 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12981 + read_8_bytes (abfd
, info_ptr
));
12984 case DW_FORM_ref_sig8
:
12985 /* Convert the signature to something we can record in DW_UNSND
12987 NOTE: This is NULL if the type wasn't found. */
12988 DW_SIGNATURED_TYPE (attr
) =
12989 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
12992 case DW_FORM_ref_udata
:
12993 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12994 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
12995 info_ptr
+= bytes_read
;
12997 case DW_FORM_indirect
:
12998 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12999 info_ptr
+= bytes_read
;
13000 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
13002 case DW_FORM_GNU_addr_index
:
13003 if (reader
->dwo_file
== NULL
)
13005 /* For now flag a hard error.
13006 Later we can turn this into a complaint. */
13007 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13008 dwarf_form_name (form
),
13009 bfd_get_filename (abfd
));
13011 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
13012 info_ptr
+= bytes_read
;
13014 case DW_FORM_GNU_str_index
:
13015 if (reader
->dwo_file
== NULL
)
13017 /* For now flag a hard error.
13018 Later we can turn this into a complaint if warranted. */
13019 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13020 dwarf_form_name (form
),
13021 bfd_get_filename (abfd
));
13024 ULONGEST str_index
=
13025 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13027 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
13028 DW_STRING_IS_CANONICAL (attr
) = 0;
13029 info_ptr
+= bytes_read
;
13033 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
13034 dwarf_form_name (form
),
13035 bfd_get_filename (abfd
));
13038 /* We have seen instances where the compiler tried to emit a byte
13039 size attribute of -1 which ended up being encoded as an unsigned
13040 0xffffffff. Although 0xffffffff is technically a valid size value,
13041 an object of this size seems pretty unlikely so we can relatively
13042 safely treat these cases as if the size attribute was invalid and
13043 treat them as zero by default. */
13044 if (attr
->name
== DW_AT_byte_size
13045 && form
== DW_FORM_data4
13046 && DW_UNSND (attr
) >= 0xffffffff)
13049 (&symfile_complaints
,
13050 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
13051 hex_string (DW_UNSND (attr
)));
13052 DW_UNSND (attr
) = 0;
13058 /* Read an attribute described by an abbreviated attribute. */
13061 read_attribute (const struct die_reader_specs
*reader
,
13062 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
13063 gdb_byte
*info_ptr
)
13065 attr
->name
= abbrev
->name
;
13066 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
13069 /* Read dwarf information from a buffer. */
13071 static unsigned int
13072 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
13074 return bfd_get_8 (abfd
, buf
);
13078 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
13080 return bfd_get_signed_8 (abfd
, buf
);
13083 static unsigned int
13084 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
13086 return bfd_get_16 (abfd
, buf
);
13090 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13092 return bfd_get_signed_16 (abfd
, buf
);
13095 static unsigned int
13096 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
13098 return bfd_get_32 (abfd
, buf
);
13102 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13104 return bfd_get_signed_32 (abfd
, buf
);
13108 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
13110 return bfd_get_64 (abfd
, buf
);
13114 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
13115 unsigned int *bytes_read
)
13117 struct comp_unit_head
*cu_header
= &cu
->header
;
13118 CORE_ADDR retval
= 0;
13120 if (cu_header
->signed_addr_p
)
13122 switch (cu_header
->addr_size
)
13125 retval
= bfd_get_signed_16 (abfd
, buf
);
13128 retval
= bfd_get_signed_32 (abfd
, buf
);
13131 retval
= bfd_get_signed_64 (abfd
, buf
);
13134 internal_error (__FILE__
, __LINE__
,
13135 _("read_address: bad switch, signed [in module %s]"),
13136 bfd_get_filename (abfd
));
13141 switch (cu_header
->addr_size
)
13144 retval
= bfd_get_16 (abfd
, buf
);
13147 retval
= bfd_get_32 (abfd
, buf
);
13150 retval
= bfd_get_64 (abfd
, buf
);
13153 internal_error (__FILE__
, __LINE__
,
13154 _("read_address: bad switch, "
13155 "unsigned [in module %s]"),
13156 bfd_get_filename (abfd
));
13160 *bytes_read
= cu_header
->addr_size
;
13164 /* Read the initial length from a section. The (draft) DWARF 3
13165 specification allows the initial length to take up either 4 bytes
13166 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
13167 bytes describe the length and all offsets will be 8 bytes in length
13170 An older, non-standard 64-bit format is also handled by this
13171 function. The older format in question stores the initial length
13172 as an 8-byte quantity without an escape value. Lengths greater
13173 than 2^32 aren't very common which means that the initial 4 bytes
13174 is almost always zero. Since a length value of zero doesn't make
13175 sense for the 32-bit format, this initial zero can be considered to
13176 be an escape value which indicates the presence of the older 64-bit
13177 format. As written, the code can't detect (old format) lengths
13178 greater than 4GB. If it becomes necessary to handle lengths
13179 somewhat larger than 4GB, we could allow other small values (such
13180 as the non-sensical values of 1, 2, and 3) to also be used as
13181 escape values indicating the presence of the old format.
13183 The value returned via bytes_read should be used to increment the
13184 relevant pointer after calling read_initial_length().
13186 [ Note: read_initial_length() and read_offset() are based on the
13187 document entitled "DWARF Debugging Information Format", revision
13188 3, draft 8, dated November 19, 2001. This document was obtained
13191 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
13193 This document is only a draft and is subject to change. (So beware.)
13195 Details regarding the older, non-standard 64-bit format were
13196 determined empirically by examining 64-bit ELF files produced by
13197 the SGI toolchain on an IRIX 6.5 machine.
13199 - Kevin, July 16, 2002
13203 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
13205 LONGEST length
= bfd_get_32 (abfd
, buf
);
13207 if (length
== 0xffffffff)
13209 length
= bfd_get_64 (abfd
, buf
+ 4);
13212 else if (length
== 0)
13214 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
13215 length
= bfd_get_64 (abfd
, buf
);
13226 /* Cover function for read_initial_length.
13227 Returns the length of the object at BUF, and stores the size of the
13228 initial length in *BYTES_READ and stores the size that offsets will be in
13230 If the initial length size is not equivalent to that specified in
13231 CU_HEADER then issue a complaint.
13232 This is useful when reading non-comp-unit headers. */
13235 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
13236 const struct comp_unit_head
*cu_header
,
13237 unsigned int *bytes_read
,
13238 unsigned int *offset_size
)
13240 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
13242 gdb_assert (cu_header
->initial_length_size
== 4
13243 || cu_header
->initial_length_size
== 8
13244 || cu_header
->initial_length_size
== 12);
13246 if (cu_header
->initial_length_size
!= *bytes_read
)
13247 complaint (&symfile_complaints
,
13248 _("intermixed 32-bit and 64-bit DWARF sections"));
13250 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
13254 /* Read an offset from the data stream. The size of the offset is
13255 given by cu_header->offset_size. */
13258 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
13259 unsigned int *bytes_read
)
13261 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
13263 *bytes_read
= cu_header
->offset_size
;
13267 /* Read an offset from the data stream. */
13270 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
13272 LONGEST retval
= 0;
13274 switch (offset_size
)
13277 retval
= bfd_get_32 (abfd
, buf
);
13280 retval
= bfd_get_64 (abfd
, buf
);
13283 internal_error (__FILE__
, __LINE__
,
13284 _("read_offset_1: bad switch [in module %s]"),
13285 bfd_get_filename (abfd
));
13292 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
13294 /* If the size of a host char is 8 bits, we can return a pointer
13295 to the buffer, otherwise we have to copy the data to a buffer
13296 allocated on the temporary obstack. */
13297 gdb_assert (HOST_CHAR_BIT
== 8);
13302 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13304 /* If the size of a host char is 8 bits, we can return a pointer
13305 to the string, otherwise we have to copy the string to a buffer
13306 allocated on the temporary obstack. */
13307 gdb_assert (HOST_CHAR_BIT
== 8);
13310 *bytes_read_ptr
= 1;
13313 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
13314 return (char *) buf
;
13318 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
13320 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
13321 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
13322 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
13323 bfd_get_filename (abfd
));
13324 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
13325 error (_("DW_FORM_strp pointing outside of "
13326 ".debug_str section [in module %s]"),
13327 bfd_get_filename (abfd
));
13328 gdb_assert (HOST_CHAR_BIT
== 8);
13329 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
13331 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
13335 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
13336 const struct comp_unit_head
*cu_header
,
13337 unsigned int *bytes_read_ptr
)
13339 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
13341 return read_indirect_string_at_offset (abfd
, str_offset
);
13345 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13348 unsigned int num_read
;
13350 unsigned char byte
;
13358 byte
= bfd_get_8 (abfd
, buf
);
13361 result
|= ((ULONGEST
) (byte
& 127) << shift
);
13362 if ((byte
& 128) == 0)
13368 *bytes_read_ptr
= num_read
;
13373 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13376 int i
, shift
, num_read
;
13377 unsigned char byte
;
13385 byte
= bfd_get_8 (abfd
, buf
);
13388 result
|= ((LONGEST
) (byte
& 127) << shift
);
13390 if ((byte
& 128) == 0)
13395 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
13396 result
|= -(((LONGEST
) 1) << shift
);
13397 *bytes_read_ptr
= num_read
;
13401 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
13402 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
13403 ADDR_SIZE is the size of addresses from the CU header. */
13406 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
13408 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13409 bfd
*abfd
= objfile
->obfd
;
13410 const gdb_byte
*info_ptr
;
13412 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
13413 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
13414 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
13416 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
13417 error (_("DW_FORM_addr_index pointing outside of "
13418 ".debug_addr section [in module %s]"),
13420 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
13421 + addr_base
+ addr_index
* addr_size
);
13422 if (addr_size
== 4)
13423 return bfd_get_32 (abfd
, info_ptr
);
13425 return bfd_get_64 (abfd
, info_ptr
);
13428 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
13431 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
13433 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
13436 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
13439 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
13440 unsigned int *bytes_read
)
13442 bfd
*abfd
= cu
->objfile
->obfd
;
13443 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
13445 return read_addr_index (cu
, addr_index
);
13448 /* Data structure to pass results from dwarf2_read_addr_index_reader
13449 back to dwarf2_read_addr_index. */
13451 struct dwarf2_read_addr_index_data
13453 ULONGEST addr_base
;
13457 /* die_reader_func for dwarf2_read_addr_index. */
13460 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
13461 gdb_byte
*info_ptr
,
13462 struct die_info
*comp_unit_die
,
13466 struct dwarf2_cu
*cu
= reader
->cu
;
13467 struct dwarf2_read_addr_index_data
*aidata
=
13468 (struct dwarf2_read_addr_index_data
*) data
;
13470 aidata
->addr_base
= cu
->addr_base
;
13471 aidata
->addr_size
= cu
->header
.addr_size
;
13474 /* Given an index in .debug_addr, fetch the value.
13475 NOTE: This can be called during dwarf expression evaluation,
13476 long after the debug information has been read, and thus per_cu->cu
13477 may no longer exist. */
13480 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
13481 unsigned int addr_index
)
13483 struct objfile
*objfile
= per_cu
->objfile
;
13484 struct dwarf2_cu
*cu
= per_cu
->cu
;
13485 ULONGEST addr_base
;
13488 /* This is intended to be called from outside this file. */
13489 dw2_setup (objfile
);
13491 /* We need addr_base and addr_size.
13492 If we don't have PER_CU->cu, we have to get it.
13493 Nasty, but the alternative is storing the needed info in PER_CU,
13494 which at this point doesn't seem justified: it's not clear how frequently
13495 it would get used and it would increase the size of every PER_CU.
13496 Entry points like dwarf2_per_cu_addr_size do a similar thing
13497 so we're not in uncharted territory here.
13498 Alas we need to be a bit more complicated as addr_base is contained
13501 We don't need to read the entire CU(/TU).
13502 We just need the header and top level die.
13503 IWBN to use the aging mechanism to let us lazily later discard the CU.
13504 See however init_cutu_and_read_dies_simple. */
13508 addr_base
= cu
->addr_base
;
13509 addr_size
= cu
->header
.addr_size
;
13513 struct dwarf2_read_addr_index_data aidata
;
13515 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
13517 addr_base
= aidata
.addr_base
;
13518 addr_size
= aidata
.addr_size
;
13521 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
13524 /* Given a DW_AT_str_index, fetch the string. */
13527 read_str_index (const struct die_reader_specs
*reader
,
13528 struct dwarf2_cu
*cu
, ULONGEST str_index
)
13530 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13531 const char *dwo_name
= objfile
->name
;
13532 bfd
*abfd
= objfile
->obfd
;
13533 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
13534 gdb_byte
*info_ptr
;
13535 ULONGEST str_offset
;
13537 dwarf2_read_section (objfile
, §ions
->str
);
13538 dwarf2_read_section (objfile
, §ions
->str_offsets
);
13539 if (sections
->str
.buffer
== NULL
)
13540 error (_("DW_FORM_str_index used without .debug_str.dwo section"
13541 " in CU at offset 0x%lx [in module %s]"),
13542 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13543 if (sections
->str_offsets
.buffer
== NULL
)
13544 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
13545 " in CU at offset 0x%lx [in module %s]"),
13546 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13547 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
13548 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
13549 " section in CU at offset 0x%lx [in module %s]"),
13550 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13551 info_ptr
= (sections
->str_offsets
.buffer
13552 + str_index
* cu
->header
.offset_size
);
13553 if (cu
->header
.offset_size
== 4)
13554 str_offset
= bfd_get_32 (abfd
, info_ptr
);
13556 str_offset
= bfd_get_64 (abfd
, info_ptr
);
13557 if (str_offset
>= sections
->str
.size
)
13558 error (_("Offset from DW_FORM_str_index pointing outside of"
13559 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
13560 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13561 return (char *) (sections
->str
.buffer
+ str_offset
);
13564 /* Return the length of an LEB128 number in BUF. */
13567 leb128_size (const gdb_byte
*buf
)
13569 const gdb_byte
*begin
= buf
;
13575 if ((byte
& 128) == 0)
13576 return buf
- begin
;
13581 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
13588 cu
->language
= language_c
;
13590 case DW_LANG_C_plus_plus
:
13591 cu
->language
= language_cplus
;
13594 cu
->language
= language_d
;
13596 case DW_LANG_Fortran77
:
13597 case DW_LANG_Fortran90
:
13598 case DW_LANG_Fortran95
:
13599 cu
->language
= language_fortran
;
13602 cu
->language
= language_go
;
13604 case DW_LANG_Mips_Assembler
:
13605 cu
->language
= language_asm
;
13608 cu
->language
= language_java
;
13610 case DW_LANG_Ada83
:
13611 case DW_LANG_Ada95
:
13612 cu
->language
= language_ada
;
13614 case DW_LANG_Modula2
:
13615 cu
->language
= language_m2
;
13617 case DW_LANG_Pascal83
:
13618 cu
->language
= language_pascal
;
13621 cu
->language
= language_objc
;
13623 case DW_LANG_Cobol74
:
13624 case DW_LANG_Cobol85
:
13626 cu
->language
= language_minimal
;
13629 cu
->language_defn
= language_def (cu
->language
);
13632 /* Return the named attribute or NULL if not there. */
13634 static struct attribute
*
13635 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
13640 struct attribute
*spec
= NULL
;
13642 for (i
= 0; i
< die
->num_attrs
; ++i
)
13644 if (die
->attrs
[i
].name
== name
)
13645 return &die
->attrs
[i
];
13646 if (die
->attrs
[i
].name
== DW_AT_specification
13647 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
13648 spec
= &die
->attrs
[i
];
13654 die
= follow_die_ref (die
, spec
, &cu
);
13660 /* Return the named attribute or NULL if not there,
13661 but do not follow DW_AT_specification, etc.
13662 This is for use in contexts where we're reading .debug_types dies.
13663 Following DW_AT_specification, DW_AT_abstract_origin will take us
13664 back up the chain, and we want to go down. */
13666 static struct attribute
*
13667 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
13671 for (i
= 0; i
< die
->num_attrs
; ++i
)
13672 if (die
->attrs
[i
].name
== name
)
13673 return &die
->attrs
[i
];
13678 /* Return non-zero iff the attribute NAME is defined for the given DIE,
13679 and holds a non-zero value. This function should only be used for
13680 DW_FORM_flag or DW_FORM_flag_present attributes. */
13683 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
13685 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
13687 return (attr
&& DW_UNSND (attr
));
13691 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
13693 /* A DIE is a declaration if it has a DW_AT_declaration attribute
13694 which value is non-zero. However, we have to be careful with
13695 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
13696 (via dwarf2_flag_true_p) follows this attribute. So we may
13697 end up accidently finding a declaration attribute that belongs
13698 to a different DIE referenced by the specification attribute,
13699 even though the given DIE does not have a declaration attribute. */
13700 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
13701 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
13704 /* Return the die giving the specification for DIE, if there is
13705 one. *SPEC_CU is the CU containing DIE on input, and the CU
13706 containing the return value on output. If there is no
13707 specification, but there is an abstract origin, that is
13710 static struct die_info
*
13711 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
13713 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
13716 if (spec_attr
== NULL
)
13717 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
13719 if (spec_attr
== NULL
)
13722 return follow_die_ref (die
, spec_attr
, spec_cu
);
13725 /* Free the line_header structure *LH, and any arrays and strings it
13727 NOTE: This is also used as a "cleanup" function. */
13730 free_line_header (struct line_header
*lh
)
13732 if (lh
->standard_opcode_lengths
)
13733 xfree (lh
->standard_opcode_lengths
);
13735 /* Remember that all the lh->file_names[i].name pointers are
13736 pointers into debug_line_buffer, and don't need to be freed. */
13737 if (lh
->file_names
)
13738 xfree (lh
->file_names
);
13740 /* Similarly for the include directory names. */
13741 if (lh
->include_dirs
)
13742 xfree (lh
->include_dirs
);
13747 /* Add an entry to LH's include directory table. */
13750 add_include_dir (struct line_header
*lh
, char *include_dir
)
13752 /* Grow the array if necessary. */
13753 if (lh
->include_dirs_size
== 0)
13755 lh
->include_dirs_size
= 1; /* for testing */
13756 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
13757 * sizeof (*lh
->include_dirs
));
13759 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
13761 lh
->include_dirs_size
*= 2;
13762 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
13763 (lh
->include_dirs_size
13764 * sizeof (*lh
->include_dirs
)));
13767 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
13770 /* Add an entry to LH's file name table. */
13773 add_file_name (struct line_header
*lh
,
13775 unsigned int dir_index
,
13776 unsigned int mod_time
,
13777 unsigned int length
)
13779 struct file_entry
*fe
;
13781 /* Grow the array if necessary. */
13782 if (lh
->file_names_size
== 0)
13784 lh
->file_names_size
= 1; /* for testing */
13785 lh
->file_names
= xmalloc (lh
->file_names_size
13786 * sizeof (*lh
->file_names
));
13788 else if (lh
->num_file_names
>= lh
->file_names_size
)
13790 lh
->file_names_size
*= 2;
13791 lh
->file_names
= xrealloc (lh
->file_names
,
13792 (lh
->file_names_size
13793 * sizeof (*lh
->file_names
)));
13796 fe
= &lh
->file_names
[lh
->num_file_names
++];
13798 fe
->dir_index
= dir_index
;
13799 fe
->mod_time
= mod_time
;
13800 fe
->length
= length
;
13801 fe
->included_p
= 0;
13805 /* Read the statement program header starting at OFFSET in
13806 .debug_line, or .debug_line.dwo. Return a pointer
13807 to a struct line_header, allocated using xmalloc.
13809 NOTE: the strings in the include directory and file name tables of
13810 the returned object point into the dwarf line section buffer,
13811 and must not be freed. */
13813 static struct line_header
*
13814 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
13816 struct cleanup
*back_to
;
13817 struct line_header
*lh
;
13818 gdb_byte
*line_ptr
;
13819 unsigned int bytes_read
, offset_size
;
13821 char *cur_dir
, *cur_file
;
13822 struct dwarf2_section_info
*section
;
13825 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
13827 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13828 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
13830 section
= &dwarf2_per_objfile
->line
;
13832 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
13833 if (section
->buffer
== NULL
)
13835 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13836 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
13838 complaint (&symfile_complaints
, _("missing .debug_line section"));
13842 /* We can't do this until we know the section is non-empty.
13843 Only then do we know we have such a section. */
13844 abfd
= section
->asection
->owner
;
13846 /* Make sure that at least there's room for the total_length field.
13847 That could be 12 bytes long, but we're just going to fudge that. */
13848 if (offset
+ 4 >= section
->size
)
13850 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13854 lh
= xmalloc (sizeof (*lh
));
13855 memset (lh
, 0, sizeof (*lh
));
13856 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
13859 line_ptr
= section
->buffer
+ offset
;
13861 /* Read in the header. */
13863 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
13864 &bytes_read
, &offset_size
);
13865 line_ptr
+= bytes_read
;
13866 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
13868 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13871 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
13872 lh
->version
= read_2_bytes (abfd
, line_ptr
);
13874 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
13875 line_ptr
+= offset_size
;
13876 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
13878 if (lh
->version
>= 4)
13880 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
13884 lh
->maximum_ops_per_instruction
= 1;
13886 if (lh
->maximum_ops_per_instruction
== 0)
13888 lh
->maximum_ops_per_instruction
= 1;
13889 complaint (&symfile_complaints
,
13890 _("invalid maximum_ops_per_instruction "
13891 "in `.debug_line' section"));
13894 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
13896 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
13898 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
13900 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
13902 lh
->standard_opcode_lengths
13903 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
13905 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
13906 for (i
= 1; i
< lh
->opcode_base
; ++i
)
13908 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
13912 /* Read directory table. */
13913 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13915 line_ptr
+= bytes_read
;
13916 add_include_dir (lh
, cur_dir
);
13918 line_ptr
+= bytes_read
;
13920 /* Read file name table. */
13921 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13923 unsigned int dir_index
, mod_time
, length
;
13925 line_ptr
+= bytes_read
;
13926 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13927 line_ptr
+= bytes_read
;
13928 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13929 line_ptr
+= bytes_read
;
13930 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13931 line_ptr
+= bytes_read
;
13933 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13935 line_ptr
+= bytes_read
;
13936 lh
->statement_program_start
= line_ptr
;
13938 if (line_ptr
> (section
->buffer
+ section
->size
))
13939 complaint (&symfile_complaints
,
13940 _("line number info header doesn't "
13941 "fit in `.debug_line' section"));
13943 discard_cleanups (back_to
);
13947 /* Subroutine of dwarf_decode_lines to simplify it.
13948 Return the file name of the psymtab for included file FILE_INDEX
13949 in line header LH of PST.
13950 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13951 If space for the result is malloc'd, it will be freed by a cleanup.
13952 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
13955 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
13956 const struct partial_symtab
*pst
,
13957 const char *comp_dir
)
13959 const struct file_entry fe
= lh
->file_names
[file_index
];
13960 char *include_name
= fe
.name
;
13961 char *include_name_to_compare
= include_name
;
13962 char *dir_name
= NULL
;
13963 const char *pst_filename
;
13964 char *copied_name
= NULL
;
13968 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
13970 if (!IS_ABSOLUTE_PATH (include_name
)
13971 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
13973 /* Avoid creating a duplicate psymtab for PST.
13974 We do this by comparing INCLUDE_NAME and PST_FILENAME.
13975 Before we do the comparison, however, we need to account
13976 for DIR_NAME and COMP_DIR.
13977 First prepend dir_name (if non-NULL). If we still don't
13978 have an absolute path prepend comp_dir (if non-NULL).
13979 However, the directory we record in the include-file's
13980 psymtab does not contain COMP_DIR (to match the
13981 corresponding symtab(s)).
13986 bash$ gcc -g ./hello.c
13987 include_name = "hello.c"
13989 DW_AT_comp_dir = comp_dir = "/tmp"
13990 DW_AT_name = "./hello.c" */
13992 if (dir_name
!= NULL
)
13994 include_name
= concat (dir_name
, SLASH_STRING
,
13995 include_name
, (char *)NULL
);
13996 include_name_to_compare
= include_name
;
13997 make_cleanup (xfree
, include_name
);
13999 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
14001 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
14002 include_name
, (char *)NULL
);
14006 pst_filename
= pst
->filename
;
14007 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
14009 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
14010 pst_filename
, (char *)NULL
);
14011 pst_filename
= copied_name
;
14014 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
14016 if (include_name_to_compare
!= include_name
)
14017 xfree (include_name_to_compare
);
14018 if (copied_name
!= NULL
)
14019 xfree (copied_name
);
14023 return include_name
;
14026 /* Ignore this record_line request. */
14029 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14034 /* Subroutine of dwarf_decode_lines to simplify it.
14035 Process the line number information in LH. */
14038 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
14039 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
14041 gdb_byte
*line_ptr
, *extended_end
;
14042 gdb_byte
*line_end
;
14043 unsigned int bytes_read
, extended_len
;
14044 unsigned char op_code
, extended_op
, adj_opcode
;
14045 CORE_ADDR baseaddr
;
14046 struct objfile
*objfile
= cu
->objfile
;
14047 bfd
*abfd
= objfile
->obfd
;
14048 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14049 const int decode_for_pst_p
= (pst
!= NULL
);
14050 struct subfile
*last_subfile
= NULL
;
14051 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14054 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14056 line_ptr
= lh
->statement_program_start
;
14057 line_end
= lh
->statement_program_end
;
14059 /* Read the statement sequences until there's nothing left. */
14060 while (line_ptr
< line_end
)
14062 /* state machine registers */
14063 CORE_ADDR address
= 0;
14064 unsigned int file
= 1;
14065 unsigned int line
= 1;
14066 unsigned int column
= 0;
14067 int is_stmt
= lh
->default_is_stmt
;
14068 int basic_block
= 0;
14069 int end_sequence
= 0;
14071 unsigned char op_index
= 0;
14073 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
14075 /* Start a subfile for the current file of the state machine. */
14076 /* lh->include_dirs and lh->file_names are 0-based, but the
14077 directory and file name numbers in the statement program
14079 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14083 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14085 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14088 /* Decode the table. */
14089 while (!end_sequence
)
14091 op_code
= read_1_byte (abfd
, line_ptr
);
14093 if (line_ptr
> line_end
)
14095 dwarf2_debug_line_missing_end_sequence_complaint ();
14099 if (op_code
>= lh
->opcode_base
)
14101 /* Special operand. */
14102 adj_opcode
= op_code
- lh
->opcode_base
;
14103 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
14104 / lh
->maximum_ops_per_instruction
)
14105 * lh
->minimum_instruction_length
);
14106 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
14107 % lh
->maximum_ops_per_instruction
);
14108 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
14109 if (lh
->num_file_names
< file
|| file
== 0)
14110 dwarf2_debug_line_missing_file_complaint ();
14111 /* For now we ignore lines not starting on an
14112 instruction boundary. */
14113 else if (op_index
== 0)
14115 lh
->file_names
[file
- 1].included_p
= 1;
14116 if (!decode_for_pst_p
&& is_stmt
)
14118 if (last_subfile
!= current_subfile
)
14120 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14122 (*p_record_line
) (last_subfile
, 0, addr
);
14123 last_subfile
= current_subfile
;
14125 /* Append row to matrix using current values. */
14126 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14127 (*p_record_line
) (current_subfile
, line
, addr
);
14132 else switch (op_code
)
14134 case DW_LNS_extended_op
:
14135 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
14137 line_ptr
+= bytes_read
;
14138 extended_end
= line_ptr
+ extended_len
;
14139 extended_op
= read_1_byte (abfd
, line_ptr
);
14141 switch (extended_op
)
14143 case DW_LNE_end_sequence
:
14144 p_record_line
= record_line
;
14147 case DW_LNE_set_address
:
14148 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
14150 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14152 /* This line table is for a function which has been
14153 GCd by the linker. Ignore it. PR gdb/12528 */
14156 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
14158 complaint (&symfile_complaints
,
14159 _(".debug_line address at offset 0x%lx is 0 "
14161 line_offset
, objfile
->name
);
14162 p_record_line
= noop_record_line
;
14166 line_ptr
+= bytes_read
;
14167 address
+= baseaddr
;
14169 case DW_LNE_define_file
:
14172 unsigned int dir_index
, mod_time
, length
;
14174 cur_file
= read_direct_string (abfd
, line_ptr
,
14176 line_ptr
+= bytes_read
;
14178 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14179 line_ptr
+= bytes_read
;
14181 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14182 line_ptr
+= bytes_read
;
14184 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14185 line_ptr
+= bytes_read
;
14186 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14189 case DW_LNE_set_discriminator
:
14190 /* The discriminator is not interesting to the debugger;
14192 line_ptr
= extended_end
;
14195 complaint (&symfile_complaints
,
14196 _("mangled .debug_line section"));
14199 /* Make sure that we parsed the extended op correctly. If e.g.
14200 we expected a different address size than the producer used,
14201 we may have read the wrong number of bytes. */
14202 if (line_ptr
!= extended_end
)
14204 complaint (&symfile_complaints
,
14205 _("mangled .debug_line section"));
14210 if (lh
->num_file_names
< file
|| file
== 0)
14211 dwarf2_debug_line_missing_file_complaint ();
14214 lh
->file_names
[file
- 1].included_p
= 1;
14215 if (!decode_for_pst_p
&& is_stmt
)
14217 if (last_subfile
!= current_subfile
)
14219 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14221 (*p_record_line
) (last_subfile
, 0, addr
);
14222 last_subfile
= current_subfile
;
14224 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14225 (*p_record_line
) (current_subfile
, line
, addr
);
14230 case DW_LNS_advance_pc
:
14233 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14235 address
+= (((op_index
+ adjust
)
14236 / lh
->maximum_ops_per_instruction
)
14237 * lh
->minimum_instruction_length
);
14238 op_index
= ((op_index
+ adjust
)
14239 % lh
->maximum_ops_per_instruction
);
14240 line_ptr
+= bytes_read
;
14243 case DW_LNS_advance_line
:
14244 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
14245 line_ptr
+= bytes_read
;
14247 case DW_LNS_set_file
:
14249 /* The arrays lh->include_dirs and lh->file_names are
14250 0-based, but the directory and file name numbers in
14251 the statement program are 1-based. */
14252 struct file_entry
*fe
;
14255 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14256 line_ptr
+= bytes_read
;
14257 if (lh
->num_file_names
< file
|| file
== 0)
14258 dwarf2_debug_line_missing_file_complaint ();
14261 fe
= &lh
->file_names
[file
- 1];
14263 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14264 if (!decode_for_pst_p
)
14266 last_subfile
= current_subfile
;
14267 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14272 case DW_LNS_set_column
:
14273 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14274 line_ptr
+= bytes_read
;
14276 case DW_LNS_negate_stmt
:
14277 is_stmt
= (!is_stmt
);
14279 case DW_LNS_set_basic_block
:
14282 /* Add to the address register of the state machine the
14283 address increment value corresponding to special opcode
14284 255. I.e., this value is scaled by the minimum
14285 instruction length since special opcode 255 would have
14286 scaled the increment. */
14287 case DW_LNS_const_add_pc
:
14289 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
14291 address
+= (((op_index
+ adjust
)
14292 / lh
->maximum_ops_per_instruction
)
14293 * lh
->minimum_instruction_length
);
14294 op_index
= ((op_index
+ adjust
)
14295 % lh
->maximum_ops_per_instruction
);
14298 case DW_LNS_fixed_advance_pc
:
14299 address
+= read_2_bytes (abfd
, line_ptr
);
14305 /* Unknown standard opcode, ignore it. */
14308 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
14310 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14311 line_ptr
+= bytes_read
;
14316 if (lh
->num_file_names
< file
|| file
== 0)
14317 dwarf2_debug_line_missing_file_complaint ();
14320 lh
->file_names
[file
- 1].included_p
= 1;
14321 if (!decode_for_pst_p
)
14323 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14324 (*p_record_line
) (current_subfile
, 0, addr
);
14330 /* Decode the Line Number Program (LNP) for the given line_header
14331 structure and CU. The actual information extracted and the type
14332 of structures created from the LNP depends on the value of PST.
14334 1. If PST is NULL, then this procedure uses the data from the program
14335 to create all necessary symbol tables, and their linetables.
14337 2. If PST is not NULL, this procedure reads the program to determine
14338 the list of files included by the unit represented by PST, and
14339 builds all the associated partial symbol tables.
14341 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
14342 It is used for relative paths in the line table.
14343 NOTE: When processing partial symtabs (pst != NULL),
14344 comp_dir == pst->dirname.
14346 NOTE: It is important that psymtabs have the same file name (via strcmp)
14347 as the corresponding symtab. Since COMP_DIR is not used in the name of the
14348 symtab we don't use it in the name of the psymtabs we create.
14349 E.g. expand_line_sal requires this when finding psymtabs to expand.
14350 A good testcase for this is mb-inline.exp. */
14353 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
14354 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
14355 int want_line_info
)
14357 struct objfile
*objfile
= cu
->objfile
;
14358 const int decode_for_pst_p
= (pst
!= NULL
);
14359 struct subfile
*first_subfile
= current_subfile
;
14361 if (want_line_info
)
14362 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
14364 if (decode_for_pst_p
)
14368 /* Now that we're done scanning the Line Header Program, we can
14369 create the psymtab of each included file. */
14370 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
14371 if (lh
->file_names
[file_index
].included_p
== 1)
14373 char *include_name
=
14374 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
14375 if (include_name
!= NULL
)
14376 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
14381 /* Make sure a symtab is created for every file, even files
14382 which contain only variables (i.e. no code with associated
14386 for (i
= 0; i
< lh
->num_file_names
; i
++)
14389 struct file_entry
*fe
;
14391 fe
= &lh
->file_names
[i
];
14393 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14394 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14396 /* Skip the main file; we don't need it, and it must be
14397 allocated last, so that it will show up before the
14398 non-primary symtabs in the objfile's symtab list. */
14399 if (current_subfile
== first_subfile
)
14402 if (current_subfile
->symtab
== NULL
)
14403 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
14405 fe
->symtab
= current_subfile
->symtab
;
14410 /* Start a subfile for DWARF. FILENAME is the name of the file and
14411 DIRNAME the name of the source directory which contains FILENAME
14412 or NULL if not known. COMP_DIR is the compilation directory for the
14413 linetable's compilation unit or NULL if not known.
14414 This routine tries to keep line numbers from identical absolute and
14415 relative file names in a common subfile.
14417 Using the `list' example from the GDB testsuite, which resides in
14418 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
14419 of /srcdir/list0.c yields the following debugging information for list0.c:
14421 DW_AT_name: /srcdir/list0.c
14422 DW_AT_comp_dir: /compdir
14423 files.files[0].name: list0.h
14424 files.files[0].dir: /srcdir
14425 files.files[1].name: list0.c
14426 files.files[1].dir: /srcdir
14428 The line number information for list0.c has to end up in a single
14429 subfile, so that `break /srcdir/list0.c:1' works as expected.
14430 start_subfile will ensure that this happens provided that we pass the
14431 concatenation of files.files[1].dir and files.files[1].name as the
14435 dwarf2_start_subfile (char *filename
, const char *dirname
,
14436 const char *comp_dir
)
14440 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
14441 `start_symtab' will always pass the contents of DW_AT_comp_dir as
14442 second argument to start_subfile. To be consistent, we do the
14443 same here. In order not to lose the line information directory,
14444 we concatenate it to the filename when it makes sense.
14445 Note that the Dwarf3 standard says (speaking of filenames in line
14446 information): ``The directory index is ignored for file names
14447 that represent full path names''. Thus ignoring dirname in the
14448 `else' branch below isn't an issue. */
14450 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
14451 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
14453 fullname
= filename
;
14455 start_subfile (fullname
, comp_dir
);
14457 if (fullname
!= filename
)
14461 /* Start a symtab for DWARF.
14462 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
14465 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
14466 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
14468 start_symtab (name
, comp_dir
, low_pc
);
14469 record_debugformat ("DWARF 2");
14470 record_producer (cu
->producer
);
14472 /* We assume that we're processing GCC output. */
14473 processing_gcc_compilation
= 2;
14475 processing_has_namespace_info
= 0;
14479 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
14480 struct dwarf2_cu
*cu
)
14482 struct objfile
*objfile
= cu
->objfile
;
14483 struct comp_unit_head
*cu_header
= &cu
->header
;
14485 /* NOTE drow/2003-01-30: There used to be a comment and some special
14486 code here to turn a symbol with DW_AT_external and a
14487 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
14488 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
14489 with some versions of binutils) where shared libraries could have
14490 relocations against symbols in their debug information - the
14491 minimal symbol would have the right address, but the debug info
14492 would not. It's no longer necessary, because we will explicitly
14493 apply relocations when we read in the debug information now. */
14495 /* A DW_AT_location attribute with no contents indicates that a
14496 variable has been optimized away. */
14497 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
14499 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14503 /* Handle one degenerate form of location expression specially, to
14504 preserve GDB's previous behavior when section offsets are
14505 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
14506 then mark this symbol as LOC_STATIC. */
14508 if (attr_form_is_block (attr
)
14509 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
14510 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
14511 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
14512 && (DW_BLOCK (attr
)->size
14513 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
14515 unsigned int dummy
;
14517 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
14518 SYMBOL_VALUE_ADDRESS (sym
) =
14519 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
14521 SYMBOL_VALUE_ADDRESS (sym
) =
14522 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
14523 SYMBOL_CLASS (sym
) = LOC_STATIC
;
14524 fixup_symbol_section (sym
, objfile
);
14525 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
14526 SYMBOL_SECTION (sym
));
14530 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
14531 expression evaluator, and use LOC_COMPUTED only when necessary
14532 (i.e. when the value of a register or memory location is
14533 referenced, or a thread-local block, etc.). Then again, it might
14534 not be worthwhile. I'm assuming that it isn't unless performance
14535 or memory numbers show me otherwise. */
14537 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
14538 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14540 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
14541 cu
->has_loclist
= 1;
14544 /* Given a pointer to a DWARF information entry, figure out if we need
14545 to make a symbol table entry for it, and if so, create a new entry
14546 and return a pointer to it.
14547 If TYPE is NULL, determine symbol type from the die, otherwise
14548 used the passed type.
14549 If SPACE is not NULL, use it to hold the new symbol. If it is
14550 NULL, allocate a new symbol on the objfile's obstack. */
14552 static struct symbol
*
14553 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
14554 struct symbol
*space
)
14556 struct objfile
*objfile
= cu
->objfile
;
14557 struct symbol
*sym
= NULL
;
14559 struct attribute
*attr
= NULL
;
14560 struct attribute
*attr2
= NULL
;
14561 CORE_ADDR baseaddr
;
14562 struct pending
**list_to_add
= NULL
;
14564 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14566 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14568 name
= dwarf2_name (die
, cu
);
14571 const char *linkagename
;
14572 int suppress_add
= 0;
14577 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
14578 OBJSTAT (objfile
, n_syms
++);
14580 /* Cache this symbol's name and the name's demangled form (if any). */
14581 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
14582 linkagename
= dwarf2_physname (name
, die
, cu
);
14583 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
14585 /* Fortran does not have mangling standard and the mangling does differ
14586 between gfortran, iFort etc. */
14587 if (cu
->language
== language_fortran
14588 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
14589 symbol_set_demangled_name (&(sym
->ginfo
),
14590 (char *) dwarf2_full_name (name
, die
, cu
),
14593 /* Default assumptions.
14594 Use the passed type or decode it from the die. */
14595 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14596 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14598 SYMBOL_TYPE (sym
) = type
;
14600 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
14601 attr
= dwarf2_attr (die
,
14602 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
14606 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
14609 attr
= dwarf2_attr (die
,
14610 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
14614 int file_index
= DW_UNSND (attr
);
14616 if (cu
->line_header
== NULL
14617 || file_index
> cu
->line_header
->num_file_names
)
14618 complaint (&symfile_complaints
,
14619 _("file index out of range"));
14620 else if (file_index
> 0)
14622 struct file_entry
*fe
;
14624 fe
= &cu
->line_header
->file_names
[file_index
- 1];
14625 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
14632 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14635 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
14637 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
14638 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
14639 SYMBOL_CLASS (sym
) = LOC_LABEL
;
14640 add_symbol_to_list (sym
, cu
->list_in_scope
);
14642 case DW_TAG_subprogram
:
14643 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14645 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14646 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14647 if ((attr2
&& (DW_UNSND (attr2
) != 0))
14648 || cu
->language
== language_ada
)
14650 /* Subprograms marked external are stored as a global symbol.
14651 Ada subprograms, whether marked external or not, are always
14652 stored as a global symbol, because we want to be able to
14653 access them globally. For instance, we want to be able
14654 to break on a nested subprogram without having to
14655 specify the context. */
14656 list_to_add
= &global_symbols
;
14660 list_to_add
= cu
->list_in_scope
;
14663 case DW_TAG_inlined_subroutine
:
14664 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14666 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14667 SYMBOL_INLINED (sym
) = 1;
14668 list_to_add
= cu
->list_in_scope
;
14670 case DW_TAG_template_value_param
:
14672 /* Fall through. */
14673 case DW_TAG_constant
:
14674 case DW_TAG_variable
:
14675 case DW_TAG_member
:
14676 /* Compilation with minimal debug info may result in
14677 variables with missing type entries. Change the
14678 misleading `void' type to something sensible. */
14679 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
14681 = objfile_type (objfile
)->nodebug_data_symbol
;
14683 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14684 /* In the case of DW_TAG_member, we should only be called for
14685 static const members. */
14686 if (die
->tag
== DW_TAG_member
)
14688 /* dwarf2_add_field uses die_is_declaration,
14689 so we do the same. */
14690 gdb_assert (die_is_declaration (die
, cu
));
14695 dwarf2_const_value (attr
, sym
, cu
);
14696 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14699 if (attr2
&& (DW_UNSND (attr2
) != 0))
14700 list_to_add
= &global_symbols
;
14702 list_to_add
= cu
->list_in_scope
;
14706 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14709 var_decode_location (attr
, sym
, cu
);
14710 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14711 if (SYMBOL_CLASS (sym
) == LOC_STATIC
14712 && SYMBOL_VALUE_ADDRESS (sym
) == 0
14713 && !dwarf2_per_objfile
->has_section_at_zero
)
14715 /* When a static variable is eliminated by the linker,
14716 the corresponding debug information is not stripped
14717 out, but the variable address is set to null;
14718 do not add such variables into symbol table. */
14720 else if (attr2
&& (DW_UNSND (attr2
) != 0))
14722 /* Workaround gfortran PR debug/40040 - it uses
14723 DW_AT_location for variables in -fPIC libraries which may
14724 get overriden by other libraries/executable and get
14725 a different address. Resolve it by the minimal symbol
14726 which may come from inferior's executable using copy
14727 relocation. Make this workaround only for gfortran as for
14728 other compilers GDB cannot guess the minimal symbol
14729 Fortran mangling kind. */
14730 if (cu
->language
== language_fortran
&& die
->parent
14731 && die
->parent
->tag
== DW_TAG_module
14733 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
14734 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14736 /* A variable with DW_AT_external is never static,
14737 but it may be block-scoped. */
14738 list_to_add
= (cu
->list_in_scope
== &file_symbols
14739 ? &global_symbols
: cu
->list_in_scope
);
14742 list_to_add
= cu
->list_in_scope
;
14746 /* We do not know the address of this symbol.
14747 If it is an external symbol and we have type information
14748 for it, enter the symbol as a LOC_UNRESOLVED symbol.
14749 The address of the variable will then be determined from
14750 the minimal symbol table whenever the variable is
14752 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14753 if (attr2
&& (DW_UNSND (attr2
) != 0)
14754 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
14756 /* A variable with DW_AT_external is never static, but it
14757 may be block-scoped. */
14758 list_to_add
= (cu
->list_in_scope
== &file_symbols
14759 ? &global_symbols
: cu
->list_in_scope
);
14761 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14763 else if (!die_is_declaration (die
, cu
))
14765 /* Use the default LOC_OPTIMIZED_OUT class. */
14766 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
14768 list_to_add
= cu
->list_in_scope
;
14772 case DW_TAG_formal_parameter
:
14773 /* If we are inside a function, mark this as an argument. If
14774 not, we might be looking at an argument to an inlined function
14775 when we do not have enough information to show inlined frames;
14776 pretend it's a local variable in that case so that the user can
14778 if (context_stack_depth
> 0
14779 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
14780 SYMBOL_IS_ARGUMENT (sym
) = 1;
14781 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14784 var_decode_location (attr
, sym
, cu
);
14786 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14789 dwarf2_const_value (attr
, sym
, cu
);
14792 list_to_add
= cu
->list_in_scope
;
14794 case DW_TAG_unspecified_parameters
:
14795 /* From varargs functions; gdb doesn't seem to have any
14796 interest in this information, so just ignore it for now.
14799 case DW_TAG_template_type_param
:
14801 /* Fall through. */
14802 case DW_TAG_class_type
:
14803 case DW_TAG_interface_type
:
14804 case DW_TAG_structure_type
:
14805 case DW_TAG_union_type
:
14806 case DW_TAG_set_type
:
14807 case DW_TAG_enumeration_type
:
14808 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14809 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
14812 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
14813 really ever be static objects: otherwise, if you try
14814 to, say, break of a class's method and you're in a file
14815 which doesn't mention that class, it won't work unless
14816 the check for all static symbols in lookup_symbol_aux
14817 saves you. See the OtherFileClass tests in
14818 gdb.c++/namespace.exp. */
14822 list_to_add
= (cu
->list_in_scope
== &file_symbols
14823 && (cu
->language
== language_cplus
14824 || cu
->language
== language_java
)
14825 ? &global_symbols
: cu
->list_in_scope
);
14827 /* The semantics of C++ state that "struct foo {
14828 ... }" also defines a typedef for "foo". A Java
14829 class declaration also defines a typedef for the
14831 if (cu
->language
== language_cplus
14832 || cu
->language
== language_java
14833 || cu
->language
== language_ada
)
14835 /* The symbol's name is already allocated along
14836 with this objfile, so we don't need to
14837 duplicate it for the type. */
14838 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
14839 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
14844 case DW_TAG_typedef
:
14845 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14846 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14847 list_to_add
= cu
->list_in_scope
;
14849 case DW_TAG_base_type
:
14850 case DW_TAG_subrange_type
:
14851 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14852 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14853 list_to_add
= cu
->list_in_scope
;
14855 case DW_TAG_enumerator
:
14856 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14859 dwarf2_const_value (attr
, sym
, cu
);
14862 /* NOTE: carlton/2003-11-10: See comment above in the
14863 DW_TAG_class_type, etc. block. */
14865 list_to_add
= (cu
->list_in_scope
== &file_symbols
14866 && (cu
->language
== language_cplus
14867 || cu
->language
== language_java
)
14868 ? &global_symbols
: cu
->list_in_scope
);
14871 case DW_TAG_namespace
:
14872 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14873 list_to_add
= &global_symbols
;
14876 /* Not a tag we recognize. Hopefully we aren't processing
14877 trash data, but since we must specifically ignore things
14878 we don't recognize, there is nothing else we should do at
14880 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
14881 dwarf_tag_name (die
->tag
));
14887 sym
->hash_next
= objfile
->template_symbols
;
14888 objfile
->template_symbols
= sym
;
14889 list_to_add
= NULL
;
14892 if (list_to_add
!= NULL
)
14893 add_symbol_to_list (sym
, list_to_add
);
14895 /* For the benefit of old versions of GCC, check for anonymous
14896 namespaces based on the demangled name. */
14897 if (!processing_has_namespace_info
14898 && cu
->language
== language_cplus
)
14899 cp_scan_for_anonymous_namespaces (sym
, objfile
);
14904 /* A wrapper for new_symbol_full that always allocates a new symbol. */
14906 static struct symbol
*
14907 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14909 return new_symbol_full (die
, type
, cu
, NULL
);
14912 /* Given an attr with a DW_FORM_dataN value in host byte order,
14913 zero-extend it as appropriate for the symbol's type. The DWARF
14914 standard (v4) is not entirely clear about the meaning of using
14915 DW_FORM_dataN for a constant with a signed type, where the type is
14916 wider than the data. The conclusion of a discussion on the DWARF
14917 list was that this is unspecified. We choose to always zero-extend
14918 because that is the interpretation long in use by GCC. */
14921 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
14922 const char *name
, struct obstack
*obstack
,
14923 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
14925 struct objfile
*objfile
= cu
->objfile
;
14926 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
14927 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
14928 LONGEST l
= DW_UNSND (attr
);
14930 if (bits
< sizeof (*value
) * 8)
14932 l
&= ((LONGEST
) 1 << bits
) - 1;
14935 else if (bits
== sizeof (*value
) * 8)
14939 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
14940 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
14947 /* Read a constant value from an attribute. Either set *VALUE, or if
14948 the value does not fit in *VALUE, set *BYTES - either already
14949 allocated on the objfile obstack, or newly allocated on OBSTACK,
14950 or, set *BATON, if we translated the constant to a location
14954 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
14955 const char *name
, struct obstack
*obstack
,
14956 struct dwarf2_cu
*cu
,
14957 LONGEST
*value
, gdb_byte
**bytes
,
14958 struct dwarf2_locexpr_baton
**baton
)
14960 struct objfile
*objfile
= cu
->objfile
;
14961 struct comp_unit_head
*cu_header
= &cu
->header
;
14962 struct dwarf_block
*blk
;
14963 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
14964 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
14970 switch (attr
->form
)
14973 case DW_FORM_GNU_addr_index
:
14977 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
14978 dwarf2_const_value_length_mismatch_complaint (name
,
14979 cu_header
->addr_size
,
14980 TYPE_LENGTH (type
));
14981 /* Symbols of this form are reasonably rare, so we just
14982 piggyback on the existing location code rather than writing
14983 a new implementation of symbol_computed_ops. */
14984 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
14985 sizeof (struct dwarf2_locexpr_baton
));
14986 (*baton
)->per_cu
= cu
->per_cu
;
14987 gdb_assert ((*baton
)->per_cu
);
14989 (*baton
)->size
= 2 + cu_header
->addr_size
;
14990 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
14991 (*baton
)->data
= data
;
14993 data
[0] = DW_OP_addr
;
14994 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
14995 byte_order
, DW_ADDR (attr
));
14996 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
14999 case DW_FORM_string
:
15001 case DW_FORM_GNU_str_index
:
15002 /* DW_STRING is already allocated on the objfile obstack, point
15004 *bytes
= (gdb_byte
*) DW_STRING (attr
);
15006 case DW_FORM_block1
:
15007 case DW_FORM_block2
:
15008 case DW_FORM_block4
:
15009 case DW_FORM_block
:
15010 case DW_FORM_exprloc
:
15011 blk
= DW_BLOCK (attr
);
15012 if (TYPE_LENGTH (type
) != blk
->size
)
15013 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
15014 TYPE_LENGTH (type
));
15015 *bytes
= blk
->data
;
15018 /* The DW_AT_const_value attributes are supposed to carry the
15019 symbol's value "represented as it would be on the target
15020 architecture." By the time we get here, it's already been
15021 converted to host endianness, so we just need to sign- or
15022 zero-extend it as appropriate. */
15023 case DW_FORM_data1
:
15024 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15025 obstack
, cu
, value
, 8);
15027 case DW_FORM_data2
:
15028 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15029 obstack
, cu
, value
, 16);
15031 case DW_FORM_data4
:
15032 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15033 obstack
, cu
, value
, 32);
15035 case DW_FORM_data8
:
15036 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15037 obstack
, cu
, value
, 64);
15040 case DW_FORM_sdata
:
15041 *value
= DW_SND (attr
);
15044 case DW_FORM_udata
:
15045 *value
= DW_UNSND (attr
);
15049 complaint (&symfile_complaints
,
15050 _("unsupported const value attribute form: '%s'"),
15051 dwarf_form_name (attr
->form
));
15058 /* Copy constant value from an attribute to a symbol. */
15061 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
15062 struct dwarf2_cu
*cu
)
15064 struct objfile
*objfile
= cu
->objfile
;
15065 struct comp_unit_head
*cu_header
= &cu
->header
;
15068 struct dwarf2_locexpr_baton
*baton
;
15070 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
15071 SYMBOL_PRINT_NAME (sym
),
15072 &objfile
->objfile_obstack
, cu
,
15073 &value
, &bytes
, &baton
);
15077 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15078 SYMBOL_LOCATION_BATON (sym
) = baton
;
15079 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15081 else if (bytes
!= NULL
)
15083 SYMBOL_VALUE_BYTES (sym
) = bytes
;
15084 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
15088 SYMBOL_VALUE (sym
) = value
;
15089 SYMBOL_CLASS (sym
) = LOC_CONST
;
15093 /* Return the type of the die in question using its DW_AT_type attribute. */
15095 static struct type
*
15096 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15098 struct attribute
*type_attr
;
15100 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15103 /* A missing DW_AT_type represents a void type. */
15104 return objfile_type (cu
->objfile
)->builtin_void
;
15107 return lookup_die_type (die
, type_attr
, cu
);
15110 /* True iff CU's producer generates GNAT Ada auxiliary information
15111 that allows to find parallel types through that information instead
15112 of having to do expensive parallel lookups by type name. */
15115 need_gnat_info (struct dwarf2_cu
*cu
)
15117 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
15118 of GNAT produces this auxiliary information, without any indication
15119 that it is produced. Part of enhancing the FSF version of GNAT
15120 to produce that information will be to put in place an indicator
15121 that we can use in order to determine whether the descriptive type
15122 info is available or not. One suggestion that has been made is
15123 to use a new attribute, attached to the CU die. For now, assume
15124 that the descriptive type info is not available. */
15128 /* Return the auxiliary type of the die in question using its
15129 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
15130 attribute is not present. */
15132 static struct type
*
15133 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15135 struct attribute
*type_attr
;
15137 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
15141 return lookup_die_type (die
, type_attr
, cu
);
15144 /* If DIE has a descriptive_type attribute, then set the TYPE's
15145 descriptive type accordingly. */
15148 set_descriptive_type (struct type
*type
, struct die_info
*die
,
15149 struct dwarf2_cu
*cu
)
15151 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
15153 if (descriptive_type
)
15155 ALLOCATE_GNAT_AUX_TYPE (type
);
15156 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
15160 /* Return the containing type of the die in question using its
15161 DW_AT_containing_type attribute. */
15163 static struct type
*
15164 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15166 struct attribute
*type_attr
;
15168 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
15170 error (_("Dwarf Error: Problem turning containing type into gdb type "
15171 "[in module %s]"), cu
->objfile
->name
);
15173 return lookup_die_type (die
, type_attr
, cu
);
15176 /* Look up the type of DIE in CU using its type attribute ATTR.
15177 If there is no type substitute an error marker. */
15179 static struct type
*
15180 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
15181 struct dwarf2_cu
*cu
)
15183 struct objfile
*objfile
= cu
->objfile
;
15184 struct type
*this_type
;
15186 /* First see if we have it cached. */
15188 if (is_ref_attr (attr
))
15190 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15192 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
15194 else if (attr
->form
== DW_FORM_ref_sig8
)
15196 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15198 /* sig_type will be NULL if the signatured type is missing from
15200 if (sig_type
== NULL
)
15201 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15202 "at 0x%x [in module %s]"),
15203 die
->offset
.sect_off
, objfile
->name
);
15205 gdb_assert (sig_type
->per_cu
.is_debug_types
);
15206 /* If we haven't filled in type_offset_in_section yet, then we
15207 haven't read the type in yet. */
15209 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
15212 get_die_type_at_offset (sig_type
->type_offset_in_section
,
15213 &sig_type
->per_cu
);
15218 dump_die_for_error (die
);
15219 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
15220 dwarf_attr_name (attr
->name
), objfile
->name
);
15223 /* If not cached we need to read it in. */
15225 if (this_type
== NULL
)
15227 struct die_info
*type_die
;
15228 struct dwarf2_cu
*type_cu
= cu
;
15230 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
15231 /* If we found the type now, it's probably because the type came
15232 from an inter-CU reference and the type's CU got expanded before
15234 this_type
= get_die_type (type_die
, type_cu
);
15235 if (this_type
== NULL
)
15236 this_type
= read_type_die_1 (type_die
, type_cu
);
15239 /* If we still don't have a type use an error marker. */
15241 if (this_type
== NULL
)
15243 char *message
, *saved
;
15245 /* read_type_die already issued a complaint. */
15246 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
15248 cu
->header
.offset
.sect_off
,
15249 die
->offset
.sect_off
);
15250 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
15251 message
, strlen (message
));
15254 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
15260 /* Return the type in DIE, CU.
15261 Returns NULL for invalid types.
15263 This first does a lookup in the appropriate type_hash table,
15264 and only reads the die in if necessary.
15266 NOTE: This can be called when reading in partial or full symbols. */
15268 static struct type
*
15269 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
15271 struct type
*this_type
;
15273 this_type
= get_die_type (die
, cu
);
15277 return read_type_die_1 (die
, cu
);
15280 /* Read the type in DIE, CU.
15281 Returns NULL for invalid types. */
15283 static struct type
*
15284 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
15286 struct type
*this_type
= NULL
;
15290 case DW_TAG_class_type
:
15291 case DW_TAG_interface_type
:
15292 case DW_TAG_structure_type
:
15293 case DW_TAG_union_type
:
15294 this_type
= read_structure_type (die
, cu
);
15296 case DW_TAG_enumeration_type
:
15297 this_type
= read_enumeration_type (die
, cu
);
15299 case DW_TAG_subprogram
:
15300 case DW_TAG_subroutine_type
:
15301 case DW_TAG_inlined_subroutine
:
15302 this_type
= read_subroutine_type (die
, cu
);
15304 case DW_TAG_array_type
:
15305 this_type
= read_array_type (die
, cu
);
15307 case DW_TAG_set_type
:
15308 this_type
= read_set_type (die
, cu
);
15310 case DW_TAG_pointer_type
:
15311 this_type
= read_tag_pointer_type (die
, cu
);
15313 case DW_TAG_ptr_to_member_type
:
15314 this_type
= read_tag_ptr_to_member_type (die
, cu
);
15316 case DW_TAG_reference_type
:
15317 this_type
= read_tag_reference_type (die
, cu
);
15319 case DW_TAG_const_type
:
15320 this_type
= read_tag_const_type (die
, cu
);
15322 case DW_TAG_volatile_type
:
15323 this_type
= read_tag_volatile_type (die
, cu
);
15325 case DW_TAG_string_type
:
15326 this_type
= read_tag_string_type (die
, cu
);
15328 case DW_TAG_typedef
:
15329 this_type
= read_typedef (die
, cu
);
15331 case DW_TAG_subrange_type
:
15332 this_type
= read_subrange_type (die
, cu
);
15334 case DW_TAG_base_type
:
15335 this_type
= read_base_type (die
, cu
);
15337 case DW_TAG_unspecified_type
:
15338 this_type
= read_unspecified_type (die
, cu
);
15340 case DW_TAG_namespace
:
15341 this_type
= read_namespace_type (die
, cu
);
15343 case DW_TAG_module
:
15344 this_type
= read_module_type (die
, cu
);
15347 complaint (&symfile_complaints
,
15348 _("unexpected tag in read_type_die: '%s'"),
15349 dwarf_tag_name (die
->tag
));
15356 /* See if we can figure out if the class lives in a namespace. We do
15357 this by looking for a member function; its demangled name will
15358 contain namespace info, if there is any.
15359 Return the computed name or NULL.
15360 Space for the result is allocated on the objfile's obstack.
15361 This is the full-die version of guess_partial_die_structure_name.
15362 In this case we know DIE has no useful parent. */
15365 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15367 struct die_info
*spec_die
;
15368 struct dwarf2_cu
*spec_cu
;
15369 struct die_info
*child
;
15372 spec_die
= die_specification (die
, &spec_cu
);
15373 if (spec_die
!= NULL
)
15379 for (child
= die
->child
;
15381 child
= child
->sibling
)
15383 if (child
->tag
== DW_TAG_subprogram
)
15385 struct attribute
*attr
;
15387 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
15389 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
15393 = language_class_name_from_physname (cu
->language_defn
,
15397 if (actual_name
!= NULL
)
15399 char *die_name
= dwarf2_name (die
, cu
);
15401 if (die_name
!= NULL
15402 && strcmp (die_name
, actual_name
) != 0)
15404 /* Strip off the class name from the full name.
15405 We want the prefix. */
15406 int die_name_len
= strlen (die_name
);
15407 int actual_name_len
= strlen (actual_name
);
15409 /* Test for '::' as a sanity check. */
15410 if (actual_name_len
> die_name_len
+ 2
15411 && actual_name
[actual_name_len
15412 - die_name_len
- 1] == ':')
15414 obsavestring (actual_name
,
15415 actual_name_len
- die_name_len
- 2,
15416 &cu
->objfile
->objfile_obstack
);
15419 xfree (actual_name
);
15428 /* GCC might emit a nameless typedef that has a linkage name. Determine the
15429 prefix part in such case. See
15430 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15433 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15435 struct attribute
*attr
;
15438 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
15439 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
15442 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15443 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
15446 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15448 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15449 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15452 /* dwarf2_name had to be already called. */
15453 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
15455 /* Strip the base name, keep any leading namespaces/classes. */
15456 base
= strrchr (DW_STRING (attr
), ':');
15457 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
15460 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
15461 &cu
->objfile
->objfile_obstack
);
15464 /* Return the name of the namespace/class that DIE is defined within,
15465 or "" if we can't tell. The caller should not xfree the result.
15467 For example, if we're within the method foo() in the following
15477 then determine_prefix on foo's die will return "N::C". */
15479 static const char *
15480 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15482 struct die_info
*parent
, *spec_die
;
15483 struct dwarf2_cu
*spec_cu
;
15484 struct type
*parent_type
;
15487 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
15488 && cu
->language
!= language_fortran
)
15491 retval
= anonymous_struct_prefix (die
, cu
);
15495 /* We have to be careful in the presence of DW_AT_specification.
15496 For example, with GCC 3.4, given the code
15500 // Definition of N::foo.
15504 then we'll have a tree of DIEs like this:
15506 1: DW_TAG_compile_unit
15507 2: DW_TAG_namespace // N
15508 3: DW_TAG_subprogram // declaration of N::foo
15509 4: DW_TAG_subprogram // definition of N::foo
15510 DW_AT_specification // refers to die #3
15512 Thus, when processing die #4, we have to pretend that we're in
15513 the context of its DW_AT_specification, namely the contex of die
15516 spec_die
= die_specification (die
, &spec_cu
);
15517 if (spec_die
== NULL
)
15518 parent
= die
->parent
;
15521 parent
= spec_die
->parent
;
15525 if (parent
== NULL
)
15527 else if (parent
->building_fullname
)
15530 const char *parent_name
;
15532 /* It has been seen on RealView 2.2 built binaries,
15533 DW_TAG_template_type_param types actually _defined_ as
15534 children of the parent class:
15537 template class <class Enum> Class{};
15538 Class<enum E> class_e;
15540 1: DW_TAG_class_type (Class)
15541 2: DW_TAG_enumeration_type (E)
15542 3: DW_TAG_enumerator (enum1:0)
15543 3: DW_TAG_enumerator (enum2:1)
15545 2: DW_TAG_template_type_param
15546 DW_AT_type DW_FORM_ref_udata (E)
15548 Besides being broken debug info, it can put GDB into an
15549 infinite loop. Consider:
15551 When we're building the full name for Class<E>, we'll start
15552 at Class, and go look over its template type parameters,
15553 finding E. We'll then try to build the full name of E, and
15554 reach here. We're now trying to build the full name of E,
15555 and look over the parent DIE for containing scope. In the
15556 broken case, if we followed the parent DIE of E, we'd again
15557 find Class, and once again go look at its template type
15558 arguments, etc., etc. Simply don't consider such parent die
15559 as source-level parent of this die (it can't be, the language
15560 doesn't allow it), and break the loop here. */
15561 name
= dwarf2_name (die
, cu
);
15562 parent_name
= dwarf2_name (parent
, cu
);
15563 complaint (&symfile_complaints
,
15564 _("template param type '%s' defined within parent '%s'"),
15565 name
? name
: "<unknown>",
15566 parent_name
? parent_name
: "<unknown>");
15570 switch (parent
->tag
)
15572 case DW_TAG_namespace
:
15573 parent_type
= read_type_die (parent
, cu
);
15574 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
15575 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
15576 Work around this problem here. */
15577 if (cu
->language
== language_cplus
15578 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
15580 /* We give a name to even anonymous namespaces. */
15581 return TYPE_TAG_NAME (parent_type
);
15582 case DW_TAG_class_type
:
15583 case DW_TAG_interface_type
:
15584 case DW_TAG_structure_type
:
15585 case DW_TAG_union_type
:
15586 case DW_TAG_module
:
15587 parent_type
= read_type_die (parent
, cu
);
15588 if (TYPE_TAG_NAME (parent_type
) != NULL
)
15589 return TYPE_TAG_NAME (parent_type
);
15591 /* An anonymous structure is only allowed non-static data
15592 members; no typedefs, no member functions, et cetera.
15593 So it does not need a prefix. */
15595 case DW_TAG_compile_unit
:
15596 case DW_TAG_partial_unit
:
15597 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
15598 if (cu
->language
== language_cplus
15599 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
15600 && die
->child
!= NULL
15601 && (die
->tag
== DW_TAG_class_type
15602 || die
->tag
== DW_TAG_structure_type
15603 || die
->tag
== DW_TAG_union_type
))
15605 char *name
= guess_full_die_structure_name (die
, cu
);
15611 return determine_prefix (parent
, cu
);
15615 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
15616 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
15617 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
15618 an obconcat, otherwise allocate storage for the result. The CU argument is
15619 used to determine the language and hence, the appropriate separator. */
15621 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
15624 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
15625 int physname
, struct dwarf2_cu
*cu
)
15627 const char *lead
= "";
15630 if (suffix
== NULL
|| suffix
[0] == '\0'
15631 || prefix
== NULL
|| prefix
[0] == '\0')
15633 else if (cu
->language
== language_java
)
15635 else if (cu
->language
== language_fortran
&& physname
)
15637 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
15638 DW_AT_MIPS_linkage_name is preferred and used instead. */
15646 if (prefix
== NULL
)
15648 if (suffix
== NULL
)
15654 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
15656 strcpy (retval
, lead
);
15657 strcat (retval
, prefix
);
15658 strcat (retval
, sep
);
15659 strcat (retval
, suffix
);
15664 /* We have an obstack. */
15665 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
15669 /* Return sibling of die, NULL if no sibling. */
15671 static struct die_info
*
15672 sibling_die (struct die_info
*die
)
15674 return die
->sibling
;
15677 /* Get name of a die, return NULL if not found. */
15680 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
15681 struct obstack
*obstack
)
15683 if (name
&& cu
->language
== language_cplus
)
15685 char *canon_name
= cp_canonicalize_string (name
);
15687 if (canon_name
!= NULL
)
15689 if (strcmp (canon_name
, name
) != 0)
15690 name
= obsavestring (canon_name
, strlen (canon_name
),
15692 xfree (canon_name
);
15699 /* Get name of a die, return NULL if not found. */
15702 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15704 struct attribute
*attr
;
15706 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15707 if ((!attr
|| !DW_STRING (attr
))
15708 && die
->tag
!= DW_TAG_class_type
15709 && die
->tag
!= DW_TAG_interface_type
15710 && die
->tag
!= DW_TAG_structure_type
15711 && die
->tag
!= DW_TAG_union_type
)
15716 case DW_TAG_compile_unit
:
15717 case DW_TAG_partial_unit
:
15718 /* Compilation units have a DW_AT_name that is a filename, not
15719 a source language identifier. */
15720 case DW_TAG_enumeration_type
:
15721 case DW_TAG_enumerator
:
15722 /* These tags always have simple identifiers already; no need
15723 to canonicalize them. */
15724 return DW_STRING (attr
);
15726 case DW_TAG_subprogram
:
15727 /* Java constructors will all be named "<init>", so return
15728 the class name when we see this special case. */
15729 if (cu
->language
== language_java
15730 && DW_STRING (attr
) != NULL
15731 && strcmp (DW_STRING (attr
), "<init>") == 0)
15733 struct dwarf2_cu
*spec_cu
= cu
;
15734 struct die_info
*spec_die
;
15736 /* GCJ will output '<init>' for Java constructor names.
15737 For this special case, return the name of the parent class. */
15739 /* GCJ may output suprogram DIEs with AT_specification set.
15740 If so, use the name of the specified DIE. */
15741 spec_die
= die_specification (die
, &spec_cu
);
15742 if (spec_die
!= NULL
)
15743 return dwarf2_name (spec_die
, spec_cu
);
15748 if (die
->tag
== DW_TAG_class_type
)
15749 return dwarf2_name (die
, cu
);
15751 while (die
->tag
!= DW_TAG_compile_unit
15752 && die
->tag
!= DW_TAG_partial_unit
);
15756 case DW_TAG_class_type
:
15757 case DW_TAG_interface_type
:
15758 case DW_TAG_structure_type
:
15759 case DW_TAG_union_type
:
15760 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
15761 structures or unions. These were of the form "._%d" in GCC 4.1,
15762 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
15763 and GCC 4.4. We work around this problem by ignoring these. */
15764 if (attr
&& DW_STRING (attr
)
15765 && (strncmp (DW_STRING (attr
), "._", 2) == 0
15766 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
15769 /* GCC might emit a nameless typedef that has a linkage name. See
15770 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15771 if (!attr
|| DW_STRING (attr
) == NULL
)
15773 char *demangled
= NULL
;
15775 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15777 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15779 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15782 /* Avoid demangling DW_STRING (attr) the second time on a second
15783 call for the same DIE. */
15784 if (!DW_STRING_IS_CANONICAL (attr
))
15785 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
15791 /* FIXME: we already did this for the partial symbol... */
15792 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
15793 &cu
->objfile
->objfile_obstack
);
15794 DW_STRING_IS_CANONICAL (attr
) = 1;
15797 /* Strip any leading namespaces/classes, keep only the base name.
15798 DW_AT_name for named DIEs does not contain the prefixes. */
15799 base
= strrchr (DW_STRING (attr
), ':');
15800 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
15803 return DW_STRING (attr
);
15812 if (!DW_STRING_IS_CANONICAL (attr
))
15815 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
15816 &cu
->objfile
->objfile_obstack
);
15817 DW_STRING_IS_CANONICAL (attr
) = 1;
15819 return DW_STRING (attr
);
15822 /* Return the die that this die in an extension of, or NULL if there
15823 is none. *EXT_CU is the CU containing DIE on input, and the CU
15824 containing the return value on output. */
15826 static struct die_info
*
15827 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
15829 struct attribute
*attr
;
15831 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
15835 return follow_die_ref (die
, attr
, ext_cu
);
15838 /* Convert a DIE tag into its string name. */
15840 static const char *
15841 dwarf_tag_name (unsigned tag
)
15843 const char *name
= get_DW_TAG_name (tag
);
15846 return "DW_TAG_<unknown>";
15851 /* Convert a DWARF attribute code into its string name. */
15853 static const char *
15854 dwarf_attr_name (unsigned attr
)
15858 #ifdef MIPS /* collides with DW_AT_HP_block_index */
15859 if (attr
== DW_AT_MIPS_fde
)
15860 return "DW_AT_MIPS_fde";
15862 if (attr
== DW_AT_HP_block_index
)
15863 return "DW_AT_HP_block_index";
15866 name
= get_DW_AT_name (attr
);
15869 return "DW_AT_<unknown>";
15874 /* Convert a DWARF value form code into its string name. */
15876 static const char *
15877 dwarf_form_name (unsigned form
)
15879 const char *name
= get_DW_FORM_name (form
);
15882 return "DW_FORM_<unknown>";
15888 dwarf_bool_name (unsigned mybool
)
15896 /* Convert a DWARF type code into its string name. */
15898 static const char *
15899 dwarf_type_encoding_name (unsigned enc
)
15901 const char *name
= get_DW_ATE_name (enc
);
15904 return "DW_ATE_<unknown>";
15910 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
15914 print_spaces (indent
, f
);
15915 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
15916 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
15918 if (die
->parent
!= NULL
)
15920 print_spaces (indent
, f
);
15921 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
15922 die
->parent
->offset
.sect_off
);
15925 print_spaces (indent
, f
);
15926 fprintf_unfiltered (f
, " has children: %s\n",
15927 dwarf_bool_name (die
->child
!= NULL
));
15929 print_spaces (indent
, f
);
15930 fprintf_unfiltered (f
, " attributes:\n");
15932 for (i
= 0; i
< die
->num_attrs
; ++i
)
15934 print_spaces (indent
, f
);
15935 fprintf_unfiltered (f
, " %s (%s) ",
15936 dwarf_attr_name (die
->attrs
[i
].name
),
15937 dwarf_form_name (die
->attrs
[i
].form
));
15939 switch (die
->attrs
[i
].form
)
15942 case DW_FORM_GNU_addr_index
:
15943 fprintf_unfiltered (f
, "address: ");
15944 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
15946 case DW_FORM_block2
:
15947 case DW_FORM_block4
:
15948 case DW_FORM_block
:
15949 case DW_FORM_block1
:
15950 fprintf_unfiltered (f
, "block: size %d",
15951 DW_BLOCK (&die
->attrs
[i
])->size
);
15953 case DW_FORM_exprloc
:
15954 fprintf_unfiltered (f
, "expression: size %u",
15955 DW_BLOCK (&die
->attrs
[i
])->size
);
15957 case DW_FORM_ref_addr
:
15958 fprintf_unfiltered (f
, "ref address: ");
15959 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
15965 case DW_FORM_ref_udata
:
15966 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
15967 (long) (DW_UNSND (&die
->attrs
[i
])));
15969 case DW_FORM_data1
:
15970 case DW_FORM_data2
:
15971 case DW_FORM_data4
:
15972 case DW_FORM_data8
:
15973 case DW_FORM_udata
:
15974 case DW_FORM_sdata
:
15975 fprintf_unfiltered (f
, "constant: %s",
15976 pulongest (DW_UNSND (&die
->attrs
[i
])));
15978 case DW_FORM_sec_offset
:
15979 fprintf_unfiltered (f
, "section offset: %s",
15980 pulongest (DW_UNSND (&die
->attrs
[i
])));
15982 case DW_FORM_ref_sig8
:
15983 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15984 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15985 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15987 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15989 case DW_FORM_string
:
15991 case DW_FORM_GNU_str_index
:
15992 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15993 DW_STRING (&die
->attrs
[i
])
15994 ? DW_STRING (&die
->attrs
[i
]) : "",
15995 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15998 if (DW_UNSND (&die
->attrs
[i
]))
15999 fprintf_unfiltered (f
, "flag: TRUE");
16001 fprintf_unfiltered (f
, "flag: FALSE");
16003 case DW_FORM_flag_present
:
16004 fprintf_unfiltered (f
, "flag: TRUE");
16006 case DW_FORM_indirect
:
16007 /* The reader will have reduced the indirect form to
16008 the "base form" so this form should not occur. */
16009 fprintf_unfiltered (f
,
16010 "unexpected attribute form: DW_FORM_indirect");
16013 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
16014 die
->attrs
[i
].form
);
16017 fprintf_unfiltered (f
, "\n");
16022 dump_die_for_error (struct die_info
*die
)
16024 dump_die_shallow (gdb_stderr
, 0, die
);
16028 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
16030 int indent
= level
* 4;
16032 gdb_assert (die
!= NULL
);
16034 if (level
>= max_level
)
16037 dump_die_shallow (f
, indent
, die
);
16039 if (die
->child
!= NULL
)
16041 print_spaces (indent
, f
);
16042 fprintf_unfiltered (f
, " Children:");
16043 if (level
+ 1 < max_level
)
16045 fprintf_unfiltered (f
, "\n");
16046 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
16050 fprintf_unfiltered (f
,
16051 " [not printed, max nesting level reached]\n");
16055 if (die
->sibling
!= NULL
&& level
> 0)
16057 dump_die_1 (f
, level
, max_level
, die
->sibling
);
16061 /* This is called from the pdie macro in gdbinit.in.
16062 It's not static so gcc will keep a copy callable from gdb. */
16065 dump_die (struct die_info
*die
, int max_level
)
16067 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
16071 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
16075 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
16081 /* DW_ADDR is always stored already as sect_offset; despite for the forms
16082 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
16085 is_ref_attr (struct attribute
*attr
)
16087 switch (attr
->form
)
16089 case DW_FORM_ref_addr
:
16094 case DW_FORM_ref_udata
:
16101 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
16105 dwarf2_get_ref_die_offset (struct attribute
*attr
)
16107 sect_offset retval
= { DW_UNSND (attr
) };
16109 if (is_ref_attr (attr
))
16112 retval
.sect_off
= 0;
16113 complaint (&symfile_complaints
,
16114 _("unsupported die ref attribute form: '%s'"),
16115 dwarf_form_name (attr
->form
));
16119 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
16120 * the value held by the attribute is not constant. */
16123 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
16125 if (attr
->form
== DW_FORM_sdata
)
16126 return DW_SND (attr
);
16127 else if (attr
->form
== DW_FORM_udata
16128 || attr
->form
== DW_FORM_data1
16129 || attr
->form
== DW_FORM_data2
16130 || attr
->form
== DW_FORM_data4
16131 || attr
->form
== DW_FORM_data8
)
16132 return DW_UNSND (attr
);
16135 complaint (&symfile_complaints
,
16136 _("Attribute value is not a constant (%s)"),
16137 dwarf_form_name (attr
->form
));
16138 return default_value
;
16142 /* Follow reference or signature attribute ATTR of SRC_DIE.
16143 On entry *REF_CU is the CU of SRC_DIE.
16144 On exit *REF_CU is the CU of the result. */
16146 static struct die_info
*
16147 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
16148 struct dwarf2_cu
**ref_cu
)
16150 struct die_info
*die
;
16152 if (is_ref_attr (attr
))
16153 die
= follow_die_ref (src_die
, attr
, ref_cu
);
16154 else if (attr
->form
== DW_FORM_ref_sig8
)
16155 die
= follow_die_sig (src_die
, attr
, ref_cu
);
16158 dump_die_for_error (src_die
);
16159 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
16160 (*ref_cu
)->objfile
->name
);
16166 /* Follow reference OFFSET.
16167 On entry *REF_CU is the CU of the source die referencing OFFSET.
16168 On exit *REF_CU is the CU of the result.
16169 Returns NULL if OFFSET is invalid. */
16171 static struct die_info
*
16172 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
16174 struct die_info temp_die
;
16175 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
16177 gdb_assert (cu
->per_cu
!= NULL
);
16181 if (cu
->per_cu
->is_debug_types
)
16183 /* .debug_types CUs cannot reference anything outside their CU.
16184 If they need to, they have to reference a signatured type via
16185 DW_FORM_ref_sig8. */
16186 if (! offset_in_cu_p (&cu
->header
, offset
))
16189 else if (! offset_in_cu_p (&cu
->header
, offset
))
16191 struct dwarf2_per_cu_data
*per_cu
;
16193 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
16195 /* If necessary, add it to the queue and load its DIEs. */
16196 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
16197 load_full_comp_unit (per_cu
, cu
->language
);
16199 target_cu
= per_cu
->cu
;
16201 else if (cu
->dies
== NULL
)
16203 /* We're loading full DIEs during partial symbol reading. */
16204 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
16205 load_full_comp_unit (cu
->per_cu
, language_minimal
);
16208 *ref_cu
= target_cu
;
16209 temp_die
.offset
= offset
;
16210 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
16213 /* Follow reference attribute ATTR of SRC_DIE.
16214 On entry *REF_CU is the CU of SRC_DIE.
16215 On exit *REF_CU is the CU of the result. */
16217 static struct die_info
*
16218 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
16219 struct dwarf2_cu
**ref_cu
)
16221 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16222 struct dwarf2_cu
*cu
= *ref_cu
;
16223 struct die_info
*die
;
16225 die
= follow_die_offset (offset
, ref_cu
);
16227 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
16228 "at 0x%x [in module %s]"),
16229 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
16234 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
16235 Returned value is intended for DW_OP_call*. Returned
16236 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
16238 struct dwarf2_locexpr_baton
16239 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
16240 struct dwarf2_per_cu_data
*per_cu
,
16241 CORE_ADDR (*get_frame_pc
) (void *baton
),
16244 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
16245 struct dwarf2_cu
*cu
;
16246 struct die_info
*die
;
16247 struct attribute
*attr
;
16248 struct dwarf2_locexpr_baton retval
;
16250 dw2_setup (per_cu
->objfile
);
16252 if (per_cu
->cu
== NULL
)
16256 die
= follow_die_offset (offset
, &cu
);
16258 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
16259 offset
.sect_off
, per_cu
->objfile
->name
);
16261 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16264 /* DWARF: "If there is no such attribute, then there is no effect.".
16265 DATA is ignored if SIZE is 0. */
16267 retval
.data
= NULL
;
16270 else if (attr_form_is_section_offset (attr
))
16272 struct dwarf2_loclist_baton loclist_baton
;
16273 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
16276 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
16278 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
16280 retval
.size
= size
;
16284 if (!attr_form_is_block (attr
))
16285 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
16286 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
16287 offset
.sect_off
, per_cu
->objfile
->name
);
16289 retval
.data
= DW_BLOCK (attr
)->data
;
16290 retval
.size
= DW_BLOCK (attr
)->size
;
16292 retval
.per_cu
= cu
->per_cu
;
16294 age_cached_comp_units ();
16299 /* Return the type of the DIE at DIE_OFFSET in the CU named by
16303 dwarf2_get_die_type (cu_offset die_offset
,
16304 struct dwarf2_per_cu_data
*per_cu
)
16306 sect_offset die_offset_sect
;
16308 dw2_setup (per_cu
->objfile
);
16310 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
16311 return get_die_type_at_offset (die_offset_sect
, per_cu
);
16314 /* Follow the signature attribute ATTR in SRC_DIE.
16315 On entry *REF_CU is the CU of SRC_DIE.
16316 On exit *REF_CU is the CU of the result. */
16318 static struct die_info
*
16319 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
16320 struct dwarf2_cu
**ref_cu
)
16322 struct objfile
*objfile
= (*ref_cu
)->objfile
;
16323 struct die_info temp_die
;
16324 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16325 struct dwarf2_cu
*sig_cu
;
16326 struct die_info
*die
;
16328 /* sig_type will be NULL if the signatured type is missing from
16330 if (sig_type
== NULL
)
16331 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16332 "at 0x%x [in module %s]"),
16333 src_die
->offset
.sect_off
, objfile
->name
);
16335 /* If necessary, add it to the queue and load its DIEs. */
16337 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
16338 read_signatured_type (sig_type
);
16340 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
16342 sig_cu
= sig_type
->per_cu
.cu
;
16343 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
16344 temp_die
.offset
= sig_type
->type_offset_in_section
;
16345 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
16346 temp_die
.offset
.sect_off
);
16353 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
16354 "from DIE at 0x%x [in module %s]"),
16355 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
16358 /* Given an offset of a signatured type, return its signatured_type. */
16360 static struct signatured_type
*
16361 lookup_signatured_type_at_offset (struct objfile
*objfile
,
16362 struct dwarf2_section_info
*section
,
16363 sect_offset offset
)
16365 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
16366 unsigned int length
, initial_length_size
;
16367 unsigned int sig_offset
;
16368 struct signatured_type find_entry
, *sig_type
;
16370 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
16371 sig_offset
= (initial_length_size
16373 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
16374 + 1 /*address_size*/);
16375 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
16376 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
16378 /* This is only used to lookup previously recorded types.
16379 If we didn't find it, it's our bug. */
16380 gdb_assert (sig_type
!= NULL
);
16381 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
16386 /* Load the DIEs associated with type unit PER_CU into memory. */
16389 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
16391 struct signatured_type
*sig_type
;
16393 /* Caller is responsible for ensuring type_unit_groups don't get here. */
16394 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
16396 /* We have the per_cu, but we need the signatured_type.
16397 Fortunately this is an easy translation. */
16398 gdb_assert (per_cu
->is_debug_types
);
16399 sig_type
= (struct signatured_type
*) per_cu
;
16401 gdb_assert (per_cu
->cu
== NULL
);
16403 read_signatured_type (sig_type
);
16405 gdb_assert (per_cu
->cu
!= NULL
);
16408 /* die_reader_func for read_signatured_type.
16409 This is identical to load_full_comp_unit_reader,
16410 but is kept separate for now. */
16413 read_signatured_type_reader (const struct die_reader_specs
*reader
,
16414 gdb_byte
*info_ptr
,
16415 struct die_info
*comp_unit_die
,
16419 struct dwarf2_cu
*cu
= reader
->cu
;
16421 gdb_assert (cu
->die_hash
== NULL
);
16423 htab_create_alloc_ex (cu
->header
.length
/ 12,
16427 &cu
->comp_unit_obstack
,
16428 hashtab_obstack_allocate
,
16429 dummy_obstack_deallocate
);
16432 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
16433 &info_ptr
, comp_unit_die
);
16434 cu
->dies
= comp_unit_die
;
16435 /* comp_unit_die is not stored in die_hash, no need. */
16437 /* We try not to read any attributes in this function, because not
16438 all CUs needed for references have been loaded yet, and symbol
16439 table processing isn't initialized. But we have to set the CU language,
16440 or we won't be able to build types correctly.
16441 Similarly, if we do not read the producer, we can not apply
16442 producer-specific interpretation. */
16443 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
16446 /* Read in a signatured type and build its CU and DIEs.
16447 If the type is a stub for the real type in a DWO file,
16448 read in the real type from the DWO file as well. */
16451 read_signatured_type (struct signatured_type
*sig_type
)
16453 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
16455 gdb_assert (per_cu
->is_debug_types
);
16456 gdb_assert (per_cu
->cu
== NULL
);
16458 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
16459 read_signatured_type_reader
, NULL
);
16462 /* Decode simple location descriptions.
16463 Given a pointer to a dwarf block that defines a location, compute
16464 the location and return the value.
16466 NOTE drow/2003-11-18: This function is called in two situations
16467 now: for the address of static or global variables (partial symbols
16468 only) and for offsets into structures which are expected to be
16469 (more or less) constant. The partial symbol case should go away,
16470 and only the constant case should remain. That will let this
16471 function complain more accurately. A few special modes are allowed
16472 without complaint for global variables (for instance, global
16473 register values and thread-local values).
16475 A location description containing no operations indicates that the
16476 object is optimized out. The return value is 0 for that case.
16477 FIXME drow/2003-11-16: No callers check for this case any more; soon all
16478 callers will only want a very basic result and this can become a
16481 Note that stack[0] is unused except as a default error return. */
16484 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
16486 struct objfile
*objfile
= cu
->objfile
;
16488 int size
= blk
->size
;
16489 gdb_byte
*data
= blk
->data
;
16490 CORE_ADDR stack
[64];
16492 unsigned int bytes_read
, unsnd
;
16498 stack
[++stacki
] = 0;
16537 stack
[++stacki
] = op
- DW_OP_lit0
;
16572 stack
[++stacki
] = op
- DW_OP_reg0
;
16574 dwarf2_complex_location_expr_complaint ();
16578 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
16580 stack
[++stacki
] = unsnd
;
16582 dwarf2_complex_location_expr_complaint ();
16586 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
16591 case DW_OP_const1u
:
16592 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
16596 case DW_OP_const1s
:
16597 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
16601 case DW_OP_const2u
:
16602 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
16606 case DW_OP_const2s
:
16607 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
16611 case DW_OP_const4u
:
16612 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
16616 case DW_OP_const4s
:
16617 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
16621 case DW_OP_const8u
:
16622 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
16627 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
16633 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
16638 stack
[stacki
+ 1] = stack
[stacki
];
16643 stack
[stacki
- 1] += stack
[stacki
];
16647 case DW_OP_plus_uconst
:
16648 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
16654 stack
[stacki
- 1] -= stack
[stacki
];
16659 /* If we're not the last op, then we definitely can't encode
16660 this using GDB's address_class enum. This is valid for partial
16661 global symbols, although the variable's address will be bogus
16664 dwarf2_complex_location_expr_complaint ();
16667 case DW_OP_GNU_push_tls_address
:
16668 /* The top of the stack has the offset from the beginning
16669 of the thread control block at which the variable is located. */
16670 /* Nothing should follow this operator, so the top of stack would
16672 /* This is valid for partial global symbols, but the variable's
16673 address will be bogus in the psymtab. Make it always at least
16674 non-zero to not look as a variable garbage collected by linker
16675 which have DW_OP_addr 0. */
16677 dwarf2_complex_location_expr_complaint ();
16681 case DW_OP_GNU_uninit
:
16684 case DW_OP_GNU_addr_index
:
16685 case DW_OP_GNU_const_index
:
16686 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
16693 const char *name
= get_DW_OP_name (op
);
16696 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
16699 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
16703 return (stack
[stacki
]);
16706 /* Enforce maximum stack depth of SIZE-1 to avoid writing
16707 outside of the allocated space. Also enforce minimum>0. */
16708 if (stacki
>= ARRAY_SIZE (stack
) - 1)
16710 complaint (&symfile_complaints
,
16711 _("location description stack overflow"));
16717 complaint (&symfile_complaints
,
16718 _("location description stack underflow"));
16722 return (stack
[stacki
]);
16725 /* memory allocation interface */
16727 static struct dwarf_block
*
16728 dwarf_alloc_block (struct dwarf2_cu
*cu
)
16730 struct dwarf_block
*blk
;
16732 blk
= (struct dwarf_block
*)
16733 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
16737 static struct die_info
*
16738 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
16740 struct die_info
*die
;
16741 size_t size
= sizeof (struct die_info
);
16744 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
16746 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
16747 memset (die
, 0, sizeof (struct die_info
));
16752 /* Macro support. */
16754 /* Return the full name of file number I in *LH's file name table.
16755 Use COMP_DIR as the name of the current directory of the
16756 compilation. The result is allocated using xmalloc; the caller is
16757 responsible for freeing it. */
16759 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
16761 /* Is the file number a valid index into the line header's file name
16762 table? Remember that file numbers start with one, not zero. */
16763 if (1 <= file
&& file
<= lh
->num_file_names
)
16765 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
16767 if (IS_ABSOLUTE_PATH (fe
->name
))
16768 return xstrdup (fe
->name
);
16776 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16782 dir_len
= strlen (dir
);
16783 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
16784 strcpy (full_name
, dir
);
16785 full_name
[dir_len
] = '/';
16786 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
16790 return xstrdup (fe
->name
);
16795 /* The compiler produced a bogus file number. We can at least
16796 record the macro definitions made in the file, even if we
16797 won't be able to find the file by name. */
16798 char fake_name
[80];
16800 sprintf (fake_name
, "<bad macro file number %d>", file
);
16802 complaint (&symfile_complaints
,
16803 _("bad file number in macro information (%d)"),
16806 return xstrdup (fake_name
);
16811 static struct macro_source_file
*
16812 macro_start_file (int file
, int line
,
16813 struct macro_source_file
*current_file
,
16814 const char *comp_dir
,
16815 struct line_header
*lh
, struct objfile
*objfile
)
16817 /* The full name of this source file. */
16818 char *full_name
= file_full_name (file
, lh
, comp_dir
);
16820 /* We don't create a macro table for this compilation unit
16821 at all until we actually get a filename. */
16822 if (! pending_macros
)
16823 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
16824 objfile
->macro_cache
);
16826 if (! current_file
)
16828 /* If we have no current file, then this must be the start_file
16829 directive for the compilation unit's main source file. */
16830 current_file
= macro_set_main (pending_macros
, full_name
);
16831 macro_define_special (pending_macros
);
16834 current_file
= macro_include (current_file
, line
, full_name
);
16838 return current_file
;
16842 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
16843 followed by a null byte. */
16845 copy_string (const char *buf
, int len
)
16847 char *s
= xmalloc (len
+ 1);
16849 memcpy (s
, buf
, len
);
16855 static const char *
16856 consume_improper_spaces (const char *p
, const char *body
)
16860 complaint (&symfile_complaints
,
16861 _("macro definition contains spaces "
16862 "in formal argument list:\n`%s'"),
16874 parse_macro_definition (struct macro_source_file
*file
, int line
,
16879 /* The body string takes one of two forms. For object-like macro
16880 definitions, it should be:
16882 <macro name> " " <definition>
16884 For function-like macro definitions, it should be:
16886 <macro name> "() " <definition>
16888 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
16890 Spaces may appear only where explicitly indicated, and in the
16893 The Dwarf 2 spec says that an object-like macro's name is always
16894 followed by a space, but versions of GCC around March 2002 omit
16895 the space when the macro's definition is the empty string.
16897 The Dwarf 2 spec says that there should be no spaces between the
16898 formal arguments in a function-like macro's formal argument list,
16899 but versions of GCC around March 2002 include spaces after the
16903 /* Find the extent of the macro name. The macro name is terminated
16904 by either a space or null character (for an object-like macro) or
16905 an opening paren (for a function-like macro). */
16906 for (p
= body
; *p
; p
++)
16907 if (*p
== ' ' || *p
== '(')
16910 if (*p
== ' ' || *p
== '\0')
16912 /* It's an object-like macro. */
16913 int name_len
= p
- body
;
16914 char *name
= copy_string (body
, name_len
);
16915 const char *replacement
;
16918 replacement
= body
+ name_len
+ 1;
16921 dwarf2_macro_malformed_definition_complaint (body
);
16922 replacement
= body
+ name_len
;
16925 macro_define_object (file
, line
, name
, replacement
);
16929 else if (*p
== '(')
16931 /* It's a function-like macro. */
16932 char *name
= copy_string (body
, p
- body
);
16935 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16939 p
= consume_improper_spaces (p
, body
);
16941 /* Parse the formal argument list. */
16942 while (*p
&& *p
!= ')')
16944 /* Find the extent of the current argument name. */
16945 const char *arg_start
= p
;
16947 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16950 if (! *p
|| p
== arg_start
)
16951 dwarf2_macro_malformed_definition_complaint (body
);
16954 /* Make sure argv has room for the new argument. */
16955 if (argc
>= argv_size
)
16958 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16961 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16964 p
= consume_improper_spaces (p
, body
);
16966 /* Consume the comma, if present. */
16971 p
= consume_improper_spaces (p
, body
);
16980 /* Perfectly formed definition, no complaints. */
16981 macro_define_function (file
, line
, name
,
16982 argc
, (const char **) argv
,
16984 else if (*p
== '\0')
16986 /* Complain, but do define it. */
16987 dwarf2_macro_malformed_definition_complaint (body
);
16988 macro_define_function (file
, line
, name
,
16989 argc
, (const char **) argv
,
16993 /* Just complain. */
16994 dwarf2_macro_malformed_definition_complaint (body
);
16997 /* Just complain. */
16998 dwarf2_macro_malformed_definition_complaint (body
);
17004 for (i
= 0; i
< argc
; i
++)
17010 dwarf2_macro_malformed_definition_complaint (body
);
17013 /* Skip some bytes from BYTES according to the form given in FORM.
17014 Returns the new pointer. */
17017 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
17018 enum dwarf_form form
,
17019 unsigned int offset_size
,
17020 struct dwarf2_section_info
*section
)
17022 unsigned int bytes_read
;
17026 case DW_FORM_data1
:
17031 case DW_FORM_data2
:
17035 case DW_FORM_data4
:
17039 case DW_FORM_data8
:
17043 case DW_FORM_string
:
17044 read_direct_string (abfd
, bytes
, &bytes_read
);
17045 bytes
+= bytes_read
;
17048 case DW_FORM_sec_offset
:
17050 bytes
+= offset_size
;
17053 case DW_FORM_block
:
17054 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
17055 bytes
+= bytes_read
;
17058 case DW_FORM_block1
:
17059 bytes
+= 1 + read_1_byte (abfd
, bytes
);
17061 case DW_FORM_block2
:
17062 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
17064 case DW_FORM_block4
:
17065 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
17068 case DW_FORM_sdata
:
17069 case DW_FORM_udata
:
17070 case DW_FORM_GNU_addr_index
:
17071 case DW_FORM_GNU_str_index
:
17072 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
17075 dwarf2_section_buffer_overflow_complaint (section
);
17083 complaint (&symfile_complaints
,
17084 _("invalid form 0x%x in `%s'"),
17086 section
->asection
->name
);
17094 /* A helper for dwarf_decode_macros that handles skipping an unknown
17095 opcode. Returns an updated pointer to the macro data buffer; or,
17096 on error, issues a complaint and returns NULL. */
17099 skip_unknown_opcode (unsigned int opcode
,
17100 gdb_byte
**opcode_definitions
,
17101 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17103 unsigned int offset_size
,
17104 struct dwarf2_section_info
*section
)
17106 unsigned int bytes_read
, i
;
17110 if (opcode_definitions
[opcode
] == NULL
)
17112 complaint (&symfile_complaints
,
17113 _("unrecognized DW_MACFINO opcode 0x%x"),
17118 defn
= opcode_definitions
[opcode
];
17119 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
17120 defn
+= bytes_read
;
17122 for (i
= 0; i
< arg
; ++i
)
17124 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
17126 if (mac_ptr
== NULL
)
17128 /* skip_form_bytes already issued the complaint. */
17136 /* A helper function which parses the header of a macro section.
17137 If the macro section is the extended (for now called "GNU") type,
17138 then this updates *OFFSET_SIZE. Returns a pointer to just after
17139 the header, or issues a complaint and returns NULL on error. */
17142 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
17145 unsigned int *offset_size
,
17146 int section_is_gnu
)
17148 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
17150 if (section_is_gnu
)
17152 unsigned int version
, flags
;
17154 version
= read_2_bytes (abfd
, mac_ptr
);
17157 complaint (&symfile_complaints
,
17158 _("unrecognized version `%d' in .debug_macro section"),
17164 flags
= read_1_byte (abfd
, mac_ptr
);
17166 *offset_size
= (flags
& 1) ? 8 : 4;
17168 if ((flags
& 2) != 0)
17169 /* We don't need the line table offset. */
17170 mac_ptr
+= *offset_size
;
17172 /* Vendor opcode descriptions. */
17173 if ((flags
& 4) != 0)
17175 unsigned int i
, count
;
17177 count
= read_1_byte (abfd
, mac_ptr
);
17179 for (i
= 0; i
< count
; ++i
)
17181 unsigned int opcode
, bytes_read
;
17184 opcode
= read_1_byte (abfd
, mac_ptr
);
17186 opcode_definitions
[opcode
] = mac_ptr
;
17187 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17188 mac_ptr
+= bytes_read
;
17197 /* A helper for dwarf_decode_macros that handles the GNU extensions,
17198 including DW_MACRO_GNU_transparent_include. */
17201 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17202 struct macro_source_file
*current_file
,
17203 struct line_header
*lh
, char *comp_dir
,
17204 struct dwarf2_section_info
*section
,
17205 int section_is_gnu
,
17206 unsigned int offset_size
,
17207 struct objfile
*objfile
,
17208 htab_t include_hash
)
17210 enum dwarf_macro_record_type macinfo_type
;
17211 int at_commandline
;
17212 gdb_byte
*opcode_definitions
[256];
17214 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17215 &offset_size
, section_is_gnu
);
17216 if (mac_ptr
== NULL
)
17218 /* We already issued a complaint. */
17222 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
17223 GDB is still reading the definitions from command line. First
17224 DW_MACINFO_start_file will need to be ignored as it was already executed
17225 to create CURRENT_FILE for the main source holding also the command line
17226 definitions. On first met DW_MACINFO_start_file this flag is reset to
17227 normally execute all the remaining DW_MACINFO_start_file macinfos. */
17229 at_commandline
= 1;
17233 /* Do we at least have room for a macinfo type byte? */
17234 if (mac_ptr
>= mac_end
)
17236 dwarf2_section_buffer_overflow_complaint (section
);
17240 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17243 /* Note that we rely on the fact that the corresponding GNU and
17244 DWARF constants are the same. */
17245 switch (macinfo_type
)
17247 /* A zero macinfo type indicates the end of the macro
17252 case DW_MACRO_GNU_define
:
17253 case DW_MACRO_GNU_undef
:
17254 case DW_MACRO_GNU_define_indirect
:
17255 case DW_MACRO_GNU_undef_indirect
:
17257 unsigned int bytes_read
;
17262 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17263 mac_ptr
+= bytes_read
;
17265 if (macinfo_type
== DW_MACRO_GNU_define
17266 || macinfo_type
== DW_MACRO_GNU_undef
)
17268 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17269 mac_ptr
+= bytes_read
;
17273 LONGEST str_offset
;
17275 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17276 mac_ptr
+= offset_size
;
17278 body
= read_indirect_string_at_offset (abfd
, str_offset
);
17281 is_define
= (macinfo_type
== DW_MACRO_GNU_define
17282 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
17283 if (! current_file
)
17285 /* DWARF violation as no main source is present. */
17286 complaint (&symfile_complaints
,
17287 _("debug info with no main source gives macro %s "
17289 is_define
? _("definition") : _("undefinition"),
17293 if ((line
== 0 && !at_commandline
)
17294 || (line
!= 0 && at_commandline
))
17295 complaint (&symfile_complaints
,
17296 _("debug info gives %s macro %s with %s line %d: %s"),
17297 at_commandline
? _("command-line") : _("in-file"),
17298 is_define
? _("definition") : _("undefinition"),
17299 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
17302 parse_macro_definition (current_file
, line
, body
);
17305 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
17306 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
17307 macro_undef (current_file
, line
, body
);
17312 case DW_MACRO_GNU_start_file
:
17314 unsigned int bytes_read
;
17317 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17318 mac_ptr
+= bytes_read
;
17319 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17320 mac_ptr
+= bytes_read
;
17322 if ((line
== 0 && !at_commandline
)
17323 || (line
!= 0 && at_commandline
))
17324 complaint (&symfile_complaints
,
17325 _("debug info gives source %d included "
17326 "from %s at %s line %d"),
17327 file
, at_commandline
? _("command-line") : _("file"),
17328 line
== 0 ? _("zero") : _("non-zero"), line
);
17330 if (at_commandline
)
17332 /* This DW_MACRO_GNU_start_file was executed in the
17334 at_commandline
= 0;
17337 current_file
= macro_start_file (file
, line
,
17338 current_file
, comp_dir
,
17343 case DW_MACRO_GNU_end_file
:
17344 if (! current_file
)
17345 complaint (&symfile_complaints
,
17346 _("macro debug info has an unmatched "
17347 "`close_file' directive"));
17350 current_file
= current_file
->included_by
;
17351 if (! current_file
)
17353 enum dwarf_macro_record_type next_type
;
17355 /* GCC circa March 2002 doesn't produce the zero
17356 type byte marking the end of the compilation
17357 unit. Complain if it's not there, but exit no
17360 /* Do we at least have room for a macinfo type byte? */
17361 if (mac_ptr
>= mac_end
)
17363 dwarf2_section_buffer_overflow_complaint (section
);
17367 /* We don't increment mac_ptr here, so this is just
17369 next_type
= read_1_byte (abfd
, mac_ptr
);
17370 if (next_type
!= 0)
17371 complaint (&symfile_complaints
,
17372 _("no terminating 0-type entry for "
17373 "macros in `.debug_macinfo' section"));
17380 case DW_MACRO_GNU_transparent_include
:
17385 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17386 mac_ptr
+= offset_size
;
17388 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17391 /* This has actually happened; see
17392 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
17393 complaint (&symfile_complaints
,
17394 _("recursive DW_MACRO_GNU_transparent_include in "
17395 ".debug_macro section"));
17401 dwarf_decode_macro_bytes (abfd
,
17402 section
->buffer
+ offset
,
17403 mac_end
, current_file
,
17405 section
, section_is_gnu
,
17406 offset_size
, objfile
, include_hash
);
17408 htab_remove_elt (include_hash
, mac_ptr
);
17413 case DW_MACINFO_vendor_ext
:
17414 if (!section_is_gnu
)
17416 unsigned int bytes_read
;
17419 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17420 mac_ptr
+= bytes_read
;
17421 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17422 mac_ptr
+= bytes_read
;
17424 /* We don't recognize any vendor extensions. */
17430 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17431 mac_ptr
, mac_end
, abfd
, offset_size
,
17433 if (mac_ptr
== NULL
)
17437 } while (macinfo_type
!= 0);
17441 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
17442 char *comp_dir
, int section_is_gnu
)
17444 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17445 struct line_header
*lh
= cu
->line_header
;
17447 gdb_byte
*mac_ptr
, *mac_end
;
17448 struct macro_source_file
*current_file
= 0;
17449 enum dwarf_macro_record_type macinfo_type
;
17450 unsigned int offset_size
= cu
->header
.offset_size
;
17451 gdb_byte
*opcode_definitions
[256];
17452 struct cleanup
*cleanup
;
17453 htab_t include_hash
;
17455 struct dwarf2_section_info
*section
;
17456 const char *section_name
;
17458 if (cu
->dwo_unit
!= NULL
)
17460 if (section_is_gnu
)
17462 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
17463 section_name
= ".debug_macro.dwo";
17467 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
17468 section_name
= ".debug_macinfo.dwo";
17473 if (section_is_gnu
)
17475 section
= &dwarf2_per_objfile
->macro
;
17476 section_name
= ".debug_macro";
17480 section
= &dwarf2_per_objfile
->macinfo
;
17481 section_name
= ".debug_macinfo";
17485 dwarf2_read_section (objfile
, section
);
17486 if (section
->buffer
== NULL
)
17488 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
17491 abfd
= section
->asection
->owner
;
17493 /* First pass: Find the name of the base filename.
17494 This filename is needed in order to process all macros whose definition
17495 (or undefinition) comes from the command line. These macros are defined
17496 before the first DW_MACINFO_start_file entry, and yet still need to be
17497 associated to the base file.
17499 To determine the base file name, we scan the macro definitions until we
17500 reach the first DW_MACINFO_start_file entry. We then initialize
17501 CURRENT_FILE accordingly so that any macro definition found before the
17502 first DW_MACINFO_start_file can still be associated to the base file. */
17504 mac_ptr
= section
->buffer
+ offset
;
17505 mac_end
= section
->buffer
+ section
->size
;
17507 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17508 &offset_size
, section_is_gnu
);
17509 if (mac_ptr
== NULL
)
17511 /* We already issued a complaint. */
17517 /* Do we at least have room for a macinfo type byte? */
17518 if (mac_ptr
>= mac_end
)
17520 /* Complaint is printed during the second pass as GDB will probably
17521 stop the first pass earlier upon finding
17522 DW_MACINFO_start_file. */
17526 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17529 /* Note that we rely on the fact that the corresponding GNU and
17530 DWARF constants are the same. */
17531 switch (macinfo_type
)
17533 /* A zero macinfo type indicates the end of the macro
17538 case DW_MACRO_GNU_define
:
17539 case DW_MACRO_GNU_undef
:
17540 /* Only skip the data by MAC_PTR. */
17542 unsigned int bytes_read
;
17544 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17545 mac_ptr
+= bytes_read
;
17546 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17547 mac_ptr
+= bytes_read
;
17551 case DW_MACRO_GNU_start_file
:
17553 unsigned int bytes_read
;
17556 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17557 mac_ptr
+= bytes_read
;
17558 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17559 mac_ptr
+= bytes_read
;
17561 current_file
= macro_start_file (file
, line
, current_file
,
17562 comp_dir
, lh
, objfile
);
17566 case DW_MACRO_GNU_end_file
:
17567 /* No data to skip by MAC_PTR. */
17570 case DW_MACRO_GNU_define_indirect
:
17571 case DW_MACRO_GNU_undef_indirect
:
17573 unsigned int bytes_read
;
17575 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17576 mac_ptr
+= bytes_read
;
17577 mac_ptr
+= offset_size
;
17581 case DW_MACRO_GNU_transparent_include
:
17582 /* Note that, according to the spec, a transparent include
17583 chain cannot call DW_MACRO_GNU_start_file. So, we can just
17584 skip this opcode. */
17585 mac_ptr
+= offset_size
;
17588 case DW_MACINFO_vendor_ext
:
17589 /* Only skip the data by MAC_PTR. */
17590 if (!section_is_gnu
)
17592 unsigned int bytes_read
;
17594 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17595 mac_ptr
+= bytes_read
;
17596 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17597 mac_ptr
+= bytes_read
;
17602 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17603 mac_ptr
, mac_end
, abfd
, offset_size
,
17605 if (mac_ptr
== NULL
)
17609 } while (macinfo_type
!= 0 && current_file
== NULL
);
17611 /* Second pass: Process all entries.
17613 Use the AT_COMMAND_LINE flag to determine whether we are still processing
17614 command-line macro definitions/undefinitions. This flag is unset when we
17615 reach the first DW_MACINFO_start_file entry. */
17617 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
17618 NULL
, xcalloc
, xfree
);
17619 cleanup
= make_cleanup_htab_delete (include_hash
);
17620 mac_ptr
= section
->buffer
+ offset
;
17621 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17623 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
17624 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
17625 offset_size
, objfile
, include_hash
);
17626 do_cleanups (cleanup
);
17629 /* Check if the attribute's form is a DW_FORM_block*
17630 if so return true else false. */
17633 attr_form_is_block (struct attribute
*attr
)
17635 return (attr
== NULL
? 0 :
17636 attr
->form
== DW_FORM_block1
17637 || attr
->form
== DW_FORM_block2
17638 || attr
->form
== DW_FORM_block4
17639 || attr
->form
== DW_FORM_block
17640 || attr
->form
== DW_FORM_exprloc
);
17643 /* Return non-zero if ATTR's value is a section offset --- classes
17644 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
17645 You may use DW_UNSND (attr) to retrieve such offsets.
17647 Section 7.5.4, "Attribute Encodings", explains that no attribute
17648 may have a value that belongs to more than one of these classes; it
17649 would be ambiguous if we did, because we use the same forms for all
17653 attr_form_is_section_offset (struct attribute
*attr
)
17655 return (attr
->form
== DW_FORM_data4
17656 || attr
->form
== DW_FORM_data8
17657 || attr
->form
== DW_FORM_sec_offset
);
17660 /* Return non-zero if ATTR's value falls in the 'constant' class, or
17661 zero otherwise. When this function returns true, you can apply
17662 dwarf2_get_attr_constant_value to it.
17664 However, note that for some attributes you must check
17665 attr_form_is_section_offset before using this test. DW_FORM_data4
17666 and DW_FORM_data8 are members of both the constant class, and of
17667 the classes that contain offsets into other debug sections
17668 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
17669 that, if an attribute's can be either a constant or one of the
17670 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
17671 taken as section offsets, not constants. */
17674 attr_form_is_constant (struct attribute
*attr
)
17676 switch (attr
->form
)
17678 case DW_FORM_sdata
:
17679 case DW_FORM_udata
:
17680 case DW_FORM_data1
:
17681 case DW_FORM_data2
:
17682 case DW_FORM_data4
:
17683 case DW_FORM_data8
:
17690 /* Return the .debug_loc section to use for CU.
17691 For DWO files use .debug_loc.dwo. */
17693 static struct dwarf2_section_info
*
17694 cu_debug_loc_section (struct dwarf2_cu
*cu
)
17697 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
17698 return &dwarf2_per_objfile
->loc
;
17701 /* A helper function that fills in a dwarf2_loclist_baton. */
17704 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
17705 struct dwarf2_loclist_baton
*baton
,
17706 struct attribute
*attr
)
17708 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17710 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17712 baton
->per_cu
= cu
->per_cu
;
17713 gdb_assert (baton
->per_cu
);
17714 /* We don't know how long the location list is, but make sure we
17715 don't run off the edge of the section. */
17716 baton
->size
= section
->size
- DW_UNSND (attr
);
17717 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
17718 baton
->base_address
= cu
->base_address
;
17719 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
17723 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
17724 struct dwarf2_cu
*cu
)
17726 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17727 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17729 if (attr_form_is_section_offset (attr
)
17730 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
17731 the section. If so, fall through to the complaint in the
17733 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
17735 struct dwarf2_loclist_baton
*baton
;
17737 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17738 sizeof (struct dwarf2_loclist_baton
));
17740 fill_in_loclist_baton (cu
, baton
, attr
);
17742 if (cu
->base_known
== 0)
17743 complaint (&symfile_complaints
,
17744 _("Location list used without "
17745 "specifying the CU base address."));
17747 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
17748 SYMBOL_LOCATION_BATON (sym
) = baton
;
17752 struct dwarf2_locexpr_baton
*baton
;
17754 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17755 sizeof (struct dwarf2_locexpr_baton
));
17756 baton
->per_cu
= cu
->per_cu
;
17757 gdb_assert (baton
->per_cu
);
17759 if (attr_form_is_block (attr
))
17761 /* Note that we're just copying the block's data pointer
17762 here, not the actual data. We're still pointing into the
17763 info_buffer for SYM's objfile; right now we never release
17764 that buffer, but when we do clean up properly this may
17766 baton
->size
= DW_BLOCK (attr
)->size
;
17767 baton
->data
= DW_BLOCK (attr
)->data
;
17771 dwarf2_invalid_attrib_class_complaint ("location description",
17772 SYMBOL_NATURAL_NAME (sym
));
17776 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
17777 SYMBOL_LOCATION_BATON (sym
) = baton
;
17781 /* Return the OBJFILE associated with the compilation unit CU. If CU
17782 came from a separate debuginfo file, then the master objfile is
17786 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
17788 struct objfile
*objfile
= per_cu
->objfile
;
17790 /* Return the master objfile, so that we can report and look up the
17791 correct file containing this variable. */
17792 if (objfile
->separate_debug_objfile_backlink
)
17793 objfile
= objfile
->separate_debug_objfile_backlink
;
17798 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
17799 (CU_HEADERP is unused in such case) or prepare a temporary copy at
17800 CU_HEADERP first. */
17802 static const struct comp_unit_head
*
17803 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
17804 struct dwarf2_per_cu_data
*per_cu
)
17806 gdb_byte
*info_ptr
;
17809 return &per_cu
->cu
->header
;
17811 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
17813 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
17814 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
17819 /* Return the address size given in the compilation unit header for CU. */
17822 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17824 struct comp_unit_head cu_header_local
;
17825 const struct comp_unit_head
*cu_headerp
;
17827 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17829 return cu_headerp
->addr_size
;
17832 /* Return the offset size given in the compilation unit header for CU. */
17835 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
17837 struct comp_unit_head cu_header_local
;
17838 const struct comp_unit_head
*cu_headerp
;
17840 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17842 return cu_headerp
->offset_size
;
17845 /* See its dwarf2loc.h declaration. */
17848 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17850 struct comp_unit_head cu_header_local
;
17851 const struct comp_unit_head
*cu_headerp
;
17853 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17855 if (cu_headerp
->version
== 2)
17856 return cu_headerp
->addr_size
;
17858 return cu_headerp
->offset_size
;
17861 /* Return the text offset of the CU. The returned offset comes from
17862 this CU's objfile. If this objfile came from a separate debuginfo
17863 file, then the offset may be different from the corresponding
17864 offset in the parent objfile. */
17867 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
17869 struct objfile
*objfile
= per_cu
->objfile
;
17871 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17874 /* Locate the .debug_info compilation unit from CU's objfile which contains
17875 the DIE at OFFSET. Raises an error on failure. */
17877 static struct dwarf2_per_cu_data
*
17878 dwarf2_find_containing_comp_unit (sect_offset offset
,
17879 struct objfile
*objfile
)
17881 struct dwarf2_per_cu_data
*this_cu
;
17885 high
= dwarf2_per_objfile
->n_comp_units
- 1;
17888 int mid
= low
+ (high
- low
) / 2;
17890 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
17891 >= offset
.sect_off
)
17896 gdb_assert (low
== high
);
17897 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
17901 error (_("Dwarf Error: could not find partial DIE containing "
17902 "offset 0x%lx [in module %s]"),
17903 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
17905 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
17906 <= offset
.sect_off
);
17907 return dwarf2_per_objfile
->all_comp_units
[low
-1];
17911 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
17912 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
17913 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
17914 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
17915 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
17920 /* Initialize dwarf2_cu CU, owned by PER_CU. */
17923 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
17925 memset (cu
, 0, sizeof (*cu
));
17927 cu
->per_cu
= per_cu
;
17928 cu
->objfile
= per_cu
->objfile
;
17929 obstack_init (&cu
->comp_unit_obstack
);
17932 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17935 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
17936 enum language pretend_language
)
17938 struct attribute
*attr
;
17940 /* Set the language we're debugging. */
17941 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17943 set_cu_language (DW_UNSND (attr
), cu
);
17946 cu
->language
= pretend_language
;
17947 cu
->language_defn
= language_def (cu
->language
);
17950 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17952 cu
->producer
= DW_STRING (attr
);
17955 /* Release one cached compilation unit, CU. We unlink it from the tree
17956 of compilation units, but we don't remove it from the read_in_chain;
17957 the caller is responsible for that.
17958 NOTE: DATA is a void * because this function is also used as a
17959 cleanup routine. */
17962 free_heap_comp_unit (void *data
)
17964 struct dwarf2_cu
*cu
= data
;
17966 gdb_assert (cu
->per_cu
!= NULL
);
17967 cu
->per_cu
->cu
= NULL
;
17970 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17975 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17976 when we're finished with it. We can't free the pointer itself, but be
17977 sure to unlink it from the cache. Also release any associated storage. */
17980 free_stack_comp_unit (void *data
)
17982 struct dwarf2_cu
*cu
= data
;
17984 gdb_assert (cu
->per_cu
!= NULL
);
17985 cu
->per_cu
->cu
= NULL
;
17988 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17989 cu
->partial_dies
= NULL
;
17992 /* Free all cached compilation units. */
17995 free_cached_comp_units (void *data
)
17997 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17999 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18000 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18001 while (per_cu
!= NULL
)
18003 struct dwarf2_per_cu_data
*next_cu
;
18005 next_cu
= per_cu
->cu
->read_in_chain
;
18007 free_heap_comp_unit (per_cu
->cu
);
18008 *last_chain
= next_cu
;
18014 /* Increase the age counter on each cached compilation unit, and free
18015 any that are too old. */
18018 age_cached_comp_units (void)
18020 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18022 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
18023 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18024 while (per_cu
!= NULL
)
18026 per_cu
->cu
->last_used
++;
18027 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
18028 dwarf2_mark (per_cu
->cu
);
18029 per_cu
= per_cu
->cu
->read_in_chain
;
18032 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18033 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18034 while (per_cu
!= NULL
)
18036 struct dwarf2_per_cu_data
*next_cu
;
18038 next_cu
= per_cu
->cu
->read_in_chain
;
18040 if (!per_cu
->cu
->mark
)
18042 free_heap_comp_unit (per_cu
->cu
);
18043 *last_chain
= next_cu
;
18046 last_chain
= &per_cu
->cu
->read_in_chain
;
18052 /* Remove a single compilation unit from the cache. */
18055 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
18057 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18059 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18060 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18061 while (per_cu
!= NULL
)
18063 struct dwarf2_per_cu_data
*next_cu
;
18065 next_cu
= per_cu
->cu
->read_in_chain
;
18067 if (per_cu
== target_per_cu
)
18069 free_heap_comp_unit (per_cu
->cu
);
18071 *last_chain
= next_cu
;
18075 last_chain
= &per_cu
->cu
->read_in_chain
;
18081 /* Release all extra memory associated with OBJFILE. */
18084 dwarf2_free_objfile (struct objfile
*objfile
)
18086 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18088 if (dwarf2_per_objfile
== NULL
)
18091 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
18092 free_cached_comp_units (NULL
);
18094 if (dwarf2_per_objfile
->quick_file_names_table
)
18095 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
18097 /* Everything else should be on the objfile obstack. */
18100 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
18101 We store these in a hash table separate from the DIEs, and preserve them
18102 when the DIEs are flushed out of cache.
18104 The CU "per_cu" pointer is needed because offset alone is not enough to
18105 uniquely identify the type. A file may have multiple .debug_types sections,
18106 or the type may come from a DWO file. We have to use something in
18107 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
18108 routine, get_die_type_at_offset, from outside this file, and thus won't
18109 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
18112 struct dwarf2_per_cu_offset_and_type
18114 const struct dwarf2_per_cu_data
*per_cu
;
18115 sect_offset offset
;
18119 /* Hash function for a dwarf2_per_cu_offset_and_type. */
18122 per_cu_offset_and_type_hash (const void *item
)
18124 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
18126 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
18129 /* Equality function for a dwarf2_per_cu_offset_and_type. */
18132 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
18134 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
18135 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
18137 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
18138 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
18141 /* Set the type associated with DIE to TYPE. Save it in CU's hash
18142 table if necessary. For convenience, return TYPE.
18144 The DIEs reading must have careful ordering to:
18145 * Not cause infite loops trying to read in DIEs as a prerequisite for
18146 reading current DIE.
18147 * Not trying to dereference contents of still incompletely read in types
18148 while reading in other DIEs.
18149 * Enable referencing still incompletely read in types just by a pointer to
18150 the type without accessing its fields.
18152 Therefore caller should follow these rules:
18153 * Try to fetch any prerequisite types we may need to build this DIE type
18154 before building the type and calling set_die_type.
18155 * After building type call set_die_type for current DIE as soon as
18156 possible before fetching more types to complete the current type.
18157 * Make the type as complete as possible before fetching more types. */
18159 static struct type
*
18160 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18162 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
18163 struct objfile
*objfile
= cu
->objfile
;
18165 /* For Ada types, make sure that the gnat-specific data is always
18166 initialized (if not already set). There are a few types where
18167 we should not be doing so, because the type-specific area is
18168 already used to hold some other piece of info (eg: TYPE_CODE_FLT
18169 where the type-specific area is used to store the floatformat).
18170 But this is not a problem, because the gnat-specific information
18171 is actually not needed for these types. */
18172 if (need_gnat_info (cu
)
18173 && TYPE_CODE (type
) != TYPE_CODE_FUNC
18174 && TYPE_CODE (type
) != TYPE_CODE_FLT
18175 && !HAVE_GNAT_AUX_INFO (type
))
18176 INIT_GNAT_SPECIFIC (type
);
18178 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18180 dwarf2_per_objfile
->die_type_hash
=
18181 htab_create_alloc_ex (127,
18182 per_cu_offset_and_type_hash
,
18183 per_cu_offset_and_type_eq
,
18185 &objfile
->objfile_obstack
,
18186 hashtab_obstack_allocate
,
18187 dummy_obstack_deallocate
);
18190 ofs
.per_cu
= cu
->per_cu
;
18191 ofs
.offset
= die
->offset
;
18193 slot
= (struct dwarf2_per_cu_offset_and_type
**)
18194 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
18196 complaint (&symfile_complaints
,
18197 _("A problem internal to GDB: DIE 0x%x has type already set"),
18198 die
->offset
.sect_off
);
18199 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
18204 /* Look up the type for the die at OFFSET in the appropriate type_hash
18205 table, or return NULL if the die does not have a saved type. */
18207 static struct type
*
18208 get_die_type_at_offset (sect_offset offset
,
18209 struct dwarf2_per_cu_data
*per_cu
)
18211 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
18213 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18216 ofs
.per_cu
= per_cu
;
18217 ofs
.offset
= offset
;
18218 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
18225 /* Look up the type for DIE in the appropriate type_hash table,
18226 or return NULL if DIE does not have a saved type. */
18228 static struct type
*
18229 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18231 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
18234 /* Add a dependence relationship from CU to REF_PER_CU. */
18237 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
18238 struct dwarf2_per_cu_data
*ref_per_cu
)
18242 if (cu
->dependencies
== NULL
)
18244 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
18245 NULL
, &cu
->comp_unit_obstack
,
18246 hashtab_obstack_allocate
,
18247 dummy_obstack_deallocate
);
18249 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
18251 *slot
= ref_per_cu
;
18254 /* Subroutine of dwarf2_mark to pass to htab_traverse.
18255 Set the mark field in every compilation unit in the
18256 cache that we must keep because we are keeping CU. */
18259 dwarf2_mark_helper (void **slot
, void *data
)
18261 struct dwarf2_per_cu_data
*per_cu
;
18263 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
18265 /* cu->dependencies references may not yet have been ever read if QUIT aborts
18266 reading of the chain. As such dependencies remain valid it is not much
18267 useful to track and undo them during QUIT cleanups. */
18268 if (per_cu
->cu
== NULL
)
18271 if (per_cu
->cu
->mark
)
18273 per_cu
->cu
->mark
= 1;
18275 if (per_cu
->cu
->dependencies
!= NULL
)
18276 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18281 /* Set the mark field in CU and in every other compilation unit in the
18282 cache that we must keep because we are keeping CU. */
18285 dwarf2_mark (struct dwarf2_cu
*cu
)
18290 if (cu
->dependencies
!= NULL
)
18291 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18295 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
18299 per_cu
->cu
->mark
= 0;
18300 per_cu
= per_cu
->cu
->read_in_chain
;
18304 /* Trivial hash function for partial_die_info: the hash value of a DIE
18305 is its offset in .debug_info for this objfile. */
18308 partial_die_hash (const void *item
)
18310 const struct partial_die_info
*part_die
= item
;
18312 return part_die
->offset
.sect_off
;
18315 /* Trivial comparison function for partial_die_info structures: two DIEs
18316 are equal if they have the same offset. */
18319 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
18321 const struct partial_die_info
*part_die_lhs
= item_lhs
;
18322 const struct partial_die_info
*part_die_rhs
= item_rhs
;
18324 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
18327 static struct cmd_list_element
*set_dwarf2_cmdlist
;
18328 static struct cmd_list_element
*show_dwarf2_cmdlist
;
18331 set_dwarf2_cmd (char *args
, int from_tty
)
18333 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
18337 show_dwarf2_cmd (char *args
, int from_tty
)
18339 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
18342 /* If section described by INFO was mmapped, munmap it now. */
18345 munmap_section_buffer (struct dwarf2_section_info
*info
)
18347 if (info
->map_addr
!= NULL
)
18352 res
= munmap (info
->map_addr
, info
->map_len
);
18353 gdb_assert (res
== 0);
18355 /* Without HAVE_MMAP, we should never be here to begin with. */
18356 gdb_assert_not_reached ("no mmap support");
18361 /* munmap debug sections for OBJFILE, if necessary. */
18364 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
18366 struct dwarf2_per_objfile
*data
= d
;
18368 struct dwarf2_section_info
*section
;
18370 /* This is sorted according to the order they're defined in to make it easier
18371 to keep in sync. */
18372 munmap_section_buffer (&data
->info
);
18373 munmap_section_buffer (&data
->abbrev
);
18374 munmap_section_buffer (&data
->line
);
18375 munmap_section_buffer (&data
->loc
);
18376 munmap_section_buffer (&data
->macinfo
);
18377 munmap_section_buffer (&data
->macro
);
18378 munmap_section_buffer (&data
->str
);
18379 munmap_section_buffer (&data
->ranges
);
18380 munmap_section_buffer (&data
->addr
);
18381 munmap_section_buffer (&data
->frame
);
18382 munmap_section_buffer (&data
->eh_frame
);
18383 munmap_section_buffer (&data
->gdb_index
);
18386 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
18388 munmap_section_buffer (section
);
18390 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
18391 VEC_free (dwarf2_per_cu_ptr
,
18392 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
18394 VEC_free (dwarf2_section_info_def
, data
->types
);
18396 if (data
->dwo_files
)
18397 free_dwo_files (data
->dwo_files
, objfile
);
18401 /* The "save gdb-index" command. */
18403 /* The contents of the hash table we create when building the string
18405 struct strtab_entry
18407 offset_type offset
;
18411 /* Hash function for a strtab_entry.
18413 Function is used only during write_hash_table so no index format backward
18414 compatibility is needed. */
18417 hash_strtab_entry (const void *e
)
18419 const struct strtab_entry
*entry
= e
;
18420 return mapped_index_string_hash (INT_MAX
, entry
->str
);
18423 /* Equality function for a strtab_entry. */
18426 eq_strtab_entry (const void *a
, const void *b
)
18428 const struct strtab_entry
*ea
= a
;
18429 const struct strtab_entry
*eb
= b
;
18430 return !strcmp (ea
->str
, eb
->str
);
18433 /* Create a strtab_entry hash table. */
18436 create_strtab (void)
18438 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
18439 xfree
, xcalloc
, xfree
);
18442 /* Add a string to the constant pool. Return the string's offset in
18446 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
18449 struct strtab_entry entry
;
18450 struct strtab_entry
*result
;
18453 slot
= htab_find_slot (table
, &entry
, INSERT
);
18458 result
= XNEW (struct strtab_entry
);
18459 result
->offset
= obstack_object_size (cpool
);
18461 obstack_grow_str0 (cpool
, str
);
18464 return result
->offset
;
18467 /* An entry in the symbol table. */
18468 struct symtab_index_entry
18470 /* The name of the symbol. */
18472 /* The offset of the name in the constant pool. */
18473 offset_type index_offset
;
18474 /* A sorted vector of the indices of all the CUs that hold an object
18476 VEC (offset_type
) *cu_indices
;
18479 /* The symbol table. This is a power-of-2-sized hash table. */
18480 struct mapped_symtab
18482 offset_type n_elements
;
18484 struct symtab_index_entry
**data
;
18487 /* Hash function for a symtab_index_entry. */
18490 hash_symtab_entry (const void *e
)
18492 const struct symtab_index_entry
*entry
= e
;
18493 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
18494 sizeof (offset_type
) * VEC_length (offset_type
,
18495 entry
->cu_indices
),
18499 /* Equality function for a symtab_index_entry. */
18502 eq_symtab_entry (const void *a
, const void *b
)
18504 const struct symtab_index_entry
*ea
= a
;
18505 const struct symtab_index_entry
*eb
= b
;
18506 int len
= VEC_length (offset_type
, ea
->cu_indices
);
18507 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
18509 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
18510 VEC_address (offset_type
, eb
->cu_indices
),
18511 sizeof (offset_type
) * len
);
18514 /* Destroy a symtab_index_entry. */
18517 delete_symtab_entry (void *p
)
18519 struct symtab_index_entry
*entry
= p
;
18520 VEC_free (offset_type
, entry
->cu_indices
);
18524 /* Create a hash table holding symtab_index_entry objects. */
18527 create_symbol_hash_table (void)
18529 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
18530 delete_symtab_entry
, xcalloc
, xfree
);
18533 /* Create a new mapped symtab object. */
18535 static struct mapped_symtab
*
18536 create_mapped_symtab (void)
18538 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
18539 symtab
->n_elements
= 0;
18540 symtab
->size
= 1024;
18541 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18545 /* Destroy a mapped_symtab. */
18548 cleanup_mapped_symtab (void *p
)
18550 struct mapped_symtab
*symtab
= p
;
18551 /* The contents of the array are freed when the other hash table is
18553 xfree (symtab
->data
);
18557 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
18560 Function is used only during write_hash_table so no index format backward
18561 compatibility is needed. */
18563 static struct symtab_index_entry
**
18564 find_slot (struct mapped_symtab
*symtab
, const char *name
)
18566 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
18568 index
= hash
& (symtab
->size
- 1);
18569 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
18573 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
18574 return &symtab
->data
[index
];
18575 index
= (index
+ step
) & (symtab
->size
- 1);
18579 /* Expand SYMTAB's hash table. */
18582 hash_expand (struct mapped_symtab
*symtab
)
18584 offset_type old_size
= symtab
->size
;
18586 struct symtab_index_entry
**old_entries
= symtab
->data
;
18589 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18591 for (i
= 0; i
< old_size
; ++i
)
18593 if (old_entries
[i
])
18595 struct symtab_index_entry
**slot
= find_slot (symtab
,
18596 old_entries
[i
]->name
);
18597 *slot
= old_entries
[i
];
18601 xfree (old_entries
);
18604 /* Add an entry to SYMTAB. NAME is the name of the symbol.
18605 CU_INDEX is the index of the CU in which the symbol appears.
18606 IS_STATIC is one if the symbol is static, otherwise zero (global). */
18609 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
18610 int is_static
, gdb_index_symbol_kind kind
,
18611 offset_type cu_index
)
18613 struct symtab_index_entry
**slot
;
18614 offset_type cu_index_and_attrs
;
18616 ++symtab
->n_elements
;
18617 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
18618 hash_expand (symtab
);
18620 slot
= find_slot (symtab
, name
);
18623 *slot
= XNEW (struct symtab_index_entry
);
18624 (*slot
)->name
= name
;
18625 /* index_offset is set later. */
18626 (*slot
)->cu_indices
= NULL
;
18629 cu_index_and_attrs
= 0;
18630 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
18631 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
18632 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
18634 /* We don't want to record an index value twice as we want to avoid the
18636 We process all global symbols and then all static symbols
18637 (which would allow us to avoid the duplication by only having to check
18638 the last entry pushed), but a symbol could have multiple kinds in one CU.
18639 To keep things simple we don't worry about the duplication here and
18640 sort and uniqufy the list after we've processed all symbols. */
18641 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
18644 /* qsort helper routine for uniquify_cu_indices. */
18647 offset_type_compare (const void *ap
, const void *bp
)
18649 offset_type a
= *(offset_type
*) ap
;
18650 offset_type b
= *(offset_type
*) bp
;
18652 return (a
> b
) - (b
> a
);
18655 /* Sort and remove duplicates of all symbols' cu_indices lists. */
18658 uniquify_cu_indices (struct mapped_symtab
*symtab
)
18662 for (i
= 0; i
< symtab
->size
; ++i
)
18664 struct symtab_index_entry
*entry
= symtab
->data
[i
];
18667 && entry
->cu_indices
!= NULL
)
18669 unsigned int next_to_insert
, next_to_check
;
18670 offset_type last_value
;
18672 qsort (VEC_address (offset_type
, entry
->cu_indices
),
18673 VEC_length (offset_type
, entry
->cu_indices
),
18674 sizeof (offset_type
), offset_type_compare
);
18676 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
18677 next_to_insert
= 1;
18678 for (next_to_check
= 1;
18679 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
18682 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
18685 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
18687 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
18692 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
18697 /* Add a vector of indices to the constant pool. */
18700 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
18701 struct symtab_index_entry
*entry
)
18705 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
18708 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
18709 offset_type val
= MAYBE_SWAP (len
);
18714 entry
->index_offset
= obstack_object_size (cpool
);
18716 obstack_grow (cpool
, &val
, sizeof (val
));
18718 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
18721 val
= MAYBE_SWAP (iter
);
18722 obstack_grow (cpool
, &val
, sizeof (val
));
18727 struct symtab_index_entry
*old_entry
= *slot
;
18728 entry
->index_offset
= old_entry
->index_offset
;
18731 return entry
->index_offset
;
18734 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
18735 constant pool entries going into the obstack CPOOL. */
18738 write_hash_table (struct mapped_symtab
*symtab
,
18739 struct obstack
*output
, struct obstack
*cpool
)
18742 htab_t symbol_hash_table
;
18745 symbol_hash_table
= create_symbol_hash_table ();
18746 str_table
= create_strtab ();
18748 /* We add all the index vectors to the constant pool first, to
18749 ensure alignment is ok. */
18750 for (i
= 0; i
< symtab
->size
; ++i
)
18752 if (symtab
->data
[i
])
18753 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
18756 /* Now write out the hash table. */
18757 for (i
= 0; i
< symtab
->size
; ++i
)
18759 offset_type str_off
, vec_off
;
18761 if (symtab
->data
[i
])
18763 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
18764 vec_off
= symtab
->data
[i
]->index_offset
;
18768 /* While 0 is a valid constant pool index, it is not valid
18769 to have 0 for both offsets. */
18774 str_off
= MAYBE_SWAP (str_off
);
18775 vec_off
= MAYBE_SWAP (vec_off
);
18777 obstack_grow (output
, &str_off
, sizeof (str_off
));
18778 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
18781 htab_delete (str_table
);
18782 htab_delete (symbol_hash_table
);
18785 /* Struct to map psymtab to CU index in the index file. */
18786 struct psymtab_cu_index_map
18788 struct partial_symtab
*psymtab
;
18789 unsigned int cu_index
;
18793 hash_psymtab_cu_index (const void *item
)
18795 const struct psymtab_cu_index_map
*map
= item
;
18797 return htab_hash_pointer (map
->psymtab
);
18801 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
18803 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
18804 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
18806 return lhs
->psymtab
== rhs
->psymtab
;
18809 /* Helper struct for building the address table. */
18810 struct addrmap_index_data
18812 struct objfile
*objfile
;
18813 struct obstack
*addr_obstack
;
18814 htab_t cu_index_htab
;
18816 /* Non-zero if the previous_* fields are valid.
18817 We can't write an entry until we see the next entry (since it is only then
18818 that we know the end of the entry). */
18819 int previous_valid
;
18820 /* Index of the CU in the table of all CUs in the index file. */
18821 unsigned int previous_cu_index
;
18822 /* Start address of the CU. */
18823 CORE_ADDR previous_cu_start
;
18826 /* Write an address entry to OBSTACK. */
18829 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
18830 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
18832 offset_type cu_index_to_write
;
18834 CORE_ADDR baseaddr
;
18836 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18838 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
18839 obstack_grow (obstack
, addr
, 8);
18840 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
18841 obstack_grow (obstack
, addr
, 8);
18842 cu_index_to_write
= MAYBE_SWAP (cu_index
);
18843 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
18846 /* Worker function for traversing an addrmap to build the address table. */
18849 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
18851 struct addrmap_index_data
*data
= datap
;
18852 struct partial_symtab
*pst
= obj
;
18854 if (data
->previous_valid
)
18855 add_address_entry (data
->objfile
, data
->addr_obstack
,
18856 data
->previous_cu_start
, start_addr
,
18857 data
->previous_cu_index
);
18859 data
->previous_cu_start
= start_addr
;
18862 struct psymtab_cu_index_map find_map
, *map
;
18863 find_map
.psymtab
= pst
;
18864 map
= htab_find (data
->cu_index_htab
, &find_map
);
18865 gdb_assert (map
!= NULL
);
18866 data
->previous_cu_index
= map
->cu_index
;
18867 data
->previous_valid
= 1;
18870 data
->previous_valid
= 0;
18875 /* Write OBJFILE's address map to OBSTACK.
18876 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
18877 in the index file. */
18880 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
18881 htab_t cu_index_htab
)
18883 struct addrmap_index_data addrmap_index_data
;
18885 /* When writing the address table, we have to cope with the fact that
18886 the addrmap iterator only provides the start of a region; we have to
18887 wait until the next invocation to get the start of the next region. */
18889 addrmap_index_data
.objfile
= objfile
;
18890 addrmap_index_data
.addr_obstack
= obstack
;
18891 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
18892 addrmap_index_data
.previous_valid
= 0;
18894 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
18895 &addrmap_index_data
);
18897 /* It's highly unlikely the last entry (end address = 0xff...ff)
18898 is valid, but we should still handle it.
18899 The end address is recorded as the start of the next region, but that
18900 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
18902 if (addrmap_index_data
.previous_valid
)
18903 add_address_entry (objfile
, obstack
,
18904 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
18905 addrmap_index_data
.previous_cu_index
);
18908 /* Return the symbol kind of PSYM. */
18910 static gdb_index_symbol_kind
18911 symbol_kind (struct partial_symbol
*psym
)
18913 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
18914 enum address_class aclass
= PSYMBOL_CLASS (psym
);
18922 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
18924 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18926 case LOC_CONST_BYTES
:
18927 case LOC_OPTIMIZED_OUT
:
18929 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18931 /* Note: It's currently impossible to recognize psyms as enum values
18932 short of reading the type info. For now punt. */
18933 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18935 /* There are other LOC_FOO values that one might want to classify
18936 as variables, but dwarf2read.c doesn't currently use them. */
18937 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18939 case STRUCT_DOMAIN
:
18940 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18942 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18946 /* Add a list of partial symbols to SYMTAB. */
18949 write_psymbols (struct mapped_symtab
*symtab
,
18951 struct partial_symbol
**psymp
,
18953 offset_type cu_index
,
18956 for (; count
-- > 0; ++psymp
)
18958 struct partial_symbol
*psym
= *psymp
;
18961 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
18962 error (_("Ada is not currently supported by the index"));
18964 /* Only add a given psymbol once. */
18965 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
18968 gdb_index_symbol_kind kind
= symbol_kind (psym
);
18971 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
18972 is_static
, kind
, cu_index
);
18977 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18978 exception if there is an error. */
18981 write_obstack (FILE *file
, struct obstack
*obstack
)
18983 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18985 != obstack_object_size (obstack
))
18986 error (_("couldn't data write to file"));
18989 /* Unlink a file if the argument is not NULL. */
18992 unlink_if_set (void *p
)
18994 char **filename
= p
;
18996 unlink (*filename
);
18999 /* A helper struct used when iterating over debug_types. */
19000 struct signatured_type_index_data
19002 struct objfile
*objfile
;
19003 struct mapped_symtab
*symtab
;
19004 struct obstack
*types_list
;
19009 /* A helper function that writes a single signatured_type to an
19013 write_one_signatured_type (void **slot
, void *d
)
19015 struct signatured_type_index_data
*info
= d
;
19016 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
19017 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
19018 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19021 write_psymbols (info
->symtab
,
19023 info
->objfile
->global_psymbols
.list
19024 + psymtab
->globals_offset
,
19025 psymtab
->n_global_syms
, info
->cu_index
,
19027 write_psymbols (info
->symtab
,
19029 info
->objfile
->static_psymbols
.list
19030 + psymtab
->statics_offset
,
19031 psymtab
->n_static_syms
, info
->cu_index
,
19034 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19035 entry
->per_cu
.offset
.sect_off
);
19036 obstack_grow (info
->types_list
, val
, 8);
19037 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19038 entry
->type_offset_in_tu
.cu_off
);
19039 obstack_grow (info
->types_list
, val
, 8);
19040 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
19041 obstack_grow (info
->types_list
, val
, 8);
19048 /* Recurse into all "included" dependencies and write their symbols as
19049 if they appeared in this psymtab. */
19052 recursively_write_psymbols (struct objfile
*objfile
,
19053 struct partial_symtab
*psymtab
,
19054 struct mapped_symtab
*symtab
,
19056 offset_type cu_index
)
19060 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
19061 if (psymtab
->dependencies
[i
]->user
!= NULL
)
19062 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
19063 symtab
, psyms_seen
, cu_index
);
19065 write_psymbols (symtab
,
19067 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
19068 psymtab
->n_global_syms
, cu_index
,
19070 write_psymbols (symtab
,
19072 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
19073 psymtab
->n_static_syms
, cu_index
,
19077 /* Create an index file for OBJFILE in the directory DIR. */
19080 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
19082 struct cleanup
*cleanup
;
19083 char *filename
, *cleanup_filename
;
19084 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
19085 struct obstack cu_list
, types_cu_list
;
19088 struct mapped_symtab
*symtab
;
19089 offset_type val
, size_of_contents
, total_len
;
19092 htab_t cu_index_htab
;
19093 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
19095 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
19098 if (dwarf2_per_objfile
->using_index
)
19099 error (_("Cannot use an index to create the index"));
19101 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
19102 error (_("Cannot make an index when the file has multiple .debug_types sections"));
19104 if (stat (objfile
->name
, &st
) < 0)
19105 perror_with_name (objfile
->name
);
19107 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
19108 INDEX_SUFFIX
, (char *) NULL
);
19109 cleanup
= make_cleanup (xfree
, filename
);
19111 out_file
= fopen (filename
, "wb");
19113 error (_("Can't open `%s' for writing"), filename
);
19115 cleanup_filename
= filename
;
19116 make_cleanup (unlink_if_set
, &cleanup_filename
);
19118 symtab
= create_mapped_symtab ();
19119 make_cleanup (cleanup_mapped_symtab
, symtab
);
19121 obstack_init (&addr_obstack
);
19122 make_cleanup_obstack_free (&addr_obstack
);
19124 obstack_init (&cu_list
);
19125 make_cleanup_obstack_free (&cu_list
);
19127 obstack_init (&types_cu_list
);
19128 make_cleanup_obstack_free (&types_cu_list
);
19130 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
19131 NULL
, xcalloc
, xfree
);
19132 make_cleanup_htab_delete (psyms_seen
);
19134 /* While we're scanning CU's create a table that maps a psymtab pointer
19135 (which is what addrmap records) to its index (which is what is recorded
19136 in the index file). This will later be needed to write the address
19138 cu_index_htab
= htab_create_alloc (100,
19139 hash_psymtab_cu_index
,
19140 eq_psymtab_cu_index
,
19141 NULL
, xcalloc
, xfree
);
19142 make_cleanup_htab_delete (cu_index_htab
);
19143 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
19144 xmalloc (sizeof (struct psymtab_cu_index_map
)
19145 * dwarf2_per_objfile
->n_comp_units
);
19146 make_cleanup (xfree
, psymtab_cu_index_map
);
19148 /* The CU list is already sorted, so we don't need to do additional
19149 work here. Also, the debug_types entries do not appear in
19150 all_comp_units, but only in their own hash table. */
19151 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
19153 struct dwarf2_per_cu_data
*per_cu
19154 = dwarf2_per_objfile
->all_comp_units
[i
];
19155 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19157 struct psymtab_cu_index_map
*map
;
19160 if (psymtab
->user
== NULL
)
19161 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
19163 map
= &psymtab_cu_index_map
[i
];
19164 map
->psymtab
= psymtab
;
19166 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
19167 gdb_assert (slot
!= NULL
);
19168 gdb_assert (*slot
== NULL
);
19171 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19172 per_cu
->offset
.sect_off
);
19173 obstack_grow (&cu_list
, val
, 8);
19174 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
19175 obstack_grow (&cu_list
, val
, 8);
19178 /* Dump the address map. */
19179 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
19181 /* Write out the .debug_type entries, if any. */
19182 if (dwarf2_per_objfile
->signatured_types
)
19184 struct signatured_type_index_data sig_data
;
19186 sig_data
.objfile
= objfile
;
19187 sig_data
.symtab
= symtab
;
19188 sig_data
.types_list
= &types_cu_list
;
19189 sig_data
.psyms_seen
= psyms_seen
;
19190 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
19191 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
19192 write_one_signatured_type
, &sig_data
);
19195 /* Now that we've processed all symbols we can shrink their cu_indices
19197 uniquify_cu_indices (symtab
);
19199 obstack_init (&constant_pool
);
19200 make_cleanup_obstack_free (&constant_pool
);
19201 obstack_init (&symtab_obstack
);
19202 make_cleanup_obstack_free (&symtab_obstack
);
19203 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
19205 obstack_init (&contents
);
19206 make_cleanup_obstack_free (&contents
);
19207 size_of_contents
= 6 * sizeof (offset_type
);
19208 total_len
= size_of_contents
;
19210 /* The version number. */
19211 val
= MAYBE_SWAP (7);
19212 obstack_grow (&contents
, &val
, sizeof (val
));
19214 /* The offset of the CU list from the start of the file. */
19215 val
= MAYBE_SWAP (total_len
);
19216 obstack_grow (&contents
, &val
, sizeof (val
));
19217 total_len
+= obstack_object_size (&cu_list
);
19219 /* The offset of the types CU list from the start of the file. */
19220 val
= MAYBE_SWAP (total_len
);
19221 obstack_grow (&contents
, &val
, sizeof (val
));
19222 total_len
+= obstack_object_size (&types_cu_list
);
19224 /* The offset of the address table from the start of the file. */
19225 val
= MAYBE_SWAP (total_len
);
19226 obstack_grow (&contents
, &val
, sizeof (val
));
19227 total_len
+= obstack_object_size (&addr_obstack
);
19229 /* The offset of the symbol table from the start of the file. */
19230 val
= MAYBE_SWAP (total_len
);
19231 obstack_grow (&contents
, &val
, sizeof (val
));
19232 total_len
+= obstack_object_size (&symtab_obstack
);
19234 /* The offset of the constant pool from the start of the file. */
19235 val
= MAYBE_SWAP (total_len
);
19236 obstack_grow (&contents
, &val
, sizeof (val
));
19237 total_len
+= obstack_object_size (&constant_pool
);
19239 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
19241 write_obstack (out_file
, &contents
);
19242 write_obstack (out_file
, &cu_list
);
19243 write_obstack (out_file
, &types_cu_list
);
19244 write_obstack (out_file
, &addr_obstack
);
19245 write_obstack (out_file
, &symtab_obstack
);
19246 write_obstack (out_file
, &constant_pool
);
19250 /* We want to keep the file, so we set cleanup_filename to NULL
19251 here. See unlink_if_set. */
19252 cleanup_filename
= NULL
;
19254 do_cleanups (cleanup
);
19257 /* Implementation of the `save gdb-index' command.
19259 Note that the file format used by this command is documented in the
19260 GDB manual. Any changes here must be documented there. */
19263 save_gdb_index_command (char *arg
, int from_tty
)
19265 struct objfile
*objfile
;
19268 error (_("usage: save gdb-index DIRECTORY"));
19270 ALL_OBJFILES (objfile
)
19274 /* If the objfile does not correspond to an actual file, skip it. */
19275 if (stat (objfile
->name
, &st
) < 0)
19278 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19279 if (dwarf2_per_objfile
)
19281 volatile struct gdb_exception except
;
19283 TRY_CATCH (except
, RETURN_MASK_ERROR
)
19285 write_psymtabs_to_index (objfile
, arg
);
19287 if (except
.reason
< 0)
19288 exception_fprintf (gdb_stderr
, except
,
19289 _("Error while writing index for `%s': "),
19297 int dwarf2_always_disassemble
;
19300 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
19301 struct cmd_list_element
*c
, const char *value
)
19303 fprintf_filtered (file
,
19304 _("Whether to always disassemble "
19305 "DWARF expressions is %s.\n"),
19310 show_check_physname (struct ui_file
*file
, int from_tty
,
19311 struct cmd_list_element
*c
, const char *value
)
19313 fprintf_filtered (file
,
19314 _("Whether to check \"physname\" is %s.\n"),
19318 void _initialize_dwarf2_read (void);
19321 _initialize_dwarf2_read (void)
19323 struct cmd_list_element
*c
;
19325 dwarf2_objfile_data_key
19326 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
19328 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
19329 Set DWARF 2 specific variables.\n\
19330 Configure DWARF 2 variables such as the cache size"),
19331 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
19332 0/*allow-unknown*/, &maintenance_set_cmdlist
);
19334 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
19335 Show DWARF 2 specific variables\n\
19336 Show DWARF 2 variables such as the cache size"),
19337 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
19338 0/*allow-unknown*/, &maintenance_show_cmdlist
);
19340 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
19341 &dwarf2_max_cache_age
, _("\
19342 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
19343 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
19344 A higher limit means that cached compilation units will be stored\n\
19345 in memory longer, and more total memory will be used. Zero disables\n\
19346 caching, which can slow down startup."),
19348 show_dwarf2_max_cache_age
,
19349 &set_dwarf2_cmdlist
,
19350 &show_dwarf2_cmdlist
);
19352 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
19353 &dwarf2_always_disassemble
, _("\
19354 Set whether `info address' always disassembles DWARF expressions."), _("\
19355 Show whether `info address' always disassembles DWARF expressions."), _("\
19356 When enabled, DWARF expressions are always printed in an assembly-like\n\
19357 syntax. When disabled, expressions will be printed in a more\n\
19358 conversational style, when possible."),
19360 show_dwarf2_always_disassemble
,
19361 &set_dwarf2_cmdlist
,
19362 &show_dwarf2_cmdlist
);
19364 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
19365 Set debugging of the dwarf2 reader."), _("\
19366 Show debugging of the dwarf2 reader."), _("\
19367 When enabled, debugging messages are printed during dwarf2 reading\n\
19368 and symtab expansion."),
19371 &setdebuglist
, &showdebuglist
);
19373 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
19374 Set debugging of the dwarf2 DIE reader."), _("\
19375 Show debugging of the dwarf2 DIE reader."), _("\
19376 When enabled (non-zero), DIEs are dumped after they are read in.\n\
19377 The value is the maximum depth to print."),
19380 &setdebuglist
, &showdebuglist
);
19382 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
19383 Set cross-checking of \"physname\" code against demangler."), _("\
19384 Show cross-checking of \"physname\" code against demangler."), _("\
19385 When enabled, GDB's internal \"physname\" code is checked against\n\
19387 NULL
, show_check_physname
,
19388 &setdebuglist
, &showdebuglist
);
19390 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
19392 Save a gdb-index file.\n\
19393 Usage: save gdb-index DIRECTORY"),
19395 set_cmd_completer (c
, filename_completer
);