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 unsigned 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 static 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 /* The shared '.dwz' file, if one exists. This is used when the
237 original data was compressed using 'dwz -m'. */
238 struct dwz_file
*dwz_file
;
240 /* A flag indicating wether this objfile has a section loaded at a
242 int has_section_at_zero
;
244 /* True if we are using the mapped index,
245 or we are faking it for OBJF_READNOW's sake. */
246 unsigned char using_index
;
248 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
249 struct mapped_index
*index_table
;
251 /* When using index_table, this keeps track of all quick_file_names entries.
252 TUs can share line table entries with CUs or other TUs, and there can be
253 a lot more TUs than unique line tables, so we maintain a separate table
254 of all line table entries to support the sharing. */
255 htab_t quick_file_names_table
;
257 /* Set during partial symbol reading, to prevent queueing of full
259 int reading_partial_symbols
;
261 /* Table mapping type DIEs to their struct type *.
262 This is NULL if not allocated yet.
263 The mapping is done via (CU/TU signature + DIE offset) -> type. */
264 htab_t die_type_hash
;
266 /* The CUs we recently read. */
267 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
270 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
272 /* Default names of the debugging sections. */
274 /* Note that if the debugging section has been compressed, it might
275 have a name like .zdebug_info. */
277 static const struct dwarf2_debug_sections dwarf2_elf_names
=
279 { ".debug_info", ".zdebug_info" },
280 { ".debug_abbrev", ".zdebug_abbrev" },
281 { ".debug_line", ".zdebug_line" },
282 { ".debug_loc", ".zdebug_loc" },
283 { ".debug_macinfo", ".zdebug_macinfo" },
284 { ".debug_macro", ".zdebug_macro" },
285 { ".debug_str", ".zdebug_str" },
286 { ".debug_ranges", ".zdebug_ranges" },
287 { ".debug_types", ".zdebug_types" },
288 { ".debug_addr", ".zdebug_addr" },
289 { ".debug_frame", ".zdebug_frame" },
290 { ".eh_frame", NULL
},
291 { ".gdb_index", ".zgdb_index" },
295 /* List of DWO sections. */
297 static const struct dwo_section_names
299 struct dwarf2_section_names abbrev_dwo
;
300 struct dwarf2_section_names info_dwo
;
301 struct dwarf2_section_names line_dwo
;
302 struct dwarf2_section_names loc_dwo
;
303 struct dwarf2_section_names macinfo_dwo
;
304 struct dwarf2_section_names macro_dwo
;
305 struct dwarf2_section_names str_dwo
;
306 struct dwarf2_section_names str_offsets_dwo
;
307 struct dwarf2_section_names types_dwo
;
311 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
312 { ".debug_info.dwo", ".zdebug_info.dwo" },
313 { ".debug_line.dwo", ".zdebug_line.dwo" },
314 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
315 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
316 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
317 { ".debug_str.dwo", ".zdebug_str.dwo" },
318 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
319 { ".debug_types.dwo", ".zdebug_types.dwo" },
322 /* local data types */
324 /* The data in a compilation unit header, after target2host
325 translation, looks like this. */
326 struct comp_unit_head
330 unsigned char addr_size
;
331 unsigned char signed_addr_p
;
332 sect_offset abbrev_offset
;
334 /* Size of file offsets; either 4 or 8. */
335 unsigned int offset_size
;
337 /* Size of the length field; either 4 or 12. */
338 unsigned int initial_length_size
;
340 /* Offset to the first byte of this compilation unit header in the
341 .debug_info section, for resolving relative reference dies. */
344 /* Offset to first die in this cu from the start of the cu.
345 This will be the first byte following the compilation unit header. */
346 cu_offset first_die_offset
;
349 /* Type used for delaying computation of method physnames.
350 See comments for compute_delayed_physnames. */
351 struct delayed_method_info
353 /* The type to which the method is attached, i.e., its parent class. */
356 /* The index of the method in the type's function fieldlists. */
359 /* The index of the method in the fieldlist. */
362 /* The name of the DIE. */
365 /* The DIE associated with this method. */
366 struct die_info
*die
;
369 typedef struct delayed_method_info delayed_method_info
;
370 DEF_VEC_O (delayed_method_info
);
372 /* Internal state when decoding a particular compilation unit. */
375 /* The objfile containing this compilation unit. */
376 struct objfile
*objfile
;
378 /* The header of the compilation unit. */
379 struct comp_unit_head header
;
381 /* Base address of this compilation unit. */
382 CORE_ADDR base_address
;
384 /* Non-zero if base_address has been set. */
387 /* The language we are debugging. */
388 enum language language
;
389 const struct language_defn
*language_defn
;
391 const char *producer
;
393 /* The generic symbol table building routines have separate lists for
394 file scope symbols and all all other scopes (local scopes). So
395 we need to select the right one to pass to add_symbol_to_list().
396 We do it by keeping a pointer to the correct list in list_in_scope.
398 FIXME: The original dwarf code just treated the file scope as the
399 first local scope, and all other local scopes as nested local
400 scopes, and worked fine. Check to see if we really need to
401 distinguish these in buildsym.c. */
402 struct pending
**list_in_scope
;
404 /* The abbrev table for this CU.
405 Normally this points to the abbrev table in the objfile.
406 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
407 struct abbrev_table
*abbrev_table
;
409 /* Hash table holding all the loaded partial DIEs
410 with partial_die->offset.SECT_OFF as hash. */
413 /* Storage for things with the same lifetime as this read-in compilation
414 unit, including partial DIEs. */
415 struct obstack comp_unit_obstack
;
417 /* When multiple dwarf2_cu structures are living in memory, this field
418 chains them all together, so that they can be released efficiently.
419 We will probably also want a generation counter so that most-recently-used
420 compilation units are cached... */
421 struct dwarf2_per_cu_data
*read_in_chain
;
423 /* Backchain to our per_cu entry if the tree has been built. */
424 struct dwarf2_per_cu_data
*per_cu
;
426 /* How many compilation units ago was this CU last referenced? */
429 /* A hash table of DIE cu_offset for following references with
430 die_info->offset.sect_off as hash. */
433 /* Full DIEs if read in. */
434 struct die_info
*dies
;
436 /* A set of pointers to dwarf2_per_cu_data objects for compilation
437 units referenced by this one. Only set during full symbol processing;
438 partial symbol tables do not have dependencies. */
441 /* Header data from the line table, during full symbol processing. */
442 struct line_header
*line_header
;
444 /* A list of methods which need to have physnames computed
445 after all type information has been read. */
446 VEC (delayed_method_info
) *method_list
;
448 /* To be copied to symtab->call_site_htab. */
449 htab_t call_site_htab
;
451 /* Non-NULL if this CU came from a DWO file.
452 There is an invariant here that is important to remember:
453 Except for attributes copied from the top level DIE in the "main"
454 (or "stub") file in preparation for reading the DWO file
455 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
456 Either there isn't a DWO file (in which case this is NULL and the point
457 is moot), or there is and either we're not going to read it (in which
458 case this is NULL) or there is and we are reading it (in which case this
460 struct dwo_unit
*dwo_unit
;
462 /* The DW_AT_addr_base attribute if present, zero otherwise
463 (zero is a valid value though).
464 Note this value comes from the stub CU/TU's DIE. */
467 /* The DW_AT_ranges_base attribute if present, zero otherwise
468 (zero is a valid value though).
469 Note this value comes from the stub CU/TU's DIE.
470 Also note that the value is zero in the non-DWO case so this value can
471 be used without needing to know whether DWO files are in use or not. */
472 ULONGEST ranges_base
;
474 /* Mark used when releasing cached dies. */
475 unsigned int mark
: 1;
477 /* This CU references .debug_loc. See the symtab->locations_valid field.
478 This test is imperfect as there may exist optimized debug code not using
479 any location list and still facing inlining issues if handled as
480 unoptimized code. For a future better test see GCC PR other/32998. */
481 unsigned int has_loclist
: 1;
483 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
484 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
485 are valid. This information is cached because profiling CU expansion
486 showed excessive time spent in producer_is_gxx_lt_4_6. */
487 unsigned int checked_producer
: 1;
488 unsigned int producer_is_gxx_lt_4_6
: 1;
489 unsigned int producer_is_icc
: 1;
492 /* Persistent data held for a compilation unit, even when not
493 processing it. We put a pointer to this structure in the
494 read_symtab_private field of the psymtab. */
496 struct dwarf2_per_cu_data
498 /* The start offset and length of this compilation unit.
499 NOTE: Unlike comp_unit_head.length, this length includes
501 If the DIE refers to a DWO file, this is always of the original die,
506 /* Flag indicating this compilation unit will be read in before
507 any of the current compilation units are processed. */
508 unsigned int queued
: 1;
510 /* This flag will be set when reading partial DIEs if we need to load
511 absolutely all DIEs for this compilation unit, instead of just the ones
512 we think are interesting. It gets set if we look for a DIE in the
513 hash table and don't find it. */
514 unsigned int load_all_dies
: 1;
516 /* Non-zero if this CU is from .debug_types. */
517 unsigned int is_debug_types
: 1;
519 /* Non-zero if this CU is from the .dwz file. */
520 unsigned int is_dwz
: 1;
522 /* The section this CU/TU lives in.
523 If the DIE refers to a DWO file, this is always the original die,
525 struct dwarf2_section_info
*info_or_types_section
;
527 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
528 of the CU cache it gets reset to NULL again. */
529 struct dwarf2_cu
*cu
;
531 /* The corresponding objfile.
532 Normally we can get the objfile from dwarf2_per_objfile.
533 However we can enter this file with just a "per_cu" handle. */
534 struct objfile
*objfile
;
536 /* When using partial symbol tables, the 'psymtab' field is active.
537 Otherwise the 'quick' field is active. */
540 /* The partial symbol table associated with this compilation unit,
541 or NULL for unread partial units. */
542 struct partial_symtab
*psymtab
;
544 /* Data needed by the "quick" functions. */
545 struct dwarf2_per_cu_quick_data
*quick
;
550 /* The CUs we import using DW_TAG_imported_unit. This is filled in
551 while reading psymtabs, used to compute the psymtab dependencies,
552 and then cleared. Then it is filled in again while reading full
553 symbols, and only deleted when the objfile is destroyed. */
554 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
556 /* Type units are grouped by their DW_AT_stmt_list entry so that they
557 can share them. If this is a TU, this points to the containing
559 struct type_unit_group
*type_unit_group
;
563 /* Entry in the signatured_types hash table. */
565 struct signatured_type
567 /* The "per_cu" object of this type.
568 N.B.: This is the first member so that it's easy to convert pointers
570 struct dwarf2_per_cu_data per_cu
;
572 /* The type's signature. */
575 /* Offset in the TU of the type's DIE, as read from the TU header.
576 If the definition lives in a DWO file, this value is unusable. */
577 cu_offset type_offset_in_tu
;
579 /* Offset in the section of the type's DIE.
580 If the definition lives in a DWO file, this is the offset in the
581 .debug_types.dwo section.
582 The value is zero until the actual value is known.
583 Zero is otherwise not a valid section offset. */
584 sect_offset type_offset_in_section
;
587 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
588 This includes type_unit_group and quick_file_names. */
590 struct stmt_list_hash
592 /* The DWO unit this table is from or NULL if there is none. */
593 struct dwo_unit
*dwo_unit
;
595 /* Offset in .debug_line or .debug_line.dwo. */
596 sect_offset line_offset
;
599 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
600 an object of this type. */
602 struct type_unit_group
604 /* dwarf2read.c's main "handle" on the symtab.
605 To simplify things we create an artificial CU that "includes" all the
606 type units using this stmt_list so that the rest of the code still has
607 a "per_cu" handle on the symtab.
608 This PER_CU is recognized by having no section. */
609 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
610 struct dwarf2_per_cu_data per_cu
;
614 /* The TUs that share this DW_AT_stmt_list entry.
615 This is added to while parsing type units to build partial symtabs,
616 and is deleted afterwards and not used again. */
617 VEC (dwarf2_per_cu_ptr
) *tus
;
619 /* When reading the line table in "quick" functions, we need a real TU.
620 Any will do, we know they all share the same DW_AT_stmt_list entry.
621 For simplicity's sake, we pick the first one. */
622 struct dwarf2_per_cu_data
*first_tu
;
625 /* The primary symtab.
626 Type units in a group needn't all be defined in the same source file,
627 so we create an essentially anonymous symtab as the primary symtab. */
628 struct symtab
*primary_symtab
;
630 /* The data used to construct the hash key. */
631 struct stmt_list_hash hash
;
633 /* The number of symtabs from the line header.
634 The value here must match line_header.num_file_names. */
635 unsigned int num_symtabs
;
637 /* The symbol tables for this TU (obtained from the files listed in
639 WARNING: The order of entries here must match the order of entries
640 in the line header. After the first TU using this type_unit_group, the
641 line header for the subsequent TUs is recreated from this. This is done
642 because we need to use the same symtabs for each TU using the same
643 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
644 there's no guarantee the line header doesn't have duplicate entries. */
645 struct symtab
**symtabs
;
648 /* These sections are what may appear in a "dwo" file. */
652 struct dwarf2_section_info abbrev
;
653 struct dwarf2_section_info info
;
654 struct dwarf2_section_info line
;
655 struct dwarf2_section_info loc
;
656 struct dwarf2_section_info macinfo
;
657 struct dwarf2_section_info macro
;
658 struct dwarf2_section_info str
;
659 struct dwarf2_section_info str_offsets
;
660 VEC (dwarf2_section_info_def
) *types
;
663 /* Common bits of DWO CUs/TUs. */
667 /* Backlink to the containing struct dwo_file. */
668 struct dwo_file
*dwo_file
;
670 /* The "id" that distinguishes this CU/TU.
671 .debug_info calls this "dwo_id", .debug_types calls this "signature".
672 Since signatures came first, we stick with it for consistency. */
675 /* The section this CU/TU lives in, in the DWO file. */
676 struct dwarf2_section_info
*info_or_types_section
;
678 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
682 /* For types, offset in the type's DIE of the type defined by this TU. */
683 cu_offset type_offset_in_tu
;
686 /* Data for one DWO file. */
690 /* The DW_AT_GNU_dwo_name attribute.
691 We don't manage space for this, it's an attribute. */
692 const char *dwo_name
;
694 /* The bfd, when the file is open. Otherwise this is NULL. */
697 /* Section info for this file. */
698 struct dwo_sections sections
;
700 /* Table of CUs in the file.
701 Each element is a struct dwo_unit. */
704 /* Table of TUs in the file.
705 Each element is a struct dwo_unit. */
709 /* This represents a '.dwz' file. */
713 /* A dwz file can only contain a few sections. */
714 struct dwarf2_section_info abbrev
;
715 struct dwarf2_section_info info
;
716 struct dwarf2_section_info str
;
717 struct dwarf2_section_info line
;
718 struct dwarf2_section_info macro
;
719 struct dwarf2_section_info gdb_index
;
725 /* Struct used to pass misc. parameters to read_die_and_children, et
726 al. which are used for both .debug_info and .debug_types dies.
727 All parameters here are unchanging for the life of the call. This
728 struct exists to abstract away the constant parameters of die reading. */
730 struct die_reader_specs
732 /* die_section->asection->owner. */
735 /* The CU of the DIE we are parsing. */
736 struct dwarf2_cu
*cu
;
738 /* Non-NULL if reading a DWO file. */
739 struct dwo_file
*dwo_file
;
741 /* The section the die comes from.
742 This is either .debug_info or .debug_types, or the .dwo variants. */
743 struct dwarf2_section_info
*die_section
;
745 /* die_section->buffer. */
748 /* The end of the buffer. */
749 const gdb_byte
*buffer_end
;
752 /* Type of function passed to init_cutu_and_read_dies, et.al. */
753 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
755 struct die_info
*comp_unit_die
,
759 /* The line number information for a compilation unit (found in the
760 .debug_line section) begins with a "statement program header",
761 which contains the following information. */
764 unsigned int total_length
;
765 unsigned short version
;
766 unsigned int header_length
;
767 unsigned char minimum_instruction_length
;
768 unsigned char maximum_ops_per_instruction
;
769 unsigned char default_is_stmt
;
771 unsigned char line_range
;
772 unsigned char opcode_base
;
774 /* standard_opcode_lengths[i] is the number of operands for the
775 standard opcode whose value is i. This means that
776 standard_opcode_lengths[0] is unused, and the last meaningful
777 element is standard_opcode_lengths[opcode_base - 1]. */
778 unsigned char *standard_opcode_lengths
;
780 /* The include_directories table. NOTE! These strings are not
781 allocated with xmalloc; instead, they are pointers into
782 debug_line_buffer. If you try to free them, `free' will get
784 unsigned int num_include_dirs
, include_dirs_size
;
787 /* The file_names table. NOTE! These strings are not allocated
788 with xmalloc; instead, they are pointers into debug_line_buffer.
789 Don't try to free them directly. */
790 unsigned int num_file_names
, file_names_size
;
794 unsigned int dir_index
;
795 unsigned int mod_time
;
797 int included_p
; /* Non-zero if referenced by the Line Number Program. */
798 struct symtab
*symtab
; /* The associated symbol table, if any. */
801 /* The start and end of the statement program following this
802 header. These point into dwarf2_per_objfile->line_buffer. */
803 gdb_byte
*statement_program_start
, *statement_program_end
;
806 /* When we construct a partial symbol table entry we only
807 need this much information. */
808 struct partial_die_info
810 /* Offset of this DIE. */
813 /* DWARF-2 tag for this DIE. */
814 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
816 /* Assorted flags describing the data found in this DIE. */
817 unsigned int has_children
: 1;
818 unsigned int is_external
: 1;
819 unsigned int is_declaration
: 1;
820 unsigned int has_type
: 1;
821 unsigned int has_specification
: 1;
822 unsigned int has_pc_info
: 1;
823 unsigned int may_be_inlined
: 1;
825 /* Flag set if the SCOPE field of this structure has been
827 unsigned int scope_set
: 1;
829 /* Flag set if the DIE has a byte_size attribute. */
830 unsigned int has_byte_size
: 1;
832 /* Flag set if any of the DIE's children are template arguments. */
833 unsigned int has_template_arguments
: 1;
835 /* Flag set if fixup_partial_die has been called on this die. */
836 unsigned int fixup_called
: 1;
838 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
839 unsigned int is_dwz
: 1;
841 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
842 unsigned int spec_is_dwz
: 1;
844 /* The name of this DIE. Normally the value of DW_AT_name, but
845 sometimes a default name for unnamed DIEs. */
848 /* The linkage name, if present. */
849 const char *linkage_name
;
851 /* The scope to prepend to our children. This is generally
852 allocated on the comp_unit_obstack, so will disappear
853 when this compilation unit leaves the cache. */
856 /* Some data associated with the partial DIE. The tag determines
857 which field is live. */
860 /* The location description associated with this DIE, if any. */
861 struct dwarf_block
*locdesc
;
862 /* The offset of an import, for DW_TAG_imported_unit. */
866 /* If HAS_PC_INFO, the PC range associated with this DIE. */
870 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
871 DW_AT_sibling, if any. */
872 /* NOTE: This member isn't strictly necessary, read_partial_die could
873 return DW_AT_sibling values to its caller load_partial_dies. */
876 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
877 DW_AT_specification (or DW_AT_abstract_origin or
879 sect_offset spec_offset
;
881 /* Pointers to this DIE's parent, first child, and next sibling,
883 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
886 /* This data structure holds the information of an abbrev. */
889 unsigned int number
; /* number identifying abbrev */
890 enum dwarf_tag tag
; /* dwarf tag */
891 unsigned short has_children
; /* boolean */
892 unsigned short num_attrs
; /* number of attributes */
893 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
894 struct abbrev_info
*next
; /* next in chain */
899 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
900 ENUM_BITFIELD(dwarf_form
) form
: 16;
903 /* Size of abbrev_table.abbrev_hash_table. */
904 #define ABBREV_HASH_SIZE 121
906 /* Top level data structure to contain an abbreviation table. */
910 /* Where the abbrev table came from.
911 This is used as a sanity check when the table is used. */
914 /* Storage for the abbrev table. */
915 struct obstack abbrev_obstack
;
917 /* Hash table of abbrevs.
918 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
919 It could be statically allocated, but the previous code didn't so we
921 struct abbrev_info
**abbrevs
;
924 /* Attributes have a name and a value. */
927 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
928 ENUM_BITFIELD(dwarf_form
) form
: 15;
930 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
931 field should be in u.str (existing only for DW_STRING) but it is kept
932 here for better struct attribute alignment. */
933 unsigned int string_is_canonical
: 1;
938 struct dwarf_block
*blk
;
942 struct signatured_type
*signatured_type
;
947 /* This data structure holds a complete die structure. */
950 /* DWARF-2 tag for this DIE. */
951 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
953 /* Number of attributes */
954 unsigned char num_attrs
;
956 /* True if we're presently building the full type name for the
957 type derived from this DIE. */
958 unsigned char building_fullname
: 1;
963 /* Offset in .debug_info or .debug_types section. */
966 /* The dies in a compilation unit form an n-ary tree. PARENT
967 points to this die's parent; CHILD points to the first child of
968 this node; and all the children of a given node are chained
969 together via their SIBLING fields. */
970 struct die_info
*child
; /* Its first child, if any. */
971 struct die_info
*sibling
; /* Its next sibling, if any. */
972 struct die_info
*parent
; /* Its parent, if any. */
974 /* An array of attributes, with NUM_ATTRS elements. There may be
975 zero, but it's not common and zero-sized arrays are not
976 sufficiently portable C. */
977 struct attribute attrs
[1];
980 /* Get at parts of an attribute structure. */
982 #define DW_STRING(attr) ((attr)->u.str)
983 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
984 #define DW_UNSND(attr) ((attr)->u.unsnd)
985 #define DW_BLOCK(attr) ((attr)->u.blk)
986 #define DW_SND(attr) ((attr)->u.snd)
987 #define DW_ADDR(attr) ((attr)->u.addr)
988 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
990 /* Blocks are a bunch of untyped bytes. */
995 /* Valid only if SIZE is not zero. */
999 #ifndef ATTR_ALLOC_CHUNK
1000 #define ATTR_ALLOC_CHUNK 4
1003 /* Allocate fields for structs, unions and enums in this size. */
1004 #ifndef DW_FIELD_ALLOC_CHUNK
1005 #define DW_FIELD_ALLOC_CHUNK 4
1008 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1009 but this would require a corresponding change in unpack_field_as_long
1011 static int bits_per_byte
= 8;
1013 /* The routines that read and process dies for a C struct or C++ class
1014 pass lists of data member fields and lists of member function fields
1015 in an instance of a field_info structure, as defined below. */
1018 /* List of data member and baseclasses fields. */
1021 struct nextfield
*next
;
1026 *fields
, *baseclasses
;
1028 /* Number of fields (including baseclasses). */
1031 /* Number of baseclasses. */
1034 /* Set if the accesibility of one of the fields is not public. */
1035 int non_public_fields
;
1037 /* Member function fields array, entries are allocated in the order they
1038 are encountered in the object file. */
1041 struct nextfnfield
*next
;
1042 struct fn_field fnfield
;
1046 /* Member function fieldlist array, contains name of possibly overloaded
1047 member function, number of overloaded member functions and a pointer
1048 to the head of the member function field chain. */
1053 struct nextfnfield
*head
;
1057 /* Number of entries in the fnfieldlists array. */
1060 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1061 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1062 struct typedef_field_list
1064 struct typedef_field field
;
1065 struct typedef_field_list
*next
;
1067 *typedef_field_list
;
1068 unsigned typedef_field_list_count
;
1071 /* One item on the queue of compilation units to read in full symbols
1073 struct dwarf2_queue_item
1075 struct dwarf2_per_cu_data
*per_cu
;
1076 enum language pretend_language
;
1077 struct dwarf2_queue_item
*next
;
1080 /* The current queue. */
1081 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1083 /* Loaded secondary compilation units are kept in memory until they
1084 have not been referenced for the processing of this many
1085 compilation units. Set this to zero to disable caching. Cache
1086 sizes of up to at least twenty will improve startup time for
1087 typical inter-CU-reference binaries, at an obvious memory cost. */
1088 static int dwarf2_max_cache_age
= 5;
1090 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1091 struct cmd_list_element
*c
, const char *value
)
1093 fprintf_filtered (file
, _("The upper bound on the age of cached "
1094 "dwarf2 compilation units is %s.\n"),
1099 /* Various complaints about symbol reading that don't abort the process. */
1102 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1104 complaint (&symfile_complaints
,
1105 _("statement list doesn't fit in .debug_line section"));
1109 dwarf2_debug_line_missing_file_complaint (void)
1111 complaint (&symfile_complaints
,
1112 _(".debug_line section has line data without a file"));
1116 dwarf2_debug_line_missing_end_sequence_complaint (void)
1118 complaint (&symfile_complaints
,
1119 _(".debug_line section has line "
1120 "program sequence without an end"));
1124 dwarf2_complex_location_expr_complaint (void)
1126 complaint (&symfile_complaints
, _("location expression too complex"));
1130 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1133 complaint (&symfile_complaints
,
1134 _("const value length mismatch for '%s', got %d, expected %d"),
1139 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1141 complaint (&symfile_complaints
,
1142 _("debug info runs off end of %s section"
1144 section
->asection
->name
,
1145 bfd_get_filename (section
->asection
->owner
));
1149 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1151 complaint (&symfile_complaints
,
1152 _("macro debug info contains a "
1153 "malformed macro definition:\n`%s'"),
1158 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1160 complaint (&symfile_complaints
,
1161 _("invalid attribute class or form for '%s' in '%s'"),
1165 /* local function prototypes */
1167 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1169 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1172 static void dwarf2_find_base_address (struct die_info
*die
,
1173 struct dwarf2_cu
*cu
);
1175 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1177 static void scan_partial_symbols (struct partial_die_info
*,
1178 CORE_ADDR
*, CORE_ADDR
*,
1179 int, struct dwarf2_cu
*);
1181 static void add_partial_symbol (struct partial_die_info
*,
1182 struct dwarf2_cu
*);
1184 static void add_partial_namespace (struct partial_die_info
*pdi
,
1185 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1186 int need_pc
, struct dwarf2_cu
*cu
);
1188 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1189 CORE_ADDR
*highpc
, int need_pc
,
1190 struct dwarf2_cu
*cu
);
1192 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1193 struct dwarf2_cu
*cu
);
1195 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1196 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1197 int need_pc
, struct dwarf2_cu
*cu
);
1199 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1201 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1203 static struct abbrev_info
*abbrev_table_lookup_abbrev
1204 (const struct abbrev_table
*, unsigned int);
1206 static struct abbrev_table
*abbrev_table_read_table
1207 (struct dwarf2_section_info
*, sect_offset
);
1209 static void abbrev_table_free (struct abbrev_table
*);
1211 static void abbrev_table_free_cleanup (void *);
1213 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1214 struct dwarf2_section_info
*);
1216 static void dwarf2_free_abbrev_table (void *);
1218 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1220 static struct partial_die_info
*load_partial_dies
1221 (const struct die_reader_specs
*, gdb_byte
*, int);
1223 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1224 struct partial_die_info
*,
1225 struct abbrev_info
*,
1229 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1230 struct dwarf2_cu
*);
1232 static void fixup_partial_die (struct partial_die_info
*,
1233 struct dwarf2_cu
*);
1235 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1236 struct attribute
*, struct attr_abbrev
*,
1239 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1241 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1243 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1245 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1247 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1249 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1252 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1254 static LONGEST read_checked_initial_length_and_offset
1255 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1256 unsigned int *, unsigned int *);
1258 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1261 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1263 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1266 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1268 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1270 static char *read_indirect_string (bfd
*, gdb_byte
*,
1271 const struct comp_unit_head
*,
1274 static char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1276 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1278 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1280 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1283 static char *read_str_index (const struct die_reader_specs
*reader
,
1284 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1286 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1288 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1289 struct dwarf2_cu
*);
1291 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1294 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1295 struct dwarf2_cu
*cu
);
1297 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1299 static struct die_info
*die_specification (struct die_info
*die
,
1300 struct dwarf2_cu
**);
1302 static void free_line_header (struct line_header
*lh
);
1304 static void add_file_name (struct line_header
*, char *, unsigned int,
1305 unsigned int, unsigned int);
1307 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1308 struct dwarf2_cu
*cu
);
1310 static void dwarf_decode_lines (struct line_header
*, const char *,
1311 struct dwarf2_cu
*, struct partial_symtab
*,
1314 static void dwarf2_start_subfile (char *, const char *, const char *);
1316 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1317 char *, char *, CORE_ADDR
);
1319 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1320 struct dwarf2_cu
*);
1322 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1323 struct dwarf2_cu
*, struct symbol
*);
1325 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1326 struct dwarf2_cu
*);
1328 static void dwarf2_const_value_attr (struct attribute
*attr
,
1331 struct obstack
*obstack
,
1332 struct dwarf2_cu
*cu
, LONGEST
*value
,
1334 struct dwarf2_locexpr_baton
**baton
);
1336 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1338 static int need_gnat_info (struct dwarf2_cu
*);
1340 static struct type
*die_descriptive_type (struct die_info
*,
1341 struct dwarf2_cu
*);
1343 static void set_descriptive_type (struct type
*, struct die_info
*,
1344 struct dwarf2_cu
*);
1346 static struct type
*die_containing_type (struct die_info
*,
1347 struct dwarf2_cu
*);
1349 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1350 struct dwarf2_cu
*);
1352 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1354 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1356 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1358 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1359 const char *suffix
, int physname
,
1360 struct dwarf2_cu
*cu
);
1362 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1364 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1366 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1368 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1370 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1372 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1373 struct dwarf2_cu
*, struct partial_symtab
*);
1375 static int dwarf2_get_pc_bounds (struct die_info
*,
1376 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1377 struct partial_symtab
*);
1379 static void get_scope_pc_bounds (struct die_info
*,
1380 CORE_ADDR
*, CORE_ADDR
*,
1381 struct dwarf2_cu
*);
1383 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1384 CORE_ADDR
, struct dwarf2_cu
*);
1386 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1387 struct dwarf2_cu
*);
1389 static void dwarf2_attach_fields_to_type (struct field_info
*,
1390 struct type
*, struct dwarf2_cu
*);
1392 static void dwarf2_add_member_fn (struct field_info
*,
1393 struct die_info
*, struct type
*,
1394 struct dwarf2_cu
*);
1396 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1398 struct dwarf2_cu
*);
1400 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1402 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1404 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1406 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1408 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1410 static struct type
*read_module_type (struct die_info
*die
,
1411 struct dwarf2_cu
*cu
);
1413 static const char *namespace_name (struct die_info
*die
,
1414 int *is_anonymous
, struct dwarf2_cu
*);
1416 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1418 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1420 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1421 struct dwarf2_cu
*);
1423 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1425 gdb_byte
**new_info_ptr
,
1426 struct die_info
*parent
);
1428 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1430 gdb_byte
**new_info_ptr
,
1431 struct die_info
*parent
);
1433 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1434 struct die_info
**, gdb_byte
*, int *, int);
1436 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1437 struct die_info
**, gdb_byte
*, int *);
1439 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1441 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1444 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1446 static const char *dwarf2_full_name (char *name
,
1447 struct die_info
*die
,
1448 struct dwarf2_cu
*cu
);
1450 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1451 struct dwarf2_cu
**);
1453 static const char *dwarf_tag_name (unsigned int);
1455 static const char *dwarf_attr_name (unsigned int);
1457 static const char *dwarf_form_name (unsigned int);
1459 static char *dwarf_bool_name (unsigned int);
1461 static const char *dwarf_type_encoding_name (unsigned int);
1463 static struct die_info
*sibling_die (struct die_info
*);
1465 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1467 static void dump_die_for_error (struct die_info
*);
1469 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1472 /*static*/ void dump_die (struct die_info
*, int max_level
);
1474 static void store_in_ref_table (struct die_info
*,
1475 struct dwarf2_cu
*);
1477 static int is_ref_attr (struct attribute
*);
1479 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1481 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1483 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1485 struct dwarf2_cu
**);
1487 static struct die_info
*follow_die_ref (struct die_info
*,
1489 struct dwarf2_cu
**);
1491 static struct die_info
*follow_die_sig (struct die_info
*,
1493 struct dwarf2_cu
**);
1495 static struct signatured_type
*lookup_signatured_type_at_offset
1496 (struct objfile
*objfile
,
1497 struct dwarf2_section_info
*section
, sect_offset offset
);
1499 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1501 static void read_signatured_type (struct signatured_type
*);
1503 static struct type_unit_group
*get_type_unit_group
1504 (struct dwarf2_cu
*, struct attribute
*);
1506 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1508 /* memory allocation interface */
1510 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1512 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1514 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1517 static int attr_form_is_block (struct attribute
*);
1519 static int attr_form_is_section_offset (struct attribute
*);
1521 static int attr_form_is_constant (struct attribute
*);
1523 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1524 struct dwarf2_loclist_baton
*baton
,
1525 struct attribute
*attr
);
1527 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1529 struct dwarf2_cu
*cu
);
1531 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1533 struct abbrev_info
*abbrev
);
1535 static void free_stack_comp_unit (void *);
1537 static hashval_t
partial_die_hash (const void *item
);
1539 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1541 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1542 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1544 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1545 struct dwarf2_per_cu_data
*per_cu
);
1547 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1548 struct die_info
*comp_unit_die
,
1549 enum language pretend_language
);
1551 static void free_heap_comp_unit (void *);
1553 static void free_cached_comp_units (void *);
1555 static void age_cached_comp_units (void);
1557 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1559 static struct type
*set_die_type (struct die_info
*, struct type
*,
1560 struct dwarf2_cu
*);
1562 static void create_all_comp_units (struct objfile
*);
1564 static int create_all_type_units (struct objfile
*);
1566 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1569 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1572 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1575 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1576 struct dwarf2_per_cu_data
*);
1578 static void dwarf2_mark (struct dwarf2_cu
*);
1580 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1582 static struct type
*get_die_type_at_offset (sect_offset
,
1583 struct dwarf2_per_cu_data
*per_cu
);
1585 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1587 static void dwarf2_release_queue (void *dummy
);
1589 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1590 enum language pretend_language
);
1592 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1593 struct dwarf2_per_cu_data
*per_cu
,
1594 enum language pretend_language
);
1596 static void process_queue (void);
1598 static void find_file_and_directory (struct die_info
*die
,
1599 struct dwarf2_cu
*cu
,
1600 char **name
, char **comp_dir
);
1602 static char *file_full_name (int file
, struct line_header
*lh
,
1603 const char *comp_dir
);
1605 static gdb_byte
*read_and_check_comp_unit_head
1606 (struct comp_unit_head
*header
,
1607 struct dwarf2_section_info
*section
,
1608 struct dwarf2_section_info
*abbrev_section
, gdb_byte
*info_ptr
,
1609 int is_debug_types_section
);
1611 static void init_cutu_and_read_dies
1612 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1613 int use_existing_cu
, int keep
,
1614 die_reader_func_ftype
*die_reader_func
, void *data
);
1616 static void init_cutu_and_read_dies_simple
1617 (struct dwarf2_per_cu_data
*this_cu
,
1618 die_reader_func_ftype
*die_reader_func
, void *data
);
1620 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1622 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1624 static struct dwo_unit
*lookup_dwo_comp_unit
1625 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1627 static struct dwo_unit
*lookup_dwo_type_unit
1628 (struct signatured_type
*, char *, const char *);
1630 static void free_dwo_file_cleanup (void *);
1632 static void process_cu_includes (void);
1636 /* Convert VALUE between big- and little-endian. */
1638 byte_swap (offset_type value
)
1642 result
= (value
& 0xff) << 24;
1643 result
|= (value
& 0xff00) << 8;
1644 result
|= (value
& 0xff0000) >> 8;
1645 result
|= (value
& 0xff000000) >> 24;
1649 #define MAYBE_SWAP(V) byte_swap (V)
1652 #define MAYBE_SWAP(V) (V)
1653 #endif /* WORDS_BIGENDIAN */
1655 /* The suffix for an index file. */
1656 #define INDEX_SUFFIX ".gdb-index"
1658 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1659 struct dwarf2_cu
*cu
);
1661 /* Try to locate the sections we need for DWARF 2 debugging
1662 information and return true if we have enough to do something.
1663 NAMES points to the dwarf2 section names, or is NULL if the standard
1664 ELF names are used. */
1667 dwarf2_has_info (struct objfile
*objfile
,
1668 const struct dwarf2_debug_sections
*names
)
1670 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1671 if (!dwarf2_per_objfile
)
1673 /* Initialize per-objfile state. */
1674 struct dwarf2_per_objfile
*data
1675 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1677 memset (data
, 0, sizeof (*data
));
1678 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1679 dwarf2_per_objfile
= data
;
1681 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1683 dwarf2_per_objfile
->objfile
= objfile
;
1685 return (dwarf2_per_objfile
->info
.asection
!= NULL
1686 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1689 /* When loading sections, we look either for uncompressed section or for
1690 compressed section names. */
1693 section_is_p (const char *section_name
,
1694 const struct dwarf2_section_names
*names
)
1696 if (names
->normal
!= NULL
1697 && strcmp (section_name
, names
->normal
) == 0)
1699 if (names
->compressed
!= NULL
1700 && strcmp (section_name
, names
->compressed
) == 0)
1705 /* This function is mapped across the sections and remembers the
1706 offset and size of each of the debugging sections we are interested
1710 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1712 const struct dwarf2_debug_sections
*names
;
1715 names
= &dwarf2_elf_names
;
1717 names
= (const struct dwarf2_debug_sections
*) vnames
;
1719 if (section_is_p (sectp
->name
, &names
->info
))
1721 dwarf2_per_objfile
->info
.asection
= sectp
;
1722 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1724 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1726 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1727 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1729 else if (section_is_p (sectp
->name
, &names
->line
))
1731 dwarf2_per_objfile
->line
.asection
= sectp
;
1732 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1734 else if (section_is_p (sectp
->name
, &names
->loc
))
1736 dwarf2_per_objfile
->loc
.asection
= sectp
;
1737 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1739 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1741 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1742 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1744 else if (section_is_p (sectp
->name
, &names
->macro
))
1746 dwarf2_per_objfile
->macro
.asection
= sectp
;
1747 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1749 else if (section_is_p (sectp
->name
, &names
->str
))
1751 dwarf2_per_objfile
->str
.asection
= sectp
;
1752 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1754 else if (section_is_p (sectp
->name
, &names
->addr
))
1756 dwarf2_per_objfile
->addr
.asection
= sectp
;
1757 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1759 else if (section_is_p (sectp
->name
, &names
->frame
))
1761 dwarf2_per_objfile
->frame
.asection
= sectp
;
1762 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1764 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1766 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1768 if (aflag
& SEC_HAS_CONTENTS
)
1770 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1771 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1774 else if (section_is_p (sectp
->name
, &names
->ranges
))
1776 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1777 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1779 else if (section_is_p (sectp
->name
, &names
->types
))
1781 struct dwarf2_section_info type_section
;
1783 memset (&type_section
, 0, sizeof (type_section
));
1784 type_section
.asection
= sectp
;
1785 type_section
.size
= bfd_get_section_size (sectp
);
1787 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1790 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1792 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1793 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1796 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1797 && bfd_section_vma (abfd
, sectp
) == 0)
1798 dwarf2_per_objfile
->has_section_at_zero
= 1;
1801 /* A helper function that decides whether a section is empty,
1805 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1807 return info
->asection
== NULL
|| info
->size
== 0;
1810 /* Read the contents of the section INFO.
1811 OBJFILE is the main object file, but not necessarily the file where
1812 the section comes from. E.g., for DWO files INFO->asection->owner
1813 is the bfd of the DWO file.
1814 If the section is compressed, uncompress it before returning. */
1817 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1819 asection
*sectp
= info
->asection
;
1821 gdb_byte
*buf
, *retbuf
;
1822 unsigned char header
[4];
1826 info
->buffer
= NULL
;
1829 if (dwarf2_section_empty_p (info
))
1832 abfd
= sectp
->owner
;
1834 /* If the section has relocations, we must read it ourselves.
1835 Otherwise we attach it to the BFD. */
1836 if ((sectp
->flags
& SEC_RELOC
) == 0)
1838 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1840 /* We have to cast away const here for historical reasons.
1841 Fixing dwarf2read to be const-correct would be quite nice. */
1842 info
->buffer
= (gdb_byte
*) bytes
;
1846 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1849 /* When debugging .o files, we may need to apply relocations; see
1850 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1851 We never compress sections in .o files, so we only need to
1852 try this when the section is not compressed. */
1853 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1856 info
->buffer
= retbuf
;
1860 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1861 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1862 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1863 bfd_get_filename (abfd
));
1866 /* A helper function that returns the size of a section in a safe way.
1867 If you are positive that the section has been read before using the
1868 size, then it is safe to refer to the dwarf2_section_info object's
1869 "size" field directly. In other cases, you must call this
1870 function, because for compressed sections the size field is not set
1871 correctly until the section has been read. */
1873 static bfd_size_type
1874 dwarf2_section_size (struct objfile
*objfile
,
1875 struct dwarf2_section_info
*info
)
1878 dwarf2_read_section (objfile
, info
);
1882 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1886 dwarf2_get_section_info (struct objfile
*objfile
,
1887 enum dwarf2_section_enum sect
,
1888 asection
**sectp
, gdb_byte
**bufp
,
1889 bfd_size_type
*sizep
)
1891 struct dwarf2_per_objfile
*data
1892 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1893 struct dwarf2_section_info
*info
;
1895 /* We may see an objfile without any DWARF, in which case we just
1906 case DWARF2_DEBUG_FRAME
:
1907 info
= &data
->frame
;
1909 case DWARF2_EH_FRAME
:
1910 info
= &data
->eh_frame
;
1913 gdb_assert_not_reached ("unexpected section");
1916 dwarf2_read_section (objfile
, info
);
1918 *sectp
= info
->asection
;
1919 *bufp
= info
->buffer
;
1920 *sizep
= info
->size
;
1923 /* A helper function to find the sections for a .dwz file. */
1926 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
1928 struct dwz_file
*dwz_file
= arg
;
1930 /* Note that we only support the standard ELF names, because .dwz
1931 is ELF-only (at the time of writing). */
1932 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
1934 dwz_file
->abbrev
.asection
= sectp
;
1935 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
1937 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
1939 dwz_file
->info
.asection
= sectp
;
1940 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
1942 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
1944 dwz_file
->str
.asection
= sectp
;
1945 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
1947 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
1949 dwz_file
->line
.asection
= sectp
;
1950 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
1952 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
1954 dwz_file
->macro
.asection
= sectp
;
1955 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
1957 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
1959 dwz_file
->gdb_index
.asection
= sectp
;
1960 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
1964 /* Open the separate '.dwz' debug file, if needed. Error if the file
1967 static struct dwz_file
*
1968 dwarf2_get_dwz_file (void)
1970 bfd
*abfd
, *dwz_bfd
;
1973 struct cleanup
*cleanup
;
1974 const char *filename
;
1975 struct dwz_file
*result
;
1977 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
1978 return dwarf2_per_objfile
->dwz_file
;
1980 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
1981 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
1982 if (section
== NULL
)
1983 error (_("could not find '.gnu_debugaltlink' section"));
1984 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
1985 error (_("could not read '.gnu_debugaltlink' section: %s"),
1986 bfd_errmsg (bfd_get_error ()));
1987 cleanup
= make_cleanup (xfree
, data
);
1990 if (!IS_ABSOLUTE_PATH (filename
))
1992 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
1995 make_cleanup (xfree
, abs
);
1996 abs
= ldirname (abs
);
1997 make_cleanup (xfree
, abs
);
1999 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2000 make_cleanup (xfree
, rel
);
2004 /* The format is just a NUL-terminated file name, followed by the
2005 build-id. For now, though, we ignore the build-id. */
2006 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2007 if (dwz_bfd
== NULL
)
2008 error (_("could not read '%s': %s"), filename
,
2009 bfd_errmsg (bfd_get_error ()));
2011 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2013 gdb_bfd_unref (dwz_bfd
);
2014 error (_("file '%s' was not usable: %s"), filename
,
2015 bfd_errmsg (bfd_get_error ()));
2018 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2020 result
->dwz_bfd
= dwz_bfd
;
2022 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2024 do_cleanups (cleanup
);
2029 /* DWARF quick_symbols_functions support. */
2031 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2032 unique line tables, so we maintain a separate table of all .debug_line
2033 derived entries to support the sharing.
2034 All the quick functions need is the list of file names. We discard the
2035 line_header when we're done and don't need to record it here. */
2036 struct quick_file_names
2038 /* The data used to construct the hash key. */
2039 struct stmt_list_hash hash
;
2041 /* The number of entries in file_names, real_names. */
2042 unsigned int num_file_names
;
2044 /* The file names from the line table, after being run through
2046 const char **file_names
;
2048 /* The file names from the line table after being run through
2049 gdb_realpath. These are computed lazily. */
2050 const char **real_names
;
2053 /* When using the index (and thus not using psymtabs), each CU has an
2054 object of this type. This is used to hold information needed by
2055 the various "quick" methods. */
2056 struct dwarf2_per_cu_quick_data
2058 /* The file table. This can be NULL if there was no file table
2059 or it's currently not read in.
2060 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2061 struct quick_file_names
*file_names
;
2063 /* The corresponding symbol table. This is NULL if symbols for this
2064 CU have not yet been read. */
2065 struct symtab
*symtab
;
2067 /* A temporary mark bit used when iterating over all CUs in
2068 expand_symtabs_matching. */
2069 unsigned int mark
: 1;
2071 /* True if we've tried to read the file table and found there isn't one.
2072 There will be no point in trying to read it again next time. */
2073 unsigned int no_file_data
: 1;
2076 /* Utility hash function for a stmt_list_hash. */
2079 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2083 if (stmt_list_hash
->dwo_unit
!= NULL
)
2084 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2085 v
+= stmt_list_hash
->line_offset
.sect_off
;
2089 /* Utility equality function for a stmt_list_hash. */
2092 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2093 const struct stmt_list_hash
*rhs
)
2095 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2097 if (lhs
->dwo_unit
!= NULL
2098 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2101 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2104 /* Hash function for a quick_file_names. */
2107 hash_file_name_entry (const void *e
)
2109 const struct quick_file_names
*file_data
= e
;
2111 return hash_stmt_list_entry (&file_data
->hash
);
2114 /* Equality function for a quick_file_names. */
2117 eq_file_name_entry (const void *a
, const void *b
)
2119 const struct quick_file_names
*ea
= a
;
2120 const struct quick_file_names
*eb
= b
;
2122 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2125 /* Delete function for a quick_file_names. */
2128 delete_file_name_entry (void *e
)
2130 struct quick_file_names
*file_data
= e
;
2133 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2135 xfree ((void*) file_data
->file_names
[i
]);
2136 if (file_data
->real_names
)
2137 xfree ((void*) file_data
->real_names
[i
]);
2140 /* The space for the struct itself lives on objfile_obstack,
2141 so we don't free it here. */
2144 /* Create a quick_file_names hash table. */
2147 create_quick_file_names_table (unsigned int nr_initial_entries
)
2149 return htab_create_alloc (nr_initial_entries
,
2150 hash_file_name_entry
, eq_file_name_entry
,
2151 delete_file_name_entry
, xcalloc
, xfree
);
2154 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2155 have to be created afterwards. You should call age_cached_comp_units after
2156 processing PER_CU->CU. dw2_setup must have been already called. */
2159 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2161 if (per_cu
->is_debug_types
)
2162 load_full_type_unit (per_cu
);
2164 load_full_comp_unit (per_cu
, language_minimal
);
2166 gdb_assert (per_cu
->cu
!= NULL
);
2168 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2171 /* Read in the symbols for PER_CU. */
2174 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2176 struct cleanup
*back_to
;
2178 /* Skip type_unit_groups, reading the type units they contain
2179 is handled elsewhere. */
2180 if (IS_TYPE_UNIT_GROUP (per_cu
))
2183 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2185 if (dwarf2_per_objfile
->using_index
2186 ? per_cu
->v
.quick
->symtab
== NULL
2187 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2189 queue_comp_unit (per_cu
, language_minimal
);
2195 /* Age the cache, releasing compilation units that have not
2196 been used recently. */
2197 age_cached_comp_units ();
2199 do_cleanups (back_to
);
2202 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2203 the objfile from which this CU came. Returns the resulting symbol
2206 static struct symtab
*
2207 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2209 gdb_assert (dwarf2_per_objfile
->using_index
);
2210 if (!per_cu
->v
.quick
->symtab
)
2212 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2213 increment_reading_symtab ();
2214 dw2_do_instantiate_symtab (per_cu
);
2215 process_cu_includes ();
2216 do_cleanups (back_to
);
2218 return per_cu
->v
.quick
->symtab
;
2221 /* Return the CU given its index.
2223 This is intended for loops like:
2225 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2226 + dwarf2_per_objfile->n_type_units); ++i)
2228 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2234 static struct dwarf2_per_cu_data
*
2235 dw2_get_cu (int index
)
2237 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2239 index
-= dwarf2_per_objfile
->n_comp_units
;
2240 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2241 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2244 return dwarf2_per_objfile
->all_comp_units
[index
];
2247 /* Return the primary CU given its index.
2248 The difference between this function and dw2_get_cu is in the handling
2249 of type units (TUs). Here we return the type_unit_group object.
2251 This is intended for loops like:
2253 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2254 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2256 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2262 static struct dwarf2_per_cu_data
*
2263 dw2_get_primary_cu (int index
)
2265 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2267 index
-= dwarf2_per_objfile
->n_comp_units
;
2268 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2269 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2272 return dwarf2_per_objfile
->all_comp_units
[index
];
2275 /* A helper function that knows how to read a 64-bit value in a way
2276 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2280 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2282 if (sizeof (ULONGEST
) < 8)
2286 /* Ignore the upper 4 bytes if they are all zero. */
2287 for (i
= 0; i
< 4; ++i
)
2288 if (bytes
[i
+ 4] != 0)
2291 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2294 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2298 /* A helper for create_cus_from_index that handles a given list of
2302 create_cus_from_index_list (struct objfile
*objfile
,
2303 const gdb_byte
*cu_list
, offset_type n_elements
,
2304 struct dwarf2_section_info
*section
,
2310 for (i
= 0; i
< n_elements
; i
+= 2)
2312 struct dwarf2_per_cu_data
*the_cu
;
2313 ULONGEST offset
, length
;
2315 if (!extract_cu_value (cu_list
, &offset
)
2316 || !extract_cu_value (cu_list
+ 8, &length
))
2320 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2321 struct dwarf2_per_cu_data
);
2322 the_cu
->offset
.sect_off
= offset
;
2323 the_cu
->length
= length
;
2324 the_cu
->objfile
= objfile
;
2325 the_cu
->info_or_types_section
= section
;
2326 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2327 struct dwarf2_per_cu_quick_data
);
2328 the_cu
->is_dwz
= is_dwz
;
2329 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2335 /* Read the CU list from the mapped index, and use it to create all
2336 the CU objects for this objfile. Return 0 if something went wrong,
2337 1 if everything went ok. */
2340 create_cus_from_index (struct objfile
*objfile
,
2341 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2342 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2344 struct dwz_file
*dwz
;
2346 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2347 dwarf2_per_objfile
->all_comp_units
2348 = obstack_alloc (&objfile
->objfile_obstack
,
2349 dwarf2_per_objfile
->n_comp_units
2350 * sizeof (struct dwarf2_per_cu_data
*));
2352 if (!create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2353 &dwarf2_per_objfile
->info
, 0, 0))
2356 if (dwz_elements
== 0)
2359 dwz
= dwarf2_get_dwz_file ();
2360 return create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
,
2361 &dwz
->info
, 1, cu_list_elements
/ 2);
2364 /* Create the signatured type hash table from the index. */
2367 create_signatured_type_table_from_index (struct objfile
*objfile
,
2368 struct dwarf2_section_info
*section
,
2369 const gdb_byte
*bytes
,
2370 offset_type elements
)
2373 htab_t sig_types_hash
;
2375 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2376 dwarf2_per_objfile
->all_type_units
2377 = obstack_alloc (&objfile
->objfile_obstack
,
2378 dwarf2_per_objfile
->n_type_units
2379 * sizeof (struct signatured_type
*));
2381 sig_types_hash
= allocate_signatured_type_table (objfile
);
2383 for (i
= 0; i
< elements
; i
+= 3)
2385 struct signatured_type
*sig_type
;
2386 ULONGEST offset
, type_offset_in_tu
, signature
;
2389 if (!extract_cu_value (bytes
, &offset
)
2390 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2392 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2395 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2396 struct signatured_type
);
2397 sig_type
->signature
= signature
;
2398 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2399 sig_type
->per_cu
.is_debug_types
= 1;
2400 sig_type
->per_cu
.info_or_types_section
= section
;
2401 sig_type
->per_cu
.offset
.sect_off
= offset
;
2402 sig_type
->per_cu
.objfile
= objfile
;
2403 sig_type
->per_cu
.v
.quick
2404 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2405 struct dwarf2_per_cu_quick_data
);
2407 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2410 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2413 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2418 /* Read the address map data from the mapped index, and use it to
2419 populate the objfile's psymtabs_addrmap. */
2422 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2424 const gdb_byte
*iter
, *end
;
2425 struct obstack temp_obstack
;
2426 struct addrmap
*mutable_map
;
2427 struct cleanup
*cleanup
;
2430 obstack_init (&temp_obstack
);
2431 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2432 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2434 iter
= index
->address_table
;
2435 end
= iter
+ index
->address_table_size
;
2437 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2441 ULONGEST hi
, lo
, cu_index
;
2442 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2444 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2446 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2449 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2450 dw2_get_cu (cu_index
));
2453 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2454 &objfile
->objfile_obstack
);
2455 do_cleanups (cleanup
);
2458 /* The hash function for strings in the mapped index. This is the same as
2459 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2460 implementation. This is necessary because the hash function is tied to the
2461 format of the mapped index file. The hash values do not have to match with
2464 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2467 mapped_index_string_hash (int index_version
, const void *p
)
2469 const unsigned char *str
= (const unsigned char *) p
;
2473 while ((c
= *str
++) != 0)
2475 if (index_version
>= 5)
2477 r
= r
* 67 + c
- 113;
2483 /* Find a slot in the mapped index INDEX for the object named NAME.
2484 If NAME is found, set *VEC_OUT to point to the CU vector in the
2485 constant pool and return 1. If NAME cannot be found, return 0. */
2488 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2489 offset_type
**vec_out
)
2491 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2493 offset_type slot
, step
;
2494 int (*cmp
) (const char *, const char *);
2496 if (current_language
->la_language
== language_cplus
2497 || current_language
->la_language
== language_java
2498 || current_language
->la_language
== language_fortran
)
2500 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2502 const char *paren
= strchr (name
, '(');
2508 dup
= xmalloc (paren
- name
+ 1);
2509 memcpy (dup
, name
, paren
- name
);
2510 dup
[paren
- name
] = 0;
2512 make_cleanup (xfree
, dup
);
2517 /* Index version 4 did not support case insensitive searches. But the
2518 indices for case insensitive languages are built in lowercase, therefore
2519 simulate our NAME being searched is also lowercased. */
2520 hash
= mapped_index_string_hash ((index
->version
== 4
2521 && case_sensitivity
== case_sensitive_off
2522 ? 5 : index
->version
),
2525 slot
= hash
& (index
->symbol_table_slots
- 1);
2526 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2527 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2531 /* Convert a slot number to an offset into the table. */
2532 offset_type i
= 2 * slot
;
2534 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2536 do_cleanups (back_to
);
2540 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2541 if (!cmp (name
, str
))
2543 *vec_out
= (offset_type
*) (index
->constant_pool
2544 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2545 do_cleanups (back_to
);
2549 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2553 /* A helper function that reads the .gdb_index from SECTION and fills
2554 in MAP. FILENAME is the name of the file containing the section;
2555 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2556 ok to use deprecated sections.
2558 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2559 out parameters that are filled in with information about the CU and
2560 TU lists in the section.
2562 Returns 1 if all went well, 0 otherwise. */
2565 read_index_from_section (struct objfile
*objfile
,
2566 const char *filename
,
2568 struct dwarf2_section_info
*section
,
2569 struct mapped_index
*map
,
2570 const gdb_byte
**cu_list
,
2571 offset_type
*cu_list_elements
,
2572 const gdb_byte
**types_list
,
2573 offset_type
*types_list_elements
)
2576 offset_type version
;
2577 offset_type
*metadata
;
2580 if (dwarf2_section_empty_p (section
))
2583 /* Older elfutils strip versions could keep the section in the main
2584 executable while splitting it for the separate debug info file. */
2585 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2588 dwarf2_read_section (objfile
, section
);
2590 addr
= section
->buffer
;
2591 /* Version check. */
2592 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2593 /* Versions earlier than 3 emitted every copy of a psymbol. This
2594 causes the index to behave very poorly for certain requests. Version 3
2595 contained incomplete addrmap. So, it seems better to just ignore such
2599 static int warning_printed
= 0;
2600 if (!warning_printed
)
2602 warning (_("Skipping obsolete .gdb_index section in %s."),
2604 warning_printed
= 1;
2608 /* Index version 4 uses a different hash function than index version
2611 Versions earlier than 6 did not emit psymbols for inlined
2612 functions. Using these files will cause GDB not to be able to
2613 set breakpoints on inlined functions by name, so we ignore these
2614 indices unless the user has done
2615 "set use-deprecated-index-sections on". */
2616 if (version
< 6 && !deprecated_ok
)
2618 static int warning_printed
= 0;
2619 if (!warning_printed
)
2622 Skipping deprecated .gdb_index section in %s.\n\
2623 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2624 to use the section anyway."),
2626 warning_printed
= 1;
2630 /* Indexes with higher version than the one supported by GDB may be no
2631 longer backward compatible. */
2635 map
->version
= version
;
2636 map
->total_size
= section
->size
;
2638 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2641 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2642 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2646 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2647 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2648 - MAYBE_SWAP (metadata
[i
]))
2652 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2653 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2654 - MAYBE_SWAP (metadata
[i
]));
2657 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2658 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2659 - MAYBE_SWAP (metadata
[i
]))
2660 / (2 * sizeof (offset_type
)));
2663 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2669 /* Read the index file. If everything went ok, initialize the "quick"
2670 elements of all the CUs and return 1. Otherwise, return 0. */
2673 dwarf2_read_index (struct objfile
*objfile
)
2675 struct mapped_index local_map
, *map
;
2676 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2677 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2679 if (!read_index_from_section (objfile
, objfile
->name
,
2680 use_deprecated_index_sections
,
2681 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2682 &cu_list
, &cu_list_elements
,
2683 &types_list
, &types_list_elements
))
2686 /* Don't use the index if it's empty. */
2687 if (local_map
.symbol_table_slots
== 0)
2690 /* If there is a .dwz file, read it so we can get its CU list as
2692 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2694 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2695 struct mapped_index dwz_map
;
2696 const gdb_byte
*dwz_types_ignore
;
2697 offset_type dwz_types_elements_ignore
;
2699 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2701 &dwz
->gdb_index
, &dwz_map
,
2702 &dwz_list
, &dwz_list_elements
,
2704 &dwz_types_elements_ignore
))
2706 warning (_("could not read '.gdb_index' section from %s; skipping"),
2707 bfd_get_filename (dwz
->dwz_bfd
));
2712 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
,
2713 dwz_list
, dwz_list_elements
))
2716 if (types_list_elements
)
2718 struct dwarf2_section_info
*section
;
2720 /* We can only handle a single .debug_types when we have an
2722 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2725 section
= VEC_index (dwarf2_section_info_def
,
2726 dwarf2_per_objfile
->types
, 0);
2728 if (!create_signatured_type_table_from_index (objfile
, section
,
2730 types_list_elements
))
2734 create_addrmap_from_index (objfile
, &local_map
);
2736 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2739 dwarf2_per_objfile
->index_table
= map
;
2740 dwarf2_per_objfile
->using_index
= 1;
2741 dwarf2_per_objfile
->quick_file_names_table
=
2742 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2747 /* A helper for the "quick" functions which sets the global
2748 dwarf2_per_objfile according to OBJFILE. */
2751 dw2_setup (struct objfile
*objfile
)
2753 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2754 gdb_assert (dwarf2_per_objfile
);
2757 /* Reader function for dw2_build_type_unit_groups. */
2760 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2762 struct die_info
*type_unit_die
,
2766 struct dwarf2_cu
*cu
= reader
->cu
;
2767 struct attribute
*attr
;
2768 struct type_unit_group
*tu_group
;
2770 gdb_assert (data
== NULL
);
2775 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2776 /* Call this for its side-effect of creating the associated
2777 struct type_unit_group if it doesn't already exist. */
2778 tu_group
= get_type_unit_group (cu
, attr
);
2781 /* Build dwarf2_per_objfile->type_unit_groups.
2782 This function may be called multiple times. */
2785 dw2_build_type_unit_groups (void)
2787 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2788 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2791 /* die_reader_func for dw2_get_file_names. */
2794 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2796 struct die_info
*comp_unit_die
,
2800 struct dwarf2_cu
*cu
= reader
->cu
;
2801 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2802 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2803 struct dwarf2_per_cu_data
*lh_cu
;
2804 struct line_header
*lh
;
2805 struct attribute
*attr
;
2807 char *name
, *comp_dir
;
2809 struct quick_file_names
*qfn
;
2810 unsigned int line_offset
;
2812 /* Our callers never want to match partial units -- instead they
2813 will match the enclosing full CU. */
2814 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2816 this_cu
->v
.quick
->no_file_data
= 1;
2820 /* If we're reading the line header for TUs, store it in the "per_cu"
2822 if (this_cu
->is_debug_types
)
2824 struct type_unit_group
*tu_group
= data
;
2826 gdb_assert (tu_group
!= NULL
);
2827 lh_cu
= &tu_group
->per_cu
;
2836 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2839 struct quick_file_names find_entry
;
2841 line_offset
= DW_UNSND (attr
);
2843 /* We may have already read in this line header (TU line header sharing).
2844 If we have we're done. */
2845 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2846 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2847 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2848 &find_entry
, INSERT
);
2851 lh_cu
->v
.quick
->file_names
= *slot
;
2855 lh
= dwarf_decode_line_header (line_offset
, cu
);
2859 lh_cu
->v
.quick
->no_file_data
= 1;
2863 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2864 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2865 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2866 gdb_assert (slot
!= NULL
);
2869 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2871 qfn
->num_file_names
= lh
->num_file_names
;
2872 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2873 lh
->num_file_names
* sizeof (char *));
2874 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2875 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2876 qfn
->real_names
= NULL
;
2878 free_line_header (lh
);
2880 lh_cu
->v
.quick
->file_names
= qfn
;
2883 /* A helper for the "quick" functions which attempts to read the line
2884 table for THIS_CU. */
2886 static struct quick_file_names
*
2887 dw2_get_file_names (struct objfile
*objfile
,
2888 struct dwarf2_per_cu_data
*this_cu
)
2890 /* For TUs this should only be called on the parent group. */
2891 if (this_cu
->is_debug_types
)
2892 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2894 if (this_cu
->v
.quick
->file_names
!= NULL
)
2895 return this_cu
->v
.quick
->file_names
;
2896 /* If we know there is no line data, no point in looking again. */
2897 if (this_cu
->v
.quick
->no_file_data
)
2900 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2901 in the stub for CUs, there's is no need to lookup the DWO file.
2902 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2904 if (this_cu
->is_debug_types
)
2906 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2908 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2909 dw2_get_file_names_reader
, tu_group
);
2912 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2914 if (this_cu
->v
.quick
->no_file_data
)
2916 return this_cu
->v
.quick
->file_names
;
2919 /* A helper for the "quick" functions which computes and caches the
2920 real path for a given file name from the line table. */
2923 dw2_get_real_path (struct objfile
*objfile
,
2924 struct quick_file_names
*qfn
, int index
)
2926 if (qfn
->real_names
== NULL
)
2927 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2928 qfn
->num_file_names
, sizeof (char *));
2930 if (qfn
->real_names
[index
] == NULL
)
2931 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2933 return qfn
->real_names
[index
];
2936 static struct symtab
*
2937 dw2_find_last_source_symtab (struct objfile
*objfile
)
2941 dw2_setup (objfile
);
2942 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2943 return dw2_instantiate_symtab (dw2_get_cu (index
));
2946 /* Traversal function for dw2_forget_cached_source_info. */
2949 dw2_free_cached_file_names (void **slot
, void *info
)
2951 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2953 if (file_data
->real_names
)
2957 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2959 xfree ((void*) file_data
->real_names
[i
]);
2960 file_data
->real_names
[i
] = NULL
;
2968 dw2_forget_cached_source_info (struct objfile
*objfile
)
2970 dw2_setup (objfile
);
2972 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2973 dw2_free_cached_file_names
, NULL
);
2976 /* Helper function for dw2_map_symtabs_matching_filename that expands
2977 the symtabs and calls the iterator. */
2980 dw2_map_expand_apply (struct objfile
*objfile
,
2981 struct dwarf2_per_cu_data
*per_cu
,
2983 const char *full_path
, const char *real_path
,
2984 int (*callback
) (struct symtab
*, void *),
2987 struct symtab
*last_made
= objfile
->symtabs
;
2989 /* Don't visit already-expanded CUs. */
2990 if (per_cu
->v
.quick
->symtab
)
2993 /* This may expand more than one symtab, and we want to iterate over
2995 dw2_instantiate_symtab (per_cu
);
2997 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2998 objfile
->symtabs
, last_made
);
3001 /* Implementation of the map_symtabs_matching_filename method. */
3004 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3005 const char *full_path
, const char *real_path
,
3006 int (*callback
) (struct symtab
*, void *),
3010 const char *name_basename
= lbasename (name
);
3011 int name_len
= strlen (name
);
3012 int is_abs
= IS_ABSOLUTE_PATH (name
);
3014 dw2_setup (objfile
);
3016 dw2_build_type_unit_groups ();
3018 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3019 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3022 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3023 struct quick_file_names
*file_data
;
3025 /* We only need to look at symtabs not already expanded. */
3026 if (per_cu
->v
.quick
->symtab
)
3029 file_data
= dw2_get_file_names (objfile
, per_cu
);
3030 if (file_data
== NULL
)
3033 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3035 const char *this_name
= file_data
->file_names
[j
];
3037 if (FILENAME_CMP (name
, this_name
) == 0
3038 || (!is_abs
&& compare_filenames_for_search (this_name
,
3041 if (dw2_map_expand_apply (objfile
, per_cu
,
3042 name
, full_path
, real_path
,
3047 /* Before we invoke realpath, which can get expensive when many
3048 files are involved, do a quick comparison of the basenames. */
3049 if (! basenames_may_differ
3050 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3053 if (full_path
!= NULL
)
3055 const char *this_real_name
= dw2_get_real_path (objfile
,
3058 if (this_real_name
!= NULL
3059 && (FILENAME_CMP (full_path
, this_real_name
) == 0
3061 && compare_filenames_for_search (this_real_name
,
3064 if (dw2_map_expand_apply (objfile
, per_cu
,
3065 name
, full_path
, real_path
,
3071 if (real_path
!= NULL
)
3073 const char *this_real_name
= dw2_get_real_path (objfile
,
3076 if (this_real_name
!= NULL
3077 && (FILENAME_CMP (real_path
, this_real_name
) == 0
3079 && compare_filenames_for_search (this_real_name
,
3082 if (dw2_map_expand_apply (objfile
, per_cu
,
3083 name
, full_path
, real_path
,
3094 static struct symtab
*
3095 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3096 const char *name
, domain_enum domain
)
3098 /* We do all the work in the pre_expand_symtabs_matching hook
3103 /* A helper function that expands all symtabs that hold an object
3104 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
3105 symbols in block BLOCK_KIND. */
3108 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
3109 int want_specific_block
,
3110 enum block_enum block_kind
,
3111 const char *name
, domain_enum domain
)
3113 struct mapped_index
*index
;
3115 dw2_setup (objfile
);
3117 index
= dwarf2_per_objfile
->index_table
;
3119 /* index_table is NULL if OBJF_READNOW. */
3124 if (find_slot_in_mapped_hash (index
, name
, &vec
))
3126 offset_type i
, len
= MAYBE_SWAP (*vec
);
3127 for (i
= 0; i
< len
; ++i
)
3129 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
3130 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3131 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3132 int want_static
= block_kind
!= GLOBAL_BLOCK
;
3133 /* This value is only valid for index versions >= 7. */
3134 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3135 gdb_index_symbol_kind symbol_kind
=
3136 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3138 if (want_specific_block
3139 && index
->version
>= 7
3140 && want_static
!= is_static
)
3143 /* Only check the symbol's kind if it has one.
3144 Indices prior to version 7 don't record it. */
3145 if (index
->version
>= 7)
3150 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3151 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3152 /* Some types are also in VAR_DOMAIN. */
3153 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3157 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3161 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3169 dw2_instantiate_symtab (per_cu
);
3176 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
3177 enum block_enum block_kind
, const char *name
,
3180 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
3184 dw2_print_stats (struct objfile
*objfile
)
3188 dw2_setup (objfile
);
3190 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3191 + dwarf2_per_objfile
->n_type_units
); ++i
)
3193 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3195 if (!per_cu
->v
.quick
->symtab
)
3198 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3202 dw2_dump (struct objfile
*objfile
)
3204 /* Nothing worth printing. */
3208 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3209 struct section_offsets
*delta
)
3211 /* There's nothing to relocate here. */
3215 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3216 const char *func_name
)
3218 /* Note: It doesn't matter what we pass for block_kind here. */
3219 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
3224 dw2_expand_all_symtabs (struct objfile
*objfile
)
3228 dw2_setup (objfile
);
3230 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3231 + dwarf2_per_objfile
->n_type_units
); ++i
)
3233 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3235 dw2_instantiate_symtab (per_cu
);
3240 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3241 const char *filename
)
3245 dw2_setup (objfile
);
3247 /* We don't need to consider type units here.
3248 This is only called for examining code, e.g. expand_line_sal.
3249 There can be an order of magnitude (or more) more type units
3250 than comp units, and we avoid them if we can. */
3252 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3255 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3256 struct quick_file_names
*file_data
;
3258 /* We only need to look at symtabs not already expanded. */
3259 if (per_cu
->v
.quick
->symtab
)
3262 file_data
= dw2_get_file_names (objfile
, per_cu
);
3263 if (file_data
== NULL
)
3266 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3268 const char *this_name
= file_data
->file_names
[j
];
3269 if (FILENAME_CMP (this_name
, filename
) == 0)
3271 dw2_instantiate_symtab (per_cu
);
3278 /* A helper function for dw2_find_symbol_file that finds the primary
3279 file name for a given CU. This is a die_reader_func. */
3282 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3284 struct die_info
*comp_unit_die
,
3288 const char **result_ptr
= data
;
3289 struct dwarf2_cu
*cu
= reader
->cu
;
3290 struct attribute
*attr
;
3292 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3296 *result_ptr
= DW_STRING (attr
);
3300 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3302 struct dwarf2_per_cu_data
*per_cu
;
3304 struct quick_file_names
*file_data
;
3305 const char *filename
;
3307 dw2_setup (objfile
);
3309 /* index_table is NULL if OBJF_READNOW. */
3310 if (!dwarf2_per_objfile
->index_table
)
3314 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3316 struct blockvector
*bv
= BLOCKVECTOR (s
);
3317 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3318 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3321 return sym
->symtab
->filename
;
3326 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3330 /* Note that this just looks at the very first one named NAME -- but
3331 actually we are looking for a function. find_main_filename
3332 should be rewritten so that it doesn't require a custom hook. It
3333 could just use the ordinary symbol tables. */
3334 /* vec[0] is the length, which must always be >0. */
3335 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3337 if (per_cu
->v
.quick
->symtab
!= NULL
)
3338 return per_cu
->v
.quick
->symtab
->filename
;
3340 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3341 dw2_get_primary_filename_reader
, &filename
);
3347 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3348 struct objfile
*objfile
, int global
,
3349 int (*callback
) (struct block
*,
3350 struct symbol
*, void *),
3351 void *data
, symbol_compare_ftype
*match
,
3352 symbol_compare_ftype
*ordered_compare
)
3354 /* Currently unimplemented; used for Ada. The function can be called if the
3355 current language is Ada for a non-Ada objfile using GNU index. As Ada
3356 does not look for non-Ada symbols this function should just return. */
3360 dw2_expand_symtabs_matching
3361 (struct objfile
*objfile
,
3362 int (*file_matcher
) (const char *, void *),
3363 int (*name_matcher
) (const char *, void *),
3364 enum search_domain kind
,
3369 struct mapped_index
*index
;
3371 dw2_setup (objfile
);
3373 /* index_table is NULL if OBJF_READNOW. */
3374 if (!dwarf2_per_objfile
->index_table
)
3376 index
= dwarf2_per_objfile
->index_table
;
3378 if (file_matcher
!= NULL
)
3380 struct cleanup
*cleanup
;
3381 htab_t visited_found
, visited_not_found
;
3383 dw2_build_type_unit_groups ();
3385 visited_found
= htab_create_alloc (10,
3386 htab_hash_pointer
, htab_eq_pointer
,
3387 NULL
, xcalloc
, xfree
);
3388 cleanup
= make_cleanup_htab_delete (visited_found
);
3389 visited_not_found
= htab_create_alloc (10,
3390 htab_hash_pointer
, htab_eq_pointer
,
3391 NULL
, xcalloc
, xfree
);
3392 make_cleanup_htab_delete (visited_not_found
);
3394 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3395 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3398 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3399 struct quick_file_names
*file_data
;
3402 per_cu
->v
.quick
->mark
= 0;
3404 /* We only need to look at symtabs not already expanded. */
3405 if (per_cu
->v
.quick
->symtab
)
3408 file_data
= dw2_get_file_names (objfile
, per_cu
);
3409 if (file_data
== NULL
)
3412 if (htab_find (visited_not_found
, file_data
) != NULL
)
3414 else if (htab_find (visited_found
, file_data
) != NULL
)
3416 per_cu
->v
.quick
->mark
= 1;
3420 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3422 if (file_matcher (file_data
->file_names
[j
], data
))
3424 per_cu
->v
.quick
->mark
= 1;
3429 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3431 : visited_not_found
,
3436 do_cleanups (cleanup
);
3439 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3441 offset_type idx
= 2 * iter
;
3443 offset_type
*vec
, vec_len
, vec_idx
;
3445 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3448 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3450 if (! (*name_matcher
) (name
, data
))
3453 /* The name was matched, now expand corresponding CUs that were
3455 vec
= (offset_type
*) (index
->constant_pool
3456 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3457 vec_len
= MAYBE_SWAP (vec
[0]);
3458 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3460 struct dwarf2_per_cu_data
*per_cu
;
3461 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3462 gdb_index_symbol_kind symbol_kind
=
3463 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3464 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3466 /* Don't crash on bad data. */
3467 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3468 + dwarf2_per_objfile
->n_type_units
))
3471 /* Only check the symbol's kind if it has one.
3472 Indices prior to version 7 don't record it. */
3473 if (index
->version
>= 7)
3477 case VARIABLES_DOMAIN
:
3478 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3481 case FUNCTIONS_DOMAIN
:
3482 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3486 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3494 per_cu
= dw2_get_cu (cu_index
);
3495 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3496 dw2_instantiate_symtab (per_cu
);
3501 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3504 static struct symtab
*
3505 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3509 if (BLOCKVECTOR (symtab
) != NULL
3510 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3513 if (symtab
->includes
== NULL
)
3516 for (i
= 0; symtab
->includes
[i
]; ++i
)
3518 struct symtab
*s
= symtab
->includes
[i
];
3520 s
= recursively_find_pc_sect_symtab (s
, pc
);
3528 static struct symtab
*
3529 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3530 struct minimal_symbol
*msymbol
,
3532 struct obj_section
*section
,
3535 struct dwarf2_per_cu_data
*data
;
3536 struct symtab
*result
;
3538 dw2_setup (objfile
);
3540 if (!objfile
->psymtabs_addrmap
)
3543 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3547 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3548 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3549 paddress (get_objfile_arch (objfile
), pc
));
3551 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3552 gdb_assert (result
!= NULL
);
3557 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3558 void *data
, int need_fullname
)
3561 struct cleanup
*cleanup
;
3562 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3563 NULL
, xcalloc
, xfree
);
3565 cleanup
= make_cleanup_htab_delete (visited
);
3566 dw2_setup (objfile
);
3568 dw2_build_type_unit_groups ();
3570 /* We can ignore file names coming from already-expanded CUs. */
3571 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3572 + dwarf2_per_objfile
->n_type_units
); ++i
)
3574 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3576 if (per_cu
->v
.quick
->symtab
)
3578 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3581 *slot
= per_cu
->v
.quick
->file_names
;
3585 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3586 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3589 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3590 struct quick_file_names
*file_data
;
3593 /* We only need to look at symtabs not already expanded. */
3594 if (per_cu
->v
.quick
->symtab
)
3597 file_data
= dw2_get_file_names (objfile
, per_cu
);
3598 if (file_data
== NULL
)
3601 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3604 /* Already visited. */
3609 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3611 const char *this_real_name
;
3614 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3616 this_real_name
= NULL
;
3617 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3621 do_cleanups (cleanup
);
3625 dw2_has_symbols (struct objfile
*objfile
)
3630 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3633 dw2_find_last_source_symtab
,
3634 dw2_forget_cached_source_info
,
3635 dw2_map_symtabs_matching_filename
,
3637 dw2_pre_expand_symtabs_matching
,
3641 dw2_expand_symtabs_for_function
,
3642 dw2_expand_all_symtabs
,
3643 dw2_expand_symtabs_with_filename
,
3644 dw2_find_symbol_file
,
3645 dw2_map_matching_symbols
,
3646 dw2_expand_symtabs_matching
,
3647 dw2_find_pc_sect_symtab
,
3648 dw2_map_symbol_filenames
3651 /* Initialize for reading DWARF for this objfile. Return 0 if this
3652 file will use psymtabs, or 1 if using the GNU index. */
3655 dwarf2_initialize_objfile (struct objfile
*objfile
)
3657 /* If we're about to read full symbols, don't bother with the
3658 indices. In this case we also don't care if some other debug
3659 format is making psymtabs, because they are all about to be
3661 if ((objfile
->flags
& OBJF_READNOW
))
3665 dwarf2_per_objfile
->using_index
= 1;
3666 create_all_comp_units (objfile
);
3667 create_all_type_units (objfile
);
3668 dwarf2_per_objfile
->quick_file_names_table
=
3669 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3671 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3672 + dwarf2_per_objfile
->n_type_units
); ++i
)
3674 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3676 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3677 struct dwarf2_per_cu_quick_data
);
3680 /* Return 1 so that gdb sees the "quick" functions. However,
3681 these functions will be no-ops because we will have expanded
3686 if (dwarf2_read_index (objfile
))
3694 /* Build a partial symbol table. */
3697 dwarf2_build_psymtabs (struct objfile
*objfile
)
3699 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3701 init_psymbol_list (objfile
, 1024);
3704 dwarf2_build_psymtabs_hard (objfile
);
3707 /* Return the total length of the CU described by HEADER. */
3710 get_cu_length (const struct comp_unit_head
*header
)
3712 return header
->initial_length_size
+ header
->length
;
3715 /* Return TRUE if OFFSET is within CU_HEADER. */
3718 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3720 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3721 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3723 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3726 /* Find the base address of the compilation unit for range lists and
3727 location lists. It will normally be specified by DW_AT_low_pc.
3728 In DWARF-3 draft 4, the base address could be overridden by
3729 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3730 compilation units with discontinuous ranges. */
3733 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3735 struct attribute
*attr
;
3738 cu
->base_address
= 0;
3740 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3743 cu
->base_address
= DW_ADDR (attr
);
3748 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3751 cu
->base_address
= DW_ADDR (attr
);
3757 /* Read in the comp unit header information from the debug_info at info_ptr.
3758 NOTE: This leaves members offset, first_die_offset to be filled in
3762 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3763 gdb_byte
*info_ptr
, bfd
*abfd
)
3766 unsigned int bytes_read
;
3768 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3769 cu_header
->initial_length_size
= bytes_read
;
3770 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3771 info_ptr
+= bytes_read
;
3772 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3774 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3776 info_ptr
+= bytes_read
;
3777 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3779 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3780 if (signed_addr
< 0)
3781 internal_error (__FILE__
, __LINE__
,
3782 _("read_comp_unit_head: dwarf from non elf file"));
3783 cu_header
->signed_addr_p
= signed_addr
;
3788 /* Helper function that returns the proper abbrev section for
3791 static struct dwarf2_section_info
*
3792 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3794 struct dwarf2_section_info
*abbrev
;
3796 if (this_cu
->is_dwz
)
3797 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3799 abbrev
= &dwarf2_per_objfile
->abbrev
;
3804 /* Subroutine of read_and_check_comp_unit_head and
3805 read_and_check_type_unit_head to simplify them.
3806 Perform various error checking on the header. */
3809 error_check_comp_unit_head (struct comp_unit_head
*header
,
3810 struct dwarf2_section_info
*section
,
3811 struct dwarf2_section_info
*abbrev_section
)
3813 bfd
*abfd
= section
->asection
->owner
;
3814 const char *filename
= bfd_get_filename (abfd
);
3816 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3817 error (_("Dwarf Error: wrong version in compilation unit header "
3818 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3821 if (header
->abbrev_offset
.sect_off
3822 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
3823 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3824 "(offset 0x%lx + 6) [in module %s]"),
3825 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3828 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3829 avoid potential 32-bit overflow. */
3830 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3832 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3833 "(offset 0x%lx + 0) [in module %s]"),
3834 (long) header
->length
, (long) header
->offset
.sect_off
,
3838 /* Read in a CU/TU header and perform some basic error checking.
3839 The contents of the header are stored in HEADER.
3840 The result is a pointer to the start of the first DIE. */
3843 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3844 struct dwarf2_section_info
*section
,
3845 struct dwarf2_section_info
*abbrev_section
,
3847 int is_debug_types_section
)
3849 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3850 bfd
*abfd
= section
->asection
->owner
;
3852 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3854 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3856 /* If we're reading a type unit, skip over the signature and
3857 type_offset fields. */
3858 if (is_debug_types_section
)
3859 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3861 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3863 error_check_comp_unit_head (header
, section
, abbrev_section
);
3868 /* Read in the types comp unit header information from .debug_types entry at
3869 types_ptr. The result is a pointer to one past the end of the header. */
3872 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3873 struct dwarf2_section_info
*section
,
3874 struct dwarf2_section_info
*abbrev_section
,
3876 ULONGEST
*signature
,
3877 cu_offset
*type_offset_in_tu
)
3879 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3880 bfd
*abfd
= section
->asection
->owner
;
3882 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3884 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3886 /* If we're reading a type unit, skip over the signature and
3887 type_offset fields. */
3888 if (signature
!= NULL
)
3889 *signature
= read_8_bytes (abfd
, info_ptr
);
3891 if (type_offset_in_tu
!= NULL
)
3892 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3893 header
->offset_size
);
3894 info_ptr
+= header
->offset_size
;
3896 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3898 error_check_comp_unit_head (header
, section
, abbrev_section
);
3903 /* Fetch the abbreviation table offset from a comp or type unit header. */
3906 read_abbrev_offset (struct dwarf2_section_info
*section
,
3909 bfd
*abfd
= section
->asection
->owner
;
3911 unsigned int length
, initial_length_size
, offset_size
;
3912 sect_offset abbrev_offset
;
3914 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3915 info_ptr
= section
->buffer
+ offset
.sect_off
;
3916 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3917 offset_size
= initial_length_size
== 4 ? 4 : 8;
3918 info_ptr
+= initial_length_size
+ 2 /*version*/;
3919 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
3920 return abbrev_offset
;
3923 /* Allocate a new partial symtab for file named NAME and mark this new
3924 partial symtab as being an include of PST. */
3927 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3928 struct objfile
*objfile
)
3930 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3932 subpst
->section_offsets
= pst
->section_offsets
;
3933 subpst
->textlow
= 0;
3934 subpst
->texthigh
= 0;
3936 subpst
->dependencies
= (struct partial_symtab
**)
3937 obstack_alloc (&objfile
->objfile_obstack
,
3938 sizeof (struct partial_symtab
*));
3939 subpst
->dependencies
[0] = pst
;
3940 subpst
->number_of_dependencies
= 1;
3942 subpst
->globals_offset
= 0;
3943 subpst
->n_global_syms
= 0;
3944 subpst
->statics_offset
= 0;
3945 subpst
->n_static_syms
= 0;
3946 subpst
->symtab
= NULL
;
3947 subpst
->read_symtab
= pst
->read_symtab
;
3950 /* No private part is necessary for include psymtabs. This property
3951 can be used to differentiate between such include psymtabs and
3952 the regular ones. */
3953 subpst
->read_symtab_private
= NULL
;
3956 /* Read the Line Number Program data and extract the list of files
3957 included by the source file represented by PST. Build an include
3958 partial symtab for each of these included files. */
3961 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3962 struct die_info
*die
,
3963 struct partial_symtab
*pst
)
3965 struct line_header
*lh
= NULL
;
3966 struct attribute
*attr
;
3968 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3970 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3972 return; /* No linetable, so no includes. */
3974 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3975 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3977 free_line_header (lh
);
3981 hash_signatured_type (const void *item
)
3983 const struct signatured_type
*sig_type
= item
;
3985 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3986 return sig_type
->signature
;
3990 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3992 const struct signatured_type
*lhs
= item_lhs
;
3993 const struct signatured_type
*rhs
= item_rhs
;
3995 return lhs
->signature
== rhs
->signature
;
3998 /* Allocate a hash table for signatured types. */
4001 allocate_signatured_type_table (struct objfile
*objfile
)
4003 return htab_create_alloc_ex (41,
4004 hash_signatured_type
,
4007 &objfile
->objfile_obstack
,
4008 hashtab_obstack_allocate
,
4009 dummy_obstack_deallocate
);
4012 /* A helper function to add a signatured type CU to a table. */
4015 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4017 struct signatured_type
*sigt
= *slot
;
4018 struct signatured_type
***datap
= datum
;
4026 /* Create the hash table of all entries in the .debug_types section.
4027 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
4028 The result is a pointer to the hash table or NULL if there are
4032 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4033 VEC (dwarf2_section_info_def
) *types
)
4035 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4036 htab_t types_htab
= NULL
;
4038 struct dwarf2_section_info
*section
;
4039 struct dwarf2_section_info
*abbrev_section
;
4041 if (VEC_empty (dwarf2_section_info_def
, types
))
4044 abbrev_section
= (dwo_file
!= NULL
4045 ? &dwo_file
->sections
.abbrev
4046 : &dwarf2_per_objfile
->abbrev
);
4048 if (dwarf2_read_debug
)
4049 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4050 dwo_file
? ".dwo" : "",
4051 bfd_get_filename (abbrev_section
->asection
->owner
));
4054 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4058 gdb_byte
*info_ptr
, *end_ptr
;
4059 struct dwarf2_section_info
*abbrev_section
;
4061 dwarf2_read_section (objfile
, section
);
4062 info_ptr
= section
->buffer
;
4064 if (info_ptr
== NULL
)
4067 /* We can't set abfd until now because the section may be empty or
4068 not present, in which case section->asection will be NULL. */
4069 abfd
= section
->asection
->owner
;
4072 abbrev_section
= &dwo_file
->sections
.abbrev
;
4074 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4076 if (types_htab
== NULL
)
4079 types_htab
= allocate_dwo_unit_table (objfile
);
4081 types_htab
= allocate_signatured_type_table (objfile
);
4084 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4085 because we don't need to read any dies: the signature is in the
4088 end_ptr
= info_ptr
+ section
->size
;
4089 while (info_ptr
< end_ptr
)
4092 cu_offset type_offset_in_tu
;
4094 struct signatured_type
*sig_type
;
4095 struct dwo_unit
*dwo_tu
;
4097 gdb_byte
*ptr
= info_ptr
;
4098 struct comp_unit_head header
;
4099 unsigned int length
;
4101 offset
.sect_off
= ptr
- section
->buffer
;
4103 /* We need to read the type's signature in order to build the hash
4104 table, but we don't need anything else just yet. */
4106 ptr
= read_and_check_type_unit_head (&header
, section
,
4107 abbrev_section
, ptr
,
4108 &signature
, &type_offset_in_tu
);
4110 length
= get_cu_length (&header
);
4112 /* Skip dummy type units. */
4113 if (ptr
>= info_ptr
+ length
4114 || peek_abbrev_code (abfd
, ptr
) == 0)
4123 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4125 dwo_tu
->dwo_file
= dwo_file
;
4126 dwo_tu
->signature
= signature
;
4127 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4128 dwo_tu
->info_or_types_section
= section
;
4129 dwo_tu
->offset
= offset
;
4130 dwo_tu
->length
= length
;
4134 /* N.B.: type_offset is not usable if this type uses a DWO file.
4135 The real type_offset is in the DWO file. */
4137 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4138 struct signatured_type
);
4139 sig_type
->signature
= signature
;
4140 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4141 sig_type
->per_cu
.objfile
= objfile
;
4142 sig_type
->per_cu
.is_debug_types
= 1;
4143 sig_type
->per_cu
.info_or_types_section
= section
;
4144 sig_type
->per_cu
.offset
= offset
;
4145 sig_type
->per_cu
.length
= length
;
4148 slot
= htab_find_slot (types_htab
,
4149 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4151 gdb_assert (slot
!= NULL
);
4154 sect_offset dup_offset
;
4158 const struct dwo_unit
*dup_tu
= *slot
;
4160 dup_offset
= dup_tu
->offset
;
4164 const struct signatured_type
*dup_tu
= *slot
;
4166 dup_offset
= dup_tu
->per_cu
.offset
;
4169 complaint (&symfile_complaints
,
4170 _("debug type entry at offset 0x%x is duplicate to the "
4171 "entry at offset 0x%x, signature 0x%s"),
4172 offset
.sect_off
, dup_offset
.sect_off
,
4173 phex (signature
, sizeof (signature
)));
4175 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4177 if (dwarf2_read_debug
)
4178 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4180 phex (signature
, sizeof (signature
)));
4189 /* Create the hash table of all entries in the .debug_types section,
4190 and initialize all_type_units.
4191 The result is zero if there is an error (e.g. missing .debug_types section),
4192 otherwise non-zero. */
4195 create_all_type_units (struct objfile
*objfile
)
4198 struct signatured_type
**iter
;
4200 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4201 if (types_htab
== NULL
)
4203 dwarf2_per_objfile
->signatured_types
= NULL
;
4207 dwarf2_per_objfile
->signatured_types
= types_htab
;
4209 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4210 dwarf2_per_objfile
->all_type_units
4211 = obstack_alloc (&objfile
->objfile_obstack
,
4212 dwarf2_per_objfile
->n_type_units
4213 * sizeof (struct signatured_type
*));
4214 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4215 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4216 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4217 == dwarf2_per_objfile
->n_type_units
);
4222 /* Lookup a signature based type for DW_FORM_ref_sig8.
4223 Returns NULL if signature SIG is not present in the table. */
4225 static struct signatured_type
*
4226 lookup_signatured_type (ULONGEST sig
)
4228 struct signatured_type find_entry
, *entry
;
4230 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4232 complaint (&symfile_complaints
,
4233 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4237 find_entry
.signature
= sig
;
4238 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4242 /* Low level DIE reading support. */
4244 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4247 init_cu_die_reader (struct die_reader_specs
*reader
,
4248 struct dwarf2_cu
*cu
,
4249 struct dwarf2_section_info
*section
,
4250 struct dwo_file
*dwo_file
)
4252 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4253 reader
->abfd
= section
->asection
->owner
;
4255 reader
->dwo_file
= dwo_file
;
4256 reader
->die_section
= section
;
4257 reader
->buffer
= section
->buffer
;
4258 reader
->buffer_end
= section
->buffer
+ section
->size
;
4261 /* Initialize a CU (or TU) and read its DIEs.
4262 If the CU defers to a DWO file, read the DWO file as well.
4264 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4265 Otherwise the table specified in the comp unit header is read in and used.
4266 This is an optimization for when we already have the abbrev table.
4268 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4269 Otherwise, a new CU is allocated with xmalloc.
4271 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4272 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4274 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4275 linker) then DIE_READER_FUNC will not get called. */
4278 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4279 struct abbrev_table
*abbrev_table
,
4280 int use_existing_cu
, int keep
,
4281 die_reader_func_ftype
*die_reader_func
,
4284 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4285 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4286 bfd
*abfd
= section
->asection
->owner
;
4287 struct dwarf2_cu
*cu
;
4288 gdb_byte
*begin_info_ptr
, *info_ptr
;
4289 struct die_reader_specs reader
;
4290 struct die_info
*comp_unit_die
;
4292 struct attribute
*attr
;
4293 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4294 struct signatured_type
*sig_type
= NULL
;
4295 struct dwarf2_section_info
*abbrev_section
;
4296 /* Non-zero if CU currently points to a DWO file and we need to
4297 reread it. When this happens we need to reread the skeleton die
4298 before we can reread the DWO file. */
4299 int rereading_dwo_cu
= 0;
4301 if (dwarf2_die_debug
)
4302 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4303 this_cu
->is_debug_types
? "type" : "comp",
4304 this_cu
->offset
.sect_off
);
4306 if (use_existing_cu
)
4309 cleanups
= make_cleanup (null_cleanup
, NULL
);
4311 /* This is cheap if the section is already read in. */
4312 dwarf2_read_section (objfile
, section
);
4314 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4316 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4318 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4322 /* If this CU is from a DWO file we need to start over, we need to
4323 refetch the attributes from the skeleton CU.
4324 This could be optimized by retrieving those attributes from when we
4325 were here the first time: the previous comp_unit_die was stored in
4326 comp_unit_obstack. But there's no data yet that we need this
4328 if (cu
->dwo_unit
!= NULL
)
4329 rereading_dwo_cu
= 1;
4333 /* If !use_existing_cu, this_cu->cu must be NULL. */
4334 gdb_assert (this_cu
->cu
== NULL
);
4336 cu
= xmalloc (sizeof (*cu
));
4337 init_one_comp_unit (cu
, this_cu
);
4339 /* If an error occurs while loading, release our storage. */
4340 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4343 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4345 /* We already have the header, there's no need to read it in again. */
4346 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4350 if (this_cu
->is_debug_types
)
4353 cu_offset type_offset_in_tu
;
4355 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4356 abbrev_section
, info_ptr
,
4358 &type_offset_in_tu
);
4360 /* Since per_cu is the first member of struct signatured_type,
4361 we can go from a pointer to one to a pointer to the other. */
4362 sig_type
= (struct signatured_type
*) this_cu
;
4363 gdb_assert (sig_type
->signature
== signature
);
4364 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4365 == type_offset_in_tu
.cu_off
);
4366 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4368 /* LENGTH has not been set yet for type units if we're
4369 using .gdb_index. */
4370 this_cu
->length
= get_cu_length (&cu
->header
);
4372 /* Establish the type offset that can be used to lookup the type. */
4373 sig_type
->type_offset_in_section
.sect_off
=
4374 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4378 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4382 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4383 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4387 /* Skip dummy compilation units. */
4388 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4389 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4391 do_cleanups (cleanups
);
4395 /* If we don't have them yet, read the abbrevs for this compilation unit.
4396 And if we need to read them now, make sure they're freed when we're
4397 done. Note that it's important that if the CU had an abbrev table
4398 on entry we don't free it when we're done: Somewhere up the call stack
4399 it may be in use. */
4400 if (abbrev_table
!= NULL
)
4402 gdb_assert (cu
->abbrev_table
== NULL
);
4403 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4404 == abbrev_table
->offset
.sect_off
);
4405 cu
->abbrev_table
= abbrev_table
;
4407 else if (cu
->abbrev_table
== NULL
)
4409 dwarf2_read_abbrevs (cu
, abbrev_section
);
4410 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4412 else if (rereading_dwo_cu
)
4414 dwarf2_free_abbrev_table (cu
);
4415 dwarf2_read_abbrevs (cu
, abbrev_section
);
4418 /* Read the top level CU/TU die. */
4419 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4420 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4422 /* If we have a DWO stub, process it and then read in the DWO file.
4423 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4424 a DWO CU, that this test will fail. */
4425 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4428 char *dwo_name
= DW_STRING (attr
);
4429 const char *comp_dir_string
;
4430 struct dwo_unit
*dwo_unit
;
4431 ULONGEST signature
; /* Or dwo_id. */
4432 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4433 int i
,num_extra_attrs
;
4434 struct dwarf2_section_info
*dwo_abbrev_section
;
4437 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4438 " has children (offset 0x%x) [in module %s]"),
4439 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4441 /* These attributes aren't processed until later:
4442 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4443 However, the attribute is found in the stub which we won't have later.
4444 In order to not impose this complication on the rest of the code,
4445 we read them here and copy them to the DWO CU/TU die. */
4447 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4450 if (! this_cu
->is_debug_types
)
4451 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4452 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4453 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4454 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4455 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4457 /* There should be a DW_AT_addr_base attribute here (if needed).
4458 We need the value before we can process DW_FORM_GNU_addr_index. */
4460 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4462 cu
->addr_base
= DW_UNSND (attr
);
4464 /* There should be a DW_AT_ranges_base attribute here (if needed).
4465 We need the value before we can process DW_AT_ranges. */
4466 cu
->ranges_base
= 0;
4467 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4469 cu
->ranges_base
= DW_UNSND (attr
);
4471 if (this_cu
->is_debug_types
)
4473 gdb_assert (sig_type
!= NULL
);
4474 signature
= sig_type
->signature
;
4478 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4480 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4482 signature
= DW_UNSND (attr
);
4485 /* We may need the comp_dir in order to find the DWO file. */
4486 comp_dir_string
= NULL
;
4488 comp_dir_string
= DW_STRING (comp_dir
);
4490 if (this_cu
->is_debug_types
)
4491 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4493 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4496 if (dwo_unit
== NULL
)
4498 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4499 " with ID %s [in module %s]"),
4500 this_cu
->offset
.sect_off
,
4501 phex (signature
, sizeof (signature
)),
4505 /* Set up for reading the DWO CU/TU. */
4506 cu
->dwo_unit
= dwo_unit
;
4507 section
= dwo_unit
->info_or_types_section
;
4508 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4509 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4510 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4512 if (this_cu
->is_debug_types
)
4516 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4520 gdb_assert (sig_type
->signature
== signature
);
4521 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4522 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4524 /* Establish the type offset that can be used to lookup the type.
4525 For DWO files, we don't know it until now. */
4526 sig_type
->type_offset_in_section
.sect_off
=
4527 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4531 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4534 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4535 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4538 /* Discard the original CU's abbrev table, and read the DWO's. */
4539 if (abbrev_table
== NULL
)
4541 dwarf2_free_abbrev_table (cu
);
4542 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4546 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4547 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4550 /* Read in the die, but leave space to copy over the attributes
4551 from the stub. This has the benefit of simplifying the rest of
4552 the code - all the real work is done here. */
4553 num_extra_attrs
= ((stmt_list
!= NULL
)
4557 + (comp_dir
!= NULL
));
4558 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4559 &has_children
, num_extra_attrs
);
4561 /* Copy over the attributes from the stub to the DWO die. */
4562 i
= comp_unit_die
->num_attrs
;
4563 if (stmt_list
!= NULL
)
4564 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4566 comp_unit_die
->attrs
[i
++] = *low_pc
;
4567 if (high_pc
!= NULL
)
4568 comp_unit_die
->attrs
[i
++] = *high_pc
;
4570 comp_unit_die
->attrs
[i
++] = *ranges
;
4571 if (comp_dir
!= NULL
)
4572 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4573 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4575 /* Skip dummy compilation units. */
4576 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4577 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4579 do_cleanups (cleanups
);
4584 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4586 if (free_cu_cleanup
!= NULL
)
4590 /* We've successfully allocated this compilation unit. Let our
4591 caller clean it up when finished with it. */
4592 discard_cleanups (free_cu_cleanup
);
4594 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4595 So we have to manually free the abbrev table. */
4596 dwarf2_free_abbrev_table (cu
);
4598 /* Link this CU into read_in_chain. */
4599 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4600 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4603 do_cleanups (free_cu_cleanup
);
4606 do_cleanups (cleanups
);
4609 /* Read CU/TU THIS_CU in section SECTION,
4610 but do not follow DW_AT_GNU_dwo_name if present.
4611 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4612 have already done the lookup to find the DWO file).
4614 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4615 THIS_CU->is_debug_types, but nothing else.
4617 We fill in THIS_CU->length.
4619 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4620 linker) then DIE_READER_FUNC will not get called.
4622 THIS_CU->cu is always freed when done.
4623 This is done in order to not leave THIS_CU->cu in a state where we have
4624 to care whether it refers to the "main" CU or the DWO CU. */
4627 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4628 struct dwarf2_section_info
*abbrev_section
,
4629 struct dwo_file
*dwo_file
,
4630 die_reader_func_ftype
*die_reader_func
,
4633 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4634 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4635 bfd
*abfd
= section
->asection
->owner
;
4636 struct dwarf2_cu cu
;
4637 gdb_byte
*begin_info_ptr
, *info_ptr
;
4638 struct die_reader_specs reader
;
4639 struct cleanup
*cleanups
;
4640 struct die_info
*comp_unit_die
;
4643 if (dwarf2_die_debug
)
4644 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4645 this_cu
->is_debug_types
? "type" : "comp",
4646 this_cu
->offset
.sect_off
);
4648 gdb_assert (this_cu
->cu
== NULL
);
4650 /* This is cheap if the section is already read in. */
4651 dwarf2_read_section (objfile
, section
);
4653 init_one_comp_unit (&cu
, this_cu
);
4655 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4657 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4658 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4659 abbrev_section
, info_ptr
,
4660 this_cu
->is_debug_types
);
4662 this_cu
->length
= get_cu_length (&cu
.header
);
4664 /* Skip dummy compilation units. */
4665 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4666 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4668 do_cleanups (cleanups
);
4672 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4673 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4675 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4676 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4678 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4680 do_cleanups (cleanups
);
4683 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4684 does not lookup the specified DWO file.
4685 This cannot be used to read DWO files.
4687 THIS_CU->cu is always freed when done.
4688 This is done in order to not leave THIS_CU->cu in a state where we have
4689 to care whether it refers to the "main" CU or the DWO CU.
4690 We can revisit this if the data shows there's a performance issue. */
4693 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4694 die_reader_func_ftype
*die_reader_func
,
4697 init_cutu_and_read_dies_no_follow (this_cu
,
4698 get_abbrev_section_for_cu (this_cu
),
4700 die_reader_func
, data
);
4703 /* Create a psymtab named NAME and assign it to PER_CU.
4705 The caller must fill in the following details:
4706 dirname, textlow, texthigh. */
4708 static struct partial_symtab
*
4709 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4711 struct objfile
*objfile
= per_cu
->objfile
;
4712 struct partial_symtab
*pst
;
4714 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4716 objfile
->global_psymbols
.next
,
4717 objfile
->static_psymbols
.next
);
4719 pst
->psymtabs_addrmap_supported
= 1;
4721 /* This is the glue that links PST into GDB's symbol API. */
4722 pst
->read_symtab_private
= per_cu
;
4723 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4724 per_cu
->v
.psymtab
= pst
;
4729 /* die_reader_func for process_psymtab_comp_unit. */
4732 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4734 struct die_info
*comp_unit_die
,
4738 struct dwarf2_cu
*cu
= reader
->cu
;
4739 struct objfile
*objfile
= cu
->objfile
;
4740 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4741 struct attribute
*attr
;
4743 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4744 struct partial_symtab
*pst
;
4746 const char *filename
;
4747 int *want_partial_unit_ptr
= data
;
4749 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4750 && (want_partial_unit_ptr
== NULL
4751 || !*want_partial_unit_ptr
))
4754 gdb_assert (! per_cu
->is_debug_types
);
4756 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4758 cu
->list_in_scope
= &file_symbols
;
4760 /* Allocate a new partial symbol table structure. */
4761 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4762 if (attr
== NULL
|| !DW_STRING (attr
))
4765 filename
= DW_STRING (attr
);
4767 pst
= create_partial_symtab (per_cu
, filename
);
4769 /* This must be done before calling dwarf2_build_include_psymtabs. */
4770 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4772 pst
->dirname
= DW_STRING (attr
);
4774 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4776 dwarf2_find_base_address (comp_unit_die
, cu
);
4778 /* Possibly set the default values of LOWPC and HIGHPC from
4780 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4781 &best_highpc
, cu
, pst
);
4782 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4783 /* Store the contiguous range if it is not empty; it can be empty for
4784 CUs with no code. */
4785 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4786 best_lowpc
+ baseaddr
,
4787 best_highpc
+ baseaddr
- 1, pst
);
4789 /* Check if comp unit has_children.
4790 If so, read the rest of the partial symbols from this comp unit.
4791 If not, there's no more debug_info for this comp unit. */
4794 struct partial_die_info
*first_die
;
4795 CORE_ADDR lowpc
, highpc
;
4797 lowpc
= ((CORE_ADDR
) -1);
4798 highpc
= ((CORE_ADDR
) 0);
4800 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4802 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4805 /* If we didn't find a lowpc, set it to highpc to avoid
4806 complaints from `maint check'. */
4807 if (lowpc
== ((CORE_ADDR
) -1))
4810 /* If the compilation unit didn't have an explicit address range,
4811 then use the information extracted from its child dies. */
4815 best_highpc
= highpc
;
4818 pst
->textlow
= best_lowpc
+ baseaddr
;
4819 pst
->texthigh
= best_highpc
+ baseaddr
;
4821 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4822 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4823 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4824 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4825 sort_pst_symbols (pst
);
4827 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4830 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4831 struct dwarf2_per_cu_data
*iter
;
4833 /* Fill in 'dependencies' here; we fill in 'users' in a
4835 pst
->number_of_dependencies
= len
;
4836 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4837 len
* sizeof (struct symtab
*));
4839 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4842 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4844 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4847 /* Get the list of files included in the current compilation unit,
4848 and build a psymtab for each of them. */
4849 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4851 if (dwarf2_read_debug
)
4853 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4855 fprintf_unfiltered (gdb_stdlog
,
4856 "Psymtab for %s unit @0x%x: 0x%s - 0x%s"
4857 ", %d global, %d static syms\n",
4858 per_cu
->is_debug_types
? "type" : "comp",
4859 per_cu
->offset
.sect_off
,
4860 paddress (gdbarch
, pst
->textlow
),
4861 paddress (gdbarch
, pst
->texthigh
),
4862 pst
->n_global_syms
, pst
->n_static_syms
);
4866 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4867 Process compilation unit THIS_CU for a psymtab. */
4870 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4871 int want_partial_unit
)
4873 /* If this compilation unit was already read in, free the
4874 cached copy in order to read it in again. This is
4875 necessary because we skipped some symbols when we first
4876 read in the compilation unit (see load_partial_dies).
4877 This problem could be avoided, but the benefit is unclear. */
4878 if (this_cu
->cu
!= NULL
)
4879 free_one_cached_comp_unit (this_cu
);
4881 gdb_assert (! this_cu
->is_debug_types
);
4882 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4883 process_psymtab_comp_unit_reader
,
4884 &want_partial_unit
);
4886 /* Age out any secondary CUs. */
4887 age_cached_comp_units ();
4891 hash_type_unit_group (const void *item
)
4893 const struct type_unit_group
*tu_group
= item
;
4895 return hash_stmt_list_entry (&tu_group
->hash
);
4899 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4901 const struct type_unit_group
*lhs
= item_lhs
;
4902 const struct type_unit_group
*rhs
= item_rhs
;
4904 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
4907 /* Allocate a hash table for type unit groups. */
4910 allocate_type_unit_groups_table (void)
4912 return htab_create_alloc_ex (3,
4913 hash_type_unit_group
,
4916 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
4917 hashtab_obstack_allocate
,
4918 dummy_obstack_deallocate
);
4921 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4922 partial symtabs. We combine several TUs per psymtab to not let the size
4923 of any one psymtab grow too big. */
4924 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4925 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4927 /* Helper routine for get_type_unit_group.
4928 Create the type_unit_group object used to hold one or more TUs. */
4930 static struct type_unit_group
*
4931 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
4933 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4934 struct dwarf2_per_cu_data
*per_cu
;
4935 struct type_unit_group
*tu_group
;
4937 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4938 struct type_unit_group
);
4939 per_cu
= &tu_group
->per_cu
;
4940 per_cu
->objfile
= objfile
;
4941 per_cu
->is_debug_types
= 1;
4942 per_cu
->s
.type_unit_group
= tu_group
;
4944 if (dwarf2_per_objfile
->using_index
)
4946 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4947 struct dwarf2_per_cu_quick_data
);
4948 tu_group
->t
.first_tu
= cu
->per_cu
;
4952 unsigned int line_offset
= line_offset_struct
.sect_off
;
4953 struct partial_symtab
*pst
;
4956 /* Give the symtab a useful name for debug purposes. */
4957 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
4958 name
= xstrprintf ("<type_units_%d>",
4959 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
4961 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
4963 pst
= create_partial_symtab (per_cu
, name
);
4969 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
4970 tu_group
->hash
.line_offset
= line_offset_struct
;
4975 /* Look up the type_unit_group for type unit CU, and create it if necessary.
4976 STMT_LIST is a DW_AT_stmt_list attribute. */
4978 static struct type_unit_group
*
4979 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
4981 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4982 struct type_unit_group
*tu_group
;
4984 unsigned int line_offset
;
4985 struct type_unit_group type_unit_group_for_lookup
;
4987 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
4989 dwarf2_per_objfile
->type_unit_groups
=
4990 allocate_type_unit_groups_table ();
4993 /* Do we need to create a new group, or can we use an existing one? */
4997 line_offset
= DW_UNSND (stmt_list
);
4998 ++tu_stats
->nr_symtab_sharers
;
5002 /* Ugh, no stmt_list. Rare, but we have to handle it.
5003 We can do various things here like create one group per TU or
5004 spread them over multiple groups to split up the expansion work.
5005 To avoid worst case scenarios (too many groups or too large groups)
5006 we, umm, group them in bunches. */
5007 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5008 | (tu_stats
->nr_stmt_less_type_units
5009 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5010 ++tu_stats
->nr_stmt_less_type_units
;
5013 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5014 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5015 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5016 &type_unit_group_for_lookup
, INSERT
);
5020 gdb_assert (tu_group
!= NULL
);
5024 sect_offset line_offset_struct
;
5026 line_offset_struct
.sect_off
= line_offset
;
5027 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5029 ++tu_stats
->nr_symtabs
;
5035 /* Struct used to sort TUs by their abbreviation table offset. */
5037 struct tu_abbrev_offset
5039 struct signatured_type
*sig_type
;
5040 sect_offset abbrev_offset
;
5043 /* Helper routine for build_type_unit_groups, passed to qsort. */
5046 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5048 const struct tu_abbrev_offset
* const *a
= ap
;
5049 const struct tu_abbrev_offset
* const *b
= bp
;
5050 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5051 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5053 return (aoff
> boff
) - (aoff
< boff
);
5056 /* A helper function to add a type_unit_group to a table. */
5059 add_type_unit_group_to_table (void **slot
, void *datum
)
5061 struct type_unit_group
*tu_group
= *slot
;
5062 struct type_unit_group
***datap
= datum
;
5070 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5071 each one passing FUNC,DATA.
5073 The efficiency is because we sort TUs by the abbrev table they use and
5074 only read each abbrev table once. In one program there are 200K TUs
5075 sharing 8K abbrev tables.
5077 The main purpose of this function is to support building the
5078 dwarf2_per_objfile->type_unit_groups table.
5079 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5080 can collapse the search space by grouping them by stmt_list.
5081 The savings can be significant, in the same program from above the 200K TUs
5082 share 8K stmt_list tables.
5084 FUNC is expected to call get_type_unit_group, which will create the
5085 struct type_unit_group if necessary and add it to
5086 dwarf2_per_objfile->type_unit_groups. */
5089 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5091 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5092 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5093 struct cleanup
*cleanups
;
5094 struct abbrev_table
*abbrev_table
;
5095 sect_offset abbrev_offset
;
5096 struct tu_abbrev_offset
*sorted_by_abbrev
;
5097 struct type_unit_group
**iter
;
5100 /* It's up to the caller to not call us multiple times. */
5101 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5103 if (dwarf2_per_objfile
->n_type_units
== 0)
5106 /* TUs typically share abbrev tables, and there can be way more TUs than
5107 abbrev tables. Sort by abbrev table to reduce the number of times we
5108 read each abbrev table in.
5109 Alternatives are to punt or to maintain a cache of abbrev tables.
5110 This is simpler and efficient enough for now.
5112 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5113 symtab to use). Typically TUs with the same abbrev offset have the same
5114 stmt_list value too so in practice this should work well.
5116 The basic algorithm here is:
5118 sort TUs by abbrev table
5119 for each TU with same abbrev table:
5120 read abbrev table if first user
5121 read TU top level DIE
5122 [IWBN if DWO skeletons had DW_AT_stmt_list]
5125 if (dwarf2_read_debug
)
5126 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5128 /* Sort in a separate table to maintain the order of all_type_units
5129 for .gdb_index: TU indices directly index all_type_units. */
5130 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5131 dwarf2_per_objfile
->n_type_units
);
5132 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5134 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5136 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5137 sorted_by_abbrev
[i
].abbrev_offset
=
5138 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5139 sig_type
->per_cu
.offset
);
5141 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5142 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5143 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5145 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5146 called any number of times, so we don't reset tu_stats here. */
5148 abbrev_offset
.sect_off
= ~(unsigned) 0;
5149 abbrev_table
= NULL
;
5150 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5152 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5154 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5156 /* Switch to the next abbrev table if necessary. */
5157 if (abbrev_table
== NULL
5158 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5160 if (abbrev_table
!= NULL
)
5162 abbrev_table_free (abbrev_table
);
5163 /* Reset to NULL in case abbrev_table_read_table throws
5164 an error: abbrev_table_free_cleanup will get called. */
5165 abbrev_table
= NULL
;
5167 abbrev_offset
= tu
->abbrev_offset
;
5169 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5171 ++tu_stats
->nr_uniq_abbrev_tables
;
5174 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5178 /* Create a vector of pointers to primary type units to make it easy to
5179 iterate over them and CUs. See dw2_get_primary_cu. */
5180 dwarf2_per_objfile
->n_type_unit_groups
=
5181 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5182 dwarf2_per_objfile
->all_type_unit_groups
=
5183 obstack_alloc (&objfile
->objfile_obstack
,
5184 dwarf2_per_objfile
->n_type_unit_groups
5185 * sizeof (struct type_unit_group
*));
5186 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5187 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5188 add_type_unit_group_to_table
, &iter
);
5189 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5190 == dwarf2_per_objfile
->n_type_unit_groups
);
5192 do_cleanups (cleanups
);
5194 if (dwarf2_read_debug
)
5196 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5197 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5198 dwarf2_per_objfile
->n_type_units
);
5199 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5200 tu_stats
->nr_uniq_abbrev_tables
);
5201 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5202 tu_stats
->nr_symtabs
);
5203 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5204 tu_stats
->nr_symtab_sharers
);
5205 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5206 tu_stats
->nr_stmt_less_type_units
);
5210 /* Reader function for build_type_psymtabs. */
5213 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5215 struct die_info
*type_unit_die
,
5219 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5220 struct dwarf2_cu
*cu
= reader
->cu
;
5221 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5222 struct type_unit_group
*tu_group
;
5223 struct attribute
*attr
;
5224 struct partial_die_info
*first_die
;
5225 CORE_ADDR lowpc
, highpc
;
5226 struct partial_symtab
*pst
;
5228 gdb_assert (data
== NULL
);
5233 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5234 tu_group
= get_type_unit_group (cu
, attr
);
5236 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5238 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5239 cu
->list_in_scope
= &file_symbols
;
5240 pst
= create_partial_symtab (per_cu
, "");
5243 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5245 lowpc
= (CORE_ADDR
) -1;
5246 highpc
= (CORE_ADDR
) 0;
5247 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5249 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5250 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5251 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5252 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5253 sort_pst_symbols (pst
);
5256 /* Traversal function for build_type_psymtabs. */
5259 build_type_psymtab_dependencies (void **slot
, void *info
)
5261 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5262 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5263 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5264 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5265 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5266 struct dwarf2_per_cu_data
*iter
;
5269 gdb_assert (len
> 0);
5271 pst
->number_of_dependencies
= len
;
5272 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5273 len
* sizeof (struct psymtab
*));
5275 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5278 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5279 iter
->s
.type_unit_group
= tu_group
;
5282 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5287 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5288 Build partial symbol tables for the .debug_types comp-units. */
5291 build_type_psymtabs (struct objfile
*objfile
)
5293 if (! create_all_type_units (objfile
))
5296 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5298 /* Now that all TUs have been processed we can fill in the dependencies. */
5299 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5300 build_type_psymtab_dependencies
, NULL
);
5303 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5306 psymtabs_addrmap_cleanup (void *o
)
5308 struct objfile
*objfile
= o
;
5310 objfile
->psymtabs_addrmap
= NULL
;
5313 /* Compute the 'user' field for each psymtab in OBJFILE. */
5316 set_partial_user (struct objfile
*objfile
)
5320 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5322 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5323 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5329 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5331 /* Set the 'user' field only if it is not already set. */
5332 if (pst
->dependencies
[j
]->user
== NULL
)
5333 pst
->dependencies
[j
]->user
= pst
;
5338 /* Build the partial symbol table by doing a quick pass through the
5339 .debug_info and .debug_abbrev sections. */
5342 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5344 struct cleanup
*back_to
, *addrmap_cleanup
;
5345 struct obstack temp_obstack
;
5348 if (dwarf2_read_debug
)
5350 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5354 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5356 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5358 /* Any cached compilation units will be linked by the per-objfile
5359 read_in_chain. Make sure to free them when we're done. */
5360 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5362 build_type_psymtabs (objfile
);
5364 create_all_comp_units (objfile
);
5366 /* Create a temporary address map on a temporary obstack. We later
5367 copy this to the final obstack. */
5368 obstack_init (&temp_obstack
);
5369 make_cleanup_obstack_free (&temp_obstack
);
5370 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5371 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5373 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5375 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5377 process_psymtab_comp_unit (per_cu
, 0);
5380 set_partial_user (objfile
);
5382 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5383 &objfile
->objfile_obstack
);
5384 discard_cleanups (addrmap_cleanup
);
5386 do_cleanups (back_to
);
5388 if (dwarf2_read_debug
)
5389 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5393 /* die_reader_func for load_partial_comp_unit. */
5396 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5398 struct die_info
*comp_unit_die
,
5402 struct dwarf2_cu
*cu
= reader
->cu
;
5404 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5406 /* Check if comp unit has_children.
5407 If so, read the rest of the partial symbols from this comp unit.
5408 If not, there's no more debug_info for this comp unit. */
5410 load_partial_dies (reader
, info_ptr
, 0);
5413 /* Load the partial DIEs for a secondary CU into memory.
5414 This is also used when rereading a primary CU with load_all_dies. */
5417 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5419 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5420 load_partial_comp_unit_reader
, NULL
);
5424 read_comp_units_from_section (struct objfile
*objfile
,
5425 struct dwarf2_section_info
*section
,
5426 unsigned int is_dwz
,
5429 struct dwarf2_per_cu_data
***all_comp_units
)
5432 bfd
*abfd
= section
->asection
->owner
;
5434 dwarf2_read_section (objfile
, section
);
5436 info_ptr
= section
->buffer
;
5438 while (info_ptr
< section
->buffer
+ section
->size
)
5440 unsigned int length
, initial_length_size
;
5441 struct dwarf2_per_cu_data
*this_cu
;
5444 offset
.sect_off
= info_ptr
- section
->buffer
;
5446 /* Read just enough information to find out where the next
5447 compilation unit is. */
5448 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5450 /* Save the compilation unit for later lookup. */
5451 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5452 sizeof (struct dwarf2_per_cu_data
));
5453 memset (this_cu
, 0, sizeof (*this_cu
));
5454 this_cu
->offset
= offset
;
5455 this_cu
->length
= length
+ initial_length_size
;
5456 this_cu
->is_dwz
= is_dwz
;
5457 this_cu
->objfile
= objfile
;
5458 this_cu
->info_or_types_section
= section
;
5460 if (*n_comp_units
== *n_allocated
)
5463 *all_comp_units
= xrealloc (*all_comp_units
,
5465 * sizeof (struct dwarf2_per_cu_data
*));
5467 (*all_comp_units
)[*n_comp_units
] = this_cu
;
5470 info_ptr
= info_ptr
+ this_cu
->length
;
5474 /* Create a list of all compilation units in OBJFILE.
5475 This is only done for -readnow and building partial symtabs. */
5478 create_all_comp_units (struct objfile
*objfile
)
5482 struct dwarf2_per_cu_data
**all_comp_units
;
5486 all_comp_units
= xmalloc (n_allocated
5487 * sizeof (struct dwarf2_per_cu_data
*));
5489 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
5490 &n_allocated
, &n_comp_units
, &all_comp_units
);
5492 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
5494 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
5496 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
5497 &n_allocated
, &n_comp_units
,
5501 dwarf2_per_objfile
->all_comp_units
5502 = obstack_alloc (&objfile
->objfile_obstack
,
5503 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5504 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5505 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5506 xfree (all_comp_units
);
5507 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5510 /* Process all loaded DIEs for compilation unit CU, starting at
5511 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5512 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5513 DW_AT_ranges). If NEED_PC is set, then this function will set
5514 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5515 and record the covered ranges in the addrmap. */
5518 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5519 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5521 struct partial_die_info
*pdi
;
5523 /* Now, march along the PDI's, descending into ones which have
5524 interesting children but skipping the children of the other ones,
5525 until we reach the end of the compilation unit. */
5531 fixup_partial_die (pdi
, cu
);
5533 /* Anonymous namespaces or modules have no name but have interesting
5534 children, so we need to look at them. Ditto for anonymous
5537 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5538 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5539 || pdi
->tag
== DW_TAG_imported_unit
)
5543 case DW_TAG_subprogram
:
5544 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5546 case DW_TAG_constant
:
5547 case DW_TAG_variable
:
5548 case DW_TAG_typedef
:
5549 case DW_TAG_union_type
:
5550 if (!pdi
->is_declaration
)
5552 add_partial_symbol (pdi
, cu
);
5555 case DW_TAG_class_type
:
5556 case DW_TAG_interface_type
:
5557 case DW_TAG_structure_type
:
5558 if (!pdi
->is_declaration
)
5560 add_partial_symbol (pdi
, cu
);
5563 case DW_TAG_enumeration_type
:
5564 if (!pdi
->is_declaration
)
5565 add_partial_enumeration (pdi
, cu
);
5567 case DW_TAG_base_type
:
5568 case DW_TAG_subrange_type
:
5569 /* File scope base type definitions are added to the partial
5571 add_partial_symbol (pdi
, cu
);
5573 case DW_TAG_namespace
:
5574 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5577 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5579 case DW_TAG_imported_unit
:
5581 struct dwarf2_per_cu_data
*per_cu
;
5583 /* For now we don't handle imported units in type units. */
5584 if (cu
->per_cu
->is_debug_types
)
5586 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5587 " supported in type units [in module %s]"),
5591 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5595 /* Go read the partial unit, if needed. */
5596 if (per_cu
->v
.psymtab
== NULL
)
5597 process_psymtab_comp_unit (per_cu
, 1);
5599 VEC_safe_push (dwarf2_per_cu_ptr
,
5600 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5608 /* If the die has a sibling, skip to the sibling. */
5610 pdi
= pdi
->die_sibling
;
5614 /* Functions used to compute the fully scoped name of a partial DIE.
5616 Normally, this is simple. For C++, the parent DIE's fully scoped
5617 name is concatenated with "::" and the partial DIE's name. For
5618 Java, the same thing occurs except that "." is used instead of "::".
5619 Enumerators are an exception; they use the scope of their parent
5620 enumeration type, i.e. the name of the enumeration type is not
5621 prepended to the enumerator.
5623 There are two complexities. One is DW_AT_specification; in this
5624 case "parent" means the parent of the target of the specification,
5625 instead of the direct parent of the DIE. The other is compilers
5626 which do not emit DW_TAG_namespace; in this case we try to guess
5627 the fully qualified name of structure types from their members'
5628 linkage names. This must be done using the DIE's children rather
5629 than the children of any DW_AT_specification target. We only need
5630 to do this for structures at the top level, i.e. if the target of
5631 any DW_AT_specification (if any; otherwise the DIE itself) does not
5634 /* Compute the scope prefix associated with PDI's parent, in
5635 compilation unit CU. The result will be allocated on CU's
5636 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5637 field. NULL is returned if no prefix is necessary. */
5639 partial_die_parent_scope (struct partial_die_info
*pdi
,
5640 struct dwarf2_cu
*cu
)
5642 char *grandparent_scope
;
5643 struct partial_die_info
*parent
, *real_pdi
;
5645 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5646 then this means the parent of the specification DIE. */
5649 while (real_pdi
->has_specification
)
5650 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
5651 real_pdi
->spec_is_dwz
, cu
);
5653 parent
= real_pdi
->die_parent
;
5657 if (parent
->scope_set
)
5658 return parent
->scope
;
5660 fixup_partial_die (parent
, cu
);
5662 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5664 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5665 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5666 Work around this problem here. */
5667 if (cu
->language
== language_cplus
5668 && parent
->tag
== DW_TAG_namespace
5669 && strcmp (parent
->name
, "::") == 0
5670 && grandparent_scope
== NULL
)
5672 parent
->scope
= NULL
;
5673 parent
->scope_set
= 1;
5677 if (pdi
->tag
== DW_TAG_enumerator
)
5678 /* Enumerators should not get the name of the enumeration as a prefix. */
5679 parent
->scope
= grandparent_scope
;
5680 else if (parent
->tag
== DW_TAG_namespace
5681 || parent
->tag
== DW_TAG_module
5682 || parent
->tag
== DW_TAG_structure_type
5683 || parent
->tag
== DW_TAG_class_type
5684 || parent
->tag
== DW_TAG_interface_type
5685 || parent
->tag
== DW_TAG_union_type
5686 || parent
->tag
== DW_TAG_enumeration_type
)
5688 if (grandparent_scope
== NULL
)
5689 parent
->scope
= parent
->name
;
5691 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5693 parent
->name
, 0, cu
);
5697 /* FIXME drow/2004-04-01: What should we be doing with
5698 function-local names? For partial symbols, we should probably be
5700 complaint (&symfile_complaints
,
5701 _("unhandled containing DIE tag %d for DIE at %d"),
5702 parent
->tag
, pdi
->offset
.sect_off
);
5703 parent
->scope
= grandparent_scope
;
5706 parent
->scope_set
= 1;
5707 return parent
->scope
;
5710 /* Return the fully scoped name associated with PDI, from compilation unit
5711 CU. The result will be allocated with malloc. */
5714 partial_die_full_name (struct partial_die_info
*pdi
,
5715 struct dwarf2_cu
*cu
)
5719 /* If this is a template instantiation, we can not work out the
5720 template arguments from partial DIEs. So, unfortunately, we have
5721 to go through the full DIEs. At least any work we do building
5722 types here will be reused if full symbols are loaded later. */
5723 if (pdi
->has_template_arguments
)
5725 fixup_partial_die (pdi
, cu
);
5727 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5729 struct die_info
*die
;
5730 struct attribute attr
;
5731 struct dwarf2_cu
*ref_cu
= cu
;
5733 /* DW_FORM_ref_addr is using section offset. */
5735 attr
.form
= DW_FORM_ref_addr
;
5736 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5737 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5739 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5743 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5744 if (parent_scope
== NULL
)
5747 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5751 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5753 struct objfile
*objfile
= cu
->objfile
;
5755 char *actual_name
= NULL
;
5757 int built_actual_name
= 0;
5759 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5761 actual_name
= partial_die_full_name (pdi
, cu
);
5763 built_actual_name
= 1;
5765 if (actual_name
== NULL
)
5766 actual_name
= pdi
->name
;
5770 case DW_TAG_subprogram
:
5771 if (pdi
->is_external
|| cu
->language
== language_ada
)
5773 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5774 of the global scope. But in Ada, we want to be able to access
5775 nested procedures globally. So all Ada subprograms are stored
5776 in the global scope. */
5777 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5778 mst_text, objfile); */
5779 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5781 VAR_DOMAIN
, LOC_BLOCK
,
5782 &objfile
->global_psymbols
,
5783 0, pdi
->lowpc
+ baseaddr
,
5784 cu
->language
, objfile
);
5788 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5789 mst_file_text, objfile); */
5790 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5792 VAR_DOMAIN
, LOC_BLOCK
,
5793 &objfile
->static_psymbols
,
5794 0, pdi
->lowpc
+ baseaddr
,
5795 cu
->language
, objfile
);
5798 case DW_TAG_constant
:
5800 struct psymbol_allocation_list
*list
;
5802 if (pdi
->is_external
)
5803 list
= &objfile
->global_psymbols
;
5805 list
= &objfile
->static_psymbols
;
5806 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5807 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5808 list
, 0, 0, cu
->language
, objfile
);
5811 case DW_TAG_variable
:
5813 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5817 && !dwarf2_per_objfile
->has_section_at_zero
)
5819 /* A global or static variable may also have been stripped
5820 out by the linker if unused, in which case its address
5821 will be nullified; do not add such variables into partial
5822 symbol table then. */
5824 else if (pdi
->is_external
)
5827 Don't enter into the minimal symbol tables as there is
5828 a minimal symbol table entry from the ELF symbols already.
5829 Enter into partial symbol table if it has a location
5830 descriptor or a type.
5831 If the location descriptor is missing, new_symbol will create
5832 a LOC_UNRESOLVED symbol, the address of the variable will then
5833 be determined from the minimal symbol table whenever the variable
5835 The address for the partial symbol table entry is not
5836 used by GDB, but it comes in handy for debugging partial symbol
5839 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5840 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5842 VAR_DOMAIN
, LOC_STATIC
,
5843 &objfile
->global_psymbols
,
5845 cu
->language
, objfile
);
5849 /* Static Variable. Skip symbols without location descriptors. */
5850 if (pdi
->d
.locdesc
== NULL
)
5852 if (built_actual_name
)
5853 xfree (actual_name
);
5856 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5857 mst_file_data, objfile); */
5858 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5860 VAR_DOMAIN
, LOC_STATIC
,
5861 &objfile
->static_psymbols
,
5863 cu
->language
, objfile
);
5866 case DW_TAG_typedef
:
5867 case DW_TAG_base_type
:
5868 case DW_TAG_subrange_type
:
5869 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5871 VAR_DOMAIN
, LOC_TYPEDEF
,
5872 &objfile
->static_psymbols
,
5873 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5875 case DW_TAG_namespace
:
5876 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5878 VAR_DOMAIN
, LOC_TYPEDEF
,
5879 &objfile
->global_psymbols
,
5880 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5882 case DW_TAG_class_type
:
5883 case DW_TAG_interface_type
:
5884 case DW_TAG_structure_type
:
5885 case DW_TAG_union_type
:
5886 case DW_TAG_enumeration_type
:
5887 /* Skip external references. The DWARF standard says in the section
5888 about "Structure, Union, and Class Type Entries": "An incomplete
5889 structure, union or class type is represented by a structure,
5890 union or class entry that does not have a byte size attribute
5891 and that has a DW_AT_declaration attribute." */
5892 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5894 if (built_actual_name
)
5895 xfree (actual_name
);
5899 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5900 static vs. global. */
5901 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5903 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5904 (cu
->language
== language_cplus
5905 || cu
->language
== language_java
)
5906 ? &objfile
->global_psymbols
5907 : &objfile
->static_psymbols
,
5908 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5911 case DW_TAG_enumerator
:
5912 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5914 VAR_DOMAIN
, LOC_CONST
,
5915 (cu
->language
== language_cplus
5916 || cu
->language
== language_java
)
5917 ? &objfile
->global_psymbols
5918 : &objfile
->static_psymbols
,
5919 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5925 if (built_actual_name
)
5926 xfree (actual_name
);
5929 /* Read a partial die corresponding to a namespace; also, add a symbol
5930 corresponding to that namespace to the symbol table. NAMESPACE is
5931 the name of the enclosing namespace. */
5934 add_partial_namespace (struct partial_die_info
*pdi
,
5935 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5936 int need_pc
, struct dwarf2_cu
*cu
)
5938 /* Add a symbol for the namespace. */
5940 add_partial_symbol (pdi
, cu
);
5942 /* Now scan partial symbols in that namespace. */
5944 if (pdi
->has_children
)
5945 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5948 /* Read a partial die corresponding to a Fortran module. */
5951 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5952 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5954 /* Now scan partial symbols in that module. */
5956 if (pdi
->has_children
)
5957 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5960 /* Read a partial die corresponding to a subprogram and create a partial
5961 symbol for that subprogram. When the CU language allows it, this
5962 routine also defines a partial symbol for each nested subprogram
5963 that this subprogram contains.
5965 DIE my also be a lexical block, in which case we simply search
5966 recursively for suprograms defined inside that lexical block.
5967 Again, this is only performed when the CU language allows this
5968 type of definitions. */
5971 add_partial_subprogram (struct partial_die_info
*pdi
,
5972 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5973 int need_pc
, struct dwarf2_cu
*cu
)
5975 if (pdi
->tag
== DW_TAG_subprogram
)
5977 if (pdi
->has_pc_info
)
5979 if (pdi
->lowpc
< *lowpc
)
5980 *lowpc
= pdi
->lowpc
;
5981 if (pdi
->highpc
> *highpc
)
5982 *highpc
= pdi
->highpc
;
5986 struct objfile
*objfile
= cu
->objfile
;
5988 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5989 SECT_OFF_TEXT (objfile
));
5990 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5991 pdi
->lowpc
+ baseaddr
,
5992 pdi
->highpc
- 1 + baseaddr
,
5993 cu
->per_cu
->v
.psymtab
);
5997 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5999 if (!pdi
->is_declaration
)
6000 /* Ignore subprogram DIEs that do not have a name, they are
6001 illegal. Do not emit a complaint at this point, we will
6002 do so when we convert this psymtab into a symtab. */
6004 add_partial_symbol (pdi
, cu
);
6008 if (! pdi
->has_children
)
6011 if (cu
->language
== language_ada
)
6013 pdi
= pdi
->die_child
;
6016 fixup_partial_die (pdi
, cu
);
6017 if (pdi
->tag
== DW_TAG_subprogram
6018 || pdi
->tag
== DW_TAG_lexical_block
)
6019 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6020 pdi
= pdi
->die_sibling
;
6025 /* Read a partial die corresponding to an enumeration type. */
6028 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6029 struct dwarf2_cu
*cu
)
6031 struct partial_die_info
*pdi
;
6033 if (enum_pdi
->name
!= NULL
)
6034 add_partial_symbol (enum_pdi
, cu
);
6036 pdi
= enum_pdi
->die_child
;
6039 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6040 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6042 add_partial_symbol (pdi
, cu
);
6043 pdi
= pdi
->die_sibling
;
6047 /* Return the initial uleb128 in the die at INFO_PTR. */
6050 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
6052 unsigned int bytes_read
;
6054 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6057 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6058 Return the corresponding abbrev, or NULL if the number is zero (indicating
6059 an empty DIE). In either case *BYTES_READ will be set to the length of
6060 the initial number. */
6062 static struct abbrev_info
*
6063 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6064 struct dwarf2_cu
*cu
)
6066 bfd
*abfd
= cu
->objfile
->obfd
;
6067 unsigned int abbrev_number
;
6068 struct abbrev_info
*abbrev
;
6070 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6072 if (abbrev_number
== 0)
6075 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6078 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6079 abbrev_number
, bfd_get_filename (abfd
));
6085 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6086 Returns a pointer to the end of a series of DIEs, terminated by an empty
6087 DIE. Any children of the skipped DIEs will also be skipped. */
6090 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
6092 struct dwarf2_cu
*cu
= reader
->cu
;
6093 struct abbrev_info
*abbrev
;
6094 unsigned int bytes_read
;
6098 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6100 return info_ptr
+ bytes_read
;
6102 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6106 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6107 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6108 abbrev corresponding to that skipped uleb128 should be passed in
6109 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6113 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
6114 struct abbrev_info
*abbrev
)
6116 unsigned int bytes_read
;
6117 struct attribute attr
;
6118 bfd
*abfd
= reader
->abfd
;
6119 struct dwarf2_cu
*cu
= reader
->cu
;
6120 gdb_byte
*buffer
= reader
->buffer
;
6121 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6122 gdb_byte
*start_info_ptr
= info_ptr
;
6123 unsigned int form
, i
;
6125 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6127 /* The only abbrev we care about is DW_AT_sibling. */
6128 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6130 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6131 if (attr
.form
== DW_FORM_ref_addr
)
6132 complaint (&symfile_complaints
,
6133 _("ignoring absolute DW_AT_sibling"));
6135 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6138 /* If it isn't DW_AT_sibling, skip this attribute. */
6139 form
= abbrev
->attrs
[i
].form
;
6143 case DW_FORM_ref_addr
:
6144 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6145 and later it is offset sized. */
6146 if (cu
->header
.version
== 2)
6147 info_ptr
+= cu
->header
.addr_size
;
6149 info_ptr
+= cu
->header
.offset_size
;
6151 case DW_FORM_GNU_ref_alt
:
6152 info_ptr
+= cu
->header
.offset_size
;
6155 info_ptr
+= cu
->header
.addr_size
;
6162 case DW_FORM_flag_present
:
6174 case DW_FORM_ref_sig8
:
6177 case DW_FORM_string
:
6178 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6179 info_ptr
+= bytes_read
;
6181 case DW_FORM_sec_offset
:
6183 case DW_FORM_GNU_strp_alt
:
6184 info_ptr
+= cu
->header
.offset_size
;
6186 case DW_FORM_exprloc
:
6188 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6189 info_ptr
+= bytes_read
;
6191 case DW_FORM_block1
:
6192 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6194 case DW_FORM_block2
:
6195 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6197 case DW_FORM_block4
:
6198 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6202 case DW_FORM_ref_udata
:
6203 case DW_FORM_GNU_addr_index
:
6204 case DW_FORM_GNU_str_index
:
6205 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6207 case DW_FORM_indirect
:
6208 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6209 info_ptr
+= bytes_read
;
6210 /* We need to continue parsing from here, so just go back to
6212 goto skip_attribute
;
6215 error (_("Dwarf Error: Cannot handle %s "
6216 "in DWARF reader [in module %s]"),
6217 dwarf_form_name (form
),
6218 bfd_get_filename (abfd
));
6222 if (abbrev
->has_children
)
6223 return skip_children (reader
, info_ptr
);
6228 /* Locate ORIG_PDI's sibling.
6229 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6232 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6233 struct partial_die_info
*orig_pdi
,
6236 /* Do we know the sibling already? */
6238 if (orig_pdi
->sibling
)
6239 return orig_pdi
->sibling
;
6241 /* Are there any children to deal with? */
6243 if (!orig_pdi
->has_children
)
6246 /* Skip the children the long way. */
6248 return skip_children (reader
, info_ptr
);
6251 /* Expand this partial symbol table into a full symbol table. */
6254 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
6260 warning (_("bug: psymtab for %s is already read in."),
6267 printf_filtered (_("Reading in symbols for %s..."),
6269 gdb_flush (gdb_stdout
);
6272 /* Restore our global data. */
6273 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
6274 dwarf2_objfile_data_key
);
6276 /* If this psymtab is constructed from a debug-only objfile, the
6277 has_section_at_zero flag will not necessarily be correct. We
6278 can get the correct value for this flag by looking at the data
6279 associated with the (presumably stripped) associated objfile. */
6280 if (pst
->objfile
->separate_debug_objfile_backlink
)
6282 struct dwarf2_per_objfile
*dpo_backlink
6283 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6284 dwarf2_objfile_data_key
);
6286 dwarf2_per_objfile
->has_section_at_zero
6287 = dpo_backlink
->has_section_at_zero
;
6290 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6292 psymtab_to_symtab_1 (pst
);
6294 /* Finish up the debug error message. */
6296 printf_filtered (_("done.\n"));
6300 process_cu_includes ();
6303 /* Reading in full CUs. */
6305 /* Add PER_CU to the queue. */
6308 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6309 enum language pretend_language
)
6311 struct dwarf2_queue_item
*item
;
6314 item
= xmalloc (sizeof (*item
));
6315 item
->per_cu
= per_cu
;
6316 item
->pretend_language
= pretend_language
;
6319 if (dwarf2_queue
== NULL
)
6320 dwarf2_queue
= item
;
6322 dwarf2_queue_tail
->next
= item
;
6324 dwarf2_queue_tail
= item
;
6327 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6328 unit and add it to our queue.
6329 The result is non-zero if PER_CU was queued, otherwise the result is zero
6330 meaning either PER_CU is already queued or it is already loaded. */
6333 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6334 struct dwarf2_per_cu_data
*per_cu
,
6335 enum language pretend_language
)
6337 /* We may arrive here during partial symbol reading, if we need full
6338 DIEs to process an unusual case (e.g. template arguments). Do
6339 not queue PER_CU, just tell our caller to load its DIEs. */
6340 if (dwarf2_per_objfile
->reading_partial_symbols
)
6342 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6347 /* Mark the dependence relation so that we don't flush PER_CU
6349 dwarf2_add_dependence (this_cu
, per_cu
);
6351 /* If it's already on the queue, we have nothing to do. */
6355 /* If the compilation unit is already loaded, just mark it as
6357 if (per_cu
->cu
!= NULL
)
6359 per_cu
->cu
->last_used
= 0;
6363 /* Add it to the queue. */
6364 queue_comp_unit (per_cu
, pretend_language
);
6369 /* Process the queue. */
6372 process_queue (void)
6374 struct dwarf2_queue_item
*item
, *next_item
;
6376 if (dwarf2_read_debug
)
6378 fprintf_unfiltered (gdb_stdlog
,
6379 "Expanding one or more symtabs of objfile %s ...\n",
6380 dwarf2_per_objfile
->objfile
->name
);
6383 /* The queue starts out with one item, but following a DIE reference
6384 may load a new CU, adding it to the end of the queue. */
6385 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6387 if (dwarf2_per_objfile
->using_index
6388 ? !item
->per_cu
->v
.quick
->symtab
6389 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6391 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6393 if (dwarf2_read_debug
)
6395 fprintf_unfiltered (gdb_stdlog
,
6396 "Expanding symtab of %s at offset 0x%x\n",
6397 per_cu
->is_debug_types
? "TU" : "CU",
6398 per_cu
->offset
.sect_off
);
6401 if (per_cu
->is_debug_types
)
6402 process_full_type_unit (per_cu
, item
->pretend_language
);
6404 process_full_comp_unit (per_cu
, item
->pretend_language
);
6406 if (dwarf2_read_debug
)
6408 fprintf_unfiltered (gdb_stdlog
,
6409 "Done expanding %s at offset 0x%x\n",
6410 per_cu
->is_debug_types
? "TU" : "CU",
6411 per_cu
->offset
.sect_off
);
6415 item
->per_cu
->queued
= 0;
6416 next_item
= item
->next
;
6420 dwarf2_queue_tail
= NULL
;
6422 if (dwarf2_read_debug
)
6424 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6425 dwarf2_per_objfile
->objfile
->name
);
6429 /* Free all allocated queue entries. This function only releases anything if
6430 an error was thrown; if the queue was processed then it would have been
6431 freed as we went along. */
6434 dwarf2_release_queue (void *dummy
)
6436 struct dwarf2_queue_item
*item
, *last
;
6438 item
= dwarf2_queue
;
6441 /* Anything still marked queued is likely to be in an
6442 inconsistent state, so discard it. */
6443 if (item
->per_cu
->queued
)
6445 if (item
->per_cu
->cu
!= NULL
)
6446 free_one_cached_comp_unit (item
->per_cu
);
6447 item
->per_cu
->queued
= 0;
6455 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6458 /* Read in full symbols for PST, and anything it depends on. */
6461 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6463 struct dwarf2_per_cu_data
*per_cu
;
6469 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6470 if (!pst
->dependencies
[i
]->readin
6471 && pst
->dependencies
[i
]->user
== NULL
)
6473 /* Inform about additional files that need to be read in. */
6476 /* FIXME: i18n: Need to make this a single string. */
6477 fputs_filtered (" ", gdb_stdout
);
6479 fputs_filtered ("and ", gdb_stdout
);
6481 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6482 wrap_here (""); /* Flush output. */
6483 gdb_flush (gdb_stdout
);
6485 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6488 per_cu
= pst
->read_symtab_private
;
6492 /* It's an include file, no symbols to read for it.
6493 Everything is in the parent symtab. */
6498 dw2_do_instantiate_symtab (per_cu
);
6501 /* Trivial hash function for die_info: the hash value of a DIE
6502 is its offset in .debug_info for this objfile. */
6505 die_hash (const void *item
)
6507 const struct die_info
*die
= item
;
6509 return die
->offset
.sect_off
;
6512 /* Trivial comparison function for die_info structures: two DIEs
6513 are equal if they have the same offset. */
6516 die_eq (const void *item_lhs
, const void *item_rhs
)
6518 const struct die_info
*die_lhs
= item_lhs
;
6519 const struct die_info
*die_rhs
= item_rhs
;
6521 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6524 /* die_reader_func for load_full_comp_unit.
6525 This is identical to read_signatured_type_reader,
6526 but is kept separate for now. */
6529 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6531 struct die_info
*comp_unit_die
,
6535 struct dwarf2_cu
*cu
= reader
->cu
;
6536 enum language
*language_ptr
= data
;
6538 gdb_assert (cu
->die_hash
== NULL
);
6540 htab_create_alloc_ex (cu
->header
.length
/ 12,
6544 &cu
->comp_unit_obstack
,
6545 hashtab_obstack_allocate
,
6546 dummy_obstack_deallocate
);
6549 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6550 &info_ptr
, comp_unit_die
);
6551 cu
->dies
= comp_unit_die
;
6552 /* comp_unit_die is not stored in die_hash, no need. */
6554 /* We try not to read any attributes in this function, because not
6555 all CUs needed for references have been loaded yet, and symbol
6556 table processing isn't initialized. But we have to set the CU language,
6557 or we won't be able to build types correctly.
6558 Similarly, if we do not read the producer, we can not apply
6559 producer-specific interpretation. */
6560 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6563 /* Load the DIEs associated with PER_CU into memory. */
6566 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6567 enum language pretend_language
)
6569 gdb_assert (! this_cu
->is_debug_types
);
6571 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6572 load_full_comp_unit_reader
, &pretend_language
);
6575 /* Add a DIE to the delayed physname list. */
6578 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6579 const char *name
, struct die_info
*die
,
6580 struct dwarf2_cu
*cu
)
6582 struct delayed_method_info mi
;
6584 mi
.fnfield_index
= fnfield_index
;
6588 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6591 /* A cleanup for freeing the delayed method list. */
6594 free_delayed_list (void *ptr
)
6596 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6597 if (cu
->method_list
!= NULL
)
6599 VEC_free (delayed_method_info
, cu
->method_list
);
6600 cu
->method_list
= NULL
;
6604 /* Compute the physnames of any methods on the CU's method list.
6606 The computation of method physnames is delayed in order to avoid the
6607 (bad) condition that one of the method's formal parameters is of an as yet
6611 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6614 struct delayed_method_info
*mi
;
6615 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6617 const char *physname
;
6618 struct fn_fieldlist
*fn_flp
6619 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6620 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6621 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6625 /* Go objects should be embedded in a DW_TAG_module DIE,
6626 and it's not clear if/how imported objects will appear.
6627 To keep Go support simple until that's worked out,
6628 go back through what we've read and create something usable.
6629 We could do this while processing each DIE, and feels kinda cleaner,
6630 but that way is more invasive.
6631 This is to, for example, allow the user to type "p var" or "b main"
6632 without having to specify the package name, and allow lookups
6633 of module.object to work in contexts that use the expression
6637 fixup_go_packaging (struct dwarf2_cu
*cu
)
6639 char *package_name
= NULL
;
6640 struct pending
*list
;
6643 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6645 for (i
= 0; i
< list
->nsyms
; ++i
)
6647 struct symbol
*sym
= list
->symbol
[i
];
6649 if (SYMBOL_LANGUAGE (sym
) == language_go
6650 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6652 char *this_package_name
= go_symbol_package_name (sym
);
6654 if (this_package_name
== NULL
)
6656 if (package_name
== NULL
)
6657 package_name
= this_package_name
;
6660 if (strcmp (package_name
, this_package_name
) != 0)
6661 complaint (&symfile_complaints
,
6662 _("Symtab %s has objects from two different Go packages: %s and %s"),
6663 (sym
->symtab
&& sym
->symtab
->filename
6664 ? sym
->symtab
->filename
6665 : cu
->objfile
->name
),
6666 this_package_name
, package_name
);
6667 xfree (this_package_name
);
6673 if (package_name
!= NULL
)
6675 struct objfile
*objfile
= cu
->objfile
;
6676 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6677 package_name
, objfile
);
6680 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6682 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6683 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6684 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6685 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6686 e.g., "main" finds the "main" module and not C's main(). */
6687 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6688 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6689 SYMBOL_TYPE (sym
) = type
;
6691 add_symbol_to_list (sym
, &global_symbols
);
6693 xfree (package_name
);
6697 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6699 /* Return the symtab for PER_CU. This works properly regardless of
6700 whether we're using the index or psymtabs. */
6702 static struct symtab
*
6703 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6705 return (dwarf2_per_objfile
->using_index
6706 ? per_cu
->v
.quick
->symtab
6707 : per_cu
->v
.psymtab
->symtab
);
6710 /* A helper function for computing the list of all symbol tables
6711 included by PER_CU. */
6714 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6715 htab_t all_children
,
6716 struct dwarf2_per_cu_data
*per_cu
)
6720 struct dwarf2_per_cu_data
*iter
;
6722 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6725 /* This inclusion and its children have been processed. */
6730 /* Only add a CU if it has a symbol table. */
6731 if (get_symtab (per_cu
) != NULL
)
6732 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6735 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6737 recursively_compute_inclusions (result
, all_children
, iter
);
6740 /* Compute the symtab 'includes' fields for the symtab related to
6744 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6746 gdb_assert (! per_cu
->is_debug_types
);
6748 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6751 struct dwarf2_per_cu_data
*iter
;
6752 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6753 htab_t all_children
;
6754 struct symtab
*symtab
= get_symtab (per_cu
);
6756 /* If we don't have a symtab, we can just skip this case. */
6760 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6761 NULL
, xcalloc
, xfree
);
6764 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6767 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6769 /* Now we have a transitive closure of all the included CUs, so
6770 we can convert it to a list of symtabs. */
6771 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6773 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6774 (len
+ 1) * sizeof (struct symtab
*));
6776 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6778 symtab
->includes
[ix
] = get_symtab (iter
);
6779 symtab
->includes
[len
] = NULL
;
6781 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6782 htab_delete (all_children
);
6786 /* Compute the 'includes' field for the symtabs of all the CUs we just
6790 process_cu_includes (void)
6793 struct dwarf2_per_cu_data
*iter
;
6796 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6800 if (! iter
->is_debug_types
)
6801 compute_symtab_includes (iter
);
6804 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6807 /* Generate full symbol information for PER_CU, whose DIEs have
6808 already been loaded into memory. */
6811 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6812 enum language pretend_language
)
6814 struct dwarf2_cu
*cu
= per_cu
->cu
;
6815 struct objfile
*objfile
= per_cu
->objfile
;
6816 CORE_ADDR lowpc
, highpc
;
6817 struct symtab
*symtab
;
6818 struct cleanup
*back_to
, *delayed_list_cleanup
;
6820 struct block
*static_block
;
6822 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6825 back_to
= make_cleanup (really_free_pendings
, NULL
);
6826 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6828 cu
->list_in_scope
= &file_symbols
;
6830 cu
->language
= pretend_language
;
6831 cu
->language_defn
= language_def (cu
->language
);
6833 /* Do line number decoding in read_file_scope () */
6834 process_die (cu
->dies
, cu
);
6836 /* For now fudge the Go package. */
6837 if (cu
->language
== language_go
)
6838 fixup_go_packaging (cu
);
6840 /* Now that we have processed all the DIEs in the CU, all the types
6841 should be complete, and it should now be safe to compute all of the
6843 compute_delayed_physnames (cu
);
6844 do_cleanups (delayed_list_cleanup
);
6846 /* Some compilers don't define a DW_AT_high_pc attribute for the
6847 compilation unit. If the DW_AT_high_pc is missing, synthesize
6848 it, by scanning the DIE's below the compilation unit. */
6849 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6852 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0,
6853 per_cu
->s
.imported_symtabs
!= NULL
);
6855 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6856 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6857 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6858 addrmap to help ensure it has an accurate map of pc values belonging to
6860 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6862 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6863 SECT_OFF_TEXT (objfile
), 0);
6867 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6869 /* Set symtab language to language from DW_AT_language. If the
6870 compilation is from a C file generated by language preprocessors, do
6871 not set the language if it was already deduced by start_subfile. */
6872 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6873 symtab
->language
= cu
->language
;
6875 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6876 produce DW_AT_location with location lists but it can be possibly
6877 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6878 there were bugs in prologue debug info, fixed later in GCC-4.5
6879 by "unwind info for epilogues" patch (which is not directly related).
6881 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6882 needed, it would be wrong due to missing DW_AT_producer there.
6884 Still one can confuse GDB by using non-standard GCC compilation
6885 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6887 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6888 symtab
->locations_valid
= 1;
6890 if (gcc_4_minor
>= 5)
6891 symtab
->epilogue_unwind_valid
= 1;
6893 symtab
->call_site_htab
= cu
->call_site_htab
;
6896 if (dwarf2_per_objfile
->using_index
)
6897 per_cu
->v
.quick
->symtab
= symtab
;
6900 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6901 pst
->symtab
= symtab
;
6905 /* Push it for inclusion processing later. */
6906 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
6908 do_cleanups (back_to
);
6911 /* Generate full symbol information for type unit PER_CU, whose DIEs have
6912 already been loaded into memory. */
6915 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
6916 enum language pretend_language
)
6918 struct dwarf2_cu
*cu
= per_cu
->cu
;
6919 struct objfile
*objfile
= per_cu
->objfile
;
6920 struct symtab
*symtab
;
6921 struct cleanup
*back_to
, *delayed_list_cleanup
;
6924 back_to
= make_cleanup (really_free_pendings
, NULL
);
6925 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6927 cu
->list_in_scope
= &file_symbols
;
6929 cu
->language
= pretend_language
;
6930 cu
->language_defn
= language_def (cu
->language
);
6932 /* The symbol tables are set up in read_type_unit_scope. */
6933 process_die (cu
->dies
, cu
);
6935 /* For now fudge the Go package. */
6936 if (cu
->language
== language_go
)
6937 fixup_go_packaging (cu
);
6939 /* Now that we have processed all the DIEs in the CU, all the types
6940 should be complete, and it should now be safe to compute all of the
6942 compute_delayed_physnames (cu
);
6943 do_cleanups (delayed_list_cleanup
);
6945 /* TUs share symbol tables.
6946 If this is the first TU to use this symtab, complete the construction
6947 of it with end_expandable_symtab. Otherwise, complete the addition of
6948 this TU's symbols to the existing symtab. */
6949 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
6951 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
6952 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
6956 /* Set symtab language to language from DW_AT_language. If the
6957 compilation is from a C file generated by language preprocessors,
6958 do not set the language if it was already deduced by
6960 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6961 symtab
->language
= cu
->language
;
6966 augment_type_symtab (objfile
,
6967 per_cu
->s
.type_unit_group
->primary_symtab
);
6968 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
6971 if (dwarf2_per_objfile
->using_index
)
6972 per_cu
->v
.quick
->symtab
= symtab
;
6975 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6976 pst
->symtab
= symtab
;
6980 do_cleanups (back_to
);
6983 /* Process an imported unit DIE. */
6986 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6988 struct attribute
*attr
;
6990 /* For now we don't handle imported units in type units. */
6991 if (cu
->per_cu
->is_debug_types
)
6993 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6994 " supported in type units [in module %s]"),
6998 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7001 struct dwarf2_per_cu_data
*per_cu
;
7002 struct symtab
*imported_symtab
;
7006 offset
= dwarf2_get_ref_die_offset (attr
);
7007 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7008 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7010 /* Queue the unit, if needed. */
7011 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7012 load_full_comp_unit (per_cu
, cu
->language
);
7014 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
7019 /* Process a die and its children. */
7022 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7026 case DW_TAG_padding
:
7028 case DW_TAG_compile_unit
:
7029 case DW_TAG_partial_unit
:
7030 read_file_scope (die
, cu
);
7032 case DW_TAG_type_unit
:
7033 read_type_unit_scope (die
, cu
);
7035 case DW_TAG_subprogram
:
7036 case DW_TAG_inlined_subroutine
:
7037 read_func_scope (die
, cu
);
7039 case DW_TAG_lexical_block
:
7040 case DW_TAG_try_block
:
7041 case DW_TAG_catch_block
:
7042 read_lexical_block_scope (die
, cu
);
7044 case DW_TAG_GNU_call_site
:
7045 read_call_site_scope (die
, cu
);
7047 case DW_TAG_class_type
:
7048 case DW_TAG_interface_type
:
7049 case DW_TAG_structure_type
:
7050 case DW_TAG_union_type
:
7051 process_structure_scope (die
, cu
);
7053 case DW_TAG_enumeration_type
:
7054 process_enumeration_scope (die
, cu
);
7057 /* These dies have a type, but processing them does not create
7058 a symbol or recurse to process the children. Therefore we can
7059 read them on-demand through read_type_die. */
7060 case DW_TAG_subroutine_type
:
7061 case DW_TAG_set_type
:
7062 case DW_TAG_array_type
:
7063 case DW_TAG_pointer_type
:
7064 case DW_TAG_ptr_to_member_type
:
7065 case DW_TAG_reference_type
:
7066 case DW_TAG_string_type
:
7069 case DW_TAG_base_type
:
7070 case DW_TAG_subrange_type
:
7071 case DW_TAG_typedef
:
7072 /* Add a typedef symbol for the type definition, if it has a
7074 new_symbol (die
, read_type_die (die
, cu
), cu
);
7076 case DW_TAG_common_block
:
7077 read_common_block (die
, cu
);
7079 case DW_TAG_common_inclusion
:
7081 case DW_TAG_namespace
:
7082 processing_has_namespace_info
= 1;
7083 read_namespace (die
, cu
);
7086 processing_has_namespace_info
= 1;
7087 read_module (die
, cu
);
7089 case DW_TAG_imported_declaration
:
7090 case DW_TAG_imported_module
:
7091 processing_has_namespace_info
= 1;
7092 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7093 || cu
->language
!= language_fortran
))
7094 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7095 dwarf_tag_name (die
->tag
));
7096 read_import_statement (die
, cu
);
7099 case DW_TAG_imported_unit
:
7100 process_imported_unit_die (die
, cu
);
7104 new_symbol (die
, NULL
, cu
);
7109 /* A helper function for dwarf2_compute_name which determines whether DIE
7110 needs to have the name of the scope prepended to the name listed in the
7114 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7116 struct attribute
*attr
;
7120 case DW_TAG_namespace
:
7121 case DW_TAG_typedef
:
7122 case DW_TAG_class_type
:
7123 case DW_TAG_interface_type
:
7124 case DW_TAG_structure_type
:
7125 case DW_TAG_union_type
:
7126 case DW_TAG_enumeration_type
:
7127 case DW_TAG_enumerator
:
7128 case DW_TAG_subprogram
:
7132 case DW_TAG_variable
:
7133 case DW_TAG_constant
:
7134 /* We only need to prefix "globally" visible variables. These include
7135 any variable marked with DW_AT_external or any variable that
7136 lives in a namespace. [Variables in anonymous namespaces
7137 require prefixing, but they are not DW_AT_external.] */
7139 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7141 struct dwarf2_cu
*spec_cu
= cu
;
7143 return die_needs_namespace (die_specification (die
, &spec_cu
),
7147 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7148 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7149 && die
->parent
->tag
!= DW_TAG_module
)
7151 /* A variable in a lexical block of some kind does not need a
7152 namespace, even though in C++ such variables may be external
7153 and have a mangled name. */
7154 if (die
->parent
->tag
== DW_TAG_lexical_block
7155 || die
->parent
->tag
== DW_TAG_try_block
7156 || die
->parent
->tag
== DW_TAG_catch_block
7157 || die
->parent
->tag
== DW_TAG_subprogram
)
7166 /* Retrieve the last character from a mem_file. */
7169 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7171 char *last_char_p
= (char *) object
;
7174 *last_char_p
= buffer
[length
- 1];
7177 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7178 compute the physname for the object, which include a method's:
7179 - formal parameters (C++/Java),
7180 - receiver type (Go),
7181 - return type (Java).
7183 The term "physname" is a bit confusing.
7184 For C++, for example, it is the demangled name.
7185 For Go, for example, it's the mangled name.
7187 For Ada, return the DIE's linkage name rather than the fully qualified
7188 name. PHYSNAME is ignored..
7190 The result is allocated on the objfile_obstack and canonicalized. */
7193 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7196 struct objfile
*objfile
= cu
->objfile
;
7199 name
= dwarf2_name (die
, cu
);
7201 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7202 compute it by typename_concat inside GDB. */
7203 if (cu
->language
== language_ada
7204 || (cu
->language
== language_fortran
&& physname
))
7206 /* For Ada unit, we prefer the linkage name over the name, as
7207 the former contains the exported name, which the user expects
7208 to be able to reference. Ideally, we want the user to be able
7209 to reference this entity using either natural or linkage name,
7210 but we haven't started looking at this enhancement yet. */
7211 struct attribute
*attr
;
7213 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7215 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7216 if (attr
&& DW_STRING (attr
))
7217 return DW_STRING (attr
);
7220 /* These are the only languages we know how to qualify names in. */
7222 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7223 || cu
->language
== language_fortran
))
7225 if (die_needs_namespace (die
, cu
))
7229 struct ui_file
*buf
;
7231 prefix
= determine_prefix (die
, cu
);
7232 buf
= mem_fileopen ();
7233 if (*prefix
!= '\0')
7235 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7238 fputs_unfiltered (prefixed_name
, buf
);
7239 xfree (prefixed_name
);
7242 fputs_unfiltered (name
, buf
);
7244 /* Template parameters may be specified in the DIE's DW_AT_name, or
7245 as children with DW_TAG_template_type_param or
7246 DW_TAG_value_type_param. If the latter, add them to the name
7247 here. If the name already has template parameters, then
7248 skip this step; some versions of GCC emit both, and
7249 it is more efficient to use the pre-computed name.
7251 Something to keep in mind about this process: it is very
7252 unlikely, or in some cases downright impossible, to produce
7253 something that will match the mangled name of a function.
7254 If the definition of the function has the same debug info,
7255 we should be able to match up with it anyway. But fallbacks
7256 using the minimal symbol, for instance to find a method
7257 implemented in a stripped copy of libstdc++, will not work.
7258 If we do not have debug info for the definition, we will have to
7259 match them up some other way.
7261 When we do name matching there is a related problem with function
7262 templates; two instantiated function templates are allowed to
7263 differ only by their return types, which we do not add here. */
7265 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7267 struct attribute
*attr
;
7268 struct die_info
*child
;
7271 die
->building_fullname
= 1;
7273 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7278 struct dwarf2_locexpr_baton
*baton
;
7281 if (child
->tag
!= DW_TAG_template_type_param
7282 && child
->tag
!= DW_TAG_template_value_param
)
7287 fputs_unfiltered ("<", buf
);
7291 fputs_unfiltered (", ", buf
);
7293 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7296 complaint (&symfile_complaints
,
7297 _("template parameter missing DW_AT_type"));
7298 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7301 type
= die_type (child
, cu
);
7303 if (child
->tag
== DW_TAG_template_type_param
)
7305 c_print_type (type
, "", buf
, -1, 0);
7309 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7312 complaint (&symfile_complaints
,
7313 _("template parameter missing "
7314 "DW_AT_const_value"));
7315 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7319 dwarf2_const_value_attr (attr
, type
, name
,
7320 &cu
->comp_unit_obstack
, cu
,
7321 &value
, &bytes
, &baton
);
7323 if (TYPE_NOSIGN (type
))
7324 /* GDB prints characters as NUMBER 'CHAR'. If that's
7325 changed, this can use value_print instead. */
7326 c_printchar (value
, type
, buf
);
7329 struct value_print_options opts
;
7332 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7336 else if (bytes
!= NULL
)
7338 v
= allocate_value (type
);
7339 memcpy (value_contents_writeable (v
), bytes
,
7340 TYPE_LENGTH (type
));
7343 v
= value_from_longest (type
, value
);
7345 /* Specify decimal so that we do not depend on
7347 get_formatted_print_options (&opts
, 'd');
7349 value_print (v
, buf
, &opts
);
7355 die
->building_fullname
= 0;
7359 /* Close the argument list, with a space if necessary
7360 (nested templates). */
7361 char last_char
= '\0';
7362 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7363 if (last_char
== '>')
7364 fputs_unfiltered (" >", buf
);
7366 fputs_unfiltered (">", buf
);
7370 /* For Java and C++ methods, append formal parameter type
7371 information, if PHYSNAME. */
7373 if (physname
&& die
->tag
== DW_TAG_subprogram
7374 && (cu
->language
== language_cplus
7375 || cu
->language
== language_java
))
7377 struct type
*type
= read_type_die (die
, cu
);
7379 c_type_print_args (type
, buf
, 1, cu
->language
);
7381 if (cu
->language
== language_java
)
7383 /* For java, we must append the return type to method
7385 if (die
->tag
== DW_TAG_subprogram
)
7386 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7389 else if (cu
->language
== language_cplus
)
7391 /* Assume that an artificial first parameter is
7392 "this", but do not crash if it is not. RealView
7393 marks unnamed (and thus unused) parameters as
7394 artificial; there is no way to differentiate
7396 if (TYPE_NFIELDS (type
) > 0
7397 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7398 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7399 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7401 fputs_unfiltered (" const", buf
);
7405 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7407 ui_file_delete (buf
);
7409 if (cu
->language
== language_cplus
)
7412 = dwarf2_canonicalize_name (name
, cu
,
7413 &objfile
->objfile_obstack
);
7424 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7425 If scope qualifiers are appropriate they will be added. The result
7426 will be allocated on the objfile_obstack, or NULL if the DIE does
7427 not have a name. NAME may either be from a previous call to
7428 dwarf2_name or NULL.
7430 The output string will be canonicalized (if C++/Java). */
7433 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7435 return dwarf2_compute_name (name
, die
, cu
, 0);
7438 /* Construct a physname for the given DIE in CU. NAME may either be
7439 from a previous call to dwarf2_name or NULL. The result will be
7440 allocated on the objfile_objstack or NULL if the DIE does not have a
7443 The output string will be canonicalized (if C++/Java). */
7446 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7448 struct objfile
*objfile
= cu
->objfile
;
7449 struct attribute
*attr
;
7450 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7451 struct cleanup
*back_to
;
7454 /* In this case dwarf2_compute_name is just a shortcut not building anything
7456 if (!die_needs_namespace (die
, cu
))
7457 return dwarf2_compute_name (name
, die
, cu
, 1);
7459 back_to
= make_cleanup (null_cleanup
, NULL
);
7461 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7463 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7465 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7467 if (attr
&& DW_STRING (attr
))
7471 mangled
= DW_STRING (attr
);
7473 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7474 type. It is easier for GDB users to search for such functions as
7475 `name(params)' than `long name(params)'. In such case the minimal
7476 symbol names do not match the full symbol names but for template
7477 functions there is never a need to look up their definition from their
7478 declaration so the only disadvantage remains the minimal symbol
7479 variant `long name(params)' does not have the proper inferior type.
7482 if (cu
->language
== language_go
)
7484 /* This is a lie, but we already lie to the caller new_symbol_full.
7485 new_symbol_full assumes we return the mangled name.
7486 This just undoes that lie until things are cleaned up. */
7491 demangled
= cplus_demangle (mangled
,
7492 (DMGL_PARAMS
| DMGL_ANSI
7493 | (cu
->language
== language_java
7494 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7499 make_cleanup (xfree
, demangled
);
7509 if (canon
== NULL
|| check_physname
)
7511 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7513 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7515 /* It may not mean a bug in GDB. The compiler could also
7516 compute DW_AT_linkage_name incorrectly. But in such case
7517 GDB would need to be bug-to-bug compatible. */
7519 complaint (&symfile_complaints
,
7520 _("Computed physname <%s> does not match demangled <%s> "
7521 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7522 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7524 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7525 is available here - over computed PHYSNAME. It is safer
7526 against both buggy GDB and buggy compilers. */
7540 retval
= obsavestring (retval
, strlen (retval
),
7541 &objfile
->objfile_obstack
);
7543 do_cleanups (back_to
);
7547 /* Read the import statement specified by the given die and record it. */
7550 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7552 struct objfile
*objfile
= cu
->objfile
;
7553 struct attribute
*import_attr
;
7554 struct die_info
*imported_die
, *child_die
;
7555 struct dwarf2_cu
*imported_cu
;
7556 const char *imported_name
;
7557 const char *imported_name_prefix
;
7558 const char *canonical_name
;
7559 const char *import_alias
;
7560 const char *imported_declaration
= NULL
;
7561 const char *import_prefix
;
7562 VEC (const_char_ptr
) *excludes
= NULL
;
7563 struct cleanup
*cleanups
;
7567 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7568 if (import_attr
== NULL
)
7570 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7571 dwarf_tag_name (die
->tag
));
7576 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7577 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7578 if (imported_name
== NULL
)
7580 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7582 The import in the following code:
7596 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7597 <52> DW_AT_decl_file : 1
7598 <53> DW_AT_decl_line : 6
7599 <54> DW_AT_import : <0x75>
7600 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7602 <5b> DW_AT_decl_file : 1
7603 <5c> DW_AT_decl_line : 2
7604 <5d> DW_AT_type : <0x6e>
7606 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7607 <76> DW_AT_byte_size : 4
7608 <77> DW_AT_encoding : 5 (signed)
7610 imports the wrong die ( 0x75 instead of 0x58 ).
7611 This case will be ignored until the gcc bug is fixed. */
7615 /* Figure out the local name after import. */
7616 import_alias
= dwarf2_name (die
, cu
);
7618 /* Figure out where the statement is being imported to. */
7619 import_prefix
= determine_prefix (die
, cu
);
7621 /* Figure out what the scope of the imported die is and prepend it
7622 to the name of the imported die. */
7623 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7625 if (imported_die
->tag
!= DW_TAG_namespace
7626 && imported_die
->tag
!= DW_TAG_module
)
7628 imported_declaration
= imported_name
;
7629 canonical_name
= imported_name_prefix
;
7631 else if (strlen (imported_name_prefix
) > 0)
7633 temp
= alloca (strlen (imported_name_prefix
)
7634 + 2 + strlen (imported_name
) + 1);
7635 strcpy (temp
, imported_name_prefix
);
7636 strcat (temp
, "::");
7637 strcat (temp
, imported_name
);
7638 canonical_name
= temp
;
7641 canonical_name
= imported_name
;
7643 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7645 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7646 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7647 child_die
= sibling_die (child_die
))
7649 /* DWARF-4: A Fortran use statement with a “rename list” may be
7650 represented by an imported module entry with an import attribute
7651 referring to the module and owned entries corresponding to those
7652 entities that are renamed as part of being imported. */
7654 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7656 complaint (&symfile_complaints
,
7657 _("child DW_TAG_imported_declaration expected "
7658 "- DIE at 0x%x [in module %s]"),
7659 child_die
->offset
.sect_off
, objfile
->name
);
7663 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7664 if (import_attr
== NULL
)
7666 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7667 dwarf_tag_name (child_die
->tag
));
7672 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7674 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7675 if (imported_name
== NULL
)
7677 complaint (&symfile_complaints
,
7678 _("child DW_TAG_imported_declaration has unknown "
7679 "imported name - DIE at 0x%x [in module %s]"),
7680 child_die
->offset
.sect_off
, objfile
->name
);
7684 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7686 process_die (child_die
, cu
);
7689 cp_add_using_directive (import_prefix
,
7692 imported_declaration
,
7694 &objfile
->objfile_obstack
);
7696 do_cleanups (cleanups
);
7699 /* Cleanup function for handle_DW_AT_stmt_list. */
7702 free_cu_line_header (void *arg
)
7704 struct dwarf2_cu
*cu
= arg
;
7706 free_line_header (cu
->line_header
);
7707 cu
->line_header
= NULL
;
7711 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7712 char **name
, char **comp_dir
)
7714 struct attribute
*attr
;
7719 /* Find the filename. Do not use dwarf2_name here, since the filename
7720 is not a source language identifier. */
7721 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7724 *name
= DW_STRING (attr
);
7727 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7729 *comp_dir
= DW_STRING (attr
);
7730 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
7732 *comp_dir
= ldirname (*name
);
7733 if (*comp_dir
!= NULL
)
7734 make_cleanup (xfree
, *comp_dir
);
7736 if (*comp_dir
!= NULL
)
7738 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7739 directory, get rid of it. */
7740 char *cp
= strchr (*comp_dir
, ':');
7742 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7747 *name
= "<unknown>";
7750 /* Handle DW_AT_stmt_list for a compilation unit.
7751 DIE is the DW_TAG_compile_unit die for CU.
7752 COMP_DIR is the compilation directory.
7753 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7756 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7757 const char *comp_dir
)
7759 struct attribute
*attr
;
7761 gdb_assert (! cu
->per_cu
->is_debug_types
);
7763 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7766 unsigned int line_offset
= DW_UNSND (attr
);
7767 struct line_header
*line_header
7768 = dwarf_decode_line_header (line_offset
, cu
);
7772 cu
->line_header
= line_header
;
7773 make_cleanup (free_cu_line_header
, cu
);
7774 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7779 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7782 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7784 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7785 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7786 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7787 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7788 struct attribute
*attr
;
7790 char *comp_dir
= NULL
;
7791 struct die_info
*child_die
;
7792 bfd
*abfd
= objfile
->obfd
;
7795 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7797 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7799 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7800 from finish_block. */
7801 if (lowpc
== ((CORE_ADDR
) -1))
7806 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7808 prepare_one_comp_unit (cu
, die
, cu
->language
);
7810 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7811 standardised yet. As a workaround for the language detection we fall
7812 back to the DW_AT_producer string. */
7813 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7814 cu
->language
= language_opencl
;
7816 /* Similar hack for Go. */
7817 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7818 set_cu_language (DW_LANG_Go
, cu
);
7820 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7822 /* Decode line number information if present. We do this before
7823 processing child DIEs, so that the line header table is available
7824 for DW_AT_decl_file. */
7825 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7827 /* Process all dies in compilation unit. */
7828 if (die
->child
!= NULL
)
7830 child_die
= die
->child
;
7831 while (child_die
&& child_die
->tag
)
7833 process_die (child_die
, cu
);
7834 child_die
= sibling_die (child_die
);
7838 /* Decode macro information, if present. Dwarf 2 macro information
7839 refers to information in the line number info statement program
7840 header, so we can only read it if we've read the header
7842 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7843 if (attr
&& cu
->line_header
)
7845 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7846 complaint (&symfile_complaints
,
7847 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7849 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7853 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7854 if (attr
&& cu
->line_header
)
7856 unsigned int macro_offset
= DW_UNSND (attr
);
7858 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7862 do_cleanups (back_to
);
7865 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7866 Create the set of symtabs used by this TU, or if this TU is sharing
7867 symtabs with another TU and the symtabs have already been created
7868 then restore those symtabs in the line header.
7869 We don't need the pc/line-number mapping for type units. */
7872 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7874 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7875 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7876 struct type_unit_group
*tu_group
;
7878 struct line_header
*lh
;
7879 struct attribute
*attr
;
7880 unsigned int i
, line_offset
;
7882 gdb_assert (per_cu
->is_debug_types
);
7884 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7886 /* If we're using .gdb_index (includes -readnow) then
7887 per_cu->s.type_unit_group may not have been set up yet. */
7888 if (per_cu
->s
.type_unit_group
== NULL
)
7889 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
7890 tu_group
= per_cu
->s
.type_unit_group
;
7892 /* If we've already processed this stmt_list there's no real need to
7893 do it again, we could fake it and just recreate the part we need
7894 (file name,index -> symtab mapping). If data shows this optimization
7895 is useful we can do it then. */
7896 first_time
= tu_group
->primary_symtab
== NULL
;
7898 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7903 line_offset
= DW_UNSND (attr
);
7904 lh
= dwarf_decode_line_header (line_offset
, cu
);
7909 dwarf2_start_symtab (cu
, "", NULL
, 0);
7912 gdb_assert (tu_group
->symtabs
== NULL
);
7915 /* Note: The primary symtab will get allocated at the end. */
7919 cu
->line_header
= lh
;
7920 make_cleanup (free_cu_line_header
, cu
);
7924 dwarf2_start_symtab (cu
, "", NULL
, 0);
7926 tu_group
->num_symtabs
= lh
->num_file_names
;
7927 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
7929 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7932 struct file_entry
*fe
= &lh
->file_names
[i
];
7935 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7936 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
7938 /* Note: We don't have to watch for the main subfile here, type units
7939 don't have DW_AT_name. */
7941 if (current_subfile
->symtab
== NULL
)
7943 /* NOTE: start_subfile will recognize when it's been passed
7944 a file it has already seen. So we can't assume there's a
7945 simple mapping from lh->file_names to subfiles,
7946 lh->file_names may contain dups. */
7947 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7951 fe
->symtab
= current_subfile
->symtab
;
7952 tu_group
->symtabs
[i
] = fe
->symtab
;
7959 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7961 struct file_entry
*fe
= &lh
->file_names
[i
];
7963 fe
->symtab
= tu_group
->symtabs
[i
];
7967 /* The main symtab is allocated last. Type units don't have DW_AT_name
7968 so they don't have a "real" (so to speak) symtab anyway.
7969 There is later code that will assign the main symtab to all symbols
7970 that don't have one. We need to handle the case of a symbol with a
7971 missing symtab (DW_AT_decl_file) anyway. */
7974 /* Process DW_TAG_type_unit.
7975 For TUs we want to skip the first top level sibling if it's not the
7976 actual type being defined by this TU. In this case the first top
7977 level sibling is there to provide context only. */
7980 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7982 struct die_info
*child_die
;
7984 prepare_one_comp_unit (cu
, die
, language_minimal
);
7986 /* Initialize (or reinitialize) the machinery for building symtabs.
7987 We do this before processing child DIEs, so that the line header table
7988 is available for DW_AT_decl_file. */
7989 setup_type_unit_groups (die
, cu
);
7991 if (die
->child
!= NULL
)
7993 child_die
= die
->child
;
7994 while (child_die
&& child_die
->tag
)
7996 process_die (child_die
, cu
);
7997 child_die
= sibling_die (child_die
);
8005 hash_dwo_file (const void *item
)
8007 const struct dwo_file
*dwo_file
= item
;
8009 return htab_hash_string (dwo_file
->dwo_name
);
8013 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8015 const struct dwo_file
*lhs
= item_lhs
;
8016 const struct dwo_file
*rhs
= item_rhs
;
8018 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
8021 /* Allocate a hash table for DWO files. */
8024 allocate_dwo_file_hash_table (void)
8026 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8028 return htab_create_alloc_ex (41,
8032 &objfile
->objfile_obstack
,
8033 hashtab_obstack_allocate
,
8034 dummy_obstack_deallocate
);
8038 hash_dwo_unit (const void *item
)
8040 const struct dwo_unit
*dwo_unit
= item
;
8042 /* This drops the top 32 bits of the id, but is ok for a hash. */
8043 return dwo_unit
->signature
;
8047 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8049 const struct dwo_unit
*lhs
= item_lhs
;
8050 const struct dwo_unit
*rhs
= item_rhs
;
8052 /* The signature is assumed to be unique within the DWO file.
8053 So while object file CU dwo_id's always have the value zero,
8054 that's OK, assuming each object file DWO file has only one CU,
8055 and that's the rule for now. */
8056 return lhs
->signature
== rhs
->signature
;
8059 /* Allocate a hash table for DWO CUs,TUs.
8060 There is one of these tables for each of CUs,TUs for each DWO file. */
8063 allocate_dwo_unit_table (struct objfile
*objfile
)
8065 /* Start out with a pretty small number.
8066 Generally DWO files contain only one CU and maybe some TUs. */
8067 return htab_create_alloc_ex (3,
8071 &objfile
->objfile_obstack
,
8072 hashtab_obstack_allocate
,
8073 dummy_obstack_deallocate
);
8076 /* This function is mapped across the sections and remembers the offset and
8077 size of each of the DWO debugging sections we are interested in. */
8080 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
8082 struct dwo_file
*dwo_file
= dwo_file_ptr
;
8083 const struct dwo_section_names
*names
= &dwo_section_names
;
8085 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8087 dwo_file
->sections
.abbrev
.asection
= sectp
;
8088 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
8090 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
8092 dwo_file
->sections
.info
.asection
= sectp
;
8093 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
8095 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8097 dwo_file
->sections
.line
.asection
= sectp
;
8098 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
8100 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8102 dwo_file
->sections
.loc
.asection
= sectp
;
8103 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
8105 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8107 dwo_file
->sections
.macinfo
.asection
= sectp
;
8108 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
8110 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8112 dwo_file
->sections
.macro
.asection
= sectp
;
8113 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
8115 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
8117 dwo_file
->sections
.str
.asection
= sectp
;
8118 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
8120 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8122 dwo_file
->sections
.str_offsets
.asection
= sectp
;
8123 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
8125 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
8127 struct dwarf2_section_info type_section
;
8129 memset (&type_section
, 0, sizeof (type_section
));
8130 type_section
.asection
= sectp
;
8131 type_section
.size
= bfd_get_section_size (sectp
);
8132 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
8137 /* Structure used to pass data to create_debug_info_hash_table_reader. */
8139 struct create_dwo_info_table_data
8141 struct dwo_file
*dwo_file
;
8145 /* die_reader_func for create_debug_info_hash_table. */
8148 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
8150 struct die_info
*comp_unit_die
,
8154 struct dwarf2_cu
*cu
= reader
->cu
;
8155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8156 sect_offset offset
= cu
->per_cu
->offset
;
8157 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
8158 struct create_dwo_info_table_data
*data
= datap
;
8159 struct dwo_file
*dwo_file
= data
->dwo_file
;
8160 htab_t cu_htab
= data
->cu_htab
;
8162 struct attribute
*attr
;
8163 struct dwo_unit
*dwo_unit
;
8165 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8168 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8169 " its dwo_id [in module %s]"),
8170 offset
.sect_off
, dwo_file
->dwo_name
);
8174 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8175 dwo_unit
->dwo_file
= dwo_file
;
8176 dwo_unit
->signature
= DW_UNSND (attr
);
8177 dwo_unit
->info_or_types_section
= section
;
8178 dwo_unit
->offset
= offset
;
8179 dwo_unit
->length
= cu
->per_cu
->length
;
8181 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8182 gdb_assert (slot
!= NULL
);
8185 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8187 complaint (&symfile_complaints
,
8188 _("debug entry at offset 0x%x is duplicate to the entry at"
8189 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8190 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8191 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8192 dwo_file
->dwo_name
);
8197 if (dwarf2_read_debug
)
8198 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8200 phex (dwo_unit
->signature
,
8201 sizeof (dwo_unit
->signature
)));
8204 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
8207 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
8209 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8210 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8213 gdb_byte
*info_ptr
, *end_ptr
;
8214 struct create_dwo_info_table_data create_dwo_info_table_data
;
8216 dwarf2_read_section (objfile
, section
);
8217 info_ptr
= section
->buffer
;
8219 if (info_ptr
== NULL
)
8222 /* We can't set abfd until now because the section may be empty or
8223 not present, in which case section->asection will be NULL. */
8224 abfd
= section
->asection
->owner
;
8226 if (dwarf2_read_debug
)
8227 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8228 bfd_get_filename (abfd
));
8230 cu_htab
= allocate_dwo_unit_table (objfile
);
8232 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8233 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8235 end_ptr
= info_ptr
+ section
->size
;
8236 while (info_ptr
< end_ptr
)
8238 struct dwarf2_per_cu_data per_cu
;
8240 memset (&per_cu
, 0, sizeof (per_cu
));
8241 per_cu
.objfile
= objfile
;
8242 per_cu
.is_debug_types
= 0;
8243 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8244 per_cu
.info_or_types_section
= section
;
8246 init_cutu_and_read_dies_no_follow (&per_cu
,
8247 &dwo_file
->sections
.abbrev
,
8249 create_debug_info_hash_table_reader
,
8250 &create_dwo_info_table_data
);
8252 info_ptr
+= per_cu
.length
;
8258 /* Subroutine of open_dwo_file to simplify it.
8259 Open the file specified by FILE_NAME and hand it off to BFD for
8260 preliminary analysis. Return a newly initialized bfd *, which
8261 includes a canonicalized copy of FILE_NAME.
8262 In case of trouble, return NULL.
8263 NOTE: This function is derived from symfile_bfd_open. */
8266 try_open_dwo_file (const char *file_name
)
8270 char *absolute_name
;
8272 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
8273 O_RDONLY
| O_BINARY
, &absolute_name
);
8277 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
8280 xfree (absolute_name
);
8283 xfree (absolute_name
);
8284 bfd_set_cacheable (sym_bfd
, 1);
8286 if (!bfd_check_format (sym_bfd
, bfd_object
))
8288 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8295 /* Try to open DWO file DWO_NAME.
8296 COMP_DIR is the DW_AT_comp_dir attribute.
8297 The result is the bfd handle of the file.
8298 If there is a problem finding or opening the file, return NULL.
8299 Upon success, the canonicalized path of the file is stored in the bfd,
8300 same as symfile_bfd_open. */
8303 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
8307 if (IS_ABSOLUTE_PATH (dwo_name
))
8308 return try_open_dwo_file (dwo_name
);
8310 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8312 if (comp_dir
!= NULL
)
8314 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
8316 /* NOTE: If comp_dir is a relative path, this will also try the
8317 search path, which seems useful. */
8318 abfd
= try_open_dwo_file (path_to_try
);
8319 xfree (path_to_try
);
8324 /* That didn't work, try debug-file-directory, which, despite its name,
8325 is a list of paths. */
8327 if (*debug_file_directory
== '\0')
8330 return try_open_dwo_file (dwo_name
);
8333 /* Initialize the use of the DWO file specified by DWO_NAME. */
8335 static struct dwo_file
*
8336 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8338 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8339 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8342 struct cleanup
*cleanups
;
8344 if (dwarf2_read_debug
)
8345 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
8347 abfd
= open_dwo_file (dwo_name
, comp_dir
);
8350 dwo_file
->dwo_name
= dwo_name
;
8351 dwo_file
->dwo_bfd
= abfd
;
8353 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8355 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
8357 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
8359 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8360 dwo_file
->sections
.types
);
8362 discard_cleanups (cleanups
);
8367 /* Lookup DWO file DWO_NAME. */
8369 static struct dwo_file
*
8370 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
8372 struct dwo_file
*dwo_file
;
8373 struct dwo_file find_entry
;
8376 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8377 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8379 /* Have we already seen this DWO file? */
8380 find_entry
.dwo_name
= dwo_name
;
8381 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8383 /* If not, read it in and build a table of the DWOs it contains. */
8385 *slot
= init_dwo_file (dwo_name
, comp_dir
);
8387 /* NOTE: This will be NULL if unable to open the file. */
8393 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
8394 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8395 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
8396 nomenclature as TUs).
8397 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8398 (dwo_id mismatch or couldn't find the DWO file). */
8400 static struct dwo_unit
*
8401 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8402 char *dwo_name
, const char *comp_dir
,
8405 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8406 struct dwo_file
*dwo_file
;
8408 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8409 if (dwo_file
== NULL
)
8412 /* Look up the DWO using its signature(dwo_id). */
8414 if (dwo_file
->cus
!= NULL
)
8416 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8418 find_dwo_cu
.signature
= signature
;
8419 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
8425 /* We didn't find it. This must mean a dwo_id mismatch. */
8427 complaint (&symfile_complaints
,
8428 _("Could not find DWO CU referenced by CU at offset 0x%x"
8430 this_cu
->offset
.sect_off
, objfile
->name
);
8434 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
8435 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8436 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8437 (dwo_id mismatch or couldn't find the DWO file). */
8439 static struct dwo_unit
*
8440 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
8441 char *dwo_name
, const char *comp_dir
)
8443 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8444 struct dwo_file
*dwo_file
;
8446 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8447 if (dwo_file
== NULL
)
8450 /* Look up the DWO using its signature(dwo_id). */
8452 if (dwo_file
->tus
!= NULL
)
8454 struct dwo_unit find_dwo_tu
, *dwo_tu
;
8456 find_dwo_tu
.signature
= this_tu
->signature
;
8457 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
8463 /* We didn't find it. This must mean a dwo_id mismatch. */
8465 complaint (&symfile_complaints
,
8466 _("Could not find DWO TU referenced by TU at offset 0x%x"
8468 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
8472 /* Free all resources associated with DWO_FILE.
8473 Close the DWO file and munmap the sections.
8474 All memory should be on the objfile obstack. */
8477 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
8480 struct dwarf2_section_info
*section
;
8482 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
8483 gdb_bfd_unref (dwo_file
->dwo_bfd
);
8485 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
8488 /* Wrapper for free_dwo_file for use in cleanups. */
8491 free_dwo_file_cleanup (void *arg
)
8493 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
8494 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8496 free_dwo_file (dwo_file
, objfile
);
8499 /* Traversal function for free_dwo_files. */
8502 free_dwo_file_from_slot (void **slot
, void *info
)
8504 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8505 struct objfile
*objfile
= (struct objfile
*) info
;
8507 free_dwo_file (dwo_file
, objfile
);
8512 /* Free all resources associated with DWO_FILES. */
8515 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
8517 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
8520 /* Read in various DIEs. */
8522 /* qsort helper for inherit_abstract_dies. */
8525 unsigned_int_compar (const void *ap
, const void *bp
)
8527 unsigned int a
= *(unsigned int *) ap
;
8528 unsigned int b
= *(unsigned int *) bp
;
8530 return (a
> b
) - (b
> a
);
8533 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
8534 Inherit only the children of the DW_AT_abstract_origin DIE not being
8535 already referenced by DW_AT_abstract_origin from the children of the
8539 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
8541 struct die_info
*child_die
;
8542 unsigned die_children_count
;
8543 /* CU offsets which were referenced by children of the current DIE. */
8544 sect_offset
*offsets
;
8545 sect_offset
*offsets_end
, *offsetp
;
8546 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
8547 struct die_info
*origin_die
;
8548 /* Iterator of the ORIGIN_DIE children. */
8549 struct die_info
*origin_child_die
;
8550 struct cleanup
*cleanups
;
8551 struct attribute
*attr
;
8552 struct dwarf2_cu
*origin_cu
;
8553 struct pending
**origin_previous_list_in_scope
;
8555 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8559 /* Note that following die references may follow to a die in a
8563 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
8565 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
8567 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
8568 origin_cu
->list_in_scope
= cu
->list_in_scope
;
8570 if (die
->tag
!= origin_die
->tag
8571 && !(die
->tag
== DW_TAG_inlined_subroutine
8572 && origin_die
->tag
== DW_TAG_subprogram
))
8573 complaint (&symfile_complaints
,
8574 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
8575 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
8577 child_die
= die
->child
;
8578 die_children_count
= 0;
8579 while (child_die
&& child_die
->tag
)
8581 child_die
= sibling_die (child_die
);
8582 die_children_count
++;
8584 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
8585 cleanups
= make_cleanup (xfree
, offsets
);
8587 offsets_end
= offsets
;
8588 child_die
= die
->child
;
8589 while (child_die
&& child_die
->tag
)
8591 /* For each CHILD_DIE, find the corresponding child of
8592 ORIGIN_DIE. If there is more than one layer of
8593 DW_AT_abstract_origin, follow them all; there shouldn't be,
8594 but GCC versions at least through 4.4 generate this (GCC PR
8596 struct die_info
*child_origin_die
= child_die
;
8597 struct dwarf2_cu
*child_origin_cu
= cu
;
8601 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
8605 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
8609 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
8610 counterpart may exist. */
8611 if (child_origin_die
!= child_die
)
8613 if (child_die
->tag
!= child_origin_die
->tag
8614 && !(child_die
->tag
== DW_TAG_inlined_subroutine
8615 && child_origin_die
->tag
== DW_TAG_subprogram
))
8616 complaint (&symfile_complaints
,
8617 _("Child DIE 0x%x and its abstract origin 0x%x have "
8618 "different tags"), child_die
->offset
.sect_off
,
8619 child_origin_die
->offset
.sect_off
);
8620 if (child_origin_die
->parent
!= origin_die
)
8621 complaint (&symfile_complaints
,
8622 _("Child DIE 0x%x and its abstract origin 0x%x have "
8623 "different parents"), child_die
->offset
.sect_off
,
8624 child_origin_die
->offset
.sect_off
);
8626 *offsets_end
++ = child_origin_die
->offset
;
8628 child_die
= sibling_die (child_die
);
8630 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
8631 unsigned_int_compar
);
8632 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
8633 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
8634 complaint (&symfile_complaints
,
8635 _("Multiple children of DIE 0x%x refer "
8636 "to DIE 0x%x as their abstract origin"),
8637 die
->offset
.sect_off
, offsetp
->sect_off
);
8640 origin_child_die
= origin_die
->child
;
8641 while (origin_child_die
&& origin_child_die
->tag
)
8643 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
8644 while (offsetp
< offsets_end
8645 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
8647 if (offsetp
>= offsets_end
8648 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
8650 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
8651 process_die (origin_child_die
, origin_cu
);
8653 origin_child_die
= sibling_die (origin_child_die
);
8655 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
8657 do_cleanups (cleanups
);
8661 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8663 struct objfile
*objfile
= cu
->objfile
;
8664 struct context_stack
*new;
8667 struct die_info
*child_die
;
8668 struct attribute
*attr
, *call_line
, *call_file
;
8671 struct block
*block
;
8672 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8673 VEC (symbolp
) *template_args
= NULL
;
8674 struct template_symbol
*templ_func
= NULL
;
8678 /* If we do not have call site information, we can't show the
8679 caller of this inlined function. That's too confusing, so
8680 only use the scope for local variables. */
8681 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
8682 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
8683 if (call_line
== NULL
|| call_file
== NULL
)
8685 read_lexical_block_scope (die
, cu
);
8690 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8692 name
= dwarf2_name (die
, cu
);
8694 /* Ignore functions with missing or empty names. These are actually
8695 illegal according to the DWARF standard. */
8698 complaint (&symfile_complaints
,
8699 _("missing name for subprogram DIE at %d"),
8700 die
->offset
.sect_off
);
8704 /* Ignore functions with missing or invalid low and high pc attributes. */
8705 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8707 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8708 if (!attr
|| !DW_UNSND (attr
))
8709 complaint (&symfile_complaints
,
8710 _("cannot get low and high bounds "
8711 "for subprogram DIE at %d"),
8712 die
->offset
.sect_off
);
8719 /* If we have any template arguments, then we must allocate a
8720 different sort of symbol. */
8721 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
8723 if (child_die
->tag
== DW_TAG_template_type_param
8724 || child_die
->tag
== DW_TAG_template_value_param
)
8726 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8727 struct template_symbol
);
8728 templ_func
->base
.is_cplus_template_function
= 1;
8733 new = push_context (0, lowpc
);
8734 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
8735 (struct symbol
*) templ_func
);
8737 /* If there is a location expression for DW_AT_frame_base, record
8739 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
8741 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
8742 expression is being recorded directly in the function's symbol
8743 and not in a separate frame-base object. I guess this hack is
8744 to avoid adding some sort of frame-base adjunct/annex to the
8745 function's symbol :-(. The problem with doing this is that it
8746 results in a function symbol with a location expression that
8747 has nothing to do with the location of the function, ouch! The
8748 relationship should be: a function's symbol has-a frame base; a
8749 frame-base has-a location expression. */
8750 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
8752 cu
->list_in_scope
= &local_symbols
;
8754 if (die
->child
!= NULL
)
8756 child_die
= die
->child
;
8757 while (child_die
&& child_die
->tag
)
8759 if (child_die
->tag
== DW_TAG_template_type_param
8760 || child_die
->tag
== DW_TAG_template_value_param
)
8762 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8765 VEC_safe_push (symbolp
, template_args
, arg
);
8768 process_die (child_die
, cu
);
8769 child_die
= sibling_die (child_die
);
8773 inherit_abstract_dies (die
, cu
);
8775 /* If we have a DW_AT_specification, we might need to import using
8776 directives from the context of the specification DIE. See the
8777 comment in determine_prefix. */
8778 if (cu
->language
== language_cplus
8779 && dwarf2_attr (die
, DW_AT_specification
, cu
))
8781 struct dwarf2_cu
*spec_cu
= cu
;
8782 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
8786 child_die
= spec_die
->child
;
8787 while (child_die
&& child_die
->tag
)
8789 if (child_die
->tag
== DW_TAG_imported_module
)
8790 process_die (child_die
, spec_cu
);
8791 child_die
= sibling_die (child_die
);
8794 /* In some cases, GCC generates specification DIEs that
8795 themselves contain DW_AT_specification attributes. */
8796 spec_die
= die_specification (spec_die
, &spec_cu
);
8800 new = pop_context ();
8801 /* Make a block for the local symbols within. */
8802 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
8803 lowpc
, highpc
, objfile
);
8805 /* For C++, set the block's scope. */
8806 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
8807 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
8808 determine_prefix (die
, cu
),
8809 processing_has_namespace_info
);
8811 /* If we have address ranges, record them. */
8812 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8814 /* Attach template arguments to function. */
8815 if (! VEC_empty (symbolp
, template_args
))
8817 gdb_assert (templ_func
!= NULL
);
8819 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
8820 templ_func
->template_arguments
8821 = obstack_alloc (&objfile
->objfile_obstack
,
8822 (templ_func
->n_template_arguments
8823 * sizeof (struct symbol
*)));
8824 memcpy (templ_func
->template_arguments
,
8825 VEC_address (symbolp
, template_args
),
8826 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
8827 VEC_free (symbolp
, template_args
);
8830 /* In C++, we can have functions nested inside functions (e.g., when
8831 a function declares a class that has methods). This means that
8832 when we finish processing a function scope, we may need to go
8833 back to building a containing block's symbol lists. */
8834 local_symbols
= new->locals
;
8835 param_symbols
= new->params
;
8836 using_directives
= new->using_directives
;
8838 /* If we've finished processing a top-level function, subsequent
8839 symbols go in the file symbol list. */
8840 if (outermost_context_p ())
8841 cu
->list_in_scope
= &file_symbols
;
8844 /* Process all the DIES contained within a lexical block scope. Start
8845 a new scope, process the dies, and then close the scope. */
8848 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8850 struct objfile
*objfile
= cu
->objfile
;
8851 struct context_stack
*new;
8852 CORE_ADDR lowpc
, highpc
;
8853 struct die_info
*child_die
;
8856 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8858 /* Ignore blocks with missing or invalid low and high pc attributes. */
8859 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
8860 as multiple lexical blocks? Handling children in a sane way would
8861 be nasty. Might be easier to properly extend generic blocks to
8863 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8868 push_context (0, lowpc
);
8869 if (die
->child
!= NULL
)
8871 child_die
= die
->child
;
8872 while (child_die
&& child_die
->tag
)
8874 process_die (child_die
, cu
);
8875 child_die
= sibling_die (child_die
);
8878 new = pop_context ();
8880 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
8883 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
8886 /* Note that recording ranges after traversing children, as we
8887 do here, means that recording a parent's ranges entails
8888 walking across all its children's ranges as they appear in
8889 the address map, which is quadratic behavior.
8891 It would be nicer to record the parent's ranges before
8892 traversing its children, simply overriding whatever you find
8893 there. But since we don't even decide whether to create a
8894 block until after we've traversed its children, that's hard
8896 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8898 local_symbols
= new->locals
;
8899 using_directives
= new->using_directives
;
8902 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
8905 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8907 struct objfile
*objfile
= cu
->objfile
;
8908 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8909 CORE_ADDR pc
, baseaddr
;
8910 struct attribute
*attr
;
8911 struct call_site
*call_site
, call_site_local
;
8914 struct die_info
*child_die
;
8916 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8918 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8921 complaint (&symfile_complaints
,
8922 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
8923 "DIE 0x%x [in module %s]"),
8924 die
->offset
.sect_off
, objfile
->name
);
8927 pc
= DW_ADDR (attr
) + baseaddr
;
8929 if (cu
->call_site_htab
== NULL
)
8930 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
8931 NULL
, &objfile
->objfile_obstack
,
8932 hashtab_obstack_allocate
, NULL
);
8933 call_site_local
.pc
= pc
;
8934 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
8937 complaint (&symfile_complaints
,
8938 _("Duplicate PC %s for DW_TAG_GNU_call_site "
8939 "DIE 0x%x [in module %s]"),
8940 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
8944 /* Count parameters at the caller. */
8947 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8948 child_die
= sibling_die (child_die
))
8950 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8952 complaint (&symfile_complaints
,
8953 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
8954 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8955 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
8962 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
8963 (sizeof (*call_site
)
8964 + (sizeof (*call_site
->parameter
)
8967 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
8970 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
8972 struct die_info
*func_die
;
8974 /* Skip also over DW_TAG_inlined_subroutine. */
8975 for (func_die
= die
->parent
;
8976 func_die
&& func_die
->tag
!= DW_TAG_subprogram
8977 && func_die
->tag
!= DW_TAG_subroutine_type
;
8978 func_die
= func_die
->parent
);
8980 /* DW_AT_GNU_all_call_sites is a superset
8981 of DW_AT_GNU_all_tail_call_sites. */
8983 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
8984 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
8986 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
8987 not complete. But keep CALL_SITE for look ups via call_site_htab,
8988 both the initial caller containing the real return address PC and
8989 the final callee containing the current PC of a chain of tail
8990 calls do not need to have the tail call list complete. But any
8991 function candidate for a virtual tail call frame searched via
8992 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
8993 determined unambiguously. */
8997 struct type
*func_type
= NULL
;
9000 func_type
= get_die_type (func_die
, cu
);
9001 if (func_type
!= NULL
)
9003 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
9005 /* Enlist this call site to the function. */
9006 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
9007 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
9010 complaint (&symfile_complaints
,
9011 _("Cannot find function owning DW_TAG_GNU_call_site "
9012 "DIE 0x%x [in module %s]"),
9013 die
->offset
.sect_off
, objfile
->name
);
9017 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
9019 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9020 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
9021 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
9022 /* Keep NULL DWARF_BLOCK. */;
9023 else if (attr_form_is_block (attr
))
9025 struct dwarf2_locexpr_baton
*dlbaton
;
9027 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
9028 dlbaton
->data
= DW_BLOCK (attr
)->data
;
9029 dlbaton
->size
= DW_BLOCK (attr
)->size
;
9030 dlbaton
->per_cu
= cu
->per_cu
;
9032 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
9034 else if (is_ref_attr (attr
))
9036 struct dwarf2_cu
*target_cu
= cu
;
9037 struct die_info
*target_die
;
9039 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
9040 gdb_assert (target_cu
->objfile
== objfile
);
9041 if (die_is_declaration (target_die
, target_cu
))
9043 const char *target_physname
;
9045 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
9046 if (target_physname
== NULL
)
9047 complaint (&symfile_complaints
,
9048 _("DW_AT_GNU_call_site_target target DIE has invalid "
9049 "physname, for referencing DIE 0x%x [in module %s]"),
9050 die
->offset
.sect_off
, objfile
->name
);
9052 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
9058 /* DW_AT_entry_pc should be preferred. */
9059 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
9060 complaint (&symfile_complaints
,
9061 _("DW_AT_GNU_call_site_target target DIE has invalid "
9062 "low pc, for referencing DIE 0x%x [in module %s]"),
9063 die
->offset
.sect_off
, objfile
->name
);
9065 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
9069 complaint (&symfile_complaints
,
9070 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9071 "block nor reference, for DIE 0x%x [in module %s]"),
9072 die
->offset
.sect_off
, objfile
->name
);
9074 call_site
->per_cu
= cu
->per_cu
;
9076 for (child_die
= die
->child
;
9077 child_die
&& child_die
->tag
;
9078 child_die
= sibling_die (child_die
))
9080 struct call_site_parameter
*parameter
;
9081 struct attribute
*loc
, *origin
;
9083 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9085 /* Already printed the complaint above. */
9089 gdb_assert (call_site
->parameter_count
< nparams
);
9090 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
9092 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9093 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9094 register is contained in DW_AT_GNU_call_site_value. */
9096 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
9097 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
9098 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
9102 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
9103 offset
= dwarf2_get_ref_die_offset (origin
);
9104 if (!offset_in_cu_p (&cu
->header
, offset
))
9106 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9107 binding can be done only inside one CU. Such referenced DIE
9108 therefore cannot be even moved to DW_TAG_partial_unit. */
9109 complaint (&symfile_complaints
,
9110 _("DW_AT_abstract_origin offset is not in CU for "
9111 "DW_TAG_GNU_call_site child DIE 0x%x "
9113 child_die
->offset
.sect_off
, objfile
->name
);
9116 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
9117 - cu
->header
.offset
.sect_off
);
9119 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
9121 complaint (&symfile_complaints
,
9122 _("No DW_FORM_block* DW_AT_location for "
9123 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9124 child_die
->offset
.sect_off
, objfile
->name
);
9129 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
9130 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
9131 if (parameter
->u
.dwarf_reg
!= -1)
9132 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
9133 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
9134 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
9135 ¶meter
->u
.fb_offset
))
9136 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
9139 complaint (&symfile_complaints
,
9140 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9141 "for DW_FORM_block* DW_AT_location is supported for "
9142 "DW_TAG_GNU_call_site child DIE 0x%x "
9144 child_die
->offset
.sect_off
, objfile
->name
);
9149 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9150 if (!attr_form_is_block (attr
))
9152 complaint (&symfile_complaints
,
9153 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9154 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9155 child_die
->offset
.sect_off
, objfile
->name
);
9158 parameter
->value
= DW_BLOCK (attr
)->data
;
9159 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9161 /* Parameters are not pre-cleared by memset above. */
9162 parameter
->data_value
= NULL
;
9163 parameter
->data_value_size
= 0;
9164 call_site
->parameter_count
++;
9166 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9169 if (!attr_form_is_block (attr
))
9170 complaint (&symfile_complaints
,
9171 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9172 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9173 child_die
->offset
.sect_off
, objfile
->name
);
9176 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9177 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9183 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9184 Return 1 if the attributes are present and valid, otherwise, return 0.
9185 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9188 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9189 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9190 struct partial_symtab
*ranges_pst
)
9192 struct objfile
*objfile
= cu
->objfile
;
9193 struct comp_unit_head
*cu_header
= &cu
->header
;
9194 bfd
*obfd
= objfile
->obfd
;
9195 unsigned int addr_size
= cu_header
->addr_size
;
9196 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9197 /* Base address selection entry. */
9208 found_base
= cu
->base_known
;
9209 base
= cu
->base_address
;
9211 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9212 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9214 complaint (&symfile_complaints
,
9215 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9219 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9221 /* Read in the largest possible address. */
9222 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9223 if ((marker
& mask
) == mask
)
9225 /* If we found the largest possible address, then
9226 read the base address. */
9227 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9228 buffer
+= 2 * addr_size
;
9229 offset
+= 2 * addr_size
;
9235 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9239 CORE_ADDR range_beginning
, range_end
;
9241 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9242 buffer
+= addr_size
;
9243 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9244 buffer
+= addr_size
;
9245 offset
+= 2 * addr_size
;
9247 /* An end of list marker is a pair of zero addresses. */
9248 if (range_beginning
== 0 && range_end
== 0)
9249 /* Found the end of list entry. */
9252 /* Each base address selection entry is a pair of 2 values.
9253 The first is the largest possible address, the second is
9254 the base address. Check for a base address here. */
9255 if ((range_beginning
& mask
) == mask
)
9257 /* If we found the largest possible address, then
9258 read the base address. */
9259 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9266 /* We have no valid base address for the ranges
9268 complaint (&symfile_complaints
,
9269 _("Invalid .debug_ranges data (no base address)"));
9273 if (range_beginning
> range_end
)
9275 /* Inverted range entries are invalid. */
9276 complaint (&symfile_complaints
,
9277 _("Invalid .debug_ranges data (inverted range)"));
9281 /* Empty range entries have no effect. */
9282 if (range_beginning
== range_end
)
9285 range_beginning
+= base
;
9288 /* A not-uncommon case of bad debug info.
9289 Don't pollute the addrmap with bad data. */
9290 if (range_beginning
+ baseaddr
== 0
9291 && !dwarf2_per_objfile
->has_section_at_zero
)
9293 complaint (&symfile_complaints
,
9294 _(".debug_ranges entry has start address of zero"
9295 " [in module %s]"), objfile
->name
);
9299 if (ranges_pst
!= NULL
)
9300 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9301 range_beginning
+ baseaddr
,
9302 range_end
- 1 + baseaddr
,
9305 /* FIXME: This is recording everything as a low-high
9306 segment of consecutive addresses. We should have a
9307 data structure for discontiguous block ranges
9311 low
= range_beginning
;
9317 if (range_beginning
< low
)
9318 low
= range_beginning
;
9319 if (range_end
> high
)
9325 /* If the first entry is an end-of-list marker, the range
9326 describes an empty scope, i.e. no instructions. */
9332 *high_return
= high
;
9336 /* Get low and high pc attributes from a die. Return 1 if the attributes
9337 are present and valid, otherwise, return 0. Return -1 if the range is
9338 discontinuous, i.e. derived from DW_AT_ranges information. */
9341 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
9342 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
9343 struct partial_symtab
*pst
)
9345 struct attribute
*attr
;
9346 struct attribute
*attr_high
;
9351 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9354 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9357 low
= DW_ADDR (attr
);
9358 if (attr_high
->form
== DW_FORM_addr
9359 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9360 high
= DW_ADDR (attr_high
);
9362 high
= low
+ DW_UNSND (attr_high
);
9365 /* Found high w/o low attribute. */
9368 /* Found consecutive range of addresses. */
9373 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9376 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9378 /* Value of the DW_AT_ranges attribute is the offset in the
9379 .debug_ranges section. */
9380 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
9382 /* Found discontinuous range of addresses. */
9387 /* read_partial_die has also the strict LOW < HIGH requirement. */
9391 /* When using the GNU linker, .gnu.linkonce. sections are used to
9392 eliminate duplicate copies of functions and vtables and such.
9393 The linker will arbitrarily choose one and discard the others.
9394 The AT_*_pc values for such functions refer to local labels in
9395 these sections. If the section from that file was discarded, the
9396 labels are not in the output, so the relocs get a value of 0.
9397 If this is a discarded function, mark the pc bounds as invalid,
9398 so that GDB will ignore it. */
9399 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9408 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
9409 its low and high PC addresses. Do nothing if these addresses could not
9410 be determined. Otherwise, set LOWPC to the low address if it is smaller,
9411 and HIGHPC to the high address if greater than HIGHPC. */
9414 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
9415 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9416 struct dwarf2_cu
*cu
)
9418 CORE_ADDR low
, high
;
9419 struct die_info
*child
= die
->child
;
9421 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
9423 *lowpc
= min (*lowpc
, low
);
9424 *highpc
= max (*highpc
, high
);
9427 /* If the language does not allow nested subprograms (either inside
9428 subprograms or lexical blocks), we're done. */
9429 if (cu
->language
!= language_ada
)
9432 /* Check all the children of the given DIE. If it contains nested
9433 subprograms, then check their pc bounds. Likewise, we need to
9434 check lexical blocks as well, as they may also contain subprogram
9436 while (child
&& child
->tag
)
9438 if (child
->tag
== DW_TAG_subprogram
9439 || child
->tag
== DW_TAG_lexical_block
)
9440 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
9441 child
= sibling_die (child
);
9445 /* Get the low and high pc's represented by the scope DIE, and store
9446 them in *LOWPC and *HIGHPC. If the correct values can't be
9447 determined, set *LOWPC to -1 and *HIGHPC to 0. */
9450 get_scope_pc_bounds (struct die_info
*die
,
9451 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9452 struct dwarf2_cu
*cu
)
9454 CORE_ADDR best_low
= (CORE_ADDR
) -1;
9455 CORE_ADDR best_high
= (CORE_ADDR
) 0;
9456 CORE_ADDR current_low
, current_high
;
9458 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
9460 best_low
= current_low
;
9461 best_high
= current_high
;
9465 struct die_info
*child
= die
->child
;
9467 while (child
&& child
->tag
)
9469 switch (child
->tag
) {
9470 case DW_TAG_subprogram
:
9471 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
9473 case DW_TAG_namespace
:
9475 /* FIXME: carlton/2004-01-16: Should we do this for
9476 DW_TAG_class_type/DW_TAG_structure_type, too? I think
9477 that current GCC's always emit the DIEs corresponding
9478 to definitions of methods of classes as children of a
9479 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
9480 the DIEs giving the declarations, which could be
9481 anywhere). But I don't see any reason why the
9482 standards says that they have to be there. */
9483 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
9485 if (current_low
!= ((CORE_ADDR
) -1))
9487 best_low
= min (best_low
, current_low
);
9488 best_high
= max (best_high
, current_high
);
9496 child
= sibling_die (child
);
9501 *highpc
= best_high
;
9504 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
9508 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
9509 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
9511 struct objfile
*objfile
= cu
->objfile
;
9512 struct attribute
*attr
;
9513 struct attribute
*attr_high
;
9515 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9518 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9521 CORE_ADDR low
= DW_ADDR (attr
);
9523 if (attr_high
->form
== DW_FORM_addr
9524 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9525 high
= DW_ADDR (attr_high
);
9527 high
= low
+ DW_UNSND (attr_high
);
9529 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
9533 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9536 bfd
*obfd
= objfile
->obfd
;
9538 /* The value of the DW_AT_ranges attribute is the offset of the
9539 address range list in the .debug_ranges section. */
9540 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9541 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9543 /* For some target architectures, but not others, the
9544 read_address function sign-extends the addresses it returns.
9545 To recognize base address selection entries, we need a
9547 unsigned int addr_size
= cu
->header
.addr_size
;
9548 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9550 /* The base address, to which the next pair is relative. Note
9551 that this 'base' is a DWARF concept: most entries in a range
9552 list are relative, to reduce the number of relocs against the
9553 debugging information. This is separate from this function's
9554 'baseaddr' argument, which GDB uses to relocate debugging
9555 information from a shared library based on the address at
9556 which the library was loaded. */
9557 CORE_ADDR base
= cu
->base_address
;
9558 int base_known
= cu
->base_known
;
9560 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
9561 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9563 complaint (&symfile_complaints
,
9564 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
9571 unsigned int bytes_read
;
9572 CORE_ADDR start
, end
;
9574 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9575 buffer
+= bytes_read
;
9576 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9577 buffer
+= bytes_read
;
9579 /* Did we find the end of the range list? */
9580 if (start
== 0 && end
== 0)
9583 /* Did we find a base address selection entry? */
9584 else if ((start
& base_select_mask
) == base_select_mask
)
9590 /* We found an ordinary address range. */
9595 complaint (&symfile_complaints
,
9596 _("Invalid .debug_ranges data "
9597 "(no base address)"));
9603 /* Inverted range entries are invalid. */
9604 complaint (&symfile_complaints
,
9605 _("Invalid .debug_ranges data "
9606 "(inverted range)"));
9610 /* Empty range entries have no effect. */
9614 start
+= base
+ baseaddr
;
9615 end
+= base
+ baseaddr
;
9617 /* A not-uncommon case of bad debug info.
9618 Don't pollute the addrmap with bad data. */
9619 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9621 complaint (&symfile_complaints
,
9622 _(".debug_ranges entry has start address of zero"
9623 " [in module %s]"), objfile
->name
);
9627 record_block_range (block
, start
, end
- 1);
9633 /* Check whether the producer field indicates either of GCC < 4.6, or the
9634 Intel C/C++ compiler, and cache the result in CU. */
9637 check_producer (struct dwarf2_cu
*cu
)
9640 int major
, minor
, release
;
9642 if (cu
->producer
== NULL
)
9644 /* For unknown compilers expect their behavior is DWARF version
9647 GCC started to support .debug_types sections by -gdwarf-4 since
9648 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
9649 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
9650 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
9651 interpreted incorrectly by GDB now - GCC PR debug/48229. */
9653 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
9655 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
9657 cs
= &cu
->producer
[strlen ("GNU ")];
9658 while (*cs
&& !isdigit (*cs
))
9660 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
9662 /* Not recognized as GCC. */
9665 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
9667 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
9668 cu
->producer_is_icc
= 1;
9671 /* For other non-GCC compilers, expect their behavior is DWARF version
9675 cu
->checked_producer
= 1;
9678 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
9679 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
9680 during 4.6.0 experimental. */
9683 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
9685 if (!cu
->checked_producer
)
9686 check_producer (cu
);
9688 return cu
->producer_is_gxx_lt_4_6
;
9691 /* Return the default accessibility type if it is not overriden by
9692 DW_AT_accessibility. */
9694 static enum dwarf_access_attribute
9695 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
9697 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
9699 /* The default DWARF 2 accessibility for members is public, the default
9700 accessibility for inheritance is private. */
9702 if (die
->tag
!= DW_TAG_inheritance
)
9703 return DW_ACCESS_public
;
9705 return DW_ACCESS_private
;
9709 /* DWARF 3+ defines the default accessibility a different way. The same
9710 rules apply now for DW_TAG_inheritance as for the members and it only
9711 depends on the container kind. */
9713 if (die
->parent
->tag
== DW_TAG_class_type
)
9714 return DW_ACCESS_private
;
9716 return DW_ACCESS_public
;
9720 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
9721 offset. If the attribute was not found return 0, otherwise return
9722 1. If it was found but could not properly be handled, set *OFFSET
9726 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
9729 struct attribute
*attr
;
9731 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
9736 /* Note that we do not check for a section offset first here.
9737 This is because DW_AT_data_member_location is new in DWARF 4,
9738 so if we see it, we can assume that a constant form is really
9739 a constant and not a section offset. */
9740 if (attr_form_is_constant (attr
))
9741 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
9742 else if (attr_form_is_section_offset (attr
))
9743 dwarf2_complex_location_expr_complaint ();
9744 else if (attr_form_is_block (attr
))
9745 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9747 dwarf2_complex_location_expr_complaint ();
9755 /* Add an aggregate field to the field list. */
9758 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
9759 struct dwarf2_cu
*cu
)
9761 struct objfile
*objfile
= cu
->objfile
;
9762 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9763 struct nextfield
*new_field
;
9764 struct attribute
*attr
;
9766 char *fieldname
= "";
9768 /* Allocate a new field list entry and link it in. */
9769 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
9770 make_cleanup (xfree
, new_field
);
9771 memset (new_field
, 0, sizeof (struct nextfield
));
9773 if (die
->tag
== DW_TAG_inheritance
)
9775 new_field
->next
= fip
->baseclasses
;
9776 fip
->baseclasses
= new_field
;
9780 new_field
->next
= fip
->fields
;
9781 fip
->fields
= new_field
;
9785 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9787 new_field
->accessibility
= DW_UNSND (attr
);
9789 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
9790 if (new_field
->accessibility
!= DW_ACCESS_public
)
9791 fip
->non_public_fields
= 1;
9793 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9795 new_field
->virtuality
= DW_UNSND (attr
);
9797 new_field
->virtuality
= DW_VIRTUALITY_none
;
9799 fp
= &new_field
->field
;
9801 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
9805 /* Data member other than a C++ static data member. */
9807 /* Get type of field. */
9808 fp
->type
= die_type (die
, cu
);
9810 SET_FIELD_BITPOS (*fp
, 0);
9812 /* Get bit size of field (zero if none). */
9813 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
9816 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
9820 FIELD_BITSIZE (*fp
) = 0;
9823 /* Get bit offset of field. */
9824 if (handle_data_member_location (die
, cu
, &offset
))
9825 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9826 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
9829 if (gdbarch_bits_big_endian (gdbarch
))
9831 /* For big endian bits, the DW_AT_bit_offset gives the
9832 additional bit offset from the MSB of the containing
9833 anonymous object to the MSB of the field. We don't
9834 have to do anything special since we don't need to
9835 know the size of the anonymous object. */
9836 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
9840 /* For little endian bits, compute the bit offset to the
9841 MSB of the anonymous object, subtract off the number of
9842 bits from the MSB of the field to the MSB of the
9843 object, and then subtract off the number of bits of
9844 the field itself. The result is the bit offset of
9845 the LSB of the field. */
9847 int bit_offset
= DW_UNSND (attr
);
9849 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9852 /* The size of the anonymous object containing
9853 the bit field is explicit, so use the
9854 indicated size (in bytes). */
9855 anonymous_size
= DW_UNSND (attr
);
9859 /* The size of the anonymous object containing
9860 the bit field must be inferred from the type
9861 attribute of the data member containing the
9863 anonymous_size
= TYPE_LENGTH (fp
->type
);
9865 SET_FIELD_BITPOS (*fp
,
9867 + anonymous_size
* bits_per_byte
9868 - bit_offset
- FIELD_BITSIZE (*fp
)));
9872 /* Get name of field. */
9873 fieldname
= dwarf2_name (die
, cu
);
9874 if (fieldname
== NULL
)
9877 /* The name is already allocated along with this objfile, so we don't
9878 need to duplicate it for the type. */
9879 fp
->name
= fieldname
;
9881 /* Change accessibility for artificial fields (e.g. virtual table
9882 pointer or virtual base class pointer) to private. */
9883 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
9885 FIELD_ARTIFICIAL (*fp
) = 1;
9886 new_field
->accessibility
= DW_ACCESS_private
;
9887 fip
->non_public_fields
= 1;
9890 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
9892 /* C++ static member. */
9894 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
9895 is a declaration, but all versions of G++ as of this writing
9896 (so through at least 3.2.1) incorrectly generate
9897 DW_TAG_variable tags. */
9899 const char *physname
;
9901 /* Get name of field. */
9902 fieldname
= dwarf2_name (die
, cu
);
9903 if (fieldname
== NULL
)
9906 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9908 /* Only create a symbol if this is an external value.
9909 new_symbol checks this and puts the value in the global symbol
9910 table, which we want. If it is not external, new_symbol
9911 will try to put the value in cu->list_in_scope which is wrong. */
9912 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
9914 /* A static const member, not much different than an enum as far as
9915 we're concerned, except that we can support more types. */
9916 new_symbol (die
, NULL
, cu
);
9919 /* Get physical name. */
9920 physname
= dwarf2_physname (fieldname
, die
, cu
);
9922 /* The name is already allocated along with this objfile, so we don't
9923 need to duplicate it for the type. */
9924 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
9925 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9926 FIELD_NAME (*fp
) = fieldname
;
9928 else if (die
->tag
== DW_TAG_inheritance
)
9932 /* C++ base class field. */
9933 if (handle_data_member_location (die
, cu
, &offset
))
9934 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9935 FIELD_BITSIZE (*fp
) = 0;
9936 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9937 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
9938 fip
->nbaseclasses
++;
9942 /* Add a typedef defined in the scope of the FIP's class. */
9945 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
9946 struct dwarf2_cu
*cu
)
9948 struct objfile
*objfile
= cu
->objfile
;
9949 struct typedef_field_list
*new_field
;
9950 struct attribute
*attr
;
9951 struct typedef_field
*fp
;
9952 char *fieldname
= "";
9954 /* Allocate a new field list entry and link it in. */
9955 new_field
= xzalloc (sizeof (*new_field
));
9956 make_cleanup (xfree
, new_field
);
9958 gdb_assert (die
->tag
== DW_TAG_typedef
);
9960 fp
= &new_field
->field
;
9962 /* Get name of field. */
9963 fp
->name
= dwarf2_name (die
, cu
);
9964 if (fp
->name
== NULL
)
9967 fp
->type
= read_type_die (die
, cu
);
9969 new_field
->next
= fip
->typedef_field_list
;
9970 fip
->typedef_field_list
= new_field
;
9971 fip
->typedef_field_list_count
++;
9974 /* Create the vector of fields, and attach it to the type. */
9977 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
9978 struct dwarf2_cu
*cu
)
9980 int nfields
= fip
->nfields
;
9982 /* Record the field count, allocate space for the array of fields,
9983 and create blank accessibility bitfields if necessary. */
9984 TYPE_NFIELDS (type
) = nfields
;
9985 TYPE_FIELDS (type
) = (struct field
*)
9986 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
9987 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
9989 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
9991 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9993 TYPE_FIELD_PRIVATE_BITS (type
) =
9994 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9995 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
9997 TYPE_FIELD_PROTECTED_BITS (type
) =
9998 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9999 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
10001 TYPE_FIELD_IGNORE_BITS (type
) =
10002 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10003 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
10006 /* If the type has baseclasses, allocate and clear a bit vector for
10007 TYPE_FIELD_VIRTUAL_BITS. */
10008 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
10010 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
10011 unsigned char *pointer
;
10013 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10014 pointer
= TYPE_ALLOC (type
, num_bytes
);
10015 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
10016 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
10017 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
10020 /* Copy the saved-up fields into the field vector. Start from the head of
10021 the list, adding to the tail of the field array, so that they end up in
10022 the same order in the array in which they were added to the list. */
10023 while (nfields
-- > 0)
10025 struct nextfield
*fieldp
;
10029 fieldp
= fip
->fields
;
10030 fip
->fields
= fieldp
->next
;
10034 fieldp
= fip
->baseclasses
;
10035 fip
->baseclasses
= fieldp
->next
;
10038 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
10039 switch (fieldp
->accessibility
)
10041 case DW_ACCESS_private
:
10042 if (cu
->language
!= language_ada
)
10043 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
10046 case DW_ACCESS_protected
:
10047 if (cu
->language
!= language_ada
)
10048 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
10051 case DW_ACCESS_public
:
10055 /* Unknown accessibility. Complain and treat it as public. */
10057 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
10058 fieldp
->accessibility
);
10062 if (nfields
< fip
->nbaseclasses
)
10064 switch (fieldp
->virtuality
)
10066 case DW_VIRTUALITY_virtual
:
10067 case DW_VIRTUALITY_pure_virtual
:
10068 if (cu
->language
== language_ada
)
10069 error (_("unexpected virtuality in component of Ada type"));
10070 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
10077 /* Add a member function to the proper fieldlist. */
10080 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
10081 struct type
*type
, struct dwarf2_cu
*cu
)
10083 struct objfile
*objfile
= cu
->objfile
;
10084 struct attribute
*attr
;
10085 struct fnfieldlist
*flp
;
10087 struct fn_field
*fnp
;
10089 struct nextfnfield
*new_fnfield
;
10090 struct type
*this_type
;
10091 enum dwarf_access_attribute accessibility
;
10093 if (cu
->language
== language_ada
)
10094 error (_("unexpected member function in Ada type"));
10096 /* Get name of member function. */
10097 fieldname
= dwarf2_name (die
, cu
);
10098 if (fieldname
== NULL
)
10101 /* Look up member function name in fieldlist. */
10102 for (i
= 0; i
< fip
->nfnfields
; i
++)
10104 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
10108 /* Create new list element if necessary. */
10109 if (i
< fip
->nfnfields
)
10110 flp
= &fip
->fnfieldlists
[i
];
10113 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10115 fip
->fnfieldlists
= (struct fnfieldlist
*)
10116 xrealloc (fip
->fnfieldlists
,
10117 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
10118 * sizeof (struct fnfieldlist
));
10119 if (fip
->nfnfields
== 0)
10120 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
10122 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
10123 flp
->name
= fieldname
;
10126 i
= fip
->nfnfields
++;
10129 /* Create a new member function field and chain it to the field list
10131 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
10132 make_cleanup (xfree
, new_fnfield
);
10133 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
10134 new_fnfield
->next
= flp
->head
;
10135 flp
->head
= new_fnfield
;
10138 /* Fill in the member function field info. */
10139 fnp
= &new_fnfield
->fnfield
;
10141 /* Delay processing of the physname until later. */
10142 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
10144 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
10149 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
10150 fnp
->physname
= physname
? physname
: "";
10153 fnp
->type
= alloc_type (objfile
);
10154 this_type
= read_type_die (die
, cu
);
10155 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
10157 int nparams
= TYPE_NFIELDS (this_type
);
10159 /* TYPE is the domain of this method, and THIS_TYPE is the type
10160 of the method itself (TYPE_CODE_METHOD). */
10161 smash_to_method_type (fnp
->type
, type
,
10162 TYPE_TARGET_TYPE (this_type
),
10163 TYPE_FIELDS (this_type
),
10164 TYPE_NFIELDS (this_type
),
10165 TYPE_VARARGS (this_type
));
10167 /* Handle static member functions.
10168 Dwarf2 has no clean way to discern C++ static and non-static
10169 member functions. G++ helps GDB by marking the first
10170 parameter for non-static member functions (which is the this
10171 pointer) as artificial. We obtain this information from
10172 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10173 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10174 fnp
->voffset
= VOFFSET_STATIC
;
10177 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10178 dwarf2_full_name (fieldname
, die
, cu
));
10180 /* Get fcontext from DW_AT_containing_type if present. */
10181 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10182 fnp
->fcontext
= die_containing_type (die
, cu
);
10184 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10185 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10187 /* Get accessibility. */
10188 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10190 accessibility
= DW_UNSND (attr
);
10192 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10193 switch (accessibility
)
10195 case DW_ACCESS_private
:
10196 fnp
->is_private
= 1;
10198 case DW_ACCESS_protected
:
10199 fnp
->is_protected
= 1;
10203 /* Check for artificial methods. */
10204 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
10205 if (attr
&& DW_UNSND (attr
) != 0)
10206 fnp
->is_artificial
= 1;
10208 /* Get index in virtual function table if it is a virtual member
10209 function. For older versions of GCC, this is an offset in the
10210 appropriate virtual table, as specified by DW_AT_containing_type.
10211 For everyone else, it is an expression to be evaluated relative
10212 to the object address. */
10214 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
10217 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
10219 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
10221 /* Old-style GCC. */
10222 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
10224 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10225 || (DW_BLOCK (attr
)->size
> 1
10226 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
10227 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
10229 struct dwarf_block blk
;
10232 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10234 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10235 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10236 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10237 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10238 dwarf2_complex_location_expr_complaint ();
10240 fnp
->voffset
/= cu
->header
.addr_size
;
10244 dwarf2_complex_location_expr_complaint ();
10246 if (!fnp
->fcontext
)
10247 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10249 else if (attr_form_is_section_offset (attr
))
10251 dwarf2_complex_location_expr_complaint ();
10255 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10261 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10262 if (attr
&& DW_UNSND (attr
))
10264 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10265 complaint (&symfile_complaints
,
10266 _("Member function \"%s\" (offset %d) is virtual "
10267 "but the vtable offset is not specified"),
10268 fieldname
, die
->offset
.sect_off
);
10269 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10270 TYPE_CPLUS_DYNAMIC (type
) = 1;
10275 /* Create the vector of member function fields, and attach it to the type. */
10278 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10279 struct dwarf2_cu
*cu
)
10281 struct fnfieldlist
*flp
;
10284 if (cu
->language
== language_ada
)
10285 error (_("unexpected member functions in Ada type"));
10287 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10288 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
10289 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
10291 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
10293 struct nextfnfield
*nfp
= flp
->head
;
10294 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
10297 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
10298 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
10299 fn_flp
->fn_fields
= (struct fn_field
*)
10300 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
10301 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
10302 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
10305 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
10308 /* Returns non-zero if NAME is the name of a vtable member in CU's
10309 language, zero otherwise. */
10311 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
10313 static const char vptr
[] = "_vptr";
10314 static const char vtable
[] = "vtable";
10316 /* Look for the C++ and Java forms of the vtable. */
10317 if ((cu
->language
== language_java
10318 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
10319 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
10320 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
10326 /* GCC outputs unnamed structures that are really pointers to member
10327 functions, with the ABI-specified layout. If TYPE describes
10328 such a structure, smash it into a member function type.
10330 GCC shouldn't do this; it should just output pointer to member DIEs.
10331 This is GCC PR debug/28767. */
10334 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
10336 struct type
*pfn_type
, *domain_type
, *new_type
;
10338 /* Check for a structure with no name and two children. */
10339 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
10342 /* Check for __pfn and __delta members. */
10343 if (TYPE_FIELD_NAME (type
, 0) == NULL
10344 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
10345 || TYPE_FIELD_NAME (type
, 1) == NULL
10346 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
10349 /* Find the type of the method. */
10350 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
10351 if (pfn_type
== NULL
10352 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
10353 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
10356 /* Look for the "this" argument. */
10357 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
10358 if (TYPE_NFIELDS (pfn_type
) == 0
10359 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
10360 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
10363 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
10364 new_type
= alloc_type (objfile
);
10365 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
10366 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
10367 TYPE_VARARGS (pfn_type
));
10368 smash_to_methodptr_type (type
, new_type
);
10371 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
10375 producer_is_icc (struct dwarf2_cu
*cu
)
10377 if (!cu
->checked_producer
)
10378 check_producer (cu
);
10380 return cu
->producer_is_icc
;
10383 /* Called when we find the DIE that starts a structure or union scope
10384 (definition) to create a type for the structure or union. Fill in
10385 the type's name and general properties; the members will not be
10386 processed until process_structure_type.
10388 NOTE: we need to call these functions regardless of whether or not the
10389 DIE has a DW_AT_name attribute, since it might be an anonymous
10390 structure or union. This gets the type entered into our set of
10391 user defined types.
10393 However, if the structure is incomplete (an opaque struct/union)
10394 then suppress creating a symbol table entry for it since gdb only
10395 wants to find the one with the complete definition. Note that if
10396 it is complete, we just call new_symbol, which does it's own
10397 checking about whether the struct/union is anonymous or not (and
10398 suppresses creating a symbol table entry itself). */
10400 static struct type
*
10401 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10403 struct objfile
*objfile
= cu
->objfile
;
10405 struct attribute
*attr
;
10408 /* If the definition of this type lives in .debug_types, read that type.
10409 Don't follow DW_AT_specification though, that will take us back up
10410 the chain and we want to go down. */
10411 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10414 struct dwarf2_cu
*type_cu
= cu
;
10415 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10417 /* We could just recurse on read_structure_type, but we need to call
10418 get_die_type to ensure only one type for this DIE is created.
10419 This is important, for example, because for c++ classes we need
10420 TYPE_NAME set which is only done by new_symbol. Blech. */
10421 type
= read_type_die (type_die
, type_cu
);
10423 /* TYPE_CU may not be the same as CU.
10424 Ensure TYPE is recorded in CU's type_hash table. */
10425 return set_die_type (die
, type
, cu
);
10428 type
= alloc_type (objfile
);
10429 INIT_CPLUS_SPECIFIC (type
);
10431 name
= dwarf2_name (die
, cu
);
10434 if (cu
->language
== language_cplus
10435 || cu
->language
== language_java
)
10437 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
10439 /* dwarf2_full_name might have already finished building the DIE's
10440 type. If so, there is no need to continue. */
10441 if (get_die_type (die
, cu
) != NULL
)
10442 return get_die_type (die
, cu
);
10444 TYPE_TAG_NAME (type
) = full_name
;
10445 if (die
->tag
== DW_TAG_structure_type
10446 || die
->tag
== DW_TAG_class_type
)
10447 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10451 /* The name is already allocated along with this objfile, so
10452 we don't need to duplicate it for the type. */
10453 TYPE_TAG_NAME (type
) = (char *) name
;
10454 if (die
->tag
== DW_TAG_class_type
)
10455 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10459 if (die
->tag
== DW_TAG_structure_type
)
10461 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10463 else if (die
->tag
== DW_TAG_union_type
)
10465 TYPE_CODE (type
) = TYPE_CODE_UNION
;
10469 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
10472 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
10473 TYPE_DECLARED_CLASS (type
) = 1;
10475 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10478 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10482 TYPE_LENGTH (type
) = 0;
10485 if (producer_is_icc (cu
))
10487 /* ICC does not output the required DW_AT_declaration
10488 on incomplete types, but gives them a size of zero. */
10491 TYPE_STUB_SUPPORTED (type
) = 1;
10493 if (die_is_declaration (die
, cu
))
10494 TYPE_STUB (type
) = 1;
10495 else if (attr
== NULL
&& die
->child
== NULL
10496 && producer_is_realview (cu
->producer
))
10497 /* RealView does not output the required DW_AT_declaration
10498 on incomplete types. */
10499 TYPE_STUB (type
) = 1;
10501 /* We need to add the type field to the die immediately so we don't
10502 infinitely recurse when dealing with pointers to the structure
10503 type within the structure itself. */
10504 set_die_type (die
, type
, cu
);
10506 /* set_die_type should be already done. */
10507 set_descriptive_type (type
, die
, cu
);
10512 /* Finish creating a structure or union type, including filling in
10513 its members and creating a symbol for it. */
10516 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10518 struct objfile
*objfile
= cu
->objfile
;
10519 struct die_info
*child_die
= die
->child
;
10522 type
= get_die_type (die
, cu
);
10524 type
= read_structure_type (die
, cu
);
10526 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
10528 struct field_info fi
;
10529 struct die_info
*child_die
;
10530 VEC (symbolp
) *template_args
= NULL
;
10531 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
10533 memset (&fi
, 0, sizeof (struct field_info
));
10535 child_die
= die
->child
;
10537 while (child_die
&& child_die
->tag
)
10539 if (child_die
->tag
== DW_TAG_member
10540 || child_die
->tag
== DW_TAG_variable
)
10542 /* NOTE: carlton/2002-11-05: A C++ static data member
10543 should be a DW_TAG_member that is a declaration, but
10544 all versions of G++ as of this writing (so through at
10545 least 3.2.1) incorrectly generate DW_TAG_variable
10546 tags for them instead. */
10547 dwarf2_add_field (&fi
, child_die
, cu
);
10549 else if (child_die
->tag
== DW_TAG_subprogram
)
10551 /* C++ member function. */
10552 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
10554 else if (child_die
->tag
== DW_TAG_inheritance
)
10556 /* C++ base class field. */
10557 dwarf2_add_field (&fi
, child_die
, cu
);
10559 else if (child_die
->tag
== DW_TAG_typedef
)
10560 dwarf2_add_typedef (&fi
, child_die
, cu
);
10561 else if (child_die
->tag
== DW_TAG_template_type_param
10562 || child_die
->tag
== DW_TAG_template_value_param
)
10564 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10567 VEC_safe_push (symbolp
, template_args
, arg
);
10570 child_die
= sibling_die (child_die
);
10573 /* Attach template arguments to type. */
10574 if (! VEC_empty (symbolp
, template_args
))
10576 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10577 TYPE_N_TEMPLATE_ARGUMENTS (type
)
10578 = VEC_length (symbolp
, template_args
);
10579 TYPE_TEMPLATE_ARGUMENTS (type
)
10580 = obstack_alloc (&objfile
->objfile_obstack
,
10581 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10582 * sizeof (struct symbol
*)));
10583 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
10584 VEC_address (symbolp
, template_args
),
10585 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10586 * sizeof (struct symbol
*)));
10587 VEC_free (symbolp
, template_args
);
10590 /* Attach fields and member functions to the type. */
10592 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
10595 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
10597 /* Get the type which refers to the base class (possibly this
10598 class itself) which contains the vtable pointer for the current
10599 class from the DW_AT_containing_type attribute. This use of
10600 DW_AT_containing_type is a GNU extension. */
10602 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10604 struct type
*t
= die_containing_type (die
, cu
);
10606 TYPE_VPTR_BASETYPE (type
) = t
;
10611 /* Our own class provides vtbl ptr. */
10612 for (i
= TYPE_NFIELDS (t
) - 1;
10613 i
>= TYPE_N_BASECLASSES (t
);
10616 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
10618 if (is_vtable_name (fieldname
, cu
))
10620 TYPE_VPTR_FIELDNO (type
) = i
;
10625 /* Complain if virtual function table field not found. */
10626 if (i
< TYPE_N_BASECLASSES (t
))
10627 complaint (&symfile_complaints
,
10628 _("virtual function table pointer "
10629 "not found when defining class '%s'"),
10630 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
10635 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
10638 else if (cu
->producer
10639 && strncmp (cu
->producer
,
10640 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
10642 /* The IBM XLC compiler does not provide direct indication
10643 of the containing type, but the vtable pointer is
10644 always named __vfp. */
10648 for (i
= TYPE_NFIELDS (type
) - 1;
10649 i
>= TYPE_N_BASECLASSES (type
);
10652 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
10654 TYPE_VPTR_FIELDNO (type
) = i
;
10655 TYPE_VPTR_BASETYPE (type
) = type
;
10662 /* Copy fi.typedef_field_list linked list elements content into the
10663 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
10664 if (fi
.typedef_field_list
)
10666 int i
= fi
.typedef_field_list_count
;
10668 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10669 TYPE_TYPEDEF_FIELD_ARRAY (type
)
10670 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
10671 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
10673 /* Reverse the list order to keep the debug info elements order. */
10676 struct typedef_field
*dest
, *src
;
10678 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
10679 src
= &fi
.typedef_field_list
->field
;
10680 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
10685 do_cleanups (back_to
);
10687 if (HAVE_CPLUS_STRUCT (type
))
10688 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
10691 quirk_gcc_member_function_pointer (type
, objfile
);
10693 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
10694 snapshots) has been known to create a die giving a declaration
10695 for a class that has, as a child, a die giving a definition for a
10696 nested class. So we have to process our children even if the
10697 current die is a declaration. Normally, of course, a declaration
10698 won't have any children at all. */
10700 while (child_die
!= NULL
&& child_die
->tag
)
10702 if (child_die
->tag
== DW_TAG_member
10703 || child_die
->tag
== DW_TAG_variable
10704 || child_die
->tag
== DW_TAG_inheritance
10705 || child_die
->tag
== DW_TAG_template_value_param
10706 || child_die
->tag
== DW_TAG_template_type_param
)
10711 process_die (child_die
, cu
);
10713 child_die
= sibling_die (child_die
);
10716 /* Do not consider external references. According to the DWARF standard,
10717 these DIEs are identified by the fact that they have no byte_size
10718 attribute, and a declaration attribute. */
10719 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
10720 || !die_is_declaration (die
, cu
))
10721 new_symbol (die
, type
, cu
);
10724 /* Given a DW_AT_enumeration_type die, set its type. We do not
10725 complete the type's fields yet, or create any symbols. */
10727 static struct type
*
10728 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10730 struct objfile
*objfile
= cu
->objfile
;
10732 struct attribute
*attr
;
10735 /* If the definition of this type lives in .debug_types, read that type.
10736 Don't follow DW_AT_specification though, that will take us back up
10737 the chain and we want to go down. */
10738 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10741 struct dwarf2_cu
*type_cu
= cu
;
10742 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10744 type
= read_type_die (type_die
, type_cu
);
10746 /* TYPE_CU may not be the same as CU.
10747 Ensure TYPE is recorded in CU's type_hash table. */
10748 return set_die_type (die
, type
, cu
);
10751 type
= alloc_type (objfile
);
10753 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
10754 name
= dwarf2_full_name (NULL
, die
, cu
);
10756 TYPE_TAG_NAME (type
) = (char *) name
;
10758 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10761 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10765 TYPE_LENGTH (type
) = 0;
10768 /* The enumeration DIE can be incomplete. In Ada, any type can be
10769 declared as private in the package spec, and then defined only
10770 inside the package body. Such types are known as Taft Amendment
10771 Types. When another package uses such a type, an incomplete DIE
10772 may be generated by the compiler. */
10773 if (die_is_declaration (die
, cu
))
10774 TYPE_STUB (type
) = 1;
10776 return set_die_type (die
, type
, cu
);
10779 /* Given a pointer to a die which begins an enumeration, process all
10780 the dies that define the members of the enumeration, and create the
10781 symbol for the enumeration type.
10783 NOTE: We reverse the order of the element list. */
10786 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10788 struct type
*this_type
;
10790 this_type
= get_die_type (die
, cu
);
10791 if (this_type
== NULL
)
10792 this_type
= read_enumeration_type (die
, cu
);
10794 if (die
->child
!= NULL
)
10796 struct die_info
*child_die
;
10797 struct symbol
*sym
;
10798 struct field
*fields
= NULL
;
10799 int num_fields
= 0;
10800 int unsigned_enum
= 1;
10805 child_die
= die
->child
;
10806 while (child_die
&& child_die
->tag
)
10808 if (child_die
->tag
!= DW_TAG_enumerator
)
10810 process_die (child_die
, cu
);
10814 name
= dwarf2_name (child_die
, cu
);
10817 sym
= new_symbol (child_die
, this_type
, cu
);
10818 if (SYMBOL_VALUE (sym
) < 0)
10823 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
10826 mask
|= SYMBOL_VALUE (sym
);
10828 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10830 fields
= (struct field
*)
10832 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
10833 * sizeof (struct field
));
10836 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
10837 FIELD_TYPE (fields
[num_fields
]) = NULL
;
10838 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
10839 FIELD_BITSIZE (fields
[num_fields
]) = 0;
10845 child_die
= sibling_die (child_die
);
10850 TYPE_NFIELDS (this_type
) = num_fields
;
10851 TYPE_FIELDS (this_type
) = (struct field
*)
10852 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
10853 memcpy (TYPE_FIELDS (this_type
), fields
,
10854 sizeof (struct field
) * num_fields
);
10858 TYPE_UNSIGNED (this_type
) = 1;
10860 TYPE_FLAG_ENUM (this_type
) = 1;
10863 /* If we are reading an enum from a .debug_types unit, and the enum
10864 is a declaration, and the enum is not the signatured type in the
10865 unit, then we do not want to add a symbol for it. Adding a
10866 symbol would in some cases obscure the true definition of the
10867 enum, giving users an incomplete type when the definition is
10868 actually available. Note that we do not want to do this for all
10869 enums which are just declarations, because C++0x allows forward
10870 enum declarations. */
10871 if (cu
->per_cu
->is_debug_types
10872 && die_is_declaration (die
, cu
))
10874 struct signatured_type
*sig_type
;
10877 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
10878 cu
->per_cu
->info_or_types_section
,
10879 cu
->per_cu
->offset
);
10880 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
10881 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
10885 new_symbol (die
, this_type
, cu
);
10888 /* Extract all information from a DW_TAG_array_type DIE and put it in
10889 the DIE's type field. For now, this only handles one dimensional
10892 static struct type
*
10893 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10895 struct objfile
*objfile
= cu
->objfile
;
10896 struct die_info
*child_die
;
10898 struct type
*element_type
, *range_type
, *index_type
;
10899 struct type
**range_types
= NULL
;
10900 struct attribute
*attr
;
10902 struct cleanup
*back_to
;
10905 element_type
= die_type (die
, cu
);
10907 /* The die_type call above may have already set the type for this DIE. */
10908 type
= get_die_type (die
, cu
);
10912 /* Irix 6.2 native cc creates array types without children for
10913 arrays with unspecified length. */
10914 if (die
->child
== NULL
)
10916 index_type
= objfile_type (objfile
)->builtin_int
;
10917 range_type
= create_range_type (NULL
, index_type
, 0, -1);
10918 type
= create_array_type (NULL
, element_type
, range_type
);
10919 return set_die_type (die
, type
, cu
);
10922 back_to
= make_cleanup (null_cleanup
, NULL
);
10923 child_die
= die
->child
;
10924 while (child_die
&& child_die
->tag
)
10926 if (child_die
->tag
== DW_TAG_subrange_type
)
10928 struct type
*child_type
= read_type_die (child_die
, cu
);
10930 if (child_type
!= NULL
)
10932 /* The range type was succesfully read. Save it for the
10933 array type creation. */
10934 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
10936 range_types
= (struct type
**)
10937 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
10938 * sizeof (struct type
*));
10940 make_cleanup (free_current_contents
, &range_types
);
10942 range_types
[ndim
++] = child_type
;
10945 child_die
= sibling_die (child_die
);
10948 /* Dwarf2 dimensions are output from left to right, create the
10949 necessary array types in backwards order. */
10951 type
= element_type
;
10953 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
10958 type
= create_array_type (NULL
, type
, range_types
[i
++]);
10963 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
10966 /* Understand Dwarf2 support for vector types (like they occur on
10967 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
10968 array type. This is not part of the Dwarf2/3 standard yet, but a
10969 custom vendor extension. The main difference between a regular
10970 array and the vector variant is that vectors are passed by value
10972 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
10974 make_vector_type (type
);
10976 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
10977 implementation may choose to implement triple vectors using this
10979 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10982 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
10983 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10985 complaint (&symfile_complaints
,
10986 _("DW_AT_byte_size for array type smaller "
10987 "than the total size of elements"));
10990 name
= dwarf2_name (die
, cu
);
10992 TYPE_NAME (type
) = name
;
10994 /* Install the type in the die. */
10995 set_die_type (die
, type
, cu
);
10997 /* set_die_type should be already done. */
10998 set_descriptive_type (type
, die
, cu
);
11000 do_cleanups (back_to
);
11005 static enum dwarf_array_dim_ordering
11006 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
11008 struct attribute
*attr
;
11010 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
11012 if (attr
) return DW_SND (attr
);
11014 /* GNU F77 is a special case, as at 08/2004 array type info is the
11015 opposite order to the dwarf2 specification, but data is still
11016 laid out as per normal fortran.
11018 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11019 version checking. */
11021 if (cu
->language
== language_fortran
11022 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
11024 return DW_ORD_row_major
;
11027 switch (cu
->language_defn
->la_array_ordering
)
11029 case array_column_major
:
11030 return DW_ORD_col_major
;
11031 case array_row_major
:
11033 return DW_ORD_row_major
;
11037 /* Extract all information from a DW_TAG_set_type DIE and put it in
11038 the DIE's type field. */
11040 static struct type
*
11041 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11043 struct type
*domain_type
, *set_type
;
11044 struct attribute
*attr
;
11046 domain_type
= die_type (die
, cu
);
11048 /* The die_type call above may have already set the type for this DIE. */
11049 set_type
= get_die_type (die
, cu
);
11053 set_type
= create_set_type (NULL
, domain_type
);
11055 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11057 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
11059 return set_die_type (die
, set_type
, cu
);
11062 /* First cut: install each common block member as a global variable. */
11065 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
11067 struct die_info
*child_die
;
11068 struct attribute
*attr
;
11069 struct symbol
*sym
;
11070 CORE_ADDR base
= (CORE_ADDR
) 0;
11072 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11075 /* Support the .debug_loc offsets. */
11076 if (attr_form_is_block (attr
))
11078 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
11080 else if (attr_form_is_section_offset (attr
))
11082 dwarf2_complex_location_expr_complaint ();
11086 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11087 "common block member");
11090 if (die
->child
!= NULL
)
11092 child_die
= die
->child
;
11093 while (child_die
&& child_die
->tag
)
11097 sym
= new_symbol (child_die
, NULL
, cu
);
11099 && handle_data_member_location (child_die
, cu
, &offset
))
11101 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
11102 add_symbol_to_list (sym
, &global_symbols
);
11104 child_die
= sibling_die (child_die
);
11109 /* Create a type for a C++ namespace. */
11111 static struct type
*
11112 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11114 struct objfile
*objfile
= cu
->objfile
;
11115 const char *previous_prefix
, *name
;
11119 /* For extensions, reuse the type of the original namespace. */
11120 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
11122 struct die_info
*ext_die
;
11123 struct dwarf2_cu
*ext_cu
= cu
;
11125 ext_die
= dwarf2_extension (die
, &ext_cu
);
11126 type
= read_type_die (ext_die
, ext_cu
);
11128 /* EXT_CU may not be the same as CU.
11129 Ensure TYPE is recorded in CU's type_hash table. */
11130 return set_die_type (die
, type
, cu
);
11133 name
= namespace_name (die
, &is_anonymous
, cu
);
11135 /* Now build the name of the current namespace. */
11137 previous_prefix
= determine_prefix (die
, cu
);
11138 if (previous_prefix
[0] != '\0')
11139 name
= typename_concat (&objfile
->objfile_obstack
,
11140 previous_prefix
, name
, 0, cu
);
11142 /* Create the type. */
11143 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
11145 TYPE_NAME (type
) = (char *) name
;
11146 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11148 return set_die_type (die
, type
, cu
);
11151 /* Read a C++ namespace. */
11154 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
11156 struct objfile
*objfile
= cu
->objfile
;
11159 /* Add a symbol associated to this if we haven't seen the namespace
11160 before. Also, add a using directive if it's an anonymous
11163 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
11167 type
= read_type_die (die
, cu
);
11168 new_symbol (die
, type
, cu
);
11170 namespace_name (die
, &is_anonymous
, cu
);
11173 const char *previous_prefix
= determine_prefix (die
, cu
);
11175 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
11176 NULL
, NULL
, &objfile
->objfile_obstack
);
11180 if (die
->child
!= NULL
)
11182 struct die_info
*child_die
= die
->child
;
11184 while (child_die
&& child_die
->tag
)
11186 process_die (child_die
, cu
);
11187 child_die
= sibling_die (child_die
);
11192 /* Read a Fortran module as type. This DIE can be only a declaration used for
11193 imported module. Still we need that type as local Fortran "use ... only"
11194 declaration imports depend on the created type in determine_prefix. */
11196 static struct type
*
11197 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11199 struct objfile
*objfile
= cu
->objfile
;
11203 module_name
= dwarf2_name (die
, cu
);
11205 complaint (&symfile_complaints
,
11206 _("DW_TAG_module has no name, offset 0x%x"),
11207 die
->offset
.sect_off
);
11208 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
11210 /* determine_prefix uses TYPE_TAG_NAME. */
11211 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11213 return set_die_type (die
, type
, cu
);
11216 /* Read a Fortran module. */
11219 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
11221 struct die_info
*child_die
= die
->child
;
11223 while (child_die
&& child_die
->tag
)
11225 process_die (child_die
, cu
);
11226 child_die
= sibling_die (child_die
);
11230 /* Return the name of the namespace represented by DIE. Set
11231 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
11234 static const char *
11235 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
11237 struct die_info
*current_die
;
11238 const char *name
= NULL
;
11240 /* Loop through the extensions until we find a name. */
11242 for (current_die
= die
;
11243 current_die
!= NULL
;
11244 current_die
= dwarf2_extension (die
, &cu
))
11246 name
= dwarf2_name (current_die
, cu
);
11251 /* Is it an anonymous namespace? */
11253 *is_anonymous
= (name
== NULL
);
11255 name
= CP_ANONYMOUS_NAMESPACE_STR
;
11260 /* Extract all information from a DW_TAG_pointer_type DIE and add to
11261 the user defined type vector. */
11263 static struct type
*
11264 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11266 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
11267 struct comp_unit_head
*cu_header
= &cu
->header
;
11269 struct attribute
*attr_byte_size
;
11270 struct attribute
*attr_address_class
;
11271 int byte_size
, addr_class
;
11272 struct type
*target_type
;
11274 target_type
= die_type (die
, cu
);
11276 /* The die_type call above may have already set the type for this DIE. */
11277 type
= get_die_type (die
, cu
);
11281 type
= lookup_pointer_type (target_type
);
11283 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11284 if (attr_byte_size
)
11285 byte_size
= DW_UNSND (attr_byte_size
);
11287 byte_size
= cu_header
->addr_size
;
11289 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
11290 if (attr_address_class
)
11291 addr_class
= DW_UNSND (attr_address_class
);
11293 addr_class
= DW_ADDR_none
;
11295 /* If the pointer size or address class is different than the
11296 default, create a type variant marked as such and set the
11297 length accordingly. */
11298 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
11300 if (gdbarch_address_class_type_flags_p (gdbarch
))
11304 type_flags
= gdbarch_address_class_type_flags
11305 (gdbarch
, byte_size
, addr_class
);
11306 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
11308 type
= make_type_with_address_space (type
, type_flags
);
11310 else if (TYPE_LENGTH (type
) != byte_size
)
11312 complaint (&symfile_complaints
,
11313 _("invalid pointer size %d"), byte_size
);
11317 /* Should we also complain about unhandled address classes? */
11321 TYPE_LENGTH (type
) = byte_size
;
11322 return set_die_type (die
, type
, cu
);
11325 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
11326 the user defined type vector. */
11328 static struct type
*
11329 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11332 struct type
*to_type
;
11333 struct type
*domain
;
11335 to_type
= die_type (die
, cu
);
11336 domain
= die_containing_type (die
, cu
);
11338 /* The calls above may have already set the type for this DIE. */
11339 type
= get_die_type (die
, cu
);
11343 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
11344 type
= lookup_methodptr_type (to_type
);
11346 type
= lookup_memberptr_type (to_type
, domain
);
11348 return set_die_type (die
, type
, cu
);
11351 /* Extract all information from a DW_TAG_reference_type DIE and add to
11352 the user defined type vector. */
11354 static struct type
*
11355 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11357 struct comp_unit_head
*cu_header
= &cu
->header
;
11358 struct type
*type
, *target_type
;
11359 struct attribute
*attr
;
11361 target_type
= die_type (die
, cu
);
11363 /* The die_type call above may have already set the type for this DIE. */
11364 type
= get_die_type (die
, cu
);
11368 type
= lookup_reference_type (target_type
);
11369 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11372 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11376 TYPE_LENGTH (type
) = cu_header
->addr_size
;
11378 return set_die_type (die
, type
, cu
);
11381 static struct type
*
11382 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11384 struct type
*base_type
, *cv_type
;
11386 base_type
= die_type (die
, cu
);
11388 /* The die_type call above may have already set the type for this DIE. */
11389 cv_type
= get_die_type (die
, cu
);
11393 /* In case the const qualifier is applied to an array type, the element type
11394 is so qualified, not the array type (section 6.7.3 of C99). */
11395 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
11397 struct type
*el_type
, *inner_array
;
11399 base_type
= copy_type (base_type
);
11400 inner_array
= base_type
;
11402 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
11404 TYPE_TARGET_TYPE (inner_array
) =
11405 copy_type (TYPE_TARGET_TYPE (inner_array
));
11406 inner_array
= TYPE_TARGET_TYPE (inner_array
);
11409 el_type
= TYPE_TARGET_TYPE (inner_array
);
11410 TYPE_TARGET_TYPE (inner_array
) =
11411 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
11413 return set_die_type (die
, base_type
, cu
);
11416 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
11417 return set_die_type (die
, cv_type
, cu
);
11420 static struct type
*
11421 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11423 struct type
*base_type
, *cv_type
;
11425 base_type
= die_type (die
, cu
);
11427 /* The die_type call above may have already set the type for this DIE. */
11428 cv_type
= get_die_type (die
, cu
);
11432 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
11433 return set_die_type (die
, cv_type
, cu
);
11436 /* Extract all information from a DW_TAG_string_type DIE and add to
11437 the user defined type vector. It isn't really a user defined type,
11438 but it behaves like one, with other DIE's using an AT_user_def_type
11439 attribute to reference it. */
11441 static struct type
*
11442 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11444 struct objfile
*objfile
= cu
->objfile
;
11445 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11446 struct type
*type
, *range_type
, *index_type
, *char_type
;
11447 struct attribute
*attr
;
11448 unsigned int length
;
11450 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
11453 length
= DW_UNSND (attr
);
11457 /* Check for the DW_AT_byte_size attribute. */
11458 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11461 length
= DW_UNSND (attr
);
11469 index_type
= objfile_type (objfile
)->builtin_int
;
11470 range_type
= create_range_type (NULL
, index_type
, 1, length
);
11471 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
11472 type
= create_string_type (NULL
, char_type
, range_type
);
11474 return set_die_type (die
, type
, cu
);
11477 /* Handle DIES due to C code like:
11481 int (*funcp)(int a, long l);
11485 ('funcp' generates a DW_TAG_subroutine_type DIE). */
11487 static struct type
*
11488 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11490 struct objfile
*objfile
= cu
->objfile
;
11491 struct type
*type
; /* Type that this function returns. */
11492 struct type
*ftype
; /* Function that returns above type. */
11493 struct attribute
*attr
;
11495 type
= die_type (die
, cu
);
11497 /* The die_type call above may have already set the type for this DIE. */
11498 ftype
= get_die_type (die
, cu
);
11502 ftype
= lookup_function_type (type
);
11504 /* All functions in C++, Pascal and Java have prototypes. */
11505 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
11506 if ((attr
&& (DW_UNSND (attr
) != 0))
11507 || cu
->language
== language_cplus
11508 || cu
->language
== language_java
11509 || cu
->language
== language_pascal
)
11510 TYPE_PROTOTYPED (ftype
) = 1;
11511 else if (producer_is_realview (cu
->producer
))
11512 /* RealView does not emit DW_AT_prototyped. We can not
11513 distinguish prototyped and unprototyped functions; default to
11514 prototyped, since that is more common in modern code (and
11515 RealView warns about unprototyped functions). */
11516 TYPE_PROTOTYPED (ftype
) = 1;
11518 /* Store the calling convention in the type if it's available in
11519 the subroutine die. Otherwise set the calling convention to
11520 the default value DW_CC_normal. */
11521 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
11523 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
11524 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
11525 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
11527 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
11529 /* We need to add the subroutine type to the die immediately so
11530 we don't infinitely recurse when dealing with parameters
11531 declared as the same subroutine type. */
11532 set_die_type (die
, ftype
, cu
);
11534 if (die
->child
!= NULL
)
11536 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
11537 struct die_info
*child_die
;
11538 int nparams
, iparams
;
11540 /* Count the number of parameters.
11541 FIXME: GDB currently ignores vararg functions, but knows about
11542 vararg member functions. */
11544 child_die
= die
->child
;
11545 while (child_die
&& child_die
->tag
)
11547 if (child_die
->tag
== DW_TAG_formal_parameter
)
11549 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
11550 TYPE_VARARGS (ftype
) = 1;
11551 child_die
= sibling_die (child_die
);
11554 /* Allocate storage for parameters and fill them in. */
11555 TYPE_NFIELDS (ftype
) = nparams
;
11556 TYPE_FIELDS (ftype
) = (struct field
*)
11557 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
11559 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
11560 even if we error out during the parameters reading below. */
11561 for (iparams
= 0; iparams
< nparams
; iparams
++)
11562 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
11565 child_die
= die
->child
;
11566 while (child_die
&& child_die
->tag
)
11568 if (child_die
->tag
== DW_TAG_formal_parameter
)
11570 struct type
*arg_type
;
11572 /* DWARF version 2 has no clean way to discern C++
11573 static and non-static member functions. G++ helps
11574 GDB by marking the first parameter for non-static
11575 member functions (which is the this pointer) as
11576 artificial. We pass this information to
11577 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
11579 DWARF version 3 added DW_AT_object_pointer, which GCC
11580 4.5 does not yet generate. */
11581 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
11583 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
11586 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
11588 /* GCC/43521: In java, the formal parameter
11589 "this" is sometimes not marked with DW_AT_artificial. */
11590 if (cu
->language
== language_java
)
11592 const char *name
= dwarf2_name (child_die
, cu
);
11594 if (name
&& !strcmp (name
, "this"))
11595 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
11598 arg_type
= die_type (child_die
, cu
);
11600 /* RealView does not mark THIS as const, which the testsuite
11601 expects. GCC marks THIS as const in method definitions,
11602 but not in the class specifications (GCC PR 43053). */
11603 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
11604 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
11607 struct dwarf2_cu
*arg_cu
= cu
;
11608 const char *name
= dwarf2_name (child_die
, cu
);
11610 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
11613 /* If the compiler emits this, use it. */
11614 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
11617 else if (name
&& strcmp (name
, "this") == 0)
11618 /* Function definitions will have the argument names. */
11620 else if (name
== NULL
&& iparams
== 0)
11621 /* Declarations may not have the names, so like
11622 elsewhere in GDB, assume an artificial first
11623 argument is "this". */
11627 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
11631 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
11634 child_die
= sibling_die (child_die
);
11641 static struct type
*
11642 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
11644 struct objfile
*objfile
= cu
->objfile
;
11645 const char *name
= NULL
;
11646 struct type
*this_type
, *target_type
;
11648 name
= dwarf2_full_name (NULL
, die
, cu
);
11649 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
11650 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
11651 TYPE_NAME (this_type
) = (char *) name
;
11652 set_die_type (die
, this_type
, cu
);
11653 target_type
= die_type (die
, cu
);
11654 if (target_type
!= this_type
)
11655 TYPE_TARGET_TYPE (this_type
) = target_type
;
11658 /* Self-referential typedefs are, it seems, not allowed by the DWARF
11659 spec and cause infinite loops in GDB. */
11660 complaint (&symfile_complaints
,
11661 _("Self-referential DW_TAG_typedef "
11662 "- DIE at 0x%x [in module %s]"),
11663 die
->offset
.sect_off
, objfile
->name
);
11664 TYPE_TARGET_TYPE (this_type
) = NULL
;
11669 /* Find a representation of a given base type and install
11670 it in the TYPE field of the die. */
11672 static struct type
*
11673 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11675 struct objfile
*objfile
= cu
->objfile
;
11677 struct attribute
*attr
;
11678 int encoding
= 0, size
= 0;
11680 enum type_code code
= TYPE_CODE_INT
;
11681 int type_flags
= 0;
11682 struct type
*target_type
= NULL
;
11684 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
11687 encoding
= DW_UNSND (attr
);
11689 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11692 size
= DW_UNSND (attr
);
11694 name
= dwarf2_name (die
, cu
);
11697 complaint (&symfile_complaints
,
11698 _("DW_AT_name missing from DW_TAG_base_type"));
11703 case DW_ATE_address
:
11704 /* Turn DW_ATE_address into a void * pointer. */
11705 code
= TYPE_CODE_PTR
;
11706 type_flags
|= TYPE_FLAG_UNSIGNED
;
11707 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
11709 case DW_ATE_boolean
:
11710 code
= TYPE_CODE_BOOL
;
11711 type_flags
|= TYPE_FLAG_UNSIGNED
;
11713 case DW_ATE_complex_float
:
11714 code
= TYPE_CODE_COMPLEX
;
11715 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
11717 case DW_ATE_decimal_float
:
11718 code
= TYPE_CODE_DECFLOAT
;
11721 code
= TYPE_CODE_FLT
;
11723 case DW_ATE_signed
:
11725 case DW_ATE_unsigned
:
11726 type_flags
|= TYPE_FLAG_UNSIGNED
;
11727 if (cu
->language
== language_fortran
11729 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
11730 code
= TYPE_CODE_CHAR
;
11732 case DW_ATE_signed_char
:
11733 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11734 || cu
->language
== language_pascal
11735 || cu
->language
== language_fortran
)
11736 code
= TYPE_CODE_CHAR
;
11738 case DW_ATE_unsigned_char
:
11739 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11740 || cu
->language
== language_pascal
11741 || cu
->language
== language_fortran
)
11742 code
= TYPE_CODE_CHAR
;
11743 type_flags
|= TYPE_FLAG_UNSIGNED
;
11746 /* We just treat this as an integer and then recognize the
11747 type by name elsewhere. */
11751 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
11752 dwarf_type_encoding_name (encoding
));
11756 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
11757 TYPE_NAME (type
) = name
;
11758 TYPE_TARGET_TYPE (type
) = target_type
;
11760 if (name
&& strcmp (name
, "char") == 0)
11761 TYPE_NOSIGN (type
) = 1;
11763 return set_die_type (die
, type
, cu
);
11766 /* Read the given DW_AT_subrange DIE. */
11768 static struct type
*
11769 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11771 struct type
*base_type
;
11772 struct type
*range_type
;
11773 struct attribute
*attr
;
11775 int low_default_is_valid
;
11777 LONGEST negative_mask
;
11779 base_type
= die_type (die
, cu
);
11780 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
11781 check_typedef (base_type
);
11783 /* The die_type call above may have already set the type for this DIE. */
11784 range_type
= get_die_type (die
, cu
);
11788 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
11789 omitting DW_AT_lower_bound. */
11790 switch (cu
->language
)
11793 case language_cplus
:
11795 low_default_is_valid
= 1;
11797 case language_fortran
:
11799 low_default_is_valid
= 1;
11802 case language_java
:
11803 case language_objc
:
11805 low_default_is_valid
= (cu
->header
.version
>= 4);
11809 case language_pascal
:
11811 low_default_is_valid
= (cu
->header
.version
>= 4);
11815 low_default_is_valid
= 0;
11819 /* FIXME: For variable sized arrays either of these could be
11820 a variable rather than a constant value. We'll allow it,
11821 but we don't know how to handle it. */
11822 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
11824 low
= dwarf2_get_attr_constant_value (attr
, low
);
11825 else if (!low_default_is_valid
)
11826 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
11827 "- DIE at 0x%x [in module %s]"),
11828 die
->offset
.sect_off
, cu
->objfile
->name
);
11830 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
11833 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
11835 /* GCC encodes arrays with unspecified or dynamic length
11836 with a DW_FORM_block1 attribute or a reference attribute.
11837 FIXME: GDB does not yet know how to handle dynamic
11838 arrays properly, treat them as arrays with unspecified
11841 FIXME: jimb/2003-09-22: GDB does not really know
11842 how to handle arrays of unspecified length
11843 either; we just represent them as zero-length
11844 arrays. Choose an appropriate upper bound given
11845 the lower bound we've computed above. */
11849 high
= dwarf2_get_attr_constant_value (attr
, 1);
11853 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
11856 int count
= dwarf2_get_attr_constant_value (attr
, 1);
11857 high
= low
+ count
- 1;
11861 /* Unspecified array length. */
11866 /* Dwarf-2 specifications explicitly allows to create subrange types
11867 without specifying a base type.
11868 In that case, the base type must be set to the type of
11869 the lower bound, upper bound or count, in that order, if any of these
11870 three attributes references an object that has a type.
11871 If no base type is found, the Dwarf-2 specifications say that
11872 a signed integer type of size equal to the size of an address should
11874 For the following C code: `extern char gdb_int [];'
11875 GCC produces an empty range DIE.
11876 FIXME: muller/2010-05-28: Possible references to object for low bound,
11877 high bound or count are not yet handled by this code. */
11878 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
11880 struct objfile
*objfile
= cu
->objfile
;
11881 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11882 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
11883 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
11885 /* Test "int", "long int", and "long long int" objfile types,
11886 and select the first one having a size above or equal to the
11887 architecture address size. */
11888 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11889 base_type
= int_type
;
11892 int_type
= objfile_type (objfile
)->builtin_long
;
11893 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11894 base_type
= int_type
;
11897 int_type
= objfile_type (objfile
)->builtin_long_long
;
11898 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11899 base_type
= int_type
;
11905 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
11906 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
11907 low
|= negative_mask
;
11908 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
11909 high
|= negative_mask
;
11911 range_type
= create_range_type (NULL
, base_type
, low
, high
);
11913 /* Mark arrays with dynamic length at least as an array of unspecified
11914 length. GDB could check the boundary but before it gets implemented at
11915 least allow accessing the array elements. */
11916 if (attr
&& attr_form_is_block (attr
))
11917 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11919 /* Ada expects an empty array on no boundary attributes. */
11920 if (attr
== NULL
&& cu
->language
!= language_ada
)
11921 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11923 name
= dwarf2_name (die
, cu
);
11925 TYPE_NAME (range_type
) = name
;
11927 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11929 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
11931 set_die_type (die
, range_type
, cu
);
11933 /* set_die_type should be already done. */
11934 set_descriptive_type (range_type
, die
, cu
);
11939 static struct type
*
11940 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11944 /* For now, we only support the C meaning of an unspecified type: void. */
11946 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
11947 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
11949 return set_die_type (die
, type
, cu
);
11952 /* Read a single die and all its descendents. Set the die's sibling
11953 field to NULL; set other fields in the die correctly, and set all
11954 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
11955 location of the info_ptr after reading all of those dies. PARENT
11956 is the parent of the die in question. */
11958 static struct die_info
*
11959 read_die_and_children (const struct die_reader_specs
*reader
,
11960 gdb_byte
*info_ptr
,
11961 gdb_byte
**new_info_ptr
,
11962 struct die_info
*parent
)
11964 struct die_info
*die
;
11968 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
11971 *new_info_ptr
= cur_ptr
;
11974 store_in_ref_table (die
, reader
->cu
);
11977 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
11981 *new_info_ptr
= cur_ptr
;
11984 die
->sibling
= NULL
;
11985 die
->parent
= parent
;
11989 /* Read a die, all of its descendents, and all of its siblings; set
11990 all of the fields of all of the dies correctly. Arguments are as
11991 in read_die_and_children. */
11993 static struct die_info
*
11994 read_die_and_siblings (const struct die_reader_specs
*reader
,
11995 gdb_byte
*info_ptr
,
11996 gdb_byte
**new_info_ptr
,
11997 struct die_info
*parent
)
11999 struct die_info
*first_die
, *last_sibling
;
12002 cur_ptr
= info_ptr
;
12003 first_die
= last_sibling
= NULL
;
12007 struct die_info
*die
12008 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
12012 *new_info_ptr
= cur_ptr
;
12019 last_sibling
->sibling
= die
;
12021 last_sibling
= die
;
12025 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12027 The caller is responsible for filling in the extra attributes
12028 and updating (*DIEP)->num_attrs.
12029 Set DIEP to point to a newly allocated die with its information,
12030 except for its child, sibling, and parent fields.
12031 Set HAS_CHILDREN to tell whether the die has children or not. */
12034 read_full_die_1 (const struct die_reader_specs
*reader
,
12035 struct die_info
**diep
, gdb_byte
*info_ptr
,
12036 int *has_children
, int num_extra_attrs
)
12038 unsigned int abbrev_number
, bytes_read
, i
;
12039 sect_offset offset
;
12040 struct abbrev_info
*abbrev
;
12041 struct die_info
*die
;
12042 struct dwarf2_cu
*cu
= reader
->cu
;
12043 bfd
*abfd
= reader
->abfd
;
12045 offset
.sect_off
= info_ptr
- reader
->buffer
;
12046 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12047 info_ptr
+= bytes_read
;
12048 if (!abbrev_number
)
12055 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
12057 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
12059 bfd_get_filename (abfd
));
12061 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
12062 die
->offset
= offset
;
12063 die
->tag
= abbrev
->tag
;
12064 die
->abbrev
= abbrev_number
;
12066 /* Make the result usable.
12067 The caller needs to update num_attrs after adding the extra
12069 die
->num_attrs
= abbrev
->num_attrs
;
12071 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12072 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
12076 *has_children
= abbrev
->has_children
;
12080 /* Read a die and all its attributes.
12081 Set DIEP to point to a newly allocated die with its information,
12082 except for its child, sibling, and parent fields.
12083 Set HAS_CHILDREN to tell whether the die has children or not. */
12086 read_full_die (const struct die_reader_specs
*reader
,
12087 struct die_info
**diep
, gdb_byte
*info_ptr
,
12090 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
12093 /* Abbreviation tables.
12095 In DWARF version 2, the description of the debugging information is
12096 stored in a separate .debug_abbrev section. Before we read any
12097 dies from a section we read in all abbreviations and install them
12098 in a hash table. */
12100 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
12102 static struct abbrev_info
*
12103 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
12105 struct abbrev_info
*abbrev
;
12107 abbrev
= (struct abbrev_info
*)
12108 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
12109 memset (abbrev
, 0, sizeof (struct abbrev_info
));
12113 /* Add an abbreviation to the table. */
12116 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
12117 unsigned int abbrev_number
,
12118 struct abbrev_info
*abbrev
)
12120 unsigned int hash_number
;
12122 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12123 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
12124 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
12127 /* Look up an abbrev in the table.
12128 Returns NULL if the abbrev is not found. */
12130 static struct abbrev_info
*
12131 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
12132 unsigned int abbrev_number
)
12134 unsigned int hash_number
;
12135 struct abbrev_info
*abbrev
;
12137 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12138 abbrev
= abbrev_table
->abbrevs
[hash_number
];
12142 if (abbrev
->number
== abbrev_number
)
12144 abbrev
= abbrev
->next
;
12149 /* Read in an abbrev table. */
12151 static struct abbrev_table
*
12152 abbrev_table_read_table (struct dwarf2_section_info
*section
,
12153 sect_offset offset
)
12155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12156 bfd
*abfd
= section
->asection
->owner
;
12157 struct abbrev_table
*abbrev_table
;
12158 gdb_byte
*abbrev_ptr
;
12159 struct abbrev_info
*cur_abbrev
;
12160 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
12161 unsigned int abbrev_form
;
12162 struct attr_abbrev
*cur_attrs
;
12163 unsigned int allocated_attrs
;
12165 abbrev_table
= XMALLOC (struct abbrev_table
);
12166 abbrev_table
->offset
= offset
;
12167 obstack_init (&abbrev_table
->abbrev_obstack
);
12168 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12170 * sizeof (struct abbrev_info
*)));
12171 memset (abbrev_table
->abbrevs
, 0,
12172 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
12174 dwarf2_read_section (objfile
, section
);
12175 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
12176 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12177 abbrev_ptr
+= bytes_read
;
12179 allocated_attrs
= ATTR_ALLOC_CHUNK
;
12180 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
12182 /* Loop until we reach an abbrev number of 0. */
12183 while (abbrev_number
)
12185 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
12187 /* read in abbrev header */
12188 cur_abbrev
->number
= abbrev_number
;
12189 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12190 abbrev_ptr
+= bytes_read
;
12191 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
12194 /* now read in declarations */
12195 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12196 abbrev_ptr
+= bytes_read
;
12197 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12198 abbrev_ptr
+= bytes_read
;
12199 while (abbrev_name
)
12201 if (cur_abbrev
->num_attrs
== allocated_attrs
)
12203 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
12205 = xrealloc (cur_attrs
, (allocated_attrs
12206 * sizeof (struct attr_abbrev
)));
12209 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
12210 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
12211 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12212 abbrev_ptr
+= bytes_read
;
12213 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12214 abbrev_ptr
+= bytes_read
;
12217 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12218 (cur_abbrev
->num_attrs
12219 * sizeof (struct attr_abbrev
)));
12220 memcpy (cur_abbrev
->attrs
, cur_attrs
,
12221 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
12223 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
12225 /* Get next abbreviation.
12226 Under Irix6 the abbreviations for a compilation unit are not
12227 always properly terminated with an abbrev number of 0.
12228 Exit loop if we encounter an abbreviation which we have
12229 already read (which means we are about to read the abbreviations
12230 for the next compile unit) or if the end of the abbreviation
12231 table is reached. */
12232 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
12234 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12235 abbrev_ptr
+= bytes_read
;
12236 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
12241 return abbrev_table
;
12244 /* Free the resources held by ABBREV_TABLE. */
12247 abbrev_table_free (struct abbrev_table
*abbrev_table
)
12249 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
12250 xfree (abbrev_table
);
12253 /* Same as abbrev_table_free but as a cleanup.
12254 We pass in a pointer to the pointer to the table so that we can
12255 set the pointer to NULL when we're done. It also simplifies
12256 build_type_unit_groups. */
12259 abbrev_table_free_cleanup (void *table_ptr
)
12261 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
12263 if (*abbrev_table_ptr
!= NULL
)
12264 abbrev_table_free (*abbrev_table_ptr
);
12265 *abbrev_table_ptr
= NULL
;
12268 /* Read the abbrev table for CU from ABBREV_SECTION. */
12271 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
12272 struct dwarf2_section_info
*abbrev_section
)
12275 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
12278 /* Release the memory used by the abbrev table for a compilation unit. */
12281 dwarf2_free_abbrev_table (void *ptr_to_cu
)
12283 struct dwarf2_cu
*cu
= ptr_to_cu
;
12285 abbrev_table_free (cu
->abbrev_table
);
12286 /* Set this to NULL so that we SEGV if we try to read it later,
12287 and also because free_comp_unit verifies this is NULL. */
12288 cu
->abbrev_table
= NULL
;
12291 /* Returns nonzero if TAG represents a type that we might generate a partial
12295 is_type_tag_for_partial (int tag
)
12300 /* Some types that would be reasonable to generate partial symbols for,
12301 that we don't at present. */
12302 case DW_TAG_array_type
:
12303 case DW_TAG_file_type
:
12304 case DW_TAG_ptr_to_member_type
:
12305 case DW_TAG_set_type
:
12306 case DW_TAG_string_type
:
12307 case DW_TAG_subroutine_type
:
12309 case DW_TAG_base_type
:
12310 case DW_TAG_class_type
:
12311 case DW_TAG_interface_type
:
12312 case DW_TAG_enumeration_type
:
12313 case DW_TAG_structure_type
:
12314 case DW_TAG_subrange_type
:
12315 case DW_TAG_typedef
:
12316 case DW_TAG_union_type
:
12323 /* Load all DIEs that are interesting for partial symbols into memory. */
12325 static struct partial_die_info
*
12326 load_partial_dies (const struct die_reader_specs
*reader
,
12327 gdb_byte
*info_ptr
, int building_psymtab
)
12329 struct dwarf2_cu
*cu
= reader
->cu
;
12330 struct objfile
*objfile
= cu
->objfile
;
12331 struct partial_die_info
*part_die
;
12332 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
12333 struct abbrev_info
*abbrev
;
12334 unsigned int bytes_read
;
12335 unsigned int load_all
= 0;
12336 int nesting_level
= 1;
12341 gdb_assert (cu
->per_cu
!= NULL
);
12342 if (cu
->per_cu
->load_all_dies
)
12346 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12350 &cu
->comp_unit_obstack
,
12351 hashtab_obstack_allocate
,
12352 dummy_obstack_deallocate
);
12354 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12355 sizeof (struct partial_die_info
));
12359 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
12361 /* A NULL abbrev means the end of a series of children. */
12362 if (abbrev
== NULL
)
12364 if (--nesting_level
== 0)
12366 /* PART_DIE was probably the last thing allocated on the
12367 comp_unit_obstack, so we could call obstack_free
12368 here. We don't do that because the waste is small,
12369 and will be cleaned up when we're done with this
12370 compilation unit. This way, we're also more robust
12371 against other users of the comp_unit_obstack. */
12374 info_ptr
+= bytes_read
;
12375 last_die
= parent_die
;
12376 parent_die
= parent_die
->die_parent
;
12380 /* Check for template arguments. We never save these; if
12381 they're seen, we just mark the parent, and go on our way. */
12382 if (parent_die
!= NULL
12383 && cu
->language
== language_cplus
12384 && (abbrev
->tag
== DW_TAG_template_type_param
12385 || abbrev
->tag
== DW_TAG_template_value_param
))
12387 parent_die
->has_template_arguments
= 1;
12391 /* We don't need a partial DIE for the template argument. */
12392 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12397 /* We only recurse into c++ subprograms looking for template arguments.
12398 Skip their other children. */
12400 && cu
->language
== language_cplus
12401 && parent_die
!= NULL
12402 && parent_die
->tag
== DW_TAG_subprogram
)
12404 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12408 /* Check whether this DIE is interesting enough to save. Normally
12409 we would not be interested in members here, but there may be
12410 later variables referencing them via DW_AT_specification (for
12411 static members). */
12413 && !is_type_tag_for_partial (abbrev
->tag
)
12414 && abbrev
->tag
!= DW_TAG_constant
12415 && abbrev
->tag
!= DW_TAG_enumerator
12416 && abbrev
->tag
!= DW_TAG_subprogram
12417 && abbrev
->tag
!= DW_TAG_lexical_block
12418 && abbrev
->tag
!= DW_TAG_variable
12419 && abbrev
->tag
!= DW_TAG_namespace
12420 && abbrev
->tag
!= DW_TAG_module
12421 && abbrev
->tag
!= DW_TAG_member
12422 && abbrev
->tag
!= DW_TAG_imported_unit
)
12424 /* Otherwise we skip to the next sibling, if any. */
12425 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12429 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
12432 /* This two-pass algorithm for processing partial symbols has a
12433 high cost in cache pressure. Thus, handle some simple cases
12434 here which cover the majority of C partial symbols. DIEs
12435 which neither have specification tags in them, nor could have
12436 specification tags elsewhere pointing at them, can simply be
12437 processed and discarded.
12439 This segment is also optional; scan_partial_symbols and
12440 add_partial_symbol will handle these DIEs if we chain
12441 them in normally. When compilers which do not emit large
12442 quantities of duplicate debug information are more common,
12443 this code can probably be removed. */
12445 /* Any complete simple types at the top level (pretty much all
12446 of them, for a language without namespaces), can be processed
12448 if (parent_die
== NULL
12449 && part_die
->has_specification
== 0
12450 && part_die
->is_declaration
== 0
12451 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
12452 || part_die
->tag
== DW_TAG_base_type
12453 || part_die
->tag
== DW_TAG_subrange_type
))
12455 if (building_psymtab
&& part_die
->name
!= NULL
)
12456 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12457 VAR_DOMAIN
, LOC_TYPEDEF
,
12458 &objfile
->static_psymbols
,
12459 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12460 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12464 /* The exception for DW_TAG_typedef with has_children above is
12465 a workaround of GCC PR debug/47510. In the case of this complaint
12466 type_name_no_tag_or_error will error on such types later.
12468 GDB skipped children of DW_TAG_typedef by the shortcut above and then
12469 it could not find the child DIEs referenced later, this is checked
12470 above. In correct DWARF DW_TAG_typedef should have no children. */
12472 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
12473 complaint (&symfile_complaints
,
12474 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
12475 "- DIE at 0x%x [in module %s]"),
12476 part_die
->offset
.sect_off
, objfile
->name
);
12478 /* If we're at the second level, and we're an enumerator, and
12479 our parent has no specification (meaning possibly lives in a
12480 namespace elsewhere), then we can add the partial symbol now
12481 instead of queueing it. */
12482 if (part_die
->tag
== DW_TAG_enumerator
12483 && parent_die
!= NULL
12484 && parent_die
->die_parent
== NULL
12485 && parent_die
->tag
== DW_TAG_enumeration_type
12486 && parent_die
->has_specification
== 0)
12488 if (part_die
->name
== NULL
)
12489 complaint (&symfile_complaints
,
12490 _("malformed enumerator DIE ignored"));
12491 else if (building_psymtab
)
12492 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12493 VAR_DOMAIN
, LOC_CONST
,
12494 (cu
->language
== language_cplus
12495 || cu
->language
== language_java
)
12496 ? &objfile
->global_psymbols
12497 : &objfile
->static_psymbols
,
12498 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12500 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12504 /* We'll save this DIE so link it in. */
12505 part_die
->die_parent
= parent_die
;
12506 part_die
->die_sibling
= NULL
;
12507 part_die
->die_child
= NULL
;
12509 if (last_die
&& last_die
== parent_die
)
12510 last_die
->die_child
= part_die
;
12512 last_die
->die_sibling
= part_die
;
12514 last_die
= part_die
;
12516 if (first_die
== NULL
)
12517 first_die
= part_die
;
12519 /* Maybe add the DIE to the hash table. Not all DIEs that we
12520 find interesting need to be in the hash table, because we
12521 also have the parent/sibling/child chains; only those that we
12522 might refer to by offset later during partial symbol reading.
12524 For now this means things that might have be the target of a
12525 DW_AT_specification, DW_AT_abstract_origin, or
12526 DW_AT_extension. DW_AT_extension will refer only to
12527 namespaces; DW_AT_abstract_origin refers to functions (and
12528 many things under the function DIE, but we do not recurse
12529 into function DIEs during partial symbol reading) and
12530 possibly variables as well; DW_AT_specification refers to
12531 declarations. Declarations ought to have the DW_AT_declaration
12532 flag. It happens that GCC forgets to put it in sometimes, but
12533 only for functions, not for types.
12535 Adding more things than necessary to the hash table is harmless
12536 except for the performance cost. Adding too few will result in
12537 wasted time in find_partial_die, when we reread the compilation
12538 unit with load_all_dies set. */
12541 || abbrev
->tag
== DW_TAG_constant
12542 || abbrev
->tag
== DW_TAG_subprogram
12543 || abbrev
->tag
== DW_TAG_variable
12544 || abbrev
->tag
== DW_TAG_namespace
12545 || part_die
->is_declaration
)
12549 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
12550 part_die
->offset
.sect_off
, INSERT
);
12554 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12555 sizeof (struct partial_die_info
));
12557 /* For some DIEs we want to follow their children (if any). For C
12558 we have no reason to follow the children of structures; for other
12559 languages we have to, so that we can get at method physnames
12560 to infer fully qualified class names, for DW_AT_specification,
12561 and for C++ template arguments. For C++, we also look one level
12562 inside functions to find template arguments (if the name of the
12563 function does not already contain the template arguments).
12565 For Ada, we need to scan the children of subprograms and lexical
12566 blocks as well because Ada allows the definition of nested
12567 entities that could be interesting for the debugger, such as
12568 nested subprograms for instance. */
12569 if (last_die
->has_children
12571 || last_die
->tag
== DW_TAG_namespace
12572 || last_die
->tag
== DW_TAG_module
12573 || last_die
->tag
== DW_TAG_enumeration_type
12574 || (cu
->language
== language_cplus
12575 && last_die
->tag
== DW_TAG_subprogram
12576 && (last_die
->name
== NULL
12577 || strchr (last_die
->name
, '<') == NULL
))
12578 || (cu
->language
!= language_c
12579 && (last_die
->tag
== DW_TAG_class_type
12580 || last_die
->tag
== DW_TAG_interface_type
12581 || last_die
->tag
== DW_TAG_structure_type
12582 || last_die
->tag
== DW_TAG_union_type
))
12583 || (cu
->language
== language_ada
12584 && (last_die
->tag
== DW_TAG_subprogram
12585 || last_die
->tag
== DW_TAG_lexical_block
))))
12588 parent_die
= last_die
;
12592 /* Otherwise we skip to the next sibling, if any. */
12593 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
12595 /* Back to the top, do it again. */
12599 /* Read a minimal amount of information into the minimal die structure. */
12602 read_partial_die (const struct die_reader_specs
*reader
,
12603 struct partial_die_info
*part_die
,
12604 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
12605 gdb_byte
*info_ptr
)
12607 struct dwarf2_cu
*cu
= reader
->cu
;
12608 struct objfile
*objfile
= cu
->objfile
;
12609 gdb_byte
*buffer
= reader
->buffer
;
12611 struct attribute attr
;
12612 int has_low_pc_attr
= 0;
12613 int has_high_pc_attr
= 0;
12614 int high_pc_relative
= 0;
12616 memset (part_die
, 0, sizeof (struct partial_die_info
));
12618 part_die
->offset
.sect_off
= info_ptr
- buffer
;
12620 info_ptr
+= abbrev_len
;
12622 if (abbrev
== NULL
)
12625 part_die
->tag
= abbrev
->tag
;
12626 part_die
->has_children
= abbrev
->has_children
;
12628 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12630 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
12632 /* Store the data if it is of an attribute we want to keep in a
12633 partial symbol table. */
12637 switch (part_die
->tag
)
12639 case DW_TAG_compile_unit
:
12640 case DW_TAG_partial_unit
:
12641 case DW_TAG_type_unit
:
12642 /* Compilation units have a DW_AT_name that is a filename, not
12643 a source language identifier. */
12644 case DW_TAG_enumeration_type
:
12645 case DW_TAG_enumerator
:
12646 /* These tags always have simple identifiers already; no need
12647 to canonicalize them. */
12648 part_die
->name
= DW_STRING (&attr
);
12652 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
12653 &objfile
->objfile_obstack
);
12657 case DW_AT_linkage_name
:
12658 case DW_AT_MIPS_linkage_name
:
12659 /* Note that both forms of linkage name might appear. We
12660 assume they will be the same, and we only store the last
12662 if (cu
->language
== language_ada
)
12663 part_die
->name
= DW_STRING (&attr
);
12664 part_die
->linkage_name
= DW_STRING (&attr
);
12667 has_low_pc_attr
= 1;
12668 part_die
->lowpc
= DW_ADDR (&attr
);
12670 case DW_AT_high_pc
:
12671 has_high_pc_attr
= 1;
12672 if (attr
.form
== DW_FORM_addr
12673 || attr
.form
== DW_FORM_GNU_addr_index
)
12674 part_die
->highpc
= DW_ADDR (&attr
);
12677 high_pc_relative
= 1;
12678 part_die
->highpc
= DW_UNSND (&attr
);
12681 case DW_AT_location
:
12682 /* Support the .debug_loc offsets. */
12683 if (attr_form_is_block (&attr
))
12685 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
12687 else if (attr_form_is_section_offset (&attr
))
12689 dwarf2_complex_location_expr_complaint ();
12693 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12694 "partial symbol information");
12697 case DW_AT_external
:
12698 part_die
->is_external
= DW_UNSND (&attr
);
12700 case DW_AT_declaration
:
12701 part_die
->is_declaration
= DW_UNSND (&attr
);
12704 part_die
->has_type
= 1;
12706 case DW_AT_abstract_origin
:
12707 case DW_AT_specification
:
12708 case DW_AT_extension
:
12709 part_die
->has_specification
= 1;
12710 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
12711 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
12712 || cu
->per_cu
->is_dwz
);
12714 case DW_AT_sibling
:
12715 /* Ignore absolute siblings, they might point outside of
12716 the current compile unit. */
12717 if (attr
.form
== DW_FORM_ref_addr
)
12718 complaint (&symfile_complaints
,
12719 _("ignoring absolute DW_AT_sibling"));
12721 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
12723 case DW_AT_byte_size
:
12724 part_die
->has_byte_size
= 1;
12726 case DW_AT_calling_convention
:
12727 /* DWARF doesn't provide a way to identify a program's source-level
12728 entry point. DW_AT_calling_convention attributes are only meant
12729 to describe functions' calling conventions.
12731 However, because it's a necessary piece of information in
12732 Fortran, and because DW_CC_program is the only piece of debugging
12733 information whose definition refers to a 'main program' at all,
12734 several compilers have begun marking Fortran main programs with
12735 DW_CC_program --- even when those functions use the standard
12736 calling conventions.
12738 So until DWARF specifies a way to provide this information and
12739 compilers pick up the new representation, we'll support this
12741 if (DW_UNSND (&attr
) == DW_CC_program
12742 && cu
->language
== language_fortran
)
12744 set_main_name (part_die
->name
);
12746 /* As this DIE has a static linkage the name would be difficult
12747 to look up later. */
12748 language_of_main
= language_fortran
;
12752 if (DW_UNSND (&attr
) == DW_INL_inlined
12753 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
12754 part_die
->may_be_inlined
= 1;
12758 if (part_die
->tag
== DW_TAG_imported_unit
)
12760 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
12761 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
12762 || cu
->per_cu
->is_dwz
);
12771 if (high_pc_relative
)
12772 part_die
->highpc
+= part_die
->lowpc
;
12774 if (has_low_pc_attr
&& has_high_pc_attr
)
12776 /* When using the GNU linker, .gnu.linkonce. sections are used to
12777 eliminate duplicate copies of functions and vtables and such.
12778 The linker will arbitrarily choose one and discard the others.
12779 The AT_*_pc values for such functions refer to local labels in
12780 these sections. If the section from that file was discarded, the
12781 labels are not in the output, so the relocs get a value of 0.
12782 If this is a discarded function, mark the pc bounds as invalid,
12783 so that GDB will ignore it. */
12784 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12786 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12788 complaint (&symfile_complaints
,
12789 _("DW_AT_low_pc %s is zero "
12790 "for DIE at 0x%x [in module %s]"),
12791 paddress (gdbarch
, part_die
->lowpc
),
12792 part_die
->offset
.sect_off
, objfile
->name
);
12794 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
12795 else if (part_die
->lowpc
>= part_die
->highpc
)
12797 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12799 complaint (&symfile_complaints
,
12800 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
12801 "for DIE at 0x%x [in module %s]"),
12802 paddress (gdbarch
, part_die
->lowpc
),
12803 paddress (gdbarch
, part_die
->highpc
),
12804 part_die
->offset
.sect_off
, objfile
->name
);
12807 part_die
->has_pc_info
= 1;
12813 /* Find a cached partial DIE at OFFSET in CU. */
12815 static struct partial_die_info
*
12816 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
12818 struct partial_die_info
*lookup_die
= NULL
;
12819 struct partial_die_info part_die
;
12821 part_die
.offset
= offset
;
12822 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
12828 /* Find a partial DIE at OFFSET, which may or may not be in CU,
12829 except in the case of .debug_types DIEs which do not reference
12830 outside their CU (they do however referencing other types via
12831 DW_FORM_ref_sig8). */
12833 static struct partial_die_info
*
12834 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
12836 struct objfile
*objfile
= cu
->objfile
;
12837 struct dwarf2_per_cu_data
*per_cu
= NULL
;
12838 struct partial_die_info
*pd
= NULL
;
12840 if (offset_in_dwz
== cu
->per_cu
->is_dwz
12841 && offset_in_cu_p (&cu
->header
, offset
))
12843 pd
= find_partial_die_in_comp_unit (offset
, cu
);
12846 /* We missed recording what we needed.
12847 Load all dies and try again. */
12848 per_cu
= cu
->per_cu
;
12852 /* TUs don't reference other CUs/TUs (except via type signatures). */
12853 if (cu
->per_cu
->is_debug_types
)
12855 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
12856 " external reference to offset 0x%lx [in module %s].\n"),
12857 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
12858 bfd_get_filename (objfile
->obfd
));
12860 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
12863 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
12864 load_partial_comp_unit (per_cu
);
12866 per_cu
->cu
->last_used
= 0;
12867 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12870 /* If we didn't find it, and not all dies have been loaded,
12871 load them all and try again. */
12873 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
12875 per_cu
->load_all_dies
= 1;
12877 /* This is nasty. When we reread the DIEs, somewhere up the call chain
12878 THIS_CU->cu may already be in use. So we can't just free it and
12879 replace its DIEs with the ones we read in. Instead, we leave those
12880 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
12881 and clobber THIS_CU->cu->partial_dies with the hash table for the new
12883 load_partial_comp_unit (per_cu
);
12885 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12889 internal_error (__FILE__
, __LINE__
,
12890 _("could not find partial DIE 0x%x "
12891 "in cache [from module %s]\n"),
12892 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
12896 /* See if we can figure out if the class lives in a namespace. We do
12897 this by looking for a member function; its demangled name will
12898 contain namespace info, if there is any. */
12901 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
12902 struct dwarf2_cu
*cu
)
12904 /* NOTE: carlton/2003-10-07: Getting the info this way changes
12905 what template types look like, because the demangler
12906 frequently doesn't give the same name as the debug info. We
12907 could fix this by only using the demangled name to get the
12908 prefix (but see comment in read_structure_type). */
12910 struct partial_die_info
*real_pdi
;
12911 struct partial_die_info
*child_pdi
;
12913 /* If this DIE (this DIE's specification, if any) has a parent, then
12914 we should not do this. We'll prepend the parent's fully qualified
12915 name when we create the partial symbol. */
12917 real_pdi
= struct_pdi
;
12918 while (real_pdi
->has_specification
)
12919 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
12920 real_pdi
->spec_is_dwz
, cu
);
12922 if (real_pdi
->die_parent
!= NULL
)
12925 for (child_pdi
= struct_pdi
->die_child
;
12927 child_pdi
= child_pdi
->die_sibling
)
12929 if (child_pdi
->tag
== DW_TAG_subprogram
12930 && child_pdi
->linkage_name
!= NULL
)
12932 char *actual_class_name
12933 = language_class_name_from_physname (cu
->language_defn
,
12934 child_pdi
->linkage_name
);
12935 if (actual_class_name
!= NULL
)
12938 = obsavestring (actual_class_name
,
12939 strlen (actual_class_name
),
12940 &cu
->objfile
->objfile_obstack
);
12941 xfree (actual_class_name
);
12948 /* Adjust PART_DIE before generating a symbol for it. This function
12949 may set the is_external flag or change the DIE's name. */
12952 fixup_partial_die (struct partial_die_info
*part_die
,
12953 struct dwarf2_cu
*cu
)
12955 /* Once we've fixed up a die, there's no point in doing so again.
12956 This also avoids a memory leak if we were to call
12957 guess_partial_die_structure_name multiple times. */
12958 if (part_die
->fixup_called
)
12961 /* If we found a reference attribute and the DIE has no name, try
12962 to find a name in the referred to DIE. */
12964 if (part_die
->name
== NULL
&& part_die
->has_specification
)
12966 struct partial_die_info
*spec_die
;
12968 spec_die
= find_partial_die (part_die
->spec_offset
,
12969 part_die
->spec_is_dwz
, cu
);
12971 fixup_partial_die (spec_die
, cu
);
12973 if (spec_die
->name
)
12975 part_die
->name
= spec_die
->name
;
12977 /* Copy DW_AT_external attribute if it is set. */
12978 if (spec_die
->is_external
)
12979 part_die
->is_external
= spec_die
->is_external
;
12983 /* Set default names for some unnamed DIEs. */
12985 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
12986 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
12988 /* If there is no parent die to provide a namespace, and there are
12989 children, see if we can determine the namespace from their linkage
12991 if (cu
->language
== language_cplus
12992 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12993 && part_die
->die_parent
== NULL
12994 && part_die
->has_children
12995 && (part_die
->tag
== DW_TAG_class_type
12996 || part_die
->tag
== DW_TAG_structure_type
12997 || part_die
->tag
== DW_TAG_union_type
))
12998 guess_partial_die_structure_name (part_die
, cu
);
13000 /* GCC might emit a nameless struct or union that has a linkage
13001 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13002 if (part_die
->name
== NULL
13003 && (part_die
->tag
== DW_TAG_class_type
13004 || part_die
->tag
== DW_TAG_interface_type
13005 || part_die
->tag
== DW_TAG_structure_type
13006 || part_die
->tag
== DW_TAG_union_type
)
13007 && part_die
->linkage_name
!= NULL
)
13011 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
13016 /* Strip any leading namespaces/classes, keep only the base name.
13017 DW_AT_name for named DIEs does not contain the prefixes. */
13018 base
= strrchr (demangled
, ':');
13019 if (base
&& base
> demangled
&& base
[-1] == ':')
13024 part_die
->name
= obsavestring (base
, strlen (base
),
13025 &cu
->objfile
->objfile_obstack
);
13030 part_die
->fixup_called
= 1;
13033 /* Read an attribute value described by an attribute form. */
13036 read_attribute_value (const struct die_reader_specs
*reader
,
13037 struct attribute
*attr
, unsigned form
,
13038 gdb_byte
*info_ptr
)
13040 struct dwarf2_cu
*cu
= reader
->cu
;
13041 bfd
*abfd
= reader
->abfd
;
13042 struct comp_unit_head
*cu_header
= &cu
->header
;
13043 unsigned int bytes_read
;
13044 struct dwarf_block
*blk
;
13049 case DW_FORM_ref_addr
:
13050 if (cu
->header
.version
== 2)
13051 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13053 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
13054 &cu
->header
, &bytes_read
);
13055 info_ptr
+= bytes_read
;
13057 case DW_FORM_GNU_ref_alt
:
13058 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13059 info_ptr
+= bytes_read
;
13062 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13063 info_ptr
+= bytes_read
;
13065 case DW_FORM_block2
:
13066 blk
= dwarf_alloc_block (cu
);
13067 blk
->size
= read_2_bytes (abfd
, info_ptr
);
13069 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13070 info_ptr
+= blk
->size
;
13071 DW_BLOCK (attr
) = blk
;
13073 case DW_FORM_block4
:
13074 blk
= dwarf_alloc_block (cu
);
13075 blk
->size
= read_4_bytes (abfd
, info_ptr
);
13077 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13078 info_ptr
+= blk
->size
;
13079 DW_BLOCK (attr
) = blk
;
13081 case DW_FORM_data2
:
13082 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
13085 case DW_FORM_data4
:
13086 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
13089 case DW_FORM_data8
:
13090 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
13093 case DW_FORM_sec_offset
:
13094 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13095 info_ptr
+= bytes_read
;
13097 case DW_FORM_string
:
13098 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
13099 DW_STRING_IS_CANONICAL (attr
) = 0;
13100 info_ptr
+= bytes_read
;
13103 if (!cu
->per_cu
->is_dwz
)
13105 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
13107 DW_STRING_IS_CANONICAL (attr
) = 0;
13108 info_ptr
+= bytes_read
;
13112 case DW_FORM_GNU_strp_alt
:
13114 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
13115 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
13118 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
13119 DW_STRING_IS_CANONICAL (attr
) = 0;
13120 info_ptr
+= bytes_read
;
13123 case DW_FORM_exprloc
:
13124 case DW_FORM_block
:
13125 blk
= dwarf_alloc_block (cu
);
13126 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13127 info_ptr
+= bytes_read
;
13128 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13129 info_ptr
+= blk
->size
;
13130 DW_BLOCK (attr
) = blk
;
13132 case DW_FORM_block1
:
13133 blk
= dwarf_alloc_block (cu
);
13134 blk
->size
= read_1_byte (abfd
, info_ptr
);
13136 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13137 info_ptr
+= blk
->size
;
13138 DW_BLOCK (attr
) = blk
;
13140 case DW_FORM_data1
:
13141 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13145 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13148 case DW_FORM_flag_present
:
13149 DW_UNSND (attr
) = 1;
13151 case DW_FORM_sdata
:
13152 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
13153 info_ptr
+= bytes_read
;
13155 case DW_FORM_udata
:
13156 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13157 info_ptr
+= bytes_read
;
13160 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13161 + read_1_byte (abfd
, info_ptr
));
13165 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13166 + read_2_bytes (abfd
, info_ptr
));
13170 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13171 + read_4_bytes (abfd
, info_ptr
));
13175 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13176 + read_8_bytes (abfd
, info_ptr
));
13179 case DW_FORM_ref_sig8
:
13180 /* Convert the signature to something we can record in DW_UNSND
13182 NOTE: This is NULL if the type wasn't found. */
13183 DW_SIGNATURED_TYPE (attr
) =
13184 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
13187 case DW_FORM_ref_udata
:
13188 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13189 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
13190 info_ptr
+= bytes_read
;
13192 case DW_FORM_indirect
:
13193 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13194 info_ptr
+= bytes_read
;
13195 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
13197 case DW_FORM_GNU_addr_index
:
13198 if (reader
->dwo_file
== NULL
)
13200 /* For now flag a hard error.
13201 Later we can turn this into a complaint. */
13202 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13203 dwarf_form_name (form
),
13204 bfd_get_filename (abfd
));
13206 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
13207 info_ptr
+= bytes_read
;
13209 case DW_FORM_GNU_str_index
:
13210 if (reader
->dwo_file
== NULL
)
13212 /* For now flag a hard error.
13213 Later we can turn this into a complaint if warranted. */
13214 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13215 dwarf_form_name (form
),
13216 bfd_get_filename (abfd
));
13219 ULONGEST str_index
=
13220 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13222 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
13223 DW_STRING_IS_CANONICAL (attr
) = 0;
13224 info_ptr
+= bytes_read
;
13228 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
13229 dwarf_form_name (form
),
13230 bfd_get_filename (abfd
));
13234 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
13235 attr
->form
= DW_FORM_GNU_ref_alt
;
13237 /* We have seen instances where the compiler tried to emit a byte
13238 size attribute of -1 which ended up being encoded as an unsigned
13239 0xffffffff. Although 0xffffffff is technically a valid size value,
13240 an object of this size seems pretty unlikely so we can relatively
13241 safely treat these cases as if the size attribute was invalid and
13242 treat them as zero by default. */
13243 if (attr
->name
== DW_AT_byte_size
13244 && form
== DW_FORM_data4
13245 && DW_UNSND (attr
) >= 0xffffffff)
13248 (&symfile_complaints
,
13249 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
13250 hex_string (DW_UNSND (attr
)));
13251 DW_UNSND (attr
) = 0;
13257 /* Read an attribute described by an abbreviated attribute. */
13260 read_attribute (const struct die_reader_specs
*reader
,
13261 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
13262 gdb_byte
*info_ptr
)
13264 attr
->name
= abbrev
->name
;
13265 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
13268 /* Read dwarf information from a buffer. */
13270 static unsigned int
13271 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
13273 return bfd_get_8 (abfd
, buf
);
13277 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
13279 return bfd_get_signed_8 (abfd
, buf
);
13282 static unsigned int
13283 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
13285 return bfd_get_16 (abfd
, buf
);
13289 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13291 return bfd_get_signed_16 (abfd
, buf
);
13294 static unsigned int
13295 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
13297 return bfd_get_32 (abfd
, buf
);
13301 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13303 return bfd_get_signed_32 (abfd
, buf
);
13307 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
13309 return bfd_get_64 (abfd
, buf
);
13313 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
13314 unsigned int *bytes_read
)
13316 struct comp_unit_head
*cu_header
= &cu
->header
;
13317 CORE_ADDR retval
= 0;
13319 if (cu_header
->signed_addr_p
)
13321 switch (cu_header
->addr_size
)
13324 retval
= bfd_get_signed_16 (abfd
, buf
);
13327 retval
= bfd_get_signed_32 (abfd
, buf
);
13330 retval
= bfd_get_signed_64 (abfd
, buf
);
13333 internal_error (__FILE__
, __LINE__
,
13334 _("read_address: bad switch, signed [in module %s]"),
13335 bfd_get_filename (abfd
));
13340 switch (cu_header
->addr_size
)
13343 retval
= bfd_get_16 (abfd
, buf
);
13346 retval
= bfd_get_32 (abfd
, buf
);
13349 retval
= bfd_get_64 (abfd
, buf
);
13352 internal_error (__FILE__
, __LINE__
,
13353 _("read_address: bad switch, "
13354 "unsigned [in module %s]"),
13355 bfd_get_filename (abfd
));
13359 *bytes_read
= cu_header
->addr_size
;
13363 /* Read the initial length from a section. The (draft) DWARF 3
13364 specification allows the initial length to take up either 4 bytes
13365 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
13366 bytes describe the length and all offsets will be 8 bytes in length
13369 An older, non-standard 64-bit format is also handled by this
13370 function. The older format in question stores the initial length
13371 as an 8-byte quantity without an escape value. Lengths greater
13372 than 2^32 aren't very common which means that the initial 4 bytes
13373 is almost always zero. Since a length value of zero doesn't make
13374 sense for the 32-bit format, this initial zero can be considered to
13375 be an escape value which indicates the presence of the older 64-bit
13376 format. As written, the code can't detect (old format) lengths
13377 greater than 4GB. If it becomes necessary to handle lengths
13378 somewhat larger than 4GB, we could allow other small values (such
13379 as the non-sensical values of 1, 2, and 3) to also be used as
13380 escape values indicating the presence of the old format.
13382 The value returned via bytes_read should be used to increment the
13383 relevant pointer after calling read_initial_length().
13385 [ Note: read_initial_length() and read_offset() are based on the
13386 document entitled "DWARF Debugging Information Format", revision
13387 3, draft 8, dated November 19, 2001. This document was obtained
13390 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
13392 This document is only a draft and is subject to change. (So beware.)
13394 Details regarding the older, non-standard 64-bit format were
13395 determined empirically by examining 64-bit ELF files produced by
13396 the SGI toolchain on an IRIX 6.5 machine.
13398 - Kevin, July 16, 2002
13402 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
13404 LONGEST length
= bfd_get_32 (abfd
, buf
);
13406 if (length
== 0xffffffff)
13408 length
= bfd_get_64 (abfd
, buf
+ 4);
13411 else if (length
== 0)
13413 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
13414 length
= bfd_get_64 (abfd
, buf
);
13425 /* Cover function for read_initial_length.
13426 Returns the length of the object at BUF, and stores the size of the
13427 initial length in *BYTES_READ and stores the size that offsets will be in
13429 If the initial length size is not equivalent to that specified in
13430 CU_HEADER then issue a complaint.
13431 This is useful when reading non-comp-unit headers. */
13434 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
13435 const struct comp_unit_head
*cu_header
,
13436 unsigned int *bytes_read
,
13437 unsigned int *offset_size
)
13439 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
13441 gdb_assert (cu_header
->initial_length_size
== 4
13442 || cu_header
->initial_length_size
== 8
13443 || cu_header
->initial_length_size
== 12);
13445 if (cu_header
->initial_length_size
!= *bytes_read
)
13446 complaint (&symfile_complaints
,
13447 _("intermixed 32-bit and 64-bit DWARF sections"));
13449 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
13453 /* Read an offset from the data stream. The size of the offset is
13454 given by cu_header->offset_size. */
13457 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
13458 unsigned int *bytes_read
)
13460 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
13462 *bytes_read
= cu_header
->offset_size
;
13466 /* Read an offset from the data stream. */
13469 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
13471 LONGEST retval
= 0;
13473 switch (offset_size
)
13476 retval
= bfd_get_32 (abfd
, buf
);
13479 retval
= bfd_get_64 (abfd
, buf
);
13482 internal_error (__FILE__
, __LINE__
,
13483 _("read_offset_1: bad switch [in module %s]"),
13484 bfd_get_filename (abfd
));
13491 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
13493 /* If the size of a host char is 8 bits, we can return a pointer
13494 to the buffer, otherwise we have to copy the data to a buffer
13495 allocated on the temporary obstack. */
13496 gdb_assert (HOST_CHAR_BIT
== 8);
13501 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13503 /* If the size of a host char is 8 bits, we can return a pointer
13504 to the string, otherwise we have to copy the string to a buffer
13505 allocated on the temporary obstack. */
13506 gdb_assert (HOST_CHAR_BIT
== 8);
13509 *bytes_read_ptr
= 1;
13512 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
13513 return (char *) buf
;
13517 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
13519 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
13520 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
13521 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
13522 bfd_get_filename (abfd
));
13523 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
13524 error (_("DW_FORM_strp pointing outside of "
13525 ".debug_str section [in module %s]"),
13526 bfd_get_filename (abfd
));
13527 gdb_assert (HOST_CHAR_BIT
== 8);
13528 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
13530 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
13533 /* Read a string at offset STR_OFFSET in the .debug_str section from
13534 the .dwz file DWZ. Throw an error if the offset is too large. If
13535 the string consists of a single NUL byte, return NULL; otherwise
13536 return a pointer to the string. */
13539 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
13541 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
13543 if (dwz
->str
.buffer
== NULL
)
13544 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
13545 "section [in module %s]"),
13546 bfd_get_filename (dwz
->dwz_bfd
));
13547 if (str_offset
>= dwz
->str
.size
)
13548 error (_("DW_FORM_GNU_strp_alt pointing outside of "
13549 ".debug_str section [in module %s]"),
13550 bfd_get_filename (dwz
->dwz_bfd
));
13551 gdb_assert (HOST_CHAR_BIT
== 8);
13552 if (dwz
->str
.buffer
[str_offset
] == '\0')
13554 return (char *) (dwz
->str
.buffer
+ str_offset
);
13558 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
13559 const struct comp_unit_head
*cu_header
,
13560 unsigned int *bytes_read_ptr
)
13562 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
13564 return read_indirect_string_at_offset (abfd
, str_offset
);
13568 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13571 unsigned int num_read
;
13573 unsigned char byte
;
13581 byte
= bfd_get_8 (abfd
, buf
);
13584 result
|= ((ULONGEST
) (byte
& 127) << shift
);
13585 if ((byte
& 128) == 0)
13591 *bytes_read_ptr
= num_read
;
13596 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13599 int i
, shift
, num_read
;
13600 unsigned char byte
;
13608 byte
= bfd_get_8 (abfd
, buf
);
13611 result
|= ((LONGEST
) (byte
& 127) << shift
);
13613 if ((byte
& 128) == 0)
13618 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
13619 result
|= -(((LONGEST
) 1) << shift
);
13620 *bytes_read_ptr
= num_read
;
13624 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
13625 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
13626 ADDR_SIZE is the size of addresses from the CU header. */
13629 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
13631 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13632 bfd
*abfd
= objfile
->obfd
;
13633 const gdb_byte
*info_ptr
;
13635 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
13636 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
13637 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
13639 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
13640 error (_("DW_FORM_addr_index pointing outside of "
13641 ".debug_addr section [in module %s]"),
13643 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
13644 + addr_base
+ addr_index
* addr_size
);
13645 if (addr_size
== 4)
13646 return bfd_get_32 (abfd
, info_ptr
);
13648 return bfd_get_64 (abfd
, info_ptr
);
13651 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
13654 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
13656 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
13659 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
13662 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
13663 unsigned int *bytes_read
)
13665 bfd
*abfd
= cu
->objfile
->obfd
;
13666 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
13668 return read_addr_index (cu
, addr_index
);
13671 /* Data structure to pass results from dwarf2_read_addr_index_reader
13672 back to dwarf2_read_addr_index. */
13674 struct dwarf2_read_addr_index_data
13676 ULONGEST addr_base
;
13680 /* die_reader_func for dwarf2_read_addr_index. */
13683 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
13684 gdb_byte
*info_ptr
,
13685 struct die_info
*comp_unit_die
,
13689 struct dwarf2_cu
*cu
= reader
->cu
;
13690 struct dwarf2_read_addr_index_data
*aidata
=
13691 (struct dwarf2_read_addr_index_data
*) data
;
13693 aidata
->addr_base
= cu
->addr_base
;
13694 aidata
->addr_size
= cu
->header
.addr_size
;
13697 /* Given an index in .debug_addr, fetch the value.
13698 NOTE: This can be called during dwarf expression evaluation,
13699 long after the debug information has been read, and thus per_cu->cu
13700 may no longer exist. */
13703 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
13704 unsigned int addr_index
)
13706 struct objfile
*objfile
= per_cu
->objfile
;
13707 struct dwarf2_cu
*cu
= per_cu
->cu
;
13708 ULONGEST addr_base
;
13711 /* This is intended to be called from outside this file. */
13712 dw2_setup (objfile
);
13714 /* We need addr_base and addr_size.
13715 If we don't have PER_CU->cu, we have to get it.
13716 Nasty, but the alternative is storing the needed info in PER_CU,
13717 which at this point doesn't seem justified: it's not clear how frequently
13718 it would get used and it would increase the size of every PER_CU.
13719 Entry points like dwarf2_per_cu_addr_size do a similar thing
13720 so we're not in uncharted territory here.
13721 Alas we need to be a bit more complicated as addr_base is contained
13724 We don't need to read the entire CU(/TU).
13725 We just need the header and top level die.
13726 IWBN to use the aging mechanism to let us lazily later discard the CU.
13727 See however init_cutu_and_read_dies_simple. */
13731 addr_base
= cu
->addr_base
;
13732 addr_size
= cu
->header
.addr_size
;
13736 struct dwarf2_read_addr_index_data aidata
;
13738 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
13740 addr_base
= aidata
.addr_base
;
13741 addr_size
= aidata
.addr_size
;
13744 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
13747 /* Given a DW_AT_str_index, fetch the string. */
13750 read_str_index (const struct die_reader_specs
*reader
,
13751 struct dwarf2_cu
*cu
, ULONGEST str_index
)
13753 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13754 const char *dwo_name
= objfile
->name
;
13755 bfd
*abfd
= objfile
->obfd
;
13756 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
13757 gdb_byte
*info_ptr
;
13758 ULONGEST str_offset
;
13760 dwarf2_read_section (objfile
, §ions
->str
);
13761 dwarf2_read_section (objfile
, §ions
->str_offsets
);
13762 if (sections
->str
.buffer
== NULL
)
13763 error (_("DW_FORM_str_index used without .debug_str.dwo section"
13764 " in CU at offset 0x%lx [in module %s]"),
13765 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13766 if (sections
->str_offsets
.buffer
== NULL
)
13767 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
13768 " in CU at offset 0x%lx [in module %s]"),
13769 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13770 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
13771 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
13772 " section in CU at offset 0x%lx [in module %s]"),
13773 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13774 info_ptr
= (sections
->str_offsets
.buffer
13775 + str_index
* cu
->header
.offset_size
);
13776 if (cu
->header
.offset_size
== 4)
13777 str_offset
= bfd_get_32 (abfd
, info_ptr
);
13779 str_offset
= bfd_get_64 (abfd
, info_ptr
);
13780 if (str_offset
>= sections
->str
.size
)
13781 error (_("Offset from DW_FORM_str_index pointing outside of"
13782 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
13783 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13784 return (char *) (sections
->str
.buffer
+ str_offset
);
13787 /* Return the length of an LEB128 number in BUF. */
13790 leb128_size (const gdb_byte
*buf
)
13792 const gdb_byte
*begin
= buf
;
13798 if ((byte
& 128) == 0)
13799 return buf
- begin
;
13804 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
13811 cu
->language
= language_c
;
13813 case DW_LANG_C_plus_plus
:
13814 cu
->language
= language_cplus
;
13817 cu
->language
= language_d
;
13819 case DW_LANG_Fortran77
:
13820 case DW_LANG_Fortran90
:
13821 case DW_LANG_Fortran95
:
13822 cu
->language
= language_fortran
;
13825 cu
->language
= language_go
;
13827 case DW_LANG_Mips_Assembler
:
13828 cu
->language
= language_asm
;
13831 cu
->language
= language_java
;
13833 case DW_LANG_Ada83
:
13834 case DW_LANG_Ada95
:
13835 cu
->language
= language_ada
;
13837 case DW_LANG_Modula2
:
13838 cu
->language
= language_m2
;
13840 case DW_LANG_Pascal83
:
13841 cu
->language
= language_pascal
;
13844 cu
->language
= language_objc
;
13846 case DW_LANG_Cobol74
:
13847 case DW_LANG_Cobol85
:
13849 cu
->language
= language_minimal
;
13852 cu
->language_defn
= language_def (cu
->language
);
13855 /* Return the named attribute or NULL if not there. */
13857 static struct attribute
*
13858 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
13863 struct attribute
*spec
= NULL
;
13865 for (i
= 0; i
< die
->num_attrs
; ++i
)
13867 if (die
->attrs
[i
].name
== name
)
13868 return &die
->attrs
[i
];
13869 if (die
->attrs
[i
].name
== DW_AT_specification
13870 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
13871 spec
= &die
->attrs
[i
];
13877 die
= follow_die_ref (die
, spec
, &cu
);
13883 /* Return the named attribute or NULL if not there,
13884 but do not follow DW_AT_specification, etc.
13885 This is for use in contexts where we're reading .debug_types dies.
13886 Following DW_AT_specification, DW_AT_abstract_origin will take us
13887 back up the chain, and we want to go down. */
13889 static struct attribute
*
13890 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
13894 for (i
= 0; i
< die
->num_attrs
; ++i
)
13895 if (die
->attrs
[i
].name
== name
)
13896 return &die
->attrs
[i
];
13901 /* Return non-zero iff the attribute NAME is defined for the given DIE,
13902 and holds a non-zero value. This function should only be used for
13903 DW_FORM_flag or DW_FORM_flag_present attributes. */
13906 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
13908 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
13910 return (attr
&& DW_UNSND (attr
));
13914 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
13916 /* A DIE is a declaration if it has a DW_AT_declaration attribute
13917 which value is non-zero. However, we have to be careful with
13918 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
13919 (via dwarf2_flag_true_p) follows this attribute. So we may
13920 end up accidently finding a declaration attribute that belongs
13921 to a different DIE referenced by the specification attribute,
13922 even though the given DIE does not have a declaration attribute. */
13923 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
13924 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
13927 /* Return the die giving the specification for DIE, if there is
13928 one. *SPEC_CU is the CU containing DIE on input, and the CU
13929 containing the return value on output. If there is no
13930 specification, but there is an abstract origin, that is
13933 static struct die_info
*
13934 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
13936 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
13939 if (spec_attr
== NULL
)
13940 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
13942 if (spec_attr
== NULL
)
13945 return follow_die_ref (die
, spec_attr
, spec_cu
);
13948 /* Free the line_header structure *LH, and any arrays and strings it
13950 NOTE: This is also used as a "cleanup" function. */
13953 free_line_header (struct line_header
*lh
)
13955 if (lh
->standard_opcode_lengths
)
13956 xfree (lh
->standard_opcode_lengths
);
13958 /* Remember that all the lh->file_names[i].name pointers are
13959 pointers into debug_line_buffer, and don't need to be freed. */
13960 if (lh
->file_names
)
13961 xfree (lh
->file_names
);
13963 /* Similarly for the include directory names. */
13964 if (lh
->include_dirs
)
13965 xfree (lh
->include_dirs
);
13970 /* Add an entry to LH's include directory table. */
13973 add_include_dir (struct line_header
*lh
, char *include_dir
)
13975 /* Grow the array if necessary. */
13976 if (lh
->include_dirs_size
== 0)
13978 lh
->include_dirs_size
= 1; /* for testing */
13979 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
13980 * sizeof (*lh
->include_dirs
));
13982 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
13984 lh
->include_dirs_size
*= 2;
13985 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
13986 (lh
->include_dirs_size
13987 * sizeof (*lh
->include_dirs
)));
13990 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
13993 /* Add an entry to LH's file name table. */
13996 add_file_name (struct line_header
*lh
,
13998 unsigned int dir_index
,
13999 unsigned int mod_time
,
14000 unsigned int length
)
14002 struct file_entry
*fe
;
14004 /* Grow the array if necessary. */
14005 if (lh
->file_names_size
== 0)
14007 lh
->file_names_size
= 1; /* for testing */
14008 lh
->file_names
= xmalloc (lh
->file_names_size
14009 * sizeof (*lh
->file_names
));
14011 else if (lh
->num_file_names
>= lh
->file_names_size
)
14013 lh
->file_names_size
*= 2;
14014 lh
->file_names
= xrealloc (lh
->file_names
,
14015 (lh
->file_names_size
14016 * sizeof (*lh
->file_names
)));
14019 fe
= &lh
->file_names
[lh
->num_file_names
++];
14021 fe
->dir_index
= dir_index
;
14022 fe
->mod_time
= mod_time
;
14023 fe
->length
= length
;
14024 fe
->included_p
= 0;
14028 /* A convenience function to find the proper .debug_line section for a
14031 static struct dwarf2_section_info
*
14032 get_debug_line_section (struct dwarf2_cu
*cu
)
14034 struct dwarf2_section_info
*section
;
14036 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14038 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14039 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
14040 else if (cu
->per_cu
->is_dwz
)
14042 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14044 section
= &dwz
->line
;
14047 section
= &dwarf2_per_objfile
->line
;
14052 /* Read the statement program header starting at OFFSET in
14053 .debug_line, or .debug_line.dwo. Return a pointer
14054 to a struct line_header, allocated using xmalloc.
14056 NOTE: the strings in the include directory and file name tables of
14057 the returned object point into the dwarf line section buffer,
14058 and must not be freed. */
14060 static struct line_header
*
14061 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
14063 struct cleanup
*back_to
;
14064 struct line_header
*lh
;
14065 gdb_byte
*line_ptr
;
14066 unsigned int bytes_read
, offset_size
;
14068 char *cur_dir
, *cur_file
;
14069 struct dwarf2_section_info
*section
;
14072 section
= get_debug_line_section (cu
);
14073 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
14074 if (section
->buffer
== NULL
)
14076 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14077 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
14079 complaint (&symfile_complaints
, _("missing .debug_line section"));
14083 /* We can't do this until we know the section is non-empty.
14084 Only then do we know we have such a section. */
14085 abfd
= section
->asection
->owner
;
14087 /* Make sure that at least there's room for the total_length field.
14088 That could be 12 bytes long, but we're just going to fudge that. */
14089 if (offset
+ 4 >= section
->size
)
14091 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14095 lh
= xmalloc (sizeof (*lh
));
14096 memset (lh
, 0, sizeof (*lh
));
14097 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
14100 line_ptr
= section
->buffer
+ offset
;
14102 /* Read in the header. */
14104 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
14105 &bytes_read
, &offset_size
);
14106 line_ptr
+= bytes_read
;
14107 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
14109 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14112 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
14113 lh
->version
= read_2_bytes (abfd
, line_ptr
);
14115 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
14116 line_ptr
+= offset_size
;
14117 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
14119 if (lh
->version
>= 4)
14121 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
14125 lh
->maximum_ops_per_instruction
= 1;
14127 if (lh
->maximum_ops_per_instruction
== 0)
14129 lh
->maximum_ops_per_instruction
= 1;
14130 complaint (&symfile_complaints
,
14131 _("invalid maximum_ops_per_instruction "
14132 "in `.debug_line' section"));
14135 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
14137 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
14139 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
14141 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
14143 lh
->standard_opcode_lengths
14144 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
14146 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
14147 for (i
= 1; i
< lh
->opcode_base
; ++i
)
14149 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
14153 /* Read directory table. */
14154 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14156 line_ptr
+= bytes_read
;
14157 add_include_dir (lh
, cur_dir
);
14159 line_ptr
+= bytes_read
;
14161 /* Read file name table. */
14162 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14164 unsigned int dir_index
, mod_time
, length
;
14166 line_ptr
+= bytes_read
;
14167 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14168 line_ptr
+= bytes_read
;
14169 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14170 line_ptr
+= bytes_read
;
14171 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14172 line_ptr
+= bytes_read
;
14174 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14176 line_ptr
+= bytes_read
;
14177 lh
->statement_program_start
= line_ptr
;
14179 if (line_ptr
> (section
->buffer
+ section
->size
))
14180 complaint (&symfile_complaints
,
14181 _("line number info header doesn't "
14182 "fit in `.debug_line' section"));
14184 discard_cleanups (back_to
);
14188 /* Subroutine of dwarf_decode_lines to simplify it.
14189 Return the file name of the psymtab for included file FILE_INDEX
14190 in line header LH of PST.
14191 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
14192 If space for the result is malloc'd, it will be freed by a cleanup.
14193 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
14196 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
14197 const struct partial_symtab
*pst
,
14198 const char *comp_dir
)
14200 const struct file_entry fe
= lh
->file_names
[file_index
];
14201 char *include_name
= fe
.name
;
14202 char *include_name_to_compare
= include_name
;
14203 char *dir_name
= NULL
;
14204 const char *pst_filename
;
14205 char *copied_name
= NULL
;
14209 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
14211 if (!IS_ABSOLUTE_PATH (include_name
)
14212 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
14214 /* Avoid creating a duplicate psymtab for PST.
14215 We do this by comparing INCLUDE_NAME and PST_FILENAME.
14216 Before we do the comparison, however, we need to account
14217 for DIR_NAME and COMP_DIR.
14218 First prepend dir_name (if non-NULL). If we still don't
14219 have an absolute path prepend comp_dir (if non-NULL).
14220 However, the directory we record in the include-file's
14221 psymtab does not contain COMP_DIR (to match the
14222 corresponding symtab(s)).
14227 bash$ gcc -g ./hello.c
14228 include_name = "hello.c"
14230 DW_AT_comp_dir = comp_dir = "/tmp"
14231 DW_AT_name = "./hello.c" */
14233 if (dir_name
!= NULL
)
14235 include_name
= concat (dir_name
, SLASH_STRING
,
14236 include_name
, (char *)NULL
);
14237 include_name_to_compare
= include_name
;
14238 make_cleanup (xfree
, include_name
);
14240 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
14242 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
14243 include_name
, (char *)NULL
);
14247 pst_filename
= pst
->filename
;
14248 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
14250 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
14251 pst_filename
, (char *)NULL
);
14252 pst_filename
= copied_name
;
14255 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
14257 if (include_name_to_compare
!= include_name
)
14258 xfree (include_name_to_compare
);
14259 if (copied_name
!= NULL
)
14260 xfree (copied_name
);
14264 return include_name
;
14267 /* Ignore this record_line request. */
14270 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14275 /* Subroutine of dwarf_decode_lines to simplify it.
14276 Process the line number information in LH. */
14279 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
14280 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
14282 gdb_byte
*line_ptr
, *extended_end
;
14283 gdb_byte
*line_end
;
14284 unsigned int bytes_read
, extended_len
;
14285 unsigned char op_code
, extended_op
, adj_opcode
;
14286 CORE_ADDR baseaddr
;
14287 struct objfile
*objfile
= cu
->objfile
;
14288 bfd
*abfd
= objfile
->obfd
;
14289 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14290 const int decode_for_pst_p
= (pst
!= NULL
);
14291 struct subfile
*last_subfile
= NULL
;
14292 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14295 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14297 line_ptr
= lh
->statement_program_start
;
14298 line_end
= lh
->statement_program_end
;
14300 /* Read the statement sequences until there's nothing left. */
14301 while (line_ptr
< line_end
)
14303 /* state machine registers */
14304 CORE_ADDR address
= 0;
14305 unsigned int file
= 1;
14306 unsigned int line
= 1;
14307 unsigned int column
= 0;
14308 int is_stmt
= lh
->default_is_stmt
;
14309 int basic_block
= 0;
14310 int end_sequence
= 0;
14312 unsigned char op_index
= 0;
14314 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
14316 /* Start a subfile for the current file of the state machine. */
14317 /* lh->include_dirs and lh->file_names are 0-based, but the
14318 directory and file name numbers in the statement program
14320 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14324 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14326 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14329 /* Decode the table. */
14330 while (!end_sequence
)
14332 op_code
= read_1_byte (abfd
, line_ptr
);
14334 if (line_ptr
> line_end
)
14336 dwarf2_debug_line_missing_end_sequence_complaint ();
14340 if (op_code
>= lh
->opcode_base
)
14342 /* Special operand. */
14343 adj_opcode
= op_code
- lh
->opcode_base
;
14344 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
14345 / lh
->maximum_ops_per_instruction
)
14346 * lh
->minimum_instruction_length
);
14347 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
14348 % lh
->maximum_ops_per_instruction
);
14349 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
14350 if (lh
->num_file_names
< file
|| file
== 0)
14351 dwarf2_debug_line_missing_file_complaint ();
14352 /* For now we ignore lines not starting on an
14353 instruction boundary. */
14354 else if (op_index
== 0)
14356 lh
->file_names
[file
- 1].included_p
= 1;
14357 if (!decode_for_pst_p
&& is_stmt
)
14359 if (last_subfile
!= current_subfile
)
14361 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14363 (*p_record_line
) (last_subfile
, 0, addr
);
14364 last_subfile
= current_subfile
;
14366 /* Append row to matrix using current values. */
14367 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14368 (*p_record_line
) (current_subfile
, line
, addr
);
14373 else switch (op_code
)
14375 case DW_LNS_extended_op
:
14376 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
14378 line_ptr
+= bytes_read
;
14379 extended_end
= line_ptr
+ extended_len
;
14380 extended_op
= read_1_byte (abfd
, line_ptr
);
14382 switch (extended_op
)
14384 case DW_LNE_end_sequence
:
14385 p_record_line
= record_line
;
14388 case DW_LNE_set_address
:
14389 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
14391 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14393 /* This line table is for a function which has been
14394 GCd by the linker. Ignore it. PR gdb/12528 */
14397 = line_ptr
- get_debug_line_section (cu
)->buffer
;
14399 complaint (&symfile_complaints
,
14400 _(".debug_line address at offset 0x%lx is 0 "
14402 line_offset
, objfile
->name
);
14403 p_record_line
= noop_record_line
;
14407 line_ptr
+= bytes_read
;
14408 address
+= baseaddr
;
14410 case DW_LNE_define_file
:
14413 unsigned int dir_index
, mod_time
, length
;
14415 cur_file
= read_direct_string (abfd
, line_ptr
,
14417 line_ptr
+= bytes_read
;
14419 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14420 line_ptr
+= bytes_read
;
14422 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14423 line_ptr
+= bytes_read
;
14425 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14426 line_ptr
+= bytes_read
;
14427 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14430 case DW_LNE_set_discriminator
:
14431 /* The discriminator is not interesting to the debugger;
14433 line_ptr
= extended_end
;
14436 complaint (&symfile_complaints
,
14437 _("mangled .debug_line section"));
14440 /* Make sure that we parsed the extended op correctly. If e.g.
14441 we expected a different address size than the producer used,
14442 we may have read the wrong number of bytes. */
14443 if (line_ptr
!= extended_end
)
14445 complaint (&symfile_complaints
,
14446 _("mangled .debug_line section"));
14451 if (lh
->num_file_names
< file
|| file
== 0)
14452 dwarf2_debug_line_missing_file_complaint ();
14455 lh
->file_names
[file
- 1].included_p
= 1;
14456 if (!decode_for_pst_p
&& is_stmt
)
14458 if (last_subfile
!= current_subfile
)
14460 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14462 (*p_record_line
) (last_subfile
, 0, addr
);
14463 last_subfile
= current_subfile
;
14465 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14466 (*p_record_line
) (current_subfile
, line
, addr
);
14471 case DW_LNS_advance_pc
:
14474 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14476 address
+= (((op_index
+ adjust
)
14477 / lh
->maximum_ops_per_instruction
)
14478 * lh
->minimum_instruction_length
);
14479 op_index
= ((op_index
+ adjust
)
14480 % lh
->maximum_ops_per_instruction
);
14481 line_ptr
+= bytes_read
;
14484 case DW_LNS_advance_line
:
14485 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
14486 line_ptr
+= bytes_read
;
14488 case DW_LNS_set_file
:
14490 /* The arrays lh->include_dirs and lh->file_names are
14491 0-based, but the directory and file name numbers in
14492 the statement program are 1-based. */
14493 struct file_entry
*fe
;
14496 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14497 line_ptr
+= bytes_read
;
14498 if (lh
->num_file_names
< file
|| file
== 0)
14499 dwarf2_debug_line_missing_file_complaint ();
14502 fe
= &lh
->file_names
[file
- 1];
14504 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14505 if (!decode_for_pst_p
)
14507 last_subfile
= current_subfile
;
14508 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14513 case DW_LNS_set_column
:
14514 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14515 line_ptr
+= bytes_read
;
14517 case DW_LNS_negate_stmt
:
14518 is_stmt
= (!is_stmt
);
14520 case DW_LNS_set_basic_block
:
14523 /* Add to the address register of the state machine the
14524 address increment value corresponding to special opcode
14525 255. I.e., this value is scaled by the minimum
14526 instruction length since special opcode 255 would have
14527 scaled the increment. */
14528 case DW_LNS_const_add_pc
:
14530 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
14532 address
+= (((op_index
+ adjust
)
14533 / lh
->maximum_ops_per_instruction
)
14534 * lh
->minimum_instruction_length
);
14535 op_index
= ((op_index
+ adjust
)
14536 % lh
->maximum_ops_per_instruction
);
14539 case DW_LNS_fixed_advance_pc
:
14540 address
+= read_2_bytes (abfd
, line_ptr
);
14546 /* Unknown standard opcode, ignore it. */
14549 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
14551 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14552 line_ptr
+= bytes_read
;
14557 if (lh
->num_file_names
< file
|| file
== 0)
14558 dwarf2_debug_line_missing_file_complaint ();
14561 lh
->file_names
[file
- 1].included_p
= 1;
14562 if (!decode_for_pst_p
)
14564 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14565 (*p_record_line
) (current_subfile
, 0, addr
);
14571 /* Decode the Line Number Program (LNP) for the given line_header
14572 structure and CU. The actual information extracted and the type
14573 of structures created from the LNP depends on the value of PST.
14575 1. If PST is NULL, then this procedure uses the data from the program
14576 to create all necessary symbol tables, and their linetables.
14578 2. If PST is not NULL, this procedure reads the program to determine
14579 the list of files included by the unit represented by PST, and
14580 builds all the associated partial symbol tables.
14582 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
14583 It is used for relative paths in the line table.
14584 NOTE: When processing partial symtabs (pst != NULL),
14585 comp_dir == pst->dirname.
14587 NOTE: It is important that psymtabs have the same file name (via strcmp)
14588 as the corresponding symtab. Since COMP_DIR is not used in the name of the
14589 symtab we don't use it in the name of the psymtabs we create.
14590 E.g. expand_line_sal requires this when finding psymtabs to expand.
14591 A good testcase for this is mb-inline.exp. */
14594 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
14595 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
14596 int want_line_info
)
14598 struct objfile
*objfile
= cu
->objfile
;
14599 const int decode_for_pst_p
= (pst
!= NULL
);
14600 struct subfile
*first_subfile
= current_subfile
;
14602 if (want_line_info
)
14603 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
14605 if (decode_for_pst_p
)
14609 /* Now that we're done scanning the Line Header Program, we can
14610 create the psymtab of each included file. */
14611 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
14612 if (lh
->file_names
[file_index
].included_p
== 1)
14614 char *include_name
=
14615 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
14616 if (include_name
!= NULL
)
14617 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
14622 /* Make sure a symtab is created for every file, even files
14623 which contain only variables (i.e. no code with associated
14627 for (i
= 0; i
< lh
->num_file_names
; i
++)
14630 struct file_entry
*fe
;
14632 fe
= &lh
->file_names
[i
];
14634 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14635 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14637 /* Skip the main file; we don't need it, and it must be
14638 allocated last, so that it will show up before the
14639 non-primary symtabs in the objfile's symtab list. */
14640 if (current_subfile
== first_subfile
)
14643 if (current_subfile
->symtab
== NULL
)
14644 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
14646 fe
->symtab
= current_subfile
->symtab
;
14651 /* Start a subfile for DWARF. FILENAME is the name of the file and
14652 DIRNAME the name of the source directory which contains FILENAME
14653 or NULL if not known. COMP_DIR is the compilation directory for the
14654 linetable's compilation unit or NULL if not known.
14655 This routine tries to keep line numbers from identical absolute and
14656 relative file names in a common subfile.
14658 Using the `list' example from the GDB testsuite, which resides in
14659 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
14660 of /srcdir/list0.c yields the following debugging information for list0.c:
14662 DW_AT_name: /srcdir/list0.c
14663 DW_AT_comp_dir: /compdir
14664 files.files[0].name: list0.h
14665 files.files[0].dir: /srcdir
14666 files.files[1].name: list0.c
14667 files.files[1].dir: /srcdir
14669 The line number information for list0.c has to end up in a single
14670 subfile, so that `break /srcdir/list0.c:1' works as expected.
14671 start_subfile will ensure that this happens provided that we pass the
14672 concatenation of files.files[1].dir and files.files[1].name as the
14676 dwarf2_start_subfile (char *filename
, const char *dirname
,
14677 const char *comp_dir
)
14681 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
14682 `start_symtab' will always pass the contents of DW_AT_comp_dir as
14683 second argument to start_subfile. To be consistent, we do the
14684 same here. In order not to lose the line information directory,
14685 we concatenate it to the filename when it makes sense.
14686 Note that the Dwarf3 standard says (speaking of filenames in line
14687 information): ``The directory index is ignored for file names
14688 that represent full path names''. Thus ignoring dirname in the
14689 `else' branch below isn't an issue. */
14691 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
14692 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
14694 fullname
= filename
;
14696 start_subfile (fullname
, comp_dir
);
14698 if (fullname
!= filename
)
14702 /* Start a symtab for DWARF.
14703 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
14706 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
14707 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
14709 start_symtab (name
, comp_dir
, low_pc
);
14710 record_debugformat ("DWARF 2");
14711 record_producer (cu
->producer
);
14713 /* We assume that we're processing GCC output. */
14714 processing_gcc_compilation
= 2;
14716 processing_has_namespace_info
= 0;
14720 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
14721 struct dwarf2_cu
*cu
)
14723 struct objfile
*objfile
= cu
->objfile
;
14724 struct comp_unit_head
*cu_header
= &cu
->header
;
14726 /* NOTE drow/2003-01-30: There used to be a comment and some special
14727 code here to turn a symbol with DW_AT_external and a
14728 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
14729 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
14730 with some versions of binutils) where shared libraries could have
14731 relocations against symbols in their debug information - the
14732 minimal symbol would have the right address, but the debug info
14733 would not. It's no longer necessary, because we will explicitly
14734 apply relocations when we read in the debug information now. */
14736 /* A DW_AT_location attribute with no contents indicates that a
14737 variable has been optimized away. */
14738 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
14740 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14744 /* Handle one degenerate form of location expression specially, to
14745 preserve GDB's previous behavior when section offsets are
14746 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
14747 then mark this symbol as LOC_STATIC. */
14749 if (attr_form_is_block (attr
)
14750 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
14751 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
14752 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
14753 && (DW_BLOCK (attr
)->size
14754 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
14756 unsigned int dummy
;
14758 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
14759 SYMBOL_VALUE_ADDRESS (sym
) =
14760 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
14762 SYMBOL_VALUE_ADDRESS (sym
) =
14763 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
14764 SYMBOL_CLASS (sym
) = LOC_STATIC
;
14765 fixup_symbol_section (sym
, objfile
);
14766 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
14767 SYMBOL_SECTION (sym
));
14771 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
14772 expression evaluator, and use LOC_COMPUTED only when necessary
14773 (i.e. when the value of a register or memory location is
14774 referenced, or a thread-local block, etc.). Then again, it might
14775 not be worthwhile. I'm assuming that it isn't unless performance
14776 or memory numbers show me otherwise. */
14778 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
14779 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14781 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
14782 cu
->has_loclist
= 1;
14785 /* Given a pointer to a DWARF information entry, figure out if we need
14786 to make a symbol table entry for it, and if so, create a new entry
14787 and return a pointer to it.
14788 If TYPE is NULL, determine symbol type from the die, otherwise
14789 used the passed type.
14790 If SPACE is not NULL, use it to hold the new symbol. If it is
14791 NULL, allocate a new symbol on the objfile's obstack. */
14793 static struct symbol
*
14794 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
14795 struct symbol
*space
)
14797 struct objfile
*objfile
= cu
->objfile
;
14798 struct symbol
*sym
= NULL
;
14800 struct attribute
*attr
= NULL
;
14801 struct attribute
*attr2
= NULL
;
14802 CORE_ADDR baseaddr
;
14803 struct pending
**list_to_add
= NULL
;
14805 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14807 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14809 name
= dwarf2_name (die
, cu
);
14812 const char *linkagename
;
14813 int suppress_add
= 0;
14818 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
14819 OBJSTAT (objfile
, n_syms
++);
14821 /* Cache this symbol's name and the name's demangled form (if any). */
14822 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
14823 linkagename
= dwarf2_physname (name
, die
, cu
);
14824 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
14826 /* Fortran does not have mangling standard and the mangling does differ
14827 between gfortran, iFort etc. */
14828 if (cu
->language
== language_fortran
14829 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
14830 symbol_set_demangled_name (&(sym
->ginfo
),
14831 (char *) dwarf2_full_name (name
, die
, cu
),
14834 /* Default assumptions.
14835 Use the passed type or decode it from the die. */
14836 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14837 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14839 SYMBOL_TYPE (sym
) = type
;
14841 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
14842 attr
= dwarf2_attr (die
,
14843 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
14847 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
14850 attr
= dwarf2_attr (die
,
14851 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
14855 int file_index
= DW_UNSND (attr
);
14857 if (cu
->line_header
== NULL
14858 || file_index
> cu
->line_header
->num_file_names
)
14859 complaint (&symfile_complaints
,
14860 _("file index out of range"));
14861 else if (file_index
> 0)
14863 struct file_entry
*fe
;
14865 fe
= &cu
->line_header
->file_names
[file_index
- 1];
14866 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
14873 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14876 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
14878 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
14879 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
14880 SYMBOL_CLASS (sym
) = LOC_LABEL
;
14881 add_symbol_to_list (sym
, cu
->list_in_scope
);
14883 case DW_TAG_subprogram
:
14884 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14886 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14887 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14888 if ((attr2
&& (DW_UNSND (attr2
) != 0))
14889 || cu
->language
== language_ada
)
14891 /* Subprograms marked external are stored as a global symbol.
14892 Ada subprograms, whether marked external or not, are always
14893 stored as a global symbol, because we want to be able to
14894 access them globally. For instance, we want to be able
14895 to break on a nested subprogram without having to
14896 specify the context. */
14897 list_to_add
= &global_symbols
;
14901 list_to_add
= cu
->list_in_scope
;
14904 case DW_TAG_inlined_subroutine
:
14905 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14907 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14908 SYMBOL_INLINED (sym
) = 1;
14909 list_to_add
= cu
->list_in_scope
;
14911 case DW_TAG_template_value_param
:
14913 /* Fall through. */
14914 case DW_TAG_constant
:
14915 case DW_TAG_variable
:
14916 case DW_TAG_member
:
14917 /* Compilation with minimal debug info may result in
14918 variables with missing type entries. Change the
14919 misleading `void' type to something sensible. */
14920 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
14922 = objfile_type (objfile
)->nodebug_data_symbol
;
14924 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14925 /* In the case of DW_TAG_member, we should only be called for
14926 static const members. */
14927 if (die
->tag
== DW_TAG_member
)
14929 /* dwarf2_add_field uses die_is_declaration,
14930 so we do the same. */
14931 gdb_assert (die_is_declaration (die
, cu
));
14936 dwarf2_const_value (attr
, sym
, cu
);
14937 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14940 if (attr2
&& (DW_UNSND (attr2
) != 0))
14941 list_to_add
= &global_symbols
;
14943 list_to_add
= cu
->list_in_scope
;
14947 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14950 var_decode_location (attr
, sym
, cu
);
14951 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14952 if (SYMBOL_CLASS (sym
) == LOC_STATIC
14953 && SYMBOL_VALUE_ADDRESS (sym
) == 0
14954 && !dwarf2_per_objfile
->has_section_at_zero
)
14956 /* When a static variable is eliminated by the linker,
14957 the corresponding debug information is not stripped
14958 out, but the variable address is set to null;
14959 do not add such variables into symbol table. */
14961 else if (attr2
&& (DW_UNSND (attr2
) != 0))
14963 /* Workaround gfortran PR debug/40040 - it uses
14964 DW_AT_location for variables in -fPIC libraries which may
14965 get overriden by other libraries/executable and get
14966 a different address. Resolve it by the minimal symbol
14967 which may come from inferior's executable using copy
14968 relocation. Make this workaround only for gfortran as for
14969 other compilers GDB cannot guess the minimal symbol
14970 Fortran mangling kind. */
14971 if (cu
->language
== language_fortran
&& die
->parent
14972 && die
->parent
->tag
== DW_TAG_module
14974 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
14975 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14977 /* A variable with DW_AT_external is never static,
14978 but it may be block-scoped. */
14979 list_to_add
= (cu
->list_in_scope
== &file_symbols
14980 ? &global_symbols
: cu
->list_in_scope
);
14983 list_to_add
= cu
->list_in_scope
;
14987 /* We do not know the address of this symbol.
14988 If it is an external symbol and we have type information
14989 for it, enter the symbol as a LOC_UNRESOLVED symbol.
14990 The address of the variable will then be determined from
14991 the minimal symbol table whenever the variable is
14993 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14994 if (attr2
&& (DW_UNSND (attr2
) != 0)
14995 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
14997 /* A variable with DW_AT_external is never static, but it
14998 may be block-scoped. */
14999 list_to_add
= (cu
->list_in_scope
== &file_symbols
15000 ? &global_symbols
: cu
->list_in_scope
);
15002 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15004 else if (!die_is_declaration (die
, cu
))
15006 /* Use the default LOC_OPTIMIZED_OUT class. */
15007 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
15009 list_to_add
= cu
->list_in_scope
;
15013 case DW_TAG_formal_parameter
:
15014 /* If we are inside a function, mark this as an argument. If
15015 not, we might be looking at an argument to an inlined function
15016 when we do not have enough information to show inlined frames;
15017 pretend it's a local variable in that case so that the user can
15019 if (context_stack_depth
> 0
15020 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
15021 SYMBOL_IS_ARGUMENT (sym
) = 1;
15022 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15025 var_decode_location (attr
, sym
, cu
);
15027 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15030 dwarf2_const_value (attr
, sym
, cu
);
15033 list_to_add
= cu
->list_in_scope
;
15035 case DW_TAG_unspecified_parameters
:
15036 /* From varargs functions; gdb doesn't seem to have any
15037 interest in this information, so just ignore it for now.
15040 case DW_TAG_template_type_param
:
15042 /* Fall through. */
15043 case DW_TAG_class_type
:
15044 case DW_TAG_interface_type
:
15045 case DW_TAG_structure_type
:
15046 case DW_TAG_union_type
:
15047 case DW_TAG_set_type
:
15048 case DW_TAG_enumeration_type
:
15049 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15050 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
15053 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
15054 really ever be static objects: otherwise, if you try
15055 to, say, break of a class's method and you're in a file
15056 which doesn't mention that class, it won't work unless
15057 the check for all static symbols in lookup_symbol_aux
15058 saves you. See the OtherFileClass tests in
15059 gdb.c++/namespace.exp. */
15063 list_to_add
= (cu
->list_in_scope
== &file_symbols
15064 && (cu
->language
== language_cplus
15065 || cu
->language
== language_java
)
15066 ? &global_symbols
: cu
->list_in_scope
);
15068 /* The semantics of C++ state that "struct foo {
15069 ... }" also defines a typedef for "foo". A Java
15070 class declaration also defines a typedef for the
15072 if (cu
->language
== language_cplus
15073 || cu
->language
== language_java
15074 || cu
->language
== language_ada
)
15076 /* The symbol's name is already allocated along
15077 with this objfile, so we don't need to
15078 duplicate it for the type. */
15079 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
15080 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
15085 case DW_TAG_typedef
:
15086 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15087 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15088 list_to_add
= cu
->list_in_scope
;
15090 case DW_TAG_base_type
:
15091 case DW_TAG_subrange_type
:
15092 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15093 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15094 list_to_add
= cu
->list_in_scope
;
15096 case DW_TAG_enumerator
:
15097 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15100 dwarf2_const_value (attr
, sym
, cu
);
15103 /* NOTE: carlton/2003-11-10: See comment above in the
15104 DW_TAG_class_type, etc. block. */
15106 list_to_add
= (cu
->list_in_scope
== &file_symbols
15107 && (cu
->language
== language_cplus
15108 || cu
->language
== language_java
)
15109 ? &global_symbols
: cu
->list_in_scope
);
15112 case DW_TAG_namespace
:
15113 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15114 list_to_add
= &global_symbols
;
15117 /* Not a tag we recognize. Hopefully we aren't processing
15118 trash data, but since we must specifically ignore things
15119 we don't recognize, there is nothing else we should do at
15121 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
15122 dwarf_tag_name (die
->tag
));
15128 sym
->hash_next
= objfile
->template_symbols
;
15129 objfile
->template_symbols
= sym
;
15130 list_to_add
= NULL
;
15133 if (list_to_add
!= NULL
)
15134 add_symbol_to_list (sym
, list_to_add
);
15136 /* For the benefit of old versions of GCC, check for anonymous
15137 namespaces based on the demangled name. */
15138 if (!processing_has_namespace_info
15139 && cu
->language
== language_cplus
)
15140 cp_scan_for_anonymous_namespaces (sym
, objfile
);
15145 /* A wrapper for new_symbol_full that always allocates a new symbol. */
15147 static struct symbol
*
15148 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15150 return new_symbol_full (die
, type
, cu
, NULL
);
15153 /* Given an attr with a DW_FORM_dataN value in host byte order,
15154 zero-extend it as appropriate for the symbol's type. The DWARF
15155 standard (v4) is not entirely clear about the meaning of using
15156 DW_FORM_dataN for a constant with a signed type, where the type is
15157 wider than the data. The conclusion of a discussion on the DWARF
15158 list was that this is unspecified. We choose to always zero-extend
15159 because that is the interpretation long in use by GCC. */
15162 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
15163 const char *name
, struct obstack
*obstack
,
15164 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
15166 struct objfile
*objfile
= cu
->objfile
;
15167 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
15168 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
15169 LONGEST l
= DW_UNSND (attr
);
15171 if (bits
< sizeof (*value
) * 8)
15173 l
&= ((LONGEST
) 1 << bits
) - 1;
15176 else if (bits
== sizeof (*value
) * 8)
15180 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
15181 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
15188 /* Read a constant value from an attribute. Either set *VALUE, or if
15189 the value does not fit in *VALUE, set *BYTES - either already
15190 allocated on the objfile obstack, or newly allocated on OBSTACK,
15191 or, set *BATON, if we translated the constant to a location
15195 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
15196 const char *name
, struct obstack
*obstack
,
15197 struct dwarf2_cu
*cu
,
15198 LONGEST
*value
, gdb_byte
**bytes
,
15199 struct dwarf2_locexpr_baton
**baton
)
15201 struct objfile
*objfile
= cu
->objfile
;
15202 struct comp_unit_head
*cu_header
= &cu
->header
;
15203 struct dwarf_block
*blk
;
15204 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
15205 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
15211 switch (attr
->form
)
15214 case DW_FORM_GNU_addr_index
:
15218 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
15219 dwarf2_const_value_length_mismatch_complaint (name
,
15220 cu_header
->addr_size
,
15221 TYPE_LENGTH (type
));
15222 /* Symbols of this form are reasonably rare, so we just
15223 piggyback on the existing location code rather than writing
15224 a new implementation of symbol_computed_ops. */
15225 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
15226 sizeof (struct dwarf2_locexpr_baton
));
15227 (*baton
)->per_cu
= cu
->per_cu
;
15228 gdb_assert ((*baton
)->per_cu
);
15230 (*baton
)->size
= 2 + cu_header
->addr_size
;
15231 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
15232 (*baton
)->data
= data
;
15234 data
[0] = DW_OP_addr
;
15235 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
15236 byte_order
, DW_ADDR (attr
));
15237 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
15240 case DW_FORM_string
:
15242 case DW_FORM_GNU_str_index
:
15243 case DW_FORM_GNU_strp_alt
:
15244 /* DW_STRING is already allocated on the objfile obstack, point
15246 *bytes
= (gdb_byte
*) DW_STRING (attr
);
15248 case DW_FORM_block1
:
15249 case DW_FORM_block2
:
15250 case DW_FORM_block4
:
15251 case DW_FORM_block
:
15252 case DW_FORM_exprloc
:
15253 blk
= DW_BLOCK (attr
);
15254 if (TYPE_LENGTH (type
) != blk
->size
)
15255 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
15256 TYPE_LENGTH (type
));
15257 *bytes
= blk
->data
;
15260 /* The DW_AT_const_value attributes are supposed to carry the
15261 symbol's value "represented as it would be on the target
15262 architecture." By the time we get here, it's already been
15263 converted to host endianness, so we just need to sign- or
15264 zero-extend it as appropriate. */
15265 case DW_FORM_data1
:
15266 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15267 obstack
, cu
, value
, 8);
15269 case DW_FORM_data2
:
15270 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15271 obstack
, cu
, value
, 16);
15273 case DW_FORM_data4
:
15274 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15275 obstack
, cu
, value
, 32);
15277 case DW_FORM_data8
:
15278 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15279 obstack
, cu
, value
, 64);
15282 case DW_FORM_sdata
:
15283 *value
= DW_SND (attr
);
15286 case DW_FORM_udata
:
15287 *value
= DW_UNSND (attr
);
15291 complaint (&symfile_complaints
,
15292 _("unsupported const value attribute form: '%s'"),
15293 dwarf_form_name (attr
->form
));
15300 /* Copy constant value from an attribute to a symbol. */
15303 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
15304 struct dwarf2_cu
*cu
)
15306 struct objfile
*objfile
= cu
->objfile
;
15307 struct comp_unit_head
*cu_header
= &cu
->header
;
15310 struct dwarf2_locexpr_baton
*baton
;
15312 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
15313 SYMBOL_PRINT_NAME (sym
),
15314 &objfile
->objfile_obstack
, cu
,
15315 &value
, &bytes
, &baton
);
15319 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15320 SYMBOL_LOCATION_BATON (sym
) = baton
;
15321 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15323 else if (bytes
!= NULL
)
15325 SYMBOL_VALUE_BYTES (sym
) = bytes
;
15326 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
15330 SYMBOL_VALUE (sym
) = value
;
15331 SYMBOL_CLASS (sym
) = LOC_CONST
;
15335 /* Return the type of the die in question using its DW_AT_type attribute. */
15337 static struct type
*
15338 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15340 struct attribute
*type_attr
;
15342 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15345 /* A missing DW_AT_type represents a void type. */
15346 return objfile_type (cu
->objfile
)->builtin_void
;
15349 return lookup_die_type (die
, type_attr
, cu
);
15352 /* True iff CU's producer generates GNAT Ada auxiliary information
15353 that allows to find parallel types through that information instead
15354 of having to do expensive parallel lookups by type name. */
15357 need_gnat_info (struct dwarf2_cu
*cu
)
15359 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
15360 of GNAT produces this auxiliary information, without any indication
15361 that it is produced. Part of enhancing the FSF version of GNAT
15362 to produce that information will be to put in place an indicator
15363 that we can use in order to determine whether the descriptive type
15364 info is available or not. One suggestion that has been made is
15365 to use a new attribute, attached to the CU die. For now, assume
15366 that the descriptive type info is not available. */
15370 /* Return the auxiliary type of the die in question using its
15371 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
15372 attribute is not present. */
15374 static struct type
*
15375 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15377 struct attribute
*type_attr
;
15379 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
15383 return lookup_die_type (die
, type_attr
, cu
);
15386 /* If DIE has a descriptive_type attribute, then set the TYPE's
15387 descriptive type accordingly. */
15390 set_descriptive_type (struct type
*type
, struct die_info
*die
,
15391 struct dwarf2_cu
*cu
)
15393 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
15395 if (descriptive_type
)
15397 ALLOCATE_GNAT_AUX_TYPE (type
);
15398 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
15402 /* Return the containing type of the die in question using its
15403 DW_AT_containing_type attribute. */
15405 static struct type
*
15406 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15408 struct attribute
*type_attr
;
15410 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
15412 error (_("Dwarf Error: Problem turning containing type into gdb type "
15413 "[in module %s]"), cu
->objfile
->name
);
15415 return lookup_die_type (die
, type_attr
, cu
);
15418 /* Look up the type of DIE in CU using its type attribute ATTR.
15419 If there is no type substitute an error marker. */
15421 static struct type
*
15422 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
15423 struct dwarf2_cu
*cu
)
15425 struct objfile
*objfile
= cu
->objfile
;
15426 struct type
*this_type
;
15428 /* First see if we have it cached. */
15430 if (attr
->form
== DW_FORM_GNU_ref_alt
)
15432 struct dwarf2_per_cu_data
*per_cu
;
15433 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15435 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
15436 this_type
= get_die_type_at_offset (offset
, per_cu
);
15438 else if (is_ref_attr (attr
))
15440 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15442 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
15444 else if (attr
->form
== DW_FORM_ref_sig8
)
15446 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15448 /* sig_type will be NULL if the signatured type is missing from
15450 if (sig_type
== NULL
)
15451 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15452 "at 0x%x [in module %s]"),
15453 die
->offset
.sect_off
, objfile
->name
);
15455 gdb_assert (sig_type
->per_cu
.is_debug_types
);
15456 /* If we haven't filled in type_offset_in_section yet, then we
15457 haven't read the type in yet. */
15459 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
15462 get_die_type_at_offset (sig_type
->type_offset_in_section
,
15463 &sig_type
->per_cu
);
15468 dump_die_for_error (die
);
15469 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
15470 dwarf_attr_name (attr
->name
), objfile
->name
);
15473 /* If not cached we need to read it in. */
15475 if (this_type
== NULL
)
15477 struct die_info
*type_die
;
15478 struct dwarf2_cu
*type_cu
= cu
;
15480 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
15481 /* If we found the type now, it's probably because the type came
15482 from an inter-CU reference and the type's CU got expanded before
15484 this_type
= get_die_type (type_die
, type_cu
);
15485 if (this_type
== NULL
)
15486 this_type
= read_type_die_1 (type_die
, type_cu
);
15489 /* If we still don't have a type use an error marker. */
15491 if (this_type
== NULL
)
15493 char *message
, *saved
;
15495 /* read_type_die already issued a complaint. */
15496 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
15498 cu
->header
.offset
.sect_off
,
15499 die
->offset
.sect_off
);
15500 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
15501 message
, strlen (message
));
15504 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
15510 /* Return the type in DIE, CU.
15511 Returns NULL for invalid types.
15513 This first does a lookup in the appropriate type_hash table,
15514 and only reads the die in if necessary.
15516 NOTE: This can be called when reading in partial or full symbols. */
15518 static struct type
*
15519 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
15521 struct type
*this_type
;
15523 this_type
= get_die_type (die
, cu
);
15527 return read_type_die_1 (die
, cu
);
15530 /* Read the type in DIE, CU.
15531 Returns NULL for invalid types. */
15533 static struct type
*
15534 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
15536 struct type
*this_type
= NULL
;
15540 case DW_TAG_class_type
:
15541 case DW_TAG_interface_type
:
15542 case DW_TAG_structure_type
:
15543 case DW_TAG_union_type
:
15544 this_type
= read_structure_type (die
, cu
);
15546 case DW_TAG_enumeration_type
:
15547 this_type
= read_enumeration_type (die
, cu
);
15549 case DW_TAG_subprogram
:
15550 case DW_TAG_subroutine_type
:
15551 case DW_TAG_inlined_subroutine
:
15552 this_type
= read_subroutine_type (die
, cu
);
15554 case DW_TAG_array_type
:
15555 this_type
= read_array_type (die
, cu
);
15557 case DW_TAG_set_type
:
15558 this_type
= read_set_type (die
, cu
);
15560 case DW_TAG_pointer_type
:
15561 this_type
= read_tag_pointer_type (die
, cu
);
15563 case DW_TAG_ptr_to_member_type
:
15564 this_type
= read_tag_ptr_to_member_type (die
, cu
);
15566 case DW_TAG_reference_type
:
15567 this_type
= read_tag_reference_type (die
, cu
);
15569 case DW_TAG_const_type
:
15570 this_type
= read_tag_const_type (die
, cu
);
15572 case DW_TAG_volatile_type
:
15573 this_type
= read_tag_volatile_type (die
, cu
);
15575 case DW_TAG_string_type
:
15576 this_type
= read_tag_string_type (die
, cu
);
15578 case DW_TAG_typedef
:
15579 this_type
= read_typedef (die
, cu
);
15581 case DW_TAG_subrange_type
:
15582 this_type
= read_subrange_type (die
, cu
);
15584 case DW_TAG_base_type
:
15585 this_type
= read_base_type (die
, cu
);
15587 case DW_TAG_unspecified_type
:
15588 this_type
= read_unspecified_type (die
, cu
);
15590 case DW_TAG_namespace
:
15591 this_type
= read_namespace_type (die
, cu
);
15593 case DW_TAG_module
:
15594 this_type
= read_module_type (die
, cu
);
15597 complaint (&symfile_complaints
,
15598 _("unexpected tag in read_type_die: '%s'"),
15599 dwarf_tag_name (die
->tag
));
15606 /* See if we can figure out if the class lives in a namespace. We do
15607 this by looking for a member function; its demangled name will
15608 contain namespace info, if there is any.
15609 Return the computed name or NULL.
15610 Space for the result is allocated on the objfile's obstack.
15611 This is the full-die version of guess_partial_die_structure_name.
15612 In this case we know DIE has no useful parent. */
15615 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15617 struct die_info
*spec_die
;
15618 struct dwarf2_cu
*spec_cu
;
15619 struct die_info
*child
;
15622 spec_die
= die_specification (die
, &spec_cu
);
15623 if (spec_die
!= NULL
)
15629 for (child
= die
->child
;
15631 child
= child
->sibling
)
15633 if (child
->tag
== DW_TAG_subprogram
)
15635 struct attribute
*attr
;
15637 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
15639 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
15643 = language_class_name_from_physname (cu
->language_defn
,
15647 if (actual_name
!= NULL
)
15649 char *die_name
= dwarf2_name (die
, cu
);
15651 if (die_name
!= NULL
15652 && strcmp (die_name
, actual_name
) != 0)
15654 /* Strip off the class name from the full name.
15655 We want the prefix. */
15656 int die_name_len
= strlen (die_name
);
15657 int actual_name_len
= strlen (actual_name
);
15659 /* Test for '::' as a sanity check. */
15660 if (actual_name_len
> die_name_len
+ 2
15661 && actual_name
[actual_name_len
15662 - die_name_len
- 1] == ':')
15664 obsavestring (actual_name
,
15665 actual_name_len
- die_name_len
- 2,
15666 &cu
->objfile
->objfile_obstack
);
15669 xfree (actual_name
);
15678 /* GCC might emit a nameless typedef that has a linkage name. Determine the
15679 prefix part in such case. See
15680 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15683 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15685 struct attribute
*attr
;
15688 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
15689 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
15692 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15693 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
15696 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15698 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15699 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15702 /* dwarf2_name had to be already called. */
15703 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
15705 /* Strip the base name, keep any leading namespaces/classes. */
15706 base
= strrchr (DW_STRING (attr
), ':');
15707 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
15710 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
15711 &cu
->objfile
->objfile_obstack
);
15714 /* Return the name of the namespace/class that DIE is defined within,
15715 or "" if we can't tell. The caller should not xfree the result.
15717 For example, if we're within the method foo() in the following
15727 then determine_prefix on foo's die will return "N::C". */
15729 static const char *
15730 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15732 struct die_info
*parent
, *spec_die
;
15733 struct dwarf2_cu
*spec_cu
;
15734 struct type
*parent_type
;
15737 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
15738 && cu
->language
!= language_fortran
)
15741 retval
= anonymous_struct_prefix (die
, cu
);
15745 /* We have to be careful in the presence of DW_AT_specification.
15746 For example, with GCC 3.4, given the code
15750 // Definition of N::foo.
15754 then we'll have a tree of DIEs like this:
15756 1: DW_TAG_compile_unit
15757 2: DW_TAG_namespace // N
15758 3: DW_TAG_subprogram // declaration of N::foo
15759 4: DW_TAG_subprogram // definition of N::foo
15760 DW_AT_specification // refers to die #3
15762 Thus, when processing die #4, we have to pretend that we're in
15763 the context of its DW_AT_specification, namely the contex of die
15766 spec_die
= die_specification (die
, &spec_cu
);
15767 if (spec_die
== NULL
)
15768 parent
= die
->parent
;
15771 parent
= spec_die
->parent
;
15775 if (parent
== NULL
)
15777 else if (parent
->building_fullname
)
15780 const char *parent_name
;
15782 /* It has been seen on RealView 2.2 built binaries,
15783 DW_TAG_template_type_param types actually _defined_ as
15784 children of the parent class:
15787 template class <class Enum> Class{};
15788 Class<enum E> class_e;
15790 1: DW_TAG_class_type (Class)
15791 2: DW_TAG_enumeration_type (E)
15792 3: DW_TAG_enumerator (enum1:0)
15793 3: DW_TAG_enumerator (enum2:1)
15795 2: DW_TAG_template_type_param
15796 DW_AT_type DW_FORM_ref_udata (E)
15798 Besides being broken debug info, it can put GDB into an
15799 infinite loop. Consider:
15801 When we're building the full name for Class<E>, we'll start
15802 at Class, and go look over its template type parameters,
15803 finding E. We'll then try to build the full name of E, and
15804 reach here. We're now trying to build the full name of E,
15805 and look over the parent DIE for containing scope. In the
15806 broken case, if we followed the parent DIE of E, we'd again
15807 find Class, and once again go look at its template type
15808 arguments, etc., etc. Simply don't consider such parent die
15809 as source-level parent of this die (it can't be, the language
15810 doesn't allow it), and break the loop here. */
15811 name
= dwarf2_name (die
, cu
);
15812 parent_name
= dwarf2_name (parent
, cu
);
15813 complaint (&symfile_complaints
,
15814 _("template param type '%s' defined within parent '%s'"),
15815 name
? name
: "<unknown>",
15816 parent_name
? parent_name
: "<unknown>");
15820 switch (parent
->tag
)
15822 case DW_TAG_namespace
:
15823 parent_type
= read_type_die (parent
, cu
);
15824 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
15825 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
15826 Work around this problem here. */
15827 if (cu
->language
== language_cplus
15828 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
15830 /* We give a name to even anonymous namespaces. */
15831 return TYPE_TAG_NAME (parent_type
);
15832 case DW_TAG_class_type
:
15833 case DW_TAG_interface_type
:
15834 case DW_TAG_structure_type
:
15835 case DW_TAG_union_type
:
15836 case DW_TAG_module
:
15837 parent_type
= read_type_die (parent
, cu
);
15838 if (TYPE_TAG_NAME (parent_type
) != NULL
)
15839 return TYPE_TAG_NAME (parent_type
);
15841 /* An anonymous structure is only allowed non-static data
15842 members; no typedefs, no member functions, et cetera.
15843 So it does not need a prefix. */
15845 case DW_TAG_compile_unit
:
15846 case DW_TAG_partial_unit
:
15847 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
15848 if (cu
->language
== language_cplus
15849 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
15850 && die
->child
!= NULL
15851 && (die
->tag
== DW_TAG_class_type
15852 || die
->tag
== DW_TAG_structure_type
15853 || die
->tag
== DW_TAG_union_type
))
15855 char *name
= guess_full_die_structure_name (die
, cu
);
15861 return determine_prefix (parent
, cu
);
15865 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
15866 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
15867 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
15868 an obconcat, otherwise allocate storage for the result. The CU argument is
15869 used to determine the language and hence, the appropriate separator. */
15871 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
15874 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
15875 int physname
, struct dwarf2_cu
*cu
)
15877 const char *lead
= "";
15880 if (suffix
== NULL
|| suffix
[0] == '\0'
15881 || prefix
== NULL
|| prefix
[0] == '\0')
15883 else if (cu
->language
== language_java
)
15885 else if (cu
->language
== language_fortran
&& physname
)
15887 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
15888 DW_AT_MIPS_linkage_name is preferred and used instead. */
15896 if (prefix
== NULL
)
15898 if (suffix
== NULL
)
15904 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
15906 strcpy (retval
, lead
);
15907 strcat (retval
, prefix
);
15908 strcat (retval
, sep
);
15909 strcat (retval
, suffix
);
15914 /* We have an obstack. */
15915 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
15919 /* Return sibling of die, NULL if no sibling. */
15921 static struct die_info
*
15922 sibling_die (struct die_info
*die
)
15924 return die
->sibling
;
15927 /* Get name of a die, return NULL if not found. */
15930 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
15931 struct obstack
*obstack
)
15933 if (name
&& cu
->language
== language_cplus
)
15935 char *canon_name
= cp_canonicalize_string (name
);
15937 if (canon_name
!= NULL
)
15939 if (strcmp (canon_name
, name
) != 0)
15940 name
= obsavestring (canon_name
, strlen (canon_name
),
15942 xfree (canon_name
);
15949 /* Get name of a die, return NULL if not found. */
15952 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15954 struct attribute
*attr
;
15956 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15957 if ((!attr
|| !DW_STRING (attr
))
15958 && die
->tag
!= DW_TAG_class_type
15959 && die
->tag
!= DW_TAG_interface_type
15960 && die
->tag
!= DW_TAG_structure_type
15961 && die
->tag
!= DW_TAG_union_type
)
15966 case DW_TAG_compile_unit
:
15967 case DW_TAG_partial_unit
:
15968 /* Compilation units have a DW_AT_name that is a filename, not
15969 a source language identifier. */
15970 case DW_TAG_enumeration_type
:
15971 case DW_TAG_enumerator
:
15972 /* These tags always have simple identifiers already; no need
15973 to canonicalize them. */
15974 return DW_STRING (attr
);
15976 case DW_TAG_subprogram
:
15977 /* Java constructors will all be named "<init>", so return
15978 the class name when we see this special case. */
15979 if (cu
->language
== language_java
15980 && DW_STRING (attr
) != NULL
15981 && strcmp (DW_STRING (attr
), "<init>") == 0)
15983 struct dwarf2_cu
*spec_cu
= cu
;
15984 struct die_info
*spec_die
;
15986 /* GCJ will output '<init>' for Java constructor names.
15987 For this special case, return the name of the parent class. */
15989 /* GCJ may output suprogram DIEs with AT_specification set.
15990 If so, use the name of the specified DIE. */
15991 spec_die
= die_specification (die
, &spec_cu
);
15992 if (spec_die
!= NULL
)
15993 return dwarf2_name (spec_die
, spec_cu
);
15998 if (die
->tag
== DW_TAG_class_type
)
15999 return dwarf2_name (die
, cu
);
16001 while (die
->tag
!= DW_TAG_compile_unit
16002 && die
->tag
!= DW_TAG_partial_unit
);
16006 case DW_TAG_class_type
:
16007 case DW_TAG_interface_type
:
16008 case DW_TAG_structure_type
:
16009 case DW_TAG_union_type
:
16010 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
16011 structures or unions. These were of the form "._%d" in GCC 4.1,
16012 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
16013 and GCC 4.4. We work around this problem by ignoring these. */
16014 if (attr
&& DW_STRING (attr
)
16015 && (strncmp (DW_STRING (attr
), "._", 2) == 0
16016 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
16019 /* GCC might emit a nameless typedef that has a linkage name. See
16020 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16021 if (!attr
|| DW_STRING (attr
) == NULL
)
16023 char *demangled
= NULL
;
16025 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16027 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16029 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16032 /* Avoid demangling DW_STRING (attr) the second time on a second
16033 call for the same DIE. */
16034 if (!DW_STRING_IS_CANONICAL (attr
))
16035 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
16041 /* FIXME: we already did this for the partial symbol... */
16042 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
16043 &cu
->objfile
->objfile_obstack
);
16044 DW_STRING_IS_CANONICAL (attr
) = 1;
16047 /* Strip any leading namespaces/classes, keep only the base name.
16048 DW_AT_name for named DIEs does not contain the prefixes. */
16049 base
= strrchr (DW_STRING (attr
), ':');
16050 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
16053 return DW_STRING (attr
);
16062 if (!DW_STRING_IS_CANONICAL (attr
))
16065 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
16066 &cu
->objfile
->objfile_obstack
);
16067 DW_STRING_IS_CANONICAL (attr
) = 1;
16069 return DW_STRING (attr
);
16072 /* Return the die that this die in an extension of, or NULL if there
16073 is none. *EXT_CU is the CU containing DIE on input, and the CU
16074 containing the return value on output. */
16076 static struct die_info
*
16077 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
16079 struct attribute
*attr
;
16081 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
16085 return follow_die_ref (die
, attr
, ext_cu
);
16088 /* Convert a DIE tag into its string name. */
16090 static const char *
16091 dwarf_tag_name (unsigned tag
)
16093 const char *name
= get_DW_TAG_name (tag
);
16096 return "DW_TAG_<unknown>";
16101 /* Convert a DWARF attribute code into its string name. */
16103 static const char *
16104 dwarf_attr_name (unsigned attr
)
16108 #ifdef MIPS /* collides with DW_AT_HP_block_index */
16109 if (attr
== DW_AT_MIPS_fde
)
16110 return "DW_AT_MIPS_fde";
16112 if (attr
== DW_AT_HP_block_index
)
16113 return "DW_AT_HP_block_index";
16116 name
= get_DW_AT_name (attr
);
16119 return "DW_AT_<unknown>";
16124 /* Convert a DWARF value form code into its string name. */
16126 static const char *
16127 dwarf_form_name (unsigned form
)
16129 const char *name
= get_DW_FORM_name (form
);
16132 return "DW_FORM_<unknown>";
16138 dwarf_bool_name (unsigned mybool
)
16146 /* Convert a DWARF type code into its string name. */
16148 static const char *
16149 dwarf_type_encoding_name (unsigned enc
)
16151 const char *name
= get_DW_ATE_name (enc
);
16154 return "DW_ATE_<unknown>";
16160 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
16164 print_spaces (indent
, f
);
16165 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
16166 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
16168 if (die
->parent
!= NULL
)
16170 print_spaces (indent
, f
);
16171 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
16172 die
->parent
->offset
.sect_off
);
16175 print_spaces (indent
, f
);
16176 fprintf_unfiltered (f
, " has children: %s\n",
16177 dwarf_bool_name (die
->child
!= NULL
));
16179 print_spaces (indent
, f
);
16180 fprintf_unfiltered (f
, " attributes:\n");
16182 for (i
= 0; i
< die
->num_attrs
; ++i
)
16184 print_spaces (indent
, f
);
16185 fprintf_unfiltered (f
, " %s (%s) ",
16186 dwarf_attr_name (die
->attrs
[i
].name
),
16187 dwarf_form_name (die
->attrs
[i
].form
));
16189 switch (die
->attrs
[i
].form
)
16192 case DW_FORM_GNU_addr_index
:
16193 fprintf_unfiltered (f
, "address: ");
16194 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
16196 case DW_FORM_block2
:
16197 case DW_FORM_block4
:
16198 case DW_FORM_block
:
16199 case DW_FORM_block1
:
16200 fprintf_unfiltered (f
, "block: size %s",
16201 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
16203 case DW_FORM_exprloc
:
16204 fprintf_unfiltered (f
, "expression: size %s",
16205 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
16207 case DW_FORM_ref_addr
:
16208 fprintf_unfiltered (f
, "ref address: ");
16209 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
16211 case DW_FORM_GNU_ref_alt
:
16212 fprintf_unfiltered (f
, "alt ref address: ");
16213 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
16219 case DW_FORM_ref_udata
:
16220 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
16221 (long) (DW_UNSND (&die
->attrs
[i
])));
16223 case DW_FORM_data1
:
16224 case DW_FORM_data2
:
16225 case DW_FORM_data4
:
16226 case DW_FORM_data8
:
16227 case DW_FORM_udata
:
16228 case DW_FORM_sdata
:
16229 fprintf_unfiltered (f
, "constant: %s",
16230 pulongest (DW_UNSND (&die
->attrs
[i
])));
16232 case DW_FORM_sec_offset
:
16233 fprintf_unfiltered (f
, "section offset: %s",
16234 pulongest (DW_UNSND (&die
->attrs
[i
])));
16236 case DW_FORM_ref_sig8
:
16237 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
16238 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
16239 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
16241 fprintf_unfiltered (f
, "signatured type, offset: unknown");
16243 case DW_FORM_string
:
16245 case DW_FORM_GNU_str_index
:
16246 case DW_FORM_GNU_strp_alt
:
16247 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
16248 DW_STRING (&die
->attrs
[i
])
16249 ? DW_STRING (&die
->attrs
[i
]) : "",
16250 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
16253 if (DW_UNSND (&die
->attrs
[i
]))
16254 fprintf_unfiltered (f
, "flag: TRUE");
16256 fprintf_unfiltered (f
, "flag: FALSE");
16258 case DW_FORM_flag_present
:
16259 fprintf_unfiltered (f
, "flag: TRUE");
16261 case DW_FORM_indirect
:
16262 /* The reader will have reduced the indirect form to
16263 the "base form" so this form should not occur. */
16264 fprintf_unfiltered (f
,
16265 "unexpected attribute form: DW_FORM_indirect");
16268 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
16269 die
->attrs
[i
].form
);
16272 fprintf_unfiltered (f
, "\n");
16277 dump_die_for_error (struct die_info
*die
)
16279 dump_die_shallow (gdb_stderr
, 0, die
);
16283 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
16285 int indent
= level
* 4;
16287 gdb_assert (die
!= NULL
);
16289 if (level
>= max_level
)
16292 dump_die_shallow (f
, indent
, die
);
16294 if (die
->child
!= NULL
)
16296 print_spaces (indent
, f
);
16297 fprintf_unfiltered (f
, " Children:");
16298 if (level
+ 1 < max_level
)
16300 fprintf_unfiltered (f
, "\n");
16301 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
16305 fprintf_unfiltered (f
,
16306 " [not printed, max nesting level reached]\n");
16310 if (die
->sibling
!= NULL
&& level
> 0)
16312 dump_die_1 (f
, level
, max_level
, die
->sibling
);
16316 /* This is called from the pdie macro in gdbinit.in.
16317 It's not static so gcc will keep a copy callable from gdb. */
16320 dump_die (struct die_info
*die
, int max_level
)
16322 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
16326 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
16330 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
16336 /* DW_ADDR is always stored already as sect_offset; despite for the forms
16337 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
16340 is_ref_attr (struct attribute
*attr
)
16342 switch (attr
->form
)
16344 case DW_FORM_ref_addr
:
16349 case DW_FORM_ref_udata
:
16350 case DW_FORM_GNU_ref_alt
:
16357 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
16361 dwarf2_get_ref_die_offset (struct attribute
*attr
)
16363 sect_offset retval
= { DW_UNSND (attr
) };
16365 if (is_ref_attr (attr
))
16368 retval
.sect_off
= 0;
16369 complaint (&symfile_complaints
,
16370 _("unsupported die ref attribute form: '%s'"),
16371 dwarf_form_name (attr
->form
));
16375 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
16376 * the value held by the attribute is not constant. */
16379 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
16381 if (attr
->form
== DW_FORM_sdata
)
16382 return DW_SND (attr
);
16383 else if (attr
->form
== DW_FORM_udata
16384 || attr
->form
== DW_FORM_data1
16385 || attr
->form
== DW_FORM_data2
16386 || attr
->form
== DW_FORM_data4
16387 || attr
->form
== DW_FORM_data8
)
16388 return DW_UNSND (attr
);
16391 complaint (&symfile_complaints
,
16392 _("Attribute value is not a constant (%s)"),
16393 dwarf_form_name (attr
->form
));
16394 return default_value
;
16398 /* Follow reference or signature attribute ATTR of SRC_DIE.
16399 On entry *REF_CU is the CU of SRC_DIE.
16400 On exit *REF_CU is the CU of the result. */
16402 static struct die_info
*
16403 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
16404 struct dwarf2_cu
**ref_cu
)
16406 struct die_info
*die
;
16408 if (is_ref_attr (attr
))
16409 die
= follow_die_ref (src_die
, attr
, ref_cu
);
16410 else if (attr
->form
== DW_FORM_ref_sig8
)
16411 die
= follow_die_sig (src_die
, attr
, ref_cu
);
16414 dump_die_for_error (src_die
);
16415 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
16416 (*ref_cu
)->objfile
->name
);
16422 /* Follow reference OFFSET.
16423 On entry *REF_CU is the CU of the source die referencing OFFSET.
16424 On exit *REF_CU is the CU of the result.
16425 Returns NULL if OFFSET is invalid. */
16427 static struct die_info
*
16428 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
16429 struct dwarf2_cu
**ref_cu
)
16431 struct die_info temp_die
;
16432 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
16434 gdb_assert (cu
->per_cu
!= NULL
);
16438 if (cu
->per_cu
->is_debug_types
)
16440 /* .debug_types CUs cannot reference anything outside their CU.
16441 If they need to, they have to reference a signatured type via
16442 DW_FORM_ref_sig8. */
16443 if (! offset_in_cu_p (&cu
->header
, offset
))
16446 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
16447 || ! offset_in_cu_p (&cu
->header
, offset
))
16449 struct dwarf2_per_cu_data
*per_cu
;
16451 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
16454 /* If necessary, add it to the queue and load its DIEs. */
16455 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
16456 load_full_comp_unit (per_cu
, cu
->language
);
16458 target_cu
= per_cu
->cu
;
16460 else if (cu
->dies
== NULL
)
16462 /* We're loading full DIEs during partial symbol reading. */
16463 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
16464 load_full_comp_unit (cu
->per_cu
, language_minimal
);
16467 *ref_cu
= target_cu
;
16468 temp_die
.offset
= offset
;
16469 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
16472 /* Follow reference attribute ATTR of SRC_DIE.
16473 On entry *REF_CU is the CU of SRC_DIE.
16474 On exit *REF_CU is the CU of the result. */
16476 static struct die_info
*
16477 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
16478 struct dwarf2_cu
**ref_cu
)
16480 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16481 struct dwarf2_cu
*cu
= *ref_cu
;
16482 struct die_info
*die
;
16484 die
= follow_die_offset (offset
,
16485 (attr
->form
== DW_FORM_GNU_ref_alt
16486 || cu
->per_cu
->is_dwz
),
16489 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
16490 "at 0x%x [in module %s]"),
16491 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
16496 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
16497 Returned value is intended for DW_OP_call*. Returned
16498 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
16500 struct dwarf2_locexpr_baton
16501 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
16502 struct dwarf2_per_cu_data
*per_cu
,
16503 CORE_ADDR (*get_frame_pc
) (void *baton
),
16506 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
16507 struct dwarf2_cu
*cu
;
16508 struct die_info
*die
;
16509 struct attribute
*attr
;
16510 struct dwarf2_locexpr_baton retval
;
16512 dw2_setup (per_cu
->objfile
);
16514 if (per_cu
->cu
== NULL
)
16518 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
16520 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
16521 offset
.sect_off
, per_cu
->objfile
->name
);
16523 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16526 /* DWARF: "If there is no such attribute, then there is no effect.".
16527 DATA is ignored if SIZE is 0. */
16529 retval
.data
= NULL
;
16532 else if (attr_form_is_section_offset (attr
))
16534 struct dwarf2_loclist_baton loclist_baton
;
16535 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
16538 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
16540 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
16542 retval
.size
= size
;
16546 if (!attr_form_is_block (attr
))
16547 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
16548 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
16549 offset
.sect_off
, per_cu
->objfile
->name
);
16551 retval
.data
= DW_BLOCK (attr
)->data
;
16552 retval
.size
= DW_BLOCK (attr
)->size
;
16554 retval
.per_cu
= cu
->per_cu
;
16556 age_cached_comp_units ();
16561 /* Return the type of the DIE at DIE_OFFSET in the CU named by
16565 dwarf2_get_die_type (cu_offset die_offset
,
16566 struct dwarf2_per_cu_data
*per_cu
)
16568 sect_offset die_offset_sect
;
16570 dw2_setup (per_cu
->objfile
);
16572 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
16573 return get_die_type_at_offset (die_offset_sect
, per_cu
);
16576 /* Follow the signature attribute ATTR in SRC_DIE.
16577 On entry *REF_CU is the CU of SRC_DIE.
16578 On exit *REF_CU is the CU of the result. */
16580 static struct die_info
*
16581 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
16582 struct dwarf2_cu
**ref_cu
)
16584 struct objfile
*objfile
= (*ref_cu
)->objfile
;
16585 struct die_info temp_die
;
16586 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16587 struct dwarf2_cu
*sig_cu
;
16588 struct die_info
*die
;
16590 /* sig_type will be NULL if the signatured type is missing from
16592 if (sig_type
== NULL
)
16593 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16594 "at 0x%x [in module %s]"),
16595 src_die
->offset
.sect_off
, objfile
->name
);
16597 /* If necessary, add it to the queue and load its DIEs. */
16599 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
16600 read_signatured_type (sig_type
);
16602 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
16604 sig_cu
= sig_type
->per_cu
.cu
;
16605 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
16606 temp_die
.offset
= sig_type
->type_offset_in_section
;
16607 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
16608 temp_die
.offset
.sect_off
);
16615 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
16616 "from DIE at 0x%x [in module %s]"),
16617 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
16620 /* Given an offset of a signatured type, return its signatured_type. */
16622 static struct signatured_type
*
16623 lookup_signatured_type_at_offset (struct objfile
*objfile
,
16624 struct dwarf2_section_info
*section
,
16625 sect_offset offset
)
16627 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
16628 unsigned int length
, initial_length_size
;
16629 unsigned int sig_offset
;
16630 struct signatured_type find_entry
, *sig_type
;
16632 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
16633 sig_offset
= (initial_length_size
16635 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
16636 + 1 /*address_size*/);
16637 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
16638 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
16640 /* This is only used to lookup previously recorded types.
16641 If we didn't find it, it's our bug. */
16642 gdb_assert (sig_type
!= NULL
);
16643 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
16648 /* Load the DIEs associated with type unit PER_CU into memory. */
16651 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
16653 struct signatured_type
*sig_type
;
16655 /* Caller is responsible for ensuring type_unit_groups don't get here. */
16656 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
16658 /* We have the per_cu, but we need the signatured_type.
16659 Fortunately this is an easy translation. */
16660 gdb_assert (per_cu
->is_debug_types
);
16661 sig_type
= (struct signatured_type
*) per_cu
;
16663 gdb_assert (per_cu
->cu
== NULL
);
16665 read_signatured_type (sig_type
);
16667 gdb_assert (per_cu
->cu
!= NULL
);
16670 /* die_reader_func for read_signatured_type.
16671 This is identical to load_full_comp_unit_reader,
16672 but is kept separate for now. */
16675 read_signatured_type_reader (const struct die_reader_specs
*reader
,
16676 gdb_byte
*info_ptr
,
16677 struct die_info
*comp_unit_die
,
16681 struct dwarf2_cu
*cu
= reader
->cu
;
16683 gdb_assert (cu
->die_hash
== NULL
);
16685 htab_create_alloc_ex (cu
->header
.length
/ 12,
16689 &cu
->comp_unit_obstack
,
16690 hashtab_obstack_allocate
,
16691 dummy_obstack_deallocate
);
16694 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
16695 &info_ptr
, comp_unit_die
);
16696 cu
->dies
= comp_unit_die
;
16697 /* comp_unit_die is not stored in die_hash, no need. */
16699 /* We try not to read any attributes in this function, because not
16700 all CUs needed for references have been loaded yet, and symbol
16701 table processing isn't initialized. But we have to set the CU language,
16702 or we won't be able to build types correctly.
16703 Similarly, if we do not read the producer, we can not apply
16704 producer-specific interpretation. */
16705 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
16708 /* Read in a signatured type and build its CU and DIEs.
16709 If the type is a stub for the real type in a DWO file,
16710 read in the real type from the DWO file as well. */
16713 read_signatured_type (struct signatured_type
*sig_type
)
16715 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
16717 gdb_assert (per_cu
->is_debug_types
);
16718 gdb_assert (per_cu
->cu
== NULL
);
16720 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
16721 read_signatured_type_reader
, NULL
);
16724 /* Decode simple location descriptions.
16725 Given a pointer to a dwarf block that defines a location, compute
16726 the location and return the value.
16728 NOTE drow/2003-11-18: This function is called in two situations
16729 now: for the address of static or global variables (partial symbols
16730 only) and for offsets into structures which are expected to be
16731 (more or less) constant. The partial symbol case should go away,
16732 and only the constant case should remain. That will let this
16733 function complain more accurately. A few special modes are allowed
16734 without complaint for global variables (for instance, global
16735 register values and thread-local values).
16737 A location description containing no operations indicates that the
16738 object is optimized out. The return value is 0 for that case.
16739 FIXME drow/2003-11-16: No callers check for this case any more; soon all
16740 callers will only want a very basic result and this can become a
16743 Note that stack[0] is unused except as a default error return. */
16746 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
16748 struct objfile
*objfile
= cu
->objfile
;
16750 size_t size
= blk
->size
;
16751 gdb_byte
*data
= blk
->data
;
16752 CORE_ADDR stack
[64];
16754 unsigned int bytes_read
, unsnd
;
16760 stack
[++stacki
] = 0;
16799 stack
[++stacki
] = op
- DW_OP_lit0
;
16834 stack
[++stacki
] = op
- DW_OP_reg0
;
16836 dwarf2_complex_location_expr_complaint ();
16840 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
16842 stack
[++stacki
] = unsnd
;
16844 dwarf2_complex_location_expr_complaint ();
16848 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
16853 case DW_OP_const1u
:
16854 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
16858 case DW_OP_const1s
:
16859 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
16863 case DW_OP_const2u
:
16864 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
16868 case DW_OP_const2s
:
16869 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
16873 case DW_OP_const4u
:
16874 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
16878 case DW_OP_const4s
:
16879 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
16883 case DW_OP_const8u
:
16884 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
16889 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
16895 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
16900 stack
[stacki
+ 1] = stack
[stacki
];
16905 stack
[stacki
- 1] += stack
[stacki
];
16909 case DW_OP_plus_uconst
:
16910 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
16916 stack
[stacki
- 1] -= stack
[stacki
];
16921 /* If we're not the last op, then we definitely can't encode
16922 this using GDB's address_class enum. This is valid for partial
16923 global symbols, although the variable's address will be bogus
16926 dwarf2_complex_location_expr_complaint ();
16929 case DW_OP_GNU_push_tls_address
:
16930 /* The top of the stack has the offset from the beginning
16931 of the thread control block at which the variable is located. */
16932 /* Nothing should follow this operator, so the top of stack would
16934 /* This is valid for partial global symbols, but the variable's
16935 address will be bogus in the psymtab. Make it always at least
16936 non-zero to not look as a variable garbage collected by linker
16937 which have DW_OP_addr 0. */
16939 dwarf2_complex_location_expr_complaint ();
16943 case DW_OP_GNU_uninit
:
16946 case DW_OP_GNU_addr_index
:
16947 case DW_OP_GNU_const_index
:
16948 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
16955 const char *name
= get_DW_OP_name (op
);
16958 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
16961 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
16965 return (stack
[stacki
]);
16968 /* Enforce maximum stack depth of SIZE-1 to avoid writing
16969 outside of the allocated space. Also enforce minimum>0. */
16970 if (stacki
>= ARRAY_SIZE (stack
) - 1)
16972 complaint (&symfile_complaints
,
16973 _("location description stack overflow"));
16979 complaint (&symfile_complaints
,
16980 _("location description stack underflow"));
16984 return (stack
[stacki
]);
16987 /* memory allocation interface */
16989 static struct dwarf_block
*
16990 dwarf_alloc_block (struct dwarf2_cu
*cu
)
16992 struct dwarf_block
*blk
;
16994 blk
= (struct dwarf_block
*)
16995 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
16999 static struct die_info
*
17000 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
17002 struct die_info
*die
;
17003 size_t size
= sizeof (struct die_info
);
17006 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
17008 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
17009 memset (die
, 0, sizeof (struct die_info
));
17014 /* Macro support. */
17016 /* Return the full name of file number I in *LH's file name table.
17017 Use COMP_DIR as the name of the current directory of the
17018 compilation. The result is allocated using xmalloc; the caller is
17019 responsible for freeing it. */
17021 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
17023 /* Is the file number a valid index into the line header's file name
17024 table? Remember that file numbers start with one, not zero. */
17025 if (1 <= file
&& file
<= lh
->num_file_names
)
17027 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
17029 if (IS_ABSOLUTE_PATH (fe
->name
))
17030 return xstrdup (fe
->name
);
17038 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17044 dir_len
= strlen (dir
);
17045 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
17046 strcpy (full_name
, dir
);
17047 full_name
[dir_len
] = '/';
17048 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
17052 return xstrdup (fe
->name
);
17057 /* The compiler produced a bogus file number. We can at least
17058 record the macro definitions made in the file, even if we
17059 won't be able to find the file by name. */
17060 char fake_name
[80];
17062 sprintf (fake_name
, "<bad macro file number %d>", file
);
17064 complaint (&symfile_complaints
,
17065 _("bad file number in macro information (%d)"),
17068 return xstrdup (fake_name
);
17073 static struct macro_source_file
*
17074 macro_start_file (int file
, int line
,
17075 struct macro_source_file
*current_file
,
17076 const char *comp_dir
,
17077 struct line_header
*lh
, struct objfile
*objfile
)
17079 /* The full name of this source file. */
17080 char *full_name
= file_full_name (file
, lh
, comp_dir
);
17082 /* We don't create a macro table for this compilation unit
17083 at all until we actually get a filename. */
17084 if (! pending_macros
)
17085 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
17086 objfile
->per_bfd
->macro_cache
);
17088 if (! current_file
)
17090 /* If we have no current file, then this must be the start_file
17091 directive for the compilation unit's main source file. */
17092 current_file
= macro_set_main (pending_macros
, full_name
);
17093 macro_define_special (pending_macros
);
17096 current_file
= macro_include (current_file
, line
, full_name
);
17100 return current_file
;
17104 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
17105 followed by a null byte. */
17107 copy_string (const char *buf
, int len
)
17109 char *s
= xmalloc (len
+ 1);
17111 memcpy (s
, buf
, len
);
17117 static const char *
17118 consume_improper_spaces (const char *p
, const char *body
)
17122 complaint (&symfile_complaints
,
17123 _("macro definition contains spaces "
17124 "in formal argument list:\n`%s'"),
17136 parse_macro_definition (struct macro_source_file
*file
, int line
,
17141 /* The body string takes one of two forms. For object-like macro
17142 definitions, it should be:
17144 <macro name> " " <definition>
17146 For function-like macro definitions, it should be:
17148 <macro name> "() " <definition>
17150 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
17152 Spaces may appear only where explicitly indicated, and in the
17155 The Dwarf 2 spec says that an object-like macro's name is always
17156 followed by a space, but versions of GCC around March 2002 omit
17157 the space when the macro's definition is the empty string.
17159 The Dwarf 2 spec says that there should be no spaces between the
17160 formal arguments in a function-like macro's formal argument list,
17161 but versions of GCC around March 2002 include spaces after the
17165 /* Find the extent of the macro name. The macro name is terminated
17166 by either a space or null character (for an object-like macro) or
17167 an opening paren (for a function-like macro). */
17168 for (p
= body
; *p
; p
++)
17169 if (*p
== ' ' || *p
== '(')
17172 if (*p
== ' ' || *p
== '\0')
17174 /* It's an object-like macro. */
17175 int name_len
= p
- body
;
17176 char *name
= copy_string (body
, name_len
);
17177 const char *replacement
;
17180 replacement
= body
+ name_len
+ 1;
17183 dwarf2_macro_malformed_definition_complaint (body
);
17184 replacement
= body
+ name_len
;
17187 macro_define_object (file
, line
, name
, replacement
);
17191 else if (*p
== '(')
17193 /* It's a function-like macro. */
17194 char *name
= copy_string (body
, p
- body
);
17197 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
17201 p
= consume_improper_spaces (p
, body
);
17203 /* Parse the formal argument list. */
17204 while (*p
&& *p
!= ')')
17206 /* Find the extent of the current argument name. */
17207 const char *arg_start
= p
;
17209 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
17212 if (! *p
|| p
== arg_start
)
17213 dwarf2_macro_malformed_definition_complaint (body
);
17216 /* Make sure argv has room for the new argument. */
17217 if (argc
>= argv_size
)
17220 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
17223 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
17226 p
= consume_improper_spaces (p
, body
);
17228 /* Consume the comma, if present. */
17233 p
= consume_improper_spaces (p
, body
);
17242 /* Perfectly formed definition, no complaints. */
17243 macro_define_function (file
, line
, name
,
17244 argc
, (const char **) argv
,
17246 else if (*p
== '\0')
17248 /* Complain, but do define it. */
17249 dwarf2_macro_malformed_definition_complaint (body
);
17250 macro_define_function (file
, line
, name
,
17251 argc
, (const char **) argv
,
17255 /* Just complain. */
17256 dwarf2_macro_malformed_definition_complaint (body
);
17259 /* Just complain. */
17260 dwarf2_macro_malformed_definition_complaint (body
);
17266 for (i
= 0; i
< argc
; i
++)
17272 dwarf2_macro_malformed_definition_complaint (body
);
17275 /* Skip some bytes from BYTES according to the form given in FORM.
17276 Returns the new pointer. */
17279 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
17280 enum dwarf_form form
,
17281 unsigned int offset_size
,
17282 struct dwarf2_section_info
*section
)
17284 unsigned int bytes_read
;
17288 case DW_FORM_data1
:
17293 case DW_FORM_data2
:
17297 case DW_FORM_data4
:
17301 case DW_FORM_data8
:
17305 case DW_FORM_string
:
17306 read_direct_string (abfd
, bytes
, &bytes_read
);
17307 bytes
+= bytes_read
;
17310 case DW_FORM_sec_offset
:
17312 case DW_FORM_GNU_strp_alt
:
17313 bytes
+= offset_size
;
17316 case DW_FORM_block
:
17317 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
17318 bytes
+= bytes_read
;
17321 case DW_FORM_block1
:
17322 bytes
+= 1 + read_1_byte (abfd
, bytes
);
17324 case DW_FORM_block2
:
17325 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
17327 case DW_FORM_block4
:
17328 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
17331 case DW_FORM_sdata
:
17332 case DW_FORM_udata
:
17333 case DW_FORM_GNU_addr_index
:
17334 case DW_FORM_GNU_str_index
:
17335 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
17338 dwarf2_section_buffer_overflow_complaint (section
);
17346 complaint (&symfile_complaints
,
17347 _("invalid form 0x%x in `%s'"),
17349 section
->asection
->name
);
17357 /* A helper for dwarf_decode_macros that handles skipping an unknown
17358 opcode. Returns an updated pointer to the macro data buffer; or,
17359 on error, issues a complaint and returns NULL. */
17362 skip_unknown_opcode (unsigned int opcode
,
17363 gdb_byte
**opcode_definitions
,
17364 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17366 unsigned int offset_size
,
17367 struct dwarf2_section_info
*section
)
17369 unsigned int bytes_read
, i
;
17373 if (opcode_definitions
[opcode
] == NULL
)
17375 complaint (&symfile_complaints
,
17376 _("unrecognized DW_MACFINO opcode 0x%x"),
17381 defn
= opcode_definitions
[opcode
];
17382 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
17383 defn
+= bytes_read
;
17385 for (i
= 0; i
< arg
; ++i
)
17387 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
17389 if (mac_ptr
== NULL
)
17391 /* skip_form_bytes already issued the complaint. */
17399 /* A helper function which parses the header of a macro section.
17400 If the macro section is the extended (for now called "GNU") type,
17401 then this updates *OFFSET_SIZE. Returns a pointer to just after
17402 the header, or issues a complaint and returns NULL on error. */
17405 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
17408 unsigned int *offset_size
,
17409 int section_is_gnu
)
17411 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
17413 if (section_is_gnu
)
17415 unsigned int version
, flags
;
17417 version
= read_2_bytes (abfd
, mac_ptr
);
17420 complaint (&symfile_complaints
,
17421 _("unrecognized version `%d' in .debug_macro section"),
17427 flags
= read_1_byte (abfd
, mac_ptr
);
17429 *offset_size
= (flags
& 1) ? 8 : 4;
17431 if ((flags
& 2) != 0)
17432 /* We don't need the line table offset. */
17433 mac_ptr
+= *offset_size
;
17435 /* Vendor opcode descriptions. */
17436 if ((flags
& 4) != 0)
17438 unsigned int i
, count
;
17440 count
= read_1_byte (abfd
, mac_ptr
);
17442 for (i
= 0; i
< count
; ++i
)
17444 unsigned int opcode
, bytes_read
;
17447 opcode
= read_1_byte (abfd
, mac_ptr
);
17449 opcode_definitions
[opcode
] = mac_ptr
;
17450 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17451 mac_ptr
+= bytes_read
;
17460 /* A helper for dwarf_decode_macros that handles the GNU extensions,
17461 including DW_MACRO_GNU_transparent_include. */
17464 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17465 struct macro_source_file
*current_file
,
17466 struct line_header
*lh
, char *comp_dir
,
17467 struct dwarf2_section_info
*section
,
17468 int section_is_gnu
, int section_is_dwz
,
17469 unsigned int offset_size
,
17470 struct objfile
*objfile
,
17471 htab_t include_hash
)
17473 enum dwarf_macro_record_type macinfo_type
;
17474 int at_commandline
;
17475 gdb_byte
*opcode_definitions
[256];
17477 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17478 &offset_size
, section_is_gnu
);
17479 if (mac_ptr
== NULL
)
17481 /* We already issued a complaint. */
17485 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
17486 GDB is still reading the definitions from command line. First
17487 DW_MACINFO_start_file will need to be ignored as it was already executed
17488 to create CURRENT_FILE for the main source holding also the command line
17489 definitions. On first met DW_MACINFO_start_file this flag is reset to
17490 normally execute all the remaining DW_MACINFO_start_file macinfos. */
17492 at_commandline
= 1;
17496 /* Do we at least have room for a macinfo type byte? */
17497 if (mac_ptr
>= mac_end
)
17499 dwarf2_section_buffer_overflow_complaint (section
);
17503 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17506 /* Note that we rely on the fact that the corresponding GNU and
17507 DWARF constants are the same. */
17508 switch (macinfo_type
)
17510 /* A zero macinfo type indicates the end of the macro
17515 case DW_MACRO_GNU_define
:
17516 case DW_MACRO_GNU_undef
:
17517 case DW_MACRO_GNU_define_indirect
:
17518 case DW_MACRO_GNU_undef_indirect
:
17519 case DW_MACRO_GNU_define_indirect_alt
:
17520 case DW_MACRO_GNU_undef_indirect_alt
:
17522 unsigned int bytes_read
;
17527 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17528 mac_ptr
+= bytes_read
;
17530 if (macinfo_type
== DW_MACRO_GNU_define
17531 || macinfo_type
== DW_MACRO_GNU_undef
)
17533 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17534 mac_ptr
+= bytes_read
;
17538 LONGEST str_offset
;
17540 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17541 mac_ptr
+= offset_size
;
17543 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
17544 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
17547 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17549 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
17552 body
= read_indirect_string_at_offset (abfd
, str_offset
);
17555 is_define
= (macinfo_type
== DW_MACRO_GNU_define
17556 || macinfo_type
== DW_MACRO_GNU_define_indirect
17557 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
17558 if (! current_file
)
17560 /* DWARF violation as no main source is present. */
17561 complaint (&symfile_complaints
,
17562 _("debug info with no main source gives macro %s "
17564 is_define
? _("definition") : _("undefinition"),
17568 if ((line
== 0 && !at_commandline
)
17569 || (line
!= 0 && at_commandline
))
17570 complaint (&symfile_complaints
,
17571 _("debug info gives %s macro %s with %s line %d: %s"),
17572 at_commandline
? _("command-line") : _("in-file"),
17573 is_define
? _("definition") : _("undefinition"),
17574 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
17577 parse_macro_definition (current_file
, line
, body
);
17580 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
17581 || macinfo_type
== DW_MACRO_GNU_undef_indirect
17582 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
17583 macro_undef (current_file
, line
, body
);
17588 case DW_MACRO_GNU_start_file
:
17590 unsigned int bytes_read
;
17593 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17594 mac_ptr
+= bytes_read
;
17595 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17596 mac_ptr
+= bytes_read
;
17598 if ((line
== 0 && !at_commandline
)
17599 || (line
!= 0 && at_commandline
))
17600 complaint (&symfile_complaints
,
17601 _("debug info gives source %d included "
17602 "from %s at %s line %d"),
17603 file
, at_commandline
? _("command-line") : _("file"),
17604 line
== 0 ? _("zero") : _("non-zero"), line
);
17606 if (at_commandline
)
17608 /* This DW_MACRO_GNU_start_file was executed in the
17610 at_commandline
= 0;
17613 current_file
= macro_start_file (file
, line
,
17614 current_file
, comp_dir
,
17619 case DW_MACRO_GNU_end_file
:
17620 if (! current_file
)
17621 complaint (&symfile_complaints
,
17622 _("macro debug info has an unmatched "
17623 "`close_file' directive"));
17626 current_file
= current_file
->included_by
;
17627 if (! current_file
)
17629 enum dwarf_macro_record_type next_type
;
17631 /* GCC circa March 2002 doesn't produce the zero
17632 type byte marking the end of the compilation
17633 unit. Complain if it's not there, but exit no
17636 /* Do we at least have room for a macinfo type byte? */
17637 if (mac_ptr
>= mac_end
)
17639 dwarf2_section_buffer_overflow_complaint (section
);
17643 /* We don't increment mac_ptr here, so this is just
17645 next_type
= read_1_byte (abfd
, mac_ptr
);
17646 if (next_type
!= 0)
17647 complaint (&symfile_complaints
,
17648 _("no terminating 0-type entry for "
17649 "macros in `.debug_macinfo' section"));
17656 case DW_MACRO_GNU_transparent_include
:
17657 case DW_MACRO_GNU_transparent_include_alt
:
17661 bfd
*include_bfd
= abfd
;
17662 struct dwarf2_section_info
*include_section
= section
;
17663 struct dwarf2_section_info alt_section
;
17664 gdb_byte
*include_mac_end
= mac_end
;
17665 int is_dwz
= section_is_dwz
;
17666 gdb_byte
*new_mac_ptr
;
17668 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17669 mac_ptr
+= offset_size
;
17671 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
17673 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17675 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
17678 include_bfd
= dwz
->macro
.asection
->owner
;
17679 include_section
= &dwz
->macro
;
17680 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
17684 new_mac_ptr
= include_section
->buffer
+ offset
;
17685 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
17689 /* This has actually happened; see
17690 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
17691 complaint (&symfile_complaints
,
17692 _("recursive DW_MACRO_GNU_transparent_include in "
17693 ".debug_macro section"));
17697 *slot
= new_mac_ptr
;
17699 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
17700 include_mac_end
, current_file
,
17702 section
, section_is_gnu
, is_dwz
,
17703 offset_size
, objfile
, include_hash
);
17705 htab_remove_elt (include_hash
, new_mac_ptr
);
17710 case DW_MACINFO_vendor_ext
:
17711 if (!section_is_gnu
)
17713 unsigned int bytes_read
;
17716 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17717 mac_ptr
+= bytes_read
;
17718 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17719 mac_ptr
+= bytes_read
;
17721 /* We don't recognize any vendor extensions. */
17727 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17728 mac_ptr
, mac_end
, abfd
, offset_size
,
17730 if (mac_ptr
== NULL
)
17734 } while (macinfo_type
!= 0);
17738 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
17739 char *comp_dir
, int section_is_gnu
)
17741 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17742 struct line_header
*lh
= cu
->line_header
;
17744 gdb_byte
*mac_ptr
, *mac_end
;
17745 struct macro_source_file
*current_file
= 0;
17746 enum dwarf_macro_record_type macinfo_type
;
17747 unsigned int offset_size
= cu
->header
.offset_size
;
17748 gdb_byte
*opcode_definitions
[256];
17749 struct cleanup
*cleanup
;
17750 htab_t include_hash
;
17752 struct dwarf2_section_info
*section
;
17753 const char *section_name
;
17755 if (cu
->dwo_unit
!= NULL
)
17757 if (section_is_gnu
)
17759 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
17760 section_name
= ".debug_macro.dwo";
17764 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
17765 section_name
= ".debug_macinfo.dwo";
17770 if (section_is_gnu
)
17772 section
= &dwarf2_per_objfile
->macro
;
17773 section_name
= ".debug_macro";
17777 section
= &dwarf2_per_objfile
->macinfo
;
17778 section_name
= ".debug_macinfo";
17782 dwarf2_read_section (objfile
, section
);
17783 if (section
->buffer
== NULL
)
17785 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
17788 abfd
= section
->asection
->owner
;
17790 /* First pass: Find the name of the base filename.
17791 This filename is needed in order to process all macros whose definition
17792 (or undefinition) comes from the command line. These macros are defined
17793 before the first DW_MACINFO_start_file entry, and yet still need to be
17794 associated to the base file.
17796 To determine the base file name, we scan the macro definitions until we
17797 reach the first DW_MACINFO_start_file entry. We then initialize
17798 CURRENT_FILE accordingly so that any macro definition found before the
17799 first DW_MACINFO_start_file can still be associated to the base file. */
17801 mac_ptr
= section
->buffer
+ offset
;
17802 mac_end
= section
->buffer
+ section
->size
;
17804 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17805 &offset_size
, section_is_gnu
);
17806 if (mac_ptr
== NULL
)
17808 /* We already issued a complaint. */
17814 /* Do we at least have room for a macinfo type byte? */
17815 if (mac_ptr
>= mac_end
)
17817 /* Complaint is printed during the second pass as GDB will probably
17818 stop the first pass earlier upon finding
17819 DW_MACINFO_start_file. */
17823 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17826 /* Note that we rely on the fact that the corresponding GNU and
17827 DWARF constants are the same. */
17828 switch (macinfo_type
)
17830 /* A zero macinfo type indicates the end of the macro
17835 case DW_MACRO_GNU_define
:
17836 case DW_MACRO_GNU_undef
:
17837 /* Only skip the data by MAC_PTR. */
17839 unsigned int bytes_read
;
17841 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17842 mac_ptr
+= bytes_read
;
17843 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17844 mac_ptr
+= bytes_read
;
17848 case DW_MACRO_GNU_start_file
:
17850 unsigned int bytes_read
;
17853 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17854 mac_ptr
+= bytes_read
;
17855 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17856 mac_ptr
+= bytes_read
;
17858 current_file
= macro_start_file (file
, line
, current_file
,
17859 comp_dir
, lh
, objfile
);
17863 case DW_MACRO_GNU_end_file
:
17864 /* No data to skip by MAC_PTR. */
17867 case DW_MACRO_GNU_define_indirect
:
17868 case DW_MACRO_GNU_undef_indirect
:
17869 case DW_MACRO_GNU_define_indirect_alt
:
17870 case DW_MACRO_GNU_undef_indirect_alt
:
17872 unsigned int bytes_read
;
17874 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17875 mac_ptr
+= bytes_read
;
17876 mac_ptr
+= offset_size
;
17880 case DW_MACRO_GNU_transparent_include
:
17881 case DW_MACRO_GNU_transparent_include_alt
:
17882 /* Note that, according to the spec, a transparent include
17883 chain cannot call DW_MACRO_GNU_start_file. So, we can just
17884 skip this opcode. */
17885 mac_ptr
+= offset_size
;
17888 case DW_MACINFO_vendor_ext
:
17889 /* Only skip the data by MAC_PTR. */
17890 if (!section_is_gnu
)
17892 unsigned int bytes_read
;
17894 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17895 mac_ptr
+= bytes_read
;
17896 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17897 mac_ptr
+= bytes_read
;
17902 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17903 mac_ptr
, mac_end
, abfd
, offset_size
,
17905 if (mac_ptr
== NULL
)
17909 } while (macinfo_type
!= 0 && current_file
== NULL
);
17911 /* Second pass: Process all entries.
17913 Use the AT_COMMAND_LINE flag to determine whether we are still processing
17914 command-line macro definitions/undefinitions. This flag is unset when we
17915 reach the first DW_MACINFO_start_file entry. */
17917 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
17918 NULL
, xcalloc
, xfree
);
17919 cleanup
= make_cleanup_htab_delete (include_hash
);
17920 mac_ptr
= section
->buffer
+ offset
;
17921 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17923 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
17924 current_file
, lh
, comp_dir
, section
,
17926 offset_size
, objfile
, include_hash
);
17927 do_cleanups (cleanup
);
17930 /* Check if the attribute's form is a DW_FORM_block*
17931 if so return true else false. */
17934 attr_form_is_block (struct attribute
*attr
)
17936 return (attr
== NULL
? 0 :
17937 attr
->form
== DW_FORM_block1
17938 || attr
->form
== DW_FORM_block2
17939 || attr
->form
== DW_FORM_block4
17940 || attr
->form
== DW_FORM_block
17941 || attr
->form
== DW_FORM_exprloc
);
17944 /* Return non-zero if ATTR's value is a section offset --- classes
17945 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
17946 You may use DW_UNSND (attr) to retrieve such offsets.
17948 Section 7.5.4, "Attribute Encodings", explains that no attribute
17949 may have a value that belongs to more than one of these classes; it
17950 would be ambiguous if we did, because we use the same forms for all
17954 attr_form_is_section_offset (struct attribute
*attr
)
17956 return (attr
->form
== DW_FORM_data4
17957 || attr
->form
== DW_FORM_data8
17958 || attr
->form
== DW_FORM_sec_offset
);
17961 /* Return non-zero if ATTR's value falls in the 'constant' class, or
17962 zero otherwise. When this function returns true, you can apply
17963 dwarf2_get_attr_constant_value to it.
17965 However, note that for some attributes you must check
17966 attr_form_is_section_offset before using this test. DW_FORM_data4
17967 and DW_FORM_data8 are members of both the constant class, and of
17968 the classes that contain offsets into other debug sections
17969 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
17970 that, if an attribute's can be either a constant or one of the
17971 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
17972 taken as section offsets, not constants. */
17975 attr_form_is_constant (struct attribute
*attr
)
17977 switch (attr
->form
)
17979 case DW_FORM_sdata
:
17980 case DW_FORM_udata
:
17981 case DW_FORM_data1
:
17982 case DW_FORM_data2
:
17983 case DW_FORM_data4
:
17984 case DW_FORM_data8
:
17991 /* Return the .debug_loc section to use for CU.
17992 For DWO files use .debug_loc.dwo. */
17994 static struct dwarf2_section_info
*
17995 cu_debug_loc_section (struct dwarf2_cu
*cu
)
17998 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
17999 return &dwarf2_per_objfile
->loc
;
18002 /* A helper function that fills in a dwarf2_loclist_baton. */
18005 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
18006 struct dwarf2_loclist_baton
*baton
,
18007 struct attribute
*attr
)
18009 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18011 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
18013 baton
->per_cu
= cu
->per_cu
;
18014 gdb_assert (baton
->per_cu
);
18015 /* We don't know how long the location list is, but make sure we
18016 don't run off the edge of the section. */
18017 baton
->size
= section
->size
- DW_UNSND (attr
);
18018 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
18019 baton
->base_address
= cu
->base_address
;
18020 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
18024 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
18025 struct dwarf2_cu
*cu
)
18027 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18028 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18030 if (attr_form_is_section_offset (attr
)
18031 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
18032 the section. If so, fall through to the complaint in the
18034 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
18036 struct dwarf2_loclist_baton
*baton
;
18038 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18039 sizeof (struct dwarf2_loclist_baton
));
18041 fill_in_loclist_baton (cu
, baton
, attr
);
18043 if (cu
->base_known
== 0)
18044 complaint (&symfile_complaints
,
18045 _("Location list used without "
18046 "specifying the CU base address."));
18048 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
18049 SYMBOL_LOCATION_BATON (sym
) = baton
;
18053 struct dwarf2_locexpr_baton
*baton
;
18055 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18056 sizeof (struct dwarf2_locexpr_baton
));
18057 baton
->per_cu
= cu
->per_cu
;
18058 gdb_assert (baton
->per_cu
);
18060 if (attr_form_is_block (attr
))
18062 /* Note that we're just copying the block's data pointer
18063 here, not the actual data. We're still pointing into the
18064 info_buffer for SYM's objfile; right now we never release
18065 that buffer, but when we do clean up properly this may
18067 baton
->size
= DW_BLOCK (attr
)->size
;
18068 baton
->data
= DW_BLOCK (attr
)->data
;
18072 dwarf2_invalid_attrib_class_complaint ("location description",
18073 SYMBOL_NATURAL_NAME (sym
));
18077 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
18078 SYMBOL_LOCATION_BATON (sym
) = baton
;
18082 /* Return the OBJFILE associated with the compilation unit CU. If CU
18083 came from a separate debuginfo file, then the master objfile is
18087 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
18089 struct objfile
*objfile
= per_cu
->objfile
;
18091 /* Return the master objfile, so that we can report and look up the
18092 correct file containing this variable. */
18093 if (objfile
->separate_debug_objfile_backlink
)
18094 objfile
= objfile
->separate_debug_objfile_backlink
;
18099 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
18100 (CU_HEADERP is unused in such case) or prepare a temporary copy at
18101 CU_HEADERP first. */
18103 static const struct comp_unit_head
*
18104 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
18105 struct dwarf2_per_cu_data
*per_cu
)
18107 gdb_byte
*info_ptr
;
18110 return &per_cu
->cu
->header
;
18112 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
18114 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
18115 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
18120 /* Return the address size given in the compilation unit header for CU. */
18123 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
18125 struct comp_unit_head cu_header_local
;
18126 const struct comp_unit_head
*cu_headerp
;
18128 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18130 return cu_headerp
->addr_size
;
18133 /* Return the offset size given in the compilation unit header for CU. */
18136 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
18138 struct comp_unit_head cu_header_local
;
18139 const struct comp_unit_head
*cu_headerp
;
18141 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18143 return cu_headerp
->offset_size
;
18146 /* See its dwarf2loc.h declaration. */
18149 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
18151 struct comp_unit_head cu_header_local
;
18152 const struct comp_unit_head
*cu_headerp
;
18154 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18156 if (cu_headerp
->version
== 2)
18157 return cu_headerp
->addr_size
;
18159 return cu_headerp
->offset_size
;
18162 /* Return the text offset of the CU. The returned offset comes from
18163 this CU's objfile. If this objfile came from a separate debuginfo
18164 file, then the offset may be different from the corresponding
18165 offset in the parent objfile. */
18168 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
18170 struct objfile
*objfile
= per_cu
->objfile
;
18172 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18175 /* Locate the .debug_info compilation unit from CU's objfile which contains
18176 the DIE at OFFSET. Raises an error on failure. */
18178 static struct dwarf2_per_cu_data
*
18179 dwarf2_find_containing_comp_unit (sect_offset offset
,
18180 unsigned int offset_in_dwz
,
18181 struct objfile
*objfile
)
18183 struct dwarf2_per_cu_data
*this_cu
;
18185 const sect_offset
*cu_off
;
18188 high
= dwarf2_per_objfile
->n_comp_units
- 1;
18191 struct dwarf2_per_cu_data
*mid_cu
;
18192 int mid
= low
+ (high
- low
) / 2;
18194 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
18195 cu_off
= &mid_cu
->offset
;
18196 if (mid_cu
->is_dwz
> offset_in_dwz
18197 || (mid_cu
->is_dwz
== offset_in_dwz
18198 && cu_off
->sect_off
>= offset
.sect_off
))
18203 gdb_assert (low
== high
);
18204 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
18205 cu_off
= &this_cu
->offset
;
18206 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
18208 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
18209 error (_("Dwarf Error: could not find partial DIE containing "
18210 "offset 0x%lx [in module %s]"),
18211 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
18213 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
18214 <= offset
.sect_off
);
18215 return dwarf2_per_objfile
->all_comp_units
[low
-1];
18219 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
18220 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
18221 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
18222 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
18223 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
18228 /* Initialize dwarf2_cu CU, owned by PER_CU. */
18231 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
18233 memset (cu
, 0, sizeof (*cu
));
18235 cu
->per_cu
= per_cu
;
18236 cu
->objfile
= per_cu
->objfile
;
18237 obstack_init (&cu
->comp_unit_obstack
);
18240 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
18243 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
18244 enum language pretend_language
)
18246 struct attribute
*attr
;
18248 /* Set the language we're debugging. */
18249 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
18251 set_cu_language (DW_UNSND (attr
), cu
);
18254 cu
->language
= pretend_language
;
18255 cu
->language_defn
= language_def (cu
->language
);
18258 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
18260 cu
->producer
= DW_STRING (attr
);
18263 /* Release one cached compilation unit, CU. We unlink it from the tree
18264 of compilation units, but we don't remove it from the read_in_chain;
18265 the caller is responsible for that.
18266 NOTE: DATA is a void * because this function is also used as a
18267 cleanup routine. */
18270 free_heap_comp_unit (void *data
)
18272 struct dwarf2_cu
*cu
= data
;
18274 gdb_assert (cu
->per_cu
!= NULL
);
18275 cu
->per_cu
->cu
= NULL
;
18278 obstack_free (&cu
->comp_unit_obstack
, NULL
);
18283 /* This cleanup function is passed the address of a dwarf2_cu on the stack
18284 when we're finished with it. We can't free the pointer itself, but be
18285 sure to unlink it from the cache. Also release any associated storage. */
18288 free_stack_comp_unit (void *data
)
18290 struct dwarf2_cu
*cu
= data
;
18292 gdb_assert (cu
->per_cu
!= NULL
);
18293 cu
->per_cu
->cu
= NULL
;
18296 obstack_free (&cu
->comp_unit_obstack
, NULL
);
18297 cu
->partial_dies
= NULL
;
18300 /* Free all cached compilation units. */
18303 free_cached_comp_units (void *data
)
18305 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18307 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18308 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18309 while (per_cu
!= NULL
)
18311 struct dwarf2_per_cu_data
*next_cu
;
18313 next_cu
= per_cu
->cu
->read_in_chain
;
18315 free_heap_comp_unit (per_cu
->cu
);
18316 *last_chain
= next_cu
;
18322 /* Increase the age counter on each cached compilation unit, and free
18323 any that are too old. */
18326 age_cached_comp_units (void)
18328 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18330 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
18331 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18332 while (per_cu
!= NULL
)
18334 per_cu
->cu
->last_used
++;
18335 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
18336 dwarf2_mark (per_cu
->cu
);
18337 per_cu
= per_cu
->cu
->read_in_chain
;
18340 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18341 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18342 while (per_cu
!= NULL
)
18344 struct dwarf2_per_cu_data
*next_cu
;
18346 next_cu
= per_cu
->cu
->read_in_chain
;
18348 if (!per_cu
->cu
->mark
)
18350 free_heap_comp_unit (per_cu
->cu
);
18351 *last_chain
= next_cu
;
18354 last_chain
= &per_cu
->cu
->read_in_chain
;
18360 /* Remove a single compilation unit from the cache. */
18363 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
18365 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18367 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18368 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18369 while (per_cu
!= NULL
)
18371 struct dwarf2_per_cu_data
*next_cu
;
18373 next_cu
= per_cu
->cu
->read_in_chain
;
18375 if (per_cu
== target_per_cu
)
18377 free_heap_comp_unit (per_cu
->cu
);
18379 *last_chain
= next_cu
;
18383 last_chain
= &per_cu
->cu
->read_in_chain
;
18389 /* Release all extra memory associated with OBJFILE. */
18392 dwarf2_free_objfile (struct objfile
*objfile
)
18394 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18396 if (dwarf2_per_objfile
== NULL
)
18399 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
18400 free_cached_comp_units (NULL
);
18402 if (dwarf2_per_objfile
->quick_file_names_table
)
18403 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
18405 /* Everything else should be on the objfile obstack. */
18408 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
18409 We store these in a hash table separate from the DIEs, and preserve them
18410 when the DIEs are flushed out of cache.
18412 The CU "per_cu" pointer is needed because offset alone is not enough to
18413 uniquely identify the type. A file may have multiple .debug_types sections,
18414 or the type may come from a DWO file. We have to use something in
18415 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
18416 routine, get_die_type_at_offset, from outside this file, and thus won't
18417 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
18420 struct dwarf2_per_cu_offset_and_type
18422 const struct dwarf2_per_cu_data
*per_cu
;
18423 sect_offset offset
;
18427 /* Hash function for a dwarf2_per_cu_offset_and_type. */
18430 per_cu_offset_and_type_hash (const void *item
)
18432 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
18434 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
18437 /* Equality function for a dwarf2_per_cu_offset_and_type. */
18440 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
18442 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
18443 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
18445 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
18446 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
18449 /* Set the type associated with DIE to TYPE. Save it in CU's hash
18450 table if necessary. For convenience, return TYPE.
18452 The DIEs reading must have careful ordering to:
18453 * Not cause infite loops trying to read in DIEs as a prerequisite for
18454 reading current DIE.
18455 * Not trying to dereference contents of still incompletely read in types
18456 while reading in other DIEs.
18457 * Enable referencing still incompletely read in types just by a pointer to
18458 the type without accessing its fields.
18460 Therefore caller should follow these rules:
18461 * Try to fetch any prerequisite types we may need to build this DIE type
18462 before building the type and calling set_die_type.
18463 * After building type call set_die_type for current DIE as soon as
18464 possible before fetching more types to complete the current type.
18465 * Make the type as complete as possible before fetching more types. */
18467 static struct type
*
18468 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18470 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
18471 struct objfile
*objfile
= cu
->objfile
;
18473 /* For Ada types, make sure that the gnat-specific data is always
18474 initialized (if not already set). There are a few types where
18475 we should not be doing so, because the type-specific area is
18476 already used to hold some other piece of info (eg: TYPE_CODE_FLT
18477 where the type-specific area is used to store the floatformat).
18478 But this is not a problem, because the gnat-specific information
18479 is actually not needed for these types. */
18480 if (need_gnat_info (cu
)
18481 && TYPE_CODE (type
) != TYPE_CODE_FUNC
18482 && TYPE_CODE (type
) != TYPE_CODE_FLT
18483 && !HAVE_GNAT_AUX_INFO (type
))
18484 INIT_GNAT_SPECIFIC (type
);
18486 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18488 dwarf2_per_objfile
->die_type_hash
=
18489 htab_create_alloc_ex (127,
18490 per_cu_offset_and_type_hash
,
18491 per_cu_offset_and_type_eq
,
18493 &objfile
->objfile_obstack
,
18494 hashtab_obstack_allocate
,
18495 dummy_obstack_deallocate
);
18498 ofs
.per_cu
= cu
->per_cu
;
18499 ofs
.offset
= die
->offset
;
18501 slot
= (struct dwarf2_per_cu_offset_and_type
**)
18502 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
18504 complaint (&symfile_complaints
,
18505 _("A problem internal to GDB: DIE 0x%x has type already set"),
18506 die
->offset
.sect_off
);
18507 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
18512 /* Look up the type for the die at OFFSET in the appropriate type_hash
18513 table, or return NULL if the die does not have a saved type. */
18515 static struct type
*
18516 get_die_type_at_offset (sect_offset offset
,
18517 struct dwarf2_per_cu_data
*per_cu
)
18519 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
18521 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18524 ofs
.per_cu
= per_cu
;
18525 ofs
.offset
= offset
;
18526 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
18533 /* Look up the type for DIE in the appropriate type_hash table,
18534 or return NULL if DIE does not have a saved type. */
18536 static struct type
*
18537 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18539 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
18542 /* Add a dependence relationship from CU to REF_PER_CU. */
18545 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
18546 struct dwarf2_per_cu_data
*ref_per_cu
)
18550 if (cu
->dependencies
== NULL
)
18552 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
18553 NULL
, &cu
->comp_unit_obstack
,
18554 hashtab_obstack_allocate
,
18555 dummy_obstack_deallocate
);
18557 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
18559 *slot
= ref_per_cu
;
18562 /* Subroutine of dwarf2_mark to pass to htab_traverse.
18563 Set the mark field in every compilation unit in the
18564 cache that we must keep because we are keeping CU. */
18567 dwarf2_mark_helper (void **slot
, void *data
)
18569 struct dwarf2_per_cu_data
*per_cu
;
18571 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
18573 /* cu->dependencies references may not yet have been ever read if QUIT aborts
18574 reading of the chain. As such dependencies remain valid it is not much
18575 useful to track and undo them during QUIT cleanups. */
18576 if (per_cu
->cu
== NULL
)
18579 if (per_cu
->cu
->mark
)
18581 per_cu
->cu
->mark
= 1;
18583 if (per_cu
->cu
->dependencies
!= NULL
)
18584 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18589 /* Set the mark field in CU and in every other compilation unit in the
18590 cache that we must keep because we are keeping CU. */
18593 dwarf2_mark (struct dwarf2_cu
*cu
)
18598 if (cu
->dependencies
!= NULL
)
18599 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18603 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
18607 per_cu
->cu
->mark
= 0;
18608 per_cu
= per_cu
->cu
->read_in_chain
;
18612 /* Trivial hash function for partial_die_info: the hash value of a DIE
18613 is its offset in .debug_info for this objfile. */
18616 partial_die_hash (const void *item
)
18618 const struct partial_die_info
*part_die
= item
;
18620 return part_die
->offset
.sect_off
;
18623 /* Trivial comparison function for partial_die_info structures: two DIEs
18624 are equal if they have the same offset. */
18627 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
18629 const struct partial_die_info
*part_die_lhs
= item_lhs
;
18630 const struct partial_die_info
*part_die_rhs
= item_rhs
;
18632 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
18635 static struct cmd_list_element
*set_dwarf2_cmdlist
;
18636 static struct cmd_list_element
*show_dwarf2_cmdlist
;
18639 set_dwarf2_cmd (char *args
, int from_tty
)
18641 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
18645 show_dwarf2_cmd (char *args
, int from_tty
)
18647 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
18650 /* Free data associated with OBJFILE, if necessary. */
18653 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
18655 struct dwarf2_per_objfile
*data
= d
;
18658 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
18659 VEC_free (dwarf2_per_cu_ptr
,
18660 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
18662 VEC_free (dwarf2_section_info_def
, data
->types
);
18664 if (data
->dwo_files
)
18665 free_dwo_files (data
->dwo_files
, objfile
);
18667 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
18668 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
18672 /* The "save gdb-index" command. */
18674 /* The contents of the hash table we create when building the string
18676 struct strtab_entry
18678 offset_type offset
;
18682 /* Hash function for a strtab_entry.
18684 Function is used only during write_hash_table so no index format backward
18685 compatibility is needed. */
18688 hash_strtab_entry (const void *e
)
18690 const struct strtab_entry
*entry
= e
;
18691 return mapped_index_string_hash (INT_MAX
, entry
->str
);
18694 /* Equality function for a strtab_entry. */
18697 eq_strtab_entry (const void *a
, const void *b
)
18699 const struct strtab_entry
*ea
= a
;
18700 const struct strtab_entry
*eb
= b
;
18701 return !strcmp (ea
->str
, eb
->str
);
18704 /* Create a strtab_entry hash table. */
18707 create_strtab (void)
18709 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
18710 xfree
, xcalloc
, xfree
);
18713 /* Add a string to the constant pool. Return the string's offset in
18717 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
18720 struct strtab_entry entry
;
18721 struct strtab_entry
*result
;
18724 slot
= htab_find_slot (table
, &entry
, INSERT
);
18729 result
= XNEW (struct strtab_entry
);
18730 result
->offset
= obstack_object_size (cpool
);
18732 obstack_grow_str0 (cpool
, str
);
18735 return result
->offset
;
18738 /* An entry in the symbol table. */
18739 struct symtab_index_entry
18741 /* The name of the symbol. */
18743 /* The offset of the name in the constant pool. */
18744 offset_type index_offset
;
18745 /* A sorted vector of the indices of all the CUs that hold an object
18747 VEC (offset_type
) *cu_indices
;
18750 /* The symbol table. This is a power-of-2-sized hash table. */
18751 struct mapped_symtab
18753 offset_type n_elements
;
18755 struct symtab_index_entry
**data
;
18758 /* Hash function for a symtab_index_entry. */
18761 hash_symtab_entry (const void *e
)
18763 const struct symtab_index_entry
*entry
= e
;
18764 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
18765 sizeof (offset_type
) * VEC_length (offset_type
,
18766 entry
->cu_indices
),
18770 /* Equality function for a symtab_index_entry. */
18773 eq_symtab_entry (const void *a
, const void *b
)
18775 const struct symtab_index_entry
*ea
= a
;
18776 const struct symtab_index_entry
*eb
= b
;
18777 int len
= VEC_length (offset_type
, ea
->cu_indices
);
18778 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
18780 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
18781 VEC_address (offset_type
, eb
->cu_indices
),
18782 sizeof (offset_type
) * len
);
18785 /* Destroy a symtab_index_entry. */
18788 delete_symtab_entry (void *p
)
18790 struct symtab_index_entry
*entry
= p
;
18791 VEC_free (offset_type
, entry
->cu_indices
);
18795 /* Create a hash table holding symtab_index_entry objects. */
18798 create_symbol_hash_table (void)
18800 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
18801 delete_symtab_entry
, xcalloc
, xfree
);
18804 /* Create a new mapped symtab object. */
18806 static struct mapped_symtab
*
18807 create_mapped_symtab (void)
18809 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
18810 symtab
->n_elements
= 0;
18811 symtab
->size
= 1024;
18812 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18816 /* Destroy a mapped_symtab. */
18819 cleanup_mapped_symtab (void *p
)
18821 struct mapped_symtab
*symtab
= p
;
18822 /* The contents of the array are freed when the other hash table is
18824 xfree (symtab
->data
);
18828 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
18831 Function is used only during write_hash_table so no index format backward
18832 compatibility is needed. */
18834 static struct symtab_index_entry
**
18835 find_slot (struct mapped_symtab
*symtab
, const char *name
)
18837 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
18839 index
= hash
& (symtab
->size
- 1);
18840 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
18844 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
18845 return &symtab
->data
[index
];
18846 index
= (index
+ step
) & (symtab
->size
- 1);
18850 /* Expand SYMTAB's hash table. */
18853 hash_expand (struct mapped_symtab
*symtab
)
18855 offset_type old_size
= symtab
->size
;
18857 struct symtab_index_entry
**old_entries
= symtab
->data
;
18860 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18862 for (i
= 0; i
< old_size
; ++i
)
18864 if (old_entries
[i
])
18866 struct symtab_index_entry
**slot
= find_slot (symtab
,
18867 old_entries
[i
]->name
);
18868 *slot
= old_entries
[i
];
18872 xfree (old_entries
);
18875 /* Add an entry to SYMTAB. NAME is the name of the symbol.
18876 CU_INDEX is the index of the CU in which the symbol appears.
18877 IS_STATIC is one if the symbol is static, otherwise zero (global). */
18880 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
18881 int is_static
, gdb_index_symbol_kind kind
,
18882 offset_type cu_index
)
18884 struct symtab_index_entry
**slot
;
18885 offset_type cu_index_and_attrs
;
18887 ++symtab
->n_elements
;
18888 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
18889 hash_expand (symtab
);
18891 slot
= find_slot (symtab
, name
);
18894 *slot
= XNEW (struct symtab_index_entry
);
18895 (*slot
)->name
= name
;
18896 /* index_offset is set later. */
18897 (*slot
)->cu_indices
= NULL
;
18900 cu_index_and_attrs
= 0;
18901 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
18902 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
18903 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
18905 /* We don't want to record an index value twice as we want to avoid the
18907 We process all global symbols and then all static symbols
18908 (which would allow us to avoid the duplication by only having to check
18909 the last entry pushed), but a symbol could have multiple kinds in one CU.
18910 To keep things simple we don't worry about the duplication here and
18911 sort and uniqufy the list after we've processed all symbols. */
18912 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
18915 /* qsort helper routine for uniquify_cu_indices. */
18918 offset_type_compare (const void *ap
, const void *bp
)
18920 offset_type a
= *(offset_type
*) ap
;
18921 offset_type b
= *(offset_type
*) bp
;
18923 return (a
> b
) - (b
> a
);
18926 /* Sort and remove duplicates of all symbols' cu_indices lists. */
18929 uniquify_cu_indices (struct mapped_symtab
*symtab
)
18933 for (i
= 0; i
< symtab
->size
; ++i
)
18935 struct symtab_index_entry
*entry
= symtab
->data
[i
];
18938 && entry
->cu_indices
!= NULL
)
18940 unsigned int next_to_insert
, next_to_check
;
18941 offset_type last_value
;
18943 qsort (VEC_address (offset_type
, entry
->cu_indices
),
18944 VEC_length (offset_type
, entry
->cu_indices
),
18945 sizeof (offset_type
), offset_type_compare
);
18947 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
18948 next_to_insert
= 1;
18949 for (next_to_check
= 1;
18950 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
18953 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
18956 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
18958 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
18963 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
18968 /* Add a vector of indices to the constant pool. */
18971 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
18972 struct symtab_index_entry
*entry
)
18976 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
18979 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
18980 offset_type val
= MAYBE_SWAP (len
);
18985 entry
->index_offset
= obstack_object_size (cpool
);
18987 obstack_grow (cpool
, &val
, sizeof (val
));
18989 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
18992 val
= MAYBE_SWAP (iter
);
18993 obstack_grow (cpool
, &val
, sizeof (val
));
18998 struct symtab_index_entry
*old_entry
= *slot
;
18999 entry
->index_offset
= old_entry
->index_offset
;
19002 return entry
->index_offset
;
19005 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
19006 constant pool entries going into the obstack CPOOL. */
19009 write_hash_table (struct mapped_symtab
*symtab
,
19010 struct obstack
*output
, struct obstack
*cpool
)
19013 htab_t symbol_hash_table
;
19016 symbol_hash_table
= create_symbol_hash_table ();
19017 str_table
= create_strtab ();
19019 /* We add all the index vectors to the constant pool first, to
19020 ensure alignment is ok. */
19021 for (i
= 0; i
< symtab
->size
; ++i
)
19023 if (symtab
->data
[i
])
19024 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
19027 /* Now write out the hash table. */
19028 for (i
= 0; i
< symtab
->size
; ++i
)
19030 offset_type str_off
, vec_off
;
19032 if (symtab
->data
[i
])
19034 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
19035 vec_off
= symtab
->data
[i
]->index_offset
;
19039 /* While 0 is a valid constant pool index, it is not valid
19040 to have 0 for both offsets. */
19045 str_off
= MAYBE_SWAP (str_off
);
19046 vec_off
= MAYBE_SWAP (vec_off
);
19048 obstack_grow (output
, &str_off
, sizeof (str_off
));
19049 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
19052 htab_delete (str_table
);
19053 htab_delete (symbol_hash_table
);
19056 /* Struct to map psymtab to CU index in the index file. */
19057 struct psymtab_cu_index_map
19059 struct partial_symtab
*psymtab
;
19060 unsigned int cu_index
;
19064 hash_psymtab_cu_index (const void *item
)
19066 const struct psymtab_cu_index_map
*map
= item
;
19068 return htab_hash_pointer (map
->psymtab
);
19072 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
19074 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
19075 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
19077 return lhs
->psymtab
== rhs
->psymtab
;
19080 /* Helper struct for building the address table. */
19081 struct addrmap_index_data
19083 struct objfile
*objfile
;
19084 struct obstack
*addr_obstack
;
19085 htab_t cu_index_htab
;
19087 /* Non-zero if the previous_* fields are valid.
19088 We can't write an entry until we see the next entry (since it is only then
19089 that we know the end of the entry). */
19090 int previous_valid
;
19091 /* Index of the CU in the table of all CUs in the index file. */
19092 unsigned int previous_cu_index
;
19093 /* Start address of the CU. */
19094 CORE_ADDR previous_cu_start
;
19097 /* Write an address entry to OBSTACK. */
19100 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
19101 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
19103 offset_type cu_index_to_write
;
19105 CORE_ADDR baseaddr
;
19107 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19109 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
19110 obstack_grow (obstack
, addr
, 8);
19111 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
19112 obstack_grow (obstack
, addr
, 8);
19113 cu_index_to_write
= MAYBE_SWAP (cu_index
);
19114 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
19117 /* Worker function for traversing an addrmap to build the address table. */
19120 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
19122 struct addrmap_index_data
*data
= datap
;
19123 struct partial_symtab
*pst
= obj
;
19125 if (data
->previous_valid
)
19126 add_address_entry (data
->objfile
, data
->addr_obstack
,
19127 data
->previous_cu_start
, start_addr
,
19128 data
->previous_cu_index
);
19130 data
->previous_cu_start
= start_addr
;
19133 struct psymtab_cu_index_map find_map
, *map
;
19134 find_map
.psymtab
= pst
;
19135 map
= htab_find (data
->cu_index_htab
, &find_map
);
19136 gdb_assert (map
!= NULL
);
19137 data
->previous_cu_index
= map
->cu_index
;
19138 data
->previous_valid
= 1;
19141 data
->previous_valid
= 0;
19146 /* Write OBJFILE's address map to OBSTACK.
19147 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
19148 in the index file. */
19151 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
19152 htab_t cu_index_htab
)
19154 struct addrmap_index_data addrmap_index_data
;
19156 /* When writing the address table, we have to cope with the fact that
19157 the addrmap iterator only provides the start of a region; we have to
19158 wait until the next invocation to get the start of the next region. */
19160 addrmap_index_data
.objfile
= objfile
;
19161 addrmap_index_data
.addr_obstack
= obstack
;
19162 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
19163 addrmap_index_data
.previous_valid
= 0;
19165 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
19166 &addrmap_index_data
);
19168 /* It's highly unlikely the last entry (end address = 0xff...ff)
19169 is valid, but we should still handle it.
19170 The end address is recorded as the start of the next region, but that
19171 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
19173 if (addrmap_index_data
.previous_valid
)
19174 add_address_entry (objfile
, obstack
,
19175 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
19176 addrmap_index_data
.previous_cu_index
);
19179 /* Return the symbol kind of PSYM. */
19181 static gdb_index_symbol_kind
19182 symbol_kind (struct partial_symbol
*psym
)
19184 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
19185 enum address_class aclass
= PSYMBOL_CLASS (psym
);
19193 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
19195 return GDB_INDEX_SYMBOL_KIND_TYPE
;
19197 case LOC_CONST_BYTES
:
19198 case LOC_OPTIMIZED_OUT
:
19200 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
19202 /* Note: It's currently impossible to recognize psyms as enum values
19203 short of reading the type info. For now punt. */
19204 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
19206 /* There are other LOC_FOO values that one might want to classify
19207 as variables, but dwarf2read.c doesn't currently use them. */
19208 return GDB_INDEX_SYMBOL_KIND_OTHER
;
19210 case STRUCT_DOMAIN
:
19211 return GDB_INDEX_SYMBOL_KIND_TYPE
;
19213 return GDB_INDEX_SYMBOL_KIND_OTHER
;
19217 /* Add a list of partial symbols to SYMTAB. */
19220 write_psymbols (struct mapped_symtab
*symtab
,
19222 struct partial_symbol
**psymp
,
19224 offset_type cu_index
,
19227 for (; count
-- > 0; ++psymp
)
19229 struct partial_symbol
*psym
= *psymp
;
19232 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
19233 error (_("Ada is not currently supported by the index"));
19235 /* Only add a given psymbol once. */
19236 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
19239 gdb_index_symbol_kind kind
= symbol_kind (psym
);
19242 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
19243 is_static
, kind
, cu_index
);
19248 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
19249 exception if there is an error. */
19252 write_obstack (FILE *file
, struct obstack
*obstack
)
19254 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
19256 != obstack_object_size (obstack
))
19257 error (_("couldn't data write to file"));
19260 /* Unlink a file if the argument is not NULL. */
19263 unlink_if_set (void *p
)
19265 char **filename
= p
;
19267 unlink (*filename
);
19270 /* A helper struct used when iterating over debug_types. */
19271 struct signatured_type_index_data
19273 struct objfile
*objfile
;
19274 struct mapped_symtab
*symtab
;
19275 struct obstack
*types_list
;
19280 /* A helper function that writes a single signatured_type to an
19284 write_one_signatured_type (void **slot
, void *d
)
19286 struct signatured_type_index_data
*info
= d
;
19287 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
19288 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
19289 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19292 write_psymbols (info
->symtab
,
19294 info
->objfile
->global_psymbols
.list
19295 + psymtab
->globals_offset
,
19296 psymtab
->n_global_syms
, info
->cu_index
,
19298 write_psymbols (info
->symtab
,
19300 info
->objfile
->static_psymbols
.list
19301 + psymtab
->statics_offset
,
19302 psymtab
->n_static_syms
, info
->cu_index
,
19305 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19306 entry
->per_cu
.offset
.sect_off
);
19307 obstack_grow (info
->types_list
, val
, 8);
19308 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19309 entry
->type_offset_in_tu
.cu_off
);
19310 obstack_grow (info
->types_list
, val
, 8);
19311 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
19312 obstack_grow (info
->types_list
, val
, 8);
19319 /* Recurse into all "included" dependencies and write their symbols as
19320 if they appeared in this psymtab. */
19323 recursively_write_psymbols (struct objfile
*objfile
,
19324 struct partial_symtab
*psymtab
,
19325 struct mapped_symtab
*symtab
,
19327 offset_type cu_index
)
19331 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
19332 if (psymtab
->dependencies
[i
]->user
!= NULL
)
19333 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
19334 symtab
, psyms_seen
, cu_index
);
19336 write_psymbols (symtab
,
19338 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
19339 psymtab
->n_global_syms
, cu_index
,
19341 write_psymbols (symtab
,
19343 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
19344 psymtab
->n_static_syms
, cu_index
,
19348 /* Create an index file for OBJFILE in the directory DIR. */
19351 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
19353 struct cleanup
*cleanup
;
19354 char *filename
, *cleanup_filename
;
19355 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
19356 struct obstack cu_list
, types_cu_list
;
19359 struct mapped_symtab
*symtab
;
19360 offset_type val
, size_of_contents
, total_len
;
19363 htab_t cu_index_htab
;
19364 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
19366 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
19369 if (dwarf2_per_objfile
->using_index
)
19370 error (_("Cannot use an index to create the index"));
19372 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
19373 error (_("Cannot make an index when the file has multiple .debug_types sections"));
19375 if (stat (objfile
->name
, &st
) < 0)
19376 perror_with_name (objfile
->name
);
19378 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
19379 INDEX_SUFFIX
, (char *) NULL
);
19380 cleanup
= make_cleanup (xfree
, filename
);
19382 out_file
= fopen (filename
, "wb");
19384 error (_("Can't open `%s' for writing"), filename
);
19386 cleanup_filename
= filename
;
19387 make_cleanup (unlink_if_set
, &cleanup_filename
);
19389 symtab
= create_mapped_symtab ();
19390 make_cleanup (cleanup_mapped_symtab
, symtab
);
19392 obstack_init (&addr_obstack
);
19393 make_cleanup_obstack_free (&addr_obstack
);
19395 obstack_init (&cu_list
);
19396 make_cleanup_obstack_free (&cu_list
);
19398 obstack_init (&types_cu_list
);
19399 make_cleanup_obstack_free (&types_cu_list
);
19401 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
19402 NULL
, xcalloc
, xfree
);
19403 make_cleanup_htab_delete (psyms_seen
);
19405 /* While we're scanning CU's create a table that maps a psymtab pointer
19406 (which is what addrmap records) to its index (which is what is recorded
19407 in the index file). This will later be needed to write the address
19409 cu_index_htab
= htab_create_alloc (100,
19410 hash_psymtab_cu_index
,
19411 eq_psymtab_cu_index
,
19412 NULL
, xcalloc
, xfree
);
19413 make_cleanup_htab_delete (cu_index_htab
);
19414 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
19415 xmalloc (sizeof (struct psymtab_cu_index_map
)
19416 * dwarf2_per_objfile
->n_comp_units
);
19417 make_cleanup (xfree
, psymtab_cu_index_map
);
19419 /* The CU list is already sorted, so we don't need to do additional
19420 work here. Also, the debug_types entries do not appear in
19421 all_comp_units, but only in their own hash table. */
19422 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
19424 struct dwarf2_per_cu_data
*per_cu
19425 = dwarf2_per_objfile
->all_comp_units
[i
];
19426 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19428 struct psymtab_cu_index_map
*map
;
19431 if (psymtab
->user
== NULL
)
19432 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
19434 map
= &psymtab_cu_index_map
[i
];
19435 map
->psymtab
= psymtab
;
19437 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
19438 gdb_assert (slot
!= NULL
);
19439 gdb_assert (*slot
== NULL
);
19442 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19443 per_cu
->offset
.sect_off
);
19444 obstack_grow (&cu_list
, val
, 8);
19445 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
19446 obstack_grow (&cu_list
, val
, 8);
19449 /* Dump the address map. */
19450 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
19452 /* Write out the .debug_type entries, if any. */
19453 if (dwarf2_per_objfile
->signatured_types
)
19455 struct signatured_type_index_data sig_data
;
19457 sig_data
.objfile
= objfile
;
19458 sig_data
.symtab
= symtab
;
19459 sig_data
.types_list
= &types_cu_list
;
19460 sig_data
.psyms_seen
= psyms_seen
;
19461 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
19462 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
19463 write_one_signatured_type
, &sig_data
);
19466 /* Now that we've processed all symbols we can shrink their cu_indices
19468 uniquify_cu_indices (symtab
);
19470 obstack_init (&constant_pool
);
19471 make_cleanup_obstack_free (&constant_pool
);
19472 obstack_init (&symtab_obstack
);
19473 make_cleanup_obstack_free (&symtab_obstack
);
19474 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
19476 obstack_init (&contents
);
19477 make_cleanup_obstack_free (&contents
);
19478 size_of_contents
= 6 * sizeof (offset_type
);
19479 total_len
= size_of_contents
;
19481 /* The version number. */
19482 val
= MAYBE_SWAP (7);
19483 obstack_grow (&contents
, &val
, sizeof (val
));
19485 /* The offset of the CU list from the start of the file. */
19486 val
= MAYBE_SWAP (total_len
);
19487 obstack_grow (&contents
, &val
, sizeof (val
));
19488 total_len
+= obstack_object_size (&cu_list
);
19490 /* The offset of the types CU list from the start of the file. */
19491 val
= MAYBE_SWAP (total_len
);
19492 obstack_grow (&contents
, &val
, sizeof (val
));
19493 total_len
+= obstack_object_size (&types_cu_list
);
19495 /* The offset of the address table from the start of the file. */
19496 val
= MAYBE_SWAP (total_len
);
19497 obstack_grow (&contents
, &val
, sizeof (val
));
19498 total_len
+= obstack_object_size (&addr_obstack
);
19500 /* The offset of the symbol table from the start of the file. */
19501 val
= MAYBE_SWAP (total_len
);
19502 obstack_grow (&contents
, &val
, sizeof (val
));
19503 total_len
+= obstack_object_size (&symtab_obstack
);
19505 /* The offset of the constant pool from the start of the file. */
19506 val
= MAYBE_SWAP (total_len
);
19507 obstack_grow (&contents
, &val
, sizeof (val
));
19508 total_len
+= obstack_object_size (&constant_pool
);
19510 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
19512 write_obstack (out_file
, &contents
);
19513 write_obstack (out_file
, &cu_list
);
19514 write_obstack (out_file
, &types_cu_list
);
19515 write_obstack (out_file
, &addr_obstack
);
19516 write_obstack (out_file
, &symtab_obstack
);
19517 write_obstack (out_file
, &constant_pool
);
19521 /* We want to keep the file, so we set cleanup_filename to NULL
19522 here. See unlink_if_set. */
19523 cleanup_filename
= NULL
;
19525 do_cleanups (cleanup
);
19528 /* Implementation of the `save gdb-index' command.
19530 Note that the file format used by this command is documented in the
19531 GDB manual. Any changes here must be documented there. */
19534 save_gdb_index_command (char *arg
, int from_tty
)
19536 struct objfile
*objfile
;
19539 error (_("usage: save gdb-index DIRECTORY"));
19541 ALL_OBJFILES (objfile
)
19545 /* If the objfile does not correspond to an actual file, skip it. */
19546 if (stat (objfile
->name
, &st
) < 0)
19549 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19550 if (dwarf2_per_objfile
)
19552 volatile struct gdb_exception except
;
19554 TRY_CATCH (except
, RETURN_MASK_ERROR
)
19556 write_psymtabs_to_index (objfile
, arg
);
19558 if (except
.reason
< 0)
19559 exception_fprintf (gdb_stderr
, except
,
19560 _("Error while writing index for `%s': "),
19568 int dwarf2_always_disassemble
;
19571 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
19572 struct cmd_list_element
*c
, const char *value
)
19574 fprintf_filtered (file
,
19575 _("Whether to always disassemble "
19576 "DWARF expressions is %s.\n"),
19581 show_check_physname (struct ui_file
*file
, int from_tty
,
19582 struct cmd_list_element
*c
, const char *value
)
19584 fprintf_filtered (file
,
19585 _("Whether to check \"physname\" is %s.\n"),
19589 void _initialize_dwarf2_read (void);
19592 _initialize_dwarf2_read (void)
19594 struct cmd_list_element
*c
;
19596 dwarf2_objfile_data_key
19597 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
19599 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
19600 Set DWARF 2 specific variables.\n\
19601 Configure DWARF 2 variables such as the cache size"),
19602 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
19603 0/*allow-unknown*/, &maintenance_set_cmdlist
);
19605 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
19606 Show DWARF 2 specific variables\n\
19607 Show DWARF 2 variables such as the cache size"),
19608 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
19609 0/*allow-unknown*/, &maintenance_show_cmdlist
);
19611 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
19612 &dwarf2_max_cache_age
, _("\
19613 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
19614 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
19615 A higher limit means that cached compilation units will be stored\n\
19616 in memory longer, and more total memory will be used. Zero disables\n\
19617 caching, which can slow down startup."),
19619 show_dwarf2_max_cache_age
,
19620 &set_dwarf2_cmdlist
,
19621 &show_dwarf2_cmdlist
);
19623 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
19624 &dwarf2_always_disassemble
, _("\
19625 Set whether `info address' always disassembles DWARF expressions."), _("\
19626 Show whether `info address' always disassembles DWARF expressions."), _("\
19627 When enabled, DWARF expressions are always printed in an assembly-like\n\
19628 syntax. When disabled, expressions will be printed in a more\n\
19629 conversational style, when possible."),
19631 show_dwarf2_always_disassemble
,
19632 &set_dwarf2_cmdlist
,
19633 &show_dwarf2_cmdlist
);
19635 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
19636 Set debugging of the dwarf2 reader."), _("\
19637 Show debugging of the dwarf2 reader."), _("\
19638 When enabled, debugging messages are printed during dwarf2 reading\n\
19639 and symtab expansion."),
19642 &setdebuglist
, &showdebuglist
);
19644 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
19645 Set debugging of the dwarf2 DIE reader."), _("\
19646 Show debugging of the dwarf2 DIE reader."), _("\
19647 When enabled (non-zero), DIEs are dumped after they are read in.\n\
19648 The value is the maximum depth to print."),
19651 &setdebuglist
, &showdebuglist
);
19653 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
19654 Set cross-checking of \"physname\" code against demangler."), _("\
19655 Show cross-checking of \"physname\" code against demangler."), _("\
19656 When enabled, GDB's internal \"physname\" code is checked against\n\
19658 NULL
, show_check_physname
,
19659 &setdebuglist
, &showdebuglist
);
19661 add_setshow_boolean_cmd ("use-deprecated-index-sections",
19662 no_class
, &use_deprecated_index_sections
, _("\
19663 Set whether to use deprecated gdb_index sections."), _("\
19664 Show whether to use deprecated gdb_index sections."), _("\
19665 When enabled, deprecated .gdb_index sections are used anyway.\n\
19666 Normally they are ignored either because of a missing feature or\n\
19667 performance issue.\n\
19668 Warning: This option must be enabled before gdb reads the file."),
19671 &setlist
, &showlist
);
19673 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
19675 Save a gdb-index file.\n\
19676 Usage: save gdb-index DIRECTORY"),
19678 set_cmd_completer (c
, filename_completer
);