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"
70 #include "gdb_string.h"
71 #include "gdb_assert.h"
72 #include <sys/types.h>
74 typedef struct symbol
*symbolp
;
77 /* When non-zero, print basic high level tracing messages.
78 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
79 static int dwarf2_read_debug
= 0;
81 /* When non-zero, dump DIEs after they are read in. */
82 static int dwarf2_die_debug
= 0;
84 /* When non-zero, cross-check physname against demangler. */
85 static int check_physname
= 0;
87 /* When non-zero, do not reject deprecated .gdb_index sections. */
88 int use_deprecated_index_sections
= 0;
90 /* When set, the file that we're processing is known to have debugging
91 info for C++ namespaces. GCC 3.3.x did not produce this information,
92 but later versions do. */
94 static int processing_has_namespace_info
;
96 static const struct objfile_data
*dwarf2_objfile_data_key
;
98 struct dwarf2_section_info
103 /* True if we have tried to read this section. */
107 typedef struct dwarf2_section_info dwarf2_section_info_def
;
108 DEF_VEC_O (dwarf2_section_info_def
);
110 /* All offsets in the index are of this type. It must be
111 architecture-independent. */
112 typedef uint32_t offset_type
;
114 DEF_VEC_I (offset_type
);
116 /* Ensure only legit values are used. */
117 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
119 gdb_assert ((unsigned int) (value) <= 1); \
120 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
123 /* Ensure only legit values are used. */
124 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
126 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
127 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
128 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
131 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
132 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
134 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
135 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
138 /* A description of the mapped index. The file format is described in
139 a comment by the code that writes the index. */
142 /* Index data format version. */
145 /* The total length of the buffer. */
148 /* A pointer to the address table data. */
149 const gdb_byte
*address_table
;
151 /* Size of the address table data in bytes. */
152 offset_type address_table_size
;
154 /* The symbol table, implemented as a hash table. */
155 const offset_type
*symbol_table
;
157 /* Size in slots, each slot is 2 offset_types. */
158 offset_type symbol_table_slots
;
160 /* A pointer to the constant pool. */
161 const char *constant_pool
;
164 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
165 DEF_VEC_P (dwarf2_per_cu_ptr
);
167 /* Collection of data recorded per objfile.
168 This hangs off of dwarf2_objfile_data_key. */
170 struct dwarf2_per_objfile
172 struct dwarf2_section_info info
;
173 struct dwarf2_section_info abbrev
;
174 struct dwarf2_section_info line
;
175 struct dwarf2_section_info loc
;
176 struct dwarf2_section_info macinfo
;
177 struct dwarf2_section_info macro
;
178 struct dwarf2_section_info str
;
179 struct dwarf2_section_info ranges
;
180 struct dwarf2_section_info addr
;
181 struct dwarf2_section_info frame
;
182 struct dwarf2_section_info eh_frame
;
183 struct dwarf2_section_info gdb_index
;
185 VEC (dwarf2_section_info_def
) *types
;
188 struct objfile
*objfile
;
190 /* Table of all the compilation units. This is used to locate
191 the target compilation unit of a particular reference. */
192 struct dwarf2_per_cu_data
**all_comp_units
;
194 /* The number of compilation units in ALL_COMP_UNITS. */
197 /* The number of .debug_types-related CUs. */
200 /* The .debug_types-related CUs (TUs). */
201 struct signatured_type
**all_type_units
;
203 /* The number of entries in all_type_unit_groups. */
204 int n_type_unit_groups
;
206 /* Table of type unit groups.
207 This exists to make it easy to iterate over all CUs and TU groups. */
208 struct type_unit_group
**all_type_unit_groups
;
210 /* Table of struct type_unit_group objects.
211 The hash key is the DW_AT_stmt_list value. */
212 htab_t type_unit_groups
;
214 /* A table mapping .debug_types signatures to its signatured_type entry.
215 This is NULL if the .debug_types section hasn't been read in yet. */
216 htab_t signatured_types
;
218 /* Type unit statistics, to see how well the scaling improvements
222 int nr_uniq_abbrev_tables
;
224 int nr_symtab_sharers
;
225 int nr_stmt_less_type_units
;
228 /* A chain of compilation units that are currently read in, so that
229 they can be freed later. */
230 struct dwarf2_per_cu_data
*read_in_chain
;
232 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
233 This is NULL if the table hasn't been allocated yet. */
236 /* A flag indicating wether this objfile has a section loaded at a
238 int has_section_at_zero
;
240 /* True if we are using the mapped index,
241 or we are faking it for OBJF_READNOW's sake. */
242 unsigned char using_index
;
244 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
245 struct mapped_index
*index_table
;
247 /* When using index_table, this keeps track of all quick_file_names entries.
248 TUs can share line table entries with CUs or other TUs, and there can be
249 a lot more TUs than unique line tables, so we maintain a separate table
250 of all line table entries to support the sharing. */
251 htab_t quick_file_names_table
;
253 /* Set during partial symbol reading, to prevent queueing of full
255 int reading_partial_symbols
;
257 /* Table mapping type DIEs to their struct type *.
258 This is NULL if not allocated yet.
259 The mapping is done via (CU/TU signature + DIE offset) -> type. */
260 htab_t die_type_hash
;
262 /* The CUs we recently read. */
263 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
266 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
268 /* Default names of the debugging sections. */
270 /* Note that if the debugging section has been compressed, it might
271 have a name like .zdebug_info. */
273 static const struct dwarf2_debug_sections dwarf2_elf_names
=
275 { ".debug_info", ".zdebug_info" },
276 { ".debug_abbrev", ".zdebug_abbrev" },
277 { ".debug_line", ".zdebug_line" },
278 { ".debug_loc", ".zdebug_loc" },
279 { ".debug_macinfo", ".zdebug_macinfo" },
280 { ".debug_macro", ".zdebug_macro" },
281 { ".debug_str", ".zdebug_str" },
282 { ".debug_ranges", ".zdebug_ranges" },
283 { ".debug_types", ".zdebug_types" },
284 { ".debug_addr", ".zdebug_addr" },
285 { ".debug_frame", ".zdebug_frame" },
286 { ".eh_frame", NULL
},
287 { ".gdb_index", ".zgdb_index" },
291 /* List of DWO sections. */
293 static const struct dwo_section_names
295 struct dwarf2_section_names abbrev_dwo
;
296 struct dwarf2_section_names info_dwo
;
297 struct dwarf2_section_names line_dwo
;
298 struct dwarf2_section_names loc_dwo
;
299 struct dwarf2_section_names macinfo_dwo
;
300 struct dwarf2_section_names macro_dwo
;
301 struct dwarf2_section_names str_dwo
;
302 struct dwarf2_section_names str_offsets_dwo
;
303 struct dwarf2_section_names types_dwo
;
307 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
308 { ".debug_info.dwo", ".zdebug_info.dwo" },
309 { ".debug_line.dwo", ".zdebug_line.dwo" },
310 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
311 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
312 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
313 { ".debug_str.dwo", ".zdebug_str.dwo" },
314 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
315 { ".debug_types.dwo", ".zdebug_types.dwo" },
318 /* local data types */
320 /* The data in a compilation unit header, after target2host
321 translation, looks like this. */
322 struct comp_unit_head
326 unsigned char addr_size
;
327 unsigned char signed_addr_p
;
328 sect_offset abbrev_offset
;
330 /* Size of file offsets; either 4 or 8. */
331 unsigned int offset_size
;
333 /* Size of the length field; either 4 or 12. */
334 unsigned int initial_length_size
;
336 /* Offset to the first byte of this compilation unit header in the
337 .debug_info section, for resolving relative reference dies. */
340 /* Offset to first die in this cu from the start of the cu.
341 This will be the first byte following the compilation unit header. */
342 cu_offset first_die_offset
;
345 /* Type used for delaying computation of method physnames.
346 See comments for compute_delayed_physnames. */
347 struct delayed_method_info
349 /* The type to which the method is attached, i.e., its parent class. */
352 /* The index of the method in the type's function fieldlists. */
355 /* The index of the method in the fieldlist. */
358 /* The name of the DIE. */
361 /* The DIE associated with this method. */
362 struct die_info
*die
;
365 typedef struct delayed_method_info delayed_method_info
;
366 DEF_VEC_O (delayed_method_info
);
368 /* Internal state when decoding a particular compilation unit. */
371 /* The objfile containing this compilation unit. */
372 struct objfile
*objfile
;
374 /* The header of the compilation unit. */
375 struct comp_unit_head header
;
377 /* Base address of this compilation unit. */
378 CORE_ADDR base_address
;
380 /* Non-zero if base_address has been set. */
383 /* The language we are debugging. */
384 enum language language
;
385 const struct language_defn
*language_defn
;
387 const char *producer
;
389 /* The generic symbol table building routines have separate lists for
390 file scope symbols and all all other scopes (local scopes). So
391 we need to select the right one to pass to add_symbol_to_list().
392 We do it by keeping a pointer to the correct list in list_in_scope.
394 FIXME: The original dwarf code just treated the file scope as the
395 first local scope, and all other local scopes as nested local
396 scopes, and worked fine. Check to see if we really need to
397 distinguish these in buildsym.c. */
398 struct pending
**list_in_scope
;
400 /* The abbrev table for this CU.
401 Normally this points to the abbrev table in the objfile.
402 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
403 struct abbrev_table
*abbrev_table
;
405 /* Hash table holding all the loaded partial DIEs
406 with partial_die->offset.SECT_OFF as hash. */
409 /* Storage for things with the same lifetime as this read-in compilation
410 unit, including partial DIEs. */
411 struct obstack comp_unit_obstack
;
413 /* When multiple dwarf2_cu structures are living in memory, this field
414 chains them all together, so that they can be released efficiently.
415 We will probably also want a generation counter so that most-recently-used
416 compilation units are cached... */
417 struct dwarf2_per_cu_data
*read_in_chain
;
419 /* Backchain to our per_cu entry if the tree has been built. */
420 struct dwarf2_per_cu_data
*per_cu
;
422 /* How many compilation units ago was this CU last referenced? */
425 /* A hash table of DIE cu_offset for following references with
426 die_info->offset.sect_off as hash. */
429 /* Full DIEs if read in. */
430 struct die_info
*dies
;
432 /* A set of pointers to dwarf2_per_cu_data objects for compilation
433 units referenced by this one. Only set during full symbol processing;
434 partial symbol tables do not have dependencies. */
437 /* Header data from the line table, during full symbol processing. */
438 struct line_header
*line_header
;
440 /* A list of methods which need to have physnames computed
441 after all type information has been read. */
442 VEC (delayed_method_info
) *method_list
;
444 /* To be copied to symtab->call_site_htab. */
445 htab_t call_site_htab
;
447 /* Non-NULL if this CU came from a DWO file.
448 There is an invariant here that is important to remember:
449 Except for attributes copied from the top level DIE in the "main"
450 (or "stub") file in preparation for reading the DWO file
451 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
452 Either there isn't a DWO file (in which case this is NULL and the point
453 is moot), or there is and either we're not going to read it (in which
454 case this is NULL) or there is and we are reading it (in which case this
456 struct dwo_unit
*dwo_unit
;
458 /* The DW_AT_addr_base attribute if present, zero otherwise
459 (zero is a valid value though).
460 Note this value comes from the stub CU/TU's DIE. */
463 /* The DW_AT_ranges_base attribute if present, zero otherwise
464 (zero is a valid value though).
465 Note this value comes from the stub CU/TU's DIE.
466 Also note that the value is zero in the non-DWO case so this value can
467 be used without needing to know whether DWO files are in use or not. */
468 ULONGEST ranges_base
;
470 /* Mark used when releasing cached dies. */
471 unsigned int mark
: 1;
473 /* This CU references .debug_loc. See the symtab->locations_valid field.
474 This test is imperfect as there may exist optimized debug code not using
475 any location list and still facing inlining issues if handled as
476 unoptimized code. For a future better test see GCC PR other/32998. */
477 unsigned int has_loclist
: 1;
479 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
480 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
481 are valid. This information is cached because profiling CU expansion
482 showed excessive time spent in producer_is_gxx_lt_4_6. */
483 unsigned int checked_producer
: 1;
484 unsigned int producer_is_gxx_lt_4_6
: 1;
485 unsigned int producer_is_icc
: 1;
488 /* Persistent data held for a compilation unit, even when not
489 processing it. We put a pointer to this structure in the
490 read_symtab_private field of the psymtab. */
492 struct dwarf2_per_cu_data
494 /* The start offset and length of this compilation unit. 2**29-1
495 bytes should suffice to store the length of any compilation unit
496 - if it doesn't, GDB will fall over anyway.
497 NOTE: Unlike comp_unit_head.length, this length includes
499 If the DIE refers to a DWO file, this is always of the original die,
502 unsigned int length
: 29;
504 /* Flag indicating this compilation unit will be read in before
505 any of the current compilation units are processed. */
506 unsigned int queued
: 1;
508 /* This flag will be set when reading partial DIEs if we need to load
509 absolutely all DIEs for this compilation unit, instead of just the ones
510 we think are interesting. It gets set if we look for a DIE in the
511 hash table and don't find it. */
512 unsigned int load_all_dies
: 1;
514 /* Non-zero if this CU is from .debug_types. */
515 unsigned int is_debug_types
: 1;
517 /* The section this CU/TU lives in.
518 If the DIE refers to a DWO file, this is always the original die,
520 struct dwarf2_section_info
*info_or_types_section
;
522 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
523 of the CU cache it gets reset to NULL again. */
524 struct dwarf2_cu
*cu
;
526 /* The corresponding objfile.
527 Normally we can get the objfile from dwarf2_per_objfile.
528 However we can enter this file with just a "per_cu" handle. */
529 struct objfile
*objfile
;
531 /* When using partial symbol tables, the 'psymtab' field is active.
532 Otherwise the 'quick' field is active. */
535 /* The partial symbol table associated with this compilation unit,
536 or NULL for unread partial units. */
537 struct partial_symtab
*psymtab
;
539 /* Data needed by the "quick" functions. */
540 struct dwarf2_per_cu_quick_data
*quick
;
545 /* The CUs we import using DW_TAG_imported_unit. This is filled in
546 while reading psymtabs, used to compute the psymtab dependencies,
547 and then cleared. Then it is filled in again while reading full
548 symbols, and only deleted when the objfile is destroyed. */
549 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
551 /* Type units are grouped by their DW_AT_stmt_list entry so that they
552 can share them. If this is a TU, this points to the containing
554 struct type_unit_group
*type_unit_group
;
558 /* Entry in the signatured_types hash table. */
560 struct signatured_type
562 /* The "per_cu" object of this type.
563 N.B.: This is the first member so that it's easy to convert pointers
565 struct dwarf2_per_cu_data per_cu
;
567 /* The type's signature. */
570 /* Offset in the TU of the type's DIE, as read from the TU header.
571 If the definition lives in a DWO file, this value is unusable. */
572 cu_offset type_offset_in_tu
;
574 /* Offset in the section of the type's DIE.
575 If the definition lives in a DWO file, this is the offset in the
576 .debug_types.dwo section.
577 The value is zero until the actual value is known.
578 Zero is otherwise not a valid section offset. */
579 sect_offset type_offset_in_section
;
582 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
583 This includes type_unit_group and quick_file_names. */
585 struct stmt_list_hash
587 /* The DWO unit this table is from or NULL if there is none. */
588 struct dwo_unit
*dwo_unit
;
590 /* Offset in .debug_line or .debug_line.dwo. */
591 sect_offset line_offset
;
594 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
595 an object of this type. */
597 struct type_unit_group
599 /* dwarf2read.c's main "handle" on the symtab.
600 To simplify things we create an artificial CU that "includes" all the
601 type units using this stmt_list so that the rest of the code still has
602 a "per_cu" handle on the symtab.
603 This PER_CU is recognized by having no section. */
604 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
605 struct dwarf2_per_cu_data per_cu
;
609 /* The TUs that share this DW_AT_stmt_list entry.
610 This is added to while parsing type units to build partial symtabs,
611 and is deleted afterwards and not used again. */
612 VEC (dwarf2_per_cu_ptr
) *tus
;
614 /* When reading the line table in "quick" functions, we need a real TU.
615 Any will do, we know they all share the same DW_AT_stmt_list entry.
616 For simplicity's sake, we pick the first one. */
617 struct dwarf2_per_cu_data
*first_tu
;
620 /* The primary symtab.
621 Type units in a group needn't all be defined in the same source file,
622 so we create an essentially anonymous symtab as the primary symtab. */
623 struct symtab
*primary_symtab
;
625 /* The data used to construct the hash key. */
626 struct stmt_list_hash hash
;
628 /* The number of symtabs from the line header.
629 The value here must match line_header.num_file_names. */
630 unsigned int num_symtabs
;
632 /* The symbol tables for this TU (obtained from the files listed in
634 WARNING: The order of entries here must match the order of entries
635 in the line header. After the first TU using this type_unit_group, the
636 line header for the subsequent TUs is recreated from this. This is done
637 because we need to use the same symtabs for each TU using the same
638 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
639 there's no guarantee the line header doesn't have duplicate entries. */
640 struct symtab
**symtabs
;
643 /* These sections are what may appear in a "dwo" file. */
647 struct dwarf2_section_info abbrev
;
648 struct dwarf2_section_info info
;
649 struct dwarf2_section_info line
;
650 struct dwarf2_section_info loc
;
651 struct dwarf2_section_info macinfo
;
652 struct dwarf2_section_info macro
;
653 struct dwarf2_section_info str
;
654 struct dwarf2_section_info str_offsets
;
655 VEC (dwarf2_section_info_def
) *types
;
658 /* Common bits of DWO CUs/TUs. */
662 /* Backlink to the containing struct dwo_file. */
663 struct dwo_file
*dwo_file
;
665 /* The "id" that distinguishes this CU/TU.
666 .debug_info calls this "dwo_id", .debug_types calls this "signature".
667 Since signatures came first, we stick with it for consistency. */
670 /* The section this CU/TU lives in, in the DWO file. */
671 struct dwarf2_section_info
*info_or_types_section
;
673 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
677 /* For types, offset in the type's DIE of the type defined by this TU. */
678 cu_offset type_offset_in_tu
;
681 /* Data for one DWO file. */
685 /* The DW_AT_GNU_dwo_name attribute.
686 We don't manage space for this, it's an attribute. */
687 const char *dwo_name
;
689 /* The bfd, when the file is open. Otherwise this is NULL. */
692 /* Section info for this file. */
693 struct dwo_sections sections
;
695 /* Table of CUs in the file.
696 Each element is a struct dwo_unit. */
699 /* Table of TUs in the file.
700 Each element is a struct dwo_unit. */
704 /* Struct used to pass misc. parameters to read_die_and_children, et
705 al. which are used for both .debug_info and .debug_types dies.
706 All parameters here are unchanging for the life of the call. This
707 struct exists to abstract away the constant parameters of die reading. */
709 struct die_reader_specs
711 /* die_section->asection->owner. */
714 /* The CU of the DIE we are parsing. */
715 struct dwarf2_cu
*cu
;
717 /* Non-NULL if reading a DWO file. */
718 struct dwo_file
*dwo_file
;
720 /* The section the die comes from.
721 This is either .debug_info or .debug_types, or the .dwo variants. */
722 struct dwarf2_section_info
*die_section
;
724 /* die_section->buffer. */
727 /* The end of the buffer. */
728 const gdb_byte
*buffer_end
;
731 /* Type of function passed to init_cutu_and_read_dies, et.al. */
732 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
734 struct die_info
*comp_unit_die
,
738 /* The line number information for a compilation unit (found in the
739 .debug_line section) begins with a "statement program header",
740 which contains the following information. */
743 unsigned int total_length
;
744 unsigned short version
;
745 unsigned int header_length
;
746 unsigned char minimum_instruction_length
;
747 unsigned char maximum_ops_per_instruction
;
748 unsigned char default_is_stmt
;
750 unsigned char line_range
;
751 unsigned char opcode_base
;
753 /* standard_opcode_lengths[i] is the number of operands for the
754 standard opcode whose value is i. This means that
755 standard_opcode_lengths[0] is unused, and the last meaningful
756 element is standard_opcode_lengths[opcode_base - 1]. */
757 unsigned char *standard_opcode_lengths
;
759 /* The include_directories table. NOTE! These strings are not
760 allocated with xmalloc; instead, they are pointers into
761 debug_line_buffer. If you try to free them, `free' will get
763 unsigned int num_include_dirs
, include_dirs_size
;
766 /* The file_names table. NOTE! These strings are not allocated
767 with xmalloc; instead, they are pointers into debug_line_buffer.
768 Don't try to free them directly. */
769 unsigned int num_file_names
, file_names_size
;
773 unsigned int dir_index
;
774 unsigned int mod_time
;
776 int included_p
; /* Non-zero if referenced by the Line Number Program. */
777 struct symtab
*symtab
; /* The associated symbol table, if any. */
780 /* The start and end of the statement program following this
781 header. These point into dwarf2_per_objfile->line_buffer. */
782 gdb_byte
*statement_program_start
, *statement_program_end
;
785 /* When we construct a partial symbol table entry we only
786 need this much information. */
787 struct partial_die_info
789 /* Offset of this DIE. */
792 /* DWARF-2 tag for this DIE. */
793 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
795 /* Assorted flags describing the data found in this DIE. */
796 unsigned int has_children
: 1;
797 unsigned int is_external
: 1;
798 unsigned int is_declaration
: 1;
799 unsigned int has_type
: 1;
800 unsigned int has_specification
: 1;
801 unsigned int has_pc_info
: 1;
802 unsigned int may_be_inlined
: 1;
804 /* Flag set if the SCOPE field of this structure has been
806 unsigned int scope_set
: 1;
808 /* Flag set if the DIE has a byte_size attribute. */
809 unsigned int has_byte_size
: 1;
811 /* Flag set if any of the DIE's children are template arguments. */
812 unsigned int has_template_arguments
: 1;
814 /* Flag set if fixup_partial_die has been called on this die. */
815 unsigned int fixup_called
: 1;
817 /* The name of this DIE. Normally the value of DW_AT_name, but
818 sometimes a default name for unnamed DIEs. */
821 /* The linkage name, if present. */
822 const char *linkage_name
;
824 /* The scope to prepend to our children. This is generally
825 allocated on the comp_unit_obstack, so will disappear
826 when this compilation unit leaves the cache. */
829 /* Some data associated with the partial DIE. The tag determines
830 which field is live. */
833 /* The location description associated with this DIE, if any. */
834 struct dwarf_block
*locdesc
;
835 /* The offset of an import, for DW_TAG_imported_unit. */
839 /* If HAS_PC_INFO, the PC range associated with this DIE. */
843 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
844 DW_AT_sibling, if any. */
845 /* NOTE: This member isn't strictly necessary, read_partial_die could
846 return DW_AT_sibling values to its caller load_partial_dies. */
849 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
850 DW_AT_specification (or DW_AT_abstract_origin or
852 sect_offset spec_offset
;
854 /* Pointers to this DIE's parent, first child, and next sibling,
856 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
859 /* This data structure holds the information of an abbrev. */
862 unsigned int number
; /* number identifying abbrev */
863 enum dwarf_tag tag
; /* dwarf tag */
864 unsigned short has_children
; /* boolean */
865 unsigned short num_attrs
; /* number of attributes */
866 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
867 struct abbrev_info
*next
; /* next in chain */
872 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
873 ENUM_BITFIELD(dwarf_form
) form
: 16;
876 /* Size of abbrev_table.abbrev_hash_table. */
877 #define ABBREV_HASH_SIZE 121
879 /* Top level data structure to contain an abbreviation table. */
883 /* Where the abbrev table came from.
884 This is used as a sanity check when the table is used. */
887 /* Storage for the abbrev table. */
888 struct obstack abbrev_obstack
;
890 /* Hash table of abbrevs.
891 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
892 It could be statically allocated, but the previous code didn't so we
894 struct abbrev_info
**abbrevs
;
897 /* Attributes have a name and a value. */
900 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
901 ENUM_BITFIELD(dwarf_form
) form
: 15;
903 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
904 field should be in u.str (existing only for DW_STRING) but it is kept
905 here for better struct attribute alignment. */
906 unsigned int string_is_canonical
: 1;
911 struct dwarf_block
*blk
;
915 struct signatured_type
*signatured_type
;
920 /* This data structure holds a complete die structure. */
923 /* DWARF-2 tag for this DIE. */
924 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
926 /* Number of attributes */
927 unsigned char num_attrs
;
929 /* True if we're presently building the full type name for the
930 type derived from this DIE. */
931 unsigned char building_fullname
: 1;
936 /* Offset in .debug_info or .debug_types section. */
939 /* The dies in a compilation unit form an n-ary tree. PARENT
940 points to this die's parent; CHILD points to the first child of
941 this node; and all the children of a given node are chained
942 together via their SIBLING fields. */
943 struct die_info
*child
; /* Its first child, if any. */
944 struct die_info
*sibling
; /* Its next sibling, if any. */
945 struct die_info
*parent
; /* Its parent, if any. */
947 /* An array of attributes, with NUM_ATTRS elements. There may be
948 zero, but it's not common and zero-sized arrays are not
949 sufficiently portable C. */
950 struct attribute attrs
[1];
953 /* Get at parts of an attribute structure. */
955 #define DW_STRING(attr) ((attr)->u.str)
956 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
957 #define DW_UNSND(attr) ((attr)->u.unsnd)
958 #define DW_BLOCK(attr) ((attr)->u.blk)
959 #define DW_SND(attr) ((attr)->u.snd)
960 #define DW_ADDR(attr) ((attr)->u.addr)
961 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
963 /* Blocks are a bunch of untyped bytes. */
968 /* Valid only if SIZE is not zero. */
972 #ifndef ATTR_ALLOC_CHUNK
973 #define ATTR_ALLOC_CHUNK 4
976 /* Allocate fields for structs, unions and enums in this size. */
977 #ifndef DW_FIELD_ALLOC_CHUNK
978 #define DW_FIELD_ALLOC_CHUNK 4
981 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
982 but this would require a corresponding change in unpack_field_as_long
984 static int bits_per_byte
= 8;
986 /* The routines that read and process dies for a C struct or C++ class
987 pass lists of data member fields and lists of member function fields
988 in an instance of a field_info structure, as defined below. */
991 /* List of data member and baseclasses fields. */
994 struct nextfield
*next
;
999 *fields
, *baseclasses
;
1001 /* Number of fields (including baseclasses). */
1004 /* Number of baseclasses. */
1007 /* Set if the accesibility of one of the fields is not public. */
1008 int non_public_fields
;
1010 /* Member function fields array, entries are allocated in the order they
1011 are encountered in the object file. */
1014 struct nextfnfield
*next
;
1015 struct fn_field fnfield
;
1019 /* Member function fieldlist array, contains name of possibly overloaded
1020 member function, number of overloaded member functions and a pointer
1021 to the head of the member function field chain. */
1026 struct nextfnfield
*head
;
1030 /* Number of entries in the fnfieldlists array. */
1033 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1034 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1035 struct typedef_field_list
1037 struct typedef_field field
;
1038 struct typedef_field_list
*next
;
1040 *typedef_field_list
;
1041 unsigned typedef_field_list_count
;
1044 /* One item on the queue of compilation units to read in full symbols
1046 struct dwarf2_queue_item
1048 struct dwarf2_per_cu_data
*per_cu
;
1049 enum language pretend_language
;
1050 struct dwarf2_queue_item
*next
;
1053 /* The current queue. */
1054 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1056 /* Loaded secondary compilation units are kept in memory until they
1057 have not been referenced for the processing of this many
1058 compilation units. Set this to zero to disable caching. Cache
1059 sizes of up to at least twenty will improve startup time for
1060 typical inter-CU-reference binaries, at an obvious memory cost. */
1061 static int dwarf2_max_cache_age
= 5;
1063 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1064 struct cmd_list_element
*c
, const char *value
)
1066 fprintf_filtered (file
, _("The upper bound on the age of cached "
1067 "dwarf2 compilation units is %s.\n"),
1072 /* Various complaints about symbol reading that don't abort the process. */
1075 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1077 complaint (&symfile_complaints
,
1078 _("statement list doesn't fit in .debug_line section"));
1082 dwarf2_debug_line_missing_file_complaint (void)
1084 complaint (&symfile_complaints
,
1085 _(".debug_line section has line data without a file"));
1089 dwarf2_debug_line_missing_end_sequence_complaint (void)
1091 complaint (&symfile_complaints
,
1092 _(".debug_line section has line "
1093 "program sequence without an end"));
1097 dwarf2_complex_location_expr_complaint (void)
1099 complaint (&symfile_complaints
, _("location expression too complex"));
1103 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1106 complaint (&symfile_complaints
,
1107 _("const value length mismatch for '%s', got %d, expected %d"),
1112 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1114 complaint (&symfile_complaints
,
1115 _("debug info runs off end of %s section"
1117 section
->asection
->name
,
1118 bfd_get_filename (section
->asection
->owner
));
1122 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1124 complaint (&symfile_complaints
,
1125 _("macro debug info contains a "
1126 "malformed macro definition:\n`%s'"),
1131 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1133 complaint (&symfile_complaints
,
1134 _("invalid attribute class or form for '%s' in '%s'"),
1138 /* local function prototypes */
1140 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1142 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1145 static void dwarf2_find_base_address (struct die_info
*die
,
1146 struct dwarf2_cu
*cu
);
1148 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1150 static void scan_partial_symbols (struct partial_die_info
*,
1151 CORE_ADDR
*, CORE_ADDR
*,
1152 int, struct dwarf2_cu
*);
1154 static void add_partial_symbol (struct partial_die_info
*,
1155 struct dwarf2_cu
*);
1157 static void add_partial_namespace (struct partial_die_info
*pdi
,
1158 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1159 int need_pc
, struct dwarf2_cu
*cu
);
1161 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1162 CORE_ADDR
*highpc
, int need_pc
,
1163 struct dwarf2_cu
*cu
);
1165 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1166 struct dwarf2_cu
*cu
);
1168 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1169 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1170 int need_pc
, struct dwarf2_cu
*cu
);
1172 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1174 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1176 static struct abbrev_info
*abbrev_table_lookup_abbrev
1177 (const struct abbrev_table
*, unsigned int);
1179 static struct abbrev_table
*abbrev_table_read_table
1180 (struct dwarf2_section_info
*, sect_offset
);
1182 static void abbrev_table_free (struct abbrev_table
*);
1184 static void abbrev_table_free_cleanup (void *);
1186 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1187 struct dwarf2_section_info
*);
1189 static void dwarf2_free_abbrev_table (void *);
1191 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1193 static struct partial_die_info
*load_partial_dies
1194 (const struct die_reader_specs
*, gdb_byte
*, int);
1196 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1197 struct partial_die_info
*,
1198 struct abbrev_info
*,
1202 static struct partial_die_info
*find_partial_die (sect_offset
,
1203 struct dwarf2_cu
*);
1205 static void fixup_partial_die (struct partial_die_info
*,
1206 struct dwarf2_cu
*);
1208 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1209 struct attribute
*, struct attr_abbrev
*,
1212 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1214 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1216 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1218 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1220 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1222 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1225 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1227 static LONGEST read_checked_initial_length_and_offset
1228 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1229 unsigned int *, unsigned int *);
1231 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1234 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1236 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1239 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1241 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1243 static char *read_indirect_string (bfd
*, gdb_byte
*,
1244 const struct comp_unit_head
*,
1247 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1249 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1251 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1254 static char *read_str_index (const struct die_reader_specs
*reader
,
1255 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1257 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1259 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1260 struct dwarf2_cu
*);
1262 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1265 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1266 struct dwarf2_cu
*cu
);
1268 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1270 static struct die_info
*die_specification (struct die_info
*die
,
1271 struct dwarf2_cu
**);
1273 static void free_line_header (struct line_header
*lh
);
1275 static void add_file_name (struct line_header
*, char *, unsigned int,
1276 unsigned int, unsigned int);
1278 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1279 struct dwarf2_cu
*cu
);
1281 static void dwarf_decode_lines (struct line_header
*, const char *,
1282 struct dwarf2_cu
*, struct partial_symtab
*,
1285 static void dwarf2_start_subfile (char *, const char *, const char *);
1287 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1288 char *, char *, CORE_ADDR
);
1290 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1291 struct dwarf2_cu
*);
1293 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1294 struct dwarf2_cu
*, struct symbol
*);
1296 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1297 struct dwarf2_cu
*);
1299 static void dwarf2_const_value_attr (struct attribute
*attr
,
1302 struct obstack
*obstack
,
1303 struct dwarf2_cu
*cu
, LONGEST
*value
,
1305 struct dwarf2_locexpr_baton
**baton
);
1307 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1309 static int need_gnat_info (struct dwarf2_cu
*);
1311 static struct type
*die_descriptive_type (struct die_info
*,
1312 struct dwarf2_cu
*);
1314 static void set_descriptive_type (struct type
*, struct die_info
*,
1315 struct dwarf2_cu
*);
1317 static struct type
*die_containing_type (struct die_info
*,
1318 struct dwarf2_cu
*);
1320 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1321 struct dwarf2_cu
*);
1323 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1325 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1327 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1329 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1330 const char *suffix
, int physname
,
1331 struct dwarf2_cu
*cu
);
1333 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1335 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1337 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1339 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1341 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1343 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1344 struct dwarf2_cu
*, struct partial_symtab
*);
1346 static int dwarf2_get_pc_bounds (struct die_info
*,
1347 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1348 struct partial_symtab
*);
1350 static void get_scope_pc_bounds (struct die_info
*,
1351 CORE_ADDR
*, CORE_ADDR
*,
1352 struct dwarf2_cu
*);
1354 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1355 CORE_ADDR
, struct dwarf2_cu
*);
1357 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1358 struct dwarf2_cu
*);
1360 static void dwarf2_attach_fields_to_type (struct field_info
*,
1361 struct type
*, struct dwarf2_cu
*);
1363 static void dwarf2_add_member_fn (struct field_info
*,
1364 struct die_info
*, struct type
*,
1365 struct dwarf2_cu
*);
1367 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1369 struct dwarf2_cu
*);
1371 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1373 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1375 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1377 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1379 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1381 static struct type
*read_module_type (struct die_info
*die
,
1382 struct dwarf2_cu
*cu
);
1384 static const char *namespace_name (struct die_info
*die
,
1385 int *is_anonymous
, struct dwarf2_cu
*);
1387 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1389 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1391 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1392 struct dwarf2_cu
*);
1394 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1396 gdb_byte
**new_info_ptr
,
1397 struct die_info
*parent
);
1399 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1401 gdb_byte
**new_info_ptr
,
1402 struct die_info
*parent
);
1404 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1405 struct die_info
**, gdb_byte
*, int *, int);
1407 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1408 struct die_info
**, gdb_byte
*, int *);
1410 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1412 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1415 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1417 static const char *dwarf2_full_name (char *name
,
1418 struct die_info
*die
,
1419 struct dwarf2_cu
*cu
);
1421 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1422 struct dwarf2_cu
**);
1424 static const char *dwarf_tag_name (unsigned int);
1426 static const char *dwarf_attr_name (unsigned int);
1428 static const char *dwarf_form_name (unsigned int);
1430 static char *dwarf_bool_name (unsigned int);
1432 static const char *dwarf_type_encoding_name (unsigned int);
1434 static struct die_info
*sibling_die (struct die_info
*);
1436 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1438 static void dump_die_for_error (struct die_info
*);
1440 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1443 /*static*/ void dump_die (struct die_info
*, int max_level
);
1445 static void store_in_ref_table (struct die_info
*,
1446 struct dwarf2_cu
*);
1448 static int is_ref_attr (struct attribute
*);
1450 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1452 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1454 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1456 struct dwarf2_cu
**);
1458 static struct die_info
*follow_die_ref (struct die_info
*,
1460 struct dwarf2_cu
**);
1462 static struct die_info
*follow_die_sig (struct die_info
*,
1464 struct dwarf2_cu
**);
1466 static struct signatured_type
*lookup_signatured_type_at_offset
1467 (struct objfile
*objfile
,
1468 struct dwarf2_section_info
*section
, sect_offset offset
);
1470 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1472 static void read_signatured_type (struct signatured_type
*);
1474 static struct type_unit_group
*get_type_unit_group
1475 (struct dwarf2_cu
*, struct attribute
*);
1477 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1479 /* memory allocation interface */
1481 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1483 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1485 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1488 static int attr_form_is_block (struct attribute
*);
1490 static int attr_form_is_section_offset (struct attribute
*);
1492 static int attr_form_is_constant (struct attribute
*);
1494 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1495 struct dwarf2_loclist_baton
*baton
,
1496 struct attribute
*attr
);
1498 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1500 struct dwarf2_cu
*cu
);
1502 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1504 struct abbrev_info
*abbrev
);
1506 static void free_stack_comp_unit (void *);
1508 static hashval_t
partial_die_hash (const void *item
);
1510 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1512 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1513 (sect_offset offset
, struct objfile
*objfile
);
1515 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1516 struct dwarf2_per_cu_data
*per_cu
);
1518 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1519 struct die_info
*comp_unit_die
,
1520 enum language pretend_language
);
1522 static void free_heap_comp_unit (void *);
1524 static void free_cached_comp_units (void *);
1526 static void age_cached_comp_units (void);
1528 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1530 static struct type
*set_die_type (struct die_info
*, struct type
*,
1531 struct dwarf2_cu
*);
1533 static void create_all_comp_units (struct objfile
*);
1535 static int create_all_type_units (struct objfile
*);
1537 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1540 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1543 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1546 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1547 struct dwarf2_per_cu_data
*);
1549 static void dwarf2_mark (struct dwarf2_cu
*);
1551 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1553 static struct type
*get_die_type_at_offset (sect_offset
,
1554 struct dwarf2_per_cu_data
*per_cu
);
1556 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1558 static void dwarf2_release_queue (void *dummy
);
1560 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1561 enum language pretend_language
);
1563 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1564 struct dwarf2_per_cu_data
*per_cu
,
1565 enum language pretend_language
);
1567 static void process_queue (void);
1569 static void find_file_and_directory (struct die_info
*die
,
1570 struct dwarf2_cu
*cu
,
1571 char **name
, char **comp_dir
);
1573 static char *file_full_name (int file
, struct line_header
*lh
,
1574 const char *comp_dir
);
1576 static void init_cutu_and_read_dies
1577 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1578 int use_existing_cu
, int keep
,
1579 die_reader_func_ftype
*die_reader_func
, void *data
);
1581 static void init_cutu_and_read_dies_simple
1582 (struct dwarf2_per_cu_data
*this_cu
,
1583 die_reader_func_ftype
*die_reader_func
, void *data
);
1585 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1587 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1589 static struct dwo_unit
*lookup_dwo_comp_unit
1590 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1592 static struct dwo_unit
*lookup_dwo_type_unit
1593 (struct signatured_type
*, char *, const char *);
1595 static void free_dwo_file_cleanup (void *);
1597 static void process_cu_includes (void);
1601 /* Convert VALUE between big- and little-endian. */
1603 byte_swap (offset_type value
)
1607 result
= (value
& 0xff) << 24;
1608 result
|= (value
& 0xff00) << 8;
1609 result
|= (value
& 0xff0000) >> 8;
1610 result
|= (value
& 0xff000000) >> 24;
1614 #define MAYBE_SWAP(V) byte_swap (V)
1617 #define MAYBE_SWAP(V) (V)
1618 #endif /* WORDS_BIGENDIAN */
1620 /* The suffix for an index file. */
1621 #define INDEX_SUFFIX ".gdb-index"
1623 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1624 struct dwarf2_cu
*cu
);
1626 /* Try to locate the sections we need for DWARF 2 debugging
1627 information and return true if we have enough to do something.
1628 NAMES points to the dwarf2 section names, or is NULL if the standard
1629 ELF names are used. */
1632 dwarf2_has_info (struct objfile
*objfile
,
1633 const struct dwarf2_debug_sections
*names
)
1635 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1636 if (!dwarf2_per_objfile
)
1638 /* Initialize per-objfile state. */
1639 struct dwarf2_per_objfile
*data
1640 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1642 memset (data
, 0, sizeof (*data
));
1643 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1644 dwarf2_per_objfile
= data
;
1646 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1648 dwarf2_per_objfile
->objfile
= objfile
;
1650 return (dwarf2_per_objfile
->info
.asection
!= NULL
1651 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1654 /* When loading sections, we look either for uncompressed section or for
1655 compressed section names. */
1658 section_is_p (const char *section_name
,
1659 const struct dwarf2_section_names
*names
)
1661 if (names
->normal
!= NULL
1662 && strcmp (section_name
, names
->normal
) == 0)
1664 if (names
->compressed
!= NULL
1665 && strcmp (section_name
, names
->compressed
) == 0)
1670 /* This function is mapped across the sections and remembers the
1671 offset and size of each of the debugging sections we are interested
1675 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1677 const struct dwarf2_debug_sections
*names
;
1680 names
= &dwarf2_elf_names
;
1682 names
= (const struct dwarf2_debug_sections
*) vnames
;
1684 if (section_is_p (sectp
->name
, &names
->info
))
1686 dwarf2_per_objfile
->info
.asection
= sectp
;
1687 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1689 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1691 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1692 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1694 else if (section_is_p (sectp
->name
, &names
->line
))
1696 dwarf2_per_objfile
->line
.asection
= sectp
;
1697 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1699 else if (section_is_p (sectp
->name
, &names
->loc
))
1701 dwarf2_per_objfile
->loc
.asection
= sectp
;
1702 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1704 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1706 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1707 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1709 else if (section_is_p (sectp
->name
, &names
->macro
))
1711 dwarf2_per_objfile
->macro
.asection
= sectp
;
1712 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1714 else if (section_is_p (sectp
->name
, &names
->str
))
1716 dwarf2_per_objfile
->str
.asection
= sectp
;
1717 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1719 else if (section_is_p (sectp
->name
, &names
->addr
))
1721 dwarf2_per_objfile
->addr
.asection
= sectp
;
1722 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1724 else if (section_is_p (sectp
->name
, &names
->frame
))
1726 dwarf2_per_objfile
->frame
.asection
= sectp
;
1727 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1729 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1731 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1733 if (aflag
& SEC_HAS_CONTENTS
)
1735 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1736 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1739 else if (section_is_p (sectp
->name
, &names
->ranges
))
1741 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1742 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1744 else if (section_is_p (sectp
->name
, &names
->types
))
1746 struct dwarf2_section_info type_section
;
1748 memset (&type_section
, 0, sizeof (type_section
));
1749 type_section
.asection
= sectp
;
1750 type_section
.size
= bfd_get_section_size (sectp
);
1752 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1755 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1757 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1758 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1761 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1762 && bfd_section_vma (abfd
, sectp
) == 0)
1763 dwarf2_per_objfile
->has_section_at_zero
= 1;
1766 /* A helper function that decides whether a section is empty,
1770 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1772 return info
->asection
== NULL
|| info
->size
== 0;
1775 /* Read the contents of the section INFO.
1776 OBJFILE is the main object file, but not necessarily the file where
1777 the section comes from. E.g., for DWO files INFO->asection->owner
1778 is the bfd of the DWO file.
1779 If the section is compressed, uncompress it before returning. */
1782 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1784 asection
*sectp
= info
->asection
;
1786 gdb_byte
*buf
, *retbuf
;
1787 unsigned char header
[4];
1791 info
->buffer
= NULL
;
1794 if (dwarf2_section_empty_p (info
))
1797 abfd
= sectp
->owner
;
1799 /* If the section has relocations, we must read it ourselves.
1800 Otherwise we attach it to the BFD. */
1801 if ((sectp
->flags
& SEC_RELOC
) == 0)
1803 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1805 /* We have to cast away const here for historical reasons.
1806 Fixing dwarf2read to be const-correct would be quite nice. */
1807 info
->buffer
= (gdb_byte
*) bytes
;
1811 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1814 /* When debugging .o files, we may need to apply relocations; see
1815 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1816 We never compress sections in .o files, so we only need to
1817 try this when the section is not compressed. */
1818 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1821 info
->buffer
= retbuf
;
1825 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1826 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1827 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1828 bfd_get_filename (abfd
));
1831 /* A helper function that returns the size of a section in a safe way.
1832 If you are positive that the section has been read before using the
1833 size, then it is safe to refer to the dwarf2_section_info object's
1834 "size" field directly. In other cases, you must call this
1835 function, because for compressed sections the size field is not set
1836 correctly until the section has been read. */
1838 static bfd_size_type
1839 dwarf2_section_size (struct objfile
*objfile
,
1840 struct dwarf2_section_info
*info
)
1843 dwarf2_read_section (objfile
, info
);
1847 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1851 dwarf2_get_section_info (struct objfile
*objfile
,
1852 enum dwarf2_section_enum sect
,
1853 asection
**sectp
, gdb_byte
**bufp
,
1854 bfd_size_type
*sizep
)
1856 struct dwarf2_per_objfile
*data
1857 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1858 struct dwarf2_section_info
*info
;
1860 /* We may see an objfile without any DWARF, in which case we just
1871 case DWARF2_DEBUG_FRAME
:
1872 info
= &data
->frame
;
1874 case DWARF2_EH_FRAME
:
1875 info
= &data
->eh_frame
;
1878 gdb_assert_not_reached ("unexpected section");
1881 dwarf2_read_section (objfile
, info
);
1883 *sectp
= info
->asection
;
1884 *bufp
= info
->buffer
;
1885 *sizep
= info
->size
;
1889 /* DWARF quick_symbols_functions support. */
1891 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1892 unique line tables, so we maintain a separate table of all .debug_line
1893 derived entries to support the sharing.
1894 All the quick functions need is the list of file names. We discard the
1895 line_header when we're done and don't need to record it here. */
1896 struct quick_file_names
1898 /* The data used to construct the hash key. */
1899 struct stmt_list_hash hash
;
1901 /* The number of entries in file_names, real_names. */
1902 unsigned int num_file_names
;
1904 /* The file names from the line table, after being run through
1906 const char **file_names
;
1908 /* The file names from the line table after being run through
1909 gdb_realpath. These are computed lazily. */
1910 const char **real_names
;
1913 /* When using the index (and thus not using psymtabs), each CU has an
1914 object of this type. This is used to hold information needed by
1915 the various "quick" methods. */
1916 struct dwarf2_per_cu_quick_data
1918 /* The file table. This can be NULL if there was no file table
1919 or it's currently not read in.
1920 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1921 struct quick_file_names
*file_names
;
1923 /* The corresponding symbol table. This is NULL if symbols for this
1924 CU have not yet been read. */
1925 struct symtab
*symtab
;
1927 /* A temporary mark bit used when iterating over all CUs in
1928 expand_symtabs_matching. */
1929 unsigned int mark
: 1;
1931 /* True if we've tried to read the file table and found there isn't one.
1932 There will be no point in trying to read it again next time. */
1933 unsigned int no_file_data
: 1;
1936 /* Utility hash function for a stmt_list_hash. */
1939 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
1943 if (stmt_list_hash
->dwo_unit
!= NULL
)
1944 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
1945 v
+= stmt_list_hash
->line_offset
.sect_off
;
1949 /* Utility equality function for a stmt_list_hash. */
1952 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
1953 const struct stmt_list_hash
*rhs
)
1955 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
1957 if (lhs
->dwo_unit
!= NULL
1958 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
1961 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
1964 /* Hash function for a quick_file_names. */
1967 hash_file_name_entry (const void *e
)
1969 const struct quick_file_names
*file_data
= e
;
1971 return hash_stmt_list_entry (&file_data
->hash
);
1974 /* Equality function for a quick_file_names. */
1977 eq_file_name_entry (const void *a
, const void *b
)
1979 const struct quick_file_names
*ea
= a
;
1980 const struct quick_file_names
*eb
= b
;
1982 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
1985 /* Delete function for a quick_file_names. */
1988 delete_file_name_entry (void *e
)
1990 struct quick_file_names
*file_data
= e
;
1993 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1995 xfree ((void*) file_data
->file_names
[i
]);
1996 if (file_data
->real_names
)
1997 xfree ((void*) file_data
->real_names
[i
]);
2000 /* The space for the struct itself lives on objfile_obstack,
2001 so we don't free it here. */
2004 /* Create a quick_file_names hash table. */
2007 create_quick_file_names_table (unsigned int nr_initial_entries
)
2009 return htab_create_alloc (nr_initial_entries
,
2010 hash_file_name_entry
, eq_file_name_entry
,
2011 delete_file_name_entry
, xcalloc
, xfree
);
2014 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2015 have to be created afterwards. You should call age_cached_comp_units after
2016 processing PER_CU->CU. dw2_setup must have been already called. */
2019 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2021 if (per_cu
->is_debug_types
)
2022 load_full_type_unit (per_cu
);
2024 load_full_comp_unit (per_cu
, language_minimal
);
2026 gdb_assert (per_cu
->cu
!= NULL
);
2028 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2031 /* Read in the symbols for PER_CU. */
2034 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2036 struct cleanup
*back_to
;
2038 /* Skip type_unit_groups, reading the type units they contain
2039 is handled elsewhere. */
2040 if (IS_TYPE_UNIT_GROUP (per_cu
))
2043 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2045 if (dwarf2_per_objfile
->using_index
2046 ? per_cu
->v
.quick
->symtab
== NULL
2047 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2049 queue_comp_unit (per_cu
, language_minimal
);
2055 /* Age the cache, releasing compilation units that have not
2056 been used recently. */
2057 age_cached_comp_units ();
2059 do_cleanups (back_to
);
2062 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2063 the objfile from which this CU came. Returns the resulting symbol
2066 static struct symtab
*
2067 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2069 gdb_assert (dwarf2_per_objfile
->using_index
);
2070 if (!per_cu
->v
.quick
->symtab
)
2072 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2073 increment_reading_symtab ();
2074 dw2_do_instantiate_symtab (per_cu
);
2075 process_cu_includes ();
2076 do_cleanups (back_to
);
2078 return per_cu
->v
.quick
->symtab
;
2081 /* Return the CU given its index.
2083 This is intended for loops like:
2085 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2086 + dwarf2_per_objfile->n_type_units); ++i)
2088 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2094 static struct dwarf2_per_cu_data
*
2095 dw2_get_cu (int index
)
2097 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2099 index
-= dwarf2_per_objfile
->n_comp_units
;
2100 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2101 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2104 return dwarf2_per_objfile
->all_comp_units
[index
];
2107 /* Return the primary CU given its index.
2108 The difference between this function and dw2_get_cu is in the handling
2109 of type units (TUs). Here we return the type_unit_group object.
2111 This is intended for loops like:
2113 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2114 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2116 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2122 static struct dwarf2_per_cu_data
*
2123 dw2_get_primary_cu (int index
)
2125 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2127 index
-= dwarf2_per_objfile
->n_comp_units
;
2128 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2129 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2132 return dwarf2_per_objfile
->all_comp_units
[index
];
2135 /* A helper function that knows how to read a 64-bit value in a way
2136 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2140 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2142 if (sizeof (ULONGEST
) < 8)
2146 /* Ignore the upper 4 bytes if they are all zero. */
2147 for (i
= 0; i
< 4; ++i
)
2148 if (bytes
[i
+ 4] != 0)
2151 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2154 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2158 /* Read the CU list from the mapped index, and use it to create all
2159 the CU objects for this objfile. Return 0 if something went wrong,
2160 1 if everything went ok. */
2163 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2164 offset_type cu_list_elements
)
2168 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2169 dwarf2_per_objfile
->all_comp_units
2170 = obstack_alloc (&objfile
->objfile_obstack
,
2171 dwarf2_per_objfile
->n_comp_units
2172 * sizeof (struct dwarf2_per_cu_data
*));
2174 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2176 struct dwarf2_per_cu_data
*the_cu
;
2177 ULONGEST offset
, length
;
2179 if (!extract_cu_value (cu_list
, &offset
)
2180 || !extract_cu_value (cu_list
+ 8, &length
))
2184 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2185 struct dwarf2_per_cu_data
);
2186 the_cu
->offset
.sect_off
= offset
;
2187 the_cu
->length
= length
;
2188 the_cu
->objfile
= objfile
;
2189 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2190 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2191 struct dwarf2_per_cu_quick_data
);
2192 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2198 /* Create the signatured type hash table from the index. */
2201 create_signatured_type_table_from_index (struct objfile
*objfile
,
2202 struct dwarf2_section_info
*section
,
2203 const gdb_byte
*bytes
,
2204 offset_type elements
)
2207 htab_t sig_types_hash
;
2209 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2210 dwarf2_per_objfile
->all_type_units
2211 = obstack_alloc (&objfile
->objfile_obstack
,
2212 dwarf2_per_objfile
->n_type_units
2213 * sizeof (struct signatured_type
*));
2215 sig_types_hash
= allocate_signatured_type_table (objfile
);
2217 for (i
= 0; i
< elements
; i
+= 3)
2219 struct signatured_type
*sig_type
;
2220 ULONGEST offset
, type_offset_in_tu
, signature
;
2223 if (!extract_cu_value (bytes
, &offset
)
2224 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2226 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2229 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2230 struct signatured_type
);
2231 sig_type
->signature
= signature
;
2232 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2233 sig_type
->per_cu
.is_debug_types
= 1;
2234 sig_type
->per_cu
.info_or_types_section
= section
;
2235 sig_type
->per_cu
.offset
.sect_off
= offset
;
2236 sig_type
->per_cu
.objfile
= objfile
;
2237 sig_type
->per_cu
.v
.quick
2238 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2239 struct dwarf2_per_cu_quick_data
);
2241 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2244 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2247 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2252 /* Read the address map data from the mapped index, and use it to
2253 populate the objfile's psymtabs_addrmap. */
2256 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2258 const gdb_byte
*iter
, *end
;
2259 struct obstack temp_obstack
;
2260 struct addrmap
*mutable_map
;
2261 struct cleanup
*cleanup
;
2264 obstack_init (&temp_obstack
);
2265 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2266 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2268 iter
= index
->address_table
;
2269 end
= iter
+ index
->address_table_size
;
2271 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2275 ULONGEST hi
, lo
, cu_index
;
2276 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2278 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2280 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2283 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2284 dw2_get_cu (cu_index
));
2287 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2288 &objfile
->objfile_obstack
);
2289 do_cleanups (cleanup
);
2292 /* The hash function for strings in the mapped index. This is the same as
2293 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2294 implementation. This is necessary because the hash function is tied to the
2295 format of the mapped index file. The hash values do not have to match with
2298 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2301 mapped_index_string_hash (int index_version
, const void *p
)
2303 const unsigned char *str
= (const unsigned char *) p
;
2307 while ((c
= *str
++) != 0)
2309 if (index_version
>= 5)
2311 r
= r
* 67 + c
- 113;
2317 /* Find a slot in the mapped index INDEX for the object named NAME.
2318 If NAME is found, set *VEC_OUT to point to the CU vector in the
2319 constant pool and return 1. If NAME cannot be found, return 0. */
2322 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2323 offset_type
**vec_out
)
2325 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2327 offset_type slot
, step
;
2328 int (*cmp
) (const char *, const char *);
2330 if (current_language
->la_language
== language_cplus
2331 || current_language
->la_language
== language_java
2332 || current_language
->la_language
== language_fortran
)
2334 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2336 const char *paren
= strchr (name
, '(');
2342 dup
= xmalloc (paren
- name
+ 1);
2343 memcpy (dup
, name
, paren
- name
);
2344 dup
[paren
- name
] = 0;
2346 make_cleanup (xfree
, dup
);
2351 /* Index version 4 did not support case insensitive searches. But the
2352 indices for case insensitive languages are built in lowercase, therefore
2353 simulate our NAME being searched is also lowercased. */
2354 hash
= mapped_index_string_hash ((index
->version
== 4
2355 && case_sensitivity
== case_sensitive_off
2356 ? 5 : index
->version
),
2359 slot
= hash
& (index
->symbol_table_slots
- 1);
2360 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2361 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2365 /* Convert a slot number to an offset into the table. */
2366 offset_type i
= 2 * slot
;
2368 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2370 do_cleanups (back_to
);
2374 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2375 if (!cmp (name
, str
))
2377 *vec_out
= (offset_type
*) (index
->constant_pool
2378 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2379 do_cleanups (back_to
);
2383 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2387 /* Read the index file. If everything went ok, initialize the "quick"
2388 elements of all the CUs and return 1. Otherwise, return 0. */
2391 dwarf2_read_index (struct objfile
*objfile
)
2394 struct mapped_index
*map
;
2395 offset_type
*metadata
;
2396 const gdb_byte
*cu_list
;
2397 const gdb_byte
*types_list
= NULL
;
2398 offset_type version
, cu_list_elements
;
2399 offset_type types_list_elements
= 0;
2402 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2405 /* Older elfutils strip versions could keep the section in the main
2406 executable while splitting it for the separate debug info file. */
2407 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2408 & SEC_HAS_CONTENTS
) == 0)
2411 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2413 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2414 /* Version check. */
2415 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2416 /* Versions earlier than 3 emitted every copy of a psymbol. This
2417 causes the index to behave very poorly for certain requests. Version 3
2418 contained incomplete addrmap. So, it seems better to just ignore such
2422 static int warning_printed
= 0;
2423 if (!warning_printed
)
2425 warning (_("Skipping obsolete .gdb_index section in %s."),
2427 warning_printed
= 1;
2431 /* Index version 4 uses a different hash function than index version
2434 Versions earlier than 6 did not emit psymbols for inlined
2435 functions. Using these files will cause GDB not to be able to
2436 set breakpoints on inlined functions by name, so we ignore these
2437 indices unless the --use-deprecated-index-sections command line
2438 option was supplied. */
2439 if (version
< 6 && !use_deprecated_index_sections
)
2441 static int warning_printed
= 0;
2442 if (!warning_printed
)
2444 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2445 "--use-deprecated-index-sections to use them anyway"),
2447 warning_printed
= 1;
2451 /* Indexes with higher version than the one supported by GDB may be no
2452 longer backward compatible. */
2456 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2457 map
->version
= version
;
2458 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2460 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2463 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2464 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2468 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2469 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2470 - MAYBE_SWAP (metadata
[i
]))
2474 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2475 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2476 - MAYBE_SWAP (metadata
[i
]));
2479 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2480 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2481 - MAYBE_SWAP (metadata
[i
]))
2482 / (2 * sizeof (offset_type
)));
2485 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2487 /* Don't use the index if it's empty. */
2488 if (map
->symbol_table_slots
== 0)
2491 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2494 if (types_list_elements
)
2496 struct dwarf2_section_info
*section
;
2498 /* We can only handle a single .debug_types when we have an
2500 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2503 section
= VEC_index (dwarf2_section_info_def
,
2504 dwarf2_per_objfile
->types
, 0);
2506 if (!create_signatured_type_table_from_index (objfile
, section
,
2508 types_list_elements
))
2512 create_addrmap_from_index (objfile
, map
);
2514 dwarf2_per_objfile
->index_table
= map
;
2515 dwarf2_per_objfile
->using_index
= 1;
2516 dwarf2_per_objfile
->quick_file_names_table
=
2517 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2522 /* A helper for the "quick" functions which sets the global
2523 dwarf2_per_objfile according to OBJFILE. */
2526 dw2_setup (struct objfile
*objfile
)
2528 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2529 gdb_assert (dwarf2_per_objfile
);
2532 /* Reader function for dw2_build_type_unit_groups. */
2535 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2537 struct die_info
*type_unit_die
,
2541 struct dwarf2_cu
*cu
= reader
->cu
;
2542 struct attribute
*attr
;
2543 struct type_unit_group
*tu_group
;
2545 gdb_assert (data
== NULL
);
2550 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2551 /* Call this for its side-effect of creating the associated
2552 struct type_unit_group if it doesn't already exist. */
2553 tu_group
= get_type_unit_group (cu
, attr
);
2556 /* Build dwarf2_per_objfile->type_unit_groups.
2557 This function may be called multiple times. */
2560 dw2_build_type_unit_groups (void)
2562 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2563 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2566 /* die_reader_func for dw2_get_file_names. */
2569 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2571 struct die_info
*comp_unit_die
,
2575 struct dwarf2_cu
*cu
= reader
->cu
;
2576 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2577 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2578 struct dwarf2_per_cu_data
*lh_cu
;
2579 struct line_header
*lh
;
2580 struct attribute
*attr
;
2582 char *name
, *comp_dir
;
2584 struct quick_file_names
*qfn
;
2585 unsigned int line_offset
;
2587 /* Our callers never want to match partial units -- instead they
2588 will match the enclosing full CU. */
2589 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2591 this_cu
->v
.quick
->no_file_data
= 1;
2595 /* If we're reading the line header for TUs, store it in the "per_cu"
2597 if (this_cu
->is_debug_types
)
2599 struct type_unit_group
*tu_group
= data
;
2601 gdb_assert (tu_group
!= NULL
);
2602 lh_cu
= &tu_group
->per_cu
;
2611 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2614 struct quick_file_names find_entry
;
2616 line_offset
= DW_UNSND (attr
);
2618 /* We may have already read in this line header (TU line header sharing).
2619 If we have we're done. */
2620 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2621 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2622 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2623 &find_entry
, INSERT
);
2626 lh_cu
->v
.quick
->file_names
= *slot
;
2630 lh
= dwarf_decode_line_header (line_offset
, cu
);
2634 lh_cu
->v
.quick
->no_file_data
= 1;
2638 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2639 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2640 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2641 gdb_assert (slot
!= NULL
);
2644 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2646 qfn
->num_file_names
= lh
->num_file_names
;
2647 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2648 lh
->num_file_names
* sizeof (char *));
2649 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2650 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2651 qfn
->real_names
= NULL
;
2653 free_line_header (lh
);
2655 lh_cu
->v
.quick
->file_names
= qfn
;
2658 /* A helper for the "quick" functions which attempts to read the line
2659 table for THIS_CU. */
2661 static struct quick_file_names
*
2662 dw2_get_file_names (struct objfile
*objfile
,
2663 struct dwarf2_per_cu_data
*this_cu
)
2665 /* For TUs this should only be called on the parent group. */
2666 if (this_cu
->is_debug_types
)
2667 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2669 if (this_cu
->v
.quick
->file_names
!= NULL
)
2670 return this_cu
->v
.quick
->file_names
;
2671 /* If we know there is no line data, no point in looking again. */
2672 if (this_cu
->v
.quick
->no_file_data
)
2675 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2676 in the stub for CUs, there's is no need to lookup the DWO file.
2677 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2679 if (this_cu
->is_debug_types
)
2681 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2683 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2684 dw2_get_file_names_reader
, tu_group
);
2687 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2689 if (this_cu
->v
.quick
->no_file_data
)
2691 return this_cu
->v
.quick
->file_names
;
2694 /* A helper for the "quick" functions which computes and caches the
2695 real path for a given file name from the line table. */
2698 dw2_get_real_path (struct objfile
*objfile
,
2699 struct quick_file_names
*qfn
, int index
)
2701 if (qfn
->real_names
== NULL
)
2702 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2703 qfn
->num_file_names
, sizeof (char *));
2705 if (qfn
->real_names
[index
] == NULL
)
2706 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2708 return qfn
->real_names
[index
];
2711 static struct symtab
*
2712 dw2_find_last_source_symtab (struct objfile
*objfile
)
2716 dw2_setup (objfile
);
2717 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2718 return dw2_instantiate_symtab (dw2_get_cu (index
));
2721 /* Traversal function for dw2_forget_cached_source_info. */
2724 dw2_free_cached_file_names (void **slot
, void *info
)
2726 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2728 if (file_data
->real_names
)
2732 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2734 xfree ((void*) file_data
->real_names
[i
]);
2735 file_data
->real_names
[i
] = NULL
;
2743 dw2_forget_cached_source_info (struct objfile
*objfile
)
2745 dw2_setup (objfile
);
2747 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2748 dw2_free_cached_file_names
, NULL
);
2751 /* Helper function for dw2_map_symtabs_matching_filename that expands
2752 the symtabs and calls the iterator. */
2755 dw2_map_expand_apply (struct objfile
*objfile
,
2756 struct dwarf2_per_cu_data
*per_cu
,
2758 const char *full_path
, const char *real_path
,
2759 int (*callback
) (struct symtab
*, void *),
2762 struct symtab
*last_made
= objfile
->symtabs
;
2764 /* Don't visit already-expanded CUs. */
2765 if (per_cu
->v
.quick
->symtab
)
2768 /* This may expand more than one symtab, and we want to iterate over
2770 dw2_instantiate_symtab (per_cu
);
2772 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2773 objfile
->symtabs
, last_made
);
2776 /* Implementation of the map_symtabs_matching_filename method. */
2779 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2780 const char *full_path
, const char *real_path
,
2781 int (*callback
) (struct symtab
*, void *),
2785 const char *name_basename
= lbasename (name
);
2786 int name_len
= strlen (name
);
2787 int is_abs
= IS_ABSOLUTE_PATH (name
);
2789 dw2_setup (objfile
);
2791 dw2_build_type_unit_groups ();
2793 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2794 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
2797 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
2798 struct quick_file_names
*file_data
;
2800 /* We only need to look at symtabs not already expanded. */
2801 if (per_cu
->v
.quick
->symtab
)
2804 file_data
= dw2_get_file_names (objfile
, per_cu
);
2805 if (file_data
== NULL
)
2808 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2810 const char *this_name
= file_data
->file_names
[j
];
2812 if (FILENAME_CMP (name
, this_name
) == 0
2813 || (!is_abs
&& compare_filenames_for_search (this_name
,
2816 if (dw2_map_expand_apply (objfile
, per_cu
,
2817 name
, full_path
, real_path
,
2822 /* Before we invoke realpath, which can get expensive when many
2823 files are involved, do a quick comparison of the basenames. */
2824 if (! basenames_may_differ
2825 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2828 if (full_path
!= NULL
)
2830 const char *this_real_name
= dw2_get_real_path (objfile
,
2833 if (this_real_name
!= NULL
2834 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2836 && compare_filenames_for_search (this_real_name
,
2839 if (dw2_map_expand_apply (objfile
, per_cu
,
2840 name
, full_path
, real_path
,
2846 if (real_path
!= NULL
)
2848 const char *this_real_name
= dw2_get_real_path (objfile
,
2851 if (this_real_name
!= NULL
2852 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2854 && compare_filenames_for_search (this_real_name
,
2857 if (dw2_map_expand_apply (objfile
, per_cu
,
2858 name
, full_path
, real_path
,
2869 static struct symtab
*
2870 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2871 const char *name
, domain_enum domain
)
2873 /* We do all the work in the pre_expand_symtabs_matching hook
2878 /* A helper function that expands all symtabs that hold an object
2879 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
2880 symbols in block BLOCK_KIND. */
2883 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
2884 int want_specific_block
,
2885 enum block_enum block_kind
,
2886 const char *name
, domain_enum domain
)
2888 struct mapped_index
*index
;
2890 dw2_setup (objfile
);
2892 index
= dwarf2_per_objfile
->index_table
;
2894 /* index_table is NULL if OBJF_READNOW. */
2899 if (find_slot_in_mapped_hash (index
, name
, &vec
))
2901 offset_type i
, len
= MAYBE_SWAP (*vec
);
2902 for (i
= 0; i
< len
; ++i
)
2904 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
2905 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
2906 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2907 int want_static
= block_kind
!= GLOBAL_BLOCK
;
2908 /* This value is only valid for index versions >= 7. */
2909 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
2910 gdb_index_symbol_kind symbol_kind
=
2911 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
2913 if (want_specific_block
2914 && index
->version
>= 7
2915 && want_static
!= is_static
)
2918 /* Only check the symbol's kind if it has one.
2919 Indices prior to version 7 don't record it. */
2920 if (index
->version
>= 7)
2925 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
2926 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
2927 /* Some types are also in VAR_DOMAIN. */
2928 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2932 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2936 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
2944 dw2_instantiate_symtab (per_cu
);
2951 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2952 enum block_enum block_kind
, const char *name
,
2955 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
2959 dw2_print_stats (struct objfile
*objfile
)
2963 dw2_setup (objfile
);
2965 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2966 + dwarf2_per_objfile
->n_type_units
); ++i
)
2968 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2970 if (!per_cu
->v
.quick
->symtab
)
2973 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2977 dw2_dump (struct objfile
*objfile
)
2979 /* Nothing worth printing. */
2983 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2984 struct section_offsets
*delta
)
2986 /* There's nothing to relocate here. */
2990 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2991 const char *func_name
)
2993 /* Note: It doesn't matter what we pass for block_kind here. */
2994 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
2999 dw2_expand_all_symtabs (struct objfile
*objfile
)
3003 dw2_setup (objfile
);
3005 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3006 + dwarf2_per_objfile
->n_type_units
); ++i
)
3008 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3010 dw2_instantiate_symtab (per_cu
);
3015 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3016 const char *filename
)
3020 dw2_setup (objfile
);
3022 /* We don't need to consider type units here.
3023 This is only called for examining code, e.g. expand_line_sal.
3024 There can be an order of magnitude (or more) more type units
3025 than comp units, and we avoid them if we can. */
3027 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3030 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3031 struct quick_file_names
*file_data
;
3033 /* We only need to look at symtabs not already expanded. */
3034 if (per_cu
->v
.quick
->symtab
)
3037 file_data
= dw2_get_file_names (objfile
, per_cu
);
3038 if (file_data
== NULL
)
3041 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3043 const char *this_name
= file_data
->file_names
[j
];
3044 if (FILENAME_CMP (this_name
, filename
) == 0)
3046 dw2_instantiate_symtab (per_cu
);
3053 /* A helper function for dw2_find_symbol_file that finds the primary
3054 file name for a given CU. This is a die_reader_func. */
3057 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3059 struct die_info
*comp_unit_die
,
3063 const char **result_ptr
= data
;
3064 struct dwarf2_cu
*cu
= reader
->cu
;
3065 struct attribute
*attr
;
3067 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3071 *result_ptr
= DW_STRING (attr
);
3075 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3077 struct dwarf2_per_cu_data
*per_cu
;
3079 struct quick_file_names
*file_data
;
3080 const char *filename
;
3082 dw2_setup (objfile
);
3084 /* index_table is NULL if OBJF_READNOW. */
3085 if (!dwarf2_per_objfile
->index_table
)
3089 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3091 struct blockvector
*bv
= BLOCKVECTOR (s
);
3092 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3093 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3096 return sym
->symtab
->filename
;
3101 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3105 /* Note that this just looks at the very first one named NAME -- but
3106 actually we are looking for a function. find_main_filename
3107 should be rewritten so that it doesn't require a custom hook. It
3108 could just use the ordinary symbol tables. */
3109 /* vec[0] is the length, which must always be >0. */
3110 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3112 if (per_cu
->v
.quick
->symtab
!= NULL
)
3113 return per_cu
->v
.quick
->symtab
->filename
;
3115 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3116 dw2_get_primary_filename_reader
, &filename
);
3122 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3123 struct objfile
*objfile
, int global
,
3124 int (*callback
) (struct block
*,
3125 struct symbol
*, void *),
3126 void *data
, symbol_compare_ftype
*match
,
3127 symbol_compare_ftype
*ordered_compare
)
3129 /* Currently unimplemented; used for Ada. The function can be called if the
3130 current language is Ada for a non-Ada objfile using GNU index. As Ada
3131 does not look for non-Ada symbols this function should just return. */
3135 dw2_expand_symtabs_matching
3136 (struct objfile
*objfile
,
3137 int (*file_matcher
) (const char *, void *),
3138 int (*name_matcher
) (const char *, void *),
3139 enum search_domain kind
,
3144 struct mapped_index
*index
;
3146 dw2_setup (objfile
);
3148 /* index_table is NULL if OBJF_READNOW. */
3149 if (!dwarf2_per_objfile
->index_table
)
3151 index
= dwarf2_per_objfile
->index_table
;
3153 if (file_matcher
!= NULL
)
3155 struct cleanup
*cleanup
;
3156 htab_t visited_found
, visited_not_found
;
3158 dw2_build_type_unit_groups ();
3160 visited_found
= htab_create_alloc (10,
3161 htab_hash_pointer
, htab_eq_pointer
,
3162 NULL
, xcalloc
, xfree
);
3163 cleanup
= make_cleanup_htab_delete (visited_found
);
3164 visited_not_found
= htab_create_alloc (10,
3165 htab_hash_pointer
, htab_eq_pointer
,
3166 NULL
, xcalloc
, xfree
);
3167 make_cleanup_htab_delete (visited_not_found
);
3169 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3170 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3173 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3174 struct quick_file_names
*file_data
;
3177 per_cu
->v
.quick
->mark
= 0;
3179 /* We only need to look at symtabs not already expanded. */
3180 if (per_cu
->v
.quick
->symtab
)
3183 file_data
= dw2_get_file_names (objfile
, per_cu
);
3184 if (file_data
== NULL
)
3187 if (htab_find (visited_not_found
, file_data
) != NULL
)
3189 else if (htab_find (visited_found
, file_data
) != NULL
)
3191 per_cu
->v
.quick
->mark
= 1;
3195 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3197 if (file_matcher (file_data
->file_names
[j
], data
))
3199 per_cu
->v
.quick
->mark
= 1;
3204 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3206 : visited_not_found
,
3211 do_cleanups (cleanup
);
3214 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3216 offset_type idx
= 2 * iter
;
3218 offset_type
*vec
, vec_len
, vec_idx
;
3220 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3223 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3225 if (! (*name_matcher
) (name
, data
))
3228 /* The name was matched, now expand corresponding CUs that were
3230 vec
= (offset_type
*) (index
->constant_pool
3231 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3232 vec_len
= MAYBE_SWAP (vec
[0]);
3233 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3235 struct dwarf2_per_cu_data
*per_cu
;
3236 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3237 gdb_index_symbol_kind symbol_kind
=
3238 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3239 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3241 /* Don't crash on bad data. */
3242 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3243 + dwarf2_per_objfile
->n_type_units
))
3246 /* Only check the symbol's kind if it has one.
3247 Indices prior to version 7 don't record it. */
3248 if (index
->version
>= 7)
3252 case VARIABLES_DOMAIN
:
3253 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3256 case FUNCTIONS_DOMAIN
:
3257 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3261 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3269 per_cu
= dw2_get_cu (cu_index
);
3270 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3271 dw2_instantiate_symtab (per_cu
);
3276 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3279 static struct symtab
*
3280 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3284 if (BLOCKVECTOR (symtab
) != NULL
3285 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3288 if (symtab
->includes
== NULL
)
3291 for (i
= 0; symtab
->includes
[i
]; ++i
)
3293 struct symtab
*s
= symtab
->includes
[i
];
3295 s
= recursively_find_pc_sect_symtab (s
, pc
);
3303 static struct symtab
*
3304 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3305 struct minimal_symbol
*msymbol
,
3307 struct obj_section
*section
,
3310 struct dwarf2_per_cu_data
*data
;
3311 struct symtab
*result
;
3313 dw2_setup (objfile
);
3315 if (!objfile
->psymtabs_addrmap
)
3318 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3322 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3323 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3324 paddress (get_objfile_arch (objfile
), pc
));
3326 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3327 gdb_assert (result
!= NULL
);
3332 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3333 void *data
, int need_fullname
)
3336 struct cleanup
*cleanup
;
3337 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3338 NULL
, xcalloc
, xfree
);
3340 cleanup
= make_cleanup_htab_delete (visited
);
3341 dw2_setup (objfile
);
3343 dw2_build_type_unit_groups ();
3345 /* We can ignore file names coming from already-expanded CUs. */
3346 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3347 + dwarf2_per_objfile
->n_type_units
); ++i
)
3349 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3351 if (per_cu
->v
.quick
->symtab
)
3353 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3356 *slot
= per_cu
->v
.quick
->file_names
;
3360 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3361 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3364 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3365 struct quick_file_names
*file_data
;
3368 /* We only need to look at symtabs not already expanded. */
3369 if (per_cu
->v
.quick
->symtab
)
3372 file_data
= dw2_get_file_names (objfile
, per_cu
);
3373 if (file_data
== NULL
)
3376 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3379 /* Already visited. */
3384 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3386 const char *this_real_name
;
3389 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3391 this_real_name
= NULL
;
3392 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3396 do_cleanups (cleanup
);
3400 dw2_has_symbols (struct objfile
*objfile
)
3405 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3408 dw2_find_last_source_symtab
,
3409 dw2_forget_cached_source_info
,
3410 dw2_map_symtabs_matching_filename
,
3412 dw2_pre_expand_symtabs_matching
,
3416 dw2_expand_symtabs_for_function
,
3417 dw2_expand_all_symtabs
,
3418 dw2_expand_symtabs_with_filename
,
3419 dw2_find_symbol_file
,
3420 dw2_map_matching_symbols
,
3421 dw2_expand_symtabs_matching
,
3422 dw2_find_pc_sect_symtab
,
3423 dw2_map_symbol_filenames
3426 /* Initialize for reading DWARF for this objfile. Return 0 if this
3427 file will use psymtabs, or 1 if using the GNU index. */
3430 dwarf2_initialize_objfile (struct objfile
*objfile
)
3432 /* If we're about to read full symbols, don't bother with the
3433 indices. In this case we also don't care if some other debug
3434 format is making psymtabs, because they are all about to be
3436 if ((objfile
->flags
& OBJF_READNOW
))
3440 dwarf2_per_objfile
->using_index
= 1;
3441 create_all_comp_units (objfile
);
3442 create_all_type_units (objfile
);
3443 dwarf2_per_objfile
->quick_file_names_table
=
3444 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3446 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3447 + dwarf2_per_objfile
->n_type_units
); ++i
)
3449 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3451 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3452 struct dwarf2_per_cu_quick_data
);
3455 /* Return 1 so that gdb sees the "quick" functions. However,
3456 these functions will be no-ops because we will have expanded
3461 if (dwarf2_read_index (objfile
))
3469 /* Build a partial symbol table. */
3472 dwarf2_build_psymtabs (struct objfile
*objfile
)
3474 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3476 init_psymbol_list (objfile
, 1024);
3479 dwarf2_build_psymtabs_hard (objfile
);
3482 /* Return the total length of the CU described by HEADER. */
3485 get_cu_length (const struct comp_unit_head
*header
)
3487 return header
->initial_length_size
+ header
->length
;
3490 /* Return TRUE if OFFSET is within CU_HEADER. */
3493 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3495 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3496 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3498 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3501 /* Find the base address of the compilation unit for range lists and
3502 location lists. It will normally be specified by DW_AT_low_pc.
3503 In DWARF-3 draft 4, the base address could be overridden by
3504 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3505 compilation units with discontinuous ranges. */
3508 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3510 struct attribute
*attr
;
3513 cu
->base_address
= 0;
3515 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3518 cu
->base_address
= DW_ADDR (attr
);
3523 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3526 cu
->base_address
= DW_ADDR (attr
);
3532 /* Read in the comp unit header information from the debug_info at info_ptr.
3533 NOTE: This leaves members offset, first_die_offset to be filled in
3537 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3538 gdb_byte
*info_ptr
, bfd
*abfd
)
3541 unsigned int bytes_read
;
3543 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3544 cu_header
->initial_length_size
= bytes_read
;
3545 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3546 info_ptr
+= bytes_read
;
3547 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3549 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3551 info_ptr
+= bytes_read
;
3552 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3554 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3555 if (signed_addr
< 0)
3556 internal_error (__FILE__
, __LINE__
,
3557 _("read_comp_unit_head: dwarf from non elf file"));
3558 cu_header
->signed_addr_p
= signed_addr
;
3563 /* Subroutine of read_and_check_comp_unit_head and
3564 read_and_check_type_unit_head to simplify them.
3565 Perform various error checking on the header. */
3568 error_check_comp_unit_head (struct comp_unit_head
*header
,
3569 struct dwarf2_section_info
*section
,
3570 struct dwarf2_section_info
*abbrev_section
)
3572 bfd
*abfd
= section
->asection
->owner
;
3573 const char *filename
= bfd_get_filename (abfd
);
3575 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3576 error (_("Dwarf Error: wrong version in compilation unit header "
3577 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3580 if (header
->abbrev_offset
.sect_off
3581 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3582 &dwarf2_per_objfile
->abbrev
))
3583 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3584 "(offset 0x%lx + 6) [in module %s]"),
3585 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3588 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3589 avoid potential 32-bit overflow. */
3590 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3592 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3593 "(offset 0x%lx + 0) [in module %s]"),
3594 (long) header
->length
, (long) header
->offset
.sect_off
,
3598 /* Read in a CU/TU header and perform some basic error checking.
3599 The contents of the header are stored in HEADER.
3600 The result is a pointer to the start of the first DIE. */
3603 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3604 struct dwarf2_section_info
*section
,
3605 struct dwarf2_section_info
*abbrev_section
,
3607 int is_debug_types_section
)
3609 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3610 bfd
*abfd
= section
->asection
->owner
;
3612 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3614 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3616 /* If we're reading a type unit, skip over the signature and
3617 type_offset fields. */
3618 if (is_debug_types_section
)
3619 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3621 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3623 error_check_comp_unit_head (header
, section
, abbrev_section
);
3628 /* Read in the types comp unit header information from .debug_types entry at
3629 types_ptr. The result is a pointer to one past the end of the header. */
3632 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3633 struct dwarf2_section_info
*section
,
3634 struct dwarf2_section_info
*abbrev_section
,
3636 ULONGEST
*signature
,
3637 cu_offset
*type_offset_in_tu
)
3639 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3640 bfd
*abfd
= section
->asection
->owner
;
3642 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3644 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3646 /* If we're reading a type unit, skip over the signature and
3647 type_offset fields. */
3648 if (signature
!= NULL
)
3649 *signature
= read_8_bytes (abfd
, info_ptr
);
3651 if (type_offset_in_tu
!= NULL
)
3652 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3653 header
->offset_size
);
3654 info_ptr
+= header
->offset_size
;
3656 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3658 error_check_comp_unit_head (header
, section
, abbrev_section
);
3663 /* Fetch the abbreviation table offset from a comp or type unit header. */
3666 read_abbrev_offset (struct dwarf2_section_info
*section
,
3669 bfd
*abfd
= section
->asection
->owner
;
3671 unsigned int length
, initial_length_size
, offset_size
;
3672 sect_offset abbrev_offset
;
3674 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3675 info_ptr
= section
->buffer
+ offset
.sect_off
;
3676 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3677 offset_size
= initial_length_size
== 4 ? 4 : 8;
3678 info_ptr
+= initial_length_size
+ 2 /*version*/;
3679 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
3680 return abbrev_offset
;
3683 /* Allocate a new partial symtab for file named NAME and mark this new
3684 partial symtab as being an include of PST. */
3687 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3688 struct objfile
*objfile
)
3690 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3692 subpst
->section_offsets
= pst
->section_offsets
;
3693 subpst
->textlow
= 0;
3694 subpst
->texthigh
= 0;
3696 subpst
->dependencies
= (struct partial_symtab
**)
3697 obstack_alloc (&objfile
->objfile_obstack
,
3698 sizeof (struct partial_symtab
*));
3699 subpst
->dependencies
[0] = pst
;
3700 subpst
->number_of_dependencies
= 1;
3702 subpst
->globals_offset
= 0;
3703 subpst
->n_global_syms
= 0;
3704 subpst
->statics_offset
= 0;
3705 subpst
->n_static_syms
= 0;
3706 subpst
->symtab
= NULL
;
3707 subpst
->read_symtab
= pst
->read_symtab
;
3710 /* No private part is necessary for include psymtabs. This property
3711 can be used to differentiate between such include psymtabs and
3712 the regular ones. */
3713 subpst
->read_symtab_private
= NULL
;
3716 /* Read the Line Number Program data and extract the list of files
3717 included by the source file represented by PST. Build an include
3718 partial symtab for each of these included files. */
3721 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3722 struct die_info
*die
,
3723 struct partial_symtab
*pst
)
3725 struct line_header
*lh
= NULL
;
3726 struct attribute
*attr
;
3728 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3730 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3732 return; /* No linetable, so no includes. */
3734 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3735 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3737 free_line_header (lh
);
3741 hash_signatured_type (const void *item
)
3743 const struct signatured_type
*sig_type
= item
;
3745 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3746 return sig_type
->signature
;
3750 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3752 const struct signatured_type
*lhs
= item_lhs
;
3753 const struct signatured_type
*rhs
= item_rhs
;
3755 return lhs
->signature
== rhs
->signature
;
3758 /* Allocate a hash table for signatured types. */
3761 allocate_signatured_type_table (struct objfile
*objfile
)
3763 return htab_create_alloc_ex (41,
3764 hash_signatured_type
,
3767 &objfile
->objfile_obstack
,
3768 hashtab_obstack_allocate
,
3769 dummy_obstack_deallocate
);
3772 /* A helper function to add a signatured type CU to a table. */
3775 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3777 struct signatured_type
*sigt
= *slot
;
3778 struct signatured_type
***datap
= datum
;
3786 /* Create the hash table of all entries in the .debug_types section.
3787 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3788 The result is a pointer to the hash table or NULL if there are
3792 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3793 VEC (dwarf2_section_info_def
) *types
)
3795 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3796 htab_t types_htab
= NULL
;
3798 struct dwarf2_section_info
*section
;
3799 struct dwarf2_section_info
*abbrev_section
;
3801 if (VEC_empty (dwarf2_section_info_def
, types
))
3804 abbrev_section
= (dwo_file
!= NULL
3805 ? &dwo_file
->sections
.abbrev
3806 : &dwarf2_per_objfile
->abbrev
);
3808 if (dwarf2_read_debug
)
3809 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
3810 dwo_file
? ".dwo" : "",
3811 bfd_get_filename (abbrev_section
->asection
->owner
));
3814 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3818 gdb_byte
*info_ptr
, *end_ptr
;
3820 dwarf2_read_section (objfile
, section
);
3821 info_ptr
= section
->buffer
;
3823 if (info_ptr
== NULL
)
3826 /* We can't set abfd until now because the section may be empty or
3827 not present, in which case section->asection will be NULL. */
3828 abfd
= section
->asection
->owner
;
3830 if (types_htab
== NULL
)
3833 types_htab
= allocate_dwo_unit_table (objfile
);
3835 types_htab
= allocate_signatured_type_table (objfile
);
3838 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3839 because we don't need to read any dies: the signature is in the
3842 end_ptr
= info_ptr
+ section
->size
;
3843 while (info_ptr
< end_ptr
)
3846 cu_offset type_offset_in_tu
;
3848 struct signatured_type
*sig_type
;
3849 struct dwo_unit
*dwo_tu
;
3851 gdb_byte
*ptr
= info_ptr
;
3852 struct comp_unit_head header
;
3853 unsigned int length
;
3855 offset
.sect_off
= ptr
- section
->buffer
;
3857 /* We need to read the type's signature in order to build the hash
3858 table, but we don't need anything else just yet. */
3860 ptr
= read_and_check_type_unit_head (&header
, section
,
3861 abbrev_section
, ptr
,
3862 &signature
, &type_offset_in_tu
);
3864 length
= get_cu_length (&header
);
3866 /* Skip dummy type units. */
3867 if (ptr
>= info_ptr
+ length
3868 || peek_abbrev_code (abfd
, ptr
) == 0)
3877 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3879 dwo_tu
->dwo_file
= dwo_file
;
3880 dwo_tu
->signature
= signature
;
3881 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3882 dwo_tu
->info_or_types_section
= section
;
3883 dwo_tu
->offset
= offset
;
3884 dwo_tu
->length
= length
;
3888 /* N.B.: type_offset is not usable if this type uses a DWO file.
3889 The real type_offset is in the DWO file. */
3891 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3892 struct signatured_type
);
3893 sig_type
->signature
= signature
;
3894 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3895 sig_type
->per_cu
.objfile
= objfile
;
3896 sig_type
->per_cu
.is_debug_types
= 1;
3897 sig_type
->per_cu
.info_or_types_section
= section
;
3898 sig_type
->per_cu
.offset
= offset
;
3899 sig_type
->per_cu
.length
= length
;
3902 slot
= htab_find_slot (types_htab
,
3903 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3905 gdb_assert (slot
!= NULL
);
3908 sect_offset dup_offset
;
3912 const struct dwo_unit
*dup_tu
= *slot
;
3914 dup_offset
= dup_tu
->offset
;
3918 const struct signatured_type
*dup_tu
= *slot
;
3920 dup_offset
= dup_tu
->per_cu
.offset
;
3923 complaint (&symfile_complaints
,
3924 _("debug type entry at offset 0x%x is duplicate to the "
3925 "entry at offset 0x%x, signature 0x%s"),
3926 offset
.sect_off
, dup_offset
.sect_off
,
3927 phex (signature
, sizeof (signature
)));
3929 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3931 if (dwarf2_read_debug
)
3932 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3934 phex (signature
, sizeof (signature
)));
3943 /* Create the hash table of all entries in the .debug_types section,
3944 and initialize all_type_units.
3945 The result is zero if there is an error (e.g. missing .debug_types section),
3946 otherwise non-zero. */
3949 create_all_type_units (struct objfile
*objfile
)
3952 struct signatured_type
**iter
;
3954 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3955 if (types_htab
== NULL
)
3957 dwarf2_per_objfile
->signatured_types
= NULL
;
3961 dwarf2_per_objfile
->signatured_types
= types_htab
;
3963 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3964 dwarf2_per_objfile
->all_type_units
3965 = obstack_alloc (&objfile
->objfile_obstack
,
3966 dwarf2_per_objfile
->n_type_units
3967 * sizeof (struct signatured_type
*));
3968 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3969 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3970 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3971 == dwarf2_per_objfile
->n_type_units
);
3976 /* Lookup a signature based type for DW_FORM_ref_sig8.
3977 Returns NULL if signature SIG is not present in the table. */
3979 static struct signatured_type
*
3980 lookup_signatured_type (ULONGEST sig
)
3982 struct signatured_type find_entry
, *entry
;
3984 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3986 complaint (&symfile_complaints
,
3987 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3991 find_entry
.signature
= sig
;
3992 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3996 /* Low level DIE reading support. */
3998 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4001 init_cu_die_reader (struct die_reader_specs
*reader
,
4002 struct dwarf2_cu
*cu
,
4003 struct dwarf2_section_info
*section
,
4004 struct dwo_file
*dwo_file
)
4006 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4007 reader
->abfd
= section
->asection
->owner
;
4009 reader
->dwo_file
= dwo_file
;
4010 reader
->die_section
= section
;
4011 reader
->buffer
= section
->buffer
;
4012 reader
->buffer_end
= section
->buffer
+ section
->size
;
4015 /* Initialize a CU (or TU) and read its DIEs.
4016 If the CU defers to a DWO file, read the DWO file as well.
4018 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4019 Otherwise the table specified in the comp unit header is read in and used.
4020 This is an optimization for when we already have the abbrev table.
4022 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4023 Otherwise, a new CU is allocated with xmalloc.
4025 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4026 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4028 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4029 linker) then DIE_READER_FUNC will not get called. */
4032 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4033 struct abbrev_table
*abbrev_table
,
4034 int use_existing_cu
, int keep
,
4035 die_reader_func_ftype
*die_reader_func
,
4038 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4039 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4040 bfd
*abfd
= section
->asection
->owner
;
4041 struct dwarf2_cu
*cu
;
4042 gdb_byte
*begin_info_ptr
, *info_ptr
;
4043 struct die_reader_specs reader
;
4044 struct die_info
*comp_unit_die
;
4046 struct attribute
*attr
;
4047 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4048 struct signatured_type
*sig_type
= NULL
;
4049 struct dwarf2_section_info
*abbrev_section
;
4050 /* Non-zero if CU currently points to a DWO file and we need to
4051 reread it. When this happens we need to reread the skeleton die
4052 before we can reread the DWO file. */
4053 int rereading_dwo_cu
= 0;
4055 if (dwarf2_die_debug
)
4056 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4057 this_cu
->is_debug_types
? "type" : "comp",
4058 this_cu
->offset
.sect_off
);
4060 if (use_existing_cu
)
4063 cleanups
= make_cleanup (null_cleanup
, NULL
);
4065 /* This is cheap if the section is already read in. */
4066 dwarf2_read_section (objfile
, section
);
4068 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4069 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4071 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4075 /* If this CU is from a DWO file we need to start over, we need to
4076 refetch the attributes from the skeleton CU.
4077 This could be optimized by retrieving those attributes from when we
4078 were here the first time: the previous comp_unit_die was stored in
4079 comp_unit_obstack. But there's no data yet that we need this
4081 if (cu
->dwo_unit
!= NULL
)
4082 rereading_dwo_cu
= 1;
4086 /* If !use_existing_cu, this_cu->cu must be NULL. */
4087 gdb_assert (this_cu
->cu
== NULL
);
4089 cu
= xmalloc (sizeof (*cu
));
4090 init_one_comp_unit (cu
, this_cu
);
4092 /* If an error occurs while loading, release our storage. */
4093 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4096 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4098 /* We already have the header, there's no need to read it in again. */
4099 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4103 if (this_cu
->is_debug_types
)
4106 cu_offset type_offset_in_tu
;
4108 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4109 abbrev_section
, info_ptr
,
4111 &type_offset_in_tu
);
4113 /* Since per_cu is the first member of struct signatured_type,
4114 we can go from a pointer to one to a pointer to the other. */
4115 sig_type
= (struct signatured_type
*) this_cu
;
4116 gdb_assert (sig_type
->signature
== signature
);
4117 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4118 == type_offset_in_tu
.cu_off
);
4119 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4121 /* LENGTH has not been set yet for type units if we're
4122 using .gdb_index. */
4123 this_cu
->length
= get_cu_length (&cu
->header
);
4125 /* Establish the type offset that can be used to lookup the type. */
4126 sig_type
->type_offset_in_section
.sect_off
=
4127 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4131 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4135 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4136 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4140 /* Skip dummy compilation units. */
4141 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4142 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4144 do_cleanups (cleanups
);
4148 /* If we don't have them yet, read the abbrevs for this compilation unit.
4149 And if we need to read them now, make sure they're freed when we're
4150 done. Note that it's important that if the CU had an abbrev table
4151 on entry we don't free it when we're done: Somewhere up the call stack
4152 it may be in use. */
4153 if (abbrev_table
!= NULL
)
4155 gdb_assert (cu
->abbrev_table
== NULL
);
4156 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4157 == abbrev_table
->offset
.sect_off
);
4158 cu
->abbrev_table
= abbrev_table
;
4160 else if (cu
->abbrev_table
== NULL
)
4162 dwarf2_read_abbrevs (cu
, abbrev_section
);
4163 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4165 else if (rereading_dwo_cu
)
4167 dwarf2_free_abbrev_table (cu
);
4168 dwarf2_read_abbrevs (cu
, abbrev_section
);
4171 /* Read the top level CU/TU die. */
4172 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4173 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4175 /* If we have a DWO stub, process it and then read in the DWO file.
4176 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4177 a DWO CU, that this test will fail. */
4178 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4181 char *dwo_name
= DW_STRING (attr
);
4182 const char *comp_dir_string
;
4183 struct dwo_unit
*dwo_unit
;
4184 ULONGEST signature
; /* Or dwo_id. */
4185 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4186 int i
,num_extra_attrs
;
4187 struct dwarf2_section_info
*dwo_abbrev_section
;
4190 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4191 " has children (offset 0x%x) [in module %s]"),
4192 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4194 /* These attributes aren't processed until later:
4195 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4196 However, the attribute is found in the stub which we won't have later.
4197 In order to not impose this complication on the rest of the code,
4198 we read them here and copy them to the DWO CU/TU die. */
4200 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4203 if (! this_cu
->is_debug_types
)
4204 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4205 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4206 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4207 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4208 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4210 /* There should be a DW_AT_addr_base attribute here (if needed).
4211 We need the value before we can process DW_FORM_GNU_addr_index. */
4213 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4215 cu
->addr_base
= DW_UNSND (attr
);
4217 /* There should be a DW_AT_ranges_base attribute here (if needed).
4218 We need the value before we can process DW_AT_ranges. */
4219 cu
->ranges_base
= 0;
4220 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4222 cu
->ranges_base
= DW_UNSND (attr
);
4224 if (this_cu
->is_debug_types
)
4226 gdb_assert (sig_type
!= NULL
);
4227 signature
= sig_type
->signature
;
4231 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4233 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4235 signature
= DW_UNSND (attr
);
4238 /* We may need the comp_dir in order to find the DWO file. */
4239 comp_dir_string
= NULL
;
4241 comp_dir_string
= DW_STRING (comp_dir
);
4243 if (this_cu
->is_debug_types
)
4244 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4246 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4249 if (dwo_unit
== NULL
)
4251 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4252 " with ID %s [in module %s]"),
4253 this_cu
->offset
.sect_off
,
4254 phex (signature
, sizeof (signature
)),
4258 /* Set up for reading the DWO CU/TU. */
4259 cu
->dwo_unit
= dwo_unit
;
4260 section
= dwo_unit
->info_or_types_section
;
4261 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4262 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4263 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4265 if (this_cu
->is_debug_types
)
4269 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4273 gdb_assert (sig_type
->signature
== signature
);
4274 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4275 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4277 /* Establish the type offset that can be used to lookup the type.
4278 For DWO files, we don't know it until now. */
4279 sig_type
->type_offset_in_section
.sect_off
=
4280 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4284 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4287 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4288 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4291 /* Discard the original CU's abbrev table, and read the DWO's. */
4292 if (abbrev_table
== NULL
)
4294 dwarf2_free_abbrev_table (cu
);
4295 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4299 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4300 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4303 /* Read in the die, but leave space to copy over the attributes
4304 from the stub. This has the benefit of simplifying the rest of
4305 the code - all the real work is done here. */
4306 num_extra_attrs
= ((stmt_list
!= NULL
)
4310 + (comp_dir
!= NULL
));
4311 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4312 &has_children
, num_extra_attrs
);
4314 /* Copy over the attributes from the stub to the DWO die. */
4315 i
= comp_unit_die
->num_attrs
;
4316 if (stmt_list
!= NULL
)
4317 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4319 comp_unit_die
->attrs
[i
++] = *low_pc
;
4320 if (high_pc
!= NULL
)
4321 comp_unit_die
->attrs
[i
++] = *high_pc
;
4323 comp_unit_die
->attrs
[i
++] = *ranges
;
4324 if (comp_dir
!= NULL
)
4325 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4326 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4328 /* Skip dummy compilation units. */
4329 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4330 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4332 do_cleanups (cleanups
);
4337 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4339 if (free_cu_cleanup
!= NULL
)
4343 /* We've successfully allocated this compilation unit. Let our
4344 caller clean it up when finished with it. */
4345 discard_cleanups (free_cu_cleanup
);
4347 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4348 So we have to manually free the abbrev table. */
4349 dwarf2_free_abbrev_table (cu
);
4351 /* Link this CU into read_in_chain. */
4352 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4353 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4356 do_cleanups (free_cu_cleanup
);
4359 do_cleanups (cleanups
);
4362 /* Read CU/TU THIS_CU in section SECTION,
4363 but do not follow DW_AT_GNU_dwo_name if present.
4364 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4365 have already done the lookup to find the DWO file).
4367 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4368 THIS_CU->is_debug_types, but nothing else.
4370 We fill in THIS_CU->length.
4372 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4373 linker) then DIE_READER_FUNC will not get called.
4375 THIS_CU->cu is always freed when done.
4376 This is done in order to not leave THIS_CU->cu in a state where we have
4377 to care whether it refers to the "main" CU or the DWO CU. */
4380 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4381 struct dwarf2_section_info
*abbrev_section
,
4382 struct dwo_file
*dwo_file
,
4383 die_reader_func_ftype
*die_reader_func
,
4386 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4387 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4388 bfd
*abfd
= section
->asection
->owner
;
4389 struct dwarf2_cu cu
;
4390 gdb_byte
*begin_info_ptr
, *info_ptr
;
4391 struct die_reader_specs reader
;
4392 struct cleanup
*cleanups
;
4393 struct die_info
*comp_unit_die
;
4396 if (dwarf2_die_debug
)
4397 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4398 this_cu
->is_debug_types
? "type" : "comp",
4399 this_cu
->offset
.sect_off
);
4401 gdb_assert (this_cu
->cu
== NULL
);
4403 /* This is cheap if the section is already read in. */
4404 dwarf2_read_section (objfile
, section
);
4406 init_one_comp_unit (&cu
, this_cu
);
4408 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4410 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4411 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4412 abbrev_section
, info_ptr
,
4413 this_cu
->is_debug_types
);
4415 this_cu
->length
= get_cu_length (&cu
.header
);
4417 /* Skip dummy compilation units. */
4418 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4419 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4421 do_cleanups (cleanups
);
4425 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4426 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4428 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4429 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4431 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4433 do_cleanups (cleanups
);
4436 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4437 does not lookup the specified DWO file.
4438 This cannot be used to read DWO files.
4440 THIS_CU->cu is always freed when done.
4441 This is done in order to not leave THIS_CU->cu in a state where we have
4442 to care whether it refers to the "main" CU or the DWO CU.
4443 We can revisit this if the data shows there's a performance issue. */
4446 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4447 die_reader_func_ftype
*die_reader_func
,
4450 init_cutu_and_read_dies_no_follow (this_cu
,
4451 &dwarf2_per_objfile
->abbrev
,
4453 die_reader_func
, data
);
4456 /* Create a psymtab named NAME and assign it to PER_CU.
4458 The caller must fill in the following details:
4459 dirname, textlow, texthigh. */
4461 static struct partial_symtab
*
4462 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4464 struct objfile
*objfile
= per_cu
->objfile
;
4465 struct partial_symtab
*pst
;
4467 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4469 objfile
->global_psymbols
.next
,
4470 objfile
->static_psymbols
.next
);
4472 pst
->psymtabs_addrmap_supported
= 1;
4474 /* This is the glue that links PST into GDB's symbol API. */
4475 pst
->read_symtab_private
= per_cu
;
4476 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4477 per_cu
->v
.psymtab
= pst
;
4482 /* die_reader_func for process_psymtab_comp_unit. */
4485 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4487 struct die_info
*comp_unit_die
,
4491 struct dwarf2_cu
*cu
= reader
->cu
;
4492 struct objfile
*objfile
= cu
->objfile
;
4493 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4494 struct attribute
*attr
;
4496 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4497 struct partial_symtab
*pst
;
4499 const char *filename
;
4500 int *want_partial_unit_ptr
= data
;
4502 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4503 && (want_partial_unit_ptr
== NULL
4504 || !*want_partial_unit_ptr
))
4507 gdb_assert (! per_cu
->is_debug_types
);
4509 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4511 cu
->list_in_scope
= &file_symbols
;
4513 /* Allocate a new partial symbol table structure. */
4514 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4515 if (attr
== NULL
|| !DW_STRING (attr
))
4518 filename
= DW_STRING (attr
);
4520 pst
= create_partial_symtab (per_cu
, filename
);
4522 /* This must be done before calling dwarf2_build_include_psymtabs. */
4523 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4525 pst
->dirname
= DW_STRING (attr
);
4527 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4529 dwarf2_find_base_address (comp_unit_die
, cu
);
4531 /* Possibly set the default values of LOWPC and HIGHPC from
4533 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4534 &best_highpc
, cu
, pst
);
4535 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4536 /* Store the contiguous range if it is not empty; it can be empty for
4537 CUs with no code. */
4538 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4539 best_lowpc
+ baseaddr
,
4540 best_highpc
+ baseaddr
- 1, pst
);
4542 /* Check if comp unit has_children.
4543 If so, read the rest of the partial symbols from this comp unit.
4544 If not, there's no more debug_info for this comp unit. */
4547 struct partial_die_info
*first_die
;
4548 CORE_ADDR lowpc
, highpc
;
4550 lowpc
= ((CORE_ADDR
) -1);
4551 highpc
= ((CORE_ADDR
) 0);
4553 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4555 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4558 /* If we didn't find a lowpc, set it to highpc to avoid
4559 complaints from `maint check'. */
4560 if (lowpc
== ((CORE_ADDR
) -1))
4563 /* If the compilation unit didn't have an explicit address range,
4564 then use the information extracted from its child dies. */
4568 best_highpc
= highpc
;
4571 pst
->textlow
= best_lowpc
+ baseaddr
;
4572 pst
->texthigh
= best_highpc
+ baseaddr
;
4574 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4575 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4576 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4577 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4578 sort_pst_symbols (pst
);
4580 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4583 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4584 struct dwarf2_per_cu_data
*iter
;
4586 /* Fill in 'dependencies' here; we fill in 'users' in a
4588 pst
->number_of_dependencies
= len
;
4589 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4590 len
* sizeof (struct symtab
*));
4592 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4595 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4597 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4600 /* Get the list of files included in the current compilation unit,
4601 and build a psymtab for each of them. */
4602 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4604 if (dwarf2_read_debug
)
4606 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4608 fprintf_unfiltered (gdb_stdlog
,
4609 "Psymtab for %s unit @0x%x: 0x%s - 0x%s"
4610 ", %d global, %d static syms\n",
4611 per_cu
->is_debug_types
? "type" : "comp",
4612 per_cu
->offset
.sect_off
,
4613 paddress (gdbarch
, pst
->textlow
),
4614 paddress (gdbarch
, pst
->texthigh
),
4615 pst
->n_global_syms
, pst
->n_static_syms
);
4619 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4620 Process compilation unit THIS_CU for a psymtab. */
4623 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4624 int want_partial_unit
)
4626 /* If this compilation unit was already read in, free the
4627 cached copy in order to read it in again. This is
4628 necessary because we skipped some symbols when we first
4629 read in the compilation unit (see load_partial_dies).
4630 This problem could be avoided, but the benefit is unclear. */
4631 if (this_cu
->cu
!= NULL
)
4632 free_one_cached_comp_unit (this_cu
);
4634 gdb_assert (! this_cu
->is_debug_types
);
4635 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4636 process_psymtab_comp_unit_reader
,
4637 &want_partial_unit
);
4639 /* Age out any secondary CUs. */
4640 age_cached_comp_units ();
4644 hash_type_unit_group (const void *item
)
4646 const struct type_unit_group
*tu_group
= item
;
4648 return hash_stmt_list_entry (&tu_group
->hash
);
4652 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4654 const struct type_unit_group
*lhs
= item_lhs
;
4655 const struct type_unit_group
*rhs
= item_rhs
;
4657 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
4660 /* Allocate a hash table for type unit groups. */
4663 allocate_type_unit_groups_table (void)
4665 return htab_create_alloc_ex (3,
4666 hash_type_unit_group
,
4669 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
4670 hashtab_obstack_allocate
,
4671 dummy_obstack_deallocate
);
4674 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4675 partial symtabs. We combine several TUs per psymtab to not let the size
4676 of any one psymtab grow too big. */
4677 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4678 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4680 /* Helper routine for get_type_unit_group.
4681 Create the type_unit_group object used to hold one or more TUs. */
4683 static struct type_unit_group
*
4684 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
4686 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4687 struct dwarf2_per_cu_data
*per_cu
;
4688 struct type_unit_group
*tu_group
;
4690 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4691 struct type_unit_group
);
4692 per_cu
= &tu_group
->per_cu
;
4693 per_cu
->objfile
= objfile
;
4694 per_cu
->is_debug_types
= 1;
4695 per_cu
->s
.type_unit_group
= tu_group
;
4697 if (dwarf2_per_objfile
->using_index
)
4699 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4700 struct dwarf2_per_cu_quick_data
);
4701 tu_group
->t
.first_tu
= cu
->per_cu
;
4705 unsigned int line_offset
= line_offset_struct
.sect_off
;
4706 struct partial_symtab
*pst
;
4709 /* Give the symtab a useful name for debug purposes. */
4710 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
4711 name
= xstrprintf ("<type_units_%d>",
4712 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
4714 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
4716 pst
= create_partial_symtab (per_cu
, name
);
4722 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
4723 tu_group
->hash
.line_offset
= line_offset_struct
;
4728 /* Look up the type_unit_group for type unit CU, and create it if necessary.
4729 STMT_LIST is a DW_AT_stmt_list attribute. */
4731 static struct type_unit_group
*
4732 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
4734 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4735 struct type_unit_group
*tu_group
;
4737 unsigned int line_offset
;
4738 struct type_unit_group type_unit_group_for_lookup
;
4740 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
4742 dwarf2_per_objfile
->type_unit_groups
=
4743 allocate_type_unit_groups_table ();
4746 /* Do we need to create a new group, or can we use an existing one? */
4750 line_offset
= DW_UNSND (stmt_list
);
4751 ++tu_stats
->nr_symtab_sharers
;
4755 /* Ugh, no stmt_list. Rare, but we have to handle it.
4756 We can do various things here like create one group per TU or
4757 spread them over multiple groups to split up the expansion work.
4758 To avoid worst case scenarios (too many groups or too large groups)
4759 we, umm, group them in bunches. */
4760 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
4761 | (tu_stats
->nr_stmt_less_type_units
4762 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
4763 ++tu_stats
->nr_stmt_less_type_units
;
4766 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
4767 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
4768 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
4769 &type_unit_group_for_lookup
, INSERT
);
4773 gdb_assert (tu_group
!= NULL
);
4777 sect_offset line_offset_struct
;
4779 line_offset_struct
.sect_off
= line_offset
;
4780 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
4782 ++tu_stats
->nr_symtabs
;
4788 /* Struct used to sort TUs by their abbreviation table offset. */
4790 struct tu_abbrev_offset
4792 struct signatured_type
*sig_type
;
4793 sect_offset abbrev_offset
;
4796 /* Helper routine for build_type_unit_groups, passed to qsort. */
4799 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
4801 const struct tu_abbrev_offset
* const *a
= ap
;
4802 const struct tu_abbrev_offset
* const *b
= bp
;
4803 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
4804 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
4806 return (aoff
> boff
) - (aoff
< boff
);
4809 /* A helper function to add a type_unit_group to a table. */
4812 add_type_unit_group_to_table (void **slot
, void *datum
)
4814 struct type_unit_group
*tu_group
= *slot
;
4815 struct type_unit_group
***datap
= datum
;
4823 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
4824 each one passing FUNC,DATA.
4826 The efficiency is because we sort TUs by the abbrev table they use and
4827 only read each abbrev table once. In one program there are 200K TUs
4828 sharing 8K abbrev tables.
4830 The main purpose of this function is to support building the
4831 dwarf2_per_objfile->type_unit_groups table.
4832 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
4833 can collapse the search space by grouping them by stmt_list.
4834 The savings can be significant, in the same program from above the 200K TUs
4835 share 8K stmt_list tables.
4837 FUNC is expected to call get_type_unit_group, which will create the
4838 struct type_unit_group if necessary and add it to
4839 dwarf2_per_objfile->type_unit_groups. */
4842 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
4844 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4845 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4846 struct cleanup
*cleanups
;
4847 struct abbrev_table
*abbrev_table
;
4848 sect_offset abbrev_offset
;
4849 struct tu_abbrev_offset
*sorted_by_abbrev
;
4850 struct type_unit_group
**iter
;
4853 /* It's up to the caller to not call us multiple times. */
4854 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
4856 if (dwarf2_per_objfile
->n_type_units
== 0)
4859 /* TUs typically share abbrev tables, and there can be way more TUs than
4860 abbrev tables. Sort by abbrev table to reduce the number of times we
4861 read each abbrev table in.
4862 Alternatives are to punt or to maintain a cache of abbrev tables.
4863 This is simpler and efficient enough for now.
4865 Later we group TUs by their DW_AT_stmt_list value (as this defines the
4866 symtab to use). Typically TUs with the same abbrev offset have the same
4867 stmt_list value too so in practice this should work well.
4869 The basic algorithm here is:
4871 sort TUs by abbrev table
4872 for each TU with same abbrev table:
4873 read abbrev table if first user
4874 read TU top level DIE
4875 [IWBN if DWO skeletons had DW_AT_stmt_list]
4878 if (dwarf2_read_debug
)
4879 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
4881 /* Sort in a separate table to maintain the order of all_type_units
4882 for .gdb_index: TU indices directly index all_type_units. */
4883 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
4884 dwarf2_per_objfile
->n_type_units
);
4885 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
4887 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
4889 sorted_by_abbrev
[i
].sig_type
= sig_type
;
4890 sorted_by_abbrev
[i
].abbrev_offset
=
4891 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
4892 sig_type
->per_cu
.offset
);
4894 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
4895 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
4896 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
4898 /* Note: In the .gdb_index case, get_type_unit_group may have already been
4899 called any number of times, so we don't reset tu_stats here. */
4901 abbrev_offset
.sect_off
= ~(unsigned) 0;
4902 abbrev_table
= NULL
;
4903 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
4905 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
4907 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
4909 /* Switch to the next abbrev table if necessary. */
4910 if (abbrev_table
== NULL
4911 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
4913 if (abbrev_table
!= NULL
)
4915 abbrev_table_free (abbrev_table
);
4916 /* Reset to NULL in case abbrev_table_read_table throws
4917 an error: abbrev_table_free_cleanup will get called. */
4918 abbrev_table
= NULL
;
4920 abbrev_offset
= tu
->abbrev_offset
;
4922 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
4924 ++tu_stats
->nr_uniq_abbrev_tables
;
4927 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
4931 /* Create a vector of pointers to primary type units to make it easy to
4932 iterate over them and CUs. See dw2_get_primary_cu. */
4933 dwarf2_per_objfile
->n_type_unit_groups
=
4934 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
4935 dwarf2_per_objfile
->all_type_unit_groups
=
4936 obstack_alloc (&objfile
->objfile_obstack
,
4937 dwarf2_per_objfile
->n_type_unit_groups
4938 * sizeof (struct type_unit_group
*));
4939 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
4940 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
4941 add_type_unit_group_to_table
, &iter
);
4942 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
4943 == dwarf2_per_objfile
->n_type_unit_groups
);
4945 do_cleanups (cleanups
);
4947 if (dwarf2_read_debug
)
4949 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
4950 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
4951 dwarf2_per_objfile
->n_type_units
);
4952 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
4953 tu_stats
->nr_uniq_abbrev_tables
);
4954 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
4955 tu_stats
->nr_symtabs
);
4956 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
4957 tu_stats
->nr_symtab_sharers
);
4958 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
4959 tu_stats
->nr_stmt_less_type_units
);
4963 /* Reader function for build_type_psymtabs. */
4966 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
4968 struct die_info
*type_unit_die
,
4972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4973 struct dwarf2_cu
*cu
= reader
->cu
;
4974 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4975 struct type_unit_group
*tu_group
;
4976 struct attribute
*attr
;
4977 struct partial_die_info
*first_die
;
4978 CORE_ADDR lowpc
, highpc
;
4979 struct partial_symtab
*pst
;
4981 gdb_assert (data
== NULL
);
4986 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
4987 tu_group
= get_type_unit_group (cu
, attr
);
4989 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
4991 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
4992 cu
->list_in_scope
= &file_symbols
;
4993 pst
= create_partial_symtab (per_cu
, "");
4996 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4998 lowpc
= (CORE_ADDR
) -1;
4999 highpc
= (CORE_ADDR
) 0;
5000 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5002 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5003 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5004 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5005 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5006 sort_pst_symbols (pst
);
5009 /* Traversal function for build_type_psymtabs. */
5012 build_type_psymtab_dependencies (void **slot
, void *info
)
5014 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5015 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5016 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5017 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5018 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5019 struct dwarf2_per_cu_data
*iter
;
5022 gdb_assert (len
> 0);
5024 pst
->number_of_dependencies
= len
;
5025 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5026 len
* sizeof (struct psymtab
*));
5028 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5031 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5032 iter
->s
.type_unit_group
= tu_group
;
5035 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5040 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5041 Build partial symbol tables for the .debug_types comp-units. */
5044 build_type_psymtabs (struct objfile
*objfile
)
5046 if (! create_all_type_units (objfile
))
5049 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5051 /* Now that all TUs have been processed we can fill in the dependencies. */
5052 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5053 build_type_psymtab_dependencies
, NULL
);
5056 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5059 psymtabs_addrmap_cleanup (void *o
)
5061 struct objfile
*objfile
= o
;
5063 objfile
->psymtabs_addrmap
= NULL
;
5066 /* Compute the 'user' field for each psymtab in OBJFILE. */
5069 set_partial_user (struct objfile
*objfile
)
5073 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5075 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5076 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5079 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5081 /* Set the 'user' field only if it is not already set. */
5082 if (pst
->dependencies
[j
]->user
== NULL
)
5083 pst
->dependencies
[j
]->user
= pst
;
5088 /* Build the partial symbol table by doing a quick pass through the
5089 .debug_info and .debug_abbrev sections. */
5092 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5094 struct cleanup
*back_to
, *addrmap_cleanup
;
5095 struct obstack temp_obstack
;
5098 if (dwarf2_read_debug
)
5100 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5104 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5106 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5108 /* Any cached compilation units will be linked by the per-objfile
5109 read_in_chain. Make sure to free them when we're done. */
5110 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5112 build_type_psymtabs (objfile
);
5114 create_all_comp_units (objfile
);
5116 /* Create a temporary address map on a temporary obstack. We later
5117 copy this to the final obstack. */
5118 obstack_init (&temp_obstack
);
5119 make_cleanup_obstack_free (&temp_obstack
);
5120 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5121 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5123 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5125 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5127 process_psymtab_comp_unit (per_cu
, 0);
5130 set_partial_user (objfile
);
5132 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5133 &objfile
->objfile_obstack
);
5134 discard_cleanups (addrmap_cleanup
);
5136 do_cleanups (back_to
);
5138 if (dwarf2_read_debug
)
5139 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5143 /* die_reader_func for load_partial_comp_unit. */
5146 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5148 struct die_info
*comp_unit_die
,
5152 struct dwarf2_cu
*cu
= reader
->cu
;
5154 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5156 /* Check if comp unit has_children.
5157 If so, read the rest of the partial symbols from this comp unit.
5158 If not, there's no more debug_info for this comp unit. */
5160 load_partial_dies (reader
, info_ptr
, 0);
5163 /* Load the partial DIEs for a secondary CU into memory.
5164 This is also used when rereading a primary CU with load_all_dies. */
5167 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5169 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5170 load_partial_comp_unit_reader
, NULL
);
5173 /* Create a list of all compilation units in OBJFILE.
5174 This is only done for -readnow and building partial symtabs. */
5177 create_all_comp_units (struct objfile
*objfile
)
5181 struct dwarf2_per_cu_data
**all_comp_units
;
5184 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5185 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
5189 all_comp_units
= xmalloc (n_allocated
5190 * sizeof (struct dwarf2_per_cu_data
*));
5192 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
5193 + dwarf2_per_objfile
->info
.size
)
5195 unsigned int length
, initial_length_size
;
5196 struct dwarf2_per_cu_data
*this_cu
;
5199 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
5201 /* Read just enough information to find out where the next
5202 compilation unit is. */
5203 length
= read_initial_length (objfile
->obfd
, info_ptr
,
5204 &initial_length_size
);
5206 /* Save the compilation unit for later lookup. */
5207 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5208 sizeof (struct dwarf2_per_cu_data
));
5209 memset (this_cu
, 0, sizeof (*this_cu
));
5210 this_cu
->offset
= offset
;
5211 this_cu
->length
= length
+ initial_length_size
;
5212 this_cu
->objfile
= objfile
;
5213 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
5215 if (n_comp_units
== n_allocated
)
5218 all_comp_units
= xrealloc (all_comp_units
,
5220 * sizeof (struct dwarf2_per_cu_data
*));
5222 all_comp_units
[n_comp_units
++] = this_cu
;
5224 info_ptr
= info_ptr
+ this_cu
->length
;
5227 dwarf2_per_objfile
->all_comp_units
5228 = obstack_alloc (&objfile
->objfile_obstack
,
5229 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5230 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5231 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5232 xfree (all_comp_units
);
5233 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5236 /* Process all loaded DIEs for compilation unit CU, starting at
5237 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5238 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5239 DW_AT_ranges). If NEED_PC is set, then this function will set
5240 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5241 and record the covered ranges in the addrmap. */
5244 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5245 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5247 struct partial_die_info
*pdi
;
5249 /* Now, march along the PDI's, descending into ones which have
5250 interesting children but skipping the children of the other ones,
5251 until we reach the end of the compilation unit. */
5257 fixup_partial_die (pdi
, cu
);
5259 /* Anonymous namespaces or modules have no name but have interesting
5260 children, so we need to look at them. Ditto for anonymous
5263 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5264 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5265 || pdi
->tag
== DW_TAG_imported_unit
)
5269 case DW_TAG_subprogram
:
5270 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5272 case DW_TAG_constant
:
5273 case DW_TAG_variable
:
5274 case DW_TAG_typedef
:
5275 case DW_TAG_union_type
:
5276 if (!pdi
->is_declaration
)
5278 add_partial_symbol (pdi
, cu
);
5281 case DW_TAG_class_type
:
5282 case DW_TAG_interface_type
:
5283 case DW_TAG_structure_type
:
5284 if (!pdi
->is_declaration
)
5286 add_partial_symbol (pdi
, cu
);
5289 case DW_TAG_enumeration_type
:
5290 if (!pdi
->is_declaration
)
5291 add_partial_enumeration (pdi
, cu
);
5293 case DW_TAG_base_type
:
5294 case DW_TAG_subrange_type
:
5295 /* File scope base type definitions are added to the partial
5297 add_partial_symbol (pdi
, cu
);
5299 case DW_TAG_namespace
:
5300 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5303 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5305 case DW_TAG_imported_unit
:
5307 struct dwarf2_per_cu_data
*per_cu
;
5309 /* For now we don't handle imported units in type units. */
5310 if (cu
->per_cu
->is_debug_types
)
5312 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5313 " supported in type units [in module %s]"),
5317 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5320 /* Go read the partial unit, if needed. */
5321 if (per_cu
->v
.psymtab
== NULL
)
5322 process_psymtab_comp_unit (per_cu
, 1);
5324 VEC_safe_push (dwarf2_per_cu_ptr
,
5325 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5333 /* If the die has a sibling, skip to the sibling. */
5335 pdi
= pdi
->die_sibling
;
5339 /* Functions used to compute the fully scoped name of a partial DIE.
5341 Normally, this is simple. For C++, the parent DIE's fully scoped
5342 name is concatenated with "::" and the partial DIE's name. For
5343 Java, the same thing occurs except that "." is used instead of "::".
5344 Enumerators are an exception; they use the scope of their parent
5345 enumeration type, i.e. the name of the enumeration type is not
5346 prepended to the enumerator.
5348 There are two complexities. One is DW_AT_specification; in this
5349 case "parent" means the parent of the target of the specification,
5350 instead of the direct parent of the DIE. The other is compilers
5351 which do not emit DW_TAG_namespace; in this case we try to guess
5352 the fully qualified name of structure types from their members'
5353 linkage names. This must be done using the DIE's children rather
5354 than the children of any DW_AT_specification target. We only need
5355 to do this for structures at the top level, i.e. if the target of
5356 any DW_AT_specification (if any; otherwise the DIE itself) does not
5359 /* Compute the scope prefix associated with PDI's parent, in
5360 compilation unit CU. The result will be allocated on CU's
5361 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5362 field. NULL is returned if no prefix is necessary. */
5364 partial_die_parent_scope (struct partial_die_info
*pdi
,
5365 struct dwarf2_cu
*cu
)
5367 char *grandparent_scope
;
5368 struct partial_die_info
*parent
, *real_pdi
;
5370 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5371 then this means the parent of the specification DIE. */
5374 while (real_pdi
->has_specification
)
5375 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
5377 parent
= real_pdi
->die_parent
;
5381 if (parent
->scope_set
)
5382 return parent
->scope
;
5384 fixup_partial_die (parent
, cu
);
5386 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5388 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5389 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5390 Work around this problem here. */
5391 if (cu
->language
== language_cplus
5392 && parent
->tag
== DW_TAG_namespace
5393 && strcmp (parent
->name
, "::") == 0
5394 && grandparent_scope
== NULL
)
5396 parent
->scope
= NULL
;
5397 parent
->scope_set
= 1;
5401 if (pdi
->tag
== DW_TAG_enumerator
)
5402 /* Enumerators should not get the name of the enumeration as a prefix. */
5403 parent
->scope
= grandparent_scope
;
5404 else if (parent
->tag
== DW_TAG_namespace
5405 || parent
->tag
== DW_TAG_module
5406 || parent
->tag
== DW_TAG_structure_type
5407 || parent
->tag
== DW_TAG_class_type
5408 || parent
->tag
== DW_TAG_interface_type
5409 || parent
->tag
== DW_TAG_union_type
5410 || parent
->tag
== DW_TAG_enumeration_type
)
5412 if (grandparent_scope
== NULL
)
5413 parent
->scope
= parent
->name
;
5415 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5417 parent
->name
, 0, cu
);
5421 /* FIXME drow/2004-04-01: What should we be doing with
5422 function-local names? For partial symbols, we should probably be
5424 complaint (&symfile_complaints
,
5425 _("unhandled containing DIE tag %d for DIE at %d"),
5426 parent
->tag
, pdi
->offset
.sect_off
);
5427 parent
->scope
= grandparent_scope
;
5430 parent
->scope_set
= 1;
5431 return parent
->scope
;
5434 /* Return the fully scoped name associated with PDI, from compilation unit
5435 CU. The result will be allocated with malloc. */
5438 partial_die_full_name (struct partial_die_info
*pdi
,
5439 struct dwarf2_cu
*cu
)
5443 /* If this is a template instantiation, we can not work out the
5444 template arguments from partial DIEs. So, unfortunately, we have
5445 to go through the full DIEs. At least any work we do building
5446 types here will be reused if full symbols are loaded later. */
5447 if (pdi
->has_template_arguments
)
5449 fixup_partial_die (pdi
, cu
);
5451 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5453 struct die_info
*die
;
5454 struct attribute attr
;
5455 struct dwarf2_cu
*ref_cu
= cu
;
5457 /* DW_FORM_ref_addr is using section offset. */
5459 attr
.form
= DW_FORM_ref_addr
;
5460 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5461 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5463 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5467 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5468 if (parent_scope
== NULL
)
5471 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5475 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5477 struct objfile
*objfile
= cu
->objfile
;
5479 char *actual_name
= NULL
;
5481 int built_actual_name
= 0;
5483 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5485 actual_name
= partial_die_full_name (pdi
, cu
);
5487 built_actual_name
= 1;
5489 if (actual_name
== NULL
)
5490 actual_name
= pdi
->name
;
5494 case DW_TAG_subprogram
:
5495 if (pdi
->is_external
|| cu
->language
== language_ada
)
5497 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5498 of the global scope. But in Ada, we want to be able to access
5499 nested procedures globally. So all Ada subprograms are stored
5500 in the global scope. */
5501 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5502 mst_text, objfile); */
5503 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5505 VAR_DOMAIN
, LOC_BLOCK
,
5506 &objfile
->global_psymbols
,
5507 0, pdi
->lowpc
+ baseaddr
,
5508 cu
->language
, objfile
);
5512 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5513 mst_file_text, objfile); */
5514 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5516 VAR_DOMAIN
, LOC_BLOCK
,
5517 &objfile
->static_psymbols
,
5518 0, pdi
->lowpc
+ baseaddr
,
5519 cu
->language
, objfile
);
5522 case DW_TAG_constant
:
5524 struct psymbol_allocation_list
*list
;
5526 if (pdi
->is_external
)
5527 list
= &objfile
->global_psymbols
;
5529 list
= &objfile
->static_psymbols
;
5530 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5531 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5532 list
, 0, 0, cu
->language
, objfile
);
5535 case DW_TAG_variable
:
5537 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5541 && !dwarf2_per_objfile
->has_section_at_zero
)
5543 /* A global or static variable may also have been stripped
5544 out by the linker if unused, in which case its address
5545 will be nullified; do not add such variables into partial
5546 symbol table then. */
5548 else if (pdi
->is_external
)
5551 Don't enter into the minimal symbol tables as there is
5552 a minimal symbol table entry from the ELF symbols already.
5553 Enter into partial symbol table if it has a location
5554 descriptor or a type.
5555 If the location descriptor is missing, new_symbol will create
5556 a LOC_UNRESOLVED symbol, the address of the variable will then
5557 be determined from the minimal symbol table whenever the variable
5559 The address for the partial symbol table entry is not
5560 used by GDB, but it comes in handy for debugging partial symbol
5563 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5564 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5566 VAR_DOMAIN
, LOC_STATIC
,
5567 &objfile
->global_psymbols
,
5569 cu
->language
, objfile
);
5573 /* Static Variable. Skip symbols without location descriptors. */
5574 if (pdi
->d
.locdesc
== NULL
)
5576 if (built_actual_name
)
5577 xfree (actual_name
);
5580 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5581 mst_file_data, objfile); */
5582 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5584 VAR_DOMAIN
, LOC_STATIC
,
5585 &objfile
->static_psymbols
,
5587 cu
->language
, objfile
);
5590 case DW_TAG_typedef
:
5591 case DW_TAG_base_type
:
5592 case DW_TAG_subrange_type
:
5593 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5595 VAR_DOMAIN
, LOC_TYPEDEF
,
5596 &objfile
->static_psymbols
,
5597 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5599 case DW_TAG_namespace
:
5600 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5602 VAR_DOMAIN
, LOC_TYPEDEF
,
5603 &objfile
->global_psymbols
,
5604 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5606 case DW_TAG_class_type
:
5607 case DW_TAG_interface_type
:
5608 case DW_TAG_structure_type
:
5609 case DW_TAG_union_type
:
5610 case DW_TAG_enumeration_type
:
5611 /* Skip external references. The DWARF standard says in the section
5612 about "Structure, Union, and Class Type Entries": "An incomplete
5613 structure, union or class type is represented by a structure,
5614 union or class entry that does not have a byte size attribute
5615 and that has a DW_AT_declaration attribute." */
5616 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5618 if (built_actual_name
)
5619 xfree (actual_name
);
5623 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5624 static vs. global. */
5625 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5627 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5628 (cu
->language
== language_cplus
5629 || cu
->language
== language_java
)
5630 ? &objfile
->global_psymbols
5631 : &objfile
->static_psymbols
,
5632 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5635 case DW_TAG_enumerator
:
5636 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5638 VAR_DOMAIN
, LOC_CONST
,
5639 (cu
->language
== language_cplus
5640 || cu
->language
== language_java
)
5641 ? &objfile
->global_psymbols
5642 : &objfile
->static_psymbols
,
5643 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5649 if (built_actual_name
)
5650 xfree (actual_name
);
5653 /* Read a partial die corresponding to a namespace; also, add a symbol
5654 corresponding to that namespace to the symbol table. NAMESPACE is
5655 the name of the enclosing namespace. */
5658 add_partial_namespace (struct partial_die_info
*pdi
,
5659 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5660 int need_pc
, struct dwarf2_cu
*cu
)
5662 /* Add a symbol for the namespace. */
5664 add_partial_symbol (pdi
, cu
);
5666 /* Now scan partial symbols in that namespace. */
5668 if (pdi
->has_children
)
5669 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5672 /* Read a partial die corresponding to a Fortran module. */
5675 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5676 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5678 /* Now scan partial symbols in that module. */
5680 if (pdi
->has_children
)
5681 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5684 /* Read a partial die corresponding to a subprogram and create a partial
5685 symbol for that subprogram. When the CU language allows it, this
5686 routine also defines a partial symbol for each nested subprogram
5687 that this subprogram contains.
5689 DIE my also be a lexical block, in which case we simply search
5690 recursively for suprograms defined inside that lexical block.
5691 Again, this is only performed when the CU language allows this
5692 type of definitions. */
5695 add_partial_subprogram (struct partial_die_info
*pdi
,
5696 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5697 int need_pc
, struct dwarf2_cu
*cu
)
5699 if (pdi
->tag
== DW_TAG_subprogram
)
5701 if (pdi
->has_pc_info
)
5703 if (pdi
->lowpc
< *lowpc
)
5704 *lowpc
= pdi
->lowpc
;
5705 if (pdi
->highpc
> *highpc
)
5706 *highpc
= pdi
->highpc
;
5710 struct objfile
*objfile
= cu
->objfile
;
5712 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5713 SECT_OFF_TEXT (objfile
));
5714 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5715 pdi
->lowpc
+ baseaddr
,
5716 pdi
->highpc
- 1 + baseaddr
,
5717 cu
->per_cu
->v
.psymtab
);
5721 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5723 if (!pdi
->is_declaration
)
5724 /* Ignore subprogram DIEs that do not have a name, they are
5725 illegal. Do not emit a complaint at this point, we will
5726 do so when we convert this psymtab into a symtab. */
5728 add_partial_symbol (pdi
, cu
);
5732 if (! pdi
->has_children
)
5735 if (cu
->language
== language_ada
)
5737 pdi
= pdi
->die_child
;
5740 fixup_partial_die (pdi
, cu
);
5741 if (pdi
->tag
== DW_TAG_subprogram
5742 || pdi
->tag
== DW_TAG_lexical_block
)
5743 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5744 pdi
= pdi
->die_sibling
;
5749 /* Read a partial die corresponding to an enumeration type. */
5752 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
5753 struct dwarf2_cu
*cu
)
5755 struct partial_die_info
*pdi
;
5757 if (enum_pdi
->name
!= NULL
)
5758 add_partial_symbol (enum_pdi
, cu
);
5760 pdi
= enum_pdi
->die_child
;
5763 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
5764 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5766 add_partial_symbol (pdi
, cu
);
5767 pdi
= pdi
->die_sibling
;
5771 /* Return the initial uleb128 in the die at INFO_PTR. */
5774 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
5776 unsigned int bytes_read
;
5778 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5781 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
5782 Return the corresponding abbrev, or NULL if the number is zero (indicating
5783 an empty DIE). In either case *BYTES_READ will be set to the length of
5784 the initial number. */
5786 static struct abbrev_info
*
5787 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
5788 struct dwarf2_cu
*cu
)
5790 bfd
*abfd
= cu
->objfile
->obfd
;
5791 unsigned int abbrev_number
;
5792 struct abbrev_info
*abbrev
;
5794 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5796 if (abbrev_number
== 0)
5799 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
5802 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
5803 abbrev_number
, bfd_get_filename (abfd
));
5809 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5810 Returns a pointer to the end of a series of DIEs, terminated by an empty
5811 DIE. Any children of the skipped DIEs will also be skipped. */
5814 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5816 struct dwarf2_cu
*cu
= reader
->cu
;
5817 struct abbrev_info
*abbrev
;
5818 unsigned int bytes_read
;
5822 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5824 return info_ptr
+ bytes_read
;
5826 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5830 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5831 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5832 abbrev corresponding to that skipped uleb128 should be passed in
5833 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5837 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5838 struct abbrev_info
*abbrev
)
5840 unsigned int bytes_read
;
5841 struct attribute attr
;
5842 bfd
*abfd
= reader
->abfd
;
5843 struct dwarf2_cu
*cu
= reader
->cu
;
5844 gdb_byte
*buffer
= reader
->buffer
;
5845 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5846 gdb_byte
*start_info_ptr
= info_ptr
;
5847 unsigned int form
, i
;
5849 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5851 /* The only abbrev we care about is DW_AT_sibling. */
5852 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5854 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5855 if (attr
.form
== DW_FORM_ref_addr
)
5856 complaint (&symfile_complaints
,
5857 _("ignoring absolute DW_AT_sibling"));
5859 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5862 /* If it isn't DW_AT_sibling, skip this attribute. */
5863 form
= abbrev
->attrs
[i
].form
;
5867 case DW_FORM_ref_addr
:
5868 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5869 and later it is offset sized. */
5870 if (cu
->header
.version
== 2)
5871 info_ptr
+= cu
->header
.addr_size
;
5873 info_ptr
+= cu
->header
.offset_size
;
5876 info_ptr
+= cu
->header
.addr_size
;
5883 case DW_FORM_flag_present
:
5895 case DW_FORM_ref_sig8
:
5898 case DW_FORM_string
:
5899 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5900 info_ptr
+= bytes_read
;
5902 case DW_FORM_sec_offset
:
5904 info_ptr
+= cu
->header
.offset_size
;
5906 case DW_FORM_exprloc
:
5908 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5909 info_ptr
+= bytes_read
;
5911 case DW_FORM_block1
:
5912 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5914 case DW_FORM_block2
:
5915 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5917 case DW_FORM_block4
:
5918 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5922 case DW_FORM_ref_udata
:
5923 case DW_FORM_GNU_addr_index
:
5924 case DW_FORM_GNU_str_index
:
5925 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
5927 case DW_FORM_indirect
:
5928 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5929 info_ptr
+= bytes_read
;
5930 /* We need to continue parsing from here, so just go back to
5932 goto skip_attribute
;
5935 error (_("Dwarf Error: Cannot handle %s "
5936 "in DWARF reader [in module %s]"),
5937 dwarf_form_name (form
),
5938 bfd_get_filename (abfd
));
5942 if (abbrev
->has_children
)
5943 return skip_children (reader
, info_ptr
);
5948 /* Locate ORIG_PDI's sibling.
5949 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5952 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5953 struct partial_die_info
*orig_pdi
,
5956 /* Do we know the sibling already? */
5958 if (orig_pdi
->sibling
)
5959 return orig_pdi
->sibling
;
5961 /* Are there any children to deal with? */
5963 if (!orig_pdi
->has_children
)
5966 /* Skip the children the long way. */
5968 return skip_children (reader
, info_ptr
);
5971 /* Expand this partial symbol table into a full symbol table. */
5974 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5980 warning (_("bug: psymtab for %s is already read in."),
5987 printf_filtered (_("Reading in symbols for %s..."),
5989 gdb_flush (gdb_stdout
);
5992 /* Restore our global data. */
5993 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5994 dwarf2_objfile_data_key
);
5996 /* If this psymtab is constructed from a debug-only objfile, the
5997 has_section_at_zero flag will not necessarily be correct. We
5998 can get the correct value for this flag by looking at the data
5999 associated with the (presumably stripped) associated objfile. */
6000 if (pst
->objfile
->separate_debug_objfile_backlink
)
6002 struct dwarf2_per_objfile
*dpo_backlink
6003 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6004 dwarf2_objfile_data_key
);
6006 dwarf2_per_objfile
->has_section_at_zero
6007 = dpo_backlink
->has_section_at_zero
;
6010 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6012 psymtab_to_symtab_1 (pst
);
6014 /* Finish up the debug error message. */
6016 printf_filtered (_("done.\n"));
6020 process_cu_includes ();
6023 /* Reading in full CUs. */
6025 /* Add PER_CU to the queue. */
6028 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6029 enum language pretend_language
)
6031 struct dwarf2_queue_item
*item
;
6034 item
= xmalloc (sizeof (*item
));
6035 item
->per_cu
= per_cu
;
6036 item
->pretend_language
= pretend_language
;
6039 if (dwarf2_queue
== NULL
)
6040 dwarf2_queue
= item
;
6042 dwarf2_queue_tail
->next
= item
;
6044 dwarf2_queue_tail
= item
;
6047 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6048 unit and add it to our queue.
6049 The result is non-zero if PER_CU was queued, otherwise the result is zero
6050 meaning either PER_CU is already queued or it is already loaded. */
6053 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6054 struct dwarf2_per_cu_data
*per_cu
,
6055 enum language pretend_language
)
6057 /* We may arrive here during partial symbol reading, if we need full
6058 DIEs to process an unusual case (e.g. template arguments). Do
6059 not queue PER_CU, just tell our caller to load its DIEs. */
6060 if (dwarf2_per_objfile
->reading_partial_symbols
)
6062 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6067 /* Mark the dependence relation so that we don't flush PER_CU
6069 dwarf2_add_dependence (this_cu
, per_cu
);
6071 /* If it's already on the queue, we have nothing to do. */
6075 /* If the compilation unit is already loaded, just mark it as
6077 if (per_cu
->cu
!= NULL
)
6079 per_cu
->cu
->last_used
= 0;
6083 /* Add it to the queue. */
6084 queue_comp_unit (per_cu
, pretend_language
);
6089 /* Process the queue. */
6092 process_queue (void)
6094 struct dwarf2_queue_item
*item
, *next_item
;
6096 if (dwarf2_read_debug
)
6098 fprintf_unfiltered (gdb_stdlog
,
6099 "Expanding one or more symtabs of objfile %s ...\n",
6100 dwarf2_per_objfile
->objfile
->name
);
6103 /* The queue starts out with one item, but following a DIE reference
6104 may load a new CU, adding it to the end of the queue. */
6105 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6107 if (dwarf2_per_objfile
->using_index
6108 ? !item
->per_cu
->v
.quick
->symtab
6109 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6111 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6113 if (dwarf2_read_debug
)
6115 fprintf_unfiltered (gdb_stdlog
,
6116 "Expanding symtab of %s at offset 0x%x\n",
6117 per_cu
->is_debug_types
? "TU" : "CU",
6118 per_cu
->offset
.sect_off
);
6121 if (per_cu
->is_debug_types
)
6122 process_full_type_unit (per_cu
, item
->pretend_language
);
6124 process_full_comp_unit (per_cu
, item
->pretend_language
);
6126 if (dwarf2_read_debug
)
6128 fprintf_unfiltered (gdb_stdlog
,
6129 "Done expanding %s at offset 0x%x\n",
6130 per_cu
->is_debug_types
? "TU" : "CU",
6131 per_cu
->offset
.sect_off
);
6135 item
->per_cu
->queued
= 0;
6136 next_item
= item
->next
;
6140 dwarf2_queue_tail
= NULL
;
6142 if (dwarf2_read_debug
)
6144 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6145 dwarf2_per_objfile
->objfile
->name
);
6149 /* Free all allocated queue entries. This function only releases anything if
6150 an error was thrown; if the queue was processed then it would have been
6151 freed as we went along. */
6154 dwarf2_release_queue (void *dummy
)
6156 struct dwarf2_queue_item
*item
, *last
;
6158 item
= dwarf2_queue
;
6161 /* Anything still marked queued is likely to be in an
6162 inconsistent state, so discard it. */
6163 if (item
->per_cu
->queued
)
6165 if (item
->per_cu
->cu
!= NULL
)
6166 free_one_cached_comp_unit (item
->per_cu
);
6167 item
->per_cu
->queued
= 0;
6175 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6178 /* Read in full symbols for PST, and anything it depends on. */
6181 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6183 struct dwarf2_per_cu_data
*per_cu
;
6189 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6190 if (!pst
->dependencies
[i
]->readin
6191 && pst
->dependencies
[i
]->user
== NULL
)
6193 /* Inform about additional files that need to be read in. */
6196 /* FIXME: i18n: Need to make this a single string. */
6197 fputs_filtered (" ", gdb_stdout
);
6199 fputs_filtered ("and ", gdb_stdout
);
6201 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6202 wrap_here (""); /* Flush output. */
6203 gdb_flush (gdb_stdout
);
6205 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6208 per_cu
= pst
->read_symtab_private
;
6212 /* It's an include file, no symbols to read for it.
6213 Everything is in the parent symtab. */
6218 dw2_do_instantiate_symtab (per_cu
);
6221 /* Trivial hash function for die_info: the hash value of a DIE
6222 is its offset in .debug_info for this objfile. */
6225 die_hash (const void *item
)
6227 const struct die_info
*die
= item
;
6229 return die
->offset
.sect_off
;
6232 /* Trivial comparison function for die_info structures: two DIEs
6233 are equal if they have the same offset. */
6236 die_eq (const void *item_lhs
, const void *item_rhs
)
6238 const struct die_info
*die_lhs
= item_lhs
;
6239 const struct die_info
*die_rhs
= item_rhs
;
6241 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6244 /* die_reader_func for load_full_comp_unit.
6245 This is identical to read_signatured_type_reader,
6246 but is kept separate for now. */
6249 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6251 struct die_info
*comp_unit_die
,
6255 struct dwarf2_cu
*cu
= reader
->cu
;
6256 enum language
*language_ptr
= data
;
6258 gdb_assert (cu
->die_hash
== NULL
);
6260 htab_create_alloc_ex (cu
->header
.length
/ 12,
6264 &cu
->comp_unit_obstack
,
6265 hashtab_obstack_allocate
,
6266 dummy_obstack_deallocate
);
6269 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6270 &info_ptr
, comp_unit_die
);
6271 cu
->dies
= comp_unit_die
;
6272 /* comp_unit_die is not stored in die_hash, no need. */
6274 /* We try not to read any attributes in this function, because not
6275 all CUs needed for references have been loaded yet, and symbol
6276 table processing isn't initialized. But we have to set the CU language,
6277 or we won't be able to build types correctly.
6278 Similarly, if we do not read the producer, we can not apply
6279 producer-specific interpretation. */
6280 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6283 /* Load the DIEs associated with PER_CU into memory. */
6286 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6287 enum language pretend_language
)
6289 gdb_assert (! this_cu
->is_debug_types
);
6291 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6292 load_full_comp_unit_reader
, &pretend_language
);
6295 /* Add a DIE to the delayed physname list. */
6298 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6299 const char *name
, struct die_info
*die
,
6300 struct dwarf2_cu
*cu
)
6302 struct delayed_method_info mi
;
6304 mi
.fnfield_index
= fnfield_index
;
6308 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6311 /* A cleanup for freeing the delayed method list. */
6314 free_delayed_list (void *ptr
)
6316 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6317 if (cu
->method_list
!= NULL
)
6319 VEC_free (delayed_method_info
, cu
->method_list
);
6320 cu
->method_list
= NULL
;
6324 /* Compute the physnames of any methods on the CU's method list.
6326 The computation of method physnames is delayed in order to avoid the
6327 (bad) condition that one of the method's formal parameters is of an as yet
6331 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6334 struct delayed_method_info
*mi
;
6335 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6337 const char *physname
;
6338 struct fn_fieldlist
*fn_flp
6339 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6340 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6341 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6345 /* Go objects should be embedded in a DW_TAG_module DIE,
6346 and it's not clear if/how imported objects will appear.
6347 To keep Go support simple until that's worked out,
6348 go back through what we've read and create something usable.
6349 We could do this while processing each DIE, and feels kinda cleaner,
6350 but that way is more invasive.
6351 This is to, for example, allow the user to type "p var" or "b main"
6352 without having to specify the package name, and allow lookups
6353 of module.object to work in contexts that use the expression
6357 fixup_go_packaging (struct dwarf2_cu
*cu
)
6359 char *package_name
= NULL
;
6360 struct pending
*list
;
6363 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6365 for (i
= 0; i
< list
->nsyms
; ++i
)
6367 struct symbol
*sym
= list
->symbol
[i
];
6369 if (SYMBOL_LANGUAGE (sym
) == language_go
6370 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6372 char *this_package_name
= go_symbol_package_name (sym
);
6374 if (this_package_name
== NULL
)
6376 if (package_name
== NULL
)
6377 package_name
= this_package_name
;
6380 if (strcmp (package_name
, this_package_name
) != 0)
6381 complaint (&symfile_complaints
,
6382 _("Symtab %s has objects from two different Go packages: %s and %s"),
6383 (sym
->symtab
&& sym
->symtab
->filename
6384 ? sym
->symtab
->filename
6385 : cu
->objfile
->name
),
6386 this_package_name
, package_name
);
6387 xfree (this_package_name
);
6393 if (package_name
!= NULL
)
6395 struct objfile
*objfile
= cu
->objfile
;
6396 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6397 package_name
, objfile
);
6400 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6402 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6403 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6404 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6405 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6406 e.g., "main" finds the "main" module and not C's main(). */
6407 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6408 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6409 SYMBOL_TYPE (sym
) = type
;
6411 add_symbol_to_list (sym
, &global_symbols
);
6413 xfree (package_name
);
6417 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6419 /* Return the symtab for PER_CU. This works properly regardless of
6420 whether we're using the index or psymtabs. */
6422 static struct symtab
*
6423 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6425 return (dwarf2_per_objfile
->using_index
6426 ? per_cu
->v
.quick
->symtab
6427 : per_cu
->v
.psymtab
->symtab
);
6430 /* A helper function for computing the list of all symbol tables
6431 included by PER_CU. */
6434 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6435 htab_t all_children
,
6436 struct dwarf2_per_cu_data
*per_cu
)
6440 struct dwarf2_per_cu_data
*iter
;
6442 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6445 /* This inclusion and its children have been processed. */
6450 /* Only add a CU if it has a symbol table. */
6451 if (get_symtab (per_cu
) != NULL
)
6452 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6455 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6457 recursively_compute_inclusions (result
, all_children
, iter
);
6460 /* Compute the symtab 'includes' fields for the symtab related to
6464 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6466 gdb_assert (! per_cu
->is_debug_types
);
6468 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6471 struct dwarf2_per_cu_data
*iter
;
6472 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6473 htab_t all_children
;
6474 struct symtab
*symtab
= get_symtab (per_cu
);
6476 /* If we don't have a symtab, we can just skip this case. */
6480 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6481 NULL
, xcalloc
, xfree
);
6484 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6487 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6489 /* Now we have a transitive closure of all the included CUs, so
6490 we can convert it to a list of symtabs. */
6491 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6493 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6494 (len
+ 1) * sizeof (struct symtab
*));
6496 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6498 symtab
->includes
[ix
] = get_symtab (iter
);
6499 symtab
->includes
[len
] = NULL
;
6501 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6502 htab_delete (all_children
);
6506 /* Compute the 'includes' field for the symtabs of all the CUs we just
6510 process_cu_includes (void)
6513 struct dwarf2_per_cu_data
*iter
;
6516 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6520 if (! iter
->is_debug_types
)
6521 compute_symtab_includes (iter
);
6524 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6527 /* Generate full symbol information for PER_CU, whose DIEs have
6528 already been loaded into memory. */
6531 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6532 enum language pretend_language
)
6534 struct dwarf2_cu
*cu
= per_cu
->cu
;
6535 struct objfile
*objfile
= per_cu
->objfile
;
6536 CORE_ADDR lowpc
, highpc
;
6537 struct symtab
*symtab
;
6538 struct cleanup
*back_to
, *delayed_list_cleanup
;
6540 struct block
*static_block
;
6542 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6545 back_to
= make_cleanup (really_free_pendings
, NULL
);
6546 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6548 cu
->list_in_scope
= &file_symbols
;
6550 cu
->language
= pretend_language
;
6551 cu
->language_defn
= language_def (cu
->language
);
6553 /* Do line number decoding in read_file_scope () */
6554 process_die (cu
->dies
, cu
);
6556 /* For now fudge the Go package. */
6557 if (cu
->language
== language_go
)
6558 fixup_go_packaging (cu
);
6560 /* Now that we have processed all the DIEs in the CU, all the types
6561 should be complete, and it should now be safe to compute all of the
6563 compute_delayed_physnames (cu
);
6564 do_cleanups (delayed_list_cleanup
);
6566 /* Some compilers don't define a DW_AT_high_pc attribute for the
6567 compilation unit. If the DW_AT_high_pc is missing, synthesize
6568 it, by scanning the DIE's below the compilation unit. */
6569 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6571 static_block
= end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0);
6573 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6574 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6575 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6576 addrmap to help ensure it has an accurate map of pc values belonging to
6578 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6580 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6581 SECT_OFF_TEXT (objfile
), 0);
6585 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6587 /* Set symtab language to language from DW_AT_language. If the
6588 compilation is from a C file generated by language preprocessors, do
6589 not set the language if it was already deduced by start_subfile. */
6590 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6591 symtab
->language
= cu
->language
;
6593 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6594 produce DW_AT_location with location lists but it can be possibly
6595 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6596 there were bugs in prologue debug info, fixed later in GCC-4.5
6597 by "unwind info for epilogues" patch (which is not directly related).
6599 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6600 needed, it would be wrong due to missing DW_AT_producer there.
6602 Still one can confuse GDB by using non-standard GCC compilation
6603 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6605 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6606 symtab
->locations_valid
= 1;
6608 if (gcc_4_minor
>= 5)
6609 symtab
->epilogue_unwind_valid
= 1;
6611 symtab
->call_site_htab
= cu
->call_site_htab
;
6614 if (dwarf2_per_objfile
->using_index
)
6615 per_cu
->v
.quick
->symtab
= symtab
;
6618 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6619 pst
->symtab
= symtab
;
6623 /* Push it for inclusion processing later. */
6624 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
6626 do_cleanups (back_to
);
6629 /* Generate full symbol information for type unit PER_CU, whose DIEs have
6630 already been loaded into memory. */
6633 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
6634 enum language pretend_language
)
6636 struct dwarf2_cu
*cu
= per_cu
->cu
;
6637 struct objfile
*objfile
= per_cu
->objfile
;
6638 struct symtab
*symtab
;
6639 struct cleanup
*back_to
, *delayed_list_cleanup
;
6642 back_to
= make_cleanup (really_free_pendings
, NULL
);
6643 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6645 cu
->list_in_scope
= &file_symbols
;
6647 cu
->language
= pretend_language
;
6648 cu
->language_defn
= language_def (cu
->language
);
6650 /* The symbol tables are set up in read_type_unit_scope. */
6651 process_die (cu
->dies
, cu
);
6653 /* For now fudge the Go package. */
6654 if (cu
->language
== language_go
)
6655 fixup_go_packaging (cu
);
6657 /* Now that we have processed all the DIEs in the CU, all the types
6658 should be complete, and it should now be safe to compute all of the
6660 compute_delayed_physnames (cu
);
6661 do_cleanups (delayed_list_cleanup
);
6663 /* TUs share symbol tables.
6664 If this is the first TU to use this symtab, complete the construction
6665 of it with end_expandable_symtab. Otherwise, complete the addition of
6666 this TU's symbols to the existing symtab. */
6667 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
6669 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
6670 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
6674 /* Set symtab language to language from DW_AT_language. If the
6675 compilation is from a C file generated by language preprocessors,
6676 do not set the language if it was already deduced by
6678 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6679 symtab
->language
= cu
->language
;
6684 augment_type_symtab (objfile
,
6685 per_cu
->s
.type_unit_group
->primary_symtab
);
6686 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
6689 if (dwarf2_per_objfile
->using_index
)
6690 per_cu
->v
.quick
->symtab
= symtab
;
6693 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6694 pst
->symtab
= symtab
;
6698 do_cleanups (back_to
);
6701 /* Process an imported unit DIE. */
6704 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6706 struct attribute
*attr
;
6708 /* For now we don't handle imported units in type units. */
6709 if (cu
->per_cu
->is_debug_types
)
6711 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6712 " supported in type units [in module %s]"),
6716 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6719 struct dwarf2_per_cu_data
*per_cu
;
6720 struct symtab
*imported_symtab
;
6723 offset
= dwarf2_get_ref_die_offset (attr
);
6724 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6726 /* Queue the unit, if needed. */
6727 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
6728 load_full_comp_unit (per_cu
, cu
->language
);
6730 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
6735 /* Process a die and its children. */
6738 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6742 case DW_TAG_padding
:
6744 case DW_TAG_compile_unit
:
6745 case DW_TAG_partial_unit
:
6746 read_file_scope (die
, cu
);
6748 case DW_TAG_type_unit
:
6749 read_type_unit_scope (die
, cu
);
6751 case DW_TAG_subprogram
:
6752 case DW_TAG_inlined_subroutine
:
6753 read_func_scope (die
, cu
);
6755 case DW_TAG_lexical_block
:
6756 case DW_TAG_try_block
:
6757 case DW_TAG_catch_block
:
6758 read_lexical_block_scope (die
, cu
);
6760 case DW_TAG_GNU_call_site
:
6761 read_call_site_scope (die
, cu
);
6763 case DW_TAG_class_type
:
6764 case DW_TAG_interface_type
:
6765 case DW_TAG_structure_type
:
6766 case DW_TAG_union_type
:
6767 process_structure_scope (die
, cu
);
6769 case DW_TAG_enumeration_type
:
6770 process_enumeration_scope (die
, cu
);
6773 /* These dies have a type, but processing them does not create
6774 a symbol or recurse to process the children. Therefore we can
6775 read them on-demand through read_type_die. */
6776 case DW_TAG_subroutine_type
:
6777 case DW_TAG_set_type
:
6778 case DW_TAG_array_type
:
6779 case DW_TAG_pointer_type
:
6780 case DW_TAG_ptr_to_member_type
:
6781 case DW_TAG_reference_type
:
6782 case DW_TAG_string_type
:
6785 case DW_TAG_base_type
:
6786 case DW_TAG_subrange_type
:
6787 case DW_TAG_typedef
:
6788 /* Add a typedef symbol for the type definition, if it has a
6790 new_symbol (die
, read_type_die (die
, cu
), cu
);
6792 case DW_TAG_common_block
:
6793 read_common_block (die
, cu
);
6795 case DW_TAG_common_inclusion
:
6797 case DW_TAG_namespace
:
6798 processing_has_namespace_info
= 1;
6799 read_namespace (die
, cu
);
6802 processing_has_namespace_info
= 1;
6803 read_module (die
, cu
);
6805 case DW_TAG_imported_declaration
:
6806 case DW_TAG_imported_module
:
6807 processing_has_namespace_info
= 1;
6808 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6809 || cu
->language
!= language_fortran
))
6810 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
6811 dwarf_tag_name (die
->tag
));
6812 read_import_statement (die
, cu
);
6815 case DW_TAG_imported_unit
:
6816 process_imported_unit_die (die
, cu
);
6820 new_symbol (die
, NULL
, cu
);
6825 /* A helper function for dwarf2_compute_name which determines whether DIE
6826 needs to have the name of the scope prepended to the name listed in the
6830 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6832 struct attribute
*attr
;
6836 case DW_TAG_namespace
:
6837 case DW_TAG_typedef
:
6838 case DW_TAG_class_type
:
6839 case DW_TAG_interface_type
:
6840 case DW_TAG_structure_type
:
6841 case DW_TAG_union_type
:
6842 case DW_TAG_enumeration_type
:
6843 case DW_TAG_enumerator
:
6844 case DW_TAG_subprogram
:
6848 case DW_TAG_variable
:
6849 case DW_TAG_constant
:
6850 /* We only need to prefix "globally" visible variables. These include
6851 any variable marked with DW_AT_external or any variable that
6852 lives in a namespace. [Variables in anonymous namespaces
6853 require prefixing, but they are not DW_AT_external.] */
6855 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6857 struct dwarf2_cu
*spec_cu
= cu
;
6859 return die_needs_namespace (die_specification (die
, &spec_cu
),
6863 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6864 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6865 && die
->parent
->tag
!= DW_TAG_module
)
6867 /* A variable in a lexical block of some kind does not need a
6868 namespace, even though in C++ such variables may be external
6869 and have a mangled name. */
6870 if (die
->parent
->tag
== DW_TAG_lexical_block
6871 || die
->parent
->tag
== DW_TAG_try_block
6872 || die
->parent
->tag
== DW_TAG_catch_block
6873 || die
->parent
->tag
== DW_TAG_subprogram
)
6882 /* Retrieve the last character from a mem_file. */
6885 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
6887 char *last_char_p
= (char *) object
;
6890 *last_char_p
= buffer
[length
- 1];
6893 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6894 compute the physname for the object, which include a method's:
6895 - formal parameters (C++/Java),
6896 - receiver type (Go),
6897 - return type (Java).
6899 The term "physname" is a bit confusing.
6900 For C++, for example, it is the demangled name.
6901 For Go, for example, it's the mangled name.
6903 For Ada, return the DIE's linkage name rather than the fully qualified
6904 name. PHYSNAME is ignored..
6906 The result is allocated on the objfile_obstack and canonicalized. */
6909 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
6912 struct objfile
*objfile
= cu
->objfile
;
6915 name
= dwarf2_name (die
, cu
);
6917 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
6918 compute it by typename_concat inside GDB. */
6919 if (cu
->language
== language_ada
6920 || (cu
->language
== language_fortran
&& physname
))
6922 /* For Ada unit, we prefer the linkage name over the name, as
6923 the former contains the exported name, which the user expects
6924 to be able to reference. Ideally, we want the user to be able
6925 to reference this entity using either natural or linkage name,
6926 but we haven't started looking at this enhancement yet. */
6927 struct attribute
*attr
;
6929 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6931 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6932 if (attr
&& DW_STRING (attr
))
6933 return DW_STRING (attr
);
6936 /* These are the only languages we know how to qualify names in. */
6938 && (cu
->language
== language_cplus
|| cu
->language
== language_java
6939 || cu
->language
== language_fortran
))
6941 if (die_needs_namespace (die
, cu
))
6945 struct ui_file
*buf
;
6947 prefix
= determine_prefix (die
, cu
);
6948 buf
= mem_fileopen ();
6949 if (*prefix
!= '\0')
6951 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
6954 fputs_unfiltered (prefixed_name
, buf
);
6955 xfree (prefixed_name
);
6958 fputs_unfiltered (name
, buf
);
6960 /* Template parameters may be specified in the DIE's DW_AT_name, or
6961 as children with DW_TAG_template_type_param or
6962 DW_TAG_value_type_param. If the latter, add them to the name
6963 here. If the name already has template parameters, then
6964 skip this step; some versions of GCC emit both, and
6965 it is more efficient to use the pre-computed name.
6967 Something to keep in mind about this process: it is very
6968 unlikely, or in some cases downright impossible, to produce
6969 something that will match the mangled name of a function.
6970 If the definition of the function has the same debug info,
6971 we should be able to match up with it anyway. But fallbacks
6972 using the minimal symbol, for instance to find a method
6973 implemented in a stripped copy of libstdc++, will not work.
6974 If we do not have debug info for the definition, we will have to
6975 match them up some other way.
6977 When we do name matching there is a related problem with function
6978 templates; two instantiated function templates are allowed to
6979 differ only by their return types, which we do not add here. */
6981 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
6983 struct attribute
*attr
;
6984 struct die_info
*child
;
6987 die
->building_fullname
= 1;
6989 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6994 struct dwarf2_locexpr_baton
*baton
;
6997 if (child
->tag
!= DW_TAG_template_type_param
6998 && child
->tag
!= DW_TAG_template_value_param
)
7003 fputs_unfiltered ("<", buf
);
7007 fputs_unfiltered (", ", buf
);
7009 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7012 complaint (&symfile_complaints
,
7013 _("template parameter missing DW_AT_type"));
7014 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7017 type
= die_type (child
, cu
);
7019 if (child
->tag
== DW_TAG_template_type_param
)
7021 c_print_type (type
, "", buf
, -1, 0);
7025 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7028 complaint (&symfile_complaints
,
7029 _("template parameter missing "
7030 "DW_AT_const_value"));
7031 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7035 dwarf2_const_value_attr (attr
, type
, name
,
7036 &cu
->comp_unit_obstack
, cu
,
7037 &value
, &bytes
, &baton
);
7039 if (TYPE_NOSIGN (type
))
7040 /* GDB prints characters as NUMBER 'CHAR'. If that's
7041 changed, this can use value_print instead. */
7042 c_printchar (value
, type
, buf
);
7045 struct value_print_options opts
;
7048 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7052 else if (bytes
!= NULL
)
7054 v
= allocate_value (type
);
7055 memcpy (value_contents_writeable (v
), bytes
,
7056 TYPE_LENGTH (type
));
7059 v
= value_from_longest (type
, value
);
7061 /* Specify decimal so that we do not depend on
7063 get_formatted_print_options (&opts
, 'd');
7065 value_print (v
, buf
, &opts
);
7071 die
->building_fullname
= 0;
7075 /* Close the argument list, with a space if necessary
7076 (nested templates). */
7077 char last_char
= '\0';
7078 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7079 if (last_char
== '>')
7080 fputs_unfiltered (" >", buf
);
7082 fputs_unfiltered (">", buf
);
7086 /* For Java and C++ methods, append formal parameter type
7087 information, if PHYSNAME. */
7089 if (physname
&& die
->tag
== DW_TAG_subprogram
7090 && (cu
->language
== language_cplus
7091 || cu
->language
== language_java
))
7093 struct type
*type
= read_type_die (die
, cu
);
7095 c_type_print_args (type
, buf
, 1, cu
->language
);
7097 if (cu
->language
== language_java
)
7099 /* For java, we must append the return type to method
7101 if (die
->tag
== DW_TAG_subprogram
)
7102 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7105 else if (cu
->language
== language_cplus
)
7107 /* Assume that an artificial first parameter is
7108 "this", but do not crash if it is not. RealView
7109 marks unnamed (and thus unused) parameters as
7110 artificial; there is no way to differentiate
7112 if (TYPE_NFIELDS (type
) > 0
7113 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7114 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7115 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7117 fputs_unfiltered (" const", buf
);
7121 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7123 ui_file_delete (buf
);
7125 if (cu
->language
== language_cplus
)
7128 = dwarf2_canonicalize_name (name
, cu
,
7129 &objfile
->objfile_obstack
);
7140 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7141 If scope qualifiers are appropriate they will be added. The result
7142 will be allocated on the objfile_obstack, or NULL if the DIE does
7143 not have a name. NAME may either be from a previous call to
7144 dwarf2_name or NULL.
7146 The output string will be canonicalized (if C++/Java). */
7149 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7151 return dwarf2_compute_name (name
, die
, cu
, 0);
7154 /* Construct a physname for the given DIE in CU. NAME may either be
7155 from a previous call to dwarf2_name or NULL. The result will be
7156 allocated on the objfile_objstack or NULL if the DIE does not have a
7159 The output string will be canonicalized (if C++/Java). */
7162 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7164 struct objfile
*objfile
= cu
->objfile
;
7165 struct attribute
*attr
;
7166 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7167 struct cleanup
*back_to
;
7170 /* In this case dwarf2_compute_name is just a shortcut not building anything
7172 if (!die_needs_namespace (die
, cu
))
7173 return dwarf2_compute_name (name
, die
, cu
, 1);
7175 back_to
= make_cleanup (null_cleanup
, NULL
);
7177 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7179 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7181 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7183 if (attr
&& DW_STRING (attr
))
7187 mangled
= DW_STRING (attr
);
7189 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7190 type. It is easier for GDB users to search for such functions as
7191 `name(params)' than `long name(params)'. In such case the minimal
7192 symbol names do not match the full symbol names but for template
7193 functions there is never a need to look up their definition from their
7194 declaration so the only disadvantage remains the minimal symbol
7195 variant `long name(params)' does not have the proper inferior type.
7198 if (cu
->language
== language_go
)
7200 /* This is a lie, but we already lie to the caller new_symbol_full.
7201 new_symbol_full assumes we return the mangled name.
7202 This just undoes that lie until things are cleaned up. */
7207 demangled
= cplus_demangle (mangled
,
7208 (DMGL_PARAMS
| DMGL_ANSI
7209 | (cu
->language
== language_java
7210 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7215 make_cleanup (xfree
, demangled
);
7225 if (canon
== NULL
|| check_physname
)
7227 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7229 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7231 /* It may not mean a bug in GDB. The compiler could also
7232 compute DW_AT_linkage_name incorrectly. But in such case
7233 GDB would need to be bug-to-bug compatible. */
7235 complaint (&symfile_complaints
,
7236 _("Computed physname <%s> does not match demangled <%s> "
7237 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7238 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7240 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7241 is available here - over computed PHYSNAME. It is safer
7242 against both buggy GDB and buggy compilers. */
7256 retval
= obsavestring (retval
, strlen (retval
),
7257 &objfile
->objfile_obstack
);
7259 do_cleanups (back_to
);
7263 /* Read the import statement specified by the given die and record it. */
7266 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7268 struct objfile
*objfile
= cu
->objfile
;
7269 struct attribute
*import_attr
;
7270 struct die_info
*imported_die
, *child_die
;
7271 struct dwarf2_cu
*imported_cu
;
7272 const char *imported_name
;
7273 const char *imported_name_prefix
;
7274 const char *canonical_name
;
7275 const char *import_alias
;
7276 const char *imported_declaration
= NULL
;
7277 const char *import_prefix
;
7278 VEC (const_char_ptr
) *excludes
= NULL
;
7279 struct cleanup
*cleanups
;
7283 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7284 if (import_attr
== NULL
)
7286 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7287 dwarf_tag_name (die
->tag
));
7292 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7293 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7294 if (imported_name
== NULL
)
7296 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7298 The import in the following code:
7312 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7313 <52> DW_AT_decl_file : 1
7314 <53> DW_AT_decl_line : 6
7315 <54> DW_AT_import : <0x75>
7316 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7318 <5b> DW_AT_decl_file : 1
7319 <5c> DW_AT_decl_line : 2
7320 <5d> DW_AT_type : <0x6e>
7322 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7323 <76> DW_AT_byte_size : 4
7324 <77> DW_AT_encoding : 5 (signed)
7326 imports the wrong die ( 0x75 instead of 0x58 ).
7327 This case will be ignored until the gcc bug is fixed. */
7331 /* Figure out the local name after import. */
7332 import_alias
= dwarf2_name (die
, cu
);
7334 /* Figure out where the statement is being imported to. */
7335 import_prefix
= determine_prefix (die
, cu
);
7337 /* Figure out what the scope of the imported die is and prepend it
7338 to the name of the imported die. */
7339 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7341 if (imported_die
->tag
!= DW_TAG_namespace
7342 && imported_die
->tag
!= DW_TAG_module
)
7344 imported_declaration
= imported_name
;
7345 canonical_name
= imported_name_prefix
;
7347 else if (strlen (imported_name_prefix
) > 0)
7349 temp
= alloca (strlen (imported_name_prefix
)
7350 + 2 + strlen (imported_name
) + 1);
7351 strcpy (temp
, imported_name_prefix
);
7352 strcat (temp
, "::");
7353 strcat (temp
, imported_name
);
7354 canonical_name
= temp
;
7357 canonical_name
= imported_name
;
7359 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7361 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7362 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7363 child_die
= sibling_die (child_die
))
7365 /* DWARF-4: A Fortran use statement with a “rename list” may be
7366 represented by an imported module entry with an import attribute
7367 referring to the module and owned entries corresponding to those
7368 entities that are renamed as part of being imported. */
7370 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7372 complaint (&symfile_complaints
,
7373 _("child DW_TAG_imported_declaration expected "
7374 "- DIE at 0x%x [in module %s]"),
7375 child_die
->offset
.sect_off
, objfile
->name
);
7379 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7380 if (import_attr
== NULL
)
7382 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7383 dwarf_tag_name (child_die
->tag
));
7388 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7390 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7391 if (imported_name
== NULL
)
7393 complaint (&symfile_complaints
,
7394 _("child DW_TAG_imported_declaration has unknown "
7395 "imported name - DIE at 0x%x [in module %s]"),
7396 child_die
->offset
.sect_off
, objfile
->name
);
7400 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7402 process_die (child_die
, cu
);
7405 cp_add_using_directive (import_prefix
,
7408 imported_declaration
,
7410 &objfile
->objfile_obstack
);
7412 do_cleanups (cleanups
);
7415 /* Cleanup function for handle_DW_AT_stmt_list. */
7418 free_cu_line_header (void *arg
)
7420 struct dwarf2_cu
*cu
= arg
;
7422 free_line_header (cu
->line_header
);
7423 cu
->line_header
= NULL
;
7427 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7428 char **name
, char **comp_dir
)
7430 struct attribute
*attr
;
7435 /* Find the filename. Do not use dwarf2_name here, since the filename
7436 is not a source language identifier. */
7437 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7440 *name
= DW_STRING (attr
);
7443 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7445 *comp_dir
= DW_STRING (attr
);
7446 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
7448 *comp_dir
= ldirname (*name
);
7449 if (*comp_dir
!= NULL
)
7450 make_cleanup (xfree
, *comp_dir
);
7452 if (*comp_dir
!= NULL
)
7454 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7455 directory, get rid of it. */
7456 char *cp
= strchr (*comp_dir
, ':');
7458 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7463 *name
= "<unknown>";
7466 /* Handle DW_AT_stmt_list for a compilation unit.
7467 DIE is the DW_TAG_compile_unit die for CU.
7468 COMP_DIR is the compilation directory.
7469 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7472 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7473 const char *comp_dir
)
7475 struct attribute
*attr
;
7477 gdb_assert (! cu
->per_cu
->is_debug_types
);
7479 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7482 unsigned int line_offset
= DW_UNSND (attr
);
7483 struct line_header
*line_header
7484 = dwarf_decode_line_header (line_offset
, cu
);
7488 cu
->line_header
= line_header
;
7489 make_cleanup (free_cu_line_header
, cu
);
7490 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7495 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7498 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7500 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7501 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7502 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7503 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7504 struct attribute
*attr
;
7506 char *comp_dir
= NULL
;
7507 struct die_info
*child_die
;
7508 bfd
*abfd
= objfile
->obfd
;
7511 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7513 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7515 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7516 from finish_block. */
7517 if (lowpc
== ((CORE_ADDR
) -1))
7522 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7524 prepare_one_comp_unit (cu
, die
, cu
->language
);
7526 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7527 standardised yet. As a workaround for the language detection we fall
7528 back to the DW_AT_producer string. */
7529 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7530 cu
->language
= language_opencl
;
7532 /* Similar hack for Go. */
7533 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7534 set_cu_language (DW_LANG_Go
, cu
);
7536 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7538 /* Decode line number information if present. We do this before
7539 processing child DIEs, so that the line header table is available
7540 for DW_AT_decl_file. */
7541 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7543 /* Process all dies in compilation unit. */
7544 if (die
->child
!= NULL
)
7546 child_die
= die
->child
;
7547 while (child_die
&& child_die
->tag
)
7549 process_die (child_die
, cu
);
7550 child_die
= sibling_die (child_die
);
7554 /* Decode macro information, if present. Dwarf 2 macro information
7555 refers to information in the line number info statement program
7556 header, so we can only read it if we've read the header
7558 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7559 if (attr
&& cu
->line_header
)
7561 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7562 complaint (&symfile_complaints
,
7563 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7565 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7569 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7570 if (attr
&& cu
->line_header
)
7572 unsigned int macro_offset
= DW_UNSND (attr
);
7574 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7578 do_cleanups (back_to
);
7581 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7582 Create the set of symtabs used by this TU, or if this TU is sharing
7583 symtabs with another TU and the symtabs have already been created
7584 then restore those symtabs in the line header.
7585 We don't need the pc/line-number mapping for type units. */
7588 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7590 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7591 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7592 struct type_unit_group
*tu_group
;
7594 struct line_header
*lh
;
7595 struct attribute
*attr
;
7596 unsigned int i
, line_offset
;
7598 gdb_assert (per_cu
->is_debug_types
);
7600 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7602 /* If we're using .gdb_index (includes -readnow) then
7603 per_cu->s.type_unit_group may not have been set up yet. */
7604 if (per_cu
->s
.type_unit_group
== NULL
)
7605 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
7606 tu_group
= per_cu
->s
.type_unit_group
;
7608 /* If we've already processed this stmt_list there's no real need to
7609 do it again, we could fake it and just recreate the part we need
7610 (file name,index -> symtab mapping). If data shows this optimization
7611 is useful we can do it then. */
7612 first_time
= tu_group
->primary_symtab
== NULL
;
7614 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7619 line_offset
= DW_UNSND (attr
);
7620 lh
= dwarf_decode_line_header (line_offset
, cu
);
7625 dwarf2_start_symtab (cu
, "", NULL
, 0);
7628 gdb_assert (tu_group
->symtabs
== NULL
);
7631 /* Note: The primary symtab will get allocated at the end. */
7635 cu
->line_header
= lh
;
7636 make_cleanup (free_cu_line_header
, cu
);
7640 dwarf2_start_symtab (cu
, "", NULL
, 0);
7642 tu_group
->num_symtabs
= lh
->num_file_names
;
7643 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
7645 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7648 struct file_entry
*fe
= &lh
->file_names
[i
];
7651 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7652 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
7654 /* Note: We don't have to watch for the main subfile here, type units
7655 don't have DW_AT_name. */
7657 if (current_subfile
->symtab
== NULL
)
7659 /* NOTE: start_subfile will recognize when it's been passed
7660 a file it has already seen. So we can't assume there's a
7661 simple mapping from lh->file_names to subfiles,
7662 lh->file_names may contain dups. */
7663 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7667 fe
->symtab
= current_subfile
->symtab
;
7668 tu_group
->symtabs
[i
] = fe
->symtab
;
7675 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7677 struct file_entry
*fe
= &lh
->file_names
[i
];
7679 fe
->symtab
= tu_group
->symtabs
[i
];
7683 /* The main symtab is allocated last. Type units don't have DW_AT_name
7684 so they don't have a "real" (so to speak) symtab anyway.
7685 There is later code that will assign the main symtab to all symbols
7686 that don't have one. We need to handle the case of a symbol with a
7687 missing symtab (DW_AT_decl_file) anyway. */
7690 /* Process DW_TAG_type_unit.
7691 For TUs we want to skip the first top level sibling if it's not the
7692 actual type being defined by this TU. In this case the first top
7693 level sibling is there to provide context only. */
7696 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7698 struct die_info
*child_die
;
7700 prepare_one_comp_unit (cu
, die
, language_minimal
);
7702 /* Initialize (or reinitialize) the machinery for building symtabs.
7703 We do this before processing child DIEs, so that the line header table
7704 is available for DW_AT_decl_file. */
7705 setup_type_unit_groups (die
, cu
);
7707 if (die
->child
!= NULL
)
7709 child_die
= die
->child
;
7710 while (child_die
&& child_die
->tag
)
7712 process_die (child_die
, cu
);
7713 child_die
= sibling_die (child_die
);
7721 hash_dwo_file (const void *item
)
7723 const struct dwo_file
*dwo_file
= item
;
7725 return htab_hash_string (dwo_file
->dwo_name
);
7729 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
7731 const struct dwo_file
*lhs
= item_lhs
;
7732 const struct dwo_file
*rhs
= item_rhs
;
7734 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
7737 /* Allocate a hash table for DWO files. */
7740 allocate_dwo_file_hash_table (void)
7742 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7744 return htab_create_alloc_ex (41,
7748 &objfile
->objfile_obstack
,
7749 hashtab_obstack_allocate
,
7750 dummy_obstack_deallocate
);
7754 hash_dwo_unit (const void *item
)
7756 const struct dwo_unit
*dwo_unit
= item
;
7758 /* This drops the top 32 bits of the id, but is ok for a hash. */
7759 return dwo_unit
->signature
;
7763 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
7765 const struct dwo_unit
*lhs
= item_lhs
;
7766 const struct dwo_unit
*rhs
= item_rhs
;
7768 /* The signature is assumed to be unique within the DWO file.
7769 So while object file CU dwo_id's always have the value zero,
7770 that's OK, assuming each object file DWO file has only one CU,
7771 and that's the rule for now. */
7772 return lhs
->signature
== rhs
->signature
;
7775 /* Allocate a hash table for DWO CUs,TUs.
7776 There is one of these tables for each of CUs,TUs for each DWO file. */
7779 allocate_dwo_unit_table (struct objfile
*objfile
)
7781 /* Start out with a pretty small number.
7782 Generally DWO files contain only one CU and maybe some TUs. */
7783 return htab_create_alloc_ex (3,
7787 &objfile
->objfile_obstack
,
7788 hashtab_obstack_allocate
,
7789 dummy_obstack_deallocate
);
7792 /* This function is mapped across the sections and remembers the offset and
7793 size of each of the DWO debugging sections we are interested in. */
7796 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
7798 struct dwo_file
*dwo_file
= dwo_file_ptr
;
7799 const struct dwo_section_names
*names
= &dwo_section_names
;
7801 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
7803 dwo_file
->sections
.abbrev
.asection
= sectp
;
7804 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
7806 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
7808 dwo_file
->sections
.info
.asection
= sectp
;
7809 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
7811 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
7813 dwo_file
->sections
.line
.asection
= sectp
;
7814 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
7816 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
7818 dwo_file
->sections
.loc
.asection
= sectp
;
7819 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
7821 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
7823 dwo_file
->sections
.macinfo
.asection
= sectp
;
7824 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
7826 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
7828 dwo_file
->sections
.macro
.asection
= sectp
;
7829 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
7831 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
7833 dwo_file
->sections
.str
.asection
= sectp
;
7834 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
7836 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
7838 dwo_file
->sections
.str_offsets
.asection
= sectp
;
7839 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
7841 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
7843 struct dwarf2_section_info type_section
;
7845 memset (&type_section
, 0, sizeof (type_section
));
7846 type_section
.asection
= sectp
;
7847 type_section
.size
= bfd_get_section_size (sectp
);
7848 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7853 /* Structure used to pass data to create_debug_info_hash_table_reader. */
7855 struct create_dwo_info_table_data
7857 struct dwo_file
*dwo_file
;
7861 /* die_reader_func for create_debug_info_hash_table. */
7864 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
7866 struct die_info
*comp_unit_die
,
7870 struct dwarf2_cu
*cu
= reader
->cu
;
7871 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7872 sect_offset offset
= cu
->per_cu
->offset
;
7873 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
7874 struct create_dwo_info_table_data
*data
= datap
;
7875 struct dwo_file
*dwo_file
= data
->dwo_file
;
7876 htab_t cu_htab
= data
->cu_htab
;
7878 struct attribute
*attr
;
7879 struct dwo_unit
*dwo_unit
;
7881 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7884 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
7885 " its dwo_id [in module %s]"),
7886 offset
.sect_off
, dwo_file
->dwo_name
);
7890 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
7891 dwo_unit
->dwo_file
= dwo_file
;
7892 dwo_unit
->signature
= DW_UNSND (attr
);
7893 dwo_unit
->info_or_types_section
= section
;
7894 dwo_unit
->offset
= offset
;
7895 dwo_unit
->length
= cu
->per_cu
->length
;
7897 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
7898 gdb_assert (slot
!= NULL
);
7901 const struct dwo_unit
*dup_dwo_unit
= *slot
;
7903 complaint (&symfile_complaints
,
7904 _("debug entry at offset 0x%x is duplicate to the entry at"
7905 " offset 0x%x, dwo_id 0x%s [in module %s]"),
7906 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
7907 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
7908 dwo_file
->dwo_name
);
7913 if (dwarf2_read_debug
)
7914 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
7916 phex (dwo_unit
->signature
,
7917 sizeof (dwo_unit
->signature
)));
7920 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
7923 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
7925 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7926 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
7929 gdb_byte
*info_ptr
, *end_ptr
;
7930 struct create_dwo_info_table_data create_dwo_info_table_data
;
7932 dwarf2_read_section (objfile
, section
);
7933 info_ptr
= section
->buffer
;
7935 if (info_ptr
== NULL
)
7938 /* We can't set abfd until now because the section may be empty or
7939 not present, in which case section->asection will be NULL. */
7940 abfd
= section
->asection
->owner
;
7942 if (dwarf2_read_debug
)
7943 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
7944 bfd_get_filename (abfd
));
7946 cu_htab
= allocate_dwo_unit_table (objfile
);
7948 create_dwo_info_table_data
.dwo_file
= dwo_file
;
7949 create_dwo_info_table_data
.cu_htab
= cu_htab
;
7951 end_ptr
= info_ptr
+ section
->size
;
7952 while (info_ptr
< end_ptr
)
7954 struct dwarf2_per_cu_data per_cu
;
7956 memset (&per_cu
, 0, sizeof (per_cu
));
7957 per_cu
.objfile
= objfile
;
7958 per_cu
.is_debug_types
= 0;
7959 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
7960 per_cu
.info_or_types_section
= section
;
7962 init_cutu_and_read_dies_no_follow (&per_cu
,
7963 &dwo_file
->sections
.abbrev
,
7965 create_debug_info_hash_table_reader
,
7966 &create_dwo_info_table_data
);
7968 info_ptr
+= per_cu
.length
;
7974 /* Subroutine of open_dwo_file to simplify it.
7975 Open the file specified by FILE_NAME and hand it off to BFD for
7976 preliminary analysis. Return a newly initialized bfd *, which
7977 includes a canonicalized copy of FILE_NAME.
7978 In case of trouble, return NULL.
7979 NOTE: This function is derived from symfile_bfd_open. */
7982 try_open_dwo_file (const char *file_name
)
7986 char *absolute_name
;
7988 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
7989 O_RDONLY
| O_BINARY
, &absolute_name
);
7993 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
7996 xfree (absolute_name
);
7999 gdb_bfd_stash_filename (sym_bfd
);
8000 xfree (absolute_name
);
8001 bfd_set_cacheable (sym_bfd
, 1);
8003 if (!bfd_check_format (sym_bfd
, bfd_object
))
8005 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8012 /* Try to open DWO file DWO_NAME.
8013 COMP_DIR is the DW_AT_comp_dir attribute.
8014 The result is the bfd handle of the file.
8015 If there is a problem finding or opening the file, return NULL.
8016 Upon success, the canonicalized path of the file is stored in the bfd,
8017 same as symfile_bfd_open. */
8020 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
8024 if (IS_ABSOLUTE_PATH (dwo_name
))
8025 return try_open_dwo_file (dwo_name
);
8027 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8029 if (comp_dir
!= NULL
)
8031 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
8033 /* NOTE: If comp_dir is a relative path, this will also try the
8034 search path, which seems useful. */
8035 abfd
= try_open_dwo_file (path_to_try
);
8036 xfree (path_to_try
);
8041 /* That didn't work, try debug-file-directory, which, despite its name,
8042 is a list of paths. */
8044 if (*debug_file_directory
== '\0')
8047 return try_open_dwo_file (dwo_name
);
8050 /* Initialize the use of the DWO file specified by DWO_NAME. */
8052 static struct dwo_file
*
8053 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8055 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8056 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8059 struct cleanup
*cleanups
;
8061 if (dwarf2_read_debug
)
8062 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
8064 abfd
= open_dwo_file (dwo_name
, comp_dir
);
8067 dwo_file
->dwo_name
= dwo_name
;
8068 dwo_file
->dwo_bfd
= abfd
;
8070 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8072 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
8074 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
8076 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8077 dwo_file
->sections
.types
);
8079 discard_cleanups (cleanups
);
8084 /* Lookup DWO file DWO_NAME. */
8086 static struct dwo_file
*
8087 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
8089 struct dwo_file
*dwo_file
;
8090 struct dwo_file find_entry
;
8093 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8094 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8096 /* Have we already seen this DWO file? */
8097 find_entry
.dwo_name
= dwo_name
;
8098 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8100 /* If not, read it in and build a table of the DWOs it contains. */
8102 *slot
= init_dwo_file (dwo_name
, comp_dir
);
8104 /* NOTE: This will be NULL if unable to open the file. */
8110 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
8111 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8112 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
8113 nomenclature as TUs).
8114 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8115 (dwo_id mismatch or couldn't find the DWO file). */
8117 static struct dwo_unit
*
8118 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8119 char *dwo_name
, const char *comp_dir
,
8122 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8123 struct dwo_file
*dwo_file
;
8125 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8126 if (dwo_file
== NULL
)
8129 /* Look up the DWO using its signature(dwo_id). */
8131 if (dwo_file
->cus
!= NULL
)
8133 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8135 find_dwo_cu
.signature
= signature
;
8136 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
8142 /* We didn't find it. This must mean a dwo_id mismatch. */
8144 complaint (&symfile_complaints
,
8145 _("Could not find DWO CU referenced by CU at offset 0x%x"
8147 this_cu
->offset
.sect_off
, objfile
->name
);
8151 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
8152 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8153 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8154 (dwo_id mismatch or couldn't find the DWO file). */
8156 static struct dwo_unit
*
8157 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
8158 char *dwo_name
, const char *comp_dir
)
8160 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8161 struct dwo_file
*dwo_file
;
8163 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8164 if (dwo_file
== NULL
)
8167 /* Look up the DWO using its signature(dwo_id). */
8169 if (dwo_file
->tus
!= NULL
)
8171 struct dwo_unit find_dwo_tu
, *dwo_tu
;
8173 find_dwo_tu
.signature
= this_tu
->signature
;
8174 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
8180 /* We didn't find it. This must mean a dwo_id mismatch. */
8182 complaint (&symfile_complaints
,
8183 _("Could not find DWO TU referenced by TU at offset 0x%x"
8185 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
8189 /* Free all resources associated with DWO_FILE.
8190 Close the DWO file and munmap the sections.
8191 All memory should be on the objfile obstack. */
8194 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
8197 struct dwarf2_section_info
*section
;
8199 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
8200 gdb_bfd_unref (dwo_file
->dwo_bfd
);
8202 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
8205 /* Wrapper for free_dwo_file for use in cleanups. */
8208 free_dwo_file_cleanup (void *arg
)
8210 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
8211 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8213 free_dwo_file (dwo_file
, objfile
);
8216 /* Traversal function for free_dwo_files. */
8219 free_dwo_file_from_slot (void **slot
, void *info
)
8221 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8222 struct objfile
*objfile
= (struct objfile
*) info
;
8224 free_dwo_file (dwo_file
, objfile
);
8229 /* Free all resources associated with DWO_FILES. */
8232 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
8234 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
8237 /* Read in various DIEs. */
8239 /* qsort helper for inherit_abstract_dies. */
8242 unsigned_int_compar (const void *ap
, const void *bp
)
8244 unsigned int a
= *(unsigned int *) ap
;
8245 unsigned int b
= *(unsigned int *) bp
;
8247 return (a
> b
) - (b
> a
);
8250 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
8251 Inherit only the children of the DW_AT_abstract_origin DIE not being
8252 already referenced by DW_AT_abstract_origin from the children of the
8256 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
8258 struct die_info
*child_die
;
8259 unsigned die_children_count
;
8260 /* CU offsets which were referenced by children of the current DIE. */
8261 sect_offset
*offsets
;
8262 sect_offset
*offsets_end
, *offsetp
;
8263 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
8264 struct die_info
*origin_die
;
8265 /* Iterator of the ORIGIN_DIE children. */
8266 struct die_info
*origin_child_die
;
8267 struct cleanup
*cleanups
;
8268 struct attribute
*attr
;
8269 struct dwarf2_cu
*origin_cu
;
8270 struct pending
**origin_previous_list_in_scope
;
8272 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8276 /* Note that following die references may follow to a die in a
8280 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
8282 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
8284 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
8285 origin_cu
->list_in_scope
= cu
->list_in_scope
;
8287 if (die
->tag
!= origin_die
->tag
8288 && !(die
->tag
== DW_TAG_inlined_subroutine
8289 && origin_die
->tag
== DW_TAG_subprogram
))
8290 complaint (&symfile_complaints
,
8291 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
8292 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
8294 child_die
= die
->child
;
8295 die_children_count
= 0;
8296 while (child_die
&& child_die
->tag
)
8298 child_die
= sibling_die (child_die
);
8299 die_children_count
++;
8301 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
8302 cleanups
= make_cleanup (xfree
, offsets
);
8304 offsets_end
= offsets
;
8305 child_die
= die
->child
;
8306 while (child_die
&& child_die
->tag
)
8308 /* For each CHILD_DIE, find the corresponding child of
8309 ORIGIN_DIE. If there is more than one layer of
8310 DW_AT_abstract_origin, follow them all; there shouldn't be,
8311 but GCC versions at least through 4.4 generate this (GCC PR
8313 struct die_info
*child_origin_die
= child_die
;
8314 struct dwarf2_cu
*child_origin_cu
= cu
;
8318 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
8322 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
8326 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
8327 counterpart may exist. */
8328 if (child_origin_die
!= child_die
)
8330 if (child_die
->tag
!= child_origin_die
->tag
8331 && !(child_die
->tag
== DW_TAG_inlined_subroutine
8332 && child_origin_die
->tag
== DW_TAG_subprogram
))
8333 complaint (&symfile_complaints
,
8334 _("Child DIE 0x%x and its abstract origin 0x%x have "
8335 "different tags"), child_die
->offset
.sect_off
,
8336 child_origin_die
->offset
.sect_off
);
8337 if (child_origin_die
->parent
!= origin_die
)
8338 complaint (&symfile_complaints
,
8339 _("Child DIE 0x%x and its abstract origin 0x%x have "
8340 "different parents"), child_die
->offset
.sect_off
,
8341 child_origin_die
->offset
.sect_off
);
8343 *offsets_end
++ = child_origin_die
->offset
;
8345 child_die
= sibling_die (child_die
);
8347 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
8348 unsigned_int_compar
);
8349 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
8350 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
8351 complaint (&symfile_complaints
,
8352 _("Multiple children of DIE 0x%x refer "
8353 "to DIE 0x%x as their abstract origin"),
8354 die
->offset
.sect_off
, offsetp
->sect_off
);
8357 origin_child_die
= origin_die
->child
;
8358 while (origin_child_die
&& origin_child_die
->tag
)
8360 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
8361 while (offsetp
< offsets_end
8362 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
8364 if (offsetp
>= offsets_end
8365 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
8367 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
8368 process_die (origin_child_die
, origin_cu
);
8370 origin_child_die
= sibling_die (origin_child_die
);
8372 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
8374 do_cleanups (cleanups
);
8378 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8380 struct objfile
*objfile
= cu
->objfile
;
8381 struct context_stack
*new;
8384 struct die_info
*child_die
;
8385 struct attribute
*attr
, *call_line
, *call_file
;
8388 struct block
*block
;
8389 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8390 VEC (symbolp
) *template_args
= NULL
;
8391 struct template_symbol
*templ_func
= NULL
;
8395 /* If we do not have call site information, we can't show the
8396 caller of this inlined function. That's too confusing, so
8397 only use the scope for local variables. */
8398 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
8399 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
8400 if (call_line
== NULL
|| call_file
== NULL
)
8402 read_lexical_block_scope (die
, cu
);
8407 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8409 name
= dwarf2_name (die
, cu
);
8411 /* Ignore functions with missing or empty names. These are actually
8412 illegal according to the DWARF standard. */
8415 complaint (&symfile_complaints
,
8416 _("missing name for subprogram DIE at %d"),
8417 die
->offset
.sect_off
);
8421 /* Ignore functions with missing or invalid low and high pc attributes. */
8422 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8424 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8425 if (!attr
|| !DW_UNSND (attr
))
8426 complaint (&symfile_complaints
,
8427 _("cannot get low and high bounds "
8428 "for subprogram DIE at %d"),
8429 die
->offset
.sect_off
);
8436 /* If we have any template arguments, then we must allocate a
8437 different sort of symbol. */
8438 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
8440 if (child_die
->tag
== DW_TAG_template_type_param
8441 || child_die
->tag
== DW_TAG_template_value_param
)
8443 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8444 struct template_symbol
);
8445 templ_func
->base
.is_cplus_template_function
= 1;
8450 new = push_context (0, lowpc
);
8451 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
8452 (struct symbol
*) templ_func
);
8454 /* If there is a location expression for DW_AT_frame_base, record
8456 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
8458 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
8459 expression is being recorded directly in the function's symbol
8460 and not in a separate frame-base object. I guess this hack is
8461 to avoid adding some sort of frame-base adjunct/annex to the
8462 function's symbol :-(. The problem with doing this is that it
8463 results in a function symbol with a location expression that
8464 has nothing to do with the location of the function, ouch! The
8465 relationship should be: a function's symbol has-a frame base; a
8466 frame-base has-a location expression. */
8467 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
8469 cu
->list_in_scope
= &local_symbols
;
8471 if (die
->child
!= NULL
)
8473 child_die
= die
->child
;
8474 while (child_die
&& child_die
->tag
)
8476 if (child_die
->tag
== DW_TAG_template_type_param
8477 || child_die
->tag
== DW_TAG_template_value_param
)
8479 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8482 VEC_safe_push (symbolp
, template_args
, arg
);
8485 process_die (child_die
, cu
);
8486 child_die
= sibling_die (child_die
);
8490 inherit_abstract_dies (die
, cu
);
8492 /* If we have a DW_AT_specification, we might need to import using
8493 directives from the context of the specification DIE. See the
8494 comment in determine_prefix. */
8495 if (cu
->language
== language_cplus
8496 && dwarf2_attr (die
, DW_AT_specification
, cu
))
8498 struct dwarf2_cu
*spec_cu
= cu
;
8499 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
8503 child_die
= spec_die
->child
;
8504 while (child_die
&& child_die
->tag
)
8506 if (child_die
->tag
== DW_TAG_imported_module
)
8507 process_die (child_die
, spec_cu
);
8508 child_die
= sibling_die (child_die
);
8511 /* In some cases, GCC generates specification DIEs that
8512 themselves contain DW_AT_specification attributes. */
8513 spec_die
= die_specification (spec_die
, &spec_cu
);
8517 new = pop_context ();
8518 /* Make a block for the local symbols within. */
8519 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
8520 lowpc
, highpc
, objfile
);
8522 /* For C++, set the block's scope. */
8523 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
8524 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
8525 determine_prefix (die
, cu
),
8526 processing_has_namespace_info
);
8528 /* If we have address ranges, record them. */
8529 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8531 /* Attach template arguments to function. */
8532 if (! VEC_empty (symbolp
, template_args
))
8534 gdb_assert (templ_func
!= NULL
);
8536 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
8537 templ_func
->template_arguments
8538 = obstack_alloc (&objfile
->objfile_obstack
,
8539 (templ_func
->n_template_arguments
8540 * sizeof (struct symbol
*)));
8541 memcpy (templ_func
->template_arguments
,
8542 VEC_address (symbolp
, template_args
),
8543 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
8544 VEC_free (symbolp
, template_args
);
8547 /* In C++, we can have functions nested inside functions (e.g., when
8548 a function declares a class that has methods). This means that
8549 when we finish processing a function scope, we may need to go
8550 back to building a containing block's symbol lists. */
8551 local_symbols
= new->locals
;
8552 param_symbols
= new->params
;
8553 using_directives
= new->using_directives
;
8555 /* If we've finished processing a top-level function, subsequent
8556 symbols go in the file symbol list. */
8557 if (outermost_context_p ())
8558 cu
->list_in_scope
= &file_symbols
;
8561 /* Process all the DIES contained within a lexical block scope. Start
8562 a new scope, process the dies, and then close the scope. */
8565 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8567 struct objfile
*objfile
= cu
->objfile
;
8568 struct context_stack
*new;
8569 CORE_ADDR lowpc
, highpc
;
8570 struct die_info
*child_die
;
8573 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8575 /* Ignore blocks with missing or invalid low and high pc attributes. */
8576 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
8577 as multiple lexical blocks? Handling children in a sane way would
8578 be nasty. Might be easier to properly extend generic blocks to
8580 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8585 push_context (0, lowpc
);
8586 if (die
->child
!= NULL
)
8588 child_die
= die
->child
;
8589 while (child_die
&& child_die
->tag
)
8591 process_die (child_die
, cu
);
8592 child_die
= sibling_die (child_die
);
8595 new = pop_context ();
8597 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
8600 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
8603 /* Note that recording ranges after traversing children, as we
8604 do here, means that recording a parent's ranges entails
8605 walking across all its children's ranges as they appear in
8606 the address map, which is quadratic behavior.
8608 It would be nicer to record the parent's ranges before
8609 traversing its children, simply overriding whatever you find
8610 there. But since we don't even decide whether to create a
8611 block until after we've traversed its children, that's hard
8613 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8615 local_symbols
= new->locals
;
8616 using_directives
= new->using_directives
;
8619 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
8622 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8624 struct objfile
*objfile
= cu
->objfile
;
8625 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8626 CORE_ADDR pc
, baseaddr
;
8627 struct attribute
*attr
;
8628 struct call_site
*call_site
, call_site_local
;
8631 struct die_info
*child_die
;
8633 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8635 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8638 complaint (&symfile_complaints
,
8639 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
8640 "DIE 0x%x [in module %s]"),
8641 die
->offset
.sect_off
, objfile
->name
);
8644 pc
= DW_ADDR (attr
) + baseaddr
;
8646 if (cu
->call_site_htab
== NULL
)
8647 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
8648 NULL
, &objfile
->objfile_obstack
,
8649 hashtab_obstack_allocate
, NULL
);
8650 call_site_local
.pc
= pc
;
8651 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
8654 complaint (&symfile_complaints
,
8655 _("Duplicate PC %s for DW_TAG_GNU_call_site "
8656 "DIE 0x%x [in module %s]"),
8657 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
8661 /* Count parameters at the caller. */
8664 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8665 child_die
= sibling_die (child_die
))
8667 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8669 complaint (&symfile_complaints
,
8670 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
8671 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8672 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
8679 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
8680 (sizeof (*call_site
)
8681 + (sizeof (*call_site
->parameter
)
8684 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
8687 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
8689 struct die_info
*func_die
;
8691 /* Skip also over DW_TAG_inlined_subroutine. */
8692 for (func_die
= die
->parent
;
8693 func_die
&& func_die
->tag
!= DW_TAG_subprogram
8694 && func_die
->tag
!= DW_TAG_subroutine_type
;
8695 func_die
= func_die
->parent
);
8697 /* DW_AT_GNU_all_call_sites is a superset
8698 of DW_AT_GNU_all_tail_call_sites. */
8700 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
8701 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
8703 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
8704 not complete. But keep CALL_SITE for look ups via call_site_htab,
8705 both the initial caller containing the real return address PC and
8706 the final callee containing the current PC of a chain of tail
8707 calls do not need to have the tail call list complete. But any
8708 function candidate for a virtual tail call frame searched via
8709 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
8710 determined unambiguously. */
8714 struct type
*func_type
= NULL
;
8717 func_type
= get_die_type (func_die
, cu
);
8718 if (func_type
!= NULL
)
8720 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
8722 /* Enlist this call site to the function. */
8723 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
8724 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
8727 complaint (&symfile_complaints
,
8728 _("Cannot find function owning DW_TAG_GNU_call_site "
8729 "DIE 0x%x [in module %s]"),
8730 die
->offset
.sect_off
, objfile
->name
);
8734 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
8736 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8737 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
8738 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
8739 /* Keep NULL DWARF_BLOCK. */;
8740 else if (attr_form_is_block (attr
))
8742 struct dwarf2_locexpr_baton
*dlbaton
;
8744 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
8745 dlbaton
->data
= DW_BLOCK (attr
)->data
;
8746 dlbaton
->size
= DW_BLOCK (attr
)->size
;
8747 dlbaton
->per_cu
= cu
->per_cu
;
8749 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
8751 else if (is_ref_attr (attr
))
8753 struct dwarf2_cu
*target_cu
= cu
;
8754 struct die_info
*target_die
;
8756 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
8757 gdb_assert (target_cu
->objfile
== objfile
);
8758 if (die_is_declaration (target_die
, target_cu
))
8760 const char *target_physname
;
8762 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
8763 if (target_physname
== NULL
)
8764 complaint (&symfile_complaints
,
8765 _("DW_AT_GNU_call_site_target target DIE has invalid "
8766 "physname, for referencing DIE 0x%x [in module %s]"),
8767 die
->offset
.sect_off
, objfile
->name
);
8769 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
8775 /* DW_AT_entry_pc should be preferred. */
8776 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
8777 complaint (&symfile_complaints
,
8778 _("DW_AT_GNU_call_site_target target DIE has invalid "
8779 "low pc, for referencing DIE 0x%x [in module %s]"),
8780 die
->offset
.sect_off
, objfile
->name
);
8782 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
8786 complaint (&symfile_complaints
,
8787 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
8788 "block nor reference, for DIE 0x%x [in module %s]"),
8789 die
->offset
.sect_off
, objfile
->name
);
8791 call_site
->per_cu
= cu
->per_cu
;
8793 for (child_die
= die
->child
;
8794 child_die
&& child_die
->tag
;
8795 child_die
= sibling_die (child_die
))
8797 struct call_site_parameter
*parameter
;
8798 struct attribute
*loc
, *origin
;
8800 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8802 /* Already printed the complaint above. */
8806 gdb_assert (call_site
->parameter_count
< nparams
);
8807 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
8809 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
8810 specifies DW_TAG_formal_parameter. Value of the data assumed for the
8811 register is contained in DW_AT_GNU_call_site_value. */
8813 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
8814 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
8815 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
8819 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
8820 offset
= dwarf2_get_ref_die_offset (origin
);
8821 if (!offset_in_cu_p (&cu
->header
, offset
))
8823 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
8824 binding can be done only inside one CU. Such referenced DIE
8825 therefore cannot be even moved to DW_TAG_partial_unit. */
8826 complaint (&symfile_complaints
,
8827 _("DW_AT_abstract_origin offset is not in CU for "
8828 "DW_TAG_GNU_call_site child DIE 0x%x "
8830 child_die
->offset
.sect_off
, objfile
->name
);
8833 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
8834 - cu
->header
.offset
.sect_off
);
8836 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
8838 complaint (&symfile_complaints
,
8839 _("No DW_FORM_block* DW_AT_location for "
8840 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8841 child_die
->offset
.sect_off
, objfile
->name
);
8846 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
8847 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
8848 if (parameter
->u
.dwarf_reg
!= -1)
8849 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
8850 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
8851 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
8852 ¶meter
->u
.fb_offset
))
8853 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
8856 complaint (&symfile_complaints
,
8857 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
8858 "for DW_FORM_block* DW_AT_location is supported for "
8859 "DW_TAG_GNU_call_site child DIE 0x%x "
8861 child_die
->offset
.sect_off
, objfile
->name
);
8866 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
8867 if (!attr_form_is_block (attr
))
8869 complaint (&symfile_complaints
,
8870 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
8871 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8872 child_die
->offset
.sect_off
, objfile
->name
);
8875 parameter
->value
= DW_BLOCK (attr
)->data
;
8876 parameter
->value_size
= DW_BLOCK (attr
)->size
;
8878 /* Parameters are not pre-cleared by memset above. */
8879 parameter
->data_value
= NULL
;
8880 parameter
->data_value_size
= 0;
8881 call_site
->parameter_count
++;
8883 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
8886 if (!attr_form_is_block (attr
))
8887 complaint (&symfile_complaints
,
8888 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
8889 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8890 child_die
->offset
.sect_off
, objfile
->name
);
8893 parameter
->data_value
= DW_BLOCK (attr
)->data
;
8894 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
8900 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
8901 Return 1 if the attributes are present and valid, otherwise, return 0.
8902 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
8905 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
8906 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
8907 struct partial_symtab
*ranges_pst
)
8909 struct objfile
*objfile
= cu
->objfile
;
8910 struct comp_unit_head
*cu_header
= &cu
->header
;
8911 bfd
*obfd
= objfile
->obfd
;
8912 unsigned int addr_size
= cu_header
->addr_size
;
8913 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8914 /* Base address selection entry. */
8925 found_base
= cu
->base_known
;
8926 base
= cu
->base_address
;
8928 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
8929 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8931 complaint (&symfile_complaints
,
8932 _("Offset %d out of bounds for DW_AT_ranges attribute"),
8936 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8938 /* Read in the largest possible address. */
8939 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
8940 if ((marker
& mask
) == mask
)
8942 /* If we found the largest possible address, then
8943 read the base address. */
8944 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8945 buffer
+= 2 * addr_size
;
8946 offset
+= 2 * addr_size
;
8952 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8956 CORE_ADDR range_beginning
, range_end
;
8958 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
8959 buffer
+= addr_size
;
8960 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
8961 buffer
+= addr_size
;
8962 offset
+= 2 * addr_size
;
8964 /* An end of list marker is a pair of zero addresses. */
8965 if (range_beginning
== 0 && range_end
== 0)
8966 /* Found the end of list entry. */
8969 /* Each base address selection entry is a pair of 2 values.
8970 The first is the largest possible address, the second is
8971 the base address. Check for a base address here. */
8972 if ((range_beginning
& mask
) == mask
)
8974 /* If we found the largest possible address, then
8975 read the base address. */
8976 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8983 /* We have no valid base address for the ranges
8985 complaint (&symfile_complaints
,
8986 _("Invalid .debug_ranges data (no base address)"));
8990 if (range_beginning
> range_end
)
8992 /* Inverted range entries are invalid. */
8993 complaint (&symfile_complaints
,
8994 _("Invalid .debug_ranges data (inverted range)"));
8998 /* Empty range entries have no effect. */
8999 if (range_beginning
== range_end
)
9002 range_beginning
+= base
;
9005 if (ranges_pst
!= NULL
)
9006 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9007 range_beginning
+ baseaddr
,
9008 range_end
- 1 + baseaddr
,
9011 /* FIXME: This is recording everything as a low-high
9012 segment of consecutive addresses. We should have a
9013 data structure for discontiguous block ranges
9017 low
= range_beginning
;
9023 if (range_beginning
< low
)
9024 low
= range_beginning
;
9025 if (range_end
> high
)
9031 /* If the first entry is an end-of-list marker, the range
9032 describes an empty scope, i.e. no instructions. */
9038 *high_return
= high
;
9042 /* Get low and high pc attributes from a die. Return 1 if the attributes
9043 are present and valid, otherwise, return 0. Return -1 if the range is
9044 discontinuous, i.e. derived from DW_AT_ranges information. */
9047 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
9048 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
9049 struct partial_symtab
*pst
)
9051 struct attribute
*attr
;
9052 struct attribute
*attr_high
;
9057 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9060 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9063 low
= DW_ADDR (attr
);
9064 if (attr_high
->form
== DW_FORM_addr
9065 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9066 high
= DW_ADDR (attr_high
);
9068 high
= low
+ DW_UNSND (attr_high
);
9071 /* Found high w/o low attribute. */
9074 /* Found consecutive range of addresses. */
9079 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9082 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9084 /* Value of the DW_AT_ranges attribute is the offset in the
9085 .debug_ranges section. */
9086 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
9088 /* Found discontinuous range of addresses. */
9093 /* read_partial_die has also the strict LOW < HIGH requirement. */
9097 /* When using the GNU linker, .gnu.linkonce. sections are used to
9098 eliminate duplicate copies of functions and vtables and such.
9099 The linker will arbitrarily choose one and discard the others.
9100 The AT_*_pc values for such functions refer to local labels in
9101 these sections. If the section from that file was discarded, the
9102 labels are not in the output, so the relocs get a value of 0.
9103 If this is a discarded function, mark the pc bounds as invalid,
9104 so that GDB will ignore it. */
9105 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9114 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
9115 its low and high PC addresses. Do nothing if these addresses could not
9116 be determined. Otherwise, set LOWPC to the low address if it is smaller,
9117 and HIGHPC to the high address if greater than HIGHPC. */
9120 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
9121 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9122 struct dwarf2_cu
*cu
)
9124 CORE_ADDR low
, high
;
9125 struct die_info
*child
= die
->child
;
9127 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
9129 *lowpc
= min (*lowpc
, low
);
9130 *highpc
= max (*highpc
, high
);
9133 /* If the language does not allow nested subprograms (either inside
9134 subprograms or lexical blocks), we're done. */
9135 if (cu
->language
!= language_ada
)
9138 /* Check all the children of the given DIE. If it contains nested
9139 subprograms, then check their pc bounds. Likewise, we need to
9140 check lexical blocks as well, as they may also contain subprogram
9142 while (child
&& child
->tag
)
9144 if (child
->tag
== DW_TAG_subprogram
9145 || child
->tag
== DW_TAG_lexical_block
)
9146 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
9147 child
= sibling_die (child
);
9151 /* Get the low and high pc's represented by the scope DIE, and store
9152 them in *LOWPC and *HIGHPC. If the correct values can't be
9153 determined, set *LOWPC to -1 and *HIGHPC to 0. */
9156 get_scope_pc_bounds (struct die_info
*die
,
9157 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9158 struct dwarf2_cu
*cu
)
9160 CORE_ADDR best_low
= (CORE_ADDR
) -1;
9161 CORE_ADDR best_high
= (CORE_ADDR
) 0;
9162 CORE_ADDR current_low
, current_high
;
9164 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
9166 best_low
= current_low
;
9167 best_high
= current_high
;
9171 struct die_info
*child
= die
->child
;
9173 while (child
&& child
->tag
)
9175 switch (child
->tag
) {
9176 case DW_TAG_subprogram
:
9177 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
9179 case DW_TAG_namespace
:
9181 /* FIXME: carlton/2004-01-16: Should we do this for
9182 DW_TAG_class_type/DW_TAG_structure_type, too? I think
9183 that current GCC's always emit the DIEs corresponding
9184 to definitions of methods of classes as children of a
9185 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
9186 the DIEs giving the declarations, which could be
9187 anywhere). But I don't see any reason why the
9188 standards says that they have to be there. */
9189 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
9191 if (current_low
!= ((CORE_ADDR
) -1))
9193 best_low
= min (best_low
, current_low
);
9194 best_high
= max (best_high
, current_high
);
9202 child
= sibling_die (child
);
9207 *highpc
= best_high
;
9210 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
9214 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
9215 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
9217 struct objfile
*objfile
= cu
->objfile
;
9218 struct attribute
*attr
;
9219 struct attribute
*attr_high
;
9221 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9224 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9227 CORE_ADDR low
= DW_ADDR (attr
);
9229 if (attr_high
->form
== DW_FORM_addr
9230 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9231 high
= DW_ADDR (attr_high
);
9233 high
= low
+ DW_UNSND (attr_high
);
9235 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
9239 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9242 bfd
*obfd
= objfile
->obfd
;
9244 /* The value of the DW_AT_ranges attribute is the offset of the
9245 address range list in the .debug_ranges section. */
9246 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9247 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9249 /* For some target architectures, but not others, the
9250 read_address function sign-extends the addresses it returns.
9251 To recognize base address selection entries, we need a
9253 unsigned int addr_size
= cu
->header
.addr_size
;
9254 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9256 /* The base address, to which the next pair is relative. Note
9257 that this 'base' is a DWARF concept: most entries in a range
9258 list are relative, to reduce the number of relocs against the
9259 debugging information. This is separate from this function's
9260 'baseaddr' argument, which GDB uses to relocate debugging
9261 information from a shared library based on the address at
9262 which the library was loaded. */
9263 CORE_ADDR base
= cu
->base_address
;
9264 int base_known
= cu
->base_known
;
9266 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
9267 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9269 complaint (&symfile_complaints
,
9270 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
9277 unsigned int bytes_read
;
9278 CORE_ADDR start
, end
;
9280 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9281 buffer
+= bytes_read
;
9282 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9283 buffer
+= bytes_read
;
9285 /* Did we find the end of the range list? */
9286 if (start
== 0 && end
== 0)
9289 /* Did we find a base address selection entry? */
9290 else if ((start
& base_select_mask
) == base_select_mask
)
9296 /* We found an ordinary address range. */
9301 complaint (&symfile_complaints
,
9302 _("Invalid .debug_ranges data "
9303 "(no base address)"));
9309 /* Inverted range entries are invalid. */
9310 complaint (&symfile_complaints
,
9311 _("Invalid .debug_ranges data "
9312 "(inverted range)"));
9316 /* Empty range entries have no effect. */
9320 record_block_range (block
,
9321 baseaddr
+ base
+ start
,
9322 baseaddr
+ base
+ end
- 1);
9328 /* Check whether the producer field indicates either of GCC < 4.6, or the
9329 Intel C/C++ compiler, and cache the result in CU. */
9332 check_producer (struct dwarf2_cu
*cu
)
9335 int major
, minor
, release
;
9337 if (cu
->producer
== NULL
)
9339 /* For unknown compilers expect their behavior is DWARF version
9342 GCC started to support .debug_types sections by -gdwarf-4 since
9343 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
9344 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
9345 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
9346 interpreted incorrectly by GDB now - GCC PR debug/48229. */
9348 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
9350 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
9352 cs
= &cu
->producer
[strlen ("GNU ")];
9353 while (*cs
&& !isdigit (*cs
))
9355 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
9357 /* Not recognized as GCC. */
9360 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
9362 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
9363 cu
->producer_is_icc
= 1;
9366 /* For other non-GCC compilers, expect their behavior is DWARF version
9370 cu
->checked_producer
= 1;
9373 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
9374 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
9375 during 4.6.0 experimental. */
9378 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
9380 if (!cu
->checked_producer
)
9381 check_producer (cu
);
9383 return cu
->producer_is_gxx_lt_4_6
;
9386 /* Return the default accessibility type if it is not overriden by
9387 DW_AT_accessibility. */
9389 static enum dwarf_access_attribute
9390 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
9392 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
9394 /* The default DWARF 2 accessibility for members is public, the default
9395 accessibility for inheritance is private. */
9397 if (die
->tag
!= DW_TAG_inheritance
)
9398 return DW_ACCESS_public
;
9400 return DW_ACCESS_private
;
9404 /* DWARF 3+ defines the default accessibility a different way. The same
9405 rules apply now for DW_TAG_inheritance as for the members and it only
9406 depends on the container kind. */
9408 if (die
->parent
->tag
== DW_TAG_class_type
)
9409 return DW_ACCESS_private
;
9411 return DW_ACCESS_public
;
9415 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
9416 offset. If the attribute was not found return 0, otherwise return
9417 1. If it was found but could not properly be handled, set *OFFSET
9421 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
9424 struct attribute
*attr
;
9426 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
9431 /* Note that we do not check for a section offset first here.
9432 This is because DW_AT_data_member_location is new in DWARF 4,
9433 so if we see it, we can assume that a constant form is really
9434 a constant and not a section offset. */
9435 if (attr_form_is_constant (attr
))
9436 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
9437 else if (attr_form_is_section_offset (attr
))
9438 dwarf2_complex_location_expr_complaint ();
9439 else if (attr_form_is_block (attr
))
9440 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9442 dwarf2_complex_location_expr_complaint ();
9450 /* Add an aggregate field to the field list. */
9453 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
9454 struct dwarf2_cu
*cu
)
9456 struct objfile
*objfile
= cu
->objfile
;
9457 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9458 struct nextfield
*new_field
;
9459 struct attribute
*attr
;
9461 char *fieldname
= "";
9463 /* Allocate a new field list entry and link it in. */
9464 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
9465 make_cleanup (xfree
, new_field
);
9466 memset (new_field
, 0, sizeof (struct nextfield
));
9468 if (die
->tag
== DW_TAG_inheritance
)
9470 new_field
->next
= fip
->baseclasses
;
9471 fip
->baseclasses
= new_field
;
9475 new_field
->next
= fip
->fields
;
9476 fip
->fields
= new_field
;
9480 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9482 new_field
->accessibility
= DW_UNSND (attr
);
9484 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
9485 if (new_field
->accessibility
!= DW_ACCESS_public
)
9486 fip
->non_public_fields
= 1;
9488 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9490 new_field
->virtuality
= DW_UNSND (attr
);
9492 new_field
->virtuality
= DW_VIRTUALITY_none
;
9494 fp
= &new_field
->field
;
9496 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
9500 /* Data member other than a C++ static data member. */
9502 /* Get type of field. */
9503 fp
->type
= die_type (die
, cu
);
9505 SET_FIELD_BITPOS (*fp
, 0);
9507 /* Get bit size of field (zero if none). */
9508 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
9511 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
9515 FIELD_BITSIZE (*fp
) = 0;
9518 /* Get bit offset of field. */
9519 if (handle_data_member_location (die
, cu
, &offset
))
9520 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9521 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
9524 if (gdbarch_bits_big_endian (gdbarch
))
9526 /* For big endian bits, the DW_AT_bit_offset gives the
9527 additional bit offset from the MSB of the containing
9528 anonymous object to the MSB of the field. We don't
9529 have to do anything special since we don't need to
9530 know the size of the anonymous object. */
9531 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
9535 /* For little endian bits, compute the bit offset to the
9536 MSB of the anonymous object, subtract off the number of
9537 bits from the MSB of the field to the MSB of the
9538 object, and then subtract off the number of bits of
9539 the field itself. The result is the bit offset of
9540 the LSB of the field. */
9542 int bit_offset
= DW_UNSND (attr
);
9544 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9547 /* The size of the anonymous object containing
9548 the bit field is explicit, so use the
9549 indicated size (in bytes). */
9550 anonymous_size
= DW_UNSND (attr
);
9554 /* The size of the anonymous object containing
9555 the bit field must be inferred from the type
9556 attribute of the data member containing the
9558 anonymous_size
= TYPE_LENGTH (fp
->type
);
9560 SET_FIELD_BITPOS (*fp
,
9562 + anonymous_size
* bits_per_byte
9563 - bit_offset
- FIELD_BITSIZE (*fp
)));
9567 /* Get name of field. */
9568 fieldname
= dwarf2_name (die
, cu
);
9569 if (fieldname
== NULL
)
9572 /* The name is already allocated along with this objfile, so we don't
9573 need to duplicate it for the type. */
9574 fp
->name
= fieldname
;
9576 /* Change accessibility for artificial fields (e.g. virtual table
9577 pointer or virtual base class pointer) to private. */
9578 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
9580 FIELD_ARTIFICIAL (*fp
) = 1;
9581 new_field
->accessibility
= DW_ACCESS_private
;
9582 fip
->non_public_fields
= 1;
9585 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
9587 /* C++ static member. */
9589 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
9590 is a declaration, but all versions of G++ as of this writing
9591 (so through at least 3.2.1) incorrectly generate
9592 DW_TAG_variable tags. */
9594 const char *physname
;
9596 /* Get name of field. */
9597 fieldname
= dwarf2_name (die
, cu
);
9598 if (fieldname
== NULL
)
9601 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9603 /* Only create a symbol if this is an external value.
9604 new_symbol checks this and puts the value in the global symbol
9605 table, which we want. If it is not external, new_symbol
9606 will try to put the value in cu->list_in_scope which is wrong. */
9607 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
9609 /* A static const member, not much different than an enum as far as
9610 we're concerned, except that we can support more types. */
9611 new_symbol (die
, NULL
, cu
);
9614 /* Get physical name. */
9615 physname
= dwarf2_physname (fieldname
, die
, cu
);
9617 /* The name is already allocated along with this objfile, so we don't
9618 need to duplicate it for the type. */
9619 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
9620 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9621 FIELD_NAME (*fp
) = fieldname
;
9623 else if (die
->tag
== DW_TAG_inheritance
)
9627 /* C++ base class field. */
9628 if (handle_data_member_location (die
, cu
, &offset
))
9629 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9630 FIELD_BITSIZE (*fp
) = 0;
9631 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9632 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
9633 fip
->nbaseclasses
++;
9637 /* Add a typedef defined in the scope of the FIP's class. */
9640 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
9641 struct dwarf2_cu
*cu
)
9643 struct objfile
*objfile
= cu
->objfile
;
9644 struct typedef_field_list
*new_field
;
9645 struct attribute
*attr
;
9646 struct typedef_field
*fp
;
9647 char *fieldname
= "";
9649 /* Allocate a new field list entry and link it in. */
9650 new_field
= xzalloc (sizeof (*new_field
));
9651 make_cleanup (xfree
, new_field
);
9653 gdb_assert (die
->tag
== DW_TAG_typedef
);
9655 fp
= &new_field
->field
;
9657 /* Get name of field. */
9658 fp
->name
= dwarf2_name (die
, cu
);
9659 if (fp
->name
== NULL
)
9662 fp
->type
= read_type_die (die
, cu
);
9664 new_field
->next
= fip
->typedef_field_list
;
9665 fip
->typedef_field_list
= new_field
;
9666 fip
->typedef_field_list_count
++;
9669 /* Create the vector of fields, and attach it to the type. */
9672 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
9673 struct dwarf2_cu
*cu
)
9675 int nfields
= fip
->nfields
;
9677 /* Record the field count, allocate space for the array of fields,
9678 and create blank accessibility bitfields if necessary. */
9679 TYPE_NFIELDS (type
) = nfields
;
9680 TYPE_FIELDS (type
) = (struct field
*)
9681 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
9682 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
9684 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
9686 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9688 TYPE_FIELD_PRIVATE_BITS (type
) =
9689 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9690 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
9692 TYPE_FIELD_PROTECTED_BITS (type
) =
9693 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9694 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
9696 TYPE_FIELD_IGNORE_BITS (type
) =
9697 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9698 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
9701 /* If the type has baseclasses, allocate and clear a bit vector for
9702 TYPE_FIELD_VIRTUAL_BITS. */
9703 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
9705 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
9706 unsigned char *pointer
;
9708 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9709 pointer
= TYPE_ALLOC (type
, num_bytes
);
9710 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
9711 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
9712 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
9715 /* Copy the saved-up fields into the field vector. Start from the head of
9716 the list, adding to the tail of the field array, so that they end up in
9717 the same order in the array in which they were added to the list. */
9718 while (nfields
-- > 0)
9720 struct nextfield
*fieldp
;
9724 fieldp
= fip
->fields
;
9725 fip
->fields
= fieldp
->next
;
9729 fieldp
= fip
->baseclasses
;
9730 fip
->baseclasses
= fieldp
->next
;
9733 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
9734 switch (fieldp
->accessibility
)
9736 case DW_ACCESS_private
:
9737 if (cu
->language
!= language_ada
)
9738 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
9741 case DW_ACCESS_protected
:
9742 if (cu
->language
!= language_ada
)
9743 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
9746 case DW_ACCESS_public
:
9750 /* Unknown accessibility. Complain and treat it as public. */
9752 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
9753 fieldp
->accessibility
);
9757 if (nfields
< fip
->nbaseclasses
)
9759 switch (fieldp
->virtuality
)
9761 case DW_VIRTUALITY_virtual
:
9762 case DW_VIRTUALITY_pure_virtual
:
9763 if (cu
->language
== language_ada
)
9764 error (_("unexpected virtuality in component of Ada type"));
9765 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
9772 /* Add a member function to the proper fieldlist. */
9775 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
9776 struct type
*type
, struct dwarf2_cu
*cu
)
9778 struct objfile
*objfile
= cu
->objfile
;
9779 struct attribute
*attr
;
9780 struct fnfieldlist
*flp
;
9782 struct fn_field
*fnp
;
9784 struct nextfnfield
*new_fnfield
;
9785 struct type
*this_type
;
9786 enum dwarf_access_attribute accessibility
;
9788 if (cu
->language
== language_ada
)
9789 error (_("unexpected member function in Ada type"));
9791 /* Get name of member function. */
9792 fieldname
= dwarf2_name (die
, cu
);
9793 if (fieldname
== NULL
)
9796 /* Look up member function name in fieldlist. */
9797 for (i
= 0; i
< fip
->nfnfields
; i
++)
9799 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
9803 /* Create new list element if necessary. */
9804 if (i
< fip
->nfnfields
)
9805 flp
= &fip
->fnfieldlists
[i
];
9808 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9810 fip
->fnfieldlists
= (struct fnfieldlist
*)
9811 xrealloc (fip
->fnfieldlists
,
9812 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
9813 * sizeof (struct fnfieldlist
));
9814 if (fip
->nfnfields
== 0)
9815 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
9817 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
9818 flp
->name
= fieldname
;
9821 i
= fip
->nfnfields
++;
9824 /* Create a new member function field and chain it to the field list
9826 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
9827 make_cleanup (xfree
, new_fnfield
);
9828 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
9829 new_fnfield
->next
= flp
->head
;
9830 flp
->head
= new_fnfield
;
9833 /* Fill in the member function field info. */
9834 fnp
= &new_fnfield
->fnfield
;
9836 /* Delay processing of the physname until later. */
9837 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
9839 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
9844 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
9845 fnp
->physname
= physname
? physname
: "";
9848 fnp
->type
= alloc_type (objfile
);
9849 this_type
= read_type_die (die
, cu
);
9850 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
9852 int nparams
= TYPE_NFIELDS (this_type
);
9854 /* TYPE is the domain of this method, and THIS_TYPE is the type
9855 of the method itself (TYPE_CODE_METHOD). */
9856 smash_to_method_type (fnp
->type
, type
,
9857 TYPE_TARGET_TYPE (this_type
),
9858 TYPE_FIELDS (this_type
),
9859 TYPE_NFIELDS (this_type
),
9860 TYPE_VARARGS (this_type
));
9862 /* Handle static member functions.
9863 Dwarf2 has no clean way to discern C++ static and non-static
9864 member functions. G++ helps GDB by marking the first
9865 parameter for non-static member functions (which is the this
9866 pointer) as artificial. We obtain this information from
9867 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
9868 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
9869 fnp
->voffset
= VOFFSET_STATIC
;
9872 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
9873 dwarf2_full_name (fieldname
, die
, cu
));
9875 /* Get fcontext from DW_AT_containing_type if present. */
9876 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9877 fnp
->fcontext
= die_containing_type (die
, cu
);
9879 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
9880 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
9882 /* Get accessibility. */
9883 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9885 accessibility
= DW_UNSND (attr
);
9887 accessibility
= dwarf2_default_access_attribute (die
, cu
);
9888 switch (accessibility
)
9890 case DW_ACCESS_private
:
9891 fnp
->is_private
= 1;
9893 case DW_ACCESS_protected
:
9894 fnp
->is_protected
= 1;
9898 /* Check for artificial methods. */
9899 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
9900 if (attr
&& DW_UNSND (attr
) != 0)
9901 fnp
->is_artificial
= 1;
9903 /* Get index in virtual function table if it is a virtual member
9904 function. For older versions of GCC, this is an offset in the
9905 appropriate virtual table, as specified by DW_AT_containing_type.
9906 For everyone else, it is an expression to be evaluated relative
9907 to the object address. */
9909 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
9912 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
9914 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
9916 /* Old-style GCC. */
9917 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
9919 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9920 || (DW_BLOCK (attr
)->size
> 1
9921 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
9922 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
9924 struct dwarf_block blk
;
9927 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9929 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
9930 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
9931 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9932 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
9933 dwarf2_complex_location_expr_complaint ();
9935 fnp
->voffset
/= cu
->header
.addr_size
;
9939 dwarf2_complex_location_expr_complaint ();
9942 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
9944 else if (attr_form_is_section_offset (attr
))
9946 dwarf2_complex_location_expr_complaint ();
9950 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
9956 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9957 if (attr
&& DW_UNSND (attr
))
9959 /* GCC does this, as of 2008-08-25; PR debug/37237. */
9960 complaint (&symfile_complaints
,
9961 _("Member function \"%s\" (offset %d) is virtual "
9962 "but the vtable offset is not specified"),
9963 fieldname
, die
->offset
.sect_off
);
9964 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9965 TYPE_CPLUS_DYNAMIC (type
) = 1;
9970 /* Create the vector of member function fields, and attach it to the type. */
9973 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
9974 struct dwarf2_cu
*cu
)
9976 struct fnfieldlist
*flp
;
9979 if (cu
->language
== language_ada
)
9980 error (_("unexpected member functions in Ada type"));
9982 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9983 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
9984 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
9986 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
9988 struct nextfnfield
*nfp
= flp
->head
;
9989 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
9992 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
9993 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
9994 fn_flp
->fn_fields
= (struct fn_field
*)
9995 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
9996 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
9997 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
10000 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
10003 /* Returns non-zero if NAME is the name of a vtable member in CU's
10004 language, zero otherwise. */
10006 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
10008 static const char vptr
[] = "_vptr";
10009 static const char vtable
[] = "vtable";
10011 /* Look for the C++ and Java forms of the vtable. */
10012 if ((cu
->language
== language_java
10013 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
10014 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
10015 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
10021 /* GCC outputs unnamed structures that are really pointers to member
10022 functions, with the ABI-specified layout. If TYPE describes
10023 such a structure, smash it into a member function type.
10025 GCC shouldn't do this; it should just output pointer to member DIEs.
10026 This is GCC PR debug/28767. */
10029 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
10031 struct type
*pfn_type
, *domain_type
, *new_type
;
10033 /* Check for a structure with no name and two children. */
10034 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
10037 /* Check for __pfn and __delta members. */
10038 if (TYPE_FIELD_NAME (type
, 0) == NULL
10039 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
10040 || TYPE_FIELD_NAME (type
, 1) == NULL
10041 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
10044 /* Find the type of the method. */
10045 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
10046 if (pfn_type
== NULL
10047 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
10048 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
10051 /* Look for the "this" argument. */
10052 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
10053 if (TYPE_NFIELDS (pfn_type
) == 0
10054 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
10055 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
10058 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
10059 new_type
= alloc_type (objfile
);
10060 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
10061 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
10062 TYPE_VARARGS (pfn_type
));
10063 smash_to_methodptr_type (type
, new_type
);
10066 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
10070 producer_is_icc (struct dwarf2_cu
*cu
)
10072 if (!cu
->checked_producer
)
10073 check_producer (cu
);
10075 return cu
->producer_is_icc
;
10078 /* Called when we find the DIE that starts a structure or union scope
10079 (definition) to create a type for the structure or union. Fill in
10080 the type's name and general properties; the members will not be
10081 processed until process_structure_type.
10083 NOTE: we need to call these functions regardless of whether or not the
10084 DIE has a DW_AT_name attribute, since it might be an anonymous
10085 structure or union. This gets the type entered into our set of
10086 user defined types.
10088 However, if the structure is incomplete (an opaque struct/union)
10089 then suppress creating a symbol table entry for it since gdb only
10090 wants to find the one with the complete definition. Note that if
10091 it is complete, we just call new_symbol, which does it's own
10092 checking about whether the struct/union is anonymous or not (and
10093 suppresses creating a symbol table entry itself). */
10095 static struct type
*
10096 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10098 struct objfile
*objfile
= cu
->objfile
;
10100 struct attribute
*attr
;
10103 /* If the definition of this type lives in .debug_types, read that type.
10104 Don't follow DW_AT_specification though, that will take us back up
10105 the chain and we want to go down. */
10106 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10109 struct dwarf2_cu
*type_cu
= cu
;
10110 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10112 /* We could just recurse on read_structure_type, but we need to call
10113 get_die_type to ensure only one type for this DIE is created.
10114 This is important, for example, because for c++ classes we need
10115 TYPE_NAME set which is only done by new_symbol. Blech. */
10116 type
= read_type_die (type_die
, type_cu
);
10118 /* TYPE_CU may not be the same as CU.
10119 Ensure TYPE is recorded in CU's type_hash table. */
10120 return set_die_type (die
, type
, cu
);
10123 type
= alloc_type (objfile
);
10124 INIT_CPLUS_SPECIFIC (type
);
10126 name
= dwarf2_name (die
, cu
);
10129 if (cu
->language
== language_cplus
10130 || cu
->language
== language_java
)
10132 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
10134 /* dwarf2_full_name might have already finished building the DIE's
10135 type. If so, there is no need to continue. */
10136 if (get_die_type (die
, cu
) != NULL
)
10137 return get_die_type (die
, cu
);
10139 TYPE_TAG_NAME (type
) = full_name
;
10140 if (die
->tag
== DW_TAG_structure_type
10141 || die
->tag
== DW_TAG_class_type
)
10142 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10146 /* The name is already allocated along with this objfile, so
10147 we don't need to duplicate it for the type. */
10148 TYPE_TAG_NAME (type
) = (char *) name
;
10149 if (die
->tag
== DW_TAG_class_type
)
10150 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10154 if (die
->tag
== DW_TAG_structure_type
)
10156 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10158 else if (die
->tag
== DW_TAG_union_type
)
10160 TYPE_CODE (type
) = TYPE_CODE_UNION
;
10164 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
10167 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
10168 TYPE_DECLARED_CLASS (type
) = 1;
10170 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10173 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10177 TYPE_LENGTH (type
) = 0;
10180 if (producer_is_icc (cu
))
10182 /* ICC does not output the required DW_AT_declaration
10183 on incomplete types, but gives them a size of zero. */
10186 TYPE_STUB_SUPPORTED (type
) = 1;
10188 if (die_is_declaration (die
, cu
))
10189 TYPE_STUB (type
) = 1;
10190 else if (attr
== NULL
&& die
->child
== NULL
10191 && producer_is_realview (cu
->producer
))
10192 /* RealView does not output the required DW_AT_declaration
10193 on incomplete types. */
10194 TYPE_STUB (type
) = 1;
10196 /* We need to add the type field to the die immediately so we don't
10197 infinitely recurse when dealing with pointers to the structure
10198 type within the structure itself. */
10199 set_die_type (die
, type
, cu
);
10201 /* set_die_type should be already done. */
10202 set_descriptive_type (type
, die
, cu
);
10207 /* Finish creating a structure or union type, including filling in
10208 its members and creating a symbol for it. */
10211 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10213 struct objfile
*objfile
= cu
->objfile
;
10214 struct die_info
*child_die
= die
->child
;
10217 type
= get_die_type (die
, cu
);
10219 type
= read_structure_type (die
, cu
);
10221 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
10223 struct field_info fi
;
10224 struct die_info
*child_die
;
10225 VEC (symbolp
) *template_args
= NULL
;
10226 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
10228 memset (&fi
, 0, sizeof (struct field_info
));
10230 child_die
= die
->child
;
10232 while (child_die
&& child_die
->tag
)
10234 if (child_die
->tag
== DW_TAG_member
10235 || child_die
->tag
== DW_TAG_variable
)
10237 /* NOTE: carlton/2002-11-05: A C++ static data member
10238 should be a DW_TAG_member that is a declaration, but
10239 all versions of G++ as of this writing (so through at
10240 least 3.2.1) incorrectly generate DW_TAG_variable
10241 tags for them instead. */
10242 dwarf2_add_field (&fi
, child_die
, cu
);
10244 else if (child_die
->tag
== DW_TAG_subprogram
)
10246 /* C++ member function. */
10247 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
10249 else if (child_die
->tag
== DW_TAG_inheritance
)
10251 /* C++ base class field. */
10252 dwarf2_add_field (&fi
, child_die
, cu
);
10254 else if (child_die
->tag
== DW_TAG_typedef
)
10255 dwarf2_add_typedef (&fi
, child_die
, cu
);
10256 else if (child_die
->tag
== DW_TAG_template_type_param
10257 || child_die
->tag
== DW_TAG_template_value_param
)
10259 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10262 VEC_safe_push (symbolp
, template_args
, arg
);
10265 child_die
= sibling_die (child_die
);
10268 /* Attach template arguments to type. */
10269 if (! VEC_empty (symbolp
, template_args
))
10271 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10272 TYPE_N_TEMPLATE_ARGUMENTS (type
)
10273 = VEC_length (symbolp
, template_args
);
10274 TYPE_TEMPLATE_ARGUMENTS (type
)
10275 = obstack_alloc (&objfile
->objfile_obstack
,
10276 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10277 * sizeof (struct symbol
*)));
10278 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
10279 VEC_address (symbolp
, template_args
),
10280 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10281 * sizeof (struct symbol
*)));
10282 VEC_free (symbolp
, template_args
);
10285 /* Attach fields and member functions to the type. */
10287 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
10290 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
10292 /* Get the type which refers to the base class (possibly this
10293 class itself) which contains the vtable pointer for the current
10294 class from the DW_AT_containing_type attribute. This use of
10295 DW_AT_containing_type is a GNU extension. */
10297 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10299 struct type
*t
= die_containing_type (die
, cu
);
10301 TYPE_VPTR_BASETYPE (type
) = t
;
10306 /* Our own class provides vtbl ptr. */
10307 for (i
= TYPE_NFIELDS (t
) - 1;
10308 i
>= TYPE_N_BASECLASSES (t
);
10311 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
10313 if (is_vtable_name (fieldname
, cu
))
10315 TYPE_VPTR_FIELDNO (type
) = i
;
10320 /* Complain if virtual function table field not found. */
10321 if (i
< TYPE_N_BASECLASSES (t
))
10322 complaint (&symfile_complaints
,
10323 _("virtual function table pointer "
10324 "not found when defining class '%s'"),
10325 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
10330 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
10333 else if (cu
->producer
10334 && strncmp (cu
->producer
,
10335 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
10337 /* The IBM XLC compiler does not provide direct indication
10338 of the containing type, but the vtable pointer is
10339 always named __vfp. */
10343 for (i
= TYPE_NFIELDS (type
) - 1;
10344 i
>= TYPE_N_BASECLASSES (type
);
10347 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
10349 TYPE_VPTR_FIELDNO (type
) = i
;
10350 TYPE_VPTR_BASETYPE (type
) = type
;
10357 /* Copy fi.typedef_field_list linked list elements content into the
10358 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
10359 if (fi
.typedef_field_list
)
10361 int i
= fi
.typedef_field_list_count
;
10363 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10364 TYPE_TYPEDEF_FIELD_ARRAY (type
)
10365 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
10366 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
10368 /* Reverse the list order to keep the debug info elements order. */
10371 struct typedef_field
*dest
, *src
;
10373 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
10374 src
= &fi
.typedef_field_list
->field
;
10375 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
10380 do_cleanups (back_to
);
10382 if (HAVE_CPLUS_STRUCT (type
))
10383 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
10386 quirk_gcc_member_function_pointer (type
, objfile
);
10388 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
10389 snapshots) has been known to create a die giving a declaration
10390 for a class that has, as a child, a die giving a definition for a
10391 nested class. So we have to process our children even if the
10392 current die is a declaration. Normally, of course, a declaration
10393 won't have any children at all. */
10395 while (child_die
!= NULL
&& child_die
->tag
)
10397 if (child_die
->tag
== DW_TAG_member
10398 || child_die
->tag
== DW_TAG_variable
10399 || child_die
->tag
== DW_TAG_inheritance
10400 || child_die
->tag
== DW_TAG_template_value_param
10401 || child_die
->tag
== DW_TAG_template_type_param
)
10406 process_die (child_die
, cu
);
10408 child_die
= sibling_die (child_die
);
10411 /* Do not consider external references. According to the DWARF standard,
10412 these DIEs are identified by the fact that they have no byte_size
10413 attribute, and a declaration attribute. */
10414 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
10415 || !die_is_declaration (die
, cu
))
10416 new_symbol (die
, type
, cu
);
10419 /* Given a DW_AT_enumeration_type die, set its type. We do not
10420 complete the type's fields yet, or create any symbols. */
10422 static struct type
*
10423 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10425 struct objfile
*objfile
= cu
->objfile
;
10427 struct attribute
*attr
;
10430 /* If the definition of this type lives in .debug_types, read that type.
10431 Don't follow DW_AT_specification though, that will take us back up
10432 the chain and we want to go down. */
10433 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10436 struct dwarf2_cu
*type_cu
= cu
;
10437 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10439 type
= read_type_die (type_die
, type_cu
);
10441 /* TYPE_CU may not be the same as CU.
10442 Ensure TYPE is recorded in CU's type_hash table. */
10443 return set_die_type (die
, type
, cu
);
10446 type
= alloc_type (objfile
);
10448 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
10449 name
= dwarf2_full_name (NULL
, die
, cu
);
10451 TYPE_TAG_NAME (type
) = (char *) name
;
10453 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10456 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10460 TYPE_LENGTH (type
) = 0;
10463 /* The enumeration DIE can be incomplete. In Ada, any type can be
10464 declared as private in the package spec, and then defined only
10465 inside the package body. Such types are known as Taft Amendment
10466 Types. When another package uses such a type, an incomplete DIE
10467 may be generated by the compiler. */
10468 if (die_is_declaration (die
, cu
))
10469 TYPE_STUB (type
) = 1;
10471 return set_die_type (die
, type
, cu
);
10474 /* Given a pointer to a die which begins an enumeration, process all
10475 the dies that define the members of the enumeration, and create the
10476 symbol for the enumeration type.
10478 NOTE: We reverse the order of the element list. */
10481 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10483 struct type
*this_type
;
10485 this_type
= get_die_type (die
, cu
);
10486 if (this_type
== NULL
)
10487 this_type
= read_enumeration_type (die
, cu
);
10489 if (die
->child
!= NULL
)
10491 struct die_info
*child_die
;
10492 struct symbol
*sym
;
10493 struct field
*fields
= NULL
;
10494 int num_fields
= 0;
10495 int unsigned_enum
= 1;
10500 child_die
= die
->child
;
10501 while (child_die
&& child_die
->tag
)
10503 if (child_die
->tag
!= DW_TAG_enumerator
)
10505 process_die (child_die
, cu
);
10509 name
= dwarf2_name (child_die
, cu
);
10512 sym
= new_symbol (child_die
, this_type
, cu
);
10513 if (SYMBOL_VALUE (sym
) < 0)
10518 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
10521 mask
|= SYMBOL_VALUE (sym
);
10523 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10525 fields
= (struct field
*)
10527 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
10528 * sizeof (struct field
));
10531 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
10532 FIELD_TYPE (fields
[num_fields
]) = NULL
;
10533 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
10534 FIELD_BITSIZE (fields
[num_fields
]) = 0;
10540 child_die
= sibling_die (child_die
);
10545 TYPE_NFIELDS (this_type
) = num_fields
;
10546 TYPE_FIELDS (this_type
) = (struct field
*)
10547 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
10548 memcpy (TYPE_FIELDS (this_type
), fields
,
10549 sizeof (struct field
) * num_fields
);
10553 TYPE_UNSIGNED (this_type
) = 1;
10555 TYPE_FLAG_ENUM (this_type
) = 1;
10558 /* If we are reading an enum from a .debug_types unit, and the enum
10559 is a declaration, and the enum is not the signatured type in the
10560 unit, then we do not want to add a symbol for it. Adding a
10561 symbol would in some cases obscure the true definition of the
10562 enum, giving users an incomplete type when the definition is
10563 actually available. Note that we do not want to do this for all
10564 enums which are just declarations, because C++0x allows forward
10565 enum declarations. */
10566 if (cu
->per_cu
->is_debug_types
10567 && die_is_declaration (die
, cu
))
10569 struct signatured_type
*sig_type
;
10572 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
10573 cu
->per_cu
->info_or_types_section
,
10574 cu
->per_cu
->offset
);
10575 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
10576 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
10580 new_symbol (die
, this_type
, cu
);
10583 /* Extract all information from a DW_TAG_array_type DIE and put it in
10584 the DIE's type field. For now, this only handles one dimensional
10587 static struct type
*
10588 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10590 struct objfile
*objfile
= cu
->objfile
;
10591 struct die_info
*child_die
;
10593 struct type
*element_type
, *range_type
, *index_type
;
10594 struct type
**range_types
= NULL
;
10595 struct attribute
*attr
;
10597 struct cleanup
*back_to
;
10600 element_type
= die_type (die
, cu
);
10602 /* The die_type call above may have already set the type for this DIE. */
10603 type
= get_die_type (die
, cu
);
10607 /* Irix 6.2 native cc creates array types without children for
10608 arrays with unspecified length. */
10609 if (die
->child
== NULL
)
10611 index_type
= objfile_type (objfile
)->builtin_int
;
10612 range_type
= create_range_type (NULL
, index_type
, 0, -1);
10613 type
= create_array_type (NULL
, element_type
, range_type
);
10614 return set_die_type (die
, type
, cu
);
10617 back_to
= make_cleanup (null_cleanup
, NULL
);
10618 child_die
= die
->child
;
10619 while (child_die
&& child_die
->tag
)
10621 if (child_die
->tag
== DW_TAG_subrange_type
)
10623 struct type
*child_type
= read_type_die (child_die
, cu
);
10625 if (child_type
!= NULL
)
10627 /* The range type was succesfully read. Save it for the
10628 array type creation. */
10629 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
10631 range_types
= (struct type
**)
10632 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
10633 * sizeof (struct type
*));
10635 make_cleanup (free_current_contents
, &range_types
);
10637 range_types
[ndim
++] = child_type
;
10640 child_die
= sibling_die (child_die
);
10643 /* Dwarf2 dimensions are output from left to right, create the
10644 necessary array types in backwards order. */
10646 type
= element_type
;
10648 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
10653 type
= create_array_type (NULL
, type
, range_types
[i
++]);
10658 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
10661 /* Understand Dwarf2 support for vector types (like they occur on
10662 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
10663 array type. This is not part of the Dwarf2/3 standard yet, but a
10664 custom vendor extension. The main difference between a regular
10665 array and the vector variant is that vectors are passed by value
10667 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
10669 make_vector_type (type
);
10671 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
10672 implementation may choose to implement triple vectors using this
10674 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10677 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
10678 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10680 complaint (&symfile_complaints
,
10681 _("DW_AT_byte_size for array type smaller "
10682 "than the total size of elements"));
10685 name
= dwarf2_name (die
, cu
);
10687 TYPE_NAME (type
) = name
;
10689 /* Install the type in the die. */
10690 set_die_type (die
, type
, cu
);
10692 /* set_die_type should be already done. */
10693 set_descriptive_type (type
, die
, cu
);
10695 do_cleanups (back_to
);
10700 static enum dwarf_array_dim_ordering
10701 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
10703 struct attribute
*attr
;
10705 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
10707 if (attr
) return DW_SND (attr
);
10709 /* GNU F77 is a special case, as at 08/2004 array type info is the
10710 opposite order to the dwarf2 specification, but data is still
10711 laid out as per normal fortran.
10713 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
10714 version checking. */
10716 if (cu
->language
== language_fortran
10717 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
10719 return DW_ORD_row_major
;
10722 switch (cu
->language_defn
->la_array_ordering
)
10724 case array_column_major
:
10725 return DW_ORD_col_major
;
10726 case array_row_major
:
10728 return DW_ORD_row_major
;
10732 /* Extract all information from a DW_TAG_set_type DIE and put it in
10733 the DIE's type field. */
10735 static struct type
*
10736 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10738 struct type
*domain_type
, *set_type
;
10739 struct attribute
*attr
;
10741 domain_type
= die_type (die
, cu
);
10743 /* The die_type call above may have already set the type for this DIE. */
10744 set_type
= get_die_type (die
, cu
);
10748 set_type
= create_set_type (NULL
, domain_type
);
10750 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10752 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
10754 return set_die_type (die
, set_type
, cu
);
10757 /* First cut: install each common block member as a global variable. */
10760 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
10762 struct die_info
*child_die
;
10763 struct attribute
*attr
;
10764 struct symbol
*sym
;
10765 CORE_ADDR base
= (CORE_ADDR
) 0;
10767 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10770 /* Support the .debug_loc offsets. */
10771 if (attr_form_is_block (attr
))
10773 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
10775 else if (attr_form_is_section_offset (attr
))
10777 dwarf2_complex_location_expr_complaint ();
10781 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10782 "common block member");
10785 if (die
->child
!= NULL
)
10787 child_die
= die
->child
;
10788 while (child_die
&& child_die
->tag
)
10792 sym
= new_symbol (child_die
, NULL
, cu
);
10794 && handle_data_member_location (child_die
, cu
, &offset
))
10796 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
10797 add_symbol_to_list (sym
, &global_symbols
);
10799 child_die
= sibling_die (child_die
);
10804 /* Create a type for a C++ namespace. */
10806 static struct type
*
10807 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10809 struct objfile
*objfile
= cu
->objfile
;
10810 const char *previous_prefix
, *name
;
10814 /* For extensions, reuse the type of the original namespace. */
10815 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
10817 struct die_info
*ext_die
;
10818 struct dwarf2_cu
*ext_cu
= cu
;
10820 ext_die
= dwarf2_extension (die
, &ext_cu
);
10821 type
= read_type_die (ext_die
, ext_cu
);
10823 /* EXT_CU may not be the same as CU.
10824 Ensure TYPE is recorded in CU's type_hash table. */
10825 return set_die_type (die
, type
, cu
);
10828 name
= namespace_name (die
, &is_anonymous
, cu
);
10830 /* Now build the name of the current namespace. */
10832 previous_prefix
= determine_prefix (die
, cu
);
10833 if (previous_prefix
[0] != '\0')
10834 name
= typename_concat (&objfile
->objfile_obstack
,
10835 previous_prefix
, name
, 0, cu
);
10837 /* Create the type. */
10838 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
10840 TYPE_NAME (type
) = (char *) name
;
10841 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10843 return set_die_type (die
, type
, cu
);
10846 /* Read a C++ namespace. */
10849 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10851 struct objfile
*objfile
= cu
->objfile
;
10854 /* Add a symbol associated to this if we haven't seen the namespace
10855 before. Also, add a using directive if it's an anonymous
10858 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
10862 type
= read_type_die (die
, cu
);
10863 new_symbol (die
, type
, cu
);
10865 namespace_name (die
, &is_anonymous
, cu
);
10868 const char *previous_prefix
= determine_prefix (die
, cu
);
10870 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
10871 NULL
, NULL
, &objfile
->objfile_obstack
);
10875 if (die
->child
!= NULL
)
10877 struct die_info
*child_die
= die
->child
;
10879 while (child_die
&& child_die
->tag
)
10881 process_die (child_die
, cu
);
10882 child_die
= sibling_die (child_die
);
10887 /* Read a Fortran module as type. This DIE can be only a declaration used for
10888 imported module. Still we need that type as local Fortran "use ... only"
10889 declaration imports depend on the created type in determine_prefix. */
10891 static struct type
*
10892 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10894 struct objfile
*objfile
= cu
->objfile
;
10898 module_name
= dwarf2_name (die
, cu
);
10900 complaint (&symfile_complaints
,
10901 _("DW_TAG_module has no name, offset 0x%x"),
10902 die
->offset
.sect_off
);
10903 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
10905 /* determine_prefix uses TYPE_TAG_NAME. */
10906 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10908 return set_die_type (die
, type
, cu
);
10911 /* Read a Fortran module. */
10914 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
10916 struct die_info
*child_die
= die
->child
;
10918 while (child_die
&& child_die
->tag
)
10920 process_die (child_die
, cu
);
10921 child_die
= sibling_die (child_die
);
10925 /* Return the name of the namespace represented by DIE. Set
10926 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
10929 static const char *
10930 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
10932 struct die_info
*current_die
;
10933 const char *name
= NULL
;
10935 /* Loop through the extensions until we find a name. */
10937 for (current_die
= die
;
10938 current_die
!= NULL
;
10939 current_die
= dwarf2_extension (die
, &cu
))
10941 name
= dwarf2_name (current_die
, cu
);
10946 /* Is it an anonymous namespace? */
10948 *is_anonymous
= (name
== NULL
);
10950 name
= CP_ANONYMOUS_NAMESPACE_STR
;
10955 /* Extract all information from a DW_TAG_pointer_type DIE and add to
10956 the user defined type vector. */
10958 static struct type
*
10959 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10961 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
10962 struct comp_unit_head
*cu_header
= &cu
->header
;
10964 struct attribute
*attr_byte_size
;
10965 struct attribute
*attr_address_class
;
10966 int byte_size
, addr_class
;
10967 struct type
*target_type
;
10969 target_type
= die_type (die
, cu
);
10971 /* The die_type call above may have already set the type for this DIE. */
10972 type
= get_die_type (die
, cu
);
10976 type
= lookup_pointer_type (target_type
);
10978 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10979 if (attr_byte_size
)
10980 byte_size
= DW_UNSND (attr_byte_size
);
10982 byte_size
= cu_header
->addr_size
;
10984 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
10985 if (attr_address_class
)
10986 addr_class
= DW_UNSND (attr_address_class
);
10988 addr_class
= DW_ADDR_none
;
10990 /* If the pointer size or address class is different than the
10991 default, create a type variant marked as such and set the
10992 length accordingly. */
10993 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
10995 if (gdbarch_address_class_type_flags_p (gdbarch
))
10999 type_flags
= gdbarch_address_class_type_flags
11000 (gdbarch
, byte_size
, addr_class
);
11001 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
11003 type
= make_type_with_address_space (type
, type_flags
);
11005 else if (TYPE_LENGTH (type
) != byte_size
)
11007 complaint (&symfile_complaints
,
11008 _("invalid pointer size %d"), byte_size
);
11012 /* Should we also complain about unhandled address classes? */
11016 TYPE_LENGTH (type
) = byte_size
;
11017 return set_die_type (die
, type
, cu
);
11020 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
11021 the user defined type vector. */
11023 static struct type
*
11024 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11027 struct type
*to_type
;
11028 struct type
*domain
;
11030 to_type
= die_type (die
, cu
);
11031 domain
= die_containing_type (die
, cu
);
11033 /* The calls above may have already set the type for this DIE. */
11034 type
= get_die_type (die
, cu
);
11038 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
11039 type
= lookup_methodptr_type (to_type
);
11041 type
= lookup_memberptr_type (to_type
, domain
);
11043 return set_die_type (die
, type
, cu
);
11046 /* Extract all information from a DW_TAG_reference_type DIE and add to
11047 the user defined type vector. */
11049 static struct type
*
11050 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11052 struct comp_unit_head
*cu_header
= &cu
->header
;
11053 struct type
*type
, *target_type
;
11054 struct attribute
*attr
;
11056 target_type
= die_type (die
, cu
);
11058 /* The die_type call above may have already set the type for this DIE. */
11059 type
= get_die_type (die
, cu
);
11063 type
= lookup_reference_type (target_type
);
11064 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11067 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11071 TYPE_LENGTH (type
) = cu_header
->addr_size
;
11073 return set_die_type (die
, type
, cu
);
11076 static struct type
*
11077 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11079 struct type
*base_type
, *cv_type
;
11081 base_type
= die_type (die
, cu
);
11083 /* The die_type call above may have already set the type for this DIE. */
11084 cv_type
= get_die_type (die
, cu
);
11088 /* In case the const qualifier is applied to an array type, the element type
11089 is so qualified, not the array type (section 6.7.3 of C99). */
11090 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
11092 struct type
*el_type
, *inner_array
;
11094 base_type
= copy_type (base_type
);
11095 inner_array
= base_type
;
11097 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
11099 TYPE_TARGET_TYPE (inner_array
) =
11100 copy_type (TYPE_TARGET_TYPE (inner_array
));
11101 inner_array
= TYPE_TARGET_TYPE (inner_array
);
11104 el_type
= TYPE_TARGET_TYPE (inner_array
);
11105 TYPE_TARGET_TYPE (inner_array
) =
11106 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
11108 return set_die_type (die
, base_type
, cu
);
11111 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
11112 return set_die_type (die
, cv_type
, cu
);
11115 static struct type
*
11116 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11118 struct type
*base_type
, *cv_type
;
11120 base_type
= die_type (die
, cu
);
11122 /* The die_type call above may have already set the type for this DIE. */
11123 cv_type
= get_die_type (die
, cu
);
11127 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
11128 return set_die_type (die
, cv_type
, cu
);
11131 /* Extract all information from a DW_TAG_string_type DIE and add to
11132 the user defined type vector. It isn't really a user defined type,
11133 but it behaves like one, with other DIE's using an AT_user_def_type
11134 attribute to reference it. */
11136 static struct type
*
11137 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11139 struct objfile
*objfile
= cu
->objfile
;
11140 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11141 struct type
*type
, *range_type
, *index_type
, *char_type
;
11142 struct attribute
*attr
;
11143 unsigned int length
;
11145 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
11148 length
= DW_UNSND (attr
);
11152 /* Check for the DW_AT_byte_size attribute. */
11153 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11156 length
= DW_UNSND (attr
);
11164 index_type
= objfile_type (objfile
)->builtin_int
;
11165 range_type
= create_range_type (NULL
, index_type
, 1, length
);
11166 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
11167 type
= create_string_type (NULL
, char_type
, range_type
);
11169 return set_die_type (die
, type
, cu
);
11172 /* Handle DIES due to C code like:
11176 int (*funcp)(int a, long l);
11180 ('funcp' generates a DW_TAG_subroutine_type DIE). */
11182 static struct type
*
11183 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11185 struct objfile
*objfile
= cu
->objfile
;
11186 struct type
*type
; /* Type that this function returns. */
11187 struct type
*ftype
; /* Function that returns above type. */
11188 struct attribute
*attr
;
11190 type
= die_type (die
, cu
);
11192 /* The die_type call above may have already set the type for this DIE. */
11193 ftype
= get_die_type (die
, cu
);
11197 ftype
= lookup_function_type (type
);
11199 /* All functions in C++, Pascal and Java have prototypes. */
11200 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
11201 if ((attr
&& (DW_UNSND (attr
) != 0))
11202 || cu
->language
== language_cplus
11203 || cu
->language
== language_java
11204 || cu
->language
== language_pascal
)
11205 TYPE_PROTOTYPED (ftype
) = 1;
11206 else if (producer_is_realview (cu
->producer
))
11207 /* RealView does not emit DW_AT_prototyped. We can not
11208 distinguish prototyped and unprototyped functions; default to
11209 prototyped, since that is more common in modern code (and
11210 RealView warns about unprototyped functions). */
11211 TYPE_PROTOTYPED (ftype
) = 1;
11213 /* Store the calling convention in the type if it's available in
11214 the subroutine die. Otherwise set the calling convention to
11215 the default value DW_CC_normal. */
11216 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
11218 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
11219 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
11220 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
11222 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
11224 /* We need to add the subroutine type to the die immediately so
11225 we don't infinitely recurse when dealing with parameters
11226 declared as the same subroutine type. */
11227 set_die_type (die
, ftype
, cu
);
11229 if (die
->child
!= NULL
)
11231 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
11232 struct die_info
*child_die
;
11233 int nparams
, iparams
;
11235 /* Count the number of parameters.
11236 FIXME: GDB currently ignores vararg functions, but knows about
11237 vararg member functions. */
11239 child_die
= die
->child
;
11240 while (child_die
&& child_die
->tag
)
11242 if (child_die
->tag
== DW_TAG_formal_parameter
)
11244 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
11245 TYPE_VARARGS (ftype
) = 1;
11246 child_die
= sibling_die (child_die
);
11249 /* Allocate storage for parameters and fill them in. */
11250 TYPE_NFIELDS (ftype
) = nparams
;
11251 TYPE_FIELDS (ftype
) = (struct field
*)
11252 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
11254 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
11255 even if we error out during the parameters reading below. */
11256 for (iparams
= 0; iparams
< nparams
; iparams
++)
11257 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
11260 child_die
= die
->child
;
11261 while (child_die
&& child_die
->tag
)
11263 if (child_die
->tag
== DW_TAG_formal_parameter
)
11265 struct type
*arg_type
;
11267 /* DWARF version 2 has no clean way to discern C++
11268 static and non-static member functions. G++ helps
11269 GDB by marking the first parameter for non-static
11270 member functions (which is the this pointer) as
11271 artificial. We pass this information to
11272 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
11274 DWARF version 3 added DW_AT_object_pointer, which GCC
11275 4.5 does not yet generate. */
11276 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
11278 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
11281 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
11283 /* GCC/43521: In java, the formal parameter
11284 "this" is sometimes not marked with DW_AT_artificial. */
11285 if (cu
->language
== language_java
)
11287 const char *name
= dwarf2_name (child_die
, cu
);
11289 if (name
&& !strcmp (name
, "this"))
11290 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
11293 arg_type
= die_type (child_die
, cu
);
11295 /* RealView does not mark THIS as const, which the testsuite
11296 expects. GCC marks THIS as const in method definitions,
11297 but not in the class specifications (GCC PR 43053). */
11298 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
11299 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
11302 struct dwarf2_cu
*arg_cu
= cu
;
11303 const char *name
= dwarf2_name (child_die
, cu
);
11305 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
11308 /* If the compiler emits this, use it. */
11309 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
11312 else if (name
&& strcmp (name
, "this") == 0)
11313 /* Function definitions will have the argument names. */
11315 else if (name
== NULL
&& iparams
== 0)
11316 /* Declarations may not have the names, so like
11317 elsewhere in GDB, assume an artificial first
11318 argument is "this". */
11322 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
11326 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
11329 child_die
= sibling_die (child_die
);
11336 static struct type
*
11337 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
11339 struct objfile
*objfile
= cu
->objfile
;
11340 const char *name
= NULL
;
11341 struct type
*this_type
, *target_type
;
11343 name
= dwarf2_full_name (NULL
, die
, cu
);
11344 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
11345 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
11346 TYPE_NAME (this_type
) = (char *) name
;
11347 set_die_type (die
, this_type
, cu
);
11348 target_type
= die_type (die
, cu
);
11349 if (target_type
!= this_type
)
11350 TYPE_TARGET_TYPE (this_type
) = target_type
;
11353 /* Self-referential typedefs are, it seems, not allowed by the DWARF
11354 spec and cause infinite loops in GDB. */
11355 complaint (&symfile_complaints
,
11356 _("Self-referential DW_TAG_typedef "
11357 "- DIE at 0x%x [in module %s]"),
11358 die
->offset
.sect_off
, objfile
->name
);
11359 TYPE_TARGET_TYPE (this_type
) = NULL
;
11364 /* Find a representation of a given base type and install
11365 it in the TYPE field of the die. */
11367 static struct type
*
11368 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11370 struct objfile
*objfile
= cu
->objfile
;
11372 struct attribute
*attr
;
11373 int encoding
= 0, size
= 0;
11375 enum type_code code
= TYPE_CODE_INT
;
11376 int type_flags
= 0;
11377 struct type
*target_type
= NULL
;
11379 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
11382 encoding
= DW_UNSND (attr
);
11384 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11387 size
= DW_UNSND (attr
);
11389 name
= dwarf2_name (die
, cu
);
11392 complaint (&symfile_complaints
,
11393 _("DW_AT_name missing from DW_TAG_base_type"));
11398 case DW_ATE_address
:
11399 /* Turn DW_ATE_address into a void * pointer. */
11400 code
= TYPE_CODE_PTR
;
11401 type_flags
|= TYPE_FLAG_UNSIGNED
;
11402 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
11404 case DW_ATE_boolean
:
11405 code
= TYPE_CODE_BOOL
;
11406 type_flags
|= TYPE_FLAG_UNSIGNED
;
11408 case DW_ATE_complex_float
:
11409 code
= TYPE_CODE_COMPLEX
;
11410 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
11412 case DW_ATE_decimal_float
:
11413 code
= TYPE_CODE_DECFLOAT
;
11416 code
= TYPE_CODE_FLT
;
11418 case DW_ATE_signed
:
11420 case DW_ATE_unsigned
:
11421 type_flags
|= TYPE_FLAG_UNSIGNED
;
11422 if (cu
->language
== language_fortran
11424 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
11425 code
= TYPE_CODE_CHAR
;
11427 case DW_ATE_signed_char
:
11428 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11429 || cu
->language
== language_pascal
11430 || cu
->language
== language_fortran
)
11431 code
= TYPE_CODE_CHAR
;
11433 case DW_ATE_unsigned_char
:
11434 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11435 || cu
->language
== language_pascal
11436 || cu
->language
== language_fortran
)
11437 code
= TYPE_CODE_CHAR
;
11438 type_flags
|= TYPE_FLAG_UNSIGNED
;
11441 /* We just treat this as an integer and then recognize the
11442 type by name elsewhere. */
11446 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
11447 dwarf_type_encoding_name (encoding
));
11451 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
11452 TYPE_NAME (type
) = name
;
11453 TYPE_TARGET_TYPE (type
) = target_type
;
11455 if (name
&& strcmp (name
, "char") == 0)
11456 TYPE_NOSIGN (type
) = 1;
11458 return set_die_type (die
, type
, cu
);
11461 /* Read the given DW_AT_subrange DIE. */
11463 static struct type
*
11464 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11466 struct type
*base_type
;
11467 struct type
*range_type
;
11468 struct attribute
*attr
;
11470 int low_default_is_valid
;
11472 LONGEST negative_mask
;
11474 base_type
= die_type (die
, cu
);
11475 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
11476 check_typedef (base_type
);
11478 /* The die_type call above may have already set the type for this DIE. */
11479 range_type
= get_die_type (die
, cu
);
11483 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
11484 omitting DW_AT_lower_bound. */
11485 switch (cu
->language
)
11488 case language_cplus
:
11490 low_default_is_valid
= 1;
11492 case language_fortran
:
11494 low_default_is_valid
= 1;
11497 case language_java
:
11498 case language_objc
:
11500 low_default_is_valid
= (cu
->header
.version
>= 4);
11504 case language_pascal
:
11506 low_default_is_valid
= (cu
->header
.version
>= 4);
11510 low_default_is_valid
= 0;
11514 /* FIXME: For variable sized arrays either of these could be
11515 a variable rather than a constant value. We'll allow it,
11516 but we don't know how to handle it. */
11517 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
11519 low
= dwarf2_get_attr_constant_value (attr
, low
);
11520 else if (!low_default_is_valid
)
11521 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
11522 "- DIE at 0x%x [in module %s]"),
11523 die
->offset
.sect_off
, cu
->objfile
->name
);
11525 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
11528 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
11530 /* GCC encodes arrays with unspecified or dynamic length
11531 with a DW_FORM_block1 attribute or a reference attribute.
11532 FIXME: GDB does not yet know how to handle dynamic
11533 arrays properly, treat them as arrays with unspecified
11536 FIXME: jimb/2003-09-22: GDB does not really know
11537 how to handle arrays of unspecified length
11538 either; we just represent them as zero-length
11539 arrays. Choose an appropriate upper bound given
11540 the lower bound we've computed above. */
11544 high
= dwarf2_get_attr_constant_value (attr
, 1);
11548 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
11551 int count
= dwarf2_get_attr_constant_value (attr
, 1);
11552 high
= low
+ count
- 1;
11556 /* Unspecified array length. */
11561 /* Dwarf-2 specifications explicitly allows to create subrange types
11562 without specifying a base type.
11563 In that case, the base type must be set to the type of
11564 the lower bound, upper bound or count, in that order, if any of these
11565 three attributes references an object that has a type.
11566 If no base type is found, the Dwarf-2 specifications say that
11567 a signed integer type of size equal to the size of an address should
11569 For the following C code: `extern char gdb_int [];'
11570 GCC produces an empty range DIE.
11571 FIXME: muller/2010-05-28: Possible references to object for low bound,
11572 high bound or count are not yet handled by this code. */
11573 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
11575 struct objfile
*objfile
= cu
->objfile
;
11576 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11577 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
11578 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
11580 /* Test "int", "long int", and "long long int" objfile types,
11581 and select the first one having a size above or equal to the
11582 architecture address size. */
11583 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11584 base_type
= int_type
;
11587 int_type
= objfile_type (objfile
)->builtin_long
;
11588 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11589 base_type
= int_type
;
11592 int_type
= objfile_type (objfile
)->builtin_long_long
;
11593 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11594 base_type
= int_type
;
11600 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
11601 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
11602 low
|= negative_mask
;
11603 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
11604 high
|= negative_mask
;
11606 range_type
= create_range_type (NULL
, base_type
, low
, high
);
11608 /* Mark arrays with dynamic length at least as an array of unspecified
11609 length. GDB could check the boundary but before it gets implemented at
11610 least allow accessing the array elements. */
11611 if (attr
&& attr_form_is_block (attr
))
11612 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11614 /* Ada expects an empty array on no boundary attributes. */
11615 if (attr
== NULL
&& cu
->language
!= language_ada
)
11616 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11618 name
= dwarf2_name (die
, cu
);
11620 TYPE_NAME (range_type
) = name
;
11622 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11624 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
11626 set_die_type (die
, range_type
, cu
);
11628 /* set_die_type should be already done. */
11629 set_descriptive_type (range_type
, die
, cu
);
11634 static struct type
*
11635 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11639 /* For now, we only support the C meaning of an unspecified type: void. */
11641 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
11642 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
11644 return set_die_type (die
, type
, cu
);
11647 /* Read a single die and all its descendents. Set the die's sibling
11648 field to NULL; set other fields in the die correctly, and set all
11649 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
11650 location of the info_ptr after reading all of those dies. PARENT
11651 is the parent of the die in question. */
11653 static struct die_info
*
11654 read_die_and_children (const struct die_reader_specs
*reader
,
11655 gdb_byte
*info_ptr
,
11656 gdb_byte
**new_info_ptr
,
11657 struct die_info
*parent
)
11659 struct die_info
*die
;
11663 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
11666 *new_info_ptr
= cur_ptr
;
11669 store_in_ref_table (die
, reader
->cu
);
11672 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
11676 *new_info_ptr
= cur_ptr
;
11679 die
->sibling
= NULL
;
11680 die
->parent
= parent
;
11684 /* Read a die, all of its descendents, and all of its siblings; set
11685 all of the fields of all of the dies correctly. Arguments are as
11686 in read_die_and_children. */
11688 static struct die_info
*
11689 read_die_and_siblings (const struct die_reader_specs
*reader
,
11690 gdb_byte
*info_ptr
,
11691 gdb_byte
**new_info_ptr
,
11692 struct die_info
*parent
)
11694 struct die_info
*first_die
, *last_sibling
;
11697 cur_ptr
= info_ptr
;
11698 first_die
= last_sibling
= NULL
;
11702 struct die_info
*die
11703 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
11707 *new_info_ptr
= cur_ptr
;
11714 last_sibling
->sibling
= die
;
11716 last_sibling
= die
;
11720 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
11722 The caller is responsible for filling in the extra attributes
11723 and updating (*DIEP)->num_attrs.
11724 Set DIEP to point to a newly allocated die with its information,
11725 except for its child, sibling, and parent fields.
11726 Set HAS_CHILDREN to tell whether the die has children or not. */
11729 read_full_die_1 (const struct die_reader_specs
*reader
,
11730 struct die_info
**diep
, gdb_byte
*info_ptr
,
11731 int *has_children
, int num_extra_attrs
)
11733 unsigned int abbrev_number
, bytes_read
, i
;
11734 sect_offset offset
;
11735 struct abbrev_info
*abbrev
;
11736 struct die_info
*die
;
11737 struct dwarf2_cu
*cu
= reader
->cu
;
11738 bfd
*abfd
= reader
->abfd
;
11740 offset
.sect_off
= info_ptr
- reader
->buffer
;
11741 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11742 info_ptr
+= bytes_read
;
11743 if (!abbrev_number
)
11750 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
11752 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
11754 bfd_get_filename (abfd
));
11756 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
11757 die
->offset
= offset
;
11758 die
->tag
= abbrev
->tag
;
11759 die
->abbrev
= abbrev_number
;
11761 /* Make the result usable.
11762 The caller needs to update num_attrs after adding the extra
11764 die
->num_attrs
= abbrev
->num_attrs
;
11766 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11767 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
11771 *has_children
= abbrev
->has_children
;
11775 /* Read a die and all its attributes.
11776 Set DIEP to point to a newly allocated die with its information,
11777 except for its child, sibling, and parent fields.
11778 Set HAS_CHILDREN to tell whether the die has children or not. */
11781 read_full_die (const struct die_reader_specs
*reader
,
11782 struct die_info
**diep
, gdb_byte
*info_ptr
,
11785 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
11788 /* Abbreviation tables.
11790 In DWARF version 2, the description of the debugging information is
11791 stored in a separate .debug_abbrev section. Before we read any
11792 dies from a section we read in all abbreviations and install them
11793 in a hash table. */
11795 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
11797 static struct abbrev_info
*
11798 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
11800 struct abbrev_info
*abbrev
;
11802 abbrev
= (struct abbrev_info
*)
11803 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
11804 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11808 /* Add an abbreviation to the table. */
11811 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
11812 unsigned int abbrev_number
,
11813 struct abbrev_info
*abbrev
)
11815 unsigned int hash_number
;
11817 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11818 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
11819 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
11822 /* Look up an abbrev in the table.
11823 Returns NULL if the abbrev is not found. */
11825 static struct abbrev_info
*
11826 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
11827 unsigned int abbrev_number
)
11829 unsigned int hash_number
;
11830 struct abbrev_info
*abbrev
;
11832 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11833 abbrev
= abbrev_table
->abbrevs
[hash_number
];
11837 if (abbrev
->number
== abbrev_number
)
11839 abbrev
= abbrev
->next
;
11844 /* Read in an abbrev table. */
11846 static struct abbrev_table
*
11847 abbrev_table_read_table (struct dwarf2_section_info
*section
,
11848 sect_offset offset
)
11850 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11851 bfd
*abfd
= section
->asection
->owner
;
11852 struct abbrev_table
*abbrev_table
;
11853 gdb_byte
*abbrev_ptr
;
11854 struct abbrev_info
*cur_abbrev
;
11855 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
11856 unsigned int abbrev_form
;
11857 struct attr_abbrev
*cur_attrs
;
11858 unsigned int allocated_attrs
;
11860 abbrev_table
= XMALLOC (struct abbrev_table
);
11861 abbrev_table
->offset
= offset
;
11862 obstack_init (&abbrev_table
->abbrev_obstack
);
11863 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
11865 * sizeof (struct abbrev_info
*)));
11866 memset (abbrev_table
->abbrevs
, 0,
11867 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
11869 dwarf2_read_section (objfile
, section
);
11870 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
11871 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11872 abbrev_ptr
+= bytes_read
;
11874 allocated_attrs
= ATTR_ALLOC_CHUNK
;
11875 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
11877 /* Loop until we reach an abbrev number of 0. */
11878 while (abbrev_number
)
11880 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
11882 /* read in abbrev header */
11883 cur_abbrev
->number
= abbrev_number
;
11884 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11885 abbrev_ptr
+= bytes_read
;
11886 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
11889 /* now read in declarations */
11890 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11891 abbrev_ptr
+= bytes_read
;
11892 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11893 abbrev_ptr
+= bytes_read
;
11894 while (abbrev_name
)
11896 if (cur_abbrev
->num_attrs
== allocated_attrs
)
11898 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
11900 = xrealloc (cur_attrs
, (allocated_attrs
11901 * sizeof (struct attr_abbrev
)));
11904 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
11905 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
11906 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11907 abbrev_ptr
+= bytes_read
;
11908 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11909 abbrev_ptr
+= bytes_read
;
11912 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
11913 (cur_abbrev
->num_attrs
11914 * sizeof (struct attr_abbrev
)));
11915 memcpy (cur_abbrev
->attrs
, cur_attrs
,
11916 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
11918 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
11920 /* Get next abbreviation.
11921 Under Irix6 the abbreviations for a compilation unit are not
11922 always properly terminated with an abbrev number of 0.
11923 Exit loop if we encounter an abbreviation which we have
11924 already read (which means we are about to read the abbreviations
11925 for the next compile unit) or if the end of the abbreviation
11926 table is reached. */
11927 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
11929 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11930 abbrev_ptr
+= bytes_read
;
11931 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
11936 return abbrev_table
;
11939 /* Free the resources held by ABBREV_TABLE. */
11942 abbrev_table_free (struct abbrev_table
*abbrev_table
)
11944 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
11945 xfree (abbrev_table
);
11948 /* Same as abbrev_table_free but as a cleanup.
11949 We pass in a pointer to the pointer to the table so that we can
11950 set the pointer to NULL when we're done. It also simplifies
11951 build_type_unit_groups. */
11954 abbrev_table_free_cleanup (void *table_ptr
)
11956 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
11958 if (*abbrev_table_ptr
!= NULL
)
11959 abbrev_table_free (*abbrev_table_ptr
);
11960 *abbrev_table_ptr
= NULL
;
11963 /* Read the abbrev table for CU from ABBREV_SECTION. */
11966 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
11967 struct dwarf2_section_info
*abbrev_section
)
11970 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
11973 /* Release the memory used by the abbrev table for a compilation unit. */
11976 dwarf2_free_abbrev_table (void *ptr_to_cu
)
11978 struct dwarf2_cu
*cu
= ptr_to_cu
;
11980 abbrev_table_free (cu
->abbrev_table
);
11981 /* Set this to NULL so that we SEGV if we try to read it later,
11982 and also because free_comp_unit verifies this is NULL. */
11983 cu
->abbrev_table
= NULL
;
11986 /* Returns nonzero if TAG represents a type that we might generate a partial
11990 is_type_tag_for_partial (int tag
)
11995 /* Some types that would be reasonable to generate partial symbols for,
11996 that we don't at present. */
11997 case DW_TAG_array_type
:
11998 case DW_TAG_file_type
:
11999 case DW_TAG_ptr_to_member_type
:
12000 case DW_TAG_set_type
:
12001 case DW_TAG_string_type
:
12002 case DW_TAG_subroutine_type
:
12004 case DW_TAG_base_type
:
12005 case DW_TAG_class_type
:
12006 case DW_TAG_interface_type
:
12007 case DW_TAG_enumeration_type
:
12008 case DW_TAG_structure_type
:
12009 case DW_TAG_subrange_type
:
12010 case DW_TAG_typedef
:
12011 case DW_TAG_union_type
:
12018 /* Load all DIEs that are interesting for partial symbols into memory. */
12020 static struct partial_die_info
*
12021 load_partial_dies (const struct die_reader_specs
*reader
,
12022 gdb_byte
*info_ptr
, int building_psymtab
)
12024 struct dwarf2_cu
*cu
= reader
->cu
;
12025 struct objfile
*objfile
= cu
->objfile
;
12026 struct partial_die_info
*part_die
;
12027 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
12028 struct abbrev_info
*abbrev
;
12029 unsigned int bytes_read
;
12030 unsigned int load_all
= 0;
12031 int nesting_level
= 1;
12036 gdb_assert (cu
->per_cu
!= NULL
);
12037 if (cu
->per_cu
->load_all_dies
)
12041 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12045 &cu
->comp_unit_obstack
,
12046 hashtab_obstack_allocate
,
12047 dummy_obstack_deallocate
);
12049 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12050 sizeof (struct partial_die_info
));
12054 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
12056 /* A NULL abbrev means the end of a series of children. */
12057 if (abbrev
== NULL
)
12059 if (--nesting_level
== 0)
12061 /* PART_DIE was probably the last thing allocated on the
12062 comp_unit_obstack, so we could call obstack_free
12063 here. We don't do that because the waste is small,
12064 and will be cleaned up when we're done with this
12065 compilation unit. This way, we're also more robust
12066 against other users of the comp_unit_obstack. */
12069 info_ptr
+= bytes_read
;
12070 last_die
= parent_die
;
12071 parent_die
= parent_die
->die_parent
;
12075 /* Check for template arguments. We never save these; if
12076 they're seen, we just mark the parent, and go on our way. */
12077 if (parent_die
!= NULL
12078 && cu
->language
== language_cplus
12079 && (abbrev
->tag
== DW_TAG_template_type_param
12080 || abbrev
->tag
== DW_TAG_template_value_param
))
12082 parent_die
->has_template_arguments
= 1;
12086 /* We don't need a partial DIE for the template argument. */
12087 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12092 /* We only recurse into c++ subprograms looking for template arguments.
12093 Skip their other children. */
12095 && cu
->language
== language_cplus
12096 && parent_die
!= NULL
12097 && parent_die
->tag
== DW_TAG_subprogram
)
12099 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12103 /* Check whether this DIE is interesting enough to save. Normally
12104 we would not be interested in members here, but there may be
12105 later variables referencing them via DW_AT_specification (for
12106 static members). */
12108 && !is_type_tag_for_partial (abbrev
->tag
)
12109 && abbrev
->tag
!= DW_TAG_constant
12110 && abbrev
->tag
!= DW_TAG_enumerator
12111 && abbrev
->tag
!= DW_TAG_subprogram
12112 && abbrev
->tag
!= DW_TAG_lexical_block
12113 && abbrev
->tag
!= DW_TAG_variable
12114 && abbrev
->tag
!= DW_TAG_namespace
12115 && abbrev
->tag
!= DW_TAG_module
12116 && abbrev
->tag
!= DW_TAG_member
12117 && abbrev
->tag
!= DW_TAG_imported_unit
)
12119 /* Otherwise we skip to the next sibling, if any. */
12120 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12124 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
12127 /* This two-pass algorithm for processing partial symbols has a
12128 high cost in cache pressure. Thus, handle some simple cases
12129 here which cover the majority of C partial symbols. DIEs
12130 which neither have specification tags in them, nor could have
12131 specification tags elsewhere pointing at them, can simply be
12132 processed and discarded.
12134 This segment is also optional; scan_partial_symbols and
12135 add_partial_symbol will handle these DIEs if we chain
12136 them in normally. When compilers which do not emit large
12137 quantities of duplicate debug information are more common,
12138 this code can probably be removed. */
12140 /* Any complete simple types at the top level (pretty much all
12141 of them, for a language without namespaces), can be processed
12143 if (parent_die
== NULL
12144 && part_die
->has_specification
== 0
12145 && part_die
->is_declaration
== 0
12146 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
12147 || part_die
->tag
== DW_TAG_base_type
12148 || part_die
->tag
== DW_TAG_subrange_type
))
12150 if (building_psymtab
&& part_die
->name
!= NULL
)
12151 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12152 VAR_DOMAIN
, LOC_TYPEDEF
,
12153 &objfile
->static_psymbols
,
12154 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12155 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12159 /* The exception for DW_TAG_typedef with has_children above is
12160 a workaround of GCC PR debug/47510. In the case of this complaint
12161 type_name_no_tag_or_error will error on such types later.
12163 GDB skipped children of DW_TAG_typedef by the shortcut above and then
12164 it could not find the child DIEs referenced later, this is checked
12165 above. In correct DWARF DW_TAG_typedef should have no children. */
12167 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
12168 complaint (&symfile_complaints
,
12169 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
12170 "- DIE at 0x%x [in module %s]"),
12171 part_die
->offset
.sect_off
, objfile
->name
);
12173 /* If we're at the second level, and we're an enumerator, and
12174 our parent has no specification (meaning possibly lives in a
12175 namespace elsewhere), then we can add the partial symbol now
12176 instead of queueing it. */
12177 if (part_die
->tag
== DW_TAG_enumerator
12178 && parent_die
!= NULL
12179 && parent_die
->die_parent
== NULL
12180 && parent_die
->tag
== DW_TAG_enumeration_type
12181 && parent_die
->has_specification
== 0)
12183 if (part_die
->name
== NULL
)
12184 complaint (&symfile_complaints
,
12185 _("malformed enumerator DIE ignored"));
12186 else if (building_psymtab
)
12187 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12188 VAR_DOMAIN
, LOC_CONST
,
12189 (cu
->language
== language_cplus
12190 || cu
->language
== language_java
)
12191 ? &objfile
->global_psymbols
12192 : &objfile
->static_psymbols
,
12193 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12195 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12199 /* We'll save this DIE so link it in. */
12200 part_die
->die_parent
= parent_die
;
12201 part_die
->die_sibling
= NULL
;
12202 part_die
->die_child
= NULL
;
12204 if (last_die
&& last_die
== parent_die
)
12205 last_die
->die_child
= part_die
;
12207 last_die
->die_sibling
= part_die
;
12209 last_die
= part_die
;
12211 if (first_die
== NULL
)
12212 first_die
= part_die
;
12214 /* Maybe add the DIE to the hash table. Not all DIEs that we
12215 find interesting need to be in the hash table, because we
12216 also have the parent/sibling/child chains; only those that we
12217 might refer to by offset later during partial symbol reading.
12219 For now this means things that might have be the target of a
12220 DW_AT_specification, DW_AT_abstract_origin, or
12221 DW_AT_extension. DW_AT_extension will refer only to
12222 namespaces; DW_AT_abstract_origin refers to functions (and
12223 many things under the function DIE, but we do not recurse
12224 into function DIEs during partial symbol reading) and
12225 possibly variables as well; DW_AT_specification refers to
12226 declarations. Declarations ought to have the DW_AT_declaration
12227 flag. It happens that GCC forgets to put it in sometimes, but
12228 only for functions, not for types.
12230 Adding more things than necessary to the hash table is harmless
12231 except for the performance cost. Adding too few will result in
12232 wasted time in find_partial_die, when we reread the compilation
12233 unit with load_all_dies set. */
12236 || abbrev
->tag
== DW_TAG_constant
12237 || abbrev
->tag
== DW_TAG_subprogram
12238 || abbrev
->tag
== DW_TAG_variable
12239 || abbrev
->tag
== DW_TAG_namespace
12240 || part_die
->is_declaration
)
12244 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
12245 part_die
->offset
.sect_off
, INSERT
);
12249 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12250 sizeof (struct partial_die_info
));
12252 /* For some DIEs we want to follow their children (if any). For C
12253 we have no reason to follow the children of structures; for other
12254 languages we have to, so that we can get at method physnames
12255 to infer fully qualified class names, for DW_AT_specification,
12256 and for C++ template arguments. For C++, we also look one level
12257 inside functions to find template arguments (if the name of the
12258 function does not already contain the template arguments).
12260 For Ada, we need to scan the children of subprograms and lexical
12261 blocks as well because Ada allows the definition of nested
12262 entities that could be interesting for the debugger, such as
12263 nested subprograms for instance. */
12264 if (last_die
->has_children
12266 || last_die
->tag
== DW_TAG_namespace
12267 || last_die
->tag
== DW_TAG_module
12268 || last_die
->tag
== DW_TAG_enumeration_type
12269 || (cu
->language
== language_cplus
12270 && last_die
->tag
== DW_TAG_subprogram
12271 && (last_die
->name
== NULL
12272 || strchr (last_die
->name
, '<') == NULL
))
12273 || (cu
->language
!= language_c
12274 && (last_die
->tag
== DW_TAG_class_type
12275 || last_die
->tag
== DW_TAG_interface_type
12276 || last_die
->tag
== DW_TAG_structure_type
12277 || last_die
->tag
== DW_TAG_union_type
))
12278 || (cu
->language
== language_ada
12279 && (last_die
->tag
== DW_TAG_subprogram
12280 || last_die
->tag
== DW_TAG_lexical_block
))))
12283 parent_die
= last_die
;
12287 /* Otherwise we skip to the next sibling, if any. */
12288 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
12290 /* Back to the top, do it again. */
12294 /* Read a minimal amount of information into the minimal die structure. */
12297 read_partial_die (const struct die_reader_specs
*reader
,
12298 struct partial_die_info
*part_die
,
12299 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
12300 gdb_byte
*info_ptr
)
12302 struct dwarf2_cu
*cu
= reader
->cu
;
12303 struct objfile
*objfile
= cu
->objfile
;
12304 gdb_byte
*buffer
= reader
->buffer
;
12306 struct attribute attr
;
12307 int has_low_pc_attr
= 0;
12308 int has_high_pc_attr
= 0;
12309 int high_pc_relative
= 0;
12311 memset (part_die
, 0, sizeof (struct partial_die_info
));
12313 part_die
->offset
.sect_off
= info_ptr
- buffer
;
12315 info_ptr
+= abbrev_len
;
12317 if (abbrev
== NULL
)
12320 part_die
->tag
= abbrev
->tag
;
12321 part_die
->has_children
= abbrev
->has_children
;
12323 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12325 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
12327 /* Store the data if it is of an attribute we want to keep in a
12328 partial symbol table. */
12332 switch (part_die
->tag
)
12334 case DW_TAG_compile_unit
:
12335 case DW_TAG_partial_unit
:
12336 case DW_TAG_type_unit
:
12337 /* Compilation units have a DW_AT_name that is a filename, not
12338 a source language identifier. */
12339 case DW_TAG_enumeration_type
:
12340 case DW_TAG_enumerator
:
12341 /* These tags always have simple identifiers already; no need
12342 to canonicalize them. */
12343 part_die
->name
= DW_STRING (&attr
);
12347 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
12348 &objfile
->objfile_obstack
);
12352 case DW_AT_linkage_name
:
12353 case DW_AT_MIPS_linkage_name
:
12354 /* Note that both forms of linkage name might appear. We
12355 assume they will be the same, and we only store the last
12357 if (cu
->language
== language_ada
)
12358 part_die
->name
= DW_STRING (&attr
);
12359 part_die
->linkage_name
= DW_STRING (&attr
);
12362 has_low_pc_attr
= 1;
12363 part_die
->lowpc
= DW_ADDR (&attr
);
12365 case DW_AT_high_pc
:
12366 has_high_pc_attr
= 1;
12367 if (attr
.form
== DW_FORM_addr
12368 || attr
.form
== DW_FORM_GNU_addr_index
)
12369 part_die
->highpc
= DW_ADDR (&attr
);
12372 high_pc_relative
= 1;
12373 part_die
->highpc
= DW_UNSND (&attr
);
12376 case DW_AT_location
:
12377 /* Support the .debug_loc offsets. */
12378 if (attr_form_is_block (&attr
))
12380 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
12382 else if (attr_form_is_section_offset (&attr
))
12384 dwarf2_complex_location_expr_complaint ();
12388 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12389 "partial symbol information");
12392 case DW_AT_external
:
12393 part_die
->is_external
= DW_UNSND (&attr
);
12395 case DW_AT_declaration
:
12396 part_die
->is_declaration
= DW_UNSND (&attr
);
12399 part_die
->has_type
= 1;
12401 case DW_AT_abstract_origin
:
12402 case DW_AT_specification
:
12403 case DW_AT_extension
:
12404 part_die
->has_specification
= 1;
12405 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
12407 case DW_AT_sibling
:
12408 /* Ignore absolute siblings, they might point outside of
12409 the current compile unit. */
12410 if (attr
.form
== DW_FORM_ref_addr
)
12411 complaint (&symfile_complaints
,
12412 _("ignoring absolute DW_AT_sibling"));
12414 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
12416 case DW_AT_byte_size
:
12417 part_die
->has_byte_size
= 1;
12419 case DW_AT_calling_convention
:
12420 /* DWARF doesn't provide a way to identify a program's source-level
12421 entry point. DW_AT_calling_convention attributes are only meant
12422 to describe functions' calling conventions.
12424 However, because it's a necessary piece of information in
12425 Fortran, and because DW_CC_program is the only piece of debugging
12426 information whose definition refers to a 'main program' at all,
12427 several compilers have begun marking Fortran main programs with
12428 DW_CC_program --- even when those functions use the standard
12429 calling conventions.
12431 So until DWARF specifies a way to provide this information and
12432 compilers pick up the new representation, we'll support this
12434 if (DW_UNSND (&attr
) == DW_CC_program
12435 && cu
->language
== language_fortran
)
12437 set_main_name (part_die
->name
);
12439 /* As this DIE has a static linkage the name would be difficult
12440 to look up later. */
12441 language_of_main
= language_fortran
;
12445 if (DW_UNSND (&attr
) == DW_INL_inlined
12446 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
12447 part_die
->may_be_inlined
= 1;
12451 if (part_die
->tag
== DW_TAG_imported_unit
)
12452 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
12460 if (high_pc_relative
)
12461 part_die
->highpc
+= part_die
->lowpc
;
12463 if (has_low_pc_attr
&& has_high_pc_attr
)
12465 /* When using the GNU linker, .gnu.linkonce. sections are used to
12466 eliminate duplicate copies of functions and vtables and such.
12467 The linker will arbitrarily choose one and discard the others.
12468 The AT_*_pc values for such functions refer to local labels in
12469 these sections. If the section from that file was discarded, the
12470 labels are not in the output, so the relocs get a value of 0.
12471 If this is a discarded function, mark the pc bounds as invalid,
12472 so that GDB will ignore it. */
12473 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12475 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12477 complaint (&symfile_complaints
,
12478 _("DW_AT_low_pc %s is zero "
12479 "for DIE at 0x%x [in module %s]"),
12480 paddress (gdbarch
, part_die
->lowpc
),
12481 part_die
->offset
.sect_off
, objfile
->name
);
12483 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
12484 else if (part_die
->lowpc
>= part_die
->highpc
)
12486 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12488 complaint (&symfile_complaints
,
12489 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
12490 "for DIE at 0x%x [in module %s]"),
12491 paddress (gdbarch
, part_die
->lowpc
),
12492 paddress (gdbarch
, part_die
->highpc
),
12493 part_die
->offset
.sect_off
, objfile
->name
);
12496 part_die
->has_pc_info
= 1;
12502 /* Find a cached partial DIE at OFFSET in CU. */
12504 static struct partial_die_info
*
12505 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
12507 struct partial_die_info
*lookup_die
= NULL
;
12508 struct partial_die_info part_die
;
12510 part_die
.offset
= offset
;
12511 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
12517 /* Find a partial DIE at OFFSET, which may or may not be in CU,
12518 except in the case of .debug_types DIEs which do not reference
12519 outside their CU (they do however referencing other types via
12520 DW_FORM_ref_sig8). */
12522 static struct partial_die_info
*
12523 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
12525 struct objfile
*objfile
= cu
->objfile
;
12526 struct dwarf2_per_cu_data
*per_cu
= NULL
;
12527 struct partial_die_info
*pd
= NULL
;
12529 if (offset_in_cu_p (&cu
->header
, offset
))
12531 pd
= find_partial_die_in_comp_unit (offset
, cu
);
12534 /* We missed recording what we needed.
12535 Load all dies and try again. */
12536 per_cu
= cu
->per_cu
;
12540 /* TUs don't reference other CUs/TUs (except via type signatures). */
12541 if (cu
->per_cu
->is_debug_types
)
12543 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
12544 " external reference to offset 0x%lx [in module %s].\n"),
12545 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
12546 bfd_get_filename (objfile
->obfd
));
12548 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
12550 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
12551 load_partial_comp_unit (per_cu
);
12553 per_cu
->cu
->last_used
= 0;
12554 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12557 /* If we didn't find it, and not all dies have been loaded,
12558 load them all and try again. */
12560 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
12562 per_cu
->load_all_dies
= 1;
12564 /* This is nasty. When we reread the DIEs, somewhere up the call chain
12565 THIS_CU->cu may already be in use. So we can't just free it and
12566 replace its DIEs with the ones we read in. Instead, we leave those
12567 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
12568 and clobber THIS_CU->cu->partial_dies with the hash table for the new
12570 load_partial_comp_unit (per_cu
);
12572 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12576 internal_error (__FILE__
, __LINE__
,
12577 _("could not find partial DIE 0x%x "
12578 "in cache [from module %s]\n"),
12579 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
12583 /* See if we can figure out if the class lives in a namespace. We do
12584 this by looking for a member function; its demangled name will
12585 contain namespace info, if there is any. */
12588 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
12589 struct dwarf2_cu
*cu
)
12591 /* NOTE: carlton/2003-10-07: Getting the info this way changes
12592 what template types look like, because the demangler
12593 frequently doesn't give the same name as the debug info. We
12594 could fix this by only using the demangled name to get the
12595 prefix (but see comment in read_structure_type). */
12597 struct partial_die_info
*real_pdi
;
12598 struct partial_die_info
*child_pdi
;
12600 /* If this DIE (this DIE's specification, if any) has a parent, then
12601 we should not do this. We'll prepend the parent's fully qualified
12602 name when we create the partial symbol. */
12604 real_pdi
= struct_pdi
;
12605 while (real_pdi
->has_specification
)
12606 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
12608 if (real_pdi
->die_parent
!= NULL
)
12611 for (child_pdi
= struct_pdi
->die_child
;
12613 child_pdi
= child_pdi
->die_sibling
)
12615 if (child_pdi
->tag
== DW_TAG_subprogram
12616 && child_pdi
->linkage_name
!= NULL
)
12618 char *actual_class_name
12619 = language_class_name_from_physname (cu
->language_defn
,
12620 child_pdi
->linkage_name
);
12621 if (actual_class_name
!= NULL
)
12624 = obsavestring (actual_class_name
,
12625 strlen (actual_class_name
),
12626 &cu
->objfile
->objfile_obstack
);
12627 xfree (actual_class_name
);
12634 /* Adjust PART_DIE before generating a symbol for it. This function
12635 may set the is_external flag or change the DIE's name. */
12638 fixup_partial_die (struct partial_die_info
*part_die
,
12639 struct dwarf2_cu
*cu
)
12641 /* Once we've fixed up a die, there's no point in doing so again.
12642 This also avoids a memory leak if we were to call
12643 guess_partial_die_structure_name multiple times. */
12644 if (part_die
->fixup_called
)
12647 /* If we found a reference attribute and the DIE has no name, try
12648 to find a name in the referred to DIE. */
12650 if (part_die
->name
== NULL
&& part_die
->has_specification
)
12652 struct partial_die_info
*spec_die
;
12654 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
12656 fixup_partial_die (spec_die
, cu
);
12658 if (spec_die
->name
)
12660 part_die
->name
= spec_die
->name
;
12662 /* Copy DW_AT_external attribute if it is set. */
12663 if (spec_die
->is_external
)
12664 part_die
->is_external
= spec_die
->is_external
;
12668 /* Set default names for some unnamed DIEs. */
12670 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
12671 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
12673 /* If there is no parent die to provide a namespace, and there are
12674 children, see if we can determine the namespace from their linkage
12676 if (cu
->language
== language_cplus
12677 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12678 && part_die
->die_parent
== NULL
12679 && part_die
->has_children
12680 && (part_die
->tag
== DW_TAG_class_type
12681 || part_die
->tag
== DW_TAG_structure_type
12682 || part_die
->tag
== DW_TAG_union_type
))
12683 guess_partial_die_structure_name (part_die
, cu
);
12685 /* GCC might emit a nameless struct or union that has a linkage
12686 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12687 if (part_die
->name
== NULL
12688 && (part_die
->tag
== DW_TAG_class_type
12689 || part_die
->tag
== DW_TAG_interface_type
12690 || part_die
->tag
== DW_TAG_structure_type
12691 || part_die
->tag
== DW_TAG_union_type
)
12692 && part_die
->linkage_name
!= NULL
)
12696 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
12701 /* Strip any leading namespaces/classes, keep only the base name.
12702 DW_AT_name for named DIEs does not contain the prefixes. */
12703 base
= strrchr (demangled
, ':');
12704 if (base
&& base
> demangled
&& base
[-1] == ':')
12709 part_die
->name
= obsavestring (base
, strlen (base
),
12710 &cu
->objfile
->objfile_obstack
);
12715 part_die
->fixup_called
= 1;
12718 /* Read an attribute value described by an attribute form. */
12721 read_attribute_value (const struct die_reader_specs
*reader
,
12722 struct attribute
*attr
, unsigned form
,
12723 gdb_byte
*info_ptr
)
12725 struct dwarf2_cu
*cu
= reader
->cu
;
12726 bfd
*abfd
= reader
->abfd
;
12727 struct comp_unit_head
*cu_header
= &cu
->header
;
12728 unsigned int bytes_read
;
12729 struct dwarf_block
*blk
;
12734 case DW_FORM_ref_addr
:
12735 if (cu
->header
.version
== 2)
12736 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12738 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
12739 &cu
->header
, &bytes_read
);
12740 info_ptr
+= bytes_read
;
12743 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12744 info_ptr
+= bytes_read
;
12746 case DW_FORM_block2
:
12747 blk
= dwarf_alloc_block (cu
);
12748 blk
->size
= read_2_bytes (abfd
, info_ptr
);
12750 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12751 info_ptr
+= blk
->size
;
12752 DW_BLOCK (attr
) = blk
;
12754 case DW_FORM_block4
:
12755 blk
= dwarf_alloc_block (cu
);
12756 blk
->size
= read_4_bytes (abfd
, info_ptr
);
12758 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12759 info_ptr
+= blk
->size
;
12760 DW_BLOCK (attr
) = blk
;
12762 case DW_FORM_data2
:
12763 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
12766 case DW_FORM_data4
:
12767 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
12770 case DW_FORM_data8
:
12771 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
12774 case DW_FORM_sec_offset
:
12775 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
12776 info_ptr
+= bytes_read
;
12778 case DW_FORM_string
:
12779 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
12780 DW_STRING_IS_CANONICAL (attr
) = 0;
12781 info_ptr
+= bytes_read
;
12784 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
12786 DW_STRING_IS_CANONICAL (attr
) = 0;
12787 info_ptr
+= bytes_read
;
12789 case DW_FORM_exprloc
:
12790 case DW_FORM_block
:
12791 blk
= dwarf_alloc_block (cu
);
12792 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12793 info_ptr
+= bytes_read
;
12794 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12795 info_ptr
+= blk
->size
;
12796 DW_BLOCK (attr
) = blk
;
12798 case DW_FORM_block1
:
12799 blk
= dwarf_alloc_block (cu
);
12800 blk
->size
= read_1_byte (abfd
, info_ptr
);
12802 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12803 info_ptr
+= blk
->size
;
12804 DW_BLOCK (attr
) = blk
;
12806 case DW_FORM_data1
:
12807 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12811 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12814 case DW_FORM_flag_present
:
12815 DW_UNSND (attr
) = 1;
12817 case DW_FORM_sdata
:
12818 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
12819 info_ptr
+= bytes_read
;
12821 case DW_FORM_udata
:
12822 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12823 info_ptr
+= bytes_read
;
12826 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12827 + read_1_byte (abfd
, info_ptr
));
12831 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12832 + read_2_bytes (abfd
, info_ptr
));
12836 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12837 + read_4_bytes (abfd
, info_ptr
));
12841 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12842 + read_8_bytes (abfd
, info_ptr
));
12845 case DW_FORM_ref_sig8
:
12846 /* Convert the signature to something we can record in DW_UNSND
12848 NOTE: This is NULL if the type wasn't found. */
12849 DW_SIGNATURED_TYPE (attr
) =
12850 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
12853 case DW_FORM_ref_udata
:
12854 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12855 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
12856 info_ptr
+= bytes_read
;
12858 case DW_FORM_indirect
:
12859 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12860 info_ptr
+= bytes_read
;
12861 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
12863 case DW_FORM_GNU_addr_index
:
12864 if (reader
->dwo_file
== NULL
)
12866 /* For now flag a hard error.
12867 Later we can turn this into a complaint. */
12868 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12869 dwarf_form_name (form
),
12870 bfd_get_filename (abfd
));
12872 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
12873 info_ptr
+= bytes_read
;
12875 case DW_FORM_GNU_str_index
:
12876 if (reader
->dwo_file
== NULL
)
12878 /* For now flag a hard error.
12879 Later we can turn this into a complaint if warranted. */
12880 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12881 dwarf_form_name (form
),
12882 bfd_get_filename (abfd
));
12885 ULONGEST str_index
=
12886 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12888 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
12889 DW_STRING_IS_CANONICAL (attr
) = 0;
12890 info_ptr
+= bytes_read
;
12894 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
12895 dwarf_form_name (form
),
12896 bfd_get_filename (abfd
));
12899 /* We have seen instances where the compiler tried to emit a byte
12900 size attribute of -1 which ended up being encoded as an unsigned
12901 0xffffffff. Although 0xffffffff is technically a valid size value,
12902 an object of this size seems pretty unlikely so we can relatively
12903 safely treat these cases as if the size attribute was invalid and
12904 treat them as zero by default. */
12905 if (attr
->name
== DW_AT_byte_size
12906 && form
== DW_FORM_data4
12907 && DW_UNSND (attr
) >= 0xffffffff)
12910 (&symfile_complaints
,
12911 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
12912 hex_string (DW_UNSND (attr
)));
12913 DW_UNSND (attr
) = 0;
12919 /* Read an attribute described by an abbreviated attribute. */
12922 read_attribute (const struct die_reader_specs
*reader
,
12923 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
12924 gdb_byte
*info_ptr
)
12926 attr
->name
= abbrev
->name
;
12927 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
12930 /* Read dwarf information from a buffer. */
12932 static unsigned int
12933 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
12935 return bfd_get_8 (abfd
, buf
);
12939 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
12941 return bfd_get_signed_8 (abfd
, buf
);
12944 static unsigned int
12945 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
12947 return bfd_get_16 (abfd
, buf
);
12951 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12953 return bfd_get_signed_16 (abfd
, buf
);
12956 static unsigned int
12957 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
12959 return bfd_get_32 (abfd
, buf
);
12963 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12965 return bfd_get_signed_32 (abfd
, buf
);
12969 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
12971 return bfd_get_64 (abfd
, buf
);
12975 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
12976 unsigned int *bytes_read
)
12978 struct comp_unit_head
*cu_header
= &cu
->header
;
12979 CORE_ADDR retval
= 0;
12981 if (cu_header
->signed_addr_p
)
12983 switch (cu_header
->addr_size
)
12986 retval
= bfd_get_signed_16 (abfd
, buf
);
12989 retval
= bfd_get_signed_32 (abfd
, buf
);
12992 retval
= bfd_get_signed_64 (abfd
, buf
);
12995 internal_error (__FILE__
, __LINE__
,
12996 _("read_address: bad switch, signed [in module %s]"),
12997 bfd_get_filename (abfd
));
13002 switch (cu_header
->addr_size
)
13005 retval
= bfd_get_16 (abfd
, buf
);
13008 retval
= bfd_get_32 (abfd
, buf
);
13011 retval
= bfd_get_64 (abfd
, buf
);
13014 internal_error (__FILE__
, __LINE__
,
13015 _("read_address: bad switch, "
13016 "unsigned [in module %s]"),
13017 bfd_get_filename (abfd
));
13021 *bytes_read
= cu_header
->addr_size
;
13025 /* Read the initial length from a section. The (draft) DWARF 3
13026 specification allows the initial length to take up either 4 bytes
13027 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
13028 bytes describe the length and all offsets will be 8 bytes in length
13031 An older, non-standard 64-bit format is also handled by this
13032 function. The older format in question stores the initial length
13033 as an 8-byte quantity without an escape value. Lengths greater
13034 than 2^32 aren't very common which means that the initial 4 bytes
13035 is almost always zero. Since a length value of zero doesn't make
13036 sense for the 32-bit format, this initial zero can be considered to
13037 be an escape value which indicates the presence of the older 64-bit
13038 format. As written, the code can't detect (old format) lengths
13039 greater than 4GB. If it becomes necessary to handle lengths
13040 somewhat larger than 4GB, we could allow other small values (such
13041 as the non-sensical values of 1, 2, and 3) to also be used as
13042 escape values indicating the presence of the old format.
13044 The value returned via bytes_read should be used to increment the
13045 relevant pointer after calling read_initial_length().
13047 [ Note: read_initial_length() and read_offset() are based on the
13048 document entitled "DWARF Debugging Information Format", revision
13049 3, draft 8, dated November 19, 2001. This document was obtained
13052 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
13054 This document is only a draft and is subject to change. (So beware.)
13056 Details regarding the older, non-standard 64-bit format were
13057 determined empirically by examining 64-bit ELF files produced by
13058 the SGI toolchain on an IRIX 6.5 machine.
13060 - Kevin, July 16, 2002
13064 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
13066 LONGEST length
= bfd_get_32 (abfd
, buf
);
13068 if (length
== 0xffffffff)
13070 length
= bfd_get_64 (abfd
, buf
+ 4);
13073 else if (length
== 0)
13075 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
13076 length
= bfd_get_64 (abfd
, buf
);
13087 /* Cover function for read_initial_length.
13088 Returns the length of the object at BUF, and stores the size of the
13089 initial length in *BYTES_READ and stores the size that offsets will be in
13091 If the initial length size is not equivalent to that specified in
13092 CU_HEADER then issue a complaint.
13093 This is useful when reading non-comp-unit headers. */
13096 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
13097 const struct comp_unit_head
*cu_header
,
13098 unsigned int *bytes_read
,
13099 unsigned int *offset_size
)
13101 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
13103 gdb_assert (cu_header
->initial_length_size
== 4
13104 || cu_header
->initial_length_size
== 8
13105 || cu_header
->initial_length_size
== 12);
13107 if (cu_header
->initial_length_size
!= *bytes_read
)
13108 complaint (&symfile_complaints
,
13109 _("intermixed 32-bit and 64-bit DWARF sections"));
13111 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
13115 /* Read an offset from the data stream. The size of the offset is
13116 given by cu_header->offset_size. */
13119 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
13120 unsigned int *bytes_read
)
13122 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
13124 *bytes_read
= cu_header
->offset_size
;
13128 /* Read an offset from the data stream. */
13131 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
13133 LONGEST retval
= 0;
13135 switch (offset_size
)
13138 retval
= bfd_get_32 (abfd
, buf
);
13141 retval
= bfd_get_64 (abfd
, buf
);
13144 internal_error (__FILE__
, __LINE__
,
13145 _("read_offset_1: bad switch [in module %s]"),
13146 bfd_get_filename (abfd
));
13153 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
13155 /* If the size of a host char is 8 bits, we can return a pointer
13156 to the buffer, otherwise we have to copy the data to a buffer
13157 allocated on the temporary obstack. */
13158 gdb_assert (HOST_CHAR_BIT
== 8);
13163 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13165 /* If the size of a host char is 8 bits, we can return a pointer
13166 to the string, otherwise we have to copy the string to a buffer
13167 allocated on the temporary obstack. */
13168 gdb_assert (HOST_CHAR_BIT
== 8);
13171 *bytes_read_ptr
= 1;
13174 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
13175 return (char *) buf
;
13179 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
13181 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
13182 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
13183 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
13184 bfd_get_filename (abfd
));
13185 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
13186 error (_("DW_FORM_strp pointing outside of "
13187 ".debug_str section [in module %s]"),
13188 bfd_get_filename (abfd
));
13189 gdb_assert (HOST_CHAR_BIT
== 8);
13190 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
13192 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
13196 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
13197 const struct comp_unit_head
*cu_header
,
13198 unsigned int *bytes_read_ptr
)
13200 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
13202 return read_indirect_string_at_offset (abfd
, str_offset
);
13206 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13209 unsigned int num_read
;
13211 unsigned char byte
;
13219 byte
= bfd_get_8 (abfd
, buf
);
13222 result
|= ((ULONGEST
) (byte
& 127) << shift
);
13223 if ((byte
& 128) == 0)
13229 *bytes_read_ptr
= num_read
;
13234 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13237 int i
, shift
, num_read
;
13238 unsigned char byte
;
13246 byte
= bfd_get_8 (abfd
, buf
);
13249 result
|= ((LONGEST
) (byte
& 127) << shift
);
13251 if ((byte
& 128) == 0)
13256 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
13257 result
|= -(((LONGEST
) 1) << shift
);
13258 *bytes_read_ptr
= num_read
;
13262 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
13263 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
13264 ADDR_SIZE is the size of addresses from the CU header. */
13267 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
13269 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13270 bfd
*abfd
= objfile
->obfd
;
13271 const gdb_byte
*info_ptr
;
13273 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
13274 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
13275 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
13277 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
13278 error (_("DW_FORM_addr_index pointing outside of "
13279 ".debug_addr section [in module %s]"),
13281 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
13282 + addr_base
+ addr_index
* addr_size
);
13283 if (addr_size
== 4)
13284 return bfd_get_32 (abfd
, info_ptr
);
13286 return bfd_get_64 (abfd
, info_ptr
);
13289 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
13292 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
13294 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
13297 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
13300 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
13301 unsigned int *bytes_read
)
13303 bfd
*abfd
= cu
->objfile
->obfd
;
13304 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
13306 return read_addr_index (cu
, addr_index
);
13309 /* Data structure to pass results from dwarf2_read_addr_index_reader
13310 back to dwarf2_read_addr_index. */
13312 struct dwarf2_read_addr_index_data
13314 ULONGEST addr_base
;
13318 /* die_reader_func for dwarf2_read_addr_index. */
13321 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
13322 gdb_byte
*info_ptr
,
13323 struct die_info
*comp_unit_die
,
13327 struct dwarf2_cu
*cu
= reader
->cu
;
13328 struct dwarf2_read_addr_index_data
*aidata
=
13329 (struct dwarf2_read_addr_index_data
*) data
;
13331 aidata
->addr_base
= cu
->addr_base
;
13332 aidata
->addr_size
= cu
->header
.addr_size
;
13335 /* Given an index in .debug_addr, fetch the value.
13336 NOTE: This can be called during dwarf expression evaluation,
13337 long after the debug information has been read, and thus per_cu->cu
13338 may no longer exist. */
13341 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
13342 unsigned int addr_index
)
13344 struct objfile
*objfile
= per_cu
->objfile
;
13345 struct dwarf2_cu
*cu
= per_cu
->cu
;
13346 ULONGEST addr_base
;
13349 /* This is intended to be called from outside this file. */
13350 dw2_setup (objfile
);
13352 /* We need addr_base and addr_size.
13353 If we don't have PER_CU->cu, we have to get it.
13354 Nasty, but the alternative is storing the needed info in PER_CU,
13355 which at this point doesn't seem justified: it's not clear how frequently
13356 it would get used and it would increase the size of every PER_CU.
13357 Entry points like dwarf2_per_cu_addr_size do a similar thing
13358 so we're not in uncharted territory here.
13359 Alas we need to be a bit more complicated as addr_base is contained
13362 We don't need to read the entire CU(/TU).
13363 We just need the header and top level die.
13364 IWBN to use the aging mechanism to let us lazily later discard the CU.
13365 See however init_cutu_and_read_dies_simple. */
13369 addr_base
= cu
->addr_base
;
13370 addr_size
= cu
->header
.addr_size
;
13374 struct dwarf2_read_addr_index_data aidata
;
13376 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
13378 addr_base
= aidata
.addr_base
;
13379 addr_size
= aidata
.addr_size
;
13382 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
13385 /* Given a DW_AT_str_index, fetch the string. */
13388 read_str_index (const struct die_reader_specs
*reader
,
13389 struct dwarf2_cu
*cu
, ULONGEST str_index
)
13391 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13392 const char *dwo_name
= objfile
->name
;
13393 bfd
*abfd
= objfile
->obfd
;
13394 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
13395 gdb_byte
*info_ptr
;
13396 ULONGEST str_offset
;
13398 dwarf2_read_section (objfile
, §ions
->str
);
13399 dwarf2_read_section (objfile
, §ions
->str_offsets
);
13400 if (sections
->str
.buffer
== NULL
)
13401 error (_("DW_FORM_str_index used without .debug_str.dwo section"
13402 " in CU at offset 0x%lx [in module %s]"),
13403 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13404 if (sections
->str_offsets
.buffer
== NULL
)
13405 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
13406 " in CU at offset 0x%lx [in module %s]"),
13407 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13408 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
13409 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
13410 " section in CU at offset 0x%lx [in module %s]"),
13411 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13412 info_ptr
= (sections
->str_offsets
.buffer
13413 + str_index
* cu
->header
.offset_size
);
13414 if (cu
->header
.offset_size
== 4)
13415 str_offset
= bfd_get_32 (abfd
, info_ptr
);
13417 str_offset
= bfd_get_64 (abfd
, info_ptr
);
13418 if (str_offset
>= sections
->str
.size
)
13419 error (_("Offset from DW_FORM_str_index pointing outside of"
13420 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
13421 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13422 return (char *) (sections
->str
.buffer
+ str_offset
);
13425 /* Return the length of an LEB128 number in BUF. */
13428 leb128_size (const gdb_byte
*buf
)
13430 const gdb_byte
*begin
= buf
;
13436 if ((byte
& 128) == 0)
13437 return buf
- begin
;
13442 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
13449 cu
->language
= language_c
;
13451 case DW_LANG_C_plus_plus
:
13452 cu
->language
= language_cplus
;
13455 cu
->language
= language_d
;
13457 case DW_LANG_Fortran77
:
13458 case DW_LANG_Fortran90
:
13459 case DW_LANG_Fortran95
:
13460 cu
->language
= language_fortran
;
13463 cu
->language
= language_go
;
13465 case DW_LANG_Mips_Assembler
:
13466 cu
->language
= language_asm
;
13469 cu
->language
= language_java
;
13471 case DW_LANG_Ada83
:
13472 case DW_LANG_Ada95
:
13473 cu
->language
= language_ada
;
13475 case DW_LANG_Modula2
:
13476 cu
->language
= language_m2
;
13478 case DW_LANG_Pascal83
:
13479 cu
->language
= language_pascal
;
13482 cu
->language
= language_objc
;
13484 case DW_LANG_Cobol74
:
13485 case DW_LANG_Cobol85
:
13487 cu
->language
= language_minimal
;
13490 cu
->language_defn
= language_def (cu
->language
);
13493 /* Return the named attribute or NULL if not there. */
13495 static struct attribute
*
13496 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
13501 struct attribute
*spec
= NULL
;
13503 for (i
= 0; i
< die
->num_attrs
; ++i
)
13505 if (die
->attrs
[i
].name
== name
)
13506 return &die
->attrs
[i
];
13507 if (die
->attrs
[i
].name
== DW_AT_specification
13508 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
13509 spec
= &die
->attrs
[i
];
13515 die
= follow_die_ref (die
, spec
, &cu
);
13521 /* Return the named attribute or NULL if not there,
13522 but do not follow DW_AT_specification, etc.
13523 This is for use in contexts where we're reading .debug_types dies.
13524 Following DW_AT_specification, DW_AT_abstract_origin will take us
13525 back up the chain, and we want to go down. */
13527 static struct attribute
*
13528 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
13532 for (i
= 0; i
< die
->num_attrs
; ++i
)
13533 if (die
->attrs
[i
].name
== name
)
13534 return &die
->attrs
[i
];
13539 /* Return non-zero iff the attribute NAME is defined for the given DIE,
13540 and holds a non-zero value. This function should only be used for
13541 DW_FORM_flag or DW_FORM_flag_present attributes. */
13544 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
13546 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
13548 return (attr
&& DW_UNSND (attr
));
13552 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
13554 /* A DIE is a declaration if it has a DW_AT_declaration attribute
13555 which value is non-zero. However, we have to be careful with
13556 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
13557 (via dwarf2_flag_true_p) follows this attribute. So we may
13558 end up accidently finding a declaration attribute that belongs
13559 to a different DIE referenced by the specification attribute,
13560 even though the given DIE does not have a declaration attribute. */
13561 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
13562 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
13565 /* Return the die giving the specification for DIE, if there is
13566 one. *SPEC_CU is the CU containing DIE on input, and the CU
13567 containing the return value on output. If there is no
13568 specification, but there is an abstract origin, that is
13571 static struct die_info
*
13572 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
13574 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
13577 if (spec_attr
== NULL
)
13578 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
13580 if (spec_attr
== NULL
)
13583 return follow_die_ref (die
, spec_attr
, spec_cu
);
13586 /* Free the line_header structure *LH, and any arrays and strings it
13588 NOTE: This is also used as a "cleanup" function. */
13591 free_line_header (struct line_header
*lh
)
13593 if (lh
->standard_opcode_lengths
)
13594 xfree (lh
->standard_opcode_lengths
);
13596 /* Remember that all the lh->file_names[i].name pointers are
13597 pointers into debug_line_buffer, and don't need to be freed. */
13598 if (lh
->file_names
)
13599 xfree (lh
->file_names
);
13601 /* Similarly for the include directory names. */
13602 if (lh
->include_dirs
)
13603 xfree (lh
->include_dirs
);
13608 /* Add an entry to LH's include directory table. */
13611 add_include_dir (struct line_header
*lh
, char *include_dir
)
13613 /* Grow the array if necessary. */
13614 if (lh
->include_dirs_size
== 0)
13616 lh
->include_dirs_size
= 1; /* for testing */
13617 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
13618 * sizeof (*lh
->include_dirs
));
13620 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
13622 lh
->include_dirs_size
*= 2;
13623 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
13624 (lh
->include_dirs_size
13625 * sizeof (*lh
->include_dirs
)));
13628 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
13631 /* Add an entry to LH's file name table. */
13634 add_file_name (struct line_header
*lh
,
13636 unsigned int dir_index
,
13637 unsigned int mod_time
,
13638 unsigned int length
)
13640 struct file_entry
*fe
;
13642 /* Grow the array if necessary. */
13643 if (lh
->file_names_size
== 0)
13645 lh
->file_names_size
= 1; /* for testing */
13646 lh
->file_names
= xmalloc (lh
->file_names_size
13647 * sizeof (*lh
->file_names
));
13649 else if (lh
->num_file_names
>= lh
->file_names_size
)
13651 lh
->file_names_size
*= 2;
13652 lh
->file_names
= xrealloc (lh
->file_names
,
13653 (lh
->file_names_size
13654 * sizeof (*lh
->file_names
)));
13657 fe
= &lh
->file_names
[lh
->num_file_names
++];
13659 fe
->dir_index
= dir_index
;
13660 fe
->mod_time
= mod_time
;
13661 fe
->length
= length
;
13662 fe
->included_p
= 0;
13666 /* Read the statement program header starting at OFFSET in
13667 .debug_line, or .debug_line.dwo. Return a pointer
13668 to a struct line_header, allocated using xmalloc.
13670 NOTE: the strings in the include directory and file name tables of
13671 the returned object point into the dwarf line section buffer,
13672 and must not be freed. */
13674 static struct line_header
*
13675 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
13677 struct cleanup
*back_to
;
13678 struct line_header
*lh
;
13679 gdb_byte
*line_ptr
;
13680 unsigned int bytes_read
, offset_size
;
13682 char *cur_dir
, *cur_file
;
13683 struct dwarf2_section_info
*section
;
13686 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
13688 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13689 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
13691 section
= &dwarf2_per_objfile
->line
;
13693 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
13694 if (section
->buffer
== NULL
)
13696 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13697 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
13699 complaint (&symfile_complaints
, _("missing .debug_line section"));
13703 /* We can't do this until we know the section is non-empty.
13704 Only then do we know we have such a section. */
13705 abfd
= section
->asection
->owner
;
13707 /* Make sure that at least there's room for the total_length field.
13708 That could be 12 bytes long, but we're just going to fudge that. */
13709 if (offset
+ 4 >= section
->size
)
13711 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13715 lh
= xmalloc (sizeof (*lh
));
13716 memset (lh
, 0, sizeof (*lh
));
13717 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
13720 line_ptr
= section
->buffer
+ offset
;
13722 /* Read in the header. */
13724 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
13725 &bytes_read
, &offset_size
);
13726 line_ptr
+= bytes_read
;
13727 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
13729 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13732 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
13733 lh
->version
= read_2_bytes (abfd
, line_ptr
);
13735 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
13736 line_ptr
+= offset_size
;
13737 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
13739 if (lh
->version
>= 4)
13741 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
13745 lh
->maximum_ops_per_instruction
= 1;
13747 if (lh
->maximum_ops_per_instruction
== 0)
13749 lh
->maximum_ops_per_instruction
= 1;
13750 complaint (&symfile_complaints
,
13751 _("invalid maximum_ops_per_instruction "
13752 "in `.debug_line' section"));
13755 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
13757 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
13759 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
13761 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
13763 lh
->standard_opcode_lengths
13764 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
13766 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
13767 for (i
= 1; i
< lh
->opcode_base
; ++i
)
13769 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
13773 /* Read directory table. */
13774 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13776 line_ptr
+= bytes_read
;
13777 add_include_dir (lh
, cur_dir
);
13779 line_ptr
+= bytes_read
;
13781 /* Read file name table. */
13782 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13784 unsigned int dir_index
, mod_time
, length
;
13786 line_ptr
+= bytes_read
;
13787 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13788 line_ptr
+= bytes_read
;
13789 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13790 line_ptr
+= bytes_read
;
13791 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13792 line_ptr
+= bytes_read
;
13794 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13796 line_ptr
+= bytes_read
;
13797 lh
->statement_program_start
= line_ptr
;
13799 if (line_ptr
> (section
->buffer
+ section
->size
))
13800 complaint (&symfile_complaints
,
13801 _("line number info header doesn't "
13802 "fit in `.debug_line' section"));
13804 discard_cleanups (back_to
);
13808 /* Subroutine of dwarf_decode_lines to simplify it.
13809 Return the file name of the psymtab for included file FILE_INDEX
13810 in line header LH of PST.
13811 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13812 If space for the result is malloc'd, it will be freed by a cleanup.
13813 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
13816 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
13817 const struct partial_symtab
*pst
,
13818 const char *comp_dir
)
13820 const struct file_entry fe
= lh
->file_names
[file_index
];
13821 char *include_name
= fe
.name
;
13822 char *include_name_to_compare
= include_name
;
13823 char *dir_name
= NULL
;
13824 const char *pst_filename
;
13825 char *copied_name
= NULL
;
13829 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
13831 if (!IS_ABSOLUTE_PATH (include_name
)
13832 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
13834 /* Avoid creating a duplicate psymtab for PST.
13835 We do this by comparing INCLUDE_NAME and PST_FILENAME.
13836 Before we do the comparison, however, we need to account
13837 for DIR_NAME and COMP_DIR.
13838 First prepend dir_name (if non-NULL). If we still don't
13839 have an absolute path prepend comp_dir (if non-NULL).
13840 However, the directory we record in the include-file's
13841 psymtab does not contain COMP_DIR (to match the
13842 corresponding symtab(s)).
13847 bash$ gcc -g ./hello.c
13848 include_name = "hello.c"
13850 DW_AT_comp_dir = comp_dir = "/tmp"
13851 DW_AT_name = "./hello.c" */
13853 if (dir_name
!= NULL
)
13855 include_name
= concat (dir_name
, SLASH_STRING
,
13856 include_name
, (char *)NULL
);
13857 include_name_to_compare
= include_name
;
13858 make_cleanup (xfree
, include_name
);
13860 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
13862 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
13863 include_name
, (char *)NULL
);
13867 pst_filename
= pst
->filename
;
13868 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
13870 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
13871 pst_filename
, (char *)NULL
);
13872 pst_filename
= copied_name
;
13875 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
13877 if (include_name_to_compare
!= include_name
)
13878 xfree (include_name_to_compare
);
13879 if (copied_name
!= NULL
)
13880 xfree (copied_name
);
13884 return include_name
;
13887 /* Ignore this record_line request. */
13890 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13895 /* Subroutine of dwarf_decode_lines to simplify it.
13896 Process the line number information in LH. */
13899 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
13900 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
13902 gdb_byte
*line_ptr
, *extended_end
;
13903 gdb_byte
*line_end
;
13904 unsigned int bytes_read
, extended_len
;
13905 unsigned char op_code
, extended_op
, adj_opcode
;
13906 CORE_ADDR baseaddr
;
13907 struct objfile
*objfile
= cu
->objfile
;
13908 bfd
*abfd
= objfile
->obfd
;
13909 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13910 const int decode_for_pst_p
= (pst
!= NULL
);
13911 struct subfile
*last_subfile
= NULL
;
13912 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13915 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13917 line_ptr
= lh
->statement_program_start
;
13918 line_end
= lh
->statement_program_end
;
13920 /* Read the statement sequences until there's nothing left. */
13921 while (line_ptr
< line_end
)
13923 /* state machine registers */
13924 CORE_ADDR address
= 0;
13925 unsigned int file
= 1;
13926 unsigned int line
= 1;
13927 unsigned int column
= 0;
13928 int is_stmt
= lh
->default_is_stmt
;
13929 int basic_block
= 0;
13930 int end_sequence
= 0;
13932 unsigned char op_index
= 0;
13934 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
13936 /* Start a subfile for the current file of the state machine. */
13937 /* lh->include_dirs and lh->file_names are 0-based, but the
13938 directory and file name numbers in the statement program
13940 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13944 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13946 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13949 /* Decode the table. */
13950 while (!end_sequence
)
13952 op_code
= read_1_byte (abfd
, line_ptr
);
13954 if (line_ptr
> line_end
)
13956 dwarf2_debug_line_missing_end_sequence_complaint ();
13960 if (op_code
>= lh
->opcode_base
)
13962 /* Special operand. */
13963 adj_opcode
= op_code
- lh
->opcode_base
;
13964 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
13965 / lh
->maximum_ops_per_instruction
)
13966 * lh
->minimum_instruction_length
);
13967 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
13968 % lh
->maximum_ops_per_instruction
);
13969 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
13970 if (lh
->num_file_names
< file
|| file
== 0)
13971 dwarf2_debug_line_missing_file_complaint ();
13972 /* For now we ignore lines not starting on an
13973 instruction boundary. */
13974 else if (op_index
== 0)
13976 lh
->file_names
[file
- 1].included_p
= 1;
13977 if (!decode_for_pst_p
&& is_stmt
)
13979 if (last_subfile
!= current_subfile
)
13981 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13983 (*p_record_line
) (last_subfile
, 0, addr
);
13984 last_subfile
= current_subfile
;
13986 /* Append row to matrix using current values. */
13987 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13988 (*p_record_line
) (current_subfile
, line
, addr
);
13993 else switch (op_code
)
13995 case DW_LNS_extended_op
:
13996 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
13998 line_ptr
+= bytes_read
;
13999 extended_end
= line_ptr
+ extended_len
;
14000 extended_op
= read_1_byte (abfd
, line_ptr
);
14002 switch (extended_op
)
14004 case DW_LNE_end_sequence
:
14005 p_record_line
= record_line
;
14008 case DW_LNE_set_address
:
14009 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
14011 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14013 /* This line table is for a function which has been
14014 GCd by the linker. Ignore it. PR gdb/12528 */
14017 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
14019 complaint (&symfile_complaints
,
14020 _(".debug_line address at offset 0x%lx is 0 "
14022 line_offset
, objfile
->name
);
14023 p_record_line
= noop_record_line
;
14027 line_ptr
+= bytes_read
;
14028 address
+= baseaddr
;
14030 case DW_LNE_define_file
:
14033 unsigned int dir_index
, mod_time
, length
;
14035 cur_file
= read_direct_string (abfd
, line_ptr
,
14037 line_ptr
+= bytes_read
;
14039 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14040 line_ptr
+= bytes_read
;
14042 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14043 line_ptr
+= bytes_read
;
14045 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14046 line_ptr
+= bytes_read
;
14047 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14050 case DW_LNE_set_discriminator
:
14051 /* The discriminator is not interesting to the debugger;
14053 line_ptr
= extended_end
;
14056 complaint (&symfile_complaints
,
14057 _("mangled .debug_line section"));
14060 /* Make sure that we parsed the extended op correctly. If e.g.
14061 we expected a different address size than the producer used,
14062 we may have read the wrong number of bytes. */
14063 if (line_ptr
!= extended_end
)
14065 complaint (&symfile_complaints
,
14066 _("mangled .debug_line section"));
14071 if (lh
->num_file_names
< file
|| file
== 0)
14072 dwarf2_debug_line_missing_file_complaint ();
14075 lh
->file_names
[file
- 1].included_p
= 1;
14076 if (!decode_for_pst_p
&& is_stmt
)
14078 if (last_subfile
!= current_subfile
)
14080 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14082 (*p_record_line
) (last_subfile
, 0, addr
);
14083 last_subfile
= current_subfile
;
14085 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14086 (*p_record_line
) (current_subfile
, line
, addr
);
14091 case DW_LNS_advance_pc
:
14094 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14096 address
+= (((op_index
+ adjust
)
14097 / lh
->maximum_ops_per_instruction
)
14098 * lh
->minimum_instruction_length
);
14099 op_index
= ((op_index
+ adjust
)
14100 % lh
->maximum_ops_per_instruction
);
14101 line_ptr
+= bytes_read
;
14104 case DW_LNS_advance_line
:
14105 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
14106 line_ptr
+= bytes_read
;
14108 case DW_LNS_set_file
:
14110 /* The arrays lh->include_dirs and lh->file_names are
14111 0-based, but the directory and file name numbers in
14112 the statement program are 1-based. */
14113 struct file_entry
*fe
;
14116 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14117 line_ptr
+= bytes_read
;
14118 if (lh
->num_file_names
< file
|| file
== 0)
14119 dwarf2_debug_line_missing_file_complaint ();
14122 fe
= &lh
->file_names
[file
- 1];
14124 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14125 if (!decode_for_pst_p
)
14127 last_subfile
= current_subfile
;
14128 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14133 case DW_LNS_set_column
:
14134 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14135 line_ptr
+= bytes_read
;
14137 case DW_LNS_negate_stmt
:
14138 is_stmt
= (!is_stmt
);
14140 case DW_LNS_set_basic_block
:
14143 /* Add to the address register of the state machine the
14144 address increment value corresponding to special opcode
14145 255. I.e., this value is scaled by the minimum
14146 instruction length since special opcode 255 would have
14147 scaled the increment. */
14148 case DW_LNS_const_add_pc
:
14150 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
14152 address
+= (((op_index
+ adjust
)
14153 / lh
->maximum_ops_per_instruction
)
14154 * lh
->minimum_instruction_length
);
14155 op_index
= ((op_index
+ adjust
)
14156 % lh
->maximum_ops_per_instruction
);
14159 case DW_LNS_fixed_advance_pc
:
14160 address
+= read_2_bytes (abfd
, line_ptr
);
14166 /* Unknown standard opcode, ignore it. */
14169 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
14171 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14172 line_ptr
+= bytes_read
;
14177 if (lh
->num_file_names
< file
|| file
== 0)
14178 dwarf2_debug_line_missing_file_complaint ();
14181 lh
->file_names
[file
- 1].included_p
= 1;
14182 if (!decode_for_pst_p
)
14184 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14185 (*p_record_line
) (current_subfile
, 0, addr
);
14191 /* Decode the Line Number Program (LNP) for the given line_header
14192 structure and CU. The actual information extracted and the type
14193 of structures created from the LNP depends on the value of PST.
14195 1. If PST is NULL, then this procedure uses the data from the program
14196 to create all necessary symbol tables, and their linetables.
14198 2. If PST is not NULL, this procedure reads the program to determine
14199 the list of files included by the unit represented by PST, and
14200 builds all the associated partial symbol tables.
14202 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
14203 It is used for relative paths in the line table.
14204 NOTE: When processing partial symtabs (pst != NULL),
14205 comp_dir == pst->dirname.
14207 NOTE: It is important that psymtabs have the same file name (via strcmp)
14208 as the corresponding symtab. Since COMP_DIR is not used in the name of the
14209 symtab we don't use it in the name of the psymtabs we create.
14210 E.g. expand_line_sal requires this when finding psymtabs to expand.
14211 A good testcase for this is mb-inline.exp. */
14214 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
14215 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
14216 int want_line_info
)
14218 struct objfile
*objfile
= cu
->objfile
;
14219 const int decode_for_pst_p
= (pst
!= NULL
);
14220 struct subfile
*first_subfile
= current_subfile
;
14222 if (want_line_info
)
14223 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
14225 if (decode_for_pst_p
)
14229 /* Now that we're done scanning the Line Header Program, we can
14230 create the psymtab of each included file. */
14231 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
14232 if (lh
->file_names
[file_index
].included_p
== 1)
14234 char *include_name
=
14235 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
14236 if (include_name
!= NULL
)
14237 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
14242 /* Make sure a symtab is created for every file, even files
14243 which contain only variables (i.e. no code with associated
14247 for (i
= 0; i
< lh
->num_file_names
; i
++)
14250 struct file_entry
*fe
;
14252 fe
= &lh
->file_names
[i
];
14254 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14255 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14257 /* Skip the main file; we don't need it, and it must be
14258 allocated last, so that it will show up before the
14259 non-primary symtabs in the objfile's symtab list. */
14260 if (current_subfile
== first_subfile
)
14263 if (current_subfile
->symtab
== NULL
)
14264 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
14266 fe
->symtab
= current_subfile
->symtab
;
14271 /* Start a subfile for DWARF. FILENAME is the name of the file and
14272 DIRNAME the name of the source directory which contains FILENAME
14273 or NULL if not known. COMP_DIR is the compilation directory for the
14274 linetable's compilation unit or NULL if not known.
14275 This routine tries to keep line numbers from identical absolute and
14276 relative file names in a common subfile.
14278 Using the `list' example from the GDB testsuite, which resides in
14279 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
14280 of /srcdir/list0.c yields the following debugging information for list0.c:
14282 DW_AT_name: /srcdir/list0.c
14283 DW_AT_comp_dir: /compdir
14284 files.files[0].name: list0.h
14285 files.files[0].dir: /srcdir
14286 files.files[1].name: list0.c
14287 files.files[1].dir: /srcdir
14289 The line number information for list0.c has to end up in a single
14290 subfile, so that `break /srcdir/list0.c:1' works as expected.
14291 start_subfile will ensure that this happens provided that we pass the
14292 concatenation of files.files[1].dir and files.files[1].name as the
14296 dwarf2_start_subfile (char *filename
, const char *dirname
,
14297 const char *comp_dir
)
14301 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
14302 `start_symtab' will always pass the contents of DW_AT_comp_dir as
14303 second argument to start_subfile. To be consistent, we do the
14304 same here. In order not to lose the line information directory,
14305 we concatenate it to the filename when it makes sense.
14306 Note that the Dwarf3 standard says (speaking of filenames in line
14307 information): ``The directory index is ignored for file names
14308 that represent full path names''. Thus ignoring dirname in the
14309 `else' branch below isn't an issue. */
14311 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
14312 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
14314 fullname
= filename
;
14316 start_subfile (fullname
, comp_dir
);
14318 if (fullname
!= filename
)
14322 /* Start a symtab for DWARF.
14323 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
14326 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
14327 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
14329 start_symtab (name
, comp_dir
, low_pc
);
14330 record_debugformat ("DWARF 2");
14331 record_producer (cu
->producer
);
14333 /* We assume that we're processing GCC output. */
14334 processing_gcc_compilation
= 2;
14336 processing_has_namespace_info
= 0;
14340 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
14341 struct dwarf2_cu
*cu
)
14343 struct objfile
*objfile
= cu
->objfile
;
14344 struct comp_unit_head
*cu_header
= &cu
->header
;
14346 /* NOTE drow/2003-01-30: There used to be a comment and some special
14347 code here to turn a symbol with DW_AT_external and a
14348 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
14349 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
14350 with some versions of binutils) where shared libraries could have
14351 relocations against symbols in their debug information - the
14352 minimal symbol would have the right address, but the debug info
14353 would not. It's no longer necessary, because we will explicitly
14354 apply relocations when we read in the debug information now. */
14356 /* A DW_AT_location attribute with no contents indicates that a
14357 variable has been optimized away. */
14358 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
14360 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14364 /* Handle one degenerate form of location expression specially, to
14365 preserve GDB's previous behavior when section offsets are
14366 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
14367 then mark this symbol as LOC_STATIC. */
14369 if (attr_form_is_block (attr
)
14370 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
14371 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
14372 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
14373 && (DW_BLOCK (attr
)->size
14374 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
14376 unsigned int dummy
;
14378 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
14379 SYMBOL_VALUE_ADDRESS (sym
) =
14380 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
14382 SYMBOL_VALUE_ADDRESS (sym
) =
14383 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
14384 SYMBOL_CLASS (sym
) = LOC_STATIC
;
14385 fixup_symbol_section (sym
, objfile
);
14386 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
14387 SYMBOL_SECTION (sym
));
14391 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
14392 expression evaluator, and use LOC_COMPUTED only when necessary
14393 (i.e. when the value of a register or memory location is
14394 referenced, or a thread-local block, etc.). Then again, it might
14395 not be worthwhile. I'm assuming that it isn't unless performance
14396 or memory numbers show me otherwise. */
14398 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
14399 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14401 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
14402 cu
->has_loclist
= 1;
14405 /* Given a pointer to a DWARF information entry, figure out if we need
14406 to make a symbol table entry for it, and if so, create a new entry
14407 and return a pointer to it.
14408 If TYPE is NULL, determine symbol type from the die, otherwise
14409 used the passed type.
14410 If SPACE is not NULL, use it to hold the new symbol. If it is
14411 NULL, allocate a new symbol on the objfile's obstack. */
14413 static struct symbol
*
14414 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
14415 struct symbol
*space
)
14417 struct objfile
*objfile
= cu
->objfile
;
14418 struct symbol
*sym
= NULL
;
14420 struct attribute
*attr
= NULL
;
14421 struct attribute
*attr2
= NULL
;
14422 CORE_ADDR baseaddr
;
14423 struct pending
**list_to_add
= NULL
;
14425 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14427 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14429 name
= dwarf2_name (die
, cu
);
14432 const char *linkagename
;
14433 int suppress_add
= 0;
14438 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
14439 OBJSTAT (objfile
, n_syms
++);
14441 /* Cache this symbol's name and the name's demangled form (if any). */
14442 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
14443 linkagename
= dwarf2_physname (name
, die
, cu
);
14444 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
14446 /* Fortran does not have mangling standard and the mangling does differ
14447 between gfortran, iFort etc. */
14448 if (cu
->language
== language_fortran
14449 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
14450 symbol_set_demangled_name (&(sym
->ginfo
),
14451 (char *) dwarf2_full_name (name
, die
, cu
),
14454 /* Default assumptions.
14455 Use the passed type or decode it from the die. */
14456 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14457 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14459 SYMBOL_TYPE (sym
) = type
;
14461 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
14462 attr
= dwarf2_attr (die
,
14463 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
14467 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
14470 attr
= dwarf2_attr (die
,
14471 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
14475 int file_index
= DW_UNSND (attr
);
14477 if (cu
->line_header
== NULL
14478 || file_index
> cu
->line_header
->num_file_names
)
14479 complaint (&symfile_complaints
,
14480 _("file index out of range"));
14481 else if (file_index
> 0)
14483 struct file_entry
*fe
;
14485 fe
= &cu
->line_header
->file_names
[file_index
- 1];
14486 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
14493 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14496 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
14498 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
14499 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
14500 SYMBOL_CLASS (sym
) = LOC_LABEL
;
14501 add_symbol_to_list (sym
, cu
->list_in_scope
);
14503 case DW_TAG_subprogram
:
14504 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14506 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14507 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14508 if ((attr2
&& (DW_UNSND (attr2
) != 0))
14509 || cu
->language
== language_ada
)
14511 /* Subprograms marked external are stored as a global symbol.
14512 Ada subprograms, whether marked external or not, are always
14513 stored as a global symbol, because we want to be able to
14514 access them globally. For instance, we want to be able
14515 to break on a nested subprogram without having to
14516 specify the context. */
14517 list_to_add
= &global_symbols
;
14521 list_to_add
= cu
->list_in_scope
;
14524 case DW_TAG_inlined_subroutine
:
14525 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14527 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14528 SYMBOL_INLINED (sym
) = 1;
14529 list_to_add
= cu
->list_in_scope
;
14531 case DW_TAG_template_value_param
:
14533 /* Fall through. */
14534 case DW_TAG_constant
:
14535 case DW_TAG_variable
:
14536 case DW_TAG_member
:
14537 /* Compilation with minimal debug info may result in
14538 variables with missing type entries. Change the
14539 misleading `void' type to something sensible. */
14540 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
14542 = objfile_type (objfile
)->nodebug_data_symbol
;
14544 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14545 /* In the case of DW_TAG_member, we should only be called for
14546 static const members. */
14547 if (die
->tag
== DW_TAG_member
)
14549 /* dwarf2_add_field uses die_is_declaration,
14550 so we do the same. */
14551 gdb_assert (die_is_declaration (die
, cu
));
14556 dwarf2_const_value (attr
, sym
, cu
);
14557 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14560 if (attr2
&& (DW_UNSND (attr2
) != 0))
14561 list_to_add
= &global_symbols
;
14563 list_to_add
= cu
->list_in_scope
;
14567 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14570 var_decode_location (attr
, sym
, cu
);
14571 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14572 if (SYMBOL_CLASS (sym
) == LOC_STATIC
14573 && SYMBOL_VALUE_ADDRESS (sym
) == 0
14574 && !dwarf2_per_objfile
->has_section_at_zero
)
14576 /* When a static variable is eliminated by the linker,
14577 the corresponding debug information is not stripped
14578 out, but the variable address is set to null;
14579 do not add such variables into symbol table. */
14581 else if (attr2
&& (DW_UNSND (attr2
) != 0))
14583 /* Workaround gfortran PR debug/40040 - it uses
14584 DW_AT_location for variables in -fPIC libraries which may
14585 get overriden by other libraries/executable and get
14586 a different address. Resolve it by the minimal symbol
14587 which may come from inferior's executable using copy
14588 relocation. Make this workaround only for gfortran as for
14589 other compilers GDB cannot guess the minimal symbol
14590 Fortran mangling kind. */
14591 if (cu
->language
== language_fortran
&& die
->parent
14592 && die
->parent
->tag
== DW_TAG_module
14594 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
14595 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14597 /* A variable with DW_AT_external is never static,
14598 but it may be block-scoped. */
14599 list_to_add
= (cu
->list_in_scope
== &file_symbols
14600 ? &global_symbols
: cu
->list_in_scope
);
14603 list_to_add
= cu
->list_in_scope
;
14607 /* We do not know the address of this symbol.
14608 If it is an external symbol and we have type information
14609 for it, enter the symbol as a LOC_UNRESOLVED symbol.
14610 The address of the variable will then be determined from
14611 the minimal symbol table whenever the variable is
14613 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14614 if (attr2
&& (DW_UNSND (attr2
) != 0)
14615 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
14617 /* A variable with DW_AT_external is never static, but it
14618 may be block-scoped. */
14619 list_to_add
= (cu
->list_in_scope
== &file_symbols
14620 ? &global_symbols
: cu
->list_in_scope
);
14622 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14624 else if (!die_is_declaration (die
, cu
))
14626 /* Use the default LOC_OPTIMIZED_OUT class. */
14627 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
14629 list_to_add
= cu
->list_in_scope
;
14633 case DW_TAG_formal_parameter
:
14634 /* If we are inside a function, mark this as an argument. If
14635 not, we might be looking at an argument to an inlined function
14636 when we do not have enough information to show inlined frames;
14637 pretend it's a local variable in that case so that the user can
14639 if (context_stack_depth
> 0
14640 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
14641 SYMBOL_IS_ARGUMENT (sym
) = 1;
14642 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14645 var_decode_location (attr
, sym
, cu
);
14647 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14650 dwarf2_const_value (attr
, sym
, cu
);
14653 list_to_add
= cu
->list_in_scope
;
14655 case DW_TAG_unspecified_parameters
:
14656 /* From varargs functions; gdb doesn't seem to have any
14657 interest in this information, so just ignore it for now.
14660 case DW_TAG_template_type_param
:
14662 /* Fall through. */
14663 case DW_TAG_class_type
:
14664 case DW_TAG_interface_type
:
14665 case DW_TAG_structure_type
:
14666 case DW_TAG_union_type
:
14667 case DW_TAG_set_type
:
14668 case DW_TAG_enumeration_type
:
14669 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14670 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
14673 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
14674 really ever be static objects: otherwise, if you try
14675 to, say, break of a class's method and you're in a file
14676 which doesn't mention that class, it won't work unless
14677 the check for all static symbols in lookup_symbol_aux
14678 saves you. See the OtherFileClass tests in
14679 gdb.c++/namespace.exp. */
14683 list_to_add
= (cu
->list_in_scope
== &file_symbols
14684 && (cu
->language
== language_cplus
14685 || cu
->language
== language_java
)
14686 ? &global_symbols
: cu
->list_in_scope
);
14688 /* The semantics of C++ state that "struct foo {
14689 ... }" also defines a typedef for "foo". A Java
14690 class declaration also defines a typedef for the
14692 if (cu
->language
== language_cplus
14693 || cu
->language
== language_java
14694 || cu
->language
== language_ada
)
14696 /* The symbol's name is already allocated along
14697 with this objfile, so we don't need to
14698 duplicate it for the type. */
14699 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
14700 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
14705 case DW_TAG_typedef
:
14706 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14707 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14708 list_to_add
= cu
->list_in_scope
;
14710 case DW_TAG_base_type
:
14711 case DW_TAG_subrange_type
:
14712 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14713 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14714 list_to_add
= cu
->list_in_scope
;
14716 case DW_TAG_enumerator
:
14717 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14720 dwarf2_const_value (attr
, sym
, cu
);
14723 /* NOTE: carlton/2003-11-10: See comment above in the
14724 DW_TAG_class_type, etc. block. */
14726 list_to_add
= (cu
->list_in_scope
== &file_symbols
14727 && (cu
->language
== language_cplus
14728 || cu
->language
== language_java
)
14729 ? &global_symbols
: cu
->list_in_scope
);
14732 case DW_TAG_namespace
:
14733 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14734 list_to_add
= &global_symbols
;
14737 /* Not a tag we recognize. Hopefully we aren't processing
14738 trash data, but since we must specifically ignore things
14739 we don't recognize, there is nothing else we should do at
14741 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
14742 dwarf_tag_name (die
->tag
));
14748 sym
->hash_next
= objfile
->template_symbols
;
14749 objfile
->template_symbols
= sym
;
14750 list_to_add
= NULL
;
14753 if (list_to_add
!= NULL
)
14754 add_symbol_to_list (sym
, list_to_add
);
14756 /* For the benefit of old versions of GCC, check for anonymous
14757 namespaces based on the demangled name. */
14758 if (!processing_has_namespace_info
14759 && cu
->language
== language_cplus
)
14760 cp_scan_for_anonymous_namespaces (sym
, objfile
);
14765 /* A wrapper for new_symbol_full that always allocates a new symbol. */
14767 static struct symbol
*
14768 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14770 return new_symbol_full (die
, type
, cu
, NULL
);
14773 /* Given an attr with a DW_FORM_dataN value in host byte order,
14774 zero-extend it as appropriate for the symbol's type. The DWARF
14775 standard (v4) is not entirely clear about the meaning of using
14776 DW_FORM_dataN for a constant with a signed type, where the type is
14777 wider than the data. The conclusion of a discussion on the DWARF
14778 list was that this is unspecified. We choose to always zero-extend
14779 because that is the interpretation long in use by GCC. */
14782 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
14783 const char *name
, struct obstack
*obstack
,
14784 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
14786 struct objfile
*objfile
= cu
->objfile
;
14787 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
14788 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
14789 LONGEST l
= DW_UNSND (attr
);
14791 if (bits
< sizeof (*value
) * 8)
14793 l
&= ((LONGEST
) 1 << bits
) - 1;
14796 else if (bits
== sizeof (*value
) * 8)
14800 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
14801 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
14808 /* Read a constant value from an attribute. Either set *VALUE, or if
14809 the value does not fit in *VALUE, set *BYTES - either already
14810 allocated on the objfile obstack, or newly allocated on OBSTACK,
14811 or, set *BATON, if we translated the constant to a location
14815 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
14816 const char *name
, struct obstack
*obstack
,
14817 struct dwarf2_cu
*cu
,
14818 LONGEST
*value
, gdb_byte
**bytes
,
14819 struct dwarf2_locexpr_baton
**baton
)
14821 struct objfile
*objfile
= cu
->objfile
;
14822 struct comp_unit_head
*cu_header
= &cu
->header
;
14823 struct dwarf_block
*blk
;
14824 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
14825 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
14831 switch (attr
->form
)
14834 case DW_FORM_GNU_addr_index
:
14838 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
14839 dwarf2_const_value_length_mismatch_complaint (name
,
14840 cu_header
->addr_size
,
14841 TYPE_LENGTH (type
));
14842 /* Symbols of this form are reasonably rare, so we just
14843 piggyback on the existing location code rather than writing
14844 a new implementation of symbol_computed_ops. */
14845 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
14846 sizeof (struct dwarf2_locexpr_baton
));
14847 (*baton
)->per_cu
= cu
->per_cu
;
14848 gdb_assert ((*baton
)->per_cu
);
14850 (*baton
)->size
= 2 + cu_header
->addr_size
;
14851 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
14852 (*baton
)->data
= data
;
14854 data
[0] = DW_OP_addr
;
14855 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
14856 byte_order
, DW_ADDR (attr
));
14857 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
14860 case DW_FORM_string
:
14862 case DW_FORM_GNU_str_index
:
14863 /* DW_STRING is already allocated on the objfile obstack, point
14865 *bytes
= (gdb_byte
*) DW_STRING (attr
);
14867 case DW_FORM_block1
:
14868 case DW_FORM_block2
:
14869 case DW_FORM_block4
:
14870 case DW_FORM_block
:
14871 case DW_FORM_exprloc
:
14872 blk
= DW_BLOCK (attr
);
14873 if (TYPE_LENGTH (type
) != blk
->size
)
14874 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
14875 TYPE_LENGTH (type
));
14876 *bytes
= blk
->data
;
14879 /* The DW_AT_const_value attributes are supposed to carry the
14880 symbol's value "represented as it would be on the target
14881 architecture." By the time we get here, it's already been
14882 converted to host endianness, so we just need to sign- or
14883 zero-extend it as appropriate. */
14884 case DW_FORM_data1
:
14885 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14886 obstack
, cu
, value
, 8);
14888 case DW_FORM_data2
:
14889 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14890 obstack
, cu
, value
, 16);
14892 case DW_FORM_data4
:
14893 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14894 obstack
, cu
, value
, 32);
14896 case DW_FORM_data8
:
14897 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14898 obstack
, cu
, value
, 64);
14901 case DW_FORM_sdata
:
14902 *value
= DW_SND (attr
);
14905 case DW_FORM_udata
:
14906 *value
= DW_UNSND (attr
);
14910 complaint (&symfile_complaints
,
14911 _("unsupported const value attribute form: '%s'"),
14912 dwarf_form_name (attr
->form
));
14919 /* Copy constant value from an attribute to a symbol. */
14922 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
14923 struct dwarf2_cu
*cu
)
14925 struct objfile
*objfile
= cu
->objfile
;
14926 struct comp_unit_head
*cu_header
= &cu
->header
;
14929 struct dwarf2_locexpr_baton
*baton
;
14931 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
14932 SYMBOL_PRINT_NAME (sym
),
14933 &objfile
->objfile_obstack
, cu
,
14934 &value
, &bytes
, &baton
);
14938 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14939 SYMBOL_LOCATION_BATON (sym
) = baton
;
14940 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14942 else if (bytes
!= NULL
)
14944 SYMBOL_VALUE_BYTES (sym
) = bytes
;
14945 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
14949 SYMBOL_VALUE (sym
) = value
;
14950 SYMBOL_CLASS (sym
) = LOC_CONST
;
14954 /* Return the type of the die in question using its DW_AT_type attribute. */
14956 static struct type
*
14957 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14959 struct attribute
*type_attr
;
14961 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14964 /* A missing DW_AT_type represents a void type. */
14965 return objfile_type (cu
->objfile
)->builtin_void
;
14968 return lookup_die_type (die
, type_attr
, cu
);
14971 /* True iff CU's producer generates GNAT Ada auxiliary information
14972 that allows to find parallel types through that information instead
14973 of having to do expensive parallel lookups by type name. */
14976 need_gnat_info (struct dwarf2_cu
*cu
)
14978 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
14979 of GNAT produces this auxiliary information, without any indication
14980 that it is produced. Part of enhancing the FSF version of GNAT
14981 to produce that information will be to put in place an indicator
14982 that we can use in order to determine whether the descriptive type
14983 info is available or not. One suggestion that has been made is
14984 to use a new attribute, attached to the CU die. For now, assume
14985 that the descriptive type info is not available. */
14989 /* Return the auxiliary type of the die in question using its
14990 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
14991 attribute is not present. */
14993 static struct type
*
14994 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14996 struct attribute
*type_attr
;
14998 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
15002 return lookup_die_type (die
, type_attr
, cu
);
15005 /* If DIE has a descriptive_type attribute, then set the TYPE's
15006 descriptive type accordingly. */
15009 set_descriptive_type (struct type
*type
, struct die_info
*die
,
15010 struct dwarf2_cu
*cu
)
15012 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
15014 if (descriptive_type
)
15016 ALLOCATE_GNAT_AUX_TYPE (type
);
15017 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
15021 /* Return the containing type of the die in question using its
15022 DW_AT_containing_type attribute. */
15024 static struct type
*
15025 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15027 struct attribute
*type_attr
;
15029 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
15031 error (_("Dwarf Error: Problem turning containing type into gdb type "
15032 "[in module %s]"), cu
->objfile
->name
);
15034 return lookup_die_type (die
, type_attr
, cu
);
15037 /* Look up the type of DIE in CU using its type attribute ATTR.
15038 If there is no type substitute an error marker. */
15040 static struct type
*
15041 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
15042 struct dwarf2_cu
*cu
)
15044 struct objfile
*objfile
= cu
->objfile
;
15045 struct type
*this_type
;
15047 /* First see if we have it cached. */
15049 if (is_ref_attr (attr
))
15051 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15053 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
15055 else if (attr
->form
== DW_FORM_ref_sig8
)
15057 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15059 /* sig_type will be NULL if the signatured type is missing from
15061 if (sig_type
== NULL
)
15062 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15063 "at 0x%x [in module %s]"),
15064 die
->offset
.sect_off
, objfile
->name
);
15066 gdb_assert (sig_type
->per_cu
.is_debug_types
);
15067 /* If we haven't filled in type_offset_in_section yet, then we
15068 haven't read the type in yet. */
15070 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
15073 get_die_type_at_offset (sig_type
->type_offset_in_section
,
15074 &sig_type
->per_cu
);
15079 dump_die_for_error (die
);
15080 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
15081 dwarf_attr_name (attr
->name
), objfile
->name
);
15084 /* If not cached we need to read it in. */
15086 if (this_type
== NULL
)
15088 struct die_info
*type_die
;
15089 struct dwarf2_cu
*type_cu
= cu
;
15091 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
15092 /* If we found the type now, it's probably because the type came
15093 from an inter-CU reference and the type's CU got expanded before
15095 this_type
= get_die_type (type_die
, type_cu
);
15096 if (this_type
== NULL
)
15097 this_type
= read_type_die_1 (type_die
, type_cu
);
15100 /* If we still don't have a type use an error marker. */
15102 if (this_type
== NULL
)
15104 char *message
, *saved
;
15106 /* read_type_die already issued a complaint. */
15107 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
15109 cu
->header
.offset
.sect_off
,
15110 die
->offset
.sect_off
);
15111 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
15112 message
, strlen (message
));
15115 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
15121 /* Return the type in DIE, CU.
15122 Returns NULL for invalid types.
15124 This first does a lookup in the appropriate type_hash table,
15125 and only reads the die in if necessary.
15127 NOTE: This can be called when reading in partial or full symbols. */
15129 static struct type
*
15130 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
15132 struct type
*this_type
;
15134 this_type
= get_die_type (die
, cu
);
15138 return read_type_die_1 (die
, cu
);
15141 /* Read the type in DIE, CU.
15142 Returns NULL for invalid types. */
15144 static struct type
*
15145 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
15147 struct type
*this_type
= NULL
;
15151 case DW_TAG_class_type
:
15152 case DW_TAG_interface_type
:
15153 case DW_TAG_structure_type
:
15154 case DW_TAG_union_type
:
15155 this_type
= read_structure_type (die
, cu
);
15157 case DW_TAG_enumeration_type
:
15158 this_type
= read_enumeration_type (die
, cu
);
15160 case DW_TAG_subprogram
:
15161 case DW_TAG_subroutine_type
:
15162 case DW_TAG_inlined_subroutine
:
15163 this_type
= read_subroutine_type (die
, cu
);
15165 case DW_TAG_array_type
:
15166 this_type
= read_array_type (die
, cu
);
15168 case DW_TAG_set_type
:
15169 this_type
= read_set_type (die
, cu
);
15171 case DW_TAG_pointer_type
:
15172 this_type
= read_tag_pointer_type (die
, cu
);
15174 case DW_TAG_ptr_to_member_type
:
15175 this_type
= read_tag_ptr_to_member_type (die
, cu
);
15177 case DW_TAG_reference_type
:
15178 this_type
= read_tag_reference_type (die
, cu
);
15180 case DW_TAG_const_type
:
15181 this_type
= read_tag_const_type (die
, cu
);
15183 case DW_TAG_volatile_type
:
15184 this_type
= read_tag_volatile_type (die
, cu
);
15186 case DW_TAG_string_type
:
15187 this_type
= read_tag_string_type (die
, cu
);
15189 case DW_TAG_typedef
:
15190 this_type
= read_typedef (die
, cu
);
15192 case DW_TAG_subrange_type
:
15193 this_type
= read_subrange_type (die
, cu
);
15195 case DW_TAG_base_type
:
15196 this_type
= read_base_type (die
, cu
);
15198 case DW_TAG_unspecified_type
:
15199 this_type
= read_unspecified_type (die
, cu
);
15201 case DW_TAG_namespace
:
15202 this_type
= read_namespace_type (die
, cu
);
15204 case DW_TAG_module
:
15205 this_type
= read_module_type (die
, cu
);
15208 complaint (&symfile_complaints
,
15209 _("unexpected tag in read_type_die: '%s'"),
15210 dwarf_tag_name (die
->tag
));
15217 /* See if we can figure out if the class lives in a namespace. We do
15218 this by looking for a member function; its demangled name will
15219 contain namespace info, if there is any.
15220 Return the computed name or NULL.
15221 Space for the result is allocated on the objfile's obstack.
15222 This is the full-die version of guess_partial_die_structure_name.
15223 In this case we know DIE has no useful parent. */
15226 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15228 struct die_info
*spec_die
;
15229 struct dwarf2_cu
*spec_cu
;
15230 struct die_info
*child
;
15233 spec_die
= die_specification (die
, &spec_cu
);
15234 if (spec_die
!= NULL
)
15240 for (child
= die
->child
;
15242 child
= child
->sibling
)
15244 if (child
->tag
== DW_TAG_subprogram
)
15246 struct attribute
*attr
;
15248 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
15250 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
15254 = language_class_name_from_physname (cu
->language_defn
,
15258 if (actual_name
!= NULL
)
15260 char *die_name
= dwarf2_name (die
, cu
);
15262 if (die_name
!= NULL
15263 && strcmp (die_name
, actual_name
) != 0)
15265 /* Strip off the class name from the full name.
15266 We want the prefix. */
15267 int die_name_len
= strlen (die_name
);
15268 int actual_name_len
= strlen (actual_name
);
15270 /* Test for '::' as a sanity check. */
15271 if (actual_name_len
> die_name_len
+ 2
15272 && actual_name
[actual_name_len
15273 - die_name_len
- 1] == ':')
15275 obsavestring (actual_name
,
15276 actual_name_len
- die_name_len
- 2,
15277 &cu
->objfile
->objfile_obstack
);
15280 xfree (actual_name
);
15289 /* GCC might emit a nameless typedef that has a linkage name. Determine the
15290 prefix part in such case. See
15291 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15294 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15296 struct attribute
*attr
;
15299 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
15300 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
15303 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15304 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
15307 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15309 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15310 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15313 /* dwarf2_name had to be already called. */
15314 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
15316 /* Strip the base name, keep any leading namespaces/classes. */
15317 base
= strrchr (DW_STRING (attr
), ':');
15318 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
15321 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
15322 &cu
->objfile
->objfile_obstack
);
15325 /* Return the name of the namespace/class that DIE is defined within,
15326 or "" if we can't tell. The caller should not xfree the result.
15328 For example, if we're within the method foo() in the following
15338 then determine_prefix on foo's die will return "N::C". */
15340 static const char *
15341 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15343 struct die_info
*parent
, *spec_die
;
15344 struct dwarf2_cu
*spec_cu
;
15345 struct type
*parent_type
;
15348 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
15349 && cu
->language
!= language_fortran
)
15352 retval
= anonymous_struct_prefix (die
, cu
);
15356 /* We have to be careful in the presence of DW_AT_specification.
15357 For example, with GCC 3.4, given the code
15361 // Definition of N::foo.
15365 then we'll have a tree of DIEs like this:
15367 1: DW_TAG_compile_unit
15368 2: DW_TAG_namespace // N
15369 3: DW_TAG_subprogram // declaration of N::foo
15370 4: DW_TAG_subprogram // definition of N::foo
15371 DW_AT_specification // refers to die #3
15373 Thus, when processing die #4, we have to pretend that we're in
15374 the context of its DW_AT_specification, namely the contex of die
15377 spec_die
= die_specification (die
, &spec_cu
);
15378 if (spec_die
== NULL
)
15379 parent
= die
->parent
;
15382 parent
= spec_die
->parent
;
15386 if (parent
== NULL
)
15388 else if (parent
->building_fullname
)
15391 const char *parent_name
;
15393 /* It has been seen on RealView 2.2 built binaries,
15394 DW_TAG_template_type_param types actually _defined_ as
15395 children of the parent class:
15398 template class <class Enum> Class{};
15399 Class<enum E> class_e;
15401 1: DW_TAG_class_type (Class)
15402 2: DW_TAG_enumeration_type (E)
15403 3: DW_TAG_enumerator (enum1:0)
15404 3: DW_TAG_enumerator (enum2:1)
15406 2: DW_TAG_template_type_param
15407 DW_AT_type DW_FORM_ref_udata (E)
15409 Besides being broken debug info, it can put GDB into an
15410 infinite loop. Consider:
15412 When we're building the full name for Class<E>, we'll start
15413 at Class, and go look over its template type parameters,
15414 finding E. We'll then try to build the full name of E, and
15415 reach here. We're now trying to build the full name of E,
15416 and look over the parent DIE for containing scope. In the
15417 broken case, if we followed the parent DIE of E, we'd again
15418 find Class, and once again go look at its template type
15419 arguments, etc., etc. Simply don't consider such parent die
15420 as source-level parent of this die (it can't be, the language
15421 doesn't allow it), and break the loop here. */
15422 name
= dwarf2_name (die
, cu
);
15423 parent_name
= dwarf2_name (parent
, cu
);
15424 complaint (&symfile_complaints
,
15425 _("template param type '%s' defined within parent '%s'"),
15426 name
? name
: "<unknown>",
15427 parent_name
? parent_name
: "<unknown>");
15431 switch (parent
->tag
)
15433 case DW_TAG_namespace
:
15434 parent_type
= read_type_die (parent
, cu
);
15435 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
15436 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
15437 Work around this problem here. */
15438 if (cu
->language
== language_cplus
15439 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
15441 /* We give a name to even anonymous namespaces. */
15442 return TYPE_TAG_NAME (parent_type
);
15443 case DW_TAG_class_type
:
15444 case DW_TAG_interface_type
:
15445 case DW_TAG_structure_type
:
15446 case DW_TAG_union_type
:
15447 case DW_TAG_module
:
15448 parent_type
= read_type_die (parent
, cu
);
15449 if (TYPE_TAG_NAME (parent_type
) != NULL
)
15450 return TYPE_TAG_NAME (parent_type
);
15452 /* An anonymous structure is only allowed non-static data
15453 members; no typedefs, no member functions, et cetera.
15454 So it does not need a prefix. */
15456 case DW_TAG_compile_unit
:
15457 case DW_TAG_partial_unit
:
15458 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
15459 if (cu
->language
== language_cplus
15460 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
15461 && die
->child
!= NULL
15462 && (die
->tag
== DW_TAG_class_type
15463 || die
->tag
== DW_TAG_structure_type
15464 || die
->tag
== DW_TAG_union_type
))
15466 char *name
= guess_full_die_structure_name (die
, cu
);
15472 return determine_prefix (parent
, cu
);
15476 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
15477 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
15478 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
15479 an obconcat, otherwise allocate storage for the result. The CU argument is
15480 used to determine the language and hence, the appropriate separator. */
15482 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
15485 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
15486 int physname
, struct dwarf2_cu
*cu
)
15488 const char *lead
= "";
15491 if (suffix
== NULL
|| suffix
[0] == '\0'
15492 || prefix
== NULL
|| prefix
[0] == '\0')
15494 else if (cu
->language
== language_java
)
15496 else if (cu
->language
== language_fortran
&& physname
)
15498 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
15499 DW_AT_MIPS_linkage_name is preferred and used instead. */
15507 if (prefix
== NULL
)
15509 if (suffix
== NULL
)
15515 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
15517 strcpy (retval
, lead
);
15518 strcat (retval
, prefix
);
15519 strcat (retval
, sep
);
15520 strcat (retval
, suffix
);
15525 /* We have an obstack. */
15526 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
15530 /* Return sibling of die, NULL if no sibling. */
15532 static struct die_info
*
15533 sibling_die (struct die_info
*die
)
15535 return die
->sibling
;
15538 /* Get name of a die, return NULL if not found. */
15541 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
15542 struct obstack
*obstack
)
15544 if (name
&& cu
->language
== language_cplus
)
15546 char *canon_name
= cp_canonicalize_string (name
);
15548 if (canon_name
!= NULL
)
15550 if (strcmp (canon_name
, name
) != 0)
15551 name
= obsavestring (canon_name
, strlen (canon_name
),
15553 xfree (canon_name
);
15560 /* Get name of a die, return NULL if not found. */
15563 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15565 struct attribute
*attr
;
15567 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15568 if ((!attr
|| !DW_STRING (attr
))
15569 && die
->tag
!= DW_TAG_class_type
15570 && die
->tag
!= DW_TAG_interface_type
15571 && die
->tag
!= DW_TAG_structure_type
15572 && die
->tag
!= DW_TAG_union_type
)
15577 case DW_TAG_compile_unit
:
15578 case DW_TAG_partial_unit
:
15579 /* Compilation units have a DW_AT_name that is a filename, not
15580 a source language identifier. */
15581 case DW_TAG_enumeration_type
:
15582 case DW_TAG_enumerator
:
15583 /* These tags always have simple identifiers already; no need
15584 to canonicalize them. */
15585 return DW_STRING (attr
);
15587 case DW_TAG_subprogram
:
15588 /* Java constructors will all be named "<init>", so return
15589 the class name when we see this special case. */
15590 if (cu
->language
== language_java
15591 && DW_STRING (attr
) != NULL
15592 && strcmp (DW_STRING (attr
), "<init>") == 0)
15594 struct dwarf2_cu
*spec_cu
= cu
;
15595 struct die_info
*spec_die
;
15597 /* GCJ will output '<init>' for Java constructor names.
15598 For this special case, return the name of the parent class. */
15600 /* GCJ may output suprogram DIEs with AT_specification set.
15601 If so, use the name of the specified DIE. */
15602 spec_die
= die_specification (die
, &spec_cu
);
15603 if (spec_die
!= NULL
)
15604 return dwarf2_name (spec_die
, spec_cu
);
15609 if (die
->tag
== DW_TAG_class_type
)
15610 return dwarf2_name (die
, cu
);
15612 while (die
->tag
!= DW_TAG_compile_unit
15613 && die
->tag
!= DW_TAG_partial_unit
);
15617 case DW_TAG_class_type
:
15618 case DW_TAG_interface_type
:
15619 case DW_TAG_structure_type
:
15620 case DW_TAG_union_type
:
15621 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
15622 structures or unions. These were of the form "._%d" in GCC 4.1,
15623 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
15624 and GCC 4.4. We work around this problem by ignoring these. */
15625 if (attr
&& DW_STRING (attr
)
15626 && (strncmp (DW_STRING (attr
), "._", 2) == 0
15627 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
15630 /* GCC might emit a nameless typedef that has a linkage name. See
15631 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15632 if (!attr
|| DW_STRING (attr
) == NULL
)
15634 char *demangled
= NULL
;
15636 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15638 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15640 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15643 /* Avoid demangling DW_STRING (attr) the second time on a second
15644 call for the same DIE. */
15645 if (!DW_STRING_IS_CANONICAL (attr
))
15646 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
15652 /* FIXME: we already did this for the partial symbol... */
15653 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
15654 &cu
->objfile
->objfile_obstack
);
15655 DW_STRING_IS_CANONICAL (attr
) = 1;
15658 /* Strip any leading namespaces/classes, keep only the base name.
15659 DW_AT_name for named DIEs does not contain the prefixes. */
15660 base
= strrchr (DW_STRING (attr
), ':');
15661 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
15664 return DW_STRING (attr
);
15673 if (!DW_STRING_IS_CANONICAL (attr
))
15676 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
15677 &cu
->objfile
->objfile_obstack
);
15678 DW_STRING_IS_CANONICAL (attr
) = 1;
15680 return DW_STRING (attr
);
15683 /* Return the die that this die in an extension of, or NULL if there
15684 is none. *EXT_CU is the CU containing DIE on input, and the CU
15685 containing the return value on output. */
15687 static struct die_info
*
15688 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
15690 struct attribute
*attr
;
15692 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
15696 return follow_die_ref (die
, attr
, ext_cu
);
15699 /* Convert a DIE tag into its string name. */
15701 static const char *
15702 dwarf_tag_name (unsigned tag
)
15704 const char *name
= get_DW_TAG_name (tag
);
15707 return "DW_TAG_<unknown>";
15712 /* Convert a DWARF attribute code into its string name. */
15714 static const char *
15715 dwarf_attr_name (unsigned attr
)
15719 #ifdef MIPS /* collides with DW_AT_HP_block_index */
15720 if (attr
== DW_AT_MIPS_fde
)
15721 return "DW_AT_MIPS_fde";
15723 if (attr
== DW_AT_HP_block_index
)
15724 return "DW_AT_HP_block_index";
15727 name
= get_DW_AT_name (attr
);
15730 return "DW_AT_<unknown>";
15735 /* Convert a DWARF value form code into its string name. */
15737 static const char *
15738 dwarf_form_name (unsigned form
)
15740 const char *name
= get_DW_FORM_name (form
);
15743 return "DW_FORM_<unknown>";
15749 dwarf_bool_name (unsigned mybool
)
15757 /* Convert a DWARF type code into its string name. */
15759 static const char *
15760 dwarf_type_encoding_name (unsigned enc
)
15762 const char *name
= get_DW_ATE_name (enc
);
15765 return "DW_ATE_<unknown>";
15771 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
15775 print_spaces (indent
, f
);
15776 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
15777 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
15779 if (die
->parent
!= NULL
)
15781 print_spaces (indent
, f
);
15782 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
15783 die
->parent
->offset
.sect_off
);
15786 print_spaces (indent
, f
);
15787 fprintf_unfiltered (f
, " has children: %s\n",
15788 dwarf_bool_name (die
->child
!= NULL
));
15790 print_spaces (indent
, f
);
15791 fprintf_unfiltered (f
, " attributes:\n");
15793 for (i
= 0; i
< die
->num_attrs
; ++i
)
15795 print_spaces (indent
, f
);
15796 fprintf_unfiltered (f
, " %s (%s) ",
15797 dwarf_attr_name (die
->attrs
[i
].name
),
15798 dwarf_form_name (die
->attrs
[i
].form
));
15800 switch (die
->attrs
[i
].form
)
15803 case DW_FORM_GNU_addr_index
:
15804 fprintf_unfiltered (f
, "address: ");
15805 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
15807 case DW_FORM_block2
:
15808 case DW_FORM_block4
:
15809 case DW_FORM_block
:
15810 case DW_FORM_block1
:
15811 fprintf_unfiltered (f
, "block: size %d",
15812 DW_BLOCK (&die
->attrs
[i
])->size
);
15814 case DW_FORM_exprloc
:
15815 fprintf_unfiltered (f
, "expression: size %u",
15816 DW_BLOCK (&die
->attrs
[i
])->size
);
15818 case DW_FORM_ref_addr
:
15819 fprintf_unfiltered (f
, "ref address: ");
15820 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
15826 case DW_FORM_ref_udata
:
15827 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
15828 (long) (DW_UNSND (&die
->attrs
[i
])));
15830 case DW_FORM_data1
:
15831 case DW_FORM_data2
:
15832 case DW_FORM_data4
:
15833 case DW_FORM_data8
:
15834 case DW_FORM_udata
:
15835 case DW_FORM_sdata
:
15836 fprintf_unfiltered (f
, "constant: %s",
15837 pulongest (DW_UNSND (&die
->attrs
[i
])));
15839 case DW_FORM_sec_offset
:
15840 fprintf_unfiltered (f
, "section offset: %s",
15841 pulongest (DW_UNSND (&die
->attrs
[i
])));
15843 case DW_FORM_ref_sig8
:
15844 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15845 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15846 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15848 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15850 case DW_FORM_string
:
15852 case DW_FORM_GNU_str_index
:
15853 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15854 DW_STRING (&die
->attrs
[i
])
15855 ? DW_STRING (&die
->attrs
[i
]) : "",
15856 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15859 if (DW_UNSND (&die
->attrs
[i
]))
15860 fprintf_unfiltered (f
, "flag: TRUE");
15862 fprintf_unfiltered (f
, "flag: FALSE");
15864 case DW_FORM_flag_present
:
15865 fprintf_unfiltered (f
, "flag: TRUE");
15867 case DW_FORM_indirect
:
15868 /* The reader will have reduced the indirect form to
15869 the "base form" so this form should not occur. */
15870 fprintf_unfiltered (f
,
15871 "unexpected attribute form: DW_FORM_indirect");
15874 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
15875 die
->attrs
[i
].form
);
15878 fprintf_unfiltered (f
, "\n");
15883 dump_die_for_error (struct die_info
*die
)
15885 dump_die_shallow (gdb_stderr
, 0, die
);
15889 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
15891 int indent
= level
* 4;
15893 gdb_assert (die
!= NULL
);
15895 if (level
>= max_level
)
15898 dump_die_shallow (f
, indent
, die
);
15900 if (die
->child
!= NULL
)
15902 print_spaces (indent
, f
);
15903 fprintf_unfiltered (f
, " Children:");
15904 if (level
+ 1 < max_level
)
15906 fprintf_unfiltered (f
, "\n");
15907 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
15911 fprintf_unfiltered (f
,
15912 " [not printed, max nesting level reached]\n");
15916 if (die
->sibling
!= NULL
&& level
> 0)
15918 dump_die_1 (f
, level
, max_level
, die
->sibling
);
15922 /* This is called from the pdie macro in gdbinit.in.
15923 It's not static so gcc will keep a copy callable from gdb. */
15926 dump_die (struct die_info
*die
, int max_level
)
15928 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
15932 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
15936 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
15942 /* DW_ADDR is always stored already as sect_offset; despite for the forms
15943 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
15946 is_ref_attr (struct attribute
*attr
)
15948 switch (attr
->form
)
15950 case DW_FORM_ref_addr
:
15955 case DW_FORM_ref_udata
:
15962 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
15966 dwarf2_get_ref_die_offset (struct attribute
*attr
)
15968 sect_offset retval
= { DW_UNSND (attr
) };
15970 if (is_ref_attr (attr
))
15973 retval
.sect_off
= 0;
15974 complaint (&symfile_complaints
,
15975 _("unsupported die ref attribute form: '%s'"),
15976 dwarf_form_name (attr
->form
));
15980 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
15981 * the value held by the attribute is not constant. */
15984 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
15986 if (attr
->form
== DW_FORM_sdata
)
15987 return DW_SND (attr
);
15988 else if (attr
->form
== DW_FORM_udata
15989 || attr
->form
== DW_FORM_data1
15990 || attr
->form
== DW_FORM_data2
15991 || attr
->form
== DW_FORM_data4
15992 || attr
->form
== DW_FORM_data8
)
15993 return DW_UNSND (attr
);
15996 complaint (&symfile_complaints
,
15997 _("Attribute value is not a constant (%s)"),
15998 dwarf_form_name (attr
->form
));
15999 return default_value
;
16003 /* Follow reference or signature attribute ATTR of SRC_DIE.
16004 On entry *REF_CU is the CU of SRC_DIE.
16005 On exit *REF_CU is the CU of the result. */
16007 static struct die_info
*
16008 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
16009 struct dwarf2_cu
**ref_cu
)
16011 struct die_info
*die
;
16013 if (is_ref_attr (attr
))
16014 die
= follow_die_ref (src_die
, attr
, ref_cu
);
16015 else if (attr
->form
== DW_FORM_ref_sig8
)
16016 die
= follow_die_sig (src_die
, attr
, ref_cu
);
16019 dump_die_for_error (src_die
);
16020 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
16021 (*ref_cu
)->objfile
->name
);
16027 /* Follow reference OFFSET.
16028 On entry *REF_CU is the CU of the source die referencing OFFSET.
16029 On exit *REF_CU is the CU of the result.
16030 Returns NULL if OFFSET is invalid. */
16032 static struct die_info
*
16033 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
16035 struct die_info temp_die
;
16036 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
16038 gdb_assert (cu
->per_cu
!= NULL
);
16042 if (cu
->per_cu
->is_debug_types
)
16044 /* .debug_types CUs cannot reference anything outside their CU.
16045 If they need to, they have to reference a signatured type via
16046 DW_FORM_ref_sig8. */
16047 if (! offset_in_cu_p (&cu
->header
, offset
))
16050 else if (! offset_in_cu_p (&cu
->header
, offset
))
16052 struct dwarf2_per_cu_data
*per_cu
;
16054 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
16056 /* If necessary, add it to the queue and load its DIEs. */
16057 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
16058 load_full_comp_unit (per_cu
, cu
->language
);
16060 target_cu
= per_cu
->cu
;
16062 else if (cu
->dies
== NULL
)
16064 /* We're loading full DIEs during partial symbol reading. */
16065 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
16066 load_full_comp_unit (cu
->per_cu
, language_minimal
);
16069 *ref_cu
= target_cu
;
16070 temp_die
.offset
= offset
;
16071 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
16074 /* Follow reference attribute ATTR of SRC_DIE.
16075 On entry *REF_CU is the CU of SRC_DIE.
16076 On exit *REF_CU is the CU of the result. */
16078 static struct die_info
*
16079 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
16080 struct dwarf2_cu
**ref_cu
)
16082 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16083 struct dwarf2_cu
*cu
= *ref_cu
;
16084 struct die_info
*die
;
16086 die
= follow_die_offset (offset
, ref_cu
);
16088 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
16089 "at 0x%x [in module %s]"),
16090 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
16095 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
16096 Returned value is intended for DW_OP_call*. Returned
16097 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
16099 struct dwarf2_locexpr_baton
16100 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
16101 struct dwarf2_per_cu_data
*per_cu
,
16102 CORE_ADDR (*get_frame_pc
) (void *baton
),
16105 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
16106 struct dwarf2_cu
*cu
;
16107 struct die_info
*die
;
16108 struct attribute
*attr
;
16109 struct dwarf2_locexpr_baton retval
;
16111 dw2_setup (per_cu
->objfile
);
16113 if (per_cu
->cu
== NULL
)
16117 die
= follow_die_offset (offset
, &cu
);
16119 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
16120 offset
.sect_off
, per_cu
->objfile
->name
);
16122 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16125 /* DWARF: "If there is no such attribute, then there is no effect.".
16126 DATA is ignored if SIZE is 0. */
16128 retval
.data
= NULL
;
16131 else if (attr_form_is_section_offset (attr
))
16133 struct dwarf2_loclist_baton loclist_baton
;
16134 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
16137 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
16139 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
16141 retval
.size
= size
;
16145 if (!attr_form_is_block (attr
))
16146 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
16147 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
16148 offset
.sect_off
, per_cu
->objfile
->name
);
16150 retval
.data
= DW_BLOCK (attr
)->data
;
16151 retval
.size
= DW_BLOCK (attr
)->size
;
16153 retval
.per_cu
= cu
->per_cu
;
16155 age_cached_comp_units ();
16160 /* Return the type of the DIE at DIE_OFFSET in the CU named by
16164 dwarf2_get_die_type (cu_offset die_offset
,
16165 struct dwarf2_per_cu_data
*per_cu
)
16167 sect_offset die_offset_sect
;
16169 dw2_setup (per_cu
->objfile
);
16171 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
16172 return get_die_type_at_offset (die_offset_sect
, per_cu
);
16175 /* Follow the signature attribute ATTR in SRC_DIE.
16176 On entry *REF_CU is the CU of SRC_DIE.
16177 On exit *REF_CU is the CU of the result. */
16179 static struct die_info
*
16180 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
16181 struct dwarf2_cu
**ref_cu
)
16183 struct objfile
*objfile
= (*ref_cu
)->objfile
;
16184 struct die_info temp_die
;
16185 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16186 struct dwarf2_cu
*sig_cu
;
16187 struct die_info
*die
;
16189 /* sig_type will be NULL if the signatured type is missing from
16191 if (sig_type
== NULL
)
16192 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16193 "at 0x%x [in module %s]"),
16194 src_die
->offset
.sect_off
, objfile
->name
);
16196 /* If necessary, add it to the queue and load its DIEs. */
16198 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
16199 read_signatured_type (sig_type
);
16201 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
16203 sig_cu
= sig_type
->per_cu
.cu
;
16204 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
16205 temp_die
.offset
= sig_type
->type_offset_in_section
;
16206 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
16207 temp_die
.offset
.sect_off
);
16214 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
16215 "from DIE at 0x%x [in module %s]"),
16216 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
16219 /* Given an offset of a signatured type, return its signatured_type. */
16221 static struct signatured_type
*
16222 lookup_signatured_type_at_offset (struct objfile
*objfile
,
16223 struct dwarf2_section_info
*section
,
16224 sect_offset offset
)
16226 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
16227 unsigned int length
, initial_length_size
;
16228 unsigned int sig_offset
;
16229 struct signatured_type find_entry
, *sig_type
;
16231 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
16232 sig_offset
= (initial_length_size
16234 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
16235 + 1 /*address_size*/);
16236 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
16237 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
16239 /* This is only used to lookup previously recorded types.
16240 If we didn't find it, it's our bug. */
16241 gdb_assert (sig_type
!= NULL
);
16242 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
16247 /* Load the DIEs associated with type unit PER_CU into memory. */
16250 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
16252 struct signatured_type
*sig_type
;
16254 /* Caller is responsible for ensuring type_unit_groups don't get here. */
16255 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
16257 /* We have the per_cu, but we need the signatured_type.
16258 Fortunately this is an easy translation. */
16259 gdb_assert (per_cu
->is_debug_types
);
16260 sig_type
= (struct signatured_type
*) per_cu
;
16262 gdb_assert (per_cu
->cu
== NULL
);
16264 read_signatured_type (sig_type
);
16266 gdb_assert (per_cu
->cu
!= NULL
);
16269 /* die_reader_func for read_signatured_type.
16270 This is identical to load_full_comp_unit_reader,
16271 but is kept separate for now. */
16274 read_signatured_type_reader (const struct die_reader_specs
*reader
,
16275 gdb_byte
*info_ptr
,
16276 struct die_info
*comp_unit_die
,
16280 struct dwarf2_cu
*cu
= reader
->cu
;
16282 gdb_assert (cu
->die_hash
== NULL
);
16284 htab_create_alloc_ex (cu
->header
.length
/ 12,
16288 &cu
->comp_unit_obstack
,
16289 hashtab_obstack_allocate
,
16290 dummy_obstack_deallocate
);
16293 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
16294 &info_ptr
, comp_unit_die
);
16295 cu
->dies
= comp_unit_die
;
16296 /* comp_unit_die is not stored in die_hash, no need. */
16298 /* We try not to read any attributes in this function, because not
16299 all CUs needed for references have been loaded yet, and symbol
16300 table processing isn't initialized. But we have to set the CU language,
16301 or we won't be able to build types correctly.
16302 Similarly, if we do not read the producer, we can not apply
16303 producer-specific interpretation. */
16304 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
16307 /* Read in a signatured type and build its CU and DIEs.
16308 If the type is a stub for the real type in a DWO file,
16309 read in the real type from the DWO file as well. */
16312 read_signatured_type (struct signatured_type
*sig_type
)
16314 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
16316 gdb_assert (per_cu
->is_debug_types
);
16317 gdb_assert (per_cu
->cu
== NULL
);
16319 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
16320 read_signatured_type_reader
, NULL
);
16323 /* Decode simple location descriptions.
16324 Given a pointer to a dwarf block that defines a location, compute
16325 the location and return the value.
16327 NOTE drow/2003-11-18: This function is called in two situations
16328 now: for the address of static or global variables (partial symbols
16329 only) and for offsets into structures which are expected to be
16330 (more or less) constant. The partial symbol case should go away,
16331 and only the constant case should remain. That will let this
16332 function complain more accurately. A few special modes are allowed
16333 without complaint for global variables (for instance, global
16334 register values and thread-local values).
16336 A location description containing no operations indicates that the
16337 object is optimized out. The return value is 0 for that case.
16338 FIXME drow/2003-11-16: No callers check for this case any more; soon all
16339 callers will only want a very basic result and this can become a
16342 Note that stack[0] is unused except as a default error return. */
16345 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
16347 struct objfile
*objfile
= cu
->objfile
;
16349 int size
= blk
->size
;
16350 gdb_byte
*data
= blk
->data
;
16351 CORE_ADDR stack
[64];
16353 unsigned int bytes_read
, unsnd
;
16359 stack
[++stacki
] = 0;
16398 stack
[++stacki
] = op
- DW_OP_lit0
;
16433 stack
[++stacki
] = op
- DW_OP_reg0
;
16435 dwarf2_complex_location_expr_complaint ();
16439 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
16441 stack
[++stacki
] = unsnd
;
16443 dwarf2_complex_location_expr_complaint ();
16447 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
16452 case DW_OP_const1u
:
16453 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
16457 case DW_OP_const1s
:
16458 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
16462 case DW_OP_const2u
:
16463 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
16467 case DW_OP_const2s
:
16468 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
16472 case DW_OP_const4u
:
16473 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
16477 case DW_OP_const4s
:
16478 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
16482 case DW_OP_const8u
:
16483 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
16488 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
16494 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
16499 stack
[stacki
+ 1] = stack
[stacki
];
16504 stack
[stacki
- 1] += stack
[stacki
];
16508 case DW_OP_plus_uconst
:
16509 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
16515 stack
[stacki
- 1] -= stack
[stacki
];
16520 /* If we're not the last op, then we definitely can't encode
16521 this using GDB's address_class enum. This is valid for partial
16522 global symbols, although the variable's address will be bogus
16525 dwarf2_complex_location_expr_complaint ();
16528 case DW_OP_GNU_push_tls_address
:
16529 /* The top of the stack has the offset from the beginning
16530 of the thread control block at which the variable is located. */
16531 /* Nothing should follow this operator, so the top of stack would
16533 /* This is valid for partial global symbols, but the variable's
16534 address will be bogus in the psymtab. Make it always at least
16535 non-zero to not look as a variable garbage collected by linker
16536 which have DW_OP_addr 0. */
16538 dwarf2_complex_location_expr_complaint ();
16542 case DW_OP_GNU_uninit
:
16545 case DW_OP_GNU_addr_index
:
16546 case DW_OP_GNU_const_index
:
16547 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
16554 const char *name
= get_DW_OP_name (op
);
16557 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
16560 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
16564 return (stack
[stacki
]);
16567 /* Enforce maximum stack depth of SIZE-1 to avoid writing
16568 outside of the allocated space. Also enforce minimum>0. */
16569 if (stacki
>= ARRAY_SIZE (stack
) - 1)
16571 complaint (&symfile_complaints
,
16572 _("location description stack overflow"));
16578 complaint (&symfile_complaints
,
16579 _("location description stack underflow"));
16583 return (stack
[stacki
]);
16586 /* memory allocation interface */
16588 static struct dwarf_block
*
16589 dwarf_alloc_block (struct dwarf2_cu
*cu
)
16591 struct dwarf_block
*blk
;
16593 blk
= (struct dwarf_block
*)
16594 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
16598 static struct die_info
*
16599 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
16601 struct die_info
*die
;
16602 size_t size
= sizeof (struct die_info
);
16605 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
16607 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
16608 memset (die
, 0, sizeof (struct die_info
));
16613 /* Macro support. */
16615 /* Return the full name of file number I in *LH's file name table.
16616 Use COMP_DIR as the name of the current directory of the
16617 compilation. The result is allocated using xmalloc; the caller is
16618 responsible for freeing it. */
16620 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
16622 /* Is the file number a valid index into the line header's file name
16623 table? Remember that file numbers start with one, not zero. */
16624 if (1 <= file
&& file
<= lh
->num_file_names
)
16626 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
16628 if (IS_ABSOLUTE_PATH (fe
->name
))
16629 return xstrdup (fe
->name
);
16637 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16643 dir_len
= strlen (dir
);
16644 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
16645 strcpy (full_name
, dir
);
16646 full_name
[dir_len
] = '/';
16647 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
16651 return xstrdup (fe
->name
);
16656 /* The compiler produced a bogus file number. We can at least
16657 record the macro definitions made in the file, even if we
16658 won't be able to find the file by name. */
16659 char fake_name
[80];
16661 sprintf (fake_name
, "<bad macro file number %d>", file
);
16663 complaint (&symfile_complaints
,
16664 _("bad file number in macro information (%d)"),
16667 return xstrdup (fake_name
);
16672 static struct macro_source_file
*
16673 macro_start_file (int file
, int line
,
16674 struct macro_source_file
*current_file
,
16675 const char *comp_dir
,
16676 struct line_header
*lh
, struct objfile
*objfile
)
16678 /* The full name of this source file. */
16679 char *full_name
= file_full_name (file
, lh
, comp_dir
);
16681 /* We don't create a macro table for this compilation unit
16682 at all until we actually get a filename. */
16683 if (! pending_macros
)
16684 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
16685 objfile
->macro_cache
);
16687 if (! current_file
)
16689 /* If we have no current file, then this must be the start_file
16690 directive for the compilation unit's main source file. */
16691 current_file
= macro_set_main (pending_macros
, full_name
);
16692 macro_define_special (pending_macros
);
16695 current_file
= macro_include (current_file
, line
, full_name
);
16699 return current_file
;
16703 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
16704 followed by a null byte. */
16706 copy_string (const char *buf
, int len
)
16708 char *s
= xmalloc (len
+ 1);
16710 memcpy (s
, buf
, len
);
16716 static const char *
16717 consume_improper_spaces (const char *p
, const char *body
)
16721 complaint (&symfile_complaints
,
16722 _("macro definition contains spaces "
16723 "in formal argument list:\n`%s'"),
16735 parse_macro_definition (struct macro_source_file
*file
, int line
,
16740 /* The body string takes one of two forms. For object-like macro
16741 definitions, it should be:
16743 <macro name> " " <definition>
16745 For function-like macro definitions, it should be:
16747 <macro name> "() " <definition>
16749 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
16751 Spaces may appear only where explicitly indicated, and in the
16754 The Dwarf 2 spec says that an object-like macro's name is always
16755 followed by a space, but versions of GCC around March 2002 omit
16756 the space when the macro's definition is the empty string.
16758 The Dwarf 2 spec says that there should be no spaces between the
16759 formal arguments in a function-like macro's formal argument list,
16760 but versions of GCC around March 2002 include spaces after the
16764 /* Find the extent of the macro name. The macro name is terminated
16765 by either a space or null character (for an object-like macro) or
16766 an opening paren (for a function-like macro). */
16767 for (p
= body
; *p
; p
++)
16768 if (*p
== ' ' || *p
== '(')
16771 if (*p
== ' ' || *p
== '\0')
16773 /* It's an object-like macro. */
16774 int name_len
= p
- body
;
16775 char *name
= copy_string (body
, name_len
);
16776 const char *replacement
;
16779 replacement
= body
+ name_len
+ 1;
16782 dwarf2_macro_malformed_definition_complaint (body
);
16783 replacement
= body
+ name_len
;
16786 macro_define_object (file
, line
, name
, replacement
);
16790 else if (*p
== '(')
16792 /* It's a function-like macro. */
16793 char *name
= copy_string (body
, p
- body
);
16796 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16800 p
= consume_improper_spaces (p
, body
);
16802 /* Parse the formal argument list. */
16803 while (*p
&& *p
!= ')')
16805 /* Find the extent of the current argument name. */
16806 const char *arg_start
= p
;
16808 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16811 if (! *p
|| p
== arg_start
)
16812 dwarf2_macro_malformed_definition_complaint (body
);
16815 /* Make sure argv has room for the new argument. */
16816 if (argc
>= argv_size
)
16819 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16822 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16825 p
= consume_improper_spaces (p
, body
);
16827 /* Consume the comma, if present. */
16832 p
= consume_improper_spaces (p
, body
);
16841 /* Perfectly formed definition, no complaints. */
16842 macro_define_function (file
, line
, name
,
16843 argc
, (const char **) argv
,
16845 else if (*p
== '\0')
16847 /* Complain, but do define it. */
16848 dwarf2_macro_malformed_definition_complaint (body
);
16849 macro_define_function (file
, line
, name
,
16850 argc
, (const char **) argv
,
16854 /* Just complain. */
16855 dwarf2_macro_malformed_definition_complaint (body
);
16858 /* Just complain. */
16859 dwarf2_macro_malformed_definition_complaint (body
);
16865 for (i
= 0; i
< argc
; i
++)
16871 dwarf2_macro_malformed_definition_complaint (body
);
16874 /* Skip some bytes from BYTES according to the form given in FORM.
16875 Returns the new pointer. */
16878 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
16879 enum dwarf_form form
,
16880 unsigned int offset_size
,
16881 struct dwarf2_section_info
*section
)
16883 unsigned int bytes_read
;
16887 case DW_FORM_data1
:
16892 case DW_FORM_data2
:
16896 case DW_FORM_data4
:
16900 case DW_FORM_data8
:
16904 case DW_FORM_string
:
16905 read_direct_string (abfd
, bytes
, &bytes_read
);
16906 bytes
+= bytes_read
;
16909 case DW_FORM_sec_offset
:
16911 bytes
+= offset_size
;
16914 case DW_FORM_block
:
16915 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
16916 bytes
+= bytes_read
;
16919 case DW_FORM_block1
:
16920 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16922 case DW_FORM_block2
:
16923 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16925 case DW_FORM_block4
:
16926 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
16929 case DW_FORM_sdata
:
16930 case DW_FORM_udata
:
16931 case DW_FORM_GNU_addr_index
:
16932 case DW_FORM_GNU_str_index
:
16933 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
16936 dwarf2_section_buffer_overflow_complaint (section
);
16944 complaint (&symfile_complaints
,
16945 _("invalid form 0x%x in `%s'"),
16947 section
->asection
->name
);
16955 /* A helper for dwarf_decode_macros that handles skipping an unknown
16956 opcode. Returns an updated pointer to the macro data buffer; or,
16957 on error, issues a complaint and returns NULL. */
16960 skip_unknown_opcode (unsigned int opcode
,
16961 gdb_byte
**opcode_definitions
,
16962 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16964 unsigned int offset_size
,
16965 struct dwarf2_section_info
*section
)
16967 unsigned int bytes_read
, i
;
16971 if (opcode_definitions
[opcode
] == NULL
)
16973 complaint (&symfile_complaints
,
16974 _("unrecognized DW_MACFINO opcode 0x%x"),
16979 defn
= opcode_definitions
[opcode
];
16980 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
16981 defn
+= bytes_read
;
16983 for (i
= 0; i
< arg
; ++i
)
16985 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
16987 if (mac_ptr
== NULL
)
16989 /* skip_form_bytes already issued the complaint. */
16997 /* A helper function which parses the header of a macro section.
16998 If the macro section is the extended (for now called "GNU") type,
16999 then this updates *OFFSET_SIZE. Returns a pointer to just after
17000 the header, or issues a complaint and returns NULL on error. */
17003 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
17006 unsigned int *offset_size
,
17007 int section_is_gnu
)
17009 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
17011 if (section_is_gnu
)
17013 unsigned int version
, flags
;
17015 version
= read_2_bytes (abfd
, mac_ptr
);
17018 complaint (&symfile_complaints
,
17019 _("unrecognized version `%d' in .debug_macro section"),
17025 flags
= read_1_byte (abfd
, mac_ptr
);
17027 *offset_size
= (flags
& 1) ? 8 : 4;
17029 if ((flags
& 2) != 0)
17030 /* We don't need the line table offset. */
17031 mac_ptr
+= *offset_size
;
17033 /* Vendor opcode descriptions. */
17034 if ((flags
& 4) != 0)
17036 unsigned int i
, count
;
17038 count
= read_1_byte (abfd
, mac_ptr
);
17040 for (i
= 0; i
< count
; ++i
)
17042 unsigned int opcode
, bytes_read
;
17045 opcode
= read_1_byte (abfd
, mac_ptr
);
17047 opcode_definitions
[opcode
] = mac_ptr
;
17048 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17049 mac_ptr
+= bytes_read
;
17058 /* A helper for dwarf_decode_macros that handles the GNU extensions,
17059 including DW_MACRO_GNU_transparent_include. */
17062 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17063 struct macro_source_file
*current_file
,
17064 struct line_header
*lh
, char *comp_dir
,
17065 struct dwarf2_section_info
*section
,
17066 int section_is_gnu
,
17067 unsigned int offset_size
,
17068 struct objfile
*objfile
,
17069 htab_t include_hash
)
17071 enum dwarf_macro_record_type macinfo_type
;
17072 int at_commandline
;
17073 gdb_byte
*opcode_definitions
[256];
17075 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17076 &offset_size
, section_is_gnu
);
17077 if (mac_ptr
== NULL
)
17079 /* We already issued a complaint. */
17083 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
17084 GDB is still reading the definitions from command line. First
17085 DW_MACINFO_start_file will need to be ignored as it was already executed
17086 to create CURRENT_FILE for the main source holding also the command line
17087 definitions. On first met DW_MACINFO_start_file this flag is reset to
17088 normally execute all the remaining DW_MACINFO_start_file macinfos. */
17090 at_commandline
= 1;
17094 /* Do we at least have room for a macinfo type byte? */
17095 if (mac_ptr
>= mac_end
)
17097 dwarf2_section_buffer_overflow_complaint (section
);
17101 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17104 /* Note that we rely on the fact that the corresponding GNU and
17105 DWARF constants are the same. */
17106 switch (macinfo_type
)
17108 /* A zero macinfo type indicates the end of the macro
17113 case DW_MACRO_GNU_define
:
17114 case DW_MACRO_GNU_undef
:
17115 case DW_MACRO_GNU_define_indirect
:
17116 case DW_MACRO_GNU_undef_indirect
:
17118 unsigned int bytes_read
;
17123 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17124 mac_ptr
+= bytes_read
;
17126 if (macinfo_type
== DW_MACRO_GNU_define
17127 || macinfo_type
== DW_MACRO_GNU_undef
)
17129 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17130 mac_ptr
+= bytes_read
;
17134 LONGEST str_offset
;
17136 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17137 mac_ptr
+= offset_size
;
17139 body
= read_indirect_string_at_offset (abfd
, str_offset
);
17142 is_define
= (macinfo_type
== DW_MACRO_GNU_define
17143 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
17144 if (! current_file
)
17146 /* DWARF violation as no main source is present. */
17147 complaint (&symfile_complaints
,
17148 _("debug info with no main source gives macro %s "
17150 is_define
? _("definition") : _("undefinition"),
17154 if ((line
== 0 && !at_commandline
)
17155 || (line
!= 0 && at_commandline
))
17156 complaint (&symfile_complaints
,
17157 _("debug info gives %s macro %s with %s line %d: %s"),
17158 at_commandline
? _("command-line") : _("in-file"),
17159 is_define
? _("definition") : _("undefinition"),
17160 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
17163 parse_macro_definition (current_file
, line
, body
);
17166 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
17167 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
17168 macro_undef (current_file
, line
, body
);
17173 case DW_MACRO_GNU_start_file
:
17175 unsigned int bytes_read
;
17178 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17179 mac_ptr
+= bytes_read
;
17180 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17181 mac_ptr
+= bytes_read
;
17183 if ((line
== 0 && !at_commandline
)
17184 || (line
!= 0 && at_commandline
))
17185 complaint (&symfile_complaints
,
17186 _("debug info gives source %d included "
17187 "from %s at %s line %d"),
17188 file
, at_commandline
? _("command-line") : _("file"),
17189 line
== 0 ? _("zero") : _("non-zero"), line
);
17191 if (at_commandline
)
17193 /* This DW_MACRO_GNU_start_file was executed in the
17195 at_commandline
= 0;
17198 current_file
= macro_start_file (file
, line
,
17199 current_file
, comp_dir
,
17204 case DW_MACRO_GNU_end_file
:
17205 if (! current_file
)
17206 complaint (&symfile_complaints
,
17207 _("macro debug info has an unmatched "
17208 "`close_file' directive"));
17211 current_file
= current_file
->included_by
;
17212 if (! current_file
)
17214 enum dwarf_macro_record_type next_type
;
17216 /* GCC circa March 2002 doesn't produce the zero
17217 type byte marking the end of the compilation
17218 unit. Complain if it's not there, but exit no
17221 /* Do we at least have room for a macinfo type byte? */
17222 if (mac_ptr
>= mac_end
)
17224 dwarf2_section_buffer_overflow_complaint (section
);
17228 /* We don't increment mac_ptr here, so this is just
17230 next_type
= read_1_byte (abfd
, mac_ptr
);
17231 if (next_type
!= 0)
17232 complaint (&symfile_complaints
,
17233 _("no terminating 0-type entry for "
17234 "macros in `.debug_macinfo' section"));
17241 case DW_MACRO_GNU_transparent_include
:
17246 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17247 mac_ptr
+= offset_size
;
17249 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17252 /* This has actually happened; see
17253 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
17254 complaint (&symfile_complaints
,
17255 _("recursive DW_MACRO_GNU_transparent_include in "
17256 ".debug_macro section"));
17262 dwarf_decode_macro_bytes (abfd
,
17263 section
->buffer
+ offset
,
17264 mac_end
, current_file
,
17266 section
, section_is_gnu
,
17267 offset_size
, objfile
, include_hash
);
17269 htab_remove_elt (include_hash
, mac_ptr
);
17274 case DW_MACINFO_vendor_ext
:
17275 if (!section_is_gnu
)
17277 unsigned int bytes_read
;
17280 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17281 mac_ptr
+= bytes_read
;
17282 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17283 mac_ptr
+= bytes_read
;
17285 /* We don't recognize any vendor extensions. */
17291 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17292 mac_ptr
, mac_end
, abfd
, offset_size
,
17294 if (mac_ptr
== NULL
)
17298 } while (macinfo_type
!= 0);
17302 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
17303 char *comp_dir
, int section_is_gnu
)
17305 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17306 struct line_header
*lh
= cu
->line_header
;
17308 gdb_byte
*mac_ptr
, *mac_end
;
17309 struct macro_source_file
*current_file
= 0;
17310 enum dwarf_macro_record_type macinfo_type
;
17311 unsigned int offset_size
= cu
->header
.offset_size
;
17312 gdb_byte
*opcode_definitions
[256];
17313 struct cleanup
*cleanup
;
17314 htab_t include_hash
;
17316 struct dwarf2_section_info
*section
;
17317 const char *section_name
;
17319 if (cu
->dwo_unit
!= NULL
)
17321 if (section_is_gnu
)
17323 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
17324 section_name
= ".debug_macro.dwo";
17328 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
17329 section_name
= ".debug_macinfo.dwo";
17334 if (section_is_gnu
)
17336 section
= &dwarf2_per_objfile
->macro
;
17337 section_name
= ".debug_macro";
17341 section
= &dwarf2_per_objfile
->macinfo
;
17342 section_name
= ".debug_macinfo";
17346 dwarf2_read_section (objfile
, section
);
17347 if (section
->buffer
== NULL
)
17349 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
17352 abfd
= section
->asection
->owner
;
17354 /* First pass: Find the name of the base filename.
17355 This filename is needed in order to process all macros whose definition
17356 (or undefinition) comes from the command line. These macros are defined
17357 before the first DW_MACINFO_start_file entry, and yet still need to be
17358 associated to the base file.
17360 To determine the base file name, we scan the macro definitions until we
17361 reach the first DW_MACINFO_start_file entry. We then initialize
17362 CURRENT_FILE accordingly so that any macro definition found before the
17363 first DW_MACINFO_start_file can still be associated to the base file. */
17365 mac_ptr
= section
->buffer
+ offset
;
17366 mac_end
= section
->buffer
+ section
->size
;
17368 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17369 &offset_size
, section_is_gnu
);
17370 if (mac_ptr
== NULL
)
17372 /* We already issued a complaint. */
17378 /* Do we at least have room for a macinfo type byte? */
17379 if (mac_ptr
>= mac_end
)
17381 /* Complaint is printed during the second pass as GDB will probably
17382 stop the first pass earlier upon finding
17383 DW_MACINFO_start_file. */
17387 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17390 /* Note that we rely on the fact that the corresponding GNU and
17391 DWARF constants are the same. */
17392 switch (macinfo_type
)
17394 /* A zero macinfo type indicates the end of the macro
17399 case DW_MACRO_GNU_define
:
17400 case DW_MACRO_GNU_undef
:
17401 /* Only skip the data by MAC_PTR. */
17403 unsigned int bytes_read
;
17405 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17406 mac_ptr
+= bytes_read
;
17407 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17408 mac_ptr
+= bytes_read
;
17412 case DW_MACRO_GNU_start_file
:
17414 unsigned int bytes_read
;
17417 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17418 mac_ptr
+= bytes_read
;
17419 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17420 mac_ptr
+= bytes_read
;
17422 current_file
= macro_start_file (file
, line
, current_file
,
17423 comp_dir
, lh
, objfile
);
17427 case DW_MACRO_GNU_end_file
:
17428 /* No data to skip by MAC_PTR. */
17431 case DW_MACRO_GNU_define_indirect
:
17432 case DW_MACRO_GNU_undef_indirect
:
17434 unsigned int bytes_read
;
17436 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17437 mac_ptr
+= bytes_read
;
17438 mac_ptr
+= offset_size
;
17442 case DW_MACRO_GNU_transparent_include
:
17443 /* Note that, according to the spec, a transparent include
17444 chain cannot call DW_MACRO_GNU_start_file. So, we can just
17445 skip this opcode. */
17446 mac_ptr
+= offset_size
;
17449 case DW_MACINFO_vendor_ext
:
17450 /* Only skip the data by MAC_PTR. */
17451 if (!section_is_gnu
)
17453 unsigned int bytes_read
;
17455 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17456 mac_ptr
+= bytes_read
;
17457 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17458 mac_ptr
+= bytes_read
;
17463 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17464 mac_ptr
, mac_end
, abfd
, offset_size
,
17466 if (mac_ptr
== NULL
)
17470 } while (macinfo_type
!= 0 && current_file
== NULL
);
17472 /* Second pass: Process all entries.
17474 Use the AT_COMMAND_LINE flag to determine whether we are still processing
17475 command-line macro definitions/undefinitions. This flag is unset when we
17476 reach the first DW_MACINFO_start_file entry. */
17478 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
17479 NULL
, xcalloc
, xfree
);
17480 cleanup
= make_cleanup_htab_delete (include_hash
);
17481 mac_ptr
= section
->buffer
+ offset
;
17482 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17484 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
17485 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
17486 offset_size
, objfile
, include_hash
);
17487 do_cleanups (cleanup
);
17490 /* Check if the attribute's form is a DW_FORM_block*
17491 if so return true else false. */
17494 attr_form_is_block (struct attribute
*attr
)
17496 return (attr
== NULL
? 0 :
17497 attr
->form
== DW_FORM_block1
17498 || attr
->form
== DW_FORM_block2
17499 || attr
->form
== DW_FORM_block4
17500 || attr
->form
== DW_FORM_block
17501 || attr
->form
== DW_FORM_exprloc
);
17504 /* Return non-zero if ATTR's value is a section offset --- classes
17505 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
17506 You may use DW_UNSND (attr) to retrieve such offsets.
17508 Section 7.5.4, "Attribute Encodings", explains that no attribute
17509 may have a value that belongs to more than one of these classes; it
17510 would be ambiguous if we did, because we use the same forms for all
17514 attr_form_is_section_offset (struct attribute
*attr
)
17516 return (attr
->form
== DW_FORM_data4
17517 || attr
->form
== DW_FORM_data8
17518 || attr
->form
== DW_FORM_sec_offset
);
17521 /* Return non-zero if ATTR's value falls in the 'constant' class, or
17522 zero otherwise. When this function returns true, you can apply
17523 dwarf2_get_attr_constant_value to it.
17525 However, note that for some attributes you must check
17526 attr_form_is_section_offset before using this test. DW_FORM_data4
17527 and DW_FORM_data8 are members of both the constant class, and of
17528 the classes that contain offsets into other debug sections
17529 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
17530 that, if an attribute's can be either a constant or one of the
17531 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
17532 taken as section offsets, not constants. */
17535 attr_form_is_constant (struct attribute
*attr
)
17537 switch (attr
->form
)
17539 case DW_FORM_sdata
:
17540 case DW_FORM_udata
:
17541 case DW_FORM_data1
:
17542 case DW_FORM_data2
:
17543 case DW_FORM_data4
:
17544 case DW_FORM_data8
:
17551 /* Return the .debug_loc section to use for CU.
17552 For DWO files use .debug_loc.dwo. */
17554 static struct dwarf2_section_info
*
17555 cu_debug_loc_section (struct dwarf2_cu
*cu
)
17558 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
17559 return &dwarf2_per_objfile
->loc
;
17562 /* A helper function that fills in a dwarf2_loclist_baton. */
17565 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
17566 struct dwarf2_loclist_baton
*baton
,
17567 struct attribute
*attr
)
17569 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17571 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17573 baton
->per_cu
= cu
->per_cu
;
17574 gdb_assert (baton
->per_cu
);
17575 /* We don't know how long the location list is, but make sure we
17576 don't run off the edge of the section. */
17577 baton
->size
= section
->size
- DW_UNSND (attr
);
17578 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
17579 baton
->base_address
= cu
->base_address
;
17580 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
17584 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
17585 struct dwarf2_cu
*cu
)
17587 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17588 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17590 if (attr_form_is_section_offset (attr
)
17591 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
17592 the section. If so, fall through to the complaint in the
17594 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
17596 struct dwarf2_loclist_baton
*baton
;
17598 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17599 sizeof (struct dwarf2_loclist_baton
));
17601 fill_in_loclist_baton (cu
, baton
, attr
);
17603 if (cu
->base_known
== 0)
17604 complaint (&symfile_complaints
,
17605 _("Location list used without "
17606 "specifying the CU base address."));
17608 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
17609 SYMBOL_LOCATION_BATON (sym
) = baton
;
17613 struct dwarf2_locexpr_baton
*baton
;
17615 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17616 sizeof (struct dwarf2_locexpr_baton
));
17617 baton
->per_cu
= cu
->per_cu
;
17618 gdb_assert (baton
->per_cu
);
17620 if (attr_form_is_block (attr
))
17622 /* Note that we're just copying the block's data pointer
17623 here, not the actual data. We're still pointing into the
17624 info_buffer for SYM's objfile; right now we never release
17625 that buffer, but when we do clean up properly this may
17627 baton
->size
= DW_BLOCK (attr
)->size
;
17628 baton
->data
= DW_BLOCK (attr
)->data
;
17632 dwarf2_invalid_attrib_class_complaint ("location description",
17633 SYMBOL_NATURAL_NAME (sym
));
17637 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
17638 SYMBOL_LOCATION_BATON (sym
) = baton
;
17642 /* Return the OBJFILE associated with the compilation unit CU. If CU
17643 came from a separate debuginfo file, then the master objfile is
17647 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
17649 struct objfile
*objfile
= per_cu
->objfile
;
17651 /* Return the master objfile, so that we can report and look up the
17652 correct file containing this variable. */
17653 if (objfile
->separate_debug_objfile_backlink
)
17654 objfile
= objfile
->separate_debug_objfile_backlink
;
17659 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
17660 (CU_HEADERP is unused in such case) or prepare a temporary copy at
17661 CU_HEADERP first. */
17663 static const struct comp_unit_head
*
17664 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
17665 struct dwarf2_per_cu_data
*per_cu
)
17667 gdb_byte
*info_ptr
;
17670 return &per_cu
->cu
->header
;
17672 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
17674 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
17675 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
17680 /* Return the address size given in the compilation unit header for CU. */
17683 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17685 struct comp_unit_head cu_header_local
;
17686 const struct comp_unit_head
*cu_headerp
;
17688 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17690 return cu_headerp
->addr_size
;
17693 /* Return the offset size given in the compilation unit header for CU. */
17696 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
17698 struct comp_unit_head cu_header_local
;
17699 const struct comp_unit_head
*cu_headerp
;
17701 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17703 return cu_headerp
->offset_size
;
17706 /* See its dwarf2loc.h declaration. */
17709 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17711 struct comp_unit_head cu_header_local
;
17712 const struct comp_unit_head
*cu_headerp
;
17714 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17716 if (cu_headerp
->version
== 2)
17717 return cu_headerp
->addr_size
;
17719 return cu_headerp
->offset_size
;
17722 /* Return the text offset of the CU. The returned offset comes from
17723 this CU's objfile. If this objfile came from a separate debuginfo
17724 file, then the offset may be different from the corresponding
17725 offset in the parent objfile. */
17728 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
17730 struct objfile
*objfile
= per_cu
->objfile
;
17732 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17735 /* Locate the .debug_info compilation unit from CU's objfile which contains
17736 the DIE at OFFSET. Raises an error on failure. */
17738 static struct dwarf2_per_cu_data
*
17739 dwarf2_find_containing_comp_unit (sect_offset offset
,
17740 struct objfile
*objfile
)
17742 struct dwarf2_per_cu_data
*this_cu
;
17746 high
= dwarf2_per_objfile
->n_comp_units
- 1;
17749 int mid
= low
+ (high
- low
) / 2;
17751 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
17752 >= offset
.sect_off
)
17757 gdb_assert (low
== high
);
17758 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
17762 error (_("Dwarf Error: could not find partial DIE containing "
17763 "offset 0x%lx [in module %s]"),
17764 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
17766 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
17767 <= offset
.sect_off
);
17768 return dwarf2_per_objfile
->all_comp_units
[low
-1];
17772 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
17773 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
17774 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
17775 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
17776 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
17781 /* Initialize dwarf2_cu CU, owned by PER_CU. */
17784 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
17786 memset (cu
, 0, sizeof (*cu
));
17788 cu
->per_cu
= per_cu
;
17789 cu
->objfile
= per_cu
->objfile
;
17790 obstack_init (&cu
->comp_unit_obstack
);
17793 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17796 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
17797 enum language pretend_language
)
17799 struct attribute
*attr
;
17801 /* Set the language we're debugging. */
17802 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17804 set_cu_language (DW_UNSND (attr
), cu
);
17807 cu
->language
= pretend_language
;
17808 cu
->language_defn
= language_def (cu
->language
);
17811 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17813 cu
->producer
= DW_STRING (attr
);
17816 /* Release one cached compilation unit, CU. We unlink it from the tree
17817 of compilation units, but we don't remove it from the read_in_chain;
17818 the caller is responsible for that.
17819 NOTE: DATA is a void * because this function is also used as a
17820 cleanup routine. */
17823 free_heap_comp_unit (void *data
)
17825 struct dwarf2_cu
*cu
= data
;
17827 gdb_assert (cu
->per_cu
!= NULL
);
17828 cu
->per_cu
->cu
= NULL
;
17831 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17836 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17837 when we're finished with it. We can't free the pointer itself, but be
17838 sure to unlink it from the cache. Also release any associated storage. */
17841 free_stack_comp_unit (void *data
)
17843 struct dwarf2_cu
*cu
= data
;
17845 gdb_assert (cu
->per_cu
!= NULL
);
17846 cu
->per_cu
->cu
= NULL
;
17849 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17850 cu
->partial_dies
= NULL
;
17853 /* Free all cached compilation units. */
17856 free_cached_comp_units (void *data
)
17858 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17860 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17861 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17862 while (per_cu
!= NULL
)
17864 struct dwarf2_per_cu_data
*next_cu
;
17866 next_cu
= per_cu
->cu
->read_in_chain
;
17868 free_heap_comp_unit (per_cu
->cu
);
17869 *last_chain
= next_cu
;
17875 /* Increase the age counter on each cached compilation unit, and free
17876 any that are too old. */
17879 age_cached_comp_units (void)
17881 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17883 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
17884 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17885 while (per_cu
!= NULL
)
17887 per_cu
->cu
->last_used
++;
17888 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
17889 dwarf2_mark (per_cu
->cu
);
17890 per_cu
= per_cu
->cu
->read_in_chain
;
17893 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17894 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17895 while (per_cu
!= NULL
)
17897 struct dwarf2_per_cu_data
*next_cu
;
17899 next_cu
= per_cu
->cu
->read_in_chain
;
17901 if (!per_cu
->cu
->mark
)
17903 free_heap_comp_unit (per_cu
->cu
);
17904 *last_chain
= next_cu
;
17907 last_chain
= &per_cu
->cu
->read_in_chain
;
17913 /* Remove a single compilation unit from the cache. */
17916 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
17918 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17920 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17921 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17922 while (per_cu
!= NULL
)
17924 struct dwarf2_per_cu_data
*next_cu
;
17926 next_cu
= per_cu
->cu
->read_in_chain
;
17928 if (per_cu
== target_per_cu
)
17930 free_heap_comp_unit (per_cu
->cu
);
17932 *last_chain
= next_cu
;
17936 last_chain
= &per_cu
->cu
->read_in_chain
;
17942 /* Release all extra memory associated with OBJFILE. */
17945 dwarf2_free_objfile (struct objfile
*objfile
)
17947 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17949 if (dwarf2_per_objfile
== NULL
)
17952 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
17953 free_cached_comp_units (NULL
);
17955 if (dwarf2_per_objfile
->quick_file_names_table
)
17956 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
17958 /* Everything else should be on the objfile obstack. */
17961 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
17962 We store these in a hash table separate from the DIEs, and preserve them
17963 when the DIEs are flushed out of cache.
17965 The CU "per_cu" pointer is needed because offset alone is not enough to
17966 uniquely identify the type. A file may have multiple .debug_types sections,
17967 or the type may come from a DWO file. We have to use something in
17968 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
17969 routine, get_die_type_at_offset, from outside this file, and thus won't
17970 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
17973 struct dwarf2_per_cu_offset_and_type
17975 const struct dwarf2_per_cu_data
*per_cu
;
17976 sect_offset offset
;
17980 /* Hash function for a dwarf2_per_cu_offset_and_type. */
17983 per_cu_offset_and_type_hash (const void *item
)
17985 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
17987 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
17990 /* Equality function for a dwarf2_per_cu_offset_and_type. */
17993 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
17995 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
17996 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
17998 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
17999 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
18002 /* Set the type associated with DIE to TYPE. Save it in CU's hash
18003 table if necessary. For convenience, return TYPE.
18005 The DIEs reading must have careful ordering to:
18006 * Not cause infite loops trying to read in DIEs as a prerequisite for
18007 reading current DIE.
18008 * Not trying to dereference contents of still incompletely read in types
18009 while reading in other DIEs.
18010 * Enable referencing still incompletely read in types just by a pointer to
18011 the type without accessing its fields.
18013 Therefore caller should follow these rules:
18014 * Try to fetch any prerequisite types we may need to build this DIE type
18015 before building the type and calling set_die_type.
18016 * After building type call set_die_type for current DIE as soon as
18017 possible before fetching more types to complete the current type.
18018 * Make the type as complete as possible before fetching more types. */
18020 static struct type
*
18021 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18023 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
18024 struct objfile
*objfile
= cu
->objfile
;
18026 /* For Ada types, make sure that the gnat-specific data is always
18027 initialized (if not already set). There are a few types where
18028 we should not be doing so, because the type-specific area is
18029 already used to hold some other piece of info (eg: TYPE_CODE_FLT
18030 where the type-specific area is used to store the floatformat).
18031 But this is not a problem, because the gnat-specific information
18032 is actually not needed for these types. */
18033 if (need_gnat_info (cu
)
18034 && TYPE_CODE (type
) != TYPE_CODE_FUNC
18035 && TYPE_CODE (type
) != TYPE_CODE_FLT
18036 && !HAVE_GNAT_AUX_INFO (type
))
18037 INIT_GNAT_SPECIFIC (type
);
18039 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18041 dwarf2_per_objfile
->die_type_hash
=
18042 htab_create_alloc_ex (127,
18043 per_cu_offset_and_type_hash
,
18044 per_cu_offset_and_type_eq
,
18046 &objfile
->objfile_obstack
,
18047 hashtab_obstack_allocate
,
18048 dummy_obstack_deallocate
);
18051 ofs
.per_cu
= cu
->per_cu
;
18052 ofs
.offset
= die
->offset
;
18054 slot
= (struct dwarf2_per_cu_offset_and_type
**)
18055 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
18057 complaint (&symfile_complaints
,
18058 _("A problem internal to GDB: DIE 0x%x has type already set"),
18059 die
->offset
.sect_off
);
18060 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
18065 /* Look up the type for the die at OFFSET in the appropriate type_hash
18066 table, or return NULL if the die does not have a saved type. */
18068 static struct type
*
18069 get_die_type_at_offset (sect_offset offset
,
18070 struct dwarf2_per_cu_data
*per_cu
)
18072 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
18074 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18077 ofs
.per_cu
= per_cu
;
18078 ofs
.offset
= offset
;
18079 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
18086 /* Look up the type for DIE in the appropriate type_hash table,
18087 or return NULL if DIE does not have a saved type. */
18089 static struct type
*
18090 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18092 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
18095 /* Add a dependence relationship from CU to REF_PER_CU. */
18098 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
18099 struct dwarf2_per_cu_data
*ref_per_cu
)
18103 if (cu
->dependencies
== NULL
)
18105 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
18106 NULL
, &cu
->comp_unit_obstack
,
18107 hashtab_obstack_allocate
,
18108 dummy_obstack_deallocate
);
18110 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
18112 *slot
= ref_per_cu
;
18115 /* Subroutine of dwarf2_mark to pass to htab_traverse.
18116 Set the mark field in every compilation unit in the
18117 cache that we must keep because we are keeping CU. */
18120 dwarf2_mark_helper (void **slot
, void *data
)
18122 struct dwarf2_per_cu_data
*per_cu
;
18124 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
18126 /* cu->dependencies references may not yet have been ever read if QUIT aborts
18127 reading of the chain. As such dependencies remain valid it is not much
18128 useful to track and undo them during QUIT cleanups. */
18129 if (per_cu
->cu
== NULL
)
18132 if (per_cu
->cu
->mark
)
18134 per_cu
->cu
->mark
= 1;
18136 if (per_cu
->cu
->dependencies
!= NULL
)
18137 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18142 /* Set the mark field in CU and in every other compilation unit in the
18143 cache that we must keep because we are keeping CU. */
18146 dwarf2_mark (struct dwarf2_cu
*cu
)
18151 if (cu
->dependencies
!= NULL
)
18152 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18156 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
18160 per_cu
->cu
->mark
= 0;
18161 per_cu
= per_cu
->cu
->read_in_chain
;
18165 /* Trivial hash function for partial_die_info: the hash value of a DIE
18166 is its offset in .debug_info for this objfile. */
18169 partial_die_hash (const void *item
)
18171 const struct partial_die_info
*part_die
= item
;
18173 return part_die
->offset
.sect_off
;
18176 /* Trivial comparison function for partial_die_info structures: two DIEs
18177 are equal if they have the same offset. */
18180 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
18182 const struct partial_die_info
*part_die_lhs
= item_lhs
;
18183 const struct partial_die_info
*part_die_rhs
= item_rhs
;
18185 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
18188 static struct cmd_list_element
*set_dwarf2_cmdlist
;
18189 static struct cmd_list_element
*show_dwarf2_cmdlist
;
18192 set_dwarf2_cmd (char *args
, int from_tty
)
18194 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
18198 show_dwarf2_cmd (char *args
, int from_tty
)
18200 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
18203 /* Free data associated with OBJFILE, if necessary. */
18206 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
18208 struct dwarf2_per_objfile
*data
= d
;
18211 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
18212 VEC_free (dwarf2_per_cu_ptr
,
18213 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
18215 VEC_free (dwarf2_section_info_def
, data
->types
);
18217 if (data
->dwo_files
)
18218 free_dwo_files (data
->dwo_files
, objfile
);
18222 /* The "save gdb-index" command. */
18224 /* The contents of the hash table we create when building the string
18226 struct strtab_entry
18228 offset_type offset
;
18232 /* Hash function for a strtab_entry.
18234 Function is used only during write_hash_table so no index format backward
18235 compatibility is needed. */
18238 hash_strtab_entry (const void *e
)
18240 const struct strtab_entry
*entry
= e
;
18241 return mapped_index_string_hash (INT_MAX
, entry
->str
);
18244 /* Equality function for a strtab_entry. */
18247 eq_strtab_entry (const void *a
, const void *b
)
18249 const struct strtab_entry
*ea
= a
;
18250 const struct strtab_entry
*eb
= b
;
18251 return !strcmp (ea
->str
, eb
->str
);
18254 /* Create a strtab_entry hash table. */
18257 create_strtab (void)
18259 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
18260 xfree
, xcalloc
, xfree
);
18263 /* Add a string to the constant pool. Return the string's offset in
18267 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
18270 struct strtab_entry entry
;
18271 struct strtab_entry
*result
;
18274 slot
= htab_find_slot (table
, &entry
, INSERT
);
18279 result
= XNEW (struct strtab_entry
);
18280 result
->offset
= obstack_object_size (cpool
);
18282 obstack_grow_str0 (cpool
, str
);
18285 return result
->offset
;
18288 /* An entry in the symbol table. */
18289 struct symtab_index_entry
18291 /* The name of the symbol. */
18293 /* The offset of the name in the constant pool. */
18294 offset_type index_offset
;
18295 /* A sorted vector of the indices of all the CUs that hold an object
18297 VEC (offset_type
) *cu_indices
;
18300 /* The symbol table. This is a power-of-2-sized hash table. */
18301 struct mapped_symtab
18303 offset_type n_elements
;
18305 struct symtab_index_entry
**data
;
18308 /* Hash function for a symtab_index_entry. */
18311 hash_symtab_entry (const void *e
)
18313 const struct symtab_index_entry
*entry
= e
;
18314 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
18315 sizeof (offset_type
) * VEC_length (offset_type
,
18316 entry
->cu_indices
),
18320 /* Equality function for a symtab_index_entry. */
18323 eq_symtab_entry (const void *a
, const void *b
)
18325 const struct symtab_index_entry
*ea
= a
;
18326 const struct symtab_index_entry
*eb
= b
;
18327 int len
= VEC_length (offset_type
, ea
->cu_indices
);
18328 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
18330 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
18331 VEC_address (offset_type
, eb
->cu_indices
),
18332 sizeof (offset_type
) * len
);
18335 /* Destroy a symtab_index_entry. */
18338 delete_symtab_entry (void *p
)
18340 struct symtab_index_entry
*entry
= p
;
18341 VEC_free (offset_type
, entry
->cu_indices
);
18345 /* Create a hash table holding symtab_index_entry objects. */
18348 create_symbol_hash_table (void)
18350 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
18351 delete_symtab_entry
, xcalloc
, xfree
);
18354 /* Create a new mapped symtab object. */
18356 static struct mapped_symtab
*
18357 create_mapped_symtab (void)
18359 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
18360 symtab
->n_elements
= 0;
18361 symtab
->size
= 1024;
18362 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18366 /* Destroy a mapped_symtab. */
18369 cleanup_mapped_symtab (void *p
)
18371 struct mapped_symtab
*symtab
= p
;
18372 /* The contents of the array are freed when the other hash table is
18374 xfree (symtab
->data
);
18378 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
18381 Function is used only during write_hash_table so no index format backward
18382 compatibility is needed. */
18384 static struct symtab_index_entry
**
18385 find_slot (struct mapped_symtab
*symtab
, const char *name
)
18387 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
18389 index
= hash
& (symtab
->size
- 1);
18390 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
18394 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
18395 return &symtab
->data
[index
];
18396 index
= (index
+ step
) & (symtab
->size
- 1);
18400 /* Expand SYMTAB's hash table. */
18403 hash_expand (struct mapped_symtab
*symtab
)
18405 offset_type old_size
= symtab
->size
;
18407 struct symtab_index_entry
**old_entries
= symtab
->data
;
18410 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18412 for (i
= 0; i
< old_size
; ++i
)
18414 if (old_entries
[i
])
18416 struct symtab_index_entry
**slot
= find_slot (symtab
,
18417 old_entries
[i
]->name
);
18418 *slot
= old_entries
[i
];
18422 xfree (old_entries
);
18425 /* Add an entry to SYMTAB. NAME is the name of the symbol.
18426 CU_INDEX is the index of the CU in which the symbol appears.
18427 IS_STATIC is one if the symbol is static, otherwise zero (global). */
18430 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
18431 int is_static
, gdb_index_symbol_kind kind
,
18432 offset_type cu_index
)
18434 struct symtab_index_entry
**slot
;
18435 offset_type cu_index_and_attrs
;
18437 ++symtab
->n_elements
;
18438 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
18439 hash_expand (symtab
);
18441 slot
= find_slot (symtab
, name
);
18444 *slot
= XNEW (struct symtab_index_entry
);
18445 (*slot
)->name
= name
;
18446 /* index_offset is set later. */
18447 (*slot
)->cu_indices
= NULL
;
18450 cu_index_and_attrs
= 0;
18451 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
18452 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
18453 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
18455 /* We don't want to record an index value twice as we want to avoid the
18457 We process all global symbols and then all static symbols
18458 (which would allow us to avoid the duplication by only having to check
18459 the last entry pushed), but a symbol could have multiple kinds in one CU.
18460 To keep things simple we don't worry about the duplication here and
18461 sort and uniqufy the list after we've processed all symbols. */
18462 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
18465 /* qsort helper routine for uniquify_cu_indices. */
18468 offset_type_compare (const void *ap
, const void *bp
)
18470 offset_type a
= *(offset_type
*) ap
;
18471 offset_type b
= *(offset_type
*) bp
;
18473 return (a
> b
) - (b
> a
);
18476 /* Sort and remove duplicates of all symbols' cu_indices lists. */
18479 uniquify_cu_indices (struct mapped_symtab
*symtab
)
18483 for (i
= 0; i
< symtab
->size
; ++i
)
18485 struct symtab_index_entry
*entry
= symtab
->data
[i
];
18488 && entry
->cu_indices
!= NULL
)
18490 unsigned int next_to_insert
, next_to_check
;
18491 offset_type last_value
;
18493 qsort (VEC_address (offset_type
, entry
->cu_indices
),
18494 VEC_length (offset_type
, entry
->cu_indices
),
18495 sizeof (offset_type
), offset_type_compare
);
18497 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
18498 next_to_insert
= 1;
18499 for (next_to_check
= 1;
18500 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
18503 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
18506 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
18508 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
18513 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
18518 /* Add a vector of indices to the constant pool. */
18521 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
18522 struct symtab_index_entry
*entry
)
18526 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
18529 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
18530 offset_type val
= MAYBE_SWAP (len
);
18535 entry
->index_offset
= obstack_object_size (cpool
);
18537 obstack_grow (cpool
, &val
, sizeof (val
));
18539 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
18542 val
= MAYBE_SWAP (iter
);
18543 obstack_grow (cpool
, &val
, sizeof (val
));
18548 struct symtab_index_entry
*old_entry
= *slot
;
18549 entry
->index_offset
= old_entry
->index_offset
;
18552 return entry
->index_offset
;
18555 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
18556 constant pool entries going into the obstack CPOOL. */
18559 write_hash_table (struct mapped_symtab
*symtab
,
18560 struct obstack
*output
, struct obstack
*cpool
)
18563 htab_t symbol_hash_table
;
18566 symbol_hash_table
= create_symbol_hash_table ();
18567 str_table
= create_strtab ();
18569 /* We add all the index vectors to the constant pool first, to
18570 ensure alignment is ok. */
18571 for (i
= 0; i
< symtab
->size
; ++i
)
18573 if (symtab
->data
[i
])
18574 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
18577 /* Now write out the hash table. */
18578 for (i
= 0; i
< symtab
->size
; ++i
)
18580 offset_type str_off
, vec_off
;
18582 if (symtab
->data
[i
])
18584 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
18585 vec_off
= symtab
->data
[i
]->index_offset
;
18589 /* While 0 is a valid constant pool index, it is not valid
18590 to have 0 for both offsets. */
18595 str_off
= MAYBE_SWAP (str_off
);
18596 vec_off
= MAYBE_SWAP (vec_off
);
18598 obstack_grow (output
, &str_off
, sizeof (str_off
));
18599 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
18602 htab_delete (str_table
);
18603 htab_delete (symbol_hash_table
);
18606 /* Struct to map psymtab to CU index in the index file. */
18607 struct psymtab_cu_index_map
18609 struct partial_symtab
*psymtab
;
18610 unsigned int cu_index
;
18614 hash_psymtab_cu_index (const void *item
)
18616 const struct psymtab_cu_index_map
*map
= item
;
18618 return htab_hash_pointer (map
->psymtab
);
18622 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
18624 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
18625 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
18627 return lhs
->psymtab
== rhs
->psymtab
;
18630 /* Helper struct for building the address table. */
18631 struct addrmap_index_data
18633 struct objfile
*objfile
;
18634 struct obstack
*addr_obstack
;
18635 htab_t cu_index_htab
;
18637 /* Non-zero if the previous_* fields are valid.
18638 We can't write an entry until we see the next entry (since it is only then
18639 that we know the end of the entry). */
18640 int previous_valid
;
18641 /* Index of the CU in the table of all CUs in the index file. */
18642 unsigned int previous_cu_index
;
18643 /* Start address of the CU. */
18644 CORE_ADDR previous_cu_start
;
18647 /* Write an address entry to OBSTACK. */
18650 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
18651 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
18653 offset_type cu_index_to_write
;
18655 CORE_ADDR baseaddr
;
18657 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18659 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
18660 obstack_grow (obstack
, addr
, 8);
18661 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
18662 obstack_grow (obstack
, addr
, 8);
18663 cu_index_to_write
= MAYBE_SWAP (cu_index
);
18664 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
18667 /* Worker function for traversing an addrmap to build the address table. */
18670 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
18672 struct addrmap_index_data
*data
= datap
;
18673 struct partial_symtab
*pst
= obj
;
18675 if (data
->previous_valid
)
18676 add_address_entry (data
->objfile
, data
->addr_obstack
,
18677 data
->previous_cu_start
, start_addr
,
18678 data
->previous_cu_index
);
18680 data
->previous_cu_start
= start_addr
;
18683 struct psymtab_cu_index_map find_map
, *map
;
18684 find_map
.psymtab
= pst
;
18685 map
= htab_find (data
->cu_index_htab
, &find_map
);
18686 gdb_assert (map
!= NULL
);
18687 data
->previous_cu_index
= map
->cu_index
;
18688 data
->previous_valid
= 1;
18691 data
->previous_valid
= 0;
18696 /* Write OBJFILE's address map to OBSTACK.
18697 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
18698 in the index file. */
18701 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
18702 htab_t cu_index_htab
)
18704 struct addrmap_index_data addrmap_index_data
;
18706 /* When writing the address table, we have to cope with the fact that
18707 the addrmap iterator only provides the start of a region; we have to
18708 wait until the next invocation to get the start of the next region. */
18710 addrmap_index_data
.objfile
= objfile
;
18711 addrmap_index_data
.addr_obstack
= obstack
;
18712 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
18713 addrmap_index_data
.previous_valid
= 0;
18715 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
18716 &addrmap_index_data
);
18718 /* It's highly unlikely the last entry (end address = 0xff...ff)
18719 is valid, but we should still handle it.
18720 The end address is recorded as the start of the next region, but that
18721 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
18723 if (addrmap_index_data
.previous_valid
)
18724 add_address_entry (objfile
, obstack
,
18725 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
18726 addrmap_index_data
.previous_cu_index
);
18729 /* Return the symbol kind of PSYM. */
18731 static gdb_index_symbol_kind
18732 symbol_kind (struct partial_symbol
*psym
)
18734 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
18735 enum address_class aclass
= PSYMBOL_CLASS (psym
);
18743 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
18745 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18747 case LOC_CONST_BYTES
:
18748 case LOC_OPTIMIZED_OUT
:
18750 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18752 /* Note: It's currently impossible to recognize psyms as enum values
18753 short of reading the type info. For now punt. */
18754 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18756 /* There are other LOC_FOO values that one might want to classify
18757 as variables, but dwarf2read.c doesn't currently use them. */
18758 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18760 case STRUCT_DOMAIN
:
18761 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18763 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18767 /* Add a list of partial symbols to SYMTAB. */
18770 write_psymbols (struct mapped_symtab
*symtab
,
18772 struct partial_symbol
**psymp
,
18774 offset_type cu_index
,
18777 for (; count
-- > 0; ++psymp
)
18779 struct partial_symbol
*psym
= *psymp
;
18782 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
18783 error (_("Ada is not currently supported by the index"));
18785 /* Only add a given psymbol once. */
18786 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
18789 gdb_index_symbol_kind kind
= symbol_kind (psym
);
18792 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
18793 is_static
, kind
, cu_index
);
18798 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18799 exception if there is an error. */
18802 write_obstack (FILE *file
, struct obstack
*obstack
)
18804 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18806 != obstack_object_size (obstack
))
18807 error (_("couldn't data write to file"));
18810 /* Unlink a file if the argument is not NULL. */
18813 unlink_if_set (void *p
)
18815 char **filename
= p
;
18817 unlink (*filename
);
18820 /* A helper struct used when iterating over debug_types. */
18821 struct signatured_type_index_data
18823 struct objfile
*objfile
;
18824 struct mapped_symtab
*symtab
;
18825 struct obstack
*types_list
;
18830 /* A helper function that writes a single signatured_type to an
18834 write_one_signatured_type (void **slot
, void *d
)
18836 struct signatured_type_index_data
*info
= d
;
18837 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
18838 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
18839 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18842 write_psymbols (info
->symtab
,
18844 info
->objfile
->global_psymbols
.list
18845 + psymtab
->globals_offset
,
18846 psymtab
->n_global_syms
, info
->cu_index
,
18848 write_psymbols (info
->symtab
,
18850 info
->objfile
->static_psymbols
.list
18851 + psymtab
->statics_offset
,
18852 psymtab
->n_static_syms
, info
->cu_index
,
18855 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18856 entry
->per_cu
.offset
.sect_off
);
18857 obstack_grow (info
->types_list
, val
, 8);
18858 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18859 entry
->type_offset_in_tu
.cu_off
);
18860 obstack_grow (info
->types_list
, val
, 8);
18861 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
18862 obstack_grow (info
->types_list
, val
, 8);
18869 /* Recurse into all "included" dependencies and write their symbols as
18870 if they appeared in this psymtab. */
18873 recursively_write_psymbols (struct objfile
*objfile
,
18874 struct partial_symtab
*psymtab
,
18875 struct mapped_symtab
*symtab
,
18877 offset_type cu_index
)
18881 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
18882 if (psymtab
->dependencies
[i
]->user
!= NULL
)
18883 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
18884 symtab
, psyms_seen
, cu_index
);
18886 write_psymbols (symtab
,
18888 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
18889 psymtab
->n_global_syms
, cu_index
,
18891 write_psymbols (symtab
,
18893 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
18894 psymtab
->n_static_syms
, cu_index
,
18898 /* Create an index file for OBJFILE in the directory DIR. */
18901 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
18903 struct cleanup
*cleanup
;
18904 char *filename
, *cleanup_filename
;
18905 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
18906 struct obstack cu_list
, types_cu_list
;
18909 struct mapped_symtab
*symtab
;
18910 offset_type val
, size_of_contents
, total_len
;
18913 htab_t cu_index_htab
;
18914 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
18916 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
18919 if (dwarf2_per_objfile
->using_index
)
18920 error (_("Cannot use an index to create the index"));
18922 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
18923 error (_("Cannot make an index when the file has multiple .debug_types sections"));
18925 if (stat (objfile
->name
, &st
) < 0)
18926 perror_with_name (objfile
->name
);
18928 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
18929 INDEX_SUFFIX
, (char *) NULL
);
18930 cleanup
= make_cleanup (xfree
, filename
);
18932 out_file
= fopen (filename
, "wb");
18934 error (_("Can't open `%s' for writing"), filename
);
18936 cleanup_filename
= filename
;
18937 make_cleanup (unlink_if_set
, &cleanup_filename
);
18939 symtab
= create_mapped_symtab ();
18940 make_cleanup (cleanup_mapped_symtab
, symtab
);
18942 obstack_init (&addr_obstack
);
18943 make_cleanup_obstack_free (&addr_obstack
);
18945 obstack_init (&cu_list
);
18946 make_cleanup_obstack_free (&cu_list
);
18948 obstack_init (&types_cu_list
);
18949 make_cleanup_obstack_free (&types_cu_list
);
18951 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
18952 NULL
, xcalloc
, xfree
);
18953 make_cleanup_htab_delete (psyms_seen
);
18955 /* While we're scanning CU's create a table that maps a psymtab pointer
18956 (which is what addrmap records) to its index (which is what is recorded
18957 in the index file). This will later be needed to write the address
18959 cu_index_htab
= htab_create_alloc (100,
18960 hash_psymtab_cu_index
,
18961 eq_psymtab_cu_index
,
18962 NULL
, xcalloc
, xfree
);
18963 make_cleanup_htab_delete (cu_index_htab
);
18964 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
18965 xmalloc (sizeof (struct psymtab_cu_index_map
)
18966 * dwarf2_per_objfile
->n_comp_units
);
18967 make_cleanup (xfree
, psymtab_cu_index_map
);
18969 /* The CU list is already sorted, so we don't need to do additional
18970 work here. Also, the debug_types entries do not appear in
18971 all_comp_units, but only in their own hash table. */
18972 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
18974 struct dwarf2_per_cu_data
*per_cu
18975 = dwarf2_per_objfile
->all_comp_units
[i
];
18976 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18978 struct psymtab_cu_index_map
*map
;
18981 if (psymtab
->user
== NULL
)
18982 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
18984 map
= &psymtab_cu_index_map
[i
];
18985 map
->psymtab
= psymtab
;
18987 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
18988 gdb_assert (slot
!= NULL
);
18989 gdb_assert (*slot
== NULL
);
18992 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18993 per_cu
->offset
.sect_off
);
18994 obstack_grow (&cu_list
, val
, 8);
18995 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
18996 obstack_grow (&cu_list
, val
, 8);
18999 /* Dump the address map. */
19000 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
19002 /* Write out the .debug_type entries, if any. */
19003 if (dwarf2_per_objfile
->signatured_types
)
19005 struct signatured_type_index_data sig_data
;
19007 sig_data
.objfile
= objfile
;
19008 sig_data
.symtab
= symtab
;
19009 sig_data
.types_list
= &types_cu_list
;
19010 sig_data
.psyms_seen
= psyms_seen
;
19011 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
19012 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
19013 write_one_signatured_type
, &sig_data
);
19016 /* Now that we've processed all symbols we can shrink their cu_indices
19018 uniquify_cu_indices (symtab
);
19020 obstack_init (&constant_pool
);
19021 make_cleanup_obstack_free (&constant_pool
);
19022 obstack_init (&symtab_obstack
);
19023 make_cleanup_obstack_free (&symtab_obstack
);
19024 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
19026 obstack_init (&contents
);
19027 make_cleanup_obstack_free (&contents
);
19028 size_of_contents
= 6 * sizeof (offset_type
);
19029 total_len
= size_of_contents
;
19031 /* The version number. */
19032 val
= MAYBE_SWAP (7);
19033 obstack_grow (&contents
, &val
, sizeof (val
));
19035 /* The offset of the CU list from the start of the file. */
19036 val
= MAYBE_SWAP (total_len
);
19037 obstack_grow (&contents
, &val
, sizeof (val
));
19038 total_len
+= obstack_object_size (&cu_list
);
19040 /* The offset of the types CU list from the start of the file. */
19041 val
= MAYBE_SWAP (total_len
);
19042 obstack_grow (&contents
, &val
, sizeof (val
));
19043 total_len
+= obstack_object_size (&types_cu_list
);
19045 /* The offset of the address table from the start of the file. */
19046 val
= MAYBE_SWAP (total_len
);
19047 obstack_grow (&contents
, &val
, sizeof (val
));
19048 total_len
+= obstack_object_size (&addr_obstack
);
19050 /* The offset of the symbol table from the start of the file. */
19051 val
= MAYBE_SWAP (total_len
);
19052 obstack_grow (&contents
, &val
, sizeof (val
));
19053 total_len
+= obstack_object_size (&symtab_obstack
);
19055 /* The offset of the constant pool from the start of the file. */
19056 val
= MAYBE_SWAP (total_len
);
19057 obstack_grow (&contents
, &val
, sizeof (val
));
19058 total_len
+= obstack_object_size (&constant_pool
);
19060 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
19062 write_obstack (out_file
, &contents
);
19063 write_obstack (out_file
, &cu_list
);
19064 write_obstack (out_file
, &types_cu_list
);
19065 write_obstack (out_file
, &addr_obstack
);
19066 write_obstack (out_file
, &symtab_obstack
);
19067 write_obstack (out_file
, &constant_pool
);
19071 /* We want to keep the file, so we set cleanup_filename to NULL
19072 here. See unlink_if_set. */
19073 cleanup_filename
= NULL
;
19075 do_cleanups (cleanup
);
19078 /* Implementation of the `save gdb-index' command.
19080 Note that the file format used by this command is documented in the
19081 GDB manual. Any changes here must be documented there. */
19084 save_gdb_index_command (char *arg
, int from_tty
)
19086 struct objfile
*objfile
;
19089 error (_("usage: save gdb-index DIRECTORY"));
19091 ALL_OBJFILES (objfile
)
19095 /* If the objfile does not correspond to an actual file, skip it. */
19096 if (stat (objfile
->name
, &st
) < 0)
19099 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19100 if (dwarf2_per_objfile
)
19102 volatile struct gdb_exception except
;
19104 TRY_CATCH (except
, RETURN_MASK_ERROR
)
19106 write_psymtabs_to_index (objfile
, arg
);
19108 if (except
.reason
< 0)
19109 exception_fprintf (gdb_stderr
, except
,
19110 _("Error while writing index for `%s': "),
19118 int dwarf2_always_disassemble
;
19121 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
19122 struct cmd_list_element
*c
, const char *value
)
19124 fprintf_filtered (file
,
19125 _("Whether to always disassemble "
19126 "DWARF expressions is %s.\n"),
19131 show_check_physname (struct ui_file
*file
, int from_tty
,
19132 struct cmd_list_element
*c
, const char *value
)
19134 fprintf_filtered (file
,
19135 _("Whether to check \"physname\" is %s.\n"),
19139 void _initialize_dwarf2_read (void);
19142 _initialize_dwarf2_read (void)
19144 struct cmd_list_element
*c
;
19146 dwarf2_objfile_data_key
19147 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
19149 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
19150 Set DWARF 2 specific variables.\n\
19151 Configure DWARF 2 variables such as the cache size"),
19152 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
19153 0/*allow-unknown*/, &maintenance_set_cmdlist
);
19155 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
19156 Show DWARF 2 specific variables\n\
19157 Show DWARF 2 variables such as the cache size"),
19158 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
19159 0/*allow-unknown*/, &maintenance_show_cmdlist
);
19161 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
19162 &dwarf2_max_cache_age
, _("\
19163 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
19164 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
19165 A higher limit means that cached compilation units will be stored\n\
19166 in memory longer, and more total memory will be used. Zero disables\n\
19167 caching, which can slow down startup."),
19169 show_dwarf2_max_cache_age
,
19170 &set_dwarf2_cmdlist
,
19171 &show_dwarf2_cmdlist
);
19173 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
19174 &dwarf2_always_disassemble
, _("\
19175 Set whether `info address' always disassembles DWARF expressions."), _("\
19176 Show whether `info address' always disassembles DWARF expressions."), _("\
19177 When enabled, DWARF expressions are always printed in an assembly-like\n\
19178 syntax. When disabled, expressions will be printed in a more\n\
19179 conversational style, when possible."),
19181 show_dwarf2_always_disassemble
,
19182 &set_dwarf2_cmdlist
,
19183 &show_dwarf2_cmdlist
);
19185 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
19186 Set debugging of the dwarf2 reader."), _("\
19187 Show debugging of the dwarf2 reader."), _("\
19188 When enabled, debugging messages are printed during dwarf2 reading\n\
19189 and symtab expansion."),
19192 &setdebuglist
, &showdebuglist
);
19194 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
19195 Set debugging of the dwarf2 DIE reader."), _("\
19196 Show debugging of the dwarf2 DIE reader."), _("\
19197 When enabled (non-zero), DIEs are dumped after they are read in.\n\
19198 The value is the maximum depth to print."),
19201 &setdebuglist
, &showdebuglist
);
19203 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
19204 Set cross-checking of \"physname\" code against demangler."), _("\
19205 Show cross-checking of \"physname\" code against demangler."), _("\
19206 When enabled, GDB's internal \"physname\" code is checked against\n\
19208 NULL
, show_check_physname
,
19209 &setdebuglist
, &showdebuglist
);
19211 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
19213 Save a gdb-index file.\n\
19214 Usage: save gdb-index DIRECTORY"),
19216 set_cmd_completer (c
, filename_completer
);