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. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "exceptions.h"
60 #include "completer.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
72 #include "gdb_string.h"
73 #include "gdb_assert.h"
74 #include <sys/types.h>
76 typedef struct symbol
*symbolp
;
79 /* When non-zero, print basic high level tracing messages.
80 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
81 static int dwarf2_read_debug
= 0;
83 /* When non-zero, dump DIEs after they are read in. */
84 static unsigned int dwarf2_die_debug
= 0;
86 /* When non-zero, cross-check physname against demangler. */
87 static int check_physname
= 0;
89 /* When non-zero, do not reject deprecated .gdb_index sections. */
90 static int use_deprecated_index_sections
= 0;
92 /* When set, the file that we're processing is known to have debugging
93 info for C++ namespaces. GCC 3.3.x did not produce this information,
94 but later versions do. */
96 static int processing_has_namespace_info
;
98 static const struct objfile_data
*dwarf2_objfile_data_key
;
100 struct dwarf2_section_info
105 /* True if we have tried to read this section. */
109 typedef struct dwarf2_section_info dwarf2_section_info_def
;
110 DEF_VEC_O (dwarf2_section_info_def
);
112 /* All offsets in the index are of this type. It must be
113 architecture-independent. */
114 typedef uint32_t offset_type
;
116 DEF_VEC_I (offset_type
);
118 /* Ensure only legit values are used. */
119 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
121 gdb_assert ((unsigned int) (value) <= 1); \
122 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
125 /* Ensure only legit values are used. */
126 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
128 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
129 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
130 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
133 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
134 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
136 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
137 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
140 /* A description of the mapped index. The file format is described in
141 a comment by the code that writes the index. */
144 /* Index data format version. */
147 /* The total length of the buffer. */
150 /* A pointer to the address table data. */
151 const gdb_byte
*address_table
;
153 /* Size of the address table data in bytes. */
154 offset_type address_table_size
;
156 /* The symbol table, implemented as a hash table. */
157 const offset_type
*symbol_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_table_slots
;
162 /* A pointer to the constant pool. */
163 const char *constant_pool
;
166 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
167 DEF_VEC_P (dwarf2_per_cu_ptr
);
169 /* Collection of data recorded per objfile.
170 This hangs off of dwarf2_objfile_data_key. */
172 struct dwarf2_per_objfile
174 struct dwarf2_section_info info
;
175 struct dwarf2_section_info abbrev
;
176 struct dwarf2_section_info line
;
177 struct dwarf2_section_info loc
;
178 struct dwarf2_section_info macinfo
;
179 struct dwarf2_section_info macro
;
180 struct dwarf2_section_info str
;
181 struct dwarf2_section_info ranges
;
182 struct dwarf2_section_info addr
;
183 struct dwarf2_section_info frame
;
184 struct dwarf2_section_info eh_frame
;
185 struct dwarf2_section_info gdb_index
;
187 VEC (dwarf2_section_info_def
) *types
;
190 struct objfile
*objfile
;
192 /* Table of all the compilation units. This is used to locate
193 the target compilation unit of a particular reference. */
194 struct dwarf2_per_cu_data
**all_comp_units
;
196 /* The number of compilation units in ALL_COMP_UNITS. */
199 /* The number of .debug_types-related CUs. */
202 /* The .debug_types-related CUs (TUs). */
203 struct signatured_type
**all_type_units
;
205 /* The number of entries in all_type_unit_groups. */
206 int n_type_unit_groups
;
208 /* Table of type unit groups.
209 This exists to make it easy to iterate over all CUs and TU groups. */
210 struct type_unit_group
**all_type_unit_groups
;
212 /* Table of struct type_unit_group objects.
213 The hash key is the DW_AT_stmt_list value. */
214 htab_t type_unit_groups
;
216 /* A table mapping .debug_types signatures to its signatured_type entry.
217 This is NULL if the .debug_types section hasn't been read in yet. */
218 htab_t signatured_types
;
220 /* Type unit statistics, to see how well the scaling improvements
224 int nr_uniq_abbrev_tables
;
226 int nr_symtab_sharers
;
227 int nr_stmt_less_type_units
;
230 /* A chain of compilation units that are currently read in, so that
231 they can be freed later. */
232 struct dwarf2_per_cu_data
*read_in_chain
;
234 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
235 This is NULL if the table hasn't been allocated yet. */
238 /* Non-zero if we've check for whether there is a DWP file. */
241 /* The DWP file if there is one, or NULL. */
242 struct dwp_file
*dwp_file
;
244 /* The shared '.dwz' file, if one exists. This is used when the
245 original data was compressed using 'dwz -m'. */
246 struct dwz_file
*dwz_file
;
248 /* A flag indicating wether this objfile has a section loaded at a
250 int has_section_at_zero
;
252 /* True if we are using the mapped index,
253 or we are faking it for OBJF_READNOW's sake. */
254 unsigned char using_index
;
256 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
257 struct mapped_index
*index_table
;
259 /* When using index_table, this keeps track of all quick_file_names entries.
260 TUs typically share line table entries with a CU, so we maintain a
261 separate table of all line table entries to support the sharing.
262 Note that while there can be way more TUs than CUs, we've already
263 sorted all the TUs into "type unit groups", grouped by their
264 DW_AT_stmt_list value. Therefore the only sharing done here is with a
265 CU and its associated TU group if there is one. */
266 htab_t quick_file_names_table
;
268 /* Set during partial symbol reading, to prevent queueing of full
270 int reading_partial_symbols
;
272 /* Table mapping type DIEs to their struct type *.
273 This is NULL if not allocated yet.
274 The mapping is done via (CU/TU signature + DIE offset) -> type. */
275 htab_t die_type_hash
;
277 /* The CUs we recently read. */
278 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
281 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_macinfo", ".zdebug_macinfo" },
295 { ".debug_macro", ".zdebug_macro" },
296 { ".debug_str", ".zdebug_str" },
297 { ".debug_ranges", ".zdebug_ranges" },
298 { ".debug_types", ".zdebug_types" },
299 { ".debug_addr", ".zdebug_addr" },
300 { ".debug_frame", ".zdebug_frame" },
301 { ".eh_frame", NULL
},
302 { ".gdb_index", ".zgdb_index" },
306 /* List of DWO/DWP sections. */
308 static const struct dwop_section_names
310 struct dwarf2_section_names abbrev_dwo
;
311 struct dwarf2_section_names info_dwo
;
312 struct dwarf2_section_names line_dwo
;
313 struct dwarf2_section_names loc_dwo
;
314 struct dwarf2_section_names macinfo_dwo
;
315 struct dwarf2_section_names macro_dwo
;
316 struct dwarf2_section_names str_dwo
;
317 struct dwarf2_section_names str_offsets_dwo
;
318 struct dwarf2_section_names types_dwo
;
319 struct dwarf2_section_names cu_index
;
320 struct dwarf2_section_names tu_index
;
324 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
325 { ".debug_info.dwo", ".zdebug_info.dwo" },
326 { ".debug_line.dwo", ".zdebug_line.dwo" },
327 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
328 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
329 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
330 { ".debug_str.dwo", ".zdebug_str.dwo" },
331 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
332 { ".debug_types.dwo", ".zdebug_types.dwo" },
333 { ".debug_cu_index", ".zdebug_cu_index" },
334 { ".debug_tu_index", ".zdebug_tu_index" },
337 /* local data types */
339 /* The data in a compilation unit header, after target2host
340 translation, looks like this. */
341 struct comp_unit_head
345 unsigned char addr_size
;
346 unsigned char signed_addr_p
;
347 sect_offset abbrev_offset
;
349 /* Size of file offsets; either 4 or 8. */
350 unsigned int offset_size
;
352 /* Size of the length field; either 4 or 12. */
353 unsigned int initial_length_size
;
355 /* Offset to the first byte of this compilation unit header in the
356 .debug_info section, for resolving relative reference dies. */
359 /* Offset to first die in this cu from the start of the cu.
360 This will be the first byte following the compilation unit header. */
361 cu_offset first_die_offset
;
364 /* Type used for delaying computation of method physnames.
365 See comments for compute_delayed_physnames. */
366 struct delayed_method_info
368 /* The type to which the method is attached, i.e., its parent class. */
371 /* The index of the method in the type's function fieldlists. */
374 /* The index of the method in the fieldlist. */
377 /* The name of the DIE. */
380 /* The DIE associated with this method. */
381 struct die_info
*die
;
384 typedef struct delayed_method_info delayed_method_info
;
385 DEF_VEC_O (delayed_method_info
);
387 /* Internal state when decoding a particular compilation unit. */
390 /* The objfile containing this compilation unit. */
391 struct objfile
*objfile
;
393 /* The header of the compilation unit. */
394 struct comp_unit_head header
;
396 /* Base address of this compilation unit. */
397 CORE_ADDR base_address
;
399 /* Non-zero if base_address has been set. */
402 /* The language we are debugging. */
403 enum language language
;
404 const struct language_defn
*language_defn
;
406 const char *producer
;
408 /* The generic symbol table building routines have separate lists for
409 file scope symbols and all all other scopes (local scopes). So
410 we need to select the right one to pass to add_symbol_to_list().
411 We do it by keeping a pointer to the correct list in list_in_scope.
413 FIXME: The original dwarf code just treated the file scope as the
414 first local scope, and all other local scopes as nested local
415 scopes, and worked fine. Check to see if we really need to
416 distinguish these in buildsym.c. */
417 struct pending
**list_in_scope
;
419 /* The abbrev table for this CU.
420 Normally this points to the abbrev table in the objfile.
421 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
422 struct abbrev_table
*abbrev_table
;
424 /* Hash table holding all the loaded partial DIEs
425 with partial_die->offset.SECT_OFF as hash. */
428 /* Storage for things with the same lifetime as this read-in compilation
429 unit, including partial DIEs. */
430 struct obstack comp_unit_obstack
;
432 /* When multiple dwarf2_cu structures are living in memory, this field
433 chains them all together, so that they can be released efficiently.
434 We will probably also want a generation counter so that most-recently-used
435 compilation units are cached... */
436 struct dwarf2_per_cu_data
*read_in_chain
;
438 /* Backchain to our per_cu entry if the tree has been built. */
439 struct dwarf2_per_cu_data
*per_cu
;
441 /* How many compilation units ago was this CU last referenced? */
444 /* A hash table of DIE cu_offset for following references with
445 die_info->offset.sect_off as hash. */
448 /* Full DIEs if read in. */
449 struct die_info
*dies
;
451 /* A set of pointers to dwarf2_per_cu_data objects for compilation
452 units referenced by this one. Only set during full symbol processing;
453 partial symbol tables do not have dependencies. */
456 /* Header data from the line table, during full symbol processing. */
457 struct line_header
*line_header
;
459 /* A list of methods which need to have physnames computed
460 after all type information has been read. */
461 VEC (delayed_method_info
) *method_list
;
463 /* To be copied to symtab->call_site_htab. */
464 htab_t call_site_htab
;
466 /* Non-NULL if this CU came from a DWO file.
467 There is an invariant here that is important to remember:
468 Except for attributes copied from the top level DIE in the "main"
469 (or "stub") file in preparation for reading the DWO file
470 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
471 Either there isn't a DWO file (in which case this is NULL and the point
472 is moot), or there is and either we're not going to read it (in which
473 case this is NULL) or there is and we are reading it (in which case this
475 struct dwo_unit
*dwo_unit
;
477 /* The DW_AT_addr_base attribute if present, zero otherwise
478 (zero is a valid value though).
479 Note this value comes from the stub CU/TU's DIE. */
482 /* The DW_AT_ranges_base attribute if present, zero otherwise
483 (zero is a valid value though).
484 Note this value comes from the stub CU/TU's DIE.
485 Also note that the value is zero in the non-DWO case so this value can
486 be used without needing to know whether DWO files are in use or not. */
487 ULONGEST ranges_base
;
489 /* Mark used when releasing cached dies. */
490 unsigned int mark
: 1;
492 /* This CU references .debug_loc. See the symtab->locations_valid field.
493 This test is imperfect as there may exist optimized debug code not using
494 any location list and still facing inlining issues if handled as
495 unoptimized code. For a future better test see GCC PR other/32998. */
496 unsigned int has_loclist
: 1;
498 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
499 if all the producer_is_* fields are valid. This information is cached
500 because profiling CU expansion showed excessive time spent in
501 producer_is_gxx_lt_4_6. */
502 unsigned int checked_producer
: 1;
503 unsigned int producer_is_gxx_lt_4_6
: 1;
504 unsigned int producer_is_gcc_lt_4_3
: 1;
505 unsigned int producer_is_icc
: 1;
508 /* Persistent data held for a compilation unit, even when not
509 processing it. We put a pointer to this structure in the
510 read_symtab_private field of the psymtab. */
512 struct dwarf2_per_cu_data
514 /* The start offset and length of this compilation unit.
515 NOTE: Unlike comp_unit_head.length, this length includes
517 If the DIE refers to a DWO file, this is always of the original die,
522 /* Flag indicating this compilation unit will be read in before
523 any of the current compilation units are processed. */
524 unsigned int queued
: 1;
526 /* This flag will be set when reading partial DIEs if we need to load
527 absolutely all DIEs for this compilation unit, instead of just the ones
528 we think are interesting. It gets set if we look for a DIE in the
529 hash table and don't find it. */
530 unsigned int load_all_dies
: 1;
532 /* Non-zero if this CU is from .debug_types. */
533 unsigned int is_debug_types
: 1;
535 /* Non-zero if this CU is from the .dwz file. */
536 unsigned int is_dwz
: 1;
538 /* The section this CU/TU lives in.
539 If the DIE refers to a DWO file, this is always the original die,
541 struct dwarf2_section_info
*info_or_types_section
;
543 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
544 of the CU cache it gets reset to NULL again. */
545 struct dwarf2_cu
*cu
;
547 /* The corresponding objfile.
548 Normally we can get the objfile from dwarf2_per_objfile.
549 However we can enter this file with just a "per_cu" handle. */
550 struct objfile
*objfile
;
552 /* When using partial symbol tables, the 'psymtab' field is active.
553 Otherwise the 'quick' field is active. */
556 /* The partial symbol table associated with this compilation unit,
557 or NULL for unread partial units. */
558 struct partial_symtab
*psymtab
;
560 /* Data needed by the "quick" functions. */
561 struct dwarf2_per_cu_quick_data
*quick
;
566 /* The CUs we import using DW_TAG_imported_unit. This is filled in
567 while reading psymtabs, used to compute the psymtab dependencies,
568 and then cleared. Then it is filled in again while reading full
569 symbols, and only deleted when the objfile is destroyed. */
570 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
572 /* Type units are grouped by their DW_AT_stmt_list entry so that they
573 can share them. If this is a TU, this points to the containing
575 struct type_unit_group
*type_unit_group
;
579 /* Entry in the signatured_types hash table. */
581 struct signatured_type
583 /* The "per_cu" object of this type.
584 N.B.: This is the first member so that it's easy to convert pointers
586 struct dwarf2_per_cu_data per_cu
;
588 /* The type's signature. */
591 /* Offset in the TU of the type's DIE, as read from the TU header.
592 If the definition lives in a DWO file, this value is unusable. */
593 cu_offset type_offset_in_tu
;
595 /* Offset in the section of the type's DIE.
596 If the definition lives in a DWO file, this is the offset in the
597 .debug_types.dwo section.
598 The value is zero until the actual value is known.
599 Zero is otherwise not a valid section offset. */
600 sect_offset type_offset_in_section
;
603 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
604 This includes type_unit_group and quick_file_names. */
606 struct stmt_list_hash
608 /* The DWO unit this table is from or NULL if there is none. */
609 struct dwo_unit
*dwo_unit
;
611 /* Offset in .debug_line or .debug_line.dwo. */
612 sect_offset line_offset
;
615 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
616 an object of this type. */
618 struct type_unit_group
620 /* dwarf2read.c's main "handle" on the symtab.
621 To simplify things we create an artificial CU that "includes" all the
622 type units using this stmt_list so that the rest of the code still has
623 a "per_cu" handle on the symtab.
624 This PER_CU is recognized by having no section. */
625 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
626 struct dwarf2_per_cu_data per_cu
;
630 /* The TUs that share this DW_AT_stmt_list entry.
631 This is added to while parsing type units to build partial symtabs,
632 and is deleted afterwards and not used again. */
633 VEC (dwarf2_per_cu_ptr
) *tus
;
635 /* When reading the line table in "quick" functions, we need a real TU.
636 Any will do, we know they all share the same DW_AT_stmt_list entry.
637 For simplicity's sake, we pick the first one. */
638 struct dwarf2_per_cu_data
*first_tu
;
641 /* The primary symtab.
642 Type units in a group needn't all be defined in the same source file,
643 so we create an essentially anonymous symtab as the primary symtab. */
644 struct symtab
*primary_symtab
;
646 /* The data used to construct the hash key. */
647 struct stmt_list_hash hash
;
649 /* The number of symtabs from the line header.
650 The value here must match line_header.num_file_names. */
651 unsigned int num_symtabs
;
653 /* The symbol tables for this TU (obtained from the files listed in
655 WARNING: The order of entries here must match the order of entries
656 in the line header. After the first TU using this type_unit_group, the
657 line header for the subsequent TUs is recreated from this. This is done
658 because we need to use the same symtabs for each TU using the same
659 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
660 there's no guarantee the line header doesn't have duplicate entries. */
661 struct symtab
**symtabs
;
664 /* These sections are what may appear in a DWO file. */
668 struct dwarf2_section_info abbrev
;
669 struct dwarf2_section_info line
;
670 struct dwarf2_section_info loc
;
671 struct dwarf2_section_info macinfo
;
672 struct dwarf2_section_info macro
;
673 struct dwarf2_section_info str
;
674 struct dwarf2_section_info str_offsets
;
675 /* In the case of a virtual DWO file, these two are unused. */
676 struct dwarf2_section_info info
;
677 VEC (dwarf2_section_info_def
) *types
;
680 /* Common bits of DWO CUs/TUs. */
684 /* Backlink to the containing struct dwo_file. */
685 struct dwo_file
*dwo_file
;
687 /* The "id" that distinguishes this CU/TU.
688 .debug_info calls this "dwo_id", .debug_types calls this "signature".
689 Since signatures came first, we stick with it for consistency. */
692 /* The section this CU/TU lives in, in the DWO file. */
693 struct dwarf2_section_info
*info_or_types_section
;
695 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
699 /* For types, offset in the type's DIE of the type defined by this TU. */
700 cu_offset type_offset_in_tu
;
703 /* Data for one DWO file.
704 This includes virtual DWO files that have been packaged into a
709 /* The DW_AT_GNU_dwo_name attribute. This is the hash key.
710 For virtual DWO files the name is constructed from the section offsets
711 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
712 from related CU+TUs. */
715 /* The bfd, when the file is open. Otherwise this is NULL.
716 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
719 /* Section info for this file. */
720 struct dwo_sections sections
;
722 /* Table of CUs in the file.
723 Each element is a struct dwo_unit. */
726 /* Table of TUs in the file.
727 Each element is a struct dwo_unit. */
731 /* These sections are what may appear in a DWP file. */
735 struct dwarf2_section_info str
;
736 struct dwarf2_section_info cu_index
;
737 struct dwarf2_section_info tu_index
;
738 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
739 by section number. We don't need to record them here. */
742 /* These sections are what may appear in a virtual DWO file. */
744 struct virtual_dwo_sections
746 struct dwarf2_section_info abbrev
;
747 struct dwarf2_section_info line
;
748 struct dwarf2_section_info loc
;
749 struct dwarf2_section_info macinfo
;
750 struct dwarf2_section_info macro
;
751 struct dwarf2_section_info str_offsets
;
752 /* Each DWP hash table entry records one CU or one TU.
753 That is recorded here, and copied to dwo_unit.info_or_types_section. */
754 struct dwarf2_section_info info_or_types
;
757 /* Contents of DWP hash tables. */
759 struct dwp_hash_table
761 uint32_t nr_units
, nr_slots
;
762 const gdb_byte
*hash_table
, *unit_table
, *section_pool
;
765 /* Data for one DWP file. */
769 /* Name of the file. */
772 /* The bfd, when the file is open. Otherwise this is NULL. */
775 /* Section info for this file. */
776 struct dwp_sections sections
;
778 /* Table of CUs in the file. */
779 const struct dwp_hash_table
*cus
;
781 /* Table of TUs in the file. */
782 const struct dwp_hash_table
*tus
;
784 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
787 /* Table to map ELF section numbers to their sections. */
788 unsigned int num_sections
;
789 asection
**elf_sections
;
792 /* This represents a '.dwz' file. */
796 /* A dwz file can only contain a few sections. */
797 struct dwarf2_section_info abbrev
;
798 struct dwarf2_section_info info
;
799 struct dwarf2_section_info str
;
800 struct dwarf2_section_info line
;
801 struct dwarf2_section_info macro
;
802 struct dwarf2_section_info gdb_index
;
808 /* Struct used to pass misc. parameters to read_die_and_children, et
809 al. which are used for both .debug_info and .debug_types dies.
810 All parameters here are unchanging for the life of the call. This
811 struct exists to abstract away the constant parameters of die reading. */
813 struct die_reader_specs
815 /* die_section->asection->owner. */
818 /* The CU of the DIE we are parsing. */
819 struct dwarf2_cu
*cu
;
821 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
822 struct dwo_file
*dwo_file
;
824 /* The section the die comes from.
825 This is either .debug_info or .debug_types, or the .dwo variants. */
826 struct dwarf2_section_info
*die_section
;
828 /* die_section->buffer. */
831 /* The end of the buffer. */
832 const gdb_byte
*buffer_end
;
835 /* Type of function passed to init_cutu_and_read_dies, et.al. */
836 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
838 struct die_info
*comp_unit_die
,
842 /* The line number information for a compilation unit (found in the
843 .debug_line section) begins with a "statement program header",
844 which contains the following information. */
847 unsigned int total_length
;
848 unsigned short version
;
849 unsigned int header_length
;
850 unsigned char minimum_instruction_length
;
851 unsigned char maximum_ops_per_instruction
;
852 unsigned char default_is_stmt
;
854 unsigned char line_range
;
855 unsigned char opcode_base
;
857 /* standard_opcode_lengths[i] is the number of operands for the
858 standard opcode whose value is i. This means that
859 standard_opcode_lengths[0] is unused, and the last meaningful
860 element is standard_opcode_lengths[opcode_base - 1]. */
861 unsigned char *standard_opcode_lengths
;
863 /* The include_directories table. NOTE! These strings are not
864 allocated with xmalloc; instead, they are pointers into
865 debug_line_buffer. If you try to free them, `free' will get
867 unsigned int num_include_dirs
, include_dirs_size
;
870 /* The file_names table. NOTE! These strings are not allocated
871 with xmalloc; instead, they are pointers into debug_line_buffer.
872 Don't try to free them directly. */
873 unsigned int num_file_names
, file_names_size
;
877 unsigned int dir_index
;
878 unsigned int mod_time
;
880 int included_p
; /* Non-zero if referenced by the Line Number Program. */
881 struct symtab
*symtab
; /* The associated symbol table, if any. */
884 /* The start and end of the statement program following this
885 header. These point into dwarf2_per_objfile->line_buffer. */
886 gdb_byte
*statement_program_start
, *statement_program_end
;
889 /* When we construct a partial symbol table entry we only
890 need this much information. */
891 struct partial_die_info
893 /* Offset of this DIE. */
896 /* DWARF-2 tag for this DIE. */
897 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
899 /* Assorted flags describing the data found in this DIE. */
900 unsigned int has_children
: 1;
901 unsigned int is_external
: 1;
902 unsigned int is_declaration
: 1;
903 unsigned int has_type
: 1;
904 unsigned int has_specification
: 1;
905 unsigned int has_pc_info
: 1;
906 unsigned int may_be_inlined
: 1;
908 /* Flag set if the SCOPE field of this structure has been
910 unsigned int scope_set
: 1;
912 /* Flag set if the DIE has a byte_size attribute. */
913 unsigned int has_byte_size
: 1;
915 /* Flag set if any of the DIE's children are template arguments. */
916 unsigned int has_template_arguments
: 1;
918 /* Flag set if fixup_partial_die has been called on this die. */
919 unsigned int fixup_called
: 1;
921 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
922 unsigned int is_dwz
: 1;
924 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
925 unsigned int spec_is_dwz
: 1;
927 /* The name of this DIE. Normally the value of DW_AT_name, but
928 sometimes a default name for unnamed DIEs. */
931 /* The linkage name, if present. */
932 const char *linkage_name
;
934 /* The scope to prepend to our children. This is generally
935 allocated on the comp_unit_obstack, so will disappear
936 when this compilation unit leaves the cache. */
939 /* Some data associated with the partial DIE. The tag determines
940 which field is live. */
943 /* The location description associated with this DIE, if any. */
944 struct dwarf_block
*locdesc
;
945 /* The offset of an import, for DW_TAG_imported_unit. */
949 /* If HAS_PC_INFO, the PC range associated with this DIE. */
953 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
954 DW_AT_sibling, if any. */
955 /* NOTE: This member isn't strictly necessary, read_partial_die could
956 return DW_AT_sibling values to its caller load_partial_dies. */
959 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
960 DW_AT_specification (or DW_AT_abstract_origin or
962 sect_offset spec_offset
;
964 /* Pointers to this DIE's parent, first child, and next sibling,
966 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
969 /* This data structure holds the information of an abbrev. */
972 unsigned int number
; /* number identifying abbrev */
973 enum dwarf_tag tag
; /* dwarf tag */
974 unsigned short has_children
; /* boolean */
975 unsigned short num_attrs
; /* number of attributes */
976 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
977 struct abbrev_info
*next
; /* next in chain */
982 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
983 ENUM_BITFIELD(dwarf_form
) form
: 16;
986 /* Size of abbrev_table.abbrev_hash_table. */
987 #define ABBREV_HASH_SIZE 121
989 /* Top level data structure to contain an abbreviation table. */
993 /* Where the abbrev table came from.
994 This is used as a sanity check when the table is used. */
997 /* Storage for the abbrev table. */
998 struct obstack abbrev_obstack
;
1000 /* Hash table of abbrevs.
1001 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1002 It could be statically allocated, but the previous code didn't so we
1004 struct abbrev_info
**abbrevs
;
1007 /* Attributes have a name and a value. */
1010 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1011 ENUM_BITFIELD(dwarf_form
) form
: 15;
1013 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1014 field should be in u.str (existing only for DW_STRING) but it is kept
1015 here for better struct attribute alignment. */
1016 unsigned int string_is_canonical
: 1;
1021 struct dwarf_block
*blk
;
1025 struct signatured_type
*signatured_type
;
1030 /* This data structure holds a complete die structure. */
1033 /* DWARF-2 tag for this DIE. */
1034 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1036 /* Number of attributes */
1037 unsigned char num_attrs
;
1039 /* True if we're presently building the full type name for the
1040 type derived from this DIE. */
1041 unsigned char building_fullname
: 1;
1044 unsigned int abbrev
;
1046 /* Offset in .debug_info or .debug_types section. */
1049 /* The dies in a compilation unit form an n-ary tree. PARENT
1050 points to this die's parent; CHILD points to the first child of
1051 this node; and all the children of a given node are chained
1052 together via their SIBLING fields. */
1053 struct die_info
*child
; /* Its first child, if any. */
1054 struct die_info
*sibling
; /* Its next sibling, if any. */
1055 struct die_info
*parent
; /* Its parent, if any. */
1057 /* An array of attributes, with NUM_ATTRS elements. There may be
1058 zero, but it's not common and zero-sized arrays are not
1059 sufficiently portable C. */
1060 struct attribute attrs
[1];
1063 /* Get at parts of an attribute structure. */
1065 #define DW_STRING(attr) ((attr)->u.str)
1066 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1067 #define DW_UNSND(attr) ((attr)->u.unsnd)
1068 #define DW_BLOCK(attr) ((attr)->u.blk)
1069 #define DW_SND(attr) ((attr)->u.snd)
1070 #define DW_ADDR(attr) ((attr)->u.addr)
1071 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
1073 /* Blocks are a bunch of untyped bytes. */
1078 /* Valid only if SIZE is not zero. */
1082 #ifndef ATTR_ALLOC_CHUNK
1083 #define ATTR_ALLOC_CHUNK 4
1086 /* Allocate fields for structs, unions and enums in this size. */
1087 #ifndef DW_FIELD_ALLOC_CHUNK
1088 #define DW_FIELD_ALLOC_CHUNK 4
1091 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1092 but this would require a corresponding change in unpack_field_as_long
1094 static int bits_per_byte
= 8;
1096 /* The routines that read and process dies for a C struct or C++ class
1097 pass lists of data member fields and lists of member function fields
1098 in an instance of a field_info structure, as defined below. */
1101 /* List of data member and baseclasses fields. */
1104 struct nextfield
*next
;
1109 *fields
, *baseclasses
;
1111 /* Number of fields (including baseclasses). */
1114 /* Number of baseclasses. */
1117 /* Set if the accesibility of one of the fields is not public. */
1118 int non_public_fields
;
1120 /* Member function fields array, entries are allocated in the order they
1121 are encountered in the object file. */
1124 struct nextfnfield
*next
;
1125 struct fn_field fnfield
;
1129 /* Member function fieldlist array, contains name of possibly overloaded
1130 member function, number of overloaded member functions and a pointer
1131 to the head of the member function field chain. */
1136 struct nextfnfield
*head
;
1140 /* Number of entries in the fnfieldlists array. */
1143 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1144 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1145 struct typedef_field_list
1147 struct typedef_field field
;
1148 struct typedef_field_list
*next
;
1150 *typedef_field_list
;
1151 unsigned typedef_field_list_count
;
1154 /* One item on the queue of compilation units to read in full symbols
1156 struct dwarf2_queue_item
1158 struct dwarf2_per_cu_data
*per_cu
;
1159 enum language pretend_language
;
1160 struct dwarf2_queue_item
*next
;
1163 /* The current queue. */
1164 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1166 /* Loaded secondary compilation units are kept in memory until they
1167 have not been referenced for the processing of this many
1168 compilation units. Set this to zero to disable caching. Cache
1169 sizes of up to at least twenty will improve startup time for
1170 typical inter-CU-reference binaries, at an obvious memory cost. */
1171 static int dwarf2_max_cache_age
= 5;
1173 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1174 struct cmd_list_element
*c
, const char *value
)
1176 fprintf_filtered (file
, _("The upper bound on the age of cached "
1177 "dwarf2 compilation units is %s.\n"),
1182 /* Various complaints about symbol reading that don't abort the process. */
1185 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1187 complaint (&symfile_complaints
,
1188 _("statement list doesn't fit in .debug_line section"));
1192 dwarf2_debug_line_missing_file_complaint (void)
1194 complaint (&symfile_complaints
,
1195 _(".debug_line section has line data without a file"));
1199 dwarf2_debug_line_missing_end_sequence_complaint (void)
1201 complaint (&symfile_complaints
,
1202 _(".debug_line section has line "
1203 "program sequence without an end"));
1207 dwarf2_complex_location_expr_complaint (void)
1209 complaint (&symfile_complaints
, _("location expression too complex"));
1213 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1216 complaint (&symfile_complaints
,
1217 _("const value length mismatch for '%s', got %d, expected %d"),
1222 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1224 complaint (&symfile_complaints
,
1225 _("debug info runs off end of %s section"
1227 section
->asection
->name
,
1228 bfd_get_filename (section
->asection
->owner
));
1232 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1234 complaint (&symfile_complaints
,
1235 _("macro debug info contains a "
1236 "malformed macro definition:\n`%s'"),
1241 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1243 complaint (&symfile_complaints
,
1244 _("invalid attribute class or form for '%s' in '%s'"),
1248 /* local function prototypes */
1250 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1252 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1255 static void dwarf2_find_base_address (struct die_info
*die
,
1256 struct dwarf2_cu
*cu
);
1258 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1260 static void scan_partial_symbols (struct partial_die_info
*,
1261 CORE_ADDR
*, CORE_ADDR
*,
1262 int, struct dwarf2_cu
*);
1264 static void add_partial_symbol (struct partial_die_info
*,
1265 struct dwarf2_cu
*);
1267 static void add_partial_namespace (struct partial_die_info
*pdi
,
1268 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1269 int need_pc
, struct dwarf2_cu
*cu
);
1271 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1272 CORE_ADDR
*highpc
, int need_pc
,
1273 struct dwarf2_cu
*cu
);
1275 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1276 struct dwarf2_cu
*cu
);
1278 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1279 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1280 int need_pc
, struct dwarf2_cu
*cu
);
1282 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1284 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1286 static struct abbrev_info
*abbrev_table_lookup_abbrev
1287 (const struct abbrev_table
*, unsigned int);
1289 static struct abbrev_table
*abbrev_table_read_table
1290 (struct dwarf2_section_info
*, sect_offset
);
1292 static void abbrev_table_free (struct abbrev_table
*);
1294 static void abbrev_table_free_cleanup (void *);
1296 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1297 struct dwarf2_section_info
*);
1299 static void dwarf2_free_abbrev_table (void *);
1301 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1303 static struct partial_die_info
*load_partial_dies
1304 (const struct die_reader_specs
*, gdb_byte
*, int);
1306 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1307 struct partial_die_info
*,
1308 struct abbrev_info
*,
1312 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1313 struct dwarf2_cu
*);
1315 static void fixup_partial_die (struct partial_die_info
*,
1316 struct dwarf2_cu
*);
1318 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1319 struct attribute
*, struct attr_abbrev
*,
1322 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1324 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1326 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1328 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1330 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1332 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1335 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1337 static LONGEST read_checked_initial_length_and_offset
1338 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1339 unsigned int *, unsigned int *);
1341 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1344 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1346 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1349 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1351 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1353 static char *read_indirect_string (bfd
*, gdb_byte
*,
1354 const struct comp_unit_head
*,
1357 static char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1359 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1361 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1363 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1366 static char *read_str_index (const struct die_reader_specs
*reader
,
1367 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1369 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1371 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1372 struct dwarf2_cu
*);
1374 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1377 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1378 struct dwarf2_cu
*cu
);
1380 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1382 static struct die_info
*die_specification (struct die_info
*die
,
1383 struct dwarf2_cu
**);
1385 static void free_line_header (struct line_header
*lh
);
1387 static void add_file_name (struct line_header
*, char *, unsigned int,
1388 unsigned int, unsigned int);
1390 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1391 struct dwarf2_cu
*cu
);
1393 static void dwarf_decode_lines (struct line_header
*, const char *,
1394 struct dwarf2_cu
*, struct partial_symtab
*,
1397 static void dwarf2_start_subfile (char *, const char *, const char *);
1399 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1400 char *, char *, CORE_ADDR
);
1402 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1403 struct dwarf2_cu
*);
1405 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1406 struct dwarf2_cu
*, struct symbol
*);
1408 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1409 struct dwarf2_cu
*);
1411 static void dwarf2_const_value_attr (struct attribute
*attr
,
1414 struct obstack
*obstack
,
1415 struct dwarf2_cu
*cu
, LONGEST
*value
,
1417 struct dwarf2_locexpr_baton
**baton
);
1419 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1421 static int need_gnat_info (struct dwarf2_cu
*);
1423 static struct type
*die_descriptive_type (struct die_info
*,
1424 struct dwarf2_cu
*);
1426 static void set_descriptive_type (struct type
*, struct die_info
*,
1427 struct dwarf2_cu
*);
1429 static struct type
*die_containing_type (struct die_info
*,
1430 struct dwarf2_cu
*);
1432 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1433 struct dwarf2_cu
*);
1435 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1437 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1439 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1441 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1442 const char *suffix
, int physname
,
1443 struct dwarf2_cu
*cu
);
1445 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1447 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1449 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1451 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1453 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1455 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1456 struct dwarf2_cu
*, struct partial_symtab
*);
1458 static int dwarf2_get_pc_bounds (struct die_info
*,
1459 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1460 struct partial_symtab
*);
1462 static void get_scope_pc_bounds (struct die_info
*,
1463 CORE_ADDR
*, CORE_ADDR
*,
1464 struct dwarf2_cu
*);
1466 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1467 CORE_ADDR
, struct dwarf2_cu
*);
1469 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1470 struct dwarf2_cu
*);
1472 static void dwarf2_attach_fields_to_type (struct field_info
*,
1473 struct type
*, struct dwarf2_cu
*);
1475 static void dwarf2_add_member_fn (struct field_info
*,
1476 struct die_info
*, struct type
*,
1477 struct dwarf2_cu
*);
1479 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1481 struct dwarf2_cu
*);
1483 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1485 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1487 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1489 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1491 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1493 static struct type
*read_module_type (struct die_info
*die
,
1494 struct dwarf2_cu
*cu
);
1496 static const char *namespace_name (struct die_info
*die
,
1497 int *is_anonymous
, struct dwarf2_cu
*);
1499 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1501 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1503 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1504 struct dwarf2_cu
*);
1506 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1508 gdb_byte
**new_info_ptr
,
1509 struct die_info
*parent
);
1511 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1513 gdb_byte
**new_info_ptr
,
1514 struct die_info
*parent
);
1516 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1517 struct die_info
**, gdb_byte
*, int *, int);
1519 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1520 struct die_info
**, gdb_byte
*, int *);
1522 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1524 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1527 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1529 static const char *dwarf2_full_name (char *name
,
1530 struct die_info
*die
,
1531 struct dwarf2_cu
*cu
);
1533 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1534 struct dwarf2_cu
**);
1536 static const char *dwarf_tag_name (unsigned int);
1538 static const char *dwarf_attr_name (unsigned int);
1540 static const char *dwarf_form_name (unsigned int);
1542 static char *dwarf_bool_name (unsigned int);
1544 static const char *dwarf_type_encoding_name (unsigned int);
1546 static struct die_info
*sibling_die (struct die_info
*);
1548 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1550 static void dump_die_for_error (struct die_info
*);
1552 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1555 /*static*/ void dump_die (struct die_info
*, int max_level
);
1557 static void store_in_ref_table (struct die_info
*,
1558 struct dwarf2_cu
*);
1560 static int is_ref_attr (struct attribute
*);
1562 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1564 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1566 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1568 struct dwarf2_cu
**);
1570 static struct die_info
*follow_die_ref (struct die_info
*,
1572 struct dwarf2_cu
**);
1574 static struct die_info
*follow_die_sig (struct die_info
*,
1576 struct dwarf2_cu
**);
1578 static struct signatured_type
*lookup_signatured_type_at_offset
1579 (struct objfile
*objfile
,
1580 struct dwarf2_section_info
*section
, sect_offset offset
);
1582 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1584 static void read_signatured_type (struct signatured_type
*);
1586 static struct type_unit_group
*get_type_unit_group
1587 (struct dwarf2_cu
*, struct attribute
*);
1589 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1591 /* memory allocation interface */
1593 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1595 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1597 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1600 static int attr_form_is_block (struct attribute
*);
1602 static int attr_form_is_section_offset (struct attribute
*);
1604 static int attr_form_is_constant (struct attribute
*);
1606 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1607 struct dwarf2_loclist_baton
*baton
,
1608 struct attribute
*attr
);
1610 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1612 struct dwarf2_cu
*cu
);
1614 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1616 struct abbrev_info
*abbrev
);
1618 static void free_stack_comp_unit (void *);
1620 static hashval_t
partial_die_hash (const void *item
);
1622 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1624 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1625 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1627 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1628 struct dwarf2_per_cu_data
*per_cu
);
1630 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1631 struct die_info
*comp_unit_die
,
1632 enum language pretend_language
);
1634 static void free_heap_comp_unit (void *);
1636 static void free_cached_comp_units (void *);
1638 static void age_cached_comp_units (void);
1640 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1642 static struct type
*set_die_type (struct die_info
*, struct type
*,
1643 struct dwarf2_cu
*);
1645 static void create_all_comp_units (struct objfile
*);
1647 static int create_all_type_units (struct objfile
*);
1649 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1652 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1655 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1658 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1659 struct dwarf2_per_cu_data
*);
1661 static void dwarf2_mark (struct dwarf2_cu
*);
1663 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1665 static struct type
*get_die_type_at_offset (sect_offset
,
1666 struct dwarf2_per_cu_data
*per_cu
);
1668 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1670 static void dwarf2_release_queue (void *dummy
);
1672 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1673 enum language pretend_language
);
1675 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1676 struct dwarf2_per_cu_data
*per_cu
,
1677 enum language pretend_language
);
1679 static void process_queue (void);
1681 static void find_file_and_directory (struct die_info
*die
,
1682 struct dwarf2_cu
*cu
,
1683 char **name
, char **comp_dir
);
1685 static char *file_full_name (int file
, struct line_header
*lh
,
1686 const char *comp_dir
);
1688 static gdb_byte
*read_and_check_comp_unit_head
1689 (struct comp_unit_head
*header
,
1690 struct dwarf2_section_info
*section
,
1691 struct dwarf2_section_info
*abbrev_section
, gdb_byte
*info_ptr
,
1692 int is_debug_types_section
);
1694 static void init_cutu_and_read_dies
1695 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1696 int use_existing_cu
, int keep
,
1697 die_reader_func_ftype
*die_reader_func
, void *data
);
1699 static void init_cutu_and_read_dies_simple
1700 (struct dwarf2_per_cu_data
*this_cu
,
1701 die_reader_func_ftype
*die_reader_func
, void *data
);
1703 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1705 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1707 static struct dwo_unit
*lookup_dwo_comp_unit
1708 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1710 static struct dwo_unit
*lookup_dwo_type_unit
1711 (struct signatured_type
*, const char *, const char *);
1713 static void free_dwo_file_cleanup (void *);
1715 static void process_cu_includes (void);
1717 static void check_producer (struct dwarf2_cu
*cu
);
1721 /* Convert VALUE between big- and little-endian. */
1723 byte_swap (offset_type value
)
1727 result
= (value
& 0xff) << 24;
1728 result
|= (value
& 0xff00) << 8;
1729 result
|= (value
& 0xff0000) >> 8;
1730 result
|= (value
& 0xff000000) >> 24;
1734 #define MAYBE_SWAP(V) byte_swap (V)
1737 #define MAYBE_SWAP(V) (V)
1738 #endif /* WORDS_BIGENDIAN */
1740 /* The suffix for an index file. */
1741 #define INDEX_SUFFIX ".gdb-index"
1743 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1744 struct dwarf2_cu
*cu
);
1746 /* Try to locate the sections we need for DWARF 2 debugging
1747 information and return true if we have enough to do something.
1748 NAMES points to the dwarf2 section names, or is NULL if the standard
1749 ELF names are used. */
1752 dwarf2_has_info (struct objfile
*objfile
,
1753 const struct dwarf2_debug_sections
*names
)
1755 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1756 if (!dwarf2_per_objfile
)
1758 /* Initialize per-objfile state. */
1759 struct dwarf2_per_objfile
*data
1760 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1762 memset (data
, 0, sizeof (*data
));
1763 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1764 dwarf2_per_objfile
= data
;
1766 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1768 dwarf2_per_objfile
->objfile
= objfile
;
1770 return (dwarf2_per_objfile
->info
.asection
!= NULL
1771 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1774 /* When loading sections, we look either for uncompressed section or for
1775 compressed section names. */
1778 section_is_p (const char *section_name
,
1779 const struct dwarf2_section_names
*names
)
1781 if (names
->normal
!= NULL
1782 && strcmp (section_name
, names
->normal
) == 0)
1784 if (names
->compressed
!= NULL
1785 && strcmp (section_name
, names
->compressed
) == 0)
1790 /* This function is mapped across the sections and remembers the
1791 offset and size of each of the debugging sections we are interested
1795 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1797 const struct dwarf2_debug_sections
*names
;
1798 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1801 names
= &dwarf2_elf_names
;
1803 names
= (const struct dwarf2_debug_sections
*) vnames
;
1805 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1808 else if (section_is_p (sectp
->name
, &names
->info
))
1810 dwarf2_per_objfile
->info
.asection
= sectp
;
1811 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1813 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1815 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1816 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1818 else if (section_is_p (sectp
->name
, &names
->line
))
1820 dwarf2_per_objfile
->line
.asection
= sectp
;
1821 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1823 else if (section_is_p (sectp
->name
, &names
->loc
))
1825 dwarf2_per_objfile
->loc
.asection
= sectp
;
1826 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1828 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1830 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1831 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1833 else if (section_is_p (sectp
->name
, &names
->macro
))
1835 dwarf2_per_objfile
->macro
.asection
= sectp
;
1836 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1838 else if (section_is_p (sectp
->name
, &names
->str
))
1840 dwarf2_per_objfile
->str
.asection
= sectp
;
1841 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1843 else if (section_is_p (sectp
->name
, &names
->addr
))
1845 dwarf2_per_objfile
->addr
.asection
= sectp
;
1846 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1848 else if (section_is_p (sectp
->name
, &names
->frame
))
1850 dwarf2_per_objfile
->frame
.asection
= sectp
;
1851 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1853 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1855 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1856 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1858 else if (section_is_p (sectp
->name
, &names
->ranges
))
1860 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1861 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1863 else if (section_is_p (sectp
->name
, &names
->types
))
1865 struct dwarf2_section_info type_section
;
1867 memset (&type_section
, 0, sizeof (type_section
));
1868 type_section
.asection
= sectp
;
1869 type_section
.size
= bfd_get_section_size (sectp
);
1871 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1874 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1876 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1877 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1880 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1881 && bfd_section_vma (abfd
, sectp
) == 0)
1882 dwarf2_per_objfile
->has_section_at_zero
= 1;
1885 /* A helper function that decides whether a section is empty,
1889 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1891 return info
->asection
== NULL
|| info
->size
== 0;
1894 /* Read the contents of the section INFO.
1895 OBJFILE is the main object file, but not necessarily the file where
1896 the section comes from. E.g., for DWO files INFO->asection->owner
1897 is the bfd of the DWO file.
1898 If the section is compressed, uncompress it before returning. */
1901 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1903 asection
*sectp
= info
->asection
;
1905 gdb_byte
*buf
, *retbuf
;
1906 unsigned char header
[4];
1910 info
->buffer
= NULL
;
1913 if (dwarf2_section_empty_p (info
))
1916 abfd
= sectp
->owner
;
1918 /* If the section has relocations, we must read it ourselves.
1919 Otherwise we attach it to the BFD. */
1920 if ((sectp
->flags
& SEC_RELOC
) == 0)
1922 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1924 /* We have to cast away const here for historical reasons.
1925 Fixing dwarf2read to be const-correct would be quite nice. */
1926 info
->buffer
= (gdb_byte
*) bytes
;
1930 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1933 /* When debugging .o files, we may need to apply relocations; see
1934 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1935 We never compress sections in .o files, so we only need to
1936 try this when the section is not compressed. */
1937 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1940 info
->buffer
= retbuf
;
1944 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1945 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1946 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1947 bfd_get_filename (abfd
));
1950 /* A helper function that returns the size of a section in a safe way.
1951 If you are positive that the section has been read before using the
1952 size, then it is safe to refer to the dwarf2_section_info object's
1953 "size" field directly. In other cases, you must call this
1954 function, because for compressed sections the size field is not set
1955 correctly until the section has been read. */
1957 static bfd_size_type
1958 dwarf2_section_size (struct objfile
*objfile
,
1959 struct dwarf2_section_info
*info
)
1962 dwarf2_read_section (objfile
, info
);
1966 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1970 dwarf2_get_section_info (struct objfile
*objfile
,
1971 enum dwarf2_section_enum sect
,
1972 asection
**sectp
, gdb_byte
**bufp
,
1973 bfd_size_type
*sizep
)
1975 struct dwarf2_per_objfile
*data
1976 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1977 struct dwarf2_section_info
*info
;
1979 /* We may see an objfile without any DWARF, in which case we just
1990 case DWARF2_DEBUG_FRAME
:
1991 info
= &data
->frame
;
1993 case DWARF2_EH_FRAME
:
1994 info
= &data
->eh_frame
;
1997 gdb_assert_not_reached ("unexpected section");
2000 dwarf2_read_section (objfile
, info
);
2002 *sectp
= info
->asection
;
2003 *bufp
= info
->buffer
;
2004 *sizep
= info
->size
;
2007 /* A helper function to find the sections for a .dwz file. */
2010 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2012 struct dwz_file
*dwz_file
= arg
;
2014 /* Note that we only support the standard ELF names, because .dwz
2015 is ELF-only (at the time of writing). */
2016 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2018 dwz_file
->abbrev
.asection
= sectp
;
2019 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2021 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2023 dwz_file
->info
.asection
= sectp
;
2024 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2026 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2028 dwz_file
->str
.asection
= sectp
;
2029 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2031 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2033 dwz_file
->line
.asection
= sectp
;
2034 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2036 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2038 dwz_file
->macro
.asection
= sectp
;
2039 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2041 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2043 dwz_file
->gdb_index
.asection
= sectp
;
2044 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2048 /* Open the separate '.dwz' debug file, if needed. Error if the file
2051 static struct dwz_file
*
2052 dwarf2_get_dwz_file (void)
2054 bfd
*abfd
, *dwz_bfd
;
2057 struct cleanup
*cleanup
;
2058 const char *filename
;
2059 struct dwz_file
*result
;
2061 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2062 return dwarf2_per_objfile
->dwz_file
;
2064 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
2065 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
2066 if (section
== NULL
)
2067 error (_("could not find '.gnu_debugaltlink' section"));
2068 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
2069 error (_("could not read '.gnu_debugaltlink' section: %s"),
2070 bfd_errmsg (bfd_get_error ()));
2071 cleanup
= make_cleanup (xfree
, data
);
2074 if (!IS_ABSOLUTE_PATH (filename
))
2076 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
2079 make_cleanup (xfree
, abs
);
2080 abs
= ldirname (abs
);
2081 make_cleanup (xfree
, abs
);
2083 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2084 make_cleanup (xfree
, rel
);
2088 /* The format is just a NUL-terminated file name, followed by the
2089 build-id. For now, though, we ignore the build-id. */
2090 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2091 if (dwz_bfd
== NULL
)
2092 error (_("could not read '%s': %s"), filename
,
2093 bfd_errmsg (bfd_get_error ()));
2095 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2097 gdb_bfd_unref (dwz_bfd
);
2098 error (_("file '%s' was not usable: %s"), filename
,
2099 bfd_errmsg (bfd_get_error ()));
2102 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2104 result
->dwz_bfd
= dwz_bfd
;
2106 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2108 do_cleanups (cleanup
);
2113 /* DWARF quick_symbols_functions support. */
2115 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2116 unique line tables, so we maintain a separate table of all .debug_line
2117 derived entries to support the sharing.
2118 All the quick functions need is the list of file names. We discard the
2119 line_header when we're done and don't need to record it here. */
2120 struct quick_file_names
2122 /* The data used to construct the hash key. */
2123 struct stmt_list_hash hash
;
2125 /* The number of entries in file_names, real_names. */
2126 unsigned int num_file_names
;
2128 /* The file names from the line table, after being run through
2130 const char **file_names
;
2132 /* The file names from the line table after being run through
2133 gdb_realpath. These are computed lazily. */
2134 const char **real_names
;
2137 /* When using the index (and thus not using psymtabs), each CU has an
2138 object of this type. This is used to hold information needed by
2139 the various "quick" methods. */
2140 struct dwarf2_per_cu_quick_data
2142 /* The file table. This can be NULL if there was no file table
2143 or it's currently not read in.
2144 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2145 struct quick_file_names
*file_names
;
2147 /* The corresponding symbol table. This is NULL if symbols for this
2148 CU have not yet been read. */
2149 struct symtab
*symtab
;
2151 /* A temporary mark bit used when iterating over all CUs in
2152 expand_symtabs_matching. */
2153 unsigned int mark
: 1;
2155 /* True if we've tried to read the file table and found there isn't one.
2156 There will be no point in trying to read it again next time. */
2157 unsigned int no_file_data
: 1;
2160 /* Utility hash function for a stmt_list_hash. */
2163 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2167 if (stmt_list_hash
->dwo_unit
!= NULL
)
2168 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2169 v
+= stmt_list_hash
->line_offset
.sect_off
;
2173 /* Utility equality function for a stmt_list_hash. */
2176 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2177 const struct stmt_list_hash
*rhs
)
2179 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2181 if (lhs
->dwo_unit
!= NULL
2182 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2185 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2188 /* Hash function for a quick_file_names. */
2191 hash_file_name_entry (const void *e
)
2193 const struct quick_file_names
*file_data
= e
;
2195 return hash_stmt_list_entry (&file_data
->hash
);
2198 /* Equality function for a quick_file_names. */
2201 eq_file_name_entry (const void *a
, const void *b
)
2203 const struct quick_file_names
*ea
= a
;
2204 const struct quick_file_names
*eb
= b
;
2206 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2209 /* Delete function for a quick_file_names. */
2212 delete_file_name_entry (void *e
)
2214 struct quick_file_names
*file_data
= e
;
2217 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2219 xfree ((void*) file_data
->file_names
[i
]);
2220 if (file_data
->real_names
)
2221 xfree ((void*) file_data
->real_names
[i
]);
2224 /* The space for the struct itself lives on objfile_obstack,
2225 so we don't free it here. */
2228 /* Create a quick_file_names hash table. */
2231 create_quick_file_names_table (unsigned int nr_initial_entries
)
2233 return htab_create_alloc (nr_initial_entries
,
2234 hash_file_name_entry
, eq_file_name_entry
,
2235 delete_file_name_entry
, xcalloc
, xfree
);
2238 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2239 have to be created afterwards. You should call age_cached_comp_units after
2240 processing PER_CU->CU. dw2_setup must have been already called. */
2243 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2245 if (per_cu
->is_debug_types
)
2246 load_full_type_unit (per_cu
);
2248 load_full_comp_unit (per_cu
, language_minimal
);
2250 gdb_assert (per_cu
->cu
!= NULL
);
2252 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2255 /* Read in the symbols for PER_CU. */
2258 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2260 struct cleanup
*back_to
;
2262 /* Skip type_unit_groups, reading the type units they contain
2263 is handled elsewhere. */
2264 if (IS_TYPE_UNIT_GROUP (per_cu
))
2267 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2269 if (dwarf2_per_objfile
->using_index
2270 ? per_cu
->v
.quick
->symtab
== NULL
2271 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2273 queue_comp_unit (per_cu
, language_minimal
);
2279 /* Age the cache, releasing compilation units that have not
2280 been used recently. */
2281 age_cached_comp_units ();
2283 do_cleanups (back_to
);
2286 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2287 the objfile from which this CU came. Returns the resulting symbol
2290 static struct symtab
*
2291 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2293 gdb_assert (dwarf2_per_objfile
->using_index
);
2294 if (!per_cu
->v
.quick
->symtab
)
2296 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2297 increment_reading_symtab ();
2298 dw2_do_instantiate_symtab (per_cu
);
2299 process_cu_includes ();
2300 do_cleanups (back_to
);
2302 return per_cu
->v
.quick
->symtab
;
2305 /* Return the CU given its index.
2307 This is intended for loops like:
2309 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2310 + dwarf2_per_objfile->n_type_units); ++i)
2312 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2318 static struct dwarf2_per_cu_data
*
2319 dw2_get_cu (int index
)
2321 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2323 index
-= dwarf2_per_objfile
->n_comp_units
;
2324 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2325 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2328 return dwarf2_per_objfile
->all_comp_units
[index
];
2331 /* Return the primary CU given its index.
2332 The difference between this function and dw2_get_cu is in the handling
2333 of type units (TUs). Here we return the type_unit_group object.
2335 This is intended for loops like:
2337 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2338 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2340 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2346 static struct dwarf2_per_cu_data
*
2347 dw2_get_primary_cu (int index
)
2349 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2351 index
-= dwarf2_per_objfile
->n_comp_units
;
2352 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2353 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2356 return dwarf2_per_objfile
->all_comp_units
[index
];
2359 /* A helper for create_cus_from_index that handles a given list of
2363 create_cus_from_index_list (struct objfile
*objfile
,
2364 const gdb_byte
*cu_list
, offset_type n_elements
,
2365 struct dwarf2_section_info
*section
,
2371 for (i
= 0; i
< n_elements
; i
+= 2)
2373 struct dwarf2_per_cu_data
*the_cu
;
2374 ULONGEST offset
, length
;
2376 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2377 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2378 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2381 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2382 struct dwarf2_per_cu_data
);
2383 the_cu
->offset
.sect_off
= offset
;
2384 the_cu
->length
= length
;
2385 the_cu
->objfile
= objfile
;
2386 the_cu
->info_or_types_section
= section
;
2387 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2388 struct dwarf2_per_cu_quick_data
);
2389 the_cu
->is_dwz
= is_dwz
;
2390 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2394 /* Read the CU list from the mapped index, and use it to create all
2395 the CU objects for this objfile. */
2398 create_cus_from_index (struct objfile
*objfile
,
2399 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2400 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2402 struct dwz_file
*dwz
;
2404 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2405 dwarf2_per_objfile
->all_comp_units
2406 = obstack_alloc (&objfile
->objfile_obstack
,
2407 dwarf2_per_objfile
->n_comp_units
2408 * sizeof (struct dwarf2_per_cu_data
*));
2410 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2411 &dwarf2_per_objfile
->info
, 0, 0);
2413 if (dwz_elements
== 0)
2416 dwz
= dwarf2_get_dwz_file ();
2417 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2418 cu_list_elements
/ 2);
2421 /* Create the signatured type hash table from the index. */
2424 create_signatured_type_table_from_index (struct objfile
*objfile
,
2425 struct dwarf2_section_info
*section
,
2426 const gdb_byte
*bytes
,
2427 offset_type elements
)
2430 htab_t sig_types_hash
;
2432 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2433 dwarf2_per_objfile
->all_type_units
2434 = obstack_alloc (&objfile
->objfile_obstack
,
2435 dwarf2_per_objfile
->n_type_units
2436 * sizeof (struct signatured_type
*));
2438 sig_types_hash
= allocate_signatured_type_table (objfile
);
2440 for (i
= 0; i
< elements
; i
+= 3)
2442 struct signatured_type
*sig_type
;
2443 ULONGEST offset
, type_offset_in_tu
, signature
;
2446 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2447 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2448 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2450 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2453 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2454 struct signatured_type
);
2455 sig_type
->signature
= signature
;
2456 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2457 sig_type
->per_cu
.is_debug_types
= 1;
2458 sig_type
->per_cu
.info_or_types_section
= section
;
2459 sig_type
->per_cu
.offset
.sect_off
= offset
;
2460 sig_type
->per_cu
.objfile
= objfile
;
2461 sig_type
->per_cu
.v
.quick
2462 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2463 struct dwarf2_per_cu_quick_data
);
2465 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2468 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2471 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2474 /* Read the address map data from the mapped index, and use it to
2475 populate the objfile's psymtabs_addrmap. */
2478 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2480 const gdb_byte
*iter
, *end
;
2481 struct obstack temp_obstack
;
2482 struct addrmap
*mutable_map
;
2483 struct cleanup
*cleanup
;
2486 obstack_init (&temp_obstack
);
2487 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2488 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2490 iter
= index
->address_table
;
2491 end
= iter
+ index
->address_table_size
;
2493 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2497 ULONGEST hi
, lo
, cu_index
;
2498 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2500 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2502 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2505 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2506 dw2_get_cu (cu_index
));
2509 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2510 &objfile
->objfile_obstack
);
2511 do_cleanups (cleanup
);
2514 /* The hash function for strings in the mapped index. This is the same as
2515 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2516 implementation. This is necessary because the hash function is tied to the
2517 format of the mapped index file. The hash values do not have to match with
2520 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2523 mapped_index_string_hash (int index_version
, const void *p
)
2525 const unsigned char *str
= (const unsigned char *) p
;
2529 while ((c
= *str
++) != 0)
2531 if (index_version
>= 5)
2533 r
= r
* 67 + c
- 113;
2539 /* Find a slot in the mapped index INDEX for the object named NAME.
2540 If NAME is found, set *VEC_OUT to point to the CU vector in the
2541 constant pool and return 1. If NAME cannot be found, return 0. */
2544 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2545 offset_type
**vec_out
)
2547 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2549 offset_type slot
, step
;
2550 int (*cmp
) (const char *, const char *);
2552 if (current_language
->la_language
== language_cplus
2553 || current_language
->la_language
== language_java
2554 || current_language
->la_language
== language_fortran
)
2556 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2558 const char *paren
= strchr (name
, '(');
2564 dup
= xmalloc (paren
- name
+ 1);
2565 memcpy (dup
, name
, paren
- name
);
2566 dup
[paren
- name
] = 0;
2568 make_cleanup (xfree
, dup
);
2573 /* Index version 4 did not support case insensitive searches. But the
2574 indices for case insensitive languages are built in lowercase, therefore
2575 simulate our NAME being searched is also lowercased. */
2576 hash
= mapped_index_string_hash ((index
->version
== 4
2577 && case_sensitivity
== case_sensitive_off
2578 ? 5 : index
->version
),
2581 slot
= hash
& (index
->symbol_table_slots
- 1);
2582 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2583 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2587 /* Convert a slot number to an offset into the table. */
2588 offset_type i
= 2 * slot
;
2590 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2592 do_cleanups (back_to
);
2596 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2597 if (!cmp (name
, str
))
2599 *vec_out
= (offset_type
*) (index
->constant_pool
2600 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2601 do_cleanups (back_to
);
2605 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2609 /* A helper function that reads the .gdb_index from SECTION and fills
2610 in MAP. FILENAME is the name of the file containing the section;
2611 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2612 ok to use deprecated sections.
2614 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2615 out parameters that are filled in with information about the CU and
2616 TU lists in the section.
2618 Returns 1 if all went well, 0 otherwise. */
2621 read_index_from_section (struct objfile
*objfile
,
2622 const char *filename
,
2624 struct dwarf2_section_info
*section
,
2625 struct mapped_index
*map
,
2626 const gdb_byte
**cu_list
,
2627 offset_type
*cu_list_elements
,
2628 const gdb_byte
**types_list
,
2629 offset_type
*types_list_elements
)
2632 offset_type version
;
2633 offset_type
*metadata
;
2636 if (dwarf2_section_empty_p (section
))
2639 /* Older elfutils strip versions could keep the section in the main
2640 executable while splitting it for the separate debug info file. */
2641 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2644 dwarf2_read_section (objfile
, section
);
2646 addr
= section
->buffer
;
2647 /* Version check. */
2648 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2649 /* Versions earlier than 3 emitted every copy of a psymbol. This
2650 causes the index to behave very poorly for certain requests. Version 3
2651 contained incomplete addrmap. So, it seems better to just ignore such
2655 static int warning_printed
= 0;
2656 if (!warning_printed
)
2658 warning (_("Skipping obsolete .gdb_index section in %s."),
2660 warning_printed
= 1;
2664 /* Index version 4 uses a different hash function than index version
2667 Versions earlier than 6 did not emit psymbols for inlined
2668 functions. Using these files will cause GDB not to be able to
2669 set breakpoints on inlined functions by name, so we ignore these
2670 indices unless the user has done
2671 "set use-deprecated-index-sections on". */
2672 if (version
< 6 && !deprecated_ok
)
2674 static int warning_printed
= 0;
2675 if (!warning_printed
)
2678 Skipping deprecated .gdb_index section in %s.\n\
2679 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2680 to use the section anyway."),
2682 warning_printed
= 1;
2686 /* Indexes with higher version than the one supported by GDB may be no
2687 longer backward compatible. */
2691 map
->version
= version
;
2692 map
->total_size
= section
->size
;
2694 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2697 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2698 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2702 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2703 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2704 - MAYBE_SWAP (metadata
[i
]))
2708 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2709 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2710 - MAYBE_SWAP (metadata
[i
]));
2713 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2714 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2715 - MAYBE_SWAP (metadata
[i
]))
2716 / (2 * sizeof (offset_type
)));
2719 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2725 /* Read the index file. If everything went ok, initialize the "quick"
2726 elements of all the CUs and return 1. Otherwise, return 0. */
2729 dwarf2_read_index (struct objfile
*objfile
)
2731 struct mapped_index local_map
, *map
;
2732 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2733 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2735 if (!read_index_from_section (objfile
, objfile
->name
,
2736 use_deprecated_index_sections
,
2737 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2738 &cu_list
, &cu_list_elements
,
2739 &types_list
, &types_list_elements
))
2742 /* Don't use the index if it's empty. */
2743 if (local_map
.symbol_table_slots
== 0)
2746 /* If there is a .dwz file, read it so we can get its CU list as
2748 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2750 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2751 struct mapped_index dwz_map
;
2752 const gdb_byte
*dwz_types_ignore
;
2753 offset_type dwz_types_elements_ignore
;
2755 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2757 &dwz
->gdb_index
, &dwz_map
,
2758 &dwz_list
, &dwz_list_elements
,
2760 &dwz_types_elements_ignore
))
2762 warning (_("could not read '.gdb_index' section from %s; skipping"),
2763 bfd_get_filename (dwz
->dwz_bfd
));
2768 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
2771 if (types_list_elements
)
2773 struct dwarf2_section_info
*section
;
2775 /* We can only handle a single .debug_types when we have an
2777 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2780 section
= VEC_index (dwarf2_section_info_def
,
2781 dwarf2_per_objfile
->types
, 0);
2783 create_signatured_type_table_from_index (objfile
, section
, types_list
,
2784 types_list_elements
);
2787 create_addrmap_from_index (objfile
, &local_map
);
2789 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2792 dwarf2_per_objfile
->index_table
= map
;
2793 dwarf2_per_objfile
->using_index
= 1;
2794 dwarf2_per_objfile
->quick_file_names_table
=
2795 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2800 /* A helper for the "quick" functions which sets the global
2801 dwarf2_per_objfile according to OBJFILE. */
2804 dw2_setup (struct objfile
*objfile
)
2806 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2807 gdb_assert (dwarf2_per_objfile
);
2810 /* Reader function for dw2_build_type_unit_groups. */
2813 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2815 struct die_info
*type_unit_die
,
2819 struct dwarf2_cu
*cu
= reader
->cu
;
2820 struct attribute
*attr
;
2821 struct type_unit_group
*tu_group
;
2823 gdb_assert (data
== NULL
);
2828 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2829 /* Call this for its side-effect of creating the associated
2830 struct type_unit_group if it doesn't already exist. */
2831 tu_group
= get_type_unit_group (cu
, attr
);
2834 /* Build dwarf2_per_objfile->type_unit_groups.
2835 This function may be called multiple times. */
2838 dw2_build_type_unit_groups (void)
2840 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2841 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2844 /* die_reader_func for dw2_get_file_names. */
2847 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2849 struct die_info
*comp_unit_die
,
2853 struct dwarf2_cu
*cu
= reader
->cu
;
2854 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2855 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2856 struct dwarf2_per_cu_data
*lh_cu
;
2857 struct line_header
*lh
;
2858 struct attribute
*attr
;
2860 char *name
, *comp_dir
;
2862 struct quick_file_names
*qfn
;
2863 unsigned int line_offset
;
2865 /* Our callers never want to match partial units -- instead they
2866 will match the enclosing full CU. */
2867 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2869 this_cu
->v
.quick
->no_file_data
= 1;
2873 /* If we're reading the line header for TUs, store it in the "per_cu"
2875 if (this_cu
->is_debug_types
)
2877 struct type_unit_group
*tu_group
= data
;
2879 gdb_assert (tu_group
!= NULL
);
2880 lh_cu
= &tu_group
->per_cu
;
2889 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2892 struct quick_file_names find_entry
;
2894 line_offset
= DW_UNSND (attr
);
2896 /* We may have already read in this line header (TU line header sharing).
2897 If we have we're done. */
2898 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2899 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2900 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2901 &find_entry
, INSERT
);
2904 lh_cu
->v
.quick
->file_names
= *slot
;
2908 lh
= dwarf_decode_line_header (line_offset
, cu
);
2912 lh_cu
->v
.quick
->no_file_data
= 1;
2916 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2917 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2918 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2919 gdb_assert (slot
!= NULL
);
2922 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2924 qfn
->num_file_names
= lh
->num_file_names
;
2925 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2926 lh
->num_file_names
* sizeof (char *));
2927 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2928 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2929 qfn
->real_names
= NULL
;
2931 free_line_header (lh
);
2933 lh_cu
->v
.quick
->file_names
= qfn
;
2936 /* A helper for the "quick" functions which attempts to read the line
2937 table for THIS_CU. */
2939 static struct quick_file_names
*
2940 dw2_get_file_names (struct objfile
*objfile
,
2941 struct dwarf2_per_cu_data
*this_cu
)
2943 /* For TUs this should only be called on the parent group. */
2944 if (this_cu
->is_debug_types
)
2945 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2947 if (this_cu
->v
.quick
->file_names
!= NULL
)
2948 return this_cu
->v
.quick
->file_names
;
2949 /* If we know there is no line data, no point in looking again. */
2950 if (this_cu
->v
.quick
->no_file_data
)
2953 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2954 in the stub for CUs, there's is no need to lookup the DWO file.
2955 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2957 if (this_cu
->is_debug_types
)
2959 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2961 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2962 dw2_get_file_names_reader
, tu_group
);
2965 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2967 if (this_cu
->v
.quick
->no_file_data
)
2969 return this_cu
->v
.quick
->file_names
;
2972 /* A helper for the "quick" functions which computes and caches the
2973 real path for a given file name from the line table. */
2976 dw2_get_real_path (struct objfile
*objfile
,
2977 struct quick_file_names
*qfn
, int index
)
2979 if (qfn
->real_names
== NULL
)
2980 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2981 qfn
->num_file_names
, sizeof (char *));
2983 if (qfn
->real_names
[index
] == NULL
)
2984 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2986 return qfn
->real_names
[index
];
2989 static struct symtab
*
2990 dw2_find_last_source_symtab (struct objfile
*objfile
)
2994 dw2_setup (objfile
);
2995 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2996 return dw2_instantiate_symtab (dw2_get_cu (index
));
2999 /* Traversal function for dw2_forget_cached_source_info. */
3002 dw2_free_cached_file_names (void **slot
, void *info
)
3004 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3006 if (file_data
->real_names
)
3010 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3012 xfree ((void*) file_data
->real_names
[i
]);
3013 file_data
->real_names
[i
] = NULL
;
3021 dw2_forget_cached_source_info (struct objfile
*objfile
)
3023 dw2_setup (objfile
);
3025 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3026 dw2_free_cached_file_names
, NULL
);
3029 /* Helper function for dw2_map_symtabs_matching_filename that expands
3030 the symtabs and calls the iterator. */
3033 dw2_map_expand_apply (struct objfile
*objfile
,
3034 struct dwarf2_per_cu_data
*per_cu
,
3036 const char *full_path
, const char *real_path
,
3037 int (*callback
) (struct symtab
*, void *),
3040 struct symtab
*last_made
= objfile
->symtabs
;
3042 /* Don't visit already-expanded CUs. */
3043 if (per_cu
->v
.quick
->symtab
)
3046 /* This may expand more than one symtab, and we want to iterate over
3048 dw2_instantiate_symtab (per_cu
);
3050 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
3051 objfile
->symtabs
, last_made
);
3054 /* Implementation of the map_symtabs_matching_filename method. */
3057 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3058 const char *full_path
, const char *real_path
,
3059 int (*callback
) (struct symtab
*, void *),
3063 const char *name_basename
= lbasename (name
);
3064 int name_len
= strlen (name
);
3065 int is_abs
= IS_ABSOLUTE_PATH (name
);
3067 dw2_setup (objfile
);
3069 dw2_build_type_unit_groups ();
3071 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3072 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3075 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3076 struct quick_file_names
*file_data
;
3078 /* We only need to look at symtabs not already expanded. */
3079 if (per_cu
->v
.quick
->symtab
)
3082 file_data
= dw2_get_file_names (objfile
, per_cu
);
3083 if (file_data
== NULL
)
3086 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3088 const char *this_name
= file_data
->file_names
[j
];
3090 if (FILENAME_CMP (name
, this_name
) == 0
3091 || (!is_abs
&& compare_filenames_for_search (this_name
,
3094 if (dw2_map_expand_apply (objfile
, per_cu
,
3095 name
, full_path
, real_path
,
3100 /* Before we invoke realpath, which can get expensive when many
3101 files are involved, do a quick comparison of the basenames. */
3102 if (! basenames_may_differ
3103 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3106 if (full_path
!= NULL
)
3108 const char *this_real_name
= dw2_get_real_path (objfile
,
3111 if (this_real_name
!= NULL
3112 && (FILENAME_CMP (full_path
, this_real_name
) == 0
3114 && compare_filenames_for_search (this_real_name
,
3117 if (dw2_map_expand_apply (objfile
, per_cu
,
3118 name
, full_path
, real_path
,
3124 if (real_path
!= NULL
)
3126 const char *this_real_name
= dw2_get_real_path (objfile
,
3129 if (this_real_name
!= NULL
3130 && (FILENAME_CMP (real_path
, this_real_name
) == 0
3132 && compare_filenames_for_search (this_real_name
,
3135 if (dw2_map_expand_apply (objfile
, per_cu
,
3136 name
, full_path
, real_path
,
3147 static struct symtab
*
3148 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3149 const char *name
, domain_enum domain
)
3151 /* We do all the work in the pre_expand_symtabs_matching hook
3156 /* A helper function that expands all symtabs that hold an object
3157 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
3158 symbols in block BLOCK_KIND. */
3161 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
3162 int want_specific_block
,
3163 enum block_enum block_kind
,
3164 const char *name
, domain_enum domain
)
3166 struct mapped_index
*index
;
3168 dw2_setup (objfile
);
3170 index
= dwarf2_per_objfile
->index_table
;
3172 /* index_table is NULL if OBJF_READNOW. */
3177 if (find_slot_in_mapped_hash (index
, name
, &vec
))
3179 offset_type i
, len
= MAYBE_SWAP (*vec
);
3180 for (i
= 0; i
< len
; ++i
)
3182 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
3183 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3184 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3185 int want_static
= block_kind
!= GLOBAL_BLOCK
;
3186 /* This value is only valid for index versions >= 7. */
3187 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3188 gdb_index_symbol_kind symbol_kind
=
3189 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3190 /* Only check the symbol attributes if they're present.
3191 Indices prior to version 7 don't record them,
3192 and indices >= 7 may elide them for certain symbols
3193 (gold does this). */
3195 (index
->version
>= 7
3196 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3199 && want_specific_block
3200 && want_static
!= is_static
)
3203 /* Only check the symbol's kind if it has one. */
3209 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3210 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3211 /* Some types are also in VAR_DOMAIN. */
3212 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3216 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3220 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3228 dw2_instantiate_symtab (per_cu
);
3235 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
3236 enum block_enum block_kind
, const char *name
,
3239 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
3243 dw2_print_stats (struct objfile
*objfile
)
3247 dw2_setup (objfile
);
3249 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3250 + dwarf2_per_objfile
->n_type_units
); ++i
)
3252 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3254 if (!per_cu
->v
.quick
->symtab
)
3257 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3261 dw2_dump (struct objfile
*objfile
)
3263 /* Nothing worth printing. */
3267 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3268 struct section_offsets
*delta
)
3270 /* There's nothing to relocate here. */
3274 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3275 const char *func_name
)
3277 /* Note: It doesn't matter what we pass for block_kind here. */
3278 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
3283 dw2_expand_all_symtabs (struct objfile
*objfile
)
3287 dw2_setup (objfile
);
3289 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3290 + dwarf2_per_objfile
->n_type_units
); ++i
)
3292 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3294 dw2_instantiate_symtab (per_cu
);
3299 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3300 const char *filename
)
3304 dw2_setup (objfile
);
3306 /* We don't need to consider type units here.
3307 This is only called for examining code, e.g. expand_line_sal.
3308 There can be an order of magnitude (or more) more type units
3309 than comp units, and we avoid them if we can. */
3311 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3314 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3315 struct quick_file_names
*file_data
;
3317 /* We only need to look at symtabs not already expanded. */
3318 if (per_cu
->v
.quick
->symtab
)
3321 file_data
= dw2_get_file_names (objfile
, per_cu
);
3322 if (file_data
== NULL
)
3325 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3327 const char *this_name
= file_data
->file_names
[j
];
3328 if (FILENAME_CMP (this_name
, filename
) == 0)
3330 dw2_instantiate_symtab (per_cu
);
3337 /* A helper function for dw2_find_symbol_file that finds the primary
3338 file name for a given CU. This is a die_reader_func. */
3341 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3343 struct die_info
*comp_unit_die
,
3347 const char **result_ptr
= data
;
3348 struct dwarf2_cu
*cu
= reader
->cu
;
3349 struct attribute
*attr
;
3351 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3355 *result_ptr
= DW_STRING (attr
);
3359 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3361 struct dwarf2_per_cu_data
*per_cu
;
3363 const char *filename
;
3365 dw2_setup (objfile
);
3367 /* index_table is NULL if OBJF_READNOW. */
3368 if (!dwarf2_per_objfile
->index_table
)
3372 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3374 struct blockvector
*bv
= BLOCKVECTOR (s
);
3375 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3376 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3379 return SYMBOL_SYMTAB (sym
)->filename
;
3384 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3388 /* Note that this just looks at the very first one named NAME -- but
3389 actually we are looking for a function. find_main_filename
3390 should be rewritten so that it doesn't require a custom hook. It
3391 could just use the ordinary symbol tables. */
3392 /* vec[0] is the length, which must always be >0. */
3393 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3395 if (per_cu
->v
.quick
->symtab
!= NULL
)
3396 return per_cu
->v
.quick
->symtab
->filename
;
3398 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3399 dw2_get_primary_filename_reader
, &filename
);
3405 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3406 struct objfile
*objfile
, int global
,
3407 int (*callback
) (struct block
*,
3408 struct symbol
*, void *),
3409 void *data
, symbol_compare_ftype
*match
,
3410 symbol_compare_ftype
*ordered_compare
)
3412 /* Currently unimplemented; used for Ada. The function can be called if the
3413 current language is Ada for a non-Ada objfile using GNU index. As Ada
3414 does not look for non-Ada symbols this function should just return. */
3418 dw2_expand_symtabs_matching
3419 (struct objfile
*objfile
,
3420 int (*file_matcher
) (const char *, void *),
3421 int (*name_matcher
) (const char *, void *),
3422 enum search_domain kind
,
3427 struct mapped_index
*index
;
3429 dw2_setup (objfile
);
3431 /* index_table is NULL if OBJF_READNOW. */
3432 if (!dwarf2_per_objfile
->index_table
)
3434 index
= dwarf2_per_objfile
->index_table
;
3436 if (file_matcher
!= NULL
)
3438 struct cleanup
*cleanup
;
3439 htab_t visited_found
, visited_not_found
;
3441 dw2_build_type_unit_groups ();
3443 visited_found
= htab_create_alloc (10,
3444 htab_hash_pointer
, htab_eq_pointer
,
3445 NULL
, xcalloc
, xfree
);
3446 cleanup
= make_cleanup_htab_delete (visited_found
);
3447 visited_not_found
= htab_create_alloc (10,
3448 htab_hash_pointer
, htab_eq_pointer
,
3449 NULL
, xcalloc
, xfree
);
3450 make_cleanup_htab_delete (visited_not_found
);
3452 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3453 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3456 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3457 struct quick_file_names
*file_data
;
3460 per_cu
->v
.quick
->mark
= 0;
3462 /* We only need to look at symtabs not already expanded. */
3463 if (per_cu
->v
.quick
->symtab
)
3466 file_data
= dw2_get_file_names (objfile
, per_cu
);
3467 if (file_data
== NULL
)
3470 if (htab_find (visited_not_found
, file_data
) != NULL
)
3472 else if (htab_find (visited_found
, file_data
) != NULL
)
3474 per_cu
->v
.quick
->mark
= 1;
3478 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3480 if (file_matcher (file_data
->file_names
[j
], data
))
3482 per_cu
->v
.quick
->mark
= 1;
3487 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3489 : visited_not_found
,
3494 do_cleanups (cleanup
);
3497 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3499 offset_type idx
= 2 * iter
;
3501 offset_type
*vec
, vec_len
, vec_idx
;
3503 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3506 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3508 if (! (*name_matcher
) (name
, data
))
3511 /* The name was matched, now expand corresponding CUs that were
3513 vec
= (offset_type
*) (index
->constant_pool
3514 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3515 vec_len
= MAYBE_SWAP (vec
[0]);
3516 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3518 struct dwarf2_per_cu_data
*per_cu
;
3519 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3520 gdb_index_symbol_kind symbol_kind
=
3521 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3522 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3524 /* Don't crash on bad data. */
3525 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3526 + dwarf2_per_objfile
->n_type_units
))
3529 /* Only check the symbol's kind if it has one.
3530 Indices prior to version 7 don't record it. */
3531 if (index
->version
>= 7)
3535 case VARIABLES_DOMAIN
:
3536 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3539 case FUNCTIONS_DOMAIN
:
3540 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3544 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3552 per_cu
= dw2_get_cu (cu_index
);
3553 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3554 dw2_instantiate_symtab (per_cu
);
3559 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3562 static struct symtab
*
3563 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3567 if (BLOCKVECTOR (symtab
) != NULL
3568 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3571 if (symtab
->includes
== NULL
)
3574 for (i
= 0; symtab
->includes
[i
]; ++i
)
3576 struct symtab
*s
= symtab
->includes
[i
];
3578 s
= recursively_find_pc_sect_symtab (s
, pc
);
3586 static struct symtab
*
3587 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3588 struct minimal_symbol
*msymbol
,
3590 struct obj_section
*section
,
3593 struct dwarf2_per_cu_data
*data
;
3594 struct symtab
*result
;
3596 dw2_setup (objfile
);
3598 if (!objfile
->psymtabs_addrmap
)
3601 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3605 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3606 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3607 paddress (get_objfile_arch (objfile
), pc
));
3609 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3610 gdb_assert (result
!= NULL
);
3615 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3616 void *data
, int need_fullname
)
3619 struct cleanup
*cleanup
;
3620 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3621 NULL
, xcalloc
, xfree
);
3623 cleanup
= make_cleanup_htab_delete (visited
);
3624 dw2_setup (objfile
);
3626 dw2_build_type_unit_groups ();
3628 /* We can ignore file names coming from already-expanded CUs. */
3629 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3630 + dwarf2_per_objfile
->n_type_units
); ++i
)
3632 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3634 if (per_cu
->v
.quick
->symtab
)
3636 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3639 *slot
= per_cu
->v
.quick
->file_names
;
3643 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3644 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3647 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3648 struct quick_file_names
*file_data
;
3651 /* We only need to look at symtabs not already expanded. */
3652 if (per_cu
->v
.quick
->symtab
)
3655 file_data
= dw2_get_file_names (objfile
, per_cu
);
3656 if (file_data
== NULL
)
3659 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3662 /* Already visited. */
3667 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3669 const char *this_real_name
;
3672 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3674 this_real_name
= NULL
;
3675 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3679 do_cleanups (cleanup
);
3683 dw2_has_symbols (struct objfile
*objfile
)
3688 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3691 dw2_find_last_source_symtab
,
3692 dw2_forget_cached_source_info
,
3693 dw2_map_symtabs_matching_filename
,
3695 dw2_pre_expand_symtabs_matching
,
3699 dw2_expand_symtabs_for_function
,
3700 dw2_expand_all_symtabs
,
3701 dw2_expand_symtabs_with_filename
,
3702 dw2_find_symbol_file
,
3703 dw2_map_matching_symbols
,
3704 dw2_expand_symtabs_matching
,
3705 dw2_find_pc_sect_symtab
,
3706 dw2_map_symbol_filenames
3709 /* Initialize for reading DWARF for this objfile. Return 0 if this
3710 file will use psymtabs, or 1 if using the GNU index. */
3713 dwarf2_initialize_objfile (struct objfile
*objfile
)
3715 /* If we're about to read full symbols, don't bother with the
3716 indices. In this case we also don't care if some other debug
3717 format is making psymtabs, because they are all about to be
3719 if ((objfile
->flags
& OBJF_READNOW
))
3723 dwarf2_per_objfile
->using_index
= 1;
3724 create_all_comp_units (objfile
);
3725 create_all_type_units (objfile
);
3726 dwarf2_per_objfile
->quick_file_names_table
=
3727 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3729 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3730 + dwarf2_per_objfile
->n_type_units
); ++i
)
3732 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3734 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3735 struct dwarf2_per_cu_quick_data
);
3738 /* Return 1 so that gdb sees the "quick" functions. However,
3739 these functions will be no-ops because we will have expanded
3744 if (dwarf2_read_index (objfile
))
3752 /* Build a partial symbol table. */
3755 dwarf2_build_psymtabs (struct objfile
*objfile
)
3757 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3759 init_psymbol_list (objfile
, 1024);
3762 dwarf2_build_psymtabs_hard (objfile
);
3765 /* Return the total length of the CU described by HEADER. */
3768 get_cu_length (const struct comp_unit_head
*header
)
3770 return header
->initial_length_size
+ header
->length
;
3773 /* Return TRUE if OFFSET is within CU_HEADER. */
3776 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3778 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3779 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3781 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3784 /* Find the base address of the compilation unit for range lists and
3785 location lists. It will normally be specified by DW_AT_low_pc.
3786 In DWARF-3 draft 4, the base address could be overridden by
3787 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3788 compilation units with discontinuous ranges. */
3791 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3793 struct attribute
*attr
;
3796 cu
->base_address
= 0;
3798 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3801 cu
->base_address
= DW_ADDR (attr
);
3806 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3809 cu
->base_address
= DW_ADDR (attr
);
3815 /* Read in the comp unit header information from the debug_info at info_ptr.
3816 NOTE: This leaves members offset, first_die_offset to be filled in
3820 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3821 gdb_byte
*info_ptr
, bfd
*abfd
)
3824 unsigned int bytes_read
;
3826 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3827 cu_header
->initial_length_size
= bytes_read
;
3828 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3829 info_ptr
+= bytes_read
;
3830 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3832 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3834 info_ptr
+= bytes_read
;
3835 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3837 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3838 if (signed_addr
< 0)
3839 internal_error (__FILE__
, __LINE__
,
3840 _("read_comp_unit_head: dwarf from non elf file"));
3841 cu_header
->signed_addr_p
= signed_addr
;
3846 /* Helper function that returns the proper abbrev section for
3849 static struct dwarf2_section_info
*
3850 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3852 struct dwarf2_section_info
*abbrev
;
3854 if (this_cu
->is_dwz
)
3855 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3857 abbrev
= &dwarf2_per_objfile
->abbrev
;
3862 /* Subroutine of read_and_check_comp_unit_head and
3863 read_and_check_type_unit_head to simplify them.
3864 Perform various error checking on the header. */
3867 error_check_comp_unit_head (struct comp_unit_head
*header
,
3868 struct dwarf2_section_info
*section
,
3869 struct dwarf2_section_info
*abbrev_section
)
3871 bfd
*abfd
= section
->asection
->owner
;
3872 const char *filename
= bfd_get_filename (abfd
);
3874 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3875 error (_("Dwarf Error: wrong version in compilation unit header "
3876 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3879 if (header
->abbrev_offset
.sect_off
3880 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
3881 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3882 "(offset 0x%lx + 6) [in module %s]"),
3883 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3886 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3887 avoid potential 32-bit overflow. */
3888 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3890 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3891 "(offset 0x%lx + 0) [in module %s]"),
3892 (long) header
->length
, (long) header
->offset
.sect_off
,
3896 /* Read in a CU/TU header and perform some basic error checking.
3897 The contents of the header are stored in HEADER.
3898 The result is a pointer to the start of the first DIE. */
3901 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3902 struct dwarf2_section_info
*section
,
3903 struct dwarf2_section_info
*abbrev_section
,
3905 int is_debug_types_section
)
3907 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3908 bfd
*abfd
= section
->asection
->owner
;
3910 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3912 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3914 /* If we're reading a type unit, skip over the signature and
3915 type_offset fields. */
3916 if (is_debug_types_section
)
3917 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3919 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3921 error_check_comp_unit_head (header
, section
, abbrev_section
);
3926 /* Read in the types comp unit header information from .debug_types entry at
3927 types_ptr. The result is a pointer to one past the end of the header. */
3930 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3931 struct dwarf2_section_info
*section
,
3932 struct dwarf2_section_info
*abbrev_section
,
3934 ULONGEST
*signature
,
3935 cu_offset
*type_offset_in_tu
)
3937 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3938 bfd
*abfd
= section
->asection
->owner
;
3940 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3942 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3944 /* If we're reading a type unit, skip over the signature and
3945 type_offset fields. */
3946 if (signature
!= NULL
)
3947 *signature
= read_8_bytes (abfd
, info_ptr
);
3949 if (type_offset_in_tu
!= NULL
)
3950 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3951 header
->offset_size
);
3952 info_ptr
+= header
->offset_size
;
3954 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3956 error_check_comp_unit_head (header
, section
, abbrev_section
);
3961 /* Fetch the abbreviation table offset from a comp or type unit header. */
3964 read_abbrev_offset (struct dwarf2_section_info
*section
,
3967 bfd
*abfd
= section
->asection
->owner
;
3969 unsigned int length
, initial_length_size
, offset_size
;
3970 sect_offset abbrev_offset
;
3972 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3973 info_ptr
= section
->buffer
+ offset
.sect_off
;
3974 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3975 offset_size
= initial_length_size
== 4 ? 4 : 8;
3976 info_ptr
+= initial_length_size
+ 2 /*version*/;
3977 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
3978 return abbrev_offset
;
3981 /* Allocate a new partial symtab for file named NAME and mark this new
3982 partial symtab as being an include of PST. */
3985 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3986 struct objfile
*objfile
)
3988 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3990 subpst
->section_offsets
= pst
->section_offsets
;
3991 subpst
->textlow
= 0;
3992 subpst
->texthigh
= 0;
3994 subpst
->dependencies
= (struct partial_symtab
**)
3995 obstack_alloc (&objfile
->objfile_obstack
,
3996 sizeof (struct partial_symtab
*));
3997 subpst
->dependencies
[0] = pst
;
3998 subpst
->number_of_dependencies
= 1;
4000 subpst
->globals_offset
= 0;
4001 subpst
->n_global_syms
= 0;
4002 subpst
->statics_offset
= 0;
4003 subpst
->n_static_syms
= 0;
4004 subpst
->symtab
= NULL
;
4005 subpst
->read_symtab
= pst
->read_symtab
;
4008 /* No private part is necessary for include psymtabs. This property
4009 can be used to differentiate between such include psymtabs and
4010 the regular ones. */
4011 subpst
->read_symtab_private
= NULL
;
4014 /* Read the Line Number Program data and extract the list of files
4015 included by the source file represented by PST. Build an include
4016 partial symtab for each of these included files. */
4019 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4020 struct die_info
*die
,
4021 struct partial_symtab
*pst
)
4023 struct line_header
*lh
= NULL
;
4024 struct attribute
*attr
;
4026 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4028 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4030 return; /* No linetable, so no includes. */
4032 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4033 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
4035 free_line_header (lh
);
4039 hash_signatured_type (const void *item
)
4041 const struct signatured_type
*sig_type
= item
;
4043 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4044 return sig_type
->signature
;
4048 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4050 const struct signatured_type
*lhs
= item_lhs
;
4051 const struct signatured_type
*rhs
= item_rhs
;
4053 return lhs
->signature
== rhs
->signature
;
4056 /* Allocate a hash table for signatured types. */
4059 allocate_signatured_type_table (struct objfile
*objfile
)
4061 return htab_create_alloc_ex (41,
4062 hash_signatured_type
,
4065 &objfile
->objfile_obstack
,
4066 hashtab_obstack_allocate
,
4067 dummy_obstack_deallocate
);
4070 /* A helper function to add a signatured type CU to a table. */
4073 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4075 struct signatured_type
*sigt
= *slot
;
4076 struct signatured_type
***datap
= datum
;
4084 /* Create the hash table of all entries in the .debug_types section.
4085 DWO_FILE is a pointer to the DWO file for .debug_types.dwo,
4087 Note: This function processes DWO files only, not DWP files.
4088 The result is a pointer to the hash table or NULL if there are
4092 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4093 VEC (dwarf2_section_info_def
) *types
)
4095 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4096 htab_t types_htab
= NULL
;
4098 struct dwarf2_section_info
*section
;
4099 struct dwarf2_section_info
*abbrev_section
;
4101 if (VEC_empty (dwarf2_section_info_def
, types
))
4104 abbrev_section
= (dwo_file
!= NULL
4105 ? &dwo_file
->sections
.abbrev
4106 : &dwarf2_per_objfile
->abbrev
);
4108 if (dwarf2_read_debug
)
4109 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4110 dwo_file
? ".dwo" : "",
4111 bfd_get_filename (abbrev_section
->asection
->owner
));
4114 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4118 gdb_byte
*info_ptr
, *end_ptr
;
4119 struct dwarf2_section_info
*abbrev_section
;
4121 dwarf2_read_section (objfile
, section
);
4122 info_ptr
= section
->buffer
;
4124 if (info_ptr
== NULL
)
4127 /* We can't set abfd until now because the section may be empty or
4128 not present, in which case section->asection will be NULL. */
4129 abfd
= section
->asection
->owner
;
4132 abbrev_section
= &dwo_file
->sections
.abbrev
;
4134 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4136 if (types_htab
== NULL
)
4139 types_htab
= allocate_dwo_unit_table (objfile
);
4141 types_htab
= allocate_signatured_type_table (objfile
);
4144 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4145 because we don't need to read any dies: the signature is in the
4148 end_ptr
= info_ptr
+ section
->size
;
4149 while (info_ptr
< end_ptr
)
4152 cu_offset type_offset_in_tu
;
4154 struct signatured_type
*sig_type
;
4155 struct dwo_unit
*dwo_tu
;
4157 gdb_byte
*ptr
= info_ptr
;
4158 struct comp_unit_head header
;
4159 unsigned int length
;
4161 offset
.sect_off
= ptr
- section
->buffer
;
4163 /* We need to read the type's signature in order to build the hash
4164 table, but we don't need anything else just yet. */
4166 ptr
= read_and_check_type_unit_head (&header
, section
,
4167 abbrev_section
, ptr
,
4168 &signature
, &type_offset_in_tu
);
4170 length
= get_cu_length (&header
);
4172 /* Skip dummy type units. */
4173 if (ptr
>= info_ptr
+ length
4174 || peek_abbrev_code (abfd
, ptr
) == 0)
4183 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4185 dwo_tu
->dwo_file
= dwo_file
;
4186 dwo_tu
->signature
= signature
;
4187 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4188 dwo_tu
->info_or_types_section
= section
;
4189 dwo_tu
->offset
= offset
;
4190 dwo_tu
->length
= length
;
4194 /* N.B.: type_offset is not usable if this type uses a DWO file.
4195 The real type_offset is in the DWO file. */
4197 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4198 struct signatured_type
);
4199 sig_type
->signature
= signature
;
4200 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4201 sig_type
->per_cu
.objfile
= objfile
;
4202 sig_type
->per_cu
.is_debug_types
= 1;
4203 sig_type
->per_cu
.info_or_types_section
= section
;
4204 sig_type
->per_cu
.offset
= offset
;
4205 sig_type
->per_cu
.length
= length
;
4208 slot
= htab_find_slot (types_htab
,
4209 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4211 gdb_assert (slot
!= NULL
);
4214 sect_offset dup_offset
;
4218 const struct dwo_unit
*dup_tu
= *slot
;
4220 dup_offset
= dup_tu
->offset
;
4224 const struct signatured_type
*dup_tu
= *slot
;
4226 dup_offset
= dup_tu
->per_cu
.offset
;
4229 complaint (&symfile_complaints
,
4230 _("debug type entry at offset 0x%x is duplicate to the "
4231 "entry at offset 0x%x, signature 0x%s"),
4232 offset
.sect_off
, dup_offset
.sect_off
,
4233 phex (signature
, sizeof (signature
)));
4235 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4237 if (dwarf2_read_debug
)
4238 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4240 phex (signature
, sizeof (signature
)));
4249 /* Create the hash table of all entries in the .debug_types section,
4250 and initialize all_type_units.
4251 The result is zero if there is an error (e.g. missing .debug_types section),
4252 otherwise non-zero. */
4255 create_all_type_units (struct objfile
*objfile
)
4258 struct signatured_type
**iter
;
4260 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4261 if (types_htab
== NULL
)
4263 dwarf2_per_objfile
->signatured_types
= NULL
;
4267 dwarf2_per_objfile
->signatured_types
= types_htab
;
4269 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4270 dwarf2_per_objfile
->all_type_units
4271 = obstack_alloc (&objfile
->objfile_obstack
,
4272 dwarf2_per_objfile
->n_type_units
4273 * sizeof (struct signatured_type
*));
4274 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4275 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4276 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4277 == dwarf2_per_objfile
->n_type_units
);
4282 /* Lookup a signature based type for DW_FORM_ref_sig8.
4283 Returns NULL if signature SIG is not present in the table. */
4285 static struct signatured_type
*
4286 lookup_signatured_type (ULONGEST sig
)
4288 struct signatured_type find_entry
, *entry
;
4290 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4292 complaint (&symfile_complaints
,
4293 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4297 find_entry
.signature
= sig
;
4298 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4302 /* Low level DIE reading support. */
4304 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4307 init_cu_die_reader (struct die_reader_specs
*reader
,
4308 struct dwarf2_cu
*cu
,
4309 struct dwarf2_section_info
*section
,
4310 struct dwo_file
*dwo_file
)
4312 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4313 reader
->abfd
= section
->asection
->owner
;
4315 reader
->dwo_file
= dwo_file
;
4316 reader
->die_section
= section
;
4317 reader
->buffer
= section
->buffer
;
4318 reader
->buffer_end
= section
->buffer
+ section
->size
;
4321 /* Initialize a CU (or TU) and read its DIEs.
4322 If the CU defers to a DWO file, read the DWO file as well.
4324 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4325 Otherwise the table specified in the comp unit header is read in and used.
4326 This is an optimization for when we already have the abbrev table.
4328 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4329 Otherwise, a new CU is allocated with xmalloc.
4331 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4332 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4334 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4335 linker) then DIE_READER_FUNC will not get called. */
4338 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4339 struct abbrev_table
*abbrev_table
,
4340 int use_existing_cu
, int keep
,
4341 die_reader_func_ftype
*die_reader_func
,
4344 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4345 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4346 bfd
*abfd
= section
->asection
->owner
;
4347 struct dwarf2_cu
*cu
;
4348 gdb_byte
*begin_info_ptr
, *info_ptr
;
4349 struct die_reader_specs reader
;
4350 struct die_info
*comp_unit_die
;
4352 struct attribute
*attr
;
4353 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4354 struct signatured_type
*sig_type
= NULL
;
4355 struct dwarf2_section_info
*abbrev_section
;
4356 /* Non-zero if CU currently points to a DWO file and we need to
4357 reread it. When this happens we need to reread the skeleton die
4358 before we can reread the DWO file. */
4359 int rereading_dwo_cu
= 0;
4361 if (dwarf2_die_debug
)
4362 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4363 this_cu
->is_debug_types
? "type" : "comp",
4364 this_cu
->offset
.sect_off
);
4366 if (use_existing_cu
)
4369 cleanups
= make_cleanup (null_cleanup
, NULL
);
4371 /* This is cheap if the section is already read in. */
4372 dwarf2_read_section (objfile
, section
);
4374 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4376 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4378 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4382 /* If this CU is from a DWO file we need to start over, we need to
4383 refetch the attributes from the skeleton CU.
4384 This could be optimized by retrieving those attributes from when we
4385 were here the first time: the previous comp_unit_die was stored in
4386 comp_unit_obstack. But there's no data yet that we need this
4388 if (cu
->dwo_unit
!= NULL
)
4389 rereading_dwo_cu
= 1;
4393 /* If !use_existing_cu, this_cu->cu must be NULL. */
4394 gdb_assert (this_cu
->cu
== NULL
);
4396 cu
= xmalloc (sizeof (*cu
));
4397 init_one_comp_unit (cu
, this_cu
);
4399 /* If an error occurs while loading, release our storage. */
4400 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4403 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4405 /* We already have the header, there's no need to read it in again. */
4406 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4410 if (this_cu
->is_debug_types
)
4413 cu_offset type_offset_in_tu
;
4415 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4416 abbrev_section
, info_ptr
,
4418 &type_offset_in_tu
);
4420 /* Since per_cu is the first member of struct signatured_type,
4421 we can go from a pointer to one to a pointer to the other. */
4422 sig_type
= (struct signatured_type
*) this_cu
;
4423 gdb_assert (sig_type
->signature
== signature
);
4424 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4425 == type_offset_in_tu
.cu_off
);
4426 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4428 /* LENGTH has not been set yet for type units if we're
4429 using .gdb_index. */
4430 this_cu
->length
= get_cu_length (&cu
->header
);
4432 /* Establish the type offset that can be used to lookup the type. */
4433 sig_type
->type_offset_in_section
.sect_off
=
4434 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4438 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4442 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4443 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4447 /* Skip dummy compilation units. */
4448 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4449 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4451 do_cleanups (cleanups
);
4455 /* If we don't have them yet, read the abbrevs for this compilation unit.
4456 And if we need to read them now, make sure they're freed when we're
4457 done. Note that it's important that if the CU had an abbrev table
4458 on entry we don't free it when we're done: Somewhere up the call stack
4459 it may be in use. */
4460 if (abbrev_table
!= NULL
)
4462 gdb_assert (cu
->abbrev_table
== NULL
);
4463 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4464 == abbrev_table
->offset
.sect_off
);
4465 cu
->abbrev_table
= abbrev_table
;
4467 else if (cu
->abbrev_table
== NULL
)
4469 dwarf2_read_abbrevs (cu
, abbrev_section
);
4470 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4472 else if (rereading_dwo_cu
)
4474 dwarf2_free_abbrev_table (cu
);
4475 dwarf2_read_abbrevs (cu
, abbrev_section
);
4478 /* Read the top level CU/TU die. */
4479 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4480 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4482 /* If we have a DWO stub, process it and then read in the DWO file.
4483 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4484 a DWO CU, that this test will fail. */
4485 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4488 char *dwo_name
= DW_STRING (attr
);
4489 const char *comp_dir_string
;
4490 struct dwo_unit
*dwo_unit
;
4491 ULONGEST signature
; /* Or dwo_id. */
4492 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4493 int i
,num_extra_attrs
;
4494 struct dwarf2_section_info
*dwo_abbrev_section
;
4497 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4498 " has children (offset 0x%x) [in module %s]"),
4499 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4501 /* These attributes aren't processed until later:
4502 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4503 However, the attribute is found in the stub which we won't have later.
4504 In order to not impose this complication on the rest of the code,
4505 we read them here and copy them to the DWO CU/TU die. */
4507 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4510 if (! this_cu
->is_debug_types
)
4511 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4512 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4513 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4514 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4515 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4517 /* There should be a DW_AT_addr_base attribute here (if needed).
4518 We need the value before we can process DW_FORM_GNU_addr_index. */
4520 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4522 cu
->addr_base
= DW_UNSND (attr
);
4524 /* There should be a DW_AT_ranges_base attribute here (if needed).
4525 We need the value before we can process DW_AT_ranges. */
4526 cu
->ranges_base
= 0;
4527 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4529 cu
->ranges_base
= DW_UNSND (attr
);
4531 if (this_cu
->is_debug_types
)
4533 gdb_assert (sig_type
!= NULL
);
4534 signature
= sig_type
->signature
;
4538 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4540 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4542 signature
= DW_UNSND (attr
);
4545 /* We may need the comp_dir in order to find the DWO file. */
4546 comp_dir_string
= NULL
;
4548 comp_dir_string
= DW_STRING (comp_dir
);
4550 if (this_cu
->is_debug_types
)
4551 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4553 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4556 if (dwo_unit
== NULL
)
4558 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4559 " with ID %s [in module %s]"),
4560 this_cu
->offset
.sect_off
,
4561 phex (signature
, sizeof (signature
)),
4565 /* Set up for reading the DWO CU/TU. */
4566 cu
->dwo_unit
= dwo_unit
;
4567 section
= dwo_unit
->info_or_types_section
;
4568 dwarf2_read_section (objfile
, section
);
4569 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4570 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4571 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4573 if (this_cu
->is_debug_types
)
4576 cu_offset type_offset_in_tu
;
4578 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4582 &type_offset_in_tu
);
4583 gdb_assert (sig_type
->signature
== signature
);
4584 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4585 /* For DWOs coming from DWP files, we don't know the CU length
4586 nor the type's offset in the TU until now. */
4587 dwo_unit
->length
= get_cu_length (&cu
->header
);
4588 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
4590 /* Establish the type offset that can be used to lookup the type.
4591 For DWO files, we don't know it until now. */
4592 sig_type
->type_offset_in_section
.sect_off
=
4593 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4597 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4600 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4601 /* For DWOs coming from DWP files, we don't know the CU length
4603 dwo_unit
->length
= get_cu_length (&cu
->header
);
4606 /* Discard the original CU's abbrev table, and read the DWO's. */
4607 if (abbrev_table
== NULL
)
4609 dwarf2_free_abbrev_table (cu
);
4610 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4614 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4615 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4618 /* Read in the die, but leave space to copy over the attributes
4619 from the stub. This has the benefit of simplifying the rest of
4620 the code - all the real work is done here. */
4621 num_extra_attrs
= ((stmt_list
!= NULL
)
4625 + (comp_dir
!= NULL
));
4626 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4627 &has_children
, num_extra_attrs
);
4629 /* Copy over the attributes from the stub to the DWO die. */
4630 i
= comp_unit_die
->num_attrs
;
4631 if (stmt_list
!= NULL
)
4632 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4634 comp_unit_die
->attrs
[i
++] = *low_pc
;
4635 if (high_pc
!= NULL
)
4636 comp_unit_die
->attrs
[i
++] = *high_pc
;
4638 comp_unit_die
->attrs
[i
++] = *ranges
;
4639 if (comp_dir
!= NULL
)
4640 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4641 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4643 /* Skip dummy compilation units. */
4644 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4645 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4647 do_cleanups (cleanups
);
4652 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4654 if (free_cu_cleanup
!= NULL
)
4658 /* We've successfully allocated this compilation unit. Let our
4659 caller clean it up when finished with it. */
4660 discard_cleanups (free_cu_cleanup
);
4662 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4663 So we have to manually free the abbrev table. */
4664 dwarf2_free_abbrev_table (cu
);
4666 /* Link this CU into read_in_chain. */
4667 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4668 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4671 do_cleanups (free_cu_cleanup
);
4674 do_cleanups (cleanups
);
4677 /* Read CU/TU THIS_CU in section SECTION,
4678 but do not follow DW_AT_GNU_dwo_name if present.
4679 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4680 to have already done the lookup to find the DWO/DWP file).
4682 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4683 THIS_CU->is_debug_types, but nothing else.
4685 We fill in THIS_CU->length.
4687 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4688 linker) then DIE_READER_FUNC will not get called.
4690 THIS_CU->cu is always freed when done.
4691 This is done in order to not leave THIS_CU->cu in a state where we have
4692 to care whether it refers to the "main" CU or the DWO CU. */
4695 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4696 struct dwarf2_section_info
*abbrev_section
,
4697 struct dwo_file
*dwo_file
,
4698 die_reader_func_ftype
*die_reader_func
,
4701 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4702 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4703 bfd
*abfd
= section
->asection
->owner
;
4704 struct dwarf2_cu cu
;
4705 gdb_byte
*begin_info_ptr
, *info_ptr
;
4706 struct die_reader_specs reader
;
4707 struct cleanup
*cleanups
;
4708 struct die_info
*comp_unit_die
;
4711 if (dwarf2_die_debug
)
4712 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4713 this_cu
->is_debug_types
? "type" : "comp",
4714 this_cu
->offset
.sect_off
);
4716 gdb_assert (this_cu
->cu
== NULL
);
4718 /* This is cheap if the section is already read in. */
4719 dwarf2_read_section (objfile
, section
);
4721 init_one_comp_unit (&cu
, this_cu
);
4723 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4725 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4726 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4727 abbrev_section
, info_ptr
,
4728 this_cu
->is_debug_types
);
4730 this_cu
->length
= get_cu_length (&cu
.header
);
4732 /* Skip dummy compilation units. */
4733 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4734 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4736 do_cleanups (cleanups
);
4740 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4741 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4743 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4744 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4746 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4748 do_cleanups (cleanups
);
4751 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4752 does not lookup the specified DWO file.
4753 This cannot be used to read DWO files.
4755 THIS_CU->cu is always freed when done.
4756 This is done in order to not leave THIS_CU->cu in a state where we have
4757 to care whether it refers to the "main" CU or the DWO CU.
4758 We can revisit this if the data shows there's a performance issue. */
4761 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4762 die_reader_func_ftype
*die_reader_func
,
4765 init_cutu_and_read_dies_no_follow (this_cu
,
4766 get_abbrev_section_for_cu (this_cu
),
4768 die_reader_func
, data
);
4771 /* Create a psymtab named NAME and assign it to PER_CU.
4773 The caller must fill in the following details:
4774 dirname, textlow, texthigh. */
4776 static struct partial_symtab
*
4777 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4779 struct objfile
*objfile
= per_cu
->objfile
;
4780 struct partial_symtab
*pst
;
4782 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4784 objfile
->global_psymbols
.next
,
4785 objfile
->static_psymbols
.next
);
4787 pst
->psymtabs_addrmap_supported
= 1;
4789 /* This is the glue that links PST into GDB's symbol API. */
4790 pst
->read_symtab_private
= per_cu
;
4791 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4792 per_cu
->v
.psymtab
= pst
;
4797 /* die_reader_func for process_psymtab_comp_unit. */
4800 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4802 struct die_info
*comp_unit_die
,
4806 struct dwarf2_cu
*cu
= reader
->cu
;
4807 struct objfile
*objfile
= cu
->objfile
;
4808 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4809 struct attribute
*attr
;
4811 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4812 struct partial_symtab
*pst
;
4814 const char *filename
;
4815 int *want_partial_unit_ptr
= data
;
4817 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4818 && (want_partial_unit_ptr
== NULL
4819 || !*want_partial_unit_ptr
))
4822 gdb_assert (! per_cu
->is_debug_types
);
4824 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4826 cu
->list_in_scope
= &file_symbols
;
4828 /* Allocate a new partial symbol table structure. */
4829 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4830 if (attr
== NULL
|| !DW_STRING (attr
))
4833 filename
= DW_STRING (attr
);
4835 pst
= create_partial_symtab (per_cu
, filename
);
4837 /* This must be done before calling dwarf2_build_include_psymtabs. */
4838 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4840 pst
->dirname
= DW_STRING (attr
);
4842 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4844 dwarf2_find_base_address (comp_unit_die
, cu
);
4846 /* Possibly set the default values of LOWPC and HIGHPC from
4848 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4849 &best_highpc
, cu
, pst
);
4850 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4851 /* Store the contiguous range if it is not empty; it can be empty for
4852 CUs with no code. */
4853 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4854 best_lowpc
+ baseaddr
,
4855 best_highpc
+ baseaddr
- 1, pst
);
4857 /* Check if comp unit has_children.
4858 If so, read the rest of the partial symbols from this comp unit.
4859 If not, there's no more debug_info for this comp unit. */
4862 struct partial_die_info
*first_die
;
4863 CORE_ADDR lowpc
, highpc
;
4865 lowpc
= ((CORE_ADDR
) -1);
4866 highpc
= ((CORE_ADDR
) 0);
4868 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4870 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4873 /* If we didn't find a lowpc, set it to highpc to avoid
4874 complaints from `maint check'. */
4875 if (lowpc
== ((CORE_ADDR
) -1))
4878 /* If the compilation unit didn't have an explicit address range,
4879 then use the information extracted from its child dies. */
4883 best_highpc
= highpc
;
4886 pst
->textlow
= best_lowpc
+ baseaddr
;
4887 pst
->texthigh
= best_highpc
+ baseaddr
;
4889 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4890 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4891 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4892 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4893 sort_pst_symbols (pst
);
4895 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4898 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4899 struct dwarf2_per_cu_data
*iter
;
4901 /* Fill in 'dependencies' here; we fill in 'users' in a
4903 pst
->number_of_dependencies
= len
;
4904 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4905 len
* sizeof (struct symtab
*));
4907 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4910 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4912 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4915 /* Get the list of files included in the current compilation unit,
4916 and build a psymtab for each of them. */
4917 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4919 if (dwarf2_read_debug
)
4921 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4923 fprintf_unfiltered (gdb_stdlog
,
4924 "Psymtab for %s unit @0x%x: %s - %s"
4925 ", %d global, %d static syms\n",
4926 per_cu
->is_debug_types
? "type" : "comp",
4927 per_cu
->offset
.sect_off
,
4928 paddress (gdbarch
, pst
->textlow
),
4929 paddress (gdbarch
, pst
->texthigh
),
4930 pst
->n_global_syms
, pst
->n_static_syms
);
4934 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4935 Process compilation unit THIS_CU for a psymtab. */
4938 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4939 int want_partial_unit
)
4941 /* If this compilation unit was already read in, free the
4942 cached copy in order to read it in again. This is
4943 necessary because we skipped some symbols when we first
4944 read in the compilation unit (see load_partial_dies).
4945 This problem could be avoided, but the benefit is unclear. */
4946 if (this_cu
->cu
!= NULL
)
4947 free_one_cached_comp_unit (this_cu
);
4949 gdb_assert (! this_cu
->is_debug_types
);
4950 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4951 process_psymtab_comp_unit_reader
,
4952 &want_partial_unit
);
4954 /* Age out any secondary CUs. */
4955 age_cached_comp_units ();
4959 hash_type_unit_group (const void *item
)
4961 const struct type_unit_group
*tu_group
= item
;
4963 return hash_stmt_list_entry (&tu_group
->hash
);
4967 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4969 const struct type_unit_group
*lhs
= item_lhs
;
4970 const struct type_unit_group
*rhs
= item_rhs
;
4972 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
4975 /* Allocate a hash table for type unit groups. */
4978 allocate_type_unit_groups_table (void)
4980 return htab_create_alloc_ex (3,
4981 hash_type_unit_group
,
4984 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
4985 hashtab_obstack_allocate
,
4986 dummy_obstack_deallocate
);
4989 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4990 partial symtabs. We combine several TUs per psymtab to not let the size
4991 of any one psymtab grow too big. */
4992 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4993 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4995 /* Helper routine for get_type_unit_group.
4996 Create the type_unit_group object used to hold one or more TUs. */
4998 static struct type_unit_group
*
4999 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5001 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5002 struct dwarf2_per_cu_data
*per_cu
;
5003 struct type_unit_group
*tu_group
;
5005 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5006 struct type_unit_group
);
5007 per_cu
= &tu_group
->per_cu
;
5008 per_cu
->objfile
= objfile
;
5009 per_cu
->is_debug_types
= 1;
5010 per_cu
->s
.type_unit_group
= tu_group
;
5012 if (dwarf2_per_objfile
->using_index
)
5014 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5015 struct dwarf2_per_cu_quick_data
);
5016 tu_group
->t
.first_tu
= cu
->per_cu
;
5020 unsigned int line_offset
= line_offset_struct
.sect_off
;
5021 struct partial_symtab
*pst
;
5024 /* Give the symtab a useful name for debug purposes. */
5025 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5026 name
= xstrprintf ("<type_units_%d>",
5027 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5029 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5031 pst
= create_partial_symtab (per_cu
, name
);
5037 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5038 tu_group
->hash
.line_offset
= line_offset_struct
;
5043 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5044 STMT_LIST is a DW_AT_stmt_list attribute. */
5046 static struct type_unit_group
*
5047 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
5049 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5050 struct type_unit_group
*tu_group
;
5052 unsigned int line_offset
;
5053 struct type_unit_group type_unit_group_for_lookup
;
5055 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5057 dwarf2_per_objfile
->type_unit_groups
=
5058 allocate_type_unit_groups_table ();
5061 /* Do we need to create a new group, or can we use an existing one? */
5065 line_offset
= DW_UNSND (stmt_list
);
5066 ++tu_stats
->nr_symtab_sharers
;
5070 /* Ugh, no stmt_list. Rare, but we have to handle it.
5071 We can do various things here like create one group per TU or
5072 spread them over multiple groups to split up the expansion work.
5073 To avoid worst case scenarios (too many groups or too large groups)
5074 we, umm, group them in bunches. */
5075 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5076 | (tu_stats
->nr_stmt_less_type_units
5077 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5078 ++tu_stats
->nr_stmt_less_type_units
;
5081 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5082 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5083 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5084 &type_unit_group_for_lookup
, INSERT
);
5088 gdb_assert (tu_group
!= NULL
);
5092 sect_offset line_offset_struct
;
5094 line_offset_struct
.sect_off
= line_offset
;
5095 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5097 ++tu_stats
->nr_symtabs
;
5103 /* Struct used to sort TUs by their abbreviation table offset. */
5105 struct tu_abbrev_offset
5107 struct signatured_type
*sig_type
;
5108 sect_offset abbrev_offset
;
5111 /* Helper routine for build_type_unit_groups, passed to qsort. */
5114 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5116 const struct tu_abbrev_offset
* const *a
= ap
;
5117 const struct tu_abbrev_offset
* const *b
= bp
;
5118 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5119 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5121 return (aoff
> boff
) - (aoff
< boff
);
5124 /* A helper function to add a type_unit_group to a table. */
5127 add_type_unit_group_to_table (void **slot
, void *datum
)
5129 struct type_unit_group
*tu_group
= *slot
;
5130 struct type_unit_group
***datap
= datum
;
5138 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5139 each one passing FUNC,DATA.
5141 The efficiency is because we sort TUs by the abbrev table they use and
5142 only read each abbrev table once. In one program there are 200K TUs
5143 sharing 8K abbrev tables.
5145 The main purpose of this function is to support building the
5146 dwarf2_per_objfile->type_unit_groups table.
5147 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5148 can collapse the search space by grouping them by stmt_list.
5149 The savings can be significant, in the same program from above the 200K TUs
5150 share 8K stmt_list tables.
5152 FUNC is expected to call get_type_unit_group, which will create the
5153 struct type_unit_group if necessary and add it to
5154 dwarf2_per_objfile->type_unit_groups. */
5157 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5159 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5160 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5161 struct cleanup
*cleanups
;
5162 struct abbrev_table
*abbrev_table
;
5163 sect_offset abbrev_offset
;
5164 struct tu_abbrev_offset
*sorted_by_abbrev
;
5165 struct type_unit_group
**iter
;
5168 /* It's up to the caller to not call us multiple times. */
5169 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5171 if (dwarf2_per_objfile
->n_type_units
== 0)
5174 /* TUs typically share abbrev tables, and there can be way more TUs than
5175 abbrev tables. Sort by abbrev table to reduce the number of times we
5176 read each abbrev table in.
5177 Alternatives are to punt or to maintain a cache of abbrev tables.
5178 This is simpler and efficient enough for now.
5180 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5181 symtab to use). Typically TUs with the same abbrev offset have the same
5182 stmt_list value too so in practice this should work well.
5184 The basic algorithm here is:
5186 sort TUs by abbrev table
5187 for each TU with same abbrev table:
5188 read abbrev table if first user
5189 read TU top level DIE
5190 [IWBN if DWO skeletons had DW_AT_stmt_list]
5193 if (dwarf2_read_debug
)
5194 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5196 /* Sort in a separate table to maintain the order of all_type_units
5197 for .gdb_index: TU indices directly index all_type_units. */
5198 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5199 dwarf2_per_objfile
->n_type_units
);
5200 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5202 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5204 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5205 sorted_by_abbrev
[i
].abbrev_offset
=
5206 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5207 sig_type
->per_cu
.offset
);
5209 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5210 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5211 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5213 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5214 called any number of times, so we don't reset tu_stats here. */
5216 abbrev_offset
.sect_off
= ~(unsigned) 0;
5217 abbrev_table
= NULL
;
5218 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5220 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5222 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5224 /* Switch to the next abbrev table if necessary. */
5225 if (abbrev_table
== NULL
5226 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5228 if (abbrev_table
!= NULL
)
5230 abbrev_table_free (abbrev_table
);
5231 /* Reset to NULL in case abbrev_table_read_table throws
5232 an error: abbrev_table_free_cleanup will get called. */
5233 abbrev_table
= NULL
;
5235 abbrev_offset
= tu
->abbrev_offset
;
5237 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5239 ++tu_stats
->nr_uniq_abbrev_tables
;
5242 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5246 /* Create a vector of pointers to primary type units to make it easy to
5247 iterate over them and CUs. See dw2_get_primary_cu. */
5248 dwarf2_per_objfile
->n_type_unit_groups
=
5249 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5250 dwarf2_per_objfile
->all_type_unit_groups
=
5251 obstack_alloc (&objfile
->objfile_obstack
,
5252 dwarf2_per_objfile
->n_type_unit_groups
5253 * sizeof (struct type_unit_group
*));
5254 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5255 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5256 add_type_unit_group_to_table
, &iter
);
5257 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5258 == dwarf2_per_objfile
->n_type_unit_groups
);
5260 do_cleanups (cleanups
);
5262 if (dwarf2_read_debug
)
5264 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5265 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5266 dwarf2_per_objfile
->n_type_units
);
5267 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5268 tu_stats
->nr_uniq_abbrev_tables
);
5269 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5270 tu_stats
->nr_symtabs
);
5271 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5272 tu_stats
->nr_symtab_sharers
);
5273 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5274 tu_stats
->nr_stmt_less_type_units
);
5278 /* Reader function for build_type_psymtabs. */
5281 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5283 struct die_info
*type_unit_die
,
5287 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5288 struct dwarf2_cu
*cu
= reader
->cu
;
5289 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5290 struct type_unit_group
*tu_group
;
5291 struct attribute
*attr
;
5292 struct partial_die_info
*first_die
;
5293 CORE_ADDR lowpc
, highpc
;
5294 struct partial_symtab
*pst
;
5296 gdb_assert (data
== NULL
);
5301 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5302 tu_group
= get_type_unit_group (cu
, attr
);
5304 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5306 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5307 cu
->list_in_scope
= &file_symbols
;
5308 pst
= create_partial_symtab (per_cu
, "");
5311 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5313 lowpc
= (CORE_ADDR
) -1;
5314 highpc
= (CORE_ADDR
) 0;
5315 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5317 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5318 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5319 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5320 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5321 sort_pst_symbols (pst
);
5324 /* Traversal function for build_type_psymtabs. */
5327 build_type_psymtab_dependencies (void **slot
, void *info
)
5329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5330 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5331 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5332 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5333 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5334 struct dwarf2_per_cu_data
*iter
;
5337 gdb_assert (len
> 0);
5339 pst
->number_of_dependencies
= len
;
5340 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5341 len
* sizeof (struct psymtab
*));
5343 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5346 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5347 iter
->s
.type_unit_group
= tu_group
;
5350 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5355 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5356 Build partial symbol tables for the .debug_types comp-units. */
5359 build_type_psymtabs (struct objfile
*objfile
)
5361 if (! create_all_type_units (objfile
))
5364 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5366 /* Now that all TUs have been processed we can fill in the dependencies. */
5367 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5368 build_type_psymtab_dependencies
, NULL
);
5371 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5374 psymtabs_addrmap_cleanup (void *o
)
5376 struct objfile
*objfile
= o
;
5378 objfile
->psymtabs_addrmap
= NULL
;
5381 /* Compute the 'user' field for each psymtab in OBJFILE. */
5384 set_partial_user (struct objfile
*objfile
)
5388 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5390 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5391 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5397 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5399 /* Set the 'user' field only if it is not already set. */
5400 if (pst
->dependencies
[j
]->user
== NULL
)
5401 pst
->dependencies
[j
]->user
= pst
;
5406 /* Build the partial symbol table by doing a quick pass through the
5407 .debug_info and .debug_abbrev sections. */
5410 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5412 struct cleanup
*back_to
, *addrmap_cleanup
;
5413 struct obstack temp_obstack
;
5416 if (dwarf2_read_debug
)
5418 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5422 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5424 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5426 /* Any cached compilation units will be linked by the per-objfile
5427 read_in_chain. Make sure to free them when we're done. */
5428 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5430 build_type_psymtabs (objfile
);
5432 create_all_comp_units (objfile
);
5434 /* Create a temporary address map on a temporary obstack. We later
5435 copy this to the final obstack. */
5436 obstack_init (&temp_obstack
);
5437 make_cleanup_obstack_free (&temp_obstack
);
5438 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5439 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5441 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5443 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5445 process_psymtab_comp_unit (per_cu
, 0);
5448 set_partial_user (objfile
);
5450 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5451 &objfile
->objfile_obstack
);
5452 discard_cleanups (addrmap_cleanup
);
5454 do_cleanups (back_to
);
5456 if (dwarf2_read_debug
)
5457 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5461 /* die_reader_func for load_partial_comp_unit. */
5464 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5466 struct die_info
*comp_unit_die
,
5470 struct dwarf2_cu
*cu
= reader
->cu
;
5472 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5474 /* Check if comp unit has_children.
5475 If so, read the rest of the partial symbols from this comp unit.
5476 If not, there's no more debug_info for this comp unit. */
5478 load_partial_dies (reader
, info_ptr
, 0);
5481 /* Load the partial DIEs for a secondary CU into memory.
5482 This is also used when rereading a primary CU with load_all_dies. */
5485 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5487 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5488 load_partial_comp_unit_reader
, NULL
);
5492 read_comp_units_from_section (struct objfile
*objfile
,
5493 struct dwarf2_section_info
*section
,
5494 unsigned int is_dwz
,
5497 struct dwarf2_per_cu_data
***all_comp_units
)
5500 bfd
*abfd
= section
->asection
->owner
;
5502 dwarf2_read_section (objfile
, section
);
5504 info_ptr
= section
->buffer
;
5506 while (info_ptr
< section
->buffer
+ section
->size
)
5508 unsigned int length
, initial_length_size
;
5509 struct dwarf2_per_cu_data
*this_cu
;
5512 offset
.sect_off
= info_ptr
- section
->buffer
;
5514 /* Read just enough information to find out where the next
5515 compilation unit is. */
5516 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5518 /* Save the compilation unit for later lookup. */
5519 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5520 sizeof (struct dwarf2_per_cu_data
));
5521 memset (this_cu
, 0, sizeof (*this_cu
));
5522 this_cu
->offset
= offset
;
5523 this_cu
->length
= length
+ initial_length_size
;
5524 this_cu
->is_dwz
= is_dwz
;
5525 this_cu
->objfile
= objfile
;
5526 this_cu
->info_or_types_section
= section
;
5528 if (*n_comp_units
== *n_allocated
)
5531 *all_comp_units
= xrealloc (*all_comp_units
,
5533 * sizeof (struct dwarf2_per_cu_data
*));
5535 (*all_comp_units
)[*n_comp_units
] = this_cu
;
5538 info_ptr
= info_ptr
+ this_cu
->length
;
5542 /* Create a list of all compilation units in OBJFILE.
5543 This is only done for -readnow and building partial symtabs. */
5546 create_all_comp_units (struct objfile
*objfile
)
5550 struct dwarf2_per_cu_data
**all_comp_units
;
5554 all_comp_units
= xmalloc (n_allocated
5555 * sizeof (struct dwarf2_per_cu_data
*));
5557 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
5558 &n_allocated
, &n_comp_units
, &all_comp_units
);
5560 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
5562 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
5564 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
5565 &n_allocated
, &n_comp_units
,
5569 dwarf2_per_objfile
->all_comp_units
5570 = obstack_alloc (&objfile
->objfile_obstack
,
5571 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5572 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5573 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5574 xfree (all_comp_units
);
5575 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5578 /* Process all loaded DIEs for compilation unit CU, starting at
5579 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5580 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5581 DW_AT_ranges). If NEED_PC is set, then this function will set
5582 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5583 and record the covered ranges in the addrmap. */
5586 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5587 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5589 struct partial_die_info
*pdi
;
5591 /* Now, march along the PDI's, descending into ones which have
5592 interesting children but skipping the children of the other ones,
5593 until we reach the end of the compilation unit. */
5599 fixup_partial_die (pdi
, cu
);
5601 /* Anonymous namespaces or modules have no name but have interesting
5602 children, so we need to look at them. Ditto for anonymous
5605 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5606 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5607 || pdi
->tag
== DW_TAG_imported_unit
)
5611 case DW_TAG_subprogram
:
5612 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5614 case DW_TAG_constant
:
5615 case DW_TAG_variable
:
5616 case DW_TAG_typedef
:
5617 case DW_TAG_union_type
:
5618 if (!pdi
->is_declaration
)
5620 add_partial_symbol (pdi
, cu
);
5623 case DW_TAG_class_type
:
5624 case DW_TAG_interface_type
:
5625 case DW_TAG_structure_type
:
5626 if (!pdi
->is_declaration
)
5628 add_partial_symbol (pdi
, cu
);
5631 case DW_TAG_enumeration_type
:
5632 if (!pdi
->is_declaration
)
5633 add_partial_enumeration (pdi
, cu
);
5635 case DW_TAG_base_type
:
5636 case DW_TAG_subrange_type
:
5637 /* File scope base type definitions are added to the partial
5639 add_partial_symbol (pdi
, cu
);
5641 case DW_TAG_namespace
:
5642 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5645 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5647 case DW_TAG_imported_unit
:
5649 struct dwarf2_per_cu_data
*per_cu
;
5651 /* For now we don't handle imported units in type units. */
5652 if (cu
->per_cu
->is_debug_types
)
5654 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5655 " supported in type units [in module %s]"),
5659 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5663 /* Go read the partial unit, if needed. */
5664 if (per_cu
->v
.psymtab
== NULL
)
5665 process_psymtab_comp_unit (per_cu
, 1);
5667 VEC_safe_push (dwarf2_per_cu_ptr
,
5668 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5676 /* If the die has a sibling, skip to the sibling. */
5678 pdi
= pdi
->die_sibling
;
5682 /* Functions used to compute the fully scoped name of a partial DIE.
5684 Normally, this is simple. For C++, the parent DIE's fully scoped
5685 name is concatenated with "::" and the partial DIE's name. For
5686 Java, the same thing occurs except that "." is used instead of "::".
5687 Enumerators are an exception; they use the scope of their parent
5688 enumeration type, i.e. the name of the enumeration type is not
5689 prepended to the enumerator.
5691 There are two complexities. One is DW_AT_specification; in this
5692 case "parent" means the parent of the target of the specification,
5693 instead of the direct parent of the DIE. The other is compilers
5694 which do not emit DW_TAG_namespace; in this case we try to guess
5695 the fully qualified name of structure types from their members'
5696 linkage names. This must be done using the DIE's children rather
5697 than the children of any DW_AT_specification target. We only need
5698 to do this for structures at the top level, i.e. if the target of
5699 any DW_AT_specification (if any; otherwise the DIE itself) does not
5702 /* Compute the scope prefix associated with PDI's parent, in
5703 compilation unit CU. The result will be allocated on CU's
5704 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5705 field. NULL is returned if no prefix is necessary. */
5707 partial_die_parent_scope (struct partial_die_info
*pdi
,
5708 struct dwarf2_cu
*cu
)
5710 char *grandparent_scope
;
5711 struct partial_die_info
*parent
, *real_pdi
;
5713 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5714 then this means the parent of the specification DIE. */
5717 while (real_pdi
->has_specification
)
5718 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
5719 real_pdi
->spec_is_dwz
, cu
);
5721 parent
= real_pdi
->die_parent
;
5725 if (parent
->scope_set
)
5726 return parent
->scope
;
5728 fixup_partial_die (parent
, cu
);
5730 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5732 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5733 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5734 Work around this problem here. */
5735 if (cu
->language
== language_cplus
5736 && parent
->tag
== DW_TAG_namespace
5737 && strcmp (parent
->name
, "::") == 0
5738 && grandparent_scope
== NULL
)
5740 parent
->scope
= NULL
;
5741 parent
->scope_set
= 1;
5745 if (pdi
->tag
== DW_TAG_enumerator
)
5746 /* Enumerators should not get the name of the enumeration as a prefix. */
5747 parent
->scope
= grandparent_scope
;
5748 else if (parent
->tag
== DW_TAG_namespace
5749 || parent
->tag
== DW_TAG_module
5750 || parent
->tag
== DW_TAG_structure_type
5751 || parent
->tag
== DW_TAG_class_type
5752 || parent
->tag
== DW_TAG_interface_type
5753 || parent
->tag
== DW_TAG_union_type
5754 || parent
->tag
== DW_TAG_enumeration_type
)
5756 if (grandparent_scope
== NULL
)
5757 parent
->scope
= parent
->name
;
5759 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5761 parent
->name
, 0, cu
);
5765 /* FIXME drow/2004-04-01: What should we be doing with
5766 function-local names? For partial symbols, we should probably be
5768 complaint (&symfile_complaints
,
5769 _("unhandled containing DIE tag %d for DIE at %d"),
5770 parent
->tag
, pdi
->offset
.sect_off
);
5771 parent
->scope
= grandparent_scope
;
5774 parent
->scope_set
= 1;
5775 return parent
->scope
;
5778 /* Return the fully scoped name associated with PDI, from compilation unit
5779 CU. The result will be allocated with malloc. */
5782 partial_die_full_name (struct partial_die_info
*pdi
,
5783 struct dwarf2_cu
*cu
)
5787 /* If this is a template instantiation, we can not work out the
5788 template arguments from partial DIEs. So, unfortunately, we have
5789 to go through the full DIEs. At least any work we do building
5790 types here will be reused if full symbols are loaded later. */
5791 if (pdi
->has_template_arguments
)
5793 fixup_partial_die (pdi
, cu
);
5795 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5797 struct die_info
*die
;
5798 struct attribute attr
;
5799 struct dwarf2_cu
*ref_cu
= cu
;
5801 /* DW_FORM_ref_addr is using section offset. */
5803 attr
.form
= DW_FORM_ref_addr
;
5804 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5805 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5807 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5811 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5812 if (parent_scope
== NULL
)
5815 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5819 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5821 struct objfile
*objfile
= cu
->objfile
;
5823 char *actual_name
= NULL
;
5825 int built_actual_name
= 0;
5827 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5829 actual_name
= partial_die_full_name (pdi
, cu
);
5831 built_actual_name
= 1;
5833 if (actual_name
== NULL
)
5834 actual_name
= pdi
->name
;
5838 case DW_TAG_subprogram
:
5839 if (pdi
->is_external
|| cu
->language
== language_ada
)
5841 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5842 of the global scope. But in Ada, we want to be able to access
5843 nested procedures globally. So all Ada subprograms are stored
5844 in the global scope. */
5845 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5846 mst_text, objfile); */
5847 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5849 VAR_DOMAIN
, LOC_BLOCK
,
5850 &objfile
->global_psymbols
,
5851 0, pdi
->lowpc
+ baseaddr
,
5852 cu
->language
, objfile
);
5856 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5857 mst_file_text, objfile); */
5858 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5860 VAR_DOMAIN
, LOC_BLOCK
,
5861 &objfile
->static_psymbols
,
5862 0, pdi
->lowpc
+ baseaddr
,
5863 cu
->language
, objfile
);
5866 case DW_TAG_constant
:
5868 struct psymbol_allocation_list
*list
;
5870 if (pdi
->is_external
)
5871 list
= &objfile
->global_psymbols
;
5873 list
= &objfile
->static_psymbols
;
5874 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5875 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5876 list
, 0, 0, cu
->language
, objfile
);
5879 case DW_TAG_variable
:
5881 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5885 && !dwarf2_per_objfile
->has_section_at_zero
)
5887 /* A global or static variable may also have been stripped
5888 out by the linker if unused, in which case its address
5889 will be nullified; do not add such variables into partial
5890 symbol table then. */
5892 else if (pdi
->is_external
)
5895 Don't enter into the minimal symbol tables as there is
5896 a minimal symbol table entry from the ELF symbols already.
5897 Enter into partial symbol table if it has a location
5898 descriptor or a type.
5899 If the location descriptor is missing, new_symbol will create
5900 a LOC_UNRESOLVED symbol, the address of the variable will then
5901 be determined from the minimal symbol table whenever the variable
5903 The address for the partial symbol table entry is not
5904 used by GDB, but it comes in handy for debugging partial symbol
5907 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5908 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5910 VAR_DOMAIN
, LOC_STATIC
,
5911 &objfile
->global_psymbols
,
5913 cu
->language
, objfile
);
5917 /* Static Variable. Skip symbols without location descriptors. */
5918 if (pdi
->d
.locdesc
== NULL
)
5920 if (built_actual_name
)
5921 xfree (actual_name
);
5924 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5925 mst_file_data, objfile); */
5926 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5928 VAR_DOMAIN
, LOC_STATIC
,
5929 &objfile
->static_psymbols
,
5931 cu
->language
, objfile
);
5934 case DW_TAG_typedef
:
5935 case DW_TAG_base_type
:
5936 case DW_TAG_subrange_type
:
5937 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5939 VAR_DOMAIN
, LOC_TYPEDEF
,
5940 &objfile
->static_psymbols
,
5941 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5943 case DW_TAG_namespace
:
5944 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5946 VAR_DOMAIN
, LOC_TYPEDEF
,
5947 &objfile
->global_psymbols
,
5948 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5950 case DW_TAG_class_type
:
5951 case DW_TAG_interface_type
:
5952 case DW_TAG_structure_type
:
5953 case DW_TAG_union_type
:
5954 case DW_TAG_enumeration_type
:
5955 /* Skip external references. The DWARF standard says in the section
5956 about "Structure, Union, and Class Type Entries": "An incomplete
5957 structure, union or class type is represented by a structure,
5958 union or class entry that does not have a byte size attribute
5959 and that has a DW_AT_declaration attribute." */
5960 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5962 if (built_actual_name
)
5963 xfree (actual_name
);
5967 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5968 static vs. global. */
5969 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5971 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5972 (cu
->language
== language_cplus
5973 || cu
->language
== language_java
)
5974 ? &objfile
->global_psymbols
5975 : &objfile
->static_psymbols
,
5976 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5979 case DW_TAG_enumerator
:
5980 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5982 VAR_DOMAIN
, LOC_CONST
,
5983 (cu
->language
== language_cplus
5984 || cu
->language
== language_java
)
5985 ? &objfile
->global_psymbols
5986 : &objfile
->static_psymbols
,
5987 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5993 if (built_actual_name
)
5994 xfree (actual_name
);
5997 /* Read a partial die corresponding to a namespace; also, add a symbol
5998 corresponding to that namespace to the symbol table. NAMESPACE is
5999 the name of the enclosing namespace. */
6002 add_partial_namespace (struct partial_die_info
*pdi
,
6003 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6004 int need_pc
, struct dwarf2_cu
*cu
)
6006 /* Add a symbol for the namespace. */
6008 add_partial_symbol (pdi
, cu
);
6010 /* Now scan partial symbols in that namespace. */
6012 if (pdi
->has_children
)
6013 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6016 /* Read a partial die corresponding to a Fortran module. */
6019 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
6020 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6022 /* Now scan partial symbols in that module. */
6024 if (pdi
->has_children
)
6025 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6028 /* Read a partial die corresponding to a subprogram and create a partial
6029 symbol for that subprogram. When the CU language allows it, this
6030 routine also defines a partial symbol for each nested subprogram
6031 that this subprogram contains.
6033 DIE my also be a lexical block, in which case we simply search
6034 recursively for suprograms defined inside that lexical block.
6035 Again, this is only performed when the CU language allows this
6036 type of definitions. */
6039 add_partial_subprogram (struct partial_die_info
*pdi
,
6040 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6041 int need_pc
, struct dwarf2_cu
*cu
)
6043 if (pdi
->tag
== DW_TAG_subprogram
)
6045 if (pdi
->has_pc_info
)
6047 if (pdi
->lowpc
< *lowpc
)
6048 *lowpc
= pdi
->lowpc
;
6049 if (pdi
->highpc
> *highpc
)
6050 *highpc
= pdi
->highpc
;
6054 struct objfile
*objfile
= cu
->objfile
;
6056 baseaddr
= ANOFFSET (objfile
->section_offsets
,
6057 SECT_OFF_TEXT (objfile
));
6058 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6059 pdi
->lowpc
+ baseaddr
,
6060 pdi
->highpc
- 1 + baseaddr
,
6061 cu
->per_cu
->v
.psymtab
);
6065 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
6067 if (!pdi
->is_declaration
)
6068 /* Ignore subprogram DIEs that do not have a name, they are
6069 illegal. Do not emit a complaint at this point, we will
6070 do so when we convert this psymtab into a symtab. */
6072 add_partial_symbol (pdi
, cu
);
6076 if (! pdi
->has_children
)
6079 if (cu
->language
== language_ada
)
6081 pdi
= pdi
->die_child
;
6084 fixup_partial_die (pdi
, cu
);
6085 if (pdi
->tag
== DW_TAG_subprogram
6086 || pdi
->tag
== DW_TAG_lexical_block
)
6087 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6088 pdi
= pdi
->die_sibling
;
6093 /* Read a partial die corresponding to an enumeration type. */
6096 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6097 struct dwarf2_cu
*cu
)
6099 struct partial_die_info
*pdi
;
6101 if (enum_pdi
->name
!= NULL
)
6102 add_partial_symbol (enum_pdi
, cu
);
6104 pdi
= enum_pdi
->die_child
;
6107 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6108 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6110 add_partial_symbol (pdi
, cu
);
6111 pdi
= pdi
->die_sibling
;
6115 /* Return the initial uleb128 in the die at INFO_PTR. */
6118 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
6120 unsigned int bytes_read
;
6122 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6125 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6126 Return the corresponding abbrev, or NULL if the number is zero (indicating
6127 an empty DIE). In either case *BYTES_READ will be set to the length of
6128 the initial number. */
6130 static struct abbrev_info
*
6131 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6132 struct dwarf2_cu
*cu
)
6134 bfd
*abfd
= cu
->objfile
->obfd
;
6135 unsigned int abbrev_number
;
6136 struct abbrev_info
*abbrev
;
6138 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6140 if (abbrev_number
== 0)
6143 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6146 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6147 abbrev_number
, bfd_get_filename (abfd
));
6153 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6154 Returns a pointer to the end of a series of DIEs, terminated by an empty
6155 DIE. Any children of the skipped DIEs will also be skipped. */
6158 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
6160 struct dwarf2_cu
*cu
= reader
->cu
;
6161 struct abbrev_info
*abbrev
;
6162 unsigned int bytes_read
;
6166 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6168 return info_ptr
+ bytes_read
;
6170 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6174 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6175 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6176 abbrev corresponding to that skipped uleb128 should be passed in
6177 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6181 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
6182 struct abbrev_info
*abbrev
)
6184 unsigned int bytes_read
;
6185 struct attribute attr
;
6186 bfd
*abfd
= reader
->abfd
;
6187 struct dwarf2_cu
*cu
= reader
->cu
;
6188 gdb_byte
*buffer
= reader
->buffer
;
6189 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6190 gdb_byte
*start_info_ptr
= info_ptr
;
6191 unsigned int form
, i
;
6193 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6195 /* The only abbrev we care about is DW_AT_sibling. */
6196 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6198 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6199 if (attr
.form
== DW_FORM_ref_addr
)
6200 complaint (&symfile_complaints
,
6201 _("ignoring absolute DW_AT_sibling"));
6203 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6206 /* If it isn't DW_AT_sibling, skip this attribute. */
6207 form
= abbrev
->attrs
[i
].form
;
6211 case DW_FORM_ref_addr
:
6212 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6213 and later it is offset sized. */
6214 if (cu
->header
.version
== 2)
6215 info_ptr
+= cu
->header
.addr_size
;
6217 info_ptr
+= cu
->header
.offset_size
;
6219 case DW_FORM_GNU_ref_alt
:
6220 info_ptr
+= cu
->header
.offset_size
;
6223 info_ptr
+= cu
->header
.addr_size
;
6230 case DW_FORM_flag_present
:
6242 case DW_FORM_ref_sig8
:
6245 case DW_FORM_string
:
6246 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6247 info_ptr
+= bytes_read
;
6249 case DW_FORM_sec_offset
:
6251 case DW_FORM_GNU_strp_alt
:
6252 info_ptr
+= cu
->header
.offset_size
;
6254 case DW_FORM_exprloc
:
6256 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6257 info_ptr
+= bytes_read
;
6259 case DW_FORM_block1
:
6260 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6262 case DW_FORM_block2
:
6263 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6265 case DW_FORM_block4
:
6266 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6270 case DW_FORM_ref_udata
:
6271 case DW_FORM_GNU_addr_index
:
6272 case DW_FORM_GNU_str_index
:
6273 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6275 case DW_FORM_indirect
:
6276 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6277 info_ptr
+= bytes_read
;
6278 /* We need to continue parsing from here, so just go back to
6280 goto skip_attribute
;
6283 error (_("Dwarf Error: Cannot handle %s "
6284 "in DWARF reader [in module %s]"),
6285 dwarf_form_name (form
),
6286 bfd_get_filename (abfd
));
6290 if (abbrev
->has_children
)
6291 return skip_children (reader
, info_ptr
);
6296 /* Locate ORIG_PDI's sibling.
6297 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6300 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6301 struct partial_die_info
*orig_pdi
,
6304 /* Do we know the sibling already? */
6306 if (orig_pdi
->sibling
)
6307 return orig_pdi
->sibling
;
6309 /* Are there any children to deal with? */
6311 if (!orig_pdi
->has_children
)
6314 /* Skip the children the long way. */
6316 return skip_children (reader
, info_ptr
);
6319 /* Expand this partial symbol table into a full symbol table. */
6322 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
6328 warning (_("bug: psymtab for %s is already read in."),
6335 printf_filtered (_("Reading in symbols for %s..."),
6337 gdb_flush (gdb_stdout
);
6340 /* Restore our global data. */
6341 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
6342 dwarf2_objfile_data_key
);
6344 /* If this psymtab is constructed from a debug-only objfile, the
6345 has_section_at_zero flag will not necessarily be correct. We
6346 can get the correct value for this flag by looking at the data
6347 associated with the (presumably stripped) associated objfile. */
6348 if (pst
->objfile
->separate_debug_objfile_backlink
)
6350 struct dwarf2_per_objfile
*dpo_backlink
6351 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6352 dwarf2_objfile_data_key
);
6354 dwarf2_per_objfile
->has_section_at_zero
6355 = dpo_backlink
->has_section_at_zero
;
6358 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6360 psymtab_to_symtab_1 (pst
);
6362 /* Finish up the debug error message. */
6364 printf_filtered (_("done.\n"));
6368 process_cu_includes ();
6371 /* Reading in full CUs. */
6373 /* Add PER_CU to the queue. */
6376 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6377 enum language pretend_language
)
6379 struct dwarf2_queue_item
*item
;
6382 item
= xmalloc (sizeof (*item
));
6383 item
->per_cu
= per_cu
;
6384 item
->pretend_language
= pretend_language
;
6387 if (dwarf2_queue
== NULL
)
6388 dwarf2_queue
= item
;
6390 dwarf2_queue_tail
->next
= item
;
6392 dwarf2_queue_tail
= item
;
6395 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6396 unit and add it to our queue.
6397 The result is non-zero if PER_CU was queued, otherwise the result is zero
6398 meaning either PER_CU is already queued or it is already loaded. */
6401 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6402 struct dwarf2_per_cu_data
*per_cu
,
6403 enum language pretend_language
)
6405 /* We may arrive here during partial symbol reading, if we need full
6406 DIEs to process an unusual case (e.g. template arguments). Do
6407 not queue PER_CU, just tell our caller to load its DIEs. */
6408 if (dwarf2_per_objfile
->reading_partial_symbols
)
6410 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6415 /* Mark the dependence relation so that we don't flush PER_CU
6417 dwarf2_add_dependence (this_cu
, per_cu
);
6419 /* If it's already on the queue, we have nothing to do. */
6423 /* If the compilation unit is already loaded, just mark it as
6425 if (per_cu
->cu
!= NULL
)
6427 per_cu
->cu
->last_used
= 0;
6431 /* Add it to the queue. */
6432 queue_comp_unit (per_cu
, pretend_language
);
6437 /* Process the queue. */
6440 process_queue (void)
6442 struct dwarf2_queue_item
*item
, *next_item
;
6444 if (dwarf2_read_debug
)
6446 fprintf_unfiltered (gdb_stdlog
,
6447 "Expanding one or more symtabs of objfile %s ...\n",
6448 dwarf2_per_objfile
->objfile
->name
);
6451 /* The queue starts out with one item, but following a DIE reference
6452 may load a new CU, adding it to the end of the queue. */
6453 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6455 if (dwarf2_per_objfile
->using_index
6456 ? !item
->per_cu
->v
.quick
->symtab
6457 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6459 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6461 if (dwarf2_read_debug
)
6463 fprintf_unfiltered (gdb_stdlog
,
6464 "Expanding symtab of %s at offset 0x%x\n",
6465 per_cu
->is_debug_types
? "TU" : "CU",
6466 per_cu
->offset
.sect_off
);
6469 if (per_cu
->is_debug_types
)
6470 process_full_type_unit (per_cu
, item
->pretend_language
);
6472 process_full_comp_unit (per_cu
, item
->pretend_language
);
6474 if (dwarf2_read_debug
)
6476 fprintf_unfiltered (gdb_stdlog
,
6477 "Done expanding %s at offset 0x%x\n",
6478 per_cu
->is_debug_types
? "TU" : "CU",
6479 per_cu
->offset
.sect_off
);
6483 item
->per_cu
->queued
= 0;
6484 next_item
= item
->next
;
6488 dwarf2_queue_tail
= NULL
;
6490 if (dwarf2_read_debug
)
6492 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6493 dwarf2_per_objfile
->objfile
->name
);
6497 /* Free all allocated queue entries. This function only releases anything if
6498 an error was thrown; if the queue was processed then it would have been
6499 freed as we went along. */
6502 dwarf2_release_queue (void *dummy
)
6504 struct dwarf2_queue_item
*item
, *last
;
6506 item
= dwarf2_queue
;
6509 /* Anything still marked queued is likely to be in an
6510 inconsistent state, so discard it. */
6511 if (item
->per_cu
->queued
)
6513 if (item
->per_cu
->cu
!= NULL
)
6514 free_one_cached_comp_unit (item
->per_cu
);
6515 item
->per_cu
->queued
= 0;
6523 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6526 /* Read in full symbols for PST, and anything it depends on. */
6529 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6531 struct dwarf2_per_cu_data
*per_cu
;
6537 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6538 if (!pst
->dependencies
[i
]->readin
6539 && pst
->dependencies
[i
]->user
== NULL
)
6541 /* Inform about additional files that need to be read in. */
6544 /* FIXME: i18n: Need to make this a single string. */
6545 fputs_filtered (" ", gdb_stdout
);
6547 fputs_filtered ("and ", gdb_stdout
);
6549 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6550 wrap_here (""); /* Flush output. */
6551 gdb_flush (gdb_stdout
);
6553 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6556 per_cu
= pst
->read_symtab_private
;
6560 /* It's an include file, no symbols to read for it.
6561 Everything is in the parent symtab. */
6566 dw2_do_instantiate_symtab (per_cu
);
6569 /* Trivial hash function for die_info: the hash value of a DIE
6570 is its offset in .debug_info for this objfile. */
6573 die_hash (const void *item
)
6575 const struct die_info
*die
= item
;
6577 return die
->offset
.sect_off
;
6580 /* Trivial comparison function for die_info structures: two DIEs
6581 are equal if they have the same offset. */
6584 die_eq (const void *item_lhs
, const void *item_rhs
)
6586 const struct die_info
*die_lhs
= item_lhs
;
6587 const struct die_info
*die_rhs
= item_rhs
;
6589 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6592 /* die_reader_func for load_full_comp_unit.
6593 This is identical to read_signatured_type_reader,
6594 but is kept separate for now. */
6597 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6599 struct die_info
*comp_unit_die
,
6603 struct dwarf2_cu
*cu
= reader
->cu
;
6604 enum language
*language_ptr
= data
;
6606 gdb_assert (cu
->die_hash
== NULL
);
6608 htab_create_alloc_ex (cu
->header
.length
/ 12,
6612 &cu
->comp_unit_obstack
,
6613 hashtab_obstack_allocate
,
6614 dummy_obstack_deallocate
);
6617 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6618 &info_ptr
, comp_unit_die
);
6619 cu
->dies
= comp_unit_die
;
6620 /* comp_unit_die is not stored in die_hash, no need. */
6622 /* We try not to read any attributes in this function, because not
6623 all CUs needed for references have been loaded yet, and symbol
6624 table processing isn't initialized. But we have to set the CU language,
6625 or we won't be able to build types correctly.
6626 Similarly, if we do not read the producer, we can not apply
6627 producer-specific interpretation. */
6628 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6631 /* Load the DIEs associated with PER_CU into memory. */
6634 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6635 enum language pretend_language
)
6637 gdb_assert (! this_cu
->is_debug_types
);
6639 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6640 load_full_comp_unit_reader
, &pretend_language
);
6643 /* Add a DIE to the delayed physname list. */
6646 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6647 const char *name
, struct die_info
*die
,
6648 struct dwarf2_cu
*cu
)
6650 struct delayed_method_info mi
;
6652 mi
.fnfield_index
= fnfield_index
;
6656 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6659 /* A cleanup for freeing the delayed method list. */
6662 free_delayed_list (void *ptr
)
6664 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6665 if (cu
->method_list
!= NULL
)
6667 VEC_free (delayed_method_info
, cu
->method_list
);
6668 cu
->method_list
= NULL
;
6672 /* Compute the physnames of any methods on the CU's method list.
6674 The computation of method physnames is delayed in order to avoid the
6675 (bad) condition that one of the method's formal parameters is of an as yet
6679 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6682 struct delayed_method_info
*mi
;
6683 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6685 const char *physname
;
6686 struct fn_fieldlist
*fn_flp
6687 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6688 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6689 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6693 /* Go objects should be embedded in a DW_TAG_module DIE,
6694 and it's not clear if/how imported objects will appear.
6695 To keep Go support simple until that's worked out,
6696 go back through what we've read and create something usable.
6697 We could do this while processing each DIE, and feels kinda cleaner,
6698 but that way is more invasive.
6699 This is to, for example, allow the user to type "p var" or "b main"
6700 without having to specify the package name, and allow lookups
6701 of module.object to work in contexts that use the expression
6705 fixup_go_packaging (struct dwarf2_cu
*cu
)
6707 char *package_name
= NULL
;
6708 struct pending
*list
;
6711 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6713 for (i
= 0; i
< list
->nsyms
; ++i
)
6715 struct symbol
*sym
= list
->symbol
[i
];
6717 if (SYMBOL_LANGUAGE (sym
) == language_go
6718 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6720 char *this_package_name
= go_symbol_package_name (sym
);
6722 if (this_package_name
== NULL
)
6724 if (package_name
== NULL
)
6725 package_name
= this_package_name
;
6728 if (strcmp (package_name
, this_package_name
) != 0)
6729 complaint (&symfile_complaints
,
6730 _("Symtab %s has objects from two different Go packages: %s and %s"),
6731 (SYMBOL_SYMTAB (sym
)
6732 && SYMBOL_SYMTAB (sym
)->filename
6733 ? SYMBOL_SYMTAB (sym
)->filename
6734 : cu
->objfile
->name
),
6735 this_package_name
, package_name
);
6736 xfree (this_package_name
);
6742 if (package_name
!= NULL
)
6744 struct objfile
*objfile
= cu
->objfile
;
6745 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6746 package_name
, objfile
);
6749 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6751 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6752 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6753 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6754 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6755 e.g., "main" finds the "main" module and not C's main(). */
6756 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6757 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6758 SYMBOL_TYPE (sym
) = type
;
6760 add_symbol_to_list (sym
, &global_symbols
);
6762 xfree (package_name
);
6766 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6768 /* Return the symtab for PER_CU. This works properly regardless of
6769 whether we're using the index or psymtabs. */
6771 static struct symtab
*
6772 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6774 return (dwarf2_per_objfile
->using_index
6775 ? per_cu
->v
.quick
->symtab
6776 : per_cu
->v
.psymtab
->symtab
);
6779 /* A helper function for computing the list of all symbol tables
6780 included by PER_CU. */
6783 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6784 htab_t all_children
,
6785 struct dwarf2_per_cu_data
*per_cu
)
6789 struct dwarf2_per_cu_data
*iter
;
6791 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6794 /* This inclusion and its children have been processed. */
6799 /* Only add a CU if it has a symbol table. */
6800 if (get_symtab (per_cu
) != NULL
)
6801 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6804 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6806 recursively_compute_inclusions (result
, all_children
, iter
);
6809 /* Compute the symtab 'includes' fields for the symtab related to
6813 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6815 gdb_assert (! per_cu
->is_debug_types
);
6817 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6820 struct dwarf2_per_cu_data
*iter
;
6821 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6822 htab_t all_children
;
6823 struct symtab
*symtab
= get_symtab (per_cu
);
6825 /* If we don't have a symtab, we can just skip this case. */
6829 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6830 NULL
, xcalloc
, xfree
);
6833 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6836 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6838 /* Now we have a transitive closure of all the included CUs, so
6839 we can convert it to a list of symtabs. */
6840 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6842 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6843 (len
+ 1) * sizeof (struct symtab
*));
6845 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6847 symtab
->includes
[ix
] = get_symtab (iter
);
6848 symtab
->includes
[len
] = NULL
;
6850 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6851 htab_delete (all_children
);
6855 /* Compute the 'includes' field for the symtabs of all the CUs we just
6859 process_cu_includes (void)
6862 struct dwarf2_per_cu_data
*iter
;
6865 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6869 if (! iter
->is_debug_types
)
6870 compute_symtab_includes (iter
);
6873 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6876 /* Generate full symbol information for PER_CU, whose DIEs have
6877 already been loaded into memory. */
6880 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6881 enum language pretend_language
)
6883 struct dwarf2_cu
*cu
= per_cu
->cu
;
6884 struct objfile
*objfile
= per_cu
->objfile
;
6885 CORE_ADDR lowpc
, highpc
;
6886 struct symtab
*symtab
;
6887 struct cleanup
*back_to
, *delayed_list_cleanup
;
6889 struct block
*static_block
;
6891 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6894 back_to
= make_cleanup (really_free_pendings
, NULL
);
6895 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6897 cu
->list_in_scope
= &file_symbols
;
6899 cu
->language
= pretend_language
;
6900 cu
->language_defn
= language_def (cu
->language
);
6902 /* Do line number decoding in read_file_scope () */
6903 process_die (cu
->dies
, cu
);
6905 /* For now fudge the Go package. */
6906 if (cu
->language
== language_go
)
6907 fixup_go_packaging (cu
);
6909 /* Now that we have processed all the DIEs in the CU, all the types
6910 should be complete, and it should now be safe to compute all of the
6912 compute_delayed_physnames (cu
);
6913 do_cleanups (delayed_list_cleanup
);
6915 /* Some compilers don't define a DW_AT_high_pc attribute for the
6916 compilation unit. If the DW_AT_high_pc is missing, synthesize
6917 it, by scanning the DIE's below the compilation unit. */
6918 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6921 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0,
6922 per_cu
->s
.imported_symtabs
!= NULL
);
6924 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6925 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6926 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6927 addrmap to help ensure it has an accurate map of pc values belonging to
6929 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6931 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6932 SECT_OFF_TEXT (objfile
), 0);
6936 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6938 /* Set symtab language to language from DW_AT_language. If the
6939 compilation is from a C file generated by language preprocessors, do
6940 not set the language if it was already deduced by start_subfile. */
6941 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6942 symtab
->language
= cu
->language
;
6944 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6945 produce DW_AT_location with location lists but it can be possibly
6946 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6947 there were bugs in prologue debug info, fixed later in GCC-4.5
6948 by "unwind info for epilogues" patch (which is not directly related).
6950 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6951 needed, it would be wrong due to missing DW_AT_producer there.
6953 Still one can confuse GDB by using non-standard GCC compilation
6954 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6956 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6957 symtab
->locations_valid
= 1;
6959 if (gcc_4_minor
>= 5)
6960 symtab
->epilogue_unwind_valid
= 1;
6962 symtab
->call_site_htab
= cu
->call_site_htab
;
6965 if (dwarf2_per_objfile
->using_index
)
6966 per_cu
->v
.quick
->symtab
= symtab
;
6969 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6970 pst
->symtab
= symtab
;
6974 /* Push it for inclusion processing later. */
6975 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
6977 do_cleanups (back_to
);
6980 /* Generate full symbol information for type unit PER_CU, whose DIEs have
6981 already been loaded into memory. */
6984 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
6985 enum language pretend_language
)
6987 struct dwarf2_cu
*cu
= per_cu
->cu
;
6988 struct objfile
*objfile
= per_cu
->objfile
;
6989 struct symtab
*symtab
;
6990 struct cleanup
*back_to
, *delayed_list_cleanup
;
6993 back_to
= make_cleanup (really_free_pendings
, NULL
);
6994 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6996 cu
->list_in_scope
= &file_symbols
;
6998 cu
->language
= pretend_language
;
6999 cu
->language_defn
= language_def (cu
->language
);
7001 /* The symbol tables are set up in read_type_unit_scope. */
7002 process_die (cu
->dies
, cu
);
7004 /* For now fudge the Go package. */
7005 if (cu
->language
== language_go
)
7006 fixup_go_packaging (cu
);
7008 /* Now that we have processed all the DIEs in the CU, all the types
7009 should be complete, and it should now be safe to compute all of the
7011 compute_delayed_physnames (cu
);
7012 do_cleanups (delayed_list_cleanup
);
7014 /* TUs share symbol tables.
7015 If this is the first TU to use this symtab, complete the construction
7016 of it with end_expandable_symtab. Otherwise, complete the addition of
7017 this TU's symbols to the existing symtab. */
7018 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
7020 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7021 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
7025 /* Set symtab language to language from DW_AT_language. If the
7026 compilation is from a C file generated by language preprocessors,
7027 do not set the language if it was already deduced by
7029 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7030 symtab
->language
= cu
->language
;
7035 augment_type_symtab (objfile
,
7036 per_cu
->s
.type_unit_group
->primary_symtab
);
7037 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
7040 if (dwarf2_per_objfile
->using_index
)
7041 per_cu
->v
.quick
->symtab
= symtab
;
7044 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7045 pst
->symtab
= symtab
;
7049 do_cleanups (back_to
);
7052 /* Process an imported unit DIE. */
7055 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7057 struct attribute
*attr
;
7059 /* For now we don't handle imported units in type units. */
7060 if (cu
->per_cu
->is_debug_types
)
7062 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7063 " supported in type units [in module %s]"),
7067 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7070 struct dwarf2_per_cu_data
*per_cu
;
7071 struct symtab
*imported_symtab
;
7075 offset
= dwarf2_get_ref_die_offset (attr
);
7076 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7077 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7079 /* Queue the unit, if needed. */
7080 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7081 load_full_comp_unit (per_cu
, cu
->language
);
7083 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
7088 /* Process a die and its children. */
7091 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7095 case DW_TAG_padding
:
7097 case DW_TAG_compile_unit
:
7098 case DW_TAG_partial_unit
:
7099 read_file_scope (die
, cu
);
7101 case DW_TAG_type_unit
:
7102 read_type_unit_scope (die
, cu
);
7104 case DW_TAG_subprogram
:
7105 case DW_TAG_inlined_subroutine
:
7106 read_func_scope (die
, cu
);
7108 case DW_TAG_lexical_block
:
7109 case DW_TAG_try_block
:
7110 case DW_TAG_catch_block
:
7111 read_lexical_block_scope (die
, cu
);
7113 case DW_TAG_GNU_call_site
:
7114 read_call_site_scope (die
, cu
);
7116 case DW_TAG_class_type
:
7117 case DW_TAG_interface_type
:
7118 case DW_TAG_structure_type
:
7119 case DW_TAG_union_type
:
7120 process_structure_scope (die
, cu
);
7122 case DW_TAG_enumeration_type
:
7123 process_enumeration_scope (die
, cu
);
7126 /* These dies have a type, but processing them does not create
7127 a symbol or recurse to process the children. Therefore we can
7128 read them on-demand through read_type_die. */
7129 case DW_TAG_subroutine_type
:
7130 case DW_TAG_set_type
:
7131 case DW_TAG_array_type
:
7132 case DW_TAG_pointer_type
:
7133 case DW_TAG_ptr_to_member_type
:
7134 case DW_TAG_reference_type
:
7135 case DW_TAG_string_type
:
7138 case DW_TAG_base_type
:
7139 case DW_TAG_subrange_type
:
7140 case DW_TAG_typedef
:
7141 /* Add a typedef symbol for the type definition, if it has a
7143 new_symbol (die
, read_type_die (die
, cu
), cu
);
7145 case DW_TAG_common_block
:
7146 read_common_block (die
, cu
);
7148 case DW_TAG_common_inclusion
:
7150 case DW_TAG_namespace
:
7151 processing_has_namespace_info
= 1;
7152 read_namespace (die
, cu
);
7155 processing_has_namespace_info
= 1;
7156 read_module (die
, cu
);
7158 case DW_TAG_imported_declaration
:
7159 case DW_TAG_imported_module
:
7160 processing_has_namespace_info
= 1;
7161 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7162 || cu
->language
!= language_fortran
))
7163 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7164 dwarf_tag_name (die
->tag
));
7165 read_import_statement (die
, cu
);
7168 case DW_TAG_imported_unit
:
7169 process_imported_unit_die (die
, cu
);
7173 new_symbol (die
, NULL
, cu
);
7178 /* A helper function for dwarf2_compute_name which determines whether DIE
7179 needs to have the name of the scope prepended to the name listed in the
7183 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7185 struct attribute
*attr
;
7189 case DW_TAG_namespace
:
7190 case DW_TAG_typedef
:
7191 case DW_TAG_class_type
:
7192 case DW_TAG_interface_type
:
7193 case DW_TAG_structure_type
:
7194 case DW_TAG_union_type
:
7195 case DW_TAG_enumeration_type
:
7196 case DW_TAG_enumerator
:
7197 case DW_TAG_subprogram
:
7201 case DW_TAG_variable
:
7202 case DW_TAG_constant
:
7203 /* We only need to prefix "globally" visible variables. These include
7204 any variable marked with DW_AT_external or any variable that
7205 lives in a namespace. [Variables in anonymous namespaces
7206 require prefixing, but they are not DW_AT_external.] */
7208 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7210 struct dwarf2_cu
*spec_cu
= cu
;
7212 return die_needs_namespace (die_specification (die
, &spec_cu
),
7216 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7217 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7218 && die
->parent
->tag
!= DW_TAG_module
)
7220 /* A variable in a lexical block of some kind does not need a
7221 namespace, even though in C++ such variables may be external
7222 and have a mangled name. */
7223 if (die
->parent
->tag
== DW_TAG_lexical_block
7224 || die
->parent
->tag
== DW_TAG_try_block
7225 || die
->parent
->tag
== DW_TAG_catch_block
7226 || die
->parent
->tag
== DW_TAG_subprogram
)
7235 /* Retrieve the last character from a mem_file. */
7238 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7240 char *last_char_p
= (char *) object
;
7243 *last_char_p
= buffer
[length
- 1];
7246 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7247 compute the physname for the object, which include a method's:
7248 - formal parameters (C++/Java),
7249 - receiver type (Go),
7250 - return type (Java).
7252 The term "physname" is a bit confusing.
7253 For C++, for example, it is the demangled name.
7254 For Go, for example, it's the mangled name.
7256 For Ada, return the DIE's linkage name rather than the fully qualified
7257 name. PHYSNAME is ignored..
7259 The result is allocated on the objfile_obstack and canonicalized. */
7262 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7265 struct objfile
*objfile
= cu
->objfile
;
7268 name
= dwarf2_name (die
, cu
);
7270 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7271 compute it by typename_concat inside GDB. */
7272 if (cu
->language
== language_ada
7273 || (cu
->language
== language_fortran
&& physname
))
7275 /* For Ada unit, we prefer the linkage name over the name, as
7276 the former contains the exported name, which the user expects
7277 to be able to reference. Ideally, we want the user to be able
7278 to reference this entity using either natural or linkage name,
7279 but we haven't started looking at this enhancement yet. */
7280 struct attribute
*attr
;
7282 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7284 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7285 if (attr
&& DW_STRING (attr
))
7286 return DW_STRING (attr
);
7289 /* These are the only languages we know how to qualify names in. */
7291 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7292 || cu
->language
== language_fortran
))
7294 if (die_needs_namespace (die
, cu
))
7298 struct ui_file
*buf
;
7300 prefix
= determine_prefix (die
, cu
);
7301 buf
= mem_fileopen ();
7302 if (*prefix
!= '\0')
7304 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7307 fputs_unfiltered (prefixed_name
, buf
);
7308 xfree (prefixed_name
);
7311 fputs_unfiltered (name
, buf
);
7313 /* Template parameters may be specified in the DIE's DW_AT_name, or
7314 as children with DW_TAG_template_type_param or
7315 DW_TAG_value_type_param. If the latter, add them to the name
7316 here. If the name already has template parameters, then
7317 skip this step; some versions of GCC emit both, and
7318 it is more efficient to use the pre-computed name.
7320 Something to keep in mind about this process: it is very
7321 unlikely, or in some cases downright impossible, to produce
7322 something that will match the mangled name of a function.
7323 If the definition of the function has the same debug info,
7324 we should be able to match up with it anyway. But fallbacks
7325 using the minimal symbol, for instance to find a method
7326 implemented in a stripped copy of libstdc++, will not work.
7327 If we do not have debug info for the definition, we will have to
7328 match them up some other way.
7330 When we do name matching there is a related problem with function
7331 templates; two instantiated function templates are allowed to
7332 differ only by their return types, which we do not add here. */
7334 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7336 struct attribute
*attr
;
7337 struct die_info
*child
;
7340 die
->building_fullname
= 1;
7342 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7347 struct dwarf2_locexpr_baton
*baton
;
7350 if (child
->tag
!= DW_TAG_template_type_param
7351 && child
->tag
!= DW_TAG_template_value_param
)
7356 fputs_unfiltered ("<", buf
);
7360 fputs_unfiltered (", ", buf
);
7362 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7365 complaint (&symfile_complaints
,
7366 _("template parameter missing DW_AT_type"));
7367 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7370 type
= die_type (child
, cu
);
7372 if (child
->tag
== DW_TAG_template_type_param
)
7374 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
7378 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7381 complaint (&symfile_complaints
,
7382 _("template parameter missing "
7383 "DW_AT_const_value"));
7384 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7388 dwarf2_const_value_attr (attr
, type
, name
,
7389 &cu
->comp_unit_obstack
, cu
,
7390 &value
, &bytes
, &baton
);
7392 if (TYPE_NOSIGN (type
))
7393 /* GDB prints characters as NUMBER 'CHAR'. If that's
7394 changed, this can use value_print instead. */
7395 c_printchar (value
, type
, buf
);
7398 struct value_print_options opts
;
7401 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7405 else if (bytes
!= NULL
)
7407 v
= allocate_value (type
);
7408 memcpy (value_contents_writeable (v
), bytes
,
7409 TYPE_LENGTH (type
));
7412 v
= value_from_longest (type
, value
);
7414 /* Specify decimal so that we do not depend on
7416 get_formatted_print_options (&opts
, 'd');
7418 value_print (v
, buf
, &opts
);
7424 die
->building_fullname
= 0;
7428 /* Close the argument list, with a space if necessary
7429 (nested templates). */
7430 char last_char
= '\0';
7431 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7432 if (last_char
== '>')
7433 fputs_unfiltered (" >", buf
);
7435 fputs_unfiltered (">", buf
);
7439 /* For Java and C++ methods, append formal parameter type
7440 information, if PHYSNAME. */
7442 if (physname
&& die
->tag
== DW_TAG_subprogram
7443 && (cu
->language
== language_cplus
7444 || cu
->language
== language_java
))
7446 struct type
*type
= read_type_die (die
, cu
);
7448 c_type_print_args (type
, buf
, 1, cu
->language
,
7449 &type_print_raw_options
);
7451 if (cu
->language
== language_java
)
7453 /* For java, we must append the return type to method
7455 if (die
->tag
== DW_TAG_subprogram
)
7456 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7457 0, 0, &type_print_raw_options
);
7459 else if (cu
->language
== language_cplus
)
7461 /* Assume that an artificial first parameter is
7462 "this", but do not crash if it is not. RealView
7463 marks unnamed (and thus unused) parameters as
7464 artificial; there is no way to differentiate
7466 if (TYPE_NFIELDS (type
) > 0
7467 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7468 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7469 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7471 fputs_unfiltered (" const", buf
);
7475 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7477 ui_file_delete (buf
);
7479 if (cu
->language
== language_cplus
)
7482 = dwarf2_canonicalize_name (name
, cu
,
7483 &objfile
->objfile_obstack
);
7494 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7495 If scope qualifiers are appropriate they will be added. The result
7496 will be allocated on the objfile_obstack, or NULL if the DIE does
7497 not have a name. NAME may either be from a previous call to
7498 dwarf2_name or NULL.
7500 The output string will be canonicalized (if C++/Java). */
7503 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7505 return dwarf2_compute_name (name
, die
, cu
, 0);
7508 /* Construct a physname for the given DIE in CU. NAME may either be
7509 from a previous call to dwarf2_name or NULL. The result will be
7510 allocated on the objfile_objstack or NULL if the DIE does not have a
7513 The output string will be canonicalized (if C++/Java). */
7516 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7518 struct objfile
*objfile
= cu
->objfile
;
7519 struct attribute
*attr
;
7520 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7521 struct cleanup
*back_to
;
7524 /* In this case dwarf2_compute_name is just a shortcut not building anything
7526 if (!die_needs_namespace (die
, cu
))
7527 return dwarf2_compute_name (name
, die
, cu
, 1);
7529 back_to
= make_cleanup (null_cleanup
, NULL
);
7531 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7533 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7535 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7537 if (attr
&& DW_STRING (attr
))
7541 mangled
= DW_STRING (attr
);
7543 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7544 type. It is easier for GDB users to search for such functions as
7545 `name(params)' than `long name(params)'. In such case the minimal
7546 symbol names do not match the full symbol names but for template
7547 functions there is never a need to look up their definition from their
7548 declaration so the only disadvantage remains the minimal symbol
7549 variant `long name(params)' does not have the proper inferior type.
7552 if (cu
->language
== language_go
)
7554 /* This is a lie, but we already lie to the caller new_symbol_full.
7555 new_symbol_full assumes we return the mangled name.
7556 This just undoes that lie until things are cleaned up. */
7561 demangled
= cplus_demangle (mangled
,
7562 (DMGL_PARAMS
| DMGL_ANSI
7563 | (cu
->language
== language_java
7564 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7569 make_cleanup (xfree
, demangled
);
7579 if (canon
== NULL
|| check_physname
)
7581 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7583 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7585 /* It may not mean a bug in GDB. The compiler could also
7586 compute DW_AT_linkage_name incorrectly. But in such case
7587 GDB would need to be bug-to-bug compatible. */
7589 complaint (&symfile_complaints
,
7590 _("Computed physname <%s> does not match demangled <%s> "
7591 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7592 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7594 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7595 is available here - over computed PHYSNAME. It is safer
7596 against both buggy GDB and buggy compilers. */
7610 retval
= obsavestring (retval
, strlen (retval
),
7611 &objfile
->objfile_obstack
);
7613 do_cleanups (back_to
);
7617 /* Read the import statement specified by the given die and record it. */
7620 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7622 struct objfile
*objfile
= cu
->objfile
;
7623 struct attribute
*import_attr
;
7624 struct die_info
*imported_die
, *child_die
;
7625 struct dwarf2_cu
*imported_cu
;
7626 const char *imported_name
;
7627 const char *imported_name_prefix
;
7628 const char *canonical_name
;
7629 const char *import_alias
;
7630 const char *imported_declaration
= NULL
;
7631 const char *import_prefix
;
7632 VEC (const_char_ptr
) *excludes
= NULL
;
7633 struct cleanup
*cleanups
;
7637 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7638 if (import_attr
== NULL
)
7640 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7641 dwarf_tag_name (die
->tag
));
7646 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7647 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7648 if (imported_name
== NULL
)
7650 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7652 The import in the following code:
7666 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7667 <52> DW_AT_decl_file : 1
7668 <53> DW_AT_decl_line : 6
7669 <54> DW_AT_import : <0x75>
7670 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7672 <5b> DW_AT_decl_file : 1
7673 <5c> DW_AT_decl_line : 2
7674 <5d> DW_AT_type : <0x6e>
7676 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7677 <76> DW_AT_byte_size : 4
7678 <77> DW_AT_encoding : 5 (signed)
7680 imports the wrong die ( 0x75 instead of 0x58 ).
7681 This case will be ignored until the gcc bug is fixed. */
7685 /* Figure out the local name after import. */
7686 import_alias
= dwarf2_name (die
, cu
);
7688 /* Figure out where the statement is being imported to. */
7689 import_prefix
= determine_prefix (die
, cu
);
7691 /* Figure out what the scope of the imported die is and prepend it
7692 to the name of the imported die. */
7693 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7695 if (imported_die
->tag
!= DW_TAG_namespace
7696 && imported_die
->tag
!= DW_TAG_module
)
7698 imported_declaration
= imported_name
;
7699 canonical_name
= imported_name_prefix
;
7701 else if (strlen (imported_name_prefix
) > 0)
7703 temp
= alloca (strlen (imported_name_prefix
)
7704 + 2 + strlen (imported_name
) + 1);
7705 strcpy (temp
, imported_name_prefix
);
7706 strcat (temp
, "::");
7707 strcat (temp
, imported_name
);
7708 canonical_name
= temp
;
7711 canonical_name
= imported_name
;
7713 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7715 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7716 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7717 child_die
= sibling_die (child_die
))
7719 /* DWARF-4: A Fortran use statement with a “rename list” may be
7720 represented by an imported module entry with an import attribute
7721 referring to the module and owned entries corresponding to those
7722 entities that are renamed as part of being imported. */
7724 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7726 complaint (&symfile_complaints
,
7727 _("child DW_TAG_imported_declaration expected "
7728 "- DIE at 0x%x [in module %s]"),
7729 child_die
->offset
.sect_off
, objfile
->name
);
7733 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7734 if (import_attr
== NULL
)
7736 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7737 dwarf_tag_name (child_die
->tag
));
7742 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7744 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7745 if (imported_name
== NULL
)
7747 complaint (&symfile_complaints
,
7748 _("child DW_TAG_imported_declaration has unknown "
7749 "imported name - DIE at 0x%x [in module %s]"),
7750 child_die
->offset
.sect_off
, objfile
->name
);
7754 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7756 process_die (child_die
, cu
);
7759 cp_add_using_directive (import_prefix
,
7762 imported_declaration
,
7764 &objfile
->objfile_obstack
);
7766 do_cleanups (cleanups
);
7769 /* Cleanup function for handle_DW_AT_stmt_list. */
7772 free_cu_line_header (void *arg
)
7774 struct dwarf2_cu
*cu
= arg
;
7776 free_line_header (cu
->line_header
);
7777 cu
->line_header
= NULL
;
7780 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7781 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7782 this, it was first present in GCC release 4.3.0. */
7785 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
7787 if (!cu
->checked_producer
)
7788 check_producer (cu
);
7790 return cu
->producer_is_gcc_lt_4_3
;
7794 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7795 char **name
, char **comp_dir
)
7797 struct attribute
*attr
;
7802 /* Find the filename. Do not use dwarf2_name here, since the filename
7803 is not a source language identifier. */
7804 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7807 *name
= DW_STRING (attr
);
7810 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7812 *comp_dir
= DW_STRING (attr
);
7813 else if (producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
7814 && IS_ABSOLUTE_PATH (*name
))
7816 *comp_dir
= ldirname (*name
);
7817 if (*comp_dir
!= NULL
)
7818 make_cleanup (xfree
, *comp_dir
);
7820 if (*comp_dir
!= NULL
)
7822 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7823 directory, get rid of it. */
7824 char *cp
= strchr (*comp_dir
, ':');
7826 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7831 *name
= "<unknown>";
7834 /* Handle DW_AT_stmt_list for a compilation unit.
7835 DIE is the DW_TAG_compile_unit die for CU.
7836 COMP_DIR is the compilation directory.
7837 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7840 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7841 const char *comp_dir
)
7843 struct attribute
*attr
;
7845 gdb_assert (! cu
->per_cu
->is_debug_types
);
7847 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7850 unsigned int line_offset
= DW_UNSND (attr
);
7851 struct line_header
*line_header
7852 = dwarf_decode_line_header (line_offset
, cu
);
7856 cu
->line_header
= line_header
;
7857 make_cleanup (free_cu_line_header
, cu
);
7858 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7863 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7866 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7868 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7869 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7870 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7871 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7872 struct attribute
*attr
;
7874 char *comp_dir
= NULL
;
7875 struct die_info
*child_die
;
7876 bfd
*abfd
= objfile
->obfd
;
7879 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7881 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7883 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7884 from finish_block. */
7885 if (lowpc
== ((CORE_ADDR
) -1))
7890 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7892 prepare_one_comp_unit (cu
, die
, cu
->language
);
7894 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7895 standardised yet. As a workaround for the language detection we fall
7896 back to the DW_AT_producer string. */
7897 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7898 cu
->language
= language_opencl
;
7900 /* Similar hack for Go. */
7901 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7902 set_cu_language (DW_LANG_Go
, cu
);
7904 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7906 /* Decode line number information if present. We do this before
7907 processing child DIEs, so that the line header table is available
7908 for DW_AT_decl_file. */
7909 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7911 /* Process all dies in compilation unit. */
7912 if (die
->child
!= NULL
)
7914 child_die
= die
->child
;
7915 while (child_die
&& child_die
->tag
)
7917 process_die (child_die
, cu
);
7918 child_die
= sibling_die (child_die
);
7922 /* Decode macro information, if present. Dwarf 2 macro information
7923 refers to information in the line number info statement program
7924 header, so we can only read it if we've read the header
7926 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7927 if (attr
&& cu
->line_header
)
7929 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7930 complaint (&symfile_complaints
,
7931 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7933 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7937 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7938 if (attr
&& cu
->line_header
)
7940 unsigned int macro_offset
= DW_UNSND (attr
);
7942 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7946 do_cleanups (back_to
);
7949 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7950 Create the set of symtabs used by this TU, or if this TU is sharing
7951 symtabs with another TU and the symtabs have already been created
7952 then restore those symtabs in the line header.
7953 We don't need the pc/line-number mapping for type units. */
7956 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7958 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7959 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7960 struct type_unit_group
*tu_group
;
7962 struct line_header
*lh
;
7963 struct attribute
*attr
;
7964 unsigned int i
, line_offset
;
7966 gdb_assert (per_cu
->is_debug_types
);
7968 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7970 /* If we're using .gdb_index (includes -readnow) then
7971 per_cu->s.type_unit_group may not have been set up yet. */
7972 if (per_cu
->s
.type_unit_group
== NULL
)
7973 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
7974 tu_group
= per_cu
->s
.type_unit_group
;
7976 /* If we've already processed this stmt_list there's no real need to
7977 do it again, we could fake it and just recreate the part we need
7978 (file name,index -> symtab mapping). If data shows this optimization
7979 is useful we can do it then. */
7980 first_time
= tu_group
->primary_symtab
== NULL
;
7982 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7987 line_offset
= DW_UNSND (attr
);
7988 lh
= dwarf_decode_line_header (line_offset
, cu
);
7993 dwarf2_start_symtab (cu
, "", NULL
, 0);
7996 gdb_assert (tu_group
->symtabs
== NULL
);
7999 /* Note: The primary symtab will get allocated at the end. */
8003 cu
->line_header
= lh
;
8004 make_cleanup (free_cu_line_header
, cu
);
8008 dwarf2_start_symtab (cu
, "", NULL
, 0);
8010 tu_group
->num_symtabs
= lh
->num_file_names
;
8011 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8013 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8016 struct file_entry
*fe
= &lh
->file_names
[i
];
8019 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8020 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8022 /* Note: We don't have to watch for the main subfile here, type units
8023 don't have DW_AT_name. */
8025 if (current_subfile
->symtab
== NULL
)
8027 /* NOTE: start_subfile will recognize when it's been passed
8028 a file it has already seen. So we can't assume there's a
8029 simple mapping from lh->file_names to subfiles,
8030 lh->file_names may contain dups. */
8031 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8035 fe
->symtab
= current_subfile
->symtab
;
8036 tu_group
->symtabs
[i
] = fe
->symtab
;
8043 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8045 struct file_entry
*fe
= &lh
->file_names
[i
];
8047 fe
->symtab
= tu_group
->symtabs
[i
];
8051 /* The main symtab is allocated last. Type units don't have DW_AT_name
8052 so they don't have a "real" (so to speak) symtab anyway.
8053 There is later code that will assign the main symtab to all symbols
8054 that don't have one. We need to handle the case of a symbol with a
8055 missing symtab (DW_AT_decl_file) anyway. */
8058 /* Process DW_TAG_type_unit.
8059 For TUs we want to skip the first top level sibling if it's not the
8060 actual type being defined by this TU. In this case the first top
8061 level sibling is there to provide context only. */
8064 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8066 struct die_info
*child_die
;
8068 prepare_one_comp_unit (cu
, die
, language_minimal
);
8070 /* Initialize (or reinitialize) the machinery for building symtabs.
8071 We do this before processing child DIEs, so that the line header table
8072 is available for DW_AT_decl_file. */
8073 setup_type_unit_groups (die
, cu
);
8075 if (die
->child
!= NULL
)
8077 child_die
= die
->child
;
8078 while (child_die
&& child_die
->tag
)
8080 process_die (child_die
, cu
);
8081 child_die
= sibling_die (child_die
);
8088 http://gcc.gnu.org/wiki/DebugFission
8089 http://gcc.gnu.org/wiki/DebugFissionDWP
8091 To simplify handling of both DWO files ("object" files with the DWARF info)
8092 and DWP files (a file with the DWOs packaged up into one file), we treat
8093 DWP files as having a collection of virtual DWO files. */
8096 hash_dwo_file (const void *item
)
8098 const struct dwo_file
*dwo_file
= item
;
8100 return htab_hash_string (dwo_file
->name
);
8104 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8106 const struct dwo_file
*lhs
= item_lhs
;
8107 const struct dwo_file
*rhs
= item_rhs
;
8109 return strcmp (lhs
->name
, rhs
->name
) == 0;
8112 /* Allocate a hash table for DWO files. */
8115 allocate_dwo_file_hash_table (void)
8117 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8119 return htab_create_alloc_ex (41,
8123 &objfile
->objfile_obstack
,
8124 hashtab_obstack_allocate
,
8125 dummy_obstack_deallocate
);
8128 /* Lookup DWO file DWO_NAME. */
8131 lookup_dwo_file_slot (const char *dwo_name
)
8133 struct dwo_file find_entry
;
8136 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8137 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8139 memset (&find_entry
, 0, sizeof (find_entry
));
8140 find_entry
.name
= dwo_name
;
8141 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8147 hash_dwo_unit (const void *item
)
8149 const struct dwo_unit
*dwo_unit
= item
;
8151 /* This drops the top 32 bits of the id, but is ok for a hash. */
8152 return dwo_unit
->signature
;
8156 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8158 const struct dwo_unit
*lhs
= item_lhs
;
8159 const struct dwo_unit
*rhs
= item_rhs
;
8161 /* The signature is assumed to be unique within the DWO file.
8162 So while object file CU dwo_id's always have the value zero,
8163 that's OK, assuming each object file DWO file has only one CU,
8164 and that's the rule for now. */
8165 return lhs
->signature
== rhs
->signature
;
8168 /* Allocate a hash table for DWO CUs,TUs.
8169 There is one of these tables for each of CUs,TUs for each DWO file. */
8172 allocate_dwo_unit_table (struct objfile
*objfile
)
8174 /* Start out with a pretty small number.
8175 Generally DWO files contain only one CU and maybe some TUs. */
8176 return htab_create_alloc_ex (3,
8180 &objfile
->objfile_obstack
,
8181 hashtab_obstack_allocate
,
8182 dummy_obstack_deallocate
);
8185 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8187 struct create_dwo_info_table_data
8189 struct dwo_file
*dwo_file
;
8193 /* die_reader_func for create_dwo_debug_info_hash_table. */
8196 create_dwo_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
8198 struct die_info
*comp_unit_die
,
8202 struct dwarf2_cu
*cu
= reader
->cu
;
8203 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8204 sect_offset offset
= cu
->per_cu
->offset
;
8205 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
8206 struct create_dwo_info_table_data
*data
= datap
;
8207 struct dwo_file
*dwo_file
= data
->dwo_file
;
8208 htab_t cu_htab
= data
->cu_htab
;
8210 struct attribute
*attr
;
8211 struct dwo_unit
*dwo_unit
;
8213 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8216 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8217 " its dwo_id [in module %s]"),
8218 offset
.sect_off
, dwo_file
->name
);
8222 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8223 dwo_unit
->dwo_file
= dwo_file
;
8224 dwo_unit
->signature
= DW_UNSND (attr
);
8225 dwo_unit
->info_or_types_section
= section
;
8226 dwo_unit
->offset
= offset
;
8227 dwo_unit
->length
= cu
->per_cu
->length
;
8229 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8230 gdb_assert (slot
!= NULL
);
8233 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8235 complaint (&symfile_complaints
,
8236 _("debug entry at offset 0x%x is duplicate to the entry at"
8237 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8238 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8239 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8245 if (dwarf2_read_debug
)
8246 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8248 phex (dwo_unit
->signature
,
8249 sizeof (dwo_unit
->signature
)));
8252 /* Create a hash table to map DWO IDs to their CU entry in
8253 .debug_info.dwo in DWO_FILE.
8254 Note: This function processes DWO files only, not DWP files. */
8257 create_dwo_debug_info_hash_table (struct dwo_file
*dwo_file
)
8259 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8260 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8263 gdb_byte
*info_ptr
, *end_ptr
;
8264 struct create_dwo_info_table_data create_dwo_info_table_data
;
8266 dwarf2_read_section (objfile
, section
);
8267 info_ptr
= section
->buffer
;
8269 if (info_ptr
== NULL
)
8272 /* We can't set abfd until now because the section may be empty or
8273 not present, in which case section->asection will be NULL. */
8274 abfd
= section
->asection
->owner
;
8276 if (dwarf2_read_debug
)
8277 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8278 bfd_get_filename (abfd
));
8280 cu_htab
= allocate_dwo_unit_table (objfile
);
8282 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8283 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8285 end_ptr
= info_ptr
+ section
->size
;
8286 while (info_ptr
< end_ptr
)
8288 struct dwarf2_per_cu_data per_cu
;
8290 memset (&per_cu
, 0, sizeof (per_cu
));
8291 per_cu
.objfile
= objfile
;
8292 per_cu
.is_debug_types
= 0;
8293 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8294 per_cu
.info_or_types_section
= section
;
8296 init_cutu_and_read_dies_no_follow (&per_cu
,
8297 &dwo_file
->sections
.abbrev
,
8299 create_dwo_debug_info_hash_table_reader
,
8300 &create_dwo_info_table_data
);
8302 info_ptr
+= per_cu
.length
;
8308 /* DWP file .debug_{cu,tu}_index section format:
8309 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8311 Both index sections have the same format, and serve to map a 64-bit
8312 signature to a set of section numbers. Each section begins with a header,
8313 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8314 indexes, and a pool of 32-bit section numbers. The index sections will be
8315 aligned at 8-byte boundaries in the file.
8317 The index section header contains two unsigned 32-bit values (using the
8318 byte order of the application binary):
8320 N, the number of compilation units or type units in the index
8321 M, the number of slots in the hash table
8323 (We assume that N and M will not exceed 2^32 - 1.)
8325 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8327 The hash table begins at offset 8 in the section, and consists of an array
8328 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8329 order of the application binary). Unused slots in the hash table are 0.
8330 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8332 The parallel table begins immediately after the hash table
8333 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8334 array of 32-bit indexes (using the byte order of the application binary),
8335 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8336 table contains a 32-bit index into the pool of section numbers. For unused
8337 hash table slots, the corresponding entry in the parallel table will be 0.
8339 Given a 64-bit compilation unit signature or a type signature S, an entry
8340 in the hash table is located as follows:
8342 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8343 the low-order k bits all set to 1.
8345 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8347 3) If the hash table entry at index H matches the signature, use that
8348 entry. If the hash table entry at index H is unused (all zeroes),
8349 terminate the search: the signature is not present in the table.
8351 4) Let H = (H + H') modulo M. Repeat at Step 3.
8353 Because M > N and H' and M are relatively prime, the search is guaranteed
8354 to stop at an unused slot or find the match.
8356 The pool of section numbers begins immediately following the hash table
8357 (at offset 8 + 12 * M from the beginning of the section). The pool of
8358 section numbers consists of an array of 32-bit words (using the byte order
8359 of the application binary). Each item in the array is indexed starting
8360 from 0. The hash table entry provides the index of the first section
8361 number in the set. Additional section numbers in the set follow, and the
8362 set is terminated by a 0 entry (section number 0 is not used in ELF).
8364 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8365 section must be the first entry in the set, and the .debug_abbrev.dwo must
8366 be the second entry. Other members of the set may follow in any order. */
8368 /* Create a hash table to map DWO IDs to their CU/TU entry in
8369 .debug_{info,types}.dwo in DWP_FILE.
8370 Returns NULL if there isn't one.
8371 Note: This function processes DWP files only, not DWO files. */
8373 static struct dwp_hash_table
*
8374 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
8376 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8377 bfd
*dbfd
= dwp_file
->dbfd
;
8378 char *index_ptr
, *index_end
;
8379 struct dwarf2_section_info
*index
;
8380 uint32_t version
, nr_units
, nr_slots
;
8381 struct dwp_hash_table
*htab
;
8384 index
= &dwp_file
->sections
.tu_index
;
8386 index
= &dwp_file
->sections
.cu_index
;
8388 if (dwarf2_section_empty_p (index
))
8390 dwarf2_read_section (objfile
, index
);
8392 index_ptr
= index
->buffer
;
8393 index_end
= index_ptr
+ index
->size
;
8395 version
= read_4_bytes (dbfd
, index_ptr
);
8396 index_ptr
+= 8; /* Skip the unused word. */
8397 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8399 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8404 error (_("Dwarf Error: unsupported DWP file version (%u)"
8406 version
, dwp_file
->name
);
8408 if (nr_slots
!= (nr_slots
& -nr_slots
))
8410 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8411 " is not power of 2 [in module %s]"),
8412 nr_slots
, dwp_file
->name
);
8415 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
8416 htab
->nr_units
= nr_units
;
8417 htab
->nr_slots
= nr_slots
;
8418 htab
->hash_table
= index_ptr
;
8419 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8420 htab
->section_pool
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8425 /* Update SECTIONS with the data from SECTP.
8427 This function is like the other "locate" section routines that are
8428 passed to bfd_map_over_sections, but in this context the sections to
8429 read comes from the DWP hash table, not the full ELF section table.
8431 The result is non-zero for success, or zero if an error was found. */
8434 locate_virtual_dwo_sections (asection
*sectp
,
8435 struct virtual_dwo_sections
*sections
)
8437 const struct dwop_section_names
*names
= &dwop_section_names
;
8439 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8441 /* There can be only one. */
8442 if (sections
->abbrev
.asection
!= NULL
)
8444 sections
->abbrev
.asection
= sectp
;
8445 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8447 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
8448 || section_is_p (sectp
->name
, &names
->types_dwo
))
8450 /* There can be only one. */
8451 if (sections
->info_or_types
.asection
!= NULL
)
8453 sections
->info_or_types
.asection
= sectp
;
8454 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
8456 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8458 /* There can be only one. */
8459 if (sections
->line
.asection
!= NULL
)
8461 sections
->line
.asection
= sectp
;
8462 sections
->line
.size
= bfd_get_section_size (sectp
);
8464 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8466 /* There can be only one. */
8467 if (sections
->loc
.asection
!= NULL
)
8469 sections
->loc
.asection
= sectp
;
8470 sections
->loc
.size
= bfd_get_section_size (sectp
);
8472 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8474 /* There can be only one. */
8475 if (sections
->macinfo
.asection
!= NULL
)
8477 sections
->macinfo
.asection
= sectp
;
8478 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8480 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8482 /* There can be only one. */
8483 if (sections
->macro
.asection
!= NULL
)
8485 sections
->macro
.asection
= sectp
;
8486 sections
->macro
.size
= bfd_get_section_size (sectp
);
8488 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8490 /* There can be only one. */
8491 if (sections
->str_offsets
.asection
!= NULL
)
8493 sections
->str_offsets
.asection
= sectp
;
8494 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8498 /* No other kind of section is valid. */
8505 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8506 HTAB is the hash table from the DWP file.
8507 SECTION_INDEX is the index of the DWO in HTAB. */
8509 static struct dwo_unit
*
8510 create_dwo_in_dwp (struct dwp_file
*dwp_file
,
8511 const struct dwp_hash_table
*htab
,
8512 uint32_t section_index
,
8513 ULONGEST signature
, int is_debug_types
)
8515 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8516 bfd
*dbfd
= dwp_file
->dbfd
;
8517 const char *kind
= is_debug_types
? "TU" : "CU";
8518 struct dwo_file
*dwo_file
;
8519 struct dwo_unit
*dwo_unit
;
8520 struct virtual_dwo_sections sections
;
8521 void **dwo_file_slot
;
8522 char *virtual_dwo_name
;
8523 struct dwarf2_section_info
*cutu
;
8524 struct cleanup
*cleanups
;
8527 if (dwarf2_read_debug
)
8529 fprintf_unfiltered (gdb_stdlog
, "Reading %s %u/0x%s in DWP file: %s\n",
8531 section_index
, phex (signature
, sizeof (signature
)),
8535 /* Fetch the sections of this DWO.
8536 Put a limit on the number of sections we look for so that bad data
8537 doesn't cause us to loop forever. */
8539 #define MAX_NR_DWO_SECTIONS \
8540 (1 /* .debug_info or .debug_types */ \
8541 + 1 /* .debug_abbrev */ \
8542 + 1 /* .debug_line */ \
8543 + 1 /* .debug_loc */ \
8544 + 1 /* .debug_str_offsets */ \
8545 + 1 /* .debug_macro */ \
8546 + 1 /* .debug_macinfo */ \
8547 + 1 /* trailing zero */)
8549 memset (§ions
, 0, sizeof (sections
));
8550 cleanups
= make_cleanup (null_cleanup
, 0);
8552 for (i
= 0; i
< MAX_NR_DWO_SECTIONS
; ++i
)
8555 uint32_t section_nr
=
8558 + (section_index
+ i
) * sizeof (uint32_t));
8560 if (section_nr
== 0)
8562 if (section_nr
>= dwp_file
->num_sections
)
8564 error (_("Dwarf Error: bad DWP hash table, section number too large"
8569 sectp
= dwp_file
->elf_sections
[section_nr
];
8570 if (! locate_virtual_dwo_sections (sectp
, §ions
))
8572 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8579 || sections
.info_or_types
.asection
== NULL
8580 || sections
.abbrev
.asection
== NULL
)
8582 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8586 if (i
== MAX_NR_DWO_SECTIONS
)
8588 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8593 /* It's easier for the rest of the code if we fake a struct dwo_file and
8594 have dwo_unit "live" in that. At least for now.
8596 The DWP file can be made up of a random collection of CUs and TUs.
8597 However, for each CU + set of TUs that came from the same original
8598 DWO file, we want combine them back into a virtual DWO file to save space
8599 (fewer struct dwo_file objects to allocated). Remember that for really
8600 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8603 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
8604 sections
.abbrev
.asection
? sections
.abbrev
.asection
->id
: 0,
8605 sections
.line
.asection
? sections
.line
.asection
->id
: 0,
8606 sections
.loc
.asection
? sections
.loc
.asection
->id
: 0,
8607 (sections
.str_offsets
.asection
8608 ? sections
.str_offsets
.asection
->id
8610 make_cleanup (xfree
, virtual_dwo_name
);
8611 /* Can we use an existing virtual DWO file? */
8612 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
);
8613 /* Create one if necessary. */
8614 if (*dwo_file_slot
== NULL
)
8616 if (dwarf2_read_debug
)
8618 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
8621 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8622 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8624 strlen (virtual_dwo_name
));
8625 dwo_file
->sections
.abbrev
= sections
.abbrev
;
8626 dwo_file
->sections
.line
= sections
.line
;
8627 dwo_file
->sections
.loc
= sections
.loc
;
8628 dwo_file
->sections
.macinfo
= sections
.macinfo
;
8629 dwo_file
->sections
.macro
= sections
.macro
;
8630 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
8631 /* The "str" section is global to the entire DWP file. */
8632 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8633 /* The info or types section is assigned later to dwo_unit,
8634 there's no need to record it in dwo_file.
8635 Also, we can't simply record type sections in dwo_file because
8636 we record a pointer into the vector in dwo_unit. As we collect more
8637 types we'll grow the vector and eventually have to reallocate space
8638 for it, invalidating all the pointers into the current copy. */
8639 *dwo_file_slot
= dwo_file
;
8643 if (dwarf2_read_debug
)
8645 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
8648 dwo_file
= *dwo_file_slot
;
8650 do_cleanups (cleanups
);
8652 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8653 dwo_unit
->dwo_file
= dwo_file
;
8654 dwo_unit
->signature
= signature
;
8655 dwo_unit
->info_or_types_section
=
8656 obstack_alloc (&objfile
->objfile_obstack
,
8657 sizeof (struct dwarf2_section_info
));
8658 *dwo_unit
->info_or_types_section
= sections
.info_or_types
;
8659 /* offset, length, type_offset_in_tu are set later. */
8664 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8666 static struct dwo_unit
*
8667 lookup_dwo_in_dwp (struct dwp_file
*dwp_file
,
8668 const struct dwp_hash_table
*htab
,
8669 ULONGEST signature
, int is_debug_types
)
8671 bfd
*dbfd
= dwp_file
->dbfd
;
8672 uint32_t mask
= htab
->nr_slots
- 1;
8673 uint32_t hash
= signature
& mask
;
8674 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
8677 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8679 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
8680 find_dwo_cu
.signature
= signature
;
8681 slot
= htab_find_slot (dwp_file
->loaded_cutus
, &find_dwo_cu
, INSERT
);
8686 /* Use a for loop so that we don't loop forever on bad debug info. */
8687 for (i
= 0; i
< htab
->nr_slots
; ++i
)
8689 ULONGEST signature_in_table
;
8691 signature_in_table
=
8692 read_8_bytes (dbfd
, htab
->hash_table
+ hash
* sizeof (uint64_t));
8693 if (signature_in_table
== signature
)
8695 uint32_t section_index
=
8696 read_4_bytes (dbfd
, htab
->unit_table
+ hash
* sizeof (uint32_t));
8698 *slot
= create_dwo_in_dwp (dwp_file
, htab
, section_index
,
8699 signature
, is_debug_types
);
8702 if (signature_in_table
== 0)
8704 hash
= (hash
+ hash2
) & mask
;
8707 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8712 /* Subroutine of open_dwop_file to simplify it.
8713 Open the file specified by FILE_NAME and hand it off to BFD for
8714 preliminary analysis. Return a newly initialized bfd *, which
8715 includes a canonicalized copy of FILE_NAME.
8716 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8717 In case of trouble, return NULL.
8718 NOTE: This function is derived from symfile_bfd_open. */
8721 try_open_dwop_file (const char *file_name
, int is_dwp
)
8725 char *absolute_name
;
8727 flags
= OPF_TRY_CWD_FIRST
;
8729 flags
|= OPF_SEARCH_IN_PATH
;
8730 desc
= openp (debug_file_directory
, flags
, file_name
,
8731 O_RDONLY
| O_BINARY
, &absolute_name
);
8735 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
8738 xfree (absolute_name
);
8741 xfree (absolute_name
);
8742 bfd_set_cacheable (sym_bfd
, 1);
8744 if (!bfd_check_format (sym_bfd
, bfd_object
))
8746 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8753 /* Try to open DWO/DWP file FILE_NAME.
8754 COMP_DIR is the DW_AT_comp_dir attribute.
8755 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8756 The result is the bfd handle of the file.
8757 If there is a problem finding or opening the file, return NULL.
8758 Upon success, the canonicalized path of the file is stored in the bfd,
8759 same as symfile_bfd_open. */
8762 open_dwop_file (const char *file_name
, const char *comp_dir
, int is_dwp
)
8766 if (IS_ABSOLUTE_PATH (file_name
))
8767 return try_open_dwop_file (file_name
, is_dwp
);
8769 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8771 if (comp_dir
!= NULL
)
8773 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
8775 /* NOTE: If comp_dir is a relative path, this will also try the
8776 search path, which seems useful. */
8777 abfd
= try_open_dwop_file (path_to_try
, is_dwp
);
8778 xfree (path_to_try
);
8783 /* That didn't work, try debug-file-directory, which, despite its name,
8784 is a list of paths. */
8786 if (*debug_file_directory
== '\0')
8789 return try_open_dwop_file (file_name
, is_dwp
);
8792 /* This function is mapped across the sections and remembers the offset and
8793 size of each of the DWO debugging sections we are interested in. */
8796 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
8798 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
8799 const struct dwop_section_names
*names
= &dwop_section_names
;
8801 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8803 dwo_sections
->abbrev
.asection
= sectp
;
8804 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8806 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
8808 dwo_sections
->info
.asection
= sectp
;
8809 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
8811 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8813 dwo_sections
->line
.asection
= sectp
;
8814 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
8816 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8818 dwo_sections
->loc
.asection
= sectp
;
8819 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
8821 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8823 dwo_sections
->macinfo
.asection
= sectp
;
8824 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8826 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8828 dwo_sections
->macro
.asection
= sectp
;
8829 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
8831 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
8833 dwo_sections
->str
.asection
= sectp
;
8834 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
8836 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8838 dwo_sections
->str_offsets
.asection
= sectp
;
8839 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8841 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
8843 struct dwarf2_section_info type_section
;
8845 memset (&type_section
, 0, sizeof (type_section
));
8846 type_section
.asection
= sectp
;
8847 type_section
.size
= bfd_get_section_size (sectp
);
8848 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
8853 /* Initialize the use of the DWO file specified by DWO_NAME.
8854 The result is NULL if DWO_NAME can't be found. */
8856 static struct dwo_file
*
8857 open_and_init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8859 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8860 struct dwo_file
*dwo_file
;
8862 struct cleanup
*cleanups
;
8864 dbfd
= open_dwop_file (dwo_name
, comp_dir
, 0);
8867 if (dwarf2_read_debug
)
8868 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
8871 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8872 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8873 dwo_name
, strlen (dwo_name
));
8874 dwo_file
->dbfd
= dbfd
;
8876 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8878 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
8880 dwo_file
->cus
= create_dwo_debug_info_hash_table (dwo_file
);
8882 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8883 dwo_file
->sections
.types
);
8885 discard_cleanups (cleanups
);
8887 if (dwarf2_read_debug
)
8888 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
8893 /* This function is mapped across the sections and remembers the offset and
8894 size of each of the DWP debugging sections we are interested in. */
8897 dwarf2_locate_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
8899 struct dwp_file
*dwp_file
= dwp_file_ptr
;
8900 const struct dwop_section_names
*names
= &dwop_section_names
;
8901 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
8903 /* Record the ELF section number for later lookup: this is what the
8904 .debug_cu_index,.debug_tu_index tables use. */
8905 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
8906 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
8908 /* Look for specific sections that we need. */
8909 if (section_is_p (sectp
->name
, &names
->str_dwo
))
8911 dwp_file
->sections
.str
.asection
= sectp
;
8912 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
8914 else if (section_is_p (sectp
->name
, &names
->cu_index
))
8916 dwp_file
->sections
.cu_index
.asection
= sectp
;
8917 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
8919 else if (section_is_p (sectp
->name
, &names
->tu_index
))
8921 dwp_file
->sections
.tu_index
.asection
= sectp
;
8922 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
8926 /* Hash function for dwp_file loaded CUs/TUs. */
8929 hash_dwp_loaded_cutus (const void *item
)
8931 const struct dwo_unit
*dwo_unit
= item
;
8933 /* This drops the top 32 bits of the signature, but is ok for a hash. */
8934 return dwo_unit
->signature
;
8937 /* Equality function for dwp_file loaded CUs/TUs. */
8940 eq_dwp_loaded_cutus (const void *a
, const void *b
)
8942 const struct dwo_unit
*dua
= a
;
8943 const struct dwo_unit
*dub
= b
;
8945 return dua
->signature
== dub
->signature
;
8948 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
8951 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
8953 return htab_create_alloc_ex (3,
8954 hash_dwp_loaded_cutus
,
8955 eq_dwp_loaded_cutus
,
8957 &objfile
->objfile_obstack
,
8958 hashtab_obstack_allocate
,
8959 dummy_obstack_deallocate
);
8962 /* Initialize the use of the DWP file for the current objfile.
8963 By convention the name of the DWP file is ${objfile}.dwp.
8964 The result is NULL if it can't be found. */
8966 static struct dwp_file
*
8967 open_and_init_dwp_file (const char *comp_dir
)
8969 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8970 struct dwp_file
*dwp_file
;
8973 struct cleanup
*cleanups
;
8975 dwp_name
= xstrprintf ("%s.dwp", dwarf2_per_objfile
->objfile
->name
);
8976 cleanups
= make_cleanup (xfree
, dwp_name
);
8978 dbfd
= open_dwop_file (dwp_name
, comp_dir
, 1);
8981 if (dwarf2_read_debug
)
8982 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
8983 do_cleanups (cleanups
);
8986 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
8987 dwp_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8988 dwp_name
, strlen (dwp_name
));
8989 dwp_file
->dbfd
= dbfd
;
8990 do_cleanups (cleanups
);
8992 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwp_file
);
8994 /* +1: section 0 is unused */
8995 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
8996 dwp_file
->elf_sections
=
8997 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
8998 dwp_file
->num_sections
, asection
*);
9000 bfd_map_over_sections (dbfd
, dwarf2_locate_dwp_sections
, dwp_file
);
9002 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
9004 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
9006 dwp_file
->loaded_cutus
= allocate_dwp_loaded_cutus_table (objfile
);
9008 discard_cleanups (cleanups
);
9010 if (dwarf2_read_debug
)
9012 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
9013 fprintf_unfiltered (gdb_stdlog
,
9014 " %u CUs, %u TUs\n",
9015 dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0,
9016 dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0);
9022 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9023 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9024 or in the DWP file for the objfile, referenced by THIS_UNIT.
9025 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9026 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9028 This is called, for example, when wanting to read a variable with a
9029 complex location. Therefore we don't want to do file i/o for every call.
9030 Therefore we don't want to look for a DWO file on every call.
9031 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9032 then we check if we've already seen DWO_NAME, and only THEN do we check
9035 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9036 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9038 static struct dwo_unit
*
9039 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
9040 const char *dwo_name
, const char *comp_dir
,
9041 ULONGEST signature
, int is_debug_types
)
9043 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9044 const char *kind
= is_debug_types
? "TU" : "CU";
9045 void **dwo_file_slot
;
9046 struct dwo_file
*dwo_file
;
9047 struct dwp_file
*dwp_file
;
9049 /* Have we already read SIGNATURE from a DWP file? */
9051 if (! dwarf2_per_objfile
->dwp_checked
)
9053 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file (comp_dir
);
9054 dwarf2_per_objfile
->dwp_checked
= 1;
9056 dwp_file
= dwarf2_per_objfile
->dwp_file
;
9058 if (dwp_file
!= NULL
)
9060 const struct dwp_hash_table
*dwp_htab
=
9061 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9063 if (dwp_htab
!= NULL
)
9065 struct dwo_unit
*dwo_cutu
=
9066 lookup_dwo_in_dwp (dwp_file
, dwp_htab
, signature
, is_debug_types
);
9068 if (dwo_cutu
!= NULL
)
9070 if (dwarf2_read_debug
)
9072 fprintf_unfiltered (gdb_stdlog
,
9073 "Virtual DWO %s %s found: @%s\n",
9074 kind
, hex_string (signature
),
9075 host_address_to_string (dwo_cutu
));
9082 /* Have we already seen DWO_NAME? */
9084 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
);
9085 if (*dwo_file_slot
== NULL
)
9087 /* Read in the file and build a table of the DWOs it contains. */
9088 *dwo_file_slot
= open_and_init_dwo_file (dwo_name
, comp_dir
);
9090 /* NOTE: This will be NULL if unable to open the file. */
9091 dwo_file
= *dwo_file_slot
;
9093 if (dwo_file
!= NULL
)
9095 htab_t htab
= is_debug_types
? dwo_file
->tus
: dwo_file
->cus
;
9099 struct dwo_unit find_dwo_cutu
, *dwo_cutu
;
9101 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9102 find_dwo_cutu
.signature
= signature
;
9103 dwo_cutu
= htab_find (htab
, &find_dwo_cutu
);
9105 if (dwo_cutu
!= NULL
)
9107 if (dwarf2_read_debug
)
9109 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
9110 kind
, dwo_name
, hex_string (signature
),
9111 host_address_to_string (dwo_cutu
));
9118 /* We didn't find it. This could mean a dwo_id mismatch, or
9119 someone deleted the DWO/DWP file, or the search path isn't set up
9120 correctly to find the file. */
9122 if (dwarf2_read_debug
)
9124 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
9125 kind
, dwo_name
, hex_string (signature
));
9128 complaint (&symfile_complaints
,
9129 _("Could not find DWO CU referenced by CU at offset 0x%x"
9131 this_unit
->offset
.sect_off
, objfile
->name
);
9135 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9136 See lookup_dwo_cutu_unit for details. */
9138 static struct dwo_unit
*
9139 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9140 const char *dwo_name
, const char *comp_dir
,
9143 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
9146 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9147 See lookup_dwo_cutu_unit for details. */
9149 static struct dwo_unit
*
9150 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
9151 const char *dwo_name
, const char *comp_dir
)
9153 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
9156 /* Free all resources associated with DWO_FILE.
9157 Close the DWO file and munmap the sections.
9158 All memory should be on the objfile obstack. */
9161 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
9164 struct dwarf2_section_info
*section
;
9166 gdb_assert (dwo_file
->dbfd
!= objfile
->obfd
);
9167 gdb_bfd_unref (dwo_file
->dbfd
);
9169 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
9172 /* Wrapper for free_dwo_file for use in cleanups. */
9175 free_dwo_file_cleanup (void *arg
)
9177 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
9178 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9180 free_dwo_file (dwo_file
, objfile
);
9183 /* Traversal function for free_dwo_files. */
9186 free_dwo_file_from_slot (void **slot
, void *info
)
9188 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
9189 struct objfile
*objfile
= (struct objfile
*) info
;
9191 free_dwo_file (dwo_file
, objfile
);
9196 /* Free all resources associated with DWO_FILES. */
9199 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
9201 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
9204 /* Read in various DIEs. */
9206 /* qsort helper for inherit_abstract_dies. */
9209 unsigned_int_compar (const void *ap
, const void *bp
)
9211 unsigned int a
= *(unsigned int *) ap
;
9212 unsigned int b
= *(unsigned int *) bp
;
9214 return (a
> b
) - (b
> a
);
9217 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9218 Inherit only the children of the DW_AT_abstract_origin DIE not being
9219 already referenced by DW_AT_abstract_origin from the children of the
9223 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9225 struct die_info
*child_die
;
9226 unsigned die_children_count
;
9227 /* CU offsets which were referenced by children of the current DIE. */
9228 sect_offset
*offsets
;
9229 sect_offset
*offsets_end
, *offsetp
;
9230 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9231 struct die_info
*origin_die
;
9232 /* Iterator of the ORIGIN_DIE children. */
9233 struct die_info
*origin_child_die
;
9234 struct cleanup
*cleanups
;
9235 struct attribute
*attr
;
9236 struct dwarf2_cu
*origin_cu
;
9237 struct pending
**origin_previous_list_in_scope
;
9239 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9243 /* Note that following die references may follow to a die in a
9247 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9249 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9251 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9252 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9254 if (die
->tag
!= origin_die
->tag
9255 && !(die
->tag
== DW_TAG_inlined_subroutine
9256 && origin_die
->tag
== DW_TAG_subprogram
))
9257 complaint (&symfile_complaints
,
9258 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9259 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
9261 child_die
= die
->child
;
9262 die_children_count
= 0;
9263 while (child_die
&& child_die
->tag
)
9265 child_die
= sibling_die (child_die
);
9266 die_children_count
++;
9268 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
9269 cleanups
= make_cleanup (xfree
, offsets
);
9271 offsets_end
= offsets
;
9272 child_die
= die
->child
;
9273 while (child_die
&& child_die
->tag
)
9275 /* For each CHILD_DIE, find the corresponding child of
9276 ORIGIN_DIE. If there is more than one layer of
9277 DW_AT_abstract_origin, follow them all; there shouldn't be,
9278 but GCC versions at least through 4.4 generate this (GCC PR
9280 struct die_info
*child_origin_die
= child_die
;
9281 struct dwarf2_cu
*child_origin_cu
= cu
;
9285 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9289 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9293 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9294 counterpart may exist. */
9295 if (child_origin_die
!= child_die
)
9297 if (child_die
->tag
!= child_origin_die
->tag
9298 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9299 && child_origin_die
->tag
== DW_TAG_subprogram
))
9300 complaint (&symfile_complaints
,
9301 _("Child DIE 0x%x and its abstract origin 0x%x have "
9302 "different tags"), child_die
->offset
.sect_off
,
9303 child_origin_die
->offset
.sect_off
);
9304 if (child_origin_die
->parent
!= origin_die
)
9305 complaint (&symfile_complaints
,
9306 _("Child DIE 0x%x and its abstract origin 0x%x have "
9307 "different parents"), child_die
->offset
.sect_off
,
9308 child_origin_die
->offset
.sect_off
);
9310 *offsets_end
++ = child_origin_die
->offset
;
9312 child_die
= sibling_die (child_die
);
9314 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
9315 unsigned_int_compar
);
9316 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
9317 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
9318 complaint (&symfile_complaints
,
9319 _("Multiple children of DIE 0x%x refer "
9320 "to DIE 0x%x as their abstract origin"),
9321 die
->offset
.sect_off
, offsetp
->sect_off
);
9324 origin_child_die
= origin_die
->child
;
9325 while (origin_child_die
&& origin_child_die
->tag
)
9327 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9328 while (offsetp
< offsets_end
9329 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
9331 if (offsetp
>= offsets_end
9332 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
9334 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9335 process_die (origin_child_die
, origin_cu
);
9337 origin_child_die
= sibling_die (origin_child_die
);
9339 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9341 do_cleanups (cleanups
);
9345 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9347 struct objfile
*objfile
= cu
->objfile
;
9348 struct context_stack
*new;
9351 struct die_info
*child_die
;
9352 struct attribute
*attr
, *call_line
, *call_file
;
9355 struct block
*block
;
9356 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9357 VEC (symbolp
) *template_args
= NULL
;
9358 struct template_symbol
*templ_func
= NULL
;
9362 /* If we do not have call site information, we can't show the
9363 caller of this inlined function. That's too confusing, so
9364 only use the scope for local variables. */
9365 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
9366 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
9367 if (call_line
== NULL
|| call_file
== NULL
)
9369 read_lexical_block_scope (die
, cu
);
9374 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9376 name
= dwarf2_name (die
, cu
);
9378 /* Ignore functions with missing or empty names. These are actually
9379 illegal according to the DWARF standard. */
9382 complaint (&symfile_complaints
,
9383 _("missing name for subprogram DIE at %d"),
9384 die
->offset
.sect_off
);
9388 /* Ignore functions with missing or invalid low and high pc attributes. */
9389 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9391 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9392 if (!attr
|| !DW_UNSND (attr
))
9393 complaint (&symfile_complaints
,
9394 _("cannot get low and high bounds "
9395 "for subprogram DIE at %d"),
9396 die
->offset
.sect_off
);
9403 /* If we have any template arguments, then we must allocate a
9404 different sort of symbol. */
9405 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
9407 if (child_die
->tag
== DW_TAG_template_type_param
9408 || child_die
->tag
== DW_TAG_template_value_param
)
9410 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
9411 struct template_symbol
);
9412 templ_func
->base
.is_cplus_template_function
= 1;
9417 new = push_context (0, lowpc
);
9418 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
9419 (struct symbol
*) templ_func
);
9421 /* If there is a location expression for DW_AT_frame_base, record
9423 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
9425 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
9426 expression is being recorded directly in the function's symbol
9427 and not in a separate frame-base object. I guess this hack is
9428 to avoid adding some sort of frame-base adjunct/annex to the
9429 function's symbol :-(. The problem with doing this is that it
9430 results in a function symbol with a location expression that
9431 has nothing to do with the location of the function, ouch! The
9432 relationship should be: a function's symbol has-a frame base; a
9433 frame-base has-a location expression. */
9434 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
9436 cu
->list_in_scope
= &local_symbols
;
9438 if (die
->child
!= NULL
)
9440 child_die
= die
->child
;
9441 while (child_die
&& child_die
->tag
)
9443 if (child_die
->tag
== DW_TAG_template_type_param
9444 || child_die
->tag
== DW_TAG_template_value_param
)
9446 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9449 VEC_safe_push (symbolp
, template_args
, arg
);
9452 process_die (child_die
, cu
);
9453 child_die
= sibling_die (child_die
);
9457 inherit_abstract_dies (die
, cu
);
9459 /* If we have a DW_AT_specification, we might need to import using
9460 directives from the context of the specification DIE. See the
9461 comment in determine_prefix. */
9462 if (cu
->language
== language_cplus
9463 && dwarf2_attr (die
, DW_AT_specification
, cu
))
9465 struct dwarf2_cu
*spec_cu
= cu
;
9466 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
9470 child_die
= spec_die
->child
;
9471 while (child_die
&& child_die
->tag
)
9473 if (child_die
->tag
== DW_TAG_imported_module
)
9474 process_die (child_die
, spec_cu
);
9475 child_die
= sibling_die (child_die
);
9478 /* In some cases, GCC generates specification DIEs that
9479 themselves contain DW_AT_specification attributes. */
9480 spec_die
= die_specification (spec_die
, &spec_cu
);
9484 new = pop_context ();
9485 /* Make a block for the local symbols within. */
9486 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
9487 lowpc
, highpc
, objfile
);
9489 /* For C++, set the block's scope. */
9490 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
9491 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
9492 determine_prefix (die
, cu
),
9493 processing_has_namespace_info
);
9495 /* If we have address ranges, record them. */
9496 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9498 /* Attach template arguments to function. */
9499 if (! VEC_empty (symbolp
, template_args
))
9501 gdb_assert (templ_func
!= NULL
);
9503 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
9504 templ_func
->template_arguments
9505 = obstack_alloc (&objfile
->objfile_obstack
,
9506 (templ_func
->n_template_arguments
9507 * sizeof (struct symbol
*)));
9508 memcpy (templ_func
->template_arguments
,
9509 VEC_address (symbolp
, template_args
),
9510 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
9511 VEC_free (symbolp
, template_args
);
9514 /* In C++, we can have functions nested inside functions (e.g., when
9515 a function declares a class that has methods). This means that
9516 when we finish processing a function scope, we may need to go
9517 back to building a containing block's symbol lists. */
9518 local_symbols
= new->locals
;
9519 using_directives
= new->using_directives
;
9521 /* If we've finished processing a top-level function, subsequent
9522 symbols go in the file symbol list. */
9523 if (outermost_context_p ())
9524 cu
->list_in_scope
= &file_symbols
;
9527 /* Process all the DIES contained within a lexical block scope. Start
9528 a new scope, process the dies, and then close the scope. */
9531 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9533 struct objfile
*objfile
= cu
->objfile
;
9534 struct context_stack
*new;
9535 CORE_ADDR lowpc
, highpc
;
9536 struct die_info
*child_die
;
9539 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9541 /* Ignore blocks with missing or invalid low and high pc attributes. */
9542 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9543 as multiple lexical blocks? Handling children in a sane way would
9544 be nasty. Might be easier to properly extend generic blocks to
9546 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9551 push_context (0, lowpc
);
9552 if (die
->child
!= NULL
)
9554 child_die
= die
->child
;
9555 while (child_die
&& child_die
->tag
)
9557 process_die (child_die
, cu
);
9558 child_die
= sibling_die (child_die
);
9561 new = pop_context ();
9563 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
9566 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
9569 /* Note that recording ranges after traversing children, as we
9570 do here, means that recording a parent's ranges entails
9571 walking across all its children's ranges as they appear in
9572 the address map, which is quadratic behavior.
9574 It would be nicer to record the parent's ranges before
9575 traversing its children, simply overriding whatever you find
9576 there. But since we don't even decide whether to create a
9577 block until after we've traversed its children, that's hard
9579 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9581 local_symbols
= new->locals
;
9582 using_directives
= new->using_directives
;
9585 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9588 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9590 struct objfile
*objfile
= cu
->objfile
;
9591 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9592 CORE_ADDR pc
, baseaddr
;
9593 struct attribute
*attr
;
9594 struct call_site
*call_site
, call_site_local
;
9597 struct die_info
*child_die
;
9599 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9601 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9604 complaint (&symfile_complaints
,
9605 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9606 "DIE 0x%x [in module %s]"),
9607 die
->offset
.sect_off
, objfile
->name
);
9610 pc
= DW_ADDR (attr
) + baseaddr
;
9612 if (cu
->call_site_htab
== NULL
)
9613 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
9614 NULL
, &objfile
->objfile_obstack
,
9615 hashtab_obstack_allocate
, NULL
);
9616 call_site_local
.pc
= pc
;
9617 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
9620 complaint (&symfile_complaints
,
9621 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9622 "DIE 0x%x [in module %s]"),
9623 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
9627 /* Count parameters at the caller. */
9630 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9631 child_die
= sibling_die (child_die
))
9633 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9635 complaint (&symfile_complaints
,
9636 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9637 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9638 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
9645 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
9646 (sizeof (*call_site
)
9647 + (sizeof (*call_site
->parameter
)
9650 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
9653 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
9655 struct die_info
*func_die
;
9657 /* Skip also over DW_TAG_inlined_subroutine. */
9658 for (func_die
= die
->parent
;
9659 func_die
&& func_die
->tag
!= DW_TAG_subprogram
9660 && func_die
->tag
!= DW_TAG_subroutine_type
;
9661 func_die
= func_die
->parent
);
9663 /* DW_AT_GNU_all_call_sites is a superset
9664 of DW_AT_GNU_all_tail_call_sites. */
9666 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
9667 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
9669 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9670 not complete. But keep CALL_SITE for look ups via call_site_htab,
9671 both the initial caller containing the real return address PC and
9672 the final callee containing the current PC of a chain of tail
9673 calls do not need to have the tail call list complete. But any
9674 function candidate for a virtual tail call frame searched via
9675 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9676 determined unambiguously. */
9680 struct type
*func_type
= NULL
;
9683 func_type
= get_die_type (func_die
, cu
);
9684 if (func_type
!= NULL
)
9686 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
9688 /* Enlist this call site to the function. */
9689 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
9690 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
9693 complaint (&symfile_complaints
,
9694 _("Cannot find function owning DW_TAG_GNU_call_site "
9695 "DIE 0x%x [in module %s]"),
9696 die
->offset
.sect_off
, objfile
->name
);
9700 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
9702 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9703 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
9704 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
9705 /* Keep NULL DWARF_BLOCK. */;
9706 else if (attr_form_is_block (attr
))
9708 struct dwarf2_locexpr_baton
*dlbaton
;
9710 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
9711 dlbaton
->data
= DW_BLOCK (attr
)->data
;
9712 dlbaton
->size
= DW_BLOCK (attr
)->size
;
9713 dlbaton
->per_cu
= cu
->per_cu
;
9715 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
9717 else if (is_ref_attr (attr
))
9719 struct dwarf2_cu
*target_cu
= cu
;
9720 struct die_info
*target_die
;
9722 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
9723 gdb_assert (target_cu
->objfile
== objfile
);
9724 if (die_is_declaration (target_die
, target_cu
))
9726 const char *target_physname
;
9728 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
9729 if (target_physname
== NULL
)
9730 complaint (&symfile_complaints
,
9731 _("DW_AT_GNU_call_site_target target DIE has invalid "
9732 "physname, for referencing DIE 0x%x [in module %s]"),
9733 die
->offset
.sect_off
, objfile
->name
);
9735 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
9741 /* DW_AT_entry_pc should be preferred. */
9742 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
9743 complaint (&symfile_complaints
,
9744 _("DW_AT_GNU_call_site_target target DIE has invalid "
9745 "low pc, for referencing DIE 0x%x [in module %s]"),
9746 die
->offset
.sect_off
, objfile
->name
);
9748 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
9752 complaint (&symfile_complaints
,
9753 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9754 "block nor reference, for DIE 0x%x [in module %s]"),
9755 die
->offset
.sect_off
, objfile
->name
);
9757 call_site
->per_cu
= cu
->per_cu
;
9759 for (child_die
= die
->child
;
9760 child_die
&& child_die
->tag
;
9761 child_die
= sibling_die (child_die
))
9763 struct call_site_parameter
*parameter
;
9764 struct attribute
*loc
, *origin
;
9766 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9768 /* Already printed the complaint above. */
9772 gdb_assert (call_site
->parameter_count
< nparams
);
9773 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
9775 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9776 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9777 register is contained in DW_AT_GNU_call_site_value. */
9779 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
9780 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
9781 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
9785 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
9786 offset
= dwarf2_get_ref_die_offset (origin
);
9787 if (!offset_in_cu_p (&cu
->header
, offset
))
9789 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9790 binding can be done only inside one CU. Such referenced DIE
9791 therefore cannot be even moved to DW_TAG_partial_unit. */
9792 complaint (&symfile_complaints
,
9793 _("DW_AT_abstract_origin offset is not in CU for "
9794 "DW_TAG_GNU_call_site child DIE 0x%x "
9796 child_die
->offset
.sect_off
, objfile
->name
);
9799 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
9800 - cu
->header
.offset
.sect_off
);
9802 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
9804 complaint (&symfile_complaints
,
9805 _("No DW_FORM_block* DW_AT_location for "
9806 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9807 child_die
->offset
.sect_off
, objfile
->name
);
9812 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
9813 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
9814 if (parameter
->u
.dwarf_reg
!= -1)
9815 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
9816 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
9817 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
9818 ¶meter
->u
.fb_offset
))
9819 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
9822 complaint (&symfile_complaints
,
9823 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9824 "for DW_FORM_block* DW_AT_location is supported for "
9825 "DW_TAG_GNU_call_site child DIE 0x%x "
9827 child_die
->offset
.sect_off
, objfile
->name
);
9832 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9833 if (!attr_form_is_block (attr
))
9835 complaint (&symfile_complaints
,
9836 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9837 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9838 child_die
->offset
.sect_off
, objfile
->name
);
9841 parameter
->value
= DW_BLOCK (attr
)->data
;
9842 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9844 /* Parameters are not pre-cleared by memset above. */
9845 parameter
->data_value
= NULL
;
9846 parameter
->data_value_size
= 0;
9847 call_site
->parameter_count
++;
9849 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9852 if (!attr_form_is_block (attr
))
9853 complaint (&symfile_complaints
,
9854 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9855 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9856 child_die
->offset
.sect_off
, objfile
->name
);
9859 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9860 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9866 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9867 Return 1 if the attributes are present and valid, otherwise, return 0.
9868 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9871 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9872 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9873 struct partial_symtab
*ranges_pst
)
9875 struct objfile
*objfile
= cu
->objfile
;
9876 struct comp_unit_head
*cu_header
= &cu
->header
;
9877 bfd
*obfd
= objfile
->obfd
;
9878 unsigned int addr_size
= cu_header
->addr_size
;
9879 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9880 /* Base address selection entry. */
9891 found_base
= cu
->base_known
;
9892 base
= cu
->base_address
;
9894 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9895 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9897 complaint (&symfile_complaints
,
9898 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9902 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9904 /* Read in the largest possible address. */
9905 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9906 if ((marker
& mask
) == mask
)
9908 /* If we found the largest possible address, then
9909 read the base address. */
9910 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9911 buffer
+= 2 * addr_size
;
9912 offset
+= 2 * addr_size
;
9918 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9922 CORE_ADDR range_beginning
, range_end
;
9924 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9925 buffer
+= addr_size
;
9926 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9927 buffer
+= addr_size
;
9928 offset
+= 2 * addr_size
;
9930 /* An end of list marker is a pair of zero addresses. */
9931 if (range_beginning
== 0 && range_end
== 0)
9932 /* Found the end of list entry. */
9935 /* Each base address selection entry is a pair of 2 values.
9936 The first is the largest possible address, the second is
9937 the base address. Check for a base address here. */
9938 if ((range_beginning
& mask
) == mask
)
9940 /* If we found the largest possible address, then
9941 read the base address. */
9942 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9949 /* We have no valid base address for the ranges
9951 complaint (&symfile_complaints
,
9952 _("Invalid .debug_ranges data (no base address)"));
9956 if (range_beginning
> range_end
)
9958 /* Inverted range entries are invalid. */
9959 complaint (&symfile_complaints
,
9960 _("Invalid .debug_ranges data (inverted range)"));
9964 /* Empty range entries have no effect. */
9965 if (range_beginning
== range_end
)
9968 range_beginning
+= base
;
9971 /* A not-uncommon case of bad debug info.
9972 Don't pollute the addrmap with bad data. */
9973 if (range_beginning
+ baseaddr
== 0
9974 && !dwarf2_per_objfile
->has_section_at_zero
)
9976 complaint (&symfile_complaints
,
9977 _(".debug_ranges entry has start address of zero"
9978 " [in module %s]"), objfile
->name
);
9982 if (ranges_pst
!= NULL
)
9983 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9984 range_beginning
+ baseaddr
,
9985 range_end
- 1 + baseaddr
,
9988 /* FIXME: This is recording everything as a low-high
9989 segment of consecutive addresses. We should have a
9990 data structure for discontiguous block ranges
9994 low
= range_beginning
;
10000 if (range_beginning
< low
)
10001 low
= range_beginning
;
10002 if (range_end
> high
)
10008 /* If the first entry is an end-of-list marker, the range
10009 describes an empty scope, i.e. no instructions. */
10015 *high_return
= high
;
10019 /* Get low and high pc attributes from a die. Return 1 if the attributes
10020 are present and valid, otherwise, return 0. Return -1 if the range is
10021 discontinuous, i.e. derived from DW_AT_ranges information. */
10024 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
10025 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
10026 struct partial_symtab
*pst
)
10028 struct attribute
*attr
;
10029 struct attribute
*attr_high
;
10031 CORE_ADDR high
= 0;
10034 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10037 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10040 low
= DW_ADDR (attr
);
10041 if (attr_high
->form
== DW_FORM_addr
10042 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10043 high
= DW_ADDR (attr_high
);
10045 high
= low
+ DW_UNSND (attr_high
);
10048 /* Found high w/o low attribute. */
10051 /* Found consecutive range of addresses. */
10056 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10059 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
10061 /* Value of the DW_AT_ranges attribute is the offset in the
10062 .debug_ranges section. */
10063 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
10065 /* Found discontinuous range of addresses. */
10070 /* read_partial_die has also the strict LOW < HIGH requirement. */
10074 /* When using the GNU linker, .gnu.linkonce. sections are used to
10075 eliminate duplicate copies of functions and vtables and such.
10076 The linker will arbitrarily choose one and discard the others.
10077 The AT_*_pc values for such functions refer to local labels in
10078 these sections. If the section from that file was discarded, the
10079 labels are not in the output, so the relocs get a value of 0.
10080 If this is a discarded function, mark the pc bounds as invalid,
10081 so that GDB will ignore it. */
10082 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10091 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10092 its low and high PC addresses. Do nothing if these addresses could not
10093 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10094 and HIGHPC to the high address if greater than HIGHPC. */
10097 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
10098 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10099 struct dwarf2_cu
*cu
)
10101 CORE_ADDR low
, high
;
10102 struct die_info
*child
= die
->child
;
10104 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
10106 *lowpc
= min (*lowpc
, low
);
10107 *highpc
= max (*highpc
, high
);
10110 /* If the language does not allow nested subprograms (either inside
10111 subprograms or lexical blocks), we're done. */
10112 if (cu
->language
!= language_ada
)
10115 /* Check all the children of the given DIE. If it contains nested
10116 subprograms, then check their pc bounds. Likewise, we need to
10117 check lexical blocks as well, as they may also contain subprogram
10119 while (child
&& child
->tag
)
10121 if (child
->tag
== DW_TAG_subprogram
10122 || child
->tag
== DW_TAG_lexical_block
)
10123 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
10124 child
= sibling_die (child
);
10128 /* Get the low and high pc's represented by the scope DIE, and store
10129 them in *LOWPC and *HIGHPC. If the correct values can't be
10130 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10133 get_scope_pc_bounds (struct die_info
*die
,
10134 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10135 struct dwarf2_cu
*cu
)
10137 CORE_ADDR best_low
= (CORE_ADDR
) -1;
10138 CORE_ADDR best_high
= (CORE_ADDR
) 0;
10139 CORE_ADDR current_low
, current_high
;
10141 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
10143 best_low
= current_low
;
10144 best_high
= current_high
;
10148 struct die_info
*child
= die
->child
;
10150 while (child
&& child
->tag
)
10152 switch (child
->tag
) {
10153 case DW_TAG_subprogram
:
10154 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
10156 case DW_TAG_namespace
:
10157 case DW_TAG_module
:
10158 /* FIXME: carlton/2004-01-16: Should we do this for
10159 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10160 that current GCC's always emit the DIEs corresponding
10161 to definitions of methods of classes as children of a
10162 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10163 the DIEs giving the declarations, which could be
10164 anywhere). But I don't see any reason why the
10165 standards says that they have to be there. */
10166 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
10168 if (current_low
!= ((CORE_ADDR
) -1))
10170 best_low
= min (best_low
, current_low
);
10171 best_high
= max (best_high
, current_high
);
10179 child
= sibling_die (child
);
10184 *highpc
= best_high
;
10187 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10191 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
10192 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
10194 struct objfile
*objfile
= cu
->objfile
;
10195 struct attribute
*attr
;
10196 struct attribute
*attr_high
;
10198 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10201 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10204 CORE_ADDR low
= DW_ADDR (attr
);
10206 if (attr_high
->form
== DW_FORM_addr
10207 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10208 high
= DW_ADDR (attr_high
);
10210 high
= low
+ DW_UNSND (attr_high
);
10212 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
10216 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10219 bfd
*obfd
= objfile
->obfd
;
10221 /* The value of the DW_AT_ranges attribute is the offset of the
10222 address range list in the .debug_ranges section. */
10223 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
10224 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10226 /* For some target architectures, but not others, the
10227 read_address function sign-extends the addresses it returns.
10228 To recognize base address selection entries, we need a
10230 unsigned int addr_size
= cu
->header
.addr_size
;
10231 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10233 /* The base address, to which the next pair is relative. Note
10234 that this 'base' is a DWARF concept: most entries in a range
10235 list are relative, to reduce the number of relocs against the
10236 debugging information. This is separate from this function's
10237 'baseaddr' argument, which GDB uses to relocate debugging
10238 information from a shared library based on the address at
10239 which the library was loaded. */
10240 CORE_ADDR base
= cu
->base_address
;
10241 int base_known
= cu
->base_known
;
10243 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
10244 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
10246 complaint (&symfile_complaints
,
10247 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10254 unsigned int bytes_read
;
10255 CORE_ADDR start
, end
;
10257 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10258 buffer
+= bytes_read
;
10259 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10260 buffer
+= bytes_read
;
10262 /* Did we find the end of the range list? */
10263 if (start
== 0 && end
== 0)
10266 /* Did we find a base address selection entry? */
10267 else if ((start
& base_select_mask
) == base_select_mask
)
10273 /* We found an ordinary address range. */
10278 complaint (&symfile_complaints
,
10279 _("Invalid .debug_ranges data "
10280 "(no base address)"));
10286 /* Inverted range entries are invalid. */
10287 complaint (&symfile_complaints
,
10288 _("Invalid .debug_ranges data "
10289 "(inverted range)"));
10293 /* Empty range entries have no effect. */
10297 start
+= base
+ baseaddr
;
10298 end
+= base
+ baseaddr
;
10300 /* A not-uncommon case of bad debug info.
10301 Don't pollute the addrmap with bad data. */
10302 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10304 complaint (&symfile_complaints
,
10305 _(".debug_ranges entry has start address of zero"
10306 " [in module %s]"), objfile
->name
);
10310 record_block_range (block
, start
, end
- 1);
10316 /* Check whether the producer field indicates either of GCC < 4.6, or the
10317 Intel C/C++ compiler, and cache the result in CU. */
10320 check_producer (struct dwarf2_cu
*cu
)
10323 int major
, minor
, release
;
10325 if (cu
->producer
== NULL
)
10327 /* For unknown compilers expect their behavior is DWARF version
10330 GCC started to support .debug_types sections by -gdwarf-4 since
10331 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10332 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10333 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10334 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10336 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
10338 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10340 cs
= &cu
->producer
[strlen ("GNU ")];
10341 while (*cs
&& !isdigit (*cs
))
10343 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
10345 /* Not recognized as GCC. */
10349 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
10350 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
10353 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10354 cu
->producer_is_icc
= 1;
10357 /* For other non-GCC compilers, expect their behavior is DWARF version
10361 cu
->checked_producer
= 1;
10364 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10365 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10366 during 4.6.0 experimental. */
10369 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
10371 if (!cu
->checked_producer
)
10372 check_producer (cu
);
10374 return cu
->producer_is_gxx_lt_4_6
;
10377 /* Return the default accessibility type if it is not overriden by
10378 DW_AT_accessibility. */
10380 static enum dwarf_access_attribute
10381 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
10383 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
10385 /* The default DWARF 2 accessibility for members is public, the default
10386 accessibility for inheritance is private. */
10388 if (die
->tag
!= DW_TAG_inheritance
)
10389 return DW_ACCESS_public
;
10391 return DW_ACCESS_private
;
10395 /* DWARF 3+ defines the default accessibility a different way. The same
10396 rules apply now for DW_TAG_inheritance as for the members and it only
10397 depends on the container kind. */
10399 if (die
->parent
->tag
== DW_TAG_class_type
)
10400 return DW_ACCESS_private
;
10402 return DW_ACCESS_public
;
10406 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10407 offset. If the attribute was not found return 0, otherwise return
10408 1. If it was found but could not properly be handled, set *OFFSET
10412 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
10415 struct attribute
*attr
;
10417 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
10422 /* Note that we do not check for a section offset first here.
10423 This is because DW_AT_data_member_location is new in DWARF 4,
10424 so if we see it, we can assume that a constant form is really
10425 a constant and not a section offset. */
10426 if (attr_form_is_constant (attr
))
10427 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
10428 else if (attr_form_is_section_offset (attr
))
10429 dwarf2_complex_location_expr_complaint ();
10430 else if (attr_form_is_block (attr
))
10431 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10433 dwarf2_complex_location_expr_complaint ();
10441 /* Add an aggregate field to the field list. */
10444 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
10445 struct dwarf2_cu
*cu
)
10447 struct objfile
*objfile
= cu
->objfile
;
10448 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10449 struct nextfield
*new_field
;
10450 struct attribute
*attr
;
10452 char *fieldname
= "";
10454 /* Allocate a new field list entry and link it in. */
10455 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
10456 make_cleanup (xfree
, new_field
);
10457 memset (new_field
, 0, sizeof (struct nextfield
));
10459 if (die
->tag
== DW_TAG_inheritance
)
10461 new_field
->next
= fip
->baseclasses
;
10462 fip
->baseclasses
= new_field
;
10466 new_field
->next
= fip
->fields
;
10467 fip
->fields
= new_field
;
10471 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10473 new_field
->accessibility
= DW_UNSND (attr
);
10475 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
10476 if (new_field
->accessibility
!= DW_ACCESS_public
)
10477 fip
->non_public_fields
= 1;
10479 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10481 new_field
->virtuality
= DW_UNSND (attr
);
10483 new_field
->virtuality
= DW_VIRTUALITY_none
;
10485 fp
= &new_field
->field
;
10487 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
10491 /* Data member other than a C++ static data member. */
10493 /* Get type of field. */
10494 fp
->type
= die_type (die
, cu
);
10496 SET_FIELD_BITPOS (*fp
, 0);
10498 /* Get bit size of field (zero if none). */
10499 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
10502 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
10506 FIELD_BITSIZE (*fp
) = 0;
10509 /* Get bit offset of field. */
10510 if (handle_data_member_location (die
, cu
, &offset
))
10511 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10512 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
10515 if (gdbarch_bits_big_endian (gdbarch
))
10517 /* For big endian bits, the DW_AT_bit_offset gives the
10518 additional bit offset from the MSB of the containing
10519 anonymous object to the MSB of the field. We don't
10520 have to do anything special since we don't need to
10521 know the size of the anonymous object. */
10522 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
10526 /* For little endian bits, compute the bit offset to the
10527 MSB of the anonymous object, subtract off the number of
10528 bits from the MSB of the field to the MSB of the
10529 object, and then subtract off the number of bits of
10530 the field itself. The result is the bit offset of
10531 the LSB of the field. */
10532 int anonymous_size
;
10533 int bit_offset
= DW_UNSND (attr
);
10535 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10538 /* The size of the anonymous object containing
10539 the bit field is explicit, so use the
10540 indicated size (in bytes). */
10541 anonymous_size
= DW_UNSND (attr
);
10545 /* The size of the anonymous object containing
10546 the bit field must be inferred from the type
10547 attribute of the data member containing the
10549 anonymous_size
= TYPE_LENGTH (fp
->type
);
10551 SET_FIELD_BITPOS (*fp
,
10552 (FIELD_BITPOS (*fp
)
10553 + anonymous_size
* bits_per_byte
10554 - bit_offset
- FIELD_BITSIZE (*fp
)));
10558 /* Get name of field. */
10559 fieldname
= dwarf2_name (die
, cu
);
10560 if (fieldname
== NULL
)
10563 /* The name is already allocated along with this objfile, so we don't
10564 need to duplicate it for the type. */
10565 fp
->name
= fieldname
;
10567 /* Change accessibility for artificial fields (e.g. virtual table
10568 pointer or virtual base class pointer) to private. */
10569 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
10571 FIELD_ARTIFICIAL (*fp
) = 1;
10572 new_field
->accessibility
= DW_ACCESS_private
;
10573 fip
->non_public_fields
= 1;
10576 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
10578 /* C++ static member. */
10580 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10581 is a declaration, but all versions of G++ as of this writing
10582 (so through at least 3.2.1) incorrectly generate
10583 DW_TAG_variable tags. */
10585 const char *physname
;
10587 /* Get name of field. */
10588 fieldname
= dwarf2_name (die
, cu
);
10589 if (fieldname
== NULL
)
10592 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10594 /* Only create a symbol if this is an external value.
10595 new_symbol checks this and puts the value in the global symbol
10596 table, which we want. If it is not external, new_symbol
10597 will try to put the value in cu->list_in_scope which is wrong. */
10598 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
10600 /* A static const member, not much different than an enum as far as
10601 we're concerned, except that we can support more types. */
10602 new_symbol (die
, NULL
, cu
);
10605 /* Get physical name. */
10606 physname
= dwarf2_physname (fieldname
, die
, cu
);
10608 /* The name is already allocated along with this objfile, so we don't
10609 need to duplicate it for the type. */
10610 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
10611 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10612 FIELD_NAME (*fp
) = fieldname
;
10614 else if (die
->tag
== DW_TAG_inheritance
)
10618 /* C++ base class field. */
10619 if (handle_data_member_location (die
, cu
, &offset
))
10620 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10621 FIELD_BITSIZE (*fp
) = 0;
10622 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10623 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
10624 fip
->nbaseclasses
++;
10628 /* Add a typedef defined in the scope of the FIP's class. */
10631 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
10632 struct dwarf2_cu
*cu
)
10634 struct objfile
*objfile
= cu
->objfile
;
10635 struct typedef_field_list
*new_field
;
10636 struct attribute
*attr
;
10637 struct typedef_field
*fp
;
10638 char *fieldname
= "";
10640 /* Allocate a new field list entry and link it in. */
10641 new_field
= xzalloc (sizeof (*new_field
));
10642 make_cleanup (xfree
, new_field
);
10644 gdb_assert (die
->tag
== DW_TAG_typedef
);
10646 fp
= &new_field
->field
;
10648 /* Get name of field. */
10649 fp
->name
= dwarf2_name (die
, cu
);
10650 if (fp
->name
== NULL
)
10653 fp
->type
= read_type_die (die
, cu
);
10655 new_field
->next
= fip
->typedef_field_list
;
10656 fip
->typedef_field_list
= new_field
;
10657 fip
->typedef_field_list_count
++;
10660 /* Create the vector of fields, and attach it to the type. */
10663 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
10664 struct dwarf2_cu
*cu
)
10666 int nfields
= fip
->nfields
;
10668 /* Record the field count, allocate space for the array of fields,
10669 and create blank accessibility bitfields if necessary. */
10670 TYPE_NFIELDS (type
) = nfields
;
10671 TYPE_FIELDS (type
) = (struct field
*)
10672 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
10673 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
10675 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
10677 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10679 TYPE_FIELD_PRIVATE_BITS (type
) =
10680 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10681 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
10683 TYPE_FIELD_PROTECTED_BITS (type
) =
10684 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10685 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
10687 TYPE_FIELD_IGNORE_BITS (type
) =
10688 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10689 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
10692 /* If the type has baseclasses, allocate and clear a bit vector for
10693 TYPE_FIELD_VIRTUAL_BITS. */
10694 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
10696 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
10697 unsigned char *pointer
;
10699 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10700 pointer
= TYPE_ALLOC (type
, num_bytes
);
10701 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
10702 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
10703 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
10706 /* Copy the saved-up fields into the field vector. Start from the head of
10707 the list, adding to the tail of the field array, so that they end up in
10708 the same order in the array in which they were added to the list. */
10709 while (nfields
-- > 0)
10711 struct nextfield
*fieldp
;
10715 fieldp
= fip
->fields
;
10716 fip
->fields
= fieldp
->next
;
10720 fieldp
= fip
->baseclasses
;
10721 fip
->baseclasses
= fieldp
->next
;
10724 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
10725 switch (fieldp
->accessibility
)
10727 case DW_ACCESS_private
:
10728 if (cu
->language
!= language_ada
)
10729 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
10732 case DW_ACCESS_protected
:
10733 if (cu
->language
!= language_ada
)
10734 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
10737 case DW_ACCESS_public
:
10741 /* Unknown accessibility. Complain and treat it as public. */
10743 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
10744 fieldp
->accessibility
);
10748 if (nfields
< fip
->nbaseclasses
)
10750 switch (fieldp
->virtuality
)
10752 case DW_VIRTUALITY_virtual
:
10753 case DW_VIRTUALITY_pure_virtual
:
10754 if (cu
->language
== language_ada
)
10755 error (_("unexpected virtuality in component of Ada type"));
10756 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
10763 /* Add a member function to the proper fieldlist. */
10766 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
10767 struct type
*type
, struct dwarf2_cu
*cu
)
10769 struct objfile
*objfile
= cu
->objfile
;
10770 struct attribute
*attr
;
10771 struct fnfieldlist
*flp
;
10773 struct fn_field
*fnp
;
10775 struct nextfnfield
*new_fnfield
;
10776 struct type
*this_type
;
10777 enum dwarf_access_attribute accessibility
;
10779 if (cu
->language
== language_ada
)
10780 error (_("unexpected member function in Ada type"));
10782 /* Get name of member function. */
10783 fieldname
= dwarf2_name (die
, cu
);
10784 if (fieldname
== NULL
)
10787 /* Look up member function name in fieldlist. */
10788 for (i
= 0; i
< fip
->nfnfields
; i
++)
10790 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
10794 /* Create new list element if necessary. */
10795 if (i
< fip
->nfnfields
)
10796 flp
= &fip
->fnfieldlists
[i
];
10799 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10801 fip
->fnfieldlists
= (struct fnfieldlist
*)
10802 xrealloc (fip
->fnfieldlists
,
10803 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
10804 * sizeof (struct fnfieldlist
));
10805 if (fip
->nfnfields
== 0)
10806 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
10808 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
10809 flp
->name
= fieldname
;
10812 i
= fip
->nfnfields
++;
10815 /* Create a new member function field and chain it to the field list
10817 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
10818 make_cleanup (xfree
, new_fnfield
);
10819 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
10820 new_fnfield
->next
= flp
->head
;
10821 flp
->head
= new_fnfield
;
10824 /* Fill in the member function field info. */
10825 fnp
= &new_fnfield
->fnfield
;
10827 /* Delay processing of the physname until later. */
10828 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
10830 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
10835 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
10836 fnp
->physname
= physname
? physname
: "";
10839 fnp
->type
= alloc_type (objfile
);
10840 this_type
= read_type_die (die
, cu
);
10841 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
10843 int nparams
= TYPE_NFIELDS (this_type
);
10845 /* TYPE is the domain of this method, and THIS_TYPE is the type
10846 of the method itself (TYPE_CODE_METHOD). */
10847 smash_to_method_type (fnp
->type
, type
,
10848 TYPE_TARGET_TYPE (this_type
),
10849 TYPE_FIELDS (this_type
),
10850 TYPE_NFIELDS (this_type
),
10851 TYPE_VARARGS (this_type
));
10853 /* Handle static member functions.
10854 Dwarf2 has no clean way to discern C++ static and non-static
10855 member functions. G++ helps GDB by marking the first
10856 parameter for non-static member functions (which is the this
10857 pointer) as artificial. We obtain this information from
10858 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10859 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10860 fnp
->voffset
= VOFFSET_STATIC
;
10863 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10864 dwarf2_full_name (fieldname
, die
, cu
));
10866 /* Get fcontext from DW_AT_containing_type if present. */
10867 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10868 fnp
->fcontext
= die_containing_type (die
, cu
);
10870 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10871 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10873 /* Get accessibility. */
10874 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10876 accessibility
= DW_UNSND (attr
);
10878 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10879 switch (accessibility
)
10881 case DW_ACCESS_private
:
10882 fnp
->is_private
= 1;
10884 case DW_ACCESS_protected
:
10885 fnp
->is_protected
= 1;
10889 /* Check for artificial methods. */
10890 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
10891 if (attr
&& DW_UNSND (attr
) != 0)
10892 fnp
->is_artificial
= 1;
10894 /* Get index in virtual function table if it is a virtual member
10895 function. For older versions of GCC, this is an offset in the
10896 appropriate virtual table, as specified by DW_AT_containing_type.
10897 For everyone else, it is an expression to be evaluated relative
10898 to the object address. */
10900 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
10903 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
10905 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
10907 /* Old-style GCC. */
10908 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
10910 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10911 || (DW_BLOCK (attr
)->size
> 1
10912 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
10913 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
10915 struct dwarf_block blk
;
10918 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10920 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10921 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10922 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10923 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10924 dwarf2_complex_location_expr_complaint ();
10926 fnp
->voffset
/= cu
->header
.addr_size
;
10930 dwarf2_complex_location_expr_complaint ();
10932 if (!fnp
->fcontext
)
10933 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10935 else if (attr_form_is_section_offset (attr
))
10937 dwarf2_complex_location_expr_complaint ();
10941 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10947 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10948 if (attr
&& DW_UNSND (attr
))
10950 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10951 complaint (&symfile_complaints
,
10952 _("Member function \"%s\" (offset %d) is virtual "
10953 "but the vtable offset is not specified"),
10954 fieldname
, die
->offset
.sect_off
);
10955 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10956 TYPE_CPLUS_DYNAMIC (type
) = 1;
10961 /* Create the vector of member function fields, and attach it to the type. */
10964 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10965 struct dwarf2_cu
*cu
)
10967 struct fnfieldlist
*flp
;
10970 if (cu
->language
== language_ada
)
10971 error (_("unexpected member functions in Ada type"));
10973 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10974 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
10975 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
10977 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
10979 struct nextfnfield
*nfp
= flp
->head
;
10980 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
10983 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
10984 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
10985 fn_flp
->fn_fields
= (struct fn_field
*)
10986 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
10987 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
10988 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
10991 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
10994 /* Returns non-zero if NAME is the name of a vtable member in CU's
10995 language, zero otherwise. */
10997 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
10999 static const char vptr
[] = "_vptr";
11000 static const char vtable
[] = "vtable";
11002 /* Look for the C++ and Java forms of the vtable. */
11003 if ((cu
->language
== language_java
11004 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
11005 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
11006 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
11012 /* GCC outputs unnamed structures that are really pointers to member
11013 functions, with the ABI-specified layout. If TYPE describes
11014 such a structure, smash it into a member function type.
11016 GCC shouldn't do this; it should just output pointer to member DIEs.
11017 This is GCC PR debug/28767. */
11020 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
11022 struct type
*pfn_type
, *domain_type
, *new_type
;
11024 /* Check for a structure with no name and two children. */
11025 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
11028 /* Check for __pfn and __delta members. */
11029 if (TYPE_FIELD_NAME (type
, 0) == NULL
11030 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
11031 || TYPE_FIELD_NAME (type
, 1) == NULL
11032 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
11035 /* Find the type of the method. */
11036 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
11037 if (pfn_type
== NULL
11038 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
11039 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
11042 /* Look for the "this" argument. */
11043 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
11044 if (TYPE_NFIELDS (pfn_type
) == 0
11045 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11046 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
11049 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
11050 new_type
= alloc_type (objfile
);
11051 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
11052 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
11053 TYPE_VARARGS (pfn_type
));
11054 smash_to_methodptr_type (type
, new_type
);
11057 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11061 producer_is_icc (struct dwarf2_cu
*cu
)
11063 if (!cu
->checked_producer
)
11064 check_producer (cu
);
11066 return cu
->producer_is_icc
;
11069 /* Called when we find the DIE that starts a structure or union scope
11070 (definition) to create a type for the structure or union. Fill in
11071 the type's name and general properties; the members will not be
11072 processed until process_structure_type.
11074 NOTE: we need to call these functions regardless of whether or not the
11075 DIE has a DW_AT_name attribute, since it might be an anonymous
11076 structure or union. This gets the type entered into our set of
11077 user defined types.
11079 However, if the structure is incomplete (an opaque struct/union)
11080 then suppress creating a symbol table entry for it since gdb only
11081 wants to find the one with the complete definition. Note that if
11082 it is complete, we just call new_symbol, which does it's own
11083 checking about whether the struct/union is anonymous or not (and
11084 suppresses creating a symbol table entry itself). */
11086 static struct type
*
11087 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11089 struct objfile
*objfile
= cu
->objfile
;
11091 struct attribute
*attr
;
11094 /* If the definition of this type lives in .debug_types, read that type.
11095 Don't follow DW_AT_specification though, that will take us back up
11096 the chain and we want to go down. */
11097 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11100 struct dwarf2_cu
*type_cu
= cu
;
11101 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11103 /* We could just recurse on read_structure_type, but we need to call
11104 get_die_type to ensure only one type for this DIE is created.
11105 This is important, for example, because for c++ classes we need
11106 TYPE_NAME set which is only done by new_symbol. Blech. */
11107 type
= read_type_die (type_die
, type_cu
);
11109 /* TYPE_CU may not be the same as CU.
11110 Ensure TYPE is recorded in CU's type_hash table. */
11111 return set_die_type (die
, type
, cu
);
11114 type
= alloc_type (objfile
);
11115 INIT_CPLUS_SPECIFIC (type
);
11117 name
= dwarf2_name (die
, cu
);
11120 if (cu
->language
== language_cplus
11121 || cu
->language
== language_java
)
11123 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
11125 /* dwarf2_full_name might have already finished building the DIE's
11126 type. If so, there is no need to continue. */
11127 if (get_die_type (die
, cu
) != NULL
)
11128 return get_die_type (die
, cu
);
11130 TYPE_TAG_NAME (type
) = full_name
;
11131 if (die
->tag
== DW_TAG_structure_type
11132 || die
->tag
== DW_TAG_class_type
)
11133 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11137 /* The name is already allocated along with this objfile, so
11138 we don't need to duplicate it for the type. */
11139 TYPE_TAG_NAME (type
) = (char *) name
;
11140 if (die
->tag
== DW_TAG_class_type
)
11141 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11145 if (die
->tag
== DW_TAG_structure_type
)
11147 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
11149 else if (die
->tag
== DW_TAG_union_type
)
11151 TYPE_CODE (type
) = TYPE_CODE_UNION
;
11155 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
11158 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
11159 TYPE_DECLARED_CLASS (type
) = 1;
11161 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11164 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11168 TYPE_LENGTH (type
) = 0;
11171 if (producer_is_icc (cu
))
11173 /* ICC does not output the required DW_AT_declaration
11174 on incomplete types, but gives them a size of zero. */
11177 TYPE_STUB_SUPPORTED (type
) = 1;
11179 if (die_is_declaration (die
, cu
))
11180 TYPE_STUB (type
) = 1;
11181 else if (attr
== NULL
&& die
->child
== NULL
11182 && producer_is_realview (cu
->producer
))
11183 /* RealView does not output the required DW_AT_declaration
11184 on incomplete types. */
11185 TYPE_STUB (type
) = 1;
11187 /* We need to add the type field to the die immediately so we don't
11188 infinitely recurse when dealing with pointers to the structure
11189 type within the structure itself. */
11190 set_die_type (die
, type
, cu
);
11192 /* set_die_type should be already done. */
11193 set_descriptive_type (type
, die
, cu
);
11198 /* Finish creating a structure or union type, including filling in
11199 its members and creating a symbol for it. */
11202 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11204 struct objfile
*objfile
= cu
->objfile
;
11205 struct die_info
*child_die
= die
->child
;
11208 type
= get_die_type (die
, cu
);
11210 type
= read_structure_type (die
, cu
);
11212 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
11214 struct field_info fi
;
11215 struct die_info
*child_die
;
11216 VEC (symbolp
) *template_args
= NULL
;
11217 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
11219 memset (&fi
, 0, sizeof (struct field_info
));
11221 child_die
= die
->child
;
11223 while (child_die
&& child_die
->tag
)
11225 if (child_die
->tag
== DW_TAG_member
11226 || child_die
->tag
== DW_TAG_variable
)
11228 /* NOTE: carlton/2002-11-05: A C++ static data member
11229 should be a DW_TAG_member that is a declaration, but
11230 all versions of G++ as of this writing (so through at
11231 least 3.2.1) incorrectly generate DW_TAG_variable
11232 tags for them instead. */
11233 dwarf2_add_field (&fi
, child_die
, cu
);
11235 else if (child_die
->tag
== DW_TAG_subprogram
)
11237 /* C++ member function. */
11238 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
11240 else if (child_die
->tag
== DW_TAG_inheritance
)
11242 /* C++ base class field. */
11243 dwarf2_add_field (&fi
, child_die
, cu
);
11245 else if (child_die
->tag
== DW_TAG_typedef
)
11246 dwarf2_add_typedef (&fi
, child_die
, cu
);
11247 else if (child_die
->tag
== DW_TAG_template_type_param
11248 || child_die
->tag
== DW_TAG_template_value_param
)
11250 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11253 VEC_safe_push (symbolp
, template_args
, arg
);
11256 child_die
= sibling_die (child_die
);
11259 /* Attach template arguments to type. */
11260 if (! VEC_empty (symbolp
, template_args
))
11262 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11263 TYPE_N_TEMPLATE_ARGUMENTS (type
)
11264 = VEC_length (symbolp
, template_args
);
11265 TYPE_TEMPLATE_ARGUMENTS (type
)
11266 = obstack_alloc (&objfile
->objfile_obstack
,
11267 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11268 * sizeof (struct symbol
*)));
11269 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
11270 VEC_address (symbolp
, template_args
),
11271 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11272 * sizeof (struct symbol
*)));
11273 VEC_free (symbolp
, template_args
);
11276 /* Attach fields and member functions to the type. */
11278 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
11281 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
11283 /* Get the type which refers to the base class (possibly this
11284 class itself) which contains the vtable pointer for the current
11285 class from the DW_AT_containing_type attribute. This use of
11286 DW_AT_containing_type is a GNU extension. */
11288 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11290 struct type
*t
= die_containing_type (die
, cu
);
11292 TYPE_VPTR_BASETYPE (type
) = t
;
11297 /* Our own class provides vtbl ptr. */
11298 for (i
= TYPE_NFIELDS (t
) - 1;
11299 i
>= TYPE_N_BASECLASSES (t
);
11302 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
11304 if (is_vtable_name (fieldname
, cu
))
11306 TYPE_VPTR_FIELDNO (type
) = i
;
11311 /* Complain if virtual function table field not found. */
11312 if (i
< TYPE_N_BASECLASSES (t
))
11313 complaint (&symfile_complaints
,
11314 _("virtual function table pointer "
11315 "not found when defining class '%s'"),
11316 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
11321 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
11324 else if (cu
->producer
11325 && strncmp (cu
->producer
,
11326 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11328 /* The IBM XLC compiler does not provide direct indication
11329 of the containing type, but the vtable pointer is
11330 always named __vfp. */
11334 for (i
= TYPE_NFIELDS (type
) - 1;
11335 i
>= TYPE_N_BASECLASSES (type
);
11338 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
11340 TYPE_VPTR_FIELDNO (type
) = i
;
11341 TYPE_VPTR_BASETYPE (type
) = type
;
11348 /* Copy fi.typedef_field_list linked list elements content into the
11349 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11350 if (fi
.typedef_field_list
)
11352 int i
= fi
.typedef_field_list_count
;
11354 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11355 TYPE_TYPEDEF_FIELD_ARRAY (type
)
11356 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
11357 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
11359 /* Reverse the list order to keep the debug info elements order. */
11362 struct typedef_field
*dest
, *src
;
11364 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
11365 src
= &fi
.typedef_field_list
->field
;
11366 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
11371 do_cleanups (back_to
);
11373 if (HAVE_CPLUS_STRUCT (type
))
11374 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
11377 quirk_gcc_member_function_pointer (type
, objfile
);
11379 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11380 snapshots) has been known to create a die giving a declaration
11381 for a class that has, as a child, a die giving a definition for a
11382 nested class. So we have to process our children even if the
11383 current die is a declaration. Normally, of course, a declaration
11384 won't have any children at all. */
11386 while (child_die
!= NULL
&& child_die
->tag
)
11388 if (child_die
->tag
== DW_TAG_member
11389 || child_die
->tag
== DW_TAG_variable
11390 || child_die
->tag
== DW_TAG_inheritance
11391 || child_die
->tag
== DW_TAG_template_value_param
11392 || child_die
->tag
== DW_TAG_template_type_param
)
11397 process_die (child_die
, cu
);
11399 child_die
= sibling_die (child_die
);
11402 /* Do not consider external references. According to the DWARF standard,
11403 these DIEs are identified by the fact that they have no byte_size
11404 attribute, and a declaration attribute. */
11405 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
11406 || !die_is_declaration (die
, cu
))
11407 new_symbol (die
, type
, cu
);
11410 /* Given a DW_AT_enumeration_type die, set its type. We do not
11411 complete the type's fields yet, or create any symbols. */
11413 static struct type
*
11414 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11416 struct objfile
*objfile
= cu
->objfile
;
11418 struct attribute
*attr
;
11421 /* If the definition of this type lives in .debug_types, read that type.
11422 Don't follow DW_AT_specification though, that will take us back up
11423 the chain and we want to go down. */
11424 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11427 struct dwarf2_cu
*type_cu
= cu
;
11428 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11430 type
= read_type_die (type_die
, type_cu
);
11432 /* TYPE_CU may not be the same as CU.
11433 Ensure TYPE is recorded in CU's type_hash table. */
11434 return set_die_type (die
, type
, cu
);
11437 type
= alloc_type (objfile
);
11439 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
11440 name
= dwarf2_full_name (NULL
, die
, cu
);
11442 TYPE_TAG_NAME (type
) = (char *) name
;
11444 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11447 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11451 TYPE_LENGTH (type
) = 0;
11454 /* The enumeration DIE can be incomplete. In Ada, any type can be
11455 declared as private in the package spec, and then defined only
11456 inside the package body. Such types are known as Taft Amendment
11457 Types. When another package uses such a type, an incomplete DIE
11458 may be generated by the compiler. */
11459 if (die_is_declaration (die
, cu
))
11460 TYPE_STUB (type
) = 1;
11462 return set_die_type (die
, type
, cu
);
11465 /* Given a pointer to a die which begins an enumeration, process all
11466 the dies that define the members of the enumeration, and create the
11467 symbol for the enumeration type.
11469 NOTE: We reverse the order of the element list. */
11472 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11474 struct type
*this_type
;
11476 this_type
= get_die_type (die
, cu
);
11477 if (this_type
== NULL
)
11478 this_type
= read_enumeration_type (die
, cu
);
11480 if (die
->child
!= NULL
)
11482 struct die_info
*child_die
;
11483 struct symbol
*sym
;
11484 struct field
*fields
= NULL
;
11485 int num_fields
= 0;
11486 int unsigned_enum
= 1;
11491 child_die
= die
->child
;
11492 while (child_die
&& child_die
->tag
)
11494 if (child_die
->tag
!= DW_TAG_enumerator
)
11496 process_die (child_die
, cu
);
11500 name
= dwarf2_name (child_die
, cu
);
11503 sym
= new_symbol (child_die
, this_type
, cu
);
11504 if (SYMBOL_VALUE (sym
) < 0)
11509 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
11512 mask
|= SYMBOL_VALUE (sym
);
11514 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
11516 fields
= (struct field
*)
11518 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
11519 * sizeof (struct field
));
11522 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
11523 FIELD_TYPE (fields
[num_fields
]) = NULL
;
11524 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
11525 FIELD_BITSIZE (fields
[num_fields
]) = 0;
11531 child_die
= sibling_die (child_die
);
11536 TYPE_NFIELDS (this_type
) = num_fields
;
11537 TYPE_FIELDS (this_type
) = (struct field
*)
11538 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
11539 memcpy (TYPE_FIELDS (this_type
), fields
,
11540 sizeof (struct field
) * num_fields
);
11544 TYPE_UNSIGNED (this_type
) = 1;
11546 TYPE_FLAG_ENUM (this_type
) = 1;
11549 /* If we are reading an enum from a .debug_types unit, and the enum
11550 is a declaration, and the enum is not the signatured type in the
11551 unit, then we do not want to add a symbol for it. Adding a
11552 symbol would in some cases obscure the true definition of the
11553 enum, giving users an incomplete type when the definition is
11554 actually available. Note that we do not want to do this for all
11555 enums which are just declarations, because C++0x allows forward
11556 enum declarations. */
11557 if (cu
->per_cu
->is_debug_types
11558 && die_is_declaration (die
, cu
))
11560 struct signatured_type
*sig_type
;
11563 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
11564 cu
->per_cu
->info_or_types_section
,
11565 cu
->per_cu
->offset
);
11566 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
11567 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
11571 new_symbol (die
, this_type
, cu
);
11574 /* Extract all information from a DW_TAG_array_type DIE and put it in
11575 the DIE's type field. For now, this only handles one dimensional
11578 static struct type
*
11579 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11581 struct objfile
*objfile
= cu
->objfile
;
11582 struct die_info
*child_die
;
11584 struct type
*element_type
, *range_type
, *index_type
;
11585 struct type
**range_types
= NULL
;
11586 struct attribute
*attr
;
11588 struct cleanup
*back_to
;
11591 element_type
= die_type (die
, cu
);
11593 /* The die_type call above may have already set the type for this DIE. */
11594 type
= get_die_type (die
, cu
);
11598 /* Irix 6.2 native cc creates array types without children for
11599 arrays with unspecified length. */
11600 if (die
->child
== NULL
)
11602 index_type
= objfile_type (objfile
)->builtin_int
;
11603 range_type
= create_range_type (NULL
, index_type
, 0, -1);
11604 type
= create_array_type (NULL
, element_type
, range_type
);
11605 return set_die_type (die
, type
, cu
);
11608 back_to
= make_cleanup (null_cleanup
, NULL
);
11609 child_die
= die
->child
;
11610 while (child_die
&& child_die
->tag
)
11612 if (child_die
->tag
== DW_TAG_subrange_type
)
11614 struct type
*child_type
= read_type_die (child_die
, cu
);
11616 if (child_type
!= NULL
)
11618 /* The range type was succesfully read. Save it for the
11619 array type creation. */
11620 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
11622 range_types
= (struct type
**)
11623 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
11624 * sizeof (struct type
*));
11626 make_cleanup (free_current_contents
, &range_types
);
11628 range_types
[ndim
++] = child_type
;
11631 child_die
= sibling_die (child_die
);
11634 /* Dwarf2 dimensions are output from left to right, create the
11635 necessary array types in backwards order. */
11637 type
= element_type
;
11639 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
11644 type
= create_array_type (NULL
, type
, range_types
[i
++]);
11649 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
11652 /* Understand Dwarf2 support for vector types (like they occur on
11653 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11654 array type. This is not part of the Dwarf2/3 standard yet, but a
11655 custom vendor extension. The main difference between a regular
11656 array and the vector variant is that vectors are passed by value
11658 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
11660 make_vector_type (type
);
11662 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11663 implementation may choose to implement triple vectors using this
11665 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11668 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
11669 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11671 complaint (&symfile_complaints
,
11672 _("DW_AT_byte_size for array type smaller "
11673 "than the total size of elements"));
11676 name
= dwarf2_name (die
, cu
);
11678 TYPE_NAME (type
) = name
;
11680 /* Install the type in the die. */
11681 set_die_type (die
, type
, cu
);
11683 /* set_die_type should be already done. */
11684 set_descriptive_type (type
, die
, cu
);
11686 do_cleanups (back_to
);
11691 static enum dwarf_array_dim_ordering
11692 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
11694 struct attribute
*attr
;
11696 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
11698 if (attr
) return DW_SND (attr
);
11700 /* GNU F77 is a special case, as at 08/2004 array type info is the
11701 opposite order to the dwarf2 specification, but data is still
11702 laid out as per normal fortran.
11704 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11705 version checking. */
11707 if (cu
->language
== language_fortran
11708 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
11710 return DW_ORD_row_major
;
11713 switch (cu
->language_defn
->la_array_ordering
)
11715 case array_column_major
:
11716 return DW_ORD_col_major
;
11717 case array_row_major
:
11719 return DW_ORD_row_major
;
11723 /* Extract all information from a DW_TAG_set_type DIE and put it in
11724 the DIE's type field. */
11726 static struct type
*
11727 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11729 struct type
*domain_type
, *set_type
;
11730 struct attribute
*attr
;
11732 domain_type
= die_type (die
, cu
);
11734 /* The die_type call above may have already set the type for this DIE. */
11735 set_type
= get_die_type (die
, cu
);
11739 set_type
= create_set_type (NULL
, domain_type
);
11741 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11743 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
11745 return set_die_type (die
, set_type
, cu
);
11748 /* A helper for read_common_block that creates a locexpr baton.
11749 SYM is the symbol which we are marking as computed.
11750 COMMON_DIE is the DIE for the common block.
11751 COMMON_LOC is the location expression attribute for the common
11753 MEMBER_LOC is the location expression attribute for the particular
11754 member of the common block that we are processing.
11755 CU is the CU from which the above come. */
11758 mark_common_block_symbol_computed (struct symbol
*sym
,
11759 struct die_info
*common_die
,
11760 struct attribute
*common_loc
,
11761 struct attribute
*member_loc
,
11762 struct dwarf2_cu
*cu
)
11764 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11765 struct dwarf2_locexpr_baton
*baton
;
11767 unsigned int cu_off
;
11768 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
11769 LONGEST offset
= 0;
11771 gdb_assert (common_loc
&& member_loc
);
11772 gdb_assert (attr_form_is_block (common_loc
));
11773 gdb_assert (attr_form_is_block (member_loc
)
11774 || attr_form_is_constant (member_loc
));
11776 baton
= obstack_alloc (&objfile
->objfile_obstack
,
11777 sizeof (struct dwarf2_locexpr_baton
));
11778 baton
->per_cu
= cu
->per_cu
;
11779 gdb_assert (baton
->per_cu
);
11781 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
11783 if (attr_form_is_constant (member_loc
))
11785 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
11786 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
11789 baton
->size
+= DW_BLOCK (member_loc
)->size
;
11791 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
11794 *ptr
++ = DW_OP_call4
;
11795 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
11796 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
11799 if (attr_form_is_constant (member_loc
))
11801 *ptr
++ = DW_OP_addr
;
11802 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
11803 ptr
+= cu
->header
.addr_size
;
11807 /* We have to copy the data here, because DW_OP_call4 will only
11808 use a DW_AT_location attribute. */
11809 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
11810 ptr
+= DW_BLOCK (member_loc
)->size
;
11813 *ptr
++ = DW_OP_plus
;
11814 gdb_assert (ptr
- baton
->data
== baton
->size
);
11816 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11817 SYMBOL_LOCATION_BATON (sym
) = baton
;
11818 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11821 /* Create appropriate locally-scoped variables for all the
11822 DW_TAG_common_block entries. Also create a struct common_block
11823 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
11824 is used to sepate the common blocks name namespace from regular
11828 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
11830 struct attribute
*attr
;
11832 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11835 /* Support the .debug_loc offsets. */
11836 if (attr_form_is_block (attr
))
11840 else if (attr_form_is_section_offset (attr
))
11842 dwarf2_complex_location_expr_complaint ();
11847 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11848 "common block member");
11853 if (die
->child
!= NULL
)
11855 struct objfile
*objfile
= cu
->objfile
;
11856 struct die_info
*child_die
;
11857 size_t n_entries
= 0, size
;
11858 struct common_block
*common_block
;
11859 struct symbol
*sym
;
11861 for (child_die
= die
->child
;
11862 child_die
&& child_die
->tag
;
11863 child_die
= sibling_die (child_die
))
11866 size
= (sizeof (struct common_block
)
11867 + (n_entries
- 1) * sizeof (struct symbol
*));
11868 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
11869 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
11870 common_block
->n_entries
= 0;
11872 for (child_die
= die
->child
;
11873 child_die
&& child_die
->tag
;
11874 child_die
= sibling_die (child_die
))
11876 /* Create the symbol in the DW_TAG_common_block block in the current
11878 sym
= new_symbol (child_die
, NULL
, cu
);
11881 struct attribute
*member_loc
;
11883 common_block
->contents
[common_block
->n_entries
++] = sym
;
11885 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
11889 /* GDB has handled this for a long time, but it is
11890 not specified by DWARF. It seems to have been
11891 emitted by gfortran at least as recently as:
11892 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
11893 complaint (&symfile_complaints
,
11894 _("Variable in common block has "
11895 "DW_AT_data_member_location "
11896 "- DIE at 0x%x [in module %s]"),
11897 child_die
->offset
.sect_off
, cu
->objfile
->name
);
11899 if (attr_form_is_section_offset (member_loc
))
11900 dwarf2_complex_location_expr_complaint ();
11901 else if (attr_form_is_constant (member_loc
)
11902 || attr_form_is_block (member_loc
))
11905 mark_common_block_symbol_computed (sym
, die
, attr
,
11909 dwarf2_complex_location_expr_complaint ();
11914 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
11915 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
11919 /* Create a type for a C++ namespace. */
11921 static struct type
*
11922 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11924 struct objfile
*objfile
= cu
->objfile
;
11925 const char *previous_prefix
, *name
;
11929 /* For extensions, reuse the type of the original namespace. */
11930 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
11932 struct die_info
*ext_die
;
11933 struct dwarf2_cu
*ext_cu
= cu
;
11935 ext_die
= dwarf2_extension (die
, &ext_cu
);
11936 type
= read_type_die (ext_die
, ext_cu
);
11938 /* EXT_CU may not be the same as CU.
11939 Ensure TYPE is recorded in CU's type_hash table. */
11940 return set_die_type (die
, type
, cu
);
11943 name
= namespace_name (die
, &is_anonymous
, cu
);
11945 /* Now build the name of the current namespace. */
11947 previous_prefix
= determine_prefix (die
, cu
);
11948 if (previous_prefix
[0] != '\0')
11949 name
= typename_concat (&objfile
->objfile_obstack
,
11950 previous_prefix
, name
, 0, cu
);
11952 /* Create the type. */
11953 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
11955 TYPE_NAME (type
) = (char *) name
;
11956 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11958 return set_die_type (die
, type
, cu
);
11961 /* Read a C++ namespace. */
11964 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
11966 struct objfile
*objfile
= cu
->objfile
;
11969 /* Add a symbol associated to this if we haven't seen the namespace
11970 before. Also, add a using directive if it's an anonymous
11973 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
11977 type
= read_type_die (die
, cu
);
11978 new_symbol (die
, type
, cu
);
11980 namespace_name (die
, &is_anonymous
, cu
);
11983 const char *previous_prefix
= determine_prefix (die
, cu
);
11985 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
11986 NULL
, NULL
, &objfile
->objfile_obstack
);
11990 if (die
->child
!= NULL
)
11992 struct die_info
*child_die
= die
->child
;
11994 while (child_die
&& child_die
->tag
)
11996 process_die (child_die
, cu
);
11997 child_die
= sibling_die (child_die
);
12002 /* Read a Fortran module as type. This DIE can be only a declaration used for
12003 imported module. Still we need that type as local Fortran "use ... only"
12004 declaration imports depend on the created type in determine_prefix. */
12006 static struct type
*
12007 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12009 struct objfile
*objfile
= cu
->objfile
;
12013 module_name
= dwarf2_name (die
, cu
);
12015 complaint (&symfile_complaints
,
12016 _("DW_TAG_module has no name, offset 0x%x"),
12017 die
->offset
.sect_off
);
12018 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
12020 /* determine_prefix uses TYPE_TAG_NAME. */
12021 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12023 return set_die_type (die
, type
, cu
);
12026 /* Read a Fortran module. */
12029 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
12031 struct die_info
*child_die
= die
->child
;
12033 while (child_die
&& child_die
->tag
)
12035 process_die (child_die
, cu
);
12036 child_die
= sibling_die (child_die
);
12040 /* Return the name of the namespace represented by DIE. Set
12041 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12044 static const char *
12045 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
12047 struct die_info
*current_die
;
12048 const char *name
= NULL
;
12050 /* Loop through the extensions until we find a name. */
12052 for (current_die
= die
;
12053 current_die
!= NULL
;
12054 current_die
= dwarf2_extension (die
, &cu
))
12056 name
= dwarf2_name (current_die
, cu
);
12061 /* Is it an anonymous namespace? */
12063 *is_anonymous
= (name
== NULL
);
12065 name
= CP_ANONYMOUS_NAMESPACE_STR
;
12070 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12071 the user defined type vector. */
12073 static struct type
*
12074 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12076 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
12077 struct comp_unit_head
*cu_header
= &cu
->header
;
12079 struct attribute
*attr_byte_size
;
12080 struct attribute
*attr_address_class
;
12081 int byte_size
, addr_class
;
12082 struct type
*target_type
;
12084 target_type
= die_type (die
, cu
);
12086 /* The die_type call above may have already set the type for this DIE. */
12087 type
= get_die_type (die
, cu
);
12091 type
= lookup_pointer_type (target_type
);
12093 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12094 if (attr_byte_size
)
12095 byte_size
= DW_UNSND (attr_byte_size
);
12097 byte_size
= cu_header
->addr_size
;
12099 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
12100 if (attr_address_class
)
12101 addr_class
= DW_UNSND (attr_address_class
);
12103 addr_class
= DW_ADDR_none
;
12105 /* If the pointer size or address class is different than the
12106 default, create a type variant marked as such and set the
12107 length accordingly. */
12108 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
12110 if (gdbarch_address_class_type_flags_p (gdbarch
))
12114 type_flags
= gdbarch_address_class_type_flags
12115 (gdbarch
, byte_size
, addr_class
);
12116 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
12118 type
= make_type_with_address_space (type
, type_flags
);
12120 else if (TYPE_LENGTH (type
) != byte_size
)
12122 complaint (&symfile_complaints
,
12123 _("invalid pointer size %d"), byte_size
);
12127 /* Should we also complain about unhandled address classes? */
12131 TYPE_LENGTH (type
) = byte_size
;
12132 return set_die_type (die
, type
, cu
);
12135 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12136 the user defined type vector. */
12138 static struct type
*
12139 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12142 struct type
*to_type
;
12143 struct type
*domain
;
12145 to_type
= die_type (die
, cu
);
12146 domain
= die_containing_type (die
, cu
);
12148 /* The calls above may have already set the type for this DIE. */
12149 type
= get_die_type (die
, cu
);
12153 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
12154 type
= lookup_methodptr_type (to_type
);
12156 type
= lookup_memberptr_type (to_type
, domain
);
12158 return set_die_type (die
, type
, cu
);
12161 /* Extract all information from a DW_TAG_reference_type DIE and add to
12162 the user defined type vector. */
12164 static struct type
*
12165 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12167 struct comp_unit_head
*cu_header
= &cu
->header
;
12168 struct type
*type
, *target_type
;
12169 struct attribute
*attr
;
12171 target_type
= die_type (die
, cu
);
12173 /* The die_type call above may have already set the type for this DIE. */
12174 type
= get_die_type (die
, cu
);
12178 type
= lookup_reference_type (target_type
);
12179 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12182 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12186 TYPE_LENGTH (type
) = cu_header
->addr_size
;
12188 return set_die_type (die
, type
, cu
);
12191 static struct type
*
12192 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12194 struct type
*base_type
, *cv_type
;
12196 base_type
= die_type (die
, cu
);
12198 /* The die_type call above may have already set the type for this DIE. */
12199 cv_type
= get_die_type (die
, cu
);
12203 /* In case the const qualifier is applied to an array type, the element type
12204 is so qualified, not the array type (section 6.7.3 of C99). */
12205 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
12207 struct type
*el_type
, *inner_array
;
12209 base_type
= copy_type (base_type
);
12210 inner_array
= base_type
;
12212 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
12214 TYPE_TARGET_TYPE (inner_array
) =
12215 copy_type (TYPE_TARGET_TYPE (inner_array
));
12216 inner_array
= TYPE_TARGET_TYPE (inner_array
);
12219 el_type
= TYPE_TARGET_TYPE (inner_array
);
12220 TYPE_TARGET_TYPE (inner_array
) =
12221 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
12223 return set_die_type (die
, base_type
, cu
);
12226 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
12227 return set_die_type (die
, cv_type
, cu
);
12230 static struct type
*
12231 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12233 struct type
*base_type
, *cv_type
;
12235 base_type
= die_type (die
, cu
);
12237 /* The die_type call above may have already set the type for this DIE. */
12238 cv_type
= get_die_type (die
, cu
);
12242 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
12243 return set_die_type (die
, cv_type
, cu
);
12246 /* Extract all information from a DW_TAG_string_type DIE and add to
12247 the user defined type vector. It isn't really a user defined type,
12248 but it behaves like one, with other DIE's using an AT_user_def_type
12249 attribute to reference it. */
12251 static struct type
*
12252 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12254 struct objfile
*objfile
= cu
->objfile
;
12255 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12256 struct type
*type
, *range_type
, *index_type
, *char_type
;
12257 struct attribute
*attr
;
12258 unsigned int length
;
12260 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
12263 length
= DW_UNSND (attr
);
12267 /* Check for the DW_AT_byte_size attribute. */
12268 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12271 length
= DW_UNSND (attr
);
12279 index_type
= objfile_type (objfile
)->builtin_int
;
12280 range_type
= create_range_type (NULL
, index_type
, 1, length
);
12281 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
12282 type
= create_string_type (NULL
, char_type
, range_type
);
12284 return set_die_type (die
, type
, cu
);
12287 /* Handle DIES due to C code like:
12291 int (*funcp)(int a, long l);
12295 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12297 static struct type
*
12298 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12300 struct objfile
*objfile
= cu
->objfile
;
12301 struct type
*type
; /* Type that this function returns. */
12302 struct type
*ftype
; /* Function that returns above type. */
12303 struct attribute
*attr
;
12305 type
= die_type (die
, cu
);
12307 /* The die_type call above may have already set the type for this DIE. */
12308 ftype
= get_die_type (die
, cu
);
12312 ftype
= lookup_function_type (type
);
12314 /* All functions in C++, Pascal and Java have prototypes. */
12315 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
12316 if ((attr
&& (DW_UNSND (attr
) != 0))
12317 || cu
->language
== language_cplus
12318 || cu
->language
== language_java
12319 || cu
->language
== language_pascal
)
12320 TYPE_PROTOTYPED (ftype
) = 1;
12321 else if (producer_is_realview (cu
->producer
))
12322 /* RealView does not emit DW_AT_prototyped. We can not
12323 distinguish prototyped and unprototyped functions; default to
12324 prototyped, since that is more common in modern code (and
12325 RealView warns about unprototyped functions). */
12326 TYPE_PROTOTYPED (ftype
) = 1;
12328 /* Store the calling convention in the type if it's available in
12329 the subroutine die. Otherwise set the calling convention to
12330 the default value DW_CC_normal. */
12331 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
12333 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
12334 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
12335 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
12337 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
12339 /* We need to add the subroutine type to the die immediately so
12340 we don't infinitely recurse when dealing with parameters
12341 declared as the same subroutine type. */
12342 set_die_type (die
, ftype
, cu
);
12344 if (die
->child
!= NULL
)
12346 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
12347 struct die_info
*child_die
;
12348 int nparams
, iparams
;
12350 /* Count the number of parameters.
12351 FIXME: GDB currently ignores vararg functions, but knows about
12352 vararg member functions. */
12354 child_die
= die
->child
;
12355 while (child_die
&& child_die
->tag
)
12357 if (child_die
->tag
== DW_TAG_formal_parameter
)
12359 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
12360 TYPE_VARARGS (ftype
) = 1;
12361 child_die
= sibling_die (child_die
);
12364 /* Allocate storage for parameters and fill them in. */
12365 TYPE_NFIELDS (ftype
) = nparams
;
12366 TYPE_FIELDS (ftype
) = (struct field
*)
12367 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
12369 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12370 even if we error out during the parameters reading below. */
12371 for (iparams
= 0; iparams
< nparams
; iparams
++)
12372 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
12375 child_die
= die
->child
;
12376 while (child_die
&& child_die
->tag
)
12378 if (child_die
->tag
== DW_TAG_formal_parameter
)
12380 struct type
*arg_type
;
12382 /* DWARF version 2 has no clean way to discern C++
12383 static and non-static member functions. G++ helps
12384 GDB by marking the first parameter for non-static
12385 member functions (which is the this pointer) as
12386 artificial. We pass this information to
12387 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12389 DWARF version 3 added DW_AT_object_pointer, which GCC
12390 4.5 does not yet generate. */
12391 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
12393 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
12396 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
12398 /* GCC/43521: In java, the formal parameter
12399 "this" is sometimes not marked with DW_AT_artificial. */
12400 if (cu
->language
== language_java
)
12402 const char *name
= dwarf2_name (child_die
, cu
);
12404 if (name
&& !strcmp (name
, "this"))
12405 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
12408 arg_type
= die_type (child_die
, cu
);
12410 /* RealView does not mark THIS as const, which the testsuite
12411 expects. GCC marks THIS as const in method definitions,
12412 but not in the class specifications (GCC PR 43053). */
12413 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
12414 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
12417 struct dwarf2_cu
*arg_cu
= cu
;
12418 const char *name
= dwarf2_name (child_die
, cu
);
12420 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
12423 /* If the compiler emits this, use it. */
12424 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
12427 else if (name
&& strcmp (name
, "this") == 0)
12428 /* Function definitions will have the argument names. */
12430 else if (name
== NULL
&& iparams
== 0)
12431 /* Declarations may not have the names, so like
12432 elsewhere in GDB, assume an artificial first
12433 argument is "this". */
12437 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
12441 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
12444 child_die
= sibling_die (child_die
);
12451 static struct type
*
12452 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
12454 struct objfile
*objfile
= cu
->objfile
;
12455 const char *name
= NULL
;
12456 struct type
*this_type
, *target_type
;
12458 name
= dwarf2_full_name (NULL
, die
, cu
);
12459 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
12460 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
12461 TYPE_NAME (this_type
) = (char *) name
;
12462 set_die_type (die
, this_type
, cu
);
12463 target_type
= die_type (die
, cu
);
12464 if (target_type
!= this_type
)
12465 TYPE_TARGET_TYPE (this_type
) = target_type
;
12468 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12469 spec and cause infinite loops in GDB. */
12470 complaint (&symfile_complaints
,
12471 _("Self-referential DW_TAG_typedef "
12472 "- DIE at 0x%x [in module %s]"),
12473 die
->offset
.sect_off
, objfile
->name
);
12474 TYPE_TARGET_TYPE (this_type
) = NULL
;
12479 /* Find a representation of a given base type and install
12480 it in the TYPE field of the die. */
12482 static struct type
*
12483 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12485 struct objfile
*objfile
= cu
->objfile
;
12487 struct attribute
*attr
;
12488 int encoding
= 0, size
= 0;
12490 enum type_code code
= TYPE_CODE_INT
;
12491 int type_flags
= 0;
12492 struct type
*target_type
= NULL
;
12494 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
12497 encoding
= DW_UNSND (attr
);
12499 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12502 size
= DW_UNSND (attr
);
12504 name
= dwarf2_name (die
, cu
);
12507 complaint (&symfile_complaints
,
12508 _("DW_AT_name missing from DW_TAG_base_type"));
12513 case DW_ATE_address
:
12514 /* Turn DW_ATE_address into a void * pointer. */
12515 code
= TYPE_CODE_PTR
;
12516 type_flags
|= TYPE_FLAG_UNSIGNED
;
12517 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
12519 case DW_ATE_boolean
:
12520 code
= TYPE_CODE_BOOL
;
12521 type_flags
|= TYPE_FLAG_UNSIGNED
;
12523 case DW_ATE_complex_float
:
12524 code
= TYPE_CODE_COMPLEX
;
12525 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
12527 case DW_ATE_decimal_float
:
12528 code
= TYPE_CODE_DECFLOAT
;
12531 code
= TYPE_CODE_FLT
;
12533 case DW_ATE_signed
:
12535 case DW_ATE_unsigned
:
12536 type_flags
|= TYPE_FLAG_UNSIGNED
;
12537 if (cu
->language
== language_fortran
12539 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
12540 code
= TYPE_CODE_CHAR
;
12542 case DW_ATE_signed_char
:
12543 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12544 || cu
->language
== language_pascal
12545 || cu
->language
== language_fortran
)
12546 code
= TYPE_CODE_CHAR
;
12548 case DW_ATE_unsigned_char
:
12549 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12550 || cu
->language
== language_pascal
12551 || cu
->language
== language_fortran
)
12552 code
= TYPE_CODE_CHAR
;
12553 type_flags
|= TYPE_FLAG_UNSIGNED
;
12556 /* We just treat this as an integer and then recognize the
12557 type by name elsewhere. */
12561 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
12562 dwarf_type_encoding_name (encoding
));
12566 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
12567 TYPE_NAME (type
) = name
;
12568 TYPE_TARGET_TYPE (type
) = target_type
;
12570 if (name
&& strcmp (name
, "char") == 0)
12571 TYPE_NOSIGN (type
) = 1;
12573 return set_die_type (die
, type
, cu
);
12576 /* Read the given DW_AT_subrange DIE. */
12578 static struct type
*
12579 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12581 struct type
*base_type
;
12582 struct type
*range_type
;
12583 struct attribute
*attr
;
12585 int low_default_is_valid
;
12587 LONGEST negative_mask
;
12589 base_type
= die_type (die
, cu
);
12590 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
12591 check_typedef (base_type
);
12593 /* The die_type call above may have already set the type for this DIE. */
12594 range_type
= get_die_type (die
, cu
);
12598 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12599 omitting DW_AT_lower_bound. */
12600 switch (cu
->language
)
12603 case language_cplus
:
12605 low_default_is_valid
= 1;
12607 case language_fortran
:
12609 low_default_is_valid
= 1;
12612 case language_java
:
12613 case language_objc
:
12615 low_default_is_valid
= (cu
->header
.version
>= 4);
12619 case language_pascal
:
12621 low_default_is_valid
= (cu
->header
.version
>= 4);
12625 low_default_is_valid
= 0;
12629 /* FIXME: For variable sized arrays either of these could be
12630 a variable rather than a constant value. We'll allow it,
12631 but we don't know how to handle it. */
12632 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
12634 low
= dwarf2_get_attr_constant_value (attr
, low
);
12635 else if (!low_default_is_valid
)
12636 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
12637 "- DIE at 0x%x [in module %s]"),
12638 die
->offset
.sect_off
, cu
->objfile
->name
);
12640 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
12643 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
12645 /* GCC encodes arrays with unspecified or dynamic length
12646 with a DW_FORM_block1 attribute or a reference attribute.
12647 FIXME: GDB does not yet know how to handle dynamic
12648 arrays properly, treat them as arrays with unspecified
12651 FIXME: jimb/2003-09-22: GDB does not really know
12652 how to handle arrays of unspecified length
12653 either; we just represent them as zero-length
12654 arrays. Choose an appropriate upper bound given
12655 the lower bound we've computed above. */
12659 high
= dwarf2_get_attr_constant_value (attr
, 1);
12663 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
12666 int count
= dwarf2_get_attr_constant_value (attr
, 1);
12667 high
= low
+ count
- 1;
12671 /* Unspecified array length. */
12676 /* Dwarf-2 specifications explicitly allows to create subrange types
12677 without specifying a base type.
12678 In that case, the base type must be set to the type of
12679 the lower bound, upper bound or count, in that order, if any of these
12680 three attributes references an object that has a type.
12681 If no base type is found, the Dwarf-2 specifications say that
12682 a signed integer type of size equal to the size of an address should
12684 For the following C code: `extern char gdb_int [];'
12685 GCC produces an empty range DIE.
12686 FIXME: muller/2010-05-28: Possible references to object for low bound,
12687 high bound or count are not yet handled by this code. */
12688 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
12690 struct objfile
*objfile
= cu
->objfile
;
12691 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12692 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
12693 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
12695 /* Test "int", "long int", and "long long int" objfile types,
12696 and select the first one having a size above or equal to the
12697 architecture address size. */
12698 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12699 base_type
= int_type
;
12702 int_type
= objfile_type (objfile
)->builtin_long
;
12703 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12704 base_type
= int_type
;
12707 int_type
= objfile_type (objfile
)->builtin_long_long
;
12708 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12709 base_type
= int_type
;
12715 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
12716 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
12717 low
|= negative_mask
;
12718 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
12719 high
|= negative_mask
;
12721 range_type
= create_range_type (NULL
, base_type
, low
, high
);
12723 /* Mark arrays with dynamic length at least as an array of unspecified
12724 length. GDB could check the boundary but before it gets implemented at
12725 least allow accessing the array elements. */
12726 if (attr
&& attr_form_is_block (attr
))
12727 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12729 /* Ada expects an empty array on no boundary attributes. */
12730 if (attr
== NULL
&& cu
->language
!= language_ada
)
12731 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12733 name
= dwarf2_name (die
, cu
);
12735 TYPE_NAME (range_type
) = name
;
12737 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12739 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
12741 set_die_type (die
, range_type
, cu
);
12743 /* set_die_type should be already done. */
12744 set_descriptive_type (range_type
, die
, cu
);
12749 static struct type
*
12750 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12754 /* For now, we only support the C meaning of an unspecified type: void. */
12756 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
12757 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
12759 return set_die_type (die
, type
, cu
);
12762 /* Read a single die and all its descendents. Set the die's sibling
12763 field to NULL; set other fields in the die correctly, and set all
12764 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
12765 location of the info_ptr after reading all of those dies. PARENT
12766 is the parent of the die in question. */
12768 static struct die_info
*
12769 read_die_and_children (const struct die_reader_specs
*reader
,
12770 gdb_byte
*info_ptr
,
12771 gdb_byte
**new_info_ptr
,
12772 struct die_info
*parent
)
12774 struct die_info
*die
;
12778 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
12781 *new_info_ptr
= cur_ptr
;
12784 store_in_ref_table (die
, reader
->cu
);
12787 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
12791 *new_info_ptr
= cur_ptr
;
12794 die
->sibling
= NULL
;
12795 die
->parent
= parent
;
12799 /* Read a die, all of its descendents, and all of its siblings; set
12800 all of the fields of all of the dies correctly. Arguments are as
12801 in read_die_and_children. */
12803 static struct die_info
*
12804 read_die_and_siblings (const struct die_reader_specs
*reader
,
12805 gdb_byte
*info_ptr
,
12806 gdb_byte
**new_info_ptr
,
12807 struct die_info
*parent
)
12809 struct die_info
*first_die
, *last_sibling
;
12812 cur_ptr
= info_ptr
;
12813 first_die
= last_sibling
= NULL
;
12817 struct die_info
*die
12818 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
12822 *new_info_ptr
= cur_ptr
;
12829 last_sibling
->sibling
= die
;
12831 last_sibling
= die
;
12835 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12837 The caller is responsible for filling in the extra attributes
12838 and updating (*DIEP)->num_attrs.
12839 Set DIEP to point to a newly allocated die with its information,
12840 except for its child, sibling, and parent fields.
12841 Set HAS_CHILDREN to tell whether the die has children or not. */
12844 read_full_die_1 (const struct die_reader_specs
*reader
,
12845 struct die_info
**diep
, gdb_byte
*info_ptr
,
12846 int *has_children
, int num_extra_attrs
)
12848 unsigned int abbrev_number
, bytes_read
, i
;
12849 sect_offset offset
;
12850 struct abbrev_info
*abbrev
;
12851 struct die_info
*die
;
12852 struct dwarf2_cu
*cu
= reader
->cu
;
12853 bfd
*abfd
= reader
->abfd
;
12855 offset
.sect_off
= info_ptr
- reader
->buffer
;
12856 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12857 info_ptr
+= bytes_read
;
12858 if (!abbrev_number
)
12865 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
12867 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
12869 bfd_get_filename (abfd
));
12871 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
12872 die
->offset
= offset
;
12873 die
->tag
= abbrev
->tag
;
12874 die
->abbrev
= abbrev_number
;
12876 /* Make the result usable.
12877 The caller needs to update num_attrs after adding the extra
12879 die
->num_attrs
= abbrev
->num_attrs
;
12881 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12882 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
12886 *has_children
= abbrev
->has_children
;
12890 /* Read a die and all its attributes.
12891 Set DIEP to point to a newly allocated die with its information,
12892 except for its child, sibling, and parent fields.
12893 Set HAS_CHILDREN to tell whether the die has children or not. */
12896 read_full_die (const struct die_reader_specs
*reader
,
12897 struct die_info
**diep
, gdb_byte
*info_ptr
,
12900 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
12903 /* Abbreviation tables.
12905 In DWARF version 2, the description of the debugging information is
12906 stored in a separate .debug_abbrev section. Before we read any
12907 dies from a section we read in all abbreviations and install them
12908 in a hash table. */
12910 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
12912 static struct abbrev_info
*
12913 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
12915 struct abbrev_info
*abbrev
;
12917 abbrev
= (struct abbrev_info
*)
12918 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
12919 memset (abbrev
, 0, sizeof (struct abbrev_info
));
12923 /* Add an abbreviation to the table. */
12926 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
12927 unsigned int abbrev_number
,
12928 struct abbrev_info
*abbrev
)
12930 unsigned int hash_number
;
12932 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12933 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
12934 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
12937 /* Look up an abbrev in the table.
12938 Returns NULL if the abbrev is not found. */
12940 static struct abbrev_info
*
12941 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
12942 unsigned int abbrev_number
)
12944 unsigned int hash_number
;
12945 struct abbrev_info
*abbrev
;
12947 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12948 abbrev
= abbrev_table
->abbrevs
[hash_number
];
12952 if (abbrev
->number
== abbrev_number
)
12954 abbrev
= abbrev
->next
;
12959 /* Read in an abbrev table. */
12961 static struct abbrev_table
*
12962 abbrev_table_read_table (struct dwarf2_section_info
*section
,
12963 sect_offset offset
)
12965 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12966 bfd
*abfd
= section
->asection
->owner
;
12967 struct abbrev_table
*abbrev_table
;
12968 gdb_byte
*abbrev_ptr
;
12969 struct abbrev_info
*cur_abbrev
;
12970 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
12971 unsigned int abbrev_form
;
12972 struct attr_abbrev
*cur_attrs
;
12973 unsigned int allocated_attrs
;
12975 abbrev_table
= XMALLOC (struct abbrev_table
);
12976 abbrev_table
->offset
= offset
;
12977 obstack_init (&abbrev_table
->abbrev_obstack
);
12978 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12980 * sizeof (struct abbrev_info
*)));
12981 memset (abbrev_table
->abbrevs
, 0,
12982 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
12984 dwarf2_read_section (objfile
, section
);
12985 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
12986 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12987 abbrev_ptr
+= bytes_read
;
12989 allocated_attrs
= ATTR_ALLOC_CHUNK
;
12990 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
12992 /* Loop until we reach an abbrev number of 0. */
12993 while (abbrev_number
)
12995 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
12997 /* read in abbrev header */
12998 cur_abbrev
->number
= abbrev_number
;
12999 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13000 abbrev_ptr
+= bytes_read
;
13001 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
13004 /* now read in declarations */
13005 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13006 abbrev_ptr
+= bytes_read
;
13007 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13008 abbrev_ptr
+= bytes_read
;
13009 while (abbrev_name
)
13011 if (cur_abbrev
->num_attrs
== allocated_attrs
)
13013 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
13015 = xrealloc (cur_attrs
, (allocated_attrs
13016 * sizeof (struct attr_abbrev
)));
13019 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
13020 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
13021 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13022 abbrev_ptr
+= bytes_read
;
13023 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13024 abbrev_ptr
+= bytes_read
;
13027 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13028 (cur_abbrev
->num_attrs
13029 * sizeof (struct attr_abbrev
)));
13030 memcpy (cur_abbrev
->attrs
, cur_attrs
,
13031 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
13033 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
13035 /* Get next abbreviation.
13036 Under Irix6 the abbreviations for a compilation unit are not
13037 always properly terminated with an abbrev number of 0.
13038 Exit loop if we encounter an abbreviation which we have
13039 already read (which means we are about to read the abbreviations
13040 for the next compile unit) or if the end of the abbreviation
13041 table is reached. */
13042 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
13044 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13045 abbrev_ptr
+= bytes_read
;
13046 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
13051 return abbrev_table
;
13054 /* Free the resources held by ABBREV_TABLE. */
13057 abbrev_table_free (struct abbrev_table
*abbrev_table
)
13059 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
13060 xfree (abbrev_table
);
13063 /* Same as abbrev_table_free but as a cleanup.
13064 We pass in a pointer to the pointer to the table so that we can
13065 set the pointer to NULL when we're done. It also simplifies
13066 build_type_unit_groups. */
13069 abbrev_table_free_cleanup (void *table_ptr
)
13071 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
13073 if (*abbrev_table_ptr
!= NULL
)
13074 abbrev_table_free (*abbrev_table_ptr
);
13075 *abbrev_table_ptr
= NULL
;
13078 /* Read the abbrev table for CU from ABBREV_SECTION. */
13081 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
13082 struct dwarf2_section_info
*abbrev_section
)
13085 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
13088 /* Release the memory used by the abbrev table for a compilation unit. */
13091 dwarf2_free_abbrev_table (void *ptr_to_cu
)
13093 struct dwarf2_cu
*cu
= ptr_to_cu
;
13095 abbrev_table_free (cu
->abbrev_table
);
13096 /* Set this to NULL so that we SEGV if we try to read it later,
13097 and also because free_comp_unit verifies this is NULL. */
13098 cu
->abbrev_table
= NULL
;
13101 /* Returns nonzero if TAG represents a type that we might generate a partial
13105 is_type_tag_for_partial (int tag
)
13110 /* Some types that would be reasonable to generate partial symbols for,
13111 that we don't at present. */
13112 case DW_TAG_array_type
:
13113 case DW_TAG_file_type
:
13114 case DW_TAG_ptr_to_member_type
:
13115 case DW_TAG_set_type
:
13116 case DW_TAG_string_type
:
13117 case DW_TAG_subroutine_type
:
13119 case DW_TAG_base_type
:
13120 case DW_TAG_class_type
:
13121 case DW_TAG_interface_type
:
13122 case DW_TAG_enumeration_type
:
13123 case DW_TAG_structure_type
:
13124 case DW_TAG_subrange_type
:
13125 case DW_TAG_typedef
:
13126 case DW_TAG_union_type
:
13133 /* Load all DIEs that are interesting for partial symbols into memory. */
13135 static struct partial_die_info
*
13136 load_partial_dies (const struct die_reader_specs
*reader
,
13137 gdb_byte
*info_ptr
, int building_psymtab
)
13139 struct dwarf2_cu
*cu
= reader
->cu
;
13140 struct objfile
*objfile
= cu
->objfile
;
13141 struct partial_die_info
*part_die
;
13142 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
13143 struct abbrev_info
*abbrev
;
13144 unsigned int bytes_read
;
13145 unsigned int load_all
= 0;
13146 int nesting_level
= 1;
13151 gdb_assert (cu
->per_cu
!= NULL
);
13152 if (cu
->per_cu
->load_all_dies
)
13156 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13160 &cu
->comp_unit_obstack
,
13161 hashtab_obstack_allocate
,
13162 dummy_obstack_deallocate
);
13164 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13165 sizeof (struct partial_die_info
));
13169 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
13171 /* A NULL abbrev means the end of a series of children. */
13172 if (abbrev
== NULL
)
13174 if (--nesting_level
== 0)
13176 /* PART_DIE was probably the last thing allocated on the
13177 comp_unit_obstack, so we could call obstack_free
13178 here. We don't do that because the waste is small,
13179 and will be cleaned up when we're done with this
13180 compilation unit. This way, we're also more robust
13181 against other users of the comp_unit_obstack. */
13184 info_ptr
+= bytes_read
;
13185 last_die
= parent_die
;
13186 parent_die
= parent_die
->die_parent
;
13190 /* Check for template arguments. We never save these; if
13191 they're seen, we just mark the parent, and go on our way. */
13192 if (parent_die
!= NULL
13193 && cu
->language
== language_cplus
13194 && (abbrev
->tag
== DW_TAG_template_type_param
13195 || abbrev
->tag
== DW_TAG_template_value_param
))
13197 parent_die
->has_template_arguments
= 1;
13201 /* We don't need a partial DIE for the template argument. */
13202 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13207 /* We only recurse into c++ subprograms looking for template arguments.
13208 Skip their other children. */
13210 && cu
->language
== language_cplus
13211 && parent_die
!= NULL
13212 && parent_die
->tag
== DW_TAG_subprogram
)
13214 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13218 /* Check whether this DIE is interesting enough to save. Normally
13219 we would not be interested in members here, but there may be
13220 later variables referencing them via DW_AT_specification (for
13221 static members). */
13223 && !is_type_tag_for_partial (abbrev
->tag
)
13224 && abbrev
->tag
!= DW_TAG_constant
13225 && abbrev
->tag
!= DW_TAG_enumerator
13226 && abbrev
->tag
!= DW_TAG_subprogram
13227 && abbrev
->tag
!= DW_TAG_lexical_block
13228 && abbrev
->tag
!= DW_TAG_variable
13229 && abbrev
->tag
!= DW_TAG_namespace
13230 && abbrev
->tag
!= DW_TAG_module
13231 && abbrev
->tag
!= DW_TAG_member
13232 && abbrev
->tag
!= DW_TAG_imported_unit
)
13234 /* Otherwise we skip to the next sibling, if any. */
13235 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13239 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
13242 /* This two-pass algorithm for processing partial symbols has a
13243 high cost in cache pressure. Thus, handle some simple cases
13244 here which cover the majority of C partial symbols. DIEs
13245 which neither have specification tags in them, nor could have
13246 specification tags elsewhere pointing at them, can simply be
13247 processed and discarded.
13249 This segment is also optional; scan_partial_symbols and
13250 add_partial_symbol will handle these DIEs if we chain
13251 them in normally. When compilers which do not emit large
13252 quantities of duplicate debug information are more common,
13253 this code can probably be removed. */
13255 /* Any complete simple types at the top level (pretty much all
13256 of them, for a language without namespaces), can be processed
13258 if (parent_die
== NULL
13259 && part_die
->has_specification
== 0
13260 && part_die
->is_declaration
== 0
13261 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
13262 || part_die
->tag
== DW_TAG_base_type
13263 || part_die
->tag
== DW_TAG_subrange_type
))
13265 if (building_psymtab
&& part_die
->name
!= NULL
)
13266 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13267 VAR_DOMAIN
, LOC_TYPEDEF
,
13268 &objfile
->static_psymbols
,
13269 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13270 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13274 /* The exception for DW_TAG_typedef with has_children above is
13275 a workaround of GCC PR debug/47510. In the case of this complaint
13276 type_name_no_tag_or_error will error on such types later.
13278 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13279 it could not find the child DIEs referenced later, this is checked
13280 above. In correct DWARF DW_TAG_typedef should have no children. */
13282 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
13283 complaint (&symfile_complaints
,
13284 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13285 "- DIE at 0x%x [in module %s]"),
13286 part_die
->offset
.sect_off
, objfile
->name
);
13288 /* If we're at the second level, and we're an enumerator, and
13289 our parent has no specification (meaning possibly lives in a
13290 namespace elsewhere), then we can add the partial symbol now
13291 instead of queueing it. */
13292 if (part_die
->tag
== DW_TAG_enumerator
13293 && parent_die
!= NULL
13294 && parent_die
->die_parent
== NULL
13295 && parent_die
->tag
== DW_TAG_enumeration_type
13296 && parent_die
->has_specification
== 0)
13298 if (part_die
->name
== NULL
)
13299 complaint (&symfile_complaints
,
13300 _("malformed enumerator DIE ignored"));
13301 else if (building_psymtab
)
13302 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13303 VAR_DOMAIN
, LOC_CONST
,
13304 (cu
->language
== language_cplus
13305 || cu
->language
== language_java
)
13306 ? &objfile
->global_psymbols
13307 : &objfile
->static_psymbols
,
13308 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13310 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13314 /* We'll save this DIE so link it in. */
13315 part_die
->die_parent
= parent_die
;
13316 part_die
->die_sibling
= NULL
;
13317 part_die
->die_child
= NULL
;
13319 if (last_die
&& last_die
== parent_die
)
13320 last_die
->die_child
= part_die
;
13322 last_die
->die_sibling
= part_die
;
13324 last_die
= part_die
;
13326 if (first_die
== NULL
)
13327 first_die
= part_die
;
13329 /* Maybe add the DIE to the hash table. Not all DIEs that we
13330 find interesting need to be in the hash table, because we
13331 also have the parent/sibling/child chains; only those that we
13332 might refer to by offset later during partial symbol reading.
13334 For now this means things that might have be the target of a
13335 DW_AT_specification, DW_AT_abstract_origin, or
13336 DW_AT_extension. DW_AT_extension will refer only to
13337 namespaces; DW_AT_abstract_origin refers to functions (and
13338 many things under the function DIE, but we do not recurse
13339 into function DIEs during partial symbol reading) and
13340 possibly variables as well; DW_AT_specification refers to
13341 declarations. Declarations ought to have the DW_AT_declaration
13342 flag. It happens that GCC forgets to put it in sometimes, but
13343 only for functions, not for types.
13345 Adding more things than necessary to the hash table is harmless
13346 except for the performance cost. Adding too few will result in
13347 wasted time in find_partial_die, when we reread the compilation
13348 unit with load_all_dies set. */
13351 || abbrev
->tag
== DW_TAG_constant
13352 || abbrev
->tag
== DW_TAG_subprogram
13353 || abbrev
->tag
== DW_TAG_variable
13354 || abbrev
->tag
== DW_TAG_namespace
13355 || part_die
->is_declaration
)
13359 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
13360 part_die
->offset
.sect_off
, INSERT
);
13364 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13365 sizeof (struct partial_die_info
));
13367 /* For some DIEs we want to follow their children (if any). For C
13368 we have no reason to follow the children of structures; for other
13369 languages we have to, so that we can get at method physnames
13370 to infer fully qualified class names, for DW_AT_specification,
13371 and for C++ template arguments. For C++, we also look one level
13372 inside functions to find template arguments (if the name of the
13373 function does not already contain the template arguments).
13375 For Ada, we need to scan the children of subprograms and lexical
13376 blocks as well because Ada allows the definition of nested
13377 entities that could be interesting for the debugger, such as
13378 nested subprograms for instance. */
13379 if (last_die
->has_children
13381 || last_die
->tag
== DW_TAG_namespace
13382 || last_die
->tag
== DW_TAG_module
13383 || last_die
->tag
== DW_TAG_enumeration_type
13384 || (cu
->language
== language_cplus
13385 && last_die
->tag
== DW_TAG_subprogram
13386 && (last_die
->name
== NULL
13387 || strchr (last_die
->name
, '<') == NULL
))
13388 || (cu
->language
!= language_c
13389 && (last_die
->tag
== DW_TAG_class_type
13390 || last_die
->tag
== DW_TAG_interface_type
13391 || last_die
->tag
== DW_TAG_structure_type
13392 || last_die
->tag
== DW_TAG_union_type
))
13393 || (cu
->language
== language_ada
13394 && (last_die
->tag
== DW_TAG_subprogram
13395 || last_die
->tag
== DW_TAG_lexical_block
))))
13398 parent_die
= last_die
;
13402 /* Otherwise we skip to the next sibling, if any. */
13403 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
13405 /* Back to the top, do it again. */
13409 /* Read a minimal amount of information into the minimal die structure. */
13412 read_partial_die (const struct die_reader_specs
*reader
,
13413 struct partial_die_info
*part_die
,
13414 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
13415 gdb_byte
*info_ptr
)
13417 struct dwarf2_cu
*cu
= reader
->cu
;
13418 struct objfile
*objfile
= cu
->objfile
;
13419 gdb_byte
*buffer
= reader
->buffer
;
13421 struct attribute attr
;
13422 int has_low_pc_attr
= 0;
13423 int has_high_pc_attr
= 0;
13424 int high_pc_relative
= 0;
13426 memset (part_die
, 0, sizeof (struct partial_die_info
));
13428 part_die
->offset
.sect_off
= info_ptr
- buffer
;
13430 info_ptr
+= abbrev_len
;
13432 if (abbrev
== NULL
)
13435 part_die
->tag
= abbrev
->tag
;
13436 part_die
->has_children
= abbrev
->has_children
;
13438 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13440 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
13442 /* Store the data if it is of an attribute we want to keep in a
13443 partial symbol table. */
13447 switch (part_die
->tag
)
13449 case DW_TAG_compile_unit
:
13450 case DW_TAG_partial_unit
:
13451 case DW_TAG_type_unit
:
13452 /* Compilation units have a DW_AT_name that is a filename, not
13453 a source language identifier. */
13454 case DW_TAG_enumeration_type
:
13455 case DW_TAG_enumerator
:
13456 /* These tags always have simple identifiers already; no need
13457 to canonicalize them. */
13458 part_die
->name
= DW_STRING (&attr
);
13462 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
13463 &objfile
->objfile_obstack
);
13467 case DW_AT_linkage_name
:
13468 case DW_AT_MIPS_linkage_name
:
13469 /* Note that both forms of linkage name might appear. We
13470 assume they will be the same, and we only store the last
13472 if (cu
->language
== language_ada
)
13473 part_die
->name
= DW_STRING (&attr
);
13474 part_die
->linkage_name
= DW_STRING (&attr
);
13477 has_low_pc_attr
= 1;
13478 part_die
->lowpc
= DW_ADDR (&attr
);
13480 case DW_AT_high_pc
:
13481 has_high_pc_attr
= 1;
13482 if (attr
.form
== DW_FORM_addr
13483 || attr
.form
== DW_FORM_GNU_addr_index
)
13484 part_die
->highpc
= DW_ADDR (&attr
);
13487 high_pc_relative
= 1;
13488 part_die
->highpc
= DW_UNSND (&attr
);
13491 case DW_AT_location
:
13492 /* Support the .debug_loc offsets. */
13493 if (attr_form_is_block (&attr
))
13495 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
13497 else if (attr_form_is_section_offset (&attr
))
13499 dwarf2_complex_location_expr_complaint ();
13503 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13504 "partial symbol information");
13507 case DW_AT_external
:
13508 part_die
->is_external
= DW_UNSND (&attr
);
13510 case DW_AT_declaration
:
13511 part_die
->is_declaration
= DW_UNSND (&attr
);
13514 part_die
->has_type
= 1;
13516 case DW_AT_abstract_origin
:
13517 case DW_AT_specification
:
13518 case DW_AT_extension
:
13519 part_die
->has_specification
= 1;
13520 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
13521 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13522 || cu
->per_cu
->is_dwz
);
13524 case DW_AT_sibling
:
13525 /* Ignore absolute siblings, they might point outside of
13526 the current compile unit. */
13527 if (attr
.form
== DW_FORM_ref_addr
)
13528 complaint (&symfile_complaints
,
13529 _("ignoring absolute DW_AT_sibling"));
13531 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
13533 case DW_AT_byte_size
:
13534 part_die
->has_byte_size
= 1;
13536 case DW_AT_calling_convention
:
13537 /* DWARF doesn't provide a way to identify a program's source-level
13538 entry point. DW_AT_calling_convention attributes are only meant
13539 to describe functions' calling conventions.
13541 However, because it's a necessary piece of information in
13542 Fortran, and because DW_CC_program is the only piece of debugging
13543 information whose definition refers to a 'main program' at all,
13544 several compilers have begun marking Fortran main programs with
13545 DW_CC_program --- even when those functions use the standard
13546 calling conventions.
13548 So until DWARF specifies a way to provide this information and
13549 compilers pick up the new representation, we'll support this
13551 if (DW_UNSND (&attr
) == DW_CC_program
13552 && cu
->language
== language_fortran
)
13554 set_main_name (part_die
->name
);
13556 /* As this DIE has a static linkage the name would be difficult
13557 to look up later. */
13558 language_of_main
= language_fortran
;
13562 if (DW_UNSND (&attr
) == DW_INL_inlined
13563 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
13564 part_die
->may_be_inlined
= 1;
13568 if (part_die
->tag
== DW_TAG_imported_unit
)
13570 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
13571 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13572 || cu
->per_cu
->is_dwz
);
13581 if (high_pc_relative
)
13582 part_die
->highpc
+= part_die
->lowpc
;
13584 if (has_low_pc_attr
&& has_high_pc_attr
)
13586 /* When using the GNU linker, .gnu.linkonce. sections are used to
13587 eliminate duplicate copies of functions and vtables and such.
13588 The linker will arbitrarily choose one and discard the others.
13589 The AT_*_pc values for such functions refer to local labels in
13590 these sections. If the section from that file was discarded, the
13591 labels are not in the output, so the relocs get a value of 0.
13592 If this is a discarded function, mark the pc bounds as invalid,
13593 so that GDB will ignore it. */
13594 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13596 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13598 complaint (&symfile_complaints
,
13599 _("DW_AT_low_pc %s is zero "
13600 "for DIE at 0x%x [in module %s]"),
13601 paddress (gdbarch
, part_die
->lowpc
),
13602 part_die
->offset
.sect_off
, objfile
->name
);
13604 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13605 else if (part_die
->lowpc
>= part_die
->highpc
)
13607 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13609 complaint (&symfile_complaints
,
13610 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13611 "for DIE at 0x%x [in module %s]"),
13612 paddress (gdbarch
, part_die
->lowpc
),
13613 paddress (gdbarch
, part_die
->highpc
),
13614 part_die
->offset
.sect_off
, objfile
->name
);
13617 part_die
->has_pc_info
= 1;
13623 /* Find a cached partial DIE at OFFSET in CU. */
13625 static struct partial_die_info
*
13626 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
13628 struct partial_die_info
*lookup_die
= NULL
;
13629 struct partial_die_info part_die
;
13631 part_die
.offset
= offset
;
13632 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
13638 /* Find a partial DIE at OFFSET, which may or may not be in CU,
13639 except in the case of .debug_types DIEs which do not reference
13640 outside their CU (they do however referencing other types via
13641 DW_FORM_ref_sig8). */
13643 static struct partial_die_info
*
13644 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
13646 struct objfile
*objfile
= cu
->objfile
;
13647 struct dwarf2_per_cu_data
*per_cu
= NULL
;
13648 struct partial_die_info
*pd
= NULL
;
13650 if (offset_in_dwz
== cu
->per_cu
->is_dwz
13651 && offset_in_cu_p (&cu
->header
, offset
))
13653 pd
= find_partial_die_in_comp_unit (offset
, cu
);
13656 /* We missed recording what we needed.
13657 Load all dies and try again. */
13658 per_cu
= cu
->per_cu
;
13662 /* TUs don't reference other CUs/TUs (except via type signatures). */
13663 if (cu
->per_cu
->is_debug_types
)
13665 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
13666 " external reference to offset 0x%lx [in module %s].\n"),
13667 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
13668 bfd_get_filename (objfile
->obfd
));
13670 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
13673 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
13674 load_partial_comp_unit (per_cu
);
13676 per_cu
->cu
->last_used
= 0;
13677 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13680 /* If we didn't find it, and not all dies have been loaded,
13681 load them all and try again. */
13683 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
13685 per_cu
->load_all_dies
= 1;
13687 /* This is nasty. When we reread the DIEs, somewhere up the call chain
13688 THIS_CU->cu may already be in use. So we can't just free it and
13689 replace its DIEs with the ones we read in. Instead, we leave those
13690 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
13691 and clobber THIS_CU->cu->partial_dies with the hash table for the new
13693 load_partial_comp_unit (per_cu
);
13695 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13699 internal_error (__FILE__
, __LINE__
,
13700 _("could not find partial DIE 0x%x "
13701 "in cache [from module %s]\n"),
13702 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
13706 /* See if we can figure out if the class lives in a namespace. We do
13707 this by looking for a member function; its demangled name will
13708 contain namespace info, if there is any. */
13711 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
13712 struct dwarf2_cu
*cu
)
13714 /* NOTE: carlton/2003-10-07: Getting the info this way changes
13715 what template types look like, because the demangler
13716 frequently doesn't give the same name as the debug info. We
13717 could fix this by only using the demangled name to get the
13718 prefix (but see comment in read_structure_type). */
13720 struct partial_die_info
*real_pdi
;
13721 struct partial_die_info
*child_pdi
;
13723 /* If this DIE (this DIE's specification, if any) has a parent, then
13724 we should not do this. We'll prepend the parent's fully qualified
13725 name when we create the partial symbol. */
13727 real_pdi
= struct_pdi
;
13728 while (real_pdi
->has_specification
)
13729 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
13730 real_pdi
->spec_is_dwz
, cu
);
13732 if (real_pdi
->die_parent
!= NULL
)
13735 for (child_pdi
= struct_pdi
->die_child
;
13737 child_pdi
= child_pdi
->die_sibling
)
13739 if (child_pdi
->tag
== DW_TAG_subprogram
13740 && child_pdi
->linkage_name
!= NULL
)
13742 char *actual_class_name
13743 = language_class_name_from_physname (cu
->language_defn
,
13744 child_pdi
->linkage_name
);
13745 if (actual_class_name
!= NULL
)
13748 = obsavestring (actual_class_name
,
13749 strlen (actual_class_name
),
13750 &cu
->objfile
->objfile_obstack
);
13751 xfree (actual_class_name
);
13758 /* Adjust PART_DIE before generating a symbol for it. This function
13759 may set the is_external flag or change the DIE's name. */
13762 fixup_partial_die (struct partial_die_info
*part_die
,
13763 struct dwarf2_cu
*cu
)
13765 /* Once we've fixed up a die, there's no point in doing so again.
13766 This also avoids a memory leak if we were to call
13767 guess_partial_die_structure_name multiple times. */
13768 if (part_die
->fixup_called
)
13771 /* If we found a reference attribute and the DIE has no name, try
13772 to find a name in the referred to DIE. */
13774 if (part_die
->name
== NULL
&& part_die
->has_specification
)
13776 struct partial_die_info
*spec_die
;
13778 spec_die
= find_partial_die (part_die
->spec_offset
,
13779 part_die
->spec_is_dwz
, cu
);
13781 fixup_partial_die (spec_die
, cu
);
13783 if (spec_die
->name
)
13785 part_die
->name
= spec_die
->name
;
13787 /* Copy DW_AT_external attribute if it is set. */
13788 if (spec_die
->is_external
)
13789 part_die
->is_external
= spec_die
->is_external
;
13793 /* Set default names for some unnamed DIEs. */
13795 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
13796 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
13798 /* If there is no parent die to provide a namespace, and there are
13799 children, see if we can determine the namespace from their linkage
13801 if (cu
->language
== language_cplus
13802 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
13803 && part_die
->die_parent
== NULL
13804 && part_die
->has_children
13805 && (part_die
->tag
== DW_TAG_class_type
13806 || part_die
->tag
== DW_TAG_structure_type
13807 || part_die
->tag
== DW_TAG_union_type
))
13808 guess_partial_die_structure_name (part_die
, cu
);
13810 /* GCC might emit a nameless struct or union that has a linkage
13811 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13812 if (part_die
->name
== NULL
13813 && (part_die
->tag
== DW_TAG_class_type
13814 || part_die
->tag
== DW_TAG_interface_type
13815 || part_die
->tag
== DW_TAG_structure_type
13816 || part_die
->tag
== DW_TAG_union_type
)
13817 && part_die
->linkage_name
!= NULL
)
13821 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
13826 /* Strip any leading namespaces/classes, keep only the base name.
13827 DW_AT_name for named DIEs does not contain the prefixes. */
13828 base
= strrchr (demangled
, ':');
13829 if (base
&& base
> demangled
&& base
[-1] == ':')
13834 part_die
->name
= obsavestring (base
, strlen (base
),
13835 &cu
->objfile
->objfile_obstack
);
13840 part_die
->fixup_called
= 1;
13843 /* Read an attribute value described by an attribute form. */
13846 read_attribute_value (const struct die_reader_specs
*reader
,
13847 struct attribute
*attr
, unsigned form
,
13848 gdb_byte
*info_ptr
)
13850 struct dwarf2_cu
*cu
= reader
->cu
;
13851 bfd
*abfd
= reader
->abfd
;
13852 struct comp_unit_head
*cu_header
= &cu
->header
;
13853 unsigned int bytes_read
;
13854 struct dwarf_block
*blk
;
13859 case DW_FORM_ref_addr
:
13860 if (cu
->header
.version
== 2)
13861 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13863 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
13864 &cu
->header
, &bytes_read
);
13865 info_ptr
+= bytes_read
;
13867 case DW_FORM_GNU_ref_alt
:
13868 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13869 info_ptr
+= bytes_read
;
13872 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13873 info_ptr
+= bytes_read
;
13875 case DW_FORM_block2
:
13876 blk
= dwarf_alloc_block (cu
);
13877 blk
->size
= read_2_bytes (abfd
, info_ptr
);
13879 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13880 info_ptr
+= blk
->size
;
13881 DW_BLOCK (attr
) = blk
;
13883 case DW_FORM_block4
:
13884 blk
= dwarf_alloc_block (cu
);
13885 blk
->size
= read_4_bytes (abfd
, info_ptr
);
13887 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13888 info_ptr
+= blk
->size
;
13889 DW_BLOCK (attr
) = blk
;
13891 case DW_FORM_data2
:
13892 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
13895 case DW_FORM_data4
:
13896 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
13899 case DW_FORM_data8
:
13900 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
13903 case DW_FORM_sec_offset
:
13904 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13905 info_ptr
+= bytes_read
;
13907 case DW_FORM_string
:
13908 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
13909 DW_STRING_IS_CANONICAL (attr
) = 0;
13910 info_ptr
+= bytes_read
;
13913 if (!cu
->per_cu
->is_dwz
)
13915 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
13917 DW_STRING_IS_CANONICAL (attr
) = 0;
13918 info_ptr
+= bytes_read
;
13922 case DW_FORM_GNU_strp_alt
:
13924 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
13925 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
13928 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
13929 DW_STRING_IS_CANONICAL (attr
) = 0;
13930 info_ptr
+= bytes_read
;
13933 case DW_FORM_exprloc
:
13934 case DW_FORM_block
:
13935 blk
= dwarf_alloc_block (cu
);
13936 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13937 info_ptr
+= bytes_read
;
13938 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13939 info_ptr
+= blk
->size
;
13940 DW_BLOCK (attr
) = blk
;
13942 case DW_FORM_block1
:
13943 blk
= dwarf_alloc_block (cu
);
13944 blk
->size
= read_1_byte (abfd
, info_ptr
);
13946 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13947 info_ptr
+= blk
->size
;
13948 DW_BLOCK (attr
) = blk
;
13950 case DW_FORM_data1
:
13951 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13955 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13958 case DW_FORM_flag_present
:
13959 DW_UNSND (attr
) = 1;
13961 case DW_FORM_sdata
:
13962 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
13963 info_ptr
+= bytes_read
;
13965 case DW_FORM_udata
:
13966 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13967 info_ptr
+= bytes_read
;
13970 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13971 + read_1_byte (abfd
, info_ptr
));
13975 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13976 + read_2_bytes (abfd
, info_ptr
));
13980 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13981 + read_4_bytes (abfd
, info_ptr
));
13985 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13986 + read_8_bytes (abfd
, info_ptr
));
13989 case DW_FORM_ref_sig8
:
13990 /* Convert the signature to something we can record in DW_UNSND
13992 NOTE: This is NULL if the type wasn't found. */
13993 DW_SIGNATURED_TYPE (attr
) =
13994 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
13997 case DW_FORM_ref_udata
:
13998 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13999 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
14000 info_ptr
+= bytes_read
;
14002 case DW_FORM_indirect
:
14003 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14004 info_ptr
+= bytes_read
;
14005 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
14007 case DW_FORM_GNU_addr_index
:
14008 if (reader
->dwo_file
== NULL
)
14010 /* For now flag a hard error.
14011 Later we can turn this into a complaint. */
14012 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14013 dwarf_form_name (form
),
14014 bfd_get_filename (abfd
));
14016 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
14017 info_ptr
+= bytes_read
;
14019 case DW_FORM_GNU_str_index
:
14020 if (reader
->dwo_file
== NULL
)
14022 /* For now flag a hard error.
14023 Later we can turn this into a complaint if warranted. */
14024 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14025 dwarf_form_name (form
),
14026 bfd_get_filename (abfd
));
14029 ULONGEST str_index
=
14030 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14032 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
14033 DW_STRING_IS_CANONICAL (attr
) = 0;
14034 info_ptr
+= bytes_read
;
14038 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14039 dwarf_form_name (form
),
14040 bfd_get_filename (abfd
));
14044 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
14045 attr
->form
= DW_FORM_GNU_ref_alt
;
14047 /* We have seen instances where the compiler tried to emit a byte
14048 size attribute of -1 which ended up being encoded as an unsigned
14049 0xffffffff. Although 0xffffffff is technically a valid size value,
14050 an object of this size seems pretty unlikely so we can relatively
14051 safely treat these cases as if the size attribute was invalid and
14052 treat them as zero by default. */
14053 if (attr
->name
== DW_AT_byte_size
14054 && form
== DW_FORM_data4
14055 && DW_UNSND (attr
) >= 0xffffffff)
14058 (&symfile_complaints
,
14059 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14060 hex_string (DW_UNSND (attr
)));
14061 DW_UNSND (attr
) = 0;
14067 /* Read an attribute described by an abbreviated attribute. */
14070 read_attribute (const struct die_reader_specs
*reader
,
14071 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
14072 gdb_byte
*info_ptr
)
14074 attr
->name
= abbrev
->name
;
14075 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
14078 /* Read dwarf information from a buffer. */
14080 static unsigned int
14081 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
14083 return bfd_get_8 (abfd
, buf
);
14087 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
14089 return bfd_get_signed_8 (abfd
, buf
);
14092 static unsigned int
14093 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14095 return bfd_get_16 (abfd
, buf
);
14099 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14101 return bfd_get_signed_16 (abfd
, buf
);
14104 static unsigned int
14105 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14107 return bfd_get_32 (abfd
, buf
);
14111 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14113 return bfd_get_signed_32 (abfd
, buf
);
14117 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14119 return bfd_get_64 (abfd
, buf
);
14123 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
14124 unsigned int *bytes_read
)
14126 struct comp_unit_head
*cu_header
= &cu
->header
;
14127 CORE_ADDR retval
= 0;
14129 if (cu_header
->signed_addr_p
)
14131 switch (cu_header
->addr_size
)
14134 retval
= bfd_get_signed_16 (abfd
, buf
);
14137 retval
= bfd_get_signed_32 (abfd
, buf
);
14140 retval
= bfd_get_signed_64 (abfd
, buf
);
14143 internal_error (__FILE__
, __LINE__
,
14144 _("read_address: bad switch, signed [in module %s]"),
14145 bfd_get_filename (abfd
));
14150 switch (cu_header
->addr_size
)
14153 retval
= bfd_get_16 (abfd
, buf
);
14156 retval
= bfd_get_32 (abfd
, buf
);
14159 retval
= bfd_get_64 (abfd
, buf
);
14162 internal_error (__FILE__
, __LINE__
,
14163 _("read_address: bad switch, "
14164 "unsigned [in module %s]"),
14165 bfd_get_filename (abfd
));
14169 *bytes_read
= cu_header
->addr_size
;
14173 /* Read the initial length from a section. The (draft) DWARF 3
14174 specification allows the initial length to take up either 4 bytes
14175 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14176 bytes describe the length and all offsets will be 8 bytes in length
14179 An older, non-standard 64-bit format is also handled by this
14180 function. The older format in question stores the initial length
14181 as an 8-byte quantity without an escape value. Lengths greater
14182 than 2^32 aren't very common which means that the initial 4 bytes
14183 is almost always zero. Since a length value of zero doesn't make
14184 sense for the 32-bit format, this initial zero can be considered to
14185 be an escape value which indicates the presence of the older 64-bit
14186 format. As written, the code can't detect (old format) lengths
14187 greater than 4GB. If it becomes necessary to handle lengths
14188 somewhat larger than 4GB, we could allow other small values (such
14189 as the non-sensical values of 1, 2, and 3) to also be used as
14190 escape values indicating the presence of the old format.
14192 The value returned via bytes_read should be used to increment the
14193 relevant pointer after calling read_initial_length().
14195 [ Note: read_initial_length() and read_offset() are based on the
14196 document entitled "DWARF Debugging Information Format", revision
14197 3, draft 8, dated November 19, 2001. This document was obtained
14200 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14202 This document is only a draft and is subject to change. (So beware.)
14204 Details regarding the older, non-standard 64-bit format were
14205 determined empirically by examining 64-bit ELF files produced by
14206 the SGI toolchain on an IRIX 6.5 machine.
14208 - Kevin, July 16, 2002
14212 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
14214 LONGEST length
= bfd_get_32 (abfd
, buf
);
14216 if (length
== 0xffffffff)
14218 length
= bfd_get_64 (abfd
, buf
+ 4);
14221 else if (length
== 0)
14223 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14224 length
= bfd_get_64 (abfd
, buf
);
14235 /* Cover function for read_initial_length.
14236 Returns the length of the object at BUF, and stores the size of the
14237 initial length in *BYTES_READ and stores the size that offsets will be in
14239 If the initial length size is not equivalent to that specified in
14240 CU_HEADER then issue a complaint.
14241 This is useful when reading non-comp-unit headers. */
14244 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
14245 const struct comp_unit_head
*cu_header
,
14246 unsigned int *bytes_read
,
14247 unsigned int *offset_size
)
14249 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
14251 gdb_assert (cu_header
->initial_length_size
== 4
14252 || cu_header
->initial_length_size
== 8
14253 || cu_header
->initial_length_size
== 12);
14255 if (cu_header
->initial_length_size
!= *bytes_read
)
14256 complaint (&symfile_complaints
,
14257 _("intermixed 32-bit and 64-bit DWARF sections"));
14259 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
14263 /* Read an offset from the data stream. The size of the offset is
14264 given by cu_header->offset_size. */
14267 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
14268 unsigned int *bytes_read
)
14270 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
14272 *bytes_read
= cu_header
->offset_size
;
14276 /* Read an offset from the data stream. */
14279 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
14281 LONGEST retval
= 0;
14283 switch (offset_size
)
14286 retval
= bfd_get_32 (abfd
, buf
);
14289 retval
= bfd_get_64 (abfd
, buf
);
14292 internal_error (__FILE__
, __LINE__
,
14293 _("read_offset_1: bad switch [in module %s]"),
14294 bfd_get_filename (abfd
));
14301 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
14303 /* If the size of a host char is 8 bits, we can return a pointer
14304 to the buffer, otherwise we have to copy the data to a buffer
14305 allocated on the temporary obstack. */
14306 gdb_assert (HOST_CHAR_BIT
== 8);
14311 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14313 /* If the size of a host char is 8 bits, we can return a pointer
14314 to the string, otherwise we have to copy the string to a buffer
14315 allocated on the temporary obstack. */
14316 gdb_assert (HOST_CHAR_BIT
== 8);
14319 *bytes_read_ptr
= 1;
14322 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
14323 return (char *) buf
;
14327 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
14329 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
14330 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
14331 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14332 bfd_get_filename (abfd
));
14333 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
14334 error (_("DW_FORM_strp pointing outside of "
14335 ".debug_str section [in module %s]"),
14336 bfd_get_filename (abfd
));
14337 gdb_assert (HOST_CHAR_BIT
== 8);
14338 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
14340 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
14343 /* Read a string at offset STR_OFFSET in the .debug_str section from
14344 the .dwz file DWZ. Throw an error if the offset is too large. If
14345 the string consists of a single NUL byte, return NULL; otherwise
14346 return a pointer to the string. */
14349 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
14351 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
14353 if (dwz
->str
.buffer
== NULL
)
14354 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14355 "section [in module %s]"),
14356 bfd_get_filename (dwz
->dwz_bfd
));
14357 if (str_offset
>= dwz
->str
.size
)
14358 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14359 ".debug_str section [in module %s]"),
14360 bfd_get_filename (dwz
->dwz_bfd
));
14361 gdb_assert (HOST_CHAR_BIT
== 8);
14362 if (dwz
->str
.buffer
[str_offset
] == '\0')
14364 return (char *) (dwz
->str
.buffer
+ str_offset
);
14368 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
14369 const struct comp_unit_head
*cu_header
,
14370 unsigned int *bytes_read_ptr
)
14372 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
14374 return read_indirect_string_at_offset (abfd
, str_offset
);
14378 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14381 unsigned int num_read
;
14383 unsigned char byte
;
14391 byte
= bfd_get_8 (abfd
, buf
);
14394 result
|= ((ULONGEST
) (byte
& 127) << shift
);
14395 if ((byte
& 128) == 0)
14401 *bytes_read_ptr
= num_read
;
14406 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14409 int i
, shift
, num_read
;
14410 unsigned char byte
;
14418 byte
= bfd_get_8 (abfd
, buf
);
14421 result
|= ((LONGEST
) (byte
& 127) << shift
);
14423 if ((byte
& 128) == 0)
14428 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
14429 result
|= -(((LONGEST
) 1) << shift
);
14430 *bytes_read_ptr
= num_read
;
14434 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14435 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14436 ADDR_SIZE is the size of addresses from the CU header. */
14439 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
14441 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14442 bfd
*abfd
= objfile
->obfd
;
14443 const gdb_byte
*info_ptr
;
14445 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
14446 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
14447 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14449 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
14450 error (_("DW_FORM_addr_index pointing outside of "
14451 ".debug_addr section [in module %s]"),
14453 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
14454 + addr_base
+ addr_index
* addr_size
);
14455 if (addr_size
== 4)
14456 return bfd_get_32 (abfd
, info_ptr
);
14458 return bfd_get_64 (abfd
, info_ptr
);
14461 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14464 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
14466 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
14469 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14472 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
14473 unsigned int *bytes_read
)
14475 bfd
*abfd
= cu
->objfile
->obfd
;
14476 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
14478 return read_addr_index (cu
, addr_index
);
14481 /* Data structure to pass results from dwarf2_read_addr_index_reader
14482 back to dwarf2_read_addr_index. */
14484 struct dwarf2_read_addr_index_data
14486 ULONGEST addr_base
;
14490 /* die_reader_func for dwarf2_read_addr_index. */
14493 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
14494 gdb_byte
*info_ptr
,
14495 struct die_info
*comp_unit_die
,
14499 struct dwarf2_cu
*cu
= reader
->cu
;
14500 struct dwarf2_read_addr_index_data
*aidata
=
14501 (struct dwarf2_read_addr_index_data
*) data
;
14503 aidata
->addr_base
= cu
->addr_base
;
14504 aidata
->addr_size
= cu
->header
.addr_size
;
14507 /* Given an index in .debug_addr, fetch the value.
14508 NOTE: This can be called during dwarf expression evaluation,
14509 long after the debug information has been read, and thus per_cu->cu
14510 may no longer exist. */
14513 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
14514 unsigned int addr_index
)
14516 struct objfile
*objfile
= per_cu
->objfile
;
14517 struct dwarf2_cu
*cu
= per_cu
->cu
;
14518 ULONGEST addr_base
;
14521 /* This is intended to be called from outside this file. */
14522 dw2_setup (objfile
);
14524 /* We need addr_base and addr_size.
14525 If we don't have PER_CU->cu, we have to get it.
14526 Nasty, but the alternative is storing the needed info in PER_CU,
14527 which at this point doesn't seem justified: it's not clear how frequently
14528 it would get used and it would increase the size of every PER_CU.
14529 Entry points like dwarf2_per_cu_addr_size do a similar thing
14530 so we're not in uncharted territory here.
14531 Alas we need to be a bit more complicated as addr_base is contained
14534 We don't need to read the entire CU(/TU).
14535 We just need the header and top level die.
14537 IWBN to use the aging mechanism to let us lazily later discard the CU.
14538 For now we skip this optimization. */
14542 addr_base
= cu
->addr_base
;
14543 addr_size
= cu
->header
.addr_size
;
14547 struct dwarf2_read_addr_index_data aidata
;
14549 /* Note: We can't use init_cutu_and_read_dies_simple here,
14550 we need addr_base. */
14551 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
14552 dwarf2_read_addr_index_reader
, &aidata
);
14553 addr_base
= aidata
.addr_base
;
14554 addr_size
= aidata
.addr_size
;
14557 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
14560 /* Given a DW_AT_str_index, fetch the string. */
14563 read_str_index (const struct die_reader_specs
*reader
,
14564 struct dwarf2_cu
*cu
, ULONGEST str_index
)
14566 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14567 const char *dwo_name
= objfile
->name
;
14568 bfd
*abfd
= objfile
->obfd
;
14569 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
14570 gdb_byte
*info_ptr
;
14571 ULONGEST str_offset
;
14573 dwarf2_read_section (objfile
, §ions
->str
);
14574 dwarf2_read_section (objfile
, §ions
->str_offsets
);
14575 if (sections
->str
.buffer
== NULL
)
14576 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14577 " in CU at offset 0x%lx [in module %s]"),
14578 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14579 if (sections
->str_offsets
.buffer
== NULL
)
14580 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14581 " in CU at offset 0x%lx [in module %s]"),
14582 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14583 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
14584 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14585 " section in CU at offset 0x%lx [in module %s]"),
14586 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14587 info_ptr
= (sections
->str_offsets
.buffer
14588 + str_index
* cu
->header
.offset_size
);
14589 if (cu
->header
.offset_size
== 4)
14590 str_offset
= bfd_get_32 (abfd
, info_ptr
);
14592 str_offset
= bfd_get_64 (abfd
, info_ptr
);
14593 if (str_offset
>= sections
->str
.size
)
14594 error (_("Offset from DW_FORM_str_index pointing outside of"
14595 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14596 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14597 return (char *) (sections
->str
.buffer
+ str_offset
);
14600 /* Return the length of an LEB128 number in BUF. */
14603 leb128_size (const gdb_byte
*buf
)
14605 const gdb_byte
*begin
= buf
;
14611 if ((byte
& 128) == 0)
14612 return buf
- begin
;
14617 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
14624 cu
->language
= language_c
;
14626 case DW_LANG_C_plus_plus
:
14627 cu
->language
= language_cplus
;
14630 cu
->language
= language_d
;
14632 case DW_LANG_Fortran77
:
14633 case DW_LANG_Fortran90
:
14634 case DW_LANG_Fortran95
:
14635 cu
->language
= language_fortran
;
14638 cu
->language
= language_go
;
14640 case DW_LANG_Mips_Assembler
:
14641 cu
->language
= language_asm
;
14644 cu
->language
= language_java
;
14646 case DW_LANG_Ada83
:
14647 case DW_LANG_Ada95
:
14648 cu
->language
= language_ada
;
14650 case DW_LANG_Modula2
:
14651 cu
->language
= language_m2
;
14653 case DW_LANG_Pascal83
:
14654 cu
->language
= language_pascal
;
14657 cu
->language
= language_objc
;
14659 case DW_LANG_Cobol74
:
14660 case DW_LANG_Cobol85
:
14662 cu
->language
= language_minimal
;
14665 cu
->language_defn
= language_def (cu
->language
);
14668 /* Return the named attribute or NULL if not there. */
14670 static struct attribute
*
14671 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
14676 struct attribute
*spec
= NULL
;
14678 for (i
= 0; i
< die
->num_attrs
; ++i
)
14680 if (die
->attrs
[i
].name
== name
)
14681 return &die
->attrs
[i
];
14682 if (die
->attrs
[i
].name
== DW_AT_specification
14683 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
14684 spec
= &die
->attrs
[i
];
14690 die
= follow_die_ref (die
, spec
, &cu
);
14696 /* Return the named attribute or NULL if not there,
14697 but do not follow DW_AT_specification, etc.
14698 This is for use in contexts where we're reading .debug_types dies.
14699 Following DW_AT_specification, DW_AT_abstract_origin will take us
14700 back up the chain, and we want to go down. */
14702 static struct attribute
*
14703 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
14707 for (i
= 0; i
< die
->num_attrs
; ++i
)
14708 if (die
->attrs
[i
].name
== name
)
14709 return &die
->attrs
[i
];
14714 /* Return non-zero iff the attribute NAME is defined for the given DIE,
14715 and holds a non-zero value. This function should only be used for
14716 DW_FORM_flag or DW_FORM_flag_present attributes. */
14719 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
14721 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
14723 return (attr
&& DW_UNSND (attr
));
14727 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
14729 /* A DIE is a declaration if it has a DW_AT_declaration attribute
14730 which value is non-zero. However, we have to be careful with
14731 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
14732 (via dwarf2_flag_true_p) follows this attribute. So we may
14733 end up accidently finding a declaration attribute that belongs
14734 to a different DIE referenced by the specification attribute,
14735 even though the given DIE does not have a declaration attribute. */
14736 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
14737 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
14740 /* Return the die giving the specification for DIE, if there is
14741 one. *SPEC_CU is the CU containing DIE on input, and the CU
14742 containing the return value on output. If there is no
14743 specification, but there is an abstract origin, that is
14746 static struct die_info
*
14747 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
14749 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
14752 if (spec_attr
== NULL
)
14753 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
14755 if (spec_attr
== NULL
)
14758 return follow_die_ref (die
, spec_attr
, spec_cu
);
14761 /* Free the line_header structure *LH, and any arrays and strings it
14763 NOTE: This is also used as a "cleanup" function. */
14766 free_line_header (struct line_header
*lh
)
14768 if (lh
->standard_opcode_lengths
)
14769 xfree (lh
->standard_opcode_lengths
);
14771 /* Remember that all the lh->file_names[i].name pointers are
14772 pointers into debug_line_buffer, and don't need to be freed. */
14773 if (lh
->file_names
)
14774 xfree (lh
->file_names
);
14776 /* Similarly for the include directory names. */
14777 if (lh
->include_dirs
)
14778 xfree (lh
->include_dirs
);
14783 /* Add an entry to LH's include directory table. */
14786 add_include_dir (struct line_header
*lh
, char *include_dir
)
14788 /* Grow the array if necessary. */
14789 if (lh
->include_dirs_size
== 0)
14791 lh
->include_dirs_size
= 1; /* for testing */
14792 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
14793 * sizeof (*lh
->include_dirs
));
14795 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
14797 lh
->include_dirs_size
*= 2;
14798 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
14799 (lh
->include_dirs_size
14800 * sizeof (*lh
->include_dirs
)));
14803 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
14806 /* Add an entry to LH's file name table. */
14809 add_file_name (struct line_header
*lh
,
14811 unsigned int dir_index
,
14812 unsigned int mod_time
,
14813 unsigned int length
)
14815 struct file_entry
*fe
;
14817 /* Grow the array if necessary. */
14818 if (lh
->file_names_size
== 0)
14820 lh
->file_names_size
= 1; /* for testing */
14821 lh
->file_names
= xmalloc (lh
->file_names_size
14822 * sizeof (*lh
->file_names
));
14824 else if (lh
->num_file_names
>= lh
->file_names_size
)
14826 lh
->file_names_size
*= 2;
14827 lh
->file_names
= xrealloc (lh
->file_names
,
14828 (lh
->file_names_size
14829 * sizeof (*lh
->file_names
)));
14832 fe
= &lh
->file_names
[lh
->num_file_names
++];
14834 fe
->dir_index
= dir_index
;
14835 fe
->mod_time
= mod_time
;
14836 fe
->length
= length
;
14837 fe
->included_p
= 0;
14841 /* A convenience function to find the proper .debug_line section for a
14844 static struct dwarf2_section_info
*
14845 get_debug_line_section (struct dwarf2_cu
*cu
)
14847 struct dwarf2_section_info
*section
;
14849 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14851 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14852 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
14853 else if (cu
->per_cu
->is_dwz
)
14855 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14857 section
= &dwz
->line
;
14860 section
= &dwarf2_per_objfile
->line
;
14865 /* Read the statement program header starting at OFFSET in
14866 .debug_line, or .debug_line.dwo. Return a pointer
14867 to a struct line_header, allocated using xmalloc.
14869 NOTE: the strings in the include directory and file name tables of
14870 the returned object point into the dwarf line section buffer,
14871 and must not be freed. */
14873 static struct line_header
*
14874 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
14876 struct cleanup
*back_to
;
14877 struct line_header
*lh
;
14878 gdb_byte
*line_ptr
;
14879 unsigned int bytes_read
, offset_size
;
14881 char *cur_dir
, *cur_file
;
14882 struct dwarf2_section_info
*section
;
14885 section
= get_debug_line_section (cu
);
14886 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
14887 if (section
->buffer
== NULL
)
14889 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14890 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
14892 complaint (&symfile_complaints
, _("missing .debug_line section"));
14896 /* We can't do this until we know the section is non-empty.
14897 Only then do we know we have such a section. */
14898 abfd
= section
->asection
->owner
;
14900 /* Make sure that at least there's room for the total_length field.
14901 That could be 12 bytes long, but we're just going to fudge that. */
14902 if (offset
+ 4 >= section
->size
)
14904 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14908 lh
= xmalloc (sizeof (*lh
));
14909 memset (lh
, 0, sizeof (*lh
));
14910 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
14913 line_ptr
= section
->buffer
+ offset
;
14915 /* Read in the header. */
14917 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
14918 &bytes_read
, &offset_size
);
14919 line_ptr
+= bytes_read
;
14920 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
14922 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14925 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
14926 lh
->version
= read_2_bytes (abfd
, line_ptr
);
14928 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
14929 line_ptr
+= offset_size
;
14930 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
14932 if (lh
->version
>= 4)
14934 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
14938 lh
->maximum_ops_per_instruction
= 1;
14940 if (lh
->maximum_ops_per_instruction
== 0)
14942 lh
->maximum_ops_per_instruction
= 1;
14943 complaint (&symfile_complaints
,
14944 _("invalid maximum_ops_per_instruction "
14945 "in `.debug_line' section"));
14948 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
14950 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
14952 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
14954 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
14956 lh
->standard_opcode_lengths
14957 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
14959 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
14960 for (i
= 1; i
< lh
->opcode_base
; ++i
)
14962 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
14966 /* Read directory table. */
14967 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14969 line_ptr
+= bytes_read
;
14970 add_include_dir (lh
, cur_dir
);
14972 line_ptr
+= bytes_read
;
14974 /* Read file name table. */
14975 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14977 unsigned int dir_index
, mod_time
, length
;
14979 line_ptr
+= bytes_read
;
14980 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14981 line_ptr
+= bytes_read
;
14982 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14983 line_ptr
+= bytes_read
;
14984 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14985 line_ptr
+= bytes_read
;
14987 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14989 line_ptr
+= bytes_read
;
14990 lh
->statement_program_start
= line_ptr
;
14992 if (line_ptr
> (section
->buffer
+ section
->size
))
14993 complaint (&symfile_complaints
,
14994 _("line number info header doesn't "
14995 "fit in `.debug_line' section"));
14997 discard_cleanups (back_to
);
15001 /* Subroutine of dwarf_decode_lines to simplify it.
15002 Return the file name of the psymtab for included file FILE_INDEX
15003 in line header LH of PST.
15004 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15005 If space for the result is malloc'd, it will be freed by a cleanup.
15006 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
15009 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
15010 const struct partial_symtab
*pst
,
15011 const char *comp_dir
)
15013 const struct file_entry fe
= lh
->file_names
[file_index
];
15014 char *include_name
= fe
.name
;
15015 char *include_name_to_compare
= include_name
;
15016 char *dir_name
= NULL
;
15017 const char *pst_filename
;
15018 char *copied_name
= NULL
;
15022 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
15024 if (!IS_ABSOLUTE_PATH (include_name
)
15025 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
15027 /* Avoid creating a duplicate psymtab for PST.
15028 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15029 Before we do the comparison, however, we need to account
15030 for DIR_NAME and COMP_DIR.
15031 First prepend dir_name (if non-NULL). If we still don't
15032 have an absolute path prepend comp_dir (if non-NULL).
15033 However, the directory we record in the include-file's
15034 psymtab does not contain COMP_DIR (to match the
15035 corresponding symtab(s)).
15040 bash$ gcc -g ./hello.c
15041 include_name = "hello.c"
15043 DW_AT_comp_dir = comp_dir = "/tmp"
15044 DW_AT_name = "./hello.c" */
15046 if (dir_name
!= NULL
)
15048 include_name
= concat (dir_name
, SLASH_STRING
,
15049 include_name
, (char *)NULL
);
15050 include_name_to_compare
= include_name
;
15051 make_cleanup (xfree
, include_name
);
15053 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
15055 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
15056 include_name
, (char *)NULL
);
15060 pst_filename
= pst
->filename
;
15061 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
15063 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
15064 pst_filename
, (char *)NULL
);
15065 pst_filename
= copied_name
;
15068 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
15070 if (include_name_to_compare
!= include_name
)
15071 xfree (include_name_to_compare
);
15072 if (copied_name
!= NULL
)
15073 xfree (copied_name
);
15077 return include_name
;
15080 /* Ignore this record_line request. */
15083 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15088 /* Subroutine of dwarf_decode_lines to simplify it.
15089 Process the line number information in LH. */
15092 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
15093 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
15095 gdb_byte
*line_ptr
, *extended_end
;
15096 gdb_byte
*line_end
;
15097 unsigned int bytes_read
, extended_len
;
15098 unsigned char op_code
, extended_op
, adj_opcode
;
15099 CORE_ADDR baseaddr
;
15100 struct objfile
*objfile
= cu
->objfile
;
15101 bfd
*abfd
= objfile
->obfd
;
15102 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15103 const int decode_for_pst_p
= (pst
!= NULL
);
15104 struct subfile
*last_subfile
= NULL
;
15105 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15108 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15110 line_ptr
= lh
->statement_program_start
;
15111 line_end
= lh
->statement_program_end
;
15113 /* Read the statement sequences until there's nothing left. */
15114 while (line_ptr
< line_end
)
15116 /* state machine registers */
15117 CORE_ADDR address
= 0;
15118 unsigned int file
= 1;
15119 unsigned int line
= 1;
15120 unsigned int column
= 0;
15121 int is_stmt
= lh
->default_is_stmt
;
15122 int basic_block
= 0;
15123 int end_sequence
= 0;
15125 unsigned char op_index
= 0;
15127 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
15129 /* Start a subfile for the current file of the state machine. */
15130 /* lh->include_dirs and lh->file_names are 0-based, but the
15131 directory and file name numbers in the statement program
15133 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15137 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15139 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15142 /* Decode the table. */
15143 while (!end_sequence
)
15145 op_code
= read_1_byte (abfd
, line_ptr
);
15147 if (line_ptr
> line_end
)
15149 dwarf2_debug_line_missing_end_sequence_complaint ();
15153 if (op_code
>= lh
->opcode_base
)
15155 /* Special operand. */
15156 adj_opcode
= op_code
- lh
->opcode_base
;
15157 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
15158 / lh
->maximum_ops_per_instruction
)
15159 * lh
->minimum_instruction_length
);
15160 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
15161 % lh
->maximum_ops_per_instruction
);
15162 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
15163 if (lh
->num_file_names
< file
|| file
== 0)
15164 dwarf2_debug_line_missing_file_complaint ();
15165 /* For now we ignore lines not starting on an
15166 instruction boundary. */
15167 else if (op_index
== 0)
15169 lh
->file_names
[file
- 1].included_p
= 1;
15170 if (!decode_for_pst_p
&& is_stmt
)
15172 if (last_subfile
!= current_subfile
)
15174 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15176 (*p_record_line
) (last_subfile
, 0, addr
);
15177 last_subfile
= current_subfile
;
15179 /* Append row to matrix using current values. */
15180 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15181 (*p_record_line
) (current_subfile
, line
, addr
);
15186 else switch (op_code
)
15188 case DW_LNS_extended_op
:
15189 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
15191 line_ptr
+= bytes_read
;
15192 extended_end
= line_ptr
+ extended_len
;
15193 extended_op
= read_1_byte (abfd
, line_ptr
);
15195 switch (extended_op
)
15197 case DW_LNE_end_sequence
:
15198 p_record_line
= record_line
;
15201 case DW_LNE_set_address
:
15202 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
15204 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15206 /* This line table is for a function which has been
15207 GCd by the linker. Ignore it. PR gdb/12528 */
15210 = line_ptr
- get_debug_line_section (cu
)->buffer
;
15212 complaint (&symfile_complaints
,
15213 _(".debug_line address at offset 0x%lx is 0 "
15215 line_offset
, objfile
->name
);
15216 p_record_line
= noop_record_line
;
15220 line_ptr
+= bytes_read
;
15221 address
+= baseaddr
;
15223 case DW_LNE_define_file
:
15226 unsigned int dir_index
, mod_time
, length
;
15228 cur_file
= read_direct_string (abfd
, line_ptr
,
15230 line_ptr
+= bytes_read
;
15232 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15233 line_ptr
+= bytes_read
;
15235 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15236 line_ptr
+= bytes_read
;
15238 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15239 line_ptr
+= bytes_read
;
15240 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15243 case DW_LNE_set_discriminator
:
15244 /* The discriminator is not interesting to the debugger;
15246 line_ptr
= extended_end
;
15249 complaint (&symfile_complaints
,
15250 _("mangled .debug_line section"));
15253 /* Make sure that we parsed the extended op correctly. If e.g.
15254 we expected a different address size than the producer used,
15255 we may have read the wrong number of bytes. */
15256 if (line_ptr
!= extended_end
)
15258 complaint (&symfile_complaints
,
15259 _("mangled .debug_line section"));
15264 if (lh
->num_file_names
< file
|| file
== 0)
15265 dwarf2_debug_line_missing_file_complaint ();
15268 lh
->file_names
[file
- 1].included_p
= 1;
15269 if (!decode_for_pst_p
&& is_stmt
)
15271 if (last_subfile
!= current_subfile
)
15273 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15275 (*p_record_line
) (last_subfile
, 0, addr
);
15276 last_subfile
= current_subfile
;
15278 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15279 (*p_record_line
) (current_subfile
, line
, addr
);
15284 case DW_LNS_advance_pc
:
15287 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15289 address
+= (((op_index
+ adjust
)
15290 / lh
->maximum_ops_per_instruction
)
15291 * lh
->minimum_instruction_length
);
15292 op_index
= ((op_index
+ adjust
)
15293 % lh
->maximum_ops_per_instruction
);
15294 line_ptr
+= bytes_read
;
15297 case DW_LNS_advance_line
:
15298 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
15299 line_ptr
+= bytes_read
;
15301 case DW_LNS_set_file
:
15303 /* The arrays lh->include_dirs and lh->file_names are
15304 0-based, but the directory and file name numbers in
15305 the statement program are 1-based. */
15306 struct file_entry
*fe
;
15309 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15310 line_ptr
+= bytes_read
;
15311 if (lh
->num_file_names
< file
|| file
== 0)
15312 dwarf2_debug_line_missing_file_complaint ();
15315 fe
= &lh
->file_names
[file
- 1];
15317 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15318 if (!decode_for_pst_p
)
15320 last_subfile
= current_subfile
;
15321 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15326 case DW_LNS_set_column
:
15327 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15328 line_ptr
+= bytes_read
;
15330 case DW_LNS_negate_stmt
:
15331 is_stmt
= (!is_stmt
);
15333 case DW_LNS_set_basic_block
:
15336 /* Add to the address register of the state machine the
15337 address increment value corresponding to special opcode
15338 255. I.e., this value is scaled by the minimum
15339 instruction length since special opcode 255 would have
15340 scaled the increment. */
15341 case DW_LNS_const_add_pc
:
15343 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
15345 address
+= (((op_index
+ adjust
)
15346 / lh
->maximum_ops_per_instruction
)
15347 * lh
->minimum_instruction_length
);
15348 op_index
= ((op_index
+ adjust
)
15349 % lh
->maximum_ops_per_instruction
);
15352 case DW_LNS_fixed_advance_pc
:
15353 address
+= read_2_bytes (abfd
, line_ptr
);
15359 /* Unknown standard opcode, ignore it. */
15362 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
15364 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15365 line_ptr
+= bytes_read
;
15370 if (lh
->num_file_names
< file
|| file
== 0)
15371 dwarf2_debug_line_missing_file_complaint ();
15374 lh
->file_names
[file
- 1].included_p
= 1;
15375 if (!decode_for_pst_p
)
15377 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15378 (*p_record_line
) (current_subfile
, 0, addr
);
15384 /* Decode the Line Number Program (LNP) for the given line_header
15385 structure and CU. The actual information extracted and the type
15386 of structures created from the LNP depends on the value of PST.
15388 1. If PST is NULL, then this procedure uses the data from the program
15389 to create all necessary symbol tables, and their linetables.
15391 2. If PST is not NULL, this procedure reads the program to determine
15392 the list of files included by the unit represented by PST, and
15393 builds all the associated partial symbol tables.
15395 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15396 It is used for relative paths in the line table.
15397 NOTE: When processing partial symtabs (pst != NULL),
15398 comp_dir == pst->dirname.
15400 NOTE: It is important that psymtabs have the same file name (via strcmp)
15401 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15402 symtab we don't use it in the name of the psymtabs we create.
15403 E.g. expand_line_sal requires this when finding psymtabs to expand.
15404 A good testcase for this is mb-inline.exp. */
15407 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
15408 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
15409 int want_line_info
)
15411 struct objfile
*objfile
= cu
->objfile
;
15412 const int decode_for_pst_p
= (pst
!= NULL
);
15413 struct subfile
*first_subfile
= current_subfile
;
15415 if (want_line_info
)
15416 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
15418 if (decode_for_pst_p
)
15422 /* Now that we're done scanning the Line Header Program, we can
15423 create the psymtab of each included file. */
15424 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
15425 if (lh
->file_names
[file_index
].included_p
== 1)
15427 char *include_name
=
15428 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
15429 if (include_name
!= NULL
)
15430 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
15435 /* Make sure a symtab is created for every file, even files
15436 which contain only variables (i.e. no code with associated
15440 for (i
= 0; i
< lh
->num_file_names
; i
++)
15443 struct file_entry
*fe
;
15445 fe
= &lh
->file_names
[i
];
15447 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15448 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15450 /* Skip the main file; we don't need it, and it must be
15451 allocated last, so that it will show up before the
15452 non-primary symtabs in the objfile's symtab list. */
15453 if (current_subfile
== first_subfile
)
15456 if (current_subfile
->symtab
== NULL
)
15457 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
15459 fe
->symtab
= current_subfile
->symtab
;
15464 /* Start a subfile for DWARF. FILENAME is the name of the file and
15465 DIRNAME the name of the source directory which contains FILENAME
15466 or NULL if not known. COMP_DIR is the compilation directory for the
15467 linetable's compilation unit or NULL if not known.
15468 This routine tries to keep line numbers from identical absolute and
15469 relative file names in a common subfile.
15471 Using the `list' example from the GDB testsuite, which resides in
15472 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15473 of /srcdir/list0.c yields the following debugging information for list0.c:
15475 DW_AT_name: /srcdir/list0.c
15476 DW_AT_comp_dir: /compdir
15477 files.files[0].name: list0.h
15478 files.files[0].dir: /srcdir
15479 files.files[1].name: list0.c
15480 files.files[1].dir: /srcdir
15482 The line number information for list0.c has to end up in a single
15483 subfile, so that `break /srcdir/list0.c:1' works as expected.
15484 start_subfile will ensure that this happens provided that we pass the
15485 concatenation of files.files[1].dir and files.files[1].name as the
15489 dwarf2_start_subfile (char *filename
, const char *dirname
,
15490 const char *comp_dir
)
15494 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15495 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15496 second argument to start_subfile. To be consistent, we do the
15497 same here. In order not to lose the line information directory,
15498 we concatenate it to the filename when it makes sense.
15499 Note that the Dwarf3 standard says (speaking of filenames in line
15500 information): ``The directory index is ignored for file names
15501 that represent full path names''. Thus ignoring dirname in the
15502 `else' branch below isn't an issue. */
15504 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
15505 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
15507 fullname
= filename
;
15509 start_subfile (fullname
, comp_dir
);
15511 if (fullname
!= filename
)
15515 /* Start a symtab for DWARF.
15516 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15519 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
15520 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
15522 start_symtab (name
, comp_dir
, low_pc
);
15523 record_debugformat ("DWARF 2");
15524 record_producer (cu
->producer
);
15526 /* We assume that we're processing GCC output. */
15527 processing_gcc_compilation
= 2;
15529 processing_has_namespace_info
= 0;
15533 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
15534 struct dwarf2_cu
*cu
)
15536 struct objfile
*objfile
= cu
->objfile
;
15537 struct comp_unit_head
*cu_header
= &cu
->header
;
15539 /* NOTE drow/2003-01-30: There used to be a comment and some special
15540 code here to turn a symbol with DW_AT_external and a
15541 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15542 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15543 with some versions of binutils) where shared libraries could have
15544 relocations against symbols in their debug information - the
15545 minimal symbol would have the right address, but the debug info
15546 would not. It's no longer necessary, because we will explicitly
15547 apply relocations when we read in the debug information now. */
15549 /* A DW_AT_location attribute with no contents indicates that a
15550 variable has been optimized away. */
15551 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
15553 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15557 /* Handle one degenerate form of location expression specially, to
15558 preserve GDB's previous behavior when section offsets are
15559 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15560 then mark this symbol as LOC_STATIC. */
15562 if (attr_form_is_block (attr
)
15563 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
15564 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
15565 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
15566 && (DW_BLOCK (attr
)->size
15567 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
15569 unsigned int dummy
;
15571 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
15572 SYMBOL_VALUE_ADDRESS (sym
) =
15573 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
15575 SYMBOL_VALUE_ADDRESS (sym
) =
15576 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
15577 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15578 fixup_symbol_section (sym
, objfile
);
15579 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
15580 SYMBOL_SECTION (sym
));
15584 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15585 expression evaluator, and use LOC_COMPUTED only when necessary
15586 (i.e. when the value of a register or memory location is
15587 referenced, or a thread-local block, etc.). Then again, it might
15588 not be worthwhile. I'm assuming that it isn't unless performance
15589 or memory numbers show me otherwise. */
15591 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
15592 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15594 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
15595 cu
->has_loclist
= 1;
15598 /* Given a pointer to a DWARF information entry, figure out if we need
15599 to make a symbol table entry for it, and if so, create a new entry
15600 and return a pointer to it.
15601 If TYPE is NULL, determine symbol type from the die, otherwise
15602 used the passed type.
15603 If SPACE is not NULL, use it to hold the new symbol. If it is
15604 NULL, allocate a new symbol on the objfile's obstack. */
15606 static struct symbol
*
15607 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
15608 struct symbol
*space
)
15610 struct objfile
*objfile
= cu
->objfile
;
15611 struct symbol
*sym
= NULL
;
15613 struct attribute
*attr
= NULL
;
15614 struct attribute
*attr2
= NULL
;
15615 CORE_ADDR baseaddr
;
15616 struct pending
**list_to_add
= NULL
;
15618 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
15620 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15622 name
= dwarf2_name (die
, cu
);
15625 const char *linkagename
;
15626 int suppress_add
= 0;
15631 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
15632 OBJSTAT (objfile
, n_syms
++);
15634 /* Cache this symbol's name and the name's demangled form (if any). */
15635 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
15636 linkagename
= dwarf2_physname (name
, die
, cu
);
15637 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
15639 /* Fortran does not have mangling standard and the mangling does differ
15640 between gfortran, iFort etc. */
15641 if (cu
->language
== language_fortran
15642 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
15643 symbol_set_demangled_name (&(sym
->ginfo
),
15644 (char *) dwarf2_full_name (name
, die
, cu
),
15647 /* Default assumptions.
15648 Use the passed type or decode it from the die. */
15649 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15650 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15652 SYMBOL_TYPE (sym
) = type
;
15654 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
15655 attr
= dwarf2_attr (die
,
15656 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
15660 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
15663 attr
= dwarf2_attr (die
,
15664 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
15668 int file_index
= DW_UNSND (attr
);
15670 if (cu
->line_header
== NULL
15671 || file_index
> cu
->line_header
->num_file_names
)
15672 complaint (&symfile_complaints
,
15673 _("file index out of range"));
15674 else if (file_index
> 0)
15676 struct file_entry
*fe
;
15678 fe
= &cu
->line_header
->file_names
[file_index
- 1];
15679 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
15686 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15689 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
15691 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
15692 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
15693 SYMBOL_CLASS (sym
) = LOC_LABEL
;
15694 add_symbol_to_list (sym
, cu
->list_in_scope
);
15696 case DW_TAG_subprogram
:
15697 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15699 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15700 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15701 if ((attr2
&& (DW_UNSND (attr2
) != 0))
15702 || cu
->language
== language_ada
)
15704 /* Subprograms marked external are stored as a global symbol.
15705 Ada subprograms, whether marked external or not, are always
15706 stored as a global symbol, because we want to be able to
15707 access them globally. For instance, we want to be able
15708 to break on a nested subprogram without having to
15709 specify the context. */
15710 list_to_add
= &global_symbols
;
15714 list_to_add
= cu
->list_in_scope
;
15717 case DW_TAG_inlined_subroutine
:
15718 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15720 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15721 SYMBOL_INLINED (sym
) = 1;
15722 list_to_add
= cu
->list_in_scope
;
15724 case DW_TAG_template_value_param
:
15726 /* Fall through. */
15727 case DW_TAG_constant
:
15728 case DW_TAG_variable
:
15729 case DW_TAG_member
:
15730 /* Compilation with minimal debug info may result in
15731 variables with missing type entries. Change the
15732 misleading `void' type to something sensible. */
15733 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
15735 = objfile_type (objfile
)->nodebug_data_symbol
;
15737 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15738 /* In the case of DW_TAG_member, we should only be called for
15739 static const members. */
15740 if (die
->tag
== DW_TAG_member
)
15742 /* dwarf2_add_field uses die_is_declaration,
15743 so we do the same. */
15744 gdb_assert (die_is_declaration (die
, cu
));
15749 dwarf2_const_value (attr
, sym
, cu
);
15750 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15753 if (attr2
&& (DW_UNSND (attr2
) != 0))
15754 list_to_add
= &global_symbols
;
15756 list_to_add
= cu
->list_in_scope
;
15760 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15763 var_decode_location (attr
, sym
, cu
);
15764 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15766 /* Fortran explicitly imports any global symbols to the local
15767 scope by DW_TAG_common_block. */
15768 if (cu
->language
== language_fortran
&& die
->parent
15769 && die
->parent
->tag
== DW_TAG_common_block
)
15772 if (SYMBOL_CLASS (sym
) == LOC_STATIC
15773 && SYMBOL_VALUE_ADDRESS (sym
) == 0
15774 && !dwarf2_per_objfile
->has_section_at_zero
)
15776 /* When a static variable is eliminated by the linker,
15777 the corresponding debug information is not stripped
15778 out, but the variable address is set to null;
15779 do not add such variables into symbol table. */
15781 else if (attr2
&& (DW_UNSND (attr2
) != 0))
15783 /* Workaround gfortran PR debug/40040 - it uses
15784 DW_AT_location for variables in -fPIC libraries which may
15785 get overriden by other libraries/executable and get
15786 a different address. Resolve it by the minimal symbol
15787 which may come from inferior's executable using copy
15788 relocation. Make this workaround only for gfortran as for
15789 other compilers GDB cannot guess the minimal symbol
15790 Fortran mangling kind. */
15791 if (cu
->language
== language_fortran
&& die
->parent
15792 && die
->parent
->tag
== DW_TAG_module
15794 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
15795 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15797 /* A variable with DW_AT_external is never static,
15798 but it may be block-scoped. */
15799 list_to_add
= (cu
->list_in_scope
== &file_symbols
15800 ? &global_symbols
: cu
->list_in_scope
);
15803 list_to_add
= cu
->list_in_scope
;
15807 /* We do not know the address of this symbol.
15808 If it is an external symbol and we have type information
15809 for it, enter the symbol as a LOC_UNRESOLVED symbol.
15810 The address of the variable will then be determined from
15811 the minimal symbol table whenever the variable is
15813 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15815 /* Fortran explicitly imports any global symbols to the local
15816 scope by DW_TAG_common_block. */
15817 if (cu
->language
== language_fortran
&& die
->parent
15818 && die
->parent
->tag
== DW_TAG_common_block
)
15820 /* SYMBOL_CLASS doesn't matter here because
15821 read_common_block is going to reset it. */
15823 list_to_add
= cu
->list_in_scope
;
15825 else if (attr2
&& (DW_UNSND (attr2
) != 0)
15826 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
15828 /* A variable with DW_AT_external is never static, but it
15829 may be block-scoped. */
15830 list_to_add
= (cu
->list_in_scope
== &file_symbols
15831 ? &global_symbols
: cu
->list_in_scope
);
15833 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15835 else if (!die_is_declaration (die
, cu
))
15837 /* Use the default LOC_OPTIMIZED_OUT class. */
15838 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
15840 list_to_add
= cu
->list_in_scope
;
15844 case DW_TAG_formal_parameter
:
15845 /* If we are inside a function, mark this as an argument. If
15846 not, we might be looking at an argument to an inlined function
15847 when we do not have enough information to show inlined frames;
15848 pretend it's a local variable in that case so that the user can
15850 if (context_stack_depth
> 0
15851 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
15852 SYMBOL_IS_ARGUMENT (sym
) = 1;
15853 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15856 var_decode_location (attr
, sym
, cu
);
15858 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15861 dwarf2_const_value (attr
, sym
, cu
);
15864 list_to_add
= cu
->list_in_scope
;
15866 case DW_TAG_unspecified_parameters
:
15867 /* From varargs functions; gdb doesn't seem to have any
15868 interest in this information, so just ignore it for now.
15871 case DW_TAG_template_type_param
:
15873 /* Fall through. */
15874 case DW_TAG_class_type
:
15875 case DW_TAG_interface_type
:
15876 case DW_TAG_structure_type
:
15877 case DW_TAG_union_type
:
15878 case DW_TAG_set_type
:
15879 case DW_TAG_enumeration_type
:
15880 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15881 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
15884 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
15885 really ever be static objects: otherwise, if you try
15886 to, say, break of a class's method and you're in a file
15887 which doesn't mention that class, it won't work unless
15888 the check for all static symbols in lookup_symbol_aux
15889 saves you. See the OtherFileClass tests in
15890 gdb.c++/namespace.exp. */
15894 list_to_add
= (cu
->list_in_scope
== &file_symbols
15895 && (cu
->language
== language_cplus
15896 || cu
->language
== language_java
)
15897 ? &global_symbols
: cu
->list_in_scope
);
15899 /* The semantics of C++ state that "struct foo {
15900 ... }" also defines a typedef for "foo". A Java
15901 class declaration also defines a typedef for the
15903 if (cu
->language
== language_cplus
15904 || cu
->language
== language_java
15905 || cu
->language
== language_ada
)
15907 /* The symbol's name is already allocated along
15908 with this objfile, so we don't need to
15909 duplicate it for the type. */
15910 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
15911 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
15916 case DW_TAG_typedef
:
15917 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15918 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15919 list_to_add
= cu
->list_in_scope
;
15921 case DW_TAG_base_type
:
15922 case DW_TAG_subrange_type
:
15923 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15924 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15925 list_to_add
= cu
->list_in_scope
;
15927 case DW_TAG_enumerator
:
15928 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15931 dwarf2_const_value (attr
, sym
, cu
);
15934 /* NOTE: carlton/2003-11-10: See comment above in the
15935 DW_TAG_class_type, etc. block. */
15937 list_to_add
= (cu
->list_in_scope
== &file_symbols
15938 && (cu
->language
== language_cplus
15939 || cu
->language
== language_java
)
15940 ? &global_symbols
: cu
->list_in_scope
);
15943 case DW_TAG_namespace
:
15944 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15945 list_to_add
= &global_symbols
;
15947 case DW_TAG_common_block
:
15948 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15949 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
15950 add_symbol_to_list (sym
, cu
->list_in_scope
);
15953 /* Not a tag we recognize. Hopefully we aren't processing
15954 trash data, but since we must specifically ignore things
15955 we don't recognize, there is nothing else we should do at
15957 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
15958 dwarf_tag_name (die
->tag
));
15964 sym
->hash_next
= objfile
->template_symbols
;
15965 objfile
->template_symbols
= sym
;
15966 list_to_add
= NULL
;
15969 if (list_to_add
!= NULL
)
15970 add_symbol_to_list (sym
, list_to_add
);
15972 /* For the benefit of old versions of GCC, check for anonymous
15973 namespaces based on the demangled name. */
15974 if (!processing_has_namespace_info
15975 && cu
->language
== language_cplus
)
15976 cp_scan_for_anonymous_namespaces (sym
, objfile
);
15981 /* A wrapper for new_symbol_full that always allocates a new symbol. */
15983 static struct symbol
*
15984 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15986 return new_symbol_full (die
, type
, cu
, NULL
);
15989 /* Given an attr with a DW_FORM_dataN value in host byte order,
15990 zero-extend it as appropriate for the symbol's type. The DWARF
15991 standard (v4) is not entirely clear about the meaning of using
15992 DW_FORM_dataN for a constant with a signed type, where the type is
15993 wider than the data. The conclusion of a discussion on the DWARF
15994 list was that this is unspecified. We choose to always zero-extend
15995 because that is the interpretation long in use by GCC. */
15998 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
15999 const char *name
, struct obstack
*obstack
,
16000 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
16002 struct objfile
*objfile
= cu
->objfile
;
16003 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
16004 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
16005 LONGEST l
= DW_UNSND (attr
);
16007 if (bits
< sizeof (*value
) * 8)
16009 l
&= ((LONGEST
) 1 << bits
) - 1;
16012 else if (bits
== sizeof (*value
) * 8)
16016 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
16017 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
16024 /* Read a constant value from an attribute. Either set *VALUE, or if
16025 the value does not fit in *VALUE, set *BYTES - either already
16026 allocated on the objfile obstack, or newly allocated on OBSTACK,
16027 or, set *BATON, if we translated the constant to a location
16031 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
16032 const char *name
, struct obstack
*obstack
,
16033 struct dwarf2_cu
*cu
,
16034 LONGEST
*value
, gdb_byte
**bytes
,
16035 struct dwarf2_locexpr_baton
**baton
)
16037 struct objfile
*objfile
= cu
->objfile
;
16038 struct comp_unit_head
*cu_header
= &cu
->header
;
16039 struct dwarf_block
*blk
;
16040 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
16041 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
16047 switch (attr
->form
)
16050 case DW_FORM_GNU_addr_index
:
16054 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
16055 dwarf2_const_value_length_mismatch_complaint (name
,
16056 cu_header
->addr_size
,
16057 TYPE_LENGTH (type
));
16058 /* Symbols of this form are reasonably rare, so we just
16059 piggyback on the existing location code rather than writing
16060 a new implementation of symbol_computed_ops. */
16061 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
16062 sizeof (struct dwarf2_locexpr_baton
));
16063 (*baton
)->per_cu
= cu
->per_cu
;
16064 gdb_assert ((*baton
)->per_cu
);
16066 (*baton
)->size
= 2 + cu_header
->addr_size
;
16067 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
16068 (*baton
)->data
= data
;
16070 data
[0] = DW_OP_addr
;
16071 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
16072 byte_order
, DW_ADDR (attr
));
16073 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
16076 case DW_FORM_string
:
16078 case DW_FORM_GNU_str_index
:
16079 case DW_FORM_GNU_strp_alt
:
16080 /* DW_STRING is already allocated on the objfile obstack, point
16082 *bytes
= (gdb_byte
*) DW_STRING (attr
);
16084 case DW_FORM_block1
:
16085 case DW_FORM_block2
:
16086 case DW_FORM_block4
:
16087 case DW_FORM_block
:
16088 case DW_FORM_exprloc
:
16089 blk
= DW_BLOCK (attr
);
16090 if (TYPE_LENGTH (type
) != blk
->size
)
16091 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
16092 TYPE_LENGTH (type
));
16093 *bytes
= blk
->data
;
16096 /* The DW_AT_const_value attributes are supposed to carry the
16097 symbol's value "represented as it would be on the target
16098 architecture." By the time we get here, it's already been
16099 converted to host endianness, so we just need to sign- or
16100 zero-extend it as appropriate. */
16101 case DW_FORM_data1
:
16102 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16103 obstack
, cu
, value
, 8);
16105 case DW_FORM_data2
:
16106 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16107 obstack
, cu
, value
, 16);
16109 case DW_FORM_data4
:
16110 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16111 obstack
, cu
, value
, 32);
16113 case DW_FORM_data8
:
16114 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16115 obstack
, cu
, value
, 64);
16118 case DW_FORM_sdata
:
16119 *value
= DW_SND (attr
);
16122 case DW_FORM_udata
:
16123 *value
= DW_UNSND (attr
);
16127 complaint (&symfile_complaints
,
16128 _("unsupported const value attribute form: '%s'"),
16129 dwarf_form_name (attr
->form
));
16136 /* Copy constant value from an attribute to a symbol. */
16139 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
16140 struct dwarf2_cu
*cu
)
16142 struct objfile
*objfile
= cu
->objfile
;
16143 struct comp_unit_head
*cu_header
= &cu
->header
;
16146 struct dwarf2_locexpr_baton
*baton
;
16148 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
16149 SYMBOL_PRINT_NAME (sym
),
16150 &objfile
->objfile_obstack
, cu
,
16151 &value
, &bytes
, &baton
);
16155 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16156 SYMBOL_LOCATION_BATON (sym
) = baton
;
16157 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
16159 else if (bytes
!= NULL
)
16161 SYMBOL_VALUE_BYTES (sym
) = bytes
;
16162 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
16166 SYMBOL_VALUE (sym
) = value
;
16167 SYMBOL_CLASS (sym
) = LOC_CONST
;
16171 /* Return the type of the die in question using its DW_AT_type attribute. */
16173 static struct type
*
16174 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16176 struct attribute
*type_attr
;
16178 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16181 /* A missing DW_AT_type represents a void type. */
16182 return objfile_type (cu
->objfile
)->builtin_void
;
16185 return lookup_die_type (die
, type_attr
, cu
);
16188 /* True iff CU's producer generates GNAT Ada auxiliary information
16189 that allows to find parallel types through that information instead
16190 of having to do expensive parallel lookups by type name. */
16193 need_gnat_info (struct dwarf2_cu
*cu
)
16195 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16196 of GNAT produces this auxiliary information, without any indication
16197 that it is produced. Part of enhancing the FSF version of GNAT
16198 to produce that information will be to put in place an indicator
16199 that we can use in order to determine whether the descriptive type
16200 info is available or not. One suggestion that has been made is
16201 to use a new attribute, attached to the CU die. For now, assume
16202 that the descriptive type info is not available. */
16206 /* Return the auxiliary type of the die in question using its
16207 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16208 attribute is not present. */
16210 static struct type
*
16211 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16213 struct attribute
*type_attr
;
16215 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
16219 return lookup_die_type (die
, type_attr
, cu
);
16222 /* If DIE has a descriptive_type attribute, then set the TYPE's
16223 descriptive type accordingly. */
16226 set_descriptive_type (struct type
*type
, struct die_info
*die
,
16227 struct dwarf2_cu
*cu
)
16229 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
16231 if (descriptive_type
)
16233 ALLOCATE_GNAT_AUX_TYPE (type
);
16234 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
16238 /* Return the containing type of the die in question using its
16239 DW_AT_containing_type attribute. */
16241 static struct type
*
16242 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16244 struct attribute
*type_attr
;
16246 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
16248 error (_("Dwarf Error: Problem turning containing type into gdb type "
16249 "[in module %s]"), cu
->objfile
->name
);
16251 return lookup_die_type (die
, type_attr
, cu
);
16254 /* Look up the type of DIE in CU using its type attribute ATTR.
16255 If there is no type substitute an error marker. */
16257 static struct type
*
16258 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
16259 struct dwarf2_cu
*cu
)
16261 struct objfile
*objfile
= cu
->objfile
;
16262 struct type
*this_type
;
16264 /* First see if we have it cached. */
16266 if (attr
->form
== DW_FORM_GNU_ref_alt
)
16268 struct dwarf2_per_cu_data
*per_cu
;
16269 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16271 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
16272 this_type
= get_die_type_at_offset (offset
, per_cu
);
16274 else if (is_ref_attr (attr
))
16276 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16278 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
16280 else if (attr
->form
== DW_FORM_ref_sig8
)
16282 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16284 /* sig_type will be NULL if the signatured type is missing from
16286 if (sig_type
== NULL
)
16287 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16288 "at 0x%x [in module %s]"),
16289 die
->offset
.sect_off
, objfile
->name
);
16291 gdb_assert (sig_type
->per_cu
.is_debug_types
);
16292 /* If we haven't filled in type_offset_in_section yet, then we
16293 haven't read the type in yet. */
16295 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
16298 get_die_type_at_offset (sig_type
->type_offset_in_section
,
16299 &sig_type
->per_cu
);
16304 dump_die_for_error (die
);
16305 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
16306 dwarf_attr_name (attr
->name
), objfile
->name
);
16309 /* If not cached we need to read it in. */
16311 if (this_type
== NULL
)
16313 struct die_info
*type_die
;
16314 struct dwarf2_cu
*type_cu
= cu
;
16316 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
16317 /* If we found the type now, it's probably because the type came
16318 from an inter-CU reference and the type's CU got expanded before
16320 this_type
= get_die_type (type_die
, type_cu
);
16321 if (this_type
== NULL
)
16322 this_type
= read_type_die_1 (type_die
, type_cu
);
16325 /* If we still don't have a type use an error marker. */
16327 if (this_type
== NULL
)
16329 char *message
, *saved
;
16331 /* read_type_die already issued a complaint. */
16332 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16334 cu
->header
.offset
.sect_off
,
16335 die
->offset
.sect_off
);
16336 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
16337 message
, strlen (message
));
16340 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
16346 /* Return the type in DIE, CU.
16347 Returns NULL for invalid types.
16349 This first does a lookup in the appropriate type_hash table,
16350 and only reads the die in if necessary.
16352 NOTE: This can be called when reading in partial or full symbols. */
16354 static struct type
*
16355 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
16357 struct type
*this_type
;
16359 this_type
= get_die_type (die
, cu
);
16363 return read_type_die_1 (die
, cu
);
16366 /* Read the type in DIE, CU.
16367 Returns NULL for invalid types. */
16369 static struct type
*
16370 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
16372 struct type
*this_type
= NULL
;
16376 case DW_TAG_class_type
:
16377 case DW_TAG_interface_type
:
16378 case DW_TAG_structure_type
:
16379 case DW_TAG_union_type
:
16380 this_type
= read_structure_type (die
, cu
);
16382 case DW_TAG_enumeration_type
:
16383 this_type
= read_enumeration_type (die
, cu
);
16385 case DW_TAG_subprogram
:
16386 case DW_TAG_subroutine_type
:
16387 case DW_TAG_inlined_subroutine
:
16388 this_type
= read_subroutine_type (die
, cu
);
16390 case DW_TAG_array_type
:
16391 this_type
= read_array_type (die
, cu
);
16393 case DW_TAG_set_type
:
16394 this_type
= read_set_type (die
, cu
);
16396 case DW_TAG_pointer_type
:
16397 this_type
= read_tag_pointer_type (die
, cu
);
16399 case DW_TAG_ptr_to_member_type
:
16400 this_type
= read_tag_ptr_to_member_type (die
, cu
);
16402 case DW_TAG_reference_type
:
16403 this_type
= read_tag_reference_type (die
, cu
);
16405 case DW_TAG_const_type
:
16406 this_type
= read_tag_const_type (die
, cu
);
16408 case DW_TAG_volatile_type
:
16409 this_type
= read_tag_volatile_type (die
, cu
);
16411 case DW_TAG_string_type
:
16412 this_type
= read_tag_string_type (die
, cu
);
16414 case DW_TAG_typedef
:
16415 this_type
= read_typedef (die
, cu
);
16417 case DW_TAG_subrange_type
:
16418 this_type
= read_subrange_type (die
, cu
);
16420 case DW_TAG_base_type
:
16421 this_type
= read_base_type (die
, cu
);
16423 case DW_TAG_unspecified_type
:
16424 this_type
= read_unspecified_type (die
, cu
);
16426 case DW_TAG_namespace
:
16427 this_type
= read_namespace_type (die
, cu
);
16429 case DW_TAG_module
:
16430 this_type
= read_module_type (die
, cu
);
16433 complaint (&symfile_complaints
,
16434 _("unexpected tag in read_type_die: '%s'"),
16435 dwarf_tag_name (die
->tag
));
16442 /* See if we can figure out if the class lives in a namespace. We do
16443 this by looking for a member function; its demangled name will
16444 contain namespace info, if there is any.
16445 Return the computed name or NULL.
16446 Space for the result is allocated on the objfile's obstack.
16447 This is the full-die version of guess_partial_die_structure_name.
16448 In this case we know DIE has no useful parent. */
16451 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16453 struct die_info
*spec_die
;
16454 struct dwarf2_cu
*spec_cu
;
16455 struct die_info
*child
;
16458 spec_die
= die_specification (die
, &spec_cu
);
16459 if (spec_die
!= NULL
)
16465 for (child
= die
->child
;
16467 child
= child
->sibling
)
16469 if (child
->tag
== DW_TAG_subprogram
)
16471 struct attribute
*attr
;
16473 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
16475 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
16479 = language_class_name_from_physname (cu
->language_defn
,
16483 if (actual_name
!= NULL
)
16485 char *die_name
= dwarf2_name (die
, cu
);
16487 if (die_name
!= NULL
16488 && strcmp (die_name
, actual_name
) != 0)
16490 /* Strip off the class name from the full name.
16491 We want the prefix. */
16492 int die_name_len
= strlen (die_name
);
16493 int actual_name_len
= strlen (actual_name
);
16495 /* Test for '::' as a sanity check. */
16496 if (actual_name_len
> die_name_len
+ 2
16497 && actual_name
[actual_name_len
16498 - die_name_len
- 1] == ':')
16500 obsavestring (actual_name
,
16501 actual_name_len
- die_name_len
- 2,
16502 &cu
->objfile
->objfile_obstack
);
16505 xfree (actual_name
);
16514 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16515 prefix part in such case. See
16516 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16519 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16521 struct attribute
*attr
;
16524 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
16525 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
16528 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16529 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
16532 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16534 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16535 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16538 /* dwarf2_name had to be already called. */
16539 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
16541 /* Strip the base name, keep any leading namespaces/classes. */
16542 base
= strrchr (DW_STRING (attr
), ':');
16543 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
16546 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
16547 &cu
->objfile
->objfile_obstack
);
16550 /* Return the name of the namespace/class that DIE is defined within,
16551 or "" if we can't tell. The caller should not xfree the result.
16553 For example, if we're within the method foo() in the following
16563 then determine_prefix on foo's die will return "N::C". */
16565 static const char *
16566 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16568 struct die_info
*parent
, *spec_die
;
16569 struct dwarf2_cu
*spec_cu
;
16570 struct type
*parent_type
;
16573 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
16574 && cu
->language
!= language_fortran
)
16577 retval
= anonymous_struct_prefix (die
, cu
);
16581 /* We have to be careful in the presence of DW_AT_specification.
16582 For example, with GCC 3.4, given the code
16586 // Definition of N::foo.
16590 then we'll have a tree of DIEs like this:
16592 1: DW_TAG_compile_unit
16593 2: DW_TAG_namespace // N
16594 3: DW_TAG_subprogram // declaration of N::foo
16595 4: DW_TAG_subprogram // definition of N::foo
16596 DW_AT_specification // refers to die #3
16598 Thus, when processing die #4, we have to pretend that we're in
16599 the context of its DW_AT_specification, namely the contex of die
16602 spec_die
= die_specification (die
, &spec_cu
);
16603 if (spec_die
== NULL
)
16604 parent
= die
->parent
;
16607 parent
= spec_die
->parent
;
16611 if (parent
== NULL
)
16613 else if (parent
->building_fullname
)
16616 const char *parent_name
;
16618 /* It has been seen on RealView 2.2 built binaries,
16619 DW_TAG_template_type_param types actually _defined_ as
16620 children of the parent class:
16623 template class <class Enum> Class{};
16624 Class<enum E> class_e;
16626 1: DW_TAG_class_type (Class)
16627 2: DW_TAG_enumeration_type (E)
16628 3: DW_TAG_enumerator (enum1:0)
16629 3: DW_TAG_enumerator (enum2:1)
16631 2: DW_TAG_template_type_param
16632 DW_AT_type DW_FORM_ref_udata (E)
16634 Besides being broken debug info, it can put GDB into an
16635 infinite loop. Consider:
16637 When we're building the full name for Class<E>, we'll start
16638 at Class, and go look over its template type parameters,
16639 finding E. We'll then try to build the full name of E, and
16640 reach here. We're now trying to build the full name of E,
16641 and look over the parent DIE for containing scope. In the
16642 broken case, if we followed the parent DIE of E, we'd again
16643 find Class, and once again go look at its template type
16644 arguments, etc., etc. Simply don't consider such parent die
16645 as source-level parent of this die (it can't be, the language
16646 doesn't allow it), and break the loop here. */
16647 name
= dwarf2_name (die
, cu
);
16648 parent_name
= dwarf2_name (parent
, cu
);
16649 complaint (&symfile_complaints
,
16650 _("template param type '%s' defined within parent '%s'"),
16651 name
? name
: "<unknown>",
16652 parent_name
? parent_name
: "<unknown>");
16656 switch (parent
->tag
)
16658 case DW_TAG_namespace
:
16659 parent_type
= read_type_die (parent
, cu
);
16660 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
16661 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
16662 Work around this problem here. */
16663 if (cu
->language
== language_cplus
16664 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
16666 /* We give a name to even anonymous namespaces. */
16667 return TYPE_TAG_NAME (parent_type
);
16668 case DW_TAG_class_type
:
16669 case DW_TAG_interface_type
:
16670 case DW_TAG_structure_type
:
16671 case DW_TAG_union_type
:
16672 case DW_TAG_module
:
16673 parent_type
= read_type_die (parent
, cu
);
16674 if (TYPE_TAG_NAME (parent_type
) != NULL
)
16675 return TYPE_TAG_NAME (parent_type
);
16677 /* An anonymous structure is only allowed non-static data
16678 members; no typedefs, no member functions, et cetera.
16679 So it does not need a prefix. */
16681 case DW_TAG_compile_unit
:
16682 case DW_TAG_partial_unit
:
16683 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
16684 if (cu
->language
== language_cplus
16685 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16686 && die
->child
!= NULL
16687 && (die
->tag
== DW_TAG_class_type
16688 || die
->tag
== DW_TAG_structure_type
16689 || die
->tag
== DW_TAG_union_type
))
16691 char *name
= guess_full_die_structure_name (die
, cu
);
16697 return determine_prefix (parent
, cu
);
16701 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
16702 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
16703 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
16704 an obconcat, otherwise allocate storage for the result. The CU argument is
16705 used to determine the language and hence, the appropriate separator. */
16707 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
16710 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
16711 int physname
, struct dwarf2_cu
*cu
)
16713 const char *lead
= "";
16716 if (suffix
== NULL
|| suffix
[0] == '\0'
16717 || prefix
== NULL
|| prefix
[0] == '\0')
16719 else if (cu
->language
== language_java
)
16721 else if (cu
->language
== language_fortran
&& physname
)
16723 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
16724 DW_AT_MIPS_linkage_name is preferred and used instead. */
16732 if (prefix
== NULL
)
16734 if (suffix
== NULL
)
16740 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
16742 strcpy (retval
, lead
);
16743 strcat (retval
, prefix
);
16744 strcat (retval
, sep
);
16745 strcat (retval
, suffix
);
16750 /* We have an obstack. */
16751 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
16755 /* Return sibling of die, NULL if no sibling. */
16757 static struct die_info
*
16758 sibling_die (struct die_info
*die
)
16760 return die
->sibling
;
16763 /* Get name of a die, return NULL if not found. */
16766 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
16767 struct obstack
*obstack
)
16769 if (name
&& cu
->language
== language_cplus
)
16771 char *canon_name
= cp_canonicalize_string (name
);
16773 if (canon_name
!= NULL
)
16775 if (strcmp (canon_name
, name
) != 0)
16776 name
= obsavestring (canon_name
, strlen (canon_name
),
16778 xfree (canon_name
);
16785 /* Get name of a die, return NULL if not found. */
16788 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16790 struct attribute
*attr
;
16792 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16793 if ((!attr
|| !DW_STRING (attr
))
16794 && die
->tag
!= DW_TAG_class_type
16795 && die
->tag
!= DW_TAG_interface_type
16796 && die
->tag
!= DW_TAG_structure_type
16797 && die
->tag
!= DW_TAG_union_type
)
16802 case DW_TAG_compile_unit
:
16803 case DW_TAG_partial_unit
:
16804 /* Compilation units have a DW_AT_name that is a filename, not
16805 a source language identifier. */
16806 case DW_TAG_enumeration_type
:
16807 case DW_TAG_enumerator
:
16808 /* These tags always have simple identifiers already; no need
16809 to canonicalize them. */
16810 return DW_STRING (attr
);
16812 case DW_TAG_subprogram
:
16813 /* Java constructors will all be named "<init>", so return
16814 the class name when we see this special case. */
16815 if (cu
->language
== language_java
16816 && DW_STRING (attr
) != NULL
16817 && strcmp (DW_STRING (attr
), "<init>") == 0)
16819 struct dwarf2_cu
*spec_cu
= cu
;
16820 struct die_info
*spec_die
;
16822 /* GCJ will output '<init>' for Java constructor names.
16823 For this special case, return the name of the parent class. */
16825 /* GCJ may output suprogram DIEs with AT_specification set.
16826 If so, use the name of the specified DIE. */
16827 spec_die
= die_specification (die
, &spec_cu
);
16828 if (spec_die
!= NULL
)
16829 return dwarf2_name (spec_die
, spec_cu
);
16834 if (die
->tag
== DW_TAG_class_type
)
16835 return dwarf2_name (die
, cu
);
16837 while (die
->tag
!= DW_TAG_compile_unit
16838 && die
->tag
!= DW_TAG_partial_unit
);
16842 case DW_TAG_class_type
:
16843 case DW_TAG_interface_type
:
16844 case DW_TAG_structure_type
:
16845 case DW_TAG_union_type
:
16846 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
16847 structures or unions. These were of the form "._%d" in GCC 4.1,
16848 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
16849 and GCC 4.4. We work around this problem by ignoring these. */
16850 if (attr
&& DW_STRING (attr
)
16851 && (strncmp (DW_STRING (attr
), "._", 2) == 0
16852 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
16855 /* GCC might emit a nameless typedef that has a linkage name. See
16856 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16857 if (!attr
|| DW_STRING (attr
) == NULL
)
16859 char *demangled
= NULL
;
16861 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16863 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16865 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16868 /* Avoid demangling DW_STRING (attr) the second time on a second
16869 call for the same DIE. */
16870 if (!DW_STRING_IS_CANONICAL (attr
))
16871 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
16877 /* FIXME: we already did this for the partial symbol... */
16878 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
16879 &cu
->objfile
->objfile_obstack
);
16880 DW_STRING_IS_CANONICAL (attr
) = 1;
16883 /* Strip any leading namespaces/classes, keep only the base name.
16884 DW_AT_name for named DIEs does not contain the prefixes. */
16885 base
= strrchr (DW_STRING (attr
), ':');
16886 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
16889 return DW_STRING (attr
);
16898 if (!DW_STRING_IS_CANONICAL (attr
))
16901 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
16902 &cu
->objfile
->objfile_obstack
);
16903 DW_STRING_IS_CANONICAL (attr
) = 1;
16905 return DW_STRING (attr
);
16908 /* Return the die that this die in an extension of, or NULL if there
16909 is none. *EXT_CU is the CU containing DIE on input, and the CU
16910 containing the return value on output. */
16912 static struct die_info
*
16913 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
16915 struct attribute
*attr
;
16917 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
16921 return follow_die_ref (die
, attr
, ext_cu
);
16924 /* Convert a DIE tag into its string name. */
16926 static const char *
16927 dwarf_tag_name (unsigned tag
)
16929 const char *name
= get_DW_TAG_name (tag
);
16932 return "DW_TAG_<unknown>";
16937 /* Convert a DWARF attribute code into its string name. */
16939 static const char *
16940 dwarf_attr_name (unsigned attr
)
16944 #ifdef MIPS /* collides with DW_AT_HP_block_index */
16945 if (attr
== DW_AT_MIPS_fde
)
16946 return "DW_AT_MIPS_fde";
16948 if (attr
== DW_AT_HP_block_index
)
16949 return "DW_AT_HP_block_index";
16952 name
= get_DW_AT_name (attr
);
16955 return "DW_AT_<unknown>";
16960 /* Convert a DWARF value form code into its string name. */
16962 static const char *
16963 dwarf_form_name (unsigned form
)
16965 const char *name
= get_DW_FORM_name (form
);
16968 return "DW_FORM_<unknown>";
16974 dwarf_bool_name (unsigned mybool
)
16982 /* Convert a DWARF type code into its string name. */
16984 static const char *
16985 dwarf_type_encoding_name (unsigned enc
)
16987 const char *name
= get_DW_ATE_name (enc
);
16990 return "DW_ATE_<unknown>";
16996 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
17000 print_spaces (indent
, f
);
17001 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
17002 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
17004 if (die
->parent
!= NULL
)
17006 print_spaces (indent
, f
);
17007 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
17008 die
->parent
->offset
.sect_off
);
17011 print_spaces (indent
, f
);
17012 fprintf_unfiltered (f
, " has children: %s\n",
17013 dwarf_bool_name (die
->child
!= NULL
));
17015 print_spaces (indent
, f
);
17016 fprintf_unfiltered (f
, " attributes:\n");
17018 for (i
= 0; i
< die
->num_attrs
; ++i
)
17020 print_spaces (indent
, f
);
17021 fprintf_unfiltered (f
, " %s (%s) ",
17022 dwarf_attr_name (die
->attrs
[i
].name
),
17023 dwarf_form_name (die
->attrs
[i
].form
));
17025 switch (die
->attrs
[i
].form
)
17028 case DW_FORM_GNU_addr_index
:
17029 fprintf_unfiltered (f
, "address: ");
17030 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
17032 case DW_FORM_block2
:
17033 case DW_FORM_block4
:
17034 case DW_FORM_block
:
17035 case DW_FORM_block1
:
17036 fprintf_unfiltered (f
, "block: size %s",
17037 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17039 case DW_FORM_exprloc
:
17040 fprintf_unfiltered (f
, "expression: size %s",
17041 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17043 case DW_FORM_ref_addr
:
17044 fprintf_unfiltered (f
, "ref address: ");
17045 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17047 case DW_FORM_GNU_ref_alt
:
17048 fprintf_unfiltered (f
, "alt ref address: ");
17049 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17055 case DW_FORM_ref_udata
:
17056 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
17057 (long) (DW_UNSND (&die
->attrs
[i
])));
17059 case DW_FORM_data1
:
17060 case DW_FORM_data2
:
17061 case DW_FORM_data4
:
17062 case DW_FORM_data8
:
17063 case DW_FORM_udata
:
17064 case DW_FORM_sdata
:
17065 fprintf_unfiltered (f
, "constant: %s",
17066 pulongest (DW_UNSND (&die
->attrs
[i
])));
17068 case DW_FORM_sec_offset
:
17069 fprintf_unfiltered (f
, "section offset: %s",
17070 pulongest (DW_UNSND (&die
->attrs
[i
])));
17072 case DW_FORM_ref_sig8
:
17073 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
17074 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
17075 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
17077 fprintf_unfiltered (f
, "signatured type, offset: unknown");
17079 case DW_FORM_string
:
17081 case DW_FORM_GNU_str_index
:
17082 case DW_FORM_GNU_strp_alt
:
17083 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
17084 DW_STRING (&die
->attrs
[i
])
17085 ? DW_STRING (&die
->attrs
[i
]) : "",
17086 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
17089 if (DW_UNSND (&die
->attrs
[i
]))
17090 fprintf_unfiltered (f
, "flag: TRUE");
17092 fprintf_unfiltered (f
, "flag: FALSE");
17094 case DW_FORM_flag_present
:
17095 fprintf_unfiltered (f
, "flag: TRUE");
17097 case DW_FORM_indirect
:
17098 /* The reader will have reduced the indirect form to
17099 the "base form" so this form should not occur. */
17100 fprintf_unfiltered (f
,
17101 "unexpected attribute form: DW_FORM_indirect");
17104 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
17105 die
->attrs
[i
].form
);
17108 fprintf_unfiltered (f
, "\n");
17113 dump_die_for_error (struct die_info
*die
)
17115 dump_die_shallow (gdb_stderr
, 0, die
);
17119 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
17121 int indent
= level
* 4;
17123 gdb_assert (die
!= NULL
);
17125 if (level
>= max_level
)
17128 dump_die_shallow (f
, indent
, die
);
17130 if (die
->child
!= NULL
)
17132 print_spaces (indent
, f
);
17133 fprintf_unfiltered (f
, " Children:");
17134 if (level
+ 1 < max_level
)
17136 fprintf_unfiltered (f
, "\n");
17137 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
17141 fprintf_unfiltered (f
,
17142 " [not printed, max nesting level reached]\n");
17146 if (die
->sibling
!= NULL
&& level
> 0)
17148 dump_die_1 (f
, level
, max_level
, die
->sibling
);
17152 /* This is called from the pdie macro in gdbinit.in.
17153 It's not static so gcc will keep a copy callable from gdb. */
17156 dump_die (struct die_info
*die
, int max_level
)
17158 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
17162 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
17166 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
17172 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17173 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17176 is_ref_attr (struct attribute
*attr
)
17178 switch (attr
->form
)
17180 case DW_FORM_ref_addr
:
17185 case DW_FORM_ref_udata
:
17186 case DW_FORM_GNU_ref_alt
:
17193 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17197 dwarf2_get_ref_die_offset (struct attribute
*attr
)
17199 sect_offset retval
= { DW_UNSND (attr
) };
17201 if (is_ref_attr (attr
))
17204 retval
.sect_off
= 0;
17205 complaint (&symfile_complaints
,
17206 _("unsupported die ref attribute form: '%s'"),
17207 dwarf_form_name (attr
->form
));
17211 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17212 * the value held by the attribute is not constant. */
17215 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
17217 if (attr
->form
== DW_FORM_sdata
)
17218 return DW_SND (attr
);
17219 else if (attr
->form
== DW_FORM_udata
17220 || attr
->form
== DW_FORM_data1
17221 || attr
->form
== DW_FORM_data2
17222 || attr
->form
== DW_FORM_data4
17223 || attr
->form
== DW_FORM_data8
)
17224 return DW_UNSND (attr
);
17227 complaint (&symfile_complaints
,
17228 _("Attribute value is not a constant (%s)"),
17229 dwarf_form_name (attr
->form
));
17230 return default_value
;
17234 /* Follow reference or signature attribute ATTR of SRC_DIE.
17235 On entry *REF_CU is the CU of SRC_DIE.
17236 On exit *REF_CU is the CU of the result. */
17238 static struct die_info
*
17239 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
17240 struct dwarf2_cu
**ref_cu
)
17242 struct die_info
*die
;
17244 if (is_ref_attr (attr
))
17245 die
= follow_die_ref (src_die
, attr
, ref_cu
);
17246 else if (attr
->form
== DW_FORM_ref_sig8
)
17247 die
= follow_die_sig (src_die
, attr
, ref_cu
);
17250 dump_die_for_error (src_die
);
17251 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17252 (*ref_cu
)->objfile
->name
);
17258 /* Follow reference OFFSET.
17259 On entry *REF_CU is the CU of the source die referencing OFFSET.
17260 On exit *REF_CU is the CU of the result.
17261 Returns NULL if OFFSET is invalid. */
17263 static struct die_info
*
17264 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
17265 struct dwarf2_cu
**ref_cu
)
17267 struct die_info temp_die
;
17268 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
17270 gdb_assert (cu
->per_cu
!= NULL
);
17274 if (cu
->per_cu
->is_debug_types
)
17276 /* .debug_types CUs cannot reference anything outside their CU.
17277 If they need to, they have to reference a signatured type via
17278 DW_FORM_ref_sig8. */
17279 if (! offset_in_cu_p (&cu
->header
, offset
))
17282 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
17283 || ! offset_in_cu_p (&cu
->header
, offset
))
17285 struct dwarf2_per_cu_data
*per_cu
;
17287 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
17290 /* If necessary, add it to the queue and load its DIEs. */
17291 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
17292 load_full_comp_unit (per_cu
, cu
->language
);
17294 target_cu
= per_cu
->cu
;
17296 else if (cu
->dies
== NULL
)
17298 /* We're loading full DIEs during partial symbol reading. */
17299 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
17300 load_full_comp_unit (cu
->per_cu
, language_minimal
);
17303 *ref_cu
= target_cu
;
17304 temp_die
.offset
= offset
;
17305 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
17308 /* Follow reference attribute ATTR of SRC_DIE.
17309 On entry *REF_CU is the CU of SRC_DIE.
17310 On exit *REF_CU is the CU of the result. */
17312 static struct die_info
*
17313 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
17314 struct dwarf2_cu
**ref_cu
)
17316 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17317 struct dwarf2_cu
*cu
= *ref_cu
;
17318 struct die_info
*die
;
17320 die
= follow_die_offset (offset
,
17321 (attr
->form
== DW_FORM_GNU_ref_alt
17322 || cu
->per_cu
->is_dwz
),
17325 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17326 "at 0x%x [in module %s]"),
17327 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
17332 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17333 Returned value is intended for DW_OP_call*. Returned
17334 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17336 struct dwarf2_locexpr_baton
17337 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
17338 struct dwarf2_per_cu_data
*per_cu
,
17339 CORE_ADDR (*get_frame_pc
) (void *baton
),
17342 struct dwarf2_cu
*cu
;
17343 struct die_info
*die
;
17344 struct attribute
*attr
;
17345 struct dwarf2_locexpr_baton retval
;
17347 dw2_setup (per_cu
->objfile
);
17349 if (per_cu
->cu
== NULL
)
17353 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
17355 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17356 offset
.sect_off
, per_cu
->objfile
->name
);
17358 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17361 /* DWARF: "If there is no such attribute, then there is no effect.".
17362 DATA is ignored if SIZE is 0. */
17364 retval
.data
= NULL
;
17367 else if (attr_form_is_section_offset (attr
))
17369 struct dwarf2_loclist_baton loclist_baton
;
17370 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
17373 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
17375 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
17377 retval
.size
= size
;
17381 if (!attr_form_is_block (attr
))
17382 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17383 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17384 offset
.sect_off
, per_cu
->objfile
->name
);
17386 retval
.data
= DW_BLOCK (attr
)->data
;
17387 retval
.size
= DW_BLOCK (attr
)->size
;
17389 retval
.per_cu
= cu
->per_cu
;
17391 age_cached_comp_units ();
17396 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
17399 struct dwarf2_locexpr_baton
17400 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
17401 struct dwarf2_per_cu_data
*per_cu
,
17402 CORE_ADDR (*get_frame_pc
) (void *baton
),
17405 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
17407 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
17410 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17414 dwarf2_get_die_type (cu_offset die_offset
,
17415 struct dwarf2_per_cu_data
*per_cu
)
17417 sect_offset die_offset_sect
;
17419 dw2_setup (per_cu
->objfile
);
17421 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
17422 return get_die_type_at_offset (die_offset_sect
, per_cu
);
17425 /* Follow the signature attribute ATTR in SRC_DIE.
17426 On entry *REF_CU is the CU of SRC_DIE.
17427 On exit *REF_CU is the CU of the result. */
17429 static struct die_info
*
17430 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
17431 struct dwarf2_cu
**ref_cu
)
17433 struct objfile
*objfile
= (*ref_cu
)->objfile
;
17434 struct die_info temp_die
;
17435 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
17436 struct dwarf2_cu
*sig_cu
;
17437 struct die_info
*die
;
17439 /* sig_type will be NULL if the signatured type is missing from
17441 if (sig_type
== NULL
)
17442 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
17443 "at 0x%x [in module %s]"),
17444 src_die
->offset
.sect_off
, objfile
->name
);
17446 /* If necessary, add it to the queue and load its DIEs. */
17448 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
17449 read_signatured_type (sig_type
);
17451 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
17453 sig_cu
= sig_type
->per_cu
.cu
;
17454 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
17455 temp_die
.offset
= sig_type
->type_offset_in_section
;
17456 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
17457 temp_die
.offset
.sect_off
);
17464 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
17465 "from DIE at 0x%x [in module %s]"),
17466 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
17469 /* Given an offset of a signatured type, return its signatured_type. */
17471 static struct signatured_type
*
17472 lookup_signatured_type_at_offset (struct objfile
*objfile
,
17473 struct dwarf2_section_info
*section
,
17474 sect_offset offset
)
17476 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
17477 unsigned int length
, initial_length_size
;
17478 unsigned int sig_offset
;
17479 struct signatured_type find_entry
, *sig_type
;
17481 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
17482 sig_offset
= (initial_length_size
17484 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
17485 + 1 /*address_size*/);
17486 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
17487 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
17489 /* This is only used to lookup previously recorded types.
17490 If we didn't find it, it's our bug. */
17491 gdb_assert (sig_type
!= NULL
);
17492 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
17497 /* Load the DIEs associated with type unit PER_CU into memory. */
17500 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
17502 struct signatured_type
*sig_type
;
17504 /* Caller is responsible for ensuring type_unit_groups don't get here. */
17505 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
17507 /* We have the per_cu, but we need the signatured_type.
17508 Fortunately this is an easy translation. */
17509 gdb_assert (per_cu
->is_debug_types
);
17510 sig_type
= (struct signatured_type
*) per_cu
;
17512 gdb_assert (per_cu
->cu
== NULL
);
17514 read_signatured_type (sig_type
);
17516 gdb_assert (per_cu
->cu
!= NULL
);
17519 /* die_reader_func for read_signatured_type.
17520 This is identical to load_full_comp_unit_reader,
17521 but is kept separate for now. */
17524 read_signatured_type_reader (const struct die_reader_specs
*reader
,
17525 gdb_byte
*info_ptr
,
17526 struct die_info
*comp_unit_die
,
17530 struct dwarf2_cu
*cu
= reader
->cu
;
17532 gdb_assert (cu
->die_hash
== NULL
);
17534 htab_create_alloc_ex (cu
->header
.length
/ 12,
17538 &cu
->comp_unit_obstack
,
17539 hashtab_obstack_allocate
,
17540 dummy_obstack_deallocate
);
17543 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
17544 &info_ptr
, comp_unit_die
);
17545 cu
->dies
= comp_unit_die
;
17546 /* comp_unit_die is not stored in die_hash, no need. */
17548 /* We try not to read any attributes in this function, because not
17549 all CUs needed for references have been loaded yet, and symbol
17550 table processing isn't initialized. But we have to set the CU language,
17551 or we won't be able to build types correctly.
17552 Similarly, if we do not read the producer, we can not apply
17553 producer-specific interpretation. */
17554 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
17557 /* Read in a signatured type and build its CU and DIEs.
17558 If the type is a stub for the real type in a DWO file,
17559 read in the real type from the DWO file as well. */
17562 read_signatured_type (struct signatured_type
*sig_type
)
17564 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
17566 gdb_assert (per_cu
->is_debug_types
);
17567 gdb_assert (per_cu
->cu
== NULL
);
17569 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
17570 read_signatured_type_reader
, NULL
);
17573 /* Decode simple location descriptions.
17574 Given a pointer to a dwarf block that defines a location, compute
17575 the location and return the value.
17577 NOTE drow/2003-11-18: This function is called in two situations
17578 now: for the address of static or global variables (partial symbols
17579 only) and for offsets into structures which are expected to be
17580 (more or less) constant. The partial symbol case should go away,
17581 and only the constant case should remain. That will let this
17582 function complain more accurately. A few special modes are allowed
17583 without complaint for global variables (for instance, global
17584 register values and thread-local values).
17586 A location description containing no operations indicates that the
17587 object is optimized out. The return value is 0 for that case.
17588 FIXME drow/2003-11-16: No callers check for this case any more; soon all
17589 callers will only want a very basic result and this can become a
17592 Note that stack[0] is unused except as a default error return. */
17595 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
17597 struct objfile
*objfile
= cu
->objfile
;
17599 size_t size
= blk
->size
;
17600 gdb_byte
*data
= blk
->data
;
17601 CORE_ADDR stack
[64];
17603 unsigned int bytes_read
, unsnd
;
17609 stack
[++stacki
] = 0;
17648 stack
[++stacki
] = op
- DW_OP_lit0
;
17683 stack
[++stacki
] = op
- DW_OP_reg0
;
17685 dwarf2_complex_location_expr_complaint ();
17689 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
17691 stack
[++stacki
] = unsnd
;
17693 dwarf2_complex_location_expr_complaint ();
17697 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
17702 case DW_OP_const1u
:
17703 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
17707 case DW_OP_const1s
:
17708 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
17712 case DW_OP_const2u
:
17713 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
17717 case DW_OP_const2s
:
17718 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
17722 case DW_OP_const4u
:
17723 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
17727 case DW_OP_const4s
:
17728 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
17732 case DW_OP_const8u
:
17733 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
17738 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
17744 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
17749 stack
[stacki
+ 1] = stack
[stacki
];
17754 stack
[stacki
- 1] += stack
[stacki
];
17758 case DW_OP_plus_uconst
:
17759 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
17765 stack
[stacki
- 1] -= stack
[stacki
];
17770 /* If we're not the last op, then we definitely can't encode
17771 this using GDB's address_class enum. This is valid for partial
17772 global symbols, although the variable's address will be bogus
17775 dwarf2_complex_location_expr_complaint ();
17778 case DW_OP_GNU_push_tls_address
:
17779 /* The top of the stack has the offset from the beginning
17780 of the thread control block at which the variable is located. */
17781 /* Nothing should follow this operator, so the top of stack would
17783 /* This is valid for partial global symbols, but the variable's
17784 address will be bogus in the psymtab. Make it always at least
17785 non-zero to not look as a variable garbage collected by linker
17786 which have DW_OP_addr 0. */
17788 dwarf2_complex_location_expr_complaint ();
17792 case DW_OP_GNU_uninit
:
17795 case DW_OP_GNU_addr_index
:
17796 case DW_OP_GNU_const_index
:
17797 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
17804 const char *name
= get_DW_OP_name (op
);
17807 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
17810 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
17814 return (stack
[stacki
]);
17817 /* Enforce maximum stack depth of SIZE-1 to avoid writing
17818 outside of the allocated space. Also enforce minimum>0. */
17819 if (stacki
>= ARRAY_SIZE (stack
) - 1)
17821 complaint (&symfile_complaints
,
17822 _("location description stack overflow"));
17828 complaint (&symfile_complaints
,
17829 _("location description stack underflow"));
17833 return (stack
[stacki
]);
17836 /* memory allocation interface */
17838 static struct dwarf_block
*
17839 dwarf_alloc_block (struct dwarf2_cu
*cu
)
17841 struct dwarf_block
*blk
;
17843 blk
= (struct dwarf_block
*)
17844 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
17848 static struct die_info
*
17849 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
17851 struct die_info
*die
;
17852 size_t size
= sizeof (struct die_info
);
17855 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
17857 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
17858 memset (die
, 0, sizeof (struct die_info
));
17863 /* Macro support. */
17865 /* Return the full name of file number I in *LH's file name table.
17866 Use COMP_DIR as the name of the current directory of the
17867 compilation. The result is allocated using xmalloc; the caller is
17868 responsible for freeing it. */
17870 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
17872 /* Is the file number a valid index into the line header's file name
17873 table? Remember that file numbers start with one, not zero. */
17874 if (1 <= file
&& file
<= lh
->num_file_names
)
17876 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
17878 if (IS_ABSOLUTE_PATH (fe
->name
))
17879 return xstrdup (fe
->name
);
17887 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17893 dir_len
= strlen (dir
);
17894 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
17895 strcpy (full_name
, dir
);
17896 full_name
[dir_len
] = '/';
17897 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
17901 return xstrdup (fe
->name
);
17906 /* The compiler produced a bogus file number. We can at least
17907 record the macro definitions made in the file, even if we
17908 won't be able to find the file by name. */
17909 char fake_name
[80];
17911 xsnprintf (fake_name
, sizeof (fake_name
),
17912 "<bad macro file number %d>", file
);
17914 complaint (&symfile_complaints
,
17915 _("bad file number in macro information (%d)"),
17918 return xstrdup (fake_name
);
17923 static struct macro_source_file
*
17924 macro_start_file (int file
, int line
,
17925 struct macro_source_file
*current_file
,
17926 const char *comp_dir
,
17927 struct line_header
*lh
, struct objfile
*objfile
)
17929 /* The full name of this source file. */
17930 char *full_name
= file_full_name (file
, lh
, comp_dir
);
17932 /* We don't create a macro table for this compilation unit
17933 at all until we actually get a filename. */
17934 if (! pending_macros
)
17935 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
17936 objfile
->per_bfd
->macro_cache
);
17938 if (! current_file
)
17940 /* If we have no current file, then this must be the start_file
17941 directive for the compilation unit's main source file. */
17942 current_file
= macro_set_main (pending_macros
, full_name
);
17943 macro_define_special (pending_macros
);
17946 current_file
= macro_include (current_file
, line
, full_name
);
17950 return current_file
;
17954 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
17955 followed by a null byte. */
17957 copy_string (const char *buf
, int len
)
17959 char *s
= xmalloc (len
+ 1);
17961 memcpy (s
, buf
, len
);
17967 static const char *
17968 consume_improper_spaces (const char *p
, const char *body
)
17972 complaint (&symfile_complaints
,
17973 _("macro definition contains spaces "
17974 "in formal argument list:\n`%s'"),
17986 parse_macro_definition (struct macro_source_file
*file
, int line
,
17991 /* The body string takes one of two forms. For object-like macro
17992 definitions, it should be:
17994 <macro name> " " <definition>
17996 For function-like macro definitions, it should be:
17998 <macro name> "() " <definition>
18000 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
18002 Spaces may appear only where explicitly indicated, and in the
18005 The Dwarf 2 spec says that an object-like macro's name is always
18006 followed by a space, but versions of GCC around March 2002 omit
18007 the space when the macro's definition is the empty string.
18009 The Dwarf 2 spec says that there should be no spaces between the
18010 formal arguments in a function-like macro's formal argument list,
18011 but versions of GCC around March 2002 include spaces after the
18015 /* Find the extent of the macro name. The macro name is terminated
18016 by either a space or null character (for an object-like macro) or
18017 an opening paren (for a function-like macro). */
18018 for (p
= body
; *p
; p
++)
18019 if (*p
== ' ' || *p
== '(')
18022 if (*p
== ' ' || *p
== '\0')
18024 /* It's an object-like macro. */
18025 int name_len
= p
- body
;
18026 char *name
= copy_string (body
, name_len
);
18027 const char *replacement
;
18030 replacement
= body
+ name_len
+ 1;
18033 dwarf2_macro_malformed_definition_complaint (body
);
18034 replacement
= body
+ name_len
;
18037 macro_define_object (file
, line
, name
, replacement
);
18041 else if (*p
== '(')
18043 /* It's a function-like macro. */
18044 char *name
= copy_string (body
, p
- body
);
18047 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
18051 p
= consume_improper_spaces (p
, body
);
18053 /* Parse the formal argument list. */
18054 while (*p
&& *p
!= ')')
18056 /* Find the extent of the current argument name. */
18057 const char *arg_start
= p
;
18059 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
18062 if (! *p
|| p
== arg_start
)
18063 dwarf2_macro_malformed_definition_complaint (body
);
18066 /* Make sure argv has room for the new argument. */
18067 if (argc
>= argv_size
)
18070 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
18073 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
18076 p
= consume_improper_spaces (p
, body
);
18078 /* Consume the comma, if present. */
18083 p
= consume_improper_spaces (p
, body
);
18092 /* Perfectly formed definition, no complaints. */
18093 macro_define_function (file
, line
, name
,
18094 argc
, (const char **) argv
,
18096 else if (*p
== '\0')
18098 /* Complain, but do define it. */
18099 dwarf2_macro_malformed_definition_complaint (body
);
18100 macro_define_function (file
, line
, name
,
18101 argc
, (const char **) argv
,
18105 /* Just complain. */
18106 dwarf2_macro_malformed_definition_complaint (body
);
18109 /* Just complain. */
18110 dwarf2_macro_malformed_definition_complaint (body
);
18116 for (i
= 0; i
< argc
; i
++)
18122 dwarf2_macro_malformed_definition_complaint (body
);
18125 /* Skip some bytes from BYTES according to the form given in FORM.
18126 Returns the new pointer. */
18129 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
18130 enum dwarf_form form
,
18131 unsigned int offset_size
,
18132 struct dwarf2_section_info
*section
)
18134 unsigned int bytes_read
;
18138 case DW_FORM_data1
:
18143 case DW_FORM_data2
:
18147 case DW_FORM_data4
:
18151 case DW_FORM_data8
:
18155 case DW_FORM_string
:
18156 read_direct_string (abfd
, bytes
, &bytes_read
);
18157 bytes
+= bytes_read
;
18160 case DW_FORM_sec_offset
:
18162 case DW_FORM_GNU_strp_alt
:
18163 bytes
+= offset_size
;
18166 case DW_FORM_block
:
18167 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
18168 bytes
+= bytes_read
;
18171 case DW_FORM_block1
:
18172 bytes
+= 1 + read_1_byte (abfd
, bytes
);
18174 case DW_FORM_block2
:
18175 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
18177 case DW_FORM_block4
:
18178 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
18181 case DW_FORM_sdata
:
18182 case DW_FORM_udata
:
18183 case DW_FORM_GNU_addr_index
:
18184 case DW_FORM_GNU_str_index
:
18185 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
18188 dwarf2_section_buffer_overflow_complaint (section
);
18196 complaint (&symfile_complaints
,
18197 _("invalid form 0x%x in `%s'"),
18199 section
->asection
->name
);
18207 /* A helper for dwarf_decode_macros that handles skipping an unknown
18208 opcode. Returns an updated pointer to the macro data buffer; or,
18209 on error, issues a complaint and returns NULL. */
18212 skip_unknown_opcode (unsigned int opcode
,
18213 gdb_byte
**opcode_definitions
,
18214 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18216 unsigned int offset_size
,
18217 struct dwarf2_section_info
*section
)
18219 unsigned int bytes_read
, i
;
18223 if (opcode_definitions
[opcode
] == NULL
)
18225 complaint (&symfile_complaints
,
18226 _("unrecognized DW_MACFINO opcode 0x%x"),
18231 defn
= opcode_definitions
[opcode
];
18232 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
18233 defn
+= bytes_read
;
18235 for (i
= 0; i
< arg
; ++i
)
18237 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
18239 if (mac_ptr
== NULL
)
18241 /* skip_form_bytes already issued the complaint. */
18249 /* A helper function which parses the header of a macro section.
18250 If the macro section is the extended (for now called "GNU") type,
18251 then this updates *OFFSET_SIZE. Returns a pointer to just after
18252 the header, or issues a complaint and returns NULL on error. */
18255 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
18258 unsigned int *offset_size
,
18259 int section_is_gnu
)
18261 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
18263 if (section_is_gnu
)
18265 unsigned int version
, flags
;
18267 version
= read_2_bytes (abfd
, mac_ptr
);
18270 complaint (&symfile_complaints
,
18271 _("unrecognized version `%d' in .debug_macro section"),
18277 flags
= read_1_byte (abfd
, mac_ptr
);
18279 *offset_size
= (flags
& 1) ? 8 : 4;
18281 if ((flags
& 2) != 0)
18282 /* We don't need the line table offset. */
18283 mac_ptr
+= *offset_size
;
18285 /* Vendor opcode descriptions. */
18286 if ((flags
& 4) != 0)
18288 unsigned int i
, count
;
18290 count
= read_1_byte (abfd
, mac_ptr
);
18292 for (i
= 0; i
< count
; ++i
)
18294 unsigned int opcode
, bytes_read
;
18297 opcode
= read_1_byte (abfd
, mac_ptr
);
18299 opcode_definitions
[opcode
] = mac_ptr
;
18300 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18301 mac_ptr
+= bytes_read
;
18310 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18311 including DW_MACRO_GNU_transparent_include. */
18314 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18315 struct macro_source_file
*current_file
,
18316 struct line_header
*lh
, char *comp_dir
,
18317 struct dwarf2_section_info
*section
,
18318 int section_is_gnu
, int section_is_dwz
,
18319 unsigned int offset_size
,
18320 struct objfile
*objfile
,
18321 htab_t include_hash
)
18323 enum dwarf_macro_record_type macinfo_type
;
18324 int at_commandline
;
18325 gdb_byte
*opcode_definitions
[256];
18327 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18328 &offset_size
, section_is_gnu
);
18329 if (mac_ptr
== NULL
)
18331 /* We already issued a complaint. */
18335 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18336 GDB is still reading the definitions from command line. First
18337 DW_MACINFO_start_file will need to be ignored as it was already executed
18338 to create CURRENT_FILE for the main source holding also the command line
18339 definitions. On first met DW_MACINFO_start_file this flag is reset to
18340 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18342 at_commandline
= 1;
18346 /* Do we at least have room for a macinfo type byte? */
18347 if (mac_ptr
>= mac_end
)
18349 dwarf2_section_buffer_overflow_complaint (section
);
18353 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18356 /* Note that we rely on the fact that the corresponding GNU and
18357 DWARF constants are the same. */
18358 switch (macinfo_type
)
18360 /* A zero macinfo type indicates the end of the macro
18365 case DW_MACRO_GNU_define
:
18366 case DW_MACRO_GNU_undef
:
18367 case DW_MACRO_GNU_define_indirect
:
18368 case DW_MACRO_GNU_undef_indirect
:
18369 case DW_MACRO_GNU_define_indirect_alt
:
18370 case DW_MACRO_GNU_undef_indirect_alt
:
18372 unsigned int bytes_read
;
18377 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18378 mac_ptr
+= bytes_read
;
18380 if (macinfo_type
== DW_MACRO_GNU_define
18381 || macinfo_type
== DW_MACRO_GNU_undef
)
18383 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18384 mac_ptr
+= bytes_read
;
18388 LONGEST str_offset
;
18390 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18391 mac_ptr
+= offset_size
;
18393 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
18394 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
18397 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18399 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
18402 body
= read_indirect_string_at_offset (abfd
, str_offset
);
18405 is_define
= (macinfo_type
== DW_MACRO_GNU_define
18406 || macinfo_type
== DW_MACRO_GNU_define_indirect
18407 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
18408 if (! current_file
)
18410 /* DWARF violation as no main source is present. */
18411 complaint (&symfile_complaints
,
18412 _("debug info with no main source gives macro %s "
18414 is_define
? _("definition") : _("undefinition"),
18418 if ((line
== 0 && !at_commandline
)
18419 || (line
!= 0 && at_commandline
))
18420 complaint (&symfile_complaints
,
18421 _("debug info gives %s macro %s with %s line %d: %s"),
18422 at_commandline
? _("command-line") : _("in-file"),
18423 is_define
? _("definition") : _("undefinition"),
18424 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
18427 parse_macro_definition (current_file
, line
, body
);
18430 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
18431 || macinfo_type
== DW_MACRO_GNU_undef_indirect
18432 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
18433 macro_undef (current_file
, line
, body
);
18438 case DW_MACRO_GNU_start_file
:
18440 unsigned int bytes_read
;
18443 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18444 mac_ptr
+= bytes_read
;
18445 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18446 mac_ptr
+= bytes_read
;
18448 if ((line
== 0 && !at_commandline
)
18449 || (line
!= 0 && at_commandline
))
18450 complaint (&symfile_complaints
,
18451 _("debug info gives source %d included "
18452 "from %s at %s line %d"),
18453 file
, at_commandline
? _("command-line") : _("file"),
18454 line
== 0 ? _("zero") : _("non-zero"), line
);
18456 if (at_commandline
)
18458 /* This DW_MACRO_GNU_start_file was executed in the
18460 at_commandline
= 0;
18463 current_file
= macro_start_file (file
, line
,
18464 current_file
, comp_dir
,
18469 case DW_MACRO_GNU_end_file
:
18470 if (! current_file
)
18471 complaint (&symfile_complaints
,
18472 _("macro debug info has an unmatched "
18473 "`close_file' directive"));
18476 current_file
= current_file
->included_by
;
18477 if (! current_file
)
18479 enum dwarf_macro_record_type next_type
;
18481 /* GCC circa March 2002 doesn't produce the zero
18482 type byte marking the end of the compilation
18483 unit. Complain if it's not there, but exit no
18486 /* Do we at least have room for a macinfo type byte? */
18487 if (mac_ptr
>= mac_end
)
18489 dwarf2_section_buffer_overflow_complaint (section
);
18493 /* We don't increment mac_ptr here, so this is just
18495 next_type
= read_1_byte (abfd
, mac_ptr
);
18496 if (next_type
!= 0)
18497 complaint (&symfile_complaints
,
18498 _("no terminating 0-type entry for "
18499 "macros in `.debug_macinfo' section"));
18506 case DW_MACRO_GNU_transparent_include
:
18507 case DW_MACRO_GNU_transparent_include_alt
:
18511 bfd
*include_bfd
= abfd
;
18512 struct dwarf2_section_info
*include_section
= section
;
18513 struct dwarf2_section_info alt_section
;
18514 gdb_byte
*include_mac_end
= mac_end
;
18515 int is_dwz
= section_is_dwz
;
18516 gdb_byte
*new_mac_ptr
;
18518 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18519 mac_ptr
+= offset_size
;
18521 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
18523 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18525 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
18528 include_bfd
= dwz
->macro
.asection
->owner
;
18529 include_section
= &dwz
->macro
;
18530 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
18534 new_mac_ptr
= include_section
->buffer
+ offset
;
18535 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
18539 /* This has actually happened; see
18540 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
18541 complaint (&symfile_complaints
,
18542 _("recursive DW_MACRO_GNU_transparent_include in "
18543 ".debug_macro section"));
18547 *slot
= new_mac_ptr
;
18549 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
18550 include_mac_end
, current_file
,
18552 section
, section_is_gnu
, is_dwz
,
18553 offset_size
, objfile
, include_hash
);
18555 htab_remove_elt (include_hash
, new_mac_ptr
);
18560 case DW_MACINFO_vendor_ext
:
18561 if (!section_is_gnu
)
18563 unsigned int bytes_read
;
18566 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18567 mac_ptr
+= bytes_read
;
18568 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18569 mac_ptr
+= bytes_read
;
18571 /* We don't recognize any vendor extensions. */
18577 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18578 mac_ptr
, mac_end
, abfd
, offset_size
,
18580 if (mac_ptr
== NULL
)
18584 } while (macinfo_type
!= 0);
18588 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
18589 char *comp_dir
, int section_is_gnu
)
18591 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18592 struct line_header
*lh
= cu
->line_header
;
18594 gdb_byte
*mac_ptr
, *mac_end
;
18595 struct macro_source_file
*current_file
= 0;
18596 enum dwarf_macro_record_type macinfo_type
;
18597 unsigned int offset_size
= cu
->header
.offset_size
;
18598 gdb_byte
*opcode_definitions
[256];
18599 struct cleanup
*cleanup
;
18600 htab_t include_hash
;
18602 struct dwarf2_section_info
*section
;
18603 const char *section_name
;
18605 if (cu
->dwo_unit
!= NULL
)
18607 if (section_is_gnu
)
18609 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
18610 section_name
= ".debug_macro.dwo";
18614 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
18615 section_name
= ".debug_macinfo.dwo";
18620 if (section_is_gnu
)
18622 section
= &dwarf2_per_objfile
->macro
;
18623 section_name
= ".debug_macro";
18627 section
= &dwarf2_per_objfile
->macinfo
;
18628 section_name
= ".debug_macinfo";
18632 dwarf2_read_section (objfile
, section
);
18633 if (section
->buffer
== NULL
)
18635 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
18638 abfd
= section
->asection
->owner
;
18640 /* First pass: Find the name of the base filename.
18641 This filename is needed in order to process all macros whose definition
18642 (or undefinition) comes from the command line. These macros are defined
18643 before the first DW_MACINFO_start_file entry, and yet still need to be
18644 associated to the base file.
18646 To determine the base file name, we scan the macro definitions until we
18647 reach the first DW_MACINFO_start_file entry. We then initialize
18648 CURRENT_FILE accordingly so that any macro definition found before the
18649 first DW_MACINFO_start_file can still be associated to the base file. */
18651 mac_ptr
= section
->buffer
+ offset
;
18652 mac_end
= section
->buffer
+ section
->size
;
18654 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18655 &offset_size
, section_is_gnu
);
18656 if (mac_ptr
== NULL
)
18658 /* We already issued a complaint. */
18664 /* Do we at least have room for a macinfo type byte? */
18665 if (mac_ptr
>= mac_end
)
18667 /* Complaint is printed during the second pass as GDB will probably
18668 stop the first pass earlier upon finding
18669 DW_MACINFO_start_file. */
18673 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18676 /* Note that we rely on the fact that the corresponding GNU and
18677 DWARF constants are the same. */
18678 switch (macinfo_type
)
18680 /* A zero macinfo type indicates the end of the macro
18685 case DW_MACRO_GNU_define
:
18686 case DW_MACRO_GNU_undef
:
18687 /* Only skip the data by MAC_PTR. */
18689 unsigned int bytes_read
;
18691 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18692 mac_ptr
+= bytes_read
;
18693 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18694 mac_ptr
+= bytes_read
;
18698 case DW_MACRO_GNU_start_file
:
18700 unsigned int bytes_read
;
18703 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18704 mac_ptr
+= bytes_read
;
18705 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18706 mac_ptr
+= bytes_read
;
18708 current_file
= macro_start_file (file
, line
, current_file
,
18709 comp_dir
, lh
, objfile
);
18713 case DW_MACRO_GNU_end_file
:
18714 /* No data to skip by MAC_PTR. */
18717 case DW_MACRO_GNU_define_indirect
:
18718 case DW_MACRO_GNU_undef_indirect
:
18719 case DW_MACRO_GNU_define_indirect_alt
:
18720 case DW_MACRO_GNU_undef_indirect_alt
:
18722 unsigned int bytes_read
;
18724 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18725 mac_ptr
+= bytes_read
;
18726 mac_ptr
+= offset_size
;
18730 case DW_MACRO_GNU_transparent_include
:
18731 case DW_MACRO_GNU_transparent_include_alt
:
18732 /* Note that, according to the spec, a transparent include
18733 chain cannot call DW_MACRO_GNU_start_file. So, we can just
18734 skip this opcode. */
18735 mac_ptr
+= offset_size
;
18738 case DW_MACINFO_vendor_ext
:
18739 /* Only skip the data by MAC_PTR. */
18740 if (!section_is_gnu
)
18742 unsigned int bytes_read
;
18744 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18745 mac_ptr
+= bytes_read
;
18746 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18747 mac_ptr
+= bytes_read
;
18752 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18753 mac_ptr
, mac_end
, abfd
, offset_size
,
18755 if (mac_ptr
== NULL
)
18759 } while (macinfo_type
!= 0 && current_file
== NULL
);
18761 /* Second pass: Process all entries.
18763 Use the AT_COMMAND_LINE flag to determine whether we are still processing
18764 command-line macro definitions/undefinitions. This flag is unset when we
18765 reach the first DW_MACINFO_start_file entry. */
18767 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
18768 NULL
, xcalloc
, xfree
);
18769 cleanup
= make_cleanup_htab_delete (include_hash
);
18770 mac_ptr
= section
->buffer
+ offset
;
18771 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
18773 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
18774 current_file
, lh
, comp_dir
, section
,
18776 offset_size
, objfile
, include_hash
);
18777 do_cleanups (cleanup
);
18780 /* Check if the attribute's form is a DW_FORM_block*
18781 if so return true else false. */
18784 attr_form_is_block (struct attribute
*attr
)
18786 return (attr
== NULL
? 0 :
18787 attr
->form
== DW_FORM_block1
18788 || attr
->form
== DW_FORM_block2
18789 || attr
->form
== DW_FORM_block4
18790 || attr
->form
== DW_FORM_block
18791 || attr
->form
== DW_FORM_exprloc
);
18794 /* Return non-zero if ATTR's value is a section offset --- classes
18795 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
18796 You may use DW_UNSND (attr) to retrieve such offsets.
18798 Section 7.5.4, "Attribute Encodings", explains that no attribute
18799 may have a value that belongs to more than one of these classes; it
18800 would be ambiguous if we did, because we use the same forms for all
18804 attr_form_is_section_offset (struct attribute
*attr
)
18806 return (attr
->form
== DW_FORM_data4
18807 || attr
->form
== DW_FORM_data8
18808 || attr
->form
== DW_FORM_sec_offset
);
18811 /* Return non-zero if ATTR's value falls in the 'constant' class, or
18812 zero otherwise. When this function returns true, you can apply
18813 dwarf2_get_attr_constant_value to it.
18815 However, note that for some attributes you must check
18816 attr_form_is_section_offset before using this test. DW_FORM_data4
18817 and DW_FORM_data8 are members of both the constant class, and of
18818 the classes that contain offsets into other debug sections
18819 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
18820 that, if an attribute's can be either a constant or one of the
18821 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
18822 taken as section offsets, not constants. */
18825 attr_form_is_constant (struct attribute
*attr
)
18827 switch (attr
->form
)
18829 case DW_FORM_sdata
:
18830 case DW_FORM_udata
:
18831 case DW_FORM_data1
:
18832 case DW_FORM_data2
:
18833 case DW_FORM_data4
:
18834 case DW_FORM_data8
:
18841 /* Return the .debug_loc section to use for CU.
18842 For DWO files use .debug_loc.dwo. */
18844 static struct dwarf2_section_info
*
18845 cu_debug_loc_section (struct dwarf2_cu
*cu
)
18848 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
18849 return &dwarf2_per_objfile
->loc
;
18852 /* A helper function that fills in a dwarf2_loclist_baton. */
18855 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
18856 struct dwarf2_loclist_baton
*baton
,
18857 struct attribute
*attr
)
18859 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18861 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
18863 baton
->per_cu
= cu
->per_cu
;
18864 gdb_assert (baton
->per_cu
);
18865 /* We don't know how long the location list is, but make sure we
18866 don't run off the edge of the section. */
18867 baton
->size
= section
->size
- DW_UNSND (attr
);
18868 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
18869 baton
->base_address
= cu
->base_address
;
18870 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
18874 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
18875 struct dwarf2_cu
*cu
)
18877 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18878 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18880 if (attr_form_is_section_offset (attr
)
18881 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
18882 the section. If so, fall through to the complaint in the
18884 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
18886 struct dwarf2_loclist_baton
*baton
;
18888 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18889 sizeof (struct dwarf2_loclist_baton
));
18891 fill_in_loclist_baton (cu
, baton
, attr
);
18893 if (cu
->base_known
== 0)
18894 complaint (&symfile_complaints
,
18895 _("Location list used without "
18896 "specifying the CU base address."));
18898 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
18899 SYMBOL_LOCATION_BATON (sym
) = baton
;
18903 struct dwarf2_locexpr_baton
*baton
;
18905 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18906 sizeof (struct dwarf2_locexpr_baton
));
18907 baton
->per_cu
= cu
->per_cu
;
18908 gdb_assert (baton
->per_cu
);
18910 if (attr_form_is_block (attr
))
18912 /* Note that we're just copying the block's data pointer
18913 here, not the actual data. We're still pointing into the
18914 info_buffer for SYM's objfile; right now we never release
18915 that buffer, but when we do clean up properly this may
18917 baton
->size
= DW_BLOCK (attr
)->size
;
18918 baton
->data
= DW_BLOCK (attr
)->data
;
18922 dwarf2_invalid_attrib_class_complaint ("location description",
18923 SYMBOL_NATURAL_NAME (sym
));
18927 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
18928 SYMBOL_LOCATION_BATON (sym
) = baton
;
18932 /* Return the OBJFILE associated with the compilation unit CU. If CU
18933 came from a separate debuginfo file, then the master objfile is
18937 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
18939 struct objfile
*objfile
= per_cu
->objfile
;
18941 /* Return the master objfile, so that we can report and look up the
18942 correct file containing this variable. */
18943 if (objfile
->separate_debug_objfile_backlink
)
18944 objfile
= objfile
->separate_debug_objfile_backlink
;
18949 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
18950 (CU_HEADERP is unused in such case) or prepare a temporary copy at
18951 CU_HEADERP first. */
18953 static const struct comp_unit_head
*
18954 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
18955 struct dwarf2_per_cu_data
*per_cu
)
18957 gdb_byte
*info_ptr
;
18960 return &per_cu
->cu
->header
;
18962 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
18964 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
18965 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
18970 /* Return the address size given in the compilation unit header for CU. */
18973 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
18975 struct comp_unit_head cu_header_local
;
18976 const struct comp_unit_head
*cu_headerp
;
18978 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18980 return cu_headerp
->addr_size
;
18983 /* Return the offset size given in the compilation unit header for CU. */
18986 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
18988 struct comp_unit_head cu_header_local
;
18989 const struct comp_unit_head
*cu_headerp
;
18991 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18993 return cu_headerp
->offset_size
;
18996 /* See its dwarf2loc.h declaration. */
18999 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19001 struct comp_unit_head cu_header_local
;
19002 const struct comp_unit_head
*cu_headerp
;
19004 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19006 if (cu_headerp
->version
== 2)
19007 return cu_headerp
->addr_size
;
19009 return cu_headerp
->offset_size
;
19012 /* Return the text offset of the CU. The returned offset comes from
19013 this CU's objfile. If this objfile came from a separate debuginfo
19014 file, then the offset may be different from the corresponding
19015 offset in the parent objfile. */
19018 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
19020 struct objfile
*objfile
= per_cu
->objfile
;
19022 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19025 /* Locate the .debug_info compilation unit from CU's objfile which contains
19026 the DIE at OFFSET. Raises an error on failure. */
19028 static struct dwarf2_per_cu_data
*
19029 dwarf2_find_containing_comp_unit (sect_offset offset
,
19030 unsigned int offset_in_dwz
,
19031 struct objfile
*objfile
)
19033 struct dwarf2_per_cu_data
*this_cu
;
19035 const sect_offset
*cu_off
;
19038 high
= dwarf2_per_objfile
->n_comp_units
- 1;
19041 struct dwarf2_per_cu_data
*mid_cu
;
19042 int mid
= low
+ (high
- low
) / 2;
19044 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
19045 cu_off
= &mid_cu
->offset
;
19046 if (mid_cu
->is_dwz
> offset_in_dwz
19047 || (mid_cu
->is_dwz
== offset_in_dwz
19048 && cu_off
->sect_off
>= offset
.sect_off
))
19053 gdb_assert (low
== high
);
19054 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19055 cu_off
= &this_cu
->offset
;
19056 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
19058 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
19059 error (_("Dwarf Error: could not find partial DIE containing "
19060 "offset 0x%lx [in module %s]"),
19061 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
19063 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
19064 <= offset
.sect_off
);
19065 return dwarf2_per_objfile
->all_comp_units
[low
-1];
19069 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19070 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
19071 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
19072 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
19073 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
19078 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19081 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
19083 memset (cu
, 0, sizeof (*cu
));
19085 cu
->per_cu
= per_cu
;
19086 cu
->objfile
= per_cu
->objfile
;
19087 obstack_init (&cu
->comp_unit_obstack
);
19090 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19093 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
19094 enum language pretend_language
)
19096 struct attribute
*attr
;
19098 /* Set the language we're debugging. */
19099 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
19101 set_cu_language (DW_UNSND (attr
), cu
);
19104 cu
->language
= pretend_language
;
19105 cu
->language_defn
= language_def (cu
->language
);
19108 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
19110 cu
->producer
= DW_STRING (attr
);
19113 /* Release one cached compilation unit, CU. We unlink it from the tree
19114 of compilation units, but we don't remove it from the read_in_chain;
19115 the caller is responsible for that.
19116 NOTE: DATA is a void * because this function is also used as a
19117 cleanup routine. */
19120 free_heap_comp_unit (void *data
)
19122 struct dwarf2_cu
*cu
= data
;
19124 gdb_assert (cu
->per_cu
!= NULL
);
19125 cu
->per_cu
->cu
= NULL
;
19128 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19133 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19134 when we're finished with it. We can't free the pointer itself, but be
19135 sure to unlink it from the cache. Also release any associated storage. */
19138 free_stack_comp_unit (void *data
)
19140 struct dwarf2_cu
*cu
= data
;
19142 gdb_assert (cu
->per_cu
!= NULL
);
19143 cu
->per_cu
->cu
= NULL
;
19146 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19147 cu
->partial_dies
= NULL
;
19150 /* Free all cached compilation units. */
19153 free_cached_comp_units (void *data
)
19155 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19157 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19158 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19159 while (per_cu
!= NULL
)
19161 struct dwarf2_per_cu_data
*next_cu
;
19163 next_cu
= per_cu
->cu
->read_in_chain
;
19165 free_heap_comp_unit (per_cu
->cu
);
19166 *last_chain
= next_cu
;
19172 /* Increase the age counter on each cached compilation unit, and free
19173 any that are too old. */
19176 age_cached_comp_units (void)
19178 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19180 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
19181 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19182 while (per_cu
!= NULL
)
19184 per_cu
->cu
->last_used
++;
19185 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
19186 dwarf2_mark (per_cu
->cu
);
19187 per_cu
= per_cu
->cu
->read_in_chain
;
19190 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19191 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19192 while (per_cu
!= NULL
)
19194 struct dwarf2_per_cu_data
*next_cu
;
19196 next_cu
= per_cu
->cu
->read_in_chain
;
19198 if (!per_cu
->cu
->mark
)
19200 free_heap_comp_unit (per_cu
->cu
);
19201 *last_chain
= next_cu
;
19204 last_chain
= &per_cu
->cu
->read_in_chain
;
19210 /* Remove a single compilation unit from the cache. */
19213 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
19215 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19217 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19218 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19219 while (per_cu
!= NULL
)
19221 struct dwarf2_per_cu_data
*next_cu
;
19223 next_cu
= per_cu
->cu
->read_in_chain
;
19225 if (per_cu
== target_per_cu
)
19227 free_heap_comp_unit (per_cu
->cu
);
19229 *last_chain
= next_cu
;
19233 last_chain
= &per_cu
->cu
->read_in_chain
;
19239 /* Release all extra memory associated with OBJFILE. */
19242 dwarf2_free_objfile (struct objfile
*objfile
)
19244 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19246 if (dwarf2_per_objfile
== NULL
)
19249 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19250 free_cached_comp_units (NULL
);
19252 if (dwarf2_per_objfile
->quick_file_names_table
)
19253 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
19255 /* Everything else should be on the objfile obstack. */
19258 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19259 We store these in a hash table separate from the DIEs, and preserve them
19260 when the DIEs are flushed out of cache.
19262 The CU "per_cu" pointer is needed because offset alone is not enough to
19263 uniquely identify the type. A file may have multiple .debug_types sections,
19264 or the type may come from a DWO file. We have to use something in
19265 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
19266 routine, get_die_type_at_offset, from outside this file, and thus won't
19267 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
19270 struct dwarf2_per_cu_offset_and_type
19272 const struct dwarf2_per_cu_data
*per_cu
;
19273 sect_offset offset
;
19277 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19280 per_cu_offset_and_type_hash (const void *item
)
19282 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
19284 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
19287 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19290 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
19292 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
19293 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
19295 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
19296 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
19299 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19300 table if necessary. For convenience, return TYPE.
19302 The DIEs reading must have careful ordering to:
19303 * Not cause infite loops trying to read in DIEs as a prerequisite for
19304 reading current DIE.
19305 * Not trying to dereference contents of still incompletely read in types
19306 while reading in other DIEs.
19307 * Enable referencing still incompletely read in types just by a pointer to
19308 the type without accessing its fields.
19310 Therefore caller should follow these rules:
19311 * Try to fetch any prerequisite types we may need to build this DIE type
19312 before building the type and calling set_die_type.
19313 * After building type call set_die_type for current DIE as soon as
19314 possible before fetching more types to complete the current type.
19315 * Make the type as complete as possible before fetching more types. */
19317 static struct type
*
19318 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19320 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
19321 struct objfile
*objfile
= cu
->objfile
;
19323 /* For Ada types, make sure that the gnat-specific data is always
19324 initialized (if not already set). There are a few types where
19325 we should not be doing so, because the type-specific area is
19326 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19327 where the type-specific area is used to store the floatformat).
19328 But this is not a problem, because the gnat-specific information
19329 is actually not needed for these types. */
19330 if (need_gnat_info (cu
)
19331 && TYPE_CODE (type
) != TYPE_CODE_FUNC
19332 && TYPE_CODE (type
) != TYPE_CODE_FLT
19333 && !HAVE_GNAT_AUX_INFO (type
))
19334 INIT_GNAT_SPECIFIC (type
);
19336 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19338 dwarf2_per_objfile
->die_type_hash
=
19339 htab_create_alloc_ex (127,
19340 per_cu_offset_and_type_hash
,
19341 per_cu_offset_and_type_eq
,
19343 &objfile
->objfile_obstack
,
19344 hashtab_obstack_allocate
,
19345 dummy_obstack_deallocate
);
19348 ofs
.per_cu
= cu
->per_cu
;
19349 ofs
.offset
= die
->offset
;
19351 slot
= (struct dwarf2_per_cu_offset_and_type
**)
19352 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
19354 complaint (&symfile_complaints
,
19355 _("A problem internal to GDB: DIE 0x%x has type already set"),
19356 die
->offset
.sect_off
);
19357 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
19362 /* Look up the type for the die at OFFSET in the appropriate type_hash
19363 table, or return NULL if the die does not have a saved type. */
19365 static struct type
*
19366 get_die_type_at_offset (sect_offset offset
,
19367 struct dwarf2_per_cu_data
*per_cu
)
19369 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
19371 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19374 ofs
.per_cu
= per_cu
;
19375 ofs
.offset
= offset
;
19376 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
19383 /* Look up the type for DIE in the appropriate type_hash table,
19384 or return NULL if DIE does not have a saved type. */
19386 static struct type
*
19387 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19389 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
19392 /* Add a dependence relationship from CU to REF_PER_CU. */
19395 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
19396 struct dwarf2_per_cu_data
*ref_per_cu
)
19400 if (cu
->dependencies
== NULL
)
19402 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
19403 NULL
, &cu
->comp_unit_obstack
,
19404 hashtab_obstack_allocate
,
19405 dummy_obstack_deallocate
);
19407 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
19409 *slot
= ref_per_cu
;
19412 /* Subroutine of dwarf2_mark to pass to htab_traverse.
19413 Set the mark field in every compilation unit in the
19414 cache that we must keep because we are keeping CU. */
19417 dwarf2_mark_helper (void **slot
, void *data
)
19419 struct dwarf2_per_cu_data
*per_cu
;
19421 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
19423 /* cu->dependencies references may not yet have been ever read if QUIT aborts
19424 reading of the chain. As such dependencies remain valid it is not much
19425 useful to track and undo them during QUIT cleanups. */
19426 if (per_cu
->cu
== NULL
)
19429 if (per_cu
->cu
->mark
)
19431 per_cu
->cu
->mark
= 1;
19433 if (per_cu
->cu
->dependencies
!= NULL
)
19434 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19439 /* Set the mark field in CU and in every other compilation unit in the
19440 cache that we must keep because we are keeping CU. */
19443 dwarf2_mark (struct dwarf2_cu
*cu
)
19448 if (cu
->dependencies
!= NULL
)
19449 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19453 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
19457 per_cu
->cu
->mark
= 0;
19458 per_cu
= per_cu
->cu
->read_in_chain
;
19462 /* Trivial hash function for partial_die_info: the hash value of a DIE
19463 is its offset in .debug_info for this objfile. */
19466 partial_die_hash (const void *item
)
19468 const struct partial_die_info
*part_die
= item
;
19470 return part_die
->offset
.sect_off
;
19473 /* Trivial comparison function for partial_die_info structures: two DIEs
19474 are equal if they have the same offset. */
19477 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
19479 const struct partial_die_info
*part_die_lhs
= item_lhs
;
19480 const struct partial_die_info
*part_die_rhs
= item_rhs
;
19482 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
19485 static struct cmd_list_element
*set_dwarf2_cmdlist
;
19486 static struct cmd_list_element
*show_dwarf2_cmdlist
;
19489 set_dwarf2_cmd (char *args
, int from_tty
)
19491 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
19495 show_dwarf2_cmd (char *args
, int from_tty
)
19497 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
19500 /* Free data associated with OBJFILE, if necessary. */
19503 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
19505 struct dwarf2_per_objfile
*data
= d
;
19508 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
19509 VEC_free (dwarf2_per_cu_ptr
,
19510 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
19512 VEC_free (dwarf2_section_info_def
, data
->types
);
19514 if (data
->dwo_files
)
19515 free_dwo_files (data
->dwo_files
, objfile
);
19517 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
19518 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
19522 /* The "save gdb-index" command. */
19524 /* The contents of the hash table we create when building the string
19526 struct strtab_entry
19528 offset_type offset
;
19532 /* Hash function for a strtab_entry.
19534 Function is used only during write_hash_table so no index format backward
19535 compatibility is needed. */
19538 hash_strtab_entry (const void *e
)
19540 const struct strtab_entry
*entry
= e
;
19541 return mapped_index_string_hash (INT_MAX
, entry
->str
);
19544 /* Equality function for a strtab_entry. */
19547 eq_strtab_entry (const void *a
, const void *b
)
19549 const struct strtab_entry
*ea
= a
;
19550 const struct strtab_entry
*eb
= b
;
19551 return !strcmp (ea
->str
, eb
->str
);
19554 /* Create a strtab_entry hash table. */
19557 create_strtab (void)
19559 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
19560 xfree
, xcalloc
, xfree
);
19563 /* Add a string to the constant pool. Return the string's offset in
19567 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
19570 struct strtab_entry entry
;
19571 struct strtab_entry
*result
;
19574 slot
= htab_find_slot (table
, &entry
, INSERT
);
19579 result
= XNEW (struct strtab_entry
);
19580 result
->offset
= obstack_object_size (cpool
);
19582 obstack_grow_str0 (cpool
, str
);
19585 return result
->offset
;
19588 /* An entry in the symbol table. */
19589 struct symtab_index_entry
19591 /* The name of the symbol. */
19593 /* The offset of the name in the constant pool. */
19594 offset_type index_offset
;
19595 /* A sorted vector of the indices of all the CUs that hold an object
19597 VEC (offset_type
) *cu_indices
;
19600 /* The symbol table. This is a power-of-2-sized hash table. */
19601 struct mapped_symtab
19603 offset_type n_elements
;
19605 struct symtab_index_entry
**data
;
19608 /* Hash function for a symtab_index_entry. */
19611 hash_symtab_entry (const void *e
)
19613 const struct symtab_index_entry
*entry
= e
;
19614 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
19615 sizeof (offset_type
) * VEC_length (offset_type
,
19616 entry
->cu_indices
),
19620 /* Equality function for a symtab_index_entry. */
19623 eq_symtab_entry (const void *a
, const void *b
)
19625 const struct symtab_index_entry
*ea
= a
;
19626 const struct symtab_index_entry
*eb
= b
;
19627 int len
= VEC_length (offset_type
, ea
->cu_indices
);
19628 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
19630 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
19631 VEC_address (offset_type
, eb
->cu_indices
),
19632 sizeof (offset_type
) * len
);
19635 /* Destroy a symtab_index_entry. */
19638 delete_symtab_entry (void *p
)
19640 struct symtab_index_entry
*entry
= p
;
19641 VEC_free (offset_type
, entry
->cu_indices
);
19645 /* Create a hash table holding symtab_index_entry objects. */
19648 create_symbol_hash_table (void)
19650 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
19651 delete_symtab_entry
, xcalloc
, xfree
);
19654 /* Create a new mapped symtab object. */
19656 static struct mapped_symtab
*
19657 create_mapped_symtab (void)
19659 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
19660 symtab
->n_elements
= 0;
19661 symtab
->size
= 1024;
19662 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19666 /* Destroy a mapped_symtab. */
19669 cleanup_mapped_symtab (void *p
)
19671 struct mapped_symtab
*symtab
= p
;
19672 /* The contents of the array are freed when the other hash table is
19674 xfree (symtab
->data
);
19678 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
19681 Function is used only during write_hash_table so no index format backward
19682 compatibility is needed. */
19684 static struct symtab_index_entry
**
19685 find_slot (struct mapped_symtab
*symtab
, const char *name
)
19687 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
19689 index
= hash
& (symtab
->size
- 1);
19690 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
19694 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
19695 return &symtab
->data
[index
];
19696 index
= (index
+ step
) & (symtab
->size
- 1);
19700 /* Expand SYMTAB's hash table. */
19703 hash_expand (struct mapped_symtab
*symtab
)
19705 offset_type old_size
= symtab
->size
;
19707 struct symtab_index_entry
**old_entries
= symtab
->data
;
19710 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19712 for (i
= 0; i
< old_size
; ++i
)
19714 if (old_entries
[i
])
19716 struct symtab_index_entry
**slot
= find_slot (symtab
,
19717 old_entries
[i
]->name
);
19718 *slot
= old_entries
[i
];
19722 xfree (old_entries
);
19725 /* Add an entry to SYMTAB. NAME is the name of the symbol.
19726 CU_INDEX is the index of the CU in which the symbol appears.
19727 IS_STATIC is one if the symbol is static, otherwise zero (global). */
19730 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
19731 int is_static
, gdb_index_symbol_kind kind
,
19732 offset_type cu_index
)
19734 struct symtab_index_entry
**slot
;
19735 offset_type cu_index_and_attrs
;
19737 ++symtab
->n_elements
;
19738 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
19739 hash_expand (symtab
);
19741 slot
= find_slot (symtab
, name
);
19744 *slot
= XNEW (struct symtab_index_entry
);
19745 (*slot
)->name
= name
;
19746 /* index_offset is set later. */
19747 (*slot
)->cu_indices
= NULL
;
19750 cu_index_and_attrs
= 0;
19751 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
19752 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
19753 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
19755 /* We don't want to record an index value twice as we want to avoid the
19757 We process all global symbols and then all static symbols
19758 (which would allow us to avoid the duplication by only having to check
19759 the last entry pushed), but a symbol could have multiple kinds in one CU.
19760 To keep things simple we don't worry about the duplication here and
19761 sort and uniqufy the list after we've processed all symbols. */
19762 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
19765 /* qsort helper routine for uniquify_cu_indices. */
19768 offset_type_compare (const void *ap
, const void *bp
)
19770 offset_type a
= *(offset_type
*) ap
;
19771 offset_type b
= *(offset_type
*) bp
;
19773 return (a
> b
) - (b
> a
);
19776 /* Sort and remove duplicates of all symbols' cu_indices lists. */
19779 uniquify_cu_indices (struct mapped_symtab
*symtab
)
19783 for (i
= 0; i
< symtab
->size
; ++i
)
19785 struct symtab_index_entry
*entry
= symtab
->data
[i
];
19788 && entry
->cu_indices
!= NULL
)
19790 unsigned int next_to_insert
, next_to_check
;
19791 offset_type last_value
;
19793 qsort (VEC_address (offset_type
, entry
->cu_indices
),
19794 VEC_length (offset_type
, entry
->cu_indices
),
19795 sizeof (offset_type
), offset_type_compare
);
19797 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
19798 next_to_insert
= 1;
19799 for (next_to_check
= 1;
19800 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
19803 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
19806 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
19808 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
19813 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
19818 /* Add a vector of indices to the constant pool. */
19821 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
19822 struct symtab_index_entry
*entry
)
19826 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
19829 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
19830 offset_type val
= MAYBE_SWAP (len
);
19835 entry
->index_offset
= obstack_object_size (cpool
);
19837 obstack_grow (cpool
, &val
, sizeof (val
));
19839 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
19842 val
= MAYBE_SWAP (iter
);
19843 obstack_grow (cpool
, &val
, sizeof (val
));
19848 struct symtab_index_entry
*old_entry
= *slot
;
19849 entry
->index_offset
= old_entry
->index_offset
;
19852 return entry
->index_offset
;
19855 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
19856 constant pool entries going into the obstack CPOOL. */
19859 write_hash_table (struct mapped_symtab
*symtab
,
19860 struct obstack
*output
, struct obstack
*cpool
)
19863 htab_t symbol_hash_table
;
19866 symbol_hash_table
= create_symbol_hash_table ();
19867 str_table
= create_strtab ();
19869 /* We add all the index vectors to the constant pool first, to
19870 ensure alignment is ok. */
19871 for (i
= 0; i
< symtab
->size
; ++i
)
19873 if (symtab
->data
[i
])
19874 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
19877 /* Now write out the hash table. */
19878 for (i
= 0; i
< symtab
->size
; ++i
)
19880 offset_type str_off
, vec_off
;
19882 if (symtab
->data
[i
])
19884 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
19885 vec_off
= symtab
->data
[i
]->index_offset
;
19889 /* While 0 is a valid constant pool index, it is not valid
19890 to have 0 for both offsets. */
19895 str_off
= MAYBE_SWAP (str_off
);
19896 vec_off
= MAYBE_SWAP (vec_off
);
19898 obstack_grow (output
, &str_off
, sizeof (str_off
));
19899 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
19902 htab_delete (str_table
);
19903 htab_delete (symbol_hash_table
);
19906 /* Struct to map psymtab to CU index in the index file. */
19907 struct psymtab_cu_index_map
19909 struct partial_symtab
*psymtab
;
19910 unsigned int cu_index
;
19914 hash_psymtab_cu_index (const void *item
)
19916 const struct psymtab_cu_index_map
*map
= item
;
19918 return htab_hash_pointer (map
->psymtab
);
19922 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
19924 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
19925 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
19927 return lhs
->psymtab
== rhs
->psymtab
;
19930 /* Helper struct for building the address table. */
19931 struct addrmap_index_data
19933 struct objfile
*objfile
;
19934 struct obstack
*addr_obstack
;
19935 htab_t cu_index_htab
;
19937 /* Non-zero if the previous_* fields are valid.
19938 We can't write an entry until we see the next entry (since it is only then
19939 that we know the end of the entry). */
19940 int previous_valid
;
19941 /* Index of the CU in the table of all CUs in the index file. */
19942 unsigned int previous_cu_index
;
19943 /* Start address of the CU. */
19944 CORE_ADDR previous_cu_start
;
19947 /* Write an address entry to OBSTACK. */
19950 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
19951 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
19953 offset_type cu_index_to_write
;
19955 CORE_ADDR baseaddr
;
19957 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19959 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
19960 obstack_grow (obstack
, addr
, 8);
19961 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
19962 obstack_grow (obstack
, addr
, 8);
19963 cu_index_to_write
= MAYBE_SWAP (cu_index
);
19964 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
19967 /* Worker function for traversing an addrmap to build the address table. */
19970 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
19972 struct addrmap_index_data
*data
= datap
;
19973 struct partial_symtab
*pst
= obj
;
19975 if (data
->previous_valid
)
19976 add_address_entry (data
->objfile
, data
->addr_obstack
,
19977 data
->previous_cu_start
, start_addr
,
19978 data
->previous_cu_index
);
19980 data
->previous_cu_start
= start_addr
;
19983 struct psymtab_cu_index_map find_map
, *map
;
19984 find_map
.psymtab
= pst
;
19985 map
= htab_find (data
->cu_index_htab
, &find_map
);
19986 gdb_assert (map
!= NULL
);
19987 data
->previous_cu_index
= map
->cu_index
;
19988 data
->previous_valid
= 1;
19991 data
->previous_valid
= 0;
19996 /* Write OBJFILE's address map to OBSTACK.
19997 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
19998 in the index file. */
20001 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
20002 htab_t cu_index_htab
)
20004 struct addrmap_index_data addrmap_index_data
;
20006 /* When writing the address table, we have to cope with the fact that
20007 the addrmap iterator only provides the start of a region; we have to
20008 wait until the next invocation to get the start of the next region. */
20010 addrmap_index_data
.objfile
= objfile
;
20011 addrmap_index_data
.addr_obstack
= obstack
;
20012 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
20013 addrmap_index_data
.previous_valid
= 0;
20015 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
20016 &addrmap_index_data
);
20018 /* It's highly unlikely the last entry (end address = 0xff...ff)
20019 is valid, but we should still handle it.
20020 The end address is recorded as the start of the next region, but that
20021 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20023 if (addrmap_index_data
.previous_valid
)
20024 add_address_entry (objfile
, obstack
,
20025 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
20026 addrmap_index_data
.previous_cu_index
);
20029 /* Return the symbol kind of PSYM. */
20031 static gdb_index_symbol_kind
20032 symbol_kind (struct partial_symbol
*psym
)
20034 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
20035 enum address_class aclass
= PSYMBOL_CLASS (psym
);
20043 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
20045 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20047 case LOC_CONST_BYTES
:
20048 case LOC_OPTIMIZED_OUT
:
20050 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20052 /* Note: It's currently impossible to recognize psyms as enum values
20053 short of reading the type info. For now punt. */
20054 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20056 /* There are other LOC_FOO values that one might want to classify
20057 as variables, but dwarf2read.c doesn't currently use them. */
20058 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20060 case STRUCT_DOMAIN
:
20061 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20063 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20067 /* Add a list of partial symbols to SYMTAB. */
20070 write_psymbols (struct mapped_symtab
*symtab
,
20072 struct partial_symbol
**psymp
,
20074 offset_type cu_index
,
20077 for (; count
-- > 0; ++psymp
)
20079 struct partial_symbol
*psym
= *psymp
;
20082 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
20083 error (_("Ada is not currently supported by the index"));
20085 /* Only add a given psymbol once. */
20086 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
20089 gdb_index_symbol_kind kind
= symbol_kind (psym
);
20092 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
20093 is_static
, kind
, cu_index
);
20098 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20099 exception if there is an error. */
20102 write_obstack (FILE *file
, struct obstack
*obstack
)
20104 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
20106 != obstack_object_size (obstack
))
20107 error (_("couldn't data write to file"));
20110 /* Unlink a file if the argument is not NULL. */
20113 unlink_if_set (void *p
)
20115 char **filename
= p
;
20117 unlink (*filename
);
20120 /* A helper struct used when iterating over debug_types. */
20121 struct signatured_type_index_data
20123 struct objfile
*objfile
;
20124 struct mapped_symtab
*symtab
;
20125 struct obstack
*types_list
;
20130 /* A helper function that writes a single signatured_type to an
20134 write_one_signatured_type (void **slot
, void *d
)
20136 struct signatured_type_index_data
*info
= d
;
20137 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
20138 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
20139 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20142 write_psymbols (info
->symtab
,
20144 info
->objfile
->global_psymbols
.list
20145 + psymtab
->globals_offset
,
20146 psymtab
->n_global_syms
, info
->cu_index
,
20148 write_psymbols (info
->symtab
,
20150 info
->objfile
->static_psymbols
.list
20151 + psymtab
->statics_offset
,
20152 psymtab
->n_static_syms
, info
->cu_index
,
20155 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20156 entry
->per_cu
.offset
.sect_off
);
20157 obstack_grow (info
->types_list
, val
, 8);
20158 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20159 entry
->type_offset_in_tu
.cu_off
);
20160 obstack_grow (info
->types_list
, val
, 8);
20161 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
20162 obstack_grow (info
->types_list
, val
, 8);
20169 /* Recurse into all "included" dependencies and write their symbols as
20170 if they appeared in this psymtab. */
20173 recursively_write_psymbols (struct objfile
*objfile
,
20174 struct partial_symtab
*psymtab
,
20175 struct mapped_symtab
*symtab
,
20177 offset_type cu_index
)
20181 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
20182 if (psymtab
->dependencies
[i
]->user
!= NULL
)
20183 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
20184 symtab
, psyms_seen
, cu_index
);
20186 write_psymbols (symtab
,
20188 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
20189 psymtab
->n_global_syms
, cu_index
,
20191 write_psymbols (symtab
,
20193 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
20194 psymtab
->n_static_syms
, cu_index
,
20198 /* Create an index file for OBJFILE in the directory DIR. */
20201 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
20203 struct cleanup
*cleanup
;
20204 char *filename
, *cleanup_filename
;
20205 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
20206 struct obstack cu_list
, types_cu_list
;
20209 struct mapped_symtab
*symtab
;
20210 offset_type val
, size_of_contents
, total_len
;
20213 htab_t cu_index_htab
;
20214 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
20216 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
20219 if (dwarf2_per_objfile
->using_index
)
20220 error (_("Cannot use an index to create the index"));
20222 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
20223 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20225 if (stat (objfile
->name
, &st
) < 0)
20226 perror_with_name (objfile
->name
);
20228 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
20229 INDEX_SUFFIX
, (char *) NULL
);
20230 cleanup
= make_cleanup (xfree
, filename
);
20232 out_file
= fopen (filename
, "wb");
20234 error (_("Can't open `%s' for writing"), filename
);
20236 cleanup_filename
= filename
;
20237 make_cleanup (unlink_if_set
, &cleanup_filename
);
20239 symtab
= create_mapped_symtab ();
20240 make_cleanup (cleanup_mapped_symtab
, symtab
);
20242 obstack_init (&addr_obstack
);
20243 make_cleanup_obstack_free (&addr_obstack
);
20245 obstack_init (&cu_list
);
20246 make_cleanup_obstack_free (&cu_list
);
20248 obstack_init (&types_cu_list
);
20249 make_cleanup_obstack_free (&types_cu_list
);
20251 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
20252 NULL
, xcalloc
, xfree
);
20253 make_cleanup_htab_delete (psyms_seen
);
20255 /* While we're scanning CU's create a table that maps a psymtab pointer
20256 (which is what addrmap records) to its index (which is what is recorded
20257 in the index file). This will later be needed to write the address
20259 cu_index_htab
= htab_create_alloc (100,
20260 hash_psymtab_cu_index
,
20261 eq_psymtab_cu_index
,
20262 NULL
, xcalloc
, xfree
);
20263 make_cleanup_htab_delete (cu_index_htab
);
20264 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
20265 xmalloc (sizeof (struct psymtab_cu_index_map
)
20266 * dwarf2_per_objfile
->n_comp_units
);
20267 make_cleanup (xfree
, psymtab_cu_index_map
);
20269 /* The CU list is already sorted, so we don't need to do additional
20270 work here. Also, the debug_types entries do not appear in
20271 all_comp_units, but only in their own hash table. */
20272 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
20274 struct dwarf2_per_cu_data
*per_cu
20275 = dwarf2_per_objfile
->all_comp_units
[i
];
20276 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20278 struct psymtab_cu_index_map
*map
;
20281 if (psymtab
->user
== NULL
)
20282 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
20284 map
= &psymtab_cu_index_map
[i
];
20285 map
->psymtab
= psymtab
;
20287 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
20288 gdb_assert (slot
!= NULL
);
20289 gdb_assert (*slot
== NULL
);
20292 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20293 per_cu
->offset
.sect_off
);
20294 obstack_grow (&cu_list
, val
, 8);
20295 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
20296 obstack_grow (&cu_list
, val
, 8);
20299 /* Dump the address map. */
20300 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
20302 /* Write out the .debug_type entries, if any. */
20303 if (dwarf2_per_objfile
->signatured_types
)
20305 struct signatured_type_index_data sig_data
;
20307 sig_data
.objfile
= objfile
;
20308 sig_data
.symtab
= symtab
;
20309 sig_data
.types_list
= &types_cu_list
;
20310 sig_data
.psyms_seen
= psyms_seen
;
20311 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
20312 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
20313 write_one_signatured_type
, &sig_data
);
20316 /* Now that we've processed all symbols we can shrink their cu_indices
20318 uniquify_cu_indices (symtab
);
20320 obstack_init (&constant_pool
);
20321 make_cleanup_obstack_free (&constant_pool
);
20322 obstack_init (&symtab_obstack
);
20323 make_cleanup_obstack_free (&symtab_obstack
);
20324 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
20326 obstack_init (&contents
);
20327 make_cleanup_obstack_free (&contents
);
20328 size_of_contents
= 6 * sizeof (offset_type
);
20329 total_len
= size_of_contents
;
20331 /* The version number. */
20332 val
= MAYBE_SWAP (7);
20333 obstack_grow (&contents
, &val
, sizeof (val
));
20335 /* The offset of the CU list from the start of the file. */
20336 val
= MAYBE_SWAP (total_len
);
20337 obstack_grow (&contents
, &val
, sizeof (val
));
20338 total_len
+= obstack_object_size (&cu_list
);
20340 /* The offset of the types CU list from the start of the file. */
20341 val
= MAYBE_SWAP (total_len
);
20342 obstack_grow (&contents
, &val
, sizeof (val
));
20343 total_len
+= obstack_object_size (&types_cu_list
);
20345 /* The offset of the address table from the start of the file. */
20346 val
= MAYBE_SWAP (total_len
);
20347 obstack_grow (&contents
, &val
, sizeof (val
));
20348 total_len
+= obstack_object_size (&addr_obstack
);
20350 /* The offset of the symbol table from the start of the file. */
20351 val
= MAYBE_SWAP (total_len
);
20352 obstack_grow (&contents
, &val
, sizeof (val
));
20353 total_len
+= obstack_object_size (&symtab_obstack
);
20355 /* The offset of the constant pool from the start of the file. */
20356 val
= MAYBE_SWAP (total_len
);
20357 obstack_grow (&contents
, &val
, sizeof (val
));
20358 total_len
+= obstack_object_size (&constant_pool
);
20360 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
20362 write_obstack (out_file
, &contents
);
20363 write_obstack (out_file
, &cu_list
);
20364 write_obstack (out_file
, &types_cu_list
);
20365 write_obstack (out_file
, &addr_obstack
);
20366 write_obstack (out_file
, &symtab_obstack
);
20367 write_obstack (out_file
, &constant_pool
);
20371 /* We want to keep the file, so we set cleanup_filename to NULL
20372 here. See unlink_if_set. */
20373 cleanup_filename
= NULL
;
20375 do_cleanups (cleanup
);
20378 /* Implementation of the `save gdb-index' command.
20380 Note that the file format used by this command is documented in the
20381 GDB manual. Any changes here must be documented there. */
20384 save_gdb_index_command (char *arg
, int from_tty
)
20386 struct objfile
*objfile
;
20389 error (_("usage: save gdb-index DIRECTORY"));
20391 ALL_OBJFILES (objfile
)
20395 /* If the objfile does not correspond to an actual file, skip it. */
20396 if (stat (objfile
->name
, &st
) < 0)
20399 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
20400 if (dwarf2_per_objfile
)
20402 volatile struct gdb_exception except
;
20404 TRY_CATCH (except
, RETURN_MASK_ERROR
)
20406 write_psymtabs_to_index (objfile
, arg
);
20408 if (except
.reason
< 0)
20409 exception_fprintf (gdb_stderr
, except
,
20410 _("Error while writing index for `%s': "),
20418 int dwarf2_always_disassemble
;
20421 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
20422 struct cmd_list_element
*c
, const char *value
)
20424 fprintf_filtered (file
,
20425 _("Whether to always disassemble "
20426 "DWARF expressions is %s.\n"),
20431 show_check_physname (struct ui_file
*file
, int from_tty
,
20432 struct cmd_list_element
*c
, const char *value
)
20434 fprintf_filtered (file
,
20435 _("Whether to check \"physname\" is %s.\n"),
20439 void _initialize_dwarf2_read (void);
20442 _initialize_dwarf2_read (void)
20444 struct cmd_list_element
*c
;
20446 dwarf2_objfile_data_key
20447 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
20449 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
20450 Set DWARF 2 specific variables.\n\
20451 Configure DWARF 2 variables such as the cache size"),
20452 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
20453 0/*allow-unknown*/, &maintenance_set_cmdlist
);
20455 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
20456 Show DWARF 2 specific variables\n\
20457 Show DWARF 2 variables such as the cache size"),
20458 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
20459 0/*allow-unknown*/, &maintenance_show_cmdlist
);
20461 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
20462 &dwarf2_max_cache_age
, _("\
20463 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
20464 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
20465 A higher limit means that cached compilation units will be stored\n\
20466 in memory longer, and more total memory will be used. Zero disables\n\
20467 caching, which can slow down startup."),
20469 show_dwarf2_max_cache_age
,
20470 &set_dwarf2_cmdlist
,
20471 &show_dwarf2_cmdlist
);
20473 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
20474 &dwarf2_always_disassemble
, _("\
20475 Set whether `info address' always disassembles DWARF expressions."), _("\
20476 Show whether `info address' always disassembles DWARF expressions."), _("\
20477 When enabled, DWARF expressions are always printed in an assembly-like\n\
20478 syntax. When disabled, expressions will be printed in a more\n\
20479 conversational style, when possible."),
20481 show_dwarf2_always_disassemble
,
20482 &set_dwarf2_cmdlist
,
20483 &show_dwarf2_cmdlist
);
20485 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
20486 Set debugging of the dwarf2 reader."), _("\
20487 Show debugging of the dwarf2 reader."), _("\
20488 When enabled, debugging messages are printed during dwarf2 reading\n\
20489 and symtab expansion."),
20492 &setdebuglist
, &showdebuglist
);
20494 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
20495 Set debugging of the dwarf2 DIE reader."), _("\
20496 Show debugging of the dwarf2 DIE reader."), _("\
20497 When enabled (non-zero), DIEs are dumped after they are read in.\n\
20498 The value is the maximum depth to print."),
20501 &setdebuglist
, &showdebuglist
);
20503 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
20504 Set cross-checking of \"physname\" code against demangler."), _("\
20505 Show cross-checking of \"physname\" code against demangler."), _("\
20506 When enabled, GDB's internal \"physname\" code is checked against\n\
20508 NULL
, show_check_physname
,
20509 &setdebuglist
, &showdebuglist
);
20511 add_setshow_boolean_cmd ("use-deprecated-index-sections",
20512 no_class
, &use_deprecated_index_sections
, _("\
20513 Set whether to use deprecated gdb_index sections."), _("\
20514 Show whether to use deprecated gdb_index sections."), _("\
20515 When enabled, deprecated .gdb_index sections are used anyway.\n\
20516 Normally they are ignored either because of a missing feature or\n\
20517 performance issue.\n\
20518 Warning: This option must be enabled before gdb reads the file."),
20521 &setlist
, &showlist
);
20523 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
20525 Save a gdb-index file.\n\
20526 Usage: save gdb-index DIRECTORY"),
20528 set_cmd_completer (c
, filename_completer
);